#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()

const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const long long LINF = 1LL << 60;
const double PI = 3.141592653589793;
const int NIL = -1;
const int MAX = 1100000;
const int LARGE = 10000;

double X, Y, R;
ll XX, YY, RR;

bool inside(ll x, ll y) {
    x *= LARGE; y *= LARGE;
    return (x - XX) * (x - XX) + (y - YY) * (y - YY) <= RR * RR;
}

ll calc_lower(ll x) {
    ll ok = floor(Y);
    ll er = ok - floor(R) - 10;
    if (!inside(x, ok)) return 0;
    while(abs(ok - er) > 1) {
        ll mid = (ok + er) / 2;
        if (inside(x, mid)) ok = mid;
        else er = mid;
    }
    return floor(Y) - er;
}

ll calc_upper(ll x) {
    ll ok = floor(Y) + 1;
    ll er = ok + floor(R) + 10;
    if (!inside(x, ok)) return 0;
    while(abs(ok - er) > 1) {
        ll mid = (ok + er) / 2;
        if (inside(x, mid)) ok = mid;
        else er = mid;
    }
    return er - (floor(Y) + 1);
}

int main() {
    cin >> X >> Y >> R;
    XX = (ll) round(X * LARGE);
    YY = (ll) round(Y * LARGE);
    RR = (ll) round(R * LARGE);

    ll ans = 0;
    for (ll x = floor(X - R - 10); x < floor(X + R + 10); x++) {
        ans += calc_upper(x) + calc_lower(x);
    }
    cout << ans << endl;
}

#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#include <tuple>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000000; //10^18
typedef long long ll;
typedef unsigned long long ull;

/*ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
  }*/

int main(void) {
  ll n, a[100100];
  cin >> n;
  rep(i, n) cin >> a[i];

  ll x[100100][3], y[100100][3];

  if (n == 1) {
    cout << a[0] << endl;
    return 0;
  }

  x[1][1] = (a[0] + a[1]) % MOD;
  x[1][0] = (a[0] - a[1] + MOD) % MOD;
  y[1][1] = 1;
  y[1][0] = 1;

  for (int i = 2; i < n; i++) {
    y[i][1] = (y[i-1][1] + y[i-1][0])%MOD;
    y[i][0] = y[i-1][1];

    x[i][1] = (x[i-1][1] + a[i]*y[i-1][1]%MOD)%MOD;
    x[i][1] += (x[i-1][0] + a[i]*y[i-1][0]%MOD)%MOD;
    x[i][1] %= MOD;

    x[i][0] = (x[i-1][1] - a[i]*y[i-1][1]%MOD + MOD)%MOD;
  }
  //cout << y[n-2][0] << " " << y[n-2][1] << endl;

  cout << (x[n-1][0] + x[n-1][1])%MOD << endl;

  return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define int  ll
#define pb push_back
#define N  2003
#define f1 first
#define s2 second
#define PII pair<int,int>

using namespace std;
double dp[105][105][105];
int a,b,c,d,t;
string s;

double dpf(int a,int b,int c){
	if(a==100 || b==100 ||c==100 )
		return 0;
	if(dp[a][b][c]!=-1){
		return dp[a][b][c] ;
	}
	// cout<<((double)a/(double)(a+b+c)) <<endl;
	dp[a][b][c]=(dpf(a+1,b,c)+1)*((double)a/(double)(a+b+c));
	dp[a][b][c]+=(dpf(a,b+1,c)+1)*((double)b/(double)(a+b+c));
	dp[a][b][c]+=(dpf(a,b,c+1)+1)*((double)c/(double)(a+b+c));

	return dp[a][b][c];
}
int32_t main(){
	// freopen("a.gir","r",stdin);
	// freopen("a.cik","w",stdout);
	// scanf("%lld",&t);
	t=1;
	while(t--){
		for(int i=0;i<101;i++)
		for(int j=0;j<101;j++)
		for(int k=0;k<101;k++)
			dp[i][j][k]=-1;

		scanf("%lld %lld %lld",&a,&b,&c);
		printf("%.10lf\n",dpf(a,b,c) ); ;
	}

}

#include<bits/stdc++.h>
using namespace std;

int H, W, A, B;

bool used[16][16];

int dfs(int x, int y, int a) {
    if (H == y) return a == 0;

    if (W == x) return dfs(0, y + 1, a);

    if (used[y][x]) return dfs(x + 1, y, a);

    int res = 0;

    if (y + 1 < H && !used[y+1][x] && 0 < a) {
        used[y][x] = true;
        used[y+1][x] = true;
        res += dfs(x+1, y, a-1);
        used[y][x] = used[y+1][x] = false;
    }
    if (x + 1 < W && !used[y][x+1] && 0 < a) {
        used[y][x] = true;
        used[y][x+1] = true;
        res += dfs(x+1, y, a-1);
        used[y][x] = false;
        used[y][x+1] = false;
    }
    res += dfs(x+1, y, a);
    return res;
}

int main() {
    cin >> H >> W >> A >> B;
    cout << dfs(0, 0, A) << endl;
}


#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
#define int long long
#define ll long long
#define INF 1LL << 33
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define SHOW(p) \
    if (test)   \
        cout << #p " : " << p << endl;
//bool test = true;
bool test = false;
int H, W;
vector<string> s;
vector<pair<int, int>> gs, gs2;
vector<bool> col, row, col2, row2;
bool update()
{
    bool update_onece = false;
    bool update = true;
    while (update) {
        update = false;
        for (auto it = gs.begin(); it != gs.end();) {
            if (row.at(it->first)) {
                if (!col.at(it->second)) {
                    update = col.at(it->second) = true;
                    it = gs.erase(it);
                } else {
                    it++;
                }
            } else if (col.at(it->second)) {
                if (!row.at(it->first)) {
                    update = row.at(it->first) = true;
                    it = gs.erase(it);
                } else {
                    it++;
                }
            } else {
                it++;
            }
            if (test) {
                cout << it->first << ":" << it->second << endl;
            }
        }
        if (update) {
            update_onece = true;
        }
    }
    return update_onece;
}
bool update2()
{
    bool update_onece = false;
    bool update = true;
    while (update) {
        update = false;
        for (auto it = gs2.begin(); it != gs2.end();) {
            if (row2.at(it->first)) {
                if (!col2.at(it->second)) {
                    update = col2.at(it->second) = true;
                    it = gs2.erase(it);
                } else {
                    it++;
                }
            } else if (col2.at(it->second)) {
                if (!row2.at(it->first)) {
                    update = row2.at(it->first) = true;
                    it = gs2.erase(it);
                } else {
                    it++;
                }
            } else {
                it++;
            }
            if (test) {
                cout << it->first << ":" << it->second << endl;
            }
        }
        if (update) {
            update_onece = true;
        }
    }
    return update_onece;
}
signed main()
{
    cin >> H >> W;
    s.resize(H);
    col.resize(W, false);
    row.resize(H, false);
    row.at(0) = row.at(H - 1) = col.at(0) = col.at(W - 1) = true;
    REP(i, H)
    {
        cin >> s.at(i);
        REP(j, W)
        {
            if (s.at(i).at(j) == '#') {
                gs.push_back({i, j});
            }
        }
    }
    update();
    row2 = row;
    col2 = col;
    gs2 = gs;
    //cols
    int ans_c = 0;
    for (int x = 0; x < H; x++) {
        if (row.at(x)) {
            continue;
        }
        ans_c++;
        row.at(x) = true;
        update();
    }
    //cols
    int ans_r = 0;
    for (int x = 0; x < W; x++) {
        if (col2.at(x)) {
            continue;
        }
        ans_r++;
        col2.at(x) = true;
        update2();
    }
    if (ans_r > ans_c) {
        cout << ans_c << endl;
    } else {
        cout << ans_r << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define maxn 2086

using namespace std;

int n, m;
char s[maxn][maxn];

int fa[maxn], siz[maxn];

int find(int x){
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

set<int> st[2];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1;i <= n;i++) scanf("%s", s[i] + 1);
	for(int i = 1;i <= n + m;i++) fa[i] = i, siz[i] = 1;
	s[1][1] = s[n][1] = s[1][m] = s[n][m] = '#';
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(s[i][j] == '#'){
				int x = find(i), y = find(j + n);
				if(x == y) continue;
				if(siz[x] > siz[y]) swap(x, y);
				fa[x] = y, siz[y] += siz[x];
			}
		}
	}
	for(int i = 1;i <= n;i++) st[0].insert(find(i));
	for(int i = 1;i <= m;i++) st[1].insert(find(i + n));
	printf("%d", min(st[0].size(), st[1].size()) - 1);
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<double> x(N), y(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  double a;
  for (int i = 0; i < N - 1; i++) {
    set<double> c;
    for (int j = i + 1; j < N; j++) {
      if (x.at(j) == x.at(i)) {
        a = 1000000;
      }
      else {
        a = (y.at(j) - y.at(i)) / (x.at(j) - x.at(i));
      }
      if (c.count(a)) {
        cout << "Yes" << endl;
        return 0;
      }
      c.insert(a);
    }
  }
  cout << "No" << endl;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
lli gcd(lli a, lli b)
{
  while (b)
  {
    lli c = b;
    b = a % b;
    a = c;
  }
  return a;
}
//---------------------------------------------------------------------------------------------------
void solve()
{
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  pair<lli, lli> A, B, C;
  map<lli, lli> ma;
  map<lli, lli> ma2;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;

  lli x, y;
  double X[n];
  double Y[n];
  bool ff = false;
  rep(i, 0, n)
  {
    cin >> X[i] >> Y[i];
    // ma[x]++;
    // ma2[y]++;
    // pr.eb(mp(x, y));
    // d[i].pb(x);
    // d[i].pb(y);
    // X.pb(x);
    // Y.pb(y);
  }
  // for (auto z : ma)
  // {
  //   if (z.second >= 3)
  //   {
  //     out("Yes");
  //     return 0;
  //   }
  // }
  // for (auto z : ma2)
  // {
  //   if (z.second >= 3)
  //   {
  //     out("Yes");
  //     return 0;
  //   }
  // }
  rep(i, 0, n - 2)
  {
    rep(j, i + 1, n - 1)
    {
      rep(k, j + 1, n)
      {
        if ((Y[j] - Y[i]) * (X[k] - X[j]) == (Y[k] - Y[j]) * (X[j] - X[i]))
        {
          out("Yes");
          return 0;
        }
      }
    }
  }
  out("No");
}


#include<algorithm>
#include<cstdio>
#define ll long long
#define MaxN 200500
using namespace std;
const int mod=1000000007;
int n,a[MaxN];
int main()
{
  scanf("%d",&n);
  for (int i=1;i<=n;i++)scanf("%d",&a[i]);
  sort(a+1,a+n+1);
  ll ans=1;
  for (int i=1;i<=n;i++)
    ans=(ans*(a[i]-a[i-1]+1))%mod;
  printf("%lld",ans);
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define vi vector<int>
#define Go(i, x, v) for (int i = 0, x = (i == v.size() ? 0 : v[i]); i < v.size(); i++, x = (i == v.size() ? 0 : v[i]))
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define gc getchar
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
template <class T> void rd(T &x) {
  x = 0; char ch = gc(); int f = 1;
  for (; !isdigit(ch); ch = gc()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = gc()) x = (x << 1) + (x << 3) + ch - '0';
  x *= f;
}
template <class T> void cmin(T &x, T y) { x = min(x, y); }
template <class T> void cmax(T &x, T y) { x = max(x, y); }
const int mod = 1e9 + 7;
void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void Sub(int &x, int y) { x += mod - y; if (x >= mod) x -= mod; }
void Mul(int &x, int y) { x = (ll)x * y % mod; }
int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; }
int sub(int x, int y) { x += mod - y; if (x >= mod) x -= mod; return x; }
int mul(int x, int y) { return (ll)x * y % mod; }
int qpow(int a, int b) { int ret = 1; for (; b; b >>= 1, Mul(a, a)) if (b & 1) Mul(ret, a); return ret; }
/* ============ Header Template ============ */

const int N = 1e5 + 10;
int n, a[N], b[N], tot;

int main() {
  rd(n);
  rep(i, 1, n) {
    rd(a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  tot = unique(b + 1, b + n + 1) - b - 1;
  int ans = 1;
  rep(i, 1, tot) {
    Mul(ans, max(1, b[i] - b[i - 1] + 1));
  }
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

/* alias */
using ull = unsigned long long;
using ll = long long;
/* define short */
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

int main() {
    ll a,b,c;
    bool even;
    cin>>a>>b>>c;
    if(c%2==0){
        even = true;
    }else{
        even = false;
    }
    if(even){
        if(abs(a)<abs(b)){
            cout<<"<"<<endl;
        }else if(abs(a)==abs(b)){
            cout<<"="<<endl;
        }else{
            cout<<">"<<endl;
        }
        return 0;
    }
    if(a<b){
        cout<<"<"<<endl;
    }else if(a==b){
        cout<<"="<<endl;
    }else{
        cout<<">"<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

long long a, b, c;

int main() {
	cin >> a >> b >> c;
	c = c % 2 ? 1 : 2;
	if (c == 1) {
		if (a > b)
		    cout << '>';
		if (a < b)
		    cout << '<';
		if (a == b)
		    cout << '=';
	}
	else {
		a *= a;
		b *= b;
		if (a > b)
		    cout << '>';
		if (a < b)
		    cout << '<';
		if (a == b)
		    cout << '=';
	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecll = vector<ll>;
using matll = vector<vector<ll>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repitr(id, itr) for (auto& id : itr)
#define repr(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define reprs(i, a, b, s) for (ll i = ll(a); i < ll(b); i += s)
#define reprms(i, a, b, s) for (ll i = ll(a); i > ll(b); i += s)
#define repdic(key, val, dic) for (const auto& [key, val] : dic)
#define sort_all(v) sort(v.begin(), v.end())
#define min_val(v) *min_element(v.begin(), v.end())
#define max_val(v) *max_element(v.begin(), v.end())
#define max_idx(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define sum(v) accumulate(v.begin(), v.end(), 0LL)
#define all(v) v.begin(), v.end()
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
#define coutdeci cout << fixed << setprecision(15)

ll smallcmb(ll n, ll r) {
    if (r < 0 || n < r) return 0;
    r = min(r, n - r);
    ll res = 1;
    rep(i, r) {
        res *= n - r + 1 + i;
        res /= i + 1;
    }
    return res;
}

string S;

int main() {
    cin >> S;
    ll o = count(all(S), 'o'), x = count(all(S), 'x');
    ll ox = count(all(S), '?');

    ll ans = 0;
    rep(i, ox + 1) {
        ll cnt = i + o;
        if (cnt == 0 || cnt > 4)
            continue;
        else if (cnt == 1)
            ans += smallcmb(ox, i);
        else if (cnt == 2)
            ans += 14 * smallcmb(ox, i);
        else if (cnt == 3)
            ans += 36 * smallcmb(ox, i);
        else if (cnt == 4)
            ans += 24 * smallcmb(ox, i);
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 300000+10;

int lcm(int x, int y){
	int g = __gcd(x, y);
	return (x * y) / g;
}

int32_t main(){
    fast_io;
    int n;
    cin >> n;
    int ans = 1;
    fo(i, 2, n) ans = lcm(i, ans);
    ans++;
    show(ans);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

template<typename T>
int sgn(T val){
  return (T(0)<val)-(val<T(0));
}

tuple<long long,long long,long long> egcd(long long a,long long b){
  // (val,da,db) val==gcd(a,b) da*a+db*b=val
  if(a==0||b==0)return std::make_tuple(0LL,0LL,0LL);
  long long sa=sgn(a),sb=sgn(b);
  a=std::abs(a);b=std::abs(b);
  long long p=1,q=0,r=0,s=1;
  while(b>0){
    long long c=a/b;
    long long d;
    d=a;a=b;b=d%b;
    d=p;p=q;q=d-c*q;
    d=r;r=s;s=d-c*s;
  }
  return std::make_tuple(a,p*sa,r*sb);
}
long long inverse(long long a,long long m){
  using namespace std;
  assert(abs(gcd(a,m))==1LL);
  assert(a!=0);
  auto [val,da,dm]=egcd(a,m);
  return (da%m+m)%m;
}
int main(){
  cout<<setprecision(1000);
  ll T;
  cin>>T;
  For(times,T){
    ll X,Y,P,Q;
    cin>>X>>Y>>P>>Q;
    ll mod=P+Q;
    ll l=X%mod,r=(X+Y)%mod;
    ll s=2*(X+Y);
    ll g=gcd(s,mod);
    ll ans=LLONG_MAX;
    FOR(i,P,P+Q){
      For(jj,Y){
        ll j=(jj+X)%mod;
        if(s%mod==0&&j!=i)continue;
        if(s%mod==0&&j==i){
          chmin(ans,jj+X);
          continue;
        }
        ll k=(i-j+mod)%mod;
        if(k%g!=0){
          continue;
        }
        ll nmod=mod/g;
        ll ns=s/g%nmod;
        ll nk=k/g;
        ll tmpans=inverse(ns,nmod)*nk%nmod*s+X+jj;
        chmin(ans,tmpans);
      }
    }
    if(ans==LLONG_MAX){
      cout<<"infinity"<<endl;
    }else{
      cout<<ans<<endl;
    }
  }
  return 0;
}


#define MOD 1000000007
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#include <numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int64_t n;
	cin>>n;
	array < int64_t , 86 > fib;
	vector < int64_t > decomp,fin,ans;
	fib[0]=fib[1]=1;
	for(int i=2; i<fib.size(); ++i){
		fib[i]=fib[i-1]+fib[i-2];
	}
	for(int i=fib.size()-1; i>=0; --i){
		while(n>=fib[i]){
			n-=fib[i];
			decomp.push_back(i);
		}
	}
	reverse(decomp.begin(),decomp.end());
	ans.resize(decomp.back()+1);
	for(auto &i:decomp){
		++ans[ans.size()-1-i];
	}
	if(decomp.back()&1){
		for(int i=0; i<ans.size(); ++i){
			while(ans[i]--){
				fin.push_back(1+!(i&1));
			}
			fin.push_back(3+(i&1));
		}
	}
	else{
		for(int i=0; i<ans.size(); ++i){
			while(ans[i]--){
				fin.push_back(1+(i&1));
			}
			fin.push_back(3+!(i&1));
		}
	}
	fin.pop_back();
	cout<<fin.size()<<'\n';;
	for(int i=0; i<fin.size(); ++i){
		cout<<fin[i]<<'\n';
	}
}

#include <bits/stdc++.h>
using namespace std;

int main(){
    long long i,j,k,l,m,n,t,r,g,b1;
    long long a[200010],b[200010],c[200010];
    char ch;
    cin>>n;
    r=g=b1=0;
    for(i=0;i<2*n;i++) {
        cin>>k;
        getchar();
        ch=getchar();
        if (ch=='R') {
            a[r++]=k;
        }
        else if (ch=='G') {
            b[g++]=k;
        }
        else if (ch=='B') {
            c[b1++]=k;
        }
    }

    sort(a,a+r);
    sort(b,b+g);
    sort(c,c+b1);

    if (r%2==0&&g%2==0&&b1%2==0) {
        cout<<0;
    }
    else {
        i=j=0;
        m=1e16;
        while(i<g&&j<b1) {
            if (m>abs(b[i]-c[j])) m=abs(b[i]-c[j]);
            if (b[i]<c[j]) i++;
            else j++;
        }
        i=j=0;
        l=1e16;
        while(i<r&&j<b1) {
            if (l>abs(a[i]-c[j])) l=abs(a[i]-c[j]);
            if (a[i]<c[j]) i++;
            else j++;
        }
        i=j=0;
        k=1e16;
        while(i<r&&j<g) {
            if (k>abs(a[i]-b[j])) k=abs(a[i]-b[j]);
            if (a[i]<b[j]) i++;
            else j++;
        }

        if (r%2==0) {
            if (m>l+k) cout<<l+k;
            else cout<<m;
        }
        else if (g%2==0) {
            if (l>m+k) cout<<m+k;
            else cout<<l;
        }
        else {
            if (k>m+l) cout<<m+l;
            else cout<<k;
        }
    }

    return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<math.h>
#include<iomanip>
#include<string>
#include <cassert>
#include <complex>
#include<math.h>
#include<bits/stdc++.h>

#define rep(s,i,n) for(int i = s;i < n;i++)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef __int128_t lll;
typedef pair<ll, ll> pll;

const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };
const ll LongINF = 1e13 + 7;
const int INF = 1e9 + 7;
const ll LL_MAX = 9223372036854775807;
const ll LL_MIN = -9223372036854775807;
//エッジが保持する情報
struct E{
  int y;
  int d;
  int c;
  E(int y,int d,int c) : y(y) , d(d), c(c) {}
} ;

//ノード一つが取り扱う情報
struct S{
  double time;
  int sp,city,prev;
  //コンストラクタ
  S(double time,int sp, int city, int prev) : time(time),sp(sp),city(city),prev(prev) {}
  bool operator > (const S & s) const{
    return time > s.time;
  }
};

int dsp[3] = {-1,0,1};

int keta(ll i){

  int keta = 0;
  do{
    keta++;
  }while(i /= 10);

  return keta;
}
//素因数分解　O(√n)
vector<pair<ll,ll>> pfactor(ll n){
  vector<pair<ll,ll>> factor;
   ll ex; //指数
   for(ll a = 2; a * a <= n; a++){
     if(n % a != 0)continue;

     ll ex = 0;

     while(n % a == 0){
       n /= a;
       ex++;
     }

     factor.push_back({a,ex});
   }

   if(n != 1) factor.push_back({n,1});

  return factor;
}

int charCheck(char c){
  int f;
  if(c >= 'a' && c <= 'z')f = 1;
  else if(c >= 'A' && c <= 'Z') f = 0;

  return f;
}

int main(void){

  string s;
  cin >> s;

  rep(1,i,s.size() + 1){
    if(i%2 != charCheck(s[i-1]))
    {
      cout << "No" ;
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

#include <bits/stdc++.h>
#include<sstream>
#include<string>
#include<vector>
#include <set>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define decimal(ans,w) cout<<fixed<<setprecision(w)<<ans
long long M=1000000007;
using namespace std;
ll fact[10000];
ll power(ll x, unsigned ll y, unsigned ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}
unsigned long long modInverse(unsigned long long n,
                                            ll p)
{
    return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
                                 ll r, ll p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;
    return (fact[n] * modInverse(fact[r], p) % p
            * modInverse(fact[n - r], p) % p)
           % p;
}
int32_t main()
{
  IOS
  string s;
  cin>>s;
  ll n=s.length(),x=0;
  deque<char>t;
  for(ll i=0;i<n;i++)
  {
      if(s[i]=='R')
      {
         x^=1;
      }
      else if(x)t.push_front(s[i]);
      else t.push_back(s[i]);
  }
  if(x)reverse(t.begin(),t.end());
  string s1;
  for(auto it:t)
  {
      if(s1.length()>0 && s1.back()==it)
      {
          s1.pop_back();
      }
      else s1.push_back(it);
  }
  cout<<s1;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;
const int N = 15;

string s1, s2, s3;
string as;

int mp[128];
void get(string& s, ll& x) {
    x = 0;
    for (int i = 0; i < s.size(); ++i) x = x * 10 + mp[s[i]];
}

bool check() {
    static ll x, y, z;
    if (!(mp[s1[0]] && mp[s2[0]] && mp[s3[0]])) return false;
    get(s1, x), get(s2, y), get(s3, z);
    if (!x || !y || !z) return false;
    if (x + y == z) {
        printf("%lld\n%lld\n%lld", x, y, z);
        return true;
    } else {
        return false;
    }
}

bool st[N];
bool dfs(int u = 0) {
    if (u == as.size()) {
        if (check()) return true;
        return false;
    }
    for (int i = 0; i < 10; ++i) {
        if (!st[i]) {
            st[i] = true;
            mp[as[u]] = i;
            if (dfs(u + 1)) return true;
            mp[as[u]] = 0;
            st[i] = false;
        }
    }
    return false;
}

int main() {
    cin >> s1 >> s2 >> s3;
    as = s1 + s2 + s3;
    sort(as.begin(), as.end());
    as.erase(unique(as.begin(), as.end()), as.end());
    if (!dfs()) puts("UNSOLVABLE");
    return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < (t); ++i)
#define dsrep(i,t,s) for(int i = (t)-1; i >= (s); --i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define bn(x) ((1<<(x))-1)
#define newline puts("")
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using PQ = priority_queue<T,vc<T>,greater<T> >;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;
using T3 = tuple<int,int,int>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vp = vc<P>;
using vt = vc<T3>;
int getInt(){int x;scanf("%d",&x);return x;}
vi pm(int n, int s=0) { vi a(n); iota(rng(a),s); return a;}
template<typename T>istream& operator>>(istream&i,vc<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vc<T>&v,const string& d=""){stringstream s;rep(i,sz(v))(i?s<<d:s)<<v[i];return s.str();}
template<typename T>ostream& operator<<(ostream&o,const vc<T>&v){if(sz(v))o<<join(v," ");return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
vc<string> split(const string& s,char d=' '){vc<string> r(1);for(char c:s)if(c==d)r.pb("");else r.back()+=c;return r;}
string operator*(const string& s,int t){return join(vc<string>(t,s));}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>T dup(T x, T y){return (x+y-1)/y;}
template<typename T>ll suma(const vc<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
// template<typename T>void uni(vc<T>& a){sort(rng(a));a.erase(unique(rng(a)),a.end());}
template<typename T>void uni(T& a){sort(rng(a));a.erase(unique(rng(a)),a.end());}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("UNSOLVABLE"); return;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
using vs = vc<string>;

struct Solver {
  void solve() {
    vs s(3);
    cin>>s;
    string cs;
    rep(i,3) cs += s[i];
    uni(cs);
    if (sz(cs) > 10) dame;
    vi p = pm(10);
    vi mp(256);
    do {
      rep(i,sz(cs)) mp[cs[i]] = p[i];
      vl t(3);
      bool ok = true;
      rep(i,3) {
        if (mp[s[i][0]] == 0) ok = false;
        for (char c : s[i]) t[i] = t[i]*10+mp[c];
      }
      if (t[0]+t[1] != t[2]) ok = false;
      if (!ok) continue;
      cout<<t<<endl;
      return;
    } while (next_permutation(rng(p)));
    dame;
  }
};

int main() {
  int ts = 1;
  // scanf("%d",&ts);
  rrep(ti,ts) {
    Solver solver;
    solver.solve();
  }
  return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define inf 0x3f3f3f3f

using namespace std;
using ll = long long int;

int main(){

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << min({a, b, c, d}) << endl;

}

// Author: bitbeast
// Practice more!

#include <bits/stdc++.h>
using namespace std;

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;

	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/*
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll n = 0;

  ll m = 1000;
  for(int i=0;i<4;i++){
    cin >>  n;
    m = min(m,n);
  }
  cout << m << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 	long long int i,n,ed=0,md=0;
 	long double dd;
 	cin>>n;
 	long long int a[n];
 	for(i=0;i<n;i++){
 		cin>>a[i];
 		if(a[i]<0) a[i]=-a[i];
 		md+=a[i];
 		ed+=a[i]*a[i];
	 }
	sort(a,a+n);
	cout<<md<<endl;
	dd=sqrt(ed);
	cout<<fixed<<setprecision(15);
	cout<<dd<<endl;
	cout<<a[n-1]<<endl;
 	 return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()

ll sum(const vector<ll>& vec) {
    ll ans = 0;
    for (ll v: vec) ans += v;
    return ans;
}

void solve(long long N, std::vector<long long> x){
    vector<ll> absX(N);
    rep(i, N) absX.at(i) = abs(x.at(i));
    vector<ll> absXQ(N);
    rep(i, N) absXQ.at(i) = absX.at(i) * absX.at(i);

    cout << sum(absX) << endl;
    cout << fixed << setprecision(9) << sqrt(double(sum(absXQ))) << endl;
    cout << *max_element(all(absX)) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, std::move(x));
    return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;

static const LL INF = 1LL << 60;

LD solve(long long A, long long B) {
	LD ans = 100.0 * LD(A - B) / A;
	return ans;
}

int main() {
	cout.precision(20);
    long long A, B;
	std::cin >> A >> B;
	cout << solve(A, B) << endl;
	return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include <functional>
#include <iomanip>
#include<cmath>
#include<deque>
#include <math.h>
#include <queue>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
using namespace std;
using ll = long long;

int GetDigit(ll num) {

	int a = 0;
	while (num) {
		num /= 10;
		a++;
	}
	return a;
}

ll Get_keta_num(ll num) {
	ll z = 0;
	while (num) {
		z += num % 10;
		num /= 10;
	}
	return z;
}

void print(set<int> s) {
	for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
		cout << *it << " ";
	}
	cout << endl;
}

ll count_num_2(ll num) {
	ll data = 0;
	while (true) {
		ll m = num % 1000;
		ll k = num % 100;
		if ((m % 8) == 0) {
			data += 3;
			num /= 8;
			continue;
		}
		else if ((k % 4) == 0) {
			data += 2;
			num /= 4;
			continue;
		}
		else if ((k % 2) == 0) {
			data++;
			num /= 2;
			continue;
		}
		break;
	}
	return data;
}
ll facctorialMethod(int k) {
	ll sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;

	}
	return sum;
}

//" "

ll Get_num_in_string(string s) {
	int n = s.length(), z;
	ll sur = 0;
	for (int i = 0; i < n; i++) {
		z = int(s[i] - '0');
		if (z < 10) {
			sur *= 10;
			sur += z;
		}
	}
	return sur;
}

ll ll_pow(int num, int zyousuu) {
	ll ans = 1;
	for (int i = 0; i < zyousuu; i++) {
		ans *= num;
	}

	return ans;
}
string substrBack(std::string str, size_t pos, size_t len) {
	const size_t strLen = str.length();

	return str.substr(strLen - pos, len);
}

ll ll_gcd(ll x, ll y) {
	if (x < y) {
		ll a = x;
		x = y;
		y = a;
	}

	while (y > 0) {
		ll r = x % y;
		x = y;
		y = r;
	}
	return x;
}

using Graph = vector<vector<int>>;

ll ll_lcm(ll a, ll b) {
	return a * b / ll_gcd(a, b);
}

string get_words_from_end(string word, int num) {
	return word.substr(word.size() - num, num);
}

string binary(ll bina) {
	string ans = "";
	if (bina == 0) {
		ans = "0";
		return ans;
	}
	if (bina == 1) {
		ans = "1";
		return ans;
	}
	while (bina != 0) {
		int a = bina % 2;
		char c = '0' + a;
		ans += c;
		bina -= a;
		bina /= 2;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

void YES() {
	cout << "YES" << endl;
}
void NO() {
	cout << "NO" << endl;
}
void Yes() {
	cout << "Yes" << endl;
}
void No() {
	cout << "No" << endl;
}

ll comb(ll N, ll i) {
	vector<vector<long long int> > v(N + 1, vector<long long int>(N + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
	return v[N][i];
}

bool is_prime(long long N) {
	if (N == 1) return false;
	for (long long i = 2; i * i <= N; ++i) {
		if (N % i == 0) return false;
	}
	return true;
}

bool divisor(long long n) {
	vector<long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end()); // 昇順に並べる
	bool x = false;
	if (ret.size() == 8)x = true;
	return x;
}

vector<bool> seen(100005, false);
vector<int> ans;
int count = 0;

void dfs(const Graph& G, int v) {
	seen[v] = true; // v を訪問済にする
	ans.push_back(v + 1);
	// v から行ける各頂点 next_v について
	for (auto next_v : G[v]) {
		if (seen[next_v]) continue; // next_v が探索済だったらスルー
		dfs(G, next_v); // 再帰的に探索
	}
}

void cout_data(ll x) {
	cout << x << endl;
}

int main() {
	int A, B; cin >> A >> B;
	int ans = 1;
	for (int i = 2; i <= B;i++) {
		int a_1 = (A + i - 1) / i;
		int b_1 = B / i;
		if (a_1 > b_1)continue;
		if ((a_1 == 0) || (b_1 == 0))continue;
		if (a_1 != b_1) {
			if ((a_1 * i >= A) && (b_1 * i <= B)) {
				if (a_1 * i < b_1 * i)ans = i;
			}
		}

	}
	cout << ans << endl;
	return 0;
}

//std::cout << std::setprecision(2) << 3.141; // "3.1"


//Starting in the name of Lord
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define Yes cout<<"Yes"<<endl
#define yes cout<<"yes"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define asort(x) sort((x).begin(),(x).end())
#define rsort(x) reverse(x.begin(),x.end())
#define ll long long
#define deciset(x) cout <<setprecision(x) <<fixed;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define jotokkjon while
#define PI 2*acos(0.0)
#define boost ios::sync_with_stdio(false);cin.tie(0)
void solve()
{
   ll a,b;
   cin>>a>>b;
   if( b % a) No;
   else Yes;

}
int main()
{

    boost;
    #ifndef ONLINE_JUDGE
    freopen("C:/Users/User/Desktop/C/input.txt", "r", stdin);
    freopen("C:/Users/User/Desktop/C/output.txt", "w", stdout);
     #endif
    ll t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
}

#include <bits/stdc++.h>
using namespace std;

int main() {
    int M, H;
    cin >> M >> H;

    cout << ((H % M == 0) ? "Yes" : "No") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

void Main(){
    int a,b; cin >> a >> b;
    int c = a+b;
    int d = b;

    int ans;
    if(c>=15 && d>=8) ans = 1;
    else if(c>=10 && d>=3) ans = 2;
    else if(c>=3) ans = 3;
    else ans = 4;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

#include<iostream>
using namespace std;
int main(){
int x,n,i;
char v;
cin >> n >> x;
for(i=1;i<=n;i++){
    cin >> v;
    if(v=='x'&&x>0)
    x--;
    else if(v=='o')
    x++;
}
cout << x;
}


#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstring>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<string>
#include<sstream>
#include<chrono>
#include<random>
#include<unordered_map>
#include<ctype.h>
#include<cassert>
#include<numeric>
#include<functional>
using namespace std;
typedef long long ll; typedef std::pair<ll, ll> pll; typedef std::pair<int, int> pii; typedef unsigned long long ull; typedef long double ldb; typedef double db;
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
template <class output_type, class input_type>
output_type Convert(const input_type& input) {
	stringstream ss; output_type result;
	ss.clear(); ss << input; ss >> result;
	return result;
}
const double Pi = acos(-1.0); const int inf = 1 << 29, Mod = 1e9 + 7, N = 1e5 + 3; const ll INF = 1ll << 60;
inline ll qpow(ll a, ll b, ll mod = Mod, ll ans = 1) {
	while (b) {
		if (b & 1)ans = ans * a % mod;
		a = a * a % mod; b >>= 1;
	}return ans;
}
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }; ll lcm(ll a, ll b) { return a * b / (gcd(a, b)); }
pii EXgcd(int x, int y) {        //return.first ny
	if (!y) { return { 1,0 }; }pii a = EXgcd(y, (x + y) % y);
	return { a.second, a.first - a.second * (x / y) };
}
inline bool Ezisprime(int n) {
	if (n <= 1)return 0; if (n <= 3)return 1;
	vector<int> ezp{ 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
	for (int i = 0; i < ezp.size(); i++)if (n == ezp[i])return 1;
	for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)return 0;
	return 1;
}
inline int LIS(const vector<int> Origins, const int n) {
	if (!n || !Origins.size()) return 0;
	int len = 0; vector<int> d(n, 0); d[0] = Origins[0];
	for (int i = 1; i < n; i++)
		if (Origins[i] >= d[len])d[++len] = Origins[i];
		else d[upper_bound(d.begin(), d.begin() + len, Origins[i]) - d.begin()] = Origins[i];
	return len + 1;
}
inline int Alptonum(const char& a) { if (a <= 'z')return int(a - 'a'); else return int(a - 'A'); }
inline char Numtoalp(const int& n, bool& t) { if (!t)return char('a' + n); else return char('A' + n); }
inline bool cmp(const pii& a, const pii& b) {  //default more and more larger
	if (a.second == b.second)return a.first < b.first;
	return a.second > b.second;
}
struct cmpstl {           //reverse
	inline bool operator()(const pii& a, const pii& b) {
		if (a.second == b.second)return a.first > b.first;
		return a.second < b.second;
	}
};
//partial_sum(begin,end,place,minus<int>()) adjacent_differece(begin,end,place)
//count(begin(),end(),char=='x') count_if(begin(),end(),boolcmp) vector<int> p(n);iota(p.begin(), p.end(), 0);

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Code follows ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV Code follows VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVII

int main()
{
	ios::sync_with_stdio(0); cout.tie(0), cin.tie(0);

	int n, m, q; cin >> n >> m >> q;
	vector<pii>bags(n); vector<int>boxes(m);
	for (auto& i : bags)cin >> i.first >> i.second;
	for (auto& i : boxes)cin >> i;
	sort(all(bags),cmp);
	while (q--)
	{
		int l, r; cin >> l >> r; --l, --r;
		vector<int> tboxes;
		for (int i = 0; i < l; ++i)tboxes.emplace_back(boxes[i]);
		for (int i = r + 1; i < m; ++i)tboxes.emplace_back(boxes[i]);
		sort(all(tboxes));
//		for (auto& box : tboxes)cout << box << ' ' << '\n';
		ll ans = 0;
		for (auto &bag:bags)
			for (auto &box:tboxes)
				if (box >= bag.first)
				{
					box=-1, ans += bag.second;
					break;
				}
		cout << ans << "\n";
	}
}

/*
3 4 3
1 9
5 3
7 8
1 8 6 9
4 4
1 4
1 3

*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;

//int v[50];
//int w[50];
int x[50];
int y[50];//クエリ作業用
int main(){
  int n,m,q;
  cin>>n>>m>>q;
  vector<P>vec;
  rep(i,n){
    int w,v;
    cin>>w>>v;
    vec.push_back({v,w});
  }
  sort(vec.begin(),vec.end());
  /*for(auto e:vec){
    cout<<e.first<<" "<<e.second<<endl;
  }*/

  rep(i,m) cin>>x[i];
  int ans=0;
  //クエリ
  rep(i,q){
    ans=0;
    int l,r;
    cin>>l>>r;
    l--;
    r--;
    for(int j=0;j<m;j++){
      if(l<=j && j<=r){
        y[j]=0;
      }
      else{
        y[j]=x[j];
      }
    }
    sort(y,y+m);
    for(int k=n-1;k>=0;k--){
      for(int l=0;l<m;l++){
        if(vec[k].second<=y[l]){
          ans+=vec[k].first;
          y[l]=0;
          break;
        }
      }
    }
    cout<<ans<<endl;
  }
}


///                          BISMILLA HIRRAHMANIR RAHIM
///                              ALLAH IS ALMIGHTY
///                          ALLAH IS MUCH MORE CREATIVE

#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb              push_back
#define ff              first
#define ss              second
#define mem(a,v)        memset(a, v, sizeof(a))
#define all(a)          (a).begin(), (a).end()
#define pii             pair<ll,ll>
#define ci(X)                cin>>X
#define cii(X, Y)            cin>>X>>Y
#define ciii(X, Y, Z)        cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z)    cin>>W>>X>>Y>>Z
#define co(x)                cout << x<< "\n"

#define rep(i,n)        for(int i = 0; i < (n); ++i)
#define rep1(i,n)       for(int i = 1; i <= (n); ++i)
#define dbg(x)          cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y)       cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z)     cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl;
#define pq              priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;
using ll =                   int64_t;
using ii=                    pair<ll,ll>;
const double PI =            acos(-1.0);
const int mx =               2e5+5;
const int M=                 1e9+7;

int dr[]= {0,-1,0,1,-1,-1,1,1};  /// first 4 are right,up,left,bottom
int dc[]= {1,0,-1,0,1,-1,-1,1};
int kx[]= {-1,-2,-2,-1,1,2,2,1};  /// knight move
int ky[]= {2,1,-1,-2,-2,-1,1,2};

bool valid(int row,int col){
    return (row>=1) && (row<=8) && (col>=1) && (col<=8);
}

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b, a % b);
}

bool sq(ll x){
   ll y= sqrt(x);
   if(y*y==x) return true;
   return false;
}

void Solve()
{
    ll i,j,x,y,z,sum=0,ans=0,n,m=0,k=0,l=0,p=0,q=0;
    cin>>n;
    ll a[n+2];
    rep(i,n) cin>>a[i];
    vector<ll>b; ll mini= 1e18;

    for(i=0; i<(1<<(n-1)); i++){      /// (1 <<(n-1)) why??  can't understand;
        ll total=0;
        for(j=0; j<n; j++){          /// all possible subset
            total= total | a[j];
            if(i & (1<<j)){
               b.pb(total);    //dbg2(total,i);
               total=0;
            }
        }
        if(total) b.pb(total);
        ll cal=0;
        for(j=0; j<b.size(); j++)
            cal= cal ^ b[j];

     b.clear();
        mini= min(mini,cal);
    }
    cout<< mini<< "\n";

    return;
}

int main()
{
    faster;

   int TC=1;

    //cin >> TC;

    while(TC--){
         Solve();
    }

    return 0;
}
/**

*/

#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  ll ans = 1LL << 40;
  for (ll x = 0; x < (1LL<<(N-1)); x++) {
    ll y = x | (1LL<<(N-1));
    ll val = 0;
    ll cur = 0;
    for (ll i = 0; i < N; i++) {
      cur |= A[i];
      if ((y >> i) & 1) {
        val ^= cur;
        cur = 0;
      }
    }
    ans = min(ans, val);
  }
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

struct UnionFind {
    vector<int> par, siz;

    UnionFind(int n) : par(n), siz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

    int root(int x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

signed main() {
    int n, m;
    cin >> n >> m;
    ll a[n], b[n];
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    UnionFind uf(n);
    int c, d;
    rep(i, m) {
        cin >> c >> d;
        c--;
        d--;
        uf.unite(c, d);
    }
    map<int, ll> suma, sumb;
    rep(i, n) {
        suma[uf.root(i)] += a[i];
        sumb[uf.root(i)] += b[i];
    }
    for (auto i : suma) {
        if (i.second != sumb[i.first]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct Edge {
	int to, nxt;
} E[N << 1];
int n, m, cnt, head[N], a[N], b[N];
long long sum;
bool vis[N];
void addedg(int u, int v) {
	E[++cnt] = (Edge){v, head[u]};
	head[u] = cnt;
}
void dfs(int u) {
	vis[u] = true;
	sum += a[u] - b[u];
	for (int i = head[u]; i; i = E[i].nxt) {
		int v = E[i].to;
		if (vis[v]) continue;
		dfs(v);
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		addedg(u, v);
		addedg(v, u);
	}
	for (int i = 1; i <= n; i++)
	if (!vis[i]) {
		sum = 0;
		dfs(i);
		if (sum) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll c[n][n];
  rep(i,n)rep(j,n) R c[i][j];
  set<vector<ll> > s1,s2;
  rep(i,n) {
    vector<ll> a,b;
    rep(j,n-1) {
      a.pb(c[i][j+1]-c[i][j]);
      b.pb(c[j+1][i]-c[j][i]);
    }
    s1.in(a);
    s2.in(b);
  }
  if(s1.size()>1||s2.size()>1) {
    pr("No");
    return;
  }
  vector<ll> v=*s1.begin();
  ll M=0,x=0;
  rep(i,v.size()) {
    x+=v[i];
    M=min(M,x);
  }
  vector<ll> b;
  x=-M;
  b.pb(x);
  rep(i,v.size()) {
    x+=v[i];
    b.pb(x);
  }
  vector<ll> a;
  rep(i,n) a.pb(c[i][0]-b[0]);
  pr("Yes");
  PR(a,n);
  PR(b,n);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

///Bismillahir Rahmanir Rahim
/*
    Author: Tanzin Ahammad
*/
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        gcd(a,b)        __gcd(a,b)
#define        lcm(a,b)        (a*b)/gcd(a,b)
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        mem(a,b)        memset(a, b, sizeof(a))
#define        uniq(v)         (v).erase(unique(all(v)),(v).end())
#define        mchk(mask,pos)  (mask & (1<<pos))
#define        mset(mask,pos)  (mask bitor (1<<pos))
#define        munset(mask,pos) (mask ^ (1<<pos))
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
const int N = 1e6+5;
const int mod = (int)  1e9 + 7;
ll arr[N];
ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}

int main()
{
    IOS;

    ll tc,n,x,i,j;
    cin>>n;
    ll M[n][n];
    for(i=0;i<n;i++)
    {
           for(j=0;j<n;j++)
           {
                  cin>>M[i][j];
           }
    }
    for(i=0;i<n;i++)
    {
           vl vt1,vt2;
           for(j=0;j<n;j++)
           {
                 vt2.pb(M[i][j]);
                 x=M[j][j]-M[i][j];
                 if(x<0) break;
                 vt1.pb(x);
           }
           if(sz(vt1)<n) continue;
           ll f=0;
           for(ll i1=0;i1<n;i1++)
           {
                  for(ll j1=0;j1<n;j1++)
                  {
                         if((vt1[i1]+vt2[j1])!=M[i1][j1])
                         {
                                f=1;break;
                         }
                  }
           }
           if(f==0)
           {
                  cout<<"Yes"<<endl;
                  for(auto p:vt1) cout<<p<<" ";
                  cout<<endl;
                  for(auto p:vt2) cout<<p<<" ";
                  cout<<endl;
                  return 0;
           }
    }
    cout<<"No"<<endl;

    return 0;
}


//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> inout(2 * n);
    auto no = [&](){
        cout << "No" << '\n';
        exit(0);
    };
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(a >= 0 && b >= 0 && a >= b){
            no();
        }
        if(a >= 0){
            if(inout[a]){ no(); }
            inout[a] = i;
        }
        if(b >= 0){
            if(inout[b]){ no(); }
            inout[b] = - i;
        }
    }
    printde(inout);
    vector<int> dp(2 * n + 1);
    dp[0] = 1;
    for(int i = 0; i < 2 * n; i++){
        if(!dp[i]){ continue; }
        for(int j = 1; i + j * 2 <= 2 * n; j++){
            bool ok = true;
            for(int k = 0; k < j; k++){
                if(inout[i + k] < 0){
                    ok = false;
                }else if(inout[i + k] > 0){
                    ok &= inout[i + j + k] == 0 || inout[i + j + k] == - inout[i + k];
                }
            }
            for(int k = 0; k < j; k++){
                if(inout[i + j + k] > 0){
                    ok = false;
                }else if(inout[i + j + k] < 0){
                    ok &= inout[i + k] == 0 || inout[i + k] == - inout[i + j + k];
                }
            }
            if(ok){
                printde(i, j, dp);
                dp[i + j * 2] = 1;
            }
        }
    }
    if(!dp[2 * n]){
        no();
    }
    cout << "Yes" << '\n';
}

//#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
//using mint = atcoder::modint1000000007;

ll max_rectangle(const vector<int>& vec) {
	ll rtn = 0;
	stack<pii> stk;
	auto calstk = [&](int ps, int ht){
		int t = ps;
		for( ;!stk.empty() && stk.top().second >= ht; stk.pop()){
			if(stk.top().second == ht) return;
			t = stk.top().first;
			rtn = max(rtn, 1LL * (ps-t) * stk.top().second);
		}
		if(ht >0 ) stk.push(pii(t, ht));
	};
	rep(i, sz(vec)) calstk(i, vec[i]);
	calstk(sz(vec), 0);
	return rtn;
}
int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	ll ans = max_rectangle(a);
	cout << ans <<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int a,b,c;
int main(){
	a=read(),b=read(),c=read();
	if(c){
		if(a<b) printf("Aoki\n");
		else printf("Takahashi\n");
	}
	else{
		if(a>b) printf("Takahashi\n");
		else printf("Aoki\n");
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define ff first
#define ss second
#define INF 1000000000000000000
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define vll vector<pair<ll,ll>>
#define vi vector<int>
#define sz(a) (int)a.size()
#define all(v) v.begin(), v.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define PI 3.141592653589793
#define o_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setpll tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
int getRand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}
ll power(ll b, ll e, ll m) {
	if (e == 0) return 1;
	if (e & 1) return b * power(b * b % m, e / 2, m) % m;
	return power(b * b % m, e / 2, m);
}
ll power( ll b, ll e)
{
	if (e == 0) return 1;
	if (e & 1) return b * power(b * b, e / 2);
	return power(b * b, e / 2);
}
ll modI(ll a, ll m)
{
	ll m0 = m, y = 0, x = 1;
	if (m == 1)return 0;
	while (a > 1) {
		ll q = a / m;
		ll t = m; m = a % m;
		a = t; t = y;
		y = x - q * y; x = t;
	}
	if (x < 0) {x += m0;}
	return x;
}
void solve() {
	// possibly pick the largest prime ?
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	for (ll x = 0; x <= 1e5 + 5; x++) {
		if (a + x * b <= d * x * c) {
			cout << x; return;
		}
	}
	cout << "-1";
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	// freopen("lcm.in", "r", stdin);
	// freopen("test_output.txt", "w", stdout);
	int t = 1;
	// cin >> t;
	for (int ntc = 1; ntc <= t; ntc++) {
		// cout << "Case #" << ntc << ": ";
		solve();
	}
	return 0;
}


/*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 1e9 + 7;
const double pi = 3.14159265359;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int inverse(int x){
    return binpow(x, MOD - 2, MOD);
}

void solve()
{
    int n, ako = 0;
    cin >> n;
    vector<int> a(n), b(n), c;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        c.push_back(2 * a[i] + b[i]);
        ako -= a[i];
    }
    sort(c.rbegin(), c.rend());
    int cnt = 0;
    for(int i = 0; i < n; i++){
        ako += c[i];
        cnt++;
        if(ako > 0) break;
    }
    cout << cnt << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n;
   cin>>n;
   int m;
   cin>>m;
   vector<int> arr(20,0);
   for(int i=0;i<n;i++){
       string s;
       cin>>s;
       int size=0;
       for(int j=0;j<m;j++){
           if(s[j]=='1'){
               size++;
           }
       }
       arr[size]++;
   }
   long long answer=0;
   long long kentebi=0;
   long long luwebi=0;
   for(int i=0;i<=20;i++){
       if(i%2==0){
           luwebi+=arr[i];
       }else{
           kentebi+=arr[i];
       }
   }
   for(int i=0;i<=20;i++){
       if(i%2==0){
           answer+=(arr[i]*kentebi);
       }else{
           answer+=(arr[i]*luwebi);
       }
   }
   cout<<answer/2<<endl;
   return 0;
}

#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    string s[100005];
    for(int i = 0; i < n; i++) cin >> s[i];
    ll c[2]{0};
    for(int i = 0; i < n; i++){
        int d = 0;
        for(int j = 0; j < m; j++) d += s[i][j] - '0';
        c[d % 2]++;
    }
    cout << c[0] * c[1] << endl;
}


#include <iostream>
#include <vector>
#include <stdexcept>
#include <string>
#include <strstream>
#include <sstream>
int main(){
    int N;
    scanf("%d\n",&N);
    int num=0;
    for (int i=1; i<=N; i++) {
        std::string S;
        std::string V;
        S = std::to_string(i);
        std::stringstream ss;
        ss << std::oct << i;
        V = ss.str();
        for (int j=0; j<V.size(); j++) {
            if (S[j]=='7' || V[j]=='7') {
                num++;
                break;
            }
        }
    }
    printf("%d\n",N-num);
}

//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;
//using namespace atcoder;

ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        int ct = 0;
        forr(i,1,n) {
            bool has7 = false;
            int nn = i;
            while (nn>0) {
                if (nn%10==7) {has7=true;}
                nn/=10;
            }
            nn = i;
            while (nn>0) {
                if (nn%8==7) {has7=true;}
                nn/=8;
            }
            if (!has7) {
                ++ct;
            }
        }
        cout << ct << endl;
    }
//        auto stop = chrono::steady_clock::now();
//        auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
//        cout << "Duration: " << duration.count() << endl;
    return 0;
}


/*
**    author : Dhiraj Govindvira
**      date : 19 June 2021 ~ Saturday
**      time : 05:32:38 PM
*/

#include <bits/stdc++.h>
using namespace std;

#ifdef DHIRAJ
    #include "D:/dhiraj/Programming/debug.h"
#else
    #define dbg(...) 1
    #define cerr if(0) cerr
#endif

using ll = long long int;
#define endl '\n'

template <typename T, typename U>
inline istream & operator >> (istream &in, pair<T, U> &p) {
    in >> p.first >> p.second;
    return in;
}
template <typename T>
inline istream & operator >> (istream &in, vector<T> &v) {
    for(T &x : v) in >> x;
    return in;
}

void solve(ll &tc)
{
    ll n;
    cin >> n;

    ll day = 0;
    ll x = 0, y = 1;
    while(x < n) {
        day++;
        x += y;
        y++;
    }
    cout << day << endl;
}

int main()
{
    #ifdef DHIRAJ
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(0);
    cin.tie(0);

    ll rep = 2;
    while(rep--) {
        ll tc = 1;
        for(ll i = 1; i <= tc; i++) {
            // cout << "Case #" << i << ": ";
            cerr << "Case #" << i << "\n";
            solve(i);
        }
        if(dbg()) break;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N  = 2e5+10;
int a[N];

void solve()
{
   int n;
   cin>>n;
   int ans = 0 ;
   for(int i=1;i<=N;i++)
   {
        a[i] =i;
        a[i]+=a[i-1];
        if(a[i]>=n)
        {
            cout<<i<<endl;
            return ;
        }
   }
}
int main()
{
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define bs binary_search
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
const int maxn = 4e5;
const int inf = 1e9;
const int mod = 1e9+7;

void open_io() { freopen("in","r",stdin); freopen("out","w",stdout); }
void fast_io() { ios::sync_with_stdio(0); cout.tie(0);  cin.tie(0);  }

int n,ans;
vector<int> adj[maxn+5];
set<int> num;
set<int> s;

int dfs(int u)
{
	int ret = adj[u].size();
	s.insert(u);
	for(int v : adj[u])
		if(not s.count(v))
			ret += dfs(v);
	return ret;
}

int32_t main ()
{
	//open_io();
	fast_io();
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
		num.insert(x);
		num.insert(y);
	}
	for(int x : num)
		if(not s.count(x))
		{
			int tmp = s.size();
			int edge = dfs(x)/2;
			int sze = s.size() - tmp;
			ans += min(sze,edge);
		}
	cout << ans << endl;
}

#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int getRand(int L, int R) {
    if (L > R) swap(L, R);
    return (int)(rng() % ((uint64_t)R - L + 1) + L);
}

template<typename T1, typename T2>
ostream& operator << (ostream &os, pair<T1, T2> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template<typename T>
ostream& operator << (ostream &os, vector<T> &vec) {
    for (int i = 0; i < vec.size(); ++i) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}

const int maxn = 2E5 + 5;

vector<int> adj[maxn], dep(maxn);
vector<pii> timestamp(maxn);
vector<int> st[maxn]; /// record timestamp in st[depth]

void dfs(int now) {
    static int tok = 0;
    st[dep[now]].eb(timestamp[now].X = ++tok);
    for (auto x : adj[now]) dfs(x);
    timestamp[now].Y = ++tok;
}

void solve() {
    int N; cin >> N;
    for (int i = 2, par; i <= N; ++i) cin >> par, adj[par].eb(i), dep[i] = dep[par] + 1;

    dfs(1);

    int Q; cin >> Q;
    while (Q--) {
        int u, d; cin >> u >> d;
        /// query how many x \in st[d] \cap [in_u, out_u] ///
        cout << upper_bound(ALL(st[d]), timestamp[u].Y)
              - lower_bound(ALL(st[d]), timestamp[u].X) << "\n";
    }
}

int32_t main() {
    fastIO();

    int t = 1; // cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case #" << _ << ": ";
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ": " << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << p.first << ' ' << p.second;
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e: v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e: v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

long long Modpow(long long a, int n, long long mod){
    if(n == 0) return 1;
    if(n%2 == 0){
      long long res = Modpow(a, n/2, mod);
      return res * res % mod;
    }
    return a * Modpow(a, n-1, mod) % mod;
}

const int MX = 1e6+5;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    V<int> a(n);
    rep(i,n) {
        if(s[i] == 'B') a[i] = 0;
        if(s[i] == 'W') a[i] = 1;
        if(s[i] == 'R') a[i] = 2;
    }

    V<int> fact(MX);
    V<int> cnt(MX);
    fact[0] = 1;
    Rep(i,MX-1) {
        fact[i] = fact[i-1];
        cnt[i] = cnt[i-1];
        if(i%3 == 0) {
            int j = i;
            while(j%3 == 0) cnt[i]++, j /= 3;
            fact[i] *= j, fact[i] %= 3;
        }
        else fact[i] *= i, fact[i] %= 3;
    }

    int d = n-1;
    lint tot = 0;
    rep(i,n) { // dCi % 3
        int cnt3 = cnt[d]-(cnt[i]+cnt[d-i]);
        if(cnt3) continue;
        tot += fact[d]*fact[i]*fact[d-i] % 3 * a[i];
        // cout << fact[d]*fact[i]*fact[d-i] % 3 << endl;
    }
    if(d % 2 == 1) tot = (3-tot) % 3;
    tot = ((tot % 3) + 3) % 3;
    if(tot == 0) cout << 'B' << endl;
    if(tot == 1) cout << 'W' << endl;
    if(tot == 2) cout << 'R' << endl;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
int dp[2][100][100];
int AB[200], *A = AB, *B = AB + 100;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M, K;
	cin >> N >> M >> K;
	rep(i, N) {
		cin >> A[i];
	}
	auto mae = dp[0], ato = dp[1];
	int are = modpow(2 * M, mod - 2);

	rep(i, M) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		if (x < y) swap(x, y);
		mae[x][x]--;
		mae[x][y]++;
		mae[y][y]--;
	}
	rep(x, N) rep(y, x + 1) {
		mae[x][y] = (ll(mae[x][y] + mod) * are + (x == y)) % mod;
		mae[y][x] = mae[x][y];
	}

	const ll ma = (1ll << 32) - 1;

	rep(i, 30) {
		if (K >> i & 1) {
			rep(i, N) {
				ll t1 = 0, t2 = 0;
				rep(j, N) {
					auto tmp = (ll)mae[i][j] * A[j];
					t1 += tmp >> 32;
					t2 += tmp & ma;
				}
				B[i] = ((t1 % mod << 32) + t2) % mod;
			}
			swap(A, B);
		}
		if (!K | i >= 31 - __builtin_clz(K)) break;
		rep(x, N) rep(y, x + 1) {
			auto tmp1 = mae[x];
			auto tmp2 = mae[y];
			ll t1 = 0, t2 = 0;
			rep(z, N) {
				auto tmp = *tmp1++ * (ll)*tmp2++;
				t1 += tmp >> 32;
				t2 += tmp & ma;
			}
			ato[y][x] = (ato[x][y] = ((t1 % mod << 32) + t2) % mod);
		}
		swap(mae, ato);
	}

	rep(i, N) co(A[i]);

	Would you please return 0;
}


#include<bits/stdc++.h>

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;
#define debug 0

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    long long n,m;
    cin>>n>>m;

    cout<<(modpow(10,n,m*m)/m)%m<<endl;
}
/*

*/

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int b,c;
    cin>>b>>c;
    if(c==1 && b!=0)
    cout<<"2\n";
    else if(c<=2*b)
    cout<<2*c-1<<"\n";
    else
    {
        if(b>0)
        cout<<c+2*b-1<<"\n";
        else
        cout<<c+abs(b)*2<<"\n";
    }
}


#include<bits/stdc++.h>
#define FULL(x,y) memset(x,y,sizeof(x))
#define ll long long
#define SZ(x) (int)x.size()
#define pb push_back
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = 1000006;
const ll mod = 1e9 + 7;
ll n, m, k;
ll inv[N];

ll cal_inv(ll x) {
    ll ans = 1, p = mod - 2;
    while(p) {
        if (p & 1) ans = (ans * x) % mod;
        x = (x * x) % mod;
        p >>= 1;
    }
    return ans;
}

ll cal(ll a, ll b) {
    ll ans = 1;
    for(ll i = a - b + 1; i <= a; ++i) ans = (ans * i) % mod;
    for(ll i = 1; i <= b; ++i) ans = (ans * inv[i]) % mod;
    return ans;
}

int main() {
    cin >> n >> m >> k;
    if (n > m + k) {
        cout << 0;
        return 0;
    }
    for(int i = 1; i <= n; ++i) {
        inv[i] = cal_inv(i);
    }
    ll ans1 = cal(n + m, n);
    ll tmp = n - k - 1 < 0 ? 0 : cal(n + m, n - k - 1);
    ans1 = (ans1 - tmp + mod) % mod;
    cout << ans1 << endl;
    return 0;
}

#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int H, W;
char nap[2020][2020];
ll memo[2020][2020];
ll sum_tate[2020][2020];
ll sum_yoko[2020][2020];
ll sum_naname[2020][2020];

ll solve(int i, int j){
    if(memo[i][j] != -1) return memo[i][j];
    if(i == H && j == W) return 1;
    ll res = 0;
    if(i < H && nap[i+1][j] == '.'){
        ll tate = solve(i+1, j);
        sum_tate[i][j] = sum_tate[i+1][j] + tate;
        sum_tate[i][j] %= MOD;
    }
    if(j < W && nap[i][j+1] == '.'){
        ll yoko = solve(i, j + 1);
        sum_yoko[i][j] = sum_yoko[i][j+1] + yoko;
        sum_yoko[i][j] %= MOD;
    }
    if(i < H && j < W && nap[i+1][j+1] == '.'){
        ll naname = solve(i + 1, j + 1);
        sum_naname[i][j] = sum_naname[i+1][j+1] + naname;
        sum_naname[i][j] %= MOD;
    }
    return memo[i][j] = (sum_yoko[i][j] + sum_tate[i][j] + sum_naname[i][j]) % MOD;
}

int main(){
    cin >> H >> W;
    REP(i,H)REP(j,W)cin >> nap[i][j];
    rep(i,2020)rep(j,2020)memo[i][j] = -1, sum_naname[i][j] = 0, sum_tate[i][j] = 0, sum_yoko[i][j] = 0;
    cout << solve(1,1) << endl;
    //REP(i,H){REP(j,W)cout << memo[i][j] << ' '; cout << endl;}
    return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <=(int)(n); i++)
#define all(V) V.begin(),V.end()
#define pi 3.1415926535897932384626
#define fi fixed<<setprecision(10)
#define MOD 1000000007
#define ll long long
using namespace std;
//lower_bound(a+l, a+r, x) - a　a[l] から a[r-1] までの中で初めて x 以上となるようなインデックスを返します。
//count(a + l, a + r, x)/find(a + l, a + r + 1, x)
int gcd(ll m,ll n){
  if(n==0) return m;
  return gcd(n,m%n);
}
int fact(ll n){
  ll x=1;REP(i,n)x*=i;
  return x;
}
const ll M = pow(10,9)+7;
vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
ll mpow(ll x, ll n){ /*x^n(mod M)*/
    ll ans = 1;
    while(n!=0){
      if(n&1) ans = ans*x % MOD;
      x = x*x % MOD;n=n>>1;
    }
  return ans;
}
ll comb(ll a, ll b){
  fac[0] = 1;ifac[0] = 1;
  for(ll i = 0; i<1000000; i++){
    fac[i+1] = fac[i]*(i+1) % MOD;ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD;
  }
  if(a==0&&b==0)return 1;
  if(a<b||a<0)return 0;
  ll tmp=ifac[a-b]*ifac[b]%MOD;
  return tmp*fac[a]%MOD;
}
ll nck(ll a,ll b){
  ll s=1,x=1;
  rep(i,b){
    s=(s*(a-i))/x;
    x++;
    }
    return s;
}
ll perm(ll a, ll b){
  fac[0] = 1;ifac[0] = 1;
  for(ll i = 0; i<1000000; i++){
   fac[i+1] = fac[i]*(i+1) % MOD;ifac[i+1] = ifac[i]*mpow(i+1, M-2) % MOD;
  }
  if(a < b) return 0;
  ll tmp = ifac[a-b] % MOD;
  return tmp * fac[a] % MOD;
}
ll dupc(ll a,ll b){
  fac[0] = 1;ifac[0] = 1;
  for(ll i = 0; i<1000000; i++){
    fac[i+1] = fac[i]*(i+1) % MOD;ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M;
  }
  if(a == 0 && b == 0)return 1;
  if(a < 0 || b == 0)return 0;
  ll tmp = ifac[a-1]* ifac[b] % MOD;
  return tmp * fac[a+b-1] % MOD;
}
void make_prime(){
  vector<int> prime;
  prime.push_back(2);
  for(int i=3;i<=pow(10,5);i++){
    bool pri=true;
    rep(j,prime.size())  if(i%prime[j]==0){ pri=false; break;}
    if(pri) prime.push_back(i);
  }
}
int main(){
  int n;cin>>n;

  vector<ll> a(n);
  rep(i,n) cin>>a[i];

  sort(a.begin(),a.end());

  vector<ll> vec(n+1);
  vec[0]=0;
  rep(i,n) vec[i+1]=vec[i]+a[i];

  ll ans=0;
  rep(i,n){
    ans+=(vec[n]-vec[i])-a[i]*(n-i);
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2 * 100010;
int a[N];
int presum[N];
bool cmp(int &a,int &b){
	return a > b;
}
signed main(){
	#ifndef ONLINE_JUDGE
		freopen("sumofdiff.txt","r",stdin);
	#endif
	ios::sync_with_stdio(false);
	int n;cin >> n;

	for(int i = 1 ; i <= n ; i++) {
		cin >> a[i];
	}
	sort(a + 1,a+n+1,cmp);
	for(int i = 1 ; i <= n; i++){
		presum[i] = presum[i-1] + a[i];
	}
//	for(int i = 1; i <= n ; i++) cout << a[i] <<",";
//	cout << endl;
	int ans = 0;
	for(int i = 1; i <= n ; i++){
		//(long long )
		ans += (((n-i) * a[i] )- (presum[n] - presum[i]));
	}
	cout << ans;
}


//2021-04-18 12:10:11
/*折半枚舉*/
#include <bits/stdc++.h>
using namespace std;

int n,a[100],id[2];
long long t;
vector<long long>re[2];//re[0]是小的那部分枚舉出來的東東，re[1]是大的那部分枚舉出來的東東

bool d[100]={0};

int target,from;//紀錄正在枚舉的頭和尾
bool big=false;//現在是否在枚舉大的
void f(int id){
    if(id==target){
        long long ans=0;
        for(int i=from;i<target;i++)ans+=d[i]*a[i];
        re[big].emplace_back(ans);
        return;}
    f(id+1);
    d[id]=1;
    f(id+1);
    d[id]=0;
return;}

int main(){
    //輸入
    scanf("%d %lld",&n,&t);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);

    //枚舉小堆的
    from=0,target=(n+1)/2;
    f(0);
    //枚舉大堆的
    from=target,target=n,big=true;
    f(from);

    //整理枚舉出來的東東
    sort(re[0].begin(),re[0].end());
    sort(re[1].begin(),re[1].end());

    //雙指針求解
    long long ans=0;
    int l1=re[0].size(),l2=re[1].size(),j=0;
    for(int i=0;i<l1;i++){
        if(re[0][i]>t)break;
        ans=max(re[0][i],ans);

        while(j<l2-1&&(re[1][j]+re[0][i])<t)j++;
        while(j>=0&&(re[1][j]+re[0][i])>t)j--;
        if(j>=0&&(re[1][j]+re[0][i])<=t)ans=max(re[0][i]+re[1][j],ans);
        if(ans==t)break;}
    printf("%lld\n",ans);
return 0;}

#include<cstdio>
#include<algorithm>
#define Q 200005
using namespace std;
#define gc() getchar()
inline bool ig(char c){return c>='0'&&c<='9';}
inline void read(int &oi){char c;int f=1,res=0;while(c=gc(),(!ig(c))&&c^'-');c^'-'?res=(c^48):f=-1;while(c=gc(),ig(c))res=res*10+(c^48);oi=f*res;}
inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);}
int l,r,ans;
inline int gcd(int x,int y){return !y?x:gcd(y,x%y);}
inline int maxx(int x,int y){return x>y?x:y;}
inline void solve(int tim){
	for(int i=2;i*i<=tim;++i){
		if(tim%i)continue;
		if(tim-(tim/i)>=l)ans=maxx(ans,tim/i);
		if(tim-i>=l)ans=maxx(ans,i);
	}
}
int main(){
	read(l);read(r);ans=gcd(l,l+1);
	for(int i=l+2;i<=r;++i)solve(i);print(ans);putchar('\n');
	return 0;
}


#include<bits/stdc++.h>
#define ll              long long int
#define ld              long double
#define ff              first
#define ss              second
#define mkpr            make_pair
#define ins             insert
#define sb              substr
#define con             continue
#define ub              upper_bound
#define lb              lower_bound
#define bp              __builtin_popcountll
#define pll             pair<ll,ll>
#define pld             pair<ld,ld>
#define take(v,n)       for(i=0;i<n;i++) cin>>v[i];
#define print(any)      for(auto i:any) cout<<i<<" ";
#define ee              endl
#define pb              push_back
#define vll             vector<ll>
#define vld             vector<ld>
#define vvll            vector< vector<ll> >
#define vvld            vector< vector<ld> >
#define mll             map<ll,ll>
#define umll            unordered_map<ll,ll>
#define f(i,x,y)        for(ll i=x;i<y;i++)
#define INF             LLONG_MAX
#define fast            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<" ";
#define yes             cout<<"YES"<<endl
#define no              cout<<"NO"<<endl
#define mod             1000000007
using namespace std;

ll power(ll x, ll y);
ll mpower(ll x, ll y, ll p);
ll modInv(ll a, ll m);
ll gcdExtended(ll a, ll b, ll *x, ll *y);
bool isPrime(ll n);

void slv()
{
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,t,u,w,x,y,z;
    string s,s1,s2;
    char ch;
    cin>>n;
    vll ar={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    mll mp;
    vll num(n);
    take(num,n);

    k=1;
    ll ans=INF;
    while(k<(1<<16))
    {
        p=k;
        c=1;
        f(i,0,15)
        {
            if(p&1) c*=ar[i];
            p=p>>1;
        }
        a=1;
        f(i,0,n)
        {
            if(__gcd(c,num[i])==1)
            {
                a=0;
                break;
            }
        }
        if(a)  ans=min(ans,c);
        k++;
    }
    cout<<ans<<ee;
}

int main()
{
    fast
    ll t;
    t=1;
    //cin>>t;
    //fun();
    while(t--)
    {
        slv();
    }
    return 0;
}

/*

*/

ll modInv(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}

ll mpower(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while(y > 0){
        if(y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(b==0)return a;
	return gcd(b,a%b);
}

int main(){
	int n;
	scanf("%d",&n);
	long long arr[n];
	for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
	long long p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
	long long ans=1012345678012345678LL;
	for(int i=0;i<(1<<15);i++){
		long long prod=1;
		int bm=i;
		while(bm&(-bm)){
			prod*=p[__builtin_ctz(bm)];
			bm-=(bm&(-bm));
		}
		bool poss=1;
		for(int j=0;j<n;j++){
			if(gcd(prod,arr[j])==1){poss=0;break;}
		}
		if(poss)ans=min(ans,prod);
	}
	printf("%lld",ans);
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    long double X, Y, R;
    cin >> X >> Y >> R;

    X = abs(X) + abs(ceil(R));
    Y = abs(Y) + abs(ceil(R));

    long long answer = 0;
    for(long long x = ceil(X - R); x <= X + R; ++x){
        long double dx = abs(X - x);
        long double dy = sqrt(R * R - dx * dx);
        long long y1 = floor(Y + dy);
        long long y2 = ceil(Y - dy);
        answer += (y1 - y2 + 1);
    }

    cout << answer;

    return 0;
}

#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
enum{N=200007};
int n,A[N],C[N];
map<int,vector<int> > G;
void upd(int u,int k=-1) {
	for(;u<=n;u+=u&-u) C[u]+=k;
}
int sum(int u) {
	int r=0;
	for(;u;u&=u-1) r+=C[u];
	return r;
}
int main() {
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&A[i]),upd(i,1);
	Dor(i,n,1) G[A[i]+i].push_back(i);
	LL ans=0;
	For(i,1,n) {
		int x;
		scanf("%d",&x);
		if(G[x+i].empty()) puts("-1"),exit(0);
		ans+=sum(G[x+i].back())-1;
		upd(G[x+i].back()),G[x+i].pop_back();
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int nt[5005];
int na[5005];
int ng[5005];
int nc[5005];

int sum(int* ar, int l, int r) {
    --l;
    return ar[r] - ar[l];
}

int main() {
    fastio;
    ll ans=0;
    ll N;
    string s;
    cin >> N >> s;
    rep1(i,N) {
        nt[i] = nt[i-1];
        na[i] = na[i-1];
        ng[i] = ng[i-1];
        nc[i] = nc[i-1];
        if (s[i-1] == 'A') ++na[i];
        if (s[i-1] == 'T') ++nt[i];
        if (s[i-1] == 'C') ++nc[i];
        if (s[i-1] == 'G') ++ng[i];
    }
    rep(j,N) rep(i,j) {
        int l = i+1, r = j+1;
        if (sum(nt, l, r) < sum(na, l, r))
            continue;
        if (sum(na, l, r) < sum(nt, l, r))
            continue;
        if (sum(nc, l, r) < sum(ng, l, r))
            continue;
        if (sum(ng, l, r) < sum(nc, l, r))
            continue;
        ++ans;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define vll vector<long long>
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL);

int lcm(int a, int b) { return (a / __gcd(a, b)) * b; }

ll bigMod(ll b, ll e, ll mod) {
    if (e == 0) return 1 % mod;
    if (e % 2 == 0) {
        ll half = bigMod(b, e / 2, mod);
        return half * half % mod;
    } else return bigMod(b, e - 1, mod) * b % mod;
}
void factors(ll n) {
    int i, j;
    vll arr;
    for (i = 1; i  <= sqrt(n); i++)
        if (n % i == 0) {
            j = n / i;
            arr.push_back(i);
            if (i != j)
                arr.push_back(i);
        }
}

#define pi acos(-1)

#define all(x) x.begin(), x.end()
#define pb push_back
#define endl "\n"
#define decimal(p) fixed<<setprecision(p)

#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vd vector<double>

#define pfd(x) printf("%d\n", x)
#define pfc(x) printf("%c\n", x)
#define pfs(x) printf("%s\n", x)

#define scd(x) scanf("%d", &x)
#define scc(x) scanf("%c", &x)
#define scf(x) scanf("%f", &x)
#define scs(x) scanf("%s", x)

#define msi map<string, int>
#define msc map<string, char>
#define msf map<string, double>
#define msd map<string, double>
#define mx 100000000000

int main() {

    vi arr;
    int x;
    for (int i = 0; i < 4; ++i) {
        cin>>x;
        arr.push_back(x);

    }

    sort(all(arr));
    cout<<arr[0]<<endl;

    return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

int C[5][5];
int nCr(int n,int r){
   if(C[0][0]==0){
      rep(i,0,5){
         C[i][0]=C[i][i]=1;
         rep(j,1,i){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%3;
         }
      }
   }
   int res=1;
   rep(_,0,30){
      res*=C[n%3][r%3];
      n/=3,r/=3;
   }
   return res;
}

int main(){
   int n;
   cin>>n;
   string s;
   cin>>s;

   int res=0;
   rep(i,0,n){
      if(s[i]=='R')continue;
      if(s[i]=='W')res=(res+nCr(n-1,i))%3;
      if(s[i]=='B')res=(res+nCr(n-1,i)*2)%3;
   }
   if(!(n&1))res=(3-res)%3;
   if(res==0)puts("R");
   if(res==1)puts("W");
   if(res==2)puts("B");
   return 0;
}

// give up
#include <bitset>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <list>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <valarray>

// alias, using declaration
using llint = long long; using ldouble = long double;
template <class T = llint> using vector = std::vector<T>;
template <class T = llint> using deque = std::deque<T>;
template <class T = llint> using list = std::list<T>;
template <class T = llint, class U = llint> using umap = std::unordered_map<T, U>;
template <class T = llint, class U = llint> using ummap = std::unordered_multimap<T, U>;
template <class T = llint> using uset = std::unordered_set<T>;
template <class T = llint> using umset = std::unordered_multiset<T>;
template <class T = llint, class U = T> using pair = std::pair<T, U>;
template <class T = llint> using varray = std::valarray<T>;
template <class T = llint, class U = vector<T>, class V = std::less<class U::value_type>> using pqueue = std::priority_queue<T, U, V>;
using std::array; using std::bitset; using std::string; using std::tuple;

// constant
constexpr llint INF = 0x7FFFFFFFFFFFFFFF;
constexpr llint INVALID = 0x8000000000000000;

namespace io {
  // in
  template <class... T, size_t... S> auto in(std::index_sequence<S...>) {tuple<T...> t; (..., (std::cin >> std::get<S>(t))); return t;}
  template <class... T, size_t... S> auto in(std::index_sequence<S...>, size_t n) {tuple<vector<T>...> t{vector<T>(n)...}; for (size_t i = 0; i < n; i++) (..., (std::cin >> std::get<S>(t)[i])); return t;}
  template <size_t N, class T = llint, class... U> auto in() {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(); else return in<T, U...>(std::index_sequence_for<T, U...>());}
  template <size_t N, class T = llint, class... U> auto in(size_t n) {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(n); else return in<T, U...>(std::index_sequence_for<T, U...>(), n);}
  template <size_t N, class T = llint> auto in(size_t n, size_t m) {static_assert(N == 1); vector<vector<T>> v(n, vector<T>(m)); for (auto&& vi : v) for (auto&& vij : vi) std::cin >> vij; return std::make_tuple(v);}
  // out
  template <class T, class... U> void out(const T& a, const U&... b) {std::cout << a << (sizeof...(b) ? " " : "\n"); if constexpr (sizeof...(b)) out(b...);}
  template <class T, class U = const char*> void out(const vector<T>& a, U d = " ") {for (auto&& b : a) std::cout << b << (&b != &a.back() ? d : "\n");}
}

int main() {
  // input
  auto [N, c] = io::in<1, llint, string>();

  // solve
  umap<char> c2n = {{'B', 0}, {'W', 1}, {'R', 2}};
  vector<> f(N), g(N);
  g[0] = 1;
  for (llint i = 1; i < N; i++) {
    g[i] = i;
  }
  for (llint i = 3; i < N; i *= 3) {
    for (llint j = i; j < N; j += i) {
      f[j]++;
      g[j] /= 3;
    }
  }
  for (llint i = 1; i < N; i++) {
    f[i] += f[i - 1];
    g[i] = (g[i - 1] * g[i]) % 3;
  }
  auto bc_mod3 = [&f, &g](llint n, llint r) {
    return f[n] - f[r] - f[n - r] > 0 ? 0 : (g[n] * g[r] * g[n - r]) % 3;
  };
  llint n_top = 0;
  for (llint i = 0; i < N; i++) {
    n_top += c2n[c[i]] * bc_mod3(N - 1, i);
  }
  n_top %= 3;
  if (~N & 1) {
    n_top = (3 - n_top) % 3;
  }
  char result = array<char, 3>{'B', 'W', 'R'}[n_top];

  // output
  io::out(result);
}