This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define F first
#define S second
#define pb push_back
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
int const MOD = 1e9 + 7;
int const N = 500009;
void solve() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  if (all_of(all(b), [](ll x) { return x == 0; })) {
    if (all_of(all(a), [](ll x) { return x == 0; })) {
      cout << "Yes\n";
    } else cout << "No\n";
    return;
  }
  while (true) {
    bool rep = false;
    for (int i = 0; i < n; ++i) {
      if (a[i] > b[i]) {
        ll diff = (a[i] - b[i] + 1) / 2;
        a[i] -= 2 * diff;
        a[(i+1) % n] += diff;
        rep = true;
      }
    }
    if ([&]{
      for (int i = 0; i < n; ++i) {
        if (a[i] != b[i]) return false;
      }
      return true;
    }()) {
      cout << "Yes\n";
      return;
    }
    if (!rep) {
      cout << "No\n";
      return;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |