/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main {
public static void main
(String[] args
) {
Scanner sc
= new Scanner
(System.
in);
int n = sc.nextInt();
int[] A = new int[n];
int[] B = new int[n];
for (int i = 0; i < n; i++)
A[i] = sc.nextInt();
for (int i = 0; i < n; i++)
B[i] = sc.nextInt();
List<Integer> badPos = new ArrayList<>();
List<Integer> goodPos = new ArrayList<>();
for (int i = 0; i < n; i++) {
if (A[i] == B[i]) badPos.add(i);
else goodPos.add(i);
}
//no conflicts → no swaps
if (badPos.size() == 0) {
return;
}
//count how many times each value appears in bad positions
Map
<Integer, Integer
> freq
= new HashMap
<>(); for (int idx : badPos) {
freq.put(A[idx], freq.getOrDefault(A[idx], 0) + 1);
}
//max heap → always solve most problematic duplicate first
PriorityQueue<int[]> pq = new PriorityQueue<>(
(x, y) -> y[1] - x[1] // sort by frequency desc
);
for (Map.
Entry<Integer, Integer
> e
: freq.
entrySet()) { pq.add(new int[]{ e.getKey(), e.getValue() });
}
int swaps = 0;
//pair off the two most frequent values repeatedly
while (pq.size() > 1) {
int[] a = pq.poll();
int[] b = pq.poll();
swaps++; //one swap fixes 2 conflict occurrences
a[1]--;
b[1]--;
if (a[1] > 0) pq.add(a);
if (b[1] > 0) pq.add(b);
}
//leftover → only one value remains to fix
if (pq.isEmpty()) {
return;
}
int[] left = pq.poll();
int need = left[1]; // how many unsolved bad occurrences remain
int v = left[0]; // the leftover value
//place these remaining occurrences into good positions
for (int g : goodPos) {
if (need == 0) break;
//avoid swapping into a position that becomes bad again
if (A[g] == v) continue;
if (B[g] == v) continue;
swaps++;
need--;
}
// if still leftover → impossible
if (need > 0) {
} else {
}
}
}