def main(): N=int(input()) p=[int(s)-1 for s in input().split()] d=m=0 for i in range(N): d+=p[i] m+=abs(d) print(m) main()