import sugar, strutils, tables 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() proc main: void = let n, m = nextInt() var ans = 0 var items = lc[j | (j <- 0 ..< n), int] var scoreDic = initTable[tuple[item1, item2: int], int]() for i in 0 ..< m: scoreDic[(nextInt(), nextInt())] = nextInt() while true: var score = 0 for j in 0 ..< n: for i in 0 ..< j: let tmp = (items[i], items[j]) if tmp in scoreDic: score += scoreDic[tmp] ans = max(ans, score) if not items.nextPermutation: break echo ans when isMainModule: main()