stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define maxn 100010

#define inf 0x3f3f3f3f

int v[maxn];

int pre[maxn];

vector<int> g[maxn];

int ty[maxn];

bool used[maxn];

int a,b;

void dfs(int u){

    a++;b+=ty[u];

    used[u]=true;

    for(int i=0;i<g[u].size();i++){

        int to=g[u][i];

        if(used[to]) continue;

        dfs(to);

    }

}

int main(){

    int n,T;

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

    scanf("%d",&v[0]);

    int minx=v[0],dis=0,pos=0;

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

        scanf("%d",&v[i]);

        if(v[i]<=minx){

            pre[i]=i;

            minx=v[i];

            pos=i;

        }

        else{

            pre[i]=pos;

            dis=max(dis,v[i]-v[pos]);

        }

    }

    memset(used,1,sizeof(used));

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

        if(v[i]-v[pre[i]]==dis){

            g[pre[i]].push_back(i);

            g[i].push_back(pre[i]);

            used[i]=used[pre[i]]=false;

            ty[pre[i]]=1;

        }

    }

    int res=0;

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

        if(!used[i]){

            a=b=0;

            dfs(i);

            res+=min(b,a-b);

        }

    }

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

    return 0;

}


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

using namespace std;

#define maxn 100010

int q[maxn],top=0;

int Max=0,cnt=0;

int n,a[maxn];

int main()

{

    int t,T;

    t=1;

    while (t--)

    {

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

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

        q[0]=a[0],top=0;

        Max=-1;

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

        {

            if (a[i]>q[top]) q[++top]=a[i];

            else if (a[i]<q[top])

            {

                if (q[top]-q[0]>Max) Max=q[top]-q[0],cnt=1;

                else if (q[top]-q[0]==Max) cnt++;

                while (top>=0&&a[i]<q[top]) top--;

                q[++top]=a[i];

            }

        }

        if (q[top]-q[0]>Max) Max=q[top]-q[0],cnt=1;

        else if (q[top]-q[0]==Max) cnt++;

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

    }

    return 0;

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

using namespace std;

int n, T, a[100010], dp[100010];

int main() {

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

	int mn = 0x3f3f3f3f, ans = 0;

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

		scanf("%d", &a[i]);

		dp[i] = max(0, a[i] - mn);

		ans = max(ans, dp[i]);

		mn = min(mn, a[i]);

	}

	mn = 0x3f3f3f3f; int tot = 0;

	for (int i = 1; i <= n; ++ i) {if (a[i] - mn == ans) ++ tot; mn = min(mn, a[i]);}

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

	return 0;

}

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

int main () {

    int n,k,a,b,c;

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

    c=k=0,n--;

    while(n--){

        scanf("%d",&a);

        if (a-b==c) k++;

        else if (a-b>c) k=1,c=a-b;

        else if (a<b) b=a;

    }

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

    return 0;

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

#include <cmath>

using namespace std;

int a[20][20];



int main(){

	

	//printf("%f",sqrt((1-5)^2)+((2-5)^2));

	

	int n,d;

	double EPS=1e-10;

	cin>>n>>d;

	

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

		for(int j=0;j<d;j++){

			cin>>a[i][j];

		}

	}

	

	int sum=0;

	

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

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

			double ans=0;

			for(int j=0;j<d;j++){

				ans+=(a[i][j]-a[k][j])*(a[i][j]-a[k][j]);

				//printf("%f\n",ans);

			}

			double ans1=sqrt(ans);

			//printf("%f\t%f\t%f\n",ans,ans1-floor(ans1),ans1-floor(ans1));

			if(ans1-floor(ans1)<EPS){

				sum++;

				//printf("%f\t\t%f\n",ans,ans1-floor(ans1));

			}

		}

	}

	cout<<sum<<endl;

	return 0;

}








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

#include<math.h>

int a[100][20]={0};

int main()

{

	int n,m,i,j,t;

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

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

	{

		for(j=0;j<m;j++)

		scanf("%d",&a[i][j]);

	}

	int sum;

	sum=0;

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

	{

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

		{

//			printf("1\n");

			double s=0;

			for(t=0;t<m;t++)

			{

				s+=((a[i][t]-a[j][t])*(a[i][t]-a[j][t]));

//				printf("2\n");

			}

			

			s=sqrt(s);

			int mu=s;

			if(s-mu==0)

			sum++;

		}

	}

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

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



#define all(c) c.begin(), c.end()

#define rall(c) c.rbegin(), c.rend()



using namespace std;



typedef long long ll;



int main(){

    int n; ll ans = 0;

    cin >> n;

    vector<int> l(n+1, 0), r(n+1, 0);

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

        cin >> l[i] >> r[i];

    sort(rall(l));

    sort(all(r));

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

    {

        if(l[i] - r[i] <= 0)

            break;

        ans += l[i] - r[i];

    }

    cout << 2*ans << endl;

}


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

#include<string.h>

#include<algorithm>

#include<math.h>

using namespace std;

#define N 100010

int l[N],r[N];



int main()

{

    int n,i,j,k,x,t1,t2,s1,s2;

    long long ans;

    scanf("%d",&n);

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

        scanf("%d%d",&l[i],&r[i]);

    sort(l,l+n+1);

    sort(r,r+n+1);

    ans=0;

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

    {

        if(l[n-i]<=r[i])

            break;

        ans=ans+l[n-i]-r[i];

    }

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

    return 0;

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

#include<cstdio>

#include<cstring>

  

const int Maxv = 100010; 

int l[Maxv << 1], r[Maxv << 1], n; 

long long ans; 

  

inline int read(){

    int x = 0, f = 1; 

    char ch = getchar(); 

    while (ch < '0' || ch > '9') {

        if (ch == '-') {

            f = -1; 

        }

        ch = getchar(); 

    }

    while (ch >= '0' && ch <= '9') {

        x = (x << 3) + (x << 1) + ch - '0'; 

        ch = getchar(); 

    }

    return x * f; 

}

  

int main(){

    n = read(); 

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

        int L = read(); 

        int R = read(); 

        l[Maxv + R]++; 

        r[Maxv + L]++; 

    }

    l[Maxv]++; 

    r[Maxv]++; 

    for (int i = 1; i < 2 * Maxv; i++) {

        l[i] += l[i - 1]; 

    }

    for (int i = 2 * Maxv - 2; i >= 0; i--) {

        r[i] += r[i + 1]; 

    }

    for (int i = 0; i < 2 * Maxv - 1; i++) {

        ans += std::min(l[i], r[i + 1]) * 2; 

    }

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

    return 0; 

}

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

using namespace std;



#define scl(x) scanf("%lld",&x)

#define sc(x)  scanf("%d",&x)

#define ll long long

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

typedef pair<int, int> ii;

typedef pair<ll, ll> pll;



const int N=1e5+100;

int n,l[N],r[N];

set<ii> sl,sr;



ll solve(int xr){

	lop(i,n){

		sl.insert(ii(l[i],i));

		sr.insert(ii(r[i],i));

	}

	ll ret=0;

	int cur=0;

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

		int i,to=cur;

		if((j&1)^xr) i=sr.begin()->second;

		else i=sl.rbegin()->second;

		if(cur<l[i])to = l[i];

		else if(cur>r[i])to=r[i];

		ret+=abs(cur-to);

		cur=to;

		sr.erase(ii(r[i],i));

		sl.erase(ii(l[i],i));

	}

	return ret+abs(cur);

}

int main(){

#ifndef ONLINE_JUDGE

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

#endif

	sc(n);

	lop(i,n)

		sc(l[i]),sc(r[i]);

	cout<<max(solve(0),solve(1));



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

#include<cstdio>

#include<cstring>

  

const int Maxv = 100010; 

int l[Maxv << 1], r[Maxv << 1], n; 

long long ans; 

  

inline int read(){

    int x = 0, f = 1; 

    char ch = getchar(); 

    while (ch < '0' || ch > '9') {

        if (ch == '-') {

            f = -1; 

        }

        ch = getchar(); 

    }

    while (ch >= '0' && ch <= '9') {

        x = (x << 3) + (x << 1) + ch - '0'; 

        ch = getchar(); 

    }

    return x * f; 

}

  

int main(){

    n = read(); 

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

        int L = read(); 

        int R = read(); 

        l[Maxv + R]++; 

        r[Maxv + L]++; 

    }

    l[Maxv]++; 

    r[Maxv]++; 

    for (int i = 1; i < 2 * Maxv; i++) {

        l[i] += l[i - 1]; 

    }

    for (int i = 2 * Maxv - 2; i >= 0; i--) {

        r[i] += r[i + 1]; 

    }

    for (int i = 0; i < 2 * Maxv - 1; i++) {

        ans += std::min(l[i], r[i + 1]) * 2; 

    }

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

    return 0; 

}

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

typedef long long ll;

using namespace std;

struct nodel{

    int x,id;

    nodel(){}

    nodel(int a,int b){x=a;id=b;}

    bool operator < (const nodel a)const {

        return a.x > x;

    }

};

struct noder{

    int x,id;

    noder(){}noder(int a,int b){x=a;id=b;}

    bool operator < (const noder a)const {

    return a.x < x;

    }

};

priority_queue<nodel> ql,ql2;

priority_queue<noder> qr,qr2;

int n,out[100000+100];

ll ans1,ans2;

int main() {

    scanf("%d",&n);

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

	{int l,r;

    scanf("%d%d",&l,&r);

    ql.push(nodel(l,i));

    ql2.push(nodel(l,i));

    qr.push(noder(r,i));

    qr2.push(noder(r,i));

    }

    int now=0;

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

        while(!ql.empty()&&out[ql.top().id])ql.pop();

        while(!qr.empty()&&out[qr.top().id])qr.pop();

        if(ti%2&&now < ql.top().x)ans1+=abs(now-ql.top().x),now=ql.top().x,out[ql.top().id]=1,ql.pop();

        else if(now > qr.top().x) ans1+=abs(now-qr.top().x),now=qr.top().x,out[qr.top().id]=1,qr.pop();

    }

    ans1 += abs(now);

    memset(out,0,sizeof(out));

    now=0;

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

    while(!ql2.empty()&&out[ql2.top().id])ql2.pop();

    while(!qr2.empty()&&out[qr2.top().id])qr2.pop();

    if(ti%2==0&&now<ql2.top().x)ans2+=abs(now-ql2.top().x),now=ql2.top().x,out[ql2.top().id]=1,ql2.pop();

    else if(now>qr2.top().x) ans2+=abs(now-qr2.top().x),now=qr2.top().x,out[qr2.top().id]=1,qr2.pop();

    }

    ans2+=abs(now);

    cout<<max(ans1,ans2) <<'\n';

    return 0;

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

#include<cstdio>

#include<cstring>

  

const int Maxv = 100010; 

int l[Maxv << 1], r[Maxv << 1], n; 

long long ans; 

  

inline int read(){

    int x = 0, f = 1; 

    char ch = getchar(); 

    while (ch < '0' || ch > '9') {

        if (ch == '-') {

            f = -1; 

        }

        ch = getchar(); 

    }

    while (ch >= '0' && ch <= '9') {

        x = (x << 3) + (x << 1) + ch - '0'; 

        ch = getchar(); 

    }

    return x * f; 

}

  

int main(){

    n = read(); 

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

        int L = read(); 

        int R = read(); 

        l[Maxv + R]++; 

        r[Maxv + L]++; 

    }

    l[Maxv]++; 

    r[Maxv]++; 

    for (int i = 1; i < 2 * Maxv; i++) {

        l[i] += l[i - 1]; 

    }

    for (int i = 2 * Maxv - 2; i >= 0; i--) {

        r[i] += r[i + 1]; 

    }

    for (int i = 0; i < 2 * Maxv - 1; i++) {

        ans += std::min(l[i], r[i + 1]) * 2; 

    }

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

    return 0; 

}

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

#define up(l,r,i) for(int i=l;i<=r;i++)

#define dn(l,r,i) for(int i=l;i>=r;i--)

using namespace std;



typedef long long LL;

const int INF =2147483647;

int qread(){

	int w=1,c,ret;

	while((c=getchar())> '9'||c< '0')

	w=(c=='-'?-1:1); ret=c-'0';

	while((c=getchar())>='0'&&c<='9')

	ret=ret*10+c-'0';

	return ret*w;

}

const int MAXN =1e5+3;

struct Node{

	int l,r,ID;

	Node(int _l,int _r,int _ID){

		l=_l,r=_r,ID=_ID;

	}

	Node(){}

}P[MAXN];

bool vis[MAXN];

struct cmp1{

	bool operator ()(Node a,Node b){

		return a.l<b.l;

	}

};

struct cmp2{

	bool operator ()(Node a,Node b){

		return a.r>b.r;

	}

};

priority_queue <Node,vector<Node>,cmp1> pq1;

priority_queue <Node,vector<Node>,cmp2> pq2;

int n,L[MAXN],R[MAXN];

LL calc(bool type){

	LL ret=0,pos=0,_pos;

	memset(vis,0,sizeof(vis));

	up(1,n,i) pq1.push(Node(L[i],R[i],i)),

			  pq2.push(Node(L[i],R[i],i));

	up(1,n,i){

		Node t=(type?pq1.top():pq2.top());

		type?pq1.pop():pq2.pop();

		if(vis[t.ID]) continue; else vis[t.ID]=true;

		if(pos<t.l) _pos=t.l; else

		if(pos>t.r) _pos=t.r; else _pos=pos;

		ret+=(LL)abs(pos-_pos),type=!type,pos=_pos;

	}

	return (ret+=(LL)abs(pos));

}

int main(){

	n=qread();

	up(1,n,i) L[i]=qread(),R[i]=qread();

	printf("%lld\n",max(calc(true),calc(false)));

	return 0;

}

/*

2

2147483647 2147483647

-2147483647 -2147483647

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

typedef long long ll;

using namespace std;

struct nodel{

    int x,id;

    nodel(){}

    nodel(int a,int b){x=a;id=b;}

    bool operator < (const nodel a)const {

        return a.x > x;

    }

};

struct noder{

    int x,id;

    noder(){}noder(int a,int b){x=a;id=b;}

    bool operator < (const noder a)const {

    return a.x < x;

    }

};

priority_queue<nodel> ql,ql2;

priority_queue<noder> qr,qr2;

int n,out[100000+100];

ll ans1,ans2;

int main() {

    scanf("%d",&n);

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

	{int l,r;

    scanf("%d%d",&l,&r);

    ql.push(nodel(l,i));

    ql2.push(nodel(l,i));

    qr.push(noder(r,i));

    qr2.push(noder(r,i));

    }

    int now=0;

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

        while(!ql.empty()&&out[ql.top().id])ql.pop();

        while(!qr.empty()&&out[qr.top().id])qr.pop();

        if(ti%2&&now < ql.top().x)ans1+=abs(now-ql.top().x),now=ql.top().x,out[ql.top().id]=1,ql.pop();

        else if(now > qr.top().x) ans1+=abs(now-qr.top().x),now=qr.top().x,out[qr.top().id]=1,qr.pop();

    }

    ans1 += abs(now);

    memset(out,0,sizeof(out));

    now=0;

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

    while(!ql2.empty()&&out[ql2.top().id])ql2.pop();

    while(!qr2.empty()&&out[qr2.top().id])qr2.pop();

    if(ti%2==0&&now<ql2.top().x)ans2+=abs(now-ql2.top().x),now=ql2.top().x,out[ql2.top().id]=1,ql2.pop();

    else if(now>qr2.top().x) ans2+=abs(now-qr2.top().x),now=qr2.top().x,out[qr2.top().id]=1,qr2.pop();

    }

    ans2+=abs(now);

    cout<<max(ans1,ans2) <<'\n';

    return 0;

}

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

#define up(l,r,i) for(int i=l;i<=r;i++)

#define dn(l,r,i) for(int i=l;i>=r;i--)

using namespace std;



typedef long long LL;

const int INF =2147483647;

int qread(){

	int w=1,c,ret;

	while((c=getchar())> '9'||c< '0')

	w=(c=='-'?-1:1); ret=c-'0';

	while((c=getchar())>='0'&&c<='9')

	ret=ret*10+c-'0';

	return ret*w;

}

const int MAXN =1e5+3;

struct Node{

	int l,r,ID;

	Node(int _l,int _r,int _ID){

		l=_l,r=_r,ID=_ID;

	}

	Node(){}

}P[MAXN];

bool vis[MAXN];

struct cmp1{

	bool operator ()(Node a,Node b){

		return a.l<b.l;

	}

};

struct cmp2{

	bool operator ()(Node a,Node b){

		return a.r>b.r;

	}

};

priority_queue <Node,vector<Node>,cmp1> pq1;

priority_queue <Node,vector<Node>,cmp2> pq2;

int n,L[MAXN],R[MAXN];

LL calc(bool type){

	LL ret=0,pos=0,_pos;

	memset(vis,0,sizeof(vis));

	up(1,n,i) pq1.push(Node(L[i],R[i],i)),

			  pq2.push(Node(L[i],R[i],i));

	up(1,n,i){

		Node t=(type?pq1.top():pq2.top());

		type?pq1.pop():pq2.pop();

		if(vis[t.ID]) continue; else vis[t.ID]=true;

		if(pos<t.l) _pos=t.l; else

		if(pos>t.r) _pos=t.r; else _pos=pos;

		ret+=(LL)abs(pos-_pos),type=!type,pos=_pos;

	}

	return (ret+=(LL)abs(pos));

}

int main(){

	n=qread();

	up(1,n,i) L[i]=qread(),R[i]=qread();

	printf("%lld\n",max(calc(true),calc(false)));

	return 0;

}

/*

2

2147483647 2147483647

-2147483647 -2147483647

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

using namespace std;



const int C=100010, N=200010;

int a[N], b[N];



int main()

{

	int n;

	scanf ("%d", &n);

	a[C]++, b[C]++;

	

	while (n--){

		int l, r;

		scanf ("%d%d", &l, &r);

		l += C, r += C;

		a[l]++, b[r]++;

	}

	

	for (int i=N-2; i>=0; i--)

		a[i] += a[i+1];

		

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

		b[i] += b[i-1];

		

	long long ans=0;

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

		ans += min (b[i], a[i+1]);

		

		

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

	return 0;

}

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

using namespace std;

#define mp(a,b) make_pair(a,b)

#define fi first

#define se second



priority_queue<pair<int,int> > LL,RR,L,R;

bool vis[100005];

long long ans1,ans2;

int n;



void PlanA(int now,long long &ans)

{

	while (!L.empty() && vis[L.top().se]) L.pop();

	while (!R.empty() && vis[R.top().se]) R.pop();

	if (!L.empty() && L.top().fi>now)

	{

		ans+=L.top().fi-now;

		now=L.top().fi;

		vis[L.top().se]=1;

		L.pop();

		PlanA(now,ans);

	}

	else if (!R.empty() && -R.top().fi<now)

	{

		ans+=now+R.top().fi;

		now=-R.top().fi;

		vis[R.top().se]=1;

		R.pop();

		PlanA(now,ans);

	}

	else ans+=abs(now);

}



void PlanB(int now,long long &ans)

{

	while (!L.empty() && vis[L.top().se]) L.pop();

	while (!R.empty() && vis[R.top().se]) R.pop();

	if (!R.empty() && -R.top().fi<now)

	{

		ans+=now+R.top().fi;

		now=-R.top().fi;

		vis[R.top().se]=1;

		R.pop();

		PlanB(now,ans);

	}

	else if (!L.empty() && L.top().fi>now)

	{

		ans+=L.top().fi-now;

		now=L.top().fi;

		vis[L.top().se]=1;

		L.pop();

		PlanB(now,ans);

	}

	else ans+=abs(now);

}



int main()

{

	scanf("%d",&n);

	for (int i=1,l,r;i<=n;i++)

	{

		scanf("%d%d",&l,&r);

		LL.push(mp(l,i));

		RR.push(mp(-r,i));

	}

	L=LL,R=RR;

	PlanA(0,ans1);

	memset(vis,0,sizeof(vis));

	L=LL,R=RR;

	PlanB(0,ans2);

	printf("%lld\n",max(ans1,ans2));

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

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bitset>

#include <ios> 

#include <bits/stdc++.h>

using namespace std;

int n,a[200004],b[200004];

int main(){

	cin>>n;

	a[100000]++;

	b[100000]++;

	while (n--){

		int l,r;

		cin>>l>>r;

		a[l+100000]++;

		b[r+100000]++;

	}

	for (int i=200000;i>=0;i--)

		a[i]+=a[i+1];

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

		b[i]+=b[i-1];

	long long ans=0;

	for (int i=0;i<=200000;i++) ans+=min(b[i],a[i+1]);

	cout<<ans*2;

}

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

#include <cstdio>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <sstream>

#include <stack>

#include <time.h>

#include <vector>

#include <complex>

#include <map>

#include <set>

#include <iomanip>

#include <math.h>

#include <stdlib.h>

#include <list>

#include <utility>

#include <memory>

#include <cstring>

#include <fstream>

#include <numeric>

#include <assert.h>

#include <bitset>

#include <ios> 

#include <bits/stdc++.h>

using namespace std;

int main(){

	int n;

	cin>>n;

	vector <int> x(n+1),y(n+1);

	for (int i=0;i<n;i++) cin>>x[i]>>y[i];

	sort (x.rbegin(),x.rend());

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

	long long ans=0;

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

		if (x[i]>y[i]){

			ans+=2*(x[i]-y[i]);

		}

	}

	cout<<ans;

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

using namespace std; 

int main() 

{ 

int a,b,c;

  cin>>a>>b>>c;

  if(a==5&&b==5&&c==7)  cout<<"YES"<<endl;

  else if(a==5&&b==7&&c==5)  cout<<"YES"<<endl;

  else if(a==7&&b==5&&c==5)  cout<<"YES"<<endl;

  else cout<<"NO"<<endl;

  return 0; 

  }

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

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>



using namespace std;



int main()

{

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	int sum5 = 0;

	int sum7 = 0;

	if(a == 7) sum7++;

	if(a == 5) sum5++;

	if(b == 7) sum7++;

	if(b == 5) sum5++;

	if(c == 7) sum7++;

	if(c == 5) sum5++;

	if(sum7 == 1 && sum5 == 2) printf("YES\n");

	else printf("NO\n");

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

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<string>

using namespace std;

int main(){

	int A,B,C;

	cin>>A>>B>>C;

	if(A==5&&B==7&&C==5)

	

	{cout<<"YES"<<endl;

	}else if(A==5&&B==5&&C==7){cout<<"YES"<<endl;

	}else if(A==7&&B==5&&C==5){cout<<"YES"<<endl;

	} 

	else{cout<<"NO"<<endl;

	}

	

}

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

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>



using namespace std;



int main()

{

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	int sum5 = 0;

	int sum7 = 0;

	if(a == 7) sum7++;

	if(a == 5) sum5++;

	if(b == 7) sum7++;

	if(b == 5) sum5++;

	if(c == 7) sum7++;

	if(c == 5) sum5++;

	if(sum7 == 1 && sum5 == 2) printf("YES\n");

	else printf("NO\n");

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



using namespace std;



int main()

{

    int a,b,c;

    cin>>a>>b>>c;

    if(a==7&&b==5&&c==5)

    {

        cout<<"YES"<<endl;

    }

    else if(a==5&&b==7&&c==5)

    {

       cout<<"YES"<<endl;

    }

    else if(a==5&&b==5&&c==7)

    {

        cout<<"YES"<<endl;

    }

    else



        cout<<"NO"<<endl;



    return 0;

}


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

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>



using namespace std;



int main()

{

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	int sum5 = 0;

	int sum7 = 0;

	if(a == 7) sum7++;

	if(a == 5) sum5++;

	if(b == 7) sum7++;

	if(b == 5) sum5++;

	if(c == 7) sum7++;

	if(c == 5) sum5++;

	if(sum7 == 1 && sum5 == 2) printf("YES\n");

	else printf("NO\n");

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

using namespace std;



map <int,int> Mapita;



int main(){

	int A,B,C;

	scanf ("%d %d %d",&A,&B,&C);

	Mapita[A]++;

	Mapita[B]++;

	Mapita[C]++;

	if (Mapita[5]>=2 && Mapita[7]>=1){

		cout << "YES";

	}else{

		cout << "NO";

	}

	return 0;

}

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

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>



using namespace std;



int main()

{

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	int sum5 = 0;

	int sum7 = 0;

	if(a == 7) sum7++;

	if(a == 5) sum5++;

	if(b == 7) sum7++;

	if(b == 5) sum5++;

	if(c == 7) sum7++;

	if(c == 5) sum5++;

	if(sum7 == 1 && sum5 == 2) printf("YES\n");

	else printf("NO\n");

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

using namespace std; 

int main() 

{ 

int a,b,c;

  cin>>a>>b>>c;

  if(a==5&&b==5&&c==7)  cout<<"YES"<<endl;

  else if(a==5&&b==7&&c==5)  cout<<"YES"<<endl;

  else if(a==7&&b==5&&c==5)  cout<<"YES"<<endl;

  else cout<<"NO"<<endl;

  return 0; 

  }

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

#include <cmath>





int main(){

	/*

	+ - 

	* / %

	=

	==  !=    <     >    <=    >=  

	double eps = 1e-8; 

	double x = 0.1, y = 0.2;

	fabs(x - y) < eps

	abs()

	if(x == y) printf("aa");

	*/

	/*

	位运算符



	&

	|

	^





	*/



	/*

	1 & 1 = 1

	1 & 0 = 0

	0 & 1 = 0

	0 & 0 = 0



	1 | 1 = 1

	1 | 0 = 1

	0 | 1 = 1

	0 | 0 = 0



	1 ^ 1 = 0

	1 ^ 0 = 1

	0 ^ 1 = 1

	0 ^ 0 = 0

	*/



	/*

   int n = 0;

   scanf("%d", &n);

   if((n & 1) == 1) printf("%d是奇数\n", n);

   else printf("%d是偶数\n", n);

	 */



	 /*

		 &&      || 

	 */

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if(a == 5 && b == 7 && c == 5) printf("YES\n");

	else if(a == 7 && b == 5 && c == 5) printf("YES\n");

	else if(a == 5 && b == 5 && c == 7) printf("YES\n");

	else printf("NO\n");

	return 0;

}