jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    rg = []

    for i in range(N):
        a,b = map(int,input().split())
        rg.append((a,b))

    def disasm(i):
        rg.sort()
        a,_ = rg[i]
        rg.sort(key=lambda x: x[1])
        _,b = rg[i]
        return a,b


    if N % 2 == 1:
        a,b = disasm(N//2)
        print(b-a+1)
        exit()

    a,b = disasm(N//2-1)
    c,d = disasm(N//2)

    print(b+d-a-c+1)


if __name__ == "__main__":
  main()
//  [java]
	import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);

	        
	        int N = sc.nextInt();
	        Integer[][] a = new Integer[N][3];
	        Integer[][] b = new Integer[N][3];
	        for(int i=0;i<N;i++) {
	        	a[i][0] = Integer.parseInt(sc.next());
	        	a[i][1] = Integer.parseInt(sc.next());
	        	a[i][2] = i;
	        	b[i][0] = a[i][0];
	        	b[i][1] = a[i][1];
	        	b[i][2] = a[i][2];
	        }
	        Arrays.sort(a, (d, c) -> Integer.compare(d[0], c[0]));
	        Arrays.sort(b, (d, c) -> Integer.compare(c[1], d[1]));
	        long ans=0;
	        if(N%2==1) {
	        	Integer min = a[N/2][0];
	        	Integer max = b[N/2][1];
        		Integer r = 0;
        		ans=max-min+1;
	        	for(int i=0;i<N;i++) {
	        		if(r>=max)break;
	        		if(r<a[i][0]&&min<a[i][0]) {
	        			ans=ans-(Math.min(a[i][0], max)-Math.max(r, min)-1);
	        		}
	        		r=Math.max(r, a[i][1]);
	        	}
	        	
	        } else {
	        	Integer min = a[N/2-1][0]+a[N/2][0];
	        	Integer max = b[N/2-1][1]+b[N/2][1];
        		ans=(max-min+1);
	        	
	        }
	        
	        System.out.println(ans);
	    }
	}
//  [java]

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();

		List<Range> ranges = new ArrayList<>();
		IntStream.range(0, n).forEach(i -> ranges.add(new Range(stdIn.nextInt(), stdIn.nextInt())));

		stdIn.close();

		if(ranges.size() % 2 == 1) {
			ranges.sort(Comparator.comparing(Range::getA));
			int min = ranges.get(ranges.size()/2).getA();

			ranges.sort(Comparator.comparing(Range::getB).reversed());
			int max = ranges.get(ranges.size()/2).getB();

			System.out.println(max - min + 1);
			return;
		}

		ranges.sort(Comparator.comparing(Range::getA));
		int minN = ranges.get((ranges.size()-1)/2).getA();
		int minN1 = ranges.get((ranges.size()-1)/2 + 1).getA();

		ranges.sort(Comparator.comparing(Range::getB).reversed());
		int maxN = ranges.get((ranges.size()-1)/2).getB();
		int maxN1 = ranges.get((ranges.size()-1)/2 + 1).getB();

//
//		int nCnt = maxN - minN + 1;
//		int n1Cnt = maxN1 - minN1 + 1;
//
//		int dupl = Integer.max(0, maxN - minN1 + 1);

		System.out.println(maxN+maxN1-minN-minN1+1);

	}
}

class Range {
	private int a;
	private int b;


	public Range(int a, int b) {
		super();
		this.a = a;
		this.b = b;
	}


	public int getA() {
		return a;
	}
	public int getB() {
		return b;
	}

	public int getRange() {
		return a + b - 1;
	}

	@Override
	public String toString() {
		return "Range [a=" + a + ", b=" + b + "]";
	}


}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

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


	int A[200000], B[200000];
	int N = getint();
	rep(i, N) {
		A[i] = getint();
		B[i] = getint();
	}

	nth_element(A, A + N / 2, A + N);
	nth_element(B, B + N / 2, B + N);
	if (N % 2) {
		printf("%d\n", B[N / 2] - A[N / 2] + 1);
	}
	else {
		int a = *max_element(A, A + N / 2);
		int b = *max_element(B, B + N / 2);
		printf("%d\n", b + B[N / 2] - a - A[N / 2] + 1);
	}

	Would you please return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(ll X, const vector<ll>& v){
  if(v.size()%2!= 0){
    vector<ll> a;
    rep(i,v.size()){
      if(v[i] <= X) a.push_back(v[i]);
    }
    if(a.size() >= v.size()/2+1) return true;
    else return false;
  }else{
    vector<ll> a, b;
    rep(i,v.size()){
      if(v[i] <= X) a.push_back(v[i]);
      else b.push_back(v[i]);
    }
    sort(ALLOF(a));
    sort(ALLOF(b));
    if(a.size() == 0) return false;
    else if(b.size() == 0) return true;
    else{
      if(a.size() == b.size()){
        if(a[a.size()-1] <= 2 * X - b[0]) return true;
        return false;
      }
      else if(a.size() > b.size()){
        return true;
      }
      else{
        return false;
      }
    }
  }
}

bool check2(ll X, const vector<ll>& v){
  if(v.size()%2!= 0){
    vector<ll> b;
    rep(i,v.size()){
      if(v[i] >= X) b.push_back(v[i]);
    }
    if(b.size() >= v.size()/2+1) return true;
    else return false;
  }else{
    vector<ll> a, b;
    rep(i,v.size()){
      if(v[i] >= X) b.push_back(v[i]);
      else a.push_back(v[i]);
    }
    sort(ALLOF(a));
    sort(ALLOF(b));
    if(a.size() == 0) return true;
    else if(b.size() == 0) return false;
    else{
      if(a.size() == b.size()){
        if(2 * X - a[a.size()-1] <= b[0]) return true;
        return false;
      }
      else if(a.size() < b.size()){
        return true;
      }
      else{
        return false;
      }
    }
  }
}

int main(){
  int N;
  cin >> N;
  vector<ll> v, w;
  rep(i,N){
    ll a, b;
    cin >> a >> b;
    if(N%2!=0){
      v.push_back(a);
      w.push_back(b);
    }else{
      v.push_back(2*a);
      w.push_back(2*b);
    }
  }


  ll x = -1, y = -1;
  {
    ll lb = 0, ub = (ll)1e11;
    while(ub-lb>1){
      ll mid = lb + (ub-lb)/2;

      if(!check(mid, v)) lb = mid;
      else ub = mid;
    }
    cerr << ub << endl;
    x = ub;
  }
  {
    ll lb = 0, ub = (ll)1e11;
    while(ub-lb>1){
      ll mid = lb + (ub-lb)/2;

      if(check2(mid, w)) lb = mid;
      else ub = mid;
    }
    cerr << ub << endl;
    y = ub;
  }

  cout << y - x << endl;
  
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

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; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  set<int> locs;
  map<int, int> beg, en;

  rep(i,0,n) {
    int a, b;
    cin >> a >> b;
    locs.insert(a);
    locs.insert(b+1);
    beg[a]++;
    en[b+1]++;
  }

  vi pos;
  for (auto x: locs) pos.pb(x);

  const int inf = 1e9+8;
  auto range = [&](int x) -> pii {
    int ba = n, eb = 0;
    pii ans = {inf, 0};
    rep(i,0,sz(pos)) {
      int loc = pos[i];
      ba -= beg[loc];
      eb += en[loc];
  //    cerr << loc << ' ' << ba << ' ' << eb << '\n';
      if (ba <= n-x-1 and eb <= x) {
        ckmin(ans.fst, pos[i]);
        ckmax(ans.snd, pos[i+1]-1);
      }
    }
    return ans;
  };


  int ans = 0;
  if (n%2==0) {
    pii a = range(n/2-1), b = range(n/2);
//    cerr << a.fst << ' ' << a.snd << '\n';
//    cerr << b.fst << ' ' << b.snd << '\n';
    int sa = a.snd-a.fst+1;
    int sb = b.snd-b.fst+1;
    ans = sa+sb-1;
  } else {
    pii a = range(n/2);
 //   cerr << a.fst << ' ' << a.snd << '\n';
    ans = a.snd-a.fst+1;
  }

  cout << ans << '\n';
}
//  [c]
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char bufr[4400007];
int bufrl;
#define getchar_unlocked() bufr[bufrl++]

int c[200000];
void rsort_u32(void *base, const int count){
	uint32_t *a=base;
	uint32_t *b=c;
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
}
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int a[200000];
int b[200000];
int main(void){
	read(STDIN_FILENO, bufr, sizeof(bufr));
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
		b[i]=nextint();
	}
	rsort_u32(a, n);
	rsort_u32(b, n);
	int ans;
	if(n&1){
		int A=a[n/2], B=b[n/2];
		ans=B-A+1;
	}else{
		int A=a[n/2]+a[n/2-1], B=b[n/2]+b[n/2-1];
		ans=B-A+1;
	}
	printf("%d\n", ans);
}
//  [c]
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char bufr[4400007];
int bufrl;
#define getchar_unlocked() bufr[bufrl++]

void rsort_u32(void *base, const int count){
	uint32_t *a=base;
	uint32_t *b=malloc(count*sizeof(uint32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int a[200000];
int b[200000];
int main(void){
	read(STDIN_FILENO, bufr, sizeof(bufr));
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
		b[i]=nextint();
	}
	rsort_u32(a, n);
	rsort_u32(b, n);
	int ans;
	if(n&1){
		int A=a[n/2], B=b[n/2];
		ans=B-A+1;
	}else{
		int A=a[n/2]+a[n/2-1], B=b[n/2]+b[n/2-1];
		ans=B-A+1;
	}
	printf("%d\n", ans);
}
//  [c]
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

void rsort_u32(void *base, const int count){
	uint32_t *a=base;
	uint32_t *b=malloc(count*sizeof(uint32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int a[200000];
int b[200000];
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
		b[i]=nextint();
	}
	rsort_u32(a, n);
	rsort_u32(b, n);
	int ans;
	if(n&1){
		int A=a[n/2], B=b[n/2];
		ans=B-A+1;
	}else{
		int A=a[n/2]+a[n/2-1], B=b[n/2]+b[n/2-1];
		ans=B-A+1;
	}
	printf("%d\n", ans);
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
long long R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]||N[H[a]]==N[H[b]]&&H[a]%2==1?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  long long n,a[200010],b[200010],i,lb=0,bf,ans=0,ra,j,r,l;
  scanf("%lld",&n);
  for(i=0;i<n;i++)scanf("%lld %lld",&a[i],&b[i]);
  if(n%2==0){
    for(i=0;i<n;i++)hin(a[i]*2);
    for(i=0;i<n/2;i++)j=N[hout()];
    l=(N[H[1]]+j)/2;
    R=C=1;
    for(i=0;i<n;i++)hin(b[i]*2);
    for(i=0;i<n/2;i++)j=N[hout()];
    r=(N[H[1]]+j)/2;//printf("%lld %lld\n",l,r);
    printf("%lld\n",r-l+1);
  }
  else{
    for(i=0;i<n;i++)hin(a[i]);
    for(i=0;i<n/2;i++)hout();
    l=N[H[1]];
    R=C=1;
    for(i=0;i<n;i++)hin(b[i]);
    for(i=0;i<n/2;i++)hout();
    r=N[H[1]];
    printf("%lld\n",r-l+1);
  }
  return 0;
}
//  [c]
#include<stdio.h>
int h[200005], l;
int comp_h(int a, int b)
{
	if (h[a] > h[b])
		return 1;
	else
		return -1;
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void f1(int ne)
{
	h[l] = ne;
	int p = l;
	l++;
	while (p > 0)
	{
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
		p = (p - 1) / 2;
	}
	return;
}
int f2()
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005], b[200005];
	for (i = 0; i < n; i++)
		scanf("%d %d", &a[i], &b[i]);
	l = 0;
	for (i = 0; i < n; i++)
		f1(a[i]);
	for (i = 0; i < n; i++)
		a[i] = f2();
	l = 0;
	for (i = 0; i < n; i++)
		f1(b[i]);
	for (i = 0; i < n; i++)
		b[i] = f2();
	if (n % 2 > 0)
		printf("%d\n", b[n / 2] - a[n / 2] + 1);
	else
		printf("%d\n", b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1);
	return 0;
}
//  [c]
#include <stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}
int even(int *a,int*,int n);
int odd(int *a,int*,int n);
int main(int argc, char *argv[])
{
	int n;
	scanf("%d",&n);
	int a[n],b[n],ans,i;
	for(i=0;i<n;i++)
		scanf("%d%d",&a[i],&b[i]);
	qsort(a,n,sizeof(int),cmp);
	qsort(b,n,sizeof(int),cmp);
	if(n%2)
		ans=odd(a,b,n);
	else ans=even(a,b,n);
	printf("%d\n",ans);
}
int odd(int a[],int b[],int n){
	int ans;
	ans=(b[(n+1)/2-1]-a[(n+1)/2-1]);
	if(ans<0)ans*=(-1);
	ans++;
	return ans;
}
int even(int a[],int b[],int n){
	int ans,aa,bb;
	aa=a[n/2-1]+a[(n/2)];
	bb=b[n/2-1]+b[(n/2)];
	ans=bb-aa;
	if(ans<0)ans*=(-1);
	ans++;
	return ans;
}
//  [javascript]
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

function next(){return +cin[cid++];}
console.log(main().toString());


function main() {
    let n = next();
    let a = Array(n);
    let b = Array(n);
    for (let i = 0; i < n; i++) {
        a[i] = next();
        b[i] = next();
    }
    a.sort((x, y) => x - y);
    b.sort((x, y) => x - y);
    let min, max;
    if (n % 2 == 0) {
        // 偶数の時 中央値は X(2/n-1)とX(2/n)の平均値
        // 最小値は、それぞれの値が異なるとき、A(2/n)-1/2、同じならA(2/n)
        min = (a[n / 2 - 1] + a[n / 2]) / 2;
        max = (b[n / 2 - 1] + b[n / 2]) / 2;
        return (max - min) * 2 + 1;
    } else {
        min = a[(n - 1) / 2];
        max = b[(n - 1) / 2];
        return (max - min) + 1;
    }


}
//  [javascript]
const inputs = require('fs')
  .readFileSync('/dev/stdin', 'utf8')
  .trim()
  .split(/\s+/)

const N = parseInt(inputs[0])
const A = new Array(N)
const B = new Array(N)

for (let i = 0, p = 1; i < N; i += 1) {
  A[i] = parseInt(inputs[p++])
  B[i] = parseInt(inputs[p++])
}

const cmp = (a, b) => a - b
A.sort(cmp)
B.sort(cmp)

if (N % 2 == 0) { // even
  const i1 = N / 2 - 1
  const i2 = N / 2
  const maxMed = B[i1] + B[i2]
  const minMed = A[i1] + A[i2]
  console.log(maxMed - minMed + 1)
} else { // odd
  const i = (N - 1) / 2
  const maxMed = B[i]
  const minMed = A[i]
  console.log(maxMed - minMed + 1)
}
//  [javascript]
"use strict";

function main(arg) {
    const input = arg.trim().split("\n");
    const N = Number(input.shift())
    const A = input.map(x=>Number(x.split(" ")[0])).sort((a,b)=>a-b);
    const B = input.map(x=>Number(x.split(" ")[1])).sort((a,b)=>a-b);
    
    let a, b, sum
    if(N%2) {
        const id0 = parseInt((N+1)/2)-1
        a = A[id0]
        b = B[id0]
        sum = b-a+1
    } else {
        const id0 = parseInt(N/2)-1
        const id1 = parseInt(N/2+1)-1
        a = (A[id0] + A[id1])/2
        b = (B[id0] + B[id1])/2
        sum = (b-a)*2+1
    }

    console.log(sum)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var a = nextm(n,2);
  a.sort((a,b) => a[0]-b[0]);
  var m = n >> 1;
  if(n & 1){
    var ans = -a[m][0];
    a.sort((a,b)=>a[1]-b[1]);
    ans += a[m][1]+1;
  }else{
    var ans = a[m][0]+a[m-1][0];
    a.sort((a,b)=>a[1]-b[1]);
    ans -= a[m][1]+a[m-1][1];
    ans = -ans+1;
  }
  return ans;
}
//  [javascript]
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var minList = new Array(N);
	var maxList = new Array(N);
	for(var i = 0; i < N; i++){
		var tmp = nextIntArray();
		minList[i] = tmp[0];
		maxList[i] = tmp[1];
	}
	minList.sort(function(a,b){
		return a - b;
	});
	maxList.sort(function(a,b){
		return a - b;
	});
	var output = 0;
	var MIN;
	var MAX;
	if(N % 2 == 1){
		MIN = minList[(N - 1) / 2];
		MAX = maxList[(N - 1) / 2];
		output = MAX - MIN + 1;
	}else{
		MIN = (minList[N / 2 - 1] + minList[N / 2]) / 2;
		MAX = (maxList[N / 2 - 1] + maxList[N / 2]) / 2;
		output = (MAX - MIN) * 2 + 1;
	}
	
	myout(output);
}
//  [javascript]
console.log((args=>{
  const [[N],...X] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  const A = [], B = [];
  for ( let i = 0; i < N; i++ ) {
    A.push(X[i][0]);
    B.push(X[i][1]);
  }
  A.sort((a,b)=>a-b);
  B.sort((a,b)=>a-b);
  if ( N&1 ) {
    const m = (N-1)/2;
    return B[m] - A[m] + 1;
  } else {
    const m = N/2;
    return B[m] + B[m-1] - A[m] - A[m-1] + 1;
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [go]
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	a, b := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = sc.NextInt()
		b[i], _ = sc.NextInt()
	}
	ans := solve(n, a, b)
	fmt.Println(ans)
}

func solve(n int, a []int, b []int) int {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	sort.Slice(b, func(i, j int) bool { return b[i] < b[j] })
	if n%2 == 0 {
		m1 := b[n/2-1] - a[n/2-1] + 1
		m2 := b[n/2] - a[n/2] + 1
		return m1 + m2 - 1
	}
	return b[n/2] - a[n/2] + 1
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i], &b[i])
	}

	sort.Ints(a)
	sort.Ints(b)
	if n%2 == 0 {
		ans := (b[n/2] + b[n/2-1]) - (a[n/2] + a[n/2-1]) + 1
		fmt.Println(ans)
	} else {
		fmt.Println(b[n/2] - a[n/2] + 1)
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i], B[i] = ReadInt(), ReadInt()
	}
	sort.Ints(A)
	sort.Ints(B)
	if N%2 == 1 {
		fmt.Println(B[N/2] - A[N/2] + 1)
	} else {
		a1, b1 := A[N/2-1], B[N/2-1]
		a2, b2 := A[N/2], B[N/2]
		fmt.Println(b1 + b2 - a1 - a2 + 1)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
//  [ruby]
N = $stdin.gets.to_i
A = []
B = []
0.upto(N - 1) do |i|
  A[i], B[i] = $stdin.gets.split.map {|j| j.to_i }
end
A.sort!
B.sort!
case N % 2
when 1
  ca = A[(N + 1) / 2 - 1]
  cb = B[(N + 1) / 2 - 1]
when 0
  ca = A[N / 2 - 1] + A[(N / 2)]
  cb = B[N / 2 - 1] + B[(N / 2)]
end
r = cb - ca + 1
if r < 0
  r = 0
end
puts r
//  [ruby]
N = gets.to_i
A = []
B = []
N.times do 
    a,b = gets.split.map &:to_i 
    A << a
    B << b
end
A.sort!
B.sort!

if N%2==1 then
    ma = A[(N+1)/2-1]
    mb = B[(N+1)/2-1]
else
    ma = A[N/2-1] + A[(N/2)]
    mb = B[N/2-1] + B[(N/2)]
end

puts mb-ma+1
//  [ruby]
n = gets.to_i

as, bs = [], []

n.times do
  a, b = gets.split.map &:to_i
  as << a
  bs << b
end

def median(xs)
  xs = xs.sort
  n = xs.size
  if n.even?
    xs[n / 2] + xs[n / 2 - 1]
  else
    xs[n / 2]
  end
end


ma = median as
mb = median bs
puts mb - ma + 1
//  [ruby]
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
ab=n.times.map{gsmi}.sort
if n.odd?
  aft=ab[n/2..-1]
  st=aft[0][0]
  b_sort = ab.sort{|x,y|x[1]<=>y[1]}
  en=b_sort[n/2][1]
  puts en-st+1
else
  aft=ab[(n/2-1)..-1]
  st=(aft[0][0]+aft[1][0])
  b_sort = ab.sort{|x,y|x[1]<=>y[1]}
  en=(b_sort[n/2-1][1]+b_sort[n/2][1])
  puts en-st+1
end
//  [ruby]
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
ab=array(N)
N.times do|i|
    ab[i]=get_i
end
a=ab.sort{|x,y| x[0]<=>y[0]}
b=ab.sort{|x,y| x[1]<=>y[1]}
if N.odd?
  puts b[N/2][1]-a[N/2][0]+1
else
  puts b[N/2-1][1]+b[N/2][1]-(a[N/2-1][0]+a[N/2][0])+1
end
//  [ruby]
n = gets.to_i
ab = n.times.map {gets.split.map(&:to_i)}

if n.odd?
    ab.sort_by!{|a,b| a}
    x = ab[n/2][0]
    ab.sort_by!{|a,b| b}
    y = ab[n/2][1]
    p y - x + 1
else
    ab.sort_by!{|a,b| a}
    x1, x2 = ab[n/2-1][0], ab[n/2][0]
    ab.sort_by!{|a,b| b}
    y1, y2 = ab[n/2-1][1], ab[n/2][1]

    p (y1 + y2) - (x1 + x2) + 1
end
//  [rust]
#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use input_scanner::*;
use math::*;
use string_algorithm::*;
use util::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let mut a: Vec<u32> = Vec::with_capacity(n);
    let mut b: Vec<u32> = Vec::with_capacity(n);
    for _i in 0..n {
        let x = scan.next();
        let y = scan.next();
        a.push(x);
        b.push(y);
    }
    a.sort();
    b.sort();

    if n % 2 == 0 {
        println!(
            "{}",
            b[(n - 1) / 2] + b[n / 2] - a[(n - 1) / 2] - a[n / 2] + 1
        );
    } else {
        println!("{}", b[n / 2] - a[n / 2] + 1);
    }
}

mod datastructure {}
mod grapth {}
mod math {}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }

    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str =
                unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}
//  [rust]
use superslice::Ext;
fn main() {
    proconio::input! {
        n: usize,
        ab: [(i32,i32);n],
    }
    let mut a: Vec<_>=ab.iter().map(|&(a,_)|a).collect();
    a.sort();
    let mut b: Vec<_>=ab.iter().map(|&(_,b)|b).collect();
    b.sort();
    if n&1==1 {
        let (s,e) = f(n/2, n, &a, &b);
        println!("{}",e-s+1);
    }
    else {
        let (s1,e1) = f(n/2-1, n, &a, &b);
        let (s2,e2) = f(n/2, n, &a, &b);
        println!("{}",(e1+e2)-(s1+s2)+1)
    }
}
fn f(k: usize, n: usize, a: &Vec<i32>, b: &Vec<i32>) -> (i32,i32) {
    let mut l=a[0]-1;
    let mut r=b[n-1]+1;
    while l+1<r {
        let m=(l+r)/2;
        let (x,y)=(b.lower_bound(&m),n-a.upper_bound(&m));
        let z=n-x-y;
        if x+z<=k {
            l=m;
        }
        else {
            r=m;
        }
    }
    let s=r;
    let mut l=a[0]-1;
    let mut r=b[n-1]+1;
    while l+1<r {
        let m=(l+r)/2;
        let (x,y)=(b.lower_bound(&m),n-a.upper_bound(&m));
        let z=n-x-y;
        if y+z<=n-1-k {
            r=m;
        }
        else {
            l=m;
        }
    }
    let e=l;
    (s,e)
}
//  [rust]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        ab: [(usize, usize); n],
    }
    let mut l = 0;
    let mut r = 10000000000;
    while r - l > 1 {
        let m = (l + r) / 2;
        let mut left = 0;
        for i in 0..n {
            if ab[i].0 < m {
                left += 1;
            }
        }
        if 2 * left < n {
            l = m;
        } else {
            r = m;
        }
    }
    let x0 = l;

    let mut l = 0;
    let mut r = 10000000000;
    while r - l > 1 {
        let m = (l + r) / 2;
        let mut left = 0;
        for i in 0..n {
            if ab[i].1 < m {
                left += 1;
            }
        }
        if 2 * left < n {
            l = m;
        } else {
            r = m;
        }
    }
    let x1 = l;

    let mut l = 0;
    let mut r = 10000000000;
    while r - l > 1 {
        let m = (l + r) / 2;
        let mut right = 0;
        for i in 0..n {
            if m < ab[i].0 {
                right += 1;
            }
        }
        if 2 * right < n {
            r = m;
        } else {
            l = m;
        }
    }
    let y0 = r;

    let mut l = 0;
    let mut r = 10000000000;
    while r - l > 1 {
        let m = (l + r) / 2;
        let mut right = 0;
        for i in 0..n {
            if m < ab[i].1 {
                right += 1;
            }
        }
        if 2 * right < n {
            r = m;
        } else {
            l = m;
        }
    }
    let y1 = r;

    eprintln!("{} {} {} {}", x0, x1, y0, y1);
    if n % 2 == 0 {
        println!("{}", (x1 + y1) + 1 - (x0 + y0));
    } else {
        println!("{}", y1 + 1 - x0)
    }
}
//  [rust]
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let n: usize = read_as_vec()[0];
    let mut uppers: Vec<usize> = vec![];
    let mut lowers: Vec<usize> = vec![];
    for _ in 0..n {
        let line = read_as_vec::<usize>();
        uppers.push(line[1]);
        lowers.push(line[0]);
    }

    uppers.sort();
    lowers.sort();
    dbg!(&uppers);
    if n % 2 == 1 {
        println!("{}", uppers[(n - 1) / 2] - lowers[(n - 1) / 2] + 1);
    } else {
        println!(
            "{}",
            uppers[(n - 1) / 2] + uppers[(n - 1) / 2 + 1]
                - (lowers[(n - 1) / 2] + lowers[(n - 1) / 2 + 1])
                + 1
        );
    }
}
//  [rust]
#[allow(dead_code)]
fn main() {
    let n = i::u();
    let ab = i::uv2(n);

    let mut small: Vec<_> = ab.iter().map(|(a, b)| a).cloned().collect();
    let mut big: Vec<_> = ab.iter().map(|(a, b)| b).cloned().collect();
    small.sort();
    big.sort();

    if n % 2 == 0 {
        let s = small[n / 2] + small[n / 2 - 1];
        let b = big[n / 2] + big[n / 2 - 1];
        println!("{}", (b - s) + 1);
    //dbg!(&s, &b);
    } else {
        let s = small[n / 2];
        let b = big[n / 2];
        println!("{}", b - s + 1);
        //dbg!(&s, &b);
    }
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn u4() -> (usize, usize, usize, usize) {
        (read(), read(), read(), read())
    }

    pub fn u5() -> (usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read())
    }

    pub fn u6() -> (usize, usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn iv3(n: usize) -> Vec<(i64, i64, i64)> {
        (0..n).map(|_| iv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  const A: number[] = [];
  const B: number[] = [];
  for (let i = 0; i < N; i++) {
    A[i] = Number(input[i + 1][0]);
    B[i] = Number(input[i + 1][1]);
  }

  A.sort((a, b) => a - b);
  B.sort((a, b) => a - b);

  if (N % 2 === 0) {
    const minMedian = A[N / 2 - 1] + A[N / 2];
    const maxMedian = B[N / 2 - 1] + B[N / 2];

    return maxMedian - minMedian + 1;
  } else {
    const minMedian = A[(N + 1) / 2 - 1];
    const maxMedian = B[(N + 1) / 2 - 1];

    return maxMedian - minMedian + 1;
  }
};

console.log(main(read()));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  const A: number[] = [];
  const B: number[] = [];
  for (let i = 0; i < N; i++) {
    A[i] = Number(input[i + 1][0]);
    B[i] = Number(input[i + 1][1]);
  }

  A.sort((a, b) => a - b);
  B.sort((a, b) => a - b);

  if (N % 2 === 0) {
    const minMedian = A[N / 2 - 1] + A[N / 2];
    const maxMedian = B[N / 2 - 1] + B[N / 2];

    return (maxMedian - minMedian + 1).toString();
  } else {
    const minMedian = A[(N + 1) / 2 - 1];
    const maxMedian = B[(N + 1) / 2 - 1];

    return (maxMedian - minMedian + 1).toString();
  }
};

console.log(main(read()));
//  [typescript]
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader = new Reader();
let N = reader.readInt();

let A: number[] = [], B: number[] = [];

for(let i=0; i<N; i++) {
	let [a, b] = reader.readInts();
	A.push(a);
	B.push(b);
}

function findMedian(arr: number[]) {
	arr.sort((a, b) => a-b);
	let median: number;
	let mid = Math.floor(arr.length/2);
	if (arr.length%2 == 1)
		median = arr[mid];
	else
		median = (arr[mid-1]+arr[mid])/2;
	return median;
}

let medians = findMedian(B)-findMedian(A)+1;
if (N%2 == 0)
	medians += medians-1
console.log(medians);
//  [python]
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
m = list(input())
answer = 0
for i in range(4):
    if m[i] == '+':
        answer += 1
    else:
        answer -= 1

print(answer)
//  [python]
import math
import numpy as np
line = input()

num = 0
for a in line:
    if a == '+':
        num += 1
    else:
        num -= 1

print(num)
//  [python]
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(input())
print(s.count('+') - s.count('-'))
//  [java]
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        String s;
        try(Scanner cin = new Scanner(System.in)) {
            s = cin.next();
        }
        long count = s.chars().filter((c) -> c == '+').count();
        System.out.println(count - (4 - count));
    }

}
//  [java]
import java.util.*;

class Main{
	public static void main(String[] A){
		Scanner s=new Scanner(System.in);
		System.out.println(s.next().chars().map(o->o=='+'?1:-1).sum());
	}
}
//  [java]
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AEatingSymbolsEasy solver = new AEatingSymbolsEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class AEatingSymbolsEasy {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println(in.nextString().chars().filter(c -> c == '+').count() * 2 - 4);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

    }
}
//  [cpp]
#include <iostream>
using namespace std;

int main(){
    string S;
    cin>>S;
    int A=0;
    for(int i=0;i<4;i++){
        if(S.at(i)=='+'){
            A++;
        }
        if(S.at(i)=='-'){
            A--;
        }
    }
    cout<<A<<endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  string s;
  cin>>s;
  int ans=0;
  rep(i,4){
    if(s[i]=='+')ans++;
    else ans--;
  }
  cout<<ans<<endl;
  return 0;
}