#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 1e6 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e7 + 100;
const ll MOD = 1e9 + 7;
const int maxl = 16;
const ll P = 31;
int n;
ll a[maxn];
ll b[maxn];
ll d[maxn];
ll c[maxn];
void test(){
cin >> n;
ll sum = 0, ok = 1;
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
sum += b[i];
ok &= a[i] == b[i];
} a[n] = a[0]; b[n] = b[0];
if(ok){
cout << "Yes\n";
return;
} if(!sum){
cout << "No\n";
return;
}
for(int i = 0; i < n; i++){
if(1 & (a[i+1] ^ b[i+1])) c[i] = 1;
} c[n] = c[0];
for(int k = 1; k < 50; k++){
for(int i = 0; i < n; i++){
if(((c[i] + a[i+1] - b[i+1])>>(k)&1) != (c[i+1]>>(k-1)&1)){
c[i] |= (1ll<<k);
}
} c[n] = c[0];
} for(int i = 1; i <= n; i++){
if(a[i] - c[i] * 2 + c[i-1] != b[i]){
// cout << a[i] << ' ' << b[i] << ' ' << c[i] << ' ' << c[i-1] << endl;
cout << "No\n";
return;
}
} cout << "Yes\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; t = 1;
while(t--) test();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |