local n, m = io.read("*n", "*n") local scores = {} for i = 1, n do scores[i] = {} end for i = 1, m do local a, b, c = io.read("*n", "*n", "*n") scores[a + 1][b + 1] = c end local tot = 1 for i = 2, n do tot = tot * i end local function getpattern(n, patall, idx) local used = {} local retary = {} local div = patall for i = 1, n do used[i] = false end for i = n, 1, -1 do div = math.floor(div / i) local v_idx = math.floor(idx / div) idx = idx % div local tmp_idx = 0 for j = 1, n do if(not used[j]) then if(tmp_idx == v_idx) then table.insert(retary, j) used[j] = true break else tmp_idx = tmp_idx + 1 end end end end return retary end local highsc = 0 local mma = math.max for i = 0, tot - 1 do local tbl = getpattern(n, tot, i) local sc = 0 for j = 1, n - 1 do for k = j + 1, n do if(scores[tbl[j]][tbl[k]] ~= nil) then sc = sc + scores[tbl[j]][tbl[k]] end end end highsc = mma(highsc, sc) end print(highsc)