#C11955. Zero Sum Subarray

    ID: 41328 Type: Default 1000ms 256MiB

Zero Sum Subarray

Zero Sum Subarray

You are given an array of N integers. Your task is to determine whether there exists a contiguous subarray (i.e. a sequence of consecutive elements) whose sum is exactly zero.

Formally, given an array \(a_1, a_2, \dots, a_N\), determine if there exists indices \(i\) and \(j\) such that \(1 \le i \le j \le N\) and \[ a_i + a_{i+1} + \cdots + a_j = 0. \]

Output YES if such a subarray exists, otherwise output NO.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (N) representing the number of elements in the array. The second line contains (N) space-separated integers representing the elements of the array.

outputFormat

Output to standard output (stdout) a single string: YES if there is a contiguous subarray whose sum is zero, otherwise NO.## sample

5
1 2 -3 4 5
YES