akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const char *Output = "AB";

const int MAX = 1e3 + 10;
int num[MAX];
char ans[MAX * 10];

PII get_spe(int sml, int lrg, int sublen) {
	int l = 0, r = sml + 1;
	while (l <= r) {
		ll m = (l + r) / 2;
		ll used = m * sublen + (sml - m) / (sublen);
		if (used >= lrg)
			r = m - 1;
		else
			l = m + 1;
	}
	ll used = r * sublen + (sml - r) / (sublen);
	return MP(r, lrg - used);
}

int main() {
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		int A, B, C, D;
		scanf("%d%d%d%d", &A, &B, &C, &D);
		const int outputlen = D - C + 1;
		if (A == B) {
			int id = (C % 2) ^ 1;
			for (int i = C; i <= D; i++, id ^= 1)
				putchar(Output[id]);
			puts("");
		}
		else {
			bool changed = false;
			if (A > B) {
				changed = true;
				swap(A, B);
				int nC = A + B + 1 - D;
				int nD = A + B + 1 - C;
				C = nC, D = nD;
			}
			const int sublen = (B - 1) / (A + 1) + 1;
			PII spe = get_spe(A, B, sublen);
			int id_spe = A - spe.F;
			int end_empty_ch = id_spe / sublen * (sublen + 1);
			debug("(%d %d) %d %d\n", spe.F, spe.S, id_spe, end_empty_ch);
			//int id = C / (sublen + 1) * (sublen + 1);
			int ed = 1;
			if (C <= end_empty_ch) {
				while (C % (sublen + 1) != 0 && C <= D) {
					ans[ed++] = 'A';
					C++;
				}
				ans[ed++] = 'B';
				C++;
				while (C <= D && C < end_empty_ch) {
					for (int i = 0; i < sublen && C <= D; i++, C++)
						ans[ed++] = 'A';
					ans[ed++] = 'B';
					C++;
				}
			}
			debug("C = %d ed %d\n", C, ed);
			const int end_spe_ch = end_empty_ch + id_spe % sublen;
			while (C <= D && C <= end_spe_ch) {
				debug("A ed %d\n", ed);
				ans[ed++] = 'A';
				C++;
			}
			const int start_nor = end_spe_ch + spe.S;
			while (C <= D && C <= start_nor) {
				debug("B ed %d\n", ed);
				ans[ed++] = 'B';
				C++;
			}
			while (C <= D) {
				if ((C - start_nor) % (sublen + 1) == 1) {
					debug("A ed %d\n", ed);
					ans[ed++] = 'A';
					debug("C = %d\n", C);
				}
				else {
					debug("B ed %d\n", ed);
					ans[ed++] = 'B';
				}
				C++;
			}

			assert(ed > outputlen);
			if (changed) {
				for (int i = outputlen; i >= 1; i--)
					putchar(ans[i] == 'A' ? 'B' : 'A');
				//putchar('!');
			}
			else {
				for (int i = 1; i <= outputlen; i++)
					putchar(ans[i]);
			}
			puts("");
		}
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){

    int N, M;
    int Ans, Ans_;
    string s;

    cin >> N >> M;

    int p_num;
    vector<int> AC(N);
    vector<int> WA(N);

    rep(i,N) {
        AC[i] = 0;
        WA[i] = 0;
    }

    rep(i,M){ cin >> p_num >> s;
        if(AC[p_num-1]==1) continue;
        else {
            if(s=="AC") AC[p_num-1]=1;
            else WA[p_num-1]++;
        } 
    }
    Ans = 0;
    Ans_ = 0;
    rep(i, N) {
        if(AC[i]==1){
        Ans+=AC[i];
        Ans_+=WA[i];
        }
    }
    
    cout << Ans << " " << Ans_;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
using namespace std;
int main(){
	int N,M,ans=0;
	cin >> N;
	string blue[800];
	for(int i=0;i<N;i++){
		cin >> blue[i];
	}
	
	cin >> M;
	string red[800];
	for(int i=0;i<M;i++){
		cin>>red[i];
	}
	
	for(int i=0;i<N;i++){
		int x=0;
		for(int j=0;j<N;j++){
			if(blue[i]==blue[j]){
				x++;
			}
		}
		for(int j=0;j<M;j++){
			if(blue[i]==red[j]){
				x--;
			}
		}
		ans = max(ans,x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();
		String[] cut = input.split(" ");
		int a =Integer.parseInt(cut[0]);
		int b =Integer.parseInt(cut[1]);
		int c =Integer.parseInt(cut[2]);
		int count=0;
	 for(int x = a;x <= b; x++ ){
		 if(c%x==0){
			 count++;
		 }
	 }
	 System.out.println(count);
	}
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,k,sum=0;
    c_p_c();
    // cin>>n>>m;
    string s;
    cin>>s;
    map<char,int> ma;
    for(char ch : s )
    	ma[ch]++;

    // watch2(ma.size(),s.size());
    if(ma.size()==s.size())
    	cout<<"yes"<<endl;
    else
    	cout<<"no"<<endl;
 
  	
 	return 0;

   }

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long K, long long A, long long B){
    ll Kold = K;
    if(B <= A) {
        cout << K+1 << endl;
        return;
    }
    ll res = 1;
    res += min(K, A-1);
    K -= A-1;
    if(K <= 0){
        cout << res << endl;
        return;
    }
    res += K/2 * (B-A);
    K -= (K/2)*2;
    if(K > 0)
        res ++;
    
    cout << max(res,  Kold+1)<< endl;

}

int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(K, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;

const int MAX_N = 1e5;
const long long MOD = 1e9 + 7;
int N;
long long A, B;
long long S[MAX_N + 1];

long long dp_x[MAX_N] = {};
long long dp_y[MAX_N] = {};
int x_last; // X の条件を満たす最大添え字+1
int y_last; // Y の条件を満たす最大添え字+1
int x_continue; // X のみで構成できる添え字の開始位置
int y_continue; // Y のみで構成できる添え字の開始位置

long long solve()
{
	dp_x[0] = 1;
	dp_y[0] = 1;
	x_last = 0;
	y_last = 0;
	x_continue = 0;
	y_continue = 0;

	for (int i = 1; i < N; ++i)
	{
		x_last = upper_bound(S + x_last, S + i + 1, S[i] - A) - S;
		y_last = upper_bound(S + y_last, S + i + 1, S[i] - B) - S;
		//while (S[i] - S[x_last] >= A) ++x_last;
		//while (S[i] - S[y_last] >= B) ++y_last;

		if (S[i] - S[i - 1] >= A)
			dp_x[i] = dp_x[i - 1];
		if (x_last >= y_continue)
			dp_x[i] = (dp_x[i] + dp_y[min(x_last, i-1)]) % MOD;

		if (S[i] - S[i - 1] >= B)
			dp_y[i] = dp_y[i - 1];
		if (y_last >= x_continue)
			dp_y[i] = (dp_y[i] + dp_x[min(y_last, i-1)]) % MOD;

		if (S[i] - S[i - 1] < A)
			x_continue = i;
		if (S[i] - S[i - 1] < B)
			y_continue = i;
	}

	return (dp_x[N - 1] + dp_y[N - 1]) % MOD;
}

int main()
{
	cin >> N >> A >> B;
	for (int i = 0; i < N; ++i)
	{
		cin >> S[i];
	}
	cout << solve() << endl;
}

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

int N;
int n=0;

void keisan(long int x,int a,int b,int c){
  if(x>N)
    return;
  if(a&&b&&c)
    n++;
  
  keisan(x*10+3,1,b,c);
  keisan(x*10+5,a,1,c);
  keisan(x*10+7,a,b,1);
}

int main(){
  cin>>N;
  keisan(0,0,0,0);
  cout<<n<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<vector>
#include<tuple>
#include<queue>
#include<cmath>
#define LL long long
#define DB double
#define TT std::tuple<LL,LL,LL>
#define PP std::pair<DB,LL>
int N;
DB D[1010];
DB x[1010], y[1010], r[1010];
std::vector<PP> G[1010];

DB pow(DB x) { return x * x; }
void add(int s, int t) {
	DB A = std::sqrt(static_cast<long double>(pow(x[s] - x[t]) + pow(y[s] - y[t])));
	A -= r[s] + r[t];
	G[s].emplace_back(PP{ std::max(A,(DB)0),t });
	G[t].emplace_back(PP{ std::max(A,(DB)0),s });
}
int main() {
	std::cin >> x[0] >> y[0] >> x[1001] >> y[1001];
	add(0, 1001);
	std::cin >> N;
	for (int i = 0; i <= 1001; i++) {
		D[i] = 1e18;
	}
	for (int i = 1; i <= N; i++) {
		std::cin >> x[i] >> y[i] >> r[i];
		add(0, i);
		add(1001, i);
	}
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			add(i, j);
		}
	}
	std::priority_queue<PP,std::vector<PP>, std::greater<PP>> pq;
	pq.push(PP{ (DB)0,0 });//cost,now
	while (!pq.empty()) {
		PP p = pq.top();
		pq.pop();
		if (p.first>D[p.second])continue;
		for (auto u : G[p.second]) {
			if (D[u.second]>p.first + u.first) {
				D[u.second] = p.first + u.first;
				pq.push(PP{ D[u.second],u.second });
			}
		}
	}
	std::cout << std::fixed << std::setprecision(10) << D[1001] << std::endl;
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if((a == b+c)||(b == a+c)||(c == a+b)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 1e5;

int n;
int s[MaxN + 5];
map <LL, int> cnt;
int main() 
{
	while(scanf("%d", &n) != EOF)
	{
		int ans = 0;
		for(int i = 1; i <= n; i++) {
			LL x;
			scanf("%lld", &x);
			if(cnt[x] == 0) {
				cnt[x] = 1;
				ans++;
			}
			else if(cnt[x] == 1) {
				cnt[x] = 0;
				ans--;
			}
		}
		printf("%d\n", ans);
		cnt.clear();
	}
	return 0;
}

Measured memory_bytes: 6528
#define put() putchar(t[d-1][x%strlen(t[d-1])])
char *t[]={"',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
main(x,c,d){
  for(d=-1,x=-1;~(c=getchar());)
    if(c=='\n'){
      if(d)put();puts(""),d=-1,x=-1;
    }else if(c-=48){
      if(c==d)x++;
      else if(~x)put(),x=0;
      if(d==-1)x=0;
      d=c;
    }else{
      if(~d&&d)put(),x=-1;
      else putchar(' ');
      d=-1;
    }
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;
static const double PI = 3.141592653589793;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> root(n+1,0);
  vector< vector<int> > v(n+1);
  for (int i=0; i<m; i++) {
    int k,l;
    cin >> k >> l;
    v.at(k).push_back(l);
    v.at(l).push_back(k);
  }

  queue<int> q;
  q.push(1);
  while (q.size() > 0) {
    int start=q.front(); q.pop();
    for (int next: v.at(start)) {
      if (root.at(next) == 0) {
        root.at(next) = start;
        q.push(next);
      }
    }
  }

  for (int i=1; i<=n; i++) {
    if (root.at(i) == 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  for (int i=2; i<=n; i++) {
    cout << root.at(i) << endl;
  }
}

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

int main()
{
    int n;
    cin >> n;
    long long p[n + 1];
    for (int i = 0; i < n; i++)
    {
        cin >> p[i] >> p[i + 1];
    }
    long long m[n + 1][n + 1];
    for (int i = 1; i <= n; i++)
        m[i][i] = 0;

    for (int l = 2; l <= n; l++)
    {
        for (int i = 1; i <= n - l + 1; i++)
        {
            int j = i + l - 1;
            m[i][j] = 1 << 21;
            for (int k = i; k <= j; k++)
            {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    cout << m[1][n] << endl;
}


Measured memory_bytes: 3144
#include<iostream>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;
typedef long long ll;

int N, A, B;
ll v[50];
map<ll, int,greater<ll>> M;
ll comb[51][51];

void init() {
	for (int i = 0; i <= 50; i++) {
		for (int j = 0; j <= i; j++) {
			if (i == j || j == 0) {
				comb[i][j] = 1LL;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}

bool isok() {
	return ((*M.begin()).second > A);
}

int main() {

	init();

	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		M[v[i]]++;
	}
	ll sum = 0;
	ll valiation = 1;
	int cpyA = A;
	if (isok()) {
		cout << (*M.begin()).first << endl;
		ll ans = 0;
		for (int i = A; i <= min((*M.begin()).second, B); i++) {
			ans += comb[(*M.begin()).second][i];
		}
		cout << ans << endl;
	}
	else {
		for (auto it = M.begin(); it != M.end(); it++) {
			if (A <= 0)break;
			else if (A >= (*it).second) {
				sum += (*it).first * (*it).second;
				A -= (*it).second;
			}
			else {
				sum += (*it).first * A;
				valiation = comb[(*it).second][A];
				A = 0;
			}
		}
		double ans = (double)sum / (double)cpyA;
		cout << setprecision(12) << ans << endl;
		cout << valiation << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [0]+[(p+1)/2 for p in P]
S = list(accumulate(P))
B = []
for j in range(N-K+1):
    B.append(S[j+K]-S[j])
ans = max(B)
print(ans)
    



Measured memory_bytes: 25152
// -*- coding: utf-8 -*-
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskB solver = new TaskB();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskB {    
    int n;
    int[] a;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      n = in.nextInt();
      a = new int[n];
      int[] p = new int[n + 1];
      for (int i = 0; i < n; ++i) {
        a[i] = in.nextInt();
        p[a[i]] = i;
      }
      TreeSet<Integer> set = new TreeSet<Integer>();
      set.add(-1);
      set.add(n);
      long ans = 0;
      for (int i = 1; i <= n; ++i) {
        int l = -1, r = -1;
        if (set.lower(p[i]) != null)
          l = set.lower(p[i]) + 1;
        else
          l = p[i];
        if (set.higher(p[i]) != null)
          r = set.higher(p[i]) - 1;
        else
          r = p[i];
        ans += (long) (p[i] - l + 1) * (r - p[i] + 1) * i;
        set.add(p[i]);
      }
      out.println(ans);
    }
    
  }
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
    
    public String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


Measured memory_bytes: 40792
///============================================================================
/// Name        : Faisal.cpp
/// Author      : Faisal Ahmed
/// Version     :
/// Copyright   : Your copyright notice
/// Description : C++, Ansi-style
///============================================================================

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

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

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

	sort(arr, arr + 3);

	cout << arr[0] + arr[1] << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()
#define tc int t;scanf("%d",&t);while (t--0)
#define int long long
const int MOD=1e9+7;
const int N=1e5+5;
int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
int invmod(int x) {return power(x,MOD-2);}
int a[N];
map<int,int>mp;
int check(int n)
{
	while(n>0)
	{
		if(mp[n%10])
			return 0;
      n/=10;
	}
	return 1;
}
int32_t main()
{
	int n,k;
	cin>>n>>k;
	
	for(int i=1;i<=k;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
		
	}
	for(int i=n;i<=1000000;i++)
	{
		if(check(i))
		{
			cout<<i<<endl;
			return 0;
		}
	}

}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7


'''
独立なグラフがいくつかできていく。
求めるもの：グラフ1にある頂点と2にある頂点の combinaton, 1と3のcombination,……2と3のcombination…… の総和を求めるのを繰り返す。
union-findで行けそうだがN, Mどちらも10**5なので間に合わなさそう。

最終的にはすべて独立となり、答えはnC2となる。
ということで nC2 からはじめてどんどん union していけばいいのでは。
union する2つのグループの頂点数の積を引いていけば良いのかな。
'''



import collections
import itertools
import operator

class UnionFind:
    def __init__(self, elems=None):
        class KeyDict(dict):  # dict + キーがないときは dict[key] = key として key を返す。
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()  # キーがなければ孤立点→自身が key（parent[key]=key）
        self.rank = collections.defaultdict(int)  # 木の高さ。デフォルトでは 0。経路圧縮すると本来は rank が下がるが、その効果は無視している。
        self.size_ = collections.defaultdict(lambda: 1)  # 根に属する頂点の個数。根の値しか信用できない。

        if elems is not None:
            for elem in elems:
                _, _ = self.parent[elem], self.rank[elem]

    def find(self, x):  # あるキーの根を探す。
        if self.parent[x] == x:
            return x  # 自身が根なら自身を返す。
        else:
            self.parent[x] = self.find(self.parent[x])  # 再帰的に親を探して、すべて根に付け替える（経路圧縮）。
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)  # x の根を求める。
        y = self.find(y)  # y の根を求める。
        if x == y:  # もともと同一の木なら何もしない。
            return
        if self.rank[x] < self.rank[y]:  # rank （木の高さ）の低いほうを高いほうに繋げたい。
            x, y = y, x
        self.parent[y] = x  # x の親を y にする。
        self.size_[x] += self.size_[y]
        if self.rank[x] == self.rank[y]:  # 同じ高さの木だったら片方の rank を1つ上げておく。
            self.rank[x] += 1

    def are_same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.size_[self.find(x)]

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]


def main(): 
    N, M = LI()

    visited = [False]*(N+1)
    uf = UnionFind()

    ans_rev = [0]*(M+1)
    ans_rev[0] = N * (N-1) // 2  # N_C_2
    A_li, B_li = [], []
    for i in range(0, M):
        A, B = LI()
        A_li.append(A)
        B_li.append(B)

    for i, (A, B) in enumerate(reversed(list(zip(A_li, B_li)))):
        if not uf.are_same(A, B):
            ans_rev[i+1] = ans_rev[i] - uf.size(A) * uf.size(B)
        else:
            ans_rev[i+1] = ans_rev[i]
        uf.unite(A, B)

    for i in reversed(ans_rev[:-1]):
        print(i)


main()

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}
int char_to_int(char val) {
    return val - '0';
}

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

    int need_left = 0;
    int pointer = 0;
    REP(i, N) {
        if(S[i] == '(') pointer++;
        else {
            if(pointer == 0) need_left++;
            else pointer--;
        }
    }

    int need_right = pointer;

    string res = S;
    REP(i, need_left) res = "(" + res;
    REP(i, need_right) res = res + ")";
    cout << res << endl;
}

Measured memory_bytes: 256
s = input().split(" ")
s = [int(s[i]) for i in range(3)]
A = s[0]
B = s[1]
C = s[2]
minPoint = min(A , B)
maxPoint = max(A, B)
if minPoint < C and C < maxPoint : 
    print("Yes")
else : 
    print("No")

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

int main()
{
  std::string str;
  std::cin >> str;
  if (str == "SAT") std::cout << 1 << std::endl;
  else if (str == "FRI") std::cout << 2 << std::endl;
  else if (str == "THU") std::cout << 3 << std::endl;
  else if (str == "WED") std::cout << 4 << std::endl;
  else if (str == "TUE") std::cout << 5 << std::endl;
  else if (str == "MON") std::cout << 6 << std::endl;
  else std::cout << 7 << std::endl;
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979323846
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	fast;
	
	int n,k;
	cin>>n>>k;
	
	int r,s,p;
	cin>>r>>s>>p;
	map<char,int>mp;
	map<int,int>tl;
	
	mp['r']=r;
	mp['s']=s;
	mp['p']=p;
	
	string t;
	cin>>t;
	
	char an[n];
	ll int sum=0;
	
	for(int i=0;i<n;i++){
		if(i<k){
			if(t[i]=='r'){
				an[i]='p';
				sum+=mp['p'];
				tl[i]=3;
			}
			
			else if(t[i]=='s'){
				an[i]='r';
				sum+=mp['r'];
				tl[i]=1;
			}
			
			else if(t[i]=='p'){
				an[i]='s';
				sum+=mp['s'];
				tl[i]=2;
			}
		}
		
		else {
			if(t[i]=='r'){
				if(an[i-k]!='p'){
					an[i]='p';
					sum+=mp['p'];
					tl[i]=3;
				}
				
				else{
					an[i]='0';
				}
			}
			
			else if(t[i]=='s'){
				if(an[i-k]!='r'){
					an[i]='r';
					sum+=mp['r'];
				}
				
				else
				an[i]='0';
			}
			
			else if(t[i]=='p'){
				if(an[i-k]!='s'){
					an[i]='s';
					sum+=mp['s'];
				}
				
				else
				an[i]='0';
			}
		}
		
		//cout<<an[i];
	}
	
	cout<<sum;
	return 0;
}

Measured memory_bytes: 4688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
	while (true) {
		int n, m, k;

		cin >> n >> m >> k;

		if (n == 0 && m == 0 && k == 0) {
			break;
		}

		vector<vector<int>> dp(n + 1, vector<int>(n*m + 1, 0));
		dp[0][0] = 1;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= n*m; j++) {
				if (dp[i][j] == 0) {
					continue;
				}

				for (int l = 1; l <= m; l++) {
					if (j + l > n*m) {
						continue;
					}

					dp[i + 1][j + l] += dp[i][j];
				}
			}
		}

		int sum = 0;

		for (int i = 0; i <= n*m; i++) {
			sum += max(i - k, 1)*dp[n][i];
		}

		printf("%.8f\n", (double)sum / pow(m, n));

	}

	return 0;
}

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

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String Line1=reader.readLine();
        String Line2=reader.readLine();
      	char tmp1[],tmp2[];
      	tmp1 = new char[3];
      	tmp2 = new char[3];
     	int count = 0;
		for(int i=0; i<3; i++){
			tmp1[i] = Line1.charAt(i);
          	tmp2[i] = Line2.charAt(i);
			if(tmp1[i] == tmp2[i]){
			count ++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21332
import java.util.Scanner;
public class Main{
    public void solve(){
    Scanner sc = new Scanner(System.in);
    int t,n;
        for(int i=0;i<=3;i++){
        t = sc.nextInt();
        n = sc.nextInt();
        if(t==1){
            int kei = 6000*n;
            System.out.println(kei);
        }else{
            if(t==2){
                int kei = 4000*n;
                System.out.println(kei);
                }else{
                    if(t==3){
                        int kei = 3000*n;
                        System.out.println(kei);
                        }else{
                        int kei = 2000*n;
                        System.out.println(kei);
                    }
            }
        }
    }
    }
        public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

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

int main(void){
   
  int x,y;
  int A[] = {1,3,5,7,8,10,12};
  int B[] = {4,6,9,10};
  int C[] = {2};
  
  cin >> x >> y;
  if( find(begin(A),end(A), x) != end(A) &&  find(begin(A),end(A), y) != end(A) ){
      cout << "Yes" <<endl;
  }
  else if(find(begin(B),end(B), x) != end(B) &&  find(begin(B),end(B), y) != end(B)){
cout << "Yes" <<endl;
  }
  else if(find(begin(C),end(C), x) != end(C) &&  find(begin(C),end(C), y) != end(C)){
cout << "Yes" <<endl;
  }
  else{
      cout << "No" <<endl;
  }
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int height;
	int hankei;
} doll_t;

int qsort_comp(const void* x,const void* y) {
	const doll_t* a=(const doll_t*)x;
	const doll_t* b=(const doll_t*)y;
	if((a->height)>(b->height))return 1;
	if((a->height)<(b->height))return -1;
	if((a->hankei)>(b->hankei))return 1;
	if((a->hankei)<(b->hankei))return -1;
	return 0;
}

int qsort_comp2(const void* x,const void* y) {
	const doll_t* a=(const doll_t*)x;
	const doll_t* b=(const doll_t*)y;
	if((a->hankei)>(b->hankei))return 1;
	if((a->hankei)<(b->hankei))return -1;
	if((a->height)>(b->height))return 1;
	if((a->height)<(b->height))return -1;
	return 0;
}

int doll_num;
doll_t dolls[200];

int new_dolls_length[200];
int new_dolls_length2[200];

int main(void) {
	int doll_num_a,doll_num_b;
	int i,j;
	int result;
	while(1) {
		scanf("%d",&doll_num_a);
		if(doll_num_a==0)break;
		for(i=0;i<doll_num_a;i++) {
			scanf("%d%d",&dolls[i].height,&dolls[i].hankei);
		}
		scanf("%d",&doll_num_b);
		for(i=0;i<doll_num_b;i++) {
			scanf("%d%d",
				&dolls[doll_num_a+i].height,&dolls[doll_num_a+i].hankei);
		}
		doll_num=doll_num_a+doll_num_b;
		qsort(dolls,doll_num,sizeof(doll_t),qsort_comp);
		for(i=0;i<doll_num;i++) {
			new_dolls_length[i]=1;
			for(j=0;j<i;j++) {
				if(dolls[j].height<dolls[i].height &&
						dolls[j].hankei<dolls[i].hankei &&
						new_dolls_length[i]<new_dolls_length[j]+1) {
					new_dolls_length[i]=new_dolls_length[j]+1;
				}
			}
		}
		qsort(dolls,doll_num,sizeof(doll_t),qsort_comp2);
		for(i=0;i<doll_num;i++) {
			new_dolls_length2[i]=1;
			for(j=0;j<i;j++) {
				if(dolls[j].height<dolls[i].height &&
						dolls[j].hankei<dolls[i].hankei &&
						new_dolls_length2[i]<new_dolls_length2[j]+1) {
					new_dolls_length2[i]=new_dolls_length2[j]+1;
				}
			}
		}
		result=new_dolls_length[doll_num-1];
		if(result<new_dolls_length2[doll_num-1]) {
			result=new_dolls_length2[doll_num-1];
		}
		printf("%d\n",result);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int x[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    Int k;
    cin >> k;
    cout << x[k-1] << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(n) for(int i=0;i<n;i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;


int main() {
	
	int n,cnt=0;
	
	cin >> n;
	
	int a[2001];
	rep(n) { cin >> a[i]; } sort(a, a + n);

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

				if (abs(a[i] - a[j]) < a[k] && a[k] < a[i] + a[j]) {
					cnt++;
					//cout << a[i] << a[j] << a[k] << endl;
				}
				else break;
			}
		}
	}
	cout << cnt << endl;
	
	return 0;
}


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

using namespace std;
using ll = long long;

int n, q;


int f(string s, vector<pair<char,char>> op) {

    if(!count(op.begin(), op.end(), make_pair(s[0],'L'))) {
        return 0;
    }


    
    int lef = 0, rig = n; //oooooxxx
    while(rig - lef > 1) {
        int mid = (lef + rig) / 2;
        int pos = mid;
        bool ok = false;
        for(int i = 0; i < q; i++) {
            if(op[i].first == s[pos]) {
                (op[i].second == 'R' ? pos++ : pos--);
                if(pos < 0){ok = true;break;}
                if(pos >= n)break;
            }
        }
        (ok ? lef : rig) = mid;
    }
    return rig;
}


int main()
{
    string s;
    cin >> n >> q >> s;
    vector<pair<char,char>> op(q);
    for(int i = 0; i < q; i++)cin >> op[i].first >> op[i].second;

    int lef = f(s, op); //xxxoooで何個落ちるか
    reverse(s.begin(), s.end());
    for(int i = 0; i < q; i++)op[i].second = (op[i].second == 'R' ? 'L' : 'R');
    int rig = f(s, op); //xxxoooの右端


    cout << n - min(rig + lef, n) << endl;


}

Measured memory_bytes: 4452
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  if(N%3!=0){
  bool x=true;
    for(int i=0;i<N;i++)
      if(A.at(i)!=0){x=false; break;}
    if(x)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  
  }else{
  sort(A.begin(),A.end());
    set<int64_t>S1; set<int64_t>S2; set<int64_t>S3;
  int k=N/3;
    for(int i=0;i<k;i++)
      S1.insert(A.at(i));
    for(int i=k;i<(2*k);i++)
      S2.insert(A.at(i));
    for(int i=(2*k);i<N;i++)
      S3.insert(A.at(i));
      int a=S1.size();
    int b=S2.size();
    int c=S3.size();
    if(a!=1 || b!=1 || c!=1)
      cout<<"No"<<endl;
    else{
    int64_t n=A.at(0); int64_t m=A.at(k); int64_t l=A.at(2*k);
      if((n^m^l)==0)
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
    
    }
  
  
  
  
  }
   return 0;
}


Measured memory_bytes: 4480
#include<stdio.h>
#include<string.h>
int solve(int n);
int main(){
    char S[200005];
    char T[200005];
    scanf("%s\n%s",S,T);
    int i,cnt=0,l=strlen(S);
    for(i=0;i<l;i++){
        if(S[i]!=T[i]) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}
int solve(int n)
{
    return n+n*n+n*n*n;
}


Measured memory_bytes: 2100
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n, ma, mb = list(map(int, input().split()))
abc = [None]*n
for i in range(n):
    a,b,c = tuple(map(int, input().split()))
    abc[i] = (a*mb - b*ma, c)
abc.sort()
def halfcomb(l):
    n = len(l)
    n1 = n//2
    n2 = (n+1)//2
    l1 = []
    l2 = []
    def sub(v1, v2, i, bound, ll, ind=0):
        if i==bound:
            ll.append((v1,v2))
            return
        sub(v1, v2, i+1, bound, ll, ind)
        sub(v1+l[ind+i][0], v2+l[ind+i][1], i+1, bound, ll, ind)
    sub(0, 0, 0, n1, l1)
    sub(0, 0, 0, n2, l2, ind=n1)
    return l1, l2
l1, l2 = halfcomb(abc)
d2 = {}
for v,c in l2:
    if v in d2:
        d2[v] = min(d2[v], c)
    else:
        d2[v] = c
ans = float("inf")
for v,c in l1:
    if v==0 and c>0:
        ans = min(ans, c)
for v,c in l2:
    if v==0 and c>0:
        ans = min(ans, c)
        
for v,c in l1:
    if -v in d2 and c+d2[-v]>0:
        ans = min(ans, c+d2[-v])
if ans == float("inf"):
    ans = -1
print(ans)

Measured memory_bytes: 188620
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut a:char = read!();
    let mut b: [char; 26] = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
    for i in 0..26 {
        if a==b[i] {
            println!("{}",b[i+1]);
        }
    }
}

Measured memory_bytes: 2084
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#define N 210
#define M 10000020
using namespace std;
int prime[M],link[N],tot;
bool p[M],vis[N];
int n;
bool can[N][N],s[M];
vector<int>v[2];
bool check(int u)
{
	for(int i=1;i<=v[1].size();i++)
	if(can[u][i] && !vis[i])
	{
		vis[i]=1;
		if(!link[i] || check(link[i]))
 		{
			link[i]=u;
			return true;
		}
	}
	return false;
}
int main()
{
	p[1]=true;
	for(int i=2;i<=M-10;i++)
	{
		if(!p[i]) prime[++tot]=i;
		for(int j=1;j<=tot && i*prime[j]<=M-10;j++)
		{
			p[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int u;
		scanf("%d",&u);
		s[u]=true;
	}
	for(int i=1;i<=M-10;i++)
	if(s[i]^s[i-1]) v[i&1].push_back(i);
	for(int i=0;i<v[0].size();i++)
		for(int j=0;j<v[1].size();j++)
		if(!p[abs(v[0][i]-v[1][j])]) can[i+1][j+1]=true;
	int ans=0;
    for(int i=0;i<v[0].size();i++)
	{
		memset(vis,0,sizeof(vis));
		ans+=check(i+1);
	}
	int tmp=ans;
	ans+=(v[0].size()-ans)/2*2+(v[1].size()-ans)/2*2;
    if((v[0].size()&1)!=(tmp&1)) ans+=3;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 20864
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
  return x;

}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
  
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    return u;
  if(k < u->key)
    return treeSearch(u->left,k);
  else
    return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  if(x->right != NIL)
    return treeMinimum(x->right);

  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;

  if(x != NIL)
    x->parent = y->parent;

  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;
  
  z->parent = y;
  
  if(y != z)
    z->key = y->key;


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL ){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }


  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25164
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    for(int i = 0; i < h; i++) cin >> s[i];

    int ans = 1 << 30;

    for(int bit = 0; bit < (1 << (h - 1)); bit++) {
        bool check = true;
        for(int j = 0; j < w; j++) {
            int tmp = 0;
            for(int i = 0; i < h; i++) {
                if(s[i][j] == '1') tmp++;
                if(tmp > k) check = false;
                if(bit & (1 << i)) tmp = 0;
            }
        }

        if(!check) continue;

        int tmp = 0;
        int sum[h] = {};
        for(int j = 0; j < w; j++) {
            int id = 0;
            for(int i = 0; i < h; i++) {
                if(s[i][j] == '1') sum[id]++;
                if(bit & (1 << i)) id++;
            }

            //kを超える列が存在するか
            bool ex = false;
            for(int i = 0; i < h; i++) {
                if(sum[i] > k) {
                    ex = true;
                }
            }

            if(ex) {
                tmp++;
                for(int i = 0; i < h; i++) {
                    sum[i] = 0;
                }
                j--;
                continue;
            }
        }

        for(int i = 0; i < h; i++) {
            if(bit & (1 << i)) tmp++;
        }

        ans = min(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(s) (intt)s.size()

#define ms0(arr) memset(arr,0,sizeof arr)
#define ms63(arr) memset(arr,63,sizeof arr)

#define forn(i,a,b) for(intt i=a;i<=b;i++)
#define rofn(i,a,b) for(intt i=a;i>=b;i--)
#define setf(it,myset) for(set<intt>::iterator it=myset.begin();it!=myset.end();it++)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define VI vector<intt>
#define PII pair<intt,intt>
#define VPII vector< PII >

#define posl(ch) (int)(ch-'a'+1)
#define posL(ch) (int)(ch-'A'+1)

#define IO ios_base::sync_with_stdio(false);cin.tie();
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a,intt b){return __gcd(a, b);}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}

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

bool isSubSequence(string str1, string str2, int m, int n)
{
   int j = 0;
   for (int i=0; i<n&&j<m; i++)
       if (str1[j] == str2[i])
         j++;
   return (j==m);
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt n;
    cin >> n;
    string s[51], ans = "";
    forn (i, 1, n) {
        cin >> s[i];
        sort (all (s[i]));
    }
    string bir = s[1];
    forn (i, 0, bir.size() - 1) {
        intt flag[51];
        memset (flag, 0, sizeof flag);
        forn (j, 2, n) {
            forn (k, 0, s[j].size() - 1)
                if (s[j][k] == bir[i]) {
                    flag[j] = 1;
                    s[j][k] = '%';
                    break;
                }
        }
        intt ff = 1;
        forn (j, 2, n)
            if (!flag[j])
                ff = 0;
        if (ff)
            ans += bir[i];
    }
    //sort (all (ans));
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    int A, B, h = 100, w = 100;
    char ans[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w / 2; j++) {
            ans[i][j] = '.';
            ans[i][w - j - 1] = '#';
        }
    }

    cin >> A >> B;
    A--, B--;
    for (int i = 0; i < B; i++) {
        ans[i / 25 * 2][i % 25 * 2] = '#';
    }
    for (int i = 0; i < A; i++) {
        ans[i / 25 * 2][i % 25 * 2 + 51] = '.';
    }
    cout << h << " " << w << endl;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
            cout << ans[i][j];
        cout << endl;
    }
}


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

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

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  vll a(n),b(n);
  REP(i,n)cin>>a[i];
  REP(i,n)cin>>b[i];

  vll c(n+1),d(n+1);
  REP(i,n)c[a[i]]++;
  REP(i,n)d[b[i]]++;

  for(ll i=1; i<=n; i++){
    if(n+1<=c[i]+d[i]){
      no;
      return 0;
    }
  }

  REP(i,n)c[i+1]+=c[i];
  REP(i,n)d[i+1]+=d[i];


  ll diff=0;
  for(ll i=1; i<=n; i++)
    diff=max(diff,c[i]-d[i-1]);

  yes;
  REP(i,n){
    if(i!=0)
      cout<<" ";
    cout<<b[(n+i-diff)%n];
  }
  cout<<endl;
}



Measured memory_bytes: 9536