n=int(input()) a=list(map(int,input().split())) l=[0]*(n+1) for i in range(len(a)) : if l[a[i]] == 0 : l[a[i]]=i else: l[a[i]]=i-l[a[i]] o=0 for i in l : o+=i print(o)