using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input4"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("5"); WillReturn.Add("1 2 3"); WillReturn.Add("4 5 6"); WillReturn.Add("7 8 9"); WillReturn.Add("10 1 2"); WillReturn.Add("3 4 5"); } else if (InputPattern == "Input2") { WillReturn.Add("3"); WillReturn.Add("1 1 1"); WillReturn.Add("1 1 1"); WillReturn.Add("1 1 1"); } else if (InputPattern == "Input3") { WillReturn.Add("3"); WillReturn.Add("1 2 3"); WillReturn.Add("5 4 1"); WillReturn.Add("1 9 2"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); IEnumerable EnumItem = InputList.Skip(1).SelectMany(X => X.Split(' '), (X, Y) => int.Parse(Y)); int PowerUpCnt = 0; //アイテムごとのCountを求める var Query = EnumItem.GroupBy(X => X).Select(X => new { X.Key, cnt = X.Count() }); //同じアイテムが2つあればパワーアップ PowerUpCnt += Query.Sum(X => X.cnt / 2); //アイテムを4つ使ってパワーアップ PowerUpCnt += Query.Sum(X => X.cnt % 2) / 4; Console.WriteLine(PowerUpCnt); } }