import algorithm, math, sequtils, strutils var n, m: int (n, m) = stdin.readLine.split.map parseInt let inputs = (0 ..< m).mapIt stdin.readLine.split.map parseInt var g = n.succ.newSeqWith newSeq[(int, int)](succ n) for v in inputs: g[v[0]].add (v[1], v[2]) proc fn(xs: seq[int]): int = result = 0 var points = 0.repeat n.succ for x in xs: result += points[x] for (b, p) in g[x]: points[b] += p var xs = (0 ..< n).toSeq maximum = fn xs while nextPermutation xs: maximum = xs.fn.max maximum echo maximum