#include #define llint long long using namespace std; llint n; llint k[300005], l[300005], d[300005]; bool check(llint x) { llint ret = 0; for(int i = 1; i <= n; i++){ if(x-l[i] < 0) continue; llint cnt = (x-l[i])/(1LL< k[i]) cnt = k[i]; ret += cnt; } return ret % 2; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> k[i] >> l[i] >> d[i]; llint ub = 1e18+5, lb = -1, mid; while(ub-lb>1){ mid=(ub+lb)/2; if(check(mid)) ub = mid; else lb = mid; } cout << ub << endl; return 0; }