#C10143. Subset Sum Zero

    ID: 39316 Type: Default 1000ms 256MiB

Subset Sum Zero

Subset Sum Zero

Given a list of integers, determine whether there exists a non-empty subset whose sum is zero. Formally, let \( S \) be any non-empty subset of the input integers. You need to check if \( \sum_{x \in S} x = 0 \). If such a subset exists, output YES; otherwise, output NO.

inputFormat

The input consists of two lines:

  • The first line contains an integer \( n \) denoting the number of integers.
  • The second line contains \( n \) space-separated integers.

outputFormat

Output a single line with YES if there exists a non-empty subset of the given integers that sums to zero; otherwise, output NO.

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

</p>