MAXZERO
You are given a sequence of N integers . Write a program to find the length of the longest continuous segment of this sequence, where the sum of the elements is zero.
Input
The first line of input contains a single natural number , the length of the sequence. The second line of input contains the integers of the sequence, separated in pairs by a single space.
Output
The output should consist of a single line containing exactly one natural number: the desired length of the longest continuous segment with a zero sum.
Constraints
Time Limit: 1 sec.
Maximum Available Memory: 64 MB
Example of Input - Output
1st
STDIN (maxzero.in)
16
25 -35 12 6 92 -115 17 2 2 2 -7 2 -9 16 2 -11
STDOUT (mazero.out)
6
Explanation of the first example: In the first example, the longest continuous segment of the sequence with a zero sum is , , , , , , which has a length of .
2nd
STDIN (maxzero.in)
6
8 -12 3 7 -13 4
STDOUT (mazero.out)
0
Explanation of the second example: In the second example, there is no non-empty segment of the sequence with a zero sum.
Comments