import java.io.*;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.IntStream;

public class swaps_av_optimal {

    void solve() {
//        stress();
        int n = in.nextInt();
        int[] a = in.nextIntArray(n), b = in.nextIntArray(n);
        for (int i = 0; i < a.length; i++) {
            a[i]--;
            b[i]--;
        }
        List<Integer> result = solve(a, b);
        if (result == null) {
            out.println("-1");
        } else {
            out.println(result.size());
            for (int i : result) {
                out.print((i + 1) + " ");
            }
            out.println();
        }
    }

    void stress() {
        Random rng = new Random();
        int nonNulls = 0;
        int total = 0;
        for (int IT = 0; IT < 10000000; IT++) {
            int n = 10;
            int[] a = IntStream.range(0, n).toArray();
            int[] b = a.clone();
            shuffle(a, rng);
            shuffle(b, rng);
            List<Integer> result = solve(a, b);
            if (result != null) {
                nonNulls++;
                total += result.size();
            }
        }
        System.err.println(nonNulls + " " + ((double) total / nonNulls));
    }

    public static void shuffle(int[] b, Random rng) {
        for (int i = 1; i < b.length; i++) {
            int pos = rng.nextInt(i + 1);
            int tmp = b[i];
            b[i] = b[pos];
            b[pos] = tmp;
        }
    }


    List<Integer> solve(int[] a, int[] b) {
        int n = a.length;
        int[] posA = inverse(a), posB = inverse(b);
        for (int i = 0; i < n - 1; i++) {
            boolean inA = posA[i] < posA[i + 1], inB = posB[i] < posB[i + 1];
            if (inA != inB) {
                return null;
            }
        }
        TreeSet<Integer> availableSwaps = new TreeSet<>();
        Predicate<Integer> canSwap = i -> Math.abs(a[i] - a[i + 1]) > 1 && posB[a[i]] > posB[a[i + 1]];
        for (int i = 0; i < n - 1; i++) {
            if (canSwap.test(i)) {
                availableSwaps.add(i);
            }
        }
        List<Integer> swaps = new ArrayList<>();
        while (!availableSwaps.isEmpty()) {
            int i = availableSwaps.pollFirst();
            availableSwaps.remove(i - 1);
            availableSwaps.remove(i + 1);
            swaps.add(i);
            swap(a, posA, i);
            if (i > 0 && canSwap.test(i - 1)) {
                availableSwaps.add(i - 1);
            }
            if (i + 1 < n - 1 && canSwap.test(i + 1)) {
                availableSwaps.add(i + 1);
            }
        }
        if (!Arrays.equals(a, b)) {
            throw new AssertionError();
        }
        return swaps;
    }

    private void swap(int[] a, int[] inv, int i) {
        int tmp = a[i];
        a[i] = a[i + 1];
        a[i + 1] = tmp;
        inv[a[i]] = i;
        inv[a[i + 1]] = i + 1;
    }

    private int[] inverse(int[] a) {
        int[] inv = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            inv[a[i]] = i;
        }
        return inv;
    }

    void run() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    FastScanner in;
    PrintWriter out;

    public static void main(String[] args) {
        new swaps_av_optimal().run();
    }

    public class FastScanner {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public boolean hasMoreTokens() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    return false;
                }
                if (line == null) {
                    return false;
                }
                st = new StringTokenizer(line);
            }
            return true;
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextIntArray(int n) {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }

        public long[] nextLongArray(int n) {
            long[] ret = new long[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextLong();
            }
            return ret;
        }
    }
}
