#C6973. Subset Sum Zero

    ID: 50792 Type: Default 1000ms 256MiB

Subset Sum Zero

Subset Sum Zero

Given a list of n integers, determine whether there exists a non-empty subset whose elements sum up to zero. More formally, given a sequence \(a_1, a_2, \dots, a_n\), you are to decide if there exists a non-empty set \(I \subseteq \{1,2,...,n\}\) such that \(\sum_{i\in I} a_i = 0\).

The input will be provided via standard input and your program should output the result to standard output. If such a subset exists, print YES; otherwise, print NO.

inputFormat

The first line contains an integer n indicating the number of integers in the list. The second line contains n space-separated integers.

Example:

5
2 -3 7 -4 1

outputFormat

Output a single line containing YES if there is a non-empty subset of the given integers whose sum equals zero, or NO if no such subset exists.

Example output for the input above:

YES
## sample
5
2 -3 7 -4 1
YES