#include using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector K(n), L(n), D(n); for (int i = 0; i < n; i++) { cin >> K[i] >> L[i] >> D[i]; } ll ok = 1000000000000000000LL, ng = -1; while (ok - ng > 1) { ll mid = (ok + ng) / 2; ll cnt = 0; for (int i = 0; i < n; i++) { if (mid < L[i]) continue; (cnt += min((mid - L[i]) / (1LL << D[i]) + 1, K[i]) % 2) %= 2; } if (cnt == 0) ng = mid; else ok = mid; } cout << ok << endl; return 0; }