Language: C++

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
pll arr[100005],so[200005];
 
bool yee(pll a,pll b)
{
	if(a.F==b.F) return a.S%2<b.S%2;
	return a.F<b.F;
}
 
int main()
{jizz
	ll n,a[2]={0,0},ans=0,mx=-1,sx=-1,my=-1,sy=-1,tmp,tmp2;
	cin >> n;
	for(ll i=0;i<n;++i)
		cin >> arr[i].F >> arr[i].S,so[i<<1]=MP(arr[i].F,i<<1),so[i<<1|1]=MP(arr[i].S,i<<1|1);
	if(n==2)
		return cout << min(arr[0].F,arr[1].S)+min(arr[1].F,arr[0].S) << "\n",0;
	sort(so,so+2*n,yee);
	for(ll i=0;i<n;++i)
		ans+=so[i].F,++a[so[i].S&1];
	if(a[0]!=1&&a[1]!=1)
		return cout << ans << "\n",0;
	if(a[0]<=1)
		for(ll i=0;i<n;++i)
			swap(arr[i].F,arr[i].S);
	ans=0;
	for(ll i=0;i<n;++i)
	{
		ans+=arr[i].F;
		if(!~mx||arr[i].F>arr[mx].F)
			sx=mx,mx=i;  
		else if(!~sx||arr[i].F>arr[sx].F)
			sx=i;
		if(!~my||arr[i].S<arr[my].S)
			sy=my,my=i;  
		else if(!~sy||arr[i].S<arr[sy].S)
			sy=i;
	}
	if(mx!=my)
		return cout << ans+min(arr[my].S-arr[mx].F,0) << "\n",0;
	cout << ans+min({arr[my].S-arr[sx].F,arr[sy].S-arr[mx].F,arr[my].S+arr[sy].S-arr[mx].F-arr[sx].F,0}) << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:39: error: no matching function for call to 'min(long long int, int)'
   55 |                 return cout << ans+min(arr[my].S-arr[mx].F,0) << "\n",0;
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:55:39: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   55 |                 return cout << ans+min(arr[my].S-arr[mx].F,0) << "\n",0;
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:55:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   55 |                 return cout << ans+min(arr[my].S-arr[mx].F,0) << "\n",0;
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:56:24: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   56 |         cout << ans+min({arr[my].S-arr[sx].F,arr[sy].S-arr[mx].F,arr[my].S+arr[sy].S-arr[mx].F-arr[sx].F,0}) << "\n";
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
a.cc:56:24: note:   deduced conflicting types for parameter '_Tp' ('long long int' and 'int')
   56 |         cout << ans+min({arr[my].S-arr[sx].F,arr[sy].S-arr[mx].F,arr[my].S+arr[sy].S-arr[mx].F-arr[sx].F,0}) << "\n";
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided