akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int x[n],y[n],h[n];
    rep(i,n)cin>>x[i]>>y[i]>>h[i];
    rep(i,101)rep(j,101){
        int ok=true;
        int H=0;
        rep(k,n){
            if(h[k]!=0){
              H=h[k]+abs(x[k]-i)+abs(y[k]-j);
              break;
            }
        }
        rep(k,n){
            if(max(H-abs(x[k]-i)-abs(y[k]-j),0)!=h[k]){
              ok=false;
              break;
            }
        }
        if(ok){
          cout<<i<<" "<<j<<" "<<H<<endl;
          return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    int dif = 'A' - 'a';
    cout << (char)(s1[0] + dif) << (char)(s2[0] + dif) << (char)(s3[0] + dif) << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int N;
V h;

int main() {
    cin >> N;
    h.resize(N);
    REP(i, N) cin >> h[i];
    int l, r, cnt = 0;
    while(true) {
        for(l = 0; l < N; l++) {
            if(h[l] > 0) break;
        }
        if(l == N) break;
        for(r = l; r < N; r++) {
            if(h[r] <= 0) break;
        }
        FOR(i, l, r) { h[i]--; }
        cnt++;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,m;
	double sum=0;
	int s=0;
	cin>>n>>m;
	int a[n];
	for (int i=0; i<n; i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	double M=sum/(4*m);
	for (int j=0; j<n; j++)
	{
		if (a[j]>=M)
		{
			s++;
		}
	}
	if (s>=m)
	{
		cout<<"Yes";
	}
	else
	  cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
int main(){
  int n;
  int k;
  cin >> n >> k;
  vector<int> p;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=p.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
const int MOD = 1000000007;

int main(){
    vector<ll> a(10000001,0);
    
    ll n; cin>>n;
    
    ll ans = 0;
    
    for(int i=1; i<=n; i++){
        ans += i * ((n/i)*(n/i+1))/2;
    }
    
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 81200
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

lli check(vector<lli>& vec, lli n,lli cmp, lli num) {
	if (num > 26)return -1;
	if (vec[n] == cmp)return 1;
	else return check(vec, vec[n], cmp, num + 1);
}

int main() {
	string s, t;
	cin >> s >> t;
	vector<lli> vec(26,-1),shift(26,-1);
	rep0(i, s.size()) {
		if (vec[(lli)(s[i] - 'a')] != -1) {
			if (vec[(lli)(s[i] - 'a')] == (lli)(t[i] - 'a')) {
				continue;
			}
			else{
				cout << "No";
				return 0;
			}
		}
		else {
			vec[(lli)(s[i] - 'a')] = (lli)(t[i] - 'a');
		}
		if (shift[(lli)(t[i] - 'a')] != -1) {
			if (shift[(lli)(t[i] - 'a')] == (lli)(s[i] - 'a')) {
				continue;
			}
			else {
				cout << "No";
				return 0;
			}
		}
		else {
			shift[(lli)(t[i] - 'a')] = (lli)(s[i] - 'a');
		}
		

	}

	cout << "Yes";
}


Measured memory_bytes: 776
print=console.log;
ls=require("fs").readFileSync("/dev/stdin","utf-8").split("\n");ls.length--
Object.prototype.trace = function(){ print(this+""); return this };
String.prototype.int = function(c){ return this.split(c||" ").map(int)};
ap = Array.prototype;
ap.trace = function(){ print(this); return this };
ap.max = function(){ return Math.max.apply(null, this) };
ap.min = function(){ return Math.min.apply(null, this) };
ap.copy = function(){ return this.map(id) };
ap.rotate = function(n){
  return this.slice(n, this.length).concat(this.slice(0, n));
};
ap.permutation = function () {
  if (this.length == 0) return [];
  if (this.length == 1) return [this];
  var ret=[], ar=this, i=0;
  for (; i<ar.length; ++i)
    ret=ret.concat(ar.slice(0, i)
           .concat(ar.slice(i+1, ar.length))
           .permutation()
           .map(function(p){ return p.concat(ar[i]) }));
  return ret;
};
ap.flatten = function() {
  for (var i=0, ret=[]; i<this.length; ++i) ret=ret.concat(this[i]);
  return ret;
};
ap.nub = function() {
  var that = this;
  return this.filter(function(x, i) {
    return that.slice(i+1).indexOf(x) < 0
  });
};
function iota(n, b, s) {
  b=b||0; s=s||1; for (var ret=[]; n--; b+=s) ret.push(b); return ret;
}
function int(s){return +s}
function add(a,b){return a+b}
function sub(a,b){return a-b}
function bus(a,b){return b-a}
function id(x){return x}

(function main() {
  var n = +ls[0],
      ab = ls[1].int(),
      a = ab[0]-1,
      b = ab[1]-1,
      cd = ls[2].int(),
      c = cd[0]-1,
      d = cd[1]-1;

  var min = n*n;
  function dis(a,b,i) {
    return Math.abs((a%i)-(b%i)) + Math.abs(((a/i)|0)-((b/i)|0))
  }
  for (var i=1; i<n; ++i) {
    var k = dis(a,b,i) + dis(c,d,i);
    // print(i, dis(a,b,i), dis(c,d,i));
    if (min > k) min = k;
  }
  print(min);
})();

// vim: set ft=javascript:

Measured memory_bytes: 7652
#include <iostream>
#include <vector>
using namespace std;

bool ContainLoop( int c, int p, const vector< vector<int> >& g, vector<int>& visit ) {

    visit[c] = true;
    
    for ( int dst : g[c] ) {
	if ( dst == p ) continue;
	if ( visit[dst] ) return true;
	if ( ContainLoop( dst, c, g, visit ) ) return true;
    }

    return false;
}

int main() {
    int n, m;
    while ( cin >> n >> m ) {

	if ( !n && !m ) break;

	vector<int> cnt( n );
	vector< vector<int> > g( n );
	vector<int> visit( n );

	bool ok = true;
	int s, t;
	for ( int i=0; i<m; ++i ) {
	    cin >> s >> t;
	    --s, --t;
	    ++cnt[s];
	    ++cnt[t];
	    if ( cnt[s] > 2 || cnt[t] > 2 ) ok = false;
	    g[s].push_back( t );
	    g[t].push_back( s );
	}

	if ( !ok ) cout << "no" << endl;
	else {
	    int i = 0;
	    for ( ; i<n; ++i ) {
		if ( !visit[i] && ContainLoop( i, -1, g, visit ) ) break;;
	    }
	    if ( i == n ) cout << "yes" << endl;
	    else cout << "no" << endl;
	    
	}

    }
    return 0;
}



Measured memory_bytes: 7008
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        System.out.println(solve(a, b, c) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int a, int b, int c) {
        return a == b + c || b == a + c || c == a + b;
    }
}

Measured memory_bytes: 19796
x,n=map(int,input().split())
if(n==0):
    print(x)
else:
    ans=99999999999
    s=set(list(map(int,input().split())))
    # print(s)
    for i in range(200,-1,-1):
        if i not in s:
            if(abs(x-i)<=abs(x-ans)):
                ans=i
    print(ans)

Measured memory_bytes: 9196
n = int(input())
a = input().split()
print(" ".join(a))
a1 = [a[0]]
a2 = a[1:]
for _ in range(n - 1):
    for j, k in enumerate(a1):
        if int(a2[0]) < int(k):
            if j == 0:
                a1.insert(0, a2[0])
            else:
                a1.insert(j, a2[0])
            break
    else:
        a1.append(a2[0])
    del a2[0]
    print(" ".join(a1 + a2))



Measured memory_bytes: 5600
import sys
from io import StringIO
import unittest

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def resolve():
    n,m,k=list(map(int,input().strip().split()))

    uf = UnionFind(n)

    res=[[] for i in range(n)]
    frd=[[] for i in range(n)]
    blk=[[] for i in range(n)]

    for i in range(m):
        a,b=list(map(int,input().strip().split()))
        a-=1
        b-=1
        uf.Unite(a,b)
        frd[a].append(b)
        frd[b].append(a)
    
    for i in range(k):
        a,b=list(map(int,input().strip().split()))
        a-=1
        b-=1
        #blk[a].append(b)
        #blk[b].append(a)
        frd[a].append(b)
        frd[b].append(a)
    
    rescnt=[]

    for i in range(n):
        ri=uf.Count(i)-1
        for f in frd[i]:
            if uf.isSameGroup(f,i):
                ri-=1
        rescnt.append(str(ri))
        ##rescnt.append(str(n-uf.size(i)-len(blk[i])))
    
    print(" ".join(rescnt))

resolve()


Measured memory_bytes: 128156
def sign(x):
    if x>0: return 1
    elif x==0: return 0
    else: return -1

def f0035(p1,p2,p3):
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3
    return sign((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1))

while True:
    try:
        dt =map(float, raw_input().split(","))
    except:
        break

    p1=dt[0:2]
    p2=dt[2:4]
    p3=dt[4:6]
    p4=dt[6:8]
    if f0035(p1,p3,p2) != f0035(p1,p3,p4) and f0035(p2,p4,p1) != f0035(p2,p4,p3): print "YES"
    else: print "NO"

Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

template<class T,T op(T,T)> class segtree{
public:
    int n,size_;
    vector<T> dat;
    T id_;
    segtree()=default;
    segtree(int size,T id,T initial_value){ init(size,id,initial_value); }
    void init(int size,T id,T initial_value){
        size_=size;
        id_=id;
        n=1;
        while(n<size) n*=2;
        dat.assign(2*n-1,id);
        for(int i=0; i<size; ++i) update(i,initial_value);
    }
    int size()const{ return size_; }
    void update(int k, T a) {
        k+=n-1; // leaf
        dat[k]=a;
        while(k>0) {
            k=(k-1)/2;
            dat[k]=op(dat[k*2+1],dat[k*2+2]);
        }
    }
    T at(int index){ return dat[index+n-1]; }
    void add(int k,T a){ update(k,at(k)+a); }
    T query(int a,int b) { return query(a,b,0,0,n); }
    T query(int a,int b,int k,int l,int r) {
        if(r<=a or b<=l) return id_;
        if(a<=l and r<=b) return dat[k];
        int m=(l+r)/2;
        return op(query(a,b,k*2+1,l,m),query(a,b,k*2+2,m,r));
    }
};

i64 sum(i64 a,i64 b){
    return a+b;
}


void solve(){
    i64 N,K;
    cin >> N >> K;
    vector<i64> a(N+1);
    rep(i,1,N+1){
        cin >> a[i];
        a[i]-=K;
    }

    vector<pair<i64,i64>> s(N+1);
    s[0]=make_pair(0,0);
    rep(i,1,N+1) s[i]=make_pair(s[i-1].first+a[i],i);
    sort(s.begin(),s.end());
    i64 ans=0;
    segtree<i64,sum> seg(N+1,0,0);
    rep(i,0,N+1){
        ans+=seg.query(0,s[i].second);
        seg.update(s[i].second,1);
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 9088
package main

import "fmt"

func main() {
	var X int
	fmt.Scan(&X)
	dp := make([]bool, X+106)
	dp[0] = true
	for i := 0; i <= X-100; i++ {
		if dp[i] {
			for j := 100; j <= 105; j++ {
				dp[i+j] = true
			}
		}
	}
	if dp[X] {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 1872
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    int a[] = new int[n];
    long aSum[] = new long[n];
    int b[] = new int[m];
    long bSum[] = new long[m];
    int ans = 0;
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.next());
      if (i == 0) {
        aSum[i] = a[i];
      } else {
        aSum[i] = aSum[i - 1] + a[i];
      }
      if (aSum[i] <= k) {
        ans = Math.max(ans, i + 1);
      }
    }
    for (int i = 0; i < m; i++) {
      b[i] = Integer.parseInt(sc.next());
      if (i == 0) {
        bSum[i] = b[i];
      } else {
        bSum[i] = bSum[i - 1] + b[i];
      }
      if (bSum[i] <= k) {
        ans = Math.max(ans, i + 1);
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (aSum[i] > k) {
        continue;
      }
      long remain = k - aSum[i];
      int maxIndex = Arrays.binarySearch(bSum, remain);
      if (maxIndex >= 0) {
        ans = Math.max(ans, i + 1 + maxIndex + 1);
      } else {
        ans = Math.max(ans, i + 1 - maxIndex - 1);
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 64144
#include <iostream>
using namespace std;

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
char v[] = { '>', 'v', '<', '^' };

int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		int H,W;
		cin >> H >> W;

		char a[H][W];
		for (int i=0; i<H; i++)
		for (int k=0; k<W; k++)
			cin >> a[i][k];

		int x,y,d;
		bool f=1;
		for (int i=0; f&&i<H; i++)
		for (int k=0; f&&k<W; k++)
			if (a[i][k]=='v'||a[i][k]=='^'||a[i][k]=='<'||a[i][k]=='>')
			{
				switch (a[i][k])
				{
					case '>':
						d=0; break;
					case 'v':
						d=1; break;
					case '<':
						d=2; break;
					case '^':
						d=3; break;
				}
				x=k; y=i; a[i][k]='.';
				f=0;
				break;
			}

		int S;
		cin >> S;
		for (int p=0; p<S; p++)
		{
			char c;
			cin >> c;
			if (c == 'S')
			{
				int px=x+dx[d], py=y+dy[d];
				while (px>=0 && px<W && py>=0 && py<H)
				{
					if (a[py][px]=='*' || a[py][px]=='#')
					{
						if (a[py][px]=='*')
							a[py][px] = '.';
						break;
					}
					px += dx[d]; py+= dy[d];
				}
			}
			else
			{
				switch (c)
				{
					case 'R':
						d=0; break;
					case 'D':
						d=1; break;
					case 'L':
						d=2; break;
					case 'U':
						d=3; break;
				}
				
				int nx=x+dx[d], ny=y+dy[d];
				if (nx>=0 && nx<W && ny>=0 && ny<H && a[ny][nx]=='.')
				{
					x=nx; y=ny;
				}
			}
		}
		
		for (int i=0; i<H; i++)
		{
			for (int k=0; k<W; k++)
				if (i==y&&k==x)
					cout << v[d];
				else
					cout << a[i][k];
			cout << endl;
		}
		
		if (N > 0)
			cout << endl;
	}
}

Measured memory_bytes: 0
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,d[100010],sonn[100010],dp[100010];
map <LL,LL> mp;
vector <LL> g[100010];
vector <pii> ans,v;
bool vis[100010];

bool cmp(pii a,pii b)
{
	return a.fi>b.fi;
}

void dfs(LL pos,LL no)
{
	if(vis[pos])
	{
		puts("-1");
		exit(0);
	}
	sonn[pos]=1;
	vis[pos]=true;
	rep(i,g[pos].size())
	{
		if(g[pos][i]==no) continue;
		dfs(g[pos][i],pos);
		dp[pos]+=dp[g[pos][i]]+sonn[g[pos][i]];
		sonn[pos]+=sonn[g[pos][i]];
	}
}

void dfs2(LL pos,LL no,LL now)
{
	if(now+dp[pos]!=d[pos])
	{
		puts("-1");
		exit(0);
	}
	rep(i,g[pos].size()) 
	if(g[pos][i]!=no) dfs2(g[pos][i],pos,now+dp[pos]-dp[g[pos][i]]-sonn[g[pos][i]]+n-sonn[g[pos][i]]);
}

int main()
{
	rep(i,100005) sonn[i]=1;
	cin>>n;
	rep(i,n)
	{
		scanf("%lld",&d[i]);
		mp[d[i]]=i;
		v.pb({d[i],i});
	}
	sort(v.begin(),v.end(),cmp);
	rep(i,v.size()-1)
	{
		LL wantpar=v[i].fi-n+sonn[v[i].se]*2;
		if(wantpar>=v[i].fi||mp.find(wantpar)==mp.end())
		{
			puts("-1");
			rt0;
		}
		sonn[mp[wantpar]]+=sonn[v[i].se];
		ans.pb({v[i].se,mp[wantpar]});
		g[v[i].se].pb(mp[wantpar]);
		g[mp[wantpar]].pb(v[i].se);
	}
	memset(sonn,0,sizeof(sonn));
	dfs(0,0);
	dfs2(0,0,0);
	rep(i,n-1) cout<<ans[i].fi+1<<' '<<ans[i].se+1<<endl;
	rt0;
}

Measured memory_bytes: 24816
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
L = []
for i in range(Q):
    B,C = map(int,input().split())
    L.append([B,C])
c = {}
for i in range(1,100001):
    c[i] = 0
for k in A:
    c[k] += 1
s = sum(A)
for i in range(Q):
    if c[L[i][0]] == 0:
        print(s)
    else:
        n = c[L[i][0]]
        c[L[i][1]] += n
        c[L[i][0]] = 0
        s += (L[i][1] - L[i][0])*n
        print(s)

Measured memory_bytes: 104280
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ll i,j;
    vector<pair<ll,ll>> c;
    ll n,m;
    cin >> n >> m;
    ll ans = 0;
    priority_queue<pair<ll,ll>> que;
    for(i = 0;i < n;++i){
        ll a,b;
        cin >> a >> b;
        que.emplace(-a,b);
    }
    ll k = m-1;
    priority_queue<ll> tmp;
    while(k >= 0){
        ll a = m+1,b;
        if(!que.empty()){
            auto d = que.top();
            a = -d.first + k;
            b = d.second;
        }

        if(a <= m){
            tmp.push(b);
            que.pop();
        }else{
            if(tmp.empty()){
                --k;
            }else{
                ans += tmp.top();
                tmp.pop();
                --k;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, M;
  cin >> N;
  map<string, int> blue, red;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i];
    blue[s[i]]++;
  }
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t[i];
    red[t[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, blue[s[i]] - red[s[i]]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int a[n];
    int i;
    int sum=0;
    for (i=0;i<n;i++){
        std::cin >> a[i];
        sum+=a[i];
    }
    int ans;
    int sum1=0;
    int value=sum;
    for (i=0;i<n;i++){
        sum1+=a[i];
        if (value>abs(sum-sum1-sum1)){value=abs(sum-sum1-sum1);}
    }
    std::cout << value << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    int four = 0;
    int two = 0;
    int odd = 0;
    for(int i = 0; i < N; ++i) {
        if(a[i] % 4 == 0)
            four++;
        else if (a[i]%2 == 0)
            two++;
        else
            odd++;
    }
    if (four >= odd)
        cout << "Yes" << endl;
    else if (four + 1 == odd && two == 0)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
//ABC118C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> l(n);
	for(int i=0;i<n;i++){
		cin >> l.at(i);
	}
	sort(l.begin(),l.end());
	int sigma = 0;
	for(int i=0;i<n-1;i++){
		sigma += l.at(i);
	}
	if(sigma > l.at(n-1)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, K, sum = 0, sum1 = 0, L;
  cin >> N >> K;
  vector<int64_t> A(2*N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A.at(i + N) = A.at(i);
  }
  for (int i = 0; i < 2*N - 1; i++) {
    for (int j = i + 1; j < 2*N; j++ ){
      if (A.at(i) > A.at(j)) {
        sum++;
      }
    }
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (A.at(i) > A.at(j)) {
        sum1++;
      }
    }
  }
  L = (K - 1)  * K / 2 % 1000000007;
  cout << (K * sum1 + (sum - 2 * sum1) * L) % 1000000007 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace Caesar_Cipher
{
    class Program
    {
        static void Main(string[] args)
        {
            string w1 = "the", w2 = "this", w3 = "that";

            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    break;
                }                

                for (int i = 0; i<26;++i)
                {
                    char[] c = input.ToCharArray();
                    for (int j = 0; j < c.Length; ++j)
                    {
                        if(c[j] != ' ' && c[j] != '.')
                        {
                            c[j]++;
                            if (c[j] > 'z') c[j] = (char)(c[j] - 26);
                        }
                    }
                    input = new string(c);
                    if (input.Contains(w1))
                    {
                        Console.WriteLine(input);
                    }
                    else if (input.Contains(w2))
                    {
                        Console.WriteLine(input);
                    }
                    else if (input.Contains(w3))
                    {
                        Console.WriteLine(input);
                    }
                }



            }
        }
    }
}


Measured memory_bytes: 13736
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;

	vector<string>kst;//n枚分のカードの情報:kst
	vector<string>card;//並べ終わった後のカードを入れるvector:card
	int n,k;
	int flag[10]={1};
void solve(string now,int i){//カードのすべてのパターンを列挙する
		if(i==k){
			bool f=true;
			for(int j=0;j<card.size();j++){
			if(now==card[j])f=false;
			}
			
			if(f)card.push_back(now);
		}
		else 
		for(int j=0;j<n;j++){
		
			if(flag[j]!=-3){
				flag[j]=-3;
			solve(now+kst[j],i+1);
			flag[j]=1;
			
			}
		}
}

int main(){
	
	while(cin>>n>>k,n&&k){
	kst.clear();
	card.clear();
	for(int i=0;i<n;i++){
		string a;
		cin>>a;
		kst.push_back(a);
	}
	solve("",0);
	int count=0;
	cout<<card.size()<<endl;
}

}

Measured memory_bytes: 1364
AA = input()
A =list(AA)
BB = input()
B = list(BB)
CC = input()
C = list(CC)

X ='a'

while True:
  
  if X  == 'a':
    if len(A) == 0:
        break
    else:
        X = A.pop(0)  
  elif X =='b':
    if len(B) ==0:
        break
    else:
        X = B.pop(0)
  else:
    if len(C) == 0:
        break
    else:
        X = C.pop(0)
print(X.upper())


Measured memory_bytes: 8976
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    while ( cin >> N, N > 0 ) {
        int cnt = 0;
        bool flag = false;
        for ( int i = 0; i < N; i++ ) {
            int k;
            cin >> k;
            if ( k > 0 ) {
                cnt++;
            }
            if ( k >= 2 ) {
                flag = true;
            }
        }
        if ( flag ) {
            cout << cnt + 1 << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 2019;
ll po(ll x, ll n ){ 
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r" , stdin);
	//freopen("output.txt", "w" , stdout);
	#endif

	string s;
	cin >> s;
	
	unordered_map<int,int> m;
	
	int n=s.length();
	int value=0,ans=0;
	
	int power_of_ten=1;
	m[0]=1;
	rep(i,n){
		int v=s[n-1-i]-'0';
		value=(power_of_ten*v+value)%mod;
		ans+=m[value];
		m[value]++;
		power_of_ten=(power_of_ten*10)%mod;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
int M, D, cont;
int main() {
	cin>>M>>D;
	for(int i = 1; i <= M; i++) {
		for(int j = 1; j <= D; j++) {
			int d1 = j % 10, d10 = j / 10;
			if(d1 >= 2 && d10 >= 2 && d1 * d10 == i)	cont++;
		}
	}
	cout<<cont<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

const int NIL = -1;
int n, m, a[55][55]={}, b[55][2];

int nyaan(){
    int d[55];
    for(int i=0; i<n; i++)d[i] = NIL;
    int que[55], l=0, r=0;
    d[0] = 0;
    que[r++] = 0;
    while(r != l){
        int t = que[l++];
        for(int i=0; i<n; i++){
            if(a[t][i] == 1 && d[i]==NIL){
                d[i] = 0;
                que[r++] = i;
            }
        }
    }
    int flag = 0;
    for(int i=0; i<n; i++)if(d[i]==NIL)flag = 1;
    return flag;
}

main(){
    scanf("%d%d", &n, &m);
    for(int i=0; i<m; i++){
        scanf("%d%d", &b[i][0], &b[i][1]);
        b[i][0]--;b[i][1]--;
        a[b[i][0]][b[i][1]] = 1;
        a[b[i][1]][b[i][0]] = 1;
    }
    int sum = 0;
    for(int i=0; i<m; i++){
        a[b[i][0]][b[i][1]] = 0;
        a[b[i][1]][b[i][0]] = 0;
        sum += nyaan();
        a[b[i][0]][b[i][1]] = 1;
        a[b[i][1]][b[i][0]] = 1;
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

int n;
vector<vector<pair<int, bool>>> data;
bitset<16> mask;
int ans = 0;

void solve(int idx) {
    if(idx == n) {
        bool f = true;
        for(int i = 0; i < n; i++) {
            if(!mask[i]) continue;
            for(auto &p : data[i]) {
                int u = p.first;
                bool kind = p.second;
                f &= (mask[u] == kind);
            }
        }

        ans = max(ans, (int)mask.count() * f);
        return;
    }

    mask.set(idx, false);
    solve(idx + 1);
    mask.set(idx, true);
    solve(idx + 1);
}

int main() {
    cin >> n;
    data.resize(n, vector<pair<int, bool>>());
    for(int i = 0; i < n; i++) {
        int k; cin >> k;
        while(k--) {
            int u;
            bool kind;
            cin >> u >> kind;
            data[i].push_back({--u, kind});
        }
    }

    solve(0);
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;

    map<int, int> number_and_count;

    for (int i = 0; i < n; i++)
    {
        int input;
        cin >> input;
        number_and_count[input] += 1;
    }

    string ans = "YES";
    for (auto entry : number_and_count)
    {
        if (entry.second != 1)
            ans = "NO";
    }

    cout << ans;
}

Measured memory_bytes: 9600
/*-------------------------------------------------
|  __                                       __    |
| |  |--.-----.---.-.----.----.-----.-----.|  |_  |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _| |
| |_____|_____|___._|____|____|_____|   __||____| |
|                                   |__|          |
-------------------------------------------------*/
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
typedef long long lint; using namespace std;
#define rep(counter, limit) for (int counter = 0; counter < (limit); counter++)
#define INF 1000000000000
#define MOD 10000007
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}setupios;
int main() {

  string s;
  cin>>s;
  string x=s.substr(0,(int(s.length())/2));
  string y=s.substr((int(s.length())/2+1),int(s.length()));s.reserve();
  if(x==y)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N;
	cin>>N;
	int num[100006];
	for(int i=0;i<N;i++){
		cin>>num[i];
	}
	long long sum=0;
	for(int i=0;i<N;i++){
		sum=sum+num[i]-1;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int W, a, b;
	cin >> W >> a >> b;
	if (a > b)
	{
		int c;
		c = b;
		b = a;
		a = c;

	}
	int ans = b - (a + W);
	if (ans< 0)
	{
		ans = 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <list>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	list<int> l;
	list<int>::iterator it, itt;
	for (int i = 0; i < n; i++){
		char command[20];
		int key;
		cin >> command;
		if(command[0] == 'i'){
			cin >> key;
			l.push_front(key);
		}else if(command[6] == 'F'){
			l.pop_front();
		}else if(command[6] == 'L'){
			l.pop_back();
		}else{
			cin >> key;
			for(it = l.begin(); it != l.end(); it++)  
			{  
				if(*it == key){
					l.erase(it);
					break; 
				}
			}   
		}
	}
	for(it= l.begin(), itt = --l.end(); it != itt; it++)  
	{  
		cout << *it << " ";
	}  
	cout << *it << endl;
	return 0;
}


Measured memory_bytes: 34292
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    string s = to_string(n);
    long long a = 0;
    for (int i = 0; i < s.size(); i++)
        a += s[i] - '0';
    if (n % a == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import fractions
a, b, c, d = map(int, input().split())

#a~bでnで割り切れるものの数
def func(a, b, n):
    answer = (int(b/n) - int((a-1)/n))
    return answer

def func_test2(a, b, n):
    answer = (int(b//n) - int((a-1)//n))
    return answer

def func_test(a,b,n):
    return b//n - (a-1)//n

lcm = int((c * d) / fractions.gcd(c, d))

print ((b - a + 1) - func_test2(a,b,c) - func_test2(a,b,d) + func_test2(a,b,lcm))

Measured memory_bytes: 5048
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;


ll add(lst & check)
{
	ll o = 0;
	ll rtn = 0;
	for(auto & c : check)
	{
		if (c == 0)
		{
			o++;
		}
		else
		{
			rtn += o;
		}
	}
	return rtn;
}


int main()
{
	string S;
	cin >> S;

	lst check;
	ll ans = 0;
	for (int i = 0; i < S.length(); ++i)
	{
		if (S[i] == 'A')
		{
			check.push_back(0);
		}
		else if (S.substr(i, 2) == "BC")
		{
			++i;
			check.push_back(1);
		}
		else
		{
			ans += add(check);
			check.clear();
		}
	}
	ans += add(check);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6660
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 100000;
int a[MAX_N];

int main(){
  cin >> N;
  REP(i, N) cin >> a[i];
  int ct[100000];
  m0(ct);
  REP(i, N) ct[a[i]]++;
  int ans = 0;
  REP(i, 100000 - 2) {
    ans = max(ans, ct[i] + ct[i + 1] + ct[i + 2]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(char i='1';i<='9';i++)
	{
		string x="";
		x+=i;
		x+=i;
		x+=i;
		if(x>=s)
		{
			cout<<x;
			break;
		}
		x="";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>



int main(void){
    int a,b,v,w,t;
    scanf("%d %d",&a,&v);
    scanf("%d %d",&b,&w);
    scanf("%d",&t);
    if(v<=w){printf("NO");return 0;}//鬼より子が早いor同速度なら永遠に追いつけない
    if(abs(a-b)-abs(w-v)*t<=0){printf("YES");}
    else{printf("NO");}

}


Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 同じ方向に2回連続で進む動作は1回分にまとめて考えられるから無視できる

ll res, s;
int n, l[100100], r[100100];

int main() {
	cin >> n;
	rep(i,n) cin >> l[i] >> r[i];
	sort(l,l+n+1), sort(r,r+n+1);
	reverse(l,l+n+1);
	rep(i,n+1) {
		s += (l[i]-r[i])*2;
		chmax(res, s);
	}
	cout << res;
}

Measured memory_bytes: 1024
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val s = List.fill(n)(sc.next())
  val m = s.map(_.toSeq.groupBy(identity).view.mapValues(_.length))
  val sb = new StringBuilder
  for (c <- 'a' to 'z') {
    val count = m.map(_.getOrElse(c, 0)).min
    sb.addAll(c.toString * count)
  }
  println(sb.toString())
}


Measured memory_bytes: 56720
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

vector<ll> F(1000000, -1);

ll power(ll a, ll e){
    if(e==0) return 1;
    if(e%2==0){
        ll r = power(a, e/2);
        return r * r % MOD;
    } else {
        ll r = power(a, e/2);
        return r * r % MOD * a % MOD;
    }
}

ll Inv(ll a){
    return power(a, MOD-2);
}

void Fact(){
    F[0] = 1;
    for(int i=0; i<1000000 - 1; i++){
        F[i+1] = F[i] * (i+1) % MOD;
    }
    return;
}


ll Combi(ll a, ll b){
    return F[a] % MOD * Inv(F[b]) % MOD * Inv(F[a-b]) % MOD;
}


int main() {
    ll H, W, A, B; cin >> H >> W >> A >> B;
    Fact();
    vector<ll> P(H-A);
    vector<ll> R(H-A);
    ll sum = 0;
    for(int i=0; i<H-A; i++){
        if(i==0) P[i] = Combi(B+i, i);
        else P[i] = ((Combi(B+i, i) + MOD) - (Combi(B+i-1, i-1))) % MOD;
        R[i] = P[i] * Combi(H-1-i+W-B-1, H-1-i) % MOD;
        sum = (sum + R[i]) % MOD;
        
    }
    
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 9472
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF (int)1e9+7
#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 vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
//#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795


ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll N=2e5+1;

ll solve(ll t,vector<ll>& a,ll n)
{
  ll ans=0;
  for(int i=1;i<=n;i++)
    ans+=(a[i]-t)*(a[i]-t);

  return ans;

}


ll bx(ll n)
{
  ll temp=10;
  while(n)
  {
    temp=min(temp,n%10);
    n/=10;
  }
  return temp;
}

ll ax(ll n)
{
  ll temp=0;
  while(n)
  {
    temp=max(temp,n%10);
    n/=10;
  }
  return temp;
}



int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);



ll n;cin>>n;

set<ll>s;
s.insert(2);
s.insert(n);
s.insert(n-1);

if (n==2)
{
  cout<<1<<"\n";
  return 0;
}

for(ll i=2;i*i<=n;i++)
{
  if((n-1)%i==0)
  {
    s.insert((n-1)/i);
    s.insert(i);
  }
  if(n%i==0)
  {
    ll copy=n/i;
    while(copy%i==0)copy/=i;
   // cout<<x<<" "<<i<<"\n";
    if(copy%i==1)s.insert(i);
  }
}

//for(auto x:s)cout<<x<<" "<<"\n";


cout<<s.size()<<"\n";

return 0;

}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
     int N, K;
     cin >> N >> K;

     vector<bool> D(10, false);

     rep(i, 0, K) {
       int tmp;
       cin >> tmp;
       D.at(tmp) = true;
     }

     for (int i = N;;i++) {
       int i_tmp = i;
       bool ok = true;
       while(i_tmp) {
         if (D.at(i_tmp % 10)) {
           ok = false;
           break;
         }
         else i_tmp /= 10;
       }
       if (ok) {
         cout << i << endl;
         break;
       }
     }
 }


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def main():
    """
    https://atcoder.jp/contests/abc045/submissions/14945636
    が高速に動作していたので参考に写経する。

    各黒マスに対して、それを含むテンプレートを左上の座標値で管理する。
    （写経元は右下座標で管理してる）
    このテンプレート及びそこに黒マスが何個入っているかを管理しておけば
    黒マス位置をソートして全体位置を把握していなくてもオンラインで更新が可能。
    """
    H, W, N = map(int, input().split())
    ans = [0] * 10
    templates = {}
    for _ in range(N):
        a, b = map(int, input().split())
        for i in range(9):
            # (h, w)がテンプレートの左上座標
            h, w = (a - 3) + i // 3, (b - 3) + i % 3
            if h < 0 or w < 0: continue
            if h > H - 3 or w > W - 3: continue
            idx = h * W + w
            if idx in templates:
                ans[templates[idx]] -= 1
                templates[idx] += 1
                ans[templates[idx]] += 1
            else:
                templates[idx] = 1
                ans[1] += 1
    ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
    for a in ans: print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 148120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int main(){
	int k, a, b;
	scanf("%d%d%d", &k, &a, &b);
	ll bs = 1;
	int t = min(a - 1, k);
	bs += t;
	k -= t;
	if (k && b - a > 2){
		int t = k >> 1;
		k -= t << 1;
		bs += (ll)(b - a) * t;
	}
	if (k)bs += k;
	printf("%lld\n", bs);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            string S = Console.ReadLine();
            int N = S.Length;
            int sum_zero=0;
            for(var i=0;i<N;i++){
                if(S[i]=='0')
                    sum_zero++;
            }
            int sum_one = N-sum_zero;
            Console.WriteLine(2*Math.Min(sum_zero,sum_one));
        }
    } 
}

Measured memory_bytes: 11232
#include<stdio.h>

int main(void)
{
  int i,j,k,n,temp,temp1;
  int m1,m2;
  char in[2], chartemp;
  int a[26];

  while(scanf("%d",&n))
    {
      for(i=0;i<26;i++)
	{
	  a[i] = 0;
	}
      if(n==0)
	break;
      else
	{
	  k = 0;
	  for(i=0;i<n;i++)
	    {
	      scanf("%s",in);
	      temp = in[0];
	      a[temp-65]++;
	      m1 = 0;
	      for(j=0;j<26;j++)
		{
		  if(m1<=a[j])
		    {
		      m1 = a[j];
		      temp1 = j;
		    }
		}
	      m2 = 0;
	      for(j=0;j<26;j++)
		{
		  if(m2<=a[j]&&j!=temp1)
		    {
		      m2 = a[j];
		    }
		}
	      if((m1-m2)>n-(i+1)&&k==0)
		k = i;
	    }
	  chartemp = temp1;
	  if(k!=0) printf("%c %d\n",chartemp+65,k+1);
	  else if(k==0&&m1!=m2) printf("%c %d\n",chartemp+65,n);
	  else printf("TIE\n");
	}
    }
  return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
int main()
{
       string s,t;
       cin>>s>>t;
       t.pop_back();
       if(t == s){
              cout<<"Yes"<<endl;
       }
       else{
              cout<<"No"<<endl;
       }
}


Measured memory_bytes: 3632