n = int(input())
nums = [int(i) for i in input().split()]
res = [10**16, -1, -1, -1]
only_ones = nums[0] in [0, 1]
 
prefix = [nums[0]]
for ind in range(1, n, 1):
    prefix.append(prefix[-1] + nums[ind])
    only_ones = only_ones and (nums[ind] in [0, 1])

need = prefix[-1] // 3
left = 0
right = 0
cur = 0

while cur != need:
    cur += nums[right]
    right += 1
    while cur > need:
        cur -= nums[left]
        left += 1

res[0] = 0
res[1] = left + 1
res[2] = right + 1

cur = 0
while cur != need:
    cur += nums[right]
    right += 1

res[3] = right + 1 

print(res[0])
print(*res[1:])