#include #include #include #include typedef int32_t i32; typedef int64_t i64; #define MIN(a,b) ((a) < (b) ? (a) : (b)) void run (void) { i32 n; scanf ("%" SCNi32, &n); i64 *k = (i64 *) calloc (3 * n, sizeof (i64)); i64 *a = k + n; i64 *d = a + n; for (i32 i = 0; i < n; ++i) { scanf ("%" SCNi64 "%" SCNi64 "%" SCNi64, k + i, a + i, d + i); d[i] = (i64) 1 << d[i]; } i64 l = -1; i64 r = 1000000000000000000LL; while (r - l > 1) { i64 m = (r + l) / 2; i64 cnt = 0; for (i32 i = 0; i < n; ++i) { if (a[i] > m) continue; cnt ^= MIN(k[i], 1 + (m - a[i]) / d[i]); } if (cnt % 2 == 1) { r = m; } else { l = m; } } printf ("%" PRIi64 "\n", r); } int main (void) { run(); return 0; }