N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) def syaku(a, b): l, r = a, a sm1, sm2 = 0, 0 res = 0 while lr: r = l return res s = -1 cnt = 0 ans = 0 for i in range(N): if B[i] == 0: if s==-1: s = i cnt = 1 else: cnt += 1 else: if cnt>0: ans += syaku(s, s+cnt) cnt = 0 s = -1 else: continue if cnt>0: ans += syaku(s, s+cnt) print(ans)