import algorithm, math, sequtils, strutils let nm = stdin.readLine.split.map parseInt n = nm[0] m = nm[1] 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