import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } public void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long[] K = new long[N]; long[] L = new long[N]; long[] D = new long[N]; for (int i = 0; i < N; ++i) { K[i] = Long.parseLong(sc.next()); L[i] = Long.parseLong(sc.next()); D[i] = Long.parseLong(sc.next()); } long ok = (long) (1e18); long ng = -1; while (ok - ng > 1) { long m = (ok + ng) / 2; long s = 0; for (int i = 0; i < N; ++i) { long v = m - L[i]; if (v < 0) continue; v /= 1L << D[i]; v = Math.min(v, K[i] - 1); ++v; s = (s + v) % 2; } if (s == 1) { ok = m; } else { ng = m; } } System.out.println(ok); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }