n = int(input())
a=list(map(int,input().split()))
l,t,sm=0,0,0
while(sm!=sum(a)//3 and t<n):
    if(sm<sum(a)//3):
        sm+=a[t]
        t+=1
    else:
        sm-=a[l]
        l+=1
sm2=0
t2=t
while(sm2<sum(a)//3):
    sm2+=a[t2%n]
    t2=(t2+1)%n
    '''
print(max(sm,sm2,sum(a)-sm-sm2)-min(sm,sm2,sum(a)-sm-sm2))
print(l+1,t+1,t2+1)
'''