#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define debug(x) cerr << #x << " = "<< x << "\n"
#define shaman ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
constexpr int inf=1e18,N=400010;
vector<int> v[N];
bool vis[N],ok;
int DFS(int now,int pre){
    int tmp=1;
    vis[now]=1;
    for(auto x:v[now]){
        if(x==pre) continue;
        if(vis[x]) {
            ok=true;
            continue;
        }
        tmp+=DFS(x,now);
    }
    return tmp;
}
signed main(){shaman
    int n,a,b;
    cin >> n;
    set<pii> st,st2;
    set<int> num;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        if(a>b) swap(a,b);
        if(st.find({a,b})!=st.end()) continue;
        st.insert({a,b});
        num.insert(a);
        num.insert(b);
        v[a].pb(b);
        v[b].pb(a);
    }
    int ans=0;
    for(auto x:num){
        ok=false;
        if(vis[x]) continue;
        ans+=DFS(x,-1);
        if(!ok) ans--;
    }
    cout << ans << "\n";
}

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout << #x << ": " << x << endl
#define clr(x,v) memset(x, v, sizeof(x))
#define dblout(x) cout << setprecision(x) << fixed;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 100 + 5;

/*
    Consider a fixed diameter D
    This circle must pass through all the gaps between some points to start from left and end up on the right
    when can it not pass through?
    Let us join all points with a line which have distance < D
    Also consider points (i, 100) and (i, -100) as well
    When the top boundary (y = 100) and bottom boundary (y = -100)
    are connected by some sequence of lines something like this
    --------------------------------
                    |
                   /
                  /
                 /
                |
    ---------------------------------
    Then no circle can pass through from the left to the right
    We can use DSU/BFS/DFS anything really to check if we can go from some (i, 100) to (j, -100)
    Used DSU here
*/

int dcmp(double a, double b)
{
    return  (fabs(a - b) < eps) ? 0 : (a < b ? -1 : +1);
}

double length(pi a, pi b)
{
    return sqrt((a.ff - b.ff) * 1.0 * (a.ff - b.ff) + (a.ss - b.ss) * 1.0 * (a.ss - b.ss));
}

int parent[10 * MAXN], sz[10 * MAXN];

void make_set(int n)
{
    iota(parent, parent + n, 0);
    fill(sz, sz + n, 1);
}

int find_set(int v)
{
    if(v == parent[v])
        return v;
    else
        return parent[v] = find_set(parent[v]);
}

bool union_set(int a, int b)
{
    a = find_set(a), b = find_set(b);
    if(sz[a] < sz[b])
        swap(a, b);
    if(a != b)
        parent[b] = a, sz[a] += sz[b];
    return a != b;
}

void cp()
{
    int n;
    cin >> n;
    vector<pi> arr;
    for(int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        arr.pb({x, y});
    }
    // [n, n + 200]
    for(int i = -100; i <= 100; i++)
        arr.pb({i, 100});
    // [n + 201, n + 401]
    for(int i = -100; i <= 100; i++)
        arr.pb({i, -100});

    double lo = 0, hi = 200;
    for(int itr = 0; itr < 50; itr++)
    {
        double mid = (lo + hi) / 2;
        make_set(sz(arr));
        for(int i = 0; i < sz(arr); i++)
            for(int j = i + 1; j < sz(arr); j++)
                if(dcmp(length(arr[i], arr[j]), mid) < 0)
                    union_set(i, j);

        bool ok = true;
        vector<bool> par(sz(arr));
        for(int i = n; i <= n + 200; i++)
            par[find_set(i)] = 1;
        for(int i = n + 201; i <= n + 401; i++)
            ok &= !par[find_set(i)];

        if(ok)
            lo = mid;
        else
            hi = mid;
    }

    dblout(20);
    cout << lo / 2 << endl;
}

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


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

typedef long long LL;
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int N = 4e5 + 10;
const int mod = 1e9 + 7;

bool vis[N], flag;
vector<int> e[N];
int cnt1 = 0, cnt2, idx = 0;
int a[N], b[N], c[N];

int find(int x) {
    return lower_bound(c + 1, c + 1 + idx, x) - c;
}

void dfs(int u) {
    vis[u] = true;
    cnt1++;
    for(auto v : e[u]) {
        cnt2++;
        if(vis[v]) continue;
        dfs(v);
    }
}

void solve() {
    int n;
    scanf("%d", &n);
    idx = 0;
    for(int i = 1; i <= n; i++) {
        scanf("%d%d", &a[i], &b[i]);
        c[++idx] = a[i];
        c[++idx] = b[i];
    }
    sort(c + 1, c + 1 + idx);
    idx = unique(c + 1, c + 1 + idx) - c - 1;
    for(int i = 1; i <= n; i++) {
        int u = find(a[i]), v = find(b[i]);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int res = 0;
    for(int i = 1; i <= idx; i++) {
        cnt1 = cnt2 = 0;
        if(!vis[i]) {
            dfs(i);
            cnt2 /= 2;
            res += min(cnt1, cnt2);
        }
    }
    printf("%d\n", res);
}

int main() {
    // freopen("in.txt", "r", stdin);
    // int t; cin >> t; while(t--)
    solve();
    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define print(x) cout << #x <<" = " << x <<"\n"
#define pprint(x) cout << #x <<" = (" << x.first <<", " << x.second <<")\n"
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MAXN 1000005
#define MOD 1000000007
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
int n, cur;
vector<int> a[2], match, vis;
bool dfs(int x) {
//	print(x);
	rep(i, 0, 1) {
		int aa = a[i][x];
//		print(aa), print(match[aa]);
		if(vis[aa] == cur) continue;
		vis[aa] = cur;
		if(match[aa] == -1 || dfs(match[aa])) {
			match[aa] = x;
			return true;
		}
	}
	return false;
}
int matching() {
	int ans = 0; cur = 0;
	match.assign(MAXN, -1);
	vis.assign(MAXN, 0);
	rep(i, 1, n) {
		cur ++, ans += dfs(i);
	}
	return ans;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a[0].assign(n + 1, 0);
	a[1].assign(n + 1, 0);
	rep(i, 1, n) cin >> a[0][i] >> a[1][i];
//	cout <<"yes\n";
	cout << matching() <<"\n";
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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

const ll mod = 1e9 + 7; //998244353;

ll modpow(ll a,ll b){
    if(b == 0){
        return 1;
    }
    if(b%2 == 0){
        ll tmp = modpow(a,b/2);
        return tmp*tmp%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }

}

struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0) : d(n,-1){}
    int find(int x) {
        if(d[x] < 0)return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int y){
        x = find(x);y = find(y);
        if(x == y)return false;
        if(d[x] > d[y])swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

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

    int size(int x){
        return -d[find(x)];
    }
    int operator[](int x){return find(x);}
    int operator()(int x){return size(x);}
};

double dp[105][105][105];

int main(void){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    dp[a][b][c] =1;
    irep(i,a,101){
        irep(j,b,101){
            irep(k,c,101){

                if(i-a > 0 && j != 100 && k != 100)dp[i][j][k] += (i-1)*dp[i-1][j][k]/(double)(i+j+k-1);
                if(j-b > 0 && i != 100 && k != 100) dp[i][j][k] += (j-1)*dp[i][j-1][k]/(double)(i+j+k-1);
                if(k-c > 0 && i != 100 && j != 100)dp[i][j][k] += (k-1)*dp[i][j][k-1]/(double)(i+j+k-1);
            }
        }
    }
    double ans = 0;
    irep(i,a,100){
        irep(j,b,100){
            double cnt = i-a + j-b+100-c;
            ans +=  cnt*dp[i][j][100];

        }
    }
    //cerr << ans << endl;
    irep(i,b,100){
        irep(j,c,100){
            double cnt = i-b + j-c+100-a;
            //cerr << cnt << endl;
            ans +=  cnt*dp[100][i][j];
        }
    }
    //cerr << ans << endl;
    irep(i,c,100){
        irep(j,a,100){
            double cnt = i-c + j-a+100-b;
            ans +=  cnt*dp[j][100][i];
            //cerr << ans << endl;

        }
    }
    //cerr << dp[a][b][c+1] << endl;

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

    return 0;

}

#include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;

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

    int a,b,c; cin>>a>>b>>c;
    cout<<(a*a+b*b<c*c ? "Yes" : "No")<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll  = long long int;
using pii = pair<ll, ll>;
using vi = vector<ll>;
template <typename T> void out(const T& t) {cout << t << '\n';}
vi vin(int n) {vi res(n); for(auto&i:res)cin>>i; return res;}
ll in() {ll x; cin>>x; return x;}

const ll MOD = 998244353;
const int N = 2e5 + 5;
ll two[N];
ll twoinv = 499122177;

ll mmod(ll x, ll y) {
    if (x >= 0LL)
        return x % y;
    else
        return (y - (-x) % y) % y;
}
int lp[N+1], cnt[N+1][18];
ll facts[N+1], invfacts[N+1];
vector<int> pr;

ll binpow(ll x, ll n) {
    ll ans=1; ll cur=x;
    for (;n;n>>=1) {
        if (n&1) ans=ans*cur%MOD;
        cur=cur*cur%MOD;
    }
    return ans;
}

ll C(ll n, ll k) {
    if (n < 0 || k < 0) return 0;
    if (k > n) return 0;
    return facts[n] * invfacts[k] % MOD * invfacts[n - k] % MOD;
}

void solve() {
    facts[0]=1;
    for (int i = 1; i <= N; ++i) facts[i] = i * facts[i - 1] % MOD;
    for (int i = 0; i <= N; ++i) invfacts[i] = binpow(facts[i], MOD-2);
    for (int i = 0; i <= N; ++i) cnt[i][0]=1;
    for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j) {
            lp[i * pr[j]] = pr[j];
        }
    }
    for (int i = 2; i <= N; ++i) {
        cnt[i][1] = 1;
        for (int j = 2; j * j <= i; ++j) {
            if (i % j == 0) {
                for (int k = 1; k <= 17; ++k) {
                    cnt[i][k] = (cnt[i][k] + cnt[i / j][k - 1]) % MOD;
                    if (i / j != j) cnt[i][k] = (cnt[i][k] + cnt[j][k - 1]) % MOD;
                }
            }
        }
    }
    ll ans = 0;
    int n = in(), m = in();
    for (int i = 1; i <= m; ++i) {
        ans;
        for (int j = 0; j <= 17; ++j) {
            ans = (ans + cnt[i][j]%MOD * C(n - 1, j)) % MOD;
        }
    }
    out(ans);
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int t=1;;while(t--)solve();return 0;
}

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

const long mod=998244353;
const long Beneath=300000;

vector<long> fac(Beneath+1),ifac(Beneath+1);

long mpow(long x,long n){
  long ans=1;
  while(n!=0){
    if(n&1) ans=ans*x%mod;
    x=x*x%mod;
    n= n>>1;
  }
  return ans;
};

long comb(long a,long b){
  if(a==0 && b==0) return 1;
  if(a<b || a<0) return 0;
  long tmp=ifac.at(a-b)*ifac.at(b)%mod;
  return tmp*fac.at(a)%mod;
};

long perm(long a,long b){
  if(a==0 && b==0) return 1;
  if(a<b || a<0) return 0;
  return fac.at(a)*ifac.at(a-b)%mod;
};

void fermat(){
  fac.at(0)=1;ifac.at(0)=1;
  for(long i=1;i<Beneath+1;i++){
    fac.at(i)=fac.at(i-1)*i%mod;
    ifac.at(i)=ifac.at(i-1)*mpow(i,mod-2)%mod;
  }
};

vector<int> Eratosthenes(int N){
  vector<bool> prime(N+1,true);
  vector<int> P;
  for(int i=2;i<=N;i++){
    if(prime.at(i)){
      for(int j=i*2;j<=N;j+=i) prime.at(j)=false;
      P.push_back(i);//素数ならif内でPに追加され、vector:prime内の倍数はfalseとなる
    }
  }
  return P;
}

int main(){
  int N,M;cin>>N>>M;
  fermat();
  vector<int> E=Eratosthenes(500);
  queue<int> q;
  vector<long> X(M+1,1);
  int k,cnt;long ret;
  for(int i=2;i<=M;i++){
    k=i;
    for(int e:E){
      if(k%e) continue;
      cnt=0;
      while(k%e==0){
        cnt++;
        k/=e;
      }
      q.push(cnt);
      if(k==1) break;
    }
    if(k!=1) q.push(1);
    ret=1;
    while(!q.empty()){
      k=q.front();q.pop();
      ret*=comb(N+k-1,k);
      ret%=mod;
    }
    X[i]=X[i-1]+ret;
    X[i]%=mod;
    //cout<<X[i]<<endl;
  }
  cout<<X[M]<<endl;
}


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

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);

    // while(X<Y){
    //     ll kako=X*A;
    //     ll atco=X+B;
    //     if(kako>atco){
    //         X=atco;
    //     }else{
    //         X=kako;
    //     }
    //     if(X>=Y) break;
    //     cnt++;
    // }

    ld border = B*1.0/A;
    ll kakocnt=0;
    ll ex = X;
    while(border>ex){
        if(ex >= Y / A) break;
        ex*=A;
        kakocnt++;
    }
    // out(ex);
    // out(kakocnt);
    ll atccnt=0;
    if((Y-ex)>0){
        atccnt=(Y-ex-1)/B;
        // if((Y-ex)%B==0) atccnt--;
    }

    cout << kakocnt + atccnt << endl;

    return 0;
}

#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i,j,k) for(int i=(j);i<=(k);i++)
#define DF(i,j,k) for(int i=(j);i>=(k);i--)
#define P pair
#define dui priority_queue
using namespace std;
template<typename T>inline void read(T &n){
    T w=1;n=0;char ch=getchar();
    while(!isdigit(ch)&&ch!=EOF){if(ch=='-')w=-1;ch=getchar();}
    while(isdigit(ch)&&ch!=EOF){n=(n<<1)+(n<<3)+(ch^48);ch=getchar();}
    n*=w;
}
template<typename T>inline void write(T x){
    ull y=0;
    T l=0;
    if(x<0){x=-x;putchar('-');}
    if(!x){putchar(48);return;}
    while(x){y=y*10+x%10;x/=10;l++;}
    while(l){putchar(y%10+48);y/=10;l--;}
}
template<typename T>inline void writeln(T x){
    write(x);
    puts("");
}
template<typename T>inline void writes(T x){
    write(x);
    putchar(' ');
}
template<typename T>inline void checkmax(T &a,T b){a=a>b?a:b;}
template<typename T>inline void checkmin(T &a,T b){a=a<b?a:b;}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	LL x,y,a,b,ans=0;read(x);read(y);read(a);read(b);
	while(x*a<x+b&&x*a<y){
		if(x*1.0>y/a*1.0)break;
		ans++;
		x*=a;
	}
	ans+=(y-x)/b-((y-x)%b==0);
	writeln(ans);
    return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii > vii;
typedef vector<vector<ll> > vvi;
typedef vector<vvi > vvvi;
typedef vector<vector<pair<ll, ll> > > vvii;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,s,e) for(ll i=(s);i<(e);++i)
#define repr(i,s,e) for(ll i=(e);i>(s);--i)
#define io ios::sync_with_stdio(false)
#define prv(v)                                                             \
	do                                                                      \
	{                                                                       \
		for(auto it = (v).begin(); it != (v).end(); ++it) cerr << *it << " "; \
		cerr << endl; \
	} while (0);
#define prm(m)                                           \
	do                                                     \
	{                                                      \
		for (auto it = (m).begin(); it != (m).end(); ++it)   \
			cerr << it->first << " -> " << it->second << endl; \
	} while (0);

const ll MOD = 1e9+7;
const ll INF = 100;
const ll TE3 = 1005;
const ll TE5 = 300005;
const string YN[2] = {"NO", "YES"};

using namespace std;

ll n, m;
ll f(vi &dp,vi &s,ll x,ll m) {
	if(binary_search(s.begin(), s.end(), x)) {
		return 1;
	}
	if(dp[x]!=-1) {
		return dp[x];
	}
	ll y = x;
	ll ans = INF;
	ll q = s.size();
	for (ll i = m-1; i >= 0;--i) {
		if((s[i]&y)==y) {
			ans = min(ans, 1 + f(dp, s, y-s[i], i-1));
		}
	}
	return dp[x] = ans;
}

int main()
{
	io;
	cin >> n >> m;
	vvi a(n, vi(n, 0));
	rep(i, 0, m)
	{
		ll x, y;
		cin >> x >> y;
		--x;
		--y;
		a[x][y] = 1;
		a[y][x] = 1;
	}
	ll z = 1ll << n;
	vi dp(z,n);
	rep(i, 0, z)
	{
		dp[i] = __builtin_popcount(i);
		ll j = i;
		vi o;
		ll c = 0;
		while (j)
		{
			if(j&1) {
				o.pb(c);
			}
			j = j >> 1;
			++c;
		}
		bool sc = true;
		for (ll t1 : o)
		{
			for(ll t2: o) {
				if(t1==t2||a[t1][t2]) {

				} else {
					sc = false;
					break;
				}
			}
			if(!sc) {
				break;
			}
		}
		if(sc && o.size()) {
			dp[i] = 1;
		}
	}
	rep(i,0,z) {
		for (ll t = i; t > 0;t=(t-1)&i) {
			dp[i] = min(dp[i], dp[t] + dp[i ^ t]);
		}
	}
	cout << dp[z-1] << endl;
	return 0;
}


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

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

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

    void add(int a,long long b){
        a++;
        for(long long i = a; i <= n; i+=LSB(i)){
            bit[i-1]+=b;
        }
    }
    void set(int a,long long b){
        ll prev = this->get(a);
        a++;
        for(long long i = a; i <= n; i+=LSB(i)){
            bit[i-1]+=b-prev;
        }
    }
    long long sum(int a){
        if(a<0)return 0;
        if(a>=n)a=n-1;
        a++;
        long long ret=0;
        for(long long i = a; i > 0; i-=LSB(i)){
            ret+=bit[i-1];
        }
        return ret;
    }
    long long sum(int a,int b){
        // [a,b)
        --b;
        if(a==0)return sum(b);
        return sum(b)-sum(a-1);
    }
    long long get(int a){
        if(a==0)return sum(0);
        return sum(a)-sum(a-1);
    }
};

void solve(long long H, long long W, long long M, std::vector<long long> X, std::vector<long long> Y){
  ll rt=W,lb=H;
  vector<pll> XY(M);
  REP(M){
    XY[i]=pll(X[i],Y[i]);
  }
  vector<ll> mh(H,W),mw(W,H);
  REP(M){
    if(X[i]==0){
      chmin(rt,Y[i]);
    }
    chmin(mh[X[i]],Y[i]);
    if(Y[i]==0){
      chmin(lb,X[i]);
    }
    chmin(mw[Y[i]],X[i]);
  }
  if(rt==1&&lb==1){
    cout<<1<<endl;
    return;
  }
  BIT wl(W),hl(H);
  ll ans=0;
  sort(XY.begin(),XY.end());
  ll idx=0;
  REP(lb){
    while(idx<XY.size()&&XY[idx].first==i){
      wl.set(XY[idx].second,1);
      ++idx;
    }
    ans+=mh[i]+max(0LL,(rt-mh[i]-wl.sum(mh[i],rt)));
  }
  REP(rt){
    if(mw[i]>=lb){
      ans+=mw[i]-lb;
    }
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> X(M);
    std::vector<long long> Y(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
        --X[i];--Y[i];
    }
    solve(H, W, M, std::move(X), std::move(Y));
    return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_REVERSE(x) SORT(x);reverse(all(x))

double calc_score(int direction, const int &ci, const int &cj, int base) {
    bool isUpperSide = ci < 25;
    bool isLeftSide = cj < 25;

    random_device rd;
    mt19937 eng(rd());
    uniform_int_distribution<int> distr(2, 15);
    int border = distr(eng);
    if (ci < border || cj < border || ci >= 50 - border || cj >= 50 - border) {
        return base;
    }
    switch (direction) {
        case 0:
            if (isUpperSide) {
                return 0;
            } else {
                return base * base;
            }
        case 1:
            if (!isLeftSide) {
                return 0;
            } else {
                return base * base;
            }
        case 2:
            if (!isUpperSide) {
                return 0;
            } else {
                return base * base;
            }
        case 3:
            if (isLeftSide) {
                return 0;
            } else {
                return base * base;
            }
        default:
            return base;
    }
}

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

    const vector<int> di = {-1, 0, 1, 0};
    const vector<int> dj = {0, 1, 0, -1};
    const vector<char> direction = {'U', 'R', 'D', 'L'};

    int si;
    cin >> si;
    int sj;
    cin >> sj;

    vector<vector<int>> tiles(50, vector<int>(50));
    vector<vector<int>> board(50, vector<int>(50));
    rep(i, 50) rep(j, 50) cin >> tiles.at(i).at(j);
    rep(i, 50) rep(j, 50) cin >> board.at(i).at(j);

    set<int> history = {};
    history.insert(tiles[si][sj]);
    string route;
    ll step = 1;

    int ci = si, cj = sj;

    while (true) {
        // label, direction, tile, nextI, nextJ
        vector<tuple<double, char, int, int, int>> list;

        int current_tile = tiles[ci][cj];

        rep(k, 4) {
            int next_i = ci + di[k];
            int next_j = cj + dj[k];

            if (next_i < 0 || next_i >= 50 || next_j < 0 || next_j >= 50) {
                continue;
            }

            int next_tile = tiles[next_i][next_j];

            if (current_tile != next_tile) {
                if (history.find(next_tile) == history.end()) {
                    double score = calc_score(k, ci, cj, board[next_i][next_j]);
                    list.emplace_back(score, direction[k], next_tile, next_i, next_j);
                }
            }
        }

        if (list.empty()) {
            break;
        } else {
            SORT_REVERSE(list);
            int label, tile, ni, nj;
            char next;
            tie(label, next, tile, ni, nj) = list.front();
            route += next;
            history.insert(tile);
            ci = ni;
            cj = nj;
            step++;
        }
    }
    cout << route << endl;
}


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

/*
    実行時MODint :
    template <int& MOD = 1000000007>
    static int MOD;
    cin >> MOD;
*/
template <int MOD = 1000000007>
struct Mint {
    int x;

    constexpr Mint() : x(0) {}
    constexpr Mint(long long t)
        : x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {}

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n;
    cin >> n;
    char caa, cab, cba, cbb;
    cin >> caa >> cab >> cba >> cbb;
    if (n <= 3) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'A') || (cab == 'B' && cbb == 'B')) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'B' && cba == 'A') ||
        (cab == 'B' && cbb == 'A' && cba == 'B')) {
        Mint<> dp[n][2];
        dp[0][0] = 1;
        rep(i, n - 1) {
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += (dp[i][0] + dp[i][1]);
        }
        cout << dp[n - 1][1] << endl;
        return 0;
    }
    cout << Mint<>(2).pow(n - 3) << endl;
    return 0;
}

/**

    template for testing/using the algorithms

    import(copy-paste the methods ;v) algorithm/s and use here

**/

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

using namespace std;

///------------------- algorithm function/s to be placed here start -------------------///

bool isEqual(double a, double b){

    double EPS = 1e-9;

    return abs(a-b) <= EPS;
}

double slope(double x1, double y1, double x2, double y2){

    if((x2-x1)==0) return -1;

    return (y2-y1)/(x2-x1);

}

bool isOnTheSameLine(int x1, int y1, int x2, int y2, int x3, int y3){

    return  (x1-x2)*(y1-y3) == (y1-y2)*(x1-x3);

}

///------------------- algorithm function/s to be placed here end -------------------///

void simulate(){
// simulate input to test the algorithm being implemented
}

int getRandomNumberInRange(int lower, int upper){
// generate a random number in the range- ['lower', 'upper']
    srand(time(0));
    return rand()%(upper-lower+1)+lower;
}

void exec(int T){
// execute the algorithm

    int n;

    cin>>n;

    vector<pair<int, int>> points;

    while(n--){
        int a,b;
        cin>>a>>b;
        points.push_back({a,b});
    }

    bool yes = false;

    for(int i=0;i<points.size();i++){
        for(int j=i+1;j<points.size();j++){

            pair<int, int> p1=points[i],p2=points[j];

            for(int k=j+1;k<points.size();k++){

                pair<int, int> p3 = points[k];

                if( isOnTheSameLine(p1.first, p1.second, p2.first, p2.second, p3.first, p3.second) ){

                    yes=true;
                    break;
                }

            }

            /*
            slopeCnt[ slopeP1P2 ]++;

            if(slopeCnt[slopeP1P2]>=2){
                yes = true;
                break;
            */
        }
        if(yes) break;
    }

    if(yes) cout<<"Yes\n";
    else cout<<"No\n";

}

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

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

    int t=1;

    //cin>>t;

    for(int T=1;T<=t;T++){

        exec(T);

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }
ll inv(ll a, ll m) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }

ll garner(vector<ll> r, vector<ll> m) {
  ll N = r.size();
  ll prod = 1, res = 0, rem = 0;
  rep(i,N) {
    ll g = gcd(prod,m[i]);
    if (abs(r[i]-res)%g) { return -1; }
    rem = res%g; prod /= g; m[i] /= g; res /= g; r[i] /= g;
    ll t = ((r[i]-res)*inv(prod,m[i])%m[i]+m[i])%m[i];
    res = (res+t*prod)*g + rem;
    prod *= m[i] * g;
  }
  return res;
}

int main() {
  ll T; cin >> T;
  rep(_,T) {
    ll X, Y, P, Q; cin >> X >> Y >> P >> Q;
    ll m1 = 2*(X+Y), m2 = P+Q;
    ll result = LLINF;
    repr(i,X,X+Y) repr(j,P,P+Q) {
      ll res = garner({i,j},{m1,m2});
      if (res!=-1) result = min(result,res);
    }
    if (result==LLINF) cout << "infinity" << endl;
    else cout << result << endl;
  }
  return 0;
}

// R SAI KRISHNA
#include <bits/stdc++.h>
#define for0(i, n) for (int i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (ll)(n); ++i)
#define forc(i, l, r) for (int i = (ll)(l); i <= (ll)(r); ++i)
#define forr0(i, n) for (int i = (ll)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (ll)(n); i >= 1; --i)
#define pb push_back
#define fi first
#define debug(x) cout << #x << " -> " << x << endl;
#define endl '\n'
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) ll((a).size())
#define mod 1000000007
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

void debug_vec(vector<ll>&v){
    cout << '[';
    for(auto i:v)cout << i << ", "; cout << "]";
    cout << "\n";
}

void debug_set(set<ll>&st){
    cout << "{";
    for(auto i:st)cout << i << ", ";
    cout << "}";
    cout << "\n";
}

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

bool prime[1000001];
void sieve()
{
  memset(prime, true, sizeof(prime));
  prime[1]=false;
  for (int p=2; p*p<=1000000; p++)
  {
    if (prime[p] == true)
    {
        for (int i=p*p; i<=1000000; i += p)
                prime[i] = false;
    }
  }
}

void print(bool f){
    if(f)cout << "YES\n";
    else cout << "NO\n";
}

void google(int x){
    cout << "Case #" << x << ": " ;
}

void solve()
{
    ll n;
    cin >> n;
    ll temp = 6;
    set<ll>st;
    st.insert(6);
    st.insert(10);
    st.insert(15);
    while(st.size() < n && temp < 10000){

        temp += 6;
        if(temp <= 10000)
        st.insert(temp);
    }
    temp = 10;
    while(st.size()<n && temp<10000){
        temp += 10;
        if(temp <= 10000)
        st.insert(temp);
    }
    temp = 15;
    while(st.size() < n && temp<10000){
        temp += 15;
        if(temp <= 10000)
        st.insert(temp);
    }
    for(auto i:st)cout << i << ' ';
    cout << endl;

}

int main()
{
  fast();
  /*ll t;
  cin >> t;
  for(int tt = 1;tt <= t ;tt++)*/
  solve();

return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  std::vector<int> p(N, 0);
  for (size_t i = 0; i < N; i++) {
    cin >> p[i];
  }

  // main procedure
  set<int> rs;  // remain_setN
  for (size_t i = 0; i <= N + 1; i++) {
    rs.insert(i);
  }

  std::vector<int> ans(N, 0);
  for (size_t i = 0; i < N; i++) {
    rs.erase(p[i]);
    ans[i] = *(rs.begin());
  }

  // output
  for (size_t i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<bool> a(n, false);
    int r = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (p >= 0 && p < n) {
            a[p] = true;
        }
        while (r < n && a[r]) {
            r++;
        }
        cout << r << endl;
    }
}


/*Author-Nilesh Chandra(isocyanide7)*/
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y)
{
    if (y==0)
        return 1;
    else if (y%2==0)
        return power(x,y/2)*power(x,y/2);
    else
        return x*power(x,y/2)*power(x,y/2);
}
ll hcf(ll a,ll b)
{
    if(b==0)
        return a;
    return hcf(b,a%b);
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    	freopen("error.txt", "w", stderr);
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       dd a,b,c,d;
       cin>>a>>b>>c>>d;
       dd ans=(dd)(a*d+b*c)/(dd)(b+d);
       cout<<fixed<<setprecision(10)<<ans;
   }
}

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

int main(){
    cout << fixed << setprecision(15);
    double sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    gy = -gy;
    double a = (gy - sy) / (gx - sx);
    double b = sy - a * sx;
    double x = -b / a;
    cout << x << endl;
}


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

const int N = 1e5 + 10;
int k, n, m, a[N], _l[N], _r[N], b[N];

bool chk(ll lim) {
  ll L = 0, R = 0;
  rep(i, 1, k) {
    ll l = max(0.0, ceil(1.0 * (m * a[i] - lim) / n)), r = (m * a[i] + lim) / n;
    if (l > r) return 0;
    L += l, R += r;
    _l[i] = l, _r[i] = r;
  }
  if (m < L || m > R) return 0;
  return 1;
}

signed main() {
  rd(k), rd(n), rd(m);
  rep(i, 1, k) {
    rd(a[i]);
  }
  ll l = 0, r = n * m, ans = r;
  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (chk(mid)) ans = mid, r = mid - 1;
    else l = mid + 1;
  }
  chk(ans);
  rep(i, 1, k) {
    m -= _l[i];
    b[i] = _l[i];
  }
  rep(i, 1, k) {
    ll t = min(_r[i] - b[i], m);
    b[i] += t, m -= t;
    if (!m) break;
  }
  rep(i, 1, k) {
    printf("%lld ", b[i]);
  } puts("");
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<ll,ll>
bool mycomp(pii a,pii b)
{
	if(a.first==b.first) return a.second>b.second;
	return a.first<b.first;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll k,n,m,sum=0;
	cin>>k>>n>>m;
	ll a[k],b[k];
	vector<pii> sub,add;
	for(int i=0;i<k;i++)
	{
		cin>>a[i];
		a[i]*=m;
		b[i]=a[i];
		ll p=a[i]%n;
		ll q=n-p;
		sub.pb({p,i});
		add.pb({q,i});
	}
    sort(sub.begin(),sub.end(),greater<pii>());
    sort(add.begin(),add.end(),mycomp);
    int i=0,j=k-1;
    while(i<j){
    	if(add[i].first>sub[j].first){
    		b[sub[j].second]-=sub[j].first;
    		b[add[i].second]+=sub[j].first;
    		add[i].first-=sub[j].first;
    		j--;
		}
		else{
			b[add[i].second]+=add[i].first;
			b[sub[j].second]-=add[i].first;
			sub[j].first-=add[i].first;
			i++;
		}
	}
	for(int i=0;i<k;i++)
	cout<<(b[i]/n)<<" ";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define INF 1e18
#define MOD 1000000007
#define MAXR 100005
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,-1,1};

struct Edge{
    int to;
    int time;
    int k;
};
vector<Edge>G[100005];
void dijkstra(int x,vector<ll>&dist){
     dist[x]=0;
    priority_queue<P,vector<P>,greater<P> >Q;
    Q.push(make_pair(0,x));
    while(!Q.empty()){
        auto p=Q.top();
        Q.pop();
        int from =p.second;
        if(dist[from]<p.first) continue;
        for(int i=0;i<G[from].size();i++){
            Edge e =G[from][i];
            ll next = 0;
            if (p.first % e.k == 0){
                next = p.first + e.time;
            }
            else{
                next = p.first + e.time + e.k - p.first%e.k;
            }
            if(dist[e.to]>next){
                dist[e.to]=next;
                Q.push(make_pair(dist[e.to],e.to));
            }
        }
    }
}

int main(){
    int n,m,x,y;
    cin >>n>>m>>x>>y;
    x--;y--;
    rep(i,m){
        int a,b,t,k;
        cin >>a>>b>>t>>k;
        a--;b--;
        G[a].push_back((Edge){b,t,k});
        G[b].push_back((Edge){a,t,k});
    }
    vector<ll>dist(n,INF);
    dijkstra(x,dist);

    if(dist[y]==INF) cout <<-1<<endl;
    else cout <<dist[y]<<endl;

    return 0;
}

#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;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
#define len(x) (lli)(x.length())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

struct edg {
    lli des, t, k;
};

void solve() {
    lli n, m, a, b, t, k, x, y;
    cin >> n >> m >> x >> y;

    vector<vector<struct edg>> adj(n + 2);
    for (lli i = 0; i < m; i++) {
        cin >> a >> b >> t >> k;
        struct edg edg1, edg2;
        edg1.des = b, edg1.t = t, edg1.k = k;
        edg2.des = a, edg2.t = t, edg2.k = k;
        adj[a].pb(edg1);
        adj[b].pb(edg2);
    }

    lli inf = -1;
    vector<lli> dis(n + 2, inf);
    set<pair<lli, lli>> st;

    dis[x] = 0;
    st.insert({dis[x], x});

    while (!st.empty()) {
        auto it = st.begin();
        lli d = it->first;
        lli a = it->second;
        // cout << d << " " << a << endl;
        st.erase(it);

        for (lli i = 0; i < adj[a].size(); i++) {
            lli des = adj[a][i].des;
            lli cost = adj[a][i].t;
            lli wait_time = 0;
            if (d % adj[a][i].k != 0) {
                lli p = d / adj[a][i].k;
                p++;
                // if (des == 3) {
                //     cout << p << endl;
                // }
                wait_time = p * adj[a][i].k - d;
            }
            lli final_cost = d + cost + wait_time;
            if (dis[des] == inf) {
                dis[des] = final_cost;
                st.insert({dis[des], des});
            } else if (dis[des] > final_cost) {
                dis[des] = final_cost;
                st.insert({dis[des], des});
            }
        }
    }

    lli ans = dis[y];
    cout << ans << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N, M;
    cin >> N >> M;
    vvc<ll> adj(N, vl(N));

    vc<vvc<ll>> G(N, vvc<ll>(26));
    rep(i, M){
        ll a, b;
        char c;
        cin >> a >> b >> c, a--, b--;
        ll ci = c - 'a';
        G[a][ci].eb(b);
        G[b][ci].eb(a);
        adj[a][b] = adj[b][a] = true;
    }

    map<pair<ll, ll>, ll> mp;
    mp[{0, N - 1}] = 0;

    queue<pair<ll, ll>> q;
    q.emplace(0, N - 1);

    ll ans = INF;
    while(!q.empty()){
        auto [s, t] = q.front();
        ll cost = mp[{s, t}];
        q.pop();

        if(adj[s][t]){
            cout << cost + 1 << endl;
            return 0;
        }

        rep(c, 26){
            repa(tos, G[s][c]){
                repa(tot, G[t][c]){
                    if (mp.count({tos, tot})) continue;
                    mp[{tos, tot}] = cost + 2;
                    if(tos == tot){
                        cout << mp[{tos, tot}] << endl;
                        return 0;
                    }else{
                        q.emplace(tos, tot);
                    }
                }
            }
        }
    }

    cout << -1 << endl;
}


#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  string c = "White";
  if(n%2==0){
    c = "White";
  }
  else{
    c = "Black";
  }
  cout << c <<endl;
}

#include <iostream>
#include <memory.h>
#include <cmath>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    char a, b, c;
    cin >> a >> b >> c;
    cout << ((a==b && b==c) ? "Won" : "Lost") << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

void fast(){

    cin.tie();
    cin.sync_with_stdio();
}
int main()
{
    fast();

    int n;
    cin>>n;

    if(n==1)

    cout<<"0";

    else if(n==2)

     cout<<"1";

    else if(n>2)

      cout<<n-1;

    return 0;
}

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

#define pb push_back
#define rep(i,j,n) for(int64_t i=j;i<n;i++)
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)v.size())
#define br '\n'

void resp(int tc) {
    int x; cin >> x;
    cout << max(0, x) << br;
}

int main() {
    int tc=1;
    // cin >> tc;
    while(tc--) resp(tc);
    return 0;
}


// Problem: D - Shipping Center
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 195)
// URL: https://atcoder.jp/contests/abc195/tasks/abc195_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Parsed on: 13-03-2021 18:36:40 IST (UTC+05:30)
// Author: Kapil Choudhary
// ********************************************************************
// कर्मण्येवाधिकारस्ते मा फलेषु कदाचन |
// मा कर्मफलहेतुर्भूर्मा ते सङ्गोऽस्त्वकर्मणि || १.४७ ||
// ********************************************************************

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii>	vpii;
typedef vector<pll>	vpll;
typedef vector<vi> vvi;
typedef vector<vll>	vvll;
typedef vector<vull> vvull;
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);
}

const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;

void solve()
{
  	int n, m, q;
  	cin >> n >> m >> q;

  	vpii v(n);
  	for(int i = 0; i < n; i++) {
  		cin >> v[i].F >> v[i].S;
  	}

  	vi t(m);
  	for(int i = 0; i < m; i++) cin >> t[i];

  	//cout << n << " " << m << " " << q << endl;
  	//for(auto x: v) cout << x.F << " " << x.S << endl;
  	//for(auto x: t) cout << x << " "; cout << endl;

  	while(q--) {
  		int L, R; cin >> L >> R;
  		L -= 1, R -= 1;
  		//deb2(L, R);
  		vi boxes;
  		for(int i = 0; i < L; i++) boxes.pb(t[i]);
  		for(int i = R + 1; i < m; i++) boxes.pb(t[i]);

  		//for(auto x: boxes) cout << x << " "; cout << endl;

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

  		vector<bool> taken(n, 0);

  		ll mx = 0LL;
  		for(int i = 0; i < (int)boxes.size(); i++) {
  			int idx = -1;
  			ll tmp = LLONG_MIN;
  			for(int j = 0; j < n; j++) {
  				if(!taken[j] and v[j].F <= boxes[i]) {
  					if(tmp < v[j].S) {
  						tmp = v[j].S;
  						idx = j;
  					}
  				}
  			}

  			if(tmp != LLONG_MIN) {
  				mx += tmp;
  				taken[idx] = 1;
  			}
  		}

  		cout << mx << "\n";
  	}
}

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

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

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

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
#define PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const LL P = 1e9 + 7;
const LL INF = 1e9;
const int N = 2e5 + 5;
mt19937 rng(time(0));

int T, n, m;
char s1[N], s2[N], s3[N], res[N];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> T;
    rep(cas, 1, T) {
        cin >> n;
        cin >> (s1 + 1) >> (s2 + 1) >> (s3 + 1);
        int j = 0;
        rep(i, 1, (n + 1) / 2) res[++j] = '0';
        rep(i, 1, n) res[++j] = '1';
        rep(i, 1, n / 2 + 1) res[++j] = '0';
        res[++j] = 0;
        cout << (res + 1) << 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;

bool cmp(const pair<string,ll>&a,const pair<string,ll>&b)
{
    if(a.se>b.se)
        return 1;
    else
        return 0;
}
Dont_Quit
{
    FASTIO_
    ll  tc,n,m,x,i,j,d;
    string s;
    tc=1;
    while(tc--)
    {
        cin>>n;
        vector<pair<string,ll>>v;
        itr(i,n)
        {
            cin>>s>>x;
            v.pb(mp(s,x));
        }
        sort(v.begin(),v.end(),cmp);

        cout<<v[1].fi<<en;

    }

    Avada_Kedavra
}

#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(10)

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

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

//最大公約数
template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

template <typename X, typename M>
struct SegTreeLazy {
    using FX = function<X(X, X)>;
    using FA = function<X(X, M)>;
    using FM = function<M(M, M)>;
    int n;
    FX fx;
    FA fa;
    FM fm;
    const X ex;
    const M em;
    vector<X> dat;
    vector<M> lazy;
    SegTreeLazy(int n_, FX fx_, FA fa_, FM fm_, X ex_, M em_)
        : n(), fx(fx_), fa(fa_), fm(fm_), ex(ex_), em(em_), dat(n_ * 4, ex), lazy(n_ * 4, em) {
        int x = 1;
        while (n_ > x) x *= 2;
        n = x;
    }

    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }

    /* lazy eval */
    void eval(int k) {
        if (lazy[k] == em) return;  // 更新するものが無ければ終了
        if (k < n - 1) {            // 葉でなければ子に伝搬
            lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]);
            lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]);
        }
        // 自身を更新
        dat[k] = fa(dat[k], lazy[k]);
        lazy[k] = em;
    }

    void update(int a, int b, M x, int k, int l, int r) {
        eval(k);
        if (a <= l && r <= b) {  // 完全に内側の時
            lazy[k] = fm(lazy[k], x);
            eval(k);
        } else if (a < r && l < b) {                     // 一部区間が被る時
            update(a, b, x, k * 2 + 1, l, (l + r) / 2);  // 左の子
            update(a, b, x, k * 2 + 2, (l + r) / 2, r);  // 右の子
            dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    void update(int a, int b, M x) { update(a, b, x, 0, 0, n); }

    X query_sub(int a, int b, int k, int l, int r) {
        eval(k);
        if (r <= a || b <= l) {  // 完全に外側の時
            return ex;
        } else if (a <= l && r <= b) {  // 完全に内側の時
            return dat[k];
        } else {  // 一部区間が被る時
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
};

bool isLarger(string s,string t){
	/*SのほうがTより大きければtrue*/
	rep(i,min(s.length(),t.length())){
		if(s[i]>t[i]){
			return true;
		}
		if(s[i]<t[i]){
			return false;
		}
	}

	if(s.length()>t.length()){
		return true;
	}
	else{
		return false;
	}
}

int main(void) {
  ll n;
  cin>>n;
  vector<vector<ll>>v(n,vector<ll>(2));
  rep(i,n){
    cin>>v[i][0]>>v[i][1];
  }

  rep(i,n){
    rep(j,n){
      rep(k,n){
        if(i==j||k==i||j==k){
          continue;
        }
        ll x1=v[i][0]-v[j][0];
        ll y1=v[i][1]-v[j][1];
        ll x2=v[i][0]-v[k][0];
        ll y2=v[i][1]-v[k][1];

        if(x1*y2==x2*y1){
          cout<<"Yes";
          return 0;
        }
      }
    }
  }

  cout<<"No";
}

/*

*/


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

int main()
{
    int n;
    double x, y;
    complex<double> a, b;

    cin >> n;
    cin >> x >> y;
    a = {x, y};
    cin >> x >> y;
    b = {x, y};

    auto m = (a + b) / 2.0;

    auto res = m + (a - m) * polar(1.0, M_PI * 2.0 / n);

    cout << setprecision(9) << res.real() << " " << res.imag() << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
#define check(x) if(x>=mod) x-=mod
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int qpow(int x,int y){
    int ret = 1;
    while(y) {
        if(y & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        y >>= 1;
    }
    return ret;
}
int n,m,a,b,ans;
char s[1005][1005];
int main()
{
    scanf("%d%d%d%d",&n,&m,&a,&b);
    rep(i,1,n) scanf("%s",s[i]+1);
    int P = a;
    while(P > 1 && s[P - 1][b] == '.') ans++,P--;
    P = b;
    while(P > 1 && s[a][P - 1] == '.') ans++,P--;
    P = a;
    while(P < n && s[P + 1][b] == '.') ans++,P++;
    P = b;
    while(P < m && s[a][P + 1] == '.') ans++,P++;
    printf("%d\n",ans+1);
    return 0;
}


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

int a[maxn],b[maxn],c[maxn];

int main()
{
    fastio();
    int n,k; cin >> n >> k;
    vector<pii_> g;
    rep(i,1,n){
        cin >> a[i] >> b[i] >> c[i];
        g.pb(mp_(a[i],c[i]));
        g.pb(mp_(b[i]+1,-c[i]));
    }
    sort(ALL(g));
    ll ans = 0,tot = 0;
    rep(i,0,2*n-1){
        int now = g[i].fi;
        tot += g[i].se;
        int pos = i;
        while(pos+1<2*n && g[pos+1].fi==now){
            tot += g[++pos].se;
        }
        if(pos == 2*n-1) break;
        ans += 1LL*min(1LL*k,tot)*(g[pos+1].fi-now);
        i = pos;
    }
    cout << ans << endl;
    return 0;
}

#include <cctype>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <ios>
#include <iostream>
#include <iterator>
#include <string_view>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>
#include <list>

const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, char> origin,
               std::pair<int64_t, int64_t> another) {
  return origin.first < another.first;
}
bool sort_pair2(std::pair<int64_t, char> origin,
               std::pair<int64_t, int64_t> another) {
  return origin.second < another.second;
}

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

int main()
{
    int64_t q,k,h,w,m,n,c;
    std::cin>> n;
    std::cin>> c;
    std::vector< std::pair< int64_t, int64_t > > list;

    for( int i = 0; i < n; i++ )
    {
        std::cin>> q;
        std::cin>> k;
        std::cin>> h;

        list.push_back( std::make_pair( q, h ) );
        list.push_back( std::make_pair( k + 1, -h ) );
    }

    std::sort( list.begin(), list.end(), sort_pair );

    q = 0;
    k = 1;
    m = 0;
    for( int i = 0; i < list.size(); i++ )
    {
        if( k != list[i].first )
        {
            q += std::min( c, m ) * ( list[i].first - k );
            k = list[i].first;
        }

        m += list[i].second;
    }

    std::cout<< q <<"\n";
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N; ll A[3010];
mint dp[3010][3010];  // dp[i][k] := i番目まででk組作った
mint tot[3010][3010]; // tot[k][mo] := k組作っていてこれまでの総和を(k+1)で割った余りがmoである
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    dp[0][0] = 1;
    tot[0][0] = 1;
    ll sum = 0;
    rep(i, 0, N) {
        sum += A[i];
        rep(k, 1, N + 1) dp[i + 1][k] = tot[k - 1][sum % k];
        rep(k, 1, N + 1) tot[k][sum % (k + 1)] += dp[i + 1][k];
    }

    mint ans = 0;
    rep(k, 1, N + 1) ans += dp[N][k];
    cout << ans << endl;
}

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

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

    vector<int> x(m);

    vector<pair<int, int>> vw(n);

    rep(i, n) cin >> vw[i].second >> vw[i].first;

    rep(i, m) cin >> x[i];

    sort(vw.begin(), vw.end(), greater<pair<int, int>>());

    rep(i, q) {
        int l, r;
        cin >> l >> r;

        ll ans = 0;
        vector<pair<int, int>> vwtemp;
        for(auto j : vw) vwtemp.push_back(j);
        vector<int> temp;
        for(int j = 0;j < l - 1;j++) temp.push_back(x[j]);
        for(int j = r;j < m;j++) temp.push_back(x[j]);

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

        for(int j : temp){
            rep(k, n) {
                if(j >= vwtemp[k].second){
                    ans += vwtemp[k].first;
                    vwtemp[k].second = INF;
                    break;
                }
            }

        }
        cout << ans << endl;

    }

    return 0;

}


#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
void solve(){
	int n;
	string s,t;
	cin>>n>>s>>t;
	vector <int> aw {0,1,1,1,1,1,1},tw {1,0,0,0,0,0,0};
	for (int i=n-1; i>=0; i--){
		vector <int> temp {0,0,0,0,0,0,0};
		if (t[i]=='A'){
			for (int j=0; j<7; j++){
				if (!aw[j]) continue;
				for (int k=0; k<7; k++){
					if ((10*k)%7==j||(10*k+s[i]-'0')%7==j) temp[k]=1;
				}
			}
			aw=temp;
			for (int j=0; j<7; j++) tw[j]=aw[j]^1;
		} else {
			for (int j=0; j<7; j++){
				if (!tw[j]) continue;
				for (int k=0; k<7; k++){
					if ((10*k)%7==j||(10*k+s[i]-'0')%7==j) temp[k]=1;
				}
			}
			tw=temp;
			for (int j=0; j<7; j++) aw[j]=tw[j]^1;
		}
	}
	if (aw[0]) cout<<"Aoki";
	else cout<<"Takahashi";
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t=1;
	//cin>>t;
	while (t--) solve();
}

#include <cstdio>
using namespace std;

const int max_n = 200000;
char s[max_n+1], op[max_n+1];
bool wn[7] = {}, nwn[7];

int main()
{
	int n, cur = 1;
	bool sl1, sl2;

	scanf("%d%s%s", &n, s, op);
	wn[0] = true;

	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = 0; j < 7; j++)
			nwn[j] = wn[j];

		if (op[i] == 'A')
		{
			for (int j = 0; j < 7; j++)
				if (!wn[(j+cur*(s[i]-'0'))%7])
					nwn[j] = false;
		}
		else
		{
			for (int j = 0; j < 7; j++)
				if (wn[(j+cur*(s[i]-'0'))%7])
					nwn[j] = true;
		}

		sl1 = true, sl2 = false;
		for (int j = 0; j < 7; j++)
		{
			wn[j] = nwn[j];
			sl1 &= wn[j], sl2 |= wn[j];
		}

		if (sl1)
		{
			puts("Takahashi");
			return 0;
		}
		else if (!sl2)
		{
			puts("Aoki");
			return 0;
		}

		cur = (cur * 10) % 7;
	}

	if (wn[0])
		puts("Takahashi");
	else
		puts("Aoki");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define MAX_N 200001
int par[MAX_N]; //親
int rnk[MAX_N]; //木の深さ
int siz[MAX_N]; //木のサイズ
typedef long long ll;

//n要素で初期化
void init(){
    REP(i,MAX_N){
        par[i]=i;
        rnk[i]=0;
        siz[i]=1;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;

    if(rnk[x]<rnk[y]){
        par[x]=y;
        siz[y]+=siz[x];
    }else{
        par[y]=x;
        siz[x]+=siz[y];
        if(rnk[x]==rnk[y]) rnk[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x)==find(y);
}

//連結成分の個数
int union_num(int n){
    int rtn=0;
    REP(i,n) if(i==find(i)) rtn++;
    return rtn;
}

int main(){
    int n;cin>>n;
    int ans=0;
    vector<int> x(n,0);
    set<int> se;
    init();
    REP(i,n){
      cin>>x.at(i);
      se.insert(x.at(i));
    }
    REP(i,n) unite(x.at(i),x.at(n-i-1));
    for(auto p:se) if(p==find(p)) ans+=siz[p]-1;
    //REP(i,n) if(x.at(i)==find(x.at(i))) ans+=siz[x.at(i)]-1;
    //for(auto p:se)  cout<<p<<" "<<find(p)<<" "<<siz[p]<<endl;
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int f=1,r=0;char c=getchar();
	while(!isdigit(c))f^=c=='-',c=getchar();
	while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
	return f?r:-r;
}
int main(){
	cout<<max(read(),0);
	return 0;
}


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

const int Max_W = 1000000, INF = 1e9;
int dpmin[Max_W+1], dpmax[Max_W+1];

int main(){
    int a, b, w;
    cin >> a >> b >> w;
    w *= 1000;
    fill(dpmin, dpmin+w+1, INF);
    fill(dpmax, dpmax+w+1, -INF);
    for (int i = a; i <= b; i++){
        dpmin[0] = 0;
        dpmax[0] = 0;
        for (int j = 0; j <= w; j++){
            if (j - i >= 0) {
                dpmin[j] = min(dpmin[j-i] + 1, dpmin[j]);
                dpmax[j] = max(dpmax[j-i] + 1, dpmax[j]);
            }
        }
    }
    if (dpmin[w] == INF || dpmax[w] == -INF) {
        cout << "UNSATISFIABLE" << endl;
        return 0;
    }
    cout << dpmin[w] << " " << dpmax[w] << endl;
    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const long double INF = 2e12;
const long double eps = 1e-12;

int N, M, K;
vector<int> A;

long double solve(long double ans){
	vector<long double> dp(N + 1), sum(N + 1);
	rep(i,N){
		int n = N - 1 - i;
		if(A[n]) dp[n] = ans;
		else dp[n] = (sum[i] - sum[max(0, i - M)]) / M + 1;
		sum[i+1] = sum[i] + dp[n];
	}
	return dp[0];
}

long double binary_search(long double left, long double right){
	if(right - left < eps * left) return left;
	long double ans = sqrt(left * right);
	long double res = solve(ans);
	if(ans > res) right = ans;
	else left = ans;
	return binary_search(left, right);
}

int main(){
	cin >> N >> M >> K;
	A = vector<int>(N + 1);
	rep(i,K){
		int a;
		cin >> a;
		A[a] = 1;
	}
	int num = 0;
	rep(i,N+1){
		if(A[i]) num++;
		else num = 0;
		if(num >= M){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << setprecision(20) << binary_search(1, INF) << endl;

	return 0;
}


//-------------------------------------
//| -<{ Besme llahe Rahmane Rahim }>- |
//-------------------------------------
#include <bits/stdc++.h>
#define pb push_back
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz(x) (int)(x).size()
#define all(c) (c).begin(),(c).end()
using namespace std;
//#include ".dbg.h"
typedef long long ll;
const int N = 300005;
ll n, cnt = 1, ans;
int a[N];

void solve(){
    ans = n * (n-1) / 2;
    sort(a, a + n);
    for(ll i = 1; i < n; i++)
    {
        if(a[i] == a[i-1]) cnt++;
        if(a[i] != a[i-1] || i == n-1)
        {
            ans -= (cnt * (cnt - 1) / 2);
            cnt = 1;
        }
    }
}

int main(){
    cin >> n; for(int i = 0; i < n; i++) cin >> a[i];
    solve();
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define pb push_back
#define F first
#define S second
typedef long long ll;
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
//a.erase(unique(all(a)), a.end()); ソート後に重複を削除
//cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる
//vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言

int main() {
ll n;
cin>>n;
vector<ll> a(n+1);
ll ans=0;
    rep(i,0,n){
        cin>>a.at(i);
    }
    a.at(n)=MOD;
    sort(all(a));
    ll last=0;
    rep(i,0,n-1){
        if(a.at(i)!=a.at(i+1)){
            //cout<<i<<" "<<a.at(i)<<" "<<i+1<<" "<<a.at(i+1)<<endl;
            last=i+1;
        }else{

        }
        ans+=last;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
std::vector<std::string> split(std::string str, char del)
{
    int first = 0;
    int last = str.find_first_of(del);

    std::vector<std::string> result;

    while (first < str.size())
    {
        std::string subStr(str, first, last - first);

        result.push_back(subStr);

        first = last + 1;
        last = str.find_first_of(del, first);

        if (last == std::string::npos)
        {
            last = str.size();
        }
    }

    return result;
}

unsigned GetDigit(unsigned num)
{
    unsigned digit = 0;
    while (num != 0)
    {
        num /= 10;
        digit++;
    }
    return digit;
}

long long int poww(int x, int y) {
    long long int res = 1;
    for (int i = 0; i < y; i++) {
        res *= x;
    }
    return res;
}

int main()
{
    long long int N;
    cin >> N;
    long long int cnt = 0;
    // for (int i = 1; i <= N; i++)
    // {
    //     int d = GetDigit(i);
    //     // cout << i << ": " << d << endl;
    //     if (d % 2 != 0)
    //     {
    //         continue;
    //     }
    //     auto a = poww(10, d/2);
    //     if (i % a == i/ a) {
    //         cnt++;
    //     }

    // }
    // cout << cnt << endl;
    for (int i= 1; i < 10e+6; i++) {
        auto d = GetDigit(i);
        auto n = poww(10,d)* i + i;
        if (n <= N) cnt++;
        else break;
    }
    cout << cnt << endl;
    return 0;
}

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

int32_t main()
{
    string s;
    cin>>s;
    int ans;
    int n=s.length();
    if(n&1) ans=pow(10,n/2)-1;
    else
    {
        int x = stoi(s.substr(0,n/2));
        int y = stoi(s.substr(n/2,n/2));
        if(x<=y) ans=x;
        else ans=x-1;
    }

    cout<<ans;
    return 0;
}


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

struct edge{ ll to, cost; };

#define MAX_N 200005
int nn = MAX_N; // 複数回根付き木を作成する場合は適宜変える.
vector<edge> pre_G[MAX_N];
vector<edge> G[MAX_N];
int par_[MAX_N];
ll par_cost[MAX_N];
int flag_netsukigi[MAX_N];
void make_netsukigi(int r){
    rep(i,nn){
        G[i].clear();
        par_[i] = 0;
        flag_netsukigi[i] = 0;
    }
    queue<int> que;
    que.push(r);
    flag_netsukigi[r] = 1;
    par_[r] = -1;

    while(que.size() > 0){
        int x = que.front();
        que.pop();
        flag_netsukigi[x] = 1;
        rep(i,pre_G[x].size()){
            if(flag_netsukigi[pre_G[x][i].to] == 0){
                par_[pre_G[x][i].to] = x;
                par_cost[pre_G[x][i].to] = pre_G[x][i].cost;
                G[x].push_back(pre_G[x][i]);
                que.push(pre_G[x][i].to);
            }
        }
    }
}

ll dp[MAX_N][64][2];
ll ans;
const ll MOD = 1000000007;

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

    int n;
    cin >> n;
    nn = n;

    rep(i,n-1){
        ll from, to, cost;
        cin >> from >> to >> cost;
        from--; to--; // 0-indexにするため.
        edge e1, e2;
        e1.to = to; e2.to = from;
        e1.cost = cost; e2.cost = cost;
        pre_G[from].push_back(e1);
        pre_G[to].push_back(e2);
    }

    make_netsukigi(0);

    int sons[n] = {};
    queue<int> que;
    rep(i,n){
        sons[i] = G[i].size();
        if(G[i].size() == 0){
            que.push(i);
        }
        rep(j,60) dp[i][j][0] = 1;
    }

    while(que.size()){
        int x = que.front();
        que.pop();
        if(x == 0) continue;
        int px = par_[x];
        ll cost = par_cost[x];
        bitset<64> bi(cost);
        rep(i,60) if(bi[i]) swap(dp[x][i][0],dp[x][i][1]);

        rep(i,60){
            ans += (1LL<<i) % MOD * dp[px][i][0] % MOD * dp[x][i][1] % MOD;
            ans += (1LL<<i) % MOD * dp[px][i][1] % MOD * dp[x][i][0] % MOD;
            ans %= MOD;
        }
        rep(i,60){
            rep(j,2){
                dp[px][i][j] += dp[x][i][j];
            }
        }

        sons[px]--;
        if(sons[px]==0) que.push(px);
    }

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

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    V<int> A(N), B(N);
    int sz = N * 2;
    V<int> tp(sz), com(sz, -1);

    bool ng = false;

    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] != -1) {
            --A[i];
            if (tp[A[i]]) ng = true;
            tp[A[i]] = i + 1;
        }
        if (B[i] != -1) {
            --B[i];
            if (tp[B[i]]) ng = true;
            tp[B[i]] = -(i + 1);
        }

        if (A[i] != -1 && B[i] != -1) {
            com[A[i]] = B[i];
            com[B[i]] = A[i];
        }
    }
    if (ng) {
        puts("No");
        return 0;
    }

    V<bool> dp(sz + 1);
    dp[0] = true;

    rep(i, sz) {
        if (!dp[i]) continue;
        for (int j = i + 1; j < sz; ++j) {
            int w = j - i + 1;
            if (w & 1) continue;
            w /= 2;
            bool ok = true;
            V<bool> exist(N);

            rep(k, w) {
                int p = i + k, q = i + k + w;
                if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) {
                    ok = false;
                }
                if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) {
                    ok = false;
                }

                bool same = true;
                if (tp[p] != 0 && tp[q] != 0) {
                    if (tp[p] < 0 || tp[p] + tp[q] != 0) {
                        ok = false;
                    } else
                        same = true;
                }
                if (tp[p] < 0 || tp[q] > 0) {
                    ok = false;
                } else {
                    if (tp[p] != 0) {
                        int v = tp[p] - 1;
                        if (exist[v]) {
                            ok = false;
                        }
                        exist[v] = true;
                    }
                    if (!same && tp[q] != 0) {
                        int v = -tp[q] - 1;
                        if (exist[v]) {
                            ok = false;
                        }
                        exist[v] = true;
                    }
                }
            }
            if (ok) {
                dp[j + 1] = true;
            }
        }
    }
    puts(dp[sz] ? "Yes" : "No");

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int RANGEMAX = 10000;
struct record{
    int id;
    int x;
    int y;
    int r;
    bool operator<(const record &other) const {
        return this->r < other.r;
    }
    bool operator>(const record &other) const {
        return this->r > other.r;
    }
};

int input(vector<int> &x, vector<int> &y, vector<int> &r){
    int n;
    cin >> n;
    x = vector<int>(n);
    y = vector<int>(n);
    r = vector<int>(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i];
    return n;
}

void output(int n, const vector<int> &a, const vector<int> &b, const vector<int> &c, const vector<int> &d){
    for(int i = 0; i < n; i++){
        cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
    }
}

// 入出力 AC Score: 823090
void solve001(int n, vector<int> x, vector<int> y, vector<int> r){
    vector<vector<bool>> isused(RANGEMAX, vector<bool>(RANGEMAX, false));
    vector<int> a(n, -1), b(n, -1), c(n, -1), d(n, -1);
    vector<record> data(n);
    for(int i = 0; i < n; i++){
        data[i] = {i, x[i], y[i], r[i]};
    }
    sort(data.begin(), data.end(), greater<record>());
    for(int curind = 0; curind < n; curind++){
        int id = data[curind].id;
        int oneSideLen = (int)sqrt(r[id]);// 1辺の長さ

        for(int i = x[id]; i < min(x[id]+oneSideLen, RANGEMAX); i++){
            for(int j = y[id]; j < min(y[id]+oneSideLen, RANGEMAX); j++){
                if(isused[i][j] && i > x[id] && j > y[id]){
                    a[id] = x[id];
                    b[id] = y[id];
                    c[id] = i-1;
                    d[id] = j-1;
                    goto EndMakeRectLoop;
                }else if(isused[i][j] && (i == x[id] && j == y[id])){
                    goto EndMakeRectLoop;
                }
            }
        }
        EndMakeRectLoop:
        if(a[id] != -1){
            for(int i = a[id]; i < c[id]; i++){
                for(int j = b[id]; j < d[id]; j++) isused[i][j] = true;
            }
        }
    }
    for(int curind = 0; curind < n; curind++){
        if(a[curind] != -1) continue;

        for(int i = 0; i < RANGEMAX; i++){
            for(int j = 0; j < RANGEMAX; j++){
                if(!isused[i][j]){
                    isused[i][j] = true;
                    a[curind] = i;
                    b[curind] = j;
                    c[curind] = i+1;
                    d[curind] = j+1;
                    goto EndMakeRectLoop2;
                }
            }
        }
        EndMakeRectLoop2:
        ;
    }
    output(n, a, b, c, d);
}

int main(){
    int n;
    vector<int> x, y, r;
    n = input(x, y, r);
    solve001(n, x, y, r);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

// constexpr ll MOD=1000000007ll;
constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int n, x[252], y[252], r[252];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  cin>>n;
  REP(i, n){
    cin>>x[i]>>y[i]>>r[i];
  }
  REP(i, n){
    cout<<i*(10000/n)<<' '<<0<<' '<<(i+1)*(10000/n)<<' '<<10000<<'\n';
  }
  return 0;
}


#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 600006
#define LL long long
#define int long long
using namespace std;

int n,m;
int a[N];
map<int,int>mp;
LL ans;
inline int qr()
{
	char a=0;int w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return x*w;
}

signed main()
{
	n=qr();
	for(register int i=1;i<=n;i++) mp[a[i]=qr()]++;
	sort(a+1,a+n+1);
	for(register int i=1;i<=n;i++)
	{
		for(register int j=-205;j<=a[i];j++)
			ans+=(a[i]-j)*(a[i]-j)*mp[j];
	}
	// for(register int i=-200;i<=200;i++)
	// 	for(register int j=i;j<=200;j++)
	// 		if(mp[i]&&mp[j])
	// 			ans+=(LL)(j-i)*(j-i)*mp[i]*mp[j];
	cout<<ans<<endl;
	return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    vec_int A(N); rep(i,N)cin>>A.at(i);
    int ans = (int)pow(10,18);

    for(int i=0;i<(1<<(N-1));i++){
        int temp = A.at(0);
        int temp_ans = 0;

        int a = 1;
        for(int j=1;j<N;j++){
            if((i/a)%2==1){
                temp_ans = temp_ans^temp;
                temp = A.at(j);
            }else{
                temp = (temp | A.at(j));
            }
            a *= 2;
        }
        temp_ans = temp_ans^temp;
        ans = min(temp_ans, ans);

    }
    cout<<ans<<endl;

    return 0;
}


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

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

// using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }

const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}

struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int n;
  cin>>n;
  double x0,y0,xn2,yn2;
  cin>>x0>>y0>>xn2>>yn2;
  cout<<fixed<<setprecision(18);
  double theta= ((n-2.0))/(2.0*n);
  theta*=acos(-1);
  // cout<<theta<<endl;
  double v1=xn2-x0,v2=yn2-y0,v3,v4;
  v3=(v1+v2*tan(theta))*cos(theta)*cos(theta);
  v4=(-v1*tan(theta)+v2)*cos(theta)*cos(theta);
  // v3=(v3*v3)/(v1*v1),v4=(v4*v4)/(v2*v2);
  // cout<<v1<<" "<<v2<<endl;
  cout<<x0+v3<<" "<<y0+v4<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;

typedef long long LL;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1.0);

double N, a, b, c, d, e, f, A1, A2, A3, len;

int main() {
	cin >> N >> a >> b >> c >> d;
	e = (a+c)/2.0;
	f = (b+d)/2.0;
	if (a != c) {
		A1 = atan((b-d)/(a-c));
	} else {
		A1 = Pi / 2;
	}
	A2 = 2 * Pi / N;
	A3 = A1 + A2;
	len = sqrt((a-c)*(a-c) + (b-d)*(b-d)) / 2;
	if (a > c || (a == c && b > d)) A3 -= Pi;
	e -= len * cos(A3);
	f -= len * sin(A3);
	printf("%lf %lf", e, f);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) (sort(all(v)), v.erase(unique(all(v)), v.end()))
typedef long long ll;
typedef pair<ll, ll> p;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll X, Y; cin >> X >> Y;
	unordered_set<ll> visited;
	queue<p> q;
	q.push({ Y,0 });
	ll ans = (ll)1e18; visited.insert(Y);
	while (!q.empty()) {
		p cur = q.front(); q.pop();
		ll y = cur.x, cnt = cur.y;
		if (cnt >= ans) continue;
		if (y == X) {
			ans = min(ans, cnt); continue;
		}
		ans = min(ans, cnt + abs(y - X));
		if (y < X) continue;
		if (y % 2 == 0) {
			if (visited.find(y / 2) == visited.end()) {
				q.push({ y / 2,cnt + 1 });
				visited.insert(y / 2);
			}
		}
		else {
			if (visited.find(y + 1) == visited.end()) {
				q.push({ y + 1,cnt + 1 });
				visited.insert(y + 1);
			}
			if (visited.find(y - 1) == visited.end()) {
				q.push({ y - 1,cnt + 1 });
				visited.insert(y - 1);
			}
		}
	}
	cout << ans;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    ll X, Y;
    cin >> X >> Y;
    if (Y <= X) {
        cout << X - Y << endl;
        return 0;
    }
    unordered_map<ll, ll> memo;
    auto dfs = [&](auto&& self, ll current) -> ll {
        if (memo.find(current) != memo.end()) return memo[current];
        ll minCost = abs(current - X);
        if (X < current) {
            for (const int add : {1, -1}) {
                ll costDiff = 0, next = current;
                while (next % 2 != 0) {
                    next += add;
                    costDiff++;
                }
                next /= 2;
                costDiff++;
                assert(next < current);
                minCost = min(minCost, self(self, next) + costDiff);
            }
        }
        return memo[current] = minCost;
    };
    cout << dfs(dfs, Y) << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second
typedef long long ll;
using Graph = vector<vector<ll>>;

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

ll dp[2000][2000];
ll nCr(ll n, ll r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n%MOD;
       if(dp[n][r]) return dp[n][r]%MOD;
       return dp[n][r] = nCr(n-1,r)%MOD + nCr(n-1,r-1)%MOD;
}

ll H(ll n, ll r) {
    return nCr(n+r-1, r)%MOD;
}

int prime[10000000];
bool is_prime[100000000 + 1];

int sieve(int n) {
    int pcnt = 0;
    for(int i = 0; i <= n; i++) {
        is_prime[i] = true;
    }

    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++) {
        if(is_prime[i]) {
            prime[pcnt++] = i;
            for(int j = 2*i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }

    return pcnt;
}

struct UnionFind {
	//自身が親であれば、その集合に属する頂点数に-1を掛けたもの
	//そうでなければ親のid
	vector<ll> r;
	UnionFind(ll N) {
		r = vector<ll>(N, -1);
	}
	ll root(ll x) {
		if (r[x] < 0) return x;
		return r[x] = root(r[x]);
	}
	bool unite(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (r[x] > r[y]) swap(x, y);
		r[x] += r[y];
		r[y] = x;
		return true;
	}
	ll size(ll x) {
		return -r[root(x)];
	}

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

void solve1() {
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }

    ll ans = 1e18;
    rep(i, n) {
        ans = min(ans, a[i]+b[i]);
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(i != j)
                ans = min(ans, max(a[i],b[j]));
        }
    }

    cout << ans << endl;
}

int main()
{
    solve1();
}

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define int long long
#define ll int
#define all(a) a.begin(),a.end()
#define rev(a) a.rbegin(),a.rend()
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
const double pi=acosl(-1);

void solve()
{
	int n;
	cin>>n;
	vector<pair<int,int>> a(n);
	int ans=1e15;
	fi(0,n){
		cin>>a[i].first>>a[i].second;
	}
	fi(0,n)
	{
		fj(0,n)
		{
			if(i==j)
			{
				ans=min(ans,a[i].first+a[j].second);
			}
			else
			{
				ans=min(ans,max(a[i].first,a[j].second));
			}
		}
	}

	cout<<ans<<'\n';

}

signed main()
{
	FAST;
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
}

//int dx[] = {+1,-1,+0,+0,-1,-1,+1,+1}; // Eight Directions
//int dy[] = {+0,+0,+1,-1,+1,-1,-1,+1}; // Eight Directions
//int dx[]= {-2,-2,-1,1,-1,1,2,2}; // Knight moves
//int dy[]= {1,-1,-2,-2,2,2,-1,1}; // Knight moves
// For (a^b)%mod, where b is large, replace b by b%(mod-1).
// a+b = (a|b)+(a&b)
// a+b = 2*(a&b)+(a^b)