N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) X=0 l=r=0 while labs(B[r]-B[l]): r+=1 else: break d=r-l X+=d*(d-1)//2 l=r print(X)