def balance(transactions)
array = transactions.split(/\s+/).map(&:to_i)
sum_left, sum_right, ans = 0, array.reduce(:+), []
array.each_index do |i|
sum_left += array[i - 1] if i > 0
sum_right -= array[i]
ans.push(i) if sum_left == sum_right
end
ans
end
if __FILE__ == $0
DATA.each_line { |transactions| puts balance(transactions).join(' ') }
end
__END__
0 -3 5 -4 -2 3 1 0
3 -2 2 0 3 4 -6 3 5 -4 8
9 0 -5 -4 1 4 -4 -9 0 -7 -1
9 -7 6 -8 3 -9 -5 3 -6 -8 5
ZGVmIGJhbGFuY2UodHJhbnNhY3Rpb25zKQogIGFycmF5ID0gdHJhbnNhY3Rpb25zLnNwbGl0KC9ccysvKS5tYXAoJjp0b19pKQogIHN1bV9sZWZ0LCBzdW1fcmlnaHQsIGFucyA9IDAsIGFycmF5LnJlZHVjZSg6KyksIFtdCiAgYXJyYXkuZWFjaF9pbmRleCBkbyB8aXwKICAgIHN1bV9sZWZ0ICs9IGFycmF5W2kgLSAxXSBpZiBpID4gMAogICAgc3VtX3JpZ2h0IC09IGFycmF5W2ldCiAgICBhbnMucHVzaChpKSBpZiBzdW1fbGVmdCA9PSBzdW1fcmlnaHQKICBlbmQKICBhbnMKZW5kCgppZiBfX0ZJTEVfXyA9PSAkMAogIERBVEEuZWFjaF9saW5lIHsgfHRyYW5zYWN0aW9uc3wgcHV0cyBiYWxhbmNlKHRyYW5zYWN0aW9ucykuam9pbignICcpIH0KZW5kCgpfX0VORF9fCjAgLTMgNSAtNCAtMiAzIDEgMAozIC0yIDIgMCAzIDQgLTYgMyA1IC00IDgKOSAwIC01IC00IDEgNCAtNCAtOSAwIC03IC0xCjkgLTcgNiAtOCAzIC05IC01IDMgLTYgLTggNQ==