input() W = set(map(int, input().split())) input() B = set(map(int, input().split())) w, b, cnt = 1, 1, 0 for x in sorted(list(W|B)): if x in W&B: cnt += 1 w, b = b, w elif b*x in W: cnt += 1 w, b = 1, 0 elif w*x in B: cnt += 1 w, b = 0, 1 print(cnt)