criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;
vector<int> fct;
int pw(int a, int b){
    if (b==1) return a;
    if (b%2==1) return (a*pw(a, b-1))%MOD;
    int kek = pw(a, b/2);
    return (kek*kek)%MOD;
}
int C(int n, int k){
    int A = fct[n], B = (fct[k] * fct[n-k])%MOD;
    return (A*pw(B, MOD-2))%MOD;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fct.push_back(1);
    for (int i=0;i<2e5; i++){
        fct.push_back((fct.back() * (i+1))%MOD);
    }
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i < n; i++) cin >> v[i];
    int pref[n+1];
    pref[0] = 0;
    for (int i=0; i < n; i++) pref[i+1] = pref[i] + v[i];
    int S = 0, L = 1, R = n-2, len = 1, ans=0;
    while (true){
        if (len > (n-1)/2) break;
        S += pref[R+1] - pref[L];
        //cout << S << endl;
        S %= MOD;
        L++, R--;
        int kk = fct[n];
        int pp = C(len+2, 2);
        pp %= MOD;
       // cout << pw(2, MOD-2) << endl;
        int hh = (kk * pw(pp, MOD-2))%MOD;
        hh %= MOD;
        ans += hh*S;
        ans %= MOD;
        len++;
    }
    S = 0, L = 1, R = n-2, len = n-2;
    while (true){
        if (len <= (n-1)/2) break;
        S += pref[R+1] - pref[L];
        //cout << S << endl;
        S %= MOD;
        L++, R--;
        int kk = fct[n];
        int pp = C(len+2, 2);
        pp %= MOD;
        //cout << C(4, 2) << endl;
        int hh = (kk * pw(pp, MOD-2))%MOD;
        hh %= MOD;
        ans += hh*S;
        ans %= MOD;
        len--;
    }
    //cout << ans << endl;
    int kk = 0;
    for (int i=0; i < n-1; i++){
        kk += v[i];
        kk %= MOD;
        int k = kk;
        k *= fct[n];
        k %= MOD;
        int del = i+2;
        k *= pw(del, MOD-2);
        ans += k;
        ans %= MOD;
    }
    kk += v[n-1];
    ans += kk * fct[n];
    ans %= MOD;
    reverse(v.begin(), v.end());
    kk = 0;
    //cout << ans << endl;
    for (int i=0; i < n-1; i++){
        kk += v[i];
        k %= MOD;
        int k=kk;
        k *= fct[n];
        k %= MOD;
        int del = i+2;
        k *= pw(del, MOD-2);
        ans += k;
        ans %= MOD;
    }
    cout << ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:85:9: error: 'k' was not declared in this scope
   85 |         k %= MOD;
      |         ^
Language: C++

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 1e5;

int n;
int t[(N << 1) + 1];
struct Node {
	int x, num;
} node[(N << 1) + 1];
ll ans;

inline bool compare(Node a, Node b)
{
	return a.x < b.x;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++) {
		int x = read();
		node[((i - 1) << 1) + 1] = Node{ x, ((i - 1) << 1) + 1 };
		x = read();
		node[i << 1] = Node{ x, i << 1 };
	}

	sort(node + 1, node + (n << 1) + 1, compare);
	for (int i = 1; i <= n; i++) {
		ans += node[i].x;
		t[node[i].num]++;
	}
	bool flag = true, flag2 = true, flag3 = true;
	for (int i = 1; i <= n; i++) {
		if (t[((i - 1) << 1) + 1])
			flag2 = false;
		if (t[i << 1])
			flag3 = false;
		if ((t[((i - 1) << 1) + 1] && t[i << 1]) || (!t[((i - 1) << 1) + 1] && !t[i << 1]))
			flag = false;

	if (flag && !flag2 && !flag3) {
		if (node[n].num / 2 != node[n + 1].num / 2)
			ans += node[n + 1].x - node[n].x;
		else
			ans += min(node[n + 2].x - node[n].x, node[n + 1].x - node[n - 1].x);
	}

	printf("%lld\n", ans);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:69:2: error: expected '}' at end of input
   69 | }
      |  ^
a.cc:37:1: note: to match this '{'
   37 | {
      | ^
Language: C++

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
typedef long long ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
void umin(ll& a,ll t){if(t<a)a=t;}
const ll INF=1ll<<58;
#define MAXN 200011
pll b[MAXN];
ll n,a[MAXN];
struct node
	{
		ll minv,pos;
		node(){minv=INF,pos=0;}
		node operator +(const node t)
		{
			node res;
			if(minv<t.minv)res=*this;
			else res=t;
			return res;
		}
	};
struct Segment_Tree
{
	node t[MAXN<<2|1];
	#define rt t[num]
	void modify(un pos,ll k,un l=1,un r=n,un num=1)
	{
		if(l==r){rt.minv=k,rt.pos=l;return;}
		un mid=(l+r)>>1;
		if(pos<=mid)modify(pos,k,l,mid,num<<1);
		else modify(pos,k,mid+1,r,num<<1|1);
		rt=t[num<<1]+t[num<<1|1];
	}
	node Qmin(un ql,un qr,un l=1,un r=n,un num=1)
	{
		if(ql>qr)return node();
		if(ql<=l&&r<=qr)return rt;
		un mid=(l+r)>>1;node res;
		if(ql<=mid)res=res+Qmin(ql,qr,l,mid,num<<1);
		if(qr>mid)res=res+Qmin(ql,qr,mid+1,r,num<<1|1);
		return res;
	}
}sgt;
int main()
{
	n=read();
	for(ll i=1;i<=n;++i)sgt.modify(i,a[i]=read()),b[i]=pll(read(),i);
	std::sort(b+1,b+n+1),std::reverse(b+1,b+n+1);
	ll ans=0;
	for(ll i=1;i<=n-2;++i)
	{
		node t=sgt.Qmin(1,b[i].second-1)+sgt.Qmin(b[i].second+1,n);
		ans+=min(b[i].first,t.minv);
		sgt.modify(t.pos,INF);
	}
	if(sgt.Qmin(b[n].second,b[n].second)==INF)
	{
		node t=sgt.Qmin(1,b[n-1].second-1)+sgt.Qmin(b[n-1].second+1,n);
		ans+=min(b[i].first,t.minv);
		sgt.modify(t.pos,INF);
		t=sgt.Qmin(1,b[n].second-1)+sgt.Qmin(b[n].second+1,n);
		printf("%lld",ans+min(b[n].first,t.minv));
	}
	else printf("%lld",ans+
		min(b[n-1].first,a[b[n].second])+
		min(b[n].first, (sgt.Qmin(1,b[n].second-1)+sgt.Qmin(b[n].second+1,n)).minv));
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:45: error: no match for 'operator==' (operand types are 'node' and 'const ll' {aka 'const long long int'})
   65 |         if(sgt.Qmin(b[n].second,b[n].second)==INF)
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
      |                    |                          |
      |                    node                       const ll {aka const long long int}
a.cc:68:28: error: 'i' was not declared in this scope
   68 |                 ans+=min(b[i].first,t.minv);
      |                            ^
Language: C++

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
typedef long long ll;
//orz yht
using namespace std;
ll n,sum1,sum2;
vector<ll>tot;
int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    vector<pair<ll,ll> >v(n);
    for(ll i=0;i<n;i++){
    	cin>>v[i].first>>v[i].second;
    	tot.push_back(v[i].first);
    	tot.push_back(v[i].second);
	}
	for(auto x : v){
		sum1+=x.first;
		sum2+=x.second;
	}
	ll ans=min(sum1,sum2);
	ll sum=0;
	sort(tot.begin(),tot.end());
	for(ll i=0;i<n;i++)
	sum+=tot[i];
	for(ll i=0;i<n;i++){
		ll mx=max(v[i].first,v[i].second);
		ll mn=min(v[i].first,v[i].second);
		if(mn>tot[n-1] || mx<tot[n-1]){
			cout<<sum;
			return 0;
		}
		ll tmp=sum;
		tmp+=mx-tot[n-1]+max(0,mn-tot[n-2]);
		ans=min(ans,tmp);
	}
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:37: error: no matching function for call to 'max(int, ll)'
   36 |                 tmp+=mx-tot[n-1]+max(0,mn-tot[n-2]);
      |                                  ~~~^~~~~~~~~~~~~~~
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:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:36:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   36 |                 tmp+=mx-tot[n-1]+max(0,mn-tot[n-2]);
      |                                  ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:36:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |                 tmp+=mx-tot[n-1]+max(0,mn-tot[n-2]);
      |                                  ~~~^~~~~~~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  ll n;cin>>n;
  ll sum=0;
  ll c=0;
  ll d=0;
  ll sum=0;
  vector<pll> v,w;
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    if(a>=b)c++;
    if(a<=b)d++;
    sum+=min(a,b);
    v.push_back(make_pair(min(a,b),i));
    w.push_back(make_pair(max(a,b),i));
  }
  if(c==n||d==n){
    cout<<sum<<endl;
    return 0;
  }
  sort(v.begin(),v.end(),greater<pll>());
  sort(w.begin(),w.end());
  ll a=v[0].first,na=v[0].second;
  ll b=w[0].first,nb=w[0].second;
  if(na!=nb){
    cout<<sum+b-a<<endl;
  }
  else{
    ll c=v[1].first,d=w[1].first;
    cout<<sum+min(d-a,b-c)<<endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:6: error: redeclaration of 'll sum'
   10 |   ll sum=0;
      |      ^~~
a.cc:7:6: note: 'll sum' previously declared here
    7 |   ll sum=0;
      |      ^~~
Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_N 100000
#define path(x,y) (min(a[(x)], b[(y)]))

int n;
int a[MAX_N], b[MAX_N];
int cycle[MAX_N];
int cost;
int data_num = 0;

void add(const int);
void insert(int [], int, int, int);
int min(int, int);

int main(){
    int i;

    scanf("%d", &n);
    
    for(i = 0; i < n; i++)
        scanf("%d %d", &a[i], &b[i]);

    // 0 -> 1 -> 0
    cost = path(0, 1) + path(1, 0);
    if( cost < path(1, 0) + path(0, 1)){
        cycle[0] = 0;
        cycle[1] = 1;
    }else{
        cycle[0] = 1;
        cycle[1] = 0;
    }
    printf("%d\n", cost);
    for(i = 2; i < n; i++){
        add(i);
    }
    printf("%d\n", cost);
}

void add(const int n){
    int n_c[n+1];
    int i;
    int min_i;
    int min_cost = -1;
    int tmp_cost;

    min_i = 0;
    // cycle[n-1] -> cycle[0]
    // => cycle[n-1] -> n, n -> cycle[0]
    tmp_cost = path(cycle[n-1], n) + path(n, cycle[0]) - path(cycle[n-1], cycle[0]);
    min_cost = tmp_cost;

    for(i = 1; i < n; i++){
        memset(n_c, 0, sizeof(int) * (n+1));
        memcpy(n_c, cycle, sizeof(int) * n);
        tmp_cost = path(cycle[i-1], n) + path(n, cycle[i]) - path(cycle[i-1], cycle[i]);
        if(min_cost > tmp_cost){
            min_cost = tmp_cost;
            min_i = i;
        }
    }
    cost += min_cost; 
    insert(cycle, n, min_i, n);
}

void insert(int arr[], int ins_data, int ins_place, int n){
    int inserted = 0;
    int i;
    int *tmp;

    tmp = malloc(sizeof(int) * n);
    memcpy(tmp, malloc, sizeof(int) * n);

    if((0 > ins_place) || (n < ins_place)){
        return;
    }
    for(i = 0; i < n; i++){
        if(i == ins_place){
            arr[i] = ins_data;
        }
        arr[i + inserted] = tmp[i];
    }
    if(inserted == 0){
        arr[n] = ins_data;
    }
}

int min(int x, int y){
    return (x < y) ? x : y;
}


Compiler output:
a.cc: In function 'void insert(int*, int, int, int)':
a.cc:73:17: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   73 |     tmp = malloc(sizeof(int) * n);
      |           ~~~~~~^~~~~~~~~~~~~~~~~
      |                 |
      |                 void*
a.cc:74:17: error: invalid conversion from 'void* (*)(size_t) noexcept' {aka 'void* (*)(long unsigned int) noexcept'} to 'const void*' [-fpermissive]
   74 |     memcpy(tmp, malloc, sizeof(int) * n);
      |                 ^~~~~~
      |                 |
      |                 void* (*)(size_t) noexcept {aka void* (*)(long unsigned int) noexcept}
In file included from a.cc:3:
/usr/include/string.h:43:70: note:   initializing argument 2 of 'void* memcpy(void*, const void*, size_t)'
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |                                               ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
Language: C++

#include<bits/stdc++.h>
#define MAX 100005
using namespace std;

int n;
long long ans, ans2, ans3, a[200002], c, d;

int main(){
  cin >> n >> c >> d;
  ans2 = c;
  ans3 = d;
  for(int i = 0; i < n - 1; i++){
    cin >> v[i * 2] >> v[i * 2 + 1];
    ans2 += a[i * 2];
    ans3 += a[i * 2 + 1];
    if(max(a[i * 2], a[i * 2 + 1]) < max(c, d)){
      swap(a[i * 2], c);
      swap(a[i * 2 + 1], d);
    }
  }
  sort(a, a + 2 * n - 2);
  for(int i = 0; i < n - 2; i++)
    ans += a[i];
  ans += min(c + d, a[n - 2] + a[n - 1]);
  cout << min(ans, min(ans2, ans3));
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:12: error: 'v' was not declared in this scope
   13 |     cin >> v[i * 2] >> v[i * 2 + 1];
      |            ^
Language: C++

/*
    author: JioFell
    ahihi
*/
#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define fi first
#define se second
#define int long long

typedef pair<int,int> ii;
typedef pair<ii, int> pii;
const int N = 1e5 + 10;
int n, suma, sumb;
int a[N], b[N], pre[N], posa[N], posb[N];
vector<pii> tmp;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	FOR(i, 1, n)    {
        cin >> a[i] >> b[i];
        tmp.pb({{a[i], i}, 0});
        tmp.pb({ {b[i], i}, 1});
        suma += a[i];
        sumb += b[i];
	}
	int ans = min(suma, sumb);
	sort(tmp.begin(), tmp.end());
	FOR(i, 0, tmp.size() - 1)   {
	    if(tmp[i].se == 0) posa[tmp[i].fi.se] = i;
	    else posb[tmp[i].fi.se ] = i;
        pre[i] = tmp[i].fi.fi;
        if(i > 0) pre[i] += pre[i - 1];
	}
	FOR(i, 1, n)    {
        int sum = pre[n - 1];
        int cur = n - 1;
        if(posa[i] > cur) {
            sum -= tmp[cur].fi.fi;
            sum += a[i];
            cur --;
        }
        if(posb[i] > cur)   {
            if(tmp[cur].fi.se != i) {
                sum += tmp[cur].fi.fi;
                sum += b[i];
            } else {
                sum -= tmp[cur - 1].fi.fi;
                sum += b[i];
            }
        }
        ans = min(ans, sum);
	}
	cout << ans;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int A[110000], B[110000];
pint pA[110000], pB[110000];
set<int> setA, setB;
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++)cin >> A[i] >> B[i];
    for (int i = 0; i < N; i++)pA[i] = pint(A[i], i), pB[i] = pint(B[i], i);
    sort(pA, pA + N);
    sort(pB, pB + N);
    reverse(pB, pB + N);
    int ans = 0;
    int idx = -1;
    for (int i = 0; i < N; i++) {
        ans += min(pA[i].first, pB[i].first);
        if (pA[i].first <= pB[i].first) {
            setA.insert(pA[i].second), setB.insert(pB[i].second);
            idx = i;
        }
    }
    if (idx == -1 || idx == N - 1) {
        cout << ans << endl;
        return 0;
    }
    if (setA == setB) {
        bool lch = idx != 0 && pA[idx] == pB[idx], rch = idx != N - 2 && pA[idx + 1] == pB[idx + 1];
        int cur = 1145141919810LL;
        if (lch) {
            if (rch) {
                cur = min(cur, min(pA[idx].first, pB[idx + 2].first) + min(pA[idx + 1].first, pB[idx - 1].first) - pA[idx].first - pB[idx + 2].first);
                cur = min(cur, min(pA[idx - 1].first, pB[idx + 2].first) + min(pA[idx + 1].first, pB[idx].first) - pA[idx - 1].first - pB[idx + 2].first);
                cur = min(cur, min(pA[idx].first, pB[idx + 1].first) + min(pA[idx + 2].first, pB[idx - 1].first) - pA[idx].first - pB[idx + 1].first);
                cur = min(cur, min(pA[idx - 1].first, pB[idx + 1].first) + min(pA[idx + 2].first, pB[idx].first) - pA[idx - 1].first - pB[idx + 1].first);
            } else {
                cur = min(cur, min(pA[idx].first, pB[idx + 1].first) + min(pA[idx + 1].first, pB[idx - 1].first) - pA[idx].first - pB[idx + 1].first);
                cur = min(cur, min(pA[idx - 1].first, pB[idx + 1].first) + min(pA[idx + 1].first, pB[idx].first) - pA[idx - 1].first - pB[idx + 1].first);
        } else {
            if (rch) {
                cur = min(cur, min(pA[idx].first, pB[idx + 2].first) + min(pA[idx + 1].first, pB[idx].first) - pA[idx].first - pB[idx + 2].first);
                cur = min(cur, min(pA[idx].first, pB[idx + 2].first) + min(pA[idx + 1].first, pB[idx].first) - pA[idx].first - pB[idx + 2].first);
            } else {
                cur = min(cur, min(pA[idx].first, pB[idx + 1].first) + min(pA[idx + 1].first, pB[idx].first) - pA[idx].first - pB[idx + 1].first);
            }
        }
        ans += cur;
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:11: error: expected '}' before 'else'
   47 |         } else {
      |           ^~~~
a.cc:38:18: note: to match this '{'
   38 |         if (lch) {
      |                  ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using int = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct QF {
  V<> par;
  V< set<int> > chi;

  QF(int n) : par(n), chi(n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      chi[i].insert(i);
    }
  }

  bool same(int a, int b) { return par[a] == par[b]; }

  int size(int a) { return chi[par[a]].size(); }

  void unite(int a, int b) {
    if (same(a, b)) return;
    if (size(a) < size(b)) swap(a, b);
    a = par[a], b = par[b];
    for (int i : chi[b]) par[i] = a;
    chi[a].insert(chi[b].begin(), chi[b].end());
    chi[b].clear();
  }
};


int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  V< pair<int, int> > ps(2 * n);
  for (int i = 0; i < n; i++) {
    ps[i] = {a[i], i};
    ps[i + n] = {b[i], i + n};
  }
  sort(ps.begin(), ps.end());
  QF qu(n);
  int p = 0;
  V<bool> used(2 * n);
  V< pair<int, int> > ap(n), bp(n);
  for (int i = 0; i < n; i++) ap[i] = {a[i], i}, bp[i] = {b[i], i + n};
  sort(ap.rbegin(), ap.rend());
  sort(bp.rbegin(), bp.rend());
  int pa = 0, pb = 0;
  lint res = 0;
  for (int i = 0; i < n - 1; i++) {
    while (p < n - 1 and used[ps[p].second]) p++;
    while (pa < n - 1 and used[ap[pa].second]) pa++;
    while (pb < n - 1 and used[bp[pb].second]) pb++;
    res += ps[p].first;
    if (ps[p].second < n) {
      while (true) {
        if (!qu.same(ps[p].second, bp[pb].second - n)) break;
        pb++;
        while (pb < n - 1 and used[bp[pb].second]) pb++;
      }
      qu.unite(ps[p].second, bp[pb].second - n);
      used[ps[p++].second] = true;
      used[bp[pb++].second] = true;
    } else {
      while (true) {
        if (!qu.same(ps[p].second - n, ap[pa].second)) break;
        pa++;
        while (pa < n - 1 and used[ap[pa].second]) pa++;
      }
      qu.unite(ps[p].second - n, ap[pa].second);
      used[ps[p++].second] = true;
      used[ap[pa++].second] = true;
    }
  }
  int mn = 2e9;
  for (int i = 0; i < 2 * n; i++) if (!used[ps[i].second]) mn = min(mn, ps[i].first);
  cout << res + mn << '\n';
}

Compiler output:
a.cc:3:7: error: expected nested-name-specifier before 'int'
    3 | using int = long long int;
      |       ^~~
a.cc: In function 'int main()':
a.cc:53:3: error: 'lint' was not declared in this scope; did you mean 'uint'?
   53 |   lint res = 0;
      |   ^~~~
      |   uint
a.cc:58:5: error: 'res' was not declared in this scope
   58 |     res += ps[p].first;
      |     ^~~
a.cc:81:11: error: 'res' was not declared in this scope
   81 |   cout << res + mn << '\n';
      |           ^~~
Language: C++

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
long long N;
long long A[100000];
long long B[100000];
int main(){
	cin>>N;
	long long sum=0;
	long long l=0,r=0;
	for(int i=0;i<N;i++){
		cin>>A[i]>>B[i];
		sum+=min(A[i],B[i]);
		l+=A[i];r+=B[i];
	}
	sort(A,A+N);
	sort(B,B+N,greater<long long>());
	long long ans=0;
	vector<long long > V,v;
	for(int i=0;i<N;i++){
		ans+=min(A[i],B[i]);
		V.push_back(min(A[i],B[i]));
		v.push_back(max(A[i],B[i]));
	}
	sort(V.rbegin(),V.rend());
	sort(v.begin(),v.end());
	if(ans!=sum){
		cout<<ans<<endl;
		return 0;
	}else{
		if(l==ans||r==ans){
			cout<<ans<<endl
			return 0;
		}
	}
	ans-=V[0];
	ans+=v[0];
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:40: error: expected ';' before 'return'
   48 |                         cout<<ans<<endl
      |                                        ^
      |                                        ;
   49 |                         return 0;
      |                         ~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;
typedef long long int;

int main(){
  int n;
  cin >> n;
  vector<pair<LL,LL>> a(2*n);
  for(int i=0;i<2*n;i++){
    cin >> a[i].first;
    a[i].second=i;
  }
  sort(a.begin(),a.end());
  LL t=0;
  vector<bool> aa(n,false),bb(n,false);
  for(int i=0;i<n;i++){
    t+=a[i].first;
    if(a[i].second%2==0){
      aa[a[i].second/2]=true;
    }else{
      bb[a[i].second/2]=true;
    }
  }
  LL ca=0,cb=0,cc=0;
  for(int i=0;i<n;i++){
    if(aa[i]&bb[i]){
      cc++;
    }else if(aa[i]){
      ca++;
    }else if(bb[i]){
      cb++;
    }
  }
  LL ta=INF,tb=INF;
  bool okflag;
  if(cc>0||ca==0||cb==0){
    cout << t << endl;
    return 0;
  }
  int ccc=0;
  for(int i=n-1;i>0;i--){
    if(a[i].second%2==1){
      ccc++;
      for(int j=n;j<2*n;j++){
        if(a[j].second%2==0&&a[i].second/2!=a[j].second/2){
          okflag=false;
          for(int k=j+1;k<2*n;k++) if(a[k].second%2==1) okflag=true;
          if(okflag){
            okflag=false;
            for(int k=i-1;k>=0;k--) if(a[k].second%2==0) okflag=true;
            if(okflag) ta=t-a[i].first+a[j].first;
          }
          break;
        }
      }
      if(ccc==2) break;
    }
  }
  ccc=0;
  for(int i=n-1;i>0;i--){
    if(a[i].second%2==0){
      ccc++;
      for(int j=n;j<2*n;j++){
        if(a[j].second%2==1&&a[i].second/2!=a[j].second/2){
          okflag=false;
          for(int k=j+1;k<2*n;k++) if(a[k].second%2==0) okflag=true;
          if(okflag){
            okflag=false;
            for(int k=i-1;k>=0;k--) if(a[k].second%2==1) okflag=true;
            if(okflag) tb=t-a[i].first+a[j].first;
          }
          break;
        }
      }
      if(ccc==2) break;
    }
  }
  t=min(ta,tb);
  ta=tb=0;
  for(int i=0;i<2*n;i++){
    if(a[i].second%2==0){
      ta+=a[i].first;
    }else{
      tb+=a[i].first;
    }
  }
  int count=0;
  okflag=true;
  for(int i=0;i<2*n;i++){
    if(a[i].second%2==0){
      count++;
    }else{
      count--;
    }
    if(count<0) okflag=false;
  }
  if(okflag) t=min(t,ta);
  count=0;
  okflag=true;
  for(int i=0;i<2*n;i++){
    if(a[i].second%2==0){
      count--;
    }else{
      count++;
    }
    if(count<0) okflag=false;
  }
  if(okflag) t=min(t,tb);
  cout << t << endl;
  return 0;
}


Compiler output:
a.cc:19:19: error: declaration does not declare anything [-fpermissive]
   19 | typedef long long int;
      |                   ^~~
Language: C++

#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n;
     rep(i,n){
       cin>>a[i]>>b[i];
       ans+=min(a[i],b[i]);
     }
     Cout(ans);
    
       
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:14: error: invalid types 'long long int[long long int]' for array subscript
   33 |        cin>>a[i]>>b[i];
      |              ^
a.cc:33:20: error: invalid types 'long long int[long long int]' for array subscript
   33 |        cin>>a[i]>>b[i];
      |                    ^
a.cc:34:18: error: invalid types 'long long int[long long int]' for array subscript
   34 |        ans+=min(a[i],b[i]);
      |                  ^
a.cc:34:23: error: invalid types 'long long int[long long int]' for array subscript
   34 |        ans+=min(a[i],b[i]);
      |                       ^
Language: C++

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
struct node{
	ll X,Y;
};
inline bool operator < (node p,node q){if(p.X!=q.X)return p.X<q.X;else return p.Y>q.Y;} 
struct nd{
	ll X,Y;
};
inline bool operator < (nd p,nd q){if(p.Y!=q.Y)return p.Y<q.Y;else return p.X>q.X;}
multiset<node> q1;
multiset<nd> q2;
multiset<node> q3;
multiset<nd> q4;
inline void Solve()
{	ll ans=1e18;
	ll res=0;
//	while(q1.size()>1)
//	{	
//		node tmp=*q1.begin();
//		q1.erase(q1.find(tmp));
//		nd tmp2;tmp2.X=tmp.X;tmp2.Y=tmp.Y;
//		q2.erase(q2.find(tmp2));
//		nd tmp3=*q2.rbegin();
//		q2.erase(q2.find(tmp3));
//		q1.erase(q1.find((node){tmp3.X,tmp3.Y}));
//		res+=min(tmp.X,tmp3.Y);
//		node tmp4=(node){tmp3.X,tmp.Y};
//		q1.insert(tmp4);
//		nd tmp5;tmp5.X=tmp4.X;tmp5.Y=tmp4.Y;
//		q2.insert(tmp5);
//	}node tt=*q1.begin();
//	res+=min(tt.X,tt.Y);ans=res;
	res=0;
	while(q4.size()>1)
	{
		nd tmp=*q4.begin();
		q4.erase(q4.find(tmp));
		node tmp2;tmp2.X=tmp.X;tmp2.Y=tmp.Y;
		q3.erase(q3.find(tmp2));
		node tmp3=*q3.rbegin();
		q3.erase(q3.find(tmp3));
		q4.erase(q4.find((nd){tmp3.X,tmp3.Y})); 
		res+=min(tmp.Y,tmp3.X);
		nd tmp4=(nd){tmp.X,tmp3.Y};
		q4.insert(tmp4);
		node tmp5;tmp5.X=tmp4.X;tmp5.Y=tmp4.Y;
		q3.insert(tmp5);
	}tt=*q3.begin();
	res+=min(tt.X,tt.Y);ans=min(ans,res);
	cout<<ans;
}
int main()
{	int n;
	n=read();
	for(rint i=1;i<=n;++i)
	{
		int a=read(),b=read();
		node tmp1=(node){a,b};
		nd tmp2=(nd){a,b};
		q1.insert(tmp1);q3.insert(tmp1);
		q2.insert(tmp2);q4.insert(tmp2);
	}
	Solve();
	return 0;
}

Compiler output:
a.cc: In function 'void Solve()':
a.cc:54:10: error: 'tt' was not declared in this scope; did you mean 'tm'?
   54 |         }tt=*q3.begin();
      |          ^~
      |          tm
a.cc: In function 'int main()':
a.cc:61:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   61 |         for(rint i=1;i<=n;++i)
      |                  ^
Language: C++

#include <iostream>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct KT {
  int a, b, c;

  bool operator<(const KT& right ) const {
    return a < right.a;
  }
};

signed main() {
  int n;
  int a[100001], b[100001];
  KT p[200001];
  cin >> n;
  rep(i, 0, n) {
    cin >> a[i] >> b[i];
    p[i * 2] = {a[i], i, 0};
    p[i * 2 + 1] = {b[i], i, 1};
  }
  sort(p, p + n * 2);
  bool u[100001] = {};
  bool f = false;
  int sum = 0;
  int ka = 0, kb = 0;
  rep(i, 0, n) {
    if(u[p[i].b]) f = true;
    else {
      u[p[i].b] = true;
    }
    if(p[i].c) ka++;
    else kb++;
    sum += p[i].a;
  }
  if(!ka || !kb) f = true;
  if(f) {
    cout << sum << endl;
  }else {
    if(p[n - 1].b == p[n].b && n > 3) {
      cout << sum - p[n - 1].a + p[n + 1].a << endl;
    }else {
      cout << sum - p[n - 1].a + p[n].a << endl;
    }
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:38:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   38 |   sort(p, p + n * 2);
      |   ^~~~
      |   short
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<int> a(n), b(n);
  rep(i,n) cin>>a[i]>>b[i];

  set<pair<int,int>> vl,vr;
  rep(i,n){
    vl.insert({a[i], i});
    vr.insert({b[i], i});
  }

  long ans = 0;
  int mina = INT_MAX, minb = INT_MAX;
  while(vl.size() + vr.size()) {
    if(vl.begin()->first > vr.begin()->first){
      swap(vl,vr);
      swap(a,b);
      swap(mina, minb);
    }

    auto p = *(vl.begin());
    auto itr = vr.rbegin();
    dbg(p,*itr);
    while(itr != vr.rend() && (p.first > itr->first || p.second == itr->second) ) itr++,dbg(p,*itr);
    if(itr == vr.rend()){
      // assert(false);
      itr--;
    }

    ans += p.first;

    vl.erase(p);
    vr.erase(*itr);
  }

  cout << ans << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:18: error: expected primary-expression before '{' token
   17 | #define dbg(...) {}
      |                  ^
a.cc:44:89: note: in expansion of macro 'dbg'
   44 |     while(itr != vr.rend() && (p.first > itr->first || p.second == itr->second) ) itr++,dbg(p,*itr);
      |                                                                                         ^~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> ii;

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, a[N], b[N];
int pb[N], pa[N];
int posa[N], posb[N];

vector<int> mem[N];
int gr[N];


void merge(int x, int y) {
    x = gr[pa[x]], y = gr[pa[y]];
    assert(x != y);
    if (mem[x].size() > mem[y].size()) swap(x,y);
    for(auto i : mem[x]){
        gr[i] = y;
        mem[y].push_back(i);
    }
}


int get(int x){
    return min(a[pa[x]], b[pb[x]]);
}
int cost(int x){
    swap(pb[x], pb[x + 1]);
    int ans = get(x) + get(x + 1);
    swap(pb[x], pb[x + 1]);
    ans -= get(x) + get(x + 1);
    return ans;
}
long long solve() {
    int ngr = 0;
    for(int st = 1; st <= n; st++) if (!gr[pa[st]]){
        ++ngr;
        int cur = st;
        while (!gr[pa[cur]]) {
            gr[pa[cur]] = ngr;
            mem[ngr].push_back(pa[cur]);
            cur = posa[pb[cur]];
        }
    }
    priority_queue<ii, vector<ii>, greater<ii>> pq;
    for(int i = 1; i < n; i++) {
        pq.push(ii(cost(i), i));
    }
    long long ans = 0;
    for(int i = 1; i <= n; i++) ans += get(i);
    while (ngr != 1){
        ii cur = pq.top(); pq.pop();
        int pos = cur.second;
        if (gr[pa[pos]] == gr[pa[pos + 1]]) continue;
        if (cur.first != cost(pos)) continue;
        ans += cost(pos);
        swap(pb[pos], pb[pos + 1]);
        merge(pos, pos + 1);
        for(int j = max(1, pos - 1); j <= min(pos + 1, n - 1); j++){
            pq.push(ii(cost(j), j));
        }
        ngr--;
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];

    long long ans = 1e18;
    for(int j = 0; j <= 1; j++){
            for(int i = 1; i <= n; i++) mem[i].clear();
            memset(gr, gr + n + 1, 0);
            for(int i = 1; i <= n; i++) pb[i] = pa[i] = i;
            sort(pa + 1, pa + n + 1, [](int x, int y){return a[x] < a[y];});
            sort(pb + 1, pb + n + 1, [](int x, int y){return b[x] > b[y];});
            for(int i = 1; i <= n; i++){
                posa[pa[i]] = i;
                posb[pb[i]] = i;
            }
            ans = min(ans,solve());
            for(int i = 1; i <= n; i++) swap(a[i], b[i]);
    }
    cout << ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:80:31: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   80 |             memset(gr, gr + n + 1, 0);
      |                        ~~~~~~~^~~
      |                               |
      |                               int*
In file included from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/string.h:61:37: note:   initializing argument 2 of 'void* memset(void*, int, size_t)'
   61 | extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
      |                                 ~~~~^~~
Language: C++

#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct KT {
  int a, b, c;

  bool operator<(const KT& right ) const {
    return a < right.a;
  }
};

signed main() {
  int n;
  int a[100001], b[100001];
  KT p[200001];
  cin >> n;
  rep(i, 0, n) {
    cin >> a[i] >> b[i];
    p[i * 2] = {a[i], i, 0};
    p[i * 2 + 1] = {b[i], i, 1};
  }
  sort(p, p + n * 2);
  bool u[100001] = {};
  bool f = false;
  int sum = 0;
  int ka = 0, kb = 0;
  rep(i, 0, n) {
    if(u[p[i].b]) f = true;
    else {
      u[p[i].b] = true;
    }
    if(p[i].c) ka++;
    else kb++;
    sum += p[i].a;
  }
  if(!ka || !kb) f = true;
  if(f) {
    cout << sum << endl;
  }else {
    cout << sum - p[n - 1].a + p[n].a << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   40 |   sort(p, p + n * 2);
      |   ^~~~
      |   short
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> a(2*n);
  for(int i=0;i<2*n;i++){
    cin >> a[i].first;
    a[i].second=i;
  }
  sort(a.begin(),a.end());
  LL t=0;
  vector<bool> aa(n,false),bb(n,false);
  for(int i=0;i<n;i++){
    t+=a[i].first;
    if(a[i].second%2){
      aa[a[i].second/2]=true;
    }else{
      bb[a[i].second/2]=true;
    }
  }
  int ca=0,cb=0,cc=0;
  for(int i=0;i<n;i++){
    if(aa[i]&bb[i]){
      cc++;
    }else if(aa[i]){
      ca++;
    }else if(bb[i]){
      cb++;
    }
  }
  LL ta=INF,tb=INF;
  bool okflag;
  if(cc>0||ca==0||cb==0){
    cout << t << endl;
    return 0;
  }
  for(int i=n;i>=0;i--){
    if(a[i].second%2==1){
      for(int j=n+1;j<2*n;j++){
        if(a[j].second%2==0&&aa[a[j].second/2]){
          okflag=false;
          for(int k=j+1;k<2*n;k++) if(a[k].second%2==1) okflag=true;
          if(okflag) ta=t-a[i].first+a[j].first;
          break;
        }
      }
      break;
    }
  }
  for(int i=n;i>=0;i--){
    if(a[i].second%2==0){
      for(int j=n+1;j<2*n;j++){
        if(a[j].second%2==1&&bb[a[j].second/2]){
          okflag=false;
          for(int k=j+1;k<2*n;k++) if(a[k].second%2==0) okflag=true;
          if(okflag) tb=t-a[i].first+a[j].first;
          break;
        }
      }
      break;
    }
  }
  t=min(ta,tb);
  ta=tb=0;
  for(int i=0;i<2*n;i++){
    if(a[i].second%2){
      ta+=a[i].first;
    }else{
      tb+=b[i].first;
    }
  }
  int count=0;
  okflag=true;
  for(int i=0;i<2*n;i++){
    if(a[i].second%2){
      count++;
    }else{
      count--;
    }
    if(count<0) okflag=false;
  }
  if(okflag) t=min(t,ta);
  count=0;
  okflag=true;
  for(int i=0;i<2*n;i++){
    if(a[i].second%2){
      count--;
    }else{
      count++;
    }
    if(count<0) okflag=false;
  }
  if(okflag) t=min(t,tb);
  cout << t << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:87:11: error: 'b' was not declared in this scope
   87 |       tb+=b[i].first;
      |           ^
Language: C++

#include<iostream>
#include<algorithm>
#include<stdint>
using namespace std;

const int MAX = 100000;
int main() {
	int N, A, B;
	static pair<pair<int, int>, int> G[MAX], G2[MAX];
	cin >> N;
	for (int i = 0;i < N;++ i) {
		cin >> A >> B;
		G[i] = make_pair(make_pair(A, B), i);
		G2[i] = make_pair(make_pair(B, A), i);
	}
	sort(G, G+N);
	sort(G2, G2+N);
	int64_t BSum = 0;
	for (int i = 0;i < N;++ i) BSum += G[i].first.second;
	
	int64_t ans = BSum, tmp = ans;
	if (G[0].second == G2[N - 1].second) {
		ans = min(ans, tmp + G[0].first.first - G2[N - 2].first.first);
	}
	for (int i = 0, j = 0;i < N;++ i) {
		tmp += G[i].first.first;
		while (j < N && (G2[j].first.first < G[i].first.first || G2[j].second == -1)) ++ j;
		if (j >= N) break;
		if (G2[j].second == G[i].second) {
			if (j >= N - 1) break;
			G2[j + 1].second = -1;
			tmp -= G2[N - i - 1].first.first;
		} else {
			G2[j].second = -1;
			tmp -= G2[N - i - 1].first.first;
		}
		if (i != 0 || G[0].second != G2[N - 1].second) ans = min(ans, tmp);
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

3
[1] 5
[4] [2]
6 3

4
[1] 5
[2] 6
[3] 7
[4] 8

6
[19] 92
[64] 64
78 [48]
[57] [33]
73 [6]
95 73

まず、最も小さい値のみを選ぶことができないか考える
これができない時とは？相手側に自分より小さい値が存在しない時
そこで、Aから選ぶ個数を決め打ってしまう
その時、Bの方にちゃんと対応関係を作れればok

さて、これが可能か考える

6
[19] 92
[57] [33]
[64] 64
73 [6]
78 [48]
95 73
の場合で考えると、次のようになる
[19] - 92, 73, 64, 48, 33, 6 - 可能, この時はBsum-92+19だけのコスト
[19][57] - 92, 73, 64, 48, 33, 6 - 可能、この時はBsum-92-33+19+57だけのコスト
[19][57][64] - 92, 73, 64, 48, 33, 6 - 可能(19-33,57-64,64-73)
[19][57][64][73] - 92, 73, 64, 48, 33, 6 - 可能(19-33,57-64,64-73,73-92)、同文
[19][57][64][73][78] - 不可能(19-33,57-64,64-73,73-92,78-×)

さて、これA決め打ちなのでコストO(N)
で、見てみると分かるがマッチングは前の計算を使えるので全体O(N)
で、もしマッチング成立した場合は任意により大きい数に繋ぎなおせる(ただし1個の場合を除く)ので
この時のコスト計算はマッチングしたのをBSumから外すのでO(1)
全体O(N)
*/

Compiler output:
a.cc:3:9: fatal error: stdint: No such file or directory
    3 | #include<stdint>
      |         ^~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long 
#define pb push_back
#define fr first
#define sc second
#define MAX ((ll)(2e17+100))
#define MX ((ll)(1e6+100))
#define ARRS ((ll)(3e6+600))
#define HS ((ll)(233))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;

ll n,m;
pair<ll,ll> a[ARRS];
ll f[ARRS];
pair<ll,ll> b[ARRS];
ll pr[ARRS];

ll par(ll x){
	if(pr[x]==x)return x;
	else return pr[x]=par(pr[x]);
}

void join(ll x,ll y){
	x=par(x);
	y=par(y);
	pr[y]=x;
}


int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>a[i].fr>>b[i].fr;
		a[i].sc=i;
		b[i].sc=i;
	}
	sort(a,a+n);
	sort(b,b+n);
	reverse(b,b+n);
	ll pas=0;
	for(int i=0; i<n; i++)pr[i]=i;
	stack<ll> sk;
	ll j=0;
	for(int i=0; i<n; i++){
		ll x=a[i].sc; 
		bool e=1;
		if(sk.size()){
			ll y=sk.front();
			if(par(x)!=par(b[y].sc)){
				e=0;
				//cout<<x<<" "<<b[y].sc<<endl;
				pas+=min(a[i].fr,b[y].fr);
				join(x,b[y].sc);
				sk.pop();
			}
		}
		//cout<<i<<endl;
		if(e){
			while(j<n&&(par(x)==par(b[j].sc)))
				sk.push(j),j++;

			if(j<n){
				join(x,b[j].sc);
				pas+=min(a[i].fr,b[j].fr);
				j++;
			}
		}
	}
	//cout<<sk.size()<<endl;
	if(sk.size())
		pas+=min(a[n-1].fr,b[sk.front()].fr);
	cout<<pas;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:33: error: 'class std::stack<long long int>' has no member named 'front'
   55 |                         ll y=sk.front();
      |                                 ^~~~~
a.cc:78:41: error: 'class std::stack<long long int>' has no member named 'front'
   78 |                 pas+=min(a[n-1].fr,b[sk.front()].fr);
      |                                         ^~~~~
Language: C++

#include<bits/stdc++.h>

#define M 1000000007
#define maxn 303

using namespace std;
typedef long long ll;

inline add(ll a, ll b) {return a + b < M ? a + b : a + b - M;}
inline sub(ll a, ll b) {return a - b < 0 ? a - b + M : a - b;}
inline mult(ll a, ll b) {return a * b % M;}

int n, k;
int a[maxn], b[maxn];

ll d[maxn][maxn];
int s[maxn][maxn];

ll g[maxn];

int main(){
  #define TASK "ABC"
  //freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n >> k;
  n *= 2;
  
  for (int i = 0; i < k; ++i) {
  	int x, y;
	cin >> x >> y;
	a[i] = min(x, y);
	b[i] = max(x, y);
	
	s[x][x] = s[y][y] = 1;
  }
  
  g[0] = 1;
  for (int i = 2; i <= n; i += 2) 
  	g[i] = mult(g[i - 2], i - 1);
  	
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
	  s[i][j] = s[i][j - 1] + s[j][j]; 
  
  ll ans = 0;
  for (int l = 1; l < n; l += 2)
  	for (int i = 1; i + l <= n; ++i) {
	  int j = i + l;
	
	  bool flag = 0;   
	  
	  for (int ik = 0; ik < k; ++ik) 
	    if ((i <= a[ik] && a[ik] <= j) ^ (i <= b[ik] && b[ik] <= j)) 
	      flag = 1;
	    	
	  if (flag) continue;
	  
	  d[i][j] = g[l + 1 - s[i][j]];
	  
	  for (int ik = i + 1; ik < j; ik += 2) 
	  	d[i][j] = sub(d[i][j], mult(d[i][ik], g[j - ik - s[ik + 1][j]]));
	  
	  ans = add(ans, mult(d[i][j], g[n - 2 * k + s[i][j] - l - 1]));	  
	}
	
  cout << ans;
  
  return 0;
}

Compiler output:
a.cc:9:8: error: ISO C++ forbids declaration of 'add' with no type [-fpermissive]
    9 | inline add(ll a, ll b) {return a + b < M ? a + b : a + b - M;}
      |        ^~~
a.cc:10:8: error: ISO C++ forbids declaration of 'sub' with no type [-fpermissive]
   10 | inline sub(ll a, ll b) {return a - b < 0 ? a - b + M : a - b;}
      |        ^~~
a.cc:11:8: error: ISO C++ forbids declaration of 'mult' with no type [-fpermissive]
   11 | inline mult(ll a, ll b) {return a * b % M;}
      |        ^~~~
Language: C++

#include<bits/stdc++.h>

#define M 1000000007
#define maxn 303

using namespace std;
typedef long long ll;

inline add(ll a, ll b) {return a + b < M ? a + b : a + b - M;}
inline sub(ll a, ll b) {return a - b < 0 ? a - b + M : a - b;}
inline mult(ll a, ll b) {return a * b % M;}

int n, k;
int a[maxn], b[maxn];

ll d[maxn][maxn];
int s[maxn][maxn];

ll g[maxn];

int main(){
  #define TASK "ABC"
 // freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n >> k;
  n *= 2;
  
  for (int i = 0; i < k; ++i) {
  	int a, b;
	cin >> a >> b;
	::a[i] = min(a, b);
	::b[i] = max(a, b);
	
	s[a][a] = s[b][b] = 1;
  }
  
  g[0] = 1;
  for (int i = 2; i <= n; i += 2) 
  	g[i] = mult(g[i - 2], i - 1);
  	
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
	  s[i][j] = s[i][j - 1] + s[j][j]; 
  
  ll ans = 0;
  for (int l = 1; l < n; l += 2)
  	for (int i = 1; i + l <= n; ++i) {
	  int j = i + l;
	
	  bool flag = 0;   
	  
	  for (int ik = 0; ik < k; ++ik) 
	    if ((i <= a[ik] && a[ik] <= j) ^ (i <= b[ik] && b[ik] <= j)) 
	      flag = 1;
	    	
	  if (flag) continue;
	  
	  d[i][j] = g[l + 1 - s[i][j]];
	  
	  for (int ik = i + 1; ik < j; ik += 2) 
	  	d[i][j] = sub(d[i][j], mult(d[i][ik], g[j - ik - s[ik + 1][j]]));
	  
	  ans = add(ans, mult(d[i][j], g[n - 2 * k + s[i][j] - l - 1]));	  
	}
	
  cout << ans;
  
  return 0;
}

Compiler output:
a.cc:9:8: error: ISO C++ forbids declaration of 'add' with no type [-fpermissive]
    9 | inline add(ll a, ll b) {return a + b < M ? a + b : a + b - M;}
      |        ^~~
a.cc:10:8: error: ISO C++ forbids declaration of 'sub' with no type [-fpermissive]
   10 | inline sub(ll a, ll b) {return a - b < 0 ? a - b + M : a - b;}
      |        ^~~
a.cc:11:8: error: ISO C++ forbids declaration of 'mult' with no type [-fpermissive]
   11 | inline mult(ll a, ll b) {return a * b % M;}
      |        ^~~~