#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; V k(n), l(n), d(n); for (int i = 0; i < n; ++i) cin >> k[i] >> l[i] >> d[i]; auto chk = [&](lint x) -> bool { lint s = 0; for (int i = 0; i < n; ++i) { s += max(min(l[i] + (k[i] << d[i]), x + 1) - l[i], 0LL) + ~(~0LL << d[i]) >> d[i]; } return s & 1; }; for (int i = 1; i <= 10; ++i) { cerr << i << ' ' << chk(i) << '\n'; } lint ng = 0, ok = 1e18; while (ok - ng > 1) { lint mid = ng + ok >> 1; (chk(mid) ? ok : ng) = mid; } cout << ok << '\n'; }