stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

    }

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

    

    

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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<<' ';

	}

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//インクルード(アルファベット順)

#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; 

}

// Optimized solution to the same problem (faster):
#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; 

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;	

		

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

#include <stdlib.h>

#include <vector>

#include <algorithm>

using namespace std;



typedef long long ll;

typedef pair<ll, pair<ll, ll> > pp;



vector<pp> v;

pp edge[1111111];

pair<ll, ll> x[111111], y[111111];

ll parent[111111];



ll Find(ll val)

{

	if (parent[val] == val)

		return val;

	else

		return parent[val] = Find(parent[val]);

}



int main(void)

{

    ll n, i, cnt = 0;



    scanf("%lld" ,&n);

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

	{

		scanf("%lld %lld" ,&x[i].first, &y[i].first);

        x[i].second = y[i].second = i;

	}



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

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



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

	{

		edge[++cnt] = make_pair(x[i + 1].first - x[i].first, make_pair(x[i].second, x[i + 1].second));

		edge[++cnt] = make_pair(y[i + 1].first - y[i].first, make_pair(y[i].second, y[i + 1].second));

	}



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



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

		parent[i] = i;



    for (i = 1; v.size() < n - 1; i++)

	{

        ll a = Find(edge[i].second.first);

        ll b = Find(edge[i].second.second);



		if (a != b)

		{

            parent[b] = a;

            v.push_back(edge[i]);

		}

	}



	ll ans = 0;

	for (i = 0; i < v.size(); i++)

        ans += v[i].first;



	printf("%lld" ,ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <algorithm>

using namespace std;



typedef long long ll;

typedef pair<ll, ll> PAIR;



pair<ll, PAIR> edge[222222];

PAIR x[111111], y[111111];

int parent[111111];



ll Find(ll val)

{

	if (parent[val] == val)

		return val;

	else

		return parent[val] = Find(parent[val]);

}



int main(void)

{

    ll n, i, ans = 0, cnt = 0;



    scanf("%lld" ,&n);

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

	{

		scanf("%lld %lld" ,&x[i].first, &y[i].first);

        x[i].second = y[i].second = i;

	}



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

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



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

	{

		edge[++cnt] = make_pair(x[i + 1].first - x[i].first, make_pair(x[i].second, x[i + 1].second));

		edge[++cnt] = make_pair(y[i + 1].first - y[i].first, make_pair(y[i].second, y[i + 1].second));

	}



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



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

		parent[i] = i;



	int num = 0;

    for (i = 1; num < n - 1; i++)

	{

        ll a = Find(edge[i].second.first);

        ll b = Find(edge[i].second.second);



		if (a != b)

		{

            parent[b] = a;

            ans += edge[i].first;

            ++num;

		}

	}



	printf("%lld" ,ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

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

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

#define pq priority_queue

#define P pair<int,int>

#define P2 pair<int,P>

#define P3 pair<int,P2>

typedef long long ll; typedef long double ld;

using namespace std;

const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};

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

const ll LINF=1e18;

const ld PI=abs(acos(-1));



int n,x[100010],y[100010];

vector<P> vec, vec2;

vector<P> g[100010];



int main(){

	cin >> n;

	REP(i,0,n){

		int a, b; cin >> a >> b;

		vec.push_back({a, i});

		vec2.push_back({b, i});

	}

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

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

	

	

	REP(i,0,n - 1){

		g[vec[i].second].push_back({vec[i + 1].second, abs(vec[i + 1].first - vec[i].first)});

		g[vec[i + 1].second].push_back({vec[i].second, abs(vec[i + 1].first - vec[i].first)});

		g[vec2[i].second].push_back({vec2[i + 1].second, abs(vec2[i + 1].first - vec2[i].first)});

		g[vec2[i + 1].second].push_back({vec2[i].second, abs(vec2[i + 1].first - vec2[i].first)});

	}

	

	ll total = 0;

	bool used[100010] = {};

	pq<P, vector<P>, greater<P>> qu; qu.push({0, 0});

	while(!qu.empty()){

		auto p = qu.top(); qu.pop();

		

		if(used[p.second]) continue; used[p.second] = true;

		total += p.first;

		for(auto e:g[p.second]) qu.push({e.second, e.first});

	}

	

	cout << total << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

typedef long long i64;

using std::cout;

using std::endl;

using std::cin;



struct UnionFind {

	std::vector<int> data;

	

	UnionFind(int n) {

		data.assign(n, -1);

	}

	

	void unite(int x, int y) {

		x = find(x); y = find(y);

		if(x == y) return;

		if(data[x] > data[y]) std::swap(x, y);

		data[x] += data[y];

		data[y] = x;

	}

	

	int find(int k) {

		if(data[k] < 0) return k;

		return data[k] = find(data[k]);

	}

	

	bool same(int x, int y) {

		return find(x) == find(y);

	}

};



int main(){

	int n; cin >> n;

	std::vector<int> x(n), y(n);

	std::vector<std::pair<int, int>> X, Y;

	std::vector<std::pair<int, std::pair<int, int>>> latte;

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

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

		

		X.push_back({x[i], i});

		Y.push_back({y[i], i});

	}

	sort(begin(X), end(X)); sort(begin(Y), end(Y));

	

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

		latte.push_back({X[i + 1].first - X[i].first, {X[i + 1].second, X[i].second}});

		latte.push_back({Y[i + 1].first - Y[i].first, {Y[i + 1].second, Y[i].second}});

	}

	sort(begin(latte), end(latte));

	

	i64 ans = 0;

	UnionFind uf(n);

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

		if(uf.same(latte[i].second.first, latte[i].second.second)) continue;

		uf.unite(latte[i].second.first, latte[i].second.second);

		ans += latte[i].first;

	}

	

	cout << ans << endl;

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<cmath>

#include<algorithm>



typedef long long ll;



const ll INF=1E9+10;

const ll MAXN=1e5+10;

using namespace std;



ll par[2*MAXN]; 



struct NODE{

	ll len,a,b;

}node[2*MAXN];



struct NO{

	ll sit,order;

}x[MAXN],y[MAXN];



ll rk[MAXN];



bool cmp1(NO i,NO j){

	return i.sit<j.sit;

}

bool cmp2(NODE h,NODE k){

	return h.len<k.len;

}





ll find(ll a){//寻找根节点 

	if(rk[a]==a)	return a;

	else {

		rk[a]=find(rk[a]);

		return rk[a];

	} 

} 



ll Kruskal(ll ver,ll edge){//顶点数量、边数 

	ll tot=0,e=0;//目前的权值和已加入的边数

	

	//初始化前驱 

	for(ll i=1;i<=ver;i++){

		rk[i]=i;//最开始第i个顶点的集合是他自己 

	}

	

	for(ll i=1;i<=edge&&e<ver-1;i++){

		ll h=find(node[i].a);//a点根节点 

		ll k=find(node[i].b);//b点根节点 

		if(h!=k){//如果这两个点不在同一个集合中，说明可以加入这条边 

			tot+=node[i].len;//增加权值 

			e++;//增加边数 

			rk[h]=k; //合并这两个点到同一个集合 

		}

	}

	 

	return tot; 

}



 int main() {

 	ll n;

 	scanf("%lld",&n);

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

 		scanf("%lld %lld",&x[i].sit,&y[i].sit);

 		x[i].order=i;

 		y[i].order=i;

	}

	sort(x+1,x+n+1,cmp1);

	sort(y+1,y+n+1,cmp1);

	 

	//一共有2*n-2条边从 1到2*n-2 

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

		node[i].len=x[i+1].sit-x[i].sit;

		node[i].a=x[i+1].order;node[i].b=x[i].order;

		

		node[i+n-1].len=y[i+1].sit-y[i].sit;

		node[i+n-1].a=y[i+1].order;node[i+n-1].b=y[i].order;

	}

	

	sort(node+1,node+2*n-1,cmp2);

	

	//克鲁斯卡尔算法 

	ll ans=Kruskal(n,2*n-2);//顶点数量、边数 

	printf("%lld\n",ans);

	

 	return 0;

 }

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#define ll long long





using namespace std;



const ll MAXN=1e5+10;



struct V{

	ll x,order;

}vx[MAXN],vy[MAXN];



struct Edge{

	int va,vb;

	ll w;

}e[2*MAXN];



int pre[MAXN];



void init(int n){

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

		pre[i]=i;

	}

}



bool cmpv(V a,V b){

	return a.x<b.x;

}

bool cmpe(Edge a,Edge b){

	return a.w<b.w;

}



int find(int v){

	if(pre[v]==v){

		return v;

	}

	else {

		pre[v]=find(pre[v]);

		return pre[v];

	}

}



ll Kruskal(int ver,int edges){

	ll tot=0,ale=0;//权重和已加入的顶点数 

	init(ver);

	for(int i=1;i<=edges&&ale<ver-1;i++){

		 int h=find(e[i].va);

		 int k=find(e[i].vb);

		 if(h!=k){

		 	tot+=e[i].w;//增加权重 

		 	ale++;//增加边 

		 	pre[h]=k;//加入集合 

		 } 

	}

	return tot; 

	

}



int main(){

	int n;

	scanf("%d",&n);

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

		scanf("%lld %lld",&vx[i].x,&vy[i].x);

		vx[i].order=vy[i].order=i;

	}

	sort(vx+1,vx+n+1,cmpv);

	sort(vy+1,vy+n+1,cmpv);

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

		e[i].w=vx[i+1].x-vx[i].x;

		e[i].va=vx[i+1].order,e[i].vb=vx[i].order;

		

		e[i+n-1].w=vy[i+1].x-vy[i].x;

		e[i+n-1].va=vy[i+1].order,e[i+n-1].vb=vy[i].order;

	}

	//对边长按权重排序 

	sort(e+1,e+2*n-1,cmpe);

	//Kruskal算法 找最小生成树 

	ll ans=Kruskal(n,2*n-2);

	printf("%lld",ans);

	return 0;

}

 

// Fastest known solution for this problem: