#K54967. Zero Sum Contiguous Subsequence
Zero Sum Contiguous Subsequence
Zero Sum Contiguous Subsequence
You are given an array of integers of length \(n\). Your task is to determine whether there exists a non-empty contiguous subsequence (subarray) whose sum is \(0\).
In other words, given an array \(a\) of length \(n\), check if there exist indices \(l\) and \(r\) such that \(1 \le l \le r \le n\) and
\(\sum_{i=l}^{r}a_i=0\)
If such a subsequence exists, output YES; otherwise, output NO.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single line containing YES if there exists a non-empty contiguous subsequence whose sum is 0. Otherwise, output NO.
## sample5
4 -1 2 -3 1
YES