ALGOR Opening Contest: Round #1
Problem F · 250 points ·
ICPC rules
~/algor $ cat contests/round-1/F
F. Zero-sum subarray
1500 ms
256 MB
A positive integer $N$ and an array of $N$ integers are given. Find the length of the longest contiguous subarray whose elements sum to $0$ (if there is no such subarray, print $0$):
$$\sum_{i=L}^{R} A_{i} = 0$$
Input
The first line contains one integer: $N$. The second line contains $N$ integers $A_{i}$ separated by spaces.
Output
One integer — the length of the longest subarray with sum $0$, or $0$.
Note
$1 \le N \le 2 * 10^{5}$
$-10^{9} \le A_{i} \le 10^{9}$
Examples
Input #1
6 1 2 -3 4 -4 5
Output #1
5
Input #2
4 5 -2 3 1
Output #2
0