#include<bits/stdc++.h>
#define ll long long
#define reg register
#define mp make_pair
#define ri register int
#define ld long double
using namespace std;
const int mxn=2e5+5;
vector<int>g[mxn];
int n,m;
int a[mxn];
int dp[111][5555][111];//i sum cnt
const ll md=998244353;
ll frac[mxn];
inline void solve(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i],m=m+a[i];
	if(m%2==1){
		cout<<0<<'\n';
		return;
	}
	m=m/2;
	frac[0]=1;
	for(int i=1;i<=n;++i)frac[i]=(frac[i-1]*i)%md;
	dp[1][0][0]=1;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=m;++j){
			for(int k=0;k<=i;++k){
				if(dp[i][j][k])(dp[i+1][j+a[i]][k+1]+=dp[i][j][k])%=md;
				(dp[i+1][j][k]+=dp[i][j][k])%=md;
			}
		}
	}
	ll ans=0;
	for(int k=1;k<n;++k){
		if(dp[n+1][m][k]){
			ans=ans+dp[n+1][m][k]%md*frac[k]%md*frac[n-k]%md;
			ans%=md;
		}
	}
	cout<<ans<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;//cin>>T;
	for(;T--;)solve();
}

#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
char s[5005][5005];
ll dp[5005][5005][3],r[5005][5005],c[5005][5005],p[100005],hell=998244353;
map<char,ll> st;
void solve(){
	ll n,m,k;
	cin>>n>>m>>k;
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=m;j++)
			s[i][j]='0';
	for(ll i=0;i<k;i++){
		ll x,y;
		char c;
		cin>>x>>y>>c;
		s[x][y]=c;
	}
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=m;j++)
			if(s[i][j]=='0')
				r[i][j]=c[i][j]=1;
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=m;j++)
			r[i][j]+=r[i][j-1];
	for(ll j=1;j<=m;j++)
		for(ll i=1;i<=n;i++)
			c[i][j]+=c[i-1][j];
	st['R']=0;st['D']=1,st['X']=2;
	if(s[1][1]=='0')
		for(ll k=0;k<3;k++)
			dp[1][1][k]=1;
	else
		dp[1][1][st[s[1][1]]]=1;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=m;j++){
			if(i==1&&j==1)
				continue;
			ll val=0,sum=0;
			sum=(dp[i-1][j][1]+dp[i-1][j][2])%hell;
			sum=(sum*(p[r[i-1][m]-r[i-1][j]]))%hell;
			val=(val+sum)%hell;
			sum=(dp[i][j-1][0]+dp[i][j-1][2])%hell;
			sum=(sum*(p[c[n][j-1]-c[i][j-1]]))%hell;
			val=(val+sum)%hell;
			if(s[i][j]=='0')
				for(ll k=0;k<3;k++)
					dp[i][j][k]=val;
			else
				dp[i][j][st[s[i][j]]]=val;
			/*for(ll k=0;k<3;k++)
				cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;*/
		}
	}
	ll res=0;
	for(ll k=0;k<3;k++)
		res=(res+dp[n][m][k])%hell;
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    p[0]=1;
    for(ll i=1;i<100005;i++)
    	p[i]=(3*p[i-1])%hell;
    for(ll i=1;i<=qc;i++){
    	//cout<<"Case #"<<i<<": ";
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


#include <cstdio>
#define ll long long
using namespace std;
int n,m;ll p[5010],g[5010][5010],ans;
const ll mod=998244353;
int main()
{
	scanf("%d %d",&n,&m);
	p[0]=1;
	for(int i=1;i<=n;i++)
		p[i]=p[i-1]*m%mod;
	for(int i=0;i<=m;i++)
	{
		g[i][0]=1;
		for(int j=1;j<=n;j++)
			g[i][j]=g[i][j-1]*i%mod;
	}
	ans=p[n]*n%mod;
	for(int x=1;x<=m;x++)
		for(int j=1;j<n;j++)
			ans=(ans-(n-j)*g[m-x][j-1]%mod*p[n-j-1]%mod+mod)%mod;
	printf("%lld",ans);
}

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

// https://github.com/nweeks1/UltiSnips
template <const int32_t MOD> struct ModInt {
  long long x;
  ModInt() : x(0) {}
  ModInt(long long u) : x(u) {
    x %= MOD;
    if (x < 0)
      x += MOD;
  }
  friend bool operator==(const ModInt &a, const ModInt &b) {
    return a.x == b.x;
  }
  friend bool operator!=(const ModInt &a, const ModInt &b) {
    return a.x != b.x;
  }
  friend bool operator<(const ModInt &a, const ModInt &b) { return a.x < b.x; }
  friend bool operator>(const ModInt &a, const ModInt &b) { return a.x > b.x; }
  friend bool operator<=(const ModInt &a, const ModInt &b) {
    return a.x <= b.x;
  }
  friend bool operator>=(const ModInt &a, const ModInt &b) {
    return a.x >= b.x;
  }
  static ModInt sign(long long k) {
    return ((k & 1) ? ModInt(MOD - 1) : ModInt(1));
  }

  ModInt &operator+=(const ModInt &m) {
    x += m.x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt &m) {
    x -= m.x;
    if (x < 0LL)
      x += MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt &m) {
    x = (1LL * x * m.x) % MOD;
    return *this;
  }

  friend ModInt operator-(const ModInt &a) {
    ModInt res(a);
    if (res.x)
      res.x = MOD - res.x;
    return res;
  }
  friend ModInt operator+(const ModInt &a, const ModInt &b) {
    return ModInt(a) += ModInt(b);
  }
  friend ModInt operator-(const ModInt &a, const ModInt &b) {
    return ModInt(a) -= ModInt(b);
  }
  friend ModInt operator*(const ModInt &a, const ModInt &b) {
    return ModInt(a) *= ModInt(b);
  }

  static long long fp(long long u, long long k) {
    long long res = 1LL;
    while (k > 0LL) {
      if (k & 1LL)
        res = (res * u) % MOD;
      u = (u * u) % MOD;
      k /= 2LL;
    }
    return res;
  }

  static constexpr int mod() { return MOD; }

  ModInt fastpow(long long k) { return ModInt(fp(x, k)); }
  ModInt inv() {
    assert(x);
    return ModInt(fp(x, MOD - 2));
  }
  ModInt &operator/=(const ModInt &m) { return *this *= ModInt(m).inv(); }
  friend ModInt operator/(const ModInt &a, const ModInt &b) {
    return ModInt(a) *= ModInt(b).inv();
  }

  friend ostream &operator<<(ostream &out, const ModInt &a) {
    return out << a.x;
  }
  friend istream &operator>>(istream &in, ModInt &a) { return in >> a.x; }
};

// const int MOD = 1e9 + 7;
const int MOD = 998244353;
using Mint = ModInt<MOD>;

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

  int N, M;
  cin >> N >> M;

  vector<Mint> dp(N);
  vector<Mint> A(N);
  dp[0] = M;
  for (int i(1); i < N; ++i) {
    A[i] = A[i - 1] * M;
    Mint x = Mint(M - 1).fastpow(i - 1);
    for (int m(1); m <= M; ++m)
      A[i] += x - Mint(M - m).fastpow(i - 1);
    dp[i] = dp[i - 1] * M + M * Mint(M - 1).fastpow(i) + A[i];
  }

  cout << dp[N - 1] << endl;
}


#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <cmath>
using namespace std;

int main() {
long long int n;
cin>>n;
long long int ans=0;
long long int s=0;
for (int i = 1; i <= sqrt(2*n); i++)
{

 if ((2*n)%i==0)
 {

   if (i%2==1)
   {
     ans++;
   }
   else
   {
     if (((2*n)/i)%2==1)
     {
       ans++;
     }

   }

 }

}

cout<<ans*2-s<<endl;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;

const int maxn = 210;

int n;
ll dp[maxn][maxn];

ll read(){ ll s = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	n = read();
	dp[0][0] = 1;
	for(int i = 1 ; i < n ; ++i){
		for(int j = 1 ; j <= min(i, 11) ; ++j){
			for(int k = 0 ; k < i ; ++k){
				dp[i][j] += dp[k][j - 1];
			}
		}
	}

//	for(int i = 1 ; i < n ; ++i){
//		for(int j = 0 ; j <= min(i, 11) ; ++j){
//			printf("%d ", dp[i][j]);
//		} printf("\n");
//	}

	ll ans = 0;
	for(int i = 1 ; i < n ; ++i) ans += dp[i][11];
	printf("%lld\n", ans);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

// round for +inf
template<typename INT>
inline INT div_ceil(INT x,INT y){
    return (x<0?x/y:(x+y-1)/y);
}

// round for -inf
template<typename INT>
inline INT div_floor(INT x,INT y){
    return (x>0?x/y:(x-y+1)/y);
}

signed main(){
    ll N,AS,BS;cin>>N>>AS>>BS;
    vector<ll> A(N),B(N);
    cin>>A;

    vector<ll> L(N),H(N);
    auto check=[&](ll t){
        ll LS=0,HS=0;
        rep(i,N){
            L[i]=div_ceil(BS*A[i]-t,AS);
            H[i]=div_floor(BS*A[i]+t,AS);
            LS+=L[i];
            HS+=H[i];
        }
        return LS<=BS and BS<=HS;
    };

    ll lw=0,hi=LINF,res=LINF;
    while(lw<=hi){
        ll mid=(lw+hi)/2;
        if(check(mid)) res=mid,hi=mid-1;
        else           lw=mid+1;
    }
    check(res);
    auto ans=L;
    for(auto &x:ans) BS-=x;
    rep(i,N){
        ll y=H[i]-L[i];
        if(BS<=y) ans[i]+=BS,BS=0;
        else      BS-=y,ans[i]+=y;
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using ll = unsigned long long;

struct Town
{
	ll val = 0ULL;
	ll a = 0ULL;
	ll b = 0ULL;
};

bool operator<( const Town& lhs, const Town& rhs )
{
	return lhs.val < rhs.val;
}

vector<Town> in;

int main()
{
	int n;
	cin >> n;
	ll sumA = 0ULL;
	for(int i=0; i<n; i++) {
		Town t;
		cin >> t.a >> t.b;
		t.val = t.a * 2 + t.b;
		in.push_back(t);
		sumA += t.a;
	}
	sort( in.rbegin(), in.rend() );
	int res = 0;
	ll sumB = 0ULL;
	while( sumA >= sumB ) {
		sumB += in[res].a + in[res].b;
		sumA -= in[res].a;
		res++;
	}
	cout << res << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[300005];
ll suffix[300005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) cin>>arr[i];
	for(int i=n; i>=1; i--) suffix[i] = suffix[i+1]+arr[i];
	ll ans = 0;
	for(int i=1; i<=n; i++){
		ll sq = arr[i]*arr[i];
		ans+=sq*(i-1);
		ans+=sq*(n-i);
		ans-=2*arr[i]*suffix[i+1];
	}
	cout<<ans;
}

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vec num(401, 0);
    cin>>N;
    rep(i, N){
        cin>>A;
        ++num[A + 200];
    }
    ll res{};
    rep(i, 401){
        rep(j, i){
            res += num[i] * num[j] * (j - i) * (j - i);
        }
    }
    cout<<res<<endl;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

void solve() {
	ll n, a, b; cin >> n >> a >> b;
	if (a + b > n) {
		cout << 0 << "\n"; return;
	}
	if (a < b)swap(a, b);
	modint al = 1;
	al *= (n - a + 1) * (n - a + 1);
	al *= (n - b + 1) * (n - b + 1);
	auto calc = [&](ll x)->ll {
		return x * (x + 1) / 2;
	};
	modint c = (a) * (n+1 - a - b);
	c += calc(a) - calc(a - b);
	c += calc(b-1);
	c += (n + 1 - a - b) * (b - 1);
	modint ans = al - c*c;
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
// const ll MOD = 1000000007LL;
const ll MOD = 998244353LL;
const ll INF = 1LL << 60;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int dy2[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx2[] = {1, 1, 0, -1, -1, -1, 0, 1};
// ios::sync_with_stdio(false);
// cin.tie(nullptr);

/*--------------------------------------------------------------------------------
--------------------------------------------------------------------------------*/

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

mint dp[6005][6005];

int main(){
    ll n, k;
    cin >> n >> k;
    dp[1][1] = 1;
    rep(i, 1, n+1){
        repr(j, 1, n+1){
            if(i < j) continue;
            dp[i][j] += dp[i-1][j-1] + dp[i][j*2];
        }
    }
    cout << dp[n][k] << endl;

    return 0;
}


//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <cassert>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define pqueue priority_queue
#define pb(x) push_back(x)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long  long

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;

const int inf = 1e9 + 228;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-5;

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("grass.in", "r", stdin);
//    freopen("grass.out", "w", stdout);
}

bool cmp(pii a, pii b){
    return a.first + a.second * 2 >= b.first + b.second * 2;
}

void solve(){
    int n;
    cin >> n;
    vpii kek(n);
    for(pii &i:kek)
        cin >> i.second >> i.first;
    int ans1 = 0;
    for(pii i:kek)
        ans1 += i.second;
    vi lol;
    for(pii i:kek)
        lol.pb(i.first + i.second * 2);
    sort(all(lol));
    reverse(all(lol));
    for(int i=0; i<n; i++){
        ans1 -= lol[i];
        if(ans1 < 0){
            cout << i + 1 << endl;
            return;
        }
    }
    cout << n << endl;
}

signed main(){
  fast_io();
//  srand(time(NULL));
//  cout << fixed << setprecision(3);
  int q = 1;
//  cin >> q;
  while(q--)
    solve();
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N;
    ll A[N], B[N]; F0R(i, N) cin >> A[i] >> B[i];
    vl ops; ll sum = 0;
    F0R(i, N) {
        sum += A[i]; ops.pb(2*A[i] + B[i]);
    }
    sort(all(ops)); reverse(all(ops));
    int ans = 0;
    F0R(i, N) {
        ans++; sum -= ops[i];
        if (sum < 0) break;
    }
    cout << ans << nl;

	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


#include<iostream>
using namespace std;
int main(){
  int n;
  long long cnt=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n/i;j++){
      for(int k=1;k<=n/i/j;k++){
	cnt++;
      }
    }
  }
  cout<<cnt<<endl;
  return(0);
}

#include<iostream>
#include<utility>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define forn(i, x, n) for(int i = x; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;
const bool DEBUG = 0;

vector<int> primes;
vector<int> lp(2e5+1);

void sieve(){
    forn(i, 2, lp.size()){
        if(lp[i] == 0){
            lp[i] = i;
            primes.push_back(i);
        }
        for(int j = 0; j < primes.size() && primes[j] <= i && primes[j]*i < lp.size(); j++){
            lp[primes[j]*i] = primes[j];
        }
    }

}

void solve(){
    int k;
    cin>>k;
    sieve();
    ll ans = 1;
    forn(i, 2, k+1){
        ll prod = 1;
        for(ll tmp = i, x = lp[tmp]; tmp > 1; x = lp[tmp]){
            ll p = 0;
            while(tmp%x == 0) tmp /= x, p++;
            if(DEBUG) cout<<i<<' '<<p<<'\n';
            prod  *= (p+2)*(p+1)/2;
        }
        if(DEBUG) cout<<prod<<'\n';
        ans += prod;
    }
    cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
    //cin>>t;
	//while(t--) cout<<solve()<<'\n';
	while(t--) solve(), cout<<'\n';

}


#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=2010;
const ll mod=1e9+7;
char g[N][N];
int n,m;
ll base[N*N];
int w[N][N];
int main()
{
    IO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++) cin>>g[i]+1;

        int cnt=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++) cnt+=(int)g[i][j]=='.';

        base[0]=1;
        for(int i=1;i<=cnt;i++) base[i]=base[i-1]*2%mod;
        ll res=0;
        for(int i=1;i<=n;i++)
        {
            int j=1;
            while(j<=m)
            {
                while(g[i][j]=='#') j++;

                int now=1,k=1;
                while(j+k<=m&&g[i][j+k]=='.') now++,k++;
                for(int p=j;p<j+k;p++) w[i][p]+=now;
                j=j+k;
            }
        }
        for(int i=1;i<=m;i++)
        {
            int j=1;
            while(j<=n)
            {
                while(g[j][i]=='#') j++;
                int now=1,k=1;
                while(j+k<=n&&g[j+k][i]=='.') now++,k++;
                for(int p=j;p<j+k;p++) w[p][i]+=now;
                j=j+k;
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(g[i][j]=='#') continue;
                int now=w[i][j]-1;
                res=(res+(base[now]-1)*base[cnt-now]%mod)%mod;

            }
        }

        cout<<(ll)(res+mod)%mod<<'\n';

    }
    return 0;
}

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

using namespace std;

using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

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

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

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

#if 1

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

  int N, M; cin >> N >> M;
  vv(vi) es(N, vvi(26));
  F0R(i, M) {
    int a, b; char c; cin >> a >> b >> c;
    a--; b--;
    es[a][c-'a'].push_back(b);
    es[b][c - 'a'].push_back(a);
  }
  //
  int inf = INT32_MAX / 2;
  vvi dp(N, vi(N, inf));
  dp[0][N - 1] = 0;
  queue<pii> qu;
  qu.emplace(0, N - 1);
  int step = 0;
  while (sz(qu)) {
    queue<pii> nq;
    while (sz(qu)) {
      auto [u, v] = qu.front(); qu.pop();
      if (dp[u][v] < step) continue;
      //cout << (u + 1) << '-' << (v + 1) << newl;
      F0R(c, 26) {
        for (auto to : es[u][c]) {
          for (auto to2 : es[v][c]) {
            if (dp[to][to2] <= step + 1) continue;
            dp[to][to2] = step + 1;
            nq.emplace(to, to2);
          }
        }
      }
    }
    qu = move(nq);
    step++;
  }
  cout << (dp[N - 1][0] >= inf ? -1 : dp[N- 1][0]) << newl;
}
#endif


#include<bits/stdc++.h>
#define endl '\n'
#define ri register
#define QAQ(m,n) for(ri int i=m;i<=n;i++)
#define QWQ(m,n) for(ri int j=m;j<=n;j++)
typedef long long ll;
using namespace std;

int main ()
{
	double a, b;
	cin >> a >> b;
	cout << (a - b) / a*100 << endl;
	return 0;
}

#include <iostream>
using namespace std;

typedef long long ll;

int main () {
	int H, W;
	int min = 101;
	int sum = 0;
	cin >> H >> W;
	for (int h=0; h<H; h++) {
		for (int w=0; w<W; w++) {
			int tmp;
			cin >> tmp;
			sum += tmp;
			if (tmp < min)
				min = tmp;
		}
	}
	cout << sum - min*H*W << endl;
	return 0;
}


//g++  7.4.0

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

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

    //A + k*B <= D*C*k
    //A/(D*C - B) <= k;

    ll A,B,C,D; cin>>A>>B>>C>>D;
    ll num = A;
    ll den = D*C - B;
    if(den <= 0)
        cout<<-1<<endl;
    else
        cout<<(num + den - 1)/den<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (ll)1000000007
#define pi 3.14159265358979323846264338327
#define pii pair<int,int>
#define pll pair<ll,ll>
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll power(ll a,ll b){ll ret=1;while(b){if(b%2)ret=ret*a%MOD;a=a*a%MOD;b/=2;}return ret;}
const int sz = 1<<17;

int a[20];
int num[30];

int f(int s,int n)
{
    int ret=0;
    for(int i=0;i<n;i++)
        if((1<<i)&s)ret|=a[i];
    return ret;
}

double dist(double x0,double y0, double x1, double y1)
{
    return (x0-x1)*(x0-x1)+(y0-y1)*(y0-y1);
}

int main()
{
    int n;scanf("%d",&n);
    double x0,y0,xh,yh;
    scanf("%lf %lf %lf %lf",&x0,&y0,&xh,&yh);
    double xm=(x0+xh)/2.0, ym=(y0+yh)/2.0;
    x0-=xm,y0-=ym;
    double degree=pi*2.0/(double)n;
    double nx=x0*cos(degree)-y0*sin(degree);
    double ny=x0*sin(degree)+y0*cos(degree);

    printf("%lf %lf",nx+xm,ny+ym);
    return 0;
}


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

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt=1;
	//cin >> tt;
	while(tt--)
	{
		int n;
		cin >> n;
		int a[n],b[n];
		for(int i=0;i<n;i++)
			cin >> a[i];
		for(int i=0;i<n;i++)
			cin >> b[i];
		pair<int,int> odd[n/2], even[n/2];
		for(int i=0;i<n;i++)
		{
			if(i%2==0)
				even[i/2]={a[i]-b[i],i};
			else
				odd[i/2]={a[i]-b[i],i};
		}
		sort(even,even+n/2);
		sort(odd,odd+n/2);
		int ans=0;
		for(int i=n/2-1;i>=0;i--)
		{
			if(even[i].first+odd[i].first>=0)
			{
				ans+=a[even[i].second]+a[odd[i].second];
			}
			else
			{
				ans+=b[even[i].second]+b[odd[i].second];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <list>
#include <algorithm>
#include <string.h>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
    int n;
    cin >> n;
    vector<long long> a(n);
    long long cu = 0;
    for (int i = 0; i < n; i++)
    {
        //  行かなきゃ-A,行けば+A+B
        //  行くと+2A+B
        long long x, y;
        cin >> x >> y;
        a[i] = 2 * x + y;
        cu -= x;
    }
    sort(a.begin(), a.end());

    for (int i = n - 1; i >= 0; i--)
    {
        cu += a[i];
        if (cu > 0)
        {
            printf("%d", n - i);
            return 0;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>

using std::cin;
using std::cout;
using std::endl;
using std::sort;
using std::string;
using std::vector;
// using namespace atcoder;
typedef long long ll;

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl;
#else
#define DEBUG(x)
#endif

#define ALL(obj) (obj).begin(), (obj).end()
#define BIT(n) (1LL << (n))

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

const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    // write code below
    int n, q;
    string s;
    cin >> n >> s >> q;

    bool flip = false;

    REP(i, q)
    {
        int t, a, b;
        cin >> t >> a >> b;
        a--;
        b--;
        if (t == 1)
        {
            if (flip)
            {
                if (a >= n)
                {
                    a %= n;
                }
                else
                {
                    a += n;
                }
                if (b >= n)
                {
                    b %= n;
                }
                else
                {
                    b += n;
                }
            }

            std::swap(s[a], s[b]);
        }
        else
        {
            flip = !flip;
        }
    }

    string l = s.substr(0, n), r = s.substr(n);

    if (flip)
    {
        cout << r + l << endl;
    }
    else
    {
        cout << l + r << endl;
    }

    // write code above
    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ll long long
#define dbwt(x) std::cout << fixed << setprecision(15) << x << '\n'
#define Wt(x) cout << x << '\n'
#define re0 return 0
#define Int(...) int __VA_ARGS__; in(__VA_ARGS__)
#define Ll(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; in(__VA_ARGS__)
#define Vec(t,a,s) vector<t>a(s); in(a)
#define Vec2(t,a,b,s) vector<t>a(s),b(s);rep(i,0,s)in(a[i],b[i])
#define Vec3(t,a,b,c,s) vector<t>a(s),b(s),c(s);rep(i,0,s)in(a[i],b[i],c[i])
#define Vec4(t,a,b,c,d,s) vector<t>a(s),b(s),c(s),d(s);rep(i,0,s) in(a[i],b[i],c[i],d[i])
#define mvec(t,a,i) vector<t>(a,i)
#define mvec2(t,a,b,i) vector<vector<t>>(a,vector<t>(b,i))
void scan(int& x) {std::cin >> x;}
void scan(ll& x) {std::cin >> x;}
void scan(double& x) {std::cin >> x;}
void scan(std::string& x) {std::cin >> x;}
void scan(std::vector<int>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void scan(std::vector<ll>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void in(){}
template<class Head, class... Tail>
void in(Head& head, Tail&... tail) {scan(head); in(tail...);}
template<class T, class U>
bool chmax(T& a, U b) {if(a < b){a=b; return true;} return false;}
template<class T, class U>
bool chmin(T& a, U b) {if(a > b){a=b; return true;} return false;}
using namespace std;
template<class T>
using vvec = vector<vector<T>>;

const int INF = 1001001001;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int main() {
    Int(H, W);
    vector<string> a(H);
    rep (i, 0, H) cin >> a[i];

    int sx, sy, gx, gy;
    set<int> st[26];
    rep (i, 0, H) rep (j, 0, W) {
        if (a[i][j] == 'S') sy = i, sx = j;
        if (a[i][j] == 'G') gy = i, gx = j;
        if ('a' <= a[i][j] && a[i][j] <= 'z') {
            st[a[i][j] - 'a'].insert(i * W + j);
        }
    }

    vector<bool> visited(26, false);
    vvec<int> dist(H, vector<int>(W, INF));
    dist[sy][sx] = 0;
    queue<int> Q;
    Q.push(sy * W + sx);
    while (!Q.empty()) {
        int v = Q.front(); Q.pop();
        int vx = v % W;
        int vy = v / W;
        if ('a' <= a[vy][vx] && a[vy][vx] <= 'z' && !visited[a[vy][vx] - 'a']) {
            visited[a[vy][vx] - 'a'] = true;
            st[a[vy][vx] - 'a'].erase(v);

            rep (i, 0, 4) {
                int x = vx + dx[i];
                int y = vy + dy[i];
                if (y < 0 || y >= H || x < 0 || x >= W || a[y][x] == '#') {
                    continue;
                }
                if (chmin(dist[y][x], dist[vy][vx] + 1)) {
                    Q.push(y * W + x);
                }
            }
            for (auto idx = st[a[vy][vx] - 'a'].begin(); idx != st[a[vy][vx] - 'a'].end(); ++idx) {
                int x = *idx % W;
                int y = *idx / W;
                if (chmin(dist[y][x], dist[vy][vx] + 1)) {
                    Q.push(y * W + x);
                }
            }
        }
        else {
            rep (i, 0, 4) {
                int x = vx + dx[i];
                int y = vy + dy[i];
                if (y < 0 || y >= H || x < 0 || x >= W || a[y][x] == '#') {
                    continue;
                }
                if (chmin(dist[y][x], dist[vy][vx] + 1)) {
                    Q.push(y * W + x);
                }
            }
        }
    }

    if (dist[gy][gx] == INF) Wt(-1);
    else Wt(dist[gy][gx]);
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
clock_t t2;
#define MAX_V 600002
struct edge{ int to,cap,rev; };
vector<edge> G[MAX_V];
int level[MAX_V],iter[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> Q;
  level[s] = 0;
  Q.push(s);
  while(!Q.empty()){
    int v = Q.front(); Q.pop();
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      edge &e = G[v][i];
      if(e.cap > 0 && level[e.to] < 0){
        level[e.to] = level[v] + 1;
        Q.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v == t) return f;
  for(int &i = iter[v] ; i < (int)G[v].size() ; i++){
    edge &e = G[v][i];
    if(e.cap > 0 && level[v] < level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll n;
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    clock_t t3=clock();
    double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
    if((double)t3/CLOCKS_PER_SEC+t4*2>1.997) {
      pr(n);
      exit(0);
    }
    bfs(s);
    if(level[t] < 0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f = dfs(s,t,MAX)) > 0){
      flow += f;
    }
  }
}

void Main() {
  t2=clock();
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  rep(i,n) a[i].F--,a[i].S--;
  rep(i,n) {
    add_edge(600000,i,1);
    add_edge(i,n+a[i].F,1);
    if(a[i].F!=a[i].S) add_edge(i,n+a[i].S,1);
  }
  rep(i,400000) add_edge(n+i,600001,1);
  pr(max_flow(600000,600001));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

#line 1 "main.cpp"
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int par[400010], rankh[400010], siz[400010], edge[400010];
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		rankh[i] = 0;
		siz[i] = 1;
		edge[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) {
		edge[x]++;
		return;
	}
	if (rankh[x] < rankh[y]) {
		par[x] = y;
		siz[y] += siz[x];
		edge[y] += edge[x] + 1;
	}
	else {
		par[y] = x;
		if (rankh[x] == rankh[y])rankh[x]++;
		siz[x] += siz[y];
		edge[x] += edge[y] + 1;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int size(int x) {
	return siz[find(x)];
}
int edges(int x) {
	return edge[find(x)];
}
int n, a[200010], b[200010];
map<int, int> mp;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i] >> b[i];
		mp[a[i]] = 0;
		mp[b[i]] = 0;
	}
	int cnt = 1;
	for (pair<const int, int>& p : mp) {
		p.second = cnt;
		cnt++;
	}
	init(mp.size());
	rep(i, n) {
		unite(mp[a[i]], mp[b[i]]);
	}
	set<int> st;
	int ans = 0;
	REP(i, mp.size()) {
		if (st.find(find(i)) != st.end())continue;
		ans += min(edges(i), size(i));
		st.insert(find(i));
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
const int N=2e6+1;
ll n,m;
ll a[N],b[N];
void solve(){
	cin >> n >> m;
	for(int i=1; i<=n ;i++){
		ll x;cin >> x;a[x]++;
	}
	ll ans=0;
	for(int i=0; i<=n+10 ;i++){
		m=min(m,a[i]);
		ans+=m;
	}
	cout << ans << '\n';
	//for(int i=1; i<=n ;i++) cout << a[i]*b[i] << ' ';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	//int t;cin >> t;while(t--) solve();
	solve();
}

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
//const int MOD = (int) 1e9 + 7;
const int MOD = 119 << 23 | 1;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
inline int mrand(int k) {return abs((int) mt()) % k;}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

void chemthan() {
    int n, k; cin >> n >> k;
    map<int, int> hs;
    FOR(i, 0, n) {
        int x; cin >> x;
        hs[x]++;
    }
    map<int, vi> g;
    for (auto [x, c] : hs) {
        FOR(i, 0, min(c, k)) {
            g[i].pb(x);
        }
    }
    auto calc = [&] (vi v) {
        map<int, int> tmp;
        for (int x : v) {
            tmp[x] = 1;
        }
        int res = 0;
        while (tmp[res]) res++;
        return res;
    };
    int res = 0;
    FOR(i, 0, k) {
        res += calc(g[i]);
    }
    cout << res << "\n";
}

int32_t main(int32_t argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
const int N = 1010;
const int M = 3200;
const int mod = 998244353;

int a[2];
void solve() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cnt = 0;
        for (int j = 0; j < s.length(); ++j) {
            cnt += s[j] - '0';
        }
        a[cnt & 1]++;
    }
    printf("%lld\n", a[0] * 1ll * a[1]);
}

int main() {
#ifdef HAMLET
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
    return 0;
}

#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define ll long long
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;
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; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
using vvv = vector<vector<vector<ll>>>;
using vv = vector<vector<ll>>;
using vec = vector<ll>;
using P = pair<ll, ll>;

int main(void) {
    ll n, m; cin >> n >> m;
    ll cnt = 0;
    string start; cin >> start;
    vector<bool> ml(n - 1);
    rep(i, n - 1){
        string s; cin >> s;
        ll match = 0;
        rep(j, m){
            if(s[j] == start[j]) match++;
        }
        if(m % 2 && match % 2 == 0){
            ml[i] = 1;
            cnt++;
        }
        if(m % 2 == 0 && match % 2){
            ml[i] = 1;
            cnt++;
        }
        //cout << ml[i] << endl;
    }
    ll ans = cnt;
    ll unMatch = n - cnt - 1;
    rep(i, n - 1){
        if(ml[i] == 1){
            ans += unMatch;
            cnt--;
        }
        else{
            ans += cnt;
            unMatch--;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define mii map<int, int>
#define pii pair<int, int>
#define qii priority_que<int, vector<int>, greater<int>>
#define For(i, n) for(int i = 0; i < n; ++i)
#define For1(i, n) for(int i = 1; i <= n; ++i)
#define Forlr(i, l, r) for(int i = l; i <= r; ++i)
#define Forrl(i, r, l) for(int i = r; i >= l; --i)
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) {For(i, a.size()) cout << a[i] <<" ";}
#define ovv(a) {For(i, a.size()) {For(j, a[i].size()) cout << a[i][j] <<" ";cout <<"\n";}}
using ll = long long;
int n, m, k, q;
const int INF = 1e9 + 5;
const int nax = 1e5 + 5;
pair<int, int> a[5 * nax];
int g[1505][1505];
ll rs = 0;
void dfs(int x, int y){
	int nx = x, ny = y;
	if(!g[nx][ny]) rs ++, g[nx][ny] = 3;
	while(1){
		nx ++;
		if(nx <= n && g[nx][ny] != 1 && g[nx][ny] != 3){
			if(!g[nx][ny]) rs ++;
			g[nx][ny] = 1;
		}
		else{
			break;
		}
	}
	nx = x;
	while(1){
		nx --;
		if(nx >= 1 && g[nx][ny] != 1 && g[nx][ny] != 3){
			if(!g[nx][ny]) rs ++;
			g[nx][ny] = 1;
		}
		else{
			break;
		}
	}
	nx = x;
	while(1){
		ny ++;
		if(ny <= m && g[nx][ny] != 3  && g[nx][ny] != 2){
			if(!g[nx][ny]) rs ++;
			g[nx][ny] = 2;
		}
		else{
			break;
		}
	}
	ny = y;
	while(1){
		ny --;
		if(ny >= 1 && g[nx][ny] != 3  && g[nx][ny] != 2){
			if(!g[nx][ny]) rs ++;
			g[nx][ny] = 2;
		}
		else{
			break;
		}
	}
}
int main()
{
	fast();
	cin >> n >> m;
	int na, nb;
	cin  >> na >> nb;
	For(i, na){
		cin >> a[i].first >> a[i].second;
	}
	For(i, nb){
		int x, y;
		cin >> x >> y;
		g[x][y] = 3;
	}
	For(i, na){
		dfs(a[i].first, a[i].second);
	}
	// For(i, n){
	// 	For(j, m){
	// 		cout << g[i + 1][j + 1] <<" ";
	// 	}
	// 	cout <<"\n";
	// }
	cout << rs;
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<ll,ll>;
const ll INF = 1e18;

ll N, M, S, T;
vector<tuple<ll,ll,ll,ll>> edge;

//経路復元なしDijkstra法
vector<ll> dijkstra(ll start, const vector<vector<pair<ll,ll>>>& Hen){

	ll N = Hen.size();
	vector<ll> dist(N, INF);
	dist[start] = 0;
	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
	que.push({0, start});
	while(que.size()) {
		ll ver = que.top().second;
		ll cost = que.top().first; que.pop();
		if(cost != dist[ver])continue;

		for(auto i : Hen[ver]) {
			auto [u, v, t, k] = edge[i.second]; //t := 長さ, k := インターバル
			auto req = cost + (k - cost % k) % k + t;

			if(dist[i.first] > req) {
				dist[i.first] = req;
				que.push({dist[i.first], i.first});
			}
		}
	}
	return dist;
}

int main()
{
	cin >> N >> M >> S >> T;
	edge.resize(M);
	vector<vector<pair<ll,ll>>> hen(N);
	S--,T--;
	for(ll i = 0; i < M; i++) {
		ll u, v, t, k ;cin >> u >> v >> t >> k;
		u--,v--;
		hen[u].push_back({v, i});
		hen[v].push_back({u, i});
		edge[i] = {u, v, t, k};
	}

	auto dist = dijkstra(S, hen);
	cout << (dist[T] == INF ? -1 : dist[T])<< endl;

}


#include <cstring>
#include <cstdlib>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define ABS(a) ((a)<0?(-(a)):(a))
#define CS while(cases())
#define I(n) int n = gi()
#define II(n) n = gi()
#define L(n) ll n = gli()
#define LL(n) n = gli()
#define F(i, n) for (int i = 0; i < n; i++)
#define Fa(n, a) for (int i = 0; i < n; i++) a[i] = gi()
#define R(i, n) for (int i = n-1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

template<class T>
T gcd(T a, T b) {
    return (b == 0 ? a : gcd(b, a%b));
}

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int cases() {
    static int t = gi();
    return t--;
}

#define MD 1000000007
int mx[200004];
int mn[200004];

void upd(map<int, ll> &m, int k, ll v) {
    if (m.find(k) == m.end() || v < m[k])
        m[k] = v;
}

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

    I(n);
    F(i, n) {
        mn[i] = MD;
        mx[i] = -MD;
    }

    F(i, n) {
        I(x);
        I(c) - 1;
        mn[c] = min(mn[c], x);
        mx[c] = max(mx[c], x);
    }

    map<int, ll> m;
    m[0] = 0;
    F(i, n) if (mn[i] != MD) {
        map<int, ll> m2;
        for (auto &it : m) {
            upd(m2, mx[i], it.second + ABS(mn[i] - it.first) + mx[i] - mn[i]);
            if (mx[i] != mn[i])
                upd(m2, mn[i], it.second + ABS(mx[i] - it.first) + mx[i] - mn[i]);
        }
        m = m2;
    }

    ll res = 100000000000000000LL;
    for (auto &it : m)
        res = min(res, it.second + ABS(it.first));

    cout << res << endl;

    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb                    push_back
#define ll                    long long
#define ld                    long double
#define sz(x)                 (ll)x.size()
#define vll                   vector<long long>

#define infi                  INT_MAX
#define infl                  LONG_LONG_MAX
#define infd                  LDBL_MAX
#define f(i,a,b)              for(ll i=a;i<b;i++)
#define fi(i,a,b)             for(ll i=(b-1);i>=a;i--)
#define F                     first
#define S                     second
#define G(a,b)                get<a>(b)
#define MP                    make_pair
#define MT                    make_tuple
#define pll                   pair<ll,ll>
#define endl                  "\n"
#define ALL(v)                v.begin(),v.end()
#define nl                    cout<<"\n";
#define deb                   cout<<"***************************************************************************************\n";
#define moshi                 cout<<"moshi moshi ! \n";
#define hi                    cout<<"hi ! \n";
#define bye                   cout<<"bye bye ! \n";
#define kawai                 cout<<"O kawai koto ! \n";
#define o_set                 tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll
#define eb                    emplace_back
const ld PI=3.1415926535897932384626433;

template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T> >;

auto clk=clock();
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 <<"\n";
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

//**********************************************************  Code begins  ***********************************************

// trick for traversing all submasks
// for (ll j=mask ;j; j=(j-1)&mask)  // also include 0 manually
// v.resize(unique(v.begin(), v.end()) - v.begin());    // remove duplicates

const ll N=1e5+5;
ll n,m,k,a[N],mn[N],mx[N],b[N];

ll ceil(ll p,ll q)
{
    ll res=(p+q-1)/q;
    return res;
}

bool can(ll d)
{
    ll small=0,big=0;
    f(i,1,k+1)
    {
        mn[i]=ceil(-d+a[i]*m,n);
        mx[i]=(d+a[i]*m)/n;
        small+=mn[i];
        big+=mx[i];
    }

    return (small<=m && big>=m);
}

void help(ll d)
{
    ll small=0,big=0,extra=m;
    f(i,1,k+1)
    {
        mn[i]=ceil(-d+a[i]*m,n);
        mx[i]=(d+a[i]*m)/n;
        small+=mn[i];
        big+=mx[i];
        extra-=mn[i];
    }

    f(i,1,k+1)
    {
        ll give=mx[i]-mn[i],take=min(give,extra);
        extra-=take;
        b[i]=mn[i]+take;
    }
}

void solve()
{
    cin>>k>>n>>m;
    f(i,1,k+1) cin>>a[i];
    ll lef=0,rig=1e18,mid,res=-1;
    while(lef<=rig)
    {
        mid=(lef+rig)>>1;
        if(can(mid)) res=mid,rig=mid-1;
        else lef=mid+1;
    }
    help(res);
    f(i,1,k+1) cout<<b[i]<<" ";
    nl
}

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

    ll test_cases=1;
    //cin>>test_cases;

    f(i,1,test_cases+1)
    {
        solve();
        //clr();
    }

    #ifdef rd
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif

    return 0;
}


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

constexpr int M = 998244353;

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        long long u = x / y;
        long long x0 = y; y = x - y * u; x = x0;
        long long r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

int main() {
    int n, m; cin >> n >> m;
    long long ans = 0;
    const int mi = modinv(m, M);
    if (n == 1) { cout << m << endl; return 0; }
    for (int v = 1; v <= m; v++) {
        long long p = m - v + 1, q = m - v, mm = modexp(m, n-2, M);
        for (int r = 0; r < n; r++) {
            ans += (p - q) * (r == n - 1 ? 1 : (v - 1) * mm % M) % M;
            p = p * (m - v + 1) % M;
            q = q * (m - v) % M;
            mm = mm * mi % M;
        }
    }
    for (int v = 1; v <= m; v++) {
        long long p = m - v + 1, q = m - v, mm = modexp(m, n-2, M);
        for (int l = n-1; l > 0; l--) {
            ans += (p - q) * (v - 1) % M * mm % M;
            p = p * (m - v + 1) % M;
            q = q * (m - v) % M;
            mm = mm * mi % M;
        }
    }
    if (n > 2) {
        for (int v = 1; v <= m; v++) {
            long long p = m - v + 1, q = m - v, mm = modexp(m, n-3, M);
            for (int d = 0; d <= n-3; d++) {
                ans += ((long long)(n - d - 2) * (v - 1) * (v - 1) % M *
                        (p - q) % M * mm % M);
                p = p * (m - v + 1) % M;
                q = q * (m - v) % M;
                mm = mm * mi % M;
            }
        }
    }
    cout << (ans % M + M) % M << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename A, typename B = A> using pr = pair<A, B>;
#define vec vector
#define ar array
#define len(a) ((int)((a).size()))
#define all(a) (a).begin(), (a).end()

const int mod = 998244353;

struct mint {
    int val;

    explicit mint() : val(0) {}
    explicit mint(int val) : val(val) {}

    inline mint operator + (mint m) {
        int sum = val + m.val;
        if (sum >= mod)
            sum -= mod;
        return mint(sum);
    }

    inline mint operator - (mint m) {
        int sum = val - m.val;
        if (sum < 0)
            sum += mod;
        return mint(sum);
    }

    inline mint operator * (mint m) {
        return mint(1ll * val * m.val % mod);
    }

    friend ostream& operator << (ostream &out, mint m) {
        return out << m.val;
    }
};

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

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

    vec<vec<mint>> val(m + 1, vec<mint>(n + 1));
    for (int i = 0; i <= m; i++)
        val[i][0] = mint(1);
    for (int j = 1; j <= n; j++)
        for (int i = 1; i <= m; i++)
            val[i][j] = val[i][j - 1] * mint(i);

    vec<vec<mint>> pref(m + 1, vec<mint>(n + 1));
    for (int j = 0; j <= n; j++) {
        pref[0][j] = val[0][j];
        for (int i = 1; i <= m; i++)
            pref[i][j] = pref[i - 1][j] + val[i][j];
    }

    mint ans = mint(n) * val[m][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < i; j++)
            ans = ans - pref[m - 1][i - j - 1] * val[m][n - i + j - 1];
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
using ull = unsigned long long;
#define loop(n) for(ull i=0;i<n;i++)

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


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef int ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

bool comp(pii a, pii b)
{
    return a.ff-a.ss>b.ff-b.ss;
}

void dfs(ll curr, ll par, vector<ll> v[], vector<pii> &dp, vector<ll> &tur)
{
    vector<pii> hold[2];
    dp[curr] = mp(0, 1);
    tur[curr] = 0;

    autoit(v[curr],it)
    {
        if(*it == par)
            continue;
        dfs(*it, curr, v, dp, tur);
        tur[curr]^=((dp[*it].ff + dp[*it].ss)%2);
        hold[tur[*it]^1].pb(dp[*it]);
    }

    vector<pii> temp;
    if(hold[0].size()>0){
        autoit(hold[0],it)
        {
            if(it->ff>=it->ss)
                dp[curr].ff+=it->ff, dp[curr].ss+=it->ss;
            else temp.pb(*it);
        }
    }

    hold[0] = temp;
    if((ll)hold[1].size()>1)
        sort(hold[1].begin(), hold[1].end(), comp);
    ll t11 = 0;
    if(hold[1].size()>0){
        autoit(hold[1],it)
        {
            if(t11 == 0)
                dp[curr].ff+=it->ff, dp[curr].ss+=it->ss;
            else dp[curr].ff+=it->ss, dp[curr].ss+=it->ff;
            t11^=1;
        }
    }
    if(hold[0].size()>0){
        if(t11 == 0){
            autoit(hold[0],it)
                dp[curr].ff+=it->ff, dp[curr].ss+=it->ss;
        }
        else{
            autoit(hold[0],it)
                dp[curr].ff+=it->ss, dp[curr].ss+=it->ff;
        }
    }

}

int main()
{
  FAST/**/

  ll n;
  cin>>n;

  vector<ll> gr[n];
  rep(n-1)
  {
      ll a;
      cin>>a;
      a--;
      ll b = i+1;
      if(a == b)
        continue;
      gr[a].pb(b);
      gr[b].pb(a);
  }

  vector<pii> dp(n, mp(0, 0));
  vector<ll> tur(n,0);
  dfs(0, -1, gr, dp, tur);
  cout<<dp[0].ss<<'\n';

  return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector< int > p(n+1);
    vector< vector< int > > p2c(n+1, vector< int >());
    for(int i = 2; i <= n; i++){
        cin >> p[i];
        p2c[p[i]].push_back(i);
    }

    vector< int > dp(n+1, -1), dpz(n+1, -1);

    auto f = [&](auto f, int v)->void{
        if(p2c[v].size() == 0){
            dp[v] = 1;
            dpz[v] = 1;
            return;
        }
        dp[v] = 1;
        vector< int > vp;
        int pn = 0;
        for(int w: p2c[v]){
            f(f, w);
            if(dp[w] < 0 && dpz[w] == 0){
                dp[v] += dp[w];
            }else if(dpz[w] == 0){
                pn += dp[w];
            }else{
                vp.push_back(dp[w]);
            }
        }
        sort(vp.begin(), vp.end());
        int vs = vp.size();
        for(int i = 0; i < vs; i++) dp[v] += (i%2 == 0 ? vp[i] : -vp[i]);
        dp[v] += (vs%2 == 0 ? pn : -pn);
        dpz[v] = (1-vs%2);
    };
    f(f, 1);
    cout << (n+dp[1])/2 << endl;
}


#include <iostream>
using namespace std;

int main()
{
  double x,y;
  cin >> x >> y;
  long double z = ((x-y)/x)*100;
  cout << z << endl;
  return 0;
}

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

#define 	 int long long
#define 	 pb push_back
#define 	 mp make_pair
#define 	 sz(v) ((int)(v).size())
#define 	 endl '\n'
#define 	 IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    	 sortA(v)          sort(v.begin(), v.end())
#define   	 sortD(v)          sort(v.rbegin(), v.rend())
#define 	 all(x)            (x).begin(),(x).end()
#define	 	 gcd(a,b) 	       __gcd(a,b)
#define 	 rep(i,a,b) 	   for(int i=a;i<b;i++)
#define 	 repd(i,a,b) 	   for(int i=b-1;i>=a;i--)
#define 	 trav(a,x) 		   for(auto &a:x)
typedef vector<int> vi;

// const int N = 1e5 + 5;

void solve(){
	float a,b;
	cin >> a >> b;
	cout << ((a-b)/a)*100 << endl;
}

int32_t main()
{
	IO;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}
    return 0;
}


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

template <int64_t mod>
class modint {
    int64_t x;

public:
    modint(int64_t x = 0) : x((x % mod + mod) % mod) {}
    modint operator-() const { return modint(-x); }
    modint& operator+=(const modint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    modint& operator-=(const modint& a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    modint& operator*=(const modint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    modint operator+(const modint& a) const {
        return modint(*this) += a;
    }
    modint operator-(const modint& a) const {
        return modint(*this) -= a;
    }
    modint operator*(const modint& a) const {
        return modint(*this) *= a;
    }
    modint pow(int64_t t) const {
        if (not t) return 1;
        modint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    modint inv() const { return pow(mod - 2); }
    modint& operator/=(const modint& a) {
        return (*this) *= a.inv();
    }
    modint operator/(const modint& a) const {
        return modint(*this) /= a;
    }
    friend ostream& operator<<(ostream& os,
                               const modint& m) {
        os << m.x;
        return os;
    }
};

const int64_t mod = 1e9 + 7;
using mint = modint<mod>;

int main() {
    int64_t n, p;
    cin >> n >> p;
    mint ans = mint(p - 1) * mint(p - 2).pow(n - 1);
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define p 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel
int power(long long x, unsigned int y)
{
	int res = 1;     // Initialize result

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

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

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

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;
}
void solve()
{
	int n, px;
	cin >> n >> px;
	if (n == 1 and px == 2)
	{
		cout << 1 << endl;
		return;
	}
	int ans = power(px - 2, n - 1);
	ans = ((ans % p) * (px - 1) % p) % p;
	cout << ans;
}

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

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


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

ll fun(ll n){
    ll res=0;
    while(n){
        res++;
        n/=10;
    }
    return res;
}

bool comp( pair<ll,ll> a, pair<ll,ll> b){
    if(a.second!=b.second)
    return a.second>b.second;
    return a.first>b.first;
}

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

        ll n,m,q;cin>>n>>m>>q;
        ll a,b;
        vector<pair<ll,ll>> arr;
        for(ll i=0;i<n;i++)
        cin>>a>>b,arr.push_back({a,b});

        sort(arr.begin(),arr.end(),comp);
        ll barr[m];
        for(auto &it:barr)cin>>it;

        ll l,r,mi,idx;vector<ll> curr;
        while(q--){
            cin>>l>>r;
            l--;r--;
            curr.clear();
            for(ll i=0;i<=l-1;i++)curr.push_back(barr[i]);
            // cout<<l<<" ";
            for(ll i=r+1;i<m;i++)curr.push_back(barr[i]);
            if(curr.empty()){
                cout<<0<<endl;continue;
            }
            sort(curr.begin(),curr.end());
            ll sum=0,vis[curr.size()]={0};
            for(ll i=0;i<n;i++){
                for(ll j=0;j<curr.size();j++){
                    if(vis[j])continue;
                    if(curr[j]>=arr[i].first){
                        sum+=arr[i].second;
                        vis[j]=1;
                        break;
                    }
                }
            }

            cout<<sum<<endl;

        }

        return 0;

}

#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int N = 5e5 + 5, Inf = 0x3f3f3f3f, Mod = 998244353;
const ll InfLL = 0x3f3f3f3f3f3f3f3fLL;

int n, k, o_dg[N];
std::vector <int> E[N];

void Add(int u, int v) {
	E[u].push_back(v);
	E[v].push_back(u);
	++o_dg[u]; ++o_dg[v];
}

int dg[N], mn[N], col[N];
std::queue <int> que;
bool Check(int mid) {
	memcpy(dg, o_dg, sizeof(dg));
	memset(col, 0x3f, sizeof(col));
	int cnt = 0, lst;
	for(int i = 1; i <= n; ++i) mn[i] = mid;
	for(int i = 1; i <= n; ++i)
		if(dg[i] == 1) que.push(i);
	while(!que.empty()) {
		int u = que.front(); que.pop();
		lst = u;
		if(!mn[u]) ++cnt, col[u] = 0;
		for(auto v : E[u]) {
			--dg[v];
			if(col[u] > mn[u]) mn[v] = std::min(mn[v], mn[u] - 1);
			col[v] = std::min(col[v], col[u] + 1);
			if(dg[v] == 1) que.push(v);
		}
	}
	if(col[lst] > mn[lst]) ++cnt;
	return cnt <= k;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int test_case_cnt = 1; //rd(test_case_cnt);
	while(test_case_cnt--) {
		rd(n, k);
		for(int i = 1; i < n; ++i) {
			int u, v; rd(u, v);
			Add(u, v);
		}
		int l = 0, r = n - 1;
		while(l < r) {
			int mid = (l + r) >> 1;
			if(Check(mid)) r = mid;
			else l = mid + 1;
		}
		printf("%d\n", l);
	} return 0;
}


/**
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
**/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <deque>
#include <map>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

typedef long long ll;

#define forn for(int i=0;i<n;i++)
#define pb push_back
#define sc second
#define f first
#define kek cout<<"\n";
#define all(v) ((v).begin()), ((v).end())

const int MAXN=100010;
const int MOD=1e9+7;
const int INF=1e9+10;
#define int ll

int raz(int a, int b)
{
    return (a+b-1)/b;
}

int32_t main()
{

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

 int tt=1;
 // cin>>tt;
 while(tt--)
 {
     // solution goes here
     int n,m;
     cin>>n>>m;
     vector<int> v(n);
     forn cin>>v[i];
     set<int> need;
     set<int> was;
     map<int,int> ma;
     for(int i=0;i<m;i++)
     {
         ma[v[i]]++;
         was.insert(v[i]);
     }
     for(int i=0;i<=n;i++)
     {
         if(!was.count(i)) need.insert(i);
     }
     int ans=*need.begin();
     for(int i=1;i<n;i++)
     {
         if(i+m-1>=n) break;
         ma[v[i-1]]--;
         if(!ma[v[i-1]]) need.insert(v[i-1]);
         ma[v[i+m-1]]++;
         if(need.count(v[i+m-1])) need.erase(v[i+m-1]);
         ans=min(ans, *need.begin());
     }
     cout<<ans;

 }

   return 0;
}

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

 #define int long long
int n, m, mx = -1e18;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    vector<int> graph[n], cost(n);
    for (int i = 0; i < n; i++) {
       cin >> cost[i];
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        graph[b - 1].push_back(a - 1);
    }
    for (int i = 0; i < n; i++) {
        int mn = 1e18;
        for (int j : graph[i]) {
            mn = min(mn, cost[j]);
        }
        mx = max(mx, cost[i] - mn);
        cost[i]  = min(cost[i], mn);
    }
    cout << mx << endl;
    return 0;
}


#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//end of libraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int max_n = 300000;

using namespace std;
int n;

ll d[20] , f[20] , cnt[20];

bool game(vector <int> a,vector<int> b){
	crep(i,1,10) {d[i]=0;f[i]=0;}

	rep(i,sz(a)) {
		d[a[i]]++;
	}
	rep(i,sz(b)){
		f[b[i]]++;
	}

	int c1=0,c2=0;

	crep(i,1,10) {
		c1 += pow(10,d[i]) * i;
		c2 += pow(10,f[i]) * i;
	}

	if(c1>c2) return 1;
	return 0;

}

vector <int> a , b;

void read(){
	string s1,s2;
	cin >> s1 >> s2;
	rep(i,sz(s1)-1) {
		a.pb(s1[i]-'0');
	}
	rep(i,sz(s2)-1){
		b.pb(s2[i]-'0');
	}
}

int main(){
fcin;
	cin >> n;
	read();

	crep(x,1,10) {
		int d=0;
		rep(i,sz(a)) if(a[i]==x)d++;
		rep(i,sz(b)) if(b[i]==x)d++;

		cnt[x]=(n-d);

	}

	ll e=0,t=0;

	crep(x,1,10) {
		crep(y,1,10) {
			if(x==y and cnt[x] < 2) continue;
			a.pb(x);b.pb(y);
			bool g = game(a,b);
			a.pop_back();b.pop_back();
			if(g==1) {
				e+=(cnt[x]*(cnt[y]-(x==y)));
			}
			t+= (cnt[x]*(cnt[y]-(x==y)));
		}
	}

	long double e1 = e;
	long double t1 = t;
	cout << fixed<<setprecision(11);
	cout << e1/t1 << "\n";

/*
*/

    return 0;
}

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

#define int long long

int c1[10], c2[10], cnt[10];
long double fav, tot;

    int qpow(int x, int e){
        if(!e) return 1;
        if(e&1) return qpow(x,e-1)*x;
        return qpow(x*x,e>>1);
    }

main(){

    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cout.setf(ios::fixed); cout.precision(5);

    int k;
    cin >> k;
    string s, t;
    cin >> s >> t;

    for(int i = 0; i < s.size()-1; ++i){
        c1[s[i]-'0']++;
        cnt[s[i]-'0']++;
    }
    for(int i = 0; i < t.size()-1; ++i){
        c2[t[i]-'0']++;
        cnt[t[i]-'0']++;
    }

    for(int i = 1; i <= 9; ++i){
        int x = k-cnt[i];
        if(x <= 0) continue;
        for(int j = 1; j <= 9; ++j){
            int y = k-cnt[j]-(i==j);
            if(y <= 0) continue;
            tot += x*y;
            c1[i]++; c2[j]++;
            int sum1 = 0, sum2 = 0;
            for(int k = 1; k <= 9; ++k)
                sum1 = sum1 + k*qpow(10,c1[k]);
            for(int k = 1; k <= 9; ++k)
                sum2 = sum2 + k*qpow(10,c2[k]);

            if(sum1 > sum2) fav += x*y;
            c1[i]--; c2[j]--;
        }
    }

    cout << fav/tot;

}


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

template<int M>
struct static_mint {
	static_assert(0 < M, "Module must be positive");

	int val;
	static_mint(): val() {}
	static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
	static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; }
	static_mint inv() const { return pow(M - 2); }

	friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }
	friend static_mint inv(const static_mint &m) { return m.inv(); }

	static_mint operator+() const { static_mint m; m.val = val; return m; }
	static_mint operator-() const { static_mint m; m.val = M - val; return m; }
	static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; }
	static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; }
	static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; }
	static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; }

	friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; }
	friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; }
	friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; }
	friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; }
	friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; }
	friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; }

	static_mint &operator++() { return *this += 1; }
	static_mint &operator--() { return *this -= 1; }
	static_mint operator++(int) { static_mint result(*this); *this += 1; return result; }
	static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; }

	template <typename T> explicit operator T() const { return T(val); }

	friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
		return os << m.val;
	}

	friend std::istream &operator>>(std::istream &is, static_mint &m) {
		long long x; is >> x; m = x;
		return is;
	}
};

template <typename>
struct is_mint : public std::false_type { };

template <int M>
struct is_mint<static_mint<M>> : public std::true_type { };

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

	using mint = static_mint<998244353>;

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

	if (m == 1) {
		cout << mint(k).pow(n) << '\n';
		return 0;
	} else if (n == 1) {
		cout << mint(k).pow(m) << '\n';
		return 0;
	}

	mint ans = 0;
	for (int mx = 1; mx <= k; mx++) {
		mint ways = mint(mx).pow(n) - mint(mx - 1).pow(n);
		ans += ways * mint(k - mx + 1).pow(m);
	}
	cout << ans << '\n';
	return 0;
}

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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b)
		cout<<"Takahashi";
	else if(a<b)
		cout<<"Aoki";
	else
		if(c==1)
			cout<<"Takahashi";
		else
			cout<<"Aoki";
	return 0;
}


#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int X; scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
#define loop(I, A, B) for (int I = (A); I <= (B); ++I)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

PLL xi[200009];
PLL yi[200009];

int main(){
    DRI(n);
    REP(i,n){
        scanf("%lld%lld",&xi[i].F,&yi[i].F);
        xi[i].S=yi[i].S=i;
    }
    sort(xi,xi+n);
    sort(yi,yi+n);
    pair<LL,PII> ans;
    vector<pair<LL,PII> > v;
    vector<PII> pp;
    pp.PB({0,n-1});
    pp.PB({0,n-2});
    pp.PB({1,n-1});
    for(PII p:pp){
        int i = p.F, j = p.S;
        v.PB({abs(xi[i].F-xi[j].F),{xi[i].S,xi[j].S}});
        v.PB({abs(yi[i].F-yi[j].F),{yi[i].S,yi[j].S}});
    }
    sort(ALL(v));
    reverse(ALL(v));
    /*for(auto i:v){
        printf("%lld %d %d\n",i.F,i.S.F,i.S.S);
    }*/
    if(v[0].S==v[1].S){
        printf("%lld",v[2].F);
    }
    else{
        printf("%lld",v[1].F);
    }
}

#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;

int main(int argc, char* argv[]){
	int n;
	cin>>n;
	vector<pair<long long, long long>>a(n);
	vector<pair<long long, long long>>b(n);
	for(int i=0;i<n;i++){
		pair<long long, long long> p;
		long long f,s;
		cin>>f>>s;
		p = make_pair(f,i);
		a[i] = p;
		p = make_pair(s,i);
		b[i] = p;
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());

	vector<long long> ans;
	vector<pair<int,int>> ans_pair;
	pair<int,int> p;
	int f,s;
	ans.push_back(abs(a[0].first-a[a.size()-1].first));
	f = min(a[0].second, a[a.size()-1].second);
	s = max(a[0].second, a[a.size()-1].second);
	p = make_pair(f,s);
	ans_pair.push_back(p);
	ans.push_back(abs(a[1].first-a[a.size()-1].first));
	f = min(a[1].second, a[a.size()-1].second);
	s = max(a[1].second, a[a.size()-1].second);
	p = make_pair(a[1].second, a[a.size()-1].second);
	ans_pair.push_back(p);
	ans.push_back(abs(a[0].first-a[a.size()-2].first));
	f = min(a[0].second, a[a.size()-2].second);
	s = max(a[0].second, a[a.size()-2].second);
	p = make_pair(a[0].second, a[a.size()-2].second);
	ans_pair.push_back(p);
//	ans.push_back(abs(b[0].first-b[b.size()-1].first));
//	ans.push_back(abs(b[1].first-b[b.size()-1].first));
//	ans.push_back(abs(b[0].first-b[b.size()-2].first));

	int idx_i, idx_j;
	idx_i = min(b[0].second,b[n-1].second);
	idx_j = max(b[0].second,b[n-1].second);
	bool flag = true;
	for(int i=0;i<3;i++){
		if(ans_pair[i].first==idx_i&&ans_pair[i].second==idx_j){
			ans[i] = max(ans[i],abs(b[0].first-b[n-1].first));
			flag = false;
		}
	}
	if (flag==true){
		ans.push_back(abs(b[0].first-b[b.size()-1].first));
	}
	idx_i = min(b[1].second,b[n-1].second);
	idx_j = max(b[1].second,b[n-1].second);
	flag = true;
	for(int i=0;i<3;i++){
		if(ans_pair[i].first==idx_i&&ans_pair[i].second==idx_j){
			ans[i] = max(ans[i],abs(b[1].first-b[n-1].first));
			flag = false;
		}
	}
	if (flag==true){
		ans.push_back(abs(b[1].first-b[n-1].first));
	}
	idx_i = min(b[0].second,b[n-2].second);
	idx_j = max(b[0].second,b[n-2].second);
	flag = true;
	for(int i=0;i<3;i++){
		if(ans_pair[i].first==idx_i&&ans_pair[i].second==idx_j){
			ans[i] = max(ans[i],abs(b[0].first-b[n-2].first));
			flag = false;
		}
	}
	if (flag==true){
		ans.push_back(abs(b[0].first-b[n-2].first));
	}
	sort(ans.begin(),ans.end());
//	for(int i=0;i<ans.size();i++){
//		cout<<ans[i]<<endl;
//	}
	cout<<ans[ans.size()-2]<<endl;

}


// 問題の URL を書いておく
//

#include <bits/stdc++.h>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = long long;

struct Vertex
{
    vector<int> children;
    ll score{0};
    ll diff{0};
    int depth{-1};
};

void fillDepth(vector<Vertex>& vs, int t, int depth)
{
    vs[t].depth = depth;
    for(auto v : vs[t].children)
    {
        if(vs[v].depth == -1)
        {
            fillDepth(vs, v, depth + 1);
        }
    }
}

int main(int, const char**)
{
    int N;
    cin >> N;
    vector<pair<int, int>> edges(N - 1);
    vector<Vertex> v(N);
    rep(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[i] = {a, b};
        v[a].children.push_back(b);
        v[b].children.push_back(a);
    }
    fillDepth(v, 0, 0);

    int Q;
    cin >> Q;
    rep(i, Q)
    {
        int t, e, x;
        cin >> t >> e >> x;
        e--;
        int s, b;
        if(t == 1)
        {
            s = edges[e].first;
            b = edges[e].second;
        }
        else
        {
            s = edges[e].second;
            b = edges[e].first;
        }

        if(v[s].depth > v[b].depth)
        {
            v[s].diff += x;
        }
        else
        {
            v[b].diff -= x;
            v[0].diff += x;
        }
    }
#if 0
    rep(i, N)
    {
        printf("v[%d]:\n", i);
        for(auto c : v[i].children)
        {
            printf("  %d\n", c);
        }
    }
#endif
    queue<int> q;
    q.push(0);
    while(!q.empty())
    {
        auto t = q.front();
        q.pop();
        auto& tv = v[t];
        for(auto n : tv.children)
        {
            if(v[n].depth <= tv.depth) continue;
            v[n].diff += tv.diff;
            q.push({n});
        }
    }
    rep(i, N)
    {
        cout << v[i].diff << endl;
    }
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;

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

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

const int MAXN = 2e5 + 20;
int n, a[MAXN], b[MAXN], dfn[MAXN], ext[MAXN], clk = 0;
list<int> g[MAXN];
ll dif[MAXN], val[MAXN];

void dfs(int u, int fa) {
  dfn[u] = ++clk;
  for (int v : g[u])
    if (v != fa) dfs(v, u);
  ext[u] = clk;
}

void proc1(int e, ll x) {
  int u = a[e], v = b[e];
  // from u, without v
  if (dfn[u] <= dfn[v] && dfn[v] <= ext[u]) {
    // u -> v
    dif[1] += x;
    dif[n + 1] -= x;
    dif[dfn[v]] -= x;
    dif[ext[v] + 1] += x;
  } else {
    // v -> u
    dif[dfn[u]] += x;
    dif[ext[u] + 1] -= x;
  }
}

void proc2(int e, ll x) {
  int u = a[e], v = b[e];
  // from v, without u
  if (dfn[u] <= dfn[v] && dfn[v] <= ext[u]) {
    // u -> v
    dif[dfn[v]] += x;
    dif[ext[v] + 1] -= x;
  } else {
    // v -> u
    dif[1] += x;
    dif[n + 1] -= x;
    dif[dfn[u]] -= x;
    dif[ext[u] + 1] += x;
  }
}

void finalize() {
  for (int i = 1; i <= n; i++) val[i] = val[i - 1] + dif[i];
}

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

  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a[i] >> b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  dfs(1, 0);
  int q;
  cin >> q;
  while (q--) {
    int t, e;
    ll x;
    cin >> t >> e >> x;
    if (t == 1) proc1(e, x);
    if (t == 2) proc2(e, x);
  }
  finalize();
  for (int i = 1; i <= n; i++) cout << val[dfn[i]] << "\n";
}


#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << a * d - b * c;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define br "\n"
#define sp " "
#define pie 3.141592653589793238462643383279
#define fo(i, n) for(int i=0;i<n;i++)
#define rfo(i, n) for(int i=n-1;i>=0;i--)
#define forl(i,a,n) for(int i=a;i<n;i++)
#define forr(i,a,n) for(int i=n-1;i>=a;i--)
#define tr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it++)
#define deb(x) cout << #x << " = " << x << endl;
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deba(i, a, n) fo(i, n){cout << a[i] << " ";}
#define popcount(x) __builtin_popcount(x)  // count the number of one’s(set bits) in an integer.
#define popcountll(x) __builtin_popcountll(x)
#define clz(x) __builtin_clz(x)   // count the leading zeros(binary representation) of the integer
#define clzll(x) __builtin_clzll(x)
#define ctz(x) __builtin_ctz(x)   // count the trailing zeros(binary representation) of the integer
#define ctzll(x) __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define lcm(a,b) (a*b)/gcd(a,b)
#define deci(n) fixed << setprecision(n)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define max5(a,b,c,d,e) max(max4(a,b,c,d),e)
#define min5(a,b,c,d,e) min(min4(a,b,c,d),e)
#define p0(a) cout << a << " "
#define p1(a) cout << a << br
#define p2(a, b) cout << a << " " << b << br
#define p3(a, b, c) cout << a << " " << b << " " << c << br
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << br
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sort(x,n) sort(x, x+n)
#define rsort(x,n) sort(x, x+n, greater<int>())
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef pair<double, double> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
typedef set<int> si;
typedef deque<int> di;
typedef queue<int> qi;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}

int midofthree(int a,int b,int c)
{
    if((a<=b and a>=c) or (a<=c and a>=b))
        return a;
    else if((b>=a and b<=c) or (b<=a and b>=c))
        return b;
    return c;
}

ll fact(int n){
    if(n==1 || n==0){
        return 1;
    }
    else{
        return n*fact(n-1);
    }
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;

    for (int i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;

    return true;
}

const int MOD = 1e9 + 7;
int mod=MOD;
/* ========== YOUR CODE HERE ========= */

void solution() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<< a*d-b*c;

}

/* ========== YOUR CODE HERE ========= */

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

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

    return 0;
}
// By Ashwani Kumar, Indian Institute Of Technology(IIT), Guwahati.


#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  s.push_back(s[0]);
  s.erase(s.begin());
  cout << s << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1002003004005006007ll;

void solve(){
ll n;cin >> n;
rep(i,pow(10,5)){
  if((2*n)<=(i*(i+1))){
    cout << i << endl;
    return;
  }
}
  return;
}

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

  solve();
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)
#define For(i, l, r) for(int i = (l), i##e = (r); i < i##e; i++)
#define pb push_back
#define eb emplace_back
#define upd(a, b) (a = min(a, b))

using namespace std;

const int N = 1e5 + 5;

int n, mi[128], f[N];
char s[N];

int main() {
    mem(f, 63), mem(mi, 63);
#ifdef local
	// freopen(".in", "r", stdin);
#endif
    scanf("%d%s", &n, s + 1);
    mi[s[1]] = 0;
    rep(i, 2, n) {
        rep(j, 'a', 'z') if(j ^ s[i]) upd(f[i], mi[j] + 1);
        upd(mi[s[i + 1]], f[i]);
    }
    if(f[n] < 0x3f3f3f3f) cout << f[n];
    else puts("-1");
    return 0;
}

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

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int n;  cin >> n >> s;
    if(s[0] != s[n - 1])
        return cout << "1", 0;
    for(int i = 1; i < n - 2; i++) {
        if(s[i] != s[0] and s[i + 1] != s[0])
            return cout << "2", 0;
    }
    cout << "-1";
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

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

/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
typedef tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)
*/

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define cntleadz(x) __builtin_clz(x) // or add ll at the end for long long
#define cnttrailz(x) __builtin_ctx(x)
#define cntpop(x) __builtin_popcount(x)
#define binparity(x) __builtin_parity(x)
#define pb push_back
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
// #define mod 1000000007
#define mod 998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

ll binExp(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

// ll fact[200001];
// ll ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod:0);}
ll modInv(ll i) {return binExp(i,mod-2);}
ll add(ll a, ll b) {ll res = a+b; if(res >= mod) res -= mod; return res;}
ll mul(ll a, ll b) {ll res = a*b; res %= mod; return res;}

char mat[5001][5001];
int dp[5001][5001];

void solve()
{
    int h,w,k;
    cin>>h>>w>>k;

    f1(i,1,h) f1(j,1,h) {mat[i][j] = '.';dp[i][j] = 0;}

    dp[1][1] = binExp(3,h*w-k);;

    int a,b;
    char c;
    f0(_,0,k)
    {
        cin>>a>>b>>c;

        mat[a][b] = c;
    }

    int by3 = modInv(3);

    f1(i,1,h) f1(j,1,w)
    {
        if(i!=1 && mat[i-1][j] != 'R')
        {
            if(mat[i-1][j] == 'X' || mat[i-1][j] == 'D')
                dp[i][j] = add(dp[i][j], dp[i-1][j]);
            else
                dp[i][j] = add(dp[i][j], mul(2*dp[i-1][j], by3));
        }
        if(j!=1 && mat[i][j-1] != 'D')
        {
            if(mat[i][j-1] == 'X' || mat[i][j-1] == 'R')
                dp[i][j] = add(dp[i][j], dp[i][j-1]);
            else
                dp[i][j] = add(dp[i][j], mul(2*dp[i][j-1], by3));
        }
        // if(i==2&&j==1)
        // {
        //     cout<<dp[i][j]<<"----\n";
        // }
    }

    // f1(i,1,h)
    // {
    //     f1(j,1,w) cout<<mat[i][j]<<' '; cout<<'\n';
    // }

    // f1(i,1,h)
    // {
    //     f1(j,1,w) cout<<dp[i][j]<<' '; cout<<'\n';
    // }

    cout<<dp[h][w];
}

signed main()
{
    fast

    // clock_t start,end;
    #ifndef ONLINE_JUDGE
        freopen("inputf.txt","r",stdin);
        freopen("outputf.txt","w",stdout);
    #endif
    // start = clock();

    // fact[0] = 1;
    // f1(i,1,200000) fact[i] = mul(fact[i-1], i);

    // test
    solve();

    // end = clock();
    // double time_taken = double(end-start) / double(CLOCKS_PER_SEC);
    // cout<<time_taken<<" sec";
}

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

const int MOD = 1000000007;
const int INF = 1e9;
const long long INFLL = 1e18;
using ll = long long;

char RSP(char i, char j){
  if(i == 'S' && j == 'P') return 'S';
  if(i == 'R' && j == 'S') return 'R';
  if(i == 'P' && j == 'R') return 'P';
  if(i == 'S' && j == 'R') return 'R';
  if(i == 'R' && j == 'P') return 'P';
  if(i == 'P' && j == 'S') return 'S';

  return i;

}

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

  if(n % 2 == 1){
    n *= 2;
    for(int i = 0; i < n/2; i++) s.push_back(s[i]);
  }

  for(int i = 0; i < k; i++){
    string ss = "";
    for(int j = 0; j < n/2; j++){
      ss.push_back(RSP(s[2*j], s[2*j+1]));
    }
    for(int j = n/2; j < n; j++) ss.push_back(ss[j-n/2]);

    for(int j = 0; j < n; j++) s[j] = ss[j];
    // cout << s << endl;
  }

  cout << s[0] << endl;

  return 0;
}