func main() var n: int :: cui@inputInt() var m: int :: cui@inputInt() var a: [][]int :: #[n, n]int for(1, m) var x: int :: cui@inputInt() var y: int :: cui@inputInt() do a[x][y] :: cui@inputInt() end for var idxs: []int :: #[n]int for i(0, n - 1) do idxs[i] :: i end for var ans: int :: 0 while(nextPermutation(idxs), skip) var score: int :: 0 for i(0, n - 1) for j(i + 1, n - 1) do score :+ a[idxs[i]][idxs[j]] end for end for do ans :: [ans, score].max() end while do cui@print("\{ans}\n") func nextPermutation(arr: []int): bool var len: int :: ^arr var left: int :: len - 2 while(left >= 0 & arr[left] >= arr[left + 1]) do left :- 1 end while if(left < 0) ret false end if var right: int :: len - 1 while(arr[left] >= arr[right]) do right :- 1 end while var tmp: int :: arr[left] do arr[left] :: arr[right] do arr[right] :: tmp do left :+ 1 do right :: len - 1 while(left < right) do tmp :: arr[left] do arr[left] :: arr[right] do arr[right] :: tmp do left :+ 1 do right :- 1 end while ret true end func end func