Language: C++

#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int N = 1e5+4;
int a[N],b[N];
vector <int> v;
map <int,bool> m;
map <int,bool> m1;
int n;
signed main()
{
	ll s1 = 0,s2 = 0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i],&b[i]);
		s1 += a[i],
		s2 += b[i];

		v.push_back(a[i]);
		v.push_back(b[i]);
	}

	sort(v.begin(),v.end());
	ll S = 0,ans = min(s1,s2);
	// cout<<s1<<' '<<s2<<'\n';

	for(int i=0;i<n-2;i++)
	{
		// cout<<v[i]<<' ';
		S += v[i];
		m[v[i]] = true;
	}
	// cout<<S<<'\n';
	for(int i=1;i<=n;i++)
	{
		ll res = S + a[i] + b[i];
		m1[a[i]] = true;
		m1[b[i]] = true;
		int cnt = 0;
		if(m[a[i]] == true)
			res -= a[i],
			cnt++;

		if(m[b[i]] == true)
			res -= b[i],
			cnt++;


		if(cnt == 1)
		{
			if(m1[v[n-2]] == true)
				res += v[n-1];
			else
				res += v[n-2];
		}
		else if(cnt == 2)
			res += (v[n-2] + v[n-1]);

		ans = min(ans,res);

	}
	cout<<ans<<'\n';
}#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int N = 1e5+4;
int a[N],b[N];
vector <int> v;
map <int,bool> m;
map <int,bool> m1;
int n;
signed main()
{
	ll s1 = 0,s2 = 0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i],&b[i]);
		s1 += a[i],
		s2 += b[i];

		v.push_back(a[i]);
		v.push_back(b[i]);
	}

	sort(v.begin(),v.end());
	ll S = 0,ans = min(s1,s2);
	// cout<<s1<<' '<<s2<<'\n';

	for(int i=0;i<n-2;i++)
	{
		// cout<<v[i]<<' ';
		S += v[i];
		m[v[i]] = true;
	}
	// cout<<S<<'\n';
	for(int i=1;i<=n;i++)
	{
		ll res = S + a[i] + b[i];
		m1[a[i]] = true;
		m1[b[i]] = true;
		int cnt = 0;
		if(m[a[i]] == true)
			res -= a[i],
			cnt++;

		if(m[b[i]] == true)
			res -= b[i],
			cnt++;


		if(cnt == 1)
		{
			if(m1[v[n-2]] == true)
				res += v[n-1];
			else
				res += v[n-2];
		}
		else if(cnt == 2)
			res += (v[n-2] + v[n-1]);

		ans = min(ans,res);

	}
	cout<<ans<<'\n';
}

Compiler output:
a.cc:65:2: error: stray '#' in program
   65 | }#include <bits/stdc++.h>
      |  ^
a.cc:65:3: error: 'include' does not name a type
   65 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:69:11: error: redefinition of 'const long long int N'
   69 | const int N = 1e5+4;
      |           ^
a.cc:5:11: note: 'const long long int N' previously defined here
    5 | const int N = 1e5+4;
      |           ^
a.cc:70:5: error: redefinition of 'long long int a [100004]'
   70 | int a[N],b[N];
      |     ^
a.cc:6:5: note: 'long long int a [100004]' previously declared here
    6 | int a[N],b[N];
      |     ^
a.cc:70:10: error: redefinition of 'long long int b [100004]'
   70 | int a[N],b[N];
      |          ^
a.cc:6:10: note: 'long long int b [100004]' previously declared here
    6 | int a[N],b[N];
      |          ^
a.cc:71:14: error: redefinition of 'std::vector<long long int> v'
   71 | vector <int> v;
      |              ^
a.cc:7:14: note: 'std::vector<long long int> v' previously declared here
    7 | vector <int> v;
      |              ^
a.cc:72:16: error: redefinition of 'std::map<long long int, bool> m'
   72 | map <int,bool> m;
      |                ^
a.cc:8:16: note: 'std::map<long long int, bool> m' previously declared here
    8 | map <int,bool> m;
      |                ^
a.cc:73:16: error: redefinition of 'std::map<long long int, bool> m1'
   73 | map <int,bool> m1;
      |                ^~
a.cc:9:16: note: 'std::map<long long int, bool> m1' previously declared here
    9 | map <int,bool> m1;
      |                ^~
a.cc:74:5: error: redefinition of 'long long int n'
   74 | int n;
      |     ^
a.cc:10:5: note: 'long long int n' previously declared here
   10 | int n;
      |     ^
a.cc:75:8: error: redefinition of 'int main()'
   75 | signed main()
      |        ^~~~
a.cc:11:8: note: 'int main()' previously defined here
   11 | signed main()
      |        ^~~~