import strutils, sequtils, math, sets, algorithm proc sorted[T](a: var seq[T]; cmp: proc (x, y: T): int {.closure.}; order = SortOrder.Ascending): seq[T] = result = a sort(result, cmp, order) var nw, nb: int w, b: seq[int] nw = stdin.readLine.parseInt w = stdin.readLine.split.map(parseInt) nb = stdin.readLine.parseInt b = stdin.readLine.split.map(parseInt) w = sorted(w, system.cmp[int]).reversed b = sorted(b, system.cmp[int]).reversed proc solve(a1:seq, a2:seq): int = var (a1, a2) = (a1, a2) result = 0 var check = high(int) var should1 = true for i in 0.. a1.high: if check > a1[i] and should1: should1 = false check = a1[i] result += 1 for j in 0.. a2.high: if check > a2[j] and not should1: should1 = true check = a2[j] result += 1 break var nya = solve(w, b) var mya = solve(b, w) echo max(nya, mya)