#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int,int>>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].emplace_back(b, c);
  }
  for (int start = 0; start < n; start++) {
    vector<int> dist(n, 1 << 30);
    priority_queue<pair<int, int>> que;
    que.emplace(0, start);
    int ans = -1;
    bool flag = false;
    while (!que.empty()) {
      auto [curd, cur] = que.top();
      que.pop();
      curd = -curd;
      if (cur == start) {
        if (flag) {
          ans = curd;
          break;
        }
        flag = true;
      }
      if (dist[cur] < curd) continue;
      for (auto [nbr, d] : g[cur]) {
        int nd = curd + d;
        if (dist[nbr] > nd) {
          if (nbr != start) {
            dist[nbr] = nd;
          }
          que.emplace(-nd, nbr);
        }
      }
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll INF = 1e18;
const ll M = 3 * 1e5 + 10, B = sqrt(M) + 10;
// バケット i は [i*B, (i+1)*B) の記録を持つ

// a_s,...,a_t の xor を返す
ll getxor(int s, int t, vll &a, vll &xors){
    ll ret = 0;
    int st = s / B, gt = t / B;

    //... || ... s ... t ... || ...
    //直接計算
    if (st == gt){
        for (int i = s; i <= t; i++) ret ^= a[i];
    }
    //... s ... || (被覆されるパケット)  || ... t ...
    else{
        //端が属するパケット内は直接計算
        for (int i = s; i < (st + 1) * B; i++) ret ^= a[i];
        for (int i = gt * B; i <= t; i++) ret ^= a[i];
        //被覆されるパケットはパケット単位で調査する
        for (int i = st + 1; i < gt; i++) ret ^= xors[i];
    }
    return ret;
}

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

    int n, q;
    cin >> n >> q;
    vll a(n), xors(B);
    REP(i, n) {
        cin >> a[i];
        xors[i / B] ^= a[i];
    }
    while (q--) {
        ll t, x, y;
        cin >> t >> x >> y;
        if(t == 1){
            x--;
            a[x] ^= y;
            xors[x / B] ^= y;
        }
        else{
            x--, y--;
            cout << getxor(x, y, a, xors) << endl;
        }
    }
    return 0;
}


//Radhe Radhe
#include<bits/stdc++.h>
#define FASTIO_  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long

#define mod 1000000007
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define itr(i,n)    for(ll i=0; i<n; i++)
#define itr_ab(i,a,b)    for(ll i=a; i<=b; i++)
#define itrV(i,n)    for(ll i=0; i<v.size(); i++)
#define fixed cout.setf(ios::fixed);
#define precise cout.precision(15);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
#define en '\n'
#define Dont_Quit int main(void)
#define Avada_Kedavra return 0;
using namespace std;

Dont_Quit
{
    FASTIO_
    ll  tc,n,m,x,i,j,d;
    string s;
    tc=1;
    while(tc--)
    {
        ll a[3];
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        if(a[2]-a[1]==a[1]-a[0])
            yes;
        else no;
    }

    Avada_Kedavra
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int arr[]={a,b,c};
    int count=0;
    sort(arr,arr+3);
        if(arr[1]-arr[0]==arr[2]-arr[1])count++;
    if(count==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n, q;
  cin>>n>>q;
  vector<ll> a(n+1, 0), c(n+1, 0);
  for (int i = 1; i <= n; ++i)
  {
    cin>>a[i];
  }
  for (int i = 1; i <= n; ++i)
  {
    c[i] = a[i] - i;
  }

  for (int i = 0; i < q; ++i)
  {
    ll k;
    cin>>k;
    if (k > c[n]) {
      cout << a[n] + k - c[n] << "\n";
      continue;
    }
    ll l = 0, r = n;
    while (r -l > 1) {
      ll m = (l+r)/2;
      if (c[m] < k) l = m;
      else r = m;
    }
    cout << a[l] + k - c[l] << "\n";
  }

}

#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

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

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

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int k;
	scanf("%d", &k);
	ll ans = 0;
	for (int a = 1; a <= k; ++a) {
		for (int ab = a; ab <= k; ab += a) {
			int nc = k / ab;
			ans += nc;
		}
	}
	printf("%lld\n", ans);
}

/*pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(firstsecond) '(' << first< ',' << second< ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001;
long double EPS = 1e-8;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

int main(){
  ll K;
  cin >> K;
  ll ans = 0;
  ll cnt = 0;
  ll m = 0;
  FOR(i,1,K+1){
    FOR(j,1,K / i + 1){
      ll l = 1,r = INF;
      while(r-l > 1){
        ll mid = (l+r)/2;
        if(i * j * mid > K) r = mid;
        else l = mid;
      }
      ans += l;
    }
  }
  cout << ans << endl;
}


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

typedef long long ll;

int N;

int f(int x) {
    while (x > N - 1) {
        int a = 1;
        while (a * 2 <= x) a *= 2;
        x -= a;
    }
    return x + 1;
}

int main() {
    cin >> N;
    rep(i, 0, N) {
        cout << f(i * 2) << " " << f(i * 2 + 1) << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t; cin >> t;
  rep(_, t) {
    ll l, r; cin >> l >> r;
    if(2*l > r) cout << 0 << endk;
    else cout << (-2*l+1)*(r-2*l+1) + r*(r+1)/2 - (2*l-1)*(2*l)/2 << endk;
  }
  return 0;
}


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

typedef long long ll;

int main() {
    int N, M, maxw = 0, minv = 1e9, ans = 1e9;
    cin >> N >> M;
    vector<int> w(N), l(M), v(M), s(1 << N, 0), d(1 << N, 0), a(N);
    rep(i, 0, N) {
        cin >> w[i];
        maxw = max(maxw, w[i]);
    }
    rep(i, 0, M) {
        cin >> l[i] >> v[i];
        minv = min(minv, v[i]);
    }
    if (maxw > minv) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, 0, 1 << N) {
        rep(j, 0, N) {
            if ((i >> j) & 1) s[i] += w[j];
        }
        rep(j, 0, M) {
            if (s[i] > v[j]) d[i] = max(d[i], l[j]);
        }
        //cout << i << " " << s[i] << " " << d[i] << endl;
    }
    rep(i, 0, N) a[i] = i;
    do {
        //rep(i, 0, N) cout << a[i]; cout << endl;
        vector<int> b(N + 1, 0);
        rep(i, 0, N) b[i + 1] = b[i] | (1 << a[i]);
        //rep(i, 0, N + 1) cout << b[i] << " "; cout << endl;
        vector<vector<int>> c(N, vector<int>(N));
        rep(i, 0, N - 1) {
            rep(j, i + 1, N) {
                c[i][j] = d[b[i] ^ b[j + 1]];
                //cout << "c[" << i << "][" << j << "]=" << c[i][j] << " ";
            }
        }
        vector<int> dist(N, 0);
        rep(i, 1, N) {
            rep(j, 0, i) {
                dist[i] = max(dist[i], dist[j] + c[j][i]);
            }
        }
        ans = min(ans, dist[N - 1]);
        //out << ans << endl;
    } while (next_permutation(a.begin(), a.end()));
    cout << ans << endl;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef __int128 int_;
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}
inline void writeint(int_ x){
	if(x > 9) writeint(x/10);
	putchar((x-x/10*10)^48);
}

int_ exgcd(int_ a,int_ b,int_ &x,int_ &y){
	if(!b){ x = 1, y = 0; return a; }
	int_ d = exgcd(b,a%b,y,x);
	y -= (a/b)*x; return d;
}

int main(){
	int_ zxy, sxy;
	for(int T=readint(); T; --T){
		int_ ans = -1; // infinity
		int x = readint(), y = readint();
		int p = readint(), q = readint();
		int T1 = 2*(x+y), T2 = p+q;
		int_ lcm = exgcd(T1,T2,zxy,sxy);
		lcm = 1ll*T1/lcm*T2;
		rep(i,x,x+y-1) rep(j,p,p+q-1){
			int_ a, b, d = exgcd(T1,T2,a,b);
			if((j-i)%d) continue; // no solution
			d = (j-i)/d; a *= d, b *= d;
			int_ t = T1*a+i; // remainder
			t = (t%lcm+lcm)%lcm; // be positive
			if(ans == -1 || ans > t) ans = t;
		}
		if(ans == -1) puts("infinity");
		else writeint(ans), putchar('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
unordered_map<ll,ll>dp;
ll n,m;
ll fun(ll x){
	if(n>=x) return n-x;
	if(dp[x]) return dp[x];
	ll c=x-n;
	c=min(c,fun(x/2)+1+x%2);
	if(x%2) c=min(c,fun(x/2+1)+2);
	return dp[x]=c;
}
int main(){
	scanf("%lld%lld",&n,&m);
	printf("%lld\n",fun(m));
	return 0;
}

/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#ifdef ONLINE_JUDGE
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define dbg(vec)
#else
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
#endif

// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

unordered_map<int64, int64> memo;

int64 f(int64 x, int64 y) {
    auto it = memo.find(y);
    if (it != memo.end()) return it->second;
    if (x >= y) {
        return x - y;
    } else if (y & 1) {
        return memo[y] = min(min(f(x, (y + 1) / 2), f(x, (y - 1) / 2)) + 2, abs(x - y));
    } else {
        return memo[y] = min(abs(x - y), f(x, y / 2) + 1);
    }
}

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    int64 x, y;
    cin >> x >> y;

    print(f(x, y));

    return 0;
}

/*
  __
 / _| ___ _ __  _ __
| |_ / __| '_ \| '_ \
|  _| (__| |_) | |_) |
|_|(_)___| .__/| .__/
         |_|   |_|
*/


#include<bits/stdc++.h>
#define LL long long
#define DB long double
using namespace std;
//#define P 998244353
//inline int ad(int x,int y){return (x+y>=P)?(x+y-P):(x+y);}
//inline int mt(int x,int y){return 1ll*x*y%P;}
//inline void mo(int &x){x=(x>=P)?(x-P):x; x=(x<0)?(x+P):x;}
template<typename T>inline void ckmx(T &x,T y){x=max(x,y);}
template<typename T>inline void ckmi(T &x,T y){x=min(x,y);}
template<typename T>void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-48;
	x*=f;
}
LL a[100010];
LL b[10];
int usd[10],n,T,bn;
int main(){
	read(T);
	while(T--){
		read(n);
		bn=0;
		int tp=0;
		for(int i=1;i<=n;++i) read(a[i]);
		sort(a+1,a+1+n);
		if(n&1) puts("Second");
		else{
			int la=0,f=1;
			for(int i=1;i<=n;++i)
				if (la==0) la=a[i];
					else if(la==a[i]) la=0;
						else f=0;
			if(f==0) puts("First");
				else puts("Second");
		}
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int ddx[]={0,0,1,-1,1,-1,1,-1};
int ddy[]={1,-1,0,0,-1,1,1,-1};
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        ll wt;
        cin>>a>>b>>wt;
        wt*=1000;
        ll p=-1,q=-1;
        for(i=a;i<=b;i++)
        {
            if(wt%i==0 || (a<=(wt%i) && (wt%i)<=b))
            {
                if(wt%i==0)p=wt/i;
                else p=(wt/i)+1;
                break;
            }
        }
        for(i=b;i>=a;i--)
        {
            if(wt%i==0 || (a<=(wt%i) && (wt%i)<=b))
            {
                if(wt%i==0)q=wt/i;
                else q=(wt/i)+1;
                break;
            }
        }
        swap(p,q);
        if(p==-1)cout<<"UNSATISFIABLE"<<endl;
        else {
          cout<<((wt/b)+((wt%b)!=0))<<" "<<((wt/a))<<endl;
        }

    }
}


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

const int MAXN = 2e5 + 5;

int n, a[MAXN];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int ans = a[0];
	for(int i = 0; i < n; ++i) {
		ans = __gcd(ans, a[i]);
	}
	// while(true) {
	// 	int minVal = 2e9;
	// 	for(int i = 0; i < n; ++i) {
	// 		if (minVal > a[i])
	// 			minVal = a[i];
	// 	}
	// 	for(int i = 0; i < n; ++i) {
	// 		if(minVal < a[i]) {
	// 			a[i] = a[i]%minVal;
	// 		}
	// 	}
	// }
	printf("%d\n", ans);
}

//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#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 vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int n; cin >> n;
    vi a(n);
    REP(i, n) cin >> a[i];

    int m = *min_element(ALL(a));

    int ans = m;
    REP(i, n) {
        ans = __gcd(ans, a[i]);
    }

    print(ans);

}


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

using namespace std;

typedef long double LD;
typedef pair<int, int> II;
const LD EPS = 1e-8;

bool solve(int N, vector<int> a, vector<int> b, vector<int> c, vector<int> d) {
	if (N <= 1) return true;
	LD dx = a[1] - a[0], dy = b[1] - b[0], r = sqrtl(dx * dx + dy * dy), deg = atan2l(dy, dx);
	set<II> s;
	for (int i = 0; i < N; ++i) {
		s.insert(II(a[i] - a[0], b[i] - b[0]));
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i == j) continue;
			LD dx2 = c[j] - c[i], dy2 = d[j] - d[i], r2 = sqrtl(dx2 * dx2 + dy2 * dy2), offset = atan2l(dy2, dx2) - deg;
			if (fabsl(r2 - r) > EPS) continue;
			set<II> s2;
			for (int k = 0; k < N; ++k) {
				LD dx3 = c[k] - c[i], dy3 = d[k] - d[i], r3 = sqrtl(dx3 * dx3 + dy3 * dy3), deg3 = atan2l(dy3, dx3) - offset;
				LD x = roundl(cosl(deg3) * r3), y = roundl(sinl(deg3) * r3);
				LD r4 = sqrtl(x * x + y * y);
				if (fabsl(r4 - r3) <= EPS) {
					s2.insert(II(int(x), int(y)));
				}
			}
			if (s == s2) {
				return true;
			}
		}
	}
	return false;
}

int main() {
#if DEBUG || _DEBUG
	freopen("in.txt", "r", stdin);
	//	freopen("in_1.txt", "r", stdin);
#endif
	int N;
	cin >> N;
	vector<int> a(N), b(N), c(N), d(N);
	for (int i = 0; i < N; i++) {
		std::cin >> a[i] >> b[i];
	}
	for (int i = 0; i < N; i++) {
		std::cin >> c[i] >> d[i];
	}
	cout << (solve(N, a, b, c, d) ? "Yes" : "No") << endl;
	return 0;
}

/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll MOD = MODBASE;

ll binPowMod(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1LL) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1LL;
    }
    return res;
}

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

ll sub(ll a, ll b) {
    return (a - b + MOD) % MOD;
}

ll mul(ll a, ll b) {
    return a * b % MOD;
}

ll inv(ll u) {
    return binPowMod(u, MOD-2);
}

ll get(ll r) {
    return mul(mul(r, r+1), inv(2));
}

ll getSum(ll l, ll r) {
    if (r < l) return 0;
    return sub(get(r), get(l-1));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int t, n, a, b;
    cin >> t;
    while (t--) {
        cin >> n >> a >> b;
        ll res = mul(mul(n-a+1, n-a+1), mul(n-b+1, n-b+1));

        if (a > b) swap(a, b);
        int l = b, r = b+a-1;
        int g = n-a+1;
        r = min(r, g);
        l = min(l, g);

        // cout << l << ' ' << r << endl;

        ll sum = mul(getSum(l, r-1), 2);
        // cout << getSum(l, r-1) << endl;
        ll remain = n-b+1 - (r - l) * 2;
        sum = add(sum, mul(remain, r));

        sum = mul(sum, sum);
        res = sub(res, sum);
        cout << res << "\n";

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define endl '\n'

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	set<ll> s;
	for(ll i=2;i*i<=n;i++)
	{
		ll res=i;
		for(int j=1;j<=35;j++)
		{
			res*=i;
			if(res<=n) s.insert(res);
			else break;
		}
	}
	cout<<n-s.size()<<endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const int INF=1e9+7;
const ll INFF=1e18+7;
#define nl '\n'
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char* x) { cout << '\"' << x << '\"'; }
void __print(const string& x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V>& x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cout << '{'; for (auto& i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; }
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int intlog(int base, int x) {
    return (int)(log(x) / log(base));
}

void solve()
{
    ll n,nr=0;
    cin>>n;
    ll a=2,b=2;
    unordered_map<ll,int> d;
    while(a*a<=n){
        while(a*b<=n){
            a*=b;
            d[a]++;
            if(d[a]==1) nr++;
        }
        b++;
        a=b;
    }
    cout<<n-nr;
}

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


#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
#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 long long  ll;
typedef vector<int> vi;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
//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());

#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
#define fi first
#define se second
#define ptr item*

const long long INF = 1e18;
const ll tam =1000100;
const ll MOD=998244353;
const ll cmplog=29;

int main()
{
    ll n;
    cin>>n;
    ll iz=1,der=2;
    ll mid;
    while(der*(der+1)/2<=n+1)
        der*=2;

    while(iz+1<der)
    {
        mid=(iz+der)/2;
        if (mid*(mid+1)/2<=n+1)
            iz=mid;
        else der=mid;
    }
    cout<<n-iz+1<<endl;
}

// #include<bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cassert>
#include <bitset>

using namespace std;

int main() {
  long long int N, ans=0;
  long long int x;
  string y;

  cin >> N;

  for(size_t i=1; i<1e+6; i++){
    y = to_string(i);
    y += to_string(i);
    x = stoll(y);

    if(x > N){
      break;
    }
    else{
      ans += 1;
    }
  }

  cout << ans << endl;
}


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

// #include <atcoder/all>
// using namespace atcoder;

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

void solve(long long N, long long K, std::vector<std::vector<long long>> A){
    // 中央値を ll 以下にすることが可能か
    int ok = 1e9;
    int ng = -1;
    auto check = [&](int l) {
        vector<vector<int>> cum1(N, vector<int>(N + 1));
        rep(i, N) {
            rep(j, N) {
                cum1[i][j + 1] = cum1[i][j] + (A[i][j] <= l);
            }
        }
        vector<vector<int>> cum2(N + 1, vector<int>(N + 1));
        rep(i, N) {
            rep(j, N + 1) {
                cum2[i + 1][j] = cum2[i][j] + cum1[i][j];
            }
        }
        // printf("l: %ld\n", l);
        rep(i, N + 1) {
            rep(j, N + 1) {
                // printf("%ld ", cum2[i][j]);
            }
            // printf("\n");
        }
        rep(i, N - K + 1) {
            rep(j, N - K + 1) {
                if (
                    cum2[i + K][j + K]
                    - cum2[i + K][j]
                    - cum2[i][j + K]
                    + cum2[i][j] >= (K * K + 1) / 2) {
                    // printf("OK\n");
                    return 1;
                }
            }
        }

        // printf("NG\n");
        return 0;
    };
    while (ok - ng > 1) {
        int l = (ok + ng) / 2;
        (check(l) ? ok : ng) = l;
    }
    cout << ok << endl;
}

// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    std::scanf("%lld", &N);
    long long K;
    std::scanf("%lld", &K);
    std::vector<std::vector<long long>> A(N, std::vector<long long>(N));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < N ; j++){
            std::scanf("%lld", &A[i][j]);
        }
    }
    solve(N, K, std::move(A));
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
// ll p = 1e9+7;
// ll p = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

ll x,y;
ll exgcd(ll a,ll b,ll &x,ll &y){
  if(b==0){x=1;y=0;return a;}
  ll d=exgcd(b,a%b,y,x);
  y-=a/b*x;
  return d;
}

int main(){
  cii(t);
  vll ans;

  while(t--){
    cii(n);
    cci(s,k);
    s=n-s;

    ll g=__gcd(n,__gcd(s,k));
    n/=g;
    s/=g;
    k/=g;

    ll g2=__gcd(n,k);
    if(g2!=1){ans.pb(-1);continue;}

    exgcd(k,n,x,y);
    (x+=n)%=n;
    ans.pb(s*x%n);
  }

  for(ll d:ans)co(d);
}


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

using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? " " : "") << a[i];
  return os << '\n';
}
template <typename T>
std::ostream& operator<<(std::ostream& os, pair<T, T>& p) {
  return os << "{ " << p.first << ", " << p.second << " }" << std::endl;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& a) {
  for (T& x : a) is >> x;
  return is;
}

[[maybe_unused]] constexpr ll MOD = 1000000007;
[[maybe_unused]] constexpr int INF = 0x3fffffff;
[[maybe_unused]] constexpr ll INFL = 0x3fffffffffffffffLL;

class combination {
public:
  combination(int n, uint64_t m)
    : mod(m), fact(n + 1), inv(n + 1), finv(n + 1) {
    fact[0] = finv[0] = inv[1] = 1;
    // i * inv[i] = 1 mod p.
    // p = p / i * i + p % i
    // => p / i * i + p % i = 0 mod p
    // => (p / i * -inv[p % i]) * i = 1 mod p
    for (uint64_t i = 2; i <= n; ++i)
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    for (uint64_t i = 1; i <= n; ++i) {
      fact[i] = fact[i - 1] * i % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }
  uint64_t operator()(int n, int k) const {
    if (n < k || n < 0 || k < 0) return 0;
    return fact[n] * finv[n - k] % mod * finv[k] % mod;
  }
  uint64_t modpow(uint64_t x, uint64_t e) {
    uint64_t res = 1;
    while (e > 0) {
      if (e & 1) res = res * x % mod;
      x = x * x % mod;
      e >>= 1;
    }
    return res;
  }

private:
  uint64_t mod;
  std::vector<uint64_t> fact, inv, finv;
};

int main() {
  cin.tie(0)->sync_with_stdio(0);
  ll n, m, k;
  cin >> n >> m >> k;
  combination c(n + m + 5, MOD);

  if (n - m > k) {
    cout << 0;
  } else {
    ll a = c(n + m, n);
    ll b = c(n + m, n - k - 1);
    cout << (MOD + (a - b) % MOD) % MOD;
  }
  return 0;
}

//It is good to start with zero//
//    kyu @Aryabhatta//

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long ll;
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define vec(i, a)  for( auto i=a.begin();i != a.end(); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mp make_pair
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in  freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sixfive in out
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
const ll MOD = 1e9 + 7;
ll n_bits(ll n ) { ll x= __builtin_popcount(n) ;return x ;}
int pow(int a, int b, int m)
{
    int ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%m;
        b/=2;
        a=(a*a)%m;
    }
    return ans;
}
int main()
{
    #ifndef ONLINE_JUDGE
    sixfive
    #endif
    fast
    ll t=1;
    //cin>>t;
    while(t--)
    {
        int a,b,c,d;
        int sum=0;
        cin>>a>>b>>c>>d;
        if(a==b+c+d||b==c+d+a||c==a+b+d||d==a+b+c)
        {
            cout<<"Yes";
            continue;
        }
        if(a+b==c+d||b+c==a+d||a+c==b+d||a+d==b+c)
        {
             cout<<"Yes";
                continue;
        }
        cout<<"No";

    }
    return 0;
}

//            sometimes I do it for her...//


#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

const int max_n = 1e5+100;
const int max_sum = 1e7+100;
const int max_len = 1e6+110;
const int offset = 1e5+10;
const int inf = 1e18;

int n;
vector<int> adj[max_n];
int st[max_n];

struct Node
{
	int first,second,turn;
	Node(){
		first=0;second=0;turn=0;
	}
};

Node dfs(int v){
	st[v]=1;
	vector<Node> c;

	for(int x:adj[v]){
		c.pb(dfs(x));
		st[v]+=st[x];
	}

	sort(c.begin(),c.end(),[](const Node& a,const Node& b)->bool{
		if(a.turn!=b.turn){
			return a.turn<b.turn;
		}else{
			return (a.second-a.first)>(b.second-b.first);
		}
	});

	Node ans;
	ans.turn = (st[v]%2);
	ans.first = 1;

	for(Node x:c){
		if(x.turn==0 && x.second>=x.first){
			ans.second+=x.second;
			ans.first+=x.first;
		}
	}

	int t=0;

	for(Node x:c){
		if(x.turn==1){
			if(t==0){
				ans.second+=x.second;
				ans.first+=x.first;
			}else{
				ans.second+=x.first;
				ans.first+=x.second;
			}

			t = (t+1)%2;
		}
	}

	for(Node x:c){
		if(x.turn==0 && x.second<x.first){
			if(t==1){
				ans.first+=x.second;
				ans.second+=x.first;
			}else{
				ans.first+=x.first;
				ans.second+=x.second;
			}
		}
	}

	return ans;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(int i=1;i<n;i++){
    	int p;cin>>p;p--;
    	adj[p].pb(i);
    }

    Node ans = dfs(0);
    cout<<ans.first<<endl;

}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef _DEBUG
    #define debug(x) cout << #x << ": " << x << std::endl
#else
    #define debug(x)
    #pragma GCC target("avx")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma GCC optimize("O3")
    #pragma GCC optimize("unroll-loops")
#endif
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); ++i)
#define all(x) (x).begin(), (x).end()
constexpr char enl = '\n';
constexpr int INF = 1000000000;  // 1e9
constexpr ll llINF = 1000000000000000000LL;  // 1e18
/*#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
*/

typedef struct node_ {
    vector<int> child;
    int invert;
    int size;
    int first;

    node_() :
        child(vector<int>(0)), invert(-1), size(1), first(-1) {}
} node;

void Main() {
    int n;
    cin >> n;
    vector<node> tree(0);
    tree.reserve(n);
    rep(i, 0, n) tree.emplace_back();
    rep(i, 1, n) {
        int p;
        cin >> p;
        tree[p - 1].child.push_back(i);
        //debug(tree[p - 1].child[tree[p - 1].child.size() - 1]);
    }

    auto get_inv = [&](auto self, int cn) -> pair<int, int> {
        int res1 = 1, res2 = 1;
        for (auto nn : tree[cn].child) {
            auto [a, b] = self(self, nn);
            res1 = (res1 + a) % 2;
            res2 += b;
        }
        tree[cn].invert = res1;
        tree[cn].size = res2;
        return {res1, res2};
    };
    get_inv(get_inv, 0);
    //rep(i, 0, n) debug(tree[i].size);

    auto get_first = [&](auto self, int cn) -> int {
        //debug(cn);
        if (tree[cn].first != -1) return tree[cn].first;
        int res = 0;
        vector<int> minus(0), plus(0), inv(0);
        for (auto nn : tree[cn].child) {
            //debug(cn); debug(nn);
            self(self, nn);
            if (tree[nn].invert == 1) inv.push_back(nn);
            else if (2 * tree[nn].first <= tree[nn].size)
                minus.push_back(nn);
            else
                plus.push_back(nn);
        }
        sort(all(inv), [&](const auto &a, const auto &b) { return 2 * tree[a].first - tree[a].size < 2 * tree[b].first - tree[b].size; });
        for (auto nn : minus) res += tree[nn].size - tree[nn].first;
        if (inv.size() % 2)
            for (auto nn : plus) res += tree[nn].first;
        else
            for (auto nn : plus) res += tree[nn].size - tree[nn].first;
        rep(i, 0, inv.size()) res += i % 2 ? tree[inv[i]].first : tree[inv[i]].size - tree[inv[i]].first;
        return tree[cn].first = tree[cn].size - res;
    };

    cout << get_first(get_first, 0) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
}


/*
  author: Kamal Kant Bhardwaj
  date:
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int             long long
#define N               20000006
#define F               first
#define S               second
#define test(x)         int x; cin>>x; while(x--)
#define pb              push_back
#define vi              vector<int>
#define mapp            map<int,int>
#define pqbig           priority_queue<int>
#define pqsmall         priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define Inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {

  c_p_c();
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (b - c) << endl;
  return 0;
}

#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int t;scanf("%d",&t);
	while(t--)
	{
		int n;scanf("%d%*s%*s%*s",&n);
		for(int i=1;i<=n;i++)putchar('0');
		for(int i=1;i<=n;i++)putchar('1');
		puts("0");
	}
	return 0;
}


#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
int main(){
  int n,m; cin >> n >> m;
  cout << n/m << endl;
}

#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define Ios ios::sync_with_stdio(false),cin.tie(0)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1000005
#define quick_pow_mod 1000000007
#define PII pair<int,int>
const int factor_N = 10000005;
const int tree_arr_N = 1000005;
using namespace std;
/*
	1.注意边界情况
	2.优先考虑时间复杂度
!!! 3.求最大值时，答案应至多初始化为INT_MIN；求最小值时，答案应至少初始化为INT_MAX
	4.遇事不决先暴力
	5.代码要写简洁
	6.计数题要开long long
*/
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
	return x * f;
}
int n, m;
int main() {
	Ios;
	cin >> n >> m;
	cout << n / m << endl;
	return 0;
}


/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
	cerr << "\e[1;33m" << s << " = [";
	while(l != r) {
		cerr << *l;
		cerr << (++l == r ? ']' : ',');
	}
	cerr << "\e[0m\n";
}

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*--------------------------------------------------------------------------------------*/

signed main() {
	int n;
	cin >> n;
	vector<vector<int>> edge(n + 1);
	vector<int> in(n + 1), out(n + 1), dep(n + 1);
	vector<vector<int>> d(n);
	for(int i = 2; i <= n; i++) {
		int x;
		cin >> x;
		edge[x].push_back(i);
	}
	int t = 0;
	function<void(int)> dfs = [&](int u) {
		d[dep[u]].push_back(t);
		in[u] = t++;
		for(int v : edge[u])
			dep[v] = dep[u] + 1, dfs(v);
		d[dep[u]].push_back(t);
		out[u] = t++;
	};
	dfs(1);
	int q;
	cin >> q;
	while(q--) {
		int u, de;
		cin >> u >> de;
		cout << (upper_bound(d[de].begin(), d[de].end(), out[u]) - lower_bound(d[de].begin(), d[de].end(), in[u])) / 2 << '\n';
	}
}

#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 200005;

vi g[N];
vi nodes[N];
int D[N];
int _tm;
int tin[N], tout[N];

void dfs(int c, int d) {
  D[c] = d;
  tin[c] = ++_tm;
  nodes[d].pb(tin[c]);
  rep(i,0,g[c].size()) {
    dfs(g[c][i], d + 1);
  }
  tout[c] = ++_tm;
}

int bs(int d, int x) {
  int lo = 0, hi = (int)nodes[d].size() - 1;
  int ans = 0;
  while(lo <= hi) {
    int mi = (lo + hi) >> 1;
    if(nodes[d][mi] <= x) {
      ans = mi + 1;
      lo = mi + 1;
    } else {
      hi = mi - 1;
    }
  }
  return ans;
}

int main() {
  int n;
  S(n);
  rep(i,2,n+1) {
    int p;
    S(p);
    g[p].pb(i);
  }
  dfs(1, 0);
  int q;
  S(q);
  while(q--) {
    int u,d;
    S2(u,d);
    if(D[u] > d) {
      P(0);
      continue;
    }
    P(bs(d, tout[u]) - bs(d, tin[u] - 1));
  }
  return 0;
}


#include <iostream>
#include <unordered_map>

int main()
{
    int n;
    std::cin >> n;
    std::unordered_map<int, int> table;
    for (int i = 0; i < n; ++i)
    {
        int a;
        std::cin >> a;
        table[a] += 1;
    }

    int64_t total = 0;
    int consumed = 0;
    for (const auto &e : table)
    {
        const int c = e.second;
        const int k = n - consumed - c;
        total += static_cast<int64_t>(c) * k;
        consumed += c;
    }

    std::cout << total << std::endl;
    return 0;
}

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

// ---------- Debugger

#define TRACE

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(char c) {
    return '\'' + string(1, c) + '\'';
}

string to_string(char * s) {
    return to_string((string) s);
}

string to_string(const char * s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template < typename A >
string to_string(A v);

template < typename A, typename B >
string to_string(pair < A, B > p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template < typename C > struct rge { C b, e; };
template < typename C > rge<C> range(C i, C j) { return rge<C>{i, j}; }

template < typename C >
string to_string(rge<C> v) {
    bool first = true;
    string res = "[";
    for(auto it = v.b; it != v.e; it++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(*it);
    }
    res += "]";
    return res;
}

template < typename A >
string to_string(A v) {
    return to_string(range(v.begin(), v.end()));
}

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Head >
void __f(const string names, Head arg1) {
    cerr << names << " : " << to_string(arg1) << endl;
}
template < typename Head, typename...Tail >
void __f(const string names, Head arg1, Tail...args) {
    int b = 0, comma = names.size();
    for(int i=0;i<names.size();i++) {
        if(names[i] == ',' && b == 0) {
            comma = i;
            break;
        }
        if(names[i] == '(' || names[i] == '{' || names[i] == '[' || names[i] == '<') b++;
        else if(names[i] == ')' || names[i] == '}' || names[i] == ']' || names[i] == '>') b--;
    }
    // size_t comma = names.find(', ');
    cerr << names.substr(0, comma) << " : " << to_string(arg1) << " | ";
    __f(names.substr(comma + 1), args...);
}
#else
#define trace(...)
#endif

// ---------- Debugger

#define LL long long
#define FI ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
const int MX = (int)2e5 + 5;

namespace modop {
    const int mod = 998244353;
    long long madd(long long a, long long b) {
        return (a + b) % mod;
    }
    long long msub(long long a, long long b) {
        return (((a - b) % mod) + mod) % mod;
    }
    long long mmul(long long a, long long b) {
        return ((a % mod) * (b % mod)) % mod;
    }
    long long mpow(long long base, long long exp) {
        long long res = 1;
        while (exp) {
            if (exp % 2 == 1){
                res = (res * base) % mod;
            }
            exp >>= 1;
            base = (base * base) % mod;
        }
        return res;
    }
    long long minv(long long base) {
        return mpow(base, mod - 2);
    }
    long long mdiv(long long a, long long b) {
        return mmul(a, minv(b));
    }
}
using namespace modop;

int n;
int inp[MX];

int vis[MX], mark[MX];
int cyc;
void dfs(int node) {
    vis[node] = 1;
    mark[node] = 1;
    int v = inp[node];

    if(mark[v] == 1) {
        cyc++;
    }

    if(!vis[v]) {
        dfs(v);
    }
    mark[node] = 0;
}

int main() {
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> inp[i];
        vis[i] = 0;
        mark[i] = 0;
    }

    cyc = 0;
    for(int i=1;i<=n;i++) {
        if(!vis[i]) {
            dfs(i);
        }
    }

    int ans = msub(mpow(2, cyc),1);
    cout << ans << endl;

    return 0;
}


//@Author: KeinYukiyoshi

// clang-format off
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#define int long long
using namespace std;
#define stoi stoll
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define _max(x) *max_element(ALL(x))
#define _min(x) *min_element(ALL(x))
#define _sum(x) accumulate(ALL(x), 0LL)

const int MOD   = 1e14;
// const int MOD    = 998244353;
const int INF    = (int)1e18;
const int INF2    = 10000000000007; // 1e13 + 7
const int INF3    = LLONG_MAX; // 9.2e18
const double EPS = 1e-8;
const double PI  = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S>  using P = pair<T, S>;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
template<class T> T chmod(T &a, T mod=MOD) {a =  a >= 0 ? a % mod : a - (mod * _ceil(a, mod)); return a;};
int _mod(int a, int mod=MOD) {return a >= 0 ? a % mod : a - (mod * _ceil(a, mod));}
int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;}
struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// clang-format on

class CDoubled {
public:
  static void solve(istream &cin, ostream &cout) {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int N;
    cin >> N;
    int ans = 0;
    rep2(i, 1, 1000000 + 100) {
      string I = to_string(i);
      int ret  = i + i * _pow(10, I.size());
      if (ret <= N) ans++;
    }
    cout << ans << endl;
  }
};

signed main() {
  CDoubled solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  cout << fixed << setprecision(10);
  ll n;
  cin >> n;
  vector<ll> a(n) , b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll sum = 0;
  rep(i,n)
  {
    sum += a[i] * b[i];
  }
  if(sum==0)
  {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define trav(a, x) for(auto& a : x)
#define vi vector<int>
#define fo(i, k, n) for(int i = k; i < n; ++i)
typedef long long ll;
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(name.size()){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

const int mod = 1e9 + 7;

int main()
{
    setIO();
    int n;
    cin >> n;
    map<int, ll> count;
    ll res = 0;
    for(int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        res += (i - count[k]);
        count[k]++;
    }
    cout << res << endl;
    return 0;
}

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

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

    int N;
    cin >> N;

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

    const int MIN_ELEM = *min_element(A.begin(), A.end());
    unordered_map<int, int> memo;
    memo[MIN_ELEM] = MIN_ELEM;
    for(int i = 0; i < N; ++i){
        for(int d = 1; d * d <= A[i]; ++d){
            if(A[i] % d == 0){
                for(int divisor: set<int>{d, A[i] / d}){
                    memo[divisor] = (memo.count(divisor) ? __gcd(memo[divisor], A[i]) : A[i]);
                }
            }
        }
    }

    int answer = 0;
    for(const pair<int, int>& P: memo){
        answer += (P.first == P.second && P.first <= MIN_ELEM);
    }

    cout << answer;

    return 0;
}


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

#define int             long long
#define w(x)            int x; cin>>x; while(x--)
#define endl            ("\n")
#define f(i, a, n)      for(int i=a; i<n; i++)
#define cc(r)           cout<<r<<" "
#define ce(r)           cout<<r<<endl

void inout()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
int nCrModpDP(int n, int r, int p)
{
    int C[r + 1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j - 1]) % p;
    }
    return C[r];
}

int nCrModpLucas(int n, int r, int p)
{
    if (r == 0)
        return 1;
    int ni = n % p, ri = r % p;
    return (nCrModpLucas(n / p, r / p, p) * nCrModpDP(ni, ri, p)) % p;
}
int32_t main()
{
    inout();
    int n;
    cin >> n;
    int r[n], a[n], ans = 0;
    f(i, 0, n) {
        r[i] = nCrModpLucas(n - 1, i, 3);
    }
    char k;
    f(i, 0, n) {
        cin >> k;
        if (k == 'B')
            a[i] = 0;
        else if (k == 'W')
            a[i] = 1;
        else
            a[i] = 2;
    }
    f(i, 0, n) {
        ans = (ans + (a[i] * r[i]) % 3) % 3;
    }
    if ((n & 1) == 0) {
        ans = (-ans + 3) % 3;
    }
    if (ans == 0)
        ce('B');
    else if (ans == 1)
        ce('W');
    else
        ce('R');

}

#include <bits/stdc++.h>
#define rep(i, a, b)   for(int i = a; i <= b; ++i)
#define repr(i,a,b)    for(int i = a ; i >= b; --i)
#define NAME           "NAME"
#define pb             push_back
#define mp             make_pair
#define EL             cout << '\n'
#define cqtshadow      int main
#define fillchar(a,x)  memset(a, x, sizeof (a))
#define faster         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
typedef int64_t        ll;
typedef vector<int>    vi;
typedef vector<ll>     vl;
typedef pair<int, int> ii;
typedef pair<ll, ll>   iil;
const ll  oo  =  1e18;
const int inf =  1e9;
const int mod =  3;
const int N   =  4e5 + 7;
const int M   =  1e6 + 7;
void file() {freopen ( NAME ".inp", "r", stdin ); freopen ( NAME ".out", "w", stdout ); freopen ( NAME ".err", "w", stderr);}

int n, c[N], C_[5][5];
string s;

void cal() {
	rep(i, 0, 3)
	rep(j, 0, i)
		if(i == 0 || j == 0) C_[i][j] = 1;
		else C_[i][j] = (C_[i - 1][j]%mod + C_[i - 1][j - 1]%mod)%mod;
}

int C(int k, int n) {
	if(k < mod && n < mod) return C_[n][k];
	return (C(k/mod, n/mod)%mod * C_[n%mod][k%mod])%mod;
}

cqtshadow () {
	faster
	cin >> n >> s;
	rep(i, 1, n) {
		if(s[i - 1] == 'W') c[i] = 0;
		if(s[i - 1] == 'R') c[i] = 1;
		if(s[i - 1] == 'B') c[i] = 2;
	}
	cal();
	int res = 0;
	rep(i, 1, n) {
		res = (res + (c[i] * C(i - 1, n - 1)%mod)%mod)%mod;
	}
	if(n%2 == 0) res *= -1;
	res = (res%mod + mod*1000000)%mod;
	if(res == 0) cout << "W";
	if(res == 1) cout << 'R';
	if(res == 2) cout << "B";
}


#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;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007 //998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1000000000000005
#define N 500005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
bool comp(pii &p1,pii &p2)
{
    if(p1.F<p2.F)return false;
    else if(p1.F == p2.F)
    {
        return p1.F<p2.F;
    }
    else return true;
}
void solve()
{
    int n,m,q;
    cin>>n>>m>>q;
    vector<pii>v(n);
    rep(i,0,n)
    {
        cin>>v[i].S>>v[i].F;
    }
    sort(all(v),comp);
    vi bags(m);
    rep(i,0,m)cin>>bags[i];
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        l--,r--;
        multiset<int> a;
        for(int i=0;i<l;i++)
        {
            a.insert(bags[i]);
        }
        for(int i=r+1;i<m;i++)
        {
            a.insert(bags[i]);
        }
        int ans=0;
        for(auto x:v)
        {
            int val = x.S;
            auto it = a.lower_bound(val);
            if(it == a.end())continue;
            a.erase(it);ans+=x.F;
        }
        cout<<ans<<endl;
    }

}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int tests;
   //cin>>tests;
   tests=1;
   for(int i=0;i<tests;i++)
   {
       solve();
   }
}

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

int main(){

  int n,m,Q;
  cin >> n >> m >> Q;
  vector<P> v(n);
  rep(i,n)cin >> v[i].first >> v[i].second;
  sort(ALL(v));
  vector<P> x(m);
  rep(i,m)cin >> x[i].first,x[i].second = i;
  sort(ALL(x));
  while(Q--){
    int l,r;cin >> l >> r;
    l--;r--;
    vector<ll> dp(m+1);
    rep(i,n){
      vector<ll> DP(m+1);
      for(int j = 1;j <= m;j++){
        if(l <= x[j-1].second && x[j-1].second <= r)continue;
        DP[j] = max(DP[j],dp[j]);
        if(v[i].first > x[j-1].first)continue;
        rep(k,j){
          DP[j] = max(DP[j],dp[k] + v[i].second);
        }
      }
      swap(DP,dp);
    }
    cout << *max_element(ALL(dp)) << "\n";
  }

  return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <cstring>
#include <utility>
#include <iostream>
#include <iomanip>
#include <list>
#include <queue>
#include <algorithm>
#include <cmath>
#include <set>
#include <unordered_set>
#include <bitset>
#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SUM(v) accumulate(ALL(v),0ll)
using ll = long long;
const ll INF=1000000;
using namespace std;
const ll mod=1000000007;
int main()
{
	ll n;
	cin>>n;
	ll x=1000;
	ll ans=0;

	while(true)
	{
		if(n<x)
		{
			break;
		}
		ans+=n-x+1;
		x*=1000;
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
long long gcd_vec(vector<long long> const &A) { // N個の要素に対する最大公約数
    int size = (int)A.size();
    long long ret = A[0];
    for (int i = 1; i < size; i++) {
        ret = gcd(ret, A[i]);
    }
    return ret;
}
long long lcm2(long long a, long long b) {
    long long d = gcd(a, b);
    return a / d * b;
}
long long lcm(const vector<long long> &vec) {
    long long l = vec[0];
    for (int i = 0; i < vec.size() - 1; i++) {
        l = lcm2(l, vec[i + 1]);
    }
    return l;
}
long long int mypow(long long int a,long long int b){
    long long int i=0,ans;
    for(i=0;i<b;i++)
    {
        if(i==0)
        {
            ans=a;
        }
        else
        {
            ans*=a;
        }
    }
    return ans;
}
struct UnionFind{
    int n;
    vector<int> par; // 親の番号
    vector<int> siz; // サイズを表している。

    // 初期化する。parは自身を指す（iotaは 0 ~ nまでの数字を順に入れていく）
    // size(siz) は最初はすべて１
    UnionFind(int n) : n(n){
        par.resize(n);
        iota(par.begin(),par.end(),0);
        siz.assign(n,1);
    }

    // 頂点の親を求める。
    // 再帰関数を使っており、経路圧縮もしている。
    int root(int x){
        // ここは親の処理。
        if (par[x] == x){
            return x;
        }

        //経路圧縮をしながら値を返す。
        // par[x] = root(par[x]);
        // return par[x];
        // と同じ意味。
        return par[x] = root(par[x]);
    }

    // unite :: a と bを同じグループに入れる。
    // もし初めから同じなら何もしない。
    void unite(int a,int b){
        int ra = root(a);
        int rb = root(b);

        if(ra == rb){
            return;
        }

        // サイズの大きい方にサイズの小さいほうを合成するので、swapしている。
        if (siz[ra] < siz[rb]){
            swap(ra,rb);
        }
        // サイズが大きい方に小さいのを合体
        // 小さいほうの親は大きい方の親になる。
        siz[ra] += siz[rb];
        par[rb] = ra;
    }

    //　同じグループかどうか判定するには、親が一緒かどうかをみたらよい
    bool same(int x,int y){
        return root(x) == root(y);
    }

    // 頂点が含まれるグループの頂点を求める。
    int get_size(int x){
        return siz[root(x)];
    }
};
    long long int facctorialMethod(int k){
    long long int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
#define PI 3.14159265359
int main()
{
	[[maybe_unused]]long long int i=0,j=0,a,b,w,g,c=0,c1=0,c2,c3,c4,n;
    [[maybe_unused]]double qw;
    string s,s1;
    cin >> n;
        c+=1000000-1000;
        c1=c;
        c+=2*(1000000000-1000000);
        c2=c;
        c+=3*(1000000000000-1000000000);
        c3=c;
        c+=4*(1000000000000000-1000000000000);
        c4=c;
    if(n<1000)
    {
        cout << "0";
    }
    else if(n<1000000)
    {
        cout << n-999;
    }
    else if(n<1000000000)
    {
        cout << c1+(n-999999)*2;
    }
    else if(n<1000000000000)
    {
        cout << c2+(n-999999999)*3;
    }
    else if(n<1000000000000000)
    {
        cout << c3+(n-999999999999)*4;
    }
    else
    {
        cout << c3+(n-999999999999-1)*4+5;
    }
    return 0;
}


#include "bits/stdc++.h"
#include <chrono>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)

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

using namespace __gnu_pbds;
using namespace std;
typedef tree< int,null_type, less<int> ,rb_tree_tag,tree_order_statistics_node_update > indexed_set;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef unordered_map<int,int> umi ;
typedef unordered_set<int> usi ;
typedef pair<int,int> pi;

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

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

bool ldequal(ld  a ,ld b){
    return abs(a-b) < 1e-9  ;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// shuffle(permutation.begin(), permutation.end(), rng); for permute
// uniform_int_distribution<int>(0, i)(rng) for rand

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int N =2e5+1 ;
ll a[N] ,b[N] ;
indexed_set s1 ;
set<pair<ll,ll>> s2 ;

bool tests=false ;
void gen(){} ;

void solve(){
   int n ;
   cin>>n ;
   REP(i,0,n){
    cin>>a[i] ;
    s1.insert(i) ;
    s2.insert({a[i]+i,i}) ;
   }
   REP(i,0,n) cin>>b[i] ;
   ll res=0 ;
   REP(i,0,n){
      ll val =b[i]+i ;
      auto l = s2.lower_bound({val,0}) ;
      if(l==s2.end()){
         cout<<-1 ;
         return ;
      }
      //pair<ll,ll> temp = MP((*l).S ,(*l).F) ;
      auto r =s1.order_of_key((*l).S)  ;
      debug(val,*l ,r ) ;
      res+=r;
      s1.erase((*l).S) ;
      s2.erase(l) ;

   }
   cout<<res ;

}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    gen() ;
    long long test =1 ;
    if(tests) cin>>test ;
    REP(i,1,test+1){
        debug(i) ;
        //cout<<"Case #"<<i<<": " ;

        solve() ;
        cout<<"\n" ;
    }
    return 0 ;
}

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define repr(i, n, s) for (int i = (int)n; (int)s < i; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
/* 1次元ベクトルをスペースでつなぎ、改行をつけて出力 vi, vl, list<int>, list<ll>に対応  */
template<class T> void print_elements(T a) {string str = ""; for (auto itr = a.begin(); itr != a.end(); ++itr) \
        {str += to_string(*itr) + ' ';} str.pop_back(); cout << str << endl;}

const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const long long MOD = 1000000009;
const double PI = acos(-1);

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

    set<ll> ans;

    for (ll i = 1; i <= (ll)sqrt(N); i++) {
        if (N % i == 0) {
            ans.insert(i);
            ans.insert(N / i);
        }
    }

    for (auto x: ans) {
        cout << x << '\n';
    }
}


#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main(){
double n, D, H;
cin >> n >> D >> H;
vector<double> d(n), h(n);
for(int i = 0; i < n; i++) cin >> d[i] >> h[i];

vector<double> x(n);
double ans = 0.0;
for(int i = 0; i < n; i++){
  x[i] = H - D * (H - h[i]) / (D - d[i]);
  ans = max(ans, x[i]);
}

if(ans == 0) cout << "0.0" << endl;
else cout << ans << endl;
return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
const double pi = 2.0 * asin(1.0);
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
int main()
{
    double n, d, h;
    cin >> n >> d >> h;
    vector<double> a(n), b(n);
    rep(i, n)
    {
        cin >> a[i] >> b[i];
    }
    double ans = 0;
    rep(i, n)
    {
        double k = h - d / (d - a[i]) * (h - b[i]);
        ans = max(ans, k);
    }

    cout << fixed << setprecision(10) << ans << endl;
}


//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> void fin(T a) { cout << a << '\n'; exit(0); }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    INT(n, m);
    vvp G(n);
    vi a(m), b(m);
    rep(i, m) {
        scan(a[i], b[i]);
        a[i]--;
        b[i]--;
    }
    vi c(n);
    cin >> c;
    vi ans(m, -1);
    int cnt = 0;
    auto direct = [&](int id, int from, int to) {
        if (a[id] == from) ans[id] = 0;
        else ans[id] = 1;
    };
    rep(i, m) {
        if (c[a[i]] > c[b[i]]) direct(i, a[i], b[i]);
        else if (c[a[i]] < c[b[i]]) direct(i, b[i], a[i]);
        else {
            G[a[i]].eb(b[i], i);
            G[b[i]].eb(a[i], i);
            cnt++;
        }
    }
    vb seen(n);
    auto dfs = [&](auto &self, int u, int p) -> void {
        seen[u] = true;
        for (auto[v, id] : G[u]) {
            if (v == p) continue;
            if (ans[id] < 0) direct(id, u, v);
            if (!seen[v]) {
                self(self, v, u);
            }
        }
    };
    rep(i, n) {
        if (seen[i]) continue;
        dfs(dfs, i, -1);
    }
    rep(i, m) {
        assert(ans[i] >= 0);
        cout << (ans[i] ? "<-" : "->") << endl;
    }
}

#include <bits/stdc++.h>
#define li long int
#define lli long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define lb lower_bound
#define ub upper_bound
#define BS binary_search
#define pll pair < lli, lli >
#define pii pair < int, int>
#define vi vector < int >
#define vvi vector < vector < int > >
#define vlli vector < lli >
#define all(x) x.begin(), x.end()
#define vvlli vector < vector < lli > >
#define vp vector < pll >
#define vvp vector< vector< pll> >
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<lli  , null_type, less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define fill(a,n) for(lli iiii=0;iiii<n;iiii++)	cin>>a[iiii];
#define mpii map<int, int>
# define precision(x) cout << fixed << setprecision(x)
#define REP(i, a, b) for (int i=a; i<=b; i++)
using namespace __gnu_pbds;
lli mod=1e9+7;
using namespace std;

int main()
{
    fastio;
	string s;
	cin>>s;
	int i,n,f=0;
	for(i=0;i<s.length();i++)
	{
		if(i%2==0)
		{
			if(s[i]>='a' && s[i]<='z') continue;
			else	{f=1;	break;}
		}
		else
		{
		if(s[i]>='A' && s[i]<='Z') continue;
			else	{f=1;	break;}
		}
	}
	if(f==0)	cout<<"Yes\n";
	else	cout<<"No\n";
}


//GOD PLEASE HELP ME ,GOD PLEASE HELP ME , GOD PLEASE HELP ME
//Name Rishiraj Kalita
// sc id : 1912041

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)    scanf("%d",&x)
#define sl(x)    scanf("%lld",&x)
#define ss(s)    scanf("%s",s)
#define pi(x)    printf("%d\n",x)
#define pl(x)    printf("%lld\n",x)
#define ps(s)    printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y <<","<< #z << "=" << z << endl
#define debv(v) for(auto x:v) cout<<x<<" "
#define debg(g,n) for(int i=1;i<=n;i++){cout<<i<<"--->";for(auto x:g[i]){cout<<x<<" ";}cout<<"\n";}
#define clrg(g,n) for(int i=0;i<=n;i++) g[i].clear();
#define pb push_back
#define mp make_pair
#define MinHeap priority_queue <ll, vector<ll>, greater<ll> >
#define e endl
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define inf 9000000000000000000
typedef pair<int, int>    pii;
typedef pair<ll, ll>    pl;
typedef vector<int>        vi;
typedef vector<ll>        vl;
typedef vector<pii>        vpii;
typedef vector<pl>        vpl;
typedef vector<vi>        vvi;
typedef vector<vl>        vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve() {
    ll i, j, n,k,data,m,f=1;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(d*c-b<=0)
    {
        cout<<"-1\n";
        return;
    }
    data=d*c-b;
    if(a%(data)==0)
    {
        cout<<a/data;
    }
    else{
        cout<<a/data+1;
    }

  }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
   // u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}

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

void solve(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll temp=(a);
    ll temp1=(d*c-b);
    if(temp1<=0)
          cout<<-1<<endl;
    else{
    if(temp%temp1==0)
    cout<<temp/temp1<<endl;
    else
        cout<<temp/temp1+1<<endl;
    }

}
int main(){
  ll t=1;
  //cin>>t;
  while(t--){
    solve();
  }
}


#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include<cassert>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
using namespace std;
using ll =long long;
#define rep(i,n)for(ll i=0;i<(n);i++)
const int mod = 1000000007;
const ll inf = 1e18 + 1;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)

///*�R���r�l�[�V����*/
//
///*Union Find*/
//#define MAX_N 200000
//#define MAX_M 200000
//vector<ll>par(MAX_N);
//vector<ll>ran(MAX_N);
//void init(ll N) {
//	rep(i, N) {
//		par[i] = i;
//		ran[i] = 0;
//	}
//}
//ll find(ll x) {
//	if (par[x] == x) {
//		return x;
//	}
//	else {
//		return par[x] = find(par[x]);
//	}
//}
////x��y�̑�����W���𕹍�
//void unite(ll x,ll y) {
//	x = find(x);
//	y = find(y);
//	if (x == y)return;
//	if (ran[x] < ran[y]) {
//		par[x] = y;
//
//	}
//	else {
//		par[y] = x;
//		if (ran[x] == ran[y])ran[x]++;
//	}
//}
//bool same(ll x, ll y) {
//	return find(x) == find(y);
//}
///*Union Find*
bool isPrime(int x) {
	int i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
	return 1;
}
int digsum(int n) {
	int res = 0;
	while (n > 0) {
		res += n % 10;
		n /= 10;
	}
	return res;
}
ll p(int x, int y) {
	ll v = 1;
	rep(i, y) {
		v *= x;
	}
	return v;
}
long long MOD = 1e9 + 7;

long long modPow(long long x, long long a) {
	if (a == 1) return x;
	if (a % 2) return (x * modPow(x, a - 1));
	long long t = modPow(x, a / 2);
	return (t * t);
}

long long modInv(long long x) {
	return modPow(x, MOD - 2);
}

long long modPerm(long long n, long long k) {
	long long ret = 1;
	for (long long i = 0; i < k; i++) {
		ret = (ret * (n - i));
	}
	return ret;
}

long long modComb(long long n, long long k) {
	long long a, b;
	a = modPerm(n, k);
	b = modPerm(k, k);
	return (a * modInv(b));
}
struct memo{
	ll time;
	ll money;
};
using vv =vector<vector<ll>>;
int N, X, cnt, a[10009];
int main() {
	int N;
	ll C;
	cin >> N >> C;
	vector<pair<ll,ll>>a(N), b(N);
	vector<pair<ll,ll>>A(2*N);
	vector<ll>c(N);
	map<ll,ll>m;
	rep(i, N) {
		cin >> a[i].first >> b[i].first >> c[i];
		b[i].first++;
		a[i].second = c[i];
		b[i].second = -c[i];
	}
	for (ll i = 0; i < N;i++) {
		A[2*i]=a[i];
		A[2 * i + 1] = b[i];
	}
	ll time = 0;
	sort(A.begin(), A.end());
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll money = 0;
	ll ans=0;
	m[0] = 0;
	rep(i,2*N){
		if (money <= C) {
			ans += (A[i].first-time) * money;
		}
		else {
			ans += (A[i].first - time) * C;
		}
		time = A[i].first;
		money += A[i].second;
	}
	cout << ans;
}

#include <bits/stdc++.h>

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

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

int main() {
  int n, d;
  cin >> n >> d;
  map<int, ll> mp;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    mp[a] += c;
    mp[b + 1] -= c;
  }
  ll ans = 0;
  ll s = 0;
  int pre = 0;
  for (auto p : mp) {
    ans += min<ll>(d, s) * (p.first - pre);
    s += p.second;
    pre = p.first;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main()
{
    ll H, W;
    ll start_x, start_y, goal_x, goal_y;
    cin >> H >> W;

    vector<vector<char>> map(H, vector<char>(W));
    vector<int> dh = {1, 0, -1, 0};
    vector<int> dw = {0, 1, 0, -1};
    vector<vector<bool>> ready(H, vector<bool>(W, false));
    vector<vector<ll>> answer(H, vector<ll>(W, 0));
    vector<vector<pair<ll, ll>>> warp(30);
    vector<bool> alpha(30, false);
    queue<pair<ll, ll>> Q;

    rep(i, H)
    {
        rep(j, W)
        {
            char input;
            cin >> input;
            if ('a' <= input && 'z' >= input)
            {
                warp[input - 'a'].push_back(make_pair(i, j));
            }
            else if (input == 'S')
            {
                start_y = i;
                start_x = j;
            }
            else if (input == 'G')
            {
                goal_y = i;
                goal_x = j;
            }
            map[i][j] = input;
        }
    }
    Q.push({start_y, start_x});
    ready[start_y][start_x] = true;

    while (!Q.empty())
    {
        ll x, y;
        y = Q.front().first;
        x = Q.front().second;
        Q.pop();
        //ワープ判定
        if (map[y][x] <= 'z' && 'a' <= map[y][x])
        {
            int f = map[y][x] - 'a';
            if (!alpha[f])
            {
                alpha[f] = true;
                rep(i, warp[f].size())
                {
                    auto k = warp[f][i];
                    if (!ready[k.first][k.second])
                    {
                        ready[k.first][k.second] = true;
                        answer[k.first][k.second] = answer[y][x] + 1;
                        Q.push(k);
                    }
                }
            }
        }
        //幅探索
        rep(k, 4)
        {
            int th, tw;
            th = y + dh[k];
            tw = x + dw[k];

            if (th < 0 || th >= H || tw < 0 || tw >= W)
                continue;
            if (map[th][tw] == '#' || ready[th][tw])
                continue;
            ready[th][tw] = true;
            answer[th][tw] = answer[y][x] + 1;
            Q.push({th, tw});
        }
        //debug
        // rep(i, H)
        // {
        //     rep(j, W)
        //     {
        //         cout << answer[i][j] << ',';
        //     }
        //     cout << endl;
        // }
        // cout << endl;
    }
    //debug
    // cout << "answer" << endl;
    // rep(i, H)
    // {
    //     rep(j, W)
    //     {
    //         cout << answer[i][j] << ',';
    //     }
    //     cout << endl;
    // }
    if (answer[goal_y][goal_x] == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << answer[goal_y][goal_x] << endl;
    }

    return 0;
}

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

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<int> > road(H*W);
  vector<vector<int> > port(26);
  vector<vector<char> > grid(H, vector<char>(W,'#'));
  int S, G;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> grid.at(i).at(j);
      if (grid.at(i).at(j) == 'S')
        S = i*W + j;
      if (grid.at(i).at(j) == 'G')
        G = i*W + j;
      if (grid.at(i).at(j) - 'a' >= 0 && grid.at(i).at(j) - 'a' < 26)
        port.at(grid.at(i).at(j) - 'a').push_back(i*W+j);
    }
  }

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (grid.at(i).at(j) == '#') continue;
      if (i != 0 && grid.at(i-1).at(j) != '#') road.at(i*W+j).push_back((i-1)*W+j);
      if (i != H-1 && grid.at(i+1).at(j) != '#') road.at(i*W+j).push_back((i+1)*W+j);
      if (j != 0 && grid.at(i).at(j-1) != '#') road.at(i*W+j).push_back(i*W+j-1);
      if (j != W-1 && grid.at(i).at(j+1) != '#') road.at(i*W+j).push_back(i*W+j+1);
    }
  }
  queue<int> que;
  vector<vector<int> > city(H, vector<int>(W,-1));
  vector<int> port_check(26, 0);
  que.push(S);
  city.at(S/W).at(S%W) = 0;
  int now;
  while(!que.empty())
  {
    now = que.front();
    que.pop();
    for (auto x : road.at(now))
    {
      if (city.at(x/W).at(x%W) >= 0) continue;
      city.at(x/W).at(x%W) = city.at(now/W).at(now%W) + 1;
      que.push(x);
    }
    if (grid.at(now/W).at(now%W) - 'a' >= 0 && grid.at(now/W).at(now%W) - 'a' < 26)
    {
      if (port_check.at(grid.at(now/W).at(now%W) - 'a') == 0)
      {
        for (auto y : port.at(grid.at(now/W).at(now%W) - 'a'))
        {
          if (city.at(y/W).at(y%W) >= 0) continue;
          city.at(y/W).at(y%W) = city.at(now/W).at(now%W) + 1;
          que.push(y);
        }
        port_check.at(grid.at(now/W).at(now%W) - 'a') = 1;
      }
    }
  }
  cout << city.at(G/W).at(G%W) << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> children(n);
    vector<int> par(n);
    par[0] = -1;

    for (int i = 1; i < n; i++){
        int p;
        cin >> p;
        p--;
        par[i] = p;
        children[p].push_back(i);
    }

    auto dfs = [&](auto v, auto dfs) -> array<int, 2>{
        vector<array<int, 2>> A;
        for (auto &c : children[v]){
            A.push_back(dfs(c, dfs));
        }

        sort(A.begin(), A.end());
        array<int, 2> res = {1, 0};
        for (const auto &[s, p]: A){
            if (s <= 0 and p == 0)
                res[0] += s;
        }

        int b = 0;
        for (const auto &[s, p]: A){
            if (p == 1){
                if (b == 0)
                    res[0] += s;
                else
                    res[0] -= s;
                b ^= 1;
            }
        }

        for (const auto &[s, p]: A){
            if (s > 0 and p == 0){
                if (b == 0)
                    res[0] += s;
                else
                    res[0] -= s;
            }
        }

        b ^= 1;
        res[1] = b;
        return res;
    };

    auto res = dfs(0, dfs);
    cout << (res[0] + n) / 2 << endl;
}

/*input
20
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("O2","unroll-loops","no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<ld,ld>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=1e18+1;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-3;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
inline ll mult(ll a,ll b){
    if(a>=MOD) a%=MOD;
    if(b>=MOD) b%=MOD;
    return (a*b)%MOD;
}
inline ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const int maxn=1e4+5;
const int maxlg=__lg(maxn)+2;
int dp[105][maxn];
ll fac[maxn];
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    int s=0;
    fac[0]=1;
    REP1(i,n) fac[i]=mult(fac[i-1],i);
    dp[0][0]=1;
    REP(i,n){
        int w;
        cin>>w;
        s+=w;
        for(int z=n;z>=1;z--){
            for(int j=maxn-1;j>=w;j--){
                dp[z][j]+=dp[z-1][j-w];
                dp[z][j]%=MOD;
            }
        }
    }
    if(s%2) cout<<0;
    else{
        ll ans=0;
        REP1(i,n){
            ans+=mult(mult(fac[i],fac[n-i]),dp[i][s/2]);
            ans%=MOD;
        }
        cout<<ans;
    }
}


#line 1 "/Users/haruki/kyopro/library/template.cpp"
// code by lynmisakura. wish to be accepted!

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define rep(i,N) for(int i = 0;i < N;i++)
#define rng(i,a,b) for(int i = a;i < b;i++)

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

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

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
    cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
    return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
    cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
    return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
    cout << "{" << p.first << "," << p.second << "}" << '\n';
    return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
    for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
    cin >> p.first >> p.second; return in;
}/////////////////////////////////////////////////////////////////////
///////////////// DON'T TOUCH BEFORE THIS LINE //////////////////////
/////////////////////////////////////////////////////////////////////

#line 2 "combined.cpp"

ll INF = (1LL << 55);
ll low = -INF,high = INF;

ll add = 0;
ll val = 0;
bool fix = false;

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

  int n;cin >> n;
  rep(i,n){
    ll a;cin >> a;
    int t;cin >> t;
    if(t == 1){
      add += a;
    }else if(t == 2){
      a -= add;
      if(fix){
        val = max(val,a);
      }else{
        if(a >= high){
          fix = 1;
          val = a;
        }else{
          low = max(low , a);
        }
      }
    }else{
      a -= add;
      if(fix){
        val = min(val,a);
      }else{
        if(a <= low){
          fix = 1;
          val = a;
        }else{
          high = min(high , a);
        }
      }
    }
  }

  low += add;
  high += add;
  int q;cin >> q;
  rep(_,q){
    ll x;cin >> x;
    if(fix){
      cout << val + add << '\n';
    }else{
      x += add;
      if(x <= low){
        cout << low << '\n';
      }else if(x >= high){
        cout << high << '\n';
      }else{
        cout << x << '\n';
      }
    }
  }

}

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

long long f(vector<long long>& a, vector<long long>& t, const long long& X0){
    long long res = X0;
    for(int i = 1; i < (int)a.size(); ++i){
        if(t[i] == 1){
            res += a[i];
        }else if(t[i] == 2){
            res = max(a[i], res);
        }else{
            res = min(a[i], res);
        }
    }
    return res;
}

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

    const long long MIN_ELEM = -1e9;
    const long long MAX_ELEM =  1e9;

    long long N;
    cin >> N;

    vector<long long> a(N + 1);
    vector<long long> t(N + 1);
    for(int i = 1; i <= N; ++i){
        cin >> a[i] >> t[i];
    }

    // X0: identity element for 'f(..)'
    // X0 = 0 for '+' operation and X0 = a[1] for 'min' and 'max' operations
    const long long X0 = (t[1] == 1 ? 0 : a[1]);
    long long fInitialValue = f(a, t, X0);
    long long fMinValue = f(a, t, MIN_ELEM);
    long long fMaxValue = f(a, t, MAX_ELEM);

    // Compute left displacement
    long long l = 0;
    long long r = 2 * MAX_ELEM + 5;
    while(l != r){
        long long mid = (l + r) / 2;
        if(f(a, t, X0 - mid) == fInitialValue){
            l = mid + 1;
        }else{
            r = mid;
        }
    }
    long long leftDispl = r - 1;

    // Compute right displacement
    l = 0;
    r = 2 * MAX_ELEM + 5;
    while(l != r){
        long long mid = (l + r) / 2;
        if(f(a, t, X0 + mid) == fInitialValue){
            l = mid + 1;
        }else{
            r = mid;
        }
    }
    long long rightDispl = r - 1;

    // Answer each query
    long long Q;
    cin >> Q;

    vector<long long> x(Q + 1);
    for(int i = 1; i <= Q; ++i){
        cin >> x[i];
    }

    for(int i = 1; i <= Q; ++i){
        long long answer = fInitialValue;
        if(x[i] < X0 && X0 - x[i] >= leftDispl){
            answer = max(fInitialValue - (X0 - x[i]) + leftDispl, fMinValue);
        }else if(x[i] > X0 && x[i] - X0 >= rightDispl){
            answer = min(fInitialValue + (x[i] - X0) - rightDispl, fMaxValue);
        }
        cout << answer << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORALL(i, n) for(int i = 0; i < n; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin, a.end()
#define mp make_pair
#define pb push_back
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 1e5;
const int mod = 1e9 + 7;
const ll inf = 1e18;
const double pi = 3.141592653589793;
const int dr[4] = {-1,0,1,0}, dc[4] = {0,1,0,-1};

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

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

	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}

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

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