akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

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

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            int state = 0;
            int n = 0;
            for (int i = 0; i < line.length(); i++) {
                char ch = line.charAt(i);
                if (state == 0) {
                    if (ch == '@') {
                        state = 1;
                    } else {
                        out.print(ch);
                    }
                } else if (state == 1) {
                    if (ch >= '0' && ch <= '9') {
                        n = ch - '0';
                        state = 2;
                    } else {
                        out.print("@" + ch);
                        state = 0;
                    }
                } else if (state == 2) {
                    for (int j = 0; j < n; j++) {
                        out.print(ch);
                    }
                    state = 0;
                }
            }
            if (state == 1) {
                out.print("@");
            } else if (state == 2) {
                out.print("@" + n);
            }
            out.println();
        }
    }
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    string S;
    cin >> S;

    int N = S.length();
    vector<vector<ll>> dp(N + 1, vector<ll>(3));
    ll cnt = 1;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'A' || S[i] == '?')
            dp[i + 1][0] += cnt;
        if (S[i] == 'B' || S[i] == '?')
            dp[i + 1][1] += dp[i][0];
        if (S[i] == 'C' || S[i] == '?')
            dp[i + 1][2] += dp[i][1];
        for (int j = 0; j < 3; ++j) {
            if (S[i] == '?') {
                dp[i + 1][j] += dp[i][j] * 3;
            } else
                dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= MOD;
        }
        if (S[i] == '?')
            (cnt *= 3) %= MOD;
    }

    cout << dp[N][2] << endl;

    return 0;
}


Measured memory_bytes: 8724
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  char z; cin >> z;
  cout << char(z + 1) << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.start();

	}

	private void start() {
		int arrayLength = 3;
		Scanner scanner = new Scanner(System.in);
		int[] num = new int[arrayLength];
		for (int i = 0; i < arrayLength; ++i) {
			num[i] = scanner.nextInt();
		}
		Arrays.sort(num);
		for (int i = 0; i < arrayLength; ++i) {
			System.out.print(num[i]);
			if (i < arrayLength - 1){
				System.out.print(" ");
				}

		}
		System.out.println();
	}
}

Measured memory_bytes: 17228
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int number = 110000;
		int[] data = new int[number + 1];
		int[] result = new int[number + 1];

		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		//手順1
		int m = 2;
		//手順2
		int n = 0;
		//手順3
		Arrays.fill(data, 1);
		//手順4
		Arrays.fill(result, 0);
		//手順5 0と1は最初から除外する
		data[0] = data[1] = 0;

		do {
			//素数の倍数をリストから削除する
			for(int i = 2 * m; i < number + 1; i += m) {
				data[i] = 0;
			}
			//結果を格納
			result[n] = m;
			n++;
			//次の素数候補を見つける
			do {
				m++;
			}while(data[m] == 0 && m < number);
		}while(m < number);

		//結果を出力
		for(int i = 0; i < result.length; i++) {
			if(result[i] >= X) {
				System.out.println(result[i]);
				break;
			}
		}
	}
}

Measured memory_bytes: 25556
#include<iostream>
#include<string>

using namespace std;

int main(){
    int h, w, i, j, d, count = 0, fcount = 0, wcount = 0;
    cin >> h >> w;
    string s[51];
    for (i = 0; i < h; ++i){
        cin >> s[i];
    }
    int x[5] = {1, 0, -1, 0};
    int y[5] = {0, -1, 0, 1};
    for (i = 0; i < h; ++i){
        for (j = 0; j < w; ++j){
            for (d = 0; d < 4; ++d){
                int ni = i + x[d];
                int nj = j + y[d];
                if(ni < 0 or nj < 0 or h <= ni or w <= nj){
                    continue;
                }
                if(s[ni][nj] == '#'){
                    count += 1;
                }
            }
                if (s[i][j] == '#' && 0 < count){
                    fcount += 1;
                }
                if(s[i][j] == '#'){
                    wcount += 1;
                }
                count = 0;
        }
    }
    if(fcount == wcount){
        cout << "Yes" << endl;
    }
    else{
        //printf("%d\n", count);
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
bool check(string t)
{
	string r=t;
	reverse(r.begin(),r.end());
	return t==r;		
}
int main()
{
	cin>>s;
	int n=s.size();
	string s1=s.substr(0,n/2);
	string s2=s.substr(n/2+1,n/2);
	if (check(s)&&check(s1)&&check(s2))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

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

const int inf = 1'000'000'000;

int main() {
  int x;
  cin >> x;
  int a = x / 500 * 1000;
  int b = x % 500 / 5 * 5;
  cout << a + b << endl;
}


Measured memory_bytes: 3504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Lesson9A １つの単語 W と文章 T が与えられます。 T の中にある W の数を出力するプログラム 文章 T
 * に含まれるスペースまたは改行で区切られた 文字列を単語 Ti とします。すべての Ti において単語 W
 * と同じになるものを数えて下さい。なお、大文字と小文字は区別しません。
 *
 * @author Internship
 *
 */
public class Main{

	/**
	 * プログラムのエントリポイント
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		// 答えをカウント
		int intAnwer = 0;

		// 1行目読み込む
		try {
			BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));

			String strLine = insBR.readLine();

			// 大文字は小文字にしておく
			strLine = strLine.toLowerCase();

			// char型に分解
			char[] chaAryLine1 = strLine.toCharArray();

			// ２行目以降を読み込む
			while (true) {
				strLine = insBR.readLine();

				// 終了条件
				if (strLine.equals("END_OF_TEXT")) {
					break;
				}

				// 大文字は小文字にしておく
				strLine = strLine.toLowerCase();

				// char型に分解
				char[] chaAryLineAll = strLine.toCharArray();

				// 何文字一緒か
				int intCount = 0;

				// 終了条件
				int intlength = chaAryLineAll.length - chaAryLine1.length + 1;

				//ロジック
				for (int i = 0; i < intlength; i++) {

					char a = chaAryLine1[0];
					char b = chaAryLineAll[i];

					if (a == b) {
						for (int j = 1; j < chaAryLine1.length; j++) {
							a = chaAryLine1[j];
							b = chaAryLineAll[i + j];

							if (a == b) {
								intCount++;

								// カウントがMAXなら
								if (intCount == chaAryLine1.length - 1) {

									//最初の文字が配列0番目で文字列の次がスペースが来るパターン
									if(i == 0 && i + j + 1 != chaAryLineAll.length) {
										if(chaAryLineAll[i + j + 1] == ' ') {
											intAnwer++;
										}

									//文字列の前がスペースで文字列の次が配列からオーバーするパターン
									}else if(0 < i && i + j + 1 == chaAryLineAll.length) {
										if(chaAryLineAll[i -1] == ' ') {
											intAnwer++;
										}
									//文字列の前と後ろの文字がスペースのパターン
									}else if(0 < i && i + j + 1 < chaAryLineAll.length) {
										if(chaAryLineAll[i -1] == ' ') {
											if(chaAryLineAll[i + j + 1] == ' ') {
												intAnwer++;
											}
										}
									//最初の文字が配列0番目で文字列の次が配列からオーバーするパターン
									}else if(i == 0 && i + j + 1 == chaAryLineAll.length) {
										intAnwer++;
									}

								}
							}
						}
					}
					
					//1列目が文字１つの時
					if(chaAryLine1.length == 1) {
						if(a == b) {
							//最初の文字が配列0番目で文字列の次がスペースが来るパターン
							if(i == 0 && i + 1 != chaAryLineAll.length) {
								if(chaAryLineAll[i + 1] == ' ') {
									intAnwer++;
								}

							//文字列の前がスペースで文字列の次が配列からオーバーするパターン
							}else if(0 < i && i + 1 == chaAryLineAll.length) {
								if(chaAryLineAll[i -1] == ' ') {
									intAnwer++;
								}
							//文字列の前と後ろの文字がスペースのパターン
							}else if(0 < i && i + 1 < chaAryLineAll.length) {
								if(chaAryLineAll[i -1] == ' ') {
									if(chaAryLineAll[i + 1] == ' ') {
										intAnwer++;
									}
								}
							//最初の文字が配列0番目で文字列の次が配列からオーバーするパターン
							}else if(i == 0 && i + 1 == chaAryLineAll.length) {
								intAnwer++;
							}
						}
						
					}
					
					// 初期化
					intCount = 0;
				}
			}

			// 出力
			System.out.println(intAnwer);

		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16868
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	int p[11];
	int max=0;
	int sum = 0;
	int pay = 0;

	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		if (max < p[i]) max = p[i];
		sum += p[i];
	}

	pay = sum - (max / 2);

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

	return 0;
}



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

int main(void){
    
    int n, m; cin >> n >> m;
    long long dp[1010][1010];
    for(int i = 0; i <= m; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = INF; 
        }
    }
    int d[1010];
    for(int j = 1; j <= n; j++){
        cin >> d[j];
    }

    int c[1010];
    for(int i = 1; i <= m; i++){
        cin >> c[i];
    }

    for(int i = 0; i <= m; i++){
        dp[i][0] = 0;
    }
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-1] + c[i]*d[j]);
        }
    }
    cout << dp[m][n] << endl;
    return 0;

}

Measured memory_bytes: 10988
#include <stdio.h>
#include <cstdio>
int main(){
	int a,b,c,i,j;
	scanf("%d %d %d",&a,&b,&c);
	for(j=a;j<=b;j++){
		if(c%j==0){
			i++;
		}
	}
	printf("%d\n",i);
}


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

using namespace std;

int main(){
        string s,t;
        cin >> s >> t;

        int n = s.size(),ans = 0;

        for (int i = 0;i < n;i++){
                if(s[i] != t[i])
                        ans++;
        }
        cout << ans << endl;
}

Measured memory_bytes: 3900
#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve_test() {
	int x;
	cin >> x;
	cout << 1 - x << '\n';
}

int32_t main() {
	int T; 
	// cin >> T;
	T = 1;
	while (T--)
		solve_test();

	return 0;
}


Measured memory_bytes: 3612
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  int N;
  cin >> N;
  int L[210] = {};
  REP(i, 2 * N) {
    cin >> L[i];
  }
  sort(L, L + 2 * N);

  int total = 0;
  REP(i, 2 * N) {
    if (i % 2 == 0) {
      total += L[i];
    }
  }

  cout << total << endl;
  return 0;
}


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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(5);
    cout << fixed;

    string S;
    stack<char> c;
    cin >> S;



    c.push(S[0]);

    for(int i = 1; i < S.size(); i++) {


        if(!c.empty() && c.top() != S[i]) {

            c.pop();
        }

        else {

            c.push(S[i]);
        }
    }




    cout << S.size() - c.size() << endl;







    return 0;
}




Measured memory_bytes: 512
def smaller(x, y):
	if x < y:
		return x
	return y
def larger(x, y):
	if x > y:
		return x
	return y

N, M = map(int, input().split())
left = 0
right = N+1
for i in range(0, M):
	L, R = map(int, input().split())
	left = larger(left, L)
	right = smaller(right, R)
if right < left:
	print(0)
else:
	print(right-left+1)

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

int main() {
	int s,w;
	cin >> s >> w;
	if (w>=s) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  REP(i, s.length() - 1) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

long long combi(long long,long long);
long long modpow(long long,long long);

int main(){
    long long n,a,b,sum=1,i,mod=1000000007;scanf("%lld%lld%lld",&n,&a,&b);
    sum=modpow(2,n);//2^(10^9)=140625001
    sum--;//combinationの和なので2の累乗を用いる
    
    sum=sum-combi(n,a);//嫌いな数になる場合を除く
    sum=sum-combi(n,b);
    
    sum=sum%mod;

    if(sum>=0){
        printf("%lld\n",sum);
    }else{
        printf("%lld\n",sum+mod);
    }
    return 0;
}

long long combi(long long n,long long r){//繰り返し二乗法を用いてcombination計算
    long long ans,i,under=1,up=1,mod=1000000007;
    for(i=1;i<=r;i++){
        under=under*i;
        under=under%mod;
    }
    under=modpow(under,mod-2);
    
    for(i=1;i<=r;i++){
        up=up*(n-i+1);
        up=up%mod;
    }
    ans=up*(under%mod);
    return ans%mod;
}

long long modpow(long long a,long long n){//繰り返し二乗法
    long long mod=1000000007;
    if(n==1) return a%mod;
    if(n%2==1) return (a*modpow(a,n-1))%mod;
    long long t=modpow(a,n/2);
    return (t*t)%mod;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vpiipi vector<piipi>
#define pb push_back
#define pob pop_back
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (int i = 0; i < n; i++)
#define repp(i,a,b) for(int i = a ; i<b ; i++)
#define reppr(i,a,b) for(int i = a-1 ; i>=b ; i--)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    int fact[500010], factinv[500010] , coefficientflag = 0;
    void Util_nCr()
    {
        fact[0] = 1 , factinv[0] = 1;
        repp(i,1,500010)
        {
            fact[i] = (fact[i-1] * i)%mod;
            factinv[i] = (factinv[i-1] * inverse(i))%mod;
        }
    }
    int nCr(int n , int r)
    {
        if(!coefficientflag) coefficientflag = 1 , Util_nCr();             
        return ((fact[n] * inverse(fact[n-r]) % mod * inverse(fact[r]))%mod) ;
    }

void solve();
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t; 
    while(t--)
        solve();
} 

void solve()            
{
    int n;
    cin >> n;
    int a[n+1] = {};
    rep(i,n+1)
        cin >> a[i];
    vpii v(n+1);
    v[n] = {a[n] , a[n]};
    repr(i,n)
    {
        v[i].ff = (v[i+1].ff + 1)/2 + a[i];
        v[i].ss = v[i+1].ss + a[i];
    }
    int currmin = 1  , currmax = 1 , vert = 0 , flag = 0;
    rep(i,n+1)
    {

        if(currmax < v[i].ff || currmin > v[i].ss)
        {
            flag = 1;
        }
        vert += min(currmax,v[i].ss);
        currmax = 2*(min(currmax,v[i].ss) - a[i]);
        currmin = max(0ll,min(currmax,v[i].ss) - a[i]);
    }    
    if(flag)
        cout << -1;
    else
        cout << vert;
}

Measured memory_bytes: 5560
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
	char suit;
	int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i=0;i<n1;i++){
		L[i] = A[left + i];
	}
	for(i=0;i<n2;i++){
		R[i] = A[mid  + i];
	}
	L[n1].value = R[n2].value = SENTINEL;
	i = j = 0;
	for(k=left; k<right; k++) {
		if(L[i].value <= R[j].value) {
			A[k] = L[i++];
		} else {
			A[k] = R[j++];
		}
	}
}

void mergeSort(struct Card A[], int n, int left, int right) {
	if(left+1 < right) {
		int mid = (left+right) / 2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid, right);
		merge(A,n,left,mid,right);
	}
}

int partition(struct Card A[], int n, int p, int r) {
	int i, j;
	struct Card t, x;
	x = A[r];
	i = p-1;
	for(j=p; j<r; j++) {
		if(A[j].value <= x.value) {
			i++;
			t=A[i]; A[i]=A[j]; A[j]=t;
		}
	}
	t=A[i+1];
	A[i+1]=A[r];
	A[r]=t;
	return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
	int q;
	if(p<r) {
		q = partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main() {
	int n, i, v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;
	
	scanf("%d", &n);
	
	for(i=0;i<n;i++) {
		scanf("%s %d",S,&v);
		A[i].suit =  B[i].suit  = S[0];
		A[i].value = B[i].value = v;
	}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i=0;i<n;i++) {
		// マージソートとクイックソートの結果を比べる
		if(A[i].suit != B[i].suit){
			stable = 0;
		}
	}
	if(stable==1){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}
	for(i=0;i<n;i++) {
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}


Measured memory_bytes: 4024
local n, m = io.read("*n", "*n")
local edge = {}
local color = {}
local searched_len = {}
for i = 1, n do
  edge[i] = {}
  color[i] = 0
  searched_len[i] = -1
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end
local q = io.read("*n")
local qv, qd, qc = {}, {}, {}
for iq = 1, q do
  qv[iq], qd[iq], qc[iq] = io.read("*n", "*n", "*n")
end
local tv, td, tc = {}, {}, {}
for iq = q, 1, -1 do
  local taskpos = 1
  tv[1], td[1], tc[1] = qv[iq], qd[iq], qc[iq]
  while 0 < taskpos do
    local src, d, c = tv[taskpos], td[taskpos], tc[taskpos]
    taskpos = taskpos - 1
    if searched_len[src] < d then
      searched_len[src] = d
    end
    if color[src] == 0 then
      color[src] = c
    end
    if 0 < d then
      for i = 1, #edge[src] do
        local dst = edge[src][i]
        if searched_len[dst] < d - 1 then
          taskpos = taskpos + 1
          tv[taskpos] = dst
          td[taskpos] = d - 1
          tc[taskpos] = c
        end
      end
    end
  end
end
for i = 1, n do
  print(color[i])
end


Measured memory_bytes: 30648
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
  int H,W;
  cin >> H >> W;
  vector<string> b(H);
  for(int i=0;i<H;i++)
    cin >> b[i];

  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      {
	if( b[i][j] == '#'
	    && (i==0 || b[i-1][j] == '.')
	    && (j==0 || b[i][j-1] == '.')
	    && (i==H-1 || b[i+1][j] == '.')
	    && (j==W-1 || b[i][j+1] == '.'))
	  {
	    cout << "No" << endl;
	    return 0;
	  }
      }
  
  cout << "Yes" << endl;
}


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

using namespace std;

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

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

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];

    int count = 0;
    while(true){
        bool doit = true;
        rep(i, n) if(nums[i] % 2 != 0) doit = false;

        if(doit){
            rep(i, n) nums[i] /= 2;
            count ++;
        }else{
            break;
        }
    }

    cout << count << endl;
}

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


int main(){
    
    int n,y;
    bool isPossible = false;
    scanf("%d", &n);
    scanf("%d", &y);
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <=n-i;j++){
            if(10000 * i + 5000 * j + 1000 * (n - i - j) == y){
                printf("%d %d %d",i,j,n-i-j);
                isPossible = true;
                break;
            }
        }
        if(isPossible){
            break;
        }
    }
    if(!isPossible){
        printf("-1 -1 -1");
    }
    return 0;
}

Measured memory_bytes: 256
const MOD: u32 = 998244353;

fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let t: usize = s.next().unwrap().parse().unwrap();
	let a: Vec<usize> = s.take(n).map(|a| a.parse().unwrap()).collect();
	let mut dp = vec![0; t + 1];
	let mut ans = 0;
	for a in a {
		dp[0] = (dp[0] + 1) % MOD;
		for i in (a..=t).rev() {
			dp[i] = (dp[i] + dp[i - a]) % MOD;
		}
		ans = (ans + dp[t]) % MOD;
	}
	println!("{}", ans);
}


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

#define pb push_back
#define MAX 100005
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

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


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i =0; i<n; ++i)
        cin>>a[i];
    int l = 0, r = n-1;
    int act = 0;
    for(int i = n-1; i>=0;i--){
        if(act==0){
            b[l]=a[i];
            ++l;
        }
        else{
            b[r]=a[i];
            --r;
        }
        act^=1;
    }
    for(int i =0; i<n; ++i){
        if(i)
            cout<<" ";
        cout<<b[i];
    }
    cout<<"\n";
    return 0;
}

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

int N;
int ans = INT_MIN;
int bit[10]{};
static const int MAX = 100;
int F[MAX][10]{};
int P[MAX][11]{};
bool flag = false;

void solve() {
  // 一番最初に呼ばれるときはビット列がすべて0なので、営業している店が0となり不適当
  if (!flag) {
    flag = true;
    return;
  }
  int profit = 0;
  // cnt: 両方が営業している時間帯の個数
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    for (int j = 0; j < 10; j++) {
      if(F[i][j] == 1 && bit[j] == 1) cnt++;
    }
    profit += P[i][cnt];
  }
  ans = max(ans, profit);
}
void rec(int k) {
  if( k == 10) {
    solve();
    return;
  }
  rec(k + 1);
  bit[k] = 1;
  rec(k + 1);
  bit[k] = 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> F[i][2 * j] >> F[i][2 * j + 1];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> P[i][j];
    }
  }
  rec(0);
  cout << ans << "\n";
  return 0;
}


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

int main(){
  int n;cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  if(a[n/2-1]==a[n/2]) cout << "0" << endl;
  else cout << a[n/2] - a[n/2-1] << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

#include <cmath>
#include <algorithm>

using namespace std;

int S[10001];

int main(){
    int s,q;
    cin>>s;
    for(int i = 0;i < s;i++) {
        cin>>S[i];
    }

    int count = 0;
    int temp;

    cin>>q;
    for(int i = 0;i < q;i++) {
        cin>>temp;
        for(int j = 0;j < s;j++) {
            if(S[j] == temp) {
                count++;
                break;
            }
        }

    }


    cout<<count<<endl;






    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < n; ++i)
#define rep(i, n) rep_init(i, 0, n)

void Main()
{
	int N, K;
	cin >> N >> K;
	int L = 0;
	rep(i, N)
	{
		int x;
		cin >> x;
		L += min(x, K-x) * 2;
	}

	cout << L << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mp make_pair
#define fi first
#define se second
#define pb push_back

const int maxn = 2e3 + 5;

int n, k, q, a[maxn], vs[maxn];
pair<int, int> b[maxn];

int main() {
  cin >> n >> k >> q;

  rep(i, 0, n) cin >> a[i];

  rep(i, 0, n) {
    b[i] = mp(a[i], i);
  }

  sort(b, b + n);

  int ans = 1e9;
  rep(i, 0, n) {
    rep(j, 0, n) vs[j] = 0;
    vs[n] = 1;
    rep(j, 0, i) {
      vs[b[j].se] = 1;
    }
    int tot = 0;
    int cnt = 0;
    vector<int> has;
    int pre = 0;
    rep(j, 0, n + 1) {
      if (!vs[j]) {
        cnt++;
      } else {
        if (cnt >= k) {
          vector<int> cur;
          rep(t, pre, j) {
            cur.pb(a[t]);
          }
          sort(cur.begin(), cur.end());
          rep(t, 0, cnt - k + 1) {
            has.pb(cur[t]);
          }
          tot += (cnt - k + 1);
        }
        pre = j + 1;
        cnt = 0;
      }
    }
    if (tot >= q) {
      sort(has.begin(), has.end());
      ans = min(ans, has[q - 1] - has[0]);
    }
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 int D;
 cin>>D;
 if(D==25)
 cout<<"Christmas"<<endl;
 else if(D==24)
 cout<<"Christmas Eve"<<endl;
 else if(D==23)
 cout<<"Christmas Eve Eve"<<endl;
 else
 cout<<"Christmas Eve Eve Eve"<<endl;
 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b;
	
	//printf("??´??°A");
	scanf("%d %d",&a,&b);
	
	if(a>b){
		printf("a > b\n");
	}
		
	else if(a<b){
		printf("a < b\n");
	}
	
	else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
N, M = list(map(int, input().split()))
A = {i: 0 for i in range(N+1)}
mod = 10 ** 9 + 7
for _ in range(M):
    A[int(input())] = 1

dp = [0 for _ in range(N+1)]
dp[0] = 1

for i in range(N+1):
    if A.get(i+1) == 0:
        dp[i + 1] += dp[i]
    if A.get(i+2) == 0:
        dp[i + 2] += dp[i]

print(dp[N]%mod)


Measured memory_bytes: 474256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  ll n, k; cin >> n >> k;
  ll ans = 0;

  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }

  for (ll b = k+1; b <= n; b++) {
    ans += (b - k) * (n / b);
    if (n % b >= k) {
      ans += (n % b) - k + 1;
    }
//    cerr << ans << endl;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long int ll;
using namespace std;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int X,A;
cin>>X>>A;
if(X<A)cout<<0<<endl;
else cout<<10<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;

const Int N = 1123456;
bool is_prime[N];
const Int inf = 1LL << 50;

int main() {
   for(Int i = 0; i < N; ++i) {
      is_prime[i] = true;
   }
   is_prime[0] = is_prime[1] = false;
   for(Int i = 2; i * i < N; ++i) {
      if( is_prime[i] ) {
         for(Int k = 2*i; k < N; k+=i) {
            is_prime[k] = false;
         }
      }
   }
   for(;;) {
      Int n, m;
      std::cin >> m >> n;
      if( n == 0 and m == 0 ) break;
      auto field = std::vector<std::vector<Int>>(1024, std::vector<Int>(1024, -1));
      Int y = 512;
      Int x = 512;
      Int dx[] = {1, 0,-1, 0};
      Int dy[] = {0,-1, 0, 1};
      Int k = 3;
      Int i = 1;
      while( i <= m ) {
         field[y][x] = i;
         i += 1;
         {
            Int nx = x + dx[(k+1)%4], ny = y + dy[(k+1)%4];
            if( field[ny][nx] == -1 ) {
               k = (k+1) % 4;
            }
         }
         Int nx = x + dx[k], ny = y + dy[k];
         x = nx;
         y = ny;
      }
      /*
      for(Int y = 512-3; y < 512+3; ++y) {
         for(Int x = 512-3; x < 512+3; ++x) {
            std::cout << field[y][x] << ' ';
         }
         std::cout << std::endl;
      }
      */
      auto dp = std::vector<std::vector<std::pair<Int,Int>>>(1024, std::vector<std::pair<Int,Int>>(1024, std::make_pair(-inf,-1)));
      for(Int y = 0; y < 1024; ++y) {
         for(Int x = 0; x < 1024; ++x) {
            if( field[y][x] == n ) {
               dp[y][x] = std::make_pair(0, field[y][x]);
               //dp[y][x] = is_prime[field[y][x]] ? 1 : 0;
            }
         }
      }
      for(Int y = 1; y < 1024; ++y) {
         for(Int x = 0; x < 1024; ++x) {
            if( x-1 >= 0 ) {
               if( dp[y][x].first < dp[y-1][x-1].first ) {
                  dp[y][x] = dp[y-1][x-1];
               }
               //dp[y][x] = std::max(dp[y][x], dp[y-1][x-1]);
            }
            if( dp[y][x].first < dp[y-1][x].first ) {
               dp[y][x] = dp[y-1][x];
            }
            //dp[y][x] = std::max(dp[y][x], dp[y-1][x]);
            if( x+1 < 1024 ) {
               if( dp[y][x].first < dp[y-1][x+1].first ) {
                  dp[y][x] = dp[y-1][x+1];
               }
               //dp[y][x] = std::max(dp[y][x], dp[y-1][x+1]);
            }
            if( is_prime[field[y][x]] ) {
               dp[y][x].first += 1;
               dp[y][x].second = field[y][x];
               //dp[y][x] += 1;
            }
         }
      }
      // for(Int y = 512-3; y < 512+3; ++y) {
      //    for(Int x = 512-3; x < 512+3; ++x) {
      //       std::cout << dp[y][x] << ' ';
      //    }
      //    std::cout << std::endl;
      // }
      std::pair<Int,Int> res(-inf,-1);
      //Int res = -inf, res_i = -1;
      for(Int y = 0; y < 1024; ++y) {
         for(Int x = 0; x < 1024; ++x) {
            if( res < dp[y][x] ) {
               res = dp[y][x];
            }
         }
      }
      if( res.first == 0 ) {
         res.second = 0;
      }
      std::cout << res.first << ' ' << res.second << std::endl;
   }
}




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

int main(){
	int a, b;
	cin >> a >> b;

	if((a+b)%2 == 0) cout << (a+b)/2 << endl;
	else cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<vector<int> > g(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> c(N);
  for (int i = 0; i < N; ++i) {
    cin >> c[i];
  }
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());

  vector<int> v(N, -1);
  
  int cnt = 0;
  queue<int> q;
  q.push(0);
  while (not q.empty()) {
    int node = q.front();
    q.pop();
    assert(v[node] == -1);
    v[node] = c[cnt];
    ++cnt;
    for (auto next : g[node]) {
      if (v[next] == -1) {  // not visited
	q.push(next);
      }
    }
  }    

  int sum = 0;
  for (int i = 1; i < N; ++i) {  // exclude max value
    sum += c[i];
  }
  cout << sum << endl;

  for (int i = 0; i < N; ++i) {
    cout << v[i] << " ";
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n,ll k)
{
	KAKA
	vector<ll> v(n);
	pragi(0,n)
	{
		cin>>v[i];
	}
	sort all(v);
	ll sum = 0;
	pragi(0,k)
	{
		sum += v[i];
	}
	cout<<sum<<"\n";
}
int main()
{
	KAKA
	ll n,k;
	cin>>n>>k;
	Compute(n,k);
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 2005;

int c[N][N];
int main() {
    for (int i = 0; i <= 2000; i++) {
        c[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
        }
    }
    int n;
    cin >> n;
    LL ans = 0;
    for (int i = 1; i <= n / 3; i++) {
        ans += c[n - i * 2 - 1][i - 1];
    }
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 17420
import numpy as np
k = int(input()) - 1
if len(str(k)) == 1:
    print(k + 1)
else:

    jjj = 0
    ans = [0]

    num = 0
    dps = []
    dp = [1] * 10
    dp[0] = 0

    flag = False
    for i in range(len(dp)):
        num += dp[i]
        if num > k:
            flag = True
            break

    dp[0] = 1
    dps.append(dp)

    flag = False
    while True:
        dp = [0] * 10
        dp[0] = 0
        for i in range(1, 9):
            dp[i] = sum(dps[-1][i - 1 : i + 2])
        dp[9] = dps[-1][8] + dps[-1][9]


        for i in range(len(dp)):
            num += dp[i]
            if num > k:
                flag = True
            if flag:
                num -= dp[i]
                break
        if flag:
            break
        dp[0] = dps[-1][0] + dps[-1][1]
        dps.append(dp)

    ans = [i]
    k = k - num
    jjj += 1

#     print(k)
    try:
        while True:
#             print(k)
            num = 0
            ii = i
            for i in range(max([ii - 1, 0]), ii + 2):
            #     print(i)
                if num + dps[-1][i]> k:
                    break
                else:
                    num += dps[-1][i]

            ans.append(i)
            k -= num
            dps = dps[:-1]
#             print(k)
            if k == 0 and len(dps) > 0:
                aaa = i - 1
                while True:    
                    if aaa < 0 :
                        aaa = 0
                    ans += [aaa]
                    aaa -= 1
                    dps = dps[:-1]
                    if len(dps) == 0:
                        break
                aaaaaa
    except:
        print("".join(map(str, ans)))

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
int main() {
 	int n, m;
 	cin >> n >> m;
 	if(n > 9 || m > 9) {
 	 	cout << -1 << endl;
 	}
 	else {
 	 	cout << n * m << endl;
 	}
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b = il()
    if a <= b:
        print(a)
    else:
        print(a-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10008
#!/usr/bin/env python3.4

# abc126_f

def main():
    # input
    m, k = [int(s) for s in input().split()]
    n = 2**m
    #
    if k >= n:
        print('-1')
        return
    elif m == 0 and k == 0:
        print('0 0')
        return
    elif m == 1 and k == 0:
        print('0 0 1 1')
        return
    elif m == 1 and k == 1:
        print('-1')
        return
    # get ans
    l = [i for i in range(n) if i!=k]
    ans = []
    ans.extend(l)
    ans.append(k)
    ans.extend(reversed(l))
    ans.append(k)
    # output
    print(' '.join(map(str, ans)))

if __name__ == '__main__':
    main()



Measured memory_bytes: 28568
import itertools as itr

n, wmax = list(map(int, input().split()))
w = [0]*(n+1)
v = [0]*(n+1)

for i in range(1, n+1):
    wi, vi = list(map(int, input().split()))
    w[i] = wi
    v[i] = vi
vmax = sum(v)
    
dp = [[10**9+7]*(vmax+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0]=0

for i, j in itr.product(range(1, n+1), range(1, vmax+1)):
    if j-v[i] >= 0:
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]]+w[i])
        #print((i,j), dp[i][j])
    else:
        dp[i][j] = dp[i-1][j]

ans = [j for j in range(vmax+1) if dp[n][j] <= wmax]       
print(ans[-1])

Measured memory_bytes: 120668
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll N, A[5], min_capacity = 	922337203685477580;
ll ans = 0;

void solve(){
    ans += 4;
    ans += (N + min_capacity -1) / min_capacity;
    cout << ans << endl;
}

int main(){
    cin >> N;
    rep(i,5) {
        cin >> A[i];
        min_capacity = min(A[i], min_capacity);
    }

    solve();
}


Measured memory_bytes: 256
a, b = map(int, input().split())
S = input()
digits = set([str(i) for i in range(10)])

for i in range(a+b+1):
    if i == a and S[i] != '-':
        print('No')
        break
    elif i == a and S[i] == '-':
        continue

    if not S[i] in digits:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    vector<pair<char,int>> vec;
    for(int i=1;i<=13;i++){
        vec.push_back(make_pair('S',i));
    }
    for(int i=1;i<=13;i++){
        vec.push_back(make_pair('H',i));
    }
    for(int i=1;i<=13;i++){
        vec.push_back(make_pair('C',i));
    }
    for(int i=1;i<=13;i++){
        vec.push_back(make_pair('D',i));
    }
    char c;
    int x,n;
    in(n);
    rep(i,n){
        in(c,x);
        rep(i,vec.size()){
            if(c==vec[i].first&&x==vec[i].second){
                vec.erase(vec.begin()+i);
                break;
            }
        }
    }
    rep(i,vec.size()){
        out(vec[i].first,vec[i].second);
    }
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()

int main() {
	int N, M, x;
	long long ans;
	cin >> N >> M;
	int P[M], Y[M];
	vector<int> BY[N+1];
	for (int i = 0; i < M; i++) {
		cin >> P[i] >> Y[i];
		BY[P[i]].push_back(Y[i]);
	}
	for (int i = 1; i <= N; i++) {
		sort(ALL(BY[i]));
	}
	for (int i = 0; i < M; i++) {
		x = int(lower_bound(ALL(BY[P[i]]), Y[i]) - BY[P[i]].begin()) + 1;
		ans = (long long)(P[i]) * 1000000 + x;
		printf("%012lld\n", ans);
	}

	return 0;
}

Measured memory_bytes: 7808
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

void main()
{
    auto N = readln.chomp.to!long;
    int[] aa;
    auto ii = new long[](N+1);
    foreach (i, a; readln.split.to!(int[])) {
        aa ~= a;
        ii[a] = i.to!int;
    }

    auto rbt = redBlackTree(-1, N);
    long res;
    foreach (long a; 1..N+1) {
        auto ls = rbt.lowerBound(ii[a]);
        auto l = ii[a] - ls.back;
        auto rs = rbt.upperBound(ii[a]);
        auto r = rs.front - ii[a];
        res += (l * r) * a;
        rbt.insert(ii[a]);
    }
    writeln(res);
}

Measured memory_bytes: 21404
def resolve():
    import math
    from collections import Counter
    n = int(input())
    v = [int(i) for i in input().split()]
    c0 = Counter(v[0::2]).most_common(2)
    c1 = Counter(v[1::2]).most_common(2)
    l0 = math.ceil(n / 2)
    l1 = n // 2
    if c0[0][0] != c1[0][0]:
        print(l0 - c0[0][1] + l1 - c1[0][1])
    else:
        if len(c0) == 1 and len(c1) == 1:
            print(n // 2)
        else:
            if len(c0) == 2 and len(c1) == 2:
                print(min(l0 - c0[0][1] + l1 - c1[1][1],
                          l0 - c0[1][1] + l1 - c1[0][1]))
            elif len(c0) == 1:
                print(l1 - c1[1][1])
            else:
                print(l0 - c0[1][1])


resolve()


Measured memory_bytes: 15584
#include<bits/stdc++.h>
using namespace std;
int n,ans,now,res,a[100005],b[100005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        if(x>0) a[++now]=x;
        else    b[++res]=x;
    }
    sort(a+1,a+now+1);
    sort(b+1,b+res+1);
    if(now&&res){
        int tot=0;
        for(int i=1;i<=now;i++) tot+=a[i];
        for(int i=1;i<=res;i++) tot-=b[i];
        printf("%d\n",tot);
        int k=b[1];
        for(int i=1;i<now;i++)
            printf("%d %d\n",k,a[i]),k-=a[i];
        printf("%d %d\n",a[now],k);a[now]-=k;
        k=a[now];
        for(int i=2;i<=res;i++)
            printf("%d %d\n",k,b[i]),k-=b[i];
    }
    if(res&&!now){
        int tot=0;
        for(int i=1;i<=res;i++) tot+=b[i];
        printf("%d\n",b[res]*2-tot);
        int k=b[res];
        for(int i=1;i<res;i++)
            printf("%d %d\n",k,b[i]),k-=b[i];
    }
    if(now&&!res){
        int tot=0;
        for(int i=1;i<=now;i++) tot+=a[i];
        cout<<tot-a[1]*2<<endl;
        int k=a[1];
        for(int i=2;i<now;i++)
            printf("%d %d\n",k,a[i]),k-=a[i];
        printf("%d %d\n",a[n],k);
    }
    return 0;
}

Measured memory_bytes: 2304