import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } void run() { PriorityQueue pq = new PriorityQueue<>(new Comparator() { public int compare(long[] obj1, long[] obj2) { return Long.compare(obj1[1], obj2[1]); } }); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; ++i) { long K = sc.nextLong(); long L = sc.nextLong(); long D = sc.nextLong(); pq.add(new long[] { K, L, D }); } pq.add(new long[] { -1, Long.MAX_VALUE, Long.MAX_VALUE }); while (!pq.isEmpty()) { long[] o1 = pq.poll(); long[] o2 = pq.poll(); if (o1[1] != o2[1]) { System.out.println(o1[1]); return; } --o1[0]; --o2[0]; o1[1] += 1L << o1[2]; o2[1] += 1L << o2[2]; if (o1[0] > 0) pq.add(o1); if (o2[0] > 0) pq.add(o2); } } }