// based on k.inaba's code in the D language using System; using System.Collections.Generic; using System.IO; public class BalanceTheTree { private static int[] ReadCase(StreamReader sr) { string[] s = sr.ReadLine().Split(' '); int n = int.Parse(s[0]); int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = int.Parse(s[i+1]); return a; } private static bool Solve(int[] a) { Stack stack = new Stack(); for(int i = a.Length - 1; i > 0; i--) { if(stack.Count == 0) stack.Push(a[i]); else { if(a[i] < stack.Peek()) { stack.Push(a[i]); continue; } if(a[i] > stack.Peek()) return false; a[i-1] += a[i]; stack.Pop(); } } return stack.Count == 0; } public static void Main() { using(StreamReader sr = new StreamReader("balance.in")) { int[] a; while((a = ReadCase(sr)).Length > 0) { Console.WriteLine(Solve(a) ? "yes" : "no"); } } } }