n = int(input())
str_digits = input().split()
digits = []
groups = [[], [], []]
sum = 0

for digit in str_digits:
    digits.append(int(digit))
    sum += int(digit)

def circle(digits, group, group_sum, sum, i, group_num):
    group.append(i)
    group_sum += digits[i]
    next_element = 0
    previous_element = 0
    digits_len = len(digits)

    if i+1 != digits_len:
        next_element = i+1
    else:
        next_element = 0

    if i-1 != -1:
        previous_element = i-1
    else:
        previous_element = digits_len-1

    if group_sum == sum:
        groups[group_num] = group
    elif digits[next_element]+digits[i] < sum and next_element not in group:
        circle(digits, group, group_sum, sum, next_element, group_num)
    else:
        circle(digits, group, group_sum, sum, previous_element, group_num)

sum /= 3

circle(digits, [], 0, sum, 0, 0)

for i in range(len(groups[0])):
    groups[0].sort()
    digits.pop(groups[0][i]-i)

circle(digits, [], 0, sum, 0, 1)

for i in range(len(groups[1])):
    groups[1].sort()
    digits.pop(groups[1][i]-i)

circle(digits, [], 0, sum, 0, 2)
results = []
print(0)

changed_group_one = False
for digit_index_one in groups[1]:
    for digit_index_two in groups[0]:
        if digit_index_one >= digit_index_two:
            if changed_group_one == False:
                changed_group_one = True
                for i in range(len(groups[1])):
                    groups[1][i] += 1

changed_group_two = False
for digit_index_one in groups[2]:
    for digit_index_two in groups[1]:
        if digit_index_one >= digit_index_two:
            if changed_group_two == False:
                changed_group_two = True
                for i in range(len(groups[2])):
                    groups[2][i] += 2

results.append(min(groups[0])+1)
results.append(min(groups[1])+1)
results.append(min(groups[2])+1)
results.sort()
outcome = ""

for i in range(len(results)):
    outcome += str(results[i])
    if i != len(results)-1:
        outcome += " "

print(outcome)