import sugar, strutils from algorithm import nextPermutation proc nextString: string = result = "" while not endOfFile stdin: let nextChar = readChar stdin case nextChar of '\r': discard of "\n"[0], ' ': break else: add result, nextChar proc nextInt: int = parseInt nextString() let n, m = nextInt() var scoreList = newSeq[tuple[item1, item2, score: int]](m) ans = 0 proc main: void = for i in 0 ..< m: scoreList[i] = (nextInt(), nextInt(), nextInt()) var items = lc[j | (j <- 0 ..< n), int] while true: var score = 0 for i in 0 ..< m: if items[scoreList[i].item1] < items[scoreList[i].item2]: score += scoreList[i].score ans = max(ans, score) if not items.nextPermutation: break echo ans when isMainModule: main()