#K83652. Three Equal Sum Split

    ID: 36245 Type: Default 1000ms 256MiB

Three Equal Sum Split

Three Equal Sum Split

Given a row of coins, determine if it is possible to split the array into exactly three non-empty contiguous subarrays that each have the same sum. Formally, let (S) be the total sum of the coin values. If (S) is divisible by 3, then each part must sum to (\frac{S}{3}). Otherwise, the split is impossible. The subarrays must be contiguous and non-empty.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n) (the number of coins). The second line contains (n) space-separated integers representing the coin values.

outputFormat

Output a single line to standard output (stdout): print 'YES' if it is possible to split the array into three contiguous parts with equal sums, otherwise print 'NO'.## sample

6
4 1 3 2 2 3
YES