/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e16;
const ll MAXN=100200;
ll i,j,mask,test;
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll n,m;
cin>>n>>m;
char a[n+2][m+2];
ll cnt=0;
F(i,0,n)
{
    F(j,0,m)
    {
        cin>>a[i][j];
    }
}
ll x[]={1,-1,0,0};
ll y[]={0,0,1,-1};
F(i,0,n)
{
    F(j,0,m)
    {
        if(a[i][j]=='.')
        {
            for(ll k=0;k<4;k++)
            {
                ll c=i+x[k],d=j+y[k];
                if(c<0 || c>=n || d<0 || d>=m || a[c][d]=='#')continue;
                cnt++;
            }
        }
    }
}
cout<<cnt/2;
return 0;
}

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

///******************************** C o n t a i n e r ********************************///

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

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///
ll n,m,ans,c;
//bool vis[101][101];
string a[105];

void _case()
{
    cin>>n>>m;
    ll i,j;
    forn(i,n) cin>>a[i];
    for(i=0;i<n;i++){
        for(j=1;j<m;j++){
            if(a[i][j]=='.' and a[i][j-1]=='.'){
                ans++;
            }
        }
    }
    for(i=1;i<n;i++){
        for(j=0;j<m;j++){
            if(a[i][j]=='.' and a[i-1][j]=='.'){
                ans++;
            }
        }
    }
    cout<<ans el;
}

main()
{
    fastio();
    _case();

}

///Thank you.

///Brainless_Loco Terminates Here!


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

struct d{ll f, s, t;};//first, second, turn

bool comp(d a, d b) {
  if (a.t == 0 || b.t == 0) {
    return a.t >= b.t;
  }
  return (a.s - a.f) >= (b.s - b.f);
}

ll N;
vector<ll> p;
vector<vector<ll>> child;
d dfs(ll now, ll turn) {
  vector<ll> FS(2, 0);
  FS.at(0) += 1;
  turn = (turn + 1) % 2;
  vector<d> ds;
  vector<vector<ll>> datas;
  for (ll i = 0; i < child.at(now).size(); ++i) {
    d temp = {1, 0, 1};
    if (child.at(child.at(now).at(i)).size() != 0) {
      temp = dfs(child.at(now).at(i), 0);
    }
    if (temp.f <= temp.s && temp.t == 0) {
      FS.at(turn) += temp.s;
      FS.at((turn + 1) % 2) += temp.f;
    }
    else {
      ds.push_back(temp);
      datas.push_back({temp.t, temp.s - temp.f, temp.f, temp.s, temp.t});
    }
  }
  // for (ll i = 0; i < datas.size(); ++i) {
  //   cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n";
  // }
  sort(rrng(datas));
  // for (ll i = 0; i < datas.size(); ++i) {
  //   cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n";
  // }
  // cout << "\n";
  for (ll i = 0; i < datas.size(); ++i) {
    d temp = {datas.at(i).at(2), datas.at(i).at(3), datas.at(i).at(4)};
    FS.at(turn) += temp.s;
    FS.at((turn + 1) % 2) += temp.f;
    turn = (turn + temp.t) % 2;
  }
  // cout << "now" << now + 1 << "\n";
  // cout << FS.at(0) << ' ' << FS.at(1) << ' ' << turn << "\n";
  return {FS.at(0), FS.at(1), turn};
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  p = vector<ll>(N, -1);
  child = vector<vector<ll>>(N);
  for (ll i = 1; i < N; ++i) {
    cin >> p.at(i);
    p.at(i) -= 1;
    child.at(p.at(i)).push_back(i);
  }
  cout << dfs(0, 0).f << "\n";
}

#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    ll ok = 1;
    ll ng = n + 1;
    while (ok + 1 < ng) {
        ll m = (ok + ng) / 2;
        if (m % 2) {
            if ((n + 1) / m >= (m + 1) / 2) ok = m;
            else ng = m;
        } else {
            if ((n + 1) / (m + 1) >= m / 2) ok = m;
            else ng = m;
        }
    }
    cout<<n - ok + 1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
inline  long long  mymin(long long  x,long long  y){return  x<y?x:y;}
inline  long long  mymax(long long  x,long long  y){return  x>y?x:y;}
long long  ans,n,k;
inline  long long  fangan(long long  x)
{
	long long l=mymax(1,x-n),r=mymin(n,x-1);
	return  r-l+1;
}
int  main()
{
	cin>>n>>k;
	if(k<0)k=-k;
	long long  ed=n<<1;
	for(long long  i=k+2;i<=ed;i++)ans+=fangan(i)*fangan(i-k);
	printf("%lld\n",ans);
	return  0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	rep(b, 2, 2 * n + 1) {
		int a = k + b;
		if (a >= 2 && a <= 2 * n) {
			ll ta, tb;
			if (b <= n) tb = b - 1;
			else tb = 2 * n + 1 - b;
			if (a <= n) ta = a - 1;
			else ta = 2 * n + 1 - a;
			ans += tb * ta;
		}
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
char IO;
int rd(){
	int num=0;bool f=0;
	while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=1;
	do num=(num<<1)+(num<<3)+(IO^48);
	while(IO=getchar(),IO>=48&&IO<=57);
	return f?-num:num;
}
ll A,B,C,D;
int main(){
	A=rd(),B=rd(),C=rd(),D=rd();
	if(C*D<=B){cout<<-1;return 0;}
	cout<<(A-1)/(C*D-B)+1;
	return 0;
}

 #include <bits/stdc++.h>
 using namespace std;
 int main() {
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   cout<<A*D-B*C<<endl;
 }


//#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
	int ans, x, y;
	cin >> x >> y;
	vector<int> input(3);
	input[x]++;
	input[y]++;

	for (int i = 0; i < 3; i++) {
		if (input[i] == 0)ans = i;
	}

	if (x == y) {
		ans = x;
	}

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

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a,b;
  cin>>a>>b;
  int c=0,d=0;
  for(auto k:a){
    c+=k-'0';
  }
  for(auto k:b){
    d+=k-'0';
  }
  cout<<max(c,d);
  return 0;
}


#include <iostream>
int a[100];
int b[100];
int used[200];
int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i] >> b[i];
        if (a[i] != -1) ++used[a[i] - 1];
        if (b[i] != -1) ++used[b[i] - 1];
        if (a[i] != -1 and b[i] != -1 and a[i] >= b[i]) {
            std::cout << "No\n";
            return 0;
        }

        if (a[i] != -1 and used[a[i] - 1] == 2) {
            std::cout << "No\n";
            return 0;
        }

        if (b[i] != -1 and used[b[i] - 1] == 2) {
            std::cout << "No\n";
            return 0;
        }
    }
    int ilen, jlen, idx;
    for (int i = 0; i < n; ++i) {
        for (int j = i - 3; j < n; ++j) {
            if (i == j) continue;
            if (j < 0) continue;
            if (a[i] == -1 or b[i] == -1) continue;
            if (a[i] <= a[j] and a[j] <= b[i] and a[i] <= b[j] and b[j] <= b[i]) {
                std::cout << "No\n";
                return 0;
            }

            if (b[j] != -1) {
                if (a[i] <= a[j] and a[j] <= b[i]) {
                    ilen = b[i] - a[i] + 1;
                    jlen = b[j] - a[j] + 1;
                    if (ilen != jlen) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            } else {
                if (a[i] <= a[j] and a[j] <= b[i]) {
                    ilen = b[i] - a[i];
                    idx = a[j] + ilen - 1;
                    if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            }

            if (a[j] != -1) {
                if (a[i] <= b[j] and b[j] <= b[i]) {
                    ilen = b[i] - a[i] + 1;
                    jlen = b[j] - a[j] + 1;
                    if (ilen != jlen) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            } else {
                if (a[i] <= b[j] and b[j] <= b[i]) {
                    ilen = b[i] - a[i];
                    idx = b[j] - ilen - 1;
                    if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            }
        }
    }
    std::cout << "Yes\n";
}

// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
        if (a[i] > 0) --a[i];
        if (b[i] > 0) --b[i];
    }

    vector<int> v(2 * n, -1);
    rep(i, n) {
        if (a[i] != -1) v[a[i]] = i;
        if (b[i] != -1) v[b[i]] = i + n;
    }

    int cnt = 0;
    rep(i, n) if (a[i] == -1 && b[i] == -1) ++cnt;
    auto dfs = [&](auto f, int now) -> void {
        // cout << now << "\n";
        if (now == 2 * n) {
            cout << "Yes\n";
            exit(0);
        }
        rep(i, 1, n + 1) {
            if (now + i * 2 > 2 * n) break;
            bool flag = true;
            int c = 0;
            rep(j, now, now + i) {
                if (v[j] >= n || (v[j + i] != -1 && v[j + i] < n)) {
                    flag = false;
                    break;
                }
                if (v[j] != -1) {
                    if (b[v[j]] != -1 && b[v[j]] != j + i) {
                        flag = false;
                        break;
                    }
                }
                if (v[j + i] != -1) {
                    if (a[v[j + i] - n] != -1 && a[v[j + i] - n] != j) {
                        flag = false;
                        break;
                    }
                }
                if (v[j] == -1 && v[i + j] == -1) ++c;
            }
            if (c > cnt) flag = false;
            if (!flag) continue;
            cnt -= c;
            f(f, now + 2 * i);
            cnt += c;
        }
    };
    dfs(dfs, 0);
    cout << "No\n";
}


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

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

	long long sum = 0;

	for (long long i = 0 ; i < n ; i++)
	{
		long long a = 0;
		long long b = 0;

		cin >> a >> b;

		sum += ((a + b) * (b - a + 1)) / 2;

	}

	cout << sum << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================
const ll MOD = 1000000007;
const ll N = 2e6+13, M = N;
//=======================
vi g[N];
ll arr[N];
vi a;
ll n, m, k;
//=======================

void solve() {
  ll i, j;
  cin >> n;
  vpii arr(n);
  ll sum = 0;
  fo(i, n) {
    ll x, y;
    cin >> x >> y;
    sum = sum + (((y* (y + 1))/2) - ((x*(x+1)) / 2) + x);
  }
  cout << sum << endl;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll t = 1;
    while(t--) {
      solve();
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main()
{

    int n;cin>>n;
    ll arr[n+3],arr1[n+3];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int j=0;j<n;j++)cin>>arr1[j];
    ll prev=-1,mx=0;
    for(int i=0;i<n;i++)
    {
        mx=max(mx,arr[i]);
        ll k=(arr[i]*arr1[i]);
        prev=max(prev,k);
        if(i>0)
        {
           prev=max(mx*arr1[i],prev);
        }
        cout<<prev<<endl;
    }
    return 0;
}

#include <cstdio>

#define rep( i, a, b ) for( int (i) = (a) ; (i) <= (b) ; (i) ++ )
#define per( i, a, b ) for( int (i) = (a) ; (i) >= (b) ; (i) -- )

typedef long long LL;

const int MAXN = 5e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int S[MAXN], T[MAXN];
int N;

int main()
{
	read( N );
	int l1 = 0, l2 = 0;
	rep( i, 1, N ) { int d;
		scanf( "%1d", &d );
		if( d ) S[++ l1] = i;
	}
	rep( i, 1, N ) { int d;
		scanf( "%1d", &d );
		if( d ) T[++ l2] = i;
	}
	int r = 1; LL ans = 0;
	for( int i = 1 ; i <= l1 ; i ++ )
		if( r <= l2 && S[i] >= T[r] )
			ans += S[i] - T[r], r ++;
		else
		{
			if( i == l1 ) return puts( "-1" ), 0;
			ans += S[i + 1] - S[i], i ++;
		}
	if( r <= l2 ) return puts( "-1" ), 0;
	write( ans ), putchar( '\n' );
	return 0;
}


#include <bits/stdc++.h>
#define For(i,l,r) for (register int i=l; i<=r; i++)
using namespace std;
typedef unsigned long long LL;
typedef signed long long ll;
template <typename T>
inline void read(T &x) {
	char c = getchar(); int w = 1; x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}

ll A, B, C, D;
signed main() {
	read(A); read(B); read(C); read(D);
	if (C * D - B <= 0) puts("-1");
	else cout << ceil(double(A * 1.0 / (C * 1.0 * D - B)));
	getchar();
	return 0;
}

#pragma region

#ifdef RYLOCAL
#include "lab.hpp"
#else
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#endif

using namespace std;
typedef long long ll;

#define INF 0x3f3f3f3f
#define dbg(x) printf("%lld ", (x));
#define LN putchar('\n')

#pragma endregion

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (b >= c * d)
        puts("-1");
    else {

        printf("%lld\n", (ll)ceil((double)a /(d * c - b)));
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
/*
 execution in cmd for windows: g++ p1.cpp -op1

  p1

  execution in terminal for linux: g++ p1.cpp

  ./a.out

*/
typedef long double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define all(v) v.begin(), v.end()
#define fsort(v) sort(all(v))
#define rsort(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(all(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define sumv(v,x) accumulate(v.begin(),v.end(),x);
const ll mod = 998244353;
const ll modulus = 1000000007;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1000000007;
#define pi 3.14159265
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define cs ll t;cin>>t;while(t--)
#define cs1 ll t;t=1;while(t--)
#define input(v) for(i=0;i<v.size();i++) cin>>v[i];
#define output(v) for(i=0;i<v.size();i++) cout<<v[i]<<" ";
#define dbg(n) cout<<"[ "<<n<<" ]" nl;

int main()
{
    io;
    //////////////////////////////////

    cs1 {
        ll i, j, s = 0, c, k = 0, q = 0, m = 0, e = 1, f = -1, x, y, ans = INF, p = 0, r, a, b, d, len, ct = 0,n;
        cin>>n;
        vll va(n),vp(n),vx(n),v;
        for(i=0;i<n;i++) {
            cin >> va[i] >> vp[i] >> vx[i];
            if(vx[i]>va[i]) v.pb(vp[i]);
        }
        if(v.size()==0) cout<<"-1";
        else{
            fsort(v);cout<<v[0] ;
        }

    }
    //////////////////////////////////
    // cer;

}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;

  ll ans = -1;
  for (int i = 0; i < N; ++i) {
    ll A, P, X;
    cin >> A >> P >> X;

    if (X - A > 0) {
      if (ans < 0) {
        ans = P;
      } else {
        ans = min(ans, P);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1e9 + 7
#define e1 1e-9
#define v vector< long long >
#define vp vector< pair < long long,long long > >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ft first
#define sd second
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test \
    ll tt{0}; \
    cin>>tt; \
    while(tt--)
using namespace std;
bool prime(ll n) {
    if (n < 2)return false;
    for (ll x = 2; x * x <= n; x++) {
        if (n % x == 0)return false;
    }
    return true;
}
vector<ll> Seiveprime(ll n)
{
    vector<bool> isPrime(n, true);
    for (int i = 2; i * i < n; i++)
    {
        if (isPrime[i])
        {
            for (int j = i * i; j < n; j += i)
                isPrime[j] = false;
        }
    }
    vector<ll> prime;
    prime.push_back(2);
    for (int i = 3; i < n; i += 2)
        if (isPrime[i])
            prime.push_back(i);
    return prime;
}
vector<ll> factors(ll n) {
    vector<ll> f;
    for (ll x = 2; x*x <= n; x++) {
        while (n%x == 0) {
            f.pb(x);
            n /= x;
        }
    }
    if (n > 1) f.pb(n);
    return f;
}
vp pri_fact(ll n) {
    v x = factors(n);
    vp y;
    y.eb(x[0], 1);

    for (ll i = 1; i < x.size(); i++) {
        if (x[i] == x[i - 1]) {
            y.back().second++;
        } else {
            y.eb(x[i], 1);
        }
    }

    return y;
}
ll lcm(ll a,ll b) {
    return (a * b) / __gcd(a, b);
}
tuple<int,int,int> gcd(int a, int b) {
    if (b == 0) {
        return {1,0,a};
    } else {
        int x,y,g;
        tie(x,y,g) = gcd(b,a%b);
        return {y,x-(a/b)*y,g};
    }
}
ll mult(ll x,ll y,ll m) {
    return (x * y) % m;
}
//returns x^n (mod m)
ll bin_pow(ll x,ll n,ll m) {
    if (n == 0)return 1;
    if (n & 1)return mult(x, bin_pow(x, n - 1, m), m);
    return bin_pow(mult(x, x, m), n / 2, m);
}
ll ind_of_2(ll x) {
    ll i = 0;

    while (x / (1 << i) != 1)
        i++;

    return i;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll r{0},x{0},y{0};
    cin>>r>>x>>y;

    if(r*r>x*x+y*y)
    {
        cout<<2;
        return 0;
    }

    for(ll i=0;i<1000000;i++)
    {
        if(i*i*r*r>=x*x+y*y) {
            cout << i;
            break;
        }
    }

    return 0;
}

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

// 2の27乗＝１億３千万
#define rep(i, n, N) for (int i = n; i < (int)(N); i++)
#define ascending(array) sort(array.begin(), array.end());
#define descending(array) sort(array.rbegin(), array.rend());
#define log(name, message) cout << name << " = " << message << endl
#define out(content) cout << content << endl
#define max(array) *max_element(array.begin(), array.end())
#define min(array) *min_element(array.begin(), array.end())

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

  double length = sqrt(pow(X, 2) + pow(Y, 2));
  if (R <= length) {
    out(ceil(length / R));
  } else {
    out(2);
  }
}


#include<iostream>
#include<string>
#include<vector>
#include<map>

using namespace std;

char winner(char a, char b){
    if(a == b) return a;
    int x;
    if(a == 'R') x = 1;
    else if (a == 'S') x = 2;
    else x = 4;
    int y;
    if(b == 'R') y = 1;
    else if (b == 'S') y = 2;
    else y = 4;
    char res;
    if(x + y == 3) res = 'R';
    if(x + y == 5) res = 'P';
    if(x + y == 6) res = 'S';
    return res;
}

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    for(int i = 0; i < k; i++){
        string t = s + s;
        for(int j = 0; j < n; j++){
            s[j] = winner(t[2 * j], t[2 * j + 1]);
        }
    }
    cout << s[0];
}


#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << " " << x << "\n";
#define fo(i, n) for(ll i = 0; i < n; i++)
#define Fo(i, k, n) for(ll i = k; i < n; i++)
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
using namespace std;
using namespace __gnu_pbds;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin >> s;
	cout << s[1] << s[2] << s[0];

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
string S;
int main(){
	cin>>S;
	cout<<S.substr(1,3)+S[0]<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,a,b,c) for(ll i=a;i<b;i+=c)
#define For2(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define vec_ll vector<vector<ll>>
#define vec_pr vector<pair<ll,ll>>
#define p_ll pair<ll,ll>
#define pbk push_back
#define mkpr make_pair
#define fst first
#define snd second

void print(ll *arr, ll n){
    For(i,0,n,1)cout<<arr[i]<<" ";
    cout<<endl;
}

void print_vec(vector<ll> &vec, ll n){
    For(i,0,n,1)cout<<vec[i]<<" ";
    cout<<endl;
}

bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll fast_expo(ll a, ll p){
    //cout<<a<<" ";
    ll x=p-2;
    ll curr=a;
    ll ans=1;
    while(x!=0){
        if(x%2==1){
            ans=(ans*curr)%p;
        }
        x/=2;
        curr=(curr*curr)%p;
    }
    return ans;
}

//

//

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

	//Step 1. Find prime factors
	vector<ll> prime;
	ll prime_len=3;
	prime.pbk(2);
	prime.pbk(3);
	prime.pbk(5);

	For(i,6,501,1){
		bool poss=true;
		ll itr=0;
		ll root = sqrt(i);
		while(itr<prime_len && prime[itr]<=root){
			if(i%prime[itr] == 0){
				poss=false;
				break;
			}
			itr++;
		}

		if(poss==true){
			prime.pbk(i);
			prime_len++;
		}
	}

	//Step2. Calculate the DP array
	ll Dp[200001];
	Dp[1]=1;Dp[2]=3;Dp[3]=5;

	For(i,4,200001,1){
		ll root=sqrt(i), prod=1, temp=i;
		ll itr=0;

		while(itr<prime_len && prime[itr]<=root){
				if(temp%prime[itr]==0){
					ll expo=0;

					while(temp%prime[itr]==0){
						expo++;
						temp/=prime[itr];
					}

					prod*=(expo+1);
				}
				itr++;
		}

		if(temp!=1)prod*=2;

		Dp[i]=Dp[i-1]+prod;

		//if(i<=10)cout<<"i: "<<i<<" prod: "<<prod<<"\n";
	}

	ll K;
	cin>>K;

	ll ans=0;
	For(i,1,K+1,1){
		//cout<<Dp[K/i]<<"\n";
		ans+=Dp[K/i];
	}

	cout<<ans;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
const int MOD=998244353,inv2=(MOD+1)/2;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
int fact[301],inv[301];
static inline void init(int MAX)
{
  fact[0]=1;rep(i,MAX)fact[i+1]=1l*fact[i]*(i+1)%MOD;
  inv[MAX]=MPow(fact[MAX],MOD-2);
  rep(i,MAX)inv[MAX-1-i]=1l*inv[MAX-i]*(MAX-i)%MOD;
}
static inline int comb(const int n,const int k)
{
  if(k<0||n<k){return 0;}return 1l*fact[n]*inv[n-k]%MOD*inv[k]%MOD;
}
int main(void)
{
  int N=IN(),K=IN(),A[N],sum[K+1]={0},temp[N],total=0;sum[0]=N;
  init(K);rep(i,N){A[i]=IN();temp[i]=1;}
  rep(i,K){rep(j,N){temp[j]=(1l*temp[j]*A[j])%MOD;if(temp[j]<0){temp[j]+=MOD;}sum[i+1]=(1l*sum[i+1]+temp[j])%MOD;}}
  rep(i,K)
  {
    total=0;
    rep(j,i+2){total=(1l*total+1l*comb(i+1,j)*(1l*sum[j]*sum[i+1-j]%MOD-sum[i+1]+MOD)%MOD*inv2)%MOD;}
    OUT(total);
  }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 100000000

using namespace std;

//unsigned long long a[(2*100000)+10]={0};

// To compute x^y under modulo m
ull power(ull x, ull y, ull m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}

// Function to find modular inverse of a under modulo m
// Assumption: m is prime
ull modInverse(ull x, ull m)
{
	return power(x,m-2,m);
}

int main(){

	int n,k,temp,ans;
	cin>>n>>k;
	ans = 0;
	temp = (n*(n+1))/2;
	ans = temp*100*k;

	temp = (k*(k+1))/2;
	ans = ans + (temp*n);
	cout<<ans;
}

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

signed main() {
    int n,x;
    cin>>n>>x;
    x *= 100;
    int v[n], p[n];
    rep(i, n) {
        cin >> v[i] >> p[i];
    }
    int sum = 0;
    rep(i, n) {
        sum += v[i] * p[i];
        if(sum > x){
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

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

#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (v).size()
#define INT(...)                                                               \
    int __VA_ARGS__;                                                           \
    read(__VA_ARGS__)
#define LL(...)                                                                \
    ll __VA_ARGS__;                                                            \
    read(__VA_ARGS__)
#define DOUBLE(...)                                                            \
    double __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define CHAR(...)                                                              \
    char __VA_ARGS__;                                                          \
    read(__VA_ARGS__)
#define STRING(...)                                                            \
    string __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
    vector<type> name(size);                                                   \
    read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <class T> inline vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}

void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
    read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
    for(auto &a : v)
        read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
    read(head), read(tail...);
}
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    LL(n, x);
    VEC(ll, a, n);
    vector<ll> res;
    rep(i, n) {
        if(a[i] != x) {
            res.push_back(a[i]);
        }
    }
    rep(i, res.size()) { cout << res[i] << (i == res.size() - 1 ? "\n" : " "); }
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int A, B, C; cin >> A >> B >> C;
if(A>B){ cout << "Takahashi\n"; return 0; }
if(A<B){ cout << "Aoki\n"; return 0; }
if(C){ cout << "Takahashi\n"; }else{ cout << "Aoki\n"; }
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;

typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

int main(){
  int n, k, m;
  cin >> n >> k >> m;
  vector<int> a(n - 1);
  rep(i, n - 1){
    cin >> a[i];
  }

  int ans = m * n;

  rep(i, n-1){
    ans -= a[i];
  }

  if(ans > k){
    cout << -1 << endl;
  } else {
    ans = max(ans, 0);
    cout << ans << endl;
  }
}


#include <iostream>
using namespace std;

int main() {
	int A,B;
  cin >>A>>B;
  cout << A*2+100-B;
	return 0;
}

//template start
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;
using Graph = vector<vector<ll>>;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define ANS cout << ans << endl
const int MOD = 1000000007;

//from char to int
ll ctoi(char c)
{
    ll i = c - 48;
    return i;
}
//素数判定
bool is_prime(ll X)
{
    for (ll i = 2; i <= ll(sqrt(X)); i++)
    {
        if (X % i == 0)
        {
            return false;
        }
    }
    return true;
}
//平方数判定
bool is_square(ll N)
{
    if (ll(sqrt(N)) * ll(sqrt(N)) == N)
    {
        return true;
    }
    else
    {
        return false;
    }
}
//各位の和の計算
ll sum_of_digits(ll num)
{
    ll sum = 0;
    while (num)
    {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}
//ベクトルの積集合
vector<ll> set_product(vector<ll> v1, vector<ll> v2)
{
    vector<ll> ret(0);
    for (ll i : v1)
    {
        if (find(v2.begin(), v2.end(), i) != v2.end())
        {
            ret.push_back(i);
        }
    }
    return ret;
}
//from string to vector<char>
vector<char> stov(string s)
{
    vector<char> v(all(s));
    return v;
}
//from decimal to binary
string itob(ll j)
{
    return bitset<10>(j).to_string();
}
//max of vector
ll vmax(vector<ll> v)
{
    return *max_element(all(v));
}
//min of vector
ll vmin(vector<ll> v)
{
    return *min_element(all(v));
}
//sum of vector
ll vsum(vector<ll> v)
{
    return accumulate(all(v), (ll)0);
}

//template end

int main()
{
    int A, B;
    cin >> A >> B;
    int ans = 2 * A + 100 - B;
    ANS;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout << '\n';
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n';

int n;
const int N=19;
int a[N][3];
int weight[N][N];
int dis[N][N];
int dp[N][1LL<<N];

int find(int cur,int mask){
	if(dp[cur][mask]!=-1) return dp[cur][mask];
	if(mask==(1LL<<(n))-1){
		//cout<<cur<<' '<<mask<<' '<<dis[cur][0];LOL
		return weight[cur][0];
	}
	int ans=INF;
	for(int i=0 ; i<n ; i++){
		if((mask|(1LL<<i))!=mask){
			ans=min(ans,weight[cur][i]+find(i,mask|(1LL<<i)));
            //cout<<cur<<" to "<<i<<" "<<(mask | (1<<(i)))<<" "<<ans<<"\n";
           // cout<<weight[cur][i]<<" "<<find(i, mask | (1<<(i)))<<"\n";
		}
	}
	return dp[cur][mask]=ans;
}

void solve(){
	cin>>n;
	for(int i=0 ; i<n ; i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<n ; j++){
			weight[i][j]=abs(a[j][0]-a[i][0])+abs(a[j][1]-a[i][1])+max(0LL,a[j][2]-a[i][2]);
			dis[i][j]=weight[i][j];
		}
	}
	for(int k=0 ; k<n ; k++){
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<n  ; j++){
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	//for(int i=0 ; i<n ; i++){
	//	for(int j=0 ; j<n ; j++){
	//		cout<<weight[i][j]<<' ';
	//	}LOL
	//}
	//LOL cout<<"-------"; LOL
	//for(int i=0 ; i<n ; i++){
	//	for(int j=0 ; j<n ; j++){
	//		cout<<dis[i][j]<<' ';
	//	}LOL
	//}
	//LOL cout<<"-------"; LOL
	memset(dp,-1,sizeof(dp));
	cout<<(find(0,0));LOL
}

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

#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#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--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
#define prl cerr<<"called: "<< __LINE__ << endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
const int N = 17;
int x[N],y[N],z[N];
const int inf = 1e9;
int dist[N][(1<<N) + 10];
typedef array<int,3> ar;

int d(int i,int j){
  return abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0LL,z[j] - z[i]);
}

int32_t main(){
  fastio;
  rep(i,0,N){
    rep(j,0,(1<<N) + 10){
      dist[i][j] = inf;
    }
  }
  int n;
  cin >> n;
  rep(i,0,n){
    cin >> x[i] >> y[i] >> z[i];
  }

  priority_queue<ar,vector<ar>, greater<ar> > pq;
  dist[0][(1<<0)] = 0;
  pq.push({0,0,(1<<0)});
  while(!pq.empty()){
    ar Cur = pq.top();
    pq.pop();
    int cur = Cur[1];
    int msk = Cur[2];
    for(int j=0;j<n;j++){
      if(d(cur,j) + dist[cur][msk] < dist[j][msk|(1<<j)]){
        dist[j][msk|(1<<j)] = d(cur,j) + dist[cur][msk];
        pq.push({dist[j][msk|(1<<j)],j,(msk|(1<<j))});
      }
    }
  }

  cout << dist[0][(1<<n)-1]<<endl;

  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}


#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){
	while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}}
#define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debugr(l,r,x)
#define cerr while(0) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll sum[500005];
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int K;
	cin>>K;
	ll ans=0;
	for(int i=1;i<=K;i++){
		sum[i]=sum[i-1];
		for(int j=1;j*j<=i;j++){
			if(i%j==0) sum[i]+=2;
			if(j*j==i) sum[i]--;
		}
	}
	debugr(1, 10, sum[i]);
	for(int i=1;i<=K;i++){
		//if(K%i!=0) continue;
		ans+=sum[K/i];
	}
	cout<<ans;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define fi first
#define se second
#define max Max
#define min Min
#define abs Abs
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define fan(x) (((x-1)^1)+1)
#define mp(x,y) make_pair(x,y)
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a<b?a:b;}
template<typename T,typename TT> inline T Max(T a,TT b){return a<b?b:a;}

const int N=1e6+5;
int l,r,m,pri[N],phi[N],vis[N],num,all;

inline void init()
{
	for(int i=2;i<=1000000;++i)
	{
		if(!vis[i])
		{
			pri[++m]=i;
			phi[i]=i-1;
		}
		for(int j=1;j<=m;++j)
		{
			if(pri[j]*i>1000000)
				break;
			vis[i*pri[j]]=1;
			if(i%pri[j]==0)
			{
				phi[i*pri[j]]=phi[i]*pri[j];
				break;
			}
			phi[i*pri[j]]=phi[i]*(pri[j]-1);
		}
	}
}

int query(int n,int x)
{
	vector<int> pp;
	for(int i=2;i*i<=x;++i)
		if(x%i==0)
		{
			pp.push_back(i);
			while(x%i==0) x/=i;
		}
	if(x>1) pp.push_back(x);
	int res=0;
	for(int i=1;i<(1<<pp.size());++i)
	{
		int p=1,num=0;
		for(int j=0;j<pp.size();++j)
			if(i>>j&1) p*=pp[j],++num;
		if(num&1) res+=n/p;
		else res-=n/p;
	}
	return n-res;
}

signed main()
{
	init();
	l=read();r=read();
	all=(r-l+1)*(r-l)/2;
	if(l==1) num+=r-1,++l;
	for(int i=l;i<=r;++i)
		num+=r/i-(l-1)/i-1;
	for(int i=l;i<=r;++i)
		num+=phi[i]-query(l-1,i);
	printf("%lld\n",(all-num)*2);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i = (n-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF=1<<30;
//const ll INF=1LL<<60;

ll binomial(ll N, ll K) {
  if(K < 0 || N < K) return 0;
  ll ret = 1;
  for(ll i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

int main() {

    ll a,b,k;
    cin >> a >> b >> k;

    ll n = a+b;
    string ans;
    ll count = 1;
    rep(i,n) {
        if(count+binomial(n-i,a)-binomial(n-i-1,a) <= k && b>0) {
            count += binomial(n-i,a)-binomial(n-i-1,a);
            ans+='b';
            --b;
        }
        else if(a>0) {
            ans+='a';
            --a;
        }
        else    ans+='b';
    }

    cout<<ans<<endl;

 return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 10010;

int a[N];

int main() {
    cin >> a[0] >>a[1] >> a[2];
    sort(a, a + 3);
    cout << a[1] + a[2];

    return 0;
}


// Author Nagendra patel
#include<bits/stdc++.h>
using namespace std;
#include <numeric>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define MOD 1000000007
#define INT_BITS 16
#define INF 1e18
#define pi 3.141592
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n"
#define pb push_back
#define pii pair<int,,int>
#define MAXN   1001
#define all(x) (x).begin(), (x).end()

#ifndef ONLINE_JUDGE
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define deb_arr(a,n) {cout<<#a<<":";for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';}
#define deb_mat(dist,n,m) {cout<<#dist<<"\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}}
#else
#define deb(x) ;
#define debug(x,y) ;
#define deb_arr(a,n) ;
#define deb_mat(dist,n,m) ;
#endif

#define x first
#define y second
#define N 400003

vector<int> G[N];

int cnt,cnt2,vis[N];

void dfs(int i) {
    vis[i]=1;
    ++cnt;
    for(int nx:G[i]) {
        if(!vis[nx])
            dfs(nx);
        ++cnt2;
    }
}

int32_t main()
{
    fast;

    int n;
    cin>>n;
    while(n--)
    {
        int u,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
     int ans=0;
    for(int i=1;i<N;++i) {
        cnt=cnt2=0;
        if(!vis[i])
            dfs(i);
        ans+=min(cnt,cnt2/2);
    }
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define vec vector
using namespace std;

const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;

long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}

ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
   //cin >> q;
  while (q-- >0) {
    int n;
    cin >> n;
    int m = 400000;
    vec<vec<int>> gr(m);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      --x;
      --y;
      gr[x].push_back(y);
      gr[y].push_back(x);
    }
    vec<bool> was(m);
    function<void(int, vec<int>&)> dfs = [&] (int v, vec<int>& comp) {
      was[v] = true;
      comp.push_back(v);
      for (int next : gr[v]) {
        if (!was[next]) {
          dfs(next, comp);
        }
      }
    };
    int ans = 0;
    for (int i = 0; i < m; ++i) {
      if (was[i]) continue;
      vec<int> comp;
      dfs(i, comp);
      int deg = 0;
      for (int x : comp) {
        deg += gr[x].size();
      }
      int edges = deg / 2;
      if (edges < comp.size()) {
        assert (edges + 1 == comp.size());
        ans += edges;
      } else {
        ans += comp.size();
      }
    }
    cout << ans << "\n";
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int64_t a=0;a<b;a++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define ll int64_t
#define mod 1000000007
#define vl vector<int64_t>

int main() {
  ll n,ans;
  ll s,t;
  s=0;
  t=0;
  ans=0;
  cin>>n;
 vector<vector<ll>> da(n, vector<ll>(2));
  fo(i,n){
    fo(j,2){
      cin>>da.at(i).at(j);
    }
  }
  fo(i,n){
    fo(j,n){
      if(i!=j){
        s=abs(da.at(j).at(1)-da.at(i).at(1));
        t=abs(da.at(j).at(0)-da.at(i).at(0));
        if(s<=t){ans++;}
      }
    }
  }
  cout<<ans/2<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  for (auto &&[x, y] : p) {
    cin >> x >> y;
  }
  sort(begin(p), end(p));
  int ans = 0;
  for (auto i = begin(p); i != end(p); ++i) {
    for (auto j = begin(p); j != i; ++j) {
      auto y = i->second - j->second;
      auto x = i->first - j->first;
      if (abs(y) > x)
        ;
      else
        ++ans;
    }
  }
  cout << ans << "\n";
}


#include<bits/stdc++.h>
#ifdef BIZON
	#define rr(x) cerr << "\e[1;38;5;172m" << #x << "\e[0m = " << (x) << endl;
#else
	#define rr(x) 0;
	#define endl '\n'
#endif
#define ALL(c) begin(c), end(c)
#define II(...) __VA_ARGS__; [](auto&...x){(cin>>...>>x);}(__VA_ARGS__);
#define ii(...) int II(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;

int main(){
	if(auto f="in.txt"; fopen(f,"r") && freopen(f,"r",stdin));
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(9);cout<<fixed;

	ii(n)
	vector<ll> a(n);
	for(auto &_ : a) cin>>_;

	ll ans = 0;
	ll p = 0, s = 0;
	ll cur = 0;
	for(auto x : a){
		s+=x;
		p = max(p, s);
		ans = max(ans, cur+p);
		cur+=s;
	}

	cout<<ans<<endl;

	return 0;
}

//Author: Xzirium
//Time and Date: 17:44:16  18 March 2021

//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(998244353);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);

}

//Work

ll root[500001];
ll _size[500001];
void initialise()
{
    for (ll i = 0; i < 500001; ++i)
    {
        root[i]=i;
    }
    for (ll i = 0; i < 500001; ++i)
    {
        _size[i]=1;
    }
}
ll find_root(ll v)
{
    if(root[v]==v)
    {
        return v;
    }
    else
    {
        root[v]=find_root(root[v]);
        return root[v];
    }
}
bool _find(ll a,ll b)
{
    return find_root(a)==find_root(b);
}
void _union(ll a,ll b)
{
    ll _rootA=find_root(a);
    ll _rootB=find_root(b);
    if(_rootA!=_rootB)
    {
        _size[_rootA]+=_size[_rootB];
        _size[_rootB]=0;
        root[_rootB]=_rootA;
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    initialise();
    READV(N);
    FORI(i,1,N+1)
    {
        READV(f);
        _union(i,f);
    }
    ll ans=1;
    FORI(i,1,N+1)
    {
        if(_size[i]>0)
        {
            ans=(ans*2)%MOD;
        }
    }
    cout<<(ans-1+MOD)%MOD<<endl;

//-----------------------------------------------------------------------------------------------------------//

    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
#define GETVEC(v) for(auto& m : v) cin >> m;
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int H, W; cin >> H >> W;
	vector<char> as(H * W);
	multimap<char, int> ch2PosMap;
	int S, G;
	REP(i, H)REP(j, W)
	{
		char ch; cin >> ch; as[i * W + j] = ch;
		ch2PosMap.insert({ ch, i * W + j });
		if (ch == 'S') S = i * W + j;
		if (ch == 'G') G = i * W + j;
	}
	const int INF = 1e9;
	vector<int> dists(H * W, INF);
	dists[S] = 0;
	deque<int> Q{ S };
	vector<bool> used(H * W, false);
	while (!Q.empty())
	{
		int t = Q.front(); Q.pop_front();
		vector<int> ns;
		if ('a' <= as[t] && as[t] <= 'z' && used[t] == false)
		{
			used[t] = true;
			auto range = ch2PosMap.equal_range(as[t]);
			for (auto itr = range.first; itr != range.second; ++itr)
			{
				int pos = itr->second;
				if (pos != t && used[pos] == false)
				{
					ns.push_back(pos);
					used[pos] = true;
				}
			}
		}
		if (t - W > 0 && as[t - W] != '#') ns.push_back(t - W);
		if (t + W < H * W && as[t + W] != '#') ns.push_back(t + W);
		if (t % W > 0 && as[t - 1] != '#') ns.push_back(t - 1);
		if (t % W != W - 1 && as[t + 1] != '#') ns.push_back(t + 1);
		for (const int n : ns)
		{
			if (dists[n] > dists[t] + 1)
			{
				dists[n] = dists[t] + 1;
				Q.push_back(n);
			}
		}
	}
	cout << (dists[G] != INF ? dists[G] : -1) << endl;
}

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

const int MAXN = 1e5 + 5;

int N, M;
int a[MAXN][2];
vector <pair <int, int>> adj[MAXN];
int bio[MAXN], ans[MAXN];
int c[MAXN];

void load() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++)
    for (int j = 0; j < 2; j++)
      scanf("%d", a[i] + j);
  for (int i = 1; i <= N; i++)
    scanf("%d", c + i);
}

void dfs(int x, int p) {
  bio[x] = 1;
  for (auto it : adj[x]) {
    int nxt = a[it.first][it.second];
    if (nxt == p || bio[nxt] == 2)
      continue;
    ans[it.first] = it.second;
    if (!bio[nxt])
      dfs(nxt, x);
  }
  bio[x] = 2;
}

void solve() {
  for (int i = 0; i < M; i++)
    if (c[a[i][0]] != c[a[i][1]])
      ans[i] = c[a[i][0]] > c[a[i][1]];
    else
      for (int j = 0; j < 2; j++)
        adj[a[i][j]].push_back({i, j ^ 1});
  for (int i = 1; i <= N; i++)
    if (!bio[i])
      dfs(i, 0);
  for (int i = 0; i < M; i++)
    printf("%s\n", ans[i] ? "->" : "<-");
}

int main() {
  load();
  solve();
  return 0;
}


    #include<iostream>
    using namespace std;

    int main(){
      int n,a,b,sum;
      scanf("%d%d%d",&n,&a,&b);
      sum = (n-a)+b;
      printf("%d",sum);

      return 0;
    }

#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
    char a = in<char>();
    char b = in<char>();
    if(a=='Y'){
        b += 'A' - 'a';
    }
    cout << b << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 998244353;
const ll INF = 1e18;
const ll MAX_N = 1010101;
void chmin(ll a, ll b) { if (a > b) { a = b; } }
void chmax(ll a, ll b) { if (a < b) { a = b; } }

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//union-find木について
ll par[201010];
ll rank2[201010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 1;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
		rank2[y] += rank2[x];
	}
	else {
		par[y] = x;
		rank2[x] += rank2[y];
	}
}

ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
bool flag[201010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll>h(n);
	rep(i, n) {
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	vector<ll>sum1((n + 1) / 2), sum2((n + 1) / 2);

	for (ll i = 0;i+1 < n;i += 2) {
		sum1[i / 2 + 1] = sum1[i / 2] + h[i + 1] - h[i];
	}
	for (ll i = n - 2;i > 0;i -= 2) {
		sum2[i / 2] = sum2[i / 2 + 1] + h[i+1] - h[i];
	}

	ll ans = INF;
	rep(i, m) {
		ll w;
		cin >> w;
		ll x = lower_bound(h.begin(), h.end(), w) - h.begin();
		if (x & 1) x ^= 1;
		ans = min(ans, sum1[x / 2] + sum2[x / 2] + abs(h[x] - w));
	}
	cout << ans << endl;
	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
long long a[200010],b[200010],sumq[200010],sumh[200010],ans=1999999999;
int main()
{
     int i,now=0;
     cin>>n>>m;
     for(i=1;i<=n;i++) cin>>a[i];
     for(i=1;i<=m;i++) cin>>b[i];
     sort(a+1,a+n+1);
     sort(b+1,b+m+1);
     for(i=2;i<=n;i+=2) sumq[i]=sumq[i-2]+a[i]-a[i-1];
     for(i=n-1;i>=1;i-=2) sumh[i]=sumh[i+2]+a[i+1]-a[i];
     /*for(i=1;i<=n;i++) cout<<a[i]<<" ";
     cout<<endl;
     for(i=1;i<=m;i++) cout<<b[i]<<" ";
     cout<<endl;
     for(i=2;i<=n;i++) cout<<sumq[i]<<" "<<sumh[i]<<endl;*/
     for(i=1;i<=m;i++)
     {
         while(b[i]>a[now]&&now<=n) now++;
         if(now%2==1) ans=min(ans,a[now]-b[i]+sumq[now-1]+sumh[now+1]);
         else ans=min(ans,b[i]-a[now-1]+sumq[now-2]+sumh[now]);
     }
     cout<<ans;
     system("pause");
}


#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
typedef vector<vector<char>> Field;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a , b, c;
    cin >> a >> b >> c;
    ll ans = 21 - (a + b + c);
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define N 100005
using namespace std;
char s[N],t[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	rep(i,1,n){
		int j=n-i+1;
		if(s[i]=='6')t[j]='9';
		else if(s[i]=='9')t[j]='6';
		else t[j]=s[i];
	}
	puts(t+1);
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
	int to,next;
}e[10000];
int n,m,a[30],head[30],cnt,ans=1,res,t,b[30];
bool vis[30];
inline void add(int u,int v){
	cnt++;
	e[cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
inline void dfs1(int u){
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(vis[v])continue;
		vis[v]=1;
		b[++t]=v;
		dfs1(v);
	}
}
inline void dfs(int u,int s){
	bool tag[4],flag=0;
	memset(tag,0,sizeof(tag));
	int sum=0;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].to;
		if(a[v]&&!tag[a[v]])tag[a[v]]=1,sum++;
	}
	if(sum==3)return;
	if(s==t){
		a[u]=0;
		for(int i=1;i<=3;i++)if(!tag[i])res++;
		return;
	}
	for(int j=1;j<=3;j++)
	if(!tag[j]){
		flag=0;
		a[u]=j;
		for(int i=head[u];i;i=e[i].next){
			int v=e[i].to;
			if(a[v])continue;
			flag=1;
			dfs(v,s+1);
			break;
		}
		if(!flag){
		    for(int i=1;i<=t;i++)
		    if(!a[b[i]]){
			    dfs(b[i],s+1);
			    break;
		    }
	    }
	}
	a[u]=0;
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1,x,y;i<=m;i++){
		scanf("%lld%lld",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++)
	if(!vis[i]){
		vis[i]=1;
		t=1;
		b[1]=i;
		dfs1(i);
		//cout<<t<<endl;
		res=0;
		dfs(i,1);
		ans*=res;
	}
	printf("%lld",ans);
	return 0;
}

#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int>
#define all(v) v.begin(), v.end()
#define mt make_tuple
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
#define hash hash1
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R)
{
     int val = rng() % R;
     assert(val >= 0);
     return val;
}

const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = MOD1;

using namespace std;

//-------------------DEBUGGING-------------------------
void my_debugger(string s, int LINE_NUM) { cerr << endl; }
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
     if (s.back() != ',')
     {
          s += ',';
          cerr << "LINE(" << LINE_NUM << "): ";
     }
     int i = s.find(',');
     cerr << s.substr(0, i) << " = " << x;
     s = s.substr(i + 1);
     if (!s.empty())
          cerr << ", ";
     my_debugger(s, LINE_NUM, y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#else
#define debug(...) ;
#endif

void setMod(int mod_val)
{
     MOD = mod_val;
}
//-----------------------------------------------------

void files_init()
{
     freopen("maxflow.in", "r", stdin);
     freopen("maxflow.out", "w", stdout);
}

const int N = 1e5 + 5;
const int LOGN = 20;

vector<int> v[25];
vector<pii> edges;
bool check[25];
int color[25];
bool g=true;

void dfs(int i,int col=0)
{
    if(!g)return;
    debug(i,col);
    color[i]=col;
    check[i]=true;
    for(auto it:v[i])
    {
         if(check[it] && color[it]==col)
         {
              g=false;
              return;
         }
         else if(!check[it])
         dfs(it,col^1);
    }
}

int32_t main()
{
     getFaster;
     //files_init();
     int tests = 1;
     //cin >> tests;
     rep(ii, 0, tests)
     {
          int n,m;
          cin>>n>>m;
          rep(i,0,m)
          {
               int x,y;
               cin>>x>>y;
               x--,y--;
               edges.push_back({x,y});
               v[x].push_back(y);
               v[y].push_back(x);
          }

          int ans=0;
          rep(mask,0,(1<<n))
          {
               fill(check,check+n,false);
               fill(color,color+n,0);
               rep(i,0,n)v[i].clear();
               g=true;
               debug("HELLO");
               for(auto& it:edges)
               {
                   int x=it.f,y=it.s;
                   if( ((1<<x)&mask) && ((1<<y)&mask))
                   {
                        g=false;
                        break;
                   }
                   else if( !((1<<x)&mask) && !((1<<y)&mask) )
                   {
                        v[x].push_back(y);
                        v[y].push_back(x);
                   }
               }

               debug("EDGES ADDED");

               if(!g)continue;
               int temp=1;

               rep(i,0,n)
               if(!check[i] && !((1<<i) & mask))
               {
                    debug("DFS FROM I=",i)
                    dfs(i);
                    temp*=2;
                    if(!g)
                    break;
               }

               if(g)
               ans+=temp;
          }

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


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> pt;

#define MOD 1000000007

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

	int N;
	cin >> N;

	vector<vector<int> > C(N, vector<int>(N));

	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			cin >> C[i][j];
		}
	}

	int p;

	for(int i = 0; i < N; i++) {
		p = min_element(C[0].begin(), C[0].end()) - C[0].begin();
	}

	vector<int> A(N), B(N);

	for(int i = 0; i < N; i++) {
		A[i] = C[i][p];
	}

	for(int i = 0; i < N; i++) {
		B[i] = C[0][i] - C[0][p];
		for(int j = 1; j < N; j++) {
			if(C[j][i] - C[j][p] != B[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;

	for(int i = 0; i < N; i++) cout << A[i] << " ";
	cout << endl;

	for(int i = 0; i < N; i++) cout << B[i] << " ";
	cout << endl;
}

// b.cpp

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

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

template <typename T>
void chmin(T& a, T b) {if (b<a) a=b;}

int main() {
	int N;
	cin >> N;
	vector<vector<int>> C(N, vector<int>(N));
	int minC=1000000001, mini=-1, minj=-1;
	rep(i,N) rep(j,N) {
		cin >> C[i][j];
		if (C[i][j] < minC) {
			minC = C[i][j];
			mini=i; minj=j;
		}
	}
	vector<int> A(N), B(N);
	rep(i,N) A[i]=C[i][minj];
	rep(j,N) B[j]=C[mini][j]-C[mini][minj];
	bool exist = true;
	rep(i,N) rep(j,N) exist &= (C[i][j] == A[i] + B[j]);

	if (exist) {
		cout << "Yes" << endl;
		rep(i,N) cout << A[i] << " ";
		cout << endl;
		rep(i,N) cout << B[i] << " ";
		cout << endl;
	} else {
		cout << "No" << endl;
	}
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vec vector
using namespace std;

const ll INF = 1e18;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	vec<ll> a[3];
	int cnt[3] = {0, 0, 0};
	char dummy_stupid;
	for (ll i=0, x, y; i<2*n; i++) {
		cin >> x >> dummy_stupid;
		if (dummy_stupid == 'R') y = 0;
		if (dummy_stupid == 'G') y = 1;
		if (dummy_stupid == 'B') y = 2;
		a[y].push_back(x);
		cnt[y]++;
	}
	if ((cnt[0]&1)==0 && (cnt[1]&1)==0 && (cnt[2]&1)==0) {
		cout << 0 << '\n';
		return 0;
	}
	int p = -1, q = -1;
	for (int i=0; i<3; i++) {
		sort(a[i].begin(), a[i].end());
		if (cnt[i]&1) {
			q = p;
			p = i;
		}
	}
	assert(p!=-1 && q!=-1);
	int r = (-p-q+3) % 3;
	assert(p!=r && q!=r);

	ll res = INF;
	for (int i=0; i<a[p].size(); i++) {
		int pos = lower_bound(a[q].begin(), a[q].end(), a[p][i]) - a[q].begin();
		if (pos<a[q].size()) res = min(res, a[q][pos] - a[p][i]);
		if (pos>0) res = min(res, a[p][i] - a[q][pos-1]);
	}
	if (cnt[r] > 0) {
		vec<ll> sf(cnt[r]+1, INF);
		for (int i=0; i<cnt[r]; i++) {
			int pos = lower_bound(a[p].begin(), a[p].end(), a[r][i]) - a[p].begin();
			if (pos<cnt[p]) sf[i] = min(sf[i], a[p][pos] - a[r][i]);
			if (pos>0) sf[i] = min(sf[i], a[r][i] - a[p][pos-1]);
		}
		for (int i=cnt[r]-1; i>=0; i--) sf[i] = min(sf[i], sf[i+1]);
		ll pf = INF;
		for (int i=0; i<cnt[r]; i++) {
			ll cur = INF;
			int pos = lower_bound(a[q].begin(), a[q].end(), a[r][i]) - a[q].begin();
			if (pos<cnt[q]) cur = min(cur, a[q][pos] - a[r][i]);
			if (pos>0) cur = min(cur, a[r][i] - a[q][pos-1]);

			res = min(res, cur + min(pf, sf[i+1]));

			pos = lower_bound(a[p].begin(), a[p].end(), a[r][i]) - a[p].begin();
			if (pos<cnt[p]) pf = min(pf, a[p][pos] - a[r][i]);
			if (pos>0) pf = min(pf, a[r][i] - a[p][pos-1]);
		}
	}
	cout << res << '\n';
}

#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=int(n-1);i>=int(0);--i)
#define fore(i,a) for(auto &i:a)
#define all(x) x.begin(),x.end()
#define sz(x) ((int)(x).size())
#define bp(x) (__builtin_popcount((long long)(x)))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define V vector
#define P pair<int,int>
#define TP tuple<int,int,int>
#define F first
#define S second
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; }
using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1001001001;
const ll INFL = 1001001001001001001;
const int MAX = 2e6+1;

int main() {
    int n;cin>>n;n*=2;
    V<ll> r,g,b;
    rep(i,n){
        ll a;char c;
        cin>>a>>c;
        switch (c)
        {
        case 'R':
            r.push_back(a);
            break;
        case 'G':
            g.push_back(a);
            break;
        case 'B':
            b.push_back(a);
            break;
        }
    }

    if(sz(r)%2==0&&sz(g)%2==0&&sz(b)%2==0){
        cout<<0<<endl;
        return 0;
    }
    if(sz(r)%2==0)swap(g,r);
    else if(sz(b)%2==0)swap(g,b);
    sort(all(r));
    sort(all(g));
    sort(all(b));

    ll ans=INFL;
    rep(i,sz(r)){
        auto x = lower_bound(all(b),r[i]);
        if(x!=b.end()){
            chmin(ans,abs(r[i]-*x));
        }
        if(x!=b.begin()){
            x--;
            chmin(ans,abs(r[i]-*x));
        }
    }

    V<pair<ll,int>> minr,minb;
    rep(i,sz(g)){
        auto x = lower_bound(all(r),g[i]);
        if(x!=r.end()){
            minr.emplace_back(abs(g[i]-*x),i);
        }
        if(x!=r.begin()){
            x--;
            minr.emplace_back(abs(g[i]-*x),i);
        }
    }
    rep(i,sz(g)){
        auto x = lower_bound(all(b),g[i]);
        if(x!=b.end()){
            minb.emplace_back(abs(g[i]-*x),i);
        }
        if(x!=b.begin()){
            x--;
            minb.emplace_back(abs(g[i]-*x),i);
        }
    }
    sort(all(minr));
    sort(all(minb));
    rep(i,min(2,sz(minr))){
        rep(j,min(2,sz(minb))){
            if(minr[i].second==minb[j].second)continue;
            chmin(ans,minr[i].first+minb[j].first);
        }
    }

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


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using ld = long double;
template <class T> using Vec = vector<T>;
constexpr ll INF = 1010000000000000017;

int main() {
ll n;
  cin >> n;
  if(n==1){
  	cout << 0;
  }
  else{
  	cout << n-1;
  }

  return 0;
}

#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N=110;

int main()
{
string s;
getline(cin,s);
int n=s.size();
for(int i=0;i<n;i++)
{
if(s[i]=='.') break;
cout<<s[i];
}
return 0;
}


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

#define debug(x) cerr << #x << '=' << x << endl
#define rep(i, b, e) for (int i = b; i <= e; i++)

char s1[512345], s2[512345];
vector<int> a(512345);
vector<int> b(512345);
signed main(void) {
    int n, cnt = 0;
    cin >> n;
    scanf("%s%s", s1 + 1, s2 + 1);
    rep (i, 1, n) {
        if (s1[i] == '0') {
            cnt++;
        }
        if (s2[i] == '0') {
            cnt--;
        }
    }
    if (cnt != 0) {
        puts("-1");
        return 0;
    }
    int ans = 0;
    rep (i, 1, n) {
        if (s1[i] == '0') {
            a.push_back(i);
        }
        if (s2[i] == '0') {
            b.push_back(i);
        }
    }
    rep (i, 0, min(a.size(), b.size()) - 1) {
        if (a[i] != b[i]) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

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

struct UnionFind {
    vector<int> par;
    map<int, int> groups;

    UnionFind(int n) : par(n) {
        rep(i, n) par[i] = i;
        rep(i, n) groups[i] = 1;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        // if (groups[rx] < groups[ry]) swap(rx, ry);
        groups[rx] += groups[ry];
        groups.erase(ry);
        par[ry] = rx;
    }

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

// input
int N, Q;
vi C;

map<int, map<int, int>> m;

void input() {
    cin >> N >> Q;
    C = vi(N);
    rep(i, N) cin >> C[i];
}

void query1(UnionFind &uf) {
    int a, b;
    cin >> a >> b;
    int r1 = uf.root(a - 1), r2 = uf.root(b - 1);
    if (r1 == r2) return;
    if (m[r1].size() < m[r2].size()) swap(r1, r2);
    uf.unite(r1, r2);
    for (auto p : m[r2]) {
        m[r1][p.first] += p.second;
    }
}

void query2(UnionFind &uf) {
    int x, y;
    cin >> x >> y;
    int r = uf.root(x - 1);
    int ans = m[r][y];
    cout << ans << endl;
}

int main() {
    input();
    UnionFind uf(N);
    rep(i, N) m[i][C[i]] = 1;
    rep(i, Q) {
        int x;
        cin >> x;
        if (x == 1) query1(uf);
        else query2(uf);
    }
}


/*
  /^--^\
  \____/
 /      \ _____  _ __  __ ____  _     ____   ____  _____
|        || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_   _|
 \__  __/ |_|   |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define int ll
#define double long double

#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id<<1)
#define R(id) (id<<1|1)

#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (ll)(1e9+7)
#define INF (1e15)
#define EPS (1e-6)

#ifdef LOCALMEOW
#define debug(...) do{\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\
	" : ("#__VA_ARGS__ << ") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
#else
#define debug(...)
#endif
inline void IOS(){ ios::sync_with_stdio(false); cin.tie(0); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	int ans=1,now=b;
	while(p){
		if(p&1) ans=ans*now%MOD;
		p/=2; now=now*now%MOD;
	}
	return ans;
}
void minify(int &a,int b) { if(b<a) a=b; }
void maxify(int &a,int b) { if(b>a) a=b; }

int32_t main(){
	IOS();
	//code...
	int n; cin>>n;
	unordered_map<int,int> mp;
	int t;
	int mn=INF;
	while(n--){
		cin>>t;
		mn=min(mn,t);
		for(int i=1;i*i<=t;i++) if(t%i==0){
			if(mp.count(i)) mp[i]=__gcd(mp[i],t);
			else mp[i]=t;
			if(mp.count(t/i)) mp[t/i]=__gcd(mp[t/i],t);
			else mp[t/i]=t;
		}
	}
	int ans=0;
	for(auto &i:mp)
		if(i.F<=mn && i.F==i.S) ans++;
	cout<<ans<<"\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define x1 gdsfdsf
#define y1 fgdfgdfg
#define endl '\n'
const ll DIM = 2000+7;
ll A[DIM],G[DIM];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    for(ll i = 1;i<=n;++i)cin>>A[i];
    sort(A+1,A+1+n);
    G[0] = A[1];
    for(ll i = 1;i<=n;++i){
        G[i] = __gcd(G[i-1],A[i]);
    }
    map<ll,ll> M;
    for(ll i = 1;i<=n;++i){
        ll sq = sqrt(A[i]);
        for(ll div = 1;div<=sq;++div){
            if (A[i]%div!=0)continue;
            ll prev = div;
            div = A[i]/div;
            {
                if (M.count(div)==0)M[div] = A[i];
                else M[div] = __gcd(M[div],A[i]);
            }
            div = prev;
            {
                if (M.count(div)==0)M[div] = A[i];
                else M[div] = __gcd(M[div],A[i]);
            }
        }
    }
    ll ptr = 0;
    G[0] = 0;
    ll res = 0;
    for(auto to:M){
        if (to.first!=to.second)continue;
        while(A[ptr+1]<=to.first && ptr<n)++ptr;
        if (G[ptr]%to.first==0)++res;
    }
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PI pair<int,int>
const int maxm=2e5+5;
int mark[maxm];
int a[maxm];
int b[maxm];
int p[maxm];
int n;
vector<PI>ans;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    for(int i=1;i<=n;i++){
        cin>>p[i];
        if(p[i]!=i&&b[p[i]]>=a[i]){//不合法
            return cout<<-1<<endl,0;
        }
    }
    for(int i=1;i<=n;i++){
        if(!mark[i]){
            //求环
            vector<int>temp;
            int x=i;
            while(!mark[x]){
                mark[x]=1;
                x=p[x];
                temp.push_back(x);
            }
            //找重量最大的最为传递员
            int ma=0;
            for(int j=0;j<temp.size();j++){
                if(a[temp[j]]>a[temp[ma]]){
                    ma=j;
                }
            }
            //走一圈,和每个人交换
            for(int j=temp[ma];p[j]!=temp[ma];j=p[j]){
                ans.push_back({temp[ma],p[j]});
            }
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans){
        cout<<i.first<<' '<<i.second<<endl;
    }
    return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int search(int& idx, map<int, int>& mp) {
    if (mp[idx] != idx) return mp[idx] = search(mp[idx], mp);
    else return idx;
}
void unite(int& id1, int& id2, map<int, int>& mp) {
    int l = search(id1, mp);
    int r = search(id2, mp);
    if (l < r) mp[r] = mp[l];
    else mp[l] = mp[r];
}

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

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

  map<int, int> mp;
  rep(i, n) mp[a[i]] = a[i];

  int ans {};
  rep(i, n/2) {
    if (search(a[i], mp) != search(a[n-i-1], mp)) {
        unite(a[i], a[n-i-1], mp);
        ++ans;
    }
  }

  cout << ans << '\n';
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const int maxn = 5005;
ll sum[maxn];
ll a[maxn];
char s[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s", s + 1);
	sum[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		if (s[i] == 'A')
			a[i] = 1;
		else if (s[i] == 'T')
			a[i] = -1;
		else if (s[i] == 'C')
			a[i] = 5000;
		else if (s[i] == 'G')
            a[i] = -5000;
	}
	for(int i = 1; i <= n; i++){
        sum[i] = sum[i - 1] + a[i];
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		for (int j = i + 2; j <= n; j += 2){
			if (sum[j] == sum[i]){
				ans++;
			}
		}
	}
	printf("%lld\n", ans);
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;

const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1;
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

bool check(map<char,int> mp) {
  if (mp['A'] == mp['T'] and mp['G'] == mp['C']) return true;
  return false;
}

void solve(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    map<char,int> mp;
    for (int j = i; j < s.size(); ++j) {
      mp[s[j]]++;
      if (check(mp)) ans++;
    }
  }
  cout << ans << "\n";
}

signed main(){
  fast;
  int test = 1;
  int i=1;
  while(test--){
    solve();
  }
}


#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)

int main(void){
    int i, j;
    int h, w, k, hp, wp;
    char c, dir[5003][5003] = {};

    cin >> h >> w >> k;
    rep0(i, h){
        rep0(j, w){
            dir[i][j] = '.';
        }
    }
    rep0(i, k){
        cin >> hp >> wp >> c;
        dir[hp - 1][wp - 1] = c;
    }

    ll dp[5003][5003] = {};
    int sc, twth;
    twth = 332748118 * 2 % mod2;    // 2/3
    dp[0][0] = 1;
    rep0(i, h){
        rep0(j, w){
            if (i > 0){
                c = dir[i - 1][j];
                if (c == 'R'){
                    sc = 0;
                }else if (c == '.'){
                    sc = twth;
                }else{
                    sc = 1;
                }
                dp[i][j] = (dp[i][j] + dp[i - 1][j] * sc % mod2) % mod2;
            }
            if (j > 0){
                c = dir[i][j - 1];
                if (c == 'D'){
                    sc = 0;
                }else if (c == '.'){
                    sc = twth;
                }else{
                    sc = 1;
                }
                dp[i][j] = (dp[i][j] + dp[i][j - 1] * sc % mod2) % mod2;
            }
        }
    }

    ll wr;
    wr = 1;
    rep0(i, h * w - k){
        wr = wr * 3 % mod2;
    }
    cout << dp[h - 1][w - 1] * wr % mod2 << endl;

    return (0);
}

#include <bits/stdc++.h>

const long long SZ = 1e5 + 7;
const long long inf = 1e18;
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
long long opnmbr = 1;

#define ll                  long long
#define ld                  long double

#define pb                  push_back
#define mp                  make_pair
#define eb                  emplace_back

#define pll                 pair<ll, ll>
#define vi                  vector<ll>
#define vs                  vector<string>
#define vpl                 vector<pll>
#define qi                  queue<ll>
#define si                  set<ll>
#define mi                  map<ll, ll>
#define umi                 unordered_map<ll, ll>

#define fi                  first
#define se                  second

#define sz(x)               (ll)x.size()

#define all(c)              (c).begin(), (c).end()
#define allr(c)             (c).rbegin(), (c).rend()

#define Max(a,b)            ((a > b) ? a : b)
#define Min(a,b)            ((a < b) ? a : b)

#define ci(X)               ll X; cin>>X
#define cii(X, Y)           ll X, Y; cin>>X>>Y
#define ciii(X, Y, Z)       ll X, Y, Z; cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z)   ll W, X, Y, Z; cin>>W>>X>>Y>>Z

#define dbg(x)              cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y)           cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z)         cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w)       cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<" "<<#w<<"="<<(w)<<endl;

#define ons()               cout<<"Case #"<<opnmbr++<<": ";
#define krosuru             ll ___T; cin>>___T; while (___T-- > 0)
#define yehbhitheekhai      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define inf                 1e18
#define Endl                endl

#define forn(i, n)          for(ll i = 0; i < (n); i++)
#define fore(i, n)          for(ll i = 1; i <= (n); i++)
#define forl(i, l, r)       for(ll i = l; i < (r); i++)
#define forr(i, l, r)       for(ll i = l; i >= (r); i--)

#define ms0(X)              memset((X), 0, sizeof((X)))
#define ms1(X, V)           memset((X), -1, sizeof((X)))
#define flv(X, V)           fill(all((X)), V)

using namespace std;

ll powermod(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1) ans = (ans * a) % MOD;
        b = b / 2;
        a = (a * a) % MOD;
    }
    return ans;
}

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

ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}

void krdiyasuru()
{
    string s;
    cin >> s;
    ll n = sz(s);
    string ans = "";
    deque<char> str;
    ll f = 1;
    forn(i, n)
    {
        if(s[i] == 'R')
        {
            f ^= 1;
        }
        else
        {
            if(f == 1)
            {
                str.pb(s[i]);
            }
            else
            {
                str.push_front(s[i]);
            }
        }
    }
    for(auto x: str)
    {
        ans += x;
    }
    if(f == 0)
    {
        reverse(all(ans));
    }
    string a;
    for(auto& c : ans)
    {
        if(sz(a) && a.back() == c)
        {
            a.pop_back();
        }
        else
        {
            a.pb(c);
        }
    }
    cout<<a<<endl;
    return;
}

int main()
{
    yehbhitheekhai;
    //    solve();
    //    krosuru
    {
        krdiyasuru();
    }
}


/*
           _                   _         _       __  __  _____
     /\   | |            /\   | |       | |     |  \/  |/ ____|
    /  \  | |__   ___   /  \  | |__   __| | ___ | \  / | |
   / /\ \ | '_ \ / _ \ / /\ \ | '_ \ / _` |/ _ \| |\/| | |
  / ____ \| |_) | (_) / ____ \| |_) | (_| | (_) | |  | | |____
 /_/    \_\_.__/ \___/_/    \_\_.__/ \__,_|\___/|_|  |_|\_____|

*/

#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld eps = 1e-9;
const int mod = 1e9 + 7;
const int oo = 1e9 + 7;
const ll lloo = 1e18 + 7;
const int N = 1e6 + 7;

void solve();

int main()
{
	// freopen("in","r",stdin);
	// freopen("out","w",stdout);
	int t = 1;
	// scanf("%d",&t);
	while (t--) solve();
	return 0;
}

char buff[N];
int nxt[N],bef[N];
void solve()
{
	scanf("%s",buff);
	string str = buff;
	int n = (int)str.size();
	deque<char> q;
	bool rev = 0;
	for(int i = 0 ; i < n ; i++)
	{
		if (str[i] == 'R') rev = !rev;
		else
		{
			if (rev) q.push_front(str[i]);
			else q.push_back(str[i]);
		}
	}

	str = "";
	for(auto x:q) str+=x;
	if (rev) reverse(all(str));

	n = (int)str.size();
	for(int i = 0 ; i < n ; i++) {nxt[i] = i+1;bef[i+1] = i;}
	nxt[n+1] = 0;
	bef[0] = n+1;
	//cout << str << endl;
	while(1)
	{
		int tmp = nxt[n+1];
		bool ok = 0;
		while (nxt[tmp] != n)
		{
			if (str[tmp] == str[nxt[tmp]])
			{
				nxt[bef[tmp]] = nxt[nxt[tmp]];
				bef[nxt[nxt[tmp]]] = bef[tmp];
				if (bef[tmp] != n+1) tmp = bef[tmp];
				else if (nxt[nxt[tmp]] != n) tmp = nxt[nxt[tmp]];
				else {ok = 0;break;}
				ok = 1;
			}
			else tmp = nxt[tmp];
		}
		if (!ok) break;
	}
	string ans = "";
	int tmp = nxt[n+1];
	while(tmp != n) {ans += str[tmp];tmp = nxt[tmp];}
	printf("%s\n",ans.c_str());
}

#include <bits/stdc++.h>
#include <chrono>
#include <ctime>
using namespace std;
using chrono::steady_clock;
using chrono::milliseconds;

#define sp " "
#define INF 1e18
#define INT_INF 1e9
typedef long long ll;
typedef pair<int,int> P;

chrono::steady_clock::time_point now_t;
chrono::steady_clock::time_point start_t;

random_device x;
mt19937 mt(x());

struct coord { int x; int y; };

const int N = 50;
vector<vector<int>> t(50,vector<int>(50));
vector<vector<int>> p(50,vector<int>(50));
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
char direct[] = {'D','R','U','L'};

struct state {
    //状態を管理
    int l;
    vector<coord> route;
    vector<char> direct;//D,R,U,L
    vector<int> score;
    vector<int> reach;//0 false 1 true
};

int get_rnd(int mod){
    return mt()%mod;
}

bool TIME_CHECK( int Limit ){
    now_t = steady_clock::now();
    if(chrono::duration_cast<milliseconds>(now_t-start_t) < milliseconds(Limit))return true;
    return false;
}

void enter(state &S){
    //入力
    int sx,sy;
  	cin >> sx >> sy;
  	coord s = {sx,sy};
  	S.route.push_back(s);
    for(int i = 0;i < 2500;i++)S.reach.push_back(0);
  	for(int i = 0;i < 50;i++){
        for(int j = 0;j < 50;j++){
            cin >> t[i][j];
        }
    }
    for(int i = 0;i < 50;i++){
        for(int j = 0;j < 50;j++){
            cin >> p[i][j];
        }
    }
    S.reach[t[S.route[0].x][S.route[0].y]] = 1;
  	S.score.push_back(p[S.route[0].x][S.route[0].y]);
    S.l = 1;
    return;
}

void output(state S){
    //出力
    int l = S.l;
    for(int i = 0;i < l-1;++i){
        //cout << i << sp << S.route[i+1].x-S.route[0].x << sp << S.route[i+1].y-S.route[0].y << endl;
        // if(S.route[i+1].x - S.route[i].x == 1)cout << "D";
        // if(S.route[i+1].x - S.route[i].x == -1)cout << "U";
        // if(S.route[i+1].y - S.route[i].y == 1)cout << "R";
        // if(S.route[i+1].y - S.route[i].y == -1)cout << "L";
        // //cout << endl;
        cout << S.direct[i];
    }
}

void dfs(state &S){
    state best_s = S;
    stack<state> st;
    st.push(S);
    while(!st.empty() && st.size() < 1000 && TIME_CHECK(1800)){
      state s = st.top();
      st.pop();
      int cx,cy,l;
      l = s.l;
      cx = s.route[l-1].x;
      cy = s.route[l-1].y;
      for(int i = 0;i < 4;i++){
        state T = s;
        if(cx+dx[i] < 0 || cx+dx[i] >= 50 || cy+dy[i] < 0 || cy+dy[i] >= 50)continue;
        else if(T.reach[t[cx+dx[i]][cy+dy[i]]] == 0){
          coord c = {cx+dx[i],cy+dy[i]};
          T.route.push_back(c);
          T.score.push_back(T.score[l-1] + p[c.x][c.y]);
          if(T.score[l] > best_s.score[best_s.l-1])best_s = T;
          if(st.size() > 50){
            if(T.score[l] < best_s.score[min(l,best_s.l - 1)]*9/10)continue;
          }
          T.reach[t[c.x][c.y]] = 1;
          T.direct.push_back(direct[i]);
          T.l += 1;
          st.push(T);
        }
      }
    }
    S = best_s;
}

//void mountain( state &S){
    //山登り
    // int l = S.l;
    // int n = get_rnd(l);
//}

// void AS ( state &S){
//     //焼きなまし
// }

/*
近傍の取り方でスコア悪化の確立が高すぎるもの、
変化がおおきすぎるものを選ぶとスコア改善しないので、
適切な近傍の取り方を考える
思いつかないなら山登りでよい
極力連続でなだらかな関数にする
近傍の取り方は2種類用意したほうがいい（できれば）
焼きなましの温度は対数的に減らす->確率は線形になる
線形的に減らす->確率は指数的になる

rand()は遅いので使わない
*/
int main(){
    start_t = steady_clock::now();
    state S;
    enter(S);
    // while(true){
    //     int res = greed(S);
    //     if(res == 0)continue;
    //     else break;
    // }
    dfs(S);
    output(S);
}


#include <bits/stdc++.h>

#define ll long long
using namespace std;
#define MOD 1000000007

ll powmod(ll a, ll p) {
    //cout<<a<<" "<<p<<endl;
    if(p==0) return 1;
    if(p%2) return (powmod(a,p-1)*a)%MOD;
    ll z = powmod(a,p/2);
    return (z*z)%MOD;
}
ll inv(ll a) {
    return powmod(a%MOD,MOD-2);
}

void solve()
{
    int N, M;
    cin>>N>>M;
    vector<int> A(N);
    for(auto &a: A) cin>>a;
    ll s = 0;
    for(auto &a: A) s+=a;

    if(s>M) {
        cout<<0<<endl;
        return;
    }

    ll n = M-s;
    ll k = s+N+1;
    ll ans = 1;
    for(int i=1; i<k; ++i) {
        ans = (ans*(n+i))%MOD;
        ans = (ans*inv(i))%MOD;
    }
    cout<<ans<<endl;

}

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

	return 0;
}

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

ll N, X;
vector<ll> A(60, 0);
const ll M = 100000;
ll memo[60][M] = {};

ll cnt(ll index, ll zan) {
  if (zan < M && memo[index][zan] > 0) return memo[index][zan];
  if (index == 0) return 1;
  if (zan == 0) return 1;
  ll temp = zan / A[index];
  ll zan1 = zan - A[index] * temp;
  ll zan2 = abs(zan - A[index] * (temp + 1));

  ll ans;
  if (temp == 0 && index != N - 1) ans = cnt(index - 1, zan1);
  else if (zan1 == 0) ans = cnt(index - 1, zan2);
  else if (zan2 == 0) ans = cnt(index - 1, zan1);
  else ans = cnt(index - 1, zan1) + cnt(index - 1, zan2);
  if (zan < M) memo[index][zan] = ans;
  return ans;
}

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

  cin >> N;
  cin >> X;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = cnt(N - 1, X);
  cout << ans << '\n';
  return 0;
}