#C8218. Partition Array with Perfect Square Product

    ID: 52176 Type: Default 1000ms 256MiB

Partition Array with Perfect Square Product

Partition Array with Perfect Square Product

You are given an array A of n integers. Your task is to determine whether it is possible to split the array into two non-empty contiguous parts such that the product of the sums of these two parts is a perfect square.

Formally, let the two parts be defined by an index i such that 1 \le i \le n-1. Let

$$S_1 = \sum_{j=1}^{i} A_j, \quad S_2 = \sum_{j=i+1}^{n} A_j. $$

You need to check if there exists an index i for which the product S1 \times S2 is a perfect square, i.e., there exists an integer k such that

k2=S1×S2.k^2 = S_1 \times S_2.

If such a partition exists, output YES, otherwise output NO.

inputFormat

The input is given from standard input and consists of two lines:

  • The first line contains a single integer n (the number of elements in the array).
  • The second line contains n space-separated integers representing the elements of the array A.

outputFormat

Print a single line with the answer: YES if there exists a partition that satisfies the condition, or NO otherwise.

## sample
4
1 2 3 4
YES