import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) A=[int(i) for i in input().split()] ans=0 cur=A[0] for i in range(1,n): if A[i]