akhauriyash/Code-Regression huggingface dataset:
import sys

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def nCr(com_n, com_r):
    if com_n < com_r: return 0
    return fac[com_n] * ifac[com_r] % md * ifac[com_n - com_r] % md

# combinationの準備
# md>n_maxの条件
md = 10 ** 9 + 7
n_max = 2000005
fac = [1]
for i in range(1, n_max + 1): fac.append(fac[-1] * i % md)
ifac = [1] * (n_max + 1)
ifac[n_max] = pow(fac[n_max], md - 2, md)
for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % md

def main():
    k=II()
    s=SI()
    r=len(s)
    ans=0
    for i in range(k+1):
        ans=ans*26+pow(25,i,md)*nCr(i+r-1,r-1)%md
        ans%=md
    print(ans)

main()

Measured memory_bytes: 163424
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int id = -1;
    rep(i, 0, n - 1){
        if(a[i] + a[i + 1] >= l){
            id = i;
            break;
        }
    }
    if(id == -1) cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        rep(i, 0, id){
            cout << i + 1 << endl;
        }
        repb(i, n - 2, id){
            cout << i + 1 << endl;
        }
    }
}

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

using namespace std;
#define mod 1000000007
#define ll long long


int main(){
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++){
        if(i%3==0||i%5==0)
        continue;
        sum+=i;
    }
    cout<<sum;
     
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();

        int answer = 0;
        for (int i = 0; i < n; i++)
        {
            int x = sc.NextInt();
            answer += Math.Min(x * 2, (k - x) * 2);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#C

#デバッグ
debug=1
def pront(*n):
    if debug==1:
        print(n)
        
#10**9+7を底とした処理

base=10**9+7

def add(a,b):#a+b
    return (a+b)%base

def sub(a,b):#a-b
    return (a-b)%base

def multi(a,b):#a*b
    return (a*b)%base

def exp(a,b):#a**b
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

def div(a,b):#a/b
    return(multi(a,exp(b,base-2)))

#入力
N,M,Z=map(int,input().split())

A=[list(map(int,input().split())) for i in range(N)]

#処理
X=[0 for i in range(N)]
x=float('inf')
while True:
    Y=[0 for i in range(M)]
    z=0
    for i in range(N):
        if X[i]==1:
            z+=A[i][0]
            for j in range(M):
                Y[j]+=A[i][j+1]
    for j in range(M):
        if Y[j]<Z:
            break
        if  j==M-1:
            #print(z,X)
            if z<x:
                
                x=z
    for i in range(N):
        if X[-i-1]==0:
            X[-i-1]=1
            break
        else:
            X[-i-1]=0
    #print(X)
    if X==[0 for i in range(N)]:
        break
if x==float('inf'):
    print(-1)
else:
    print(x)

Measured memory_bytes: 9324
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, M;
string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> S >> T;
    int g = gcd(N, M);

    int ok = 1;
    rep(i, 0, g) if (S[N / g * i] != T[M / g * i]) ok = 0;

    if (ok) cout << (1LL * N * M / g) << endl;
    else cout << "-1" << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    {
        if(n<1200)
            printf("ABC\n");
    }
    {
        if(n>=1200 && n<2800)
            printf("ARC\n");
    }
    {
        if(n>=2800)
            printf("AGC\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

const int N = 200;
const int M = 10;

int main(void) {
  int a = 0;
  int b = 0;

  while (!std::cin.eof()) {
    std::cin >> a;
    std::cin >> b;

    if (std::cin.eof()) {
      break;
    }

    int c = a + b;

    int count = 1;

    while (c >= M) {
      c /= M;
      count++;

      if (c < M) {
	break;
      }
    }

    std::cout << count << std::endl;

    if (std::cin.eof()) {
      break;
    }
  }
   
  return 0;
}

Measured memory_bytes: 1160
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 


def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

def lcm(a, b):
  return a*b // gcd(a, b)

def div2cnt(a):
  cnt = 0
  while a%2 == 0:
    a //= 2
    cnt += 1
  return cnt

N, M = map(int, inp().split())
A = list(map(int, inp().split()))
# 2で割ったものに置き換え a -> a'
Ad = [a//2 for a in A]

# 各要素について、2で割り切れる回数が等しいかチェック
div2 = div2cnt(Ad[0])
for a in Ad:
  if div2cnt(a) != div2:
    print(0)
    exit()
    
# LCM
_lcm = Ad[0]
for a in Ad:
  _lcm = lcm(_lcm, a)
if _lcm > M:
  print(0)
  exit()
  
print((M//_lcm + 1) // 2)   # 切り上げ



Measured memory_bytes: 13024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define ALLA(a) a,a+a.size();
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;


struct Node{ int p, l, r;};

const int NIL = -1;

Node T[100005];
int D[100005];
int H[100005];
int deep = 0;

void print(int u){
  cout << "node " << u << ": parent = " << T[u].p  << ", sibling = ";
  if(T[u].p == NIL) cout << NIL;
  else{
    if(T[T[u].p].r == u) cout << T[T[u].p].l;
    else if(T[T[u].p].l == u) cout << T[T[u].p].r;
    else cout << NIL;
  }
  
  cout << ", degree = ";

  int degree = 0;
  if(T[u].r != NIL) degree ++;
  if(T[u].l != NIL) degree ++;

  cout << degree << ", depth = " << D[u] << ", height = " << H[u];
  
  cout << ", ";
  if(T[u].p == NIL)cout << "root";
  else if(T[u].l != NIL || T[u].r != NIL)cout << "internal node";
  else cout << "leaf";
  cout << endl;
}

int setHeight(int u){
  int right = 0;
  int left = 0;
  if(T[u].l != NIL) left = setHeight(T[u].l) + 1;
  if(T[u].r != NIL) right = setHeight(T[u].r) + 1;
  
  return H[u] = max(right, left);
}

void setDepth(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) setDepth(T[u].r, p + 1);
  if(T[u].l != NIL) setDepth(T[u].l, p + 1);
}

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

    //配列初期化
    REP(i,n) T[i].p = T[i].l = T[i].r = NIL;

    int id, l , r;
    REP(i,n){
      cin >> id >>  l >> r;
      if(l != NIL){
	T[id].l = l;
	T[T[id].l].p = id;
      }
      if(r != NIL){
	T[id].r = r;
	T[T[id].r].p = id;
      }
    }

    int ln;
    REP(i,n){
      //親を持っていない(最上位のノード)
      if(T[i].p == NIL) ln = i;
    }

    //深さを格納する配列Dに値を設定
    setDepth(ln , 0);
    //高さを格納する配列Hに値を設定
    setHeight(ln);
    //出力する
    REP(i,n)print(i);
   
  }
  return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>

// 線形探索
int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while ( A[i] != key ) i++;
  return i != n;
}

int main() {
  int i, n, A[10000+1], q, key, sum = 0;

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

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &key);
    if ( search(A, n, key) ) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int i=0; i < (n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
using namespace std;

int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

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

  int n,m;
  cin >> n >> m;

  priority_queue<int> pq;
  REP(i,n) {
    int a;
    cin >> a;
    pq.push(a);
  }
  REP(i,m) {
    int max_ = pq.top(); pq.pop();
    pq.push(max_/2);
  }

  int ans = 0;
  REP(i,n) {
    ans += pq.top(); pq.pop();
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

int n;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    if(n == 0) cout << 1 << endl;
    else if(n == 1) cout << 2 << endl;
    else if(n == 2) cout << 1 << endl;
    else cout << 0 << endl;
}



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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll p,q,r; ll n;
   cin>>n;
   ll arr[n];
   for(int i=0;i<n;i++){
       cin>>arr[i];
   }
   ll lsum=0; ll rsum=0;
   ll ans=INT_MAX;
   for(int i=0;i<n;i++){
       rsum=0;
       lsum+=arr[i];
       for(int j=i+1;j<n;j++){
           rsum+=arr[j];
       }
       ans=min(ans,abs(rsum-lsum));
   }
   cout<<ans<<endl;
   
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int Q,H,S,D,N;
  cin>>Q>>H>>S>>D>>N;
  cout<<(N/2)*min({Q*8,H*4,S*2,D})+(N%2)*min({Q*4,H*2,S})<<endl;
}

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

using namespace std;

int main()
{
   long long x,k,d,y,z;
   cin>>x>>k>>d;
   x=abs(x);
   if(x<=d)
   {
        if(k%2)
            cout<<abs(x-d);
        else
            cout<<x;
   }
   else
   {
        z=x/d;
        if(k<=z)
        {
            cout<<x-k*d;
        }
        else
        {
            x=x-z*d;
            k=k-z;
            if(k%2)
                cout<<abs(x-d);
            else
                cout<<x;
       }
   }
   
   return 0;
}

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

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) {
	return y ? GCD(y, x % y) : x;
}

long long LCM(long long x, long long y) {
	return x * y / GCD(x, y);
}

int A() {
	int n;

	scani(n);

	YesNo(7 == n % 10 || 7 == n / 10 % 10 || 7 == n / 100);


	return 0;
}

int B() {
	int n;

	scani(n);

	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 && i % 5) {
			ans += i;
		}
	}

	printll(ans);

	return 0;
}

int Main() {
	int k;
	int ans = 0;

	scani(k);

	int a = 1, b = 1, c = 1;
	for (a = 1; a <= k; a++) {
		for (b = 1; b <= k; b++) {
			for (c = 1; c <= k; c++) {
				//so
				if (1 == a || 1 == b || 1 == c ||
					(0 == a % b &&
						0 == a % c &&
						0 == b % a &&
						0 == b % c &&
						0 == c % a &&
						0 == c % b))
				{
					ans += 1;
					continue;
				}
				int tmp = GCD(a, b);
				ans += GCD(tmp, c);
			}
		}
	}

	printi(ans);

	return 0;
}

int D() {
	int n;

	string s;
	scani(n);
	cin >> s;
	int r, g, b;
	r = g = b = 0;
	for (auto x : s) {
		switch (x) {
		case 'R':
			r++;
			break;
		case 'G':
			g++;
			break;
		default:
			b++;
			break;
		}
	}

	ll ans = (ll)r * g * b;
	ll sub = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) continue;
			int k = j * 2 - i;
			if (n <= k || s[k] == s[i] || s[k] == s[j]) continue;
				sub++;
		}
	}

	ans -= sub;

	printll(ans);

	return 0;
}

int main()
{
	//Main();
	D();
	return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int H, W; cin >> H >> W;
	vector<string> S(H);
	REP(i,H) cin >> S[i];

	vector<int> dx{1,1,0,-1,-1,-1,0,1};
	vector<int> dy{0,1,1,1,0,-1,-1,-1};

	REP(i,H){
		REP(j,W){
			int cnt = 0;
			REP(k,8){
				int y = j + dy[k];
				int x = i + dx[k];
				if(x >= 0 and x < H and y >= 0 and y < W and S[x][y] == '#') cnt++;
			}
			if(S[i][j] == '.') S[i][j] = '0' + cnt;
		}
	}

	REP(i,H) cout << S[i] << endl;


	return 0;

}


Measured memory_bytes: 256
import java.util.*;

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

        if (a >= 3200) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }
        

    }
}


Measured memory_bytes: 22868
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}


int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> v;
	for(int i = 0 ; i < n ; i++){
		int t;
		cin >> t;
		v.push_back(t);
	}
	srand(time(NULL));
	//random_shuffle(v.begin(),v.end());
	//for(int i = 0 ; i < v.size() ; i++)
	//	cout << v[i] << " ";
	sort(v.rbegin(),v.rend());
	long long D[4] = {};
	long long ans = 0;
	for(int i = 0 ; i < v.size() ; i++) {
		ans += max(0 , v[i] - i / 4 );
	}
	cout << ans+1 << endl;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
ll N;
ll A[100010];
ll cnt[62];
ll solve[100010][62];
ll res[62];
ll sort(ll size){
    ll ne = 0;
    for(ll i = size - 1; i >= 0; i--){
        ll id = -1;
        for(ll j = ne; j < N; j++){
            if(solve[j][i]) id = j;
        }
        if(id == -1) continue;
        for(ll j = 0; j < size; j++){
            ll a = solve[id][j];
            solve[id][j] = solve[ne][j];
            solve[ne][j] = a;
        }
        for(ll j = 0; j < N; j++){
            if(j == ne) continue;
            if(solve[j][i] == 0) continue;
            for(ll k = 0; k < size; k++){
                solve[j][k] ^= solve[ne][k];
            }
        }
        ne++;
    }
   
    ll s = 0;
    for(ll i = size - 1; i >= 0; i--){
        if(solve[s][i]){
            for(ll j = 0; j < size; j++){
                res[j] ^= solve[s][j];
            }
            s++;
        }
    }
    ll ret = 0;
    for(ll i = 0; i < size; i++){
        if(res[i]) ret += 1LL<<i;
    }
   return ret; 
}

int main(){
    scanf("%lld", &N);
    for(ll i = 0; i < N; i++) scanf("%lld", &A[i]);
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < 62; j++){
            if((A[i]>>j)&1) cnt[j]++;
        }
    }
    
    ll size = 0;
    for(ll i = 0; i < 62; i++){
        if(cnt[i] % 2 == 0){
            for(ll j = 0; j < N; j++){
                if((A[j]>>i)&1) solve[j][size] = 1;
            }
            size++;
        }
    }
    ll res = sort(size);
    size = 0;
    ll ans = 0;
    for(ll i = 0; i < 62; i++){
        if(cnt[i] % 2 == 0){
            if((res>>size) & 1){
                ans += 1LL<<(i+1);
            }
            size++;
        }else{
            ans += 1LL<<i;
        }
    }
    printf("%lld", ans);
}

Measured memory_bytes: 49408
#include<stdio.h>
#include<stdlib.h>
#define M 2000001
#define V 10000

int main(){
	unsigned short *a, *b;

	int c[V+1];
	int num,i,j;

	scanf("%d",&num);

	a=malloc(sizeof(short)*num+1);

	b=malloc(sizeof(short)*num+1);



	for(i=0;i<V+1;i++){
		c[i]=0;
	}

	for(i=0;i<num;i++){
		scanf("%hu",&a[i+1]);
		c[a[i+1]]=c[a[i+1]]+1;
	}

	for(i=1;i<V+1;i++){
		c[i]=c[i]+c[i-1];
	}

	for(j=1;j<num+1;j++){
		b[c[a[j]]]=a[j];
		c[a[j]]=c[a[j]]-1;
	}


	for(i=1;i<num+1;i++){
		if(i>1)
			printf(" ");

		printf("%d",b[i]);
	}

	printf("\n");

	return 0;
}


Measured memory_bytes: 9636
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

void solve() {
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll a, b;
        cin >> a >> b;
        if (a * b % 2 == 0) cout << "Even" << endl;
        else cout << "Odd" << endl;

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int s;
double  x,y;
double a1,a2;
int ans=0;
int solve();
int solve(){
   for(int i=1;i<s;i++) {
        a1=i;
        a2=s-i;
        for(int j=0;j<s;j++){
            if(i==int((100+x)*a1/100)){
            //cout<<" aa";
                for(int k=0;k<s-i;k++){
                    if(s-i==int((100+x)*a2/100)){
                        //cout<<i<<" "<<a1<<" "<<a2<<" "<<int((100+y)*a1/100)+int((100+y)*a2/100)<<endl;//
                        //if(ans<(100+y)/100*a1+(100+y)/100*a2)cout<<"  a"<<endl;
                        ans=max(ans,int((100+y)*a1/100)+int((100+y)*a2/100));
                    }
                    a2--;
                }
            }
            a1--;
        }
   }
   return ans;
}
int main()
{
    while(1){
        ans=0;
        cin>>x>>y>>s;
        if(x==0&&y==0&&s==0)return 0;
        //cout<<x<<y<<s<<endl;
        solve();
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b; cin >> a >> b;
    if(b < a) a--;

    cout << a << endl;

    return 0;
}


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

int main()
{
	while( 1 ) {
		int x, y;
		cin >> x >> y;
		if( x == 0 && y == 0 ) {
			break;
		}
		if( x > y ) {
			swap( x, y );
		}
		cout << x << " " << y << endl;
	}
}



Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
int N;
int nmax = 100;
vector<int> t(nmax);
vector<int> v(nmax);
vector<int> sum(nmax+1,0);

double solve(int ts, int tg, int vmin){
    int vm = 100;
    double ret;
    int is,ig;
    for(int i=1;i<=N;i++){
        if(ts>=sum[i-1]&&ts<sum[i]) is = i-1;
        if(tg>sum[i-1]&&tg<=sum[i]) ig = i-1;
    }
    //////
    //cout << ts <<" " << tg << " " << is << " "<<ig <<endl;
    //// 
    for(int i=is;i<=ig;i++) if(v[i]>vmin)vm = min(vm,v[i]);
    if(tg-ts<=(vm-vmin)*2) {
        ret = (double)((tg-ts)*(tg-ts))/(double)4.0;
    }else{
        ret = (double)((tg-ts)*(vm-vmin)-(vm-vmin)*(vm-vmin));
        ts += (vm-vmin);
        tg -= (vm-vmin);
        for(int i=1;i<=N;i++){
            if(ts>=sum[i-1]&&ts<sum[i]) is = i-1;
            if(tg>sum[i-1]&&tg<=sum[i]) ig = i-1;
        }
        bool f = false;
        int ts2,tg2;
        ///////ここの処理をがんばる
        for(int i=is;i<=ig;i++){
            if(f==false){
                if(v[i]>vm){
                    f  = true;
                    ts2 = max(ts,sum[i]);
                }
            }
            if(f== true){
                if(v[i]==vm){
                    f = false;
                    tg2 = min(tg,sum[i]);
                    ret+=solve(ts2,tg2,vm);
                }else if(i==ig){
                    f=false;
                    tg2 = tg;
                    ret+=solve(ts2,tg2,vm);
                }
            }
        }
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    sum[0]=0;
    REP(i,N) {
        cin >> t[i];
        sum[i+1] = sum[i]+t[i];
    }
    REP(i,N) cin >> v[i];
    double ans = 0.0;
    ans = solve(0,sum[N],0);
    cout << fixed << setprecision(3) << ans << endl;
    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main(){
  int N;
  std::cin>>N;
  std::vector<int> a;
  std::vector<int> h;
 
  int dummy;
  for(int i = 0; i < N;i++ ){
    std::cin>>dummy;
    h.push_back(dummy);
  }

  int Ryokan_Ocean=1;
  int k;
  int points;
  for(int i=1;i<N;i++){
    k = 0;
    points = 0;
    while(k<i){
      if(h[k]<=h[i]) points++;
      k++;
    }
    if(points == i) Ryokan_Ocean++;
  }

  std::cout<<Ryokan_Ocean<<std::endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStrings(N int) []string {
	ret := make([]string, N)
	for i := 0; i < N; i++ {
		ret[i] = getString()
	}
	return ret
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = 1001001001001

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	r := make(map[string]int)
	b := make(map[string]int)
	m := make(map[string]int)
	for i := 0; i < N; i++ {
		s := getString()
		b[s]++
		m[s]++
	}
	M := getInt()
	for i := 0; i < M; i++ {
		s := getString()
		r[s]++
		m[s]++
	}
	ans := 0
	for s := range m {
		ans = max(ans, b[s]-r[s])
	}
	out(ans)
}


Measured memory_bytes: 1776
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <unordered_set>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()

int main()
{
	int n;
	vector<int> dp(35);
	dp[0] = 1;
	REP(i, 30)REP(j, 3)dp[i + 1 + j] += dp[i];
	while (cin >> n && n)
	{
		cout << (dp[n] / 10 / 365 + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int n_digit(long long x) {
	if (x == 0) {
		return 1;
	}
	int ret = 0;
	while (x > 0) {
		ret++;
		x /= 10;
	}
	return ret;
}

int n_digit2(long long x) {
	return to_string(x).size();
}

int f(long long a, long long b) {
	return max(n_digit2(a), n_digit2(b));
}

int main() {
	long long n;
	cin >> n;

	int x = sqrt(n);
	while (x > 0) {
		if (n % x == 0) {
			break;
		}
		x--;
	}

	cout << f(n / x, x) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.nio.file.*;
import java.nio.charset.*;
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        Integer[] arr = {a, a - 1, b, b - 1};
        Arrays.sort(arr, Comparator.reverseOrder());
        System.out.println(arr[0]+arr[1]);
    }
    }



Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,sz[2],ans,mn,mx;
char s[200001];
int main(){
	scanf("%d%d",&n,&m);
	ans=n;
	scanf("%s",s+1);
	for(i=1;i<=n;i++){
		if(i==1||s[i]!=s[i-1])sz[s[i]=='R']++,ans--;
	}
	mn=min(sz[0],sz[1]);
	mx=max(sz[0],sz[1]);
	if(mx>mn){
		ans+=min(m,mn)*2;
	}
	 else{
	 	ans+=min(m,mn-1)*2;
	 	m-=min(m,mn-1);
	 	if(m)ans++;
	 }
	printf("%d",ans);
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args){
	int N,K,X,Y;

	Scanner sc = new Scanner(System.in);
	N = sc.nextInt();
	K = sc.nextInt();
	X = sc.nextInt();
	Y = sc.nextInt();

	int sum = 0;

	if(N>K){
	    sum =K*X +(N -K)*Y;
	}else{
	    sum = N*X;
	}

	System.out.println(sum);
    }
}


Measured memory_bytes: 10060
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<ll> dqll;

#define MOD 1000000007

int main() {
  ll N;
  cin >> N;

  vll lst(N);

  for (int i = 0; i < N; i++) {
    cin >> lst[i];
  }

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

  ll a = lst.back();
  lst.pop_back();
  double tgt = ((double)a)/2;
  ll b = lst.front();
  for (int i = 0; i < N; i++) {
    if (abs(lst[i] - tgt) < abs(b - tgt)) b = lst[i];
  }

  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m,s,g;
vector<pair<int,string> >edge[45];
string dp[45];
struct S{
	int v; string s;
	bool operator <(const S &a)const{
		return s > a.s;
	}
	S(int a,string b){
		v = a; s = b;
	}
};
int a[3005],b[3005]; string c[3005];
int main(){
	while(1){
		scanf("%d%d%d%d",&n,&m,&s,&g);
		if(n==0) return 0;
		for(int i=0;i<n;i++){
			edge[i].clear();
			dp[i] = "1";
		}
		for(int i=0;i<m;i++){
			cin >> a[i] >> b[i] >> c[i];
			edge[b[i]].pb(mp(a[i],c[i]));
		}
		
		priority_queue<S>que;
		que.push(S(g,"")); dp[g] = "";
		while(!que.empty()){
			S t = que.top(); que.pop();
			if(dp[t.v] != "1" && dp[t.v] < t.s) continue;
			if(t.s.size() > 500) continue;
			for(int i=0;i<edge[t.v].size();i++){
				string nex = edge[t.v][i].sc;
				nex += t.s;
				if(dp[edge[t.v][i].fi] == "1" || dp[edge[t.v][i].fi] > nex){
					dp[edge[t.v][i].fi] = nex;
					que.push(S(edge[t.v][i].fi,nex));
				}
			}
		}
		if(dp[s].size() >= 250 || dp[s] == "1") puts("NO");
		else cout << dp[s] << endl;
	}
}

Measured memory_bytes: 5840
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N; cin >> N;
  map<ll, ll> mp;
  rep(i, N) {
    ll tmp; cin >> tmp;
    if(mp.find(tmp) != mp.end()) mp[tmp]++;
    else mp[tmp] = 1;
  }
  ll ans = 0;
  for(auto i:mp) {
    if(i.first < i.second) {
      ans += i.second-i.first;
    } else if(i.first > i.second) {
      ans += i.second;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	if(s=="ABC") cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    string s1, s2;
    cin >> s1 >> s2;
    int DP[1001][1001];
    int L1 = s1.size(), L2 = s2.size();
    
    for (int l1 = 0; l1 <= L1; ++l1) {
        DP[l1][0] = l1;
    }
    for (int l2 = 0; l2 <= L2; ++l2) {
        DP[0][l2] = l2;
    }
    for (int l1 = 1; l1 <= L1; ++l1) {
        for (int l2 = 1; l2 <= L2; ++l2) {
            DP[l1][l2] = min(DP[l1-1][l2], DP[l1][l2-1]) + 1;
            if (s1[l1-1] == s2[l2-1]) {
                DP[l1][l2] = min(DP[l1-1][l2-1], DP[l1][l2]);
            } else {
                DP[l1][l2] = min(DP[l1][l2], DP[l1-1][l2-1] + 1);
            }
        }
    }
    cout << DP[L1][L2] << endl;

    return 0;
}



Measured memory_bytes: 7140
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	long x;
	scanf("%d%ld",&n,&x);
	long arr[n];
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%ld",&arr[i]);
	}
	sort(arr,arr+n);
	long sum = 0;
	int count = 0;
	for(i=0;i<n;i++)
	{
		sum= sum + arr[i] ;
		if(sum>x)
		{
			break;
		}
		if(sum == x)
		{
			count++;
			break;
			
		}
		if(i==(n-1))
		{
			break;
		}
		count++;
	}
	printf("%d\n",count);
	
	return 0;
	
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] tokuten;
        String line;
        while (!(line = br.readLine()).equals("0")) {
            int n = Integer.parseInt(line);
            tokuten = br.readLine().split(" ");
 
            double ave = 0;
            for (int i = 0; i < n; i++) {
                ave += Integer.parseInt(tokuten[i]);
            }
            ave = ave / n;
 
            double sd = 0;
            for (int i = 0; i < n; i++) {
                sd += (Math.pow(Integer.parseInt(tokuten[i]) - ave, 2.0)) / n;
            }
 
            sd = Math.sqrt(sd);
            System.out.println(sd);
        }
    }
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 5;
int n;

int main() {
	scanf("%d", &n);

	multiset<ii> by_l, by_r;
	fori(i, 0, n) {
		int l, r;
		scanf("%d %d", &l, &r);
		by_l.emplace(-l, r);
		by_r.emplace(r, l);
	}

	ll ans = -(1LL << 60);
	fori(i, 0, 2) {
		multiset<ii> s[2];
		s[i] = by_l;
		s[!i] = by_r;

		int pos = 0;
		ll total = 0;
		fori(j, 0, n) {
			ii cur = *s[j & 1].begin();
			ii ocur;
			int l, r;
			if(i == (j & 1)) {
				l = -cur.first;
				r = cur.second;
				ocur = ii(r, l);
			}
			else {
				l = cur.second;
				r = cur.first;
				ocur = ii(-l, r);
			}

			if(pos < l) {
				total += l - pos;
				pos = l;
			}
			else if(pos > r) {
				total += pos - r;
				pos = r;
			}

			assert(s[j & 1].count(cur));
			assert(s[!(j & 1)].count(ocur));

			s[j & 1].erase(s[j & 1].find(cur));
			s[!(j & 1)].erase(s[!(j & 1)].find(ocur));
		}

		total += abs(pos);
		ans = max(ans, total);
	}

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

	return 0;
}


Measured memory_bytes: 18944
#include<stdio.h>
#define N 10000
#define NIL -1

struct Node {int p,l,r;};
struct Node T[N];
int n;

void preparse(int u){
  if(u==NIL)return;
  printf(" %d",u);
  preparse(T[u].l);
  preparse(T[u].r);
}

void inparse(int u){
  if(u==NIL)return;
  inparse(T[u].l);
  printf(" %d",u);
  inparse(T[u].r);
}

void postparse(int u){
  if(u==NIL)return;
  postparse(T[u].l);
  postparse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l != NIL)T[l].p=v;
     if(r != NIL)T[r].p=v;
  }

  for(i=0;i<n;i++)if(T[i].p==NIL)root=i;

  printf("Preorder\n");
  preparse(root);
  printf("\n");
  printf("Inorder\n");
  inparse(root);
  printf("\n");
  printf("Postorder\n");
  postparse(root);
  printf("\n");
  
  return 0;
}



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

using namespace std;


long long n, dp[100002][3], v[3];

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[0] >> v[1] >> v[2];
    for (int j = 0; j < 3; j++) {
      int a, b;
      if (j == 0)
        a = 1, b = 2;
      if (j == 1)
        a = 0, b = 2;
      if (j == 2)
        a = 0, b = 1;
      dp[i][j] = v[j] + max(dp[i - 1][a], dp[i - 1][b]);
    }
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
  return 0;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) cin >> P.at(i);
    int k = 0;
    for(int i = 0; i < N; i++){
        if(P.at(i) != i + 1) k++;
    }
    if(k <= 2) puts("YES");
    else puts("NO");
}

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

int64 n, m;
vector<int64> a;
vector<int64> idx;
int64 sum;

bool f(int mid){
	sum = 0;
	for(int i = 0; i < n; i++){
		idx[i] = lower_bound(a.begin(), a.end(), mid - a[i]) - a.begin();
		sum += n - idx[i];
	}
	return sum >= m;
}

int main(){
	cin >> n >> m;
	a.resize(n);
	idx.resize(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int64 ans = 0;
	int64 ok = 2, ng = 1e6;
	while(ng - ok > 1){
		int64 mid = (ng + ok) / 2;
		if(f(mid)) ok = mid;
		else ng = mid;
	}
	f(ok);
	for(int i = 0; i < n; i++){
		ans += (n - idx[i]) * a[i] * 2;
	}
	ans -= (sum - m) * ok;
	cout << ans << endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front

using namespace std;	
typedef long long int lli;
lli n,k,m,t,a,b,l,r,temp1,temp2,s,x,y,temp,q,d,mod=1e9+7,w,p,c;
string one,two;


lli from(lli a)
{
	if(one.length()-a<two.length())
	{
		return 1e9;
	}
	
	lli cnt=0;
	lli ptr=0;
	for(int i=a;i<a+two.length();i++)
	{
		if(one[i]==two[ptr])
		{
			cnt++;
			//ptr++;
		}
		ptr++;
	}
	
	return two.length()-cnt;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	
  	cin>>one>>two;
  	lli mn=1e18;
  	
  	for(int i=0;i<one.length();i++)
  	{
  		mn=min(mn,from(i));
  	}
  	
  	cout<<mn<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int M=100005;
int n,m;
struct node{
	int yc,val;
}A[M];
bool comp(node a,node b){
	return a.val>b.val;
}
bool mark[M];
set<int>s;
set<int>::iterator it;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&A[i].yc,&A[i].val);
	sort(A+1,A+n+1,comp);
	int ans=0;
	for(int i=0;i<=m;i++)s.insert(-i);
	for(int i=1;i<=n;i++){
		int t=m-A[i].yc;
		if(t<0)continue;
		it=s.lower_bound(-t);
		if(it==s.end())continue;
		int k=-(*it);
		mark[k]=1;
		s.erase(-k);
		ans+=A[i].val;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    map<int,int> A;
    rep(i,N) {
        int n; cin >> n;
        A[n]++;
    }
    bool success = false;
    if (A.size() == 1 && A[0] == N) success = true;
    else if (N % 3 == 0) {
        if (A.size() == 2 && A[0] == N / 3) success = true;
        else if (A.size() == 3) {
            vector<int> keys;
            for (auto [k,v] : A) {
                keys.push_back(k);
                if (v != N/3) goto END;
            }
            if ((keys[0] ^ keys[1] ^ keys[2]) == 0) success = true;
        }
    }
END:
    if (success) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 7196
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, a);
    IN(ll, b);
    ll ans = a - (b < a);
    OUT(ans);
}

Measured memory_bytes: 3576
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nab = Input.ar;
        var hp = Enumerable.Repeat(0, nab[0]).Select(v => Input.numL).ToArray();
        var left = 0L;
        var right = (long)int.MaxValue;
        while (right - left > 1)
        {
            var mid = (right + left) / 2;
            var ct = 0L;
            for (var i = 0; i < nab[0]; i++)
                ct += Max(0, (hp[i] - mid * nab[2] + nab[1] - nab[2] - 1) / (nab[1] - nab[2]));
            if (ct > mid) left = mid;
            else right = mid;
        }
        WriteLine(right);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 17884