n = int(input()) S = list(map(int, input().split())) T = list(map(int, input().split())) ds = [set() for i in range(3)] dt = [set() for i in range(3)] for i, s in enumerate(S): ds[s].add(i) for i, t in enumerate(T): dt[t].add(i) A = [[0]*n for _ in range(n)] for i in ds[2]: for j in range(n): A[i][j] = 1 for j in dt[2]: for i in range(n): A[i][j] = 1 for i in ds[1]: cnt = 0 for j in range(n): if A[i][j] == 1: cnt += 1 if cnt == 0: for j in range(n): if j not in dt[0] and j in dt[1]: A[i][j] = 1 dt[1].remove(j) break for j in dt[1]: cnt = 0 for i in range(n): if A[i][j] == 1: cnt += 1 if cnt == 0: for i in range(n): if i not in ds[0] and ds[1]: A[i][j] = 1 ds[1].remove(i) break #print(A) ans = 0 for i in range(n): for j in range(n): ans += A[i][j] print(ans)