#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<long long> a(n), b(n), c(n); for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i] >> c[i]; } long long s = accumulate(begin(a), end(a), 0LL); assert(n <= 24); long long res = 0; for (int bt = 0; bt < 1 << n; bt += 2) { bool ok = true; for (int i = 1; i < n; ++i) { if (bt >> i & 1 and bt >> (i - 1) & 1) { ok = false; break; } } if (not ok) { continue; } long long sw = 0, sv = 0; for (int i = 0; i < n; ++i) { if (bt >> i & 1) { sw += a[i - 1] + a[i] + c[i]; sv += b[i]; } } if (sw <= s) { res = max(res, sv); } } cout << res << '\n'; }