akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
const int Max = 3;
int a[4][2]= {0,-1,1,0,0,1,-1,0};
int last[9][2]= {{2,2},{0,0},{0,1},{0,2},{1,0},{1,1},{1,2},{2,0},{2,1}}; // 目标状态的数字所在位置
int k[Max][Max],k2[Max*Max],flag=0,limit,Mi;   // k用来保存八数码状态，k2用来计算曼巴顿距离
int add(int k[Max][Max])       // 曼哈顿距离为 所有的数字要走到目标状态，最少要和0换的次数；
{
    int i,j;
    int sum = 0;
    for(i=0; i<3; i++)
        for(j=0; j<3; j++)
        {
            if(k[i][j]!=0)     //判断曼哈顿距离不能判断0；
                sum += abs(i-last[k[i][j]][0])+abs(j - last[k[i][j]][1]);  //求曼哈顿距离
        }
    return sum;
}
void dfs(int y,int x,int len,int f)     // x,y当前0的坐标 len 为已经走了几步了，f为当上一次的搜索方向
{
    int s = add(k);                     // 求当前状态的曼哈顿距离
    if(flag) return;                    // 如果找到符合的结果，不在搜索
    if(len<=limit)
    {
        if(s==0)                        //曼哈顿距离为零，为目标状态
        {
            flag=1;
            Mi=len;
            return ;
        }
        if(len==limit) return;          //递归到了本轮终点，结束
    }
    for(int i=0; i<4; i++)
    {
        int tx = x + a[i][0];
        int ty = y + a[i][1];
        if(tx>=0&&ty>=0&&ty<3&&tx<3&&((f==-1)||i!=(f+2)%4))
        {
            swap(k[y][x],k[ty][tx]);    // 让下一个数与 0 交换位置
            if(len+add(k)<=limit)       // IDA* 值减少，当前走的步数 加上 当前状态到达标状态的最小步数，
            {
                // 要小于等于当前枚举到的最小的 从起始状态到达目标状态的步数，不能超过；
                dfs(ty,tx,len+1,i);
                if(flag) return ;
            }
            swap(k[y][x],k[ty][tx]);    //还原
        }
    }
}
int main()
{
    int i,j;
    while(~scanf("%d",&k2[0]))
    {
        int y,x;
        k[0][0] = k2[0];
        if(k2[0]==0)    //记录 0 所在的位置
        {
            y = 0;
            x = 0;
        }
        for(i=1; i<Max*Max; i++)
        {
            scanf("%d",&k2[i]);
            k[i/3][i%3] = k2[i];//把输入的数存到二维数组
            if(k2[i]==0)        //记录 0 所在的位置
            {
                y = i/3;
                x = i%3;
            }
        }
        flag = 0;
        limit = add(k);        // 当前要达到目标状态的最小步数；
        while(!flag&&limit<=36)
        {
            dfs(y,x,0,-1);
            if(!flag)          //如果本轮没有满足的条件，扩大搜索范围
                limit ++;      // 深搜底线 +1
        }
        if(flag)
            printf("%d\n",Mi);
    }
    return 0;
}



Measured memory_bytes: 2748
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int x, y, kame = 0;
    int total = 0;
    cin >> x >> y;
    if(y%2 != 0){
        cout << "No" << endl;
        exit(0);
    }
    if(y-2*x < 0){
        cout << "No" << endl;
        exit(0);
    }
    kame = (y- 2 * x)/2;
    if(x-kame>=0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n, m, count = 0;
	scanf("%d", &n);
	
	set<int> s;
	
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &m);
		s.insert(m);
	}
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &m);
		
		if(s.find(m) != s.end())
			count++;
	}
	
	printf("%d\n", count);
	
	return 0;
}


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

#define check(n) (s.substr(s.size() - n, n))

int main()
{
    int count;
    string s;
    cin >> s;
    count = s.size();
    while (count){
        if (check(5) == "dream" || check(5) == "erase"){
            count -= 5;
            s = s.substr(0, s.size() - 5);
        }else if (check(6) == "eraser"){
            count -= 6;
            s = s.substr(0, s.size() - 6);
        }else if (check(7) == "dreamer"){
            count -= 7;
            s = s.substr(0, s.size() - 7);
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}

__attribute__((constructor)) void init()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

signed main()
{
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  int cnt = 0;
  rep(i, n)
  {
    if (v[i] <= x)
    {
      if (i != n - 1)
      {
        cnt++;
        x -= v[i];
      }
      else
      {
        if (v[i] == x)
        {
          cnt++;
        }
      }
    }
    else
    {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,a[10];
	n=0;
	for(i=1;i<=3;i++)
	 cin>>a[i];
	sort(a+1,a+3+1);
	cout<<a[2]+a[1];
	  
	 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;

  string res = "";
  for(int i=0;i<n;++i){
    res += s[i];
    res += t[i];
  }
  cout << res << "\n";
  return 0;
}



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

    int X,num,md;
    cin >> X;
    num = X/100;
    md = X%100;
    if(md<=num*5) cout << "1" << endl;
    else cout << "0" << endl;

  return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 003
"""

from operator import itemgetter

n = int(input())
ali = [int(input()) for i in range(n)]
sortedali = sorted(enumerate(ali), key=itemgetter(1))

ansdouble = 0
for (i, (j, _)) in enumerate(sortedali):
    if (i-j) % 2 != 0:
        ansdouble += 1

print(ansdouble//2)


Measured memory_bytes: 19060
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <functional>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

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

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

bool res() {
	int n;
	cin >> n;
	if (!cin) return false;
	vi a(n); for (int i = 0; i < n; ++i) cin >> a[i];
	vi b(n); for (int i = 0; i < n; ++i) cin >> b[i];

	bool pos = true;
	ll nmov = 0;

	queue<int> picos;
	for (int i = 1; i < n - 1; ++i) {
		if (b[i] == a[i]) {}
		else if (b[i] == b[i + 1] || b[i] == b[i - 1] || b[i] < a[i]) {
			pos = false;
			break;
		}
		else if (b[i] > b[i + 1] && b[i] > b[i - 1]) {
			picos.push(i);
		}
	}

	if (b[0] == a[0]) {}
	else if (b[0] == b[1] || b[0] == b[n - 1] || b[0] < a[0]) {
		pos = false;
	}
	else if (b[0] > b[1] && b[0] > b[n - 1]) {
		picos.push(0);
	}

	if (b[n-1] == a[n - 1]) {}
	else if (b[n - 1] == b[0] || b[n - 1] == b[n - 2] || b[n-1] < a[n-1]) {
		pos = false;
	}
	else if (b[n - 1] > b[0] && b[n - 1] > b[n - 2]) {
		picos.push(n-1);
	}

	while (!picos.empty()) {
		int idxact = picos.front(); picos.pop();

		int lados = 0;
		int lad1, lad2;
		if (idxact == 0) {
			lad1 = b[n - 1];
		}
		else {
			lad1 = b[idxact - 1];
		}
		if (idxact == n - 1) {
			lad2 = b[0];
		}
		else {
			lad2 = b[idxact + 1];
		}
		lados = lad1 + lad2;

		int divis;
		
		int dif = b[idxact] - max({ a[idxact] , lad1,lad2});
		double divsnec = ((double)dif) / lados;
		divis = ceil(divsnec);

		b[idxact] -= divis * lados;
		nmov += divis;

		if (b[idxact] < a[idxact]) {
			pos = false;
			break;
		}
		else {
			//Miramos si los de los lados son picos
			int dcha = (idxact + 1) % n;
			int izq = (idxact - 1 + n) % n;

			int i1 = min(izq, dcha);
			int i2 = max(izq, dcha);

			if (i1 == 0) {
				if (b[0] == a[0]) {}
				else if (b[0] == b[0 + 1] || b[0] == b[n - 1]) {
					pos = false;
					break;
				}
				else if (b[0] > b[0 + 1] && b[0] > b[n - 1]) {
					picos.push(i1);
				}
			}
			else {
				if (b[i1] == a[i1]) {}
				else if (b[i1] == b[i1 + 1] || b[i1] == b[i1 - 1]) {
					pos = false;
					break;
				}
				else if (b[i1] > b[i1 + 1] && b[i1] > b[i1 - 1]) {
					picos.push(i1);
				}
			}

			if (i2 == n-1) {
				if (b[n-1] == a[n - 1]) {}
				else if (b[n - 1] == b[0] || b[n - 1] == b[n - 2]) {
					pos = false;
					break;
				}
				else if (b[n - 1] > b[0] && b[n - 1] > b[n - 2]) {
					picos.push(i2);
				}
			}
			else {
				if (b[i2] == a[i2]) {}
				else if (b[i2] == b[i2 + 1] || b[i2] == b[i2 - 1]) {
					pos = false;
					break;
				}
				else if (b[i2] > b[i2 + 1] && b[i2] > b[i2 - 1]) {
					picos.push(i2);
				}
			}
		}
	}


	if (pos) cout << nmov << '\n';
	else cout << "-1\n";

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

void dump(vector<long long > hoge) {
    int n = hoge.size(); for(int i = 0; i < n; ++i){ cout << hoge[i] << " "; } cout << endl;
}

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool augment(const Graph& g, int u, vector<int>& matchTo, vector<bool>& visited) {
  if (u < 0) return true;
  FOR(e, g[u]) if (!visited[e->dst]) {
    visited[e->dst] = true;
    if (augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
int bipartiteMatching(const Graph& g, int L) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  return match;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<pair<int, int>> reds, blues;
    reds.reserve(n);
    blues.reserve(n);
    for(int i = 0; i < n; ++i){
        int a,b;
        cin >> a >> b;
        reds.push_back(make_pair(a,b));
    }
    for(int i = 0; i < n; ++i){
        int a,b;
        cin >> a >> b;
        blues.push_back(make_pair(a,b));
    }

    Graph g(n*2);

    for(int i = 0; i < n; ++i){
        int ax = reds[i].first, ay = reds[i].second;
        for(int j = 0; j < n; ++j){
            int bx = blues[j].first, by = blues[j].second;

            if (ax < bx && ay < by) {
                g[i].push_back(Edge(i, n+j,1));
            }
        }
    }

    int ans = bipartiteMatching(g, n);
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
/*小文字判定
if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  */

int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(int *a, int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}//ちいさい順
//qsort(a,n,sizeof(int),cmp);
//char s[n][11]

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);


int main (void)
{
	int a[210000],b,c,n,i,k,count=0,count2=0;
  char s[200005], s2[200005],temp[5];

scanf("%d",&n);
scanf("%s",s);
  
  for(i=0;i<n;i++){
  s2[i]=s[i];
  
  }

	for(i=n-1; i>0; i--){
    if(s[i]=='R'&&s[i-1]=='W'){
      s[i-1]='R';
    count++;
    }
    }
  i=0;
  k=n-1;
  while(1){
  while(s2[i]!='W'&&i<=n) i++;
    while(s2[k]!='R'&&k>=0) k--;
  if(i>=k) break;
    temp[0]=s2[i];
      s2[i]=s2[k];
    s2[k]=temp[0];
      count2++;
    i++;
    k--;
    
  }
  
  if(count2>count){
  printf("%d",count);
return 0;
  }
  printf("%d",count2);
  return 0;
}


Measured memory_bytes: 2120
#include<stdio.h>
int a[400000];
int visit[400000];
int cur,num,i,record,n;
long long k,t,cycle;
int main(){
	scanf("%d %lld",&n,&k);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for (i=1;i<=n;i++) visit[i]=0;
	cur=1;num=0;
	while (1==1){
		num++;
		cur=a[cur];
		if (visit[cur]!=0)
		{record=cur;
		 break;
		}else{
			visit[cur]=num;
		}
	}
	cycle=num-visit[record];
	if (k<=visit[record]){
		cur=1;
		for (i=1;i<=k;i++)
		  cur=a[cur];
		printf("%d",cur);
	}else{
		t=(k-(visit[record]-1))%cycle;
		if (t==0) t=cycle;
		cur=1;
		for (i=1;i<=visit[record]-1+t;i++)
		  cur=a[cur];
		printf("%d",cur);
	}
}

Measured memory_bytes: 3296
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int candy = sc.nextInt();
        int[] a = new int[N];
        for(int n=0;n<N;n++) a[n]=sc.nextInt();
        Arrays.sort(a);
        
        int ans = 0;
        for(int n=0;n<N;n++){
        	if(candy < a[n]) break;
        	if(n<N-1 || a[n]==candy){
        	    ans++;
        	    candy -= a[n];
        	}
        }
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int cnt[256];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>s;
	FORR(c,s) cnt[c]++;
	
	FOR(i,256) if(cnt[i]%2) return _P("No\n");
	_P("Yes\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
n, k = ARGF.gets.split.map(&:to_i)
s = ARGF.gets.chomp

#$stderr.puts "'#{s}'"

h = 0
(1...n).each do |i|
#  $stderr.puts "#{i-1}:#{s[i-1]} - #{i}:#{s[i]}"
  if s[i-1] == s[i]
    h += 1
  end
end


#$stderr.puts h
h += 2 * k
#$stderr.puts h

unless h < n
  h = n - 1
end
puts h


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
int main()
{
  ll sum=0;
  ll K;
  cin>>K;
  rep(i,K){
    rep(j,K){
      rep(l,K){
        sum+=gcd(i+1,gcd(j+1,l+1));
      }
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include<string.h>
int main(){
  
    int arr[100] ; 
    int n  , i; 
    scanf("%d",&n);
    for(i = 0 ; i<n ; i++){
        scanf("%d",&arr[i]);
    }
    int max = 0 ,  j ;
    for(i = 0 ;i< n-1 ; i++){
        for(j = i+1 ; j< n ;j++ ){
            if(abs(arr[i]-arr[j])>max){
                max = abs(arr[i]-arr[j]) ; 
            }
        }
    }
    printf("%d",max);
}

Measured memory_bytes: 128
//
//  main.c
//  Ferris Wheel
//
//  Created by yuta on 2019/05/25.
//  Copyright © 2019 501Software. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
	int a,b;


	// スペース区切りの整数の入力
	scanf("%d %d",&a,&b);


	if (a >= 13)
		printf("%d\n",b);
	else if (a < 6)
		printf("0\n");
	else
		printf("%d\n",b/2);
	
	return 0;
}


Measured memory_bytes: 128
object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    def reduce(h: Array[Int]): Int = {
      var count = 0
      var previousWatered = false
      for { i <- h.indices } {
        if (h(i) != 0) {
          if (!previousWatered) count += 1
          h(i) -= 1
          previousWatered = true
        } else {
          previousWatered = false
        }
      }
      count
    }

    val N = sc.nextLine().toInt
    val h = readLineInts
    var count = 0
    while (true) {
      val next = reduce(h)
      if (next == 0) return println(count)
      count += next
    }
  }
}

Measured memory_bytes: 25876
import sys


def resolve():
    alphabets = dict([(chr(c), 0) for c in range(ord('a'), ord('z') + 1)])

    for line in sys.stdin:
        for c in list(line):
            if c.isalpha():
                alphabets[c.lower()] += 1

    for k, v in alphabets.items():
        print("{} : {}".format(k, v))


resolve()


Measured memory_bytes: 5576
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		if (n == 100) {
			System.out.println((long)(Math.pow(100, d)) * 101);
		}
		else {
			System.out.println((long)(Math.pow(100, d)) * n);
		}
	}

}


Measured memory_bytes: 21972
#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;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n;
    cin>>n;
    string s;
    cin>>s;
    int a = 0, b = 0;
    f(i, n){
        if(s[i] == 'R') a++;
        else b++;
    }
    cout<<(a > b ? "Yes" : "No");
    return 0;
}

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


int main() {
string A,B;
cin >> A >> B;
sort(A.begin(),A.end());

sort(B.begin(),B.end());
reverse(B.begin(),B.end());

if(A >= B) cout << "No" << endl;
else cout << "Yes" << endl;

return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var s = Console.ReadLine();
        int w = s.Split('B').Where(x => x != "").Count();
        int b = s.Split('W').Where(x => x != "").Count();
        Console.WriteLine(b + w - 1);
    }
}



Measured memory_bytes: 15072
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define vi vector <ll> v
#define vii vector<pair<ll,ll>>v
#define pb push_back
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define while_ int t;cin>>t;while(t--)
#define t32 32
using namespace std;

ll ways(int n, int A[])
{
    ll a=0,b=abs(A[1]-A[0]),c=0;
    f(i,2,n)
    {
        c=min( b+abs(A[i]-A[i-1]), a+abs(A[i]-A[i-2]) );
        a=b;
        b=c;
    }
    return b;
}

int main() {
    fastio
   
        int n; cin>>n;
        int A[n];
        f(i,0,n) cin>>A[i];
        cout<<ways(n,A);
    
    
}













Measured memory_bytes: 640
#include<cstdio>
using namespace std;
typedef long long LL;
const int maxn=1e6+2;
const int mod=998244353;
int n,k;
LL ans;
LL inv[maxn],s1[maxn],s2[maxn];
LL C(int n,int m){
	if (m<0) return 0;
	return s1[n]*s2[m]%mod*s2[n-m]%mod;
}
LL find(int r,int b){
	if (r<=b) return 0;
	if (r<n) return 0;
	return C(r+b,b)-C(r+b,b-(r-n+1));
}
void init(){
	inv[1]=1;
	for (int i=2;i<=maxn-2;i++) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
	s1[0]=s2[0]=1;
	for (int i=1;i<=maxn-2;i++){
		s1[i]=s1[i-1]*i%mod;
		s2[i]=s2[i-1]*inv[i]%mod;
	}
}
int main(){
	init();
	scanf("%d%d",&n,&k);
	for (int i=1;i<=k;i++) ans=(ans+find(i,k-i))%mod;
	if (k%2==0&&k/2>=n) ans=(ans+C(k-1,k/2)-C(k-1,n-2))%mod;
	ans=(ans%mod+mod)%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 23680
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    int s;
    cin >> s;

    ll dp[2002] = {0};
    dp[0] = 1;

    for(int i = 3; i <= 2000; i++){

        for(int j = 3; j < 2001; j++){

            if(i - j >= 0){
                dp[i] += dp[i - j];
                dp[i] %= MOD;
            }
        }
    }

    cout << dp[s];
}


Measured memory_bytes: 3660
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


vector<int> g[100005];
bool check[100005];
bool check2[100005];

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);


	int n, u, v;
	cin >> n >> u >> v;
	u--;
	v--;
	
	
	for (int i = 0; i < n - 1; i++) {
		//cout << "i= " << i << endl;
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		g[x].emplace_back(y);
		g[y].emplace_back(x);
	}
	//cout << "a" << endl;

	queue<int> que;
	que.push(u);

	vector<int> dist(100005, INF);
	dist[u] = 0;


	while (!que.empty()) {

		int now = que.front();
		que.pop();
		if (check[now] == 1)continue;
		check[now] = 1;

		for (int nxt : g[now]) {

			if (check[nxt] == 0) {

				if (dist[nxt] > dist[now] + 1) {
					dist[nxt] = dist[now] + 1;
					que.push(nxt);
				}
			}
		}
	}


	vector<int> dist2(100005, INF);
	dist2[v] = 0;
	que.push(v);

	while (!que.empty()) {

		int now = que.front();
		que.pop();
		if (check2[now] == 1)continue;
		check2[now] = 1;

		for (int nxt : g[now]) {

			if (check2[nxt] == 0) {

				if (dist2[nxt] > dist2[now] + 1) {
					dist2[nxt] = dist2[now] + 1;
					que.push(nxt);
				}
			}
		}
	}

	
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (dist[i] < dist2[i]) {

			//高橋君からの方が近い
			ans = max(ans, dist2[i] - 1);
		}

	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 6912
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i <= n; i++)

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	rep(i, a) {
		rep(j, b) {
			rep(k, c) {
				int sum = 500 * i + 100 * j + 50 * k;
				if (sum == x) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, raw_input().strip().split())
l = map(int, raw_input().strip().split())
ls = []
for x in l:
	ls.append(str(x))

def has_string(ns):
	r = True
	for x in ls:
		if x not in ns:
			pass
		else:
			r = False
	return r

while n < 100000:
	ns = str(n)
	if has_string(ns):
		print(ns)
		exit()
	else:
		n+=1

Measured memory_bytes: 2568
#include <iostream>
    #include <vector>
    using namespace std;
     
    int main() {
      int N, a[200000];
      cin >> N;
      for (int i=0; i<N; i++) {
        cin >> a[i];
      }
      int sum = 0, left = 0;
      long long ans = 0;
      for (int i=0; i<N; i++) {
        while (sum & a[i]) {
          ans += i - left;
          sum -= a[left];
          left++;
        }
       sum |= a[i];
      }
      while (left < N) ans += N - left++;
      cout << ans << endl;
      return 0;
    }

Measured memory_bytes: 1024
#

import sys
input=sys.stdin.readline

def main():
    X,Y,A,B,C=map(int,input().split())
    P=list(map(int,input().split()))
    Q=list(map(int,input().split()))
    R=list(map(int,input().split()))
    lis=[]
    for i in range(A):
        lis.append((P[i],0))
    for i in range(B):
        lis.append((Q[i],1))
    for i in range(C):
        lis.append((R[i],2))
        
    lis.sort(reverse=True)
    white=[]
    sumc=0
    xy=[X,Y]
    for i in range(len(lis)):
        if lis[i][1]==2:
            white.append(lis[i])
        elif xy[lis[i][1]]:
            xy[lis[i][1]]-=1
            sumc+=lis[i][0]
        if (sum(xy)<=len(white)):
            break
    for i in range(len(white)):
        sumc+=white[i][0]
    print(sumc)
            
    
if __name__=="__main__":
    main()


Measured memory_bytes: 126564
#include <stdio.h>

int main(void){
	int A, B, C, D;
	int ans;
	int i,j,k;

	scanf("%d", &D);
	A = D / 1000;
	B = (D - A * 1000) / 100;
	C = (D - A * 1000 - B * 100) / 10;
	D = D - A * 1000 - B * 100 - C * 10;

	ans = 0;
	for(i = 0; i < 2; i++) {
		for(j = 0; j < 2; j++) {
			for(k = 0; k < 2; k++) {	
				if(i == 0) {
					ans += A;
					ans += B;
				}
				else {
					ans += A;
					ans -= B;
				}
				if(j == 0) {
					ans += C;
				}
				else {
					ans -= C;
				}
				if(k == 0) {
					ans += D;
				}
				else {
					ans -= D;
				}
				if(ans == 7) {
					break;
				}
				else {
					ans = 0;
				}
			}
			if(ans == 7)
				break;
		}
		if(ans == 7)
			break;
	}

	printf("%d", A);
	if(i == 0) {
		putchar('+');
	}
	else {
		putchar('-');
	}
	printf("%d", B);
	if(j == 0) {
		putchar('+');
	}
	else {
		putchar('-');
	}
	printf("%d", C);
	if(k == 0) {
		putchar('+');
	}
	else {
		putchar('-');
	}
	printf("%d", D);
	printf("=7");

	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	char C()
	{
		char ch;
		while((ch=getchar())!='B'&&ch!='W');
		return ch;
	}
}
int s[4444][4444];
int main()
{
	int n=io::F(),k=io::F();
	for(register int i=1;i<=n;++i)
	{
		int x=io::F(),y=io::F();
		char c=io::C();
		x%=k+k,y%=k+k;
		if(c=='B')s[x][y]++,s[x+k][y]--,s[x][y+k]--,s[x+k][y+k]++,s[x+k][y+k]++,s[x+k][y+k+k]--,s[x+k+k][y+k]--,s[x+k+k][y+k+k]++;
			else s[x+k][y]++,s[x+k+k][y]--,s[x+k][y+k]--,s[x+k+k][y+k]++,s[x][y+k]++,s[x+k][y+k]--,s[x][y+k+k]--,s[x+k][y+k+k]++;
	}
	for(register int i=1;i<4*k;++i)
		for(register int j=0;j<4*k;++j)
			s[i][j]+=s[i-1][j];
	for(register int i=0;i<4*k;++i)
		for(register int j=1;j<4*k;++j)
			s[i][j]+=s[i][j-1];
	int ans=0;
	for(register int i=0;i<k+k;++i)
		for(register int j=0;j<k+k;++j)
			cmax(ans,s[i][j]+s[i][j+k+k]+s[i+k+k][j]+s[i+k+k][j+k+k]);
	printf("%d\n",ans); 
	return 0;
}




Measured memory_bytes: 69760
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '1') cout << '9';
        else cout << '1';
    }
    return 0;
}


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

#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vvi;
typedef vector<vi64> vvi64;
typedef double ld;

int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N;
    cin >> N;
    vi64 v(N);
    forn(i, N) cin >> v[i];

    sort(all(v));

    if (N == 2) {
        cout << v[1] - v[0] << endl;
        return 0;
    }

    if (N == 3) {
        cout << max(v[2] + v[1] - v[0] - v[0], v[2] + v[2] - v[1] - v[0]) << endl;
        return 0;
    }

    i64 ans = v[N - 1] - v[0];

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

        if (i != N / 2 or (N % 2) == 1 ) {
            ans += v[N - i] - v[i];
            //cout << " up  " << v[N - i] << " " << v[i] << endl;
        }
        if (i != N / 2 or (N % 2) == 0 ) {
            ans += v[N - i - 1] - v[i - 1];
            //cout << "down " << v[N - i - 1] << " " << v[i - 1] << endl;
        }

    }
    

    forn(i, N) v[i] = -v[i];
    sort(all(v));
    i64 ans2 = v[N - 1] - v[0];

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

        if (i != N / 2 or (N % 2) == 1 ) {
            ans2 += v[N - i] - v[i];
            //cout << " up  " << v[N - i] << " " << v[i] << endl;
        }
        if (i != N / 2 or (N % 2) == 0 ) {
            ans2 += v[N - i - 1] - v[i - 1];
            //cout << "down " << v[N - i - 1] << " " << v[i - 1] << endl;
        }

    }

    cout << max(ans, ans2) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int l,r,d;
  cin >> l >> r >> d;
  int ans;
  ans = r/d - (l-1)/d;
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits.h>
#include <cmath>
#include <map>
using namespace std;
using ll=long long;
const int INF=INT_MAX/3;
struct edge{
    int to,cap,rev;
};
vector<edge> G[210];
vector<bool> used(210);
void add_edge(int from,int to,int cap){
    G[from].emplace_back((edge){to,cap,(int)G[to].size()});
    G[to].emplace_back((edge){from,0,(int)G[from].size()-1});
}
int dfs(int v,int t,int f){
    if(v==t)return f;
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        if(!used[e.to]&&e.cap>0){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t){
    int flow=0;
    while(1){
        fill(used.begin(),used.end(),false);
        int f=dfs(s,t,INF);
        if(f==0)return flow;
        flow+=f;
    }
}
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> a(h,vector<char>(w));
    pair<int,int> s,t;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
            if(a[i][j]=='S'){
                add_edge(0,i+1,INF);
                add_edge(0,h+j+1,INF);
                s.first=i,s.second=j;
            }
            if(a[i][j]=='T'){
                add_edge(i+1,h+w+1,INF);
                add_edge(h+j+1,h+w+1,INF);
                t.first=i,t.second=j;
            }
            if(a[i][j]=='o'){
                add_edge(i+1,h+j+1,1);
                add_edge(h+j+1,i+1,1);
            }
        }
    }
    if(s.first==t.first||s.second==t.second){
        cout<<-1<<endl;
        return 0;
    }
    int ret=max_flow(0,h+w+1);
    if(ret==INF)ret=-1;
    cout<<ret<<endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef double db;
int a,b,c,Max;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	Max=max(max(a,b),c);
	if((3*Max-a-b-c)%2==0) printf("%d\n",(3*Max-a-b-c)/2);
	else printf("%d\n",(3*Max-a-b-c+3)/2);
	return 0;
}


Measured memory_bytes: 256
import time
t1=time.time()
a,b,c=map(int,input().split())
cnt=0
while a%2==0 and b%2==0 and c%2==0:
	a,b,c=b//2+c//2,a//2+c//2,a//2+b//2
	cnt+=1
	t2=time.time()
	if t2-t1>1.97:
		print(-1)
		exit()
print(cnt)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        System.out.println(-1);
    }

}

Measured memory_bytes: 50916
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
    int n,m;cin>>n>>m;
    vector<P>p;
    vector<P>q;
    rep(i,m){
        int l,r;cin>>l>>r;
        p.emplace_back(l,r);
        q.emplace_back(r,l);
    }
    sort(ALL(p),greater<P>());
    sort(ALL(q));
    if(q[0].first-p[0].first<0)cout<<0;
    else cout<<q[0].first-p[0].first+1;
}



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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct Edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main(){
    int n; ll ans = 0;
    cin >> n;
    vector<ll> l(n+1, 0), r(n+1, 0);
    rep(n) cin >> l[i] >> r[i];
    sort(rall(l)); sort(all(r));


    rep(n){
        if(l[i] - r[i] <= 0) break;
        ans += l[i] - r[i];
    }

    cout << 2*ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 2e5 + 5;

const int inf = (signed) (~0u >> 2);

typedef class SegTreeNode {
	public:
		int v;
		SegTreeNode *l, *r;
		
		SegTreeNode() : v(-inf), l(NULL), r(NULL) {	}

		void push_up() {
			v = max(l->v, r->v);
		}
} SegTreeNode;

SegTreeNode pool[N << 2];
SegTreeNode *_top = pool;

typedef class SegmentTree {
	public:
		int n;
		SegTreeNode* rt;

		void build(SegTreeNode*& p, int l, int r) {
			p = _top++;
			if (l == r) {
				return;
			}
			int mid = (l + r) >> 1;
			build(p->l, l, mid);
			build(p->r, mid + 1, r);
		}
		void build(int n) {
			this->n = n;
			build(rt, 1, n);
		}

		int query(SegTreeNode* p, int l, int r, int ql, int qr) {
			if (l == ql && r == qr) {
				return p->v;
			}
			int mid = (l + r) >> 1;
			if (qr <= mid) {
				return query(p->l, l, mid, ql, qr);
			} else if (ql > mid) {
				return query(p->r, mid + 1, r, ql, qr);
			}
			int a = query(p->l, l, mid, ql, mid);
			int b = query(p->r, mid + 1, r, mid + 1, qr);
			return max(a, b);
		}
		int query(int l, int r) {
			return query(rt, 1, n, l, r);
		}

		void modify(SegTreeNode* p, int l, int r, int idx, int v) {
			if (l == r) {
				p->v = v;
				return;
			}
			int mid = (l + r) >> 1;
			if (idx <= mid) {
				modify(p->l, l, mid, idx, v);
			} else {
				modify(p->r, mid + 1, r, idx, v);
			}
			p->push_up();
		}
		void modify(int idx, int v) {
			modify(rt, 1, n, idx, v);
		}
} SegmentTree;

int n;
int a[N];
int cnt[N];
int f[N][2];
char ans[N];
boolean isp[N];
SegmentTree st[2];

boolean check(int i, int mxX, int cntX, int mxY, int cntY) {
	// cntX + Q - k = cntY + k + m
	// 2k + m = cntX + Q - cntY
	int Q = cnt[n] - cnt[i];
	int dlt = cntX + Q - cntY;
	if (dlt >= 0 && st[dlt & 1].query(mxY + 1, n + 1) >= dlt)
		return true;
	dlt = cntY + Q - cntX;
	return dlt >= 0 && (st[dlt & 1].query(mxX + 1, n + 1) >= dlt);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		mx = max(mx, a[i]);
		isp[i] = (mx == a[i]);
		cnt[i] = cnt[i - 1] + isp[i];
	}
	st[0].build(n + 1);
	st[1].build(n + 1);
	f[n + 1][0] = 0;
	f[n + 1][1] = -inf;
	st[0].modify(n + 1, 0);
	for (int i = n; i; i--) {
		if (isp[i]) {
			f[i][0] = st[0].query(a[i], n + 1) + 2;
			f[i][1] = st[1].query(a[i], n + 1) + 2;
		} else {
			f[i][0] = st[1].query(a[i], n + 1) + 1;
			f[i][1] = st[0].query(a[i], n + 1) + 1;
		}
		st[0].modify(a[i], f[i][0]);
		st[1].modify(a[i], f[i][1]);
	}
//	for (int i = 1; i <= n; i++)
//		cerr << f[i][0] << " ";
//	cerr << '\n';
//	for (int i = 1; i <= n; i++)
//		cerr << f[i][1] << " ";
//	cerr << '\n';
	int cntX = 0, cntY = 0;
	int mxX = 0, mxY = 0;
	if (!check(0, 0, 0, 0, 0)) {
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		st[0].modify(a[i], -inf);
		st[1].modify(a[i], -inf);
		if (check(i, max(a[i], mxX), cntX + (a[i] > mxX), mxY, cntY)) {
			ans[i] = '0';
			cntX += (a[i] > mxX);
			mxX = max(a[i], mxX);
		} else {
			ans[i] = '1';
			cntY += (a[i] > mxY);
			mxY = max(a[i], mxY);
		}
	}
	puts(ans + 1);
	return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;

int dp[100005];

int add_self(int &a,int b)
{
    a+=b;
    if (a>=mod)
        a-=mod;
}

int sub_self(int &a,int b)
{
    a-=b;
    if (a<0)
        a+=mod;
}

int main()
{
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n,k;
    cin >> n >> k;

    dp[0]=1;
    for (int child=0;child<n;child++)
    {
        int x;
        cin >> x;
        vector <int> fake(k+1);

        for (int used=k;used>=0;used--)
        {
            int L=used+1;
            int R=used+min(x,k-used);

            if (L<=R)
            {
                add_self(fake[L],dp[used]);
                if (R+1<=k)
                    sub_self(fake[R+1],dp[used]);
            }
        }

        int pref=0;
        for (int i=0;i<=k;i++)
        {
            add_self(pref,fake[i]);
            add_self(dp[i],pref);
        }
    }

    cout << dp[k];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
int main () {
int a [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
int x , y ; cin >> x >> y ;
cout << ( a [ x ] == a [ y ] ? " Yes " : " No ") << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin >> A >> B>>C;
  A=A+B;
  D=A+1;
  if(B>=C)cout <<"delicious"<<endl;
  else if(A>=C)cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
}


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

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

	string S; cin >> S;
	string ans;

	if (S == "Sunny")
	{
		ans = "Cloudy";
	}
	else if (S == "Cloudy")
	{
		ans = "Rainy";
	}
	else if (S == "Rainy")
	{
		ans = "Sunny";
	}

	cout << ans << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;
  if (x < 1200)
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

vector<bool> prime(void){
  vector<bool> f(110000,1);
  f[0]=0;
  f[1]=0;
  REP2(i,2,110000/2) f[i*2]=0;
  for(int i=3;i<110000;i+=2){
    for(int j=2;i*j<110000;j++){
      f[i*j]=0;
    }
  }
  return f;
}

int main()
{
  int x;
  cin>>x;

  vector<bool> f;
  f=prime();
  REP2(i,x,110000){
    if(f[i]==1){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    string s;
    cin >> s;
    if(s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" ||
       s == "cba") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define speedhack ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fromfile freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout); 
#define mod int (1e9+7)
#define MAXN int (1e9)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;


ll n,k,z,npos;
ll loop;

int main() {
    speedhack;
    //fromfile;
    cin >> n >> k;
    k += 1;
    vector<ll> a;
    a.pb(0);
    for (int j = 0; j<n; j++){
        cin >> z;
        a.pb(z);
    }
    vector<ll> found(n+1, -1); // found[i] stores step that we had at the ith city
    vector<ll> route;
    route.pb(0);
    ll pos = 1;
    route.pb(pos);
    for (int i = 1; i<=n; i++){ // i corresponds to the step number
        if (k - i == 0){
            cout << pos;
            return 0;
        }
        else if (found[pos] == -1){ // if city is never visited
            found[pos] = i;
            pos = a[pos];
            route.pb(pos);
        }
        else{ // if city is visited before, then there's a loop
            loop = i - found[pos];
            npos = k - found[pos];
            npos %= loop;
            break;
        }
    }
    cout << route[found[pos] + npos]; 
    





    }

Measured memory_bytes: 9408
#include<bits/stdc++.h>
using namespace std;
main()
{
     long long int res=1,i,j=0,cur=1,ok,n,k,a=1,b=1;
     string s;
     vector<int>vect;
     cin>>n;
    cout<<n+n*n+n*n*n<<endl;
}


Measured memory_bytes: 3572