PDP-27 (2015) - Camp seniors - 2 (maxzero)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

MAXZERO

You are given a sequence of N integers A_1, A_2, ..., A_N. 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 N, the length of the sequence. The second line of input contains the N integers A_i 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

1 \le N \le 1.000.000
|A_i| \le 1.000
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 92, -115, 17, 2, 2, 2, which has a length of 6.


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

There are no comments at the moment.