using System; using System.Collections.Generic; using System.Linq; // https://yukicoder.me/problems/no/1594 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("5"); WillReturn.Add("1 2 3 4 5"); } else if (InputPattern == "Input2") { WillReturn.Add("7"); WillReturn.Add("3 1 4 1 5 9 2"); } else if (InputPattern == "Input3") { WillReturn.Add("9"); WillReturn.Add("729 756 767 778 792 804 816 831 855"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); long[] EArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray(); long UB = EArr.GetUpperBound(0); var Stk = new Stack(); JyoutaiDef WillPush; WillPush.ValList = new List(); WillPush.CurrInd = 0; Stk.Push(WillPush); while (Stk.Count > 0) { JyoutaiDef Popped = Stk.Pop(); int CurrInd = Popped.CurrInd; if (CurrInd > UB) { if (Popped.ValList.Count == 3) { if (Popped.ValList.Distinct().Count() == 1) { Console.WriteLine("Yes"); return; } } continue; } // 枝切り if (Popped.ValList.Count >= 2) { if (Popped.ValList[0] < Popped.ValList[1]) { continue; } } // Listの要素に足し算する場合 for (int I = 0; I <= Popped.ValList.Count - 1; I++) { WillPush.ValList = new List(Popped.ValList); WillPush.ValList[I] = Popped.ValList[I] + EArr[CurrInd]; WillPush.CurrInd = CurrInd + 1; Stk.Push(WillPush); } // ListにAddする場合 WillPush.ValList = new List(Popped.ValList); WillPush.ValList.Add(EArr[CurrInd]); WillPush.CurrInd = CurrInd + 1; Stk.Push(WillPush); } Console.WriteLine("No"); } struct JyoutaiDef { internal List ValList; internal int CurrInd; } }