using System; using System.Collections.Generic; using System.Linq; namespace No90_2 { public class Program { public static void Main(string[] args) { var input = ReadList(Convert.ToInt32); var n = input[0]; var m = input[1]; var score = new List[m]; for(var i = 0; i < m; i++) { score[i] = ReadList(Convert.ToInt32); } var stack = new Stack(); var max = 0; Action act = null; act = cnt => { for(var i = 0; i < n; i++) { if(!stack.Contains(i)) { stack.Push(i); } else { continue; } act(cnt + 1); stack.Pop(); } if(cnt == n) { var tmp = new int[m][]; for(var i = 0; i < m; i++){ tmp[i] = new int[3]; } for(var i = 0; i < m; i++){ score[i].CopyTo(tmp[i]); } var point = 0; foreach(var s in stack) { for(var i = 0; i < m; i++){ if(tmp[i][0] == s) point += tmp[i][2]; } for(var i = 0; i < m; i++){ if(tmp[i][1] == s) tmp[i][2] = 0; } } max = Math.Max(max, point); } }; act(0); foreach(var sc in score){ foreach(var s in sc){ Console.Write(s); } Console.WriteLine(); } Console.WriteLine(max); } public static List ReadList(Converter converter, char c = ' ') { return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter); } } }