Balanced sequences P49052


Statement
 

pdf   zip

Write a program to tell if a given sequence of integer numbers x1xnx_1 \dots x_n is balanced or not. Let m=n/2m = \lceil n/2 \rceil. In this problem, we say that a sequence is balanced if n2n \le 2, or if the left-hand half x1xmx_1 \dots x_m and the right-hand half xm+1xnx_{m+1} \dots x_n have the same sum, and both are balanced.

For instance, the sequence 5 -3 2 0 -1 3 2 is balanced, because the sum of 5 -3 2 0 and the sum of -1 3 2 are 4, and it is easy to see that both sequences are balanced.

Input

Input consists of several cases. Every one begins with nn, followed ny nn integer numbers. You can assume 0n1040 \le n \le 10^4.

Output

For every case, print “yes” or “no” as required.

Public test cases
  • Input

    7  5 -3 2 0 -1 3 2
    0
    3  -1 -1 -2
    6  2 2 4 3 3 6
    

    Output

    yes
    yes
    yes
    no
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++