from itertools import groupby N = int(input()) ans = N*(N+1)//2 for v, g in groupby(map(int, input().split())): ans -= (l:=len([*g]))*(l+1)//2*v print(ans)