#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define int lld
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef int64_t lld;
typedef pair<int, int> pii;
template<size_t MOD>
struct S{
static int mdu(int a){ return a < 0?a+MOD:a; }
static int mdd(int a){ return a>=MOD?a-MOD:a; }
static int invmod(int a, int b = MOD, int s0 = 0, int s1 = 1){
return b?invmod(b, a%b, mdu(s1-(lld)(a/b)*s0%MOD), s0):s1;
}
int f, s;
S(int a){ f = 0, s = a; }
S(int a, int b){ f = a, s = b; }
S operator+(S a){ return {mdd(f+a.f), mdd(s+a.s)}; }
S operator-(S a){ return {mdu(f-a.f), mdu(s-a.s)}; }
S operator/(int b){ return b = mdu(invmod(b)), S((lld)f*b%MOD, (lld)s*b%MOD); }
friend ostream& operator<<(ostream& out, S a){ return out << a.f << "x + " << a.s; }
int solve(){ return (lld)s*invmod(mdu(1-f))%MOD; }
};
const int md1 = 1000000007, md2 = 1000000009, md3 = 998244353;
vector<pii> v;
signed main(){
int n;
cin >> n;
S<md1> curgive1 = {1, 0};
S<md2> curgive2 = {1, 0};
S<md3> curgive3 = {1, 0};
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
v.pb({a, b});
curgive1 = (curgive1+a-b)/2;
curgive2 = (curgive2+a-b)/2;
curgive3 = (curgive3+a-b)/2;
//cout << curgive1 << endl << curgive2 << endl;
//cout << curgive1.solve() << " " << curgive2.solve() << endl;
}
if(curgive1.f == 1){
assert(curgive2.ff == 1 && curgive3.ff == 1);
}
if(curgive1.f == 1 && curgive2.f == 1 && curgive3.f == 1){
return cout << "Yes" << endl, 0;
}
lld ans;
if(curgive1.f == 1){
if(curgive2.f == 1 || curgive3.f == 1)return cout << "No" << endl, 0;
lld ans3 = curgive3.solve(), ans2 = curgive2.solve(); // a = ((lld)(ans2-ans1)*invmod(md1, md2)%md2+md2)%md2 (mod md2)
ans = (lld)S<md2>::mdu((ans2-ans3)*S<md2>::invmod(md3)%md2)*md3+ans3;
} else if(curgive2.f == 1) {
lld ans1 = curgive1.solve(), ans3 = curgive3.solve(); // a = ((lld)(ans2-ans1)*invmod(md1, md2)%md2+md2)%md2 (mod md2)
ans = (lld)S<md3>::mdu((ans3-ans1)*S<md3>::invmod(md1)%md3)*md1+ans1;
} else if(curgive3.f == 1)
return cout << "No" << endl, 0;
else {
lld ans1 = curgive1.solve(), ans2 = curgive2.solve(); // a = ((lld)(ans2-ans1)*invmod(md1, md2)%md2+md2)%md2 (mod md2)
ans = (lld)S<md2>::mdu((ans2-ans1)*S<md2>::invmod(md1)%md2)*md1+ans1;
}
//cout << ans << endl;
lld curgive = ans;
for(int i = 0; i < n; i++){
curgive = curgive + v[i].ff-v[i].ss;
if(curgive<0 || curgive&1)return cout << "No" << endl, 0;
curgive /= 2;
}
if(curgive == ans)cout << "Yes" << endl;
else cout << "No" << endl;
}
/*
5
0 0
1 0
2 3
3 3
4 0
*/
Compilation message
In file included from /usr/include/c++/9/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
from remittance.cpp:1:
remittance.cpp: In function 'int main()':
remittance.cpp:2:12: error: 'struct S<1000000009>' has no member named 'first'
2 | #define ff first
| ^~~~~
remittance.cpp:48:21: note: in expansion of macro 'ff'
48 | assert(curgive2.ff == 1 && curgive3.ff == 1);
| ^~
remittance.cpp:2:12: error: 'struct S<998244353>' has no member named 'first'
2 | #define ff first
| ^~~~~
remittance.cpp:48:41: note: in expansion of macro 'ff'
48 | assert(curgive2.ff == 1 && curgive3.ff == 1);
| ^~
remittance.cpp: In instantiation of 'static lld S<MOD>::mdd(lld) [with long unsigned int MOD = 1000000007; lld = long int]':
remittance.cpp:21:32: required from 'S<MOD> S<MOD>::operator+(S<MOD>) [with long unsigned int MOD = 1000000007]'
remittance.cpp:41:26: required from here
remittance.cpp:14:34: warning: comparison of integer expressions of different signedness: 'lld' {aka 'long int'} and 'long unsigned int' [-Wsign-compare]
14 | static int mdd(int a){ return a>=MOD?a-MOD:a; }
| ~^~~~~
remittance.cpp: In instantiation of 'static lld S<MOD>::mdd(lld) [with long unsigned int MOD = 1000000009; lld = long int]':
remittance.cpp:21:32: required from 'S<MOD> S<MOD>::operator+(S<MOD>) [with long unsigned int MOD = 1000000009]'
remittance.cpp:42:26: required from here
remittance.cpp:14:34: warning: comparison of integer expressions of different signedness: 'lld' {aka 'long int'} and 'long unsigned int' [-Wsign-compare]
remittance.cpp: In instantiation of 'static lld S<MOD>::mdd(lld) [with long unsigned int MOD = 998244353; lld = long int]':
remittance.cpp:21:32: required from 'S<MOD> S<MOD>::operator+(S<MOD>) [with long unsigned int MOD = 998244353]'
remittance.cpp:43:26: required from here
remittance.cpp:14:34: warning: comparison of integer expressions of different signedness: 'lld' {aka 'long int'} and 'long unsigned int' [-Wsign-compare]