#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 300005
#define MOD 998244353
#define SMOD 998244353
#define ROOT 512
#define GMAX 20
#define INF 2000000000000000
#define EPS 0.000000001
#define NIL 0
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int prime[MAX+1];
void sieve()
{
    int i,j;
    for(i=2; i*i<=MAX; i++)
    {
        if(prime[i]) continue;
        for(j=i; j*i<=MAX; j++)
        {
            if(prime[i*j]==0) prime[i*j]=i;
        }
    }
}
long long int fact[MAX+1],fact_inv[MAX+1];
long long int gcd(long long int a,long long int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
long long int egcd(long long int a, long long int b, long long int & x, long long int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    long long int x1, y1;
    long long int d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
long long int ModuloInverse(long long int a,long long int n)
{
    long long int x,y;
    x=gcd(a,n);
    a=a/x;
    n=n/x;
    long long int res = egcd(a,n,x,y);
    x=(x%n+n)%n;
    return x;
}
void precal()
{
    int i;
    fact[0]=fact_inv[0]=1;
    for(i=1;i<=MAX;i++)
    {
        fact[i]=(fact[i-1]*i)%MOD;

    }
    i=MAX;
    fact_inv[i]=ModuloInverse(fact[i],MOD);
    for(i=MAX-1;i>0;i--)
    {
        fact_inv[i]=(fact_inv[i+1]*(i+1))%MOD;
    }
}
long long int C(int n,int r)
{
    long long int res=fact[n];
    res=(res*fact_inv[n-r])%MOD;
    res=(res*fact_inv[r])%MOD;
    return res;
}
int main()
{
    sieve();
    precal();
    int n,m,i;
    scanf("%d %d",&n,&m);
    long long ans=0;
    for(i=1;i<=m;i++)
    {
        int curr=i;
        int j;
        long long tot=1;
        while(curr>1)
        {
            int d=curr;
            if(prime[curr]) d=prime[curr];
            int cnt=0;
            while(curr%d==0)
            {
                curr=curr/d;
                cnt++;
            }
            tot=(tot*C(n-1+cnt,cnt))%MOD;
        }
        ans=(ans+tot)%MOD;
    }
    printf("%lld",ans);
    return 0;
}

//#include <atcoder/maxflow.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <bitset>

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

typedef long long ll;

//using namespace __gnu_pbds;
//using namespace atcoder;
using namespace std;

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

template<class T>
T fastpower(T x, ll pw, T id = 1) {
    T w = x, res = id;
    while (pw>0) {
        if (pw&1) {
            res = (res * w) % modd;
        }
        pw >>= 1;
        w = (w * w) % modd;
    }
    return res;
}

class Factorial {
    public:
      vector<ll> bin;

      Factorial(int n) : bin(n+1, 0) {
          bin[0] = 1;
          forr(i,1,n) {
              bin[i] = i*bin[i-1]; bin[i] = bin[i] % modd;
          }
      }

      ll val(int i) {  return bin[i];  }
};

class BinomialWithFactorial {  // inverse_fact forming is very slow; perhaps thorw out and comupte inverse_fact on the fly
    public:
      Factorial fact;
      vector<ll> inverse_fact;

      BinomialWithFactorial(int n) : fact(n) {
          FillInverse();
      }

      BinomialWithFactorial(Factorial& f) : fact(f) {
          FillInverse();
      }

      void FillInverse() {
          forr(i,0,fact.bin.size()) {
              inverse_fact.push_back(fastpower<ll>(fact.val(i), modd-2));
          }
      }

      ll val(int i, int j) {
          if ((j<0) || (j>i)) { return 0; }
          ll temp = (fact.val(i) * inverse_fact[j]) % modd;
          return (temp * inverse_fact[i-j]) % modd;
      }
};

BinomialWithFactorial bin(400005);

class Eratostenes {
    public:
      int N;
      vector<int> lp, pr;  // lp[i] = smallest prime that divides i; pr -- array of primes

    Eratostenes(int n) : N(n), lp(n+1, 0) {
      for (int i=2; i<=N; ++i) {
         if (lp[i] == 0) {
         lp[i] = i;
         pr.push_back (i);
      }
      for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
        lp[i * pr[j]] = pr[j];
      }
    }
};

Eratostenes erat(200006);

int main(int argc, char *argv[])   {

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

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

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(m);

        ll ans = 0;
        forr(i,1,m) {
            map<int,int> decomp;
            int j = i;
            while (j>1) {
                ++decomp[erat.lp[j]];
                j /= erat.lp[j];
            }
            ll val = 1;
            for(auto x : decomp) {
                val *= bin.val(n+x.second-1, x.second);
                val %= modd;
            }
            ans += val;
        }
        cout << ans%modd << endl;

    }

    return 0;
}


#include <iostream>
using namespace std;
double a,d=1.0;
int b, c;
int main() {
	cin>>b>>c;
	a= c;
	a/=b;
	a= a*100;
	a=100-a;
	cout<<a;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using pii = pair<int, int>;
using ld = double;

#define X first
#define Y second

#define FWRITE

namespace io
{

#ifndef FWRITE
#include <unistd.h>
#endif
	const int BUFSIZE = 1 << 20;

	int isize, osize;
	char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10];
	char* is, * it, * os = obuf, * ot = obuf + BUFSIZE;

	char getchar()
	{
		if (is == it)
		{
			is = ibuf;
#ifdef FWRITE
			it = ibuf + fread(ibuf, 1, BUFSIZE, stdin);
#else
			it = ibuf + read(STDIN_FILENO, ibuf, BUFSIZE);
#endif
			if (is == it) return EOF;
		}
		return *is++;
	}

	char getalpha()
	{
		char c = getchar();
		while (!isalpha(c)) c = getchar();
		return c;
	}

	void putchar(char c)
	{
		*os++ = c;
		if (os == ot)
		{
#ifdef FWRITE
			fwrite(obuf, 1, BUFSIZE, stdout);
#else
			write(STDOUT_FILENO, obuf, BUFSIZE);
#endif
			os = obuf;
		}
	}

	int inp() {
		int x = 0, f = 0; char ch;
		for (ch = getchar(); !isdigit(ch); ch = getchar())
		{
			//if (ch == EOF) return -1;
			if (ch == '-') f = 1;
		}
		for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return f ? -x : x;
	}

	ll inp_ll() {
		ll x = 0; int f = 0; char ch;
		for (ch = getchar(); !isdigit(ch); ch = getchar())
			if (ch == '-') f = 1;
		for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return f ? -x : x;
	}

	template<class T>
	bool read(T& x)
	{
		x = 0;
		char ch = getchar();
		if (ch == EOF) return 0;
		for (; !isdigit(ch); )
		{
			ch = getchar();
			if (ch == EOF) return 0;
		}
		for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return 1;
	}

	template<class T>
	void write(T x)
	{
		static char s[22];
		static char* it = s + 20;
		static char* end = s + 20;

		if (x < 0)
		{
			putchar('-');
			x = -x;
		}

		do
		{
			*--it = x % 10 + '0';
			x /= 10;
		} while (x);
		/*
		if (!x)
			*-- it = '0';
		while (x)
		{
			*-- it = x%10+'0';
			x /= 10;
		}
		*/
		for (; it < end; ++it)
			putchar(*it);
	}

	template<>
	void write(const char* s)
	{
		for (; *s; ++s) putchar(*s);
	}

	template<>
	void write(char c)
	{
		putchar(c);
	}

	template<class T, class V>
	void write(T x, V y)
	{
		write(x);
		write(y);
	}

	template<class T>
	void writeln(T x)
	{
		write(x);
		putchar('\n');
	}

	struct ender
	{
		~ender()
		{
			if (os != obuf)
#ifdef FWRITE
				fwrite(obuf, 1, os - obuf, stdout);
#else
				write(STDOUT_FILENO, obuf, os - obuf);
#endif
		}
	}__ender;

}

template<class T>
void print(const T& a)
{
	for (auto x : a) printf("%d ", x); puts("");
}

int64_t power(int64_t a, int64_t b, int64_t p)
{
	if (!b) return 1;
	int64_t t = power(a, b>>1, p);
	t = t * t % p;
	if (b & 1) t = t * a % p;
	return t;
}

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

using namespace io;

template<class T>
inline void freshmin(T& a, const T& b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T& a, const T& b)
{
	if (a < b) a = b;
}

const ll B = 31;
const ll MOD = 1000000007;
const int MAXN = 100010;

void solve()
{
	int n = inp();
	int k = inp();
	int m = inp();
	int cur = 0;
	for (int i = 1; i < n; ++i)
		cur += inp();
	int ans = max(0, m * n - cur);
	if (ans <= k)
		writeln(ans);
	else
		writeln(-1);
}

int main()
{

	//for (int T = inp(); T --; )
	solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;

int t,n;

int main(){
	sf("%d%d",&t,&n);
	pf("%lld\n",((ll)n*100+t-1)/t+n-1);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
// const int MOD = 998244353;
struct mint {
	ll x;
	mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
	mint operator-() { return mint(-x); }
	mint operator+=(mint rhs) {
		x += rhs.x;
		if (x >= MOD) x -= MOD;
		return *this;
	}
	mint operator-=(mint rhs) {
		x -= rhs.x;
		if (x < 0) x += MOD;
		return *this;
	}
	mint operator*=(mint rhs) {
		x = x * rhs.x % MOD;
		return *this;
	}
	mint operator+(mint rhs) { return mint(*this) += rhs; }
	mint operator-(mint rhs) { return mint(*this) -= rhs; }
	mint operator*(mint rhs) { return mint(*this) *= rhs; }
	mint pow(ll n) {
		mint r = 1;
		for (mint t = (*this); n; t *= t, n >>= 1)
			if (n & 1) r *= t;
		return r;
	}
	mint inv() { return (*this).pow(MOD - 2); }
	mint operator/=(mint rhs) { return *this *= rhs.inv(); }
	mint operator/(mint rhs) { return mint(*this) /= rhs; }
};
ostream &operator<<(ostream &os, const mint &dt) {
	os << dt.x;
	return os;
}
int main() {
	int n, p;
	cin >> n >> p;
	mint ans = mint(p - 2).pow(n - 1) * (p - 1);
	cout << ans << endl;
	return 0;
}


/*First,solve the problem then write the code:);)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t;cin>>t;while(t--)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define fr(n) for(int i=0;i<n;i++)
#define fr1(n) for(int i=1;i<=n;i++)
#define vll vector<ll>
#define mll map<ll,ll>
#define vvll vector<vector<ll>>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vector<pair<ll,ll>>>
#define mpll map<pair<ll,ll>,ll>
#define pll pair<ll,ll>
#define sll stack<ll>
#define qll queue<ll>
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(x) x.rbegin(),x.rend()
#define mod 1000000007
#define ma 1000000000000000000
#define mi -1000000000000000000
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio
  vector<pair<ll,string>>v;
  ll n;
  cin>>n;
  string str;
  ll h;
  for(ll i=0;i<n;i++)
  {
  	cin>>str>>h;
  	v.pb(make_pair(h,str));
  }
  sort(all(v));
  cout<<v[v.size()-2].ss<<"\n";
	return 0;
}

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

#define si pair<int,string>

int n;
vector<si> v;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n;

	string a;
	int b;

	rep(x,0,n){
		cin>>a>>b;
		v.pub(si(b,a));
	}

	sort(all(v));
	reverse(all(v));

	cout<<v[1].se<<endl;
}


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

int main(){
 ll c,b,ans,ml,mr,pl,pr;
  cin>>b>>c;
  ans=c/2+(c-2)/2+1+(c-1)/2+(c-1)/2+1;
  ml=-b-(c-1)/2;
  mr=-b+(c-1)/2;
  pl=b-c/2;
  pr=b+(c-2)/2;

  if(pl<=mr) {//ダブりがある
   ans-= min(abs(mr),abs(pr))+min(abs(pl),abs(ml))+1;
  }

  cout<<ans<<endl;
}

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

#define ll long long
#define print(a)          \
    for (auto x : a)      \
        cout << x << " "; \
    cout << endl
#define print_upto(a, n)        \
    for (ll i = 1; i <= n; i++) \
        cout << a[i] << " ";    \
    cout << endl
#define take(a, n)              \
    for (ll i = 1; i <= n; i++) \
        cin >> a[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n"
#define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n"

#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(), (c).end()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define inf 1e17
// cout << fixed << setprecision(9) << ans << nl;

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;

const ll N = 200009;

void solve()
{
    ll b, c;
    cin >> b >> c;

    ll ans = 0;
    if (b < 0)
        ans++;
    b = abs(b);

    if (b == 0)
    {
        ll xr = 0;
        if (c >= 3)
        {
            xr = 1 + (c - 3) / 2;
        }

        ll xl = 0;
        if (c >= 2)
        {
            xl = 1 + (c - 2) / 2;
        }

        cout << 1 + xl + xr << nl;
        return;
    }

    if (c == 0)
    {
        cout << 1 << nl;
        return;
    }

    ll xr;
    if (c < 4)
    {
        xr = 0;
    }
    else
    {
        xr = 1 + (c - 4) / 2;
    }

    ll mxl;
    if (c < 3)
    {
        mxl = 0;
    }
    else
    {
        mxl = 1 + (c - 3) / 2;
    }

    ll xl;
    if (c < 2)
    {
        xl = 0;
    }
    else
    {
        ll limit = min(b * 2, c);
        xl = 1 + (limit - 2) / 2;
    }

    ll mxr;
    if (c < 1)
    {
        mxr = 0;
    }
    else
    {
        ll no = b;
        if (no == 0)
        {
            mxr = 0;
        }
        else
        {
            ll val = 1 + (no - 1) * 2;
            ll limit = min(val, c);
            mxr = 1 + (limit - 1) / 2;
        }
    }

    ans += 1 + xr + mxl + xl + mxr;
    cout << ans << nl;
}

int main()
{

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

    ll t = 1;
    // cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <unordered_map>
#include <unordered_set>

#define ll long long
#define mod 1000000007

using namespace std;

int main() {
    int N; ll X;
    cin >> N >> X;
    vector<int> a(N);
    ll ans=X;
    for (auto &e : a) {
        cin >> e;
    }
    // try all sizes of 1, 2, 3, ... N materials
    for (int k=1; k<=N; ++k) {
        // given two sums of size k with the same remainder (mod k)
        // we only care about the larger on since that will get to X faster
        //
        // Let dp[i][j] be the maximum sum of size i that has remainder j
        // dp[i][j] = -1 if it is impossible to have remainder j for size i
        //
        vector<vector<ll>> dp(k+1, vector<ll>(k,-1));
        dp[0][0]=0;
        for (auto e : a) {
            // look at previous elements
            for (int c=k-1; c>=0; --c) {
                // look at all possible remainders
                for (int r=0; r<k; ++r) {
                    if (dp[c][r]==-1) continue;
                    ll nxt = dp[c][r] + e;
                    dp[c+1][nxt%k] = max(dp[c+1][nxt%k], nxt);
                }
            }
        }
        if (dp[k][X%k]==-1) {
            continue;
        } else {
            ans = min(ans, (X-dp[k][X%k])/k);
        }
    }
    cout << ans << endl;
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int score(map<LL, LL> m) {
  int ret = 0;
  for (int i = 1; i <= 9; ++i) {
    ret += i * pow(10, m[i]);
  }
  return ret;
}

int main() {
  LL K; cin >> K;
  std::map<LL, LL> m, m_S, m_T;
  for (int i = 1; i <= 9; ++i) m[i] = K;
  string S, T; cin >> S >> T;

  for (char c : S) {
    int v = c - '0';
    m_S[v]++;
    m[v]--;
  }
  for (char c : T) {
    int v = c - '0';
    m_T[v]++;
    m[v]--;
  }

  long double prob = 0;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      auto m1 = m;
      m1[i]--;
      auto m2 = m1;
      m2[j]--;
      if (m1[i] < 0 || m2[j] < 0) continue;

      auto tmp_S = m_S, tmp_T = m_T;
      tmp_S[i]++; tmp_T[j]++;
      if (score(tmp_S) > score(tmp_T)) {
        long double p1 = (long double)m[i] / (9LL * K - 8LL);
        long double p2 = (long double)m1[j] / (9LL * K - 9LL);
        prob += p1 * p2;
      }
    }
  }
  printf("%.12Lf\n", prob);
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
// warning: pragmas don't work on USACO and just set to O0

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //gp_hash_table<T, U, chash>;
#include <ext/pb_ds/tree_policy.hpp>     //tree<T, U, cmp, rb_tree_tag,tree_order_statistics_node_update>;
using namespace std; using namespace __gnu_pbds;
// shorter template (CF specialization, because compile time better)

inline int RAND(int l, int r) {
    mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> unifd(l, r); return unifd(mt);
}

template <class T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long; using db = double; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>;
using vll = vector<ll>; const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};

#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define pf push_front

//#define TC
const ll INF = 1e18; const db EPS = 1e-8;
const int MOD = 1e9 + 7, // 998244353
    _ = 2e5 + 5;

void solve() {
    int n;
    cin>>n;
    vll a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    sort(all(a));
    ll ans = 1;
    for(int i=1;i<n;i++) {
        ll res = (a[i]-a[i-1]+1);
        ans *= res;
        ans%=MOD;
    }

    ans *= (a[0]+1);
    ans%=MOD;
    cout<<ans;

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    cin.tie(0)->sync_with_stdio(0); //cout << setprecision(3) << fixed << showpoint;
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
using namespace std;
const ll M = 1e9 + 7;
const ll mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
//#define double long double
ll binpow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
#define int long long
void solve(){
	int n;
	cin >> n;
	vector<int> a(n);
	re(a);
	sort(td(a));
	a.resize(distance(a.begin(), unique(td(a))));
	ll ans = a[0];
	while(true){
		bool ok = false;
		for(int i=n-1;i>=0;i--){
			if(a[i] % ans != 0){
				ans = a[i] % ans;
				ok = true;
			}
		}
		if(!ok) break;
	}
	cout << ans << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen("jump.in", "r", stdin);
	//freopen("equal.out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}


#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll mod(ll a, ll m) {
  ll r = (a % m + m) % m;
  return r;
}

ll extGcd(ll a, ll b, ll &p, ll &q) {
  if (b == 0) {
    p = 1;
    q = 0;
    return a;
  }
  ll d = extGcd(b, a % b, q, p);
  q -= a / b * p;
  return d;
}

pair<ll, ll> crt(const vector<ll> &b, const vector<ll> &m) {
  ll r = 0, M = 1;
  for (int i = 0; i < (int)b.size(); ++i) {
    ll p, q;
    ll d = extGcd(M, m[i], p, q);
    if ((b[i] - r) % d != 0) {
      return make_pair(0, -1);
    }
    ll tmp = (b[i] - r) / d * p % (m[i] / d);
    r += M * tmp;
    M *= m[i] / d;
  }
  return make_pair(mod(r, M), M);
}

int main() {
  ll T;
  scanf("%lld", &T);

  for (ll i = 0; i < T; i++) {
    ll N, S, K;
    scanf("%lld %lld %lld", &N, &S, &K);

    auto r1 = crt({0, N - S}, {K, N});
    // cout << r1.second << "k+" << r1.first << endl;  // 15k + 8

    ll ans;
    if (r1.second <= 0) {
      ans = -1;
    } else {
      ans = r1.first / K;
    }
    cout << (ans) << endl;
    // cout << ("") << endl;
  }

  //
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define ZERO {puts("0"); return 0;}
#define NO {puts("No"); return 0;}
#define ALL(obj) begin(obj), end(obj)
#define pb push_back

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

// {g,x,y}: ax+by=g
tuple<ll,ll,ll> extgcd(ll a, ll b)
{
  if (b == 0) return {a,1,0};
  ll g, x, y;
  tie(g,x,y) = extgcd(b, a%b);
  return {g, y, x-a/b*y};
}

void solve()
{
  ll n, s, k;
  cin >> n >> s >> k;
  ll g, x, y;
  tie(g,x,y) = extgcd(k,n);
  if (s%g != 0) {
    cout << -1 << endl;
    return;
  }
  n /= g;
  s /= g;
  k /= g;
  ll ans = ((x*-s)%n+n)%n;
  cout << ans << endl;
}

int main()
{
  int t; cin >> t;
  rep(i,t) solve();
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 103;

int N,M,Q;
int W[MAX_N],V[MAX_N];
int X[MAX_N];
int L[MAX_N],R[MAX_N];

void solve()
{
	vector<pair<int,int>> v;
	for(int i=1;i<=N;++i)v.emplace_back(V[i],W[i]);
	sort(v.rbegin(),v.rend());
	for(int i=0;i<Q;++i){
		const int l=L[i],r=R[i];
		multiset<int> cap;
		for(int k=1;k<l;++k)cap.insert(X[k]);
		for(int k=r+1;k<=M;++k)cap.insert(X[k]);
		ll ans = 0;
		for(auto& p : v){
			auto it = cap.lower_bound(p.second);
			if(it!=cap.end()){
				ans += p.first;
				cap.erase(it);
			}
		}
		cout<<ans<<'\n';
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> N >> M >> Q;
	for(int i=1;i<=N;++i)cin>>W[i]>>V[i];
	for(int i=1;i<=M;++i)cin>>X[i];
	for(int i=0;i<Q;++i)cin>>L[i]>>R[i];
	solve();
	return 0;
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
inline int read(){
	int x = 0, f = 1; char c = getchar();
	while(c < '0' || c > '9'){if(c == '-')f = -1; c = getchar();}
	while(c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + c - '0'; c = getchar();}
	return x * f;
}
set<int> c;
int n;
int main(){
    for(int i = 6; i <= 10000; i += 6){
    	c.insert(i);
	}
    for(int i = 10; i <= 10000; i += 10){
    	c.insert(i);
	}

    for(int i = 14; i <= 10000; i += 14){
    	c.insert(i);
	}
    n = read();
    --n;
    printf("%d ", 3 * 5 * 7);
    for(int i : c){
        printf("%d ", i);
        --n;
        if(!n){
        	break;
		}
    }
    return 0;
}


#include<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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

int main(){
    int n, m; cin >> n >> m;
    vector<ll> h(n), w(m);
    for(auto &x : h) cin >> x;
    for(auto &x : w) cin >> x;

    sort(all(h));
    int p=(n+1)/2;
    vector<ll> sl(p, 0), sr(p, 0);
    for(int i=0; i<p-1; i++){
        sl[i+1]=sl[i]+h[2*i+1]-h[2*i];
    }
    for(int i=p-1; i>=1; i--){
        sr[i-1]=sr[i]+h[2*i]-h[2*i-1];
    }

    ll ans=LINF;
    for(int i=0; i<m; i++){
        int id=lower_bound(all(h), w[i])-h.begin();
        ll sum;
        if(id%2 == 0){
            sum=sr[id/2]+h[id]-w[i]+sl[id/2];
            chmin(ans, sum);
        }
        else{
            sum=sr[(id-1)/2]+w[i]-h[id-1]+sl[(id-1)/2];
            chmin(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}

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

bool less_size(string ls, string rs) {
  return ls.size() < rs.size();
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> s(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i];
  }

  sort(s.begin(), s.end(), less_size);
  int j = 0;
  for (int i = 0; i < N; i++) {
    int count = 0;
    while (j < M && count + s[j].size() <= 20) {
      count += s[j].size();
      cout << s[j];
      j++;
    }
    for (int k = count; k < N; k++) {
      cout << ".";
    }
    cout << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
typedef long  llu;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)

using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef vector<ll>  vi;
typedef pair<ii, ll>  iii;
typedef pair<double, double>  iidb;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long INF = 1e18;
const double PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
#define fi first
#define se second

const ll tam =5010000;
const ll MOD=1e9+7;
const ll cmplog=29;
int n;
char arr[tam];
int dp2[tam],dp3[tam];
int f2(int u)
{
	if (u==0)return 1;
	if (u<=1)return 0;
	if (dp2[u]!=-1)
		return dp2[u];
	int tot=0;
	tot+=f2(u-1);
	tot+=f2(u-2);
	tot%=MOD;
	return dp2[u]=tot;
}
int f3(int u)
{
	if (u==2)return 1;
	if (u<=2)return 0;
	if (dp3[u]!=-1)
		return dp3[u];
	int tot=0;
	forr(i,0,u)
	{
		tot+=f3(u-1-i);
		tot%=MOD;
	}
	return dp3[u]=tot;
}
int main()
{
	memset(dp2,-1,sizeof dp2);
	memset(dp3,-1,sizeof dp3);
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	forr(i,0,4)
		cin>>arr[i];
	if (arr[1]=='A')
	{
		if (arr[0]=='A')
			cout<<1<<endl;
		else
		{
			if (arr[2]=='A')
				cout<<f2(n)<<endl;
			else
				cout<<f3(n)<<endl;
		}
	}
	else
	{
		if (arr[3]=='B')
			cout<<1<<endl;
		else
		{
			if (arr[2]=='B')
				cout<<f2(n);
			else
				cout<<f3(n)<<endl;
		}
	}
}

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

const int mod = 1000000007;

long long f[1010], pw[1010];

int main () {
	f[0] = 1, f[1] = 2, pw[0] = 1, pw[1] = 2;
	for (int i = 2; i <= 1005; i++) {
		f[i] = (f[i - 1] + f[i - 2]) % mod;
		pw[i] = pw[i - 1] * 2 % mod;
	}
	int n; cin >> n;
	char AA, AB, BA, BB; cin >> AA >> AB >> BA >> BB;
	if (n == 2) {
		cout << 1 << endl;
		return 0;
	}
	if (AB == 'A') {
		if (AA == 'A') {
			cout << 1 << endl;
			return 0;
		}
		if (BA == 'B') {
			cout << pw[n - 3] << endl;
			return 0;
		}
		cout << f[n - 3] << endl;
		return 0;
	}
	if (AB == 'B') {
		if (BB == 'B') {
			cout << 1 << endl;
			return 0;
		}
		if (BA == 'A') {
			cout << pw[n - 3] << endl;
			return 0;
		}
		cout << f[n - 3] << endl;
		return 0;
	}
	return 0;
}


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

const int N=100005;
int n,p;
vector<int> G[N];
int f[N],sz[N];

void dfs(int x) {
	int sum=0;
	vector<int> vec;
	int len=G[x].size();
	for(int i=0;i<len;i++) {
		int v=G[x][i];
		dfs(v);
		sz[x]+=sz[v];
		if (sz[v]%2==0) {
			if (f[v]<0) f[x]+=f[v];
			else sum+=(-f[v]);
		}
		else {
			vec.pb(-f[v]);
		}
	}
	sort(vec.begin(),vec.end(),greater<int>());
	vec.pb(sum);
	for(int i=0;i<vec.size();i++) {
		if ((i&1)==0) f[x]-=vec[i];
		else f[x]+=vec[i];
	}
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		sz[i]=1;f[i]=1;
	}
	for(int i=2;i<=n;i++) {
		cin>>p;
		G[p].pb(i);
	}
	dfs(1);
	cout<<(n+f[1])/2;
	return 0;
}

//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound

#define si(x) int(x.size())
#define sum_all(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };

ll min(ll a,ll b)
{
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b)
{
    if(a>b)return a;
    return b;
}
ll ceil1(ll a,ll b)
{
    return(a+b-1)/b;
}
void read(vector<ll> & arr)
{
  for(ll i=0;i<si(arr);i++)
    cin >> arr[i];

}

void read_graph(vector<vector<ll>>& g, ll m)
{
  while(m--)
  {
    ll x,y; cin >> x>> y ;
    x--,y--;
    g[x].pb(y);
    g[y].pb(x);
  }
}
 ll n;
vector<vector<ll>> g ;
vector<ll> sz ;

void dfs1(ll r)
{

  sz[r]=1;
 for(auto a:g[r])
 {
     dfs1(a);
     sz[r]+=sz[a];
 }
  return ;
}
pair<ll,ll>  dfs(ll r)
{

 vector<pair<ll,ll>> odd;
 vector<pair<ll,ll>> even1;
 vector<pair<ll,ll>> even2;

 ll master=1 ;
 ll follower= 0 ;
 for(auto a: g[r])
 {
   if(sz[a]%2==0)
   {
       auto temp = dfs(a);
      if(temp.ff>temp.ss)  even1.pb(temp);
      else even2.pb(temp);

   }
   else
   {
      auto temp =dfs(a);
       odd.pb(temp);

   }
 }

 if(si(odd)%2==0)
  {
     for(auto a: even1 ) master+=a.ff,follower+=a.ss;
   }
   else
   {
      for(auto a: even1 ) master+=a.ss,follower+=a.ff;
   }

   for(auto a: even2 ) master+=a.ff,follower+=a.ss;

    vector<ll> temp ;
   for(auto a: odd)
   {
     master+= a.ss;
     follower+=a.ss;
     temp.pb(a.ff-a.ss);
   }
   sort(temp.begin(),temp.end());

   for(ll i=0;i<temp.size();i++ )
     {
         if(i%2==0)
         {
           master+=temp[i];
         }
         else
         {
          follower+=temp[i];
         }
     }
  return {master,follower};

}

void solve()
{

  cin >> n;
  g=vector<vector<ll>>(n);
  sz=vector<ll>(n);
  for(ll i=1;i<n;i++)
  {
     ll x;
     cin >> x;
     x--;
     g[x].pb(i);
  }
dfs1(0);
 auto temp =dfs(0);
   cout <<temp.ff << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    //int t; cin >> t; while (t--)
    solve();

}


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

ll n;
bool ada = false;

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

int main() {
    fastio;
    cin >> n;
    for(ll i=1; i<=38; i++){
        for(ll j=1; j<=26; j++){
            if(binexp(3, i) + binexp(5, j) == n){
                cout << i << " " << j;
                ada = true;
                break;
            }
        }
    }
    if(!ada) cout << -1;
}

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007LL
#define MXN 10005
#define INF 1e9
#define EPS 1e-8
#define endl '\n'
#define lowbit(x) (x&-x)
using namespace std;

mt19937 gen(time(0));

ll n;
bool isprime[MXN];
bool v[MXN];
ll ans[MXN];
ll factor[] = {6,10,15};
vector<ll> prime;

void sieve(){
    for(ll i=2;i<=10000;i++){
        if(isprime[i])  continue;
        prime.push_back(i);
        for(ll j=i*i;j<=10000;j+=i){
            isprime[j]=1;
        }
    }
}

bool isfactor(ll x){
    for(int i=0;i<3;i++)    if(x%factor[i]==0)  return 1;
    return 0;
}

bool check(){
    ll gcd=ans[0];
    for(int i=0;i<n;i++){
        gcd=__gcd(gcd,ans[i]);
        if(ans[i]>10000)    return 0;
        if(ans[i]<=0)   return 0;
        if(v[ans[i]])   return 0;
        v[ans[i]]=1;
    }
    return gcd==1;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    sieve();
    // cout<<prime.size()<<endl;
    // for(auto i:prime)   cout<<i<<" ";
    // cout<<endl;
    cin>>n;

    ans[0] = 6;
    ans[1] = 10;
    ans[2] = 15;
    ans[3] = 12;

    for(int i=4,j=16;i<n;i++,j++){
        while(!isfactor(j)){ j++; }
        ans[i]=j;
    }

    assert(check());
    for(int i=0;i<n;i++)    cout<<ans[i]<<" ";
    cout<<endl;

    return 0;
}

/*

*/


#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define r 1000000007
#define pb push_back
#define pf push_front
#define loop(i,a,b) for (LL i = a; i < b; i++)

#define numberOfOnes(n) __builtin_popcountll(n)
#define parity(n) __builtin_parityll(n)             // = 1 when numberOfOnes(n) is odd
#define leadingZeros(n) __builtin_clzll(n)
#define trailingZeros(n) __builtin_ctzll(n)

double prod[90] = {0};

void mul(double c[], double q[]) {
	loop(i, 0, 90) {
		prod[i] = 0;
	}
	loop(i, 0, 90) {
		loop(j, 0, 90) {
			if (i + j < 90) {
				prod[i + j] += c[i] * q[j];
			}
		}
	}
}

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

	char c;

	LL o = 0, x = 0, q = 0;
	loop(i, 0, 10) {
		cin >> c;
		if (c == 'o') {
			o++;
		}
		else if (c == 'x') {
			x++;
		}
		else if (c == '?') {
			q++;
		}
	}
	// cout << o;

	double on[90] = {0};
	double qn[90] = {0};
	double sum[90] = {0};

	on[1] = 1;
	on[2] = (float)1 / 2;
	on[3] = (float)1 / 6;
	on[4] = (float)1 / 24;

	qn[0] = 1;
	qn[1] = 1;
	qn[2] = (float)1 / 2;
	qn[3] = (float)1 / 6;
	qn[4] = (float)1 / 24;

	if (o > 0) {
		loop(i, 0, 5) {
			sum[i] = on[i];
		}
		if (o > 1) {
			loop(i, 0, o - 1) {
				mul(sum, on);
				loop(j, 0, 90) {
					sum[j] = prod[j];
				}
			}
		}
		if (q > 0) {
			loop(i, 0, q) {
				mul(sum, qn);
				loop(j, 0, 90) {
					sum[j] = prod[j];
				}
			}
		}
	}
	else if (q > 0) {
		loop(i, 0, 5) {
			sum[i] = qn[i];
		}
		if (q > 1) {
			loop(i, 0, q - 1) {
				mul(sum, qn);
				loop(j, 0, 90) {
					sum[j] = prod[j];
				}
			}
		}
	}
	else {
		cout << 0;
		return 0;
	}

	cout << 24.0 * sum[4];

	return 0;
}

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

int main(){
	string s; cin>>s;
	int cnt = 0;
	for(int i = 0; i<=9999; i++){
		vector<bool>a(10);
		int pss = i;
		for(int j = 0; j<4; j++){
			a[pss%10] = 1;
			pss /= 10;
		}
		bool ok = 1;
		for(int k = 0; k<10; k++){
			if(s[k]=='o'&&!a[k])ok = 0;
			if(s[k]=='x'&&a[k])ok = 0;
		}
		if(ok)cnt++;
	}
	cout<<cnt<<endl;
}


#include <bits/extc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,a,b) for(int i=a;i<=int(b);i++)
#define ALL(x) x.begin(),x.end()
#define MOD (ll)1000000007
set<ll> ans;
vector<pair<ll, ll>> xy;

signed main() {
  ll n;
  int m;
  cin >> n >> m;
  ans.insert(n);
  xy.resize(m);
  REP(i, m){
    ll x, y;
    cin >> x >> y;
    xy[i] = make_pair(x, y);
  }
  ll xb = 0;

  sort(xy.begin(), xy.end());
  if(m > 0) {
    xb = xy[0].first;
  }
  vector<ll> dellist(0);
  vector<ll> addlist(0);
  REP(i, m){
    ll x, y;
    tie(x, y) = xy[i];
    if(xb != x){
      for(ll del: dellist){
        if(ans.find(del) != ans.end()) ans.erase(del);
      }
      for(ll add: addlist){
        if(ans.find(add) == ans.end()) ans.insert(add);
      }
      dellist.clear();
      addlist.clear();
    }
    if(ans.find(y) != ans.end()){
      dellist.push_back(y);

    }
    if(y - 1 >= 0){
      if(ans.find(y - 1) != ans.end()){
        addlist.push_back(y);
      }
    }
    if(y + 1 <= 2 * n){
      if(ans.find(y + 1) != ans.end()){
        addlist.push_back(y);
      }
    }
    xb = x;
  }
  for(ll del: dellist){
    if(ans.find(del) != ans.end()) ans.erase(del);
  }
  for(ll add: addlist){
    if(ans.find(add) == ans.end()) ans.insert(add);
  }
  cout << ans.size();
  return 0;
}

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

#define Mod(x) (x>=P)&&(x-=P)||(x<0)&&(x+=P)
#define rep(i,a,b) for(ll i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(ll i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(ll i=hd[a];i;i=nxt[i])

typedef long long ll;
void Max(ll &x,ll y){(x<y)&&(x=y);}
void Min(ll &x,ll y){(x>y)&&(x=y);}

bool vio;
char IO;
ll rd(ll res=0){
	bool f=0;
	while(IO=getchar(),IO<48||IO>57)
		f=IO=='-';
	do res=(res<<1)+(res<<3)+(IO^48);
	while(IO=getchar(),isdigit(IO));
	return f?-res:res;
}
const ll M=3e6+10,P=1e9+7;
ll fac[M],inv[M];
ll Pow(ll a,ll b){
	ll res=1;
	for(;b;b>>=1,a=a*a%P)
		if(b&1)res=res*a%P;
	return res;
}
ll C(ll n,ll m){
	if(n<m||n<0||m<0)return 0;
	return fac[n]*inv[m]%P*inv[n-m]%P;
}
bool let;
int main(){
	cerr<<(&vio-&let)/1024.0/1024<<endl;
	ll n=rd(),m=rd(),q=rd();
	rep(i,fac[0]=1,n+m+1)fac[i]=fac[i-1]*i%P;
	inv[n+m]=Pow(fac[n+m],P-2);
	drep(i,n+m,1)inv[i-1]=inv[i]*i%P;
	if(n>m+q)return puts("0"),0;
	printf("%lld",(C(n+m,n)-C(n+m,m+q+1)+P)%P);
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;

int in(){///値を丸める
  double x;
  cin >> x;
  x *= 10000;
  return round(x);
}

bool ok(ll dx,ll dy,ll z){//円のうちなら1
  return dx*dx + dy*dy <= z*z;
}

ll f(ll x,ll y,ll z,ll lim){
  int l=0,r=1;
  ll res = 0;
  for(int i=int(1000000000);i>=lim;i-=10000){
    while(ok(l*10000+x,i-y,z))++l;
    while(ok(r*10000-x,i-y,z))++r;
    res += r+l-1;
  }
  return res;
}

int main(){
  ll x=in();
  ll y=in();
  ll z=in();
  x%=10000;
  y%=10000;
  ll ans =f(x,y,z,10000);
  ans += f(x,-y,z,0);
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, begin, end) for (i=begin;i<end;i++)
#define printint(i0, i1) printf("%d %d\n", i0, i1)
#define MAX_N 1000

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
ll i, j, n, m, k, ans;
ll c[500][500];
ll a[500], b[500];

int main() {
    scanf(" %lld", &n);
    rep(i,0,n) rep(j,0,n) {
        scanf(" %lld", &c[i][j]);
    }
    bool exists = true;
    ll mincol = 0;
    rep(i,0,n) if (c[i][0] < c[mincol][0]) mincol = i;
    rep(i,0,n-1) {
        ll law = c[i+1][0] - c[i][0];
        rep(j,1,n) {
            if (c[i+1][j] - c[i][j] != law) {
                exists = false;
            }
        }
    }
    rep(j,0,n-1) {
        ll law = c[0][j+1] - c[0][j];
        rep(i,1,n) {
            if (c[i][j+1] - c[i][j] != law) {
                exists = false;
            }
        }
    }
    rep(j,0,n) b[j] = c[mincol][j];
    rep(i,0,n) a[i] = c[i][0] - c[mincol][0];

    if (exists) {
        printf("Yes\n");
        rep(i,0,n) printf("%lld ", a[i]);
        printf("\n");
        rep(i,0,n) printf("%lld ", b[i]);
        printf("\n");
    } else {
        printf("No\n");
    }
}


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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e18;
int inf = 1e9;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll x, y; cin >> x >> y;

    if (x >= y) {
        print(x - y);
        return 0;
    }

    unordered_map<ll, ll> m;

    ll ans = INF;

    auto dfs = [&] (auto && f, ll y_cur, int cnt) {
        if (ans <= cnt) return;

        auto it = m.find(y_cur);
        if (it != m.end()) {
            if (it->second <= cnt) return;
        }

        m[y_cur] = cnt;

        ans = min(ans, cnt + abs(x - y_cur));

        if (y_cur <= x) return;

        if (y_cur & 1) {
            f(f, (y_cur + 1), cnt + 1);
            f(f, (y_cur - 1), cnt + 1);
        } else {
            f(f, y_cur / 2, cnt + 1);
        }
    };

    dfs(dfs, y, 0);

    print(ans);
}

/*
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
*/
#include<bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define ll long long
#define db double
#define ull unsigned long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int a[maxn],p[maxn],x[maxn];

int main()
{
    fastio();
    int n; cin >> n;
    rep(i,1,n) cin >> a[i] >> p[i] >> x[i];
    int ans = inf;
    rep(i,1,n){
        if(a[i] <= (x[i]-1) ) ans = min(ans,p[i]);
    }
    if(ans==inf) cout << -1 << endl;
    else cout <<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    ll ans = 0;
    while(a < (x + b) / x && x * a < y){
        x = x * a;
        ans++;
    }
    ans += (y - 1 - x) / b;
    cout << ans;
}

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

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

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

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a % m + m) % m;}

ll extgcd(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }

    ll d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

pll ChineseRem(const vector<ll> &b, const vector<ll> &m) {
    ll r = 0, M = 1;
    rep(i, (int)b.size()) {
        ll p, q;
        ll d = extgcd(M, m[i], p, q); // p is inv of M/d (mod. m[i]/d)
        if ((b[i] - r) % d != 0) return make_pair(0, -1);

        ll tmp = (b[i] - r) / d * p % (m[i]/d);
        r += M * tmp;
        M *= m[i]/d;
    }

    return make_pair(mod(r, M), M);
}

void solve(){
    ll x, y, p, q;
    cin >> x >> y >> p >> q;

    ll ans = LINF;

    for(ll t1 = x; t1 < x + y; ++t1){
        for(ll t2 = p; t2 < p + q; ++t2){
            pll res = ChineseRem({t1, t2}, {(x + y) * 2, p + q});

            if(res.second < 0)continue;
            chmin(ans, res.first);
        }
    }

    if(ans >= LINF)cout << "infinity\n";
    else cout << ans << endl;
}

int main(){
    ll t;
    cin >> t;
    rep(i, t)solve();
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

vector<int> BFS(vector<vector<int>> &Graph,int iv,int n){
  vector<int> dist(n,-1);
  queue<int> q;

  dist[iv]=0;
  q.push(iv);
  while(!q.empty()){
    int v = q.front();q.pop();
    //if(dist[v]!=-1) continue;

    for(auto nv : Graph[v]){
      if(dist[nv]!=-1) continue;

      dist[nv]=dist[v]+1;
      q.push(nv);
    }
  }
  return dist;
}

int main(void){
  int n,m; cin >> n >> m;
  vector<vector<int>> g(n);
  rep(i,m){
    int a,b; cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
  }

  vector<int> d;

  ll ans = 0;
  rep(i,n){
    d = BFS(g,i,n);
    rep(j,n){
      if(d[j] != -1) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int N, M;
map<int, vector<int>> G;

void get_input();
void solve();

void dfs(vector<bool> &seen, int v);

/**
 * @brief メイン処理.
 *
 * @return int 0
 */
int main() {
    // 標準入力を取得
    get_input();

    // 求解処理
    solve();

    return 0;
}

/**
 * @brief Get the input object
 *
 */
void get_input() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
}

/**
 * @brief 求解処理.
 *
 */
void solve() {
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        vector<bool> seen(N);
        dfs(seen, i);
        ans += accumulate(seen.begin(), seen.end(), 0);
    }

    // 結果出力
    cout << ans << endl;
}

/**
 * @brief 深さ優先探索.
 *
 * @param seen 探索済みリスト
 * @param v ノード
 */
void dfs(vector<bool> &seen, int v) {
    if (seen[v - 1]) return;

    seen[v - 1] = true;
    for (int w : G[v]) {
        dfs(seen, w);
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ULL;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
void read(vector<int> &a, int n) {for (int i = 0; i < n; i++)cin >> a[i];}
void read(vector<ll> &a, int n) {for (int i = 0; i < n; i++)cin >> a[i];}
const int MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const ll LINF = (ll)1e18;
const ld PI = 3.1415926535897932384626433832795;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int calc(string s1, string s2) {
    string s3 = s1;
    vector<int> z;
    int n = s1.size();
    for (int i = 0; i < n; i++) {
        if (s1[i] == '0') {
            z.pb(i);
        }
    }
    reverse(all(z));
    int ans = INF, cnt = 0;
    for (int i = 0; i < n; i++) {
        if (s1[i] == '0') {
            z.pop_back();
        }
        if (s1[i] == s2[i]) {
            continue;
        }
        if (s1[i] == '1' && s2[i] == '0') {
            if (i == n - 1 || z.size() == 0) {
                continue;
            }
            swap(s1[i], s1[z.back()]);
            z.pop_back();
            cnt++;
        }
    }
    bool ok = 1;
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i]) {
            ok = 0;
        }
    }
    if (ok) {
        ans = cnt;
    }
    z.clear();
    for (int i = 0; i < n; i++) {
        if (s3[i] == '0') {
            z.pb(i);
        }
    }
    cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (s3[i] == '0') {
            z.pop_back();
        }
        if (s3[i] == s2[i]) {
            continue;
        }
        if (s3[i] == '1' && s2[i] == '0') {
            cnt++;
            if (i == 0 || z.size() == 0) {
                continue;
            }
            swap(s3[i], s3[z.back()]);
            z.pop_back();
        }
    }
    ok = 1;
    for (int i = 0; i < n; i++) {
        if (s3[i] != s2[i]) {
            ok = 0;
        }
    }
    if (ok) {
        ans = min(ans, cnt);
    }
    return ans;
}

void solve() {
    int n;
    cin >> n;
    string s, T;
    cin >> s >> T;
    int n1 = 0, n2 = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            n1++;
        }
        if (T[i] == '0') {
            n2++;
        }
    }
    if (n1 != n2) {
        cout << -1 << endl;
        return;
    }
    int z = 0, o = 0, ans = 0;
    string s1 = "", s2 = "";
    for (int i = 0; i < n; i++) {
        s1 += s[i], s2 += T[i];
        if (s[i] == T[i]) {
            continue;
        }
        if (s[i] == '0') {
            z++;
        }
        else {
            o++;
        }
        if (z == o) {
            ans += calc(s1, s2);
            z = 0, o = 0;
            s1 = "", s2 = "";
        }
    }
    cout << ans << endl;
}

int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int tt = 1; tt <= t; tt++)
    {
        //cout << "Case #" << tt << ": ";
        solve();
    }
}


#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

	string s;
	cin >> s;

	int n = s.size();
	int cnt[26];
	memset(cnt, 0, sizeof cnt);

    LL res = 0;

	for (int i = n - 1; i > 0; i--) {
		if (s[i] == s[i - 1]) {
			res += n - i - 1 - cnt[s[i] - 'a'];
			memset(cnt, 0, sizeof cnt);
			cnt[s[i] - 'a'] = n - i - 1;
		}
		cnt[s[i] - 'a']++;
	}

	cout << res << endl;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define pb          push_back
#define all(v)      v.begin(),v.end()
#define ya          cout<<"Yes"<<endl;
#define no          cout<<"No"<<endl;
#define ff          first
#define sc          second
#define inf         999999999
#define pi          3.14159265359
#define printv(v)   for(auto x:v)cout<<x<<' ';cout<<endl;
#define takev(v)    for(auto &x:v)cin>>x;
inline  int         random(int a=1,int b=10)
{
    return a+rand()%(b-a+1);
}
typedef long long ll;
inline ll           lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
//#define see(x)  cout<<endl<<#x<<" : "<<(x)<<endl;
#define see(args...) \
{ \
    string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);\
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr<< *it << " = " << a <<",\n"[++it==istream_iterator<string>()];
    err(it, args...);
}
#define scc(n) scanf("%lld",&n);
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int N=3e6+9,mod=998244353;

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

    string s;
    cin>>s;
    ll i,a,ans=0,n=s.size(),last=1;
    map<char,int>last_seen;
    for(i=n-1;i>=0;i--)
    {
        if(i-2>=0 && s[i]!=s[i-1] && s[i-1]==s[i-2])
        {
//            see(s[i-1],last_seen[s[i-1]])
            ans += (n-i) - last_seen[s[i-1]];
            for(char j='a';j<='z';j++)last_seen[j]=0;
            last_seen[s[i-1]]=n-i;
        }
        else
        last_seen[s[i]]++;

    }
/// anerroroccucced -> 12
    cout<<ans<<endl;

    return 0;
}


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

#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;

// Euclides Estendido
ll gcd(ll A, ll B, ll &X, ll &Y) {
	if(B == 0) {
		X = 1; Y = 0;
		return A;
	}
	ll x1, y1;
	ll G = gcd(B, A % B, x1, y1);
	X = y1; Y = x1 - (A / B) * y1;
	return G;
}

// Acha a primeira vez que dois eventos ocorrem ao mesmo tempo
// Os eventos acontecem a cada:
// A * T1 + Z1 e B * T2 + Z2
ll solve(ll A, ll B, ll Z1, ll Z2) {
	if(Z2 > Z1) swap(A, B), swap(Z1, Z2);
	ll X, Y, ans = 0;
	ll G = gcd(A, B, X, Y), C = Z2-Z1;
	if(C%G) return 1LL << 62;	// impossivel
	C /= G; X *= C; Y *= C;
	// Acho o primeiro X positivo
	if(X >= 0) {
		ll K = (X * G) / B;
		ans = A * (X - K * (B / G)) + Z1;
	} else {
		ll K = (-X * G + B - 1) / B;
		ans = A * (X + K * (B / G)) + Z1;
	}
	// retorna um par na forma (A, Z)
	// A -> novo tamanho do ciclo
	// Z -> primeira vez que acontece
	// return mk(A * (B / G), ans);
	return ans;
}

// Anotação importante, Há duas formas de alterar as soluções:
// (1) -> X = X + K * (B / G) e Y = Y - K * (A / G)
// (2) -> X = X - K * (B / G) e Y = Y + K * (A / G)

int main(int argc, char** argv) {
	int T, X, Y, P, Q;
	scanf("%d", &T);
	rep(t, 0, T) {
		ll ans = (1LL <<62);
		scanf("%d%d", &X, &Y);
		scanf("%d%d", &P, &Q);
		rep(y, 0, Y) rep(q, 0, Q)
			ans = min(ans, solve(2*X+2*Y, P+Q, X + y, P + q));
		if(ans != (1LL << 62))
			printf("%lld\n", ans);
		else puts("infinity");
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;

long GCD(const long n, const long m){
    long a = abs(n), b = abs(m);
    if(a<b){
        swap(a,b);
    }
    while (b > 0) {
        long t = a / b;
        a -= t * b;
        swap(a, b);
    }
    return a;
}

long Inverse(const long n, const long nPrime){
    long a = n, b = nPrime, u = 1, v = 0;
    while (b > 0) {
        long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= nPrime;
    if (u < 0){
        u += nPrime;
    }
    return u;
}

// k≡n(mod p), k≡m(mod q)なるkを求める(p,qは互いに素,0<=k<pq)
long CRT_Prime(const long n, const long p, const long m, const long q){
    long i = (n-m) * Inverse(q, p);
    i %= p;
    i *= q;
    i += m;
    i %= (p*q);
    if(i < 0){
        i += p*q;
    }
    return i;
}

// k≡n(mod p), k≡m(mod q)なるkを求める(p,qは互いに素,0<=k<LCM(p,q))
long CRT(long n, const long p, long m, const long q){
    if(p == 0 || q == 0){
        return LONG_MAX; // 存在しないのでInfを返す
    }
    n %= p;
    m %= q;
    if(n < 0){
        n+= p;
    }
    if(m < q){
        m += q;
    }

    long iGCD = GCD(p,q);
    long iLCM = (p/iGCD) * q;
    if((n-m) % iGCD != 0){
        return LONG_MAX; // 存在しないのでInfを返す
    }

    long nRemain = n % iGCD;
    long n1 = (n-nRemain) / iGCD;
    long m1 = (m-nRemain) / iGCD;
    long p1 = p / iGCD;
    long q1 = q / iGCD;

    long nReturn = CRT_Prime(n1,p1,m1,q1) * iGCD + nRemain;
    nReturn %= iLCM;
    if(nReturn < 0){
        nReturn += iLCM;
    }
    return nReturn;

}

int main() {
    int t;
    cin >> t;
    while(t--){
        long x,y,p,q;
        cin >> x >> y >> p >> q;
        long nAns = 2e18;
        for(long i = 0; i < y; i++){
            nAns = min(nAns, CRT(x+i, 2*(x+y), p, p+q));
        }
        for(long i = 0; i < q; i++){
            nAns = min(nAns, CRT(x, 2*(x+y), p+i, p+q));
        }
        if(nAns < 2e18){
            cout << nAns << endl;
        }
        else {
           cout << "infinity" << endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define e "\n"
#define fl(x,n) for(ll i=x;i<=n;i++)
#define fl2(x,n) for(ll i=x;i>=n;i--)
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        int n,Max,Min,x;
        cin >> n;
        cin >> Max;
        fl(2,n)
        {
            cin >> x;
            if(x>Max)
                Max=x;
        }
        cin >> Min;
        fl(2,n)
        {
            cin >> x;
            if(x<Min)
            Min=x;
        }
        if(Min-Max+1<=0)
            cout << 0 << e;
        else
            cout << Min-Max+1 << e;

       return 0;
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define endl "\n"
#define    rep(X,Y)     for(X=0;X<Y;X++)
#define    rep1(X,Y)    for(X=1;X<=Y;X++)
#define    rrep(X,Y)    for(X=Y-1;X>=0;X--)
#define    rrep1(X,Y)   for(X=Y;X>=1;X--)
#define ml ll T,g; cin>>T; for(g=0;g<T;g++)
#define case "Case "<<g+1<<": "
#define sf(T) scanf("%lld",&T)
#define pf(T) printf("%lld\n",T)
#define FastRead                      \
                                    ios_base::sync_with_stdio(false); \
                                    cin.tie(0);
#define pi acos(-1)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
    FastRead
    string a;
    cin>>a;
    ll n=a.size(),i,c=0,d=0;
    rep(i,n/2)
    {
        if(a[i]!=a[n-i-1])
        {
            c=1;
            break;
        }

    }
    if(c==0)
        cout<<"Yes";

    else
    {
        rrep(i,n)
        {
            if(a[i]!='0')
            {
                d=i;
                break;
            }

        }
        c=0;
        for(i=0;i<=d;i++)
        {
            if(a[i]!=a[d-i])
            {
                c=1;
                break;
            }
        }
        if(c==0)
            cout<<"Yes";
        else
            cout<<"No";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
struct edge
{
    int v,w,k;
    edge(){}
    edge(int _v, int _w, int _k)
    {
        v = _v;
        w = _w;
        k = _k;
    }
};

const int N = 1e5 + 5;
const long long oo = 1e18;

vector <edge> adj[N];

long long dis[N];

int n,m,s,t;

bool mini(long long &a, long long b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("file.inp","r",stdin);
    cin >> n >> m >> s >> t;
    for (int i = 1; i <= m; i++)
    {
        int u,v,w,k;
        cin >> u >> v >> w >> k;
        adj[u].push_back(edge(v, w, k));
        adj[v].push_back(edge(u, w, k));
    }

    priority_queue <pair <long long, int>> heap;

    for (int i = 1; i <= n; i++)
        dis[i] = oo;

    dis[s] = 0;
    heap.push(mp(0, s));

    while (heap.size())
    {
        int u = heap.top().se;
        long long cur = -heap.top().fi;
        heap.pop();

        if (dis[u] != cur)
            continue;

        for (edge to : adj[u])
        {
            int v = to.v;
            int w = to.w;
            int k = to.k;

            long long st = cur / k * k + (cur % k > 0) * k;
            if (mini(dis[v], st + w))
                heap.push(mp(-dis[v], v));
        }
    }

    if (dis[t] == oo)
        cout << -1;
    else
        cout << dis[t];
    return 0;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 998244353 //1000000009
#define cont continue
#define PI 3.141592653589793238462643383279502
#define debug(n1) cout<<"debug... "<<n1<<"\n"
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
#define sq(a) ( (a)*(a) )
////////////////////////////////////////////////////////
ld dp[101][101][101];

ld xd( ll i , ll j , ll k )
{
    if( dp[i][j][k] > 0 )
    return dp[i][j][k];
    if( i>=100 || j>=100 || k>=100 )
    return 0.0;

    dp[i][j][k] = (ld)i/(i+j+k)*( 1 + xd(i+1,j,k ) ) + (ld)j/(i+j+k)*( 1 + xd(i,j+1,k ) ) + (ld)k/(i+j+k)*( 1 + xd(i,j,k+1 ) ) ;
    return dp[i][j][k];
}

////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc=1;
    // cin>>tc;
    while(tc--)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        memset(dp,-1,sizeof(dp));
        ld ans = xd(a,b,c);
        cout<< fixed << setprecision(12) << ans;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n);i++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
#define ALL(a)  (a).begin(),(a).end()
const int MOD = 1000000007;
const int MAX = 510000;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
ll getmaxlen(ll p){
    ll curlen = 0;
    for(ll i = 2; i * i <= p; i++){
        while(p % i == 0){
            curlen++;
            p /= i;
        }
       }
    if(p != 1){
        curlen++;

    }
    return curlen + 1;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    cout << 1;
    if(n == 1){
        cout << endl;
        return 0;
    }
    cout << " ";
    rep2(i, 2, n+1){
        cout<<  getmaxlen((ll)i) << " ";
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long;
#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) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
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; }

void Main()
{
    int n;
    cin >> n;
    set<int> is;
    // rep(i, 1, n+1) is.insert(i);
    rep(i, 1, 100) is.insert(i);
    vector<set<int>> vs(n+1, is);
    for (int i = 1; i <= n; i++)
    {
        auto x = *vs[i].begin();
        for (int j = 2; i*j <= n; j++)
        {
            vs[i*j].erase(x);
        }
    }
    rep(i, 1, n+1) cout << *vs[i].begin() << " ";
    cout << endl;

    // rep(i, 1, n+1) if(vs[i].size() == 0) cout << "zero:" << i << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // int t; cin >> t; rep(i, t)
    Main();
    return 0;
}


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

#define co(n) cout<<n<<endl;
const double eps=1e-10,pi=3.1415926535898;
const int mod=998244353,maxn=5e3+10;
int T,n,m,k,x,y;
long long dp[maxn][15],vis[maxn][15];

long long fac[maxn]={1,1},inv[maxn]={1,1},fac_inv[maxn]={1,1};

void init() {
	for (int i=2;i<maxn;++i) {
		fac[i] = i*fac[i-1]%mod;
		inv[i] = (mod-mod/i)*inv[mod%i]%mod;
		fac_inv[i] = fac_inv[i-1]*inv[i]%mod;
	}
}

long long C(int n, int m) {
	if (n < m or m < 0) return 0;
	return fac[n]*fac_inv[n-m]%mod*fac_inv[m]%mod;
}

long long dfs(int x, int y) {
	if (vis[x][y]) {
		return dp[x][y];
	}
	vis[x][y] = 1;
	if (y == 0) {
		return dp[x][y] = C(n, x);
	}
	long long cnt=0;
	int z=1<<y;
	for (int i=0;i*z<=x and i<=n;i+=2) {
		cnt += C(n, i)*dfs(x-i*z, y-1)%mod;
	}
	return dp[x][y]=cnt%mod;
}

int main(int argc, char const *argv[]) {
	init();
	scanf("%d %d", &n, &m);
	if (m&1) {
		printf("0\n");
		return 0;
	}
	dfs(m, 12);
	printf("%lld\n", dp[m][12]);
	return 0;
}

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
clock_t clk;
clk = clock();
if(clock() - clk > CLOCKS_PER_SEC * 0.9)
      T
W     L
A C M E R
  E L   E
    E
*/

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

template <typename U>
map<U, int> primeFactorization(U n) {

  map<U, int> rs;

  while (!(n & 1)) {
    n >>= 1;
    rs[2]++;
  }

  for (U i = 3; i * i <= n; /*NOP*/) {
    auto q = n / i;
    auto r = n - i * q;
    if (r == 0) {
      rs[i]++;
      n = q;
    }
    else {
      i += 2;
    }
  }

  if (n > 1) {
    rs[n]++;
  }

  return rs;
}

template<typename T>
vector<T> getCompositeNums(map<T, int> primeNums) {

  vector<T> results;

  if (primeNums.empty()) {
    return results;
  }

  // どの素数を何個ずつ掛け合わせるか
  auto cur(primeNums);
  for (auto& c : cur) {
    c.second = 0;
  }

  auto it = cur.begin();
  while (true) {
    if (++it == cur.end()) {
      u64 com = 1;
      for (auto& c : cur) {
        com *= pow<u64>(c.first, c.second);
#if 0
        cout << c.first << "," << c.second << '\n';
#endif
      }
      if (com > 1) {
        results.push_back(com);
#if 0
        cout << com << '\n';
#endif
      }

      bool end = false;
      while (true) {
        if (it == cur.begin()) {
          end = true;
          break;
        }
        it--;
        if (++(it->second) > primeNums[it->first]) {
          it->second = 0;
          continue;
        }
        break;
      }
      if (end) {
        break;
      }
    }
  }

  sort(results.begin(), results.end());
  return results;
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 N; cin >> N;
  cout << 1 << newl;
  auto cs = getCompositeNums(primeFactorization(N));
  F0R(i, cs.size()) {
    cout << cs[i] << newl;
  }
}
#endif


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <time.h>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vd vector<double>
#define vvd vector<vd>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdi pair<double, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using namespace std;
constexpr int n = 20;
int m;
vector<string> s;
vector<deque<string>> ss(n + 1);
vvi board(n, vi(n));
void tekitou_sort(){
	rep(i, n){
		int nokori = n;
		while(true){
			bool found = false;
			for(int j = nokori; j >= 0; j--) if(!ss[j].empty()){
				found = true;
				rep(k, j) board[i][n-nokori+k] = ss[j][0][k] - 'A';
				nokori -= j;
				ss[j].pop_front();
				break;
			}
			if(!found) break;
		}
	}
}
void inputs(){
	cin >> m >> m;
	s.resize(m);
	rep(i, m) cin >> s[i];
}
int main(){
	srand(time(NULL));
	inputs();
	rep(i, m) ss[s[i].size()].push_back(s[i]);

	rep(i, n) rep(j, n) board[i][j] = rand() % 8;
	tekitou_sort();

	rep(i, n){
		rep(j, s[i].size()) board[i][j] = s[i][j] - 'A';
	}
	rep(i, n){
		rep(j, n) printf("%c", board[i][j] + 'A');
		printf("\n");
	}
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T>
void read(T &x) {
	x = 0; char c = getchar(); int f = 0;
	for (; !isdigit(c); c = getchar())
		f |= c == '-';
	for (; isdigit(c); c = getchar())
		x = x * 10 + (c ^ '0');
	if (f) x = -x;
}
template <typename T>
void write(T x, char ed = '\n') {
	if (x < 0) putchar('-'), x = -x;
	static short st[30], tp;
	do st[++tp] = x % 10, x /= 10; while (x);
	while (tp) putchar(st[tp--] | '0');
	putchar(ed);
}

const int N = 1005000;
int ans, n;
char s[N];
inline int C(int n, int m) {
	if (m > n) return 0;
	if (n >= 3) return C(n / 3, m / 3) * C(n % 3, m % 3) % 3;
	if (n == 2) return 1 + (m == 1);
	return 1;
}

int main() {
	read(n), scanf ("%s", s + 1);
	for (int i = 1;i <= n; ++i) {
		int c = (s[i] > 'B') + (s[i] > 'R');
		ans += C(n - 1, i - 1) * c;
	}
	if (~n & 1) ans *= -1;
	ans = (ans % 3 + 3) % 3;
	if (ans == 0) putchar('B');
	else if (ans == 1) putchar('R');
	else putchar('W');
	return 0;
}


/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

#define double long double

using namespace std;

typedef long long ll;

const int N_MAX = 200005;

int n, m, k;

bool trap[N_MAX];

double dp[N_MAX];

double solve (double answer)
{
    dp[1] = answer;
    double sum = 0;
    for(int i = n; i >= 1; i--)
    {
        if(trap[i] == true)
            dp[i] = dp[1];
        else
            dp[i] = 1 + sum / m;
        sum += dp[i];
        if(i + m <= n)
            sum -= dp[i + m];
    }
    return dp[1];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++)
    {
        int pos;
        cin >> pos;
        pos++;
        trap[pos] = true;
    }
    cout << fixed << setprecision(15);
    if(k == 0)
    {
        cout << solve(0) << "\n";
        return 0;
    }
    int lg = 0;
    for(int i = 1; i <= n; i++)
    {
        if(trap[i] == true)
            lg++;
        else
            lg = 0;
        if(lg >= m)
        {
            cout << "-1\n";
            return 0;
        }
    }
    double l = 1, r = 10000000000000000;
    int cnt = 2250;
    while(cnt--)
    {
        double mid = (l + r) / 2;
        if(solve(mid) < mid)
            r = mid;
        else
            l = mid;
    }
    cout << l << "\n";
    return 0;
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class FSugoroku2 {
public:
    vector<int> furidashi;
    int N, M, K;

    double calc(double m) {
        vector<double> dp(N + M + 5);
        double sum = 0;
        for (int i = N - 1; i >= 0; i--) {
            if (furidashi[i] > 0) {
                dp[i] = m;
            } else {
                dp[i] = 1 + sum / M;
            }
            sum += dp[i];
            sum -= dp[i+M];
        }
        return dp[0];
    }

    void solve(std::istream& cin, std::ostream& cout) {
        cin >> N >> M >> K;
        furidashi.resize(N+1);
        bool ok = true;
        int cur = 0;
        int prev = -INF;
        REP(i, K) {
            int a;
            cin >> a;
            furidashi[a] = 1;
            if (a - prev == 1) {
                cur++;
            } else {
                cur = 1;
            }
            if (cur >= M) {
                ok = false;
            }
            prev = a;
        }
        if (!ok) {
            cout << -1 << endl;
            return;
        }
        double l = 0;
        double r = INF;
        REP(i, 300) {
            double m = (l + r) / 2;
            if (calc(m) > m) {
                l = m;
            } else {
                r = m;
            }
        }
        fcout << l << endl;
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    FSugoroku2 solver;
    solver.solve(in, out);
    return 0;
}


/**
 *    author:  avoas
 *    created: 02.03.2021 18:53:30
**/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

#define all(x) (x).begin(),(x).end()

#define int long long

constexpr double EPS = 1e-12;

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

    int n;
    cin >> n;

    set<int> s;

    for(int a = 2; a*a <= n; a++){
        int b = 2;
        while(pow(a,b) <= n){
            s.insert(pow(a,b));
            b++;
        }
    }
    int ans = n - s.size();
    cout << ans << endl;
}

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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

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

// BEGIN CUT
ll modpow(ll x, ll y, ll m) {
    ll a = 1, p = x;
    while (y > 0) {
        if (y % 2 == 0) {
            p = (p * p) % m;
            y /= 2;
        } else {
            a = (a * p) % m;
            y--;
        }
    }
    return a;
}
// END CUT

unordered_map<ll, ll> t;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));
    REP(i, N) {
        for (ll d = 1; d * d <= A[i]; d++) {
            if (A[i] % d == 0) {
                if (t.count(d) == 0) {
                    t[d] = A[i];
                } else {
                    t[d] = gcd(t[d], A[i]);
                }
                if (t.count(A[i] / d) == 0) {
                    t[A[i] / d] = A[i];
                } else {
                    t[A[i] / d] = gcd(t[A[i] / d], A[i]);
                }
            }
        }
    }
    ll ans = 0;
    for (auto p : t) {
        if (p.first <= A[0] && p.first == p.second)
            ans++;
    }
    cout << ans << endl;
}


#include <stdio.h>
#include <stdbool.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int b[n];
	for (int i = 0; i < n; i++) b[i] = ri();

	int res = 0;
	for (int i = 1; i <= 1000; i++) {
		bool ok = true;
		for (int j = 0; j < n; j++) if (i < a[j] || i > b[j]) ok = false;
		if (ok) res++;
	}

	printf("%d\n", res);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,j,n) for(int i=j;i<n;i++)
#define readvec(v,n) for(int i=0;i<n;i++){cin>>v[i];}
#define MOD 1000000007
vector<vector<ll>> dp;
ll rec(int x,int y)
{
  if(dp[x][y]!=-1)return dp[x][y];
  dp[x][y]=0;
  if(x>0)dp[x][y] += rec(x-1,y);
  if(y>0)dp[x][y] += rec(x,y-1);
  return dp[x][y];
}
int main()
{
  int a,b;ll k;cin>>a>>b>>k;
  dp = vector<vector<ll>>(a+1,vector<ll>(b+1,-1));
  dp[0][0] = 1;
  rec(a,b);
  string s(a+b,'x');
  //rep(i,0,a+1){rep(j,0,b+1)cout<<dp[i][j]<<" ";cout<<"\n";}
  int i=0;
  for(;i<s.size();i++)
  {
    if(k==1)break;
    if(dp[a-1][b]>=k){
      s[i]='a';a--;
    }
    else{
      s[i]='b';
      k-=dp[a-1][b];
      b--;
    }
  }
  while(a--){s[i]='a';i++;}
  while(b--){s[i]='b';i++;}
  cout<<s<<"\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100 + 10;
int n, k, pw[N];
char s[N];
int dp[N][N];
char tp(int x){
	if(x==0)return 'R';
	if(x==1)return 'S';
	return 'P';
}
int id(char c){
	if(c=='R')return 0;
	if(c=='S')return 1;
	return 2;
}
int win(int x,int y){
	if((x+1)%3==y)return x;
	if((y+1)%3==x)return y;
	return x;
}
int brute(int l,int r){
	if(l==r) return id(s[l]);
	int mid=(l+r)>>1;
	return win(brute(l,mid), brute(mid+1,r));
}
int solve(int suf,int k){
	if(dp[suf][k]!=-1)return dp[suf][k];
	if(k<=10 && suf>=1<<k)
		return brute(n-suf,n-suf+(1<<k)-1);
	 int l=solve(suf,k-1);
	 int pre=((pw[k-1]-suf)%n+n)%n;
	 int nexsuf=(n-pre)%n; if(nexsuf==0) nexsuf=n;
	 int r=solve(nexsuf,k-1);
	 return dp[suf][k]=win(l,r);
}
int main() {
	scanf("%d%d%s",&n,&k,s);
	pw[0]=1;
	for(int i=1;i<N;i++) pw[i]=pw[i-1]*2%n;
	memset(dp,-1,sizeof(dp));
	cout<<tp(solve(n,k))<<endl;
}

#include <bits/stdc++.h>
#define i64 long long
using namespace std;
int n,k;
string s;
char Win(char a,char b){
    if(a==b) return a;
    if(a=='R' && b=='S') return a;
    if(a=='P' && b=='R') return a;
    if(a=='S' && b=='P') return a;
    return b;
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL_DEFINE
    freopen("input.txt","r",stdin);
#endif // LOCAL_DEFINE
    cin>>n>>k;
    cin>>s;
    int shift=1;
    for(int i=0; i<k; ++i){
        string new_s="";
        for(int i=0; i<n; ++i){
            new_s+=Win(s[i],s[(i+shift)%n]);
        }
        shift*=2;
        shift%=n;
        s=new_s;
    }
    cout<<s[0]<<'\n';
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
    int ret = 1; while (b > 0) {
        if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
    } return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
typedef vector<int> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j]));
    return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
    int n = a.size(); Mat ret(n, Vec(n, 0));
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
    return ret;
}
Mat fastpow(Mat x, ll n)
{
    Mat ret(x.size(), Vec(x.size(), 0));
    rep(i, 0, x.size()) ret[i][i] = 1;
    while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
    return ret;
}
void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, M, K, A[101];
int X[10101], Y[10101];
int cnt[101];
bool E[101][101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> K;
	rep(i, 0, N) cin >> A[i];
    rep(i, 0, M) cin >> X[i] >> Y[i], X[i]--, Y[i]--;

    Mat Ma(N, Vec(N));
	rep(i, 0, M) {
        cnt[X[i]]--;
        cnt[Y[i]]--;
        E[X[i]][Y[i]] = E[Y[i]][X[i]] = true;
	}

    rep(to, 0, N) {
        int cnt = M;
        rep(from, 0, N) if (to != from) {
            if (E[to][from]) {
                Ma[to][to] = add(Ma[to][to], mul(modinv(M), modinv(2)));
                Ma[to][from] = add(Ma[to][from], mul(modinv(M), modinv(2)));
                cnt--;
            }
        }
        Ma[to][to] = add(Ma[to][to], mul(cnt, modinv(M)));
    }

    Vec v(N, 0);
    rep(i, 0, N) v[i] = A[i];

    Ma = fastpow(Ma, K);
    v = mulMatVec(Ma, v);
    rep(i, 0, N) cout << v[i] << endl;
}

#include <bits/stdc++.h>
constexpr int DEBUG = 0;
using namespace std;
using int64 = long long;

struct Edge {
  int s, t;
  Edge(int s, int t) : s(s), t(t) {}
};

vector<vector<Edge>> ReadUndirectedGraph(int n, int m, int offset) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2; cin >> v1 >> v2; v1 -= offset; v2 -= offset;
    graph[v1].push_back(Edge(v1, v2)); graph[v2].push_back(Edge(v2, v1));
  }
  return graph;
}

class FF {
 private:
  int x_;
  void Normalize() {
    if (0 <= x_ && x_ < P) { return; } x_ %= P; if (x_ < 0) { x_ += P; }
  }
 public:
  // static constexpr int P = 998244353;
  static constexpr int P = 1000000007;
  FF(int x) : x_(x) { Normalize(); }
  FF() : x_(0) {}
  int Value() const { return x_; }
  FF operator+(FF o) const { FF r(*this); r += o; return r; }
  FF operator-(FF o) const { FF r(*this); r -= o; return r; }
  FF operator* (FF o) const { FF r(*this); r *= o; return r; }
  FF operator/ (FF o) const { return (*this) * o.Power(P - 2); }
  bool operator== (FF o) const { return x_ == o.x_; }
  void operator+= (FF o) { x_ += o.x_; if (x_ >= P) x_ -= P; }
  void operator-= (FF o) { x_ -= o.x_; if (x_ < 0) x_ += P; }
  void operator*= (FF o) { x_ = (int64(x_) * o.x_) % P; }
  FF Power(int64 p) const {
    if (p < 0) { return FF(1) / Power(-p); } FF x(*this), r(1);
    while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r;
  }
};
ostream& operator<<(ostream& s, const FF& x) { s << x.Value(); return s; }

template<typename T>
vector<vector<T>> Make2D(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

vector<vector<FF>> Id(int n) {
  auto a = Make2D(n, n, FF(0));
  for (int i = 0; i < n; i++) { a[i][i] = 1; }
  return a;
}

vector<vector<FF>> Multiply(vector<vector<FF>> a, vector<vector<FF>> b) {
  int n = a.size();
  auto c = Make2D(n, n, FF(0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  return c;
}

vector<vector<FF>> Power(vector<vector<FF>> a, int p) {
  int n = a.size();
  vector<vector<FF>> r = Id(n);
  // while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r;
  while (p) {
    if (p % 2) {
      r = Multiply(r, a);
    }
    a = Multiply(a, a);
    p /= 2;
  }
  return r;
}

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

  int n, m, k; cin >> n >> m >> k;
  vector<FF> xs(n);
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    xs[i] = x;
  }
  auto graph = ReadUndirectedGraph(n, m, 1);

  auto a = Make2D(n, n, FF(0));
  for (int i = 0; i < n; i++) {
    a[i][i] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (const auto& e : graph[i]) {
      a[i][e.t] += FF(1) / FF(2 * m);
      a[i][i] -= FF(1) / FF(2 * m);
    }
  }

  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < n; j++) {
  //     cout << a[i][j] * 4 << " ";
  //   }
  //   cout << endl;
  // }

  a = Power(a, k);

  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < n; j++) {
  //     cout << a[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  for (int i = 0; i < n; i++) {
    FF e = 0;
    for (int j = 0; j < n; j++) {
      e += a[i][j] * xs[j];
    }
    cout << e << endl;
  }
}


#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;

const int N = 2e5;
int n, k, f[N];
vector<int> G[N];

int dfs(int u, int fa, int mid) {
	f[u] = 0;
	int res = 0;
	vector<int> F;
	for (const int &v : G[u]) {
		if (v == fa) {
			continue;
		}
		res += dfs(v, u, mid);
		if (f[v] == mid) {
			res += 1;
		} else {
			F.push_back(f[v] + 1);
		}
	}
	if (sz(F)) {
		sort(all(F));
		f[u] = F.back();
		rep(i, 1, sz(F)) {
			if (F[i] + F[i - 1] > mid) {
				res += sz(F) - i;
				f[u] = F[i - 1];
				break;
			}
		}
	}
	return res;
}

int check(int mid) {
	int res = dfs(0, -1, mid) + 1;
	// cout << "mid = " << mid << " res = " << res << '\n';
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	rep(i, 0, n - 1) {
		int u, v;
		cin >> u >> v, --u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int l = -1, r = n;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (check(mid) <= k) {
			r = mid;
		} else {
			l = mid;
		}
	}
	cout << (r + 1) / 2 << '\n';
	return 0;
}

/*
// My Code in Contest
#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;

const int N = 2e5 + 1;
int n, k, L;
vector<int> G[N];

int *f[N], *g[N], wf[N], wg[N];
int *mf = wf, *mg = wg, tmp[N], mx[N], my[N];
int len[N], s[N], fa[N], tp[N];

void FindSon(int u) {
	for (const int &v : G[u]) {
		if (v == fa[u]) {
			continue;
		}
		fa[v] = u, FindSon(v);
		if (s[u] == -1 or len[v] > len[u]) {
			len[u] = len[v], s[u] = v;
		}
	}
	len[u] += 1;
}

void GetF(int u) {
	if (u == tp[u]) {
		f[u] = mf, mf += len[u];
		g[u] = mg, mg += len[u];
	}
	if (s[u] != -1) {
		f[s[u]] = f[u] + 1;
		tp[s[u]] = tp[u];
		GetF(s[u]);
	}
	for (const int &v : G[u]) {
		if (v == fa[u] or v == s[u]) {
			continue;
		}
		tp[v] = v, GetF(v);
	}
}

void DP(int u) {
	if (s[u] != -1) {
		DP(s[u]);
		f[u][0] = f[u][min(len[s[u]], L + 1)] + 1;
	}
	for (const int &v : G[u]) {
		if (v == fa[u] or v == s[u]) {
			continue;
		}
		DP(v);
		int F = 0;
		rep(i, 0, min(L, len[v]) + 1) {
			f[u][i] += (F += g[u][i]), g[u][i] = 0;
			tmp[i] = min(tmp[i], f[u][i] + my[min(i, L - i)]);
			if (i) {
				tmp[i] = min(tmp[i], f[v][i - 1] + mx[min(i, L - i + 1)]);
			}
			if (i == min(L, len[v])) {
				break;
			}
			mx[i + 1] = min(f[u][i], mx[i]);
			my[i + 1] = min(f[v][i], my[i]);
		}
		if (min(L, len[v]) + 1 < min(L + 1, len[u])) {
			g[u][min(L, len[v]) + 1] += my[min(L, len[v])];
		}
		rep(i, 0, min(L, len[v]) + 1) {
			tmp[i] = min(tmp[i], f[u][i] + my[min(L, len[v])] + 1);
			f[u][i] = tmp[i], tmp[i] = mx[i] = my[i] = n;
		}
	}
	if (u == tp[u]) {
		int F = 0;
		rep(i, 0, min(len[u], L + 1)) {
			f[u][i] += (F += g[u][i]), g[u][i] = 0;
		}
	}
	cout << "u = " << u << '\n';
	rep(i, 0, min(L + 1, len[u])) {
		cout << f[u][i] << ' ';
	}
	cout << '\n';
}

int check() {
	DP(0);
	int res = n;
	rep(i, 0, min(len[0], L + 1)) {
		res = min(res, f[0][i]);
	}
	res += 1;
	cout << "L = " << L << " res = " << res << '\n';
	for (int *i = wf; i != mf; *(i++) = 0);
	for (int *i = wg; i != mg; *(i++) = 0);
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	rep(u, 0, n) {
		fa[u] = s[u] = -1;
		tmp[u] = mx[u] = my[u] = n;
	}
	rep(i, 0, n - 1) {
		int u, v;
		cin >> u >> v, --u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	FindSon(0), tp[0] = 0, GetF(0);
	cout << "here" << endl;
	int l = -1, r = n;
	while (r - l > 1) {
		L = (l + r) / 2;
		if (check() <= k) {
			r = L;
		} else {
			l = L;
		}
	}
	cout << (r + 1) / 2 << '\n';
	return 0;
}
*/

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

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

using namespace std;
typedef long long ll;

int n, k;
vector<vector<int>> g;
bool used[200000];
int a[200000], b[200000];
const int INF = 1e9;

void input(){
    cin >> n >> k;
    g.resize(n);
    for(int i = 0; i < n-1; i++){
        int u, v; cin >> u >> v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
}

void clear(){
    for(int i = 0; i < n; i++){
        a[i] = 0;
        b[i] = INF;
        used[i] = false;
    }
}

void dfs(int v, int &cnt, int c){
    used[v] = true;
    for(int to : g[v]){
        if(!used[to]){
            dfs(to, cnt, c);
            chmax(a[v], a[to]+1);
            chmin(b[v], b[to]+1);
        }
    }
    if(a[v]+b[v] <= c){
        a[v] = -1;
    }
    if(a[v] >= c){
        cnt++;
        a[v] = -1;
        b[v] = 0;
    }
}

bool judge(int c){
    clear();
    int cnt = 0;
    dfs(0, cnt, c);
    if(a[0] != -1) cnt++;
    return cnt <= k;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    input();
    if(judge(1)){
        cout << 1 << endl;
        return 0;
    }
    int l = 1, r = n;
    while(r-l > 1){
        int c = (l+r)/2;
        if(judge(c)) r = c;
        else l = c;
    }
    cout << r << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n;
    cin>>n;
    int d=(n/100)*100+100;
    cout<<d-n<<endl;
}

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

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(){
    int x,a;
    cin>>x;
    a=x%100;
    if(a==0) cout << 100;
    else cout << 100-a;
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    ll ans = 0;

    int amari = -1;
    queue<int> que;
    rep(i,n){
        if(s[i] == '0' && t[i] == '1'){
            que.push(i);
        }

        if(s[i] == '1' && t[i] == '0'){
            if(amari!=-1&&que.size()>0){
                if(que.front() < amari){
                    ans += i - que.front();
                    que.pop();
                }else{
                    ans += i - amari;
                    amari = -1;
                }
            }else if(amari != -1){
                ans += i - amari;
                amari = -1;
            }else if(que.size()>0){
                ans += i - que.front();
                que.pop();
            }else{
                amari = i;
            }
        }
    }

    if(amari != -1) ans = -1;
    if(que.size() > 0) ans = -1;

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e2 + 10;

int n, a[N];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	int mi = INT_MAX;
	for (int i = 1; i < (1 << n); i++)
	{
		bitset<25> st(i);

		int sum = 0, tot = 0;
		for (int j = 0; j < n; j++)
		{
			sum |= a[j];
			if (st[j] == 1) tot ^= sum, sum = 0;
		}
		tot ^= sum;
		mi = min(mi, tot);
	}
	cout << mi << "\n";

	return 0;
}


//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

//#define DIV 1000000007
#define TE 5e5
using namespace std;
using ll = long long;
using ldb = long double;

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

	ll cnt = 0, tens = 10;
	for (ll i = 1; i <= 16; i++) {
		ll p = (i - 1) / 3;
		if (N >= tens) {
			cnt += p*(tens / 10) * 9;
			//cout << "tens=" << tens << "cnt=" << cnt << endl;
		}

		else {
			cnt += (tens / 10) * p * (N / (tens / 10) - 1);
			cnt += p * (N % (tens / 10)+1);
			//cout << "tens=" << tens << "cnt=" << cnt << endl;
			break;
		}

		tens *= 10;
	}

	cout << cnt << endl;
}

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

int main()
{
    string s;
    cin >> s;
    int count = 0;
    while (true)
    {
        int a = s.find("ZONe");
        if (a == std::string::npos)
        {
            cout << count;
            return 0;
        }
        s = s.substr(a + 4, s.length() - (a + 4));
        count++;
    }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int64_t> A(N+1);
    vector<int64_t> M(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] += A[i-1];
        M[i] = M[i-1];
        M[i] = max(M[i], A[i]);
    }
    int64_t total = 0;
    int64_t ans = 0;
    for (int i = 1; i <= N; i++) {
        ans = max(ans, total + M[i]);
        total += A[i];
        ans = max(ans, total);
    }
    cout << ans;
}

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

const int N = 100005;

int n;
int p[N];

int sz[N];
vector<int> edges[N];

int dfs(int u) {
  sz[u] = 1;
  vector<int> evens;
  vector<int> odds;
  for (int v : edges[u]) {
    int val = dfs(v);
    sz[u] += sz[v];

    if (sz[v] & 1) {
      odds.emplace_back(val);
    } else {
      evens.emplace_back(val);
    }
  }

  int ret = 1;
  for (int i = 0; i < evens.size(); ++i) if (evens[i] < 0) ret += evens[i];
  sort(odds.begin(), odds.end());
  for (int i = 0; i < odds.size(); ++i) {
    if (i & 1) ret -= odds[i];
    else ret += odds[i];
  }

  for (int i = 0; i < evens.size(); ++i) {
    if (evens[i] >= 0) {
      if (odds.size() & 1) ret -= evens[i];
      else ret += evens[i];
    }
  }

  return ret;
}

int solve() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int p;
    scanf("%d", &p);
    edges[--p].push_back(i);
  }

  int ans = dfs(0);
  ans += sz[0];
  ans /= 2;

  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    solve();
  }
  return 0;
}