import sys def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = II() kk, ll, dd = [], [], [] mx = 0 for _ in range(n): k, l, d = LI() kk.append(k) ll.append(l) dd.append(d) mx = max(mx, l+(k-1)*2**d) def binary_search(l, r, ok, minimize): if minimize: l -= 1 else: r += 1 while l+1 < r: m = (l+r)//2 if ok(m) ^ minimize: l = m else: r = m if minimize: return r return l def ok(m): cnt = 0 for k, l, d in zip(kk, ll, dd): cnt += max(0, (m-l)//(1 << d)+1) return cnt & 1 ans = binary_search(0, mx, ok, True) print(ans)