Balanced sequences P49052


Statement
 

pdf   zip

thehtml

Write a program to tell if a given sequence of integer numbers x1xn is balanced or not. Let m = ⌈ n/2 ⌉. In this problem, we say that a sequence is balanced if n ≤ 2, or if the left-hand half x1xm and the right-hand half xm+1xn 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 n, followed ny n integer numbers. You can assume 0 ≤ n ≤ 104.

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++