Language: C++

#include <stdio.h>
#include <algorithm>
using namespace std;

int N; pair<int, pair<int, int> > ev[400200];

int main()
{
	scanf ("%d", &N);
	for (int i = 0; i < N; i++){
		int s, e; scanf ("%d %d", &s, &e);
		ev[i] = { s, {1, 0} };
		ev[i + N] = { e + 1, {0, 1} };
	}
	sort(ev, ev + N * 2);
	int n = N * 2;
	for (int i = 1, j = 0; i < N * 2; i++){
		if (ev[i].first == ev[j].first){
			ev[j].second.first += ev[i].second.first;
			ev[j].second.second += ev[i].second.second;
			n--;
		}
		else{
			ev[++j] = ev[i];
		}
	}
	ev[n].first = 1.1e9;

	if (N % 2){
		int d = (N + 1) / 2;
		int o = 0, c = 0, a = 0;
		for (int i = 0; i < n; i++){
			o += ev[i].second.first;
			c += ev[i].second.second;
			if (c < d && d <= o) a += ev[i + 1].first - ev[i].first;
		}
		printf ("%d\n", a);
	}
	else{
		int d = N / 2;

		int o = 0, c = 0, s1 = 0x7fffffff, e1 = 0, s2 = 0x7fffffff, e2 = 0;
		for (int i = 0; i < n; i++){
			o += ev[i].second.first;
			c += ev[i].second.second;
			if (c < d && d <= o){
				s1 = min(s1, ev[i].first);
				e1 = max(e1, ev[i + 1].first - 1);
			}
			if (c < d + 1 && d + 1 <= o){
				s2 = min(s2, ev[i].first);
				e2 = max(e2, ev[i + 1].first - 1);
			}
		}

		printf ("%d\n", (e1 + e2) - (s1 + s2) + 1);
	}

	return 0;
}
#include <stdio.h>
#include <algorithm>
using namespace std;

int N; pair<int, pair<int, int> > ev[400200];

int main()
{
	scanf ("%d", &N);
	for (int i = 0; i < N; i++){
		int s, e; scanf ("%d %d", &s, &e);
		ev[i] = { s, {1, 0} };
		ev[i + N] = { e + 1, {0, 1} };
	}
	sort(ev, ev + N * 2);
	int n = N * 2;
	for (int i = 1, j = 0; i < N * 2; i++){
		if (ev[i].first == ev[j].first){
			ev[j].second.first += ev[i].second.first;
			ev[j].second.second += ev[i].second.second;
			n--;
		}
		else{
			ev[++j] = ev[i];
		}
	}
	ev[n].first = 1.1e9;

	if (N % 2){
		int d = (N + 1) / 2;
		int o = 0, c = 0, a = 0;
		for (int i = 0; i < n; i++){
			o += ev[i].second.first;
			c += ev[i].second.second;
			if (c < d && d <= o) a += ev[i + 1].first - ev[i].first;
		}
		printf ("%d\n", a);
	}
	else{
		int d = N / 2;

		int o = 0, c = 0, s1 = 0x7fffffff, e1 = 0, s2 = 0x7fffffff, e2 = 0;
		for (int i = 0; i < n; i++){
			o += ev[i].second.first;
			c += ev[i].second.second;
			if (c < d && d <= o){
				s1 = min(s1, ev[i].first);
				e1 = max(e1, ev[i + 1].first - 1);
			}
			if (c < d + 1 && d + 1 <= o){
				s2 = min(s2, ev[i].first);
				e2 = max(e2, ev[i + 1].first - 1);
			}
		}

		printf ("%d\n", (e1 + e2) - (s1 + s2) + 1);
	}

	return 0;
}


Compiler output:
a.cc:65:5: error: redefinition of 'int N'
   65 | int N; pair<int, pair<int, int> > ev[400200];
      |     ^
a.cc:5:5: note: 'int N' previously declared here
    5 | int N; pair<int, pair<int, int> > ev[400200];
      |     ^
a.cc:65:35: error: redefinition of 'std::pair<int, std::pair<int, int> > ev [400200]'
   65 | int N; pair<int, pair<int, int> > ev[400200];
      |                                   ^~
a.cc:5:35: note: 'std::pair<int, std::pair<int, int> > ev [400200]' previously defined here
    5 | int N; pair<int, pair<int, int> > ev[400200];
      |                                   ^~
a.cc:67:5: error: redefinition of 'int main()'
   67 | int main()
      |     ^~~~
a.cc:7:5: note: 'int main()' previously defined here
    7 | int main()
      |     ^~~~