#include int main(){ using namespace std; unsigned long N; cin >> N; vector, unsigned long>> r(N); for(auto&& i : r){ vector v{0, 0, 0}; cin >> v[0] >> v[1] >> v[2]; sort(v.begin(), v.end()); i.first.first = v[0]; i.first.second = v[1]; i.second = v[2]; } unsigned long ans{0}; vector> dp(1UL << N); const auto& enc = [](unsigned long x, unsigned long y) -> unsigned long { return x * 16777216 + y; }; for(unsigned long i{0}; i < N; ++i){ ans = max(ans, r[i].second); dp[1UL << i][enc(r[i].first.first, r[i].first.second)] = r[i].second; dp[1UL << i][enc(r[i].first.first, r[i].second)] = r[i].first.second; dp[1UL << i][enc(r[i].first.second, r[i].second)] = r[i].first.first; } const auto& chmax = [&ans](unsigned long& x, unsigned long a) -> unsigned long { ans = max(ans, a); return x = max(x, a); }; for(unsigned long j{1}; j < 1UL << N; ++j)for(const auto& [s, h] : dp[j])for(unsigned long i{0}; i < N; ++i)if(!((j >> i) & 1)){ unsigned long c{1UL << i}; const auto& [x, y] = make_pair(s / 16777216, s % 16777216); if(r[i].first.first <= x && r[i].first.second <= y)chmax(dp[j | c][enc(r[i].first.first, r[i].first.second)], h + r[i].second); if(r[i].first.first <= x && r[i].second <= y)chmax(dp[j | c][enc(r[i].first.first, r[i].second)], h + r[i].first.second); if(r[i].first.second <= x && r[i].second <= y)chmax(dp[j | c][enc(r[i].first.second, r[i].second)], h + r[i].first.first); } cout << ans << endl; return 0; }