N=int(input()) A=list(map(int,input().split())) res=0 x=0 for i in range(N): while x