#K40817. Equal Sum Partition of Array

    ID: 26727 Type: Default 1000ms 256MiB

Equal Sum Partition of Array

Equal Sum Partition of Array

Given an array of n integers, determine whether it is possible to partition the array into two non-empty consecutive subarrays such that the sum of the elements in the left subarray is equal to the sum of the elements in the right subarray.

Formally, if the array is denoted as \(a_1, a_2, \ldots, a_n\), you need to check if there exists an index \(i\) (with \(1 \le i < n\)) such that:

\(\sum_{j=1}^{i} a_j = \sum_{j=i+1}^{n} a_j\)

Note that the partition point cannot be the very first element or the very last element. If such an index exists, output YES; otherwise, output NO.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  1. The first line contains a single integer \(n\) (\(2 \le n \le 10^5\)), representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) (each \(|a_i| \leq 10^9\)).

outputFormat

Output a single line to standard output (stdout) containing YES if there exists a valid partition point, and NO otherwise.

## sample
4
2 4 2 4
YES