Language: C++

#include <bits/stdc++.h>
#define int long long
#define N 100005

using namespace std;
typedef long long ll;

template <class T> inline void read(T &x) {
	char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	if (flag) x = -x;
}

inline int input() {
	int x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

const int mod = 1e9 + 7;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; }
inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; }

inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = (ll) res * x % mod;
		x = (ll) x * x % mod, y >>= 1;
	} return res;
}

template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; }
template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> T gcd(T x, T y) { return !y ? x : gcd(x % y, y); }

struct node{int x, opt, id;} c[maxn];
bool cmp(node g, node h){return g.x < h.x;}
int n, a[maxn], b[maxn], ans, sum, cnt, d[maxn], w[3], t;

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		c[++cnt].x = a[i], c[cnt].id = i, c[cnt].opt = 0;
		c[++cnt].x = b[i], c[cnt].id = i, c[cnt].opt = 1;
	}
	sort(c + 1, c + cnt + 1, cmp);
	for(int i = 1; i <= n; i++){
		d[c[i].id]++; ans += c[i].x;
		w[c[i].opt]++; if(d[c[i].id] == 2) t = 1;
	}
	if(t == 1 || w[1] == 0 || w[0] == 0){
		cout << ans << endl; return 0;
	}
	Ans = LLONG_MAX;
	for(int i = 1; i <= n; i++){
		if(c[n].id != i) Ans = min(Ans, ans + max(a[i], b[i]) - c[n].x);
		else Ans = min(Ans, ans + max(a[i], b[i]) - c[n - 1].x);
	}
	cout << Ans << endl;
	return 0;
}


Compiler output:
a.cc:38:32: error: 'maxn' was not declared in this scope
   38 | struct node{int x, opt, id;} c[maxn];
      |                                ^~~~
a.cc:40:10: error: 'maxn' was not declared in this scope
   40 | int n, a[maxn], b[maxn], ans, sum, cnt, d[maxn], w[3], t;
      |          ^~~~
a.cc:40:19: error: 'maxn' was not declared in this scope
   40 | int n, a[maxn], b[maxn], ans, sum, cnt, d[maxn], w[3], t;
      |                   ^~~~
a.cc:40:43: error: 'maxn' was not declared in this scope
   40 | int n, a[maxn], b[maxn], ans, sum, cnt, d[maxn], w[3], t;
      |                                           ^~~~
a.cc: In function 'int main()':
a.cc:46:24: error: 'a' was not declared in this scope
   46 |                 cin >> a[i] >> b[i];
      |                        ^
a.cc:46:32: error: 'b' was not declared in this scope
   46 |                 cin >> a[i] >> b[i];
      |                                ^
a.cc:47:17: error: 'c' was not declared in this scope
   47 |                 c[++cnt].x = a[i], c[cnt].id = i, c[cnt].opt = 0;
      |                 ^
a.cc:50:14: error: 'c' was not declared in this scope
   50 |         sort(c + 1, c + cnt + 1, cmp);
      |              ^
a.cc:52:17: error: 'd' was not declared in this scope
   52 |                 d[c[i].id]++; ans += c[i].x;
      |                 ^
a.cc:58:9: error: 'Ans' was not declared in this scope; did you mean 'ans'?
   58 |         Ans = LLONG_MAX;
      |         ^~~
      |         ans
a.cc:60:59: error: 'a' was not declared in this scope
   60 |                 if(c[n].id != i) Ans = min(Ans, ans + max(a[i], b[i]) - c[n].x);
      |                                                           ^
a.cc:60:65: error: 'b' was not declared in this scope
   60 |                 if(c[n].id != i) Ans = min(Ans, ans + max(a[i], b[i]) - c[n].x);
      |                                                                 ^
a.cc:61:47: error: 'a' was not declared in this scope
   61 |                 else Ans = min(Ans, ans + max(a[i], b[i]) - c[n - 1].x);
      |                                               ^
a.cc:61:53: error: 'b' was not declared in this scope
   61 |                 else Ans = min(Ans, ans + max(a[i], b[i]) - c[n - 1].x);
      |                                                     ^