#C8218. Partition Array with Perfect Square Product
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
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
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.
## sample4
1 2 3 4
YES