n = int(input())
nums = [int(i) for i in input().split()]
res = [10**16, -1, -1, -1]

need = sum(nums) // 3
left = 0
right = 0
cur = 0

while res[3] == -1:
    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

    cur2 = 0
    right2 = right
    while cur2 != need and right2 != n:
        cur2 += nums[right2]
        right2 += 1

    if cur2 != need:
        cur -= nums[left]
        left += 1
    else:
        res[3] = right2 + 1 

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