// {{{ Templates #include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; template constexpr T INF = numeric_limits::max() / 100; // }}} int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector front(M); vector back(M); vector score(M); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; front[i] = a; back[i] = b; score[i] = c; } vector index(N); ll patterns = 1; for (int i = 0; i < N; i++) { index[i] = i; patterns *= (i + 1); } int maxi = -INF; for (ll i = 0; i < patterns; i++) { int s = 0; for (ll j = 0; j < M; j++) { if (index[front[j]] < index[back[j]]) { s += score[j]; } } maxi = max(maxi, s); next_permutation(index.begin(), index.end()); } cout << maxi << endl; return 0; }