import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n; scan(n); auto a = readln.split.to!(int[]); auto b = readln.split.to!(int[]); auto ar = new int[](n + 1); foreach (i ; 0 .. n) { ar[a[i]] = i; } auto set = redBlackTree!(int)(); auto aw = new bool[](n + 1); foreach (i ; 0 .. n) { set.insert(ar[b[i]]); if (set.upperBound(ar[b[i]]).empty) { aw[b[i]] = true; } } foreach (i ; 1 .. n + 1) { if (aw[i]) writeln(i); } } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }