using System.Linq; using System.Collections.Generic; using System; public class P { public int t { get; set; } public string s { get; set; } } public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); if (a.Sum() % n != 0) Console.WriteLine("No"); else getAns(n, a); } static void getAns(int n, int[] a) { var q = new Queue
(); q.Enqueue(new P { s = "", t = 0 }); while (q.Count() > 0) { var w = q.Dequeue(); if (w.t == n ) { if (check(w.s, n, a)) { Console.WriteLine("Yes"); return; } else continue; } for (int i = 0; i < 3; i++) { q.Enqueue(new P { s = w.s + i.ToString(), t = w.t + 1 }); } } Console.WriteLine("No"); } static bool check(string s, int n, int[] a) { var sum = new int[3]; for (int i = 0; i < n; i++) sum[s[i] - '0'] += a[i]; return (sum[0] == sum[1] && sum[1] == sum[2]); } }