Language: C++

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        long[] a = new long[N];
        long[] b = new long[N];
        for(int i=0;i<N;++i)a[i] =scan.nextLong();
        for(int i=0;i<N;++i)b[i] =scan.nextLong();
        Map<Long,Integer> countmap = new HashMap<>();
        long x = 0;
        for(int i=0;i<N;++i)x^=a[i];
        countmap.put(x,1);
        for(int i=0;i<N;++i){
            if(!countmap.containsKey(a[i]))countmap.put(a[i],0);
            countmap.put(a[i], countmap.get(a[i])+1);
        }
        for(int i=0;i<N;++i){
            if(!countmap.containsKey(b[i]) || countmap.get(b[i])==0){
                System.out.println(-1);
                return;
            }
            countmap.put(b[i], countmap.get(b[i])-1);
        }
        Map<Long, Deque<Integer>> bNumToIndex = new HashMap<>();
        for(int i=0;i<N;++i){
            if(!bNumToIndex.containsKey(b[i]))bNumToIndex.put(b[i],new ArrayDeque<>());
            bNumToIndex.get(b[i]).add(i);
        }
        int ans =0;
        boolean used[] = new boolean[N];
        int index=0;
        while(true){
            int nextIndex=-1;
            if(bNumToIndex.containsKey(x)){
                nextIndex=bNumToIndex.get(x).poll();
                while(used[nextIndex] && !bNumToIndex.get(x).isEmpty()){
                    nextIndex = bNumToIndex.get(x).poll();
                }
                if(bNumToIndex.get(x).isEmpty())bNumToIndex.remove(x);
                if(used[nextIndex])nextIndex=-1;
            }
            if(nextIndex<0){
                while(index<N &&(used[index] || a[index]==b[index]))++index;
                if(index>=N)break;
                nextIndex=index;
                ++ans;
            }
            used[nextIndex]=true;
            if(x!=a[nextIndex]){
                ++ans;
                x=a[nextIndex];
            };
        }

        System.out.println(ans);


    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.ArrayDeque;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.ArrayList;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.Deque;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.HashMap;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.List;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.util.Map;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import java.util.Scanner;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import java.util.Set;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:11:11: error: expected ':' before 'static'
   11 |     public static void main(String[] args){
      |           ^~~~~~~
      |           :
a.cc:11:29: error: 'String' has not been declared
   11 |     public static void main(String[] args){
      |                             ^~~~~~
a.cc:11:38: error: expected ',' or '...' before 'args'
   11 |     public static void main(String[] args){
      |                                      ^~~~
a.cc:68:2: error: expected ';' after class definition
   68 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:12:9: error: 'Scanner' was not declared in this scope
   12 |         Scanner scan = new Scanner(System.in);
      |         ^~~~~~~
a.cc:13:17: error: 'scan' was not declared in this scope
   13 |         int N = scan.nextInt();
      |                 ^~~~
a.cc:14:13: error: structured binding declaration cannot have type 'long int'
   14 |         long[] a = new long[N];
      |             ^~
a.cc:14:13: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:14:13: error: empty structured binding declaration
a.cc:14:16: error: expected initializer before 'a'
   14 |         long[] a = new long[N];
      |                ^
a.cc:15:13: error: structured binding declaration cannot have type 'long int'
   15 |         long[] b = new long[N];
      |             ^~
a.cc:15:13: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:15:13: error: empty structured binding declaration
a.cc:15:16: error: expected initializer before 'b'
   15 |         long[] b = new long[N];
      |                ^
a.cc:16:29: error: 'a' was not declared in this scope
   16 |         for(int i=0;i<N;++i)a[i] =scan.nextLong();
      |                             ^
a.cc:17:29: error: 'b' was not declared in this scope
   17 |         for(int i=0;i<N;++i)b[i] =scan.nextLong();
      |                             ^
a.cc:18:9: error: 'Map' was not declared in this scope
   18 |         Map<Long,Integer> countmap = new HashMap<>();
      |         ^~~
a.cc:18:13: error: 'Long' was not declared in this scope; did you mean 'long'?
   18 |         Map<Long,Integer> countmap = new HashMap<>();
      |             ^~~~
      |             long
a.cc:18:18: error: 'Integer' was not declared in this scope
   18 |         Map<Long,Integer> countmap = new HashMap<>();
      |                  ^~~~~~~
a.cc:18:27: error: 'countmap' was not declared in this scope
   18 |         Map<Long,Integer> countmap = new HashMap<>();
      |                           ^~~~~~~~
a.cc:18:42: error: 'HashMap' does not name a type
   18 |         Map<Long,Integer> countmap = new HashMap<>();
      |                                          ^~~~~~~
a.cc:18:50: error: expected primary-expression before '>' token
   18 |         Map<Long,Integer> countmap = new HashMap<>();
      |                                                  ^
a.cc:18:52: error: expected primary-expression before ')' token
   18 |         Map<Long,Integer> countmap = new HashMap<>();
      |                                                    ^
a.cc:20:32: error: 'a' was not declared in this scope
   20 |         for(int i=0;i<N;++i)x^=a[i];
      |                                ^
a.cc:23:38: error: 'a' was not declared in this scope
   23 |             if(!countmap.containsKey(a[i]))countmap.put(a[i],0);
      |                                      ^
a.cc:24:26: error: 'a' was not declared in this scope
   24 |             countmap.put(a[i], countmap.get(a[i])+1);
      |                          ^
a.cc:27:38: error: 'b' was not declared in this scope
   27 |             if(!countmap.containsKey(b[i]) || countmap.get(b[i])==0){
      |                                      ^
a.cc:28:17: error: 'System' was not declared in this scope
   28 |                 System.out.println(-1);
      |                 ^~~~~~
a.cc:31:26: error: 'b' was not declared in this scope
   31 |             countmap.put(b[i], countmap.get(b[i])-1);
      |                          ^
a.cc:33:19: error: 'Deque' was not declared in this scope
   33 |         Map<Long, Deque<Integer>> bNumToIndex = new HashMap<>();
      |                   ^~~~~
a.cc:33:35: error: 'bNumToIndex' was not declared in this scope
   33 |         Map<Long, Deque<Integer>> bNumToIndex = new HashMap<>();
      |                                   ^~~~~~~~~~~
a.cc:33:53: error: 'HashMap' does not name a type
   33 |         Map<Long, Deque<Integer>> bNumToIndex = new HashMap<>();
      |                                                     ^~~~~~~
a.cc:33:61: error: expected primary-expression before '>' token
   33 |         Map<Long, Deque<Integer>> bNumToIndex = new HashMap<>();
      |                                                             ^
a.cc:33:63: error: expected primary-expression before ')' token
   33 |         Map<Long, Deque<Integer>> bNumToIndex = new HashMap<>();
      |                                                               ^
a.cc:35:41: error: 'b' was not declared in this scope
   35 |             if(!bNumToIndex.containsKey(b[i]))bNumToIndex.put(b[i],new ArrayDeque<>());
      |                                         ^
a.cc:35:72: error: 'ArrayDeque' does not name a type
   35 |             if(!bNumToIndex.containsKey(b[i]))bNumToIndex.put(b[i],new ArrayDeque<>());
      |                                                                        ^~~~~~~~~~
a.cc:35:83: error: expected primary-expression before '>' token
   35 |             if(!bNumToIndex.containsKey(b[i]))bNumToIndex.put(b[i],new ArrayDeque<>());
      |                                                                                   ^
a.cc:35:85: error: expected primary-expression before ')' token
   35 |             if(!bNumToIndex.containsKey(b[i]))bNumToIndex.put(b[i],new ArrayDeque<>());
      |                                                                                     ^
a.cc:36:29: error: 'b' was not declared in this scope
   36 |             bNumToIndex.get(b[i]).add(i);
      |                             ^
a.cc:39:9: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   39 |         boolean used[] = new boolean[N];
      |         ^~~~~~~
      |         bool
a.cc:45:23: error: 'used' was not declared in this scope
   45 |                 while(used[nextIndex] && !bNumToIndex.get(x).isEmpty()){
      |                       ^~~~
a.cc:49:20: error: 'used' was not declared in this scope
   49 |                 if(used[nextIndex])nextIndex=-1;
      |                    ^~~~
a.cc:52:34: error: 'used' was not declared in this scope
   52 |                 while(index<N &&(used[index] || a[index]==b[index]))++index;
      |                                  ^~~~
a.cc:52:49: error: 'a' was not declared in this scope
   52 |                 while(index<N &&(used[index] || a[index]==b[index]))++index;
      |                                                 ^
a.cc:52:59: error: 'b' was not declared in this scope
   52 |                 while(index<N &&(used[index] || a[index]==b[index]))++index;
      |                                                           ^
a.cc:57:13: error: 'used' was not declared in this scope
   57 |             used[nextIndex]=true;
      |             ^~~~
a.cc:58:19: error: 'a' was not declared in this scope
   58 |             if(x!=a[nextIndex]){
      |                   ^
a.cc:64:9: error: 'System' was not declared in this scope
   64 |         System.out.println(ans);
      |         ^~~~~~