#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 1000005;
int n;
pii a[MN * 2];
int fpow(int b, int p, int mod) {
if (!p) return 1;
int ret = fpow(b, p / 2, mod);
if (p & 1) return ret * ret % mod * b % mod;
return ret * ret % mod;
}
int32_t main() {
boost();
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i].f >> a[i].s;
for (int i = 0; i < MN; i++) {
if (a[i].s > a[i].f) {
int d = a[i].s - a[i].f;
a[i].s -= d;
a[i + n].s += d;
}
int d = a[i].f - a[i].s;
int tk = min(a[i].f / 2, (d + 1) / 2);
a[i].f -= tk * 2;
a[i + 1].f += tk;
if (a[i].s > a[i].f) {
int d = a[i].s - a[i].f;
a[i].s -= d;
a[i + n].s += d;
}
if (a[i].f > a[i].s) {
int d = a[i].f - a[i].s;
a[i].f -= d;
a[i + n].f += d;
}
}
int was = (1ll << n) - 1, sum = 0;
for (int i = 0; i < MN * 2; i++) {
assert(a[i].f >= 0 && a[i].s >= 0);
if (a[i].f != a[i].s) return 0 * printf("No\n");
sum += fpow(2, i, was) * (a[i].f - a[i].s) % was;
}
if (sum % was == 0) printf("Yes\n");
else printf("No\n");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
15956 KB |
Output is correct |
2 |
Correct |
251 ms |
15980 KB |
Output is correct |
3 |
Correct |
214 ms |
15988 KB |
Output is correct |
4 |
Correct |
218 ms |
15996 KB |
Output is correct |
5 |
Correct |
234 ms |
15984 KB |
Output is correct |
6 |
Correct |
221 ms |
15992 KB |
Output is correct |
7 |
Correct |
244 ms |
15988 KB |
Output is correct |
8 |
Correct |
215 ms |
15988 KB |
Output is correct |
9 |
Correct |
217 ms |
15984 KB |
Output is correct |
10 |
Correct |
235 ms |
15980 KB |
Output is correct |
11 |
Correct |
224 ms |
15968 KB |
Output is correct |
12 |
Correct |
107 ms |
15964 KB |
Output is correct |
13 |
Correct |
121 ms |
15960 KB |
Output is correct |
14 |
Correct |
118 ms |
15984 KB |
Output is correct |
15 |
Correct |
109 ms |
15976 KB |
Output is correct |
16 |
Correct |
106 ms |
15956 KB |
Output is correct |
17 |
Correct |
109 ms |
15960 KB |
Output is correct |
18 |
Correct |
243 ms |
15988 KB |
Output is correct |
19 |
Correct |
113 ms |
15976 KB |
Output is correct |
20 |
Correct |
107 ms |
15964 KB |
Output is correct |
21 |
Correct |
115 ms |
15968 KB |
Output is correct |
22 |
Correct |
113 ms |
15956 KB |
Output is correct |
23 |
Correct |
115 ms |
16068 KB |
Output is correct |
24 |
Correct |
223 ms |
15968 KB |
Output is correct |
25 |
Correct |
118 ms |
15972 KB |
Output is correct |
26 |
Correct |
113 ms |
15968 KB |
Output is correct |
27 |
Correct |
116 ms |
15972 KB |
Output is correct |
28 |
Correct |
237 ms |
15988 KB |
Output is correct |
29 |
Correct |
231 ms |
16008 KB |
Output is correct |
30 |
Correct |
118 ms |
15968 KB |
Output is correct |
31 |
Correct |
110 ms |
15972 KB |
Output is correct |
32 |
Correct |
242 ms |
16096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
15956 KB |
Output is correct |
2 |
Correct |
251 ms |
15980 KB |
Output is correct |
3 |
Correct |
214 ms |
15988 KB |
Output is correct |
4 |
Correct |
218 ms |
15996 KB |
Output is correct |
5 |
Correct |
234 ms |
15984 KB |
Output is correct |
6 |
Correct |
221 ms |
15992 KB |
Output is correct |
7 |
Correct |
244 ms |
15988 KB |
Output is correct |
8 |
Correct |
215 ms |
15988 KB |
Output is correct |
9 |
Correct |
217 ms |
15984 KB |
Output is correct |
10 |
Correct |
235 ms |
15980 KB |
Output is correct |
11 |
Correct |
224 ms |
15968 KB |
Output is correct |
12 |
Correct |
107 ms |
15964 KB |
Output is correct |
13 |
Correct |
121 ms |
15960 KB |
Output is correct |
14 |
Correct |
118 ms |
15984 KB |
Output is correct |
15 |
Correct |
109 ms |
15976 KB |
Output is correct |
16 |
Correct |
106 ms |
15956 KB |
Output is correct |
17 |
Correct |
109 ms |
15960 KB |
Output is correct |
18 |
Correct |
243 ms |
15988 KB |
Output is correct |
19 |
Correct |
113 ms |
15976 KB |
Output is correct |
20 |
Correct |
107 ms |
15964 KB |
Output is correct |
21 |
Correct |
115 ms |
15968 KB |
Output is correct |
22 |
Correct |
113 ms |
15956 KB |
Output is correct |
23 |
Correct |
115 ms |
16068 KB |
Output is correct |
24 |
Correct |
223 ms |
15968 KB |
Output is correct |
25 |
Correct |
118 ms |
15972 KB |
Output is correct |
26 |
Correct |
113 ms |
15968 KB |
Output is correct |
27 |
Correct |
116 ms |
15972 KB |
Output is correct |
28 |
Correct |
237 ms |
15988 KB |
Output is correct |
29 |
Correct |
231 ms |
16008 KB |
Output is correct |
30 |
Correct |
118 ms |
15968 KB |
Output is correct |
31 |
Correct |
110 ms |
15972 KB |
Output is correct |
32 |
Correct |
242 ms |
16096 KB |
Output is correct |
33 |
Correct |
111 ms |
15956 KB |
Output is correct |
34 |
Correct |
233 ms |
15992 KB |
Output is correct |
35 |
Correct |
234 ms |
15976 KB |
Output is correct |
36 |
Incorrect |
114 ms |
16068 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
15956 KB |
Output is correct |
2 |
Correct |
251 ms |
15980 KB |
Output is correct |
3 |
Correct |
214 ms |
15988 KB |
Output is correct |
4 |
Correct |
218 ms |
15996 KB |
Output is correct |
5 |
Correct |
234 ms |
15984 KB |
Output is correct |
6 |
Correct |
221 ms |
15992 KB |
Output is correct |
7 |
Correct |
244 ms |
15988 KB |
Output is correct |
8 |
Correct |
215 ms |
15988 KB |
Output is correct |
9 |
Correct |
217 ms |
15984 KB |
Output is correct |
10 |
Correct |
235 ms |
15980 KB |
Output is correct |
11 |
Correct |
224 ms |
15968 KB |
Output is correct |
12 |
Correct |
107 ms |
15964 KB |
Output is correct |
13 |
Correct |
121 ms |
15960 KB |
Output is correct |
14 |
Correct |
118 ms |
15984 KB |
Output is correct |
15 |
Correct |
109 ms |
15976 KB |
Output is correct |
16 |
Correct |
106 ms |
15956 KB |
Output is correct |
17 |
Correct |
109 ms |
15960 KB |
Output is correct |
18 |
Correct |
243 ms |
15988 KB |
Output is correct |
19 |
Correct |
113 ms |
15976 KB |
Output is correct |
20 |
Correct |
107 ms |
15964 KB |
Output is correct |
21 |
Correct |
115 ms |
15968 KB |
Output is correct |
22 |
Correct |
113 ms |
15956 KB |
Output is correct |
23 |
Correct |
115 ms |
16068 KB |
Output is correct |
24 |
Correct |
223 ms |
15968 KB |
Output is correct |
25 |
Correct |
118 ms |
15972 KB |
Output is correct |
26 |
Correct |
113 ms |
15968 KB |
Output is correct |
27 |
Correct |
116 ms |
15972 KB |
Output is correct |
28 |
Correct |
237 ms |
15988 KB |
Output is correct |
29 |
Correct |
231 ms |
16008 KB |
Output is correct |
30 |
Correct |
118 ms |
15968 KB |
Output is correct |
31 |
Correct |
110 ms |
15972 KB |
Output is correct |
32 |
Correct |
242 ms |
16096 KB |
Output is correct |
33 |
Correct |
111 ms |
15956 KB |
Output is correct |
34 |
Correct |
233 ms |
15992 KB |
Output is correct |
35 |
Correct |
234 ms |
15976 KB |
Output is correct |
36 |
Incorrect |
114 ms |
16068 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |