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.int64) L=np.array(L,dtype=np.int64) D=np.array(D,dtype=np.int64) def is_ok(ans): cnt=0 return np.sum(np.minimum(K,(ans-L>>D)+1)&1)&1 ans=Bisect_Int(1<<60,-1,is_ok) print(ans)