import std.stdio; import std.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; void main() { int n = readln.chomp.to!int; int[] a, b; foreach (i; 0..n) { auto v = readln.chomp.split.map!(to!int); a ~= v.front; b ~= v.back; } int m = readln.chomp.to!int; int[] x, y; foreach (i; 0..m) { auto v = readln.chomp.split.map!(to!int); x ~= v.front; y ~= v.back; } alias Node = Tuple!(int, "count", int, "index"); Node[] arr; foreach (i; 0..m) { int cnt = 0; foreach (j; 0..n) { if (x[i] > a[j]) { continue; } if (y[i] < b[j]) { continue; } ++cnt; } arr ~= Node(cnt, i + 1); } auto val = arr.reduce!max; if (val.count) { foreach (w; arr.filter!(a => a.count == val.count)) { writeln = w.index; } } else { 0.writeln; } }