#K54457. Split Array into Three Equal Sum Subarrays

    ID: 29757 Type: Default 1000ms 256MiB

Split Array into Three Equal Sum Subarrays

Split Array into Three Equal Sum Subarrays

Given an array of integers, determine whether it is possible to partition the array into three non-empty contiguous subarrays such that the sum of the elements in each subarray is equal. Formally, if the array is a with n elements, find indices i and j satisfying 0 < i < j < n such that

$$\sum_{k=0}^{i-1}a_k = \sum_{k=i}^{j-1}a_k = \sum_{k=j}^{n-1}a_k$$

If such a partition exists, output "Yes"; otherwise, output "No".

inputFormat

The first line contains a single integer n denoting the number of elements in the array.

The second line contains n space-separated integers representing the array elements.

outputFormat

Output a single line containing "Yes" if the array can be partitioned into three contiguous subarrays with equal sum, and "No" otherwise.

## sample
6
1 2 1 2 1 2
Yes