Problem:
Score : 500 points

Problem Statement

There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i.
Find the number of different values that the median of X_1, X_2, \cdots, X_N can take.

Notes

The median of X_1, X_2, \cdots, X_N is defined as follows. Let x_1, x_2, \cdots, x_N be the result of sorting X_1, X_2, \cdots, X_N in ascending order.

If N is odd, the median is x_{(N+1)/2};

if N is even, the median is (x_{N/2} + x_{N/2+1}) / 2.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the answer.

Sample Input 1

2
1 2
2 3

Sample Output 1

3

If X_1 = 1 and X_2 = 2, the median is \frac{3}{2};

if X_1 = 1 and X_2 = 3, the median is 2;

if X_1 = 2 and X_2 = 2, the median is 2;

if X_1 = 2 and X_2 = 3, the median is \frac{5}{2}.

Thus, the median can take three values: \frac{3}{2}, 2, and \frac{5}{2}.

Sample Input 2

3
100 100
10 10000
1 1000000000

Sample Output 2

9991

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define print(x) cout << x << endl
#define debug print("reaching\n")
#define mll map<ll,ll>
#define lsb(i) i&(-i)
#define printv(x) \
	FORALL(i, x.size()) \
	{ \
		cout << x[i] << ' '; \
	} \
	cout << endl \
;
#define input(v,x) \
	FORALL(i,n) \
	{ \
		cin>>v[i]; \
	} \
;
#define printm(m) \
	for(auto i: m){\
		cout<<i.ff<<' '<<i.ss<<endl; \
	}\
;
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
	if(b<=0) return 1;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

// vll start;
// vll finish;
// vll ft;
// void dfs(vector<vll>& g, ll cur, ll par){
//     static ll timer = 0;
//     ft[timer] = cur;
//     start[cur] = timer;
//     timer++;
//     for(int i = 0; i < g[cur].size(); i++)
//         if(g[cur][i] != par)
//             dfs(g, g[cur][i], cur);
//     finish[cur] = timer;
//     ft[timer] = cur;
//     timer++;
// }

// node st[4*(1000001)];
// int lazy[4*(1000001)];

// void build(int si, int ss, int se){
// 	if(ss == se){
// 		st[si].a[0] = 1;
// 		st[si].a[1] = 0;
// 		st[si].a[2] = 0;
// 		return;
// 	}
// 	int mid = (ss+se)/2;
// 	build(2*si, ss, mid);
// 	build(2*si + 1, mid+1,se);
// 	st[si].a[0] = st[2*si].a[0] + st[2*si + 1].a[0];
// 	st[si].a[1] = st[2*si].a[1] + st[2*si + 1].a[1];
// 	st[si].a[2] = st[2*si].a[2] + st[2*si + 1].a[2];
// }

// void update(int si, int ss, int se, int qs, int qe){
// 	if(lazy[si]!= 0){
// 		int add = lazy[si];
// 		lazy[si]%=3;
// 		FORALL(i,lazy[si]){
// 			swap(st[si].a[0], st[si].a[1]);
// 			swap(st[si].a[0], st[si].a[2]);
// 		}
// 		if(ss!=se){
// 			lazy[2*si] += add;
// 			lazy[2*si+1] += add;
// 		}
// 		lazy[si] = 0;
// 	}
// 	if(ss>qe or qs>se) return;
// 	if(ss>=qs and qe>=se){
// 		swap(st[si].a[0], st[si].a[1]);
// 		swap(st[si].a[0], st[si].a[2]);
// 		if(ss!=se){
// 			lazy[2*si]++;
// 			lazy[2*si+1]++;
// 		}
// 		return;
// 	}
// 	int mid = (ss + se)/2;
// 	update(2*si, ss, mid, qs, qe);
// 	update(2*si+1, mid+1, se, qs, qe);
// 	st[si].a[0] = st[2*si].a[0] + st[2*si + 1].a[0];
// 	st[si].a[1] = st[2*si].a[1] + st[2*si + 1].a[1];
// 	st[si].a[2] = st[2*si].a[2] + st[2*si + 1].a[2];
// }

// int get(int si, int ss, int se, int qs, int qe){
// 	if(lazy[si]!= 0){
// 		int add = lazy[si];
// 		lazy[si]%=3;
// 		FORALL(i,lazy[si]){
// 			swap(st[si].a[0], st[si].a[1]);
// 			swap(st[si].a[0], st[si].a[2]);
// 		}
// 		if(ss!=se){
// 			lazy[2*si] += add;
// 			lazy[2*si+1] += add;
// 		}
// 		lazy[si] = 0;
// 	}
// 	if(ss>qe or qs>se) return 0;
// 	if(ss>=qs and qe>=se){
// 		return st[si].a[0];
// 	}
// 	int mid = (ss + se)/2;
// 	int left = get(2*si, ss, mid, qs, qe);
// 	int right = get(2*si+1, mid+1, se, qs, qe);
// 	return left + right;
// }


template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	else
	{
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m)
{
	T x, y;
	extGcd(a, m, x, y);
	return (x % m + m) % m;
}

// ll fac[1000005];
// ll ifac[1000005];
// void temp(){
// 		fac[0] = fac[1] = 1;
// 		ifac[0] = ifac[1] = 1;
// 		for(int i=1;i< 1000005;i++){
// 			fac[i] = (fac[i-1]%MOD)*(i%MOD);
// 			fac[i] += MOD;
// 			fac[i]%=MOD;
// 			ifac[i] = (ifac[i-1]%MOD)*(modInv(i, MOD)%MOD);
// 			ifac[i] += MOD;
// 			ifac[i]%=MOD;
// 		}
// }
// ll cc(int n, int r){
// 	if(n==0) return 0;
// 	if(n==1) return 1;
// 	ll ans = (fac[n] * ifac[n-r])%MOD;
// 	ans = ans * ifac[r];
// 	ans%=MOD;
// 	return ans;
// }

bool com(pll a, pll b){
	if(a.ff == b.ff){
		return a.ss < b.ss;
	}
	return a.ff < b.ff;
}

int main()
{
	fast;
	// cin.tie(0);
	// cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int t=1;
	// cin>>t;
	ll tot=t;
	while(t--){
		// string s;
		// cin>>s;
		// int last = -1;
		// int ans = 0;
		// int n = s.length();
		// int dp[n][2];
		// memset(dp, 0, sizeof(dp));
		// for(int i =0; i<n;i++){
		// 	if(s[i]==s[(i-1+n)%n]){
		// 		dp[i][1] = (1 + dp[(i-1+n)%n][0]);
		// 		dp[i][0] = dp[(i-1+n)%n][1];
		// 	}
		// 	else{
		// 		dp[i][1] = dp[(i-1+n)%n][1] + 1;
		// 		dp[i][0] = dp[(i-1+n)%n][0];
		// 	}
		// }
		// // cout<<dp[n-1][0]<<' '<<dp[n-1][1]<<endl;
		// ans = min(dp[n-1][0], dp[n-1][1]);
		// if(n!=2 and dp[n-1][1]<=dp[n-1][0] and s[0]==s[n-1]){
		// 	ans--;
		// }
		// print(ans);
		ll n;
		cin>>n;
		vector<pll> v(n);
		FORALL(i,n){
			ll x,y;
			cin>>x>>y;
			v[i].ff = x;
			v[i].ss = y;
		}

		sort(all(v), com);
		if(n&1){
			cout<<(v[n/2].ss - v[n/2].ff + 1)<<endl;
		}
		else{
			ll ans = 0;
			ans += (v[n/2].ss - v[n/2].ff + 1);
			ans += (v[n/2 - 1].ss - v[n/2 - 1].ff + 1);
			if(v[n/2].ff <= v[n/2 - 1].ss)
				ans--;
			print(ans);
		}

	}
	return 0;
}