stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <map>

#include <cmath>

#include <queue>

#include <numeric>

#include <climits>

#include <iterator>

#include <iomanip>

#include <stack>

#include <bitset>

#include <functional>

using namespace std;

const constexpr int INF = 1e9;

//typedef std::pair<std::string,double> P;

 

 

typedef long long ll;

typedef vector<int> VI;

    

vector<pair<int, int> > vp;

 

struct Less {

    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {

        return x.first > y.first;

    }

};

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)

#define REP(i, n) FOR(i, 0, n)



ll GCD(ll a, ll b){

    if(b==0) return a;

    return GCD(b, a%b);

}

//グラフの隣接リスト

VI g[200010];

//頂点の入次数を管理

int h[100010];

ll N, K;

string s;

ll a[100010];

int main(void) {

    cin >> N >> K;

    REP(i, N) cin >> a[i];

    

    ll gcd=a[0];

    ll maxV=0;

    

    REP(i, N) maxV = max(maxV, a[i]);

    

    for(int i=1; i<N; ++i){

        gcd = GCD(gcd, a[i]);

    }

    if(K%gcd==0&&maxV>=K) cout << "POSSIBLE" << endl;

    else cout << "IMPOSSIBLE" << endl; 

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.47614080482128x):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <queue>

using namespace std;

using ll = long long;

#define INF 1LL << 59

//西暦⇒時代の歴



ll a[201000];

ll N, K;

ll GCD(ll a, ll b)

{

    if (a < b)

        swap(a, b);



    if (b == 0)

        return a;

    return GCD(b, a % b);

}

int main()

{

    cin >> N >> K;

    ll maxV = 0;

    for (int i = 0; i < N; ++i)

    {

        cin >> a[i];

        maxV = max(maxV, a[i]);

    }

    if (N == 1)

    {

        if (a[0] == K)

            cout << "POSSIBLE" << endl;

        else

            cout << "IMPOSSIBLE" << endl;

        return 0;

    }

    ll d = GCD(a[0], a[1]);



    for (int i = 2; i < N; ++i)

    {

        d = GCD(d, a[i]);

    }

    if (K % d == 0 && maxV >= K)

        cout << "POSSIBLE" << endl;

    else

        cout << "IMPOSSIBLE" << endl;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#include<tr1/unordered_map>

#define CLR(a,x) memset(a,x,sizeof(a))

#define MP make_pair

#define fi first

#define se second

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<int,int> pa;

const int maxn=1e5+10;



inline ll rd(){

    ll x=0;char c=getchar();int neg=1;

    while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}

    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();

    return x*neg;

}



int N,K;



inline int gcd(int a,int b){return a?gcd(b%a,a):b;}



int main(){

    //freopen("","r",stdin);

	N=rd(),K=rd();

	int g=0,ma=0;

	for(int i=1;i<=N;i++){

		int x=rd();

		g=gcd(g,x);

		ma=max(ma,x);

	}

	if(ma>=K&&K%g==0) printf("POSSIBLE\n");

	else printf("IMPOSSIBLE\n");

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.206406666316402x):
#include <algorithm>

#include <cstdio>



using namespace std;



int n,k,a,ak,h,i;



int max(int a,int b)

{return(a>b?a:b);}



int main()

{

    scanf("%d %d %d",&n,&k,&a);

    h=a;

    for(i=2;i<=n;++i)

    {

        scanf("%d",&ak);

        a=__gcd(a,ak);

        h=max(ak,h);

    }

    if(k%a==0&&k<=h)printf("POSSIBLE\n");

    else printf("IMPOSSIBLE\n");

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

    int N, K;

    cin >> N >> K;

    vector<int> A(N);

    for(int i = 0; i < N; ++i) {

        cin >> A[i];

    }



    int g = 0;

    int ma = 0;

    for(int i = 0; i < N; ++i) {

        g = __gcd(g, A[i]);

        ma = max(ma, A[i]);

    }

    if(ma >= K && K % g == 0) {

        cout << "POSSIBLE" << endl;

    } else {

        cout << "IMPOSSIBLE" << endl;

    }

}


// Faster C++ solution for the same problem (measured speedup: 5.354883219586356x):
#include <cstdio>

#include <cstdlib>



const int MAXN=100011;



int gcd(int a, int b){

	return (b==0)?a:gcd(b, a%b);

}



void Show(bool i){

	if(i)	puts("POSSIBLE");

	else	puts("IMPOSSIBLE");

}



int N, K;

int A[MAXN], G;



void Test(int a){

	if(a>=0 && a%G==0){

		Show(true);

		exit(0);

	}

}



int main(){

	

	scanf("%d%d", &N, &K);

	for(int i=1;i<=N;++i)	scanf("%d", &A[i]);

	

	G=0;

	for(int i=1;i<=N;++i)	G=gcd(A[i], G);

	

	for(int i=1;i<=N;++i)	Test(A[i]-K);

	

	Show(false);

	

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include <complex>



using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;

//#define double float



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL) INF;



const double EPS = 1e-6;

const int MAX = 2000 +47;

const int MIN = 50 + 7;

const int MOD = INF;



int gcd(int a, int b)

{

    if (a == 0)return b;

    return gcd(b % a, a);

}



int main()

{

    int n, m;

    scanf("%d%d", &n, &m);

    int g = 0;

    int mx = 0;

    FOR(i, 0, n)

    {

        int x;

        scanf("%d", &x);

        if (x == m)

        {

            cout << "POSSIBLE" << endl;

            return 0;

        }

        mx = max(mx, x);

        g = gcd(g, x);

    }

    

    if (m > mx || m % g)

    {

        cout << "IMPOSSIBLE" << endl;

        return 0;

    }

    cout << "POSSIBLE" << endl;

    

    

}


// Faster C++ solution for the same problem (measured speedup: 5.257092290367591x):
#include <cstdio>

#include <cstdlib>



const int MAXN=100011;



int gcd(int a, int b){

	return (b==0)?a:gcd(b, a%b);

}



void Show(bool i){

	if(i)	puts("POSSIBLE");

	else	puts("IMPOSSIBLE");

}



int N, K;

int A[MAXN], G;



void Test(int a){

	if(a>=0 && a%G==0){

		Show(true);

		exit(0);

	}

}



int main(){

	

	scanf("%d%d", &N, &K);

	for(int i=1;i<=N;++i)	scanf("%d", &A[i]);

	

	G=0;

	for(int i=1;i<=N;++i)	G=gcd(A[i], G);

	

	for(int i=1;i<=N;++i)	Test(A[i]-K);

	

	Show(false);

	

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define max(x,y) ((x)>(y)?(x):(y))

#define min(x,y) ((x)<(y)?(x):(y))

typedef long long ll;

typedef pair<int,int> pii;

const int maxn=1010;

map<int,int> cnt,tmp;

vector<int> gt[100001];

struct req {long long x; long long d;};

deque<req> q;

int n,a,b,i,j,m,c,d,k;

int fac[8]={1,1,2,6,24,120,720,5040};

vector<string> prim; string cur;

vector<int> fin={2,3,5,7};

int p(int x)

{

	int a=sqrt(x);

	for (int i=2;i<=a;i++) if (x%i); else return 0;

	return 1;

}

int cmp (string a, string b)

{

	if (a.length()-b.length()) return (a.length()<b.length());

	return (a<b);

}

int expect(string a)

{

	int n=a.length(),cnt1=0,cnt3=0,cnt7=0,cnt9=0;

	for (int i=0;i<n;i++)

	{

		if (a[i]=='1') cnt1++;

		if (a[i]=='3') cnt3++;

		if (a[i]=='7') cnt7++;

		if (a[i]=='9') cnt9++;

	}

	return fac[n]/fac[cnt1]/fac[cnt3]/fac[cnt7]/fac[cnt9];

}

int conv (string a)

{

	int n=a.length(),res=0;

	for (int i=0;i<n;i++)

	{

		res*=10;

		res+=a[i]-48;

	}

	return res;

}

void build(int i)

{

	if ((i>=2)and(p(c))) {sort(cur.begin(),cur.end()); prim.push_back(cur);}

	if (i<7)

	{

		cur.push_back('1');

		c*=10;

		c+=1;

		build(i+1);

		cur.pop_back();

		cur.push_back('3');

		c-=1;

		c+=3;

		build(i+1);

		cur.pop_back();

		cur.push_back('7');

		c-=3;

		c+=7;

		build(i+1);

		cur.pop_back();

		cur.push_back('9');

		c-=7;

		c+=9;

		build(i+1);

		cur.pop_back();

		c-=9;

		c/=10;

	}

}

int main()

{

	#define endl "\n"

//	freopen("janitorin.txt","r",stdin);

//	freopen("janitorout.txt","w",stdout);

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

	int n,k,s;

	cin>>n>>k>>s;

	

	{

		

	for (i=0;i<n;i++) if (i<k) cout<<s<<' '; else if (s<1e9) cout<<s+1<<' '; else cout<<s-1<<' ';

	}

}

// Faster C++ solution for the same problem (measured speedup: 3.5289676600229867x):
#include <bits/stdc++.h>

#define _for(i, a, b) for (int i = (a); i < (b); ++i)

#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)

#define ll long long

using namespace std;





int main(){

    ios::sync_with_stdio(0);	//解决c++输入输出流被卡问题

    ll n,m,sum;

    cin >> n >> m >> sum;

    _for(i,0,m){

        cout << sum << " ";

    }

    _for(i,0,n-m){

        if(sum != 1000000000){

            cout << sum + 1 << " ";

        }

        else

        {

            cout << sum - 1 << " ";

        }

        

    }

    cout << endl;

    

    return 0;

}
// Slower C++ solution:
//インクルード(アルファベット順)

#include<algorithm>//sort,二分探索,など

#include<bitset>//固定長bit集合

#include<cmath>//pow,logなど

#include<complex>//複素数

#include<deque>//両端アクセスのキュー

#include<functional>//sortのgreater

#include<iomanip>//setprecision(浮動小数点の出力の誤差)

#include<iostream>//入出力

#include<iterator>//集合演算(積集合,和集合,差集合など)

#include<map>//map(辞書)

#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)

#include<queue>//キュー

#include<set>//集合

#include<stack>//スタック

#include<string>//文字列

#include<unordered_map>//イテレータあるけど順序保持しないmap

#include<unordered_set>//イテレータあるけど順序保持しないset

#include<utility>//pair

#include<vector>//可変長配列



using namespace std;

typedef long long ll;



//マクロ

//forループ関係

//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか

//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)

#define REPD(i,n) for(ll i=n-1;i>=0;i--)

#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)

#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//xにはvectorなどのコンテナ

#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい

#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく

//定数

#define INF 1000000000000 //10^12:極めて大きい値,∞

#define MOD 1000000007 //10^9+7:合同式の法

#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

//略記

#define PB push_back //vectorヘの挿入

#define MP make_pair //pairのコンストラクタ

#define F first //pairの一つ目の要素

#define S second //pairの二つ目の要素

#define Umap unordered_map

#define Uset unordered_set



ll a[200000];string ans[200000];



signed main(){

    //入力の高速化用のコード

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    ll n;cin>>n;

    REP(i,n)cin>>a[i];

    ll b=0;REP(i,n)b^=a[i];

    string ans="";

    REP(i,n){ans+=to_string(a[i]^b);ans+=" ";}

    cout<<ans<<endl; 

}

// Faster C++ solution for the same problem (measured speedup: 8.126121961188394x):
#include<iostream>//入出力

#include<string>//文字列



using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)



int a[200000];



signed main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;cin>>n;

    REP(i,n)cin>>a[i];

    int b=0;REP(i,n)b^=a[i];

    string ans="";

    REP(i,n){ans+=to_string(a[i]^b);ans+=" ";}

    cout<<ans<<endl; 

}
// Slower C++ solution:
//インクルード(アルファベット順)

#include<algorithm>//sort,二分探索,など

#include<bitset>//固定長bit集合

#include<cmath>//pow,logなど

#include<complex>//複素数

#include<deque>//両端アクセスのキュー

#include<functional>//sortのgreater

#include<iomanip>//setprecision(浮動小数点の出力の誤差)

#include<iostream>//入出力

#include<iterator>//集合演算(積集合,和集合,差集合など)

#include<map>//map(辞書)

#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)

#include<queue>//キュー

#include<set>//集合

#include<stack>//スタック

#include<string>//文字列

#include<unordered_map>//イテレータあるけど順序保持しないmap

#include<unordered_set>//イテレータあるけど順序保持しないset

#include<utility>//pair

#include<vector>//可変長配列



using namespace std;

typedef long long ll;



//マクロ

//forループ関係

//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか

//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)

#define REPD(i,n) for(ll i=n-1;i>=0;i--)

#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)

#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//xにはvectorなどのコンテナ

#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい

#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく

//定数

#define INF 1000000000000 //10^12:極めて大きい値,∞

#define MOD 1000000007 //10^9+7:合同式の法

#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

//略記

#define PB push_back //vectorヘの挿入

#define MP make_pair //pairのコンストラクタ

#define F first //pairの一つ目の要素

#define S second //pairの二つ目の要素

#define Umap unordered_map

#define Uset unordered_set



ll a[200000];string ans[200000];



signed main(){

    //入力の高速化用のコード

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    ll n;cin>>n;

    REP(i,n)cin>>a[i];

    ll b=0;REP(i,n)b^=a[i];

    string ans="";

    REP(i,n){ans+=to_string(a[i]^b);ans+=" ";}

    cout<<ans<<endl; 

}

// Faster C++ solution for the same problem (measured speedup: 8.126121961188394x):
#include<iostream>//入出力

#include<string>//文字列



using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)



int a[200000];



signed main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;cin>>n;

    REP(i,n)cin>>a[i];

    int b=0;REP(i,n)b^=a[i];

    string ans="";

    REP(i,n){ans+=to_string(a[i]^b);ans+=" ";}

    cout<<ans<<endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define f first

#define s second

using namespace std;

const int N = 2e5+5;

int n, par[N], sz[N];

vector<pair<int, int>> x, y;

int find(int x)

{

	return (par[x] == x? x : par[x] = find(par[x]));

}

void Union(int x, int y)

{

	if(sz[x] < sz[y]) swap(x, y);

	sz[x] += sz[y];

	par[y] = x;

}

int main()

{

	iota(par, par+N, 0);

	fill(sz, sz+N, 1);

	cin >> n;

	for(int i=0, a, b; i<n; i++)

	{

		cin >> a >> b;

		x.push_back({a, i});

		y.push_back({b, i});

	}

	sort(x.begin(), x.end());

	sort(y.begin(), y.end());

	priority_queue<pair<int, pair<int, int>>> q;

	for(int i=0; i<n-1; i++) q.push({x[i].f-x[i+1].f, {x[i].s, x[i+1].s}}),

	q.push({y[i].f-y[i+1].f, {y[i].s, y[i+1].s}});

	int ans = 0;

	while(!q.empty())

	{

		auto t = q.top();

		int cost = -t.f;

		int u = find(t.s.f), v = find(t.s.s);

		q.pop();

		if(u == v) continue;

		Union(u, v);

		ans += cost;

	}

	cout << ans << endl;	

		

}

// Faster C++ solution for the same problem (measured speedup: 2.616990963892415x):
#include<bits/stdc++.h>

#define sci(a) scanf("%d", &a)

#define fto(i, a, b) for (int i = a; i <= b; ++i)

#define fdto(i, a, b) for (int i = a; i >= b; --i)

#define scii(a, b) scanf("%d %d", &a, &b)

#define ll long long

#define ff first

#define ss second

#define vi vector<int>

#define pi pair<int, int>

#define maxN 100005

#define oo 1000000007

#define mp make_pair

#define pb push_back

#define bug(a) cout << #a << "= " << a << endl;

#define bugarr(a, x, y) cout << #a << "[" << x << ", " << y << "]= "; for (int i = x; i <= y; ++i) cout << a[i] << ", "; cout << endl;

#define sz(a) (int)a.size()

#define vii vector<pi>

#define db double

#define forit(var, it) for(__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)



using namespace std;



pair<pi, int> a[maxN], b[maxN];

int n, m, p[maxN];



int _find(int i) {

    if (i == p[i]) return i;

    return p[i] = _find(p[i]);

}



int main() {

   // #ifndef ONLINE_JUDGE

        //freopen("Built.inp", "r", stdin);

        //freopen("Built.out", "w", stdout);

    //#endif // ONLINE_JUDGE



    sci(n);

    fto(i, 1, n) scii(a[i].ff.ff, a[i].ff.ss);

    fto(i, 1, n) {

        a[i].ss = i;

        b[i] = mp(mp(a[i].ff.ss, a[i].ff.ff), a[i].ss);

    }

    sort(a+1, a+1+n);

    sort(b+1, b+1+n);

    vector<pair<int, pi> > canh;

    fto(i, 1, n-1) {

        int u = a[i].ss, v = a[i+1].ss, w = a[i+1].ff.ff - a[i].ff.ff;

        canh.pb(mp(w, mp(u, v)));

    }

    fto(i, 1, n-1) {

        int u = b[i].ss, v = b[i+1].ss, w = b[i+1].ff.ff - b[i].ff.ff;

        canh.pb(mp(w, mp(u, v)));

    }

    sort(canh.begin(), canh.end());

    ll ans = 0;

    fto(i, 1, n) p[i] = i;

    fto(i, 0, (int)canh.size()-1) {

        int u = canh[i].ss.ff, v = canh[i].ss.ss;

        int cutou = _find(u), cutov = _find(v);

        if (cutou != cutov) {

            ans+=canh[i].ff;

            p[cutou] = cutov;

        }

    }

    cout << ans;



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define f first

#define s second

using namespace std;

const int N = 2e5+5;

int n, par[N], sz[N];

vector<pair<int, int>> x, y;

int find(int x)

{

	return (par[x] == x? x : par[x] = find(par[x]));

}

void Union(int x, int y)

{

	if(sz[x] < sz[y]) swap(x, y);

	sz[x] += sz[y];

	par[y] = x;

}

int main()

{

	iota(par, par+N, 0);

	fill(sz, sz+N, 1);

	cin >> n;

	for(int i=0, a, b; i<n; i++)

	{

		cin >> a >> b;

		x.push_back({a, i});

		y.push_back({b, i});

	}

	sort(x.begin(), x.end());

	sort(y.begin(), y.end());

	priority_queue<pair<int, pair<int, int>>> q;

	for(int i=0; i<n-1; i++) q.push({x[i].f-x[i+1].f, {x[i].s, x[i+1].s}}),

	q.push({y[i].f-y[i+1].f, {y[i].s, y[i+1].s}});

	int ans = 0;

	while(!q.empty())

	{

		auto t = q.top();

		int cost = -t.f;

		int u = find(t.s.f), v = find(t.s.s);

		q.pop();

		if(u == v) continue;

		Union(u, v);

		ans += cost;

	}

	cout << ans << endl;	

		

}

// Faster C++ solution for the same problem (measured speedup: 2.6454278011944674x):
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<cmath>

#include<ctime>

#include<algorithm>

#include<utility>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<map>

#include<bitset>

#define EPS 1e-9

#define PI acos(-1.0)

#define INF 0x3f3f3f3f

#define LL long long

const int MOD = 1E9+7;

const int N = 200000+5;

const int dx[] = {-1,1,0,0,-1,-1,1,1};

const int dy[] = {0,0,-1,1,-1,1,-1,1};

using namespace std;

struct Edge{

    int x,y;

    int dis;

    Edge(){}

    Edge(int x,int y,int dis):x(x),y(y),dis(dis){}

    bool operator <(const Edge &rhs)const{

        return dis<rhs.dis;

    }

}edge[N];

int tot;

struct Node{

    int x,y;

}node[N];

int father[N];



bool cmpX(int a,int b){

    return node[a].x<node[b].x;

}

bool cmpY(int a,int b){

    return node[a].y<node[b].y;

}

int Find(int x){

    if(father[x]!=x)

        return father[x]=Find(father[x]);

    return x;

}

int n;

int Kruskal(){

    for(int i=1;i<=n;i++)

        father[i]=i;



    int mst=0;

    sort(edge+1,edge+1+tot);

    for(int i=1;i<=tot;i++){

        int x=Find(edge[i].x);

        int y=Find(edge[i].y);

        if(x!=y){

            mst+=edge[i].dis;

            father[x]=y;

        }

    }

    return mst;

}

int main(){

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

        scanf("%d%d",&node[i].x,&node[i].y);



    for(int i=1;i<=n;i++)

        father[i]=i;

    sort(father+1,father+1+n,cmpX);

    for(int i=1;i<n;i++){

        int x=father[i];

        int y=father[i+1];

        int dis=node[y].x-node[x].x;

        edge[++tot]=Edge(x,y,dis);

    }



    for(int i=1;i<=n;i++)

        father[i]=i;

    sort(father+1,father+1+n,cmpY);

    for(int i=1;i<n;i++){

        int x=father[i];

        int y=father[i+1];

        int dis=node[y].y-node[x].y;

        edge[++tot]=Edge(x,y,dis);

    }

    int mst=Kruskal();

    printf("%d\n",mst);



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define f first

#define s second

using namespace std;

const int N = 2e5+5;

int n, par[N], sz[N];

vector<pair<int, int>> x, y;

int find(int x)

{

	return (par[x] == x? x : par[x] = find(par[x]));

}

void Union(int x, int y)

{

	if(sz[x] < sz[y]) swap(x, y);

	sz[x] += sz[y];

	par[y] = x;

}

int main()

{

	iota(par, par+N, 0);

	fill(sz, sz+N, 1);

	cin >> n;

	for(int i=0, a, b; i<n; i++)

	{

		cin >> a >> b;

		x.push_back({a, i});

		y.push_back({b, i});

	}

	sort(x.begin(), x.end());

	sort(y.begin(), y.end());

	priority_queue<pair<int, pair<int, int>>> q;

	for(int i=0; i<n-1; i++) q.push({x[i].f-x[i+1].f, {x[i].s, x[i+1].s}}),

	q.push({y[i].f-y[i+1].f, {y[i].s, y[i+1].s}});

	int ans = 0;

	while(!q.empty())

	{

		auto t = q.top();

		int cost = -t.f;

		int u = find(t.s.f), v = find(t.s.s);

		q.pop();

		if(u == v) continue;

		Union(u, v);

		ans += cost;

	}

	cout << ans << endl;	

		

}

// Faster C++ solution for the same problem (measured speedup: 2.6115106430746895x):
#include <iostream>

#include <cstdio>

#include <sstream>

#include <cstring>

#include <vector>

#include <algorithm>

#include <cmath>

#include <iomanip>

#include <queue>

#include <stack>

using namespace std;

typedef long long ll;

const int mod=1e9+7;

const int maxn=2e5+10;

struct dot

{

    int num,x,y;

}dots[maxn];

struct node

{

    int u,v;

    ll w;

    bool operator<(const node &b)const

    {

        return w<b.w;

    }

};

vector<node>edge;

int p[maxn];

void init(int n)

{

    for(int i=0; i<=n; i++) p[i]=i;

}

int Find(int x)

{

    if(x==p[x]) return p[x];

    int y=Find(p[x]);

    return p[x]=y;

}

int Union(int x,int y)

{

    int x1=Find(x);

    int y1=Find(y);

    if(x1==y1) return 0;

    p[x1]=y1;

    return 1;

}

void kruskal(int n)

{

    ll sum=0;

    int num=0;

    init(n);

    sort(edge.begin(),edge.end());

    for(int i=0; i<edge.size(); i++)

    {

        int u=edge[i].u;

        int v=edge[i].v;

        ll w=edge[i].w;

        if(Union(u,v))

        {

            num++;

            sum+=w;

        }

        if(num==n-1) break;

    }

    cout<<sum<<endl;

}

int cmpx(dot a,dot b)

{

    return a.x<b.x;

}

int cmpy(dot a,dot b)

{

    return a.y<b.y;

}

int main()

{

    int N;

    cin>>N;

    for(int i=0;i<N;i++)

    {

        cin>>dots[i].x>>dots[i].y;

        dots[i].num=i;

    }node tmp;

    sort(dots,dots+N,cmpx);

    for(int i=1;i<N;i++)

    {

        tmp.u=dots[i-1].num;

        tmp.v=dots[i].num;

        tmp.w=abs(dots[i-1].x-dots[i].x);

        edge.push_back(tmp);

    }

    sort(dots,dots+N,cmpy);

    for(int i=1;i<N;i++)

    {

        tmp.u=dots[i-1].num;

        tmp.v=dots[i].num;

        tmp.w=abs(dots[i-1].y-dots[i].y);

        edge.push_back(tmp);

    }

    kruskal(N);





    return 0;

}