#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int N = 1e6+5;
const int block = 650;
int n,a[N],b[N];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	for(int i = 0; i < 30; i++){
		for(int j = 1; j <= n; j++){
			if(a[j] > b[j]+1){
				int x = a[j]-b[j];
				if(x % 2 == 1 && x+1 <= a[j]) x++;
				x /= 2;
				a[j] -= 2*x;
				a[(j+1) % n] += x;
			}
		}
	}
	for(int i = 1; i <= n; i++){
		if(a[i] != b[i]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |