#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define ar array
const int M = 1e6;
const int N = 26e4 + 20;
const int LOG = 31;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;
inline void mm(int &x){x = (x % MOD + MOD) % MOD;}
inline void chmin(int &x, int y){x = min(x, y);}
inline void chmax(int &x, int y){x = max(x, y);}
#pragma GCC optimize("unroll-loops,O3")
void orz(){
    int n;
    cin>>n;
    int A[n], B[n];
    int sum = 0;
    for(int i = 0;i < n;i++)cin>>A[i]>>B[i], sum += B[i];
    if(sum == 0){
        for(int i = 0;i < n;i++){
            if(A[i] != B[i]){
                cout<<"No";
                return;
            }
        }
        cout<<"Yes";
        return;
    }
    bool f = 1;
    while(f){
        f = 0;
        for(int i = 0;i < n;i++){
            if(A[i] > B[i]){
                f = 1;
                int j = (i + 1) % n;
                int x = (A[i] - B[i] + 1) / 2;
                A[j] += x;
                A[i] -= x * 2;
            }
        }
    }
    for(int i = 0;i < n;i++){
        if(A[i] != B[i]){
            cout<<"No";
            return;
        }
    }
    cout<<"Yes";
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
   
    int t = 1;
    //cin>>t;
    while(t--)orz();
} 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |