#include #include #include typedef long long ll; #define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i)) #define rep(i,n) REP(i,0,n) using namespace std; int main(){ //std::ios::sync_with_stdio(false);std::cin.tie(0); int N; scanf("%d",&N); vector K(N), L(N); vector D(N); rep(i, N) scanf("%lld%lld%d",&K[i],&L[i],&D[i]); ll lb = -1, ub = (ll)1e18+10; while(ub-lb>1){ ll md = (lb+ub+1)/2; int x = 0; rep(i, N){ ll t = md-L[i]; if(t<0) continue; t >>= D[i]; t = min(t, K[i]-1); if(t%2==0) x = !x; } (x==1?ub:lb)=md; } cout<