#yuki929 n=int(raw_input()) p=map(int,raw_input().split()) f=0 res=0 for x in p: f+=x-1 res+=abs(f) print res