#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, k;
    cin >> n >> k;
    vector<vector<int>> t(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> t[i][j];
        }
    }

    int ans = 0;

    // 全探索

    vector<int> order(n - 1);
    iota(order.begin(), order.end(), 1);
    do {
        int time = t[0][order.front()];
        for (int i = 1; i < n - 1; i++) {
            time += t[order[i]][order[i - 1]];
        }
        time += t[order.back()][0];

        if (time == k) ans++;

    } while (next_permutation(order.begin(), order.end()));

    cout << ans << "\n";
}

#include "bits/stdc++.h"
#pragma GCC optimize "trapv"

#define int long long int
#define For(i,a,b) for(int  i=a;i<b;i++)

#define pb push_back
#define endl "\n"

#define F first
#define S second

#define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()

#define TEST_CASE int  t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);

using namespace std;
const int MOD = 1e9 + 7;

void print()  {    cout<<endl;  }
void printArray()  {    return;  }
void read() { return; }

template<typename T , typename... Args>  void print(T a , Args... arg)    {    cout << a << " " ;    print(arg...);    }

template<typename T , typename... Args> void read(T &a , Args&... arg) {   cin >> a;   read(arg...);   }

template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) {  for(auto &i : v)  cin>>i;  read(arg...);  }

template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) {   for(auto i : v)     cout<<i<<" ";   cout<<endl;  printArray(arg...);    }

int power(int a,int b) { int  res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; }

int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }

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

int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }

int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }

int Time[11][11];

int timeTaken(vector<int>&v)
{
    int t = 0 , n = v.size(),last = 1;
    For(i,0,n)
    {
        t = t + Time[last][v[i]];
        last = v[i];
    }
    t += Time[last][1];
    return t;
}

void runCase_()
{
    int n,k;
    read(n,k);
    For(i,1,n+1)
        For(j,1,n+1)
            read(Time[i][j]);
    vector<int>v;
    int ans = 0;
    For(i,2,n+1) v.pb(i);
    do
    {
        int t = timeTaken(v);
        // printArray(v);
        // debug(t);
        if(t == k) ++ans;
    }
    while(next_permutation(all(v)));
    print(ans);
}

signed main()
{
    drink_boost;
    // TEST_CASE
    runCase_();
    return 0;
}

/** TEST CASES HERE **/
/*

*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
using Graph = vector<vector<int>>;

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> s(h+2, vector<char>(w+2, '.'));
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)
      cin >> s[i][j];

  int ans = 0;
  for(int i=0;i<=h;i++){
    int c=0;
    for(int j=1;j<=w;j++)
    {
      if(s[i][j]==s[i+1][j]){
        c = 0;
      }else{
        if(c==0) ans++;
        c++;
      }
    }
  }

  for(int j=0;j<=w;j++){
    int c = 0;
    for(int i=1;i<=h;i++){
      if(s[i][j]==s[i][j+1]){
        c = 0;
      }else{
        if(c==0) ans++;
        c++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

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 T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> G[n][26];
    bool E[n][n];
    rep(i, n) rep(j, n) E[i][j] = false;
    rep(i, m) {
        int a, b;
        char c;
        scanf("%d%d %c", &a, &b, &c);
        --a;
        --b;
        G[a][c - 'a'].push_back(b);
        G[b][c - 'a'].push_back(a);
        E[a][b] = E[b][a] = true;
    }
    rep(i, n) rep(c, 26) {
        sort(G[i][c].begin(), G[i][c].end());
        G[i][c].erase(unique(G[i][c].begin(), G[i][c].end()), G[i][c].end());
    }

    int d[n][n];
    rep(i, n) rep(j, n) d[i][j] = mod;
    d[0][n - 1] = 0;
    queue<pii> que;
    que.emplace(0, n - 1);
    while (!que.empty()) {
        auto [u, v] = que.front();
        if (E[u][v]) {
            printf("%d\n", d[u][v] + 1);
            return 0;
        }
        que.pop();
        rep(c, 26) for (auto nu : G[u][c]) for (auto nv : G[v][c]) {
            if (chmin(d[nu][nv], d[u][v] + 2)) {
                if (nu == nv) {
                    printf("%d\n", d[nu][nv]);
                    return 0;
                }
                que.emplace(nu, nv);
            }
        }
    }
    puts("-1");
}


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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	a=a+b+c;
	a=21-a;
	cout<<a;
}

#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    if(A-B==0){
        if(C==0){
            cout<<"Aoki"<<endl;
        }else{
            cout<<"Takahashi"<<endl;
        }
    }else if(A-B>0){
        cout<<"Takahashi"<<endl;
    }else{
        cout<<"Aoki"<<endl;
    }
    return 0;
}


//{{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VLL = vector<LL>;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

int prm[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
LL a, b;

LL dp[2][1 << 20];

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> a >> b)
    {
        int cur = 0;
        clr(dp[cur], 0);
        dp[cur][0] = 1;
        for (LL i = a; i <= b; i++)
        {
            memcpy(dp[cur ^ 1], dp[cur], sizeof(dp[cur]));
            int mask = 0;
            for (int j = 0; j < 20; j++)
                if (i % prm[j] == 0) mask |= (1 << j);

            for (int pres = 0; pres < (1 << 20); pres++)
            {
                if ((pres & mask) != 0) continue;
                dp[cur ^ 1][pres | mask] += dp[cur][pres];
            }
            cur ^= 1;
        }

        LL ans = 0;
        for (int i = 0; i < (1 << 20); i++) ans += dp[cur][i];
        cout << ans << endl;
    }

    return 0;
}

#include <vector>
#include <iostream>

#define int         long long
#define double      long double
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

signed main() {
    tezz

    vector<int> primes;
    for (int i = 2; i < 72; i++) {
        bool flag = true;
        for (int j = 2; j < i; j++) {
            if (i % j == 0) flag = false;
        }
        if (flag) primes.emplace_back(i);
    }

    int A, B;
    cin >> A >> B;
    vector<int> v(B - A + 1);
    for (int i = A; i <= B; i++) {
        int mask = 0;
        for (int j = 0; j < primes.size(); j++) {
            if (i % primes[j] == 0) {
                mask |= (1 << j);
            }
        }
        v[i - A] = mask;
    }

    vector<int> dp(1<<primes.size());
    dp[0] = 1;
    for (int x: v) {
        for (int mask = 0; mask < (1 << primes.size()); mask++) {
            if (dp[mask]&&(mask & x)==0) {
                dp[mask ^ x] += dp[mask];
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << primes.size()); i++) ans += dp[i];
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll  vector<ll>
const int inf = 1e9 + 7;
const int MOD = 1e9 + 7;

void solve(){
  int n , a,  b;
  cin >> n >> a >> b;
  cout << (n - a + b) << endl;
}

int main(){
    ios :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
    // cin >> tt;
    for(int tc = 1; tc <= tt; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define DBG 1
#define debg(a) if(DBG) cout<<#a<<": "<<a<<endl;
#define out(a) debg(a);
#define aout(a) for(auto&e:a)cout<<e<<" ";
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
// template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    cout << N-A+B << endl;
    return 0;
}


/**
 * @file:           A.cpp
 * @author:         yaoxi-std
 * @description:    A.cpp
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define resetIO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
#define testcases int T; read(T); while(T --)
#define debug(fmt, ...) fprintf(stderr, "[%s:%d] " fmt, __FILE__, __LINE__, ## __VA_ARGS__)
#define debug_var(var) cerr << #var" = " << var << endl
#define debug_arr(arr, n) cerr << #arr" = ["; for(int _i=1; _i<=n; _i++) \
        cerr << arr[_i] << (_i == n ? "]\n" : ", ")
#define debug_vec(vec) cerr << #vec" = ["; for(int _i=0; _i<vec.size(); _i++) \
        cerr << vec[_i] << (_i == vec.size() - 1 ? "]\n" : ", ")
template<class T> inline void read(T &x){
    T f = 1; x = 0; char ch = getchar();
    for( ; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -f;
    for( ; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= f;
}
template<class T> inline void write(T x){
    if(x < 0) { putchar('-'); x = -x; }
    if(x > 9) write(x / 10); putchar((x % 10) ^ 48);
}
const int maxn = 1005;
const int maxm = 1e5+5;
const int inf = 1LL << 60;
const int ddx[4] = { -1, 0, 1, 0 };
const int ddy[4] = { 0, -1, 0, 1 };
const char dchr[4] = { 'U', 'L', 'D', 'R' };
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, -1, 0, 1 };
char chr[4] = { 'U', 'L', 'D', 'R' };
int n, sx, sy, t[maxn][maxn], p[maxn][maxn], mx, mxstp, cnt;
int ord[maxm];
char mxord[maxm];
bool vis[maxm];
bool dfs(int x, int y, int sc, int stp){
    ++ cnt;
    if(stp > 1000) return false;
    if(sc > mx){
        mx = sc; mxstp = stp;
        for(int i=1; i<stp; i++) mxord[i] = chr[ord[i]];
    }
    if(cnt > 4000000) return true;
    for(int i=0; i<4; i++){
        int tx = x + dx[i];
        int ty = y + dy[i];
        if(tx < 1 || ty < 1 || tx > n || ty > n) continue;
        if(vis[t[tx][ty]]) continue;
        vis[t[tx][ty]] = true;
        ord[stp] = i;
        if(dfs(tx, ty, sc + p[tx][ty], stp + 1)){
            vis[t[tx][ty]] = false;
            return true;
        }
        vis[t[tx][ty]] = false;
    }
    return false;
}
signed main(){
    n = 50;
    read(sx); read(sy); sx ++; sy ++;
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) read(t[i][j]);
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) read(p[i][j]);
    vis[t[sx][sy]] = true;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                for(int l=0; l<4; l++){
                    if(i == j || j == k || k == l ||
                       i == k || i == l || j == l) continue;
                    dx[0] = ddx[i]; dy[0] = ddy[i]; chr[0] = dchr[i];
                    dx[1] = ddx[j]; dy[1] = ddy[j]; chr[1] = dchr[j];
                    dx[2] = ddx[k]; dy[2] = ddy[k]; chr[2] = dchr[k];
                    dx[3] = ddx[l]; dy[3] = ddy[l]; chr[3] = dchr[l];
                    memset(vis, false, sizeof(vis)); cnt = 0;
                    vis[t[sx][sy]] = true;
                    dfs(sx, sy, 0, 1);
                }
            }
        }
    }
    for(int i=1; i<mxstp; i++) putchar(mxord[i]);
    putchar('\n');
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
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; }

//==================param==========
ll depth = 10;
//=================================

ll si, sj;
vector<vector<ll>> board(50, vector<ll>(50));
vector<vector<ll>> point(50, vector<ll>(50));
map<ll, bool> already;
vector<char> way_char = {'R', 'D', 'L', 'U'};
vector<vector<ll>> ways = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
stack<ll> max_ans;
stack<ll> ans;
stack<ll> est;
ll max_point = 0;
ll now_point = 0;
clock_t start;
mt19937 mt{random_device{}()};
uniform_int_distribution<int> dist(0, 3);
uniform_int_distribution<int> choose_way(0, 23);

vector<vector<ll>> all_ways;

void get_input() {
  cin >> si >> sj;
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> board.at(i).at(j);
    }
  }
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> point.at(i).at(j);
    }
  }
  already[board.at(si).at(sj)] = true;

  for (ll i = 0; i < 4; ++i) {
    for (ll j = 0; j < 4; ++j) {
      for (ll k = 0; k < 4; ++k) {
        for (ll l = 0; l < 4; ++l) {
          set<ll> temp_st;
          temp_st.insert(i);
          temp_st.insert(j);
          temp_st.insert(k);
          temp_st.insert(l);
          if (temp_st.size() != 4) {
            continue;
          }
          all_ways.push_back({i, j, k, l});
        }
      }
    }
  }
}

bool can_move(ll way) {
  ll nh = si + ways.at(way).at(0), nw = sj + ways.at(way).at(1);
  if (nh < 0 || nw < 0 || nh >= 50 || nw >= 50) {
    return false;
  }
  if (already[board.at(nh).at(nw)]) {
    return false;
  }
  return true;
}

void make_move(ll way) {
  si += ways.at(way).at(0), sj += ways.at(way).at(1);
  already[board.at(si).at(sj)] = true;
  ans.push(way);
  now_point += point.at(si).at(sj);
  if (now_point > max_point) {
    max_ans = ans;
    max_point = now_point;
  }
}
void rev_move() {
  ll way = ans.top();
  ans.pop();
  now_point -= point.at(si).at(sj);
  already[board.at(si).at(sj)] = false;
  si -= ways.at(way).at(0), sj -= ways.at(way).at(1);
}

ll cnt = 0;
bool fin = false;
ll last = 0;
vector<ll> now_ways;
void dfs() {
  if (fin) {
    return;
  }
  cnt += 1;
  if (cnt % 1000 == 0) {
    clock_t end = clock();
    ld time = (ld)(end - start) / CLOCKS_PER_SEC * 1000.0;
    if (time > 1900 || time - last >= 100) {
      fin = true;
      last = time;
      return;
    }
  }
  for (ll i = 0; i < 4; ++i) {
    ll w = now_ways.at(i);
    if (can_move(w)) {
      make_move(w);
      dfs();
      rev_move();
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  start = clock();
  get_input();
  while (true) {
    now_ways = all_ways.at(choose_way(mt));
    dfs();
    if (last > 1900) {
      break;
    }
    uniform_int_distribution<int> temp(max(0ll, (ll)ans.size() - 5), (ll)ans.size());
    for (ll i = 0; i < temp(mt); ++i) {
      rev_move();
    }
    // ans = est;
    // now_point = 0;
    fin = false;
  }
  string s_ans = "";
  while (!max_ans.empty()) {
    s_ans += way_char.at(max_ans.top());
    max_ans.pop();
  }
  reverse(rng(s_ans));
  cout << s_ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;//1152921504606846976
const int mod = 1000000007;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;cin>>n>>m;
    vector<ll> a(n);rep(i,n)cin>>a[i];
    set<ll> st;
    rep(i,n+1)st.insert(i);
    vector<ll> cnt(n,0);
    ll ans = INF;
    rep(i,n){
        st.erase(a[i]);
        cnt[a[i]]++;
        if(i>=m){
            cnt[a[i-m]]--;
            if(cnt[a[i-m]]==0)st.insert(a[i-m]);
        }
        if(i>=m-1){
            ans = min(ans, *st.begin());
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ri register signed
#define rd(x) x=read()
#define pos(x) ((((x)-1)/sz)+1)
using namespace std;
const int N=5e5+5;
const int M=3e7+5;
int mod=998244353;
inline int read(){int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline int ksm(int x,int y=mod-2,int z=mod){int ret=1;while (y){if (y&1) ret=(ret*x)%z;x=(x*x)%z;y>>=1;}return ret;}
int n;
struct Node
{
    int a,c;
}p[N];
bool cmp(Node x,Node y){return x.a<y.a;}
char ch[N];
int num[N];
int a,b,c,ans,ans2,ans1,ans3,ans4;
int laa,lab,posa,posb,lac,lapc;
signed main()
{
    rd(n);n*=2;
    for (int i=1;i<=n;i++)
    {
        rd(p[i].a);
        scanf("%s",ch);
        if (ch[0]=='R') p[i].c=0;
        if (ch[0]=='G') p[i].c=1;
        if (ch[0]=='B') p[i].c=2;
        num[p[i].c]++;
    }
    sort(p+1,p+n+1,cmp);
    if (num[0]%2==0 && num[1]%2==0) {puts("0");return 0;}
    if (num[0]%2==0) a=1,b=2,c=0;
    if (num[1]%2==0) a=0,b=2,c=1;
    if (num[2]%2==0) a=0,b=1,c=2;
    ans=ans1=ans2=ans3=ans4=1e18;
    laa=lab=-1e16;
    //for (int i=1;i<=n;i++) printf("%lld %lld\n",p[i].a,p[i].c);
    for (int i=1;i<=n;i++)
    {
        if (p[i].c==a) ans=min(ans,p[i].a-lab),laa=p[i].a;
        if (p[i].c==b) ans=min(ans,p[i].a-laa),lab=p[i].a;
    }
    laa=lab=lac=-1e16;
    for (int i=1;i<=n;i++)
    {
        if (p[i].c==c)
        {
            if (p[i].a-laa<ans1) ans1=p[i].a-laa,posa=i;
            lapc=i;lac=p[i].a;
        }
        if (p[i].c==a)
        {
            if (p[i].a-lac<ans1) ans1=p[i].a-lac,posa=i;
            laa=p[i].a;
        }
    }
    laa=lab=lac=-1e16;
    for (int i=1;i<=n;i++)
    {
        if (p[i].c==c)
        {
            if (p[i].a-lab<ans2) ans2=p[i].a-lab,posb=i;
            lapc=i;lac=p[i].a;
        }
        if (p[i].c==b)
        {
            if (p[i].a-lac<ans2) ans2=p[i].a-lac,posb=i;
            lab=p[i].a;
        }
    }
    cout<<min(ans,ans1+ans2)<<endl;
}


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

#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
#define uwu ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize("Ofast")

const int INF = 1e9 + 7;
const long long INF2 = 1e17;

int main(void) {
	uwu

	set <int> s;
	for(int i = 6; i <= 10000; i += 6) s.insert(i);
	for(int i = 10; i <= 10000; i += 10) s.insert(i);
	for(int i = 15; i <= 10000; i += 15) s.insert(i);

	vector <int> v;
	for(auto x: s) v.push_back(x);
	swap(v[2], v[3]);

	int n; cin >> n;
	ffor(n) cout << v[i] << ' ';
	cout << '\n';
}
/*
C:\Users\kenne\OneDrive\Desktop\competitive_programming\main.cpp
*/

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <bits/stdc++.h>
using namespace std;

#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define MAX 1000005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}

const int PRIMERANGE = 1000000;
int prime[PRIMERANGE + 1];
int getPrime()
{
    memset (prime, 0, sizeof (int) * (PRIMERANGE + 1));
    for (int i = 2; i <= PRIMERANGE; i++)
    {
        if (!prime[i]) prime[++prime[0]] = i;
        for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++)
        {
            prime[prime[j]*i] = 1;
            if (i % prime[j] == 0) break;
        }
    }
    return prime[0];
}

int main () {
    ll n; cin >> n;
    // getPrime();
    // vector<ll> ans;
    // ans.push_back(30);
    vector<ll> base;
    unordered_map<int, int> hash;
    int i = 15;
    base.push_back(15); hash[15] = 1;
    base.push_back(10); hash[10] = 1;
    base.push_back(6);  hash[6] = 1;
    while (i < 10000) {
        if (!hash[i])
            base.push_back(i);hash[i] = 1;
        i += 15;
    }
    i = 10;
    while (i < 10000) {
        if (!hash[i])
            base.push_back(i);hash[i] = 1;
        i += 10;
    }
    i = 6;
    while (i < 10000) {
        if (!hash[i])
            base.push_back(i);hash[i] = 1;
        i += 6;
    }
    for (int i = 0; i < n; ++i) cout << base[i] << ' ';
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x, y, r;
        cin >> x >> y >> r;
        cout << x << " " << y << " " << x + 1 << " " << y + 1 << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
ll q_p(ll x,ll y){
	ll res=1;
	x%=mod;
	while(y){
		if(y%2){
			res=res*x;
			res%=mod;
		}
		y/=2;
		x=x*x;
		x%=mod;
	}
	re res;
}
long double r,x,y,j;
int main(){
	ios::sync_with_stdio(0);
	cin>>r>>x>>y;
	j=sqrt(x*x+y*y);
	if(j<r){
		cout<<2;
		re 0;
	}
	int ans=(int)j/r;
	j-=ans*r;
	if(j)
	ans++;
	cout<<ans;
	re 0;
}
/*
检查循环是rep(i,n)还是rep(i,m)!!
long long所要的时间比int长!!
没有long long必要不写long long!!
写公式前先想一想!!
二分前看一看边界对不对，有没有特殊值!!
提交前要测特殊数据（边界上的）!!
*/

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

int main(){
  double r,x,y;
  ll hosu = 0;
  cin >> r >> x >> y;
  if(sqrt(x * x + y * y) / r < 1){
    hosu = 2;
  }
  else{
    hosu = ceil(sqrt(x * x + y * y) / r);
  }
  cout << hosu;
}


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

int main(){//cout<<fixed<<setprecision(20);
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2])cout<<"Won"<<endl;
  else cout<<"Lost"<<endl;
}

const bool isDebugMode = true;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const int SHOWSIZE = 1 << 5;
const long long MOD = 1000000007; //998244353;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
const string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
long long power(long long a, long long n){long long res = 1; while(n > 0){if(n & 1)res = res * a; a = a * a; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)){rep(j, min(v[i].size(), SHOWSIZE)) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;}
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); }
template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v){for (auto &e : u) fill_v<T>(e, v...);}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

void solve();

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // cin >> testcase;
    while(testcase--) solve();
    return 0;
}

void solve(){
    char a, b, c; cin >> a >> b >> c;
    pt((a == b && b == c ? "Won" : "Lost"));
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int M, H;
    cin >> M >> H;
    if (H % M == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
}

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

int main(){
  int N,W;
  cin>>N>>W;
  cout<<N/W<<endl;
}


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

int main() {
    float a,b;
    cin>>a>>b;
    cout<<a/100*b<<endl;
}

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

int main() {
  long long T;
  cin>>T;
  for(long long a=0;a<T;a++){
    long long L,R;
    cin>>L>>R;
    if(R>=2*L){
      cout<<((R-2*L+1)*(1+R-2*L+1))/2<<endl;
    }
    else{
      cout<<'0'<<endl;
    }

  }
}


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

int main(void)
{
  int64_t N, K;
  cin >> N >> K;

  for (int i = 0; i < K; i++)
  {
    if (N % 200 == 0)
    {
      N /= 200;
    }
    else
    {
      N = N * 1000 + 200;
    }
  }
  cout << N;
}

#include <bits/stdc++.h>
using namespace std;//gcd=__gcd swap(a,b)
typedef long long ll;
ll md=1e9+7;
#define pb push_back
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pair<int,int>> vii;
typedef vector<pair<ll,ll>> vll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef unsigned long long ull;
#define mp make_pair
ull PowMod(ull a,ull n)
{
    ull ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * a % md;
        a = a * a % md;
        n >>= 1;
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,p;
    cin>>n>>p;
    ll a=PowMod(p-2,n-1);
    cout<<a*(p-1)%md;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define __ template<typename T, typename... Types>
void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);}
void o() {rt;}  __ void o(T a, Types... b){cout<<(a);sp; o(b...);}
#define fr(Hi,a,n) for(ll Hi=a;Hi<=n;Hi++)
#define frm(Hi,a,n) for(ll Hi=n;Hi>=a;Hi--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=998244353;
ll ar[AS],br[AS],xr[AS],tem[AS];
ll dp[107][5007];
int main()
{
    fast;
    in(n);
    fr(i,1,n)in(ar[i]),c+=ar[i];
    if(c%2){o(0);rt 0;}
    c/=2;
    dp[0][0]=1;
    xr[0]=1;
    fr(k,1,n)
    {
        xr[k]=(xr[k-1]*k)%mod;
        frm(i,1,n)
        {
            frm(j,ar[k],c)
            {
                dp[i][j]+=dp[i-1][j-ar[k]];
                dp[i][j]%=mod;
            }
        }
    }
    ll ans=0;
    fr(i,1,n)
    {
        ans=(ans+dp[i][c]*xr[i]%mod*xr[n-i]%mod)%mod;
    }
    o(ans);
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>
#include <cstddef>
#include <type_traits>
#include <vector>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i, n) for(int i=0;i<(int)(n);i++)

int main() {

  int n; cin >> n;
  vector<vector<lint>> dp(n + 1, vector<lint>(2, 0));
  dp[0][0] = 1;
  dp[0][1] = 1;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    for (int j = 0; j < 2; j++) {
      if (dp[i][j] == 0) continue;

      for (int jj = 0; jj < 2; jj++) {
        int nj;
        if (s == "AND") nj = j & jj;
        else            nj = j | jj;

        dp[i + 1][nj] += dp[i][j];
      }
    }
  }

  cout << dp[n][1] << endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <bitset>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i=0;i<N;i++)
    cin >> s.at(i);

  long long t=1;
  long long f=1;

  for(int j=0; j<N; j++){
    if(s.at(j)=="AND"){
      f= f*2 + t;
    }else{
      t = t*2 + f;
    }
  }
  cout << t << endl;
}


#include<bits/stdc++.h>
#define N 105
using namespace std;
int n,a[N],ans=1e9;
char s[N];
int Abs(int x) {
	return x<0?-x:x;
}
int main() {
	scanf("%d%s",&n,s+1);
	for(int i=0; i<=n; ++i) {
		scanf("%d",&a[i]);
		if(i>0)ans=min(ans,Abs(a[i]-a[i-1]));
	}
	cout<<ans<<"\n";
	for(int i=0; i<ans; ++i,puts(""))
		for(int j=0; j<=n; ++j)cout<<a[j]/ans+(i<a[j]%ans)<<" ";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

ll N = 50;
ll sy,sx;
vector<vector<ll>> T(N),P(N);

pair<ll,string> eval(string K){

    bool visited[2500]={};
    string R;
    ll score = 0;

    ll y=sy,x=sx;
    visited[T[y][x]]=true;
    score += P[y][x];

    REP(i,K.size()){
        if(K[i]=='L'){
            x--;
        }else if(K[i]=='R'){
            x++;
        }else if(K[i]=='D'){
            y++;
        }else{
            y--;
        }

        if(!(0<=x && x<N)){
            return {score,R};
        }
        if(!(0<=y && y<N)){
            return {score,R};
        }
        if(visited[T[y][x]]){
            return {score,R};
        }
        visited[T[y][x]]=true;
        score += P[y][x];
        R.push_back(K[i]);
    }
    return {score,R};
}

int main(void){

    cin >> sy >> sx;
    REP(i,N){REP(j,N){
        ll t;
        cin >> t;
        T[i].push_back(t);
    }}
    REP(i,N){REP(j,N){
        ll p;
        cin >> p;
        P[i].push_back(p);
    }}

    char C[4]={'L','R','U','D'};

    std::mt19937 mt{ std::random_device{}() };
    std::uniform_int_distribution<int> dist(0, 3);

    string dna = "";
    REP(i,N*N){dna.push_back(C[dist(mt)]);}
    ll rna = eval(dna).first;

    vector<ll> Per;
    REP(i,N*N){
        REP(j,max((N*N-i)/10,2ll)){
            Per.push_back(i);
        }
    }

    ll M = Per.size();
    std::mt19937 mt2{ std::random_device{}() };
    std::uniform_int_distribution<int> dist2(0, M-1);

    REP(j,240000){

        ll genes = rna;string gene = dna;

        REP(k,10){
            string S = dna;
            char c = C[dist(mt)];
            ll l = Per[dist2(mt2)];
            S[l]=c;

            pair<ll,string> Nd = eval(S);
            if(Nd.first>=genes){
                genes = Nd.first;
                gene = S;
            }

        }

        if(genes>=rna){
            rna = genes;
            dna = gene;
        }

    }

    dna = eval(dna).second;
    cout << dna << endl;

    /*
    ll score = 0;string K = "";
    REP(j,10000){

        string S;
        REP(i,N*N){
            S.push_back(C[dist(mt)]);
        }
        pair<ll,string> R = eval(S);
        if(score<=R.first){
            score = R.first;
            K = R.second;
        }

    }
    cout << K << endl;*/

    return 0;
}


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

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

  int count =0;
  while((X*X+Y*Y)-(R*(count+1))*(R*(count+1))>0)count++;

  if(((X*X+Y*Y)-(R*(count+1))*(R*(count+1))==0))count++;
  else count++;

  if(count==1&&(X*X+Y*Y)-(R*(count))*(R*(count))!=0)count++;
  cout << count << endl;

}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

#define mp make_pair
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(v) (v).begin(), (v).end()
#define endl "\n"
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#define files(name) ifstream fin(name".in"); ofstream fout(name".out");
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

const int mod = 1e9 + 7;
const int mxN = 101;
const int inf = 1e9;

void solve() {
    ll r, x, y;
    cin >> r >> x >> y;
    ll d = x*x+y*y;
    if(d==r*r) {
        cout << 1 << endl;
        return;
    }
    for(ll i=2;; ++i) {
        if(r*r*i*i>=d) {
            cout << i << endl;
            return;
        }

    }
}

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

    //int tt;
    //cin >> tt;
    //while(tt--) {
        solve();
    //}
    return 0;
}


/*input
2
1 1

*/

// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++)
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}
const ll NMax = 2e5+5,mod = 998244353;
vvi adj(NMax);
vi vis(NMax,0);
void dfs(ll u){
	vis[u] = 1;
	for(ll ch : adj[u]){
		if(vis[ch]==0) dfs(ch);
	}
	return ;
}

int solve()
{
	ll N;cin>>N;
	vi f(N);
	rep(i,0,N) { cin>>f[i]; f[i]--;  adj[i].pb(f[i]); adj[f[i]].pb(i); }

	ll ans = 0;
	rep(i,0,N){
		if(vis[i]==0){
			dfs(i);
			ans++;
		}
	}

	ll temp = 1;
	while(ans--) temp = (temp * 2)%mod;
	temp = (temp - 1)%mod;
	if(temp<0) temp+=mod;
	cout<<temp<<"\n";

	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

// Problem: B - Special Subsets
// Contest: AtCoder - AtCoder Regular Contest 114
// URL: https://atcoder.jp/contests/arc114/tasks/arc114_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define debug(a) cout << #a << ": " << a << endl
#define false_stdio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int maxn=2e5+5;

typedef long long ll;
using namespace std;
const ll mod=998244353;
int n;
ll cnt;
bool vis[maxn];
int f[maxn];
set<int> s;

bool dfs(int u){
	if(vis[u]) {
		if(s.count(u)) return 1;
		else return 0;
	}
	vis[u]=1;
	s.insert(u);
	return dfs(f[u]);
}

ll pow2(ll base,ll sup){
	ll res=1;
	while(sup){
		if(sup&1)res=res*base%mod;
		base=base*base%mod;
		sup>>=1;
	}
	return res;
}

int main() {
    false_stdio;
	cin>>n;
	for(int i=1;i<=n;i++){
		int v;cin>>v;
		f[i]=v;
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			s.clear();
			if(dfs(i)) cnt++;
		}
	}
	// debug(cnt);
	cout<<(pow2(2,cnt)-1+mod)%mod<<endl;
    return 0;
}


#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <fstream>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))
#define N 200005

int main(void) {
	int n;
	scanf("%d", &n);
	vector<ll> v;

	ll sum = 0;
	REP(i, n) {
		ll a, b;
		scanf("%lld%lld", &a, &b);
		sum += a;
		v.pb(2 * a + b);
	}

	SORT(v);
	int i = n - 1;
	int cnt = 0;
	while (i >= 0 && sum >= 0) {
		sum -= v[i];
		i--;
		cnt++;
	}

	printf("%d\n", cnt);
}

/***************************************************
* AUTHOR : Anav Prasad
* Nick : Vrangr
****************************************************/
#include <bits/stdc++.h>

using namespace std;

#define bline "\n"
#define fastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define forn(i, n) for (int i = 0; i < n; i++)
#define forsn(i, st_val, n) for (int i = st_val; i <= n; ++i)
#define pb(a) push_back(a)
#define pass (void)0
typedef long long int ll;
void print(vector<vector<int>> &arr){
	cout << "2d vector: \n";
	forn(i, arr.size()){
		forn(j, arr[i].size())
			cout << arr[i][j] << " ";
		cout << bline;
	}
}
void print(vector<int> &arr){
	cout << "1d vector: \n";
	forn(i, arr.size())
		cout << arr[i] << " ";
	cout << bline;
}

int main(){
	fastIO;
	int x, y;
	cin >> x >> y;
	if (x == y)
		cout << x;
	else{
		cout << (3 - x - y);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<cmath>
#define ll long long
#define N 100005

struct P{int x,y,w;}p[N];

ll n;

double ansx,ansy;

inline  double find(double x){
	double ans = 0;
	for(int i = 1;i <= n;++i)
	ans += (p[i].x + x - std::min((double)p[i].x,(double)(2 * x))) / (1.0 * n);
	return ans;
}

int main(){
//	freopen("q.in","r",stdin);
//	freopen("q.out","w",stdout);
	srand(273352);
	scanf("%lld",&n);
	for(int i = 1;i <= n;++i){
		scanf("%d",&p[i].x);
		ansx += p[i].x;	}
	ansx = (ansx) / (1.0 * n);
	ansy = 0x7f7f7f7f;
	double eps = 1e-15;
	double T = 200;//初始温度
	while(T > eps && ((double)(clock())/CLOCKS_PER_SEC)<1.9){//终止态
//		std::cout<<T<<" "<<(rand() * 2 - RAND_MAX) * T<<std::endl;
		double nowx = ansx + ((rand() * 2 - RAND_MAX + 1) * T);//在值域[ansx - t,ansx + t];中挑选一个随机数
		long double z = find(nowx) - find(ansx);
		if(z < 0)
		ansx = nowx,ansy = std::min(ansy,find(nowx));
		else
		if(exp(-z / T) * RAND_MAX > rand())//随机接受
		ansx = nowx;
		T *= 0.997;//降温速率
//		std::cout<<ansx<<std::endl;
	}
	printf("%.12lf\n",ansy);
}

#include<bits/stdc++.h>
#define For(i,j,k)  for(int i=j;i<=k;++i)
#define Dow(i,j,k)  for(int i=k;i>=j;--i)
#define ll long long
#define pb push_back
#define fir first
#define sec second
#define pb push_back
#define pa pair<int,int>
#define mk make_pair

using namespace std;

inline ll read()
{
    ll t=0,dp=1;char c=getchar();
    while(!isdigit(c))  {if(c=='-') dp=-1;c=getchar();}
    while(isdigit(c))   t=t*10+c-48,c=getchar();
    return t*dp;
}
inline void write(ll x){if(x<0)  {putchar('-');x=-x;}    if(x>=10)    write(x/10);putchar(x%10+48);}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
int main()
{
	ll N=read();
	ll f[233];
	ll x=0,y=0;
	f[0]=1;f[1]=2;
	int tot=1;
	For(i,2,100)
	{
		f[i]=f[i-1]+f[i-2];
		if(f[i]>N)	break;
		tot=i;
	}
	int top=0;
	int q[233];
	Dow(i,0,tot)
	{
		if(f[i]<=N)	q[++top]=i,N-=f[i];
	}
	reverse(q+1,q+top+1);
	int now=3;
	int tep=1;
	int ans[233],top_ans=0;
	For(i,1,tot+1)
	{
		ans[++top_ans]=now;
		if(now==3)	x=x+y;
		if(now==4)	y=x+y;
		if(q[tep]==i-1)
		{
			if(now==4)	ans[++top_ans]=1;
			else	ans[++top_ans]=2;
			++tep;
		}
		now=7-now;
	}
	writeln(top_ans);
	x=y=0;
	Dow(i,1,top_ans)
	{
		writeln(ans[i]);
		if(ans[i]==1)	x++;
		if(ans[i]==2)	y++;
		if(ans[i]==3)	x=x+y;
		if(ans[i]==4)	y=x+y;
	}
	// cout<<tot<<' '<<f[tot]<<endl;
	// cout<<x<<"=="<<y<<endl;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
	-- Benq
*/


#include<cstdio>
using namespace std;
typedef long long LL;
const int maxn=2000,maxt=maxn*maxn,MOD=1e9+7;

int n,m,ans,cnt,pw[maxt+5];char pic[maxn+5][maxn+5];
int U[maxn+5][maxn+5],D[maxn+5][maxn+5],L[maxn+5][maxn+5],R[maxn+5][maxn+5];

inline char readc(){
	static char buf[100000],*l=buf,*r=buf;
	return l==r && (r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
#define ADD(x,y) (((x)+(y))%MOD)
#define MUL(x,y) ((LL)(x)*(y)%MOD)
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			char ch=readc();while (ch!='.' && ch!='#') ch=readc();
			cnt+=ch=='.';pic[i][j]=ch;
		}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++) pic[i][j]=='.'?L[i][j]=L[i][j-1]+1:L[i][j]=0;
		for (int j=m;j>=1;j--) pic[i][j]=='.'?R[i][j]=R[i][j+1]+1:R[i][j]=0;
	}
	for (int j=1;j<=m;j++){
		for (int i=1;i<=n;i++) pic[i][j]=='.'?U[i][j]=U[i-1][j]+1:U[i][j]=0;
		for (int i=n;i>=1;i--) pic[i][j]=='.'?D[i][j]=D[i+1][j]+1:D[i][j]=0;
	}
	pw[0]=1;for (int i=1;i<=cnt+1;i++) pw[i]=(pw[i-1]<<1)%MOD;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			if (pic[i][j]=='#') continue;
			int now=L[i][j]+R[i][j]+U[i][j]+D[i][j]-3;
			ans=ADD(ans,MUL(pw[now]-1,pw[cnt-now]));
		}
	printf("%d\n",ans);
	return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define rev(v)  if(!v.empty())reverse(v.begin(),v.end())
#define PI 3.141592653589793238
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

pii find(ll b,ll c){

	if(c==0){
		return make_pair(b,b);
	}
	if(c%2){
		ll n=c/2;
		return make_pair(-b-n,-b+n);
	}

	return make_pair(b-c/2,b+c/2-1);
}

pii in(ll l,ll r,ll ss,ll se){
	return make_pair(max(ss,l),min(se,r));
}
void solve()
{
     ll b,c;
	 cin>>b>>c;

	 ll l=find(b,c).ff;
	 ll r=find(b,c).ss;

//	 cout<<l<<" "<<r<<endl;

	 ll ss=find(b,c-1).ff;
	 ll se=find(b,c-1).ss;

//	 cout<<ss<<" "<<se<<endl;
	 ll sl=in(l,r,ss,se).ff;
	 ll sr=in(l,r,ss,se).ss;

	 cout<<(max(0LL,r-l+1)+max(0LL,se-ss+1)-max(0LL,sr-sl+1));

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

//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();

//Good Bye!
    return 0;
}


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

#define ll long long

int main(){
    ll n;
    cin>>n;
    ll arr[n];
    ll m[201];
    memset(m,0,sizeof(m));

    for(ll i=0; i<n; i++){
        cin>>arr[i];
        m[arr[i]%200]++;
    }
    ll sum=0;

    for(int i=0; i<= 200; i++){
        sum += m[i]*(m[i]-1);
    }

    cout<<sum/2;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 1000000007;
using ll = long long;
vector<int> dx = {0,1,0,-1};
vector<int> dy = {-1,0,1,0};

long long pow(long long x,long long n){
    long long ans = 1;
    while(n != 0){
        long long a = x;
        long long z = 1;
        while(z*2 <= n){
            a *=a;
            a=a%mod1;
            z*=2;
        }
        ans*=a;
        ans=ans%mod1;
        n-=z;
    }
    return ans;
}//累乗 x^n

template<typename T>
void input_vec(vector<T> &A,long long N){
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    return;
}//入力を配列で受け取る

template<typename T>
void output_vec(vector<T> &A,long long N){
    for(int i = 0; i < N; i++){
        if(i != 0){
            cout << " ";
        }
        cout << A.at(i);
    }
    cout << endl;
    return;
}//配列を出力

template<typename T>
long long count_vec(vector<T> &A,T x){
    long long counter = 0;
    for(int i = 0; i < (int)A.size(); i++){
        if(A.at(i) == x){
            counter++;
        }
    }
    return counter;
}//配列内のxの個数をreturn

vector<char> change_vec(string s,int n){
    vector<char> ans(n);
    for(int i = 0; i < n; i++){
        ans.at(i) = s.at(i);
    }
    return ans;
}//文字列を配列に変換

int main(){
    ll N;cin >> N;
    vector<ll> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    for(int i = 0; i < N; i++){
        a.at(i) = a.at(i)%200;
    }
    sort(a.begin(),a.end());
    ll count = 1;
    ll lastnumber = a.at(0);
    ll ans = 0;
    for(int i = 0; i < N-1; i++){
        if(a.at(i+1) == lastnumber){
            count++;
        }
        else{
            ans += count*(count-1)/2;
            count = 1;
            lastnumber = a.at(i+1);
        }
    }
    ans += count*(count-1)/2;

    cout << ans << endl;
}


#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <cmath>

using namespace std;

int main() {
long long int n,x;
cin>>n>>x;
map<long long int,long long int> m;
//int ans=0;

int q=0;
long long int max=0;
for (int i = 0; i < n; i++)
{
    int a,b,c;
  cin>>a>>b>>c;
 m[a]+=c;
  m[b+1]-=c;
if (b>max)
{
    max=b;
}

}

for (auto p : m) {
  auto key = p.first;
  auto value = p.second;
 //cout<<key<<value<<endl;
}

long long int mon=0;
long long int ans=0;
bool big=false;
long long int before=0;
for (auto p : m)
{

if (p.first<=max)
{
  if (mon>x)
{
   ans+=(p.first-before)*x;
}
else
{
    ans+=(p.first-before)*mon;
}
before=p.first;
 mon+=p.second;
}

//cout<<p.first<<" "<<mon<<" "<<ans<<endl;

}

ans+=(max+1-before)*min(x,mon);
    cout<<ans<<endl;

}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, a) for(auto &x: (a))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PR pair
#define X first
#define Y second

void solve(){
	int n, g;
	cin >> n >> g;
	vector<ii> eve(n*2);
	FOR(i, 0, n){
		int a, b, c;
		cin >> a >> b >> c;
		eve.PB({a, c}), eve.PB({b+1, -c});
	}
	sort(eve.begin(), eve.end());
	int last = 0;
	ll ans = 0, akt = 0;
	TRAV(x, eve){
		ans += min(akt, 1ll*g) * (x.X-last);
		last = x.X;
		akt += x.Y;
	}
	cout << ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int tt; cin >> tt;
	// FOR(te, 0, tt){
	// 	// cout << "Case #" << te+1 << ": ";
	// 	solve();
	// }
	solve();
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  if(n%100==0){
    cout << n/100 << endl;
  }
  else{
    cout << n/100 +1 << endl;
  }
}

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <math.h>
#include <iomanip>
#define INF 100000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
  ll n;
  cin >> n;
  ll ans = 2;
  for (ll i = 3; i <= n; i++) {
    ans = lcm(ans, i);
  }
  cout << ans+1 << endl;

  return 0;
}


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif

using namespace std;
using Graph = vector<vector<int>>;
using vst= vector<string>;
using vin= vector<int>;
using ll=long long;
using ull=unsigned long long;
using vll= vector<ll>;
using P=pair<int ,int>;
using pqi=priority_queue<int, vector<int>, greater<int>>;
using pqp=priority_queue<P, vector<P>, greater<P>>;

//const long double pi=acos(-1);
#define ft first
#define sd second
#define fn front
#define pb push_back
#define eb emplace_back
#define it insert
#define vvi vector<vector<int>>
#define si(v) int((v).size())
#define pq priority_queue
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define gsot(x) sort(x.begin(), x.end(), greater<ll>());
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))
#define cps CLOCKS_PER_SEC
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define cset(x) cout<<fixed<<setprecision(x)

//const int INF=1001001001;
//const ll INF=1e18;
//998244353  1000000007

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vin a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];
    vin cnt(100008,0),d(n);
    rep(i,n){
        cnt[a[i]]++;
    }
    rep(i,n){
        d[c[i]-1]++;
    }
    ll ans=0;
    rep(i,n){
        ans+=(d[i]*cnt[b[i]]);
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
/* #include <atcoder/lazysegtree> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vint = vector<int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}
template <typename... T>
void In(T&&... args) {
    (std::cin >> ... >> args);
}
template <typename T, typename ...Tail>
void Out(T head, Tail... tail) {
    std::cout << head;
    if constexpr(sizeof...(tail) > 0) {
        std::cout << ' ';
        Out(tail...);
    } else {
        std::cout << '\n';
    }
}
template <typename T>
T& chmin(T& val, T val2) {
    return val = min(val, val2);
}
template <typename T>
T& chmax(T& val, T val2) {
    return val = max(val, val2);
}

void solve() {
    int n; In(n);
    vector<vll> c(n, vll(n,0));
    REP(i,n) {
        REP(j,n) {
            cin >> c[i][j];
        }
    }
    bool flag = true;
    vll asub(n-1,0), bsub(n-1,0);
    REP(j,n) {
        vll tmp;
        REP(i,n-1) {
            tmp.push_back(c[i+1][j] - c[i][j]);
        }
        if (j == 0) {
            asub = tmp;
        } else {
            if (asub != tmp) {
                flag = false;
                break;
            }
        }
    }
    REP(i,n) {
        vll tmp;
        REP(j,n-1) {
            tmp.push_back(c[i][j+1] - c[i][j]);
        }
        if (i == 0) {
            bsub = tmp;
        } else {
            if (bsub != tmp) {
                flag = false;
                break;
            }
        }
    }
    if (!flag) {
        Out("No");
        return;
    }
    vll a,b;
    a.push_back(0);
    b.push_back(c[0][0]);
    REP(i,n-1) {
        a.push_back((*a.rbegin()) + asub[i]);
        b.push_back((*b.rbegin()) + bsub[i]);
    }
    ll amin = LLONG_MAX, bmin = LLONG_MAX;
    REP(i,n) {
        chmin(amin,a[i]);
        chmin(bmin,b[i]);
    }
    if (amin < 0) {
        bmin += amin;
        if (bmin < 0) {
            Out("No");
            return;
        }
        REP(i,n) {
            a[i] -= amin;
            b[i] += amin;
        }
    } else if (bmin < 0) {
        amin += bmin;
        if (amin < 0) {
            Out("No");
            return;
        }
        REP(i,n) {
            a[i] += bmin;
            b[i] -= bmin;
        }
    }
    Out("Yes");
    Out(a);
    Out(b);
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;
#define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout<<endl;
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

ll I(ll x){if(x%2){return 1;}else{return -1;};}
signed main(){
    ll n;cin>>n;
    vector<ll> a(n,0),s(n+1,0);REP(i,n){cin>>a[i];};
    s[0]=0;REP(i,n){
        s[i+1]=I(i)*a[i]+s[i];
    };
    sort(ALL(s));
    ll x=0,y=s[0]-1,z=0;
    REP(i,n+1){
        if(y==s[i]){
            z++;
        }else{
            x+=z*(1+z)/2;
            z=0;y=s[i];
        };
    };
    x+=z*(z+1)/2;
    cout<<x;
}

#include "bits/stdc++.h"
using namespace std;
#define int long long
int dp[300001][2][2];
int a[300001];
void solution() {
  int n;
  cin >> n;
  map<int, int> m;
  m[0] = 1;
  int sum = 0;
  int ans = 0;
  for (int i = 1; i <= n; i ++) {
    cin >> a[i];
    sum += (a[i]) * (i % 2 == 1 ? 1 : -1);
    ans += m[sum];
    m[sum] ++;
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1;
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif
  // cin >> tc;
  while (tc --) { solution(); cout << "\n"; }
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int MAX_H = 100;
const int MAX_W = 100;

vector<vector<char>> board;

int main(void) {
    int H, W;
    cin >> H >> W;

    board.resize(MAX_H + 1, vector<char>(MAX_W + 1, '#'));

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c;
            cin >> c;
            if (c == '.') {
                board[i][j] = '.';
            }
        }
    }

    int cnt = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (board[h][w] == '.' && board[h][w + 1] == '.') {
                cnt++;
            }
        }
    }
    for (int w = 0; w < W; w++) {
        for (int h = 0; h < H; h++) {
            if (board[h][w] == '.' && board[h + 1][w] == '.') {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    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;

#define mod 1000000007
#define pb push_back
#define ll long long int
#define ull unsigned ll
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse
#define itr iterator
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

/*
const ll infinity = 9e18;

bool compare(ll a,ll b) {return a > b;}
bool compare1(ppl a,ppl b) {return a.ff > b.ff;}
bool compare2(ppl a,ppl b) {return a.ss < b.ss;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}

ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

    int n,m;
    cin>>n>>m;

    vector<vector<char>> grid(n,vector<char>(m));

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin>>grid[i][j];
        }
    }

    ll total = 0;

    for(int i = 0; i < n; i++)
    {
        int count = 0;

        for(int j = 0; j < m; j++)
        {
            if(grid[i][j] == '.')
            {
                count++;
            }
            else
            {
                if(count) total += (count-1);
                count = 0;
            }
        }
        if(count) total += (count-1);
    }

    for(int i = 0; i < m; i++)
    {
        int count = 0;

        for(int j = 0; j < n; j++)
        {
            if(grid[j][i] == '.')
            {
                count++;
            }
            else
            {
                if(count) total += (count-1);
                count = 0;
            }
        }
        if(count) total += (count-1);
    }

    cout<<total;

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 998244353;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

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

  int n;
  cin >> n;
  ll ret = 0;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    ret += (a+b)*(b-a+1)/2;
  }
  cout << ret << endl;
}

#include<bits/stdc++.h>
#include<string>
using namespace std;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long int
#define mod 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int>sum(1000006);
void cal() {
	sum[0] = 0;
	sum[1] = 1;
	for (int i = 2; i <= 1000000; i++) {
		sum[i] = i + sum[i - 1];
	}
}
void solve() {
	int ans = 0;
	int n;
	cin >> n;
	int a, b;
	while (n--) {
		cin >> a >> b;
		ans += (sum[b] - sum[a - 1]);
	}
	cout << ans << endl;
	return;
}
int32_t main()
{
	cal();
	fio
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=998244353;
ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result

     // Update x if it is more than or
                // equal to p

    //if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % mod;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res;
}
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans;
    ans=(a*(a+1));
    ans=ans%mod;
    ans=((ans%mod)*((b*(b+1))%mod))%mod;
    ans=ans%mod;
    ans=((ans%mod)*((c*(c+1))%mod))%mod;
    ans=ans%mod;
    ll temp=power(8,mod-2);
    ans=(((ans)%mod)*(temp%mod))%mod;
    cout<<ans<<endl;

}

#include<bits/stdc++.h>
using namespace std;
# define test int t;cin>>t;while(t--)
#define ff first
#define ss second
#define ll long long int
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll mod = 998244353;
    ll ans  = (((a) * (a + 1) / 2) % mod);

    ans = (ans * (((b) * (b + 1) / 2) % mod)) % mod;

    ans = (ans * (((c) * (c + 1) / 2) % mod)) % mod;

    cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

namespace model{
	const int N = 1e6+7,P=998244353;
	int read()
	{
		int a = 0,x = 1;char ch = getchar();
		while(ch > '9' || ch < '0') {if(ch == '-') x = -1;ch = getchar();}
		while(ch >= '0' && ch <= '9'){a = a*10 + ch-'0';ch = getchar();}
		return a*x;
	}
	int fpow(int a,int x,int p)
	{
		if(x == 1) return a;
		if(x == 0) return 1;
		int t = fpow(a,x>>1,p);
		if(x&1) return t*t%p*a%p;
		return t*t%p;
	}
	void Mod(int &a) {if(a >= P) a %= P;}
}

using model::read;
using model::N;
int n,a[N];

void solve()
{
	n = read();
	for(int i = 1;i <= n;i ++) a[i] = read();
	sort(a+1,a+1+n);int len = unique(a+1,a+1+n) - a-1;
	if(n == len) puts("Yes");
	else puts("No");
}

int main()
{
	int t = 1;
	while(t --) solve();
}

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

void solve() {
    int n;
    cin >> n;
    int arr[n], check[n+1];
    memset(check, 0, sizeof(check));
    for(int i=0; i<n; i++){
        cin >> arr[i];
        check[arr[i]]++;
    }

    for(int i=1; i<=n; i++){
        if(check[i]!=1){
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
    return;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>
#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define CREP(i, l, r) for(int i = l; i <= r; i++)
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> T;
typedef pair<ll,ll> P;
typedef vector<int> V;
typedef vector<ll> Vll;
const int INF = 1000000000;      //10^9, 2*INF
const ll LLINF = (1LL << 60);   // > 10^18 ll  2*LLINF

int main() {
    int n;
    ll co;
    cin >> n >> co;
    Vll a(n), b(n), c(n); rep(i, n) scanf("%lld%lld%lld", &a[i],&b[i],&c[i]);

    vector<P> ac(n), bc(n);
    rep(i,n){
        ac[i] = P(a[i],c[i]);
        bc[i] = P(b[i],c[i]);
    }

    sort(ac.begin(),ac.end());
    sort(bc.begin(),bc.end());

    ac.emplace_back(P(LLINF,LLINF));
    bc.emplace_back(P(LLINF,LLINF));

    ll pc = 0, day = 0, ans = 0;
    int aci=0,bci = 0;
    bool snk = false;
    while(aci < n || bci < n){
        ll nday = min(ac[aci].first, bc[bci].first);
        ans += (snk ? co : pc)*(nday-day);
        day = nday;

        while(aci < n && ac[aci].first == day) {
            pc += ac[aci].second;
            aci++;
        }
        if(pc > co) snk = true;
        else snk = false;
        ans += (snk ? co : pc);
        while(bci < n && bc[bci].first == day) {
            pc -= bc[bci].second;
            bci++;
        }
        if(pc > co) snk = true;
        else snk = false;
        day++;
        //printf("day %lld\n", day);
    }

    printf("%lld\n", ans);
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque>
#include <string>

using namespace std;

struct Num {
	int in;
	int out;
	long long cost;
};

Num nums[200010];
int n;

struct Event {
	int type;
	int cost;
	int t;

    bool operator < (const Event &a) const {
    	int x = abs(this->t);
    	int ax = abs(a.t);
        return x>ax;//最小值优先
    }
};

long long c;

int main()
{
	scanf("%d%lld", &n, &c);

	std::priority_queue<Event> q;

	for (int i = 0 ; i < n ; i++) {
		scanf("%d%d%lld", &(nums[i].in), &(nums[i].out), &(nums[i].cost));
		Event inEvent;
		inEvent.cost = nums[i].cost;
		inEvent.type = 1;	//in
		inEvent.t = nums[i].in;
		q.push(inEvent);

		Event outEvent;
		outEvent.cost = nums[i].cost;
		outEvent.type = -1;
		outEvent.t = nums[i].out + 1;
		q.push(outEvent);
	}

	long long totalCost = 0;
	long long curCost = 0;
	int lastTime = 0;
	int curTime;

	while (!q.empty()) {
		Event curEvent = q.top();

		curTime = curEvent.t;
		if (curCost < c) {
			totalCost = totalCost + (curTime - lastTime) * curCost;
		} else {
			totalCost = totalCost + (curTime - lastTime) * c;
		}

		while (curTime == curEvent.t) {
			q.pop();
			if (curEvent.type == 1) {
				curCost = curCost + curEvent.cost;
			} else {
				curCost = curCost - curEvent.cost;
			}

			if (q.empty()) {
				break;
			}

			curEvent = q.top();
		}

		lastTime = curTime;
	}

	printf("%lld\n", totalCost);

	return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define Rep(i,n) for(int i = 1 ; i <= n ; i++)
const int maxn=2e5+5;
const bool DEBUG = 0;

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

    int n,m,t;
	int a,b;
	int left,time;
	string ans = "Yes";

    cin >> n >> m >> t;
    left = n;
	time = 0;
	rep(i,m){
		cin >> a >> b;
		if(left - (a-time) <= 0){
			ans = "No";
			break;
		}else{
			left += b - 2*a + time;
			if(left > n){
				left = n;
			}
		}
		time = b;
	}

	if(left - (t-time) <= 0){
		ans = "No";
	}

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

/*ll fact[1001];
ll binpow(ll a, ll b) {

    ll res=1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

ll cal(ll c,ll k)
{
    ll res=fact[c];

    ll res1=((fact[k]%mod)*(fact[(c-k)]%mod))%mod;

    ll res0;
    res0=binpow(res1,mod-2);
    return ((res*res0)%mod);
}*/

/*bool cmp(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(a.first==b.first)
    {
        return(a.second<b.second);
    }
    else
    {
        return (a.first<b.first);
    }
}*/

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

    ll n,m,t;
    cin>>n>>m>>t;

    vector<pair<ll,ll>>v;

    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    ll f=0;
    ll ans=n;

    ans-=(v[0].first);
    if(ans<=0)
    {
        f=-1;
    }
    for(ll i=0;i<m-1;i++)
    {
        ans+=((v[i].second-v[i].first));
        if(ans>n)
        {
            ans=n;
        }
        ans-=((v[i+1].first-v[i].second));
        //cout<<"A"<<ans<<endl;
        if(ans<=0)
        {
            f=-1;
            break;
        }
    }
    ans+=((v[m-1].second-v[m-1].first));
     if(ans>n)
        {
            ans=n;
        }
    if(((t-v[m-1].second)>=ans))
    {
        f=-1;
    }
    if(f==-1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }

	return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Read questions carefully.


#include "bits/stdc++.h"
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
using namespace std;
using ll = long long;

const int mod = 1e9+7;
ll ans = 0;

void dfs(auto &g, int u, int par, auto &pref, auto &sz)
{
    sz[u] = 1;
    for (auto [v, w] : g[u]) {
        if (v == par) continue;
        pref[v] = pref[u] ^ w;
        dfs(g, v, u, pref, sz);
        sz[u] += sz[v];
    }
}

array<int, 61> dfs2(auto &g, int u, int par, auto &pref, auto &sz)
{
    array<int, 61> ret{};
    int tot = 0;
    for (auto [v, w] : g[u]) {
        if (v == par) continue;
        auto child = dfs2(g, v, u, pref, sz);
        for (int i = 0; i < 61; ++i) {
            ll mul = 1LL << i; mul %= mod;
            ll ct = 1LL*child[i]*(tot-ret[i]) + 1LL*(sz[v]-child[i])*ret[i];
            ct %= mod;
            ans += mul*ct; ans %= mod;
            ret[i] += child[i];
        }
        tot += sz[v];
    }
    for (int i = 0; i < 61; ++i) {
        ll mul = 1LL << i; mul %= mod;
        ll ct = 0;
        if ((pref[u]>>i)&1) {
            ct = sz[u]-1-ret[i];
            ++ret[i];
        }
        else {
            ct = ret[i];
        }
        ct %= mod;
        ans += mul*ct; ans %= mod;
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

    int n; cin >> n;
    vector<vector<array<ll, 2>>> g(n);
    for (int i = 0; i < n-1; ++i) {
        int u, v; cin >> u >> v;
        ll w; cin >> w;
        g[--u].push_back({--v, w});
        g[v].push_back({u, w});
    }
    vector<ll> pref(n);
    vector<int> sz(n);
    dfs(g, 0, 0, pref, sz);
    dfs2(g, 0, 0, pref, sz);
    cout << ans;
}

#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int ll
#define vi vector<int>
#define vb vector<bool>
#define vvb vector<vb >
#define pii pair<int,int>
#define ss second
#define ff first
#define vpii vector<pii>
#define vvi vector<vi >
#define vs vector<string>
#define vvs vector<vs >
#define pqi priority_queue <int>
#define minpqi priority_queue <int, vector<int>, greater<int> >
#define all(x) x.begin(),x.end()
#define mii map<int,int>
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define per1(i,n) for(ll i=n;i>0;i--)
#define repeat(i,start,n) for(ll i=start;i<n;i++)
#define inp(arr,n) ll arr[n];rep(i,n){ cin>>arr[i];}
#define inp1(arr,n) ll arr[n+1];rep1(i,n){ cin>>arr[i];}
#define inp2d(arr,n,m) ll arr[n][m];rep(i,n)rep(j,m)cin>>arr[i][j];
#define inpg(adj,m) rep(i,m){int a,b;cin>>a>>b;adj[a].pb(b);adj[b].pb(a);}
#define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
#define print1(a,n) for(ll i=1;i<=n;i++){ cout<<a[i]<<endl;}
#define mod 1000000007
#define maxx 1000000000000000000
#define PI 3.141592653589793238462643383279
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define init(arr,a) memset(arr,a,sizeof(arr))
#define lb lower_bound
#define ub upper_bound
//          " "
vector<pii> v[200001];

long long sum=0;
long long value[200001];
void dfs(int node,int par,int xorr)
{
//	int sum=0;
//	int xorr=0;
	for(auto it:v[node])
	{
		if(it.first!=par)
		{
			xorr^=it.second;
			value[it.first]=xorr;
			dfs(it.first,node,xorr);
			xorr^=it.second;
			//return ans;
		}
	}
	return ;
}
signed main()
{

     int n;
     cin>>n;

     for1(i,n-1)
     {
     	int a,b,c;
     	cin>>a>>b>>c;
     	v[a].pb({b,c});
     	v[b].pb({a,c});
	 }

	 dfs(1,0,0);

	int ans=0;
	map<int,int>mpp;
	for(int i=2;i<=n;i++)
	{

		for(int j=0;j<=63;j++)
		{

			if((1ll<<j)&value[i])
			{
				mpp[j]++;
			}
		}
	}

	for0(i,64)
	{
		ans=ans%mod+((1ll<<i)%mod*((mpp[i]*(n-mpp[i]))%mod)%mod)%mod;
	}
	 //for1(i,n)cout<<visit[i]<<endl;
	 cout<<ans<<endl;
	 return 0;

}


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

typedef vector<long long> vi;
typedef unordered_set<long long> usi;
typedef set<long long> osi;
typedef vector<pair<long long,long long>> vpi;
typedef long long ll;

#define pb push_back
#define popb pop_back
#define mp make_pair

#define read(a) ll a; cin>>a;
#define pt(a) cout << a << "\t"
#define pl(a) cout << a << "\n"

#define fori(i,n) for(ll i = 0; i < n; i++)
#define fori2(i,m,n) for (ll i = m; i <= n; i++)
#define ford(i,n) for (ll i = n - 1; i >= 0; i--)
#define ford2(i,m,n) for (ll i = m; i >=n; i--)
#define iter(s) for(auto it:s)

#define mod 1000000007
#define PI 3.1415926535897932384626433832

/*
//a raised to the power n
ll pow1(ll a,ll n)
{
    if(n==0)
    {
        return 1;
    }
    else
    {
        return a*pow1(a,n-1);
    }
}
*/

/*
//total sum of a vector
ll sum1(vi v)
{
    ll sum = 0;
    for(int i=0 ; i<v.size() ; i++)
    {
        sum = sum + v[i];
    }
    return sum;
}
*/

/*
//printing contents of a vector
void printv(vi v)
{
    for(auto it=v.begin(); it!=v.end() ; it++)
    {
        cout<<*it<<"\t";
    }
    cout<<"\t";
}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	// your code goes here
	int t = 1;
	//read(t);
	while(t--)
	{
	    // your code goes here
	    ll suml = 0;

	    read(n);

	    ll a[n];
	    ll m[n] = {0};
	    ll s[n] = {0};
	    ll st[n] = {0};

	    fori(i,n)
	    {
	        cin>>a[i];

	        if(i==0)    m[i] = a[i];
	        else    m[i] = max(m[i-1],a[i]);

	        if(i==0)    s[i] = a[i];
	        else    s[i] = s[i-1] + a[i];
	    }

	    st[0] = s[0];

	    fori2(i,1,n-1)
	    {
	        st[i] = st[i-1] + s[i];
	    }

	    fori(i,n)
	    {
	        pl((st[i] + m[i]*(i+1)));
	    }

	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#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 FOR(i, n, m) for (int i=(n); i<=(int)(m); i++)
#define ll long long
const ll INF=1LL<<60;
const double pi=3.1415926535;

int main() {
    vector<vector<int>> dp(900, vector<int>(900));
    vector<int> vec_output;

    rep(i, 1000) {

        //入力
        vector<int> input(4);
        rep(j, 4) cin >> input.at(j);

        //通った道
        vector<int> usei(0), usej(0);
        usei.push_back(input.at(0));
        usej.push_back(input.at(1));

        int x = input.at(1);
        int y = input.at(0);
        int xplus = 0;
        int yplus = 0;
        if (x < input.at(3)) xplus = 1;
        if (x > input.at(3)) xplus = -1;
        if (y < input.at(2)) yplus = 1;
        if (y > input.at(2)) yplus = -1;
        bool X = false;

        //経路探索
        while (x != input.at(3)) {
            //ｘの残りをうめる
            if (y == input.at(2)) {
                while (x != input.at(3)) {
                    x += xplus;
                    usei.push_back(y);
                    usej.push_back(x);
                    cout << (xplus == 1 ? "R" : "L") << flush;
                }
                break;
            }

            //探索済みか調べる
            if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0 && dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
                X = X;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0) {
                X = true;
            } else if (dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
                X = false;
            }
            //近い方を調べる
            if (dp.at(y*30 + x).at(y*30 + x+xplus) < dp.at(y*30 + x).at((y+yplus)*30 + x)) {
                X = true;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) > dp.at(y*30 + x).at((y+yplus)*30 + x)) {
                X = false;
            } else {
                X = !X;
            }

            if (X) {
                x += xplus;
                usei.push_back(y);
                usej.push_back(x);
                cout << (xplus == 1 ? "R" : "L") << flush;
            } else {
                y += yplus;
                usei.push_back(y);
                usej.push_back(x);
                cout << (yplus == 1 ? "D" : "U") << flush;
            }
        }

        //yの残りをうめる
        while (y != input.at(2)) {
            y += yplus;
            usei.push_back(y);
            usej.push_back(x);
            cout << (yplus == 1 ? "D" : "U") << flush;
        }
        cout << endl;

        //入力
        ll output;
        cin >> output;

        //点数の平均を計算
        vec_output.push_back(output);
        ll sum = 0;
        for (ll a : vec_output) {
            sum += a;
        }
        ll ave = sum / vec_output.size();
        output -= ave;
        output *= 60;
        int size = usei.size();

        rep(j, usei.size()-1) {
            int a = usei.at(j);
            int b = usej.at(j);
            int c = usei.at(j+1);
            int d = usej.at(j+1);
            //cout << a*30+b << " " << c*30+d << endl;
            dp.at(a*30+b).at(c*30+d) += output / size;
            dp.at(c*30+d).at(a*30+b) += output / size;
        }

        /*rep(j, 29) {
            rep(k, 29) {
                cout << " " << dp.at(j*30+k).at(j*30+k+1);
            }
            cout << endl;
            rep(k, 30) {
                cout << dp.at(j*30+k).at((j+1)*30+k) << " ";
            }
            cout << endl;
        }*/
    }
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define int long long
using namespace std;

const int N = 3e3 + 5;
const int mod = 998244353;
const int INF = 1e15 + 5;

int dp[N][N];

int32_t main(){
	fast;
	int n, k;
	cin >> n >> k;
	memset(dp, 0, sizeof dp);
	dp[0][0] = 1;
	for(int i=1; i<=n; i++){
		for(int j=n; j>=0; j--){
			int sum = 0;
			if(j > 0){
				sum = (sum + dp[i-1][j-1])%mod;
			}
			if(2*j <= n)
				sum = (sum + dp[i][2*j])%mod;
			dp[i][j] = sum;
		}
	}
	cout << dp[n][k] << endl;

}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int A, B;
  cin >> A >> B;
  vector<int> C, D;

  int delta = 0;
  if (A > B) {
    rep(i, A) C.push_back(i + 1);
    rep(i, B - 1) D.push_back(-1 * (i + 1));
    for (int i = B; i <= A; i++)
      delta += -1 * i;
    D.push_back(delta);
  } else if (A < B) {
    rep(i, A - 1) C.push_back(i + 1);
    rep(i, B) D.push_back(-1 * (i + 1));
    for (int i = A; i <= B; i++)
      delta += i;
    C.push_back(delta);
  } else if (A == B) {
    rep(i, A) C.push_back(i + 1);
    rep(i, B) D.push_back(-1 * (i + 1));
  }

  rep(i, D.size()) cout << D.at(i) << " ";
  rep(i, C.size()) {
    cout << C.at(i);
    if (i != (int)C.size() - 1)
      cout << " ";
  }
  cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
using pint = pair<ll, ll>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const ll mod = 998244353;

int n;
bool seen[200200];
vector<vector<int>> g(200200);

int dfs(int a) {
    if (seen[a]) return a;
    seen[a] = 1;
    for (auto b : g[a]) {
        seen[b] = 1;
        return dfs(b);
    }
}

ll modpow(ll n, ll m) {
    ll ans = 1;
    while (n > 0) {
        if (n & 1) ans = ans * m % mod;
        m = m * m % mod;
        n >>= 1;
    }
    return ans;
}

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}  //親は-1

    int root(int x) {
        if (par[x] < 0)
            return x;  //自身が親
        else
            return par[x] = root(par[x]);  //再帰
    }

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

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;  //既に同じ根
        // xとyのサイズの大きいほうにまとめたい
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];  //根のparは-(要素数)になる
        par[y] = x;        //親を更新
        return;
    }

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

int main() {
    cin >> n;
    vector<int> f(n);
    vector<int> pp;
    UnionFind tree(n);
    rep(i, 0, n) {
        cin >> f[i];
        f[i]--;
        g[i].push_back(f[i]);
        if (i == f[i]) {
            pp.push_back(i);
        }
        tree.merge(i, f[i]);
    }
    int cnt = 0;
    set<int> st;
    rep(i, 0, n) st.insert(tree.root(i));
    cnt = st.size();
    ll ans = modpow(cnt, 2) - 1;
    cout << ans << "\n";
}

#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  int n,num=0;
  cin >> n;

  vector<int>f(n);
  for (int i = 0; i < n; i++) {
    int f_;
    cin >> f_;
    f_--;
    f[i] = f_;
  }

  vector<bool>seen(n+1,0);

  for (int i = 0; i < n; i++) {
    if (seen[i]==1) continue;
    else {
      int k = f[i];
      set<int>seen2;
      while(1) {
        if (seen2.count(k)) {
          num++;
          break;
        }
        if (seen[k]) {
          break;
        }
        seen[k] = 1;
        seen2.insert(k);
        k = f[k];
      }
    }
  }
  ll ans = 1;
  while(num) {
    ans *= 2;
    ans %= 998244353;
    num--;
  }
  cout << ans - 1 << endl;
}


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

struct desire
{
  int x;
  int y;
  int r;
};
struct place
{
  vector<int> d;
  int s;
};

void input(vector<desire> &ads_de, vector<place> &ads_pl, int N);
void output(vector<place> &ads_pl, int N);
void expand(vector<desire> &ads_de, vector<place> &ads_pl, int N);
bool can_expand(vector<place> &ads_pl, int N, int vertex, int company);

int main()
{
  int N;
  cin >> N;
  vector<desire> ads_de(N);
  vector<place> ads_pl(N);
  input(ads_de, ads_pl, N);
  expand(ads_de, ads_pl, N);
  output(ads_pl, N);
}

void input(vector<desire> &ads_de, vector<place> &ads_pl, int N)
{
  for (int i = 0; i < N; i++)
  {
    cin >> ads_de.at(i).x >> ads_de.at(i).y >> ads_de.at(i).r;
    ads_pl.at(i).d.push_back(ads_de.at(i).x);
    ads_pl.at(i).d.push_back(ads_de.at(i).y);
    ads_pl.at(i).d.push_back(ads_de.at(i).x+1);
    ads_pl.at(i).d.push_back(ads_de.at(i).y+1);
    ads_pl.at(i).s = 1;
  }
}
void output(vector<place> &ads_pl, int N)
{
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 4; j++) cout << ads_pl.at(i).d.at(j) << " ";
    cout << "\n";
  }
}
void expand(vector<desire> &ads_de, vector<place> &ads_pl, int N)
{
  int check = 1;
  int expand_s;
  while (check)
  {
    check = 0;
    for (int i = 0; i < 4; i++)
    {
      for (int j = 0; j < N; j++)
      {
        if (can_expand(ads_pl,N,i,j))
        {
          expand_s = ads_pl.at(j).s+abs(ads_pl.at(j).d.at((i+1)%4)-ads_pl.at(j).d.at((i+3)%4));
          if ((double)min(expand_s,ads_de.at(j).r)/max(expand_s,ads_de.at(j).r) > (double)min(ads_pl.at(j).s,ads_de.at(j).r)/max(ads_pl.at(j).s,ads_de.at(j).r))
          {
            ads_pl.at(j).s = expand_s;
            ads_pl.at(j).d.at(i) += pow(-1,i/2+1);
            check = 1;
          }
        }
      }
    }
  }
}

bool can_expand(vector<place> &ads_pl, int N, int vertex, int company)
{
  int side_min, side_max, each_min, each_max, dir;
  bool ret;

  side_min = min(ads_pl.at(company).d.at((vertex+1)%4),ads_pl.at(company).d.at((vertex+3)%4));
  side_max = max(ads_pl.at(company).d.at((vertex+1)%4),ads_pl.at(company).d.at((vertex+3)%4));
  dir = pow(-1,vertex/2+1);
  if (ads_pl.at(company).d.at(vertex)+dir<0 || ads_pl.at(company).d.at(vertex)+dir>10000)
    return false;
  ret = true;
  for (int i = 0; i < N; i++)
  {
    if (i == company) continue;
    each_min = min(ads_pl.at(i).d.at((vertex+1)%4),ads_pl.at(i).d.at((vertex+3)%4));
    each_max = max(ads_pl.at(i).d.at((vertex+1)%4),ads_pl.at(i).d.at((vertex+3)%4));
    if (side_max <= each_min || side_min >= each_max) continue;
    if ((ads_pl.at(company).d.at(vertex)+dir)*dir > ads_pl.at(i).d.at((vertex+2)%4)*dir && (ads_pl.at(company).d.at((vertex+2)%4))*dir < ads_pl.at(i).d.at(vertex)*dir)
    {
      ret = false;
      break;
    }
  }
  return ret;
}

#include <iostream>
#include <cstdlib>
#include<vector>
#include<memory>
#include<algorithm>

struct Box{
    int x;
    int y;
    int r;
    int a,b,c,d;
};
int Len = 10000;
struct Col{
    int x;
    int x_min;
    int x_max;
    std::vector<std::shared_ptr<Box>> elem;
};

double count_score(Col const&c){
    double t = 0;
    if(c.x_min <= c.x && c.x+1 <= c.x_max){
        for (auto p : c.elem) {
            auto s = (c.x_max - c.x_min) * Len / c.elem.size();
            auto xten = std::min<int>(s, p->r) / (double)p->r;
            t += 1 - (1 - xten) * (1 - xten);
        }
    }else{
        t = - (std::max(c.x+1 - c.x_max, c.x_min - c.x) * 100);
    }

    return t;
}

int main()
{
    std::vector<std::shared_ptr<Box>> input;
    int n;
    std::cin>>n;
    for(int i=0;i<n;++i){
        Box b;
        std::cin>>b.x>>b.y>>b.r;
        input.push_back(std::make_shared<Box>(b));
    }

    std::vector<std::vector<std::shared_ptr<Box>>> backet(Len);
    for(auto p : input){
        backet[p->x].push_back(p);
    }

    std::vector<std::shared_ptr<Col>> col_list;
    {
        Col c;
        c.x_min = -1;
        c.x = -1;
        col_list.push_back(std::make_shared<Col>(c));
    }

    for(auto&v: backet){
        if(v.size() > 0){
            Col c;
            c.x = v[0]->x;
            c.elem = v;
            col_list.push_back(std::make_shared<Col>(c));
        }
    }

    {
        Col c;
        c.x = Len;
        c.x_max = Len + 1;
        col_list.push_back(std::make_shared<Col>(c));
    }

    for(int i=0;i+1<col_list.size();++i){
        auto m = (col_list[i]->x + col_list[i+1]->x)/2;
        col_list[i]->x_max = m;
        col_list[i+1]->x_min = m;
    }

    for(int t= 0 ;t<1000;++t){
        for(int i=0;i+1<col_list.size();++i){
            auto count = [&](int shift_val){
                auto lshift1 = *(col_list[i]);
                auto lshift2 = *(col_list[i+1]);
                lshift1.x_max += shift_val;
                lshift2.x_min += shift_val;
                return count_score(lshift1) + count_score(lshift2);
            };
            auto lshift = count(-1);
            auto noshift = count(0);
            auto rshift = count(1);
            if(lshift >= rshift && lshift >= noshift){
                col_list[i]->x_max+=-1;
                col_list[i+1]->x_min+=-1;
            }else if(lshift <= rshift && rshift >= noshift){
                col_list[i]->x_max+=1;
                col_list[i+1]->x_min+=1;
            }
        }
    }

    for(auto c: col_list){
        for(int i =0;i<c->elem.size();++i){
            int y_len = c->elem[i]->r/(c->x_max - c->x_min);
            int y_min = i==0? 0 : c->elem[i]->y;
            int y_max = i+1==c->elem.size() ? Len : c->elem[i+1]->y;
            if(y_len > y_max - y_min){
                c->elem[i]->b = y_min;
                c->elem[i]->d = y_max;
            }else{
                auto bottom = c->elem[i]->y + y_len;
                if(bottom > y_max){
                    bottom = y_max;
                }
                c->elem[i]->b = bottom - y_len;
                c->elem[i]->d = bottom;
            }
            c->elem[i]->a = c->x_min;
            c->elem[i]->c = c->x_max;
        }
    }
    for(auto p: input){
        std::cout<<p->a<<" "<<p->b<<" "<<p->c<<" "<<p->d<<"\n";
    }
}