#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(readline()) KLD = np.array(read().split(), np.int64) K = KLD[::3] L = KLD[1::3] D = KLD[2::3] D2 = 1 << D def test(x): # x 以下が奇数個ある return np.minimum(K, np.maximum(0, (x - L) // D2 + 1)).sum() % 2 == 1 left = -1 right = 10 ** 18 + 10 while left + 1 < right: x = (left + right) // 2 if test(x): right = x else: left = x print(right)