import std.algorithm, std.array, std.container, std.range; import std.string, std.conv, std.bigint, std.math, std.random; import std.stdio, std.typecons; alias Tuple!(int, "i1", int, "i2", int, "sc") row; void main() { auto rd = readln.split.map!(to!int); auto n = rd[0]; auto m = rd[1]; auto tbl = iota(m).map!((_) { auto rd = readln.split.map!(to!int); return row(rd[0], rd[1], rd[2]); }).array; auto max = 0; foreach (ai; iota(n).permutations) { auto r = calc(ai.array, tbl); if (r > max) max = r; } writeln(max); } int calc(int[] ai, row[] tbl) { return tbl.map!((row) { auto f1 = ai.find(row.i1); auto f2 = ai.find(row.i2); if (!f1.empty && !f2.empty && f1.length > f2.length) return row.sc; else return 0; }).sum; }