import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) throws IOException, ClassNotFoundException{ boolean[] f = new boolean[1000005]; for(int i=2; i a1 = (ArrayList) o1.readObject(); ArrayList a2 = (ArrayList) o2.readObject(); TreeSet t = new TreeSet<>(a1); t.forEach(e1 -> { int e2 = n - e1; if(e2 > e1 && f[e1] && f[e2] && a1.contains(e2) && !a2.contains(e1) && !a2.contains(e2)){ System.out.println(e1 + " " + e2); } }); } }