import sys readline=sys.stdin.readline def Bisect_Int(ok,ng,is_ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok import numpy as np N=int(readline()) K,L,D=[],[],[] for _ in range(N): k,l,d=map(int,readline().split()) K.append(k) L.append(l) D.append(d) K=np.array(K,dtype=np.int32) L=np.array(L,dtype=np.int32) D=np.array(D,dtype=np.int32) def is_ok(ans): where=np.where(ans>=L)[0] return np.sum(np.minimum(K[where],(ans-L[where]>>D[where])+1)%2)%2 ans=Bisect_Int(1<<60,-1,is_ok) print(ans)