akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define FOR(i,l,r) for(int i=l;i<=r;++i)
#define REP(i,l,r) for(int i=l;i<r;++i)

inline int read(){
	int ss=0,ff=1; char chr=getchar();
	while(chr<'0'||chr>'9') {if(chr=='-') ff=-1; chr=getchar();}
	while('0'<=chr&&chr<='9') ss=(ss<<3)+(ss<<1)+chr-'0',chr=getchar();
	return ss*ff;
}

const int N=107;
int a,b,n,m,c[507][507];

int main(){
	cout<<100<<' '<<100<<endl;
	cin>>a>>b;
	for(int i=1;i<=100;++i)
		for(int j=1;j<=100;++j)
			if(j<=50) c[i][j]=0;
				else c[i][j]=1;
	a--; b--;
	for(int i=1;i<=100;i+=2)
		for(int j=1;j<=50;j+=2)
			if(b){
				b--;
				c[i][j]=1;
			}
	for(int i=1;i<=100;i+=2)
		for(int j=52;j<=100;j+=2)
			if(a){
				a--;
				c[i][j]=0;
			}
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j)
			if(c[i][j]==0) cout<<'.';
				else cout<<'#';
		cout<<endl;
	}
}

Measured memory_bytes: 512
#include <cstdio>

using i32 = int;
using i64 = long long;
constexpr i32 maxn = 100000;

inline int in() {
	static int n;
	scanf("%d", &n);
	return n;
}

char s[maxn + 1];

i32 main() {
	scanf("%s", s + 1);
	i32 ans = 0;
	for (i32 i = 2; s[i]; ++i)
		if (s[i - 1] != s[i]) ++ans;
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 3304
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
string s;
long long n, f[4][100000]; // 0 ? 1 A 2 AB 3 ABC

int main(){
    cin >> s;
    n = s.size() - 1;
    f[0][-1] = 1;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= 3; j++){
            f[j][i] = f[j][i-1];
            if (s[i] == '?') f[j][i] = (f[j][i]*3)% mod;
            if (j > 0 && (s[i] == '?' || s[i] - 'A' + 1 == j)){
                f[j][i] = (f[j][i] + f[j-1][i-1])% mod;
            }
        }
    }
    cout << f[3][n];
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <cstring>

using namespace std;

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

int main() {
    char S[51];
    char T[51];
    scanf("%s", S);
    scanf("%s", T);

    int s_len = (int)strlen(S);
    int t_len = (int)strlen(T);

    if (t_len > s_len) {
        printf("UNRESTORABLE\n");
        return 0;
    }

    bool done = false;
    int index = 0;
    RREP(s_len - t_len + 1, i) {
        done = true;
        REP(j, t_len) {
            if (! (S[i + j] == T[j] || S[i + j] == '?')) {
                done = false;
                break;
            }
        }

        if (done) {
            index = i;
            break;
        }
    }

    if (done) {
        REP(i, s_len) {
            if (i == index) {
                // printf("i = %d\n", i);
                REP(j, t_len) {
                    S[index + j] = T[j];
                }
                i += t_len - 1;
            } else {
                // printf("i = %d\n", i);
                S[i] = (S[i] == '?') ? 'a' : S[i];
            }
        }
        printf("%s\n", S);
    } else {
        printf("UNRESTORABLE\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; ++i) cin >> h[i];
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    bool ok = true;
    for (int j = 0; j < i; ++j) {
      if (h[j] > h[i]) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
  return 0;
}

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


n = int(input())
a = list(map(int, input().split()))
s = set(a)
if len(s)>2:
    ans = "No"
elif len(s)==2:
    if max(s)-min(s)!=1:
        ans = "No"
    else:
        x = max(s)
        n2 = sum(num==x-1 for num in a)
        if x-n2>0 and n2 + 2*(x-n2) <= n:
            ans = "Yes"
        else:
            ans = "No"
else:
    x = max(s)
    if x==n-1 or 2*x<=n:
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Measured memory_bytes: 97740
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        (n, h, w): (i32, i32, i32),
        ab: [(i32, i32); n]
    };
    
    let mut ans = 0;
    for (a, b) in ab {
        if(a>=h && b>=w){
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2180
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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;
}


int N, A, B, C;
int l[10];

int main () {
  cin >> N >> A >> B >> C;

  Rep(i, N) {
    cin >> l[i];
  }

  int ans = INF;

  Rep(num, pow(4, N)) {
    int tmp = 0;
    int tmp_a = 0;
    int tmp_b = 0;
    int tmp_c = 0;

    Rep(i, N) {
      int cri = (num >> (2 * i)) % 4;

      if (cri % 4 == 0) {
        if (tmp_a != 0) tmp += 10;
        tmp_a += l[i];
      } else if (cri % 4 == 1) {
        if (tmp_b != 0) tmp += 10;
        tmp_b += l[i];
      } else if (cri % 4 == 2) {
        if (tmp_c != 0) tmp += 10;
        tmp_c += l[i];
      }
    }

    tmp += (abs(A - tmp_a) + abs(B - tmp_b) + abs(C - tmp_c));

    if (tmp_a != 0 && tmp_b != 0 && tmp_c != 0) {
      ans = min(tmp, ans);
    }
  }

  cout << ans << "\n";
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  llong n;
  cin >> n;

  llong ans = 0;
  for(llong i = 1; i <= 1000000; ++i){
    if((n-i) % i == 0){
      llong m = (n-i) / i;
      if(m > 0 && n / m == n % m)
        ans += m;
    } 
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	Scanner input = new Scanner(System.in);
    	while(input.hasNext()){
    		int a = input.nextInt();
    		int b = input.nextInt();
    		int n = input.nextInt();
    		System.out.println(doub(a,b,n));
    	}
    }
    
    public static int doub(int a,int b,int n){
    	double frac = (double)a/b;
    	int sum = 0;
    	String fracst = String.valueOf(frac);
    	int index = fracst.indexOf(".")+1;
    	for(int i = index ; i <= index+n-1 ; i++){
    		if(i < fracst.length()){
    			sum += fracst.charAt(i)-48;
    		}
    	}
    	return sum;
    }
}

Measured memory_bytes: 20264
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b; cin>>a>>b;
  string s;cin>>s;
  bool flag=true;
  for(int i=0;i<a+b+1;i++){
    if(i<a && !(isdigit(s[i]))) flag=false;
    if(i==a && s[i]!='-') flag=false;
    if(i>a && !(isdigit(s[i]))) flag=false;
  }
  if(flag) cout <<"Yes"<<endl;
  else cout <<"No" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define ll long long
#define inf LLONG_MAX
using namespace std;
int n,ans,k,a[100004];
vector<int> q;
signed main(){
	cin>>n;
	cin>>a[0];
	q.push_back(a[0]);
	for(int i=1;i<n;i++){
		cin>>a[i];
		int basho=lower_bound(q.begin(),q.end(),a[i])-q.begin()-1;
		if(basho<0){
			q.insert(q.begin(),a[i]);
		}else{
			q[basho]=a[i];
		}
	}
	cout<<q.size()<<endl;
	//for(int i=0;i<3;i++){cout<<q[i]<<endl;}
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

map<string, int> ns, ms;

int main()
{
    int n;
    cin >> n;
    vector<string> s_vec;
    rep(i, n){ 
        string s; cin >> s;
        s_vec.push_back(s);
        if (ns.find(s) == ns.end()){
            ns.insert({s, 1});        
        } else {
            ns[s] += 1;
        }
    }
    int m;
    cin >> m;
    rep(i, m){ 
        string s; cin >> s;
        if (ms.find(s) == ms.end()){
            ms.insert({s, 1});        
        } else {
            ms[s] += 1;
        }
    }
    int ans_max = 0;
    rep(i, n){
        int ans = 0;
        string key = s_vec[i];
        //cout << key << endl;
        if (ns.find(key) != ns.end()){
            ans += ns[key];
        }
        if (ms.find(key) != ms.end()){
            ans -= ms[key];
        }
        ans_max = max(ans_max, ans);
    }
    cout << ans_max << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int a, b, c;
    cin >> a >> b >> c;

    if(b - a == c - b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    n = int(input())

    if 1 <= n <= 999:
        print("ABC")
    else:
        print("ABD")

main()


Measured memory_bytes: 5056
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> as;
    for (int i = 0; i < n; ++i) {
        int b;
        cin >> b;
        as.push_back(b);
    }
    map<int, int> odd;
    map<int, int> even;
    bool isOdd = false;
    for (auto a : as) {
        if (isOdd) {
            odd[a]++;
        } else {
            even[a]++;
        }
        isOdd = !isOdd;
    }
    int oddMax = 0;
    int oddMax2 = 0;
    int oSel = -1;
    for (auto a : odd) {
        auto b = a.second;
        if (b > oddMax) {
            if (oddMax > oddMax2) {
                oddMax2 = oddMax;
            }
            oddMax = b;
            oSel = a.first;
        } else if (b > oddMax2) {
            oddMax2 = b;
        }
    }
    int evenMax = 0;
    int evenMax2 = 0;
    int eSel = -1;
    for (auto a : even) {
        auto b = a.second;
        if (b > evenMax) {
            if (evenMax > evenMax2) {
                evenMax2 = evenMax;
            }
            evenMax = b;
            eSel = a.first;
        } else if (b > evenMax2) {
            evenMax2 = b;
        }
    }
    if (oSel == eSel) {
        if (oddMax > evenMax) {
            cout << n - oddMax - evenMax2 << endl;
            return 0;
        }
        if (evenMax > oddMax) {
            cout << n - evenMax - oddMax2 << endl;
            return 0;
        }
        if (evenMax2 > oddMax2) {
            cout << n - oddMax - evenMax2 << endl;
        } else {
            cout << n - oddMax2 - evenMax << endl;
        }
        return 0;
    }
    cout << n - oddMax - evenMax << endl;
    return 0;
}


Measured memory_bytes: 5368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define line cout<<"\n"
#define ci std ::cin
#define co std ::cout
#define sf scanf
#define sff(n,m) scanf("%d%d",&n,&m)
#define pf printf
#define p_line printf("\n")
#define cas(n) printf("Case %d: ",n++)
#define task return
#define loop(x,n)  for(int x = 0 ; x < n ; x++)
#define constloop(x,a,n) for(int x = a ; x < n ; x++)
#define revloop(x,a,n)  for(int x = a ; x >= n ; x--)
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
#define mx 10000000
/*ll P[mx+5],cnt=1;
bool nP[mx+5];
void sieve(void)
{
    P[0]=2;
    nP[0]=true;
    nP[1]=true;
    for(ll i=3 ; i<=mx ; i+=2)
    {
        if(nP[i]==true)
            continue;
        for(ll j=i+i ; j<=mx ; j+=i)
            nP[j]=true;
        P[cnt++]=i;
    }
}*/
int dp[100000+5];
int A[100000+5];
int n,k;
int dpcall(int pos)
{
	if(pos>=n-1)
		return 0;
	if(dp[pos]!=-1)
		return dp[pos];
	vector<int>v;
	for(int i=1 ; i<=k ; i++)
	{
		if(pos+i<n)
		{
			v.pb(abs(A[pos]-A[pos+i])+dpcall(pos+i));
		}
	}
	int ans=INT_MAX;
	for(int i=0 ; i<v.size() ; i++)
	{
		ans=min(ans,v[i]);
	}
	return dp[pos]=ans;
}
void solve()
{
    //Code here
 	ci>>n>>k;
 	for(int i=0 ; i<n ; i++)
 	{
 		ci>>A[i];
 	}
 	memset(dp,-1,sizeof(dp));
 	co<<dpcall(0);
 	line;
}
int main()
{
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	/*ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);*/
	solve();
	return 0;
}

Measured memory_bytes: 16860
num = int(input())
L = []
al = ["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 xx in range(num):
	lis = []
	S = input()
	for yy in range(26):
		LL = S.count(al[yy])
		lis.append(LL)
	L.append(lis)
st = ""
for i in range(26):
	xxx = []
	for j in range(num):
		xxx.append(L[j][i])
	nn = min(xxx)
	st += al[i] * nn
print(st)


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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

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

    int ans = 0;
    for(int i = 0; i < n - 2; i++) {
        for(int j  = i + 1; j < n - 1; j++) {
            int idx = lower_bound(v.begin(), v.end(), v[i] + v[j]) - v.begin();
            ans += max(0, idx - j - 1);
        }
    }

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



Measured memory_bytes: 3592
#include <math.h>
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	int n = 0;
	//double ave = 0, sum = 0;	
	while (cin >> n,n != 0) {
		int temp[1001];
		double ave = 0, sum = 0;
		memset(temp, 0, sizeof(temp));
		int cnt = n;
		while (cnt) {
			cin >> temp[n - cnt];
			sum += temp[n - cnt];
			cnt--;
		}
		ave = sum / n;
		double db = 0;
		for (int i = 0; i < n; i++) {
			db += pow(temp[i] - ave, 2);
		}
		cout << fixed << sqrt(db / n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3240
#include<iostream>
#include<cstdio>
#include<cmath>
#define int long long
using namespace std;
int n,ans;
double d;
signed main(){
	scanf("%lld%lf",&n,&d);
	for(int i=1,x,y;i<=n;i++){
		scanf("%lld%lld",&x,&y);
		double res=sqrt(x*x+y*y);
		if(res<=d)	ans++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
int f[100001]={0},a[100001],n,i;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=2;i<=n;i++)
	{
		if(i==2)
		{
			f[i]=abs(a[i]-a[i-1])+f[i-1];
			continue;
		}
		f[i]=min(abs(a[i]-a[i-1])+f[i-1],abs(a[i]-a[i-2])+f[i-2]);
	}
	printf("%d",f[n]);
	return 0;
}

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

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){

        int n = sc.nextInt();
        String s = sc.next();
        int count = 0;

        for(int i = 0; i < n - 2; i++){
            if(s.substring(i, i+3).equals("ABC")) count++;
        }

        System.out.println(count);

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

    boolean is_prime(long a){
        if(a <= 1) return false;
        for(int i = 2; i*i <= a; i++){
            if(a % i == 0) return false;
        }
        return true;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


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

int rec(int n, int p, int s) {
  if(s < 0) return 0;
  if(n == 0) return s == 0;
  int res = 0;
  for(; p <= 9; ++p) {
    res += rec(n-1, p+1, s-p);
  }
  return res;
}

int main() {
  int n, s;
  while(cin >> n >> s && (n|s)) {
    cout << rec(n,0,s) << endl;
  }
  return 0;
}

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

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


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
    
int par[100000];
    
void init(int);
int dep(int);
int inp(void);
   
char *p;
char in[1500000];
int tree[100000][15],idx[100000];
   
int main(){
  int n,i,j,id,k,c;
   
  fread(in,sizeof(in),1,stdin);  
  p = in;
   
  n = inp(); init(n);
  for(i = 0 ; i < n ; i++){
    id = inp();
    k = inp();
    for(j = 0 ; j < k ; j++){
      c = inp();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
    
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],dep(i));
       
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }
   
    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
  return 0;
}
   
void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}
   
int dep(int x){
  if(par[x] == -1) return 0;
  return dep(par[x]) + 1;
}
   
int inp(){
  int v = 0;
  while(!isdigit(*p)) ++p;
  v = *p++&15;
  while(isdigit(*p)){
    v = (v<<3)+(v<<1)+(*p++&15);
  }
  return v;
}

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

int main() {
    fixed(cout);

    int n, k; cin >> n >> k;
    vector<double> csum(n + 1);
    csum[0] = 0;

    for (int i = 1; i <= n; ++i) {
        int p; cin >> p;
        auto ave = (p * (p + 1) / 2) / double(p);

        csum[i] = csum[i - 1] + ave;
    }

    double ans = 0;
    for (int i = k; i <= n; ++i) {
        ans = max(ans, csum[i] - csum[i - k]);
    }

    cout << ans << endl;
}



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

int N;
pii A[100100];

signed main() {
    cin >> N;
    rep(i, N) {
        int a;
        cin >> a;
        ++a;
        A[i] = pii(a, i + 1);
    }
    sort(A, A + N);
    rep(i, N) {
        cout << A[i].second;
        if (i != N - 1)cout << " ";
        else cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2432
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

ll N, K;
vector<ll> A;

void solve() {
  vector<ll> r;
  map<ll, ll> seen;
  rep(i, N) { seen[i] = -1; }

  ll idx = 0;
  ll len = 0;

  while (true) {
    if (seen[idx] != -1) {
      break;
    }
    if (K <= len) {
      cout << idx + 1 << endl;
      return;
    }

    seen[idx] = len;
    r.push_back(idx);
    idx = A.at(idx);
    len++;
  }

  ll d;
  if (K - seen[idx] >= 0) {
    if (len - seen[idx] <= 0) {
      d = seen[idx] + (K - seen[idx]);
    } else {
      d = seen[idx] + (K - seen[idx]) % (len - seen[idx]);
    }
  } else {
    d = K;
  }
  cout << r.at(d) + 1 << endl;
}

int main() {
  cin >> N >> K;
  A.resize(N);
  rep(i, N) {
    cin >> A.at(i);
    A.at(i)--;  // 0-indexed
  }

  solve();

  return 0;
}


Measured memory_bytes: 19404
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;

int main()
{
	fast
	ll t, k, mn;
	cin>>t>>k;
	mn=min(t%k,abs((t%k)-k));
	cout<<mn<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
#define PI 3.14159265 
using namespace std;
 
int main()
{
	int sum = 0;
	string s, t;

	cin >> s >> t;

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != t[i])
		{
			sum++;
		}
	}

	cout << sum;

  	return 0;
}

Measured memory_bytes: 3912
#include <stdio.h>
#include <math.h>
int main (int argc, char * argv[])
{
    int a,b,c;
    double rad;
    double S,L,h;
    double PI = acos(-1);
    scanf("%d %d %d",&a,&b,&c);
    rad = c*PI/180;
    S = (a*b*sin(rad))/2;
    L = a+b+sqrt(pow(a,2)+(pow(b,2)-2*a*b*cos(rad)));
    h = b*sin(rad);
    printf("%f\n",S);
    printf("%f\n",L);
    printf("%f\n",h);
    return 0;
}



Measured memory_bytes: 2112
// AtCoder Beginner Contest 092 - Problem D: Grid Components (https://atcoder.jp/contests/abc092/tasks/arc093_b)
#include <bits/stdc++.h>

using namespace std;

const int MAX { 100 };

vector<string> solve(int A, int B)
{
    vector<string> ans(MAX, string(MAX, '.'));

    int x = 0, y = 0;

    if (A > 1)
        B--;

    // A região conectada bracn é um ponto branco envolto por uma borda preta
    while (--A)
    {
        if (y + 1 >= MAX)
        {
            y = 0;
            x += 3;
        }

        for (int i = 0; i < 3; ++i)
            for (int j = 0; j < 3; ++j)
                ans[x + i][y + j] = '#';

        ans[x + 1][y + 1] = '.';
        y += 3;
    }


    // A região conectada preta é um ponto envolto por uma borda branca
    while (B--)
    {
        if (y + 1 >= MAX)
        {
            y = 0;
            x += 3;
        }

        ans[x + 1][y + 1] = '#';

        y += 3;
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;

    cout << MAX << ' ' << MAX << '\n';

    auto ans = solve(A, B);

    for (const auto& x : ans)
        cout << x << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
  double a,b,c,PI = 3.14159265359;
  cin >> a >> b >> c;
  printf("%f\n",a*b*sin(PI/180.0*c)/2.0);
  printf("%f\n",a+b+sqrt(a*a+b*b-2*a*b*cos(PI/180.0*c)));
  printf("%f\n",b*sin(PI/180.0*c));
  return 0;
}


Measured memory_bytes: 3476
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e15;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const ll MOD = 1000000007;
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; }
int main(void) {
    int n, a, b; cin >> n >> a >> b;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    ll right = MOD * 5,left = 0;
    while (right - left > 1) {
        ll mid = (right + left) / 2, cnt = 0;
        rep(i, n) {
            ll sum = max(h[i] - b * mid, 0LL);
            if (sum != 0) cnt += (sum - 1) / (a - b) + 1;
        }if (cnt > mid) left = mid;
        else right = mid;
    }cout << right << endl;
}

Measured memory_bytes: 3956
#include<iostream>
//#include<map>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
using namespace std;

static const ll mod  = 1e9 + 7;
static const ll inf  = 1e18;

void printvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b){
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
} 

int main(){
    int n, m;
    cin >> n >> m;
    int a, b;
    vector<pair<int,int> > pairs, pairs1;

    //代入
    REP(i,m){
        cin >> a >> b;
        pairs.push_back(make_pair(a,b));
    }

    //b順にソート
    sort(ALL(pairs), compare_by_b);

    int k = 0, cnt = 0;
/*
    for(int i = 0; i < pairs.size()-1; i++){
        if(pairs[i].first == pairs[i+1].first){
            pairs.erase(pairs.begin() + i + 1);
            i--;
        }
    }


    for(int i = 0; i < pairs.size()-1;){
        if(pairs[i].second >= pairs[i+1].second){
            pairs.erase(pairs.begin() + i);
        }
        else{
            i++;
        }
    }
*/

    int lastBridgeBreak = 0;

    for(auto pair : pairs){
        int left = pair.first;
        int right = pair.second;

        if(lastBridgeBreak < left){
            //if(lastBridgeBreak < right - 1){
                lastBridgeBreak = right - 1;
                cnt++;
            //}
        }
    }

    p(cnt);
/*
    REP(i,pairs.size()){
        cout << pairs[i].first << " " << pairs[i].second << endl;
    }
    for(int i = 0; i < pairs.size() ;i++){
        if(pairs[k].second <= pairs[i].first ){
            k = i;
            cnt++;
        }
    }
    p(cnt);
    */
}

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

int check(void);

#define INIT    0
#define NO      1

int main() {

    int W       =INIT;
    int H       =INIT;
    int x       =INIT;
    int y       =INIT;
    int r       =INIT;
    int flag    =INIT;

    //data input
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
    
    if (x < r) {
        flag = check();
    }

    if (y < r) {
        flag = check();
    }

    if ((x + r) > W) {
        flag = check();
    }

    if ((y + r) > H) {
        flag = check();
    }

    if (flag == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout <<  "No" << endl;
    }
}

int check(void)
{
    return NO;
}

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

void solve()
{
    int n, w = 0, r = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            r++;
        else
            w++;
    }
    int c = 0;
    for (int i = 0; i < r; i++)
    {
        if (s[i] == 'W')
            c++;
    }
    cout << min(r, min(w, c));
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	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> p(n, -1), d(n, -1);
	p[0] = -1;
	d[0] = 0;
	queue<Int> q;
	q.push(0);
	while(!q.empty()){
		Int v = q.front(); q.pop();
		for(auto t:g[v])
			if(d[t] == -1){
				p[t] = v;
				d[t] = d[v] + 1;
				q.push(t);
			}
	}
	Int m; cin >> m;
	vector<Int> u(m), v(m);
	for(Int i=0; i<m; ++i){
		cin >> u[i] >> v[i];
		--u[i]; --v[i];
	}
	vector<Int> l(m);
	for(Int i=0; i<m; ++i){
		Int x = u[i], y = v[i];
		if(d[x] < d[y])
			swap(x, y);
		while(d[x] > d[y])
			x = p[x];
		while(x != y){
			x = p[x];
			y = p[y];
		}
		l[i] = x;
	}
	Int ans = 0;
	vector<Int> w;
	for(Int b=0; b<(1ll<<m); ++b){
		Int cnt = 0;
		w.assign(n, 0);
		for(Int i=0; i<m; ++i)
			if((b >> i) & 1){
				++cnt;
				Int x = u[i], y = v[i];
				while(x != l[i]){
					w[x] = 1;
					x = p[x];
				}
				while(y != l[i]){
					w[y] = 1;
					y = p[y];
				}
			}
		Int nw = 0;
		for(Int i=0; i<n; ++i)
			nw += w[i];
		ans += (1-2*(cnt%2)) * (1ll << (n-1-nw));
	}
	cout << ans << "\n";
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int n; cin >> n;
    vector<int> c(n-1), s(n-1), f(n-1);
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
    
    rep(i,n-1){
        int t = s[i] + c[i];
        reps(j,i+1,n-2){
            t = max(ceiv(t,f[j]) * f[j], s[j]);
            t += c[j];
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}

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

int main() {
    int a,b,k,i;
    vector<int> common;
    cin >> a >> b >> k;
    i = b;

    while(i != 0) {
        if((a % i == 0) && (b % i == 0)) {
            common.push_back(i);
            //cout << i << endl;
        }
        --i;

    }
    cout << common.at(k - 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
 
int main(){
 int n ; cin>>n ;
 vector<int> A(n) ;
 vector<int> B(n) ;
 rep(i,n){
   cin>> A[i] ;
   B[i] =A[i] ;
 }
   sort(B.begin(),B.end()) ;
   rep(i,n){
     if(A[i]<=B[(n/2)-1] )
     cout<<B[n/2]<<endl ;
     else cout<<B[(n/2)-1]<<endl ;
   }
    return 0;
  }

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

const int MOD=1e9+7;

int mod_add(int a, int b)
{
    return ((a%MOD)+(b%MOD))%MOD;
}

int solve(int const &H, int const &W, vector<vector<int> > &dp, vector<string> const &maze)
{
    map<pair<int,int>, bool> visited;
    queue<pair<int,int> > q;
    q.push({0,0});
    dp[1][1]=1;
    for(int i=1 ; i<=H ; ++i)
    {
        for(int j=1 ; j<=W ; ++j)
        {
            if(maze[i-1][j-1]=='.')
            {
                dp[i][j]=mod_add(mod_add(dp[i][j],dp[i-1][j]),dp[i][j-1]);
            }
        }
    }
    return dp[H][W];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H,W;
    cin>>H>>W;
    vector<vector<int> > dp(H+4,vector<int>(W+4,0));
    vector<string> maze(H);
    for(int i=0 ; i<H ; ++i)
    cin>>maze[i];
    cout<<solve(H,W,dp,maze)<<endl;
    return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>
#define N 8
#define notfree 1
#define free 0

int queen[N],col[N],dpos[N*2-1],dneg[N*2-1],h[N];

void setQueen(int i){

  int j;

  if(i == N) {
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
	if(j == queen[i])printf("Q");
	else printf(".");
      }
      printf("\n");
    }
    return;
  }

  if(h[i] != -1){
    setQueen(i+1);
    return;
  }

  for(j=0;j<N;j++){
    if(col[j] == notfree || dpos[i+j] == notfree || dneg[i-j+N-1] == notfree) continue;

    queen[i]=j;
    col[j]=notfree;
    dpos[i+j]=notfree;
    dneg[i-j+N-1]=notfree;

    setQueen(i+1);

    col[j]=free;
    dpos[i+j]=free;
    dneg[i-j+N-1]=free;
    
  }
  
}

int main(){

  int i,j,k,r,c;

  scanf("%d",&k);

  for(i=0;i<N;i++)h[i]=-1;

  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    queen[r]=c;
    col[c]=notfree;
    dpos[r+c]=notfree;
    dneg[r-c+N-1]=notfree;
    h[r]=c;
    }

  setQueen(0);

  return 0;
}



Measured memory_bytes: 2112
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

struct Node {
    int id;
    int parent;
    int left;
    int right;
    int depth;
    int height;
};

#define MAX(x, y) ((x) > (y) ? (x) : (y))

static int FindRoot(const struct Node nodes[], int n) {
    int i;

    for ( i = 0; i < n; i++ ) {
        if ( nodes[i].parent == -1 ) {
            return nodes[i].id;
        }
    }

    assert( 0 );

    return -1;
}

static int UpdateDepthAndHeight(int root, struct Node nodes[], int n) {
    int height_l = 0;
    int height_r = 0;

      /* left */
    if ( (nodes[root].left == -1) && (nodes[root].right == -1) ) {
        nodes[root].height = 0;        
        return 0;
    }

    if ( nodes[root].left != -1 ) {
        int left = nodes[root].left;

        nodes[left].depth = nodes[root].depth + 1;

        height_l = UpdateDepthAndHeight(left, nodes, n) + 1;        
    }

    if ( nodes[root].right != -1 ) {
        int right = nodes[root].right;

        nodes[right].depth = nodes[root].depth + 1;

        height_r = UpdateDepthAndHeight(right, nodes, n) + 1;
    }
    
    nodes[root].height = MAX(height_l, height_r);

    return nodes[root].height;
}


static const char* GetType(const struct Node* p_node) {
    if ( p_node->parent == -1 ) {
        return "root";
    }

    if ( (p_node->left == -1) && (p_node->right == -1) ) {
        return "leaf";
    }

    return "internal node";
}

int main(void) {
    int i;
    int n;
    int id, left, right;
    struct Node* nodes;

    scanf("%d\n", &n);

    nodes = malloc(sizeof(struct Node) * n);

      /* init */
    for ( i = 0; i < n; i++ ){
        nodes[i].id = -1;
        nodes[i].parent = nodes[i].left = nodes[i].right = -1;
        nodes[i].depth = nodes[i].height = 0;
    }

    for ( i = 0; i < n; i++ ) {
        scanf("%d %d %d\n", &id, &left, &right);

        nodes[id].id = id;

        nodes[id].left  = left;
        if ( left != -1 ) {
            nodes[left].parent = id;
        }
        
        nodes[id].right = right;
        if ( right != -1 ) {
            nodes[right].parent = id;
        }
    }

    int root = FindRoot(nodes, n);

    UpdateDepthAndHeight(root, nodes, n);

    for ( i = 0; i < n; i++ ) {
        int id = nodes[i].id;
        int parent = nodes[i].parent;
        int sibling = parent == -1 ?
            -1 : 
            nodes[parent].left == id ? nodes[parent].right : nodes[parent].left;
        int degree = (nodes[i].left != -1) + (nodes[i].right != -1);
        int depth = nodes[i].depth;
        int height = nodes[i].height;
        const char* type = GetType(&nodes[i]);
        
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
               id, parent, sibling, degree, depth, height, type);
    }

    free(nodes);

    return 0;
}



Measured memory_bytes: 2128
import sys
s = input()
for i in range(len(s)//2):
    if s[i] != s[len(s) - i - 1]:
        print("No")
        sys.exit(0)
for i in range((len(s) - 1)//4):
    if s[i] != s[(len(s) - 1)//2 - i - 1]:
        print("No")
        sys.exit(0)
print("Yes")

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

// iがa以上b以下ならtrueを返す関数
bool ch(int i, int a, int b){
  if (a<=i && i<=b) return true;
  else return false;
}

int main() {
  int n; cin >>n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >>a.at(i);
  vector<int> color(9);
  
  for (int i=0; i<n; i++){
    int j = a.at(i);
    if         (ch(j,1,399))  color.at(0)=1;
    else if  (ch(j,400,799))  color.at(1)=1;
    else if (ch(j,800,1199))  color.at(2)=1;
    else if (ch(j,1200,1599)) color.at(3)=1;
    else if (ch(j,1600,1999)) color.at(4)=1;
    else if (ch(j,2000,2399)) color.at(5)=1;
    else if (ch(j,2400,2799)) color.at(6)=1;
    else if (ch(j,2800,3199)) color.at(7)=1;
    else                      color.at(8)++;
  }
  
  int min=0;
  for (int i=0; i<8; i++) min += color.at(i);
  int max = min + color.at(8);
  if (min == 0) min = 1;
  
  cout <<min <<" " <<max <<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        int k = scan.nextInt();
        System.out.println(solve(s, k));
    }

    public static String solve(String s, int k) {
        StringBuilder sb = new StringBuilder(s);
        List<String> all_candidate_list = new ArrayList<>();
        for(int i = 1; i <= k; i++) {
            all_candidate_list.addAll(substring(sb, i));
        }
        String[] all_candidates = all_candidate_list.toArray(new String[0]);
        Arrays.sort(all_candidates);
        return all_candidates[k-1];
    }

    public static List<String> substring(StringBuilder sb, int length) {
        HashSet<String> answer = new HashSet<>();
        for (int i = 0; i < sb.length(); i++) {
            if (sb.length() < i + length) {
                continue;
            }
            String x = sb.substring(i, i+length);
            if (!answer.contains(x)) {
                answer.add(x);
            }
        }
        List<String> substrings = new ArrayList<>();
        for(String s: answer) {
            substrings.add(s);
        }
        return substrings;
    }
}


Measured memory_bytes: 26836
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

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

  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  string result;
  for(int i=0;i<2*n;i++){
    if(i%2==0){
      result+=s[i/2];
    }else{
      result+=t[i/2];
    }
  }
  cout<<result<<endl;



  return 0;
}

Measured memory_bytes: 888
#include <cstdio>

constexpr unsigned int InputSize = 3e6;
unsigned char Input[InputSize];
unsigned char* pointer = Input;

inline unsigned int getInt(void){
    unsigned int res = 0; while(*pointer < '0') ++pointer;
    do{
        res = 10 * res + ((*pointer) - '0');
    } while(*(++pointer) >= '0');
    return res;
}

unsigned int n;
unsigned int N;
constexpr unsigned int SIZE = (1U << 19) + 1;
unsigned int data[2 * SIZE];

inline void set(void){
    N = 1; while(N < n) N <<= 1;
    while(*pointer < 'a') ++pointer;
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j){ 
        unsigned char idx = *(pointer++) - 'a'; data[j] = 1U << idx;
    }
    for(; i < N; ++i, ++j) data[j] = 0;
    for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1U];
}

inline void query(void){
    while(*pointer < '0') ++pointer;
    if(*(pointer++) == '1'){
        unsigned int index = getInt() - 1;
        while(*pointer < 'a') ++pointer;
        unsigned char idx = *(pointer++) - 'a';
        data[index += N] = 1U << idx;
        while(index >>= 1) data[index] = data[index << 1] | data[(index << 1) | 1U];
    }
    else{
        unsigned int l = getInt() + N - 1, r = getInt() + N;
        unsigned int res = 0;
        while(l < r){
            if(l & 1) res |= data[l++]; l >>= 1;
            if(r & 1) res |= data[--r]; r >>= 1;
        }
        printf("%u\n", __builtin_popcount(res));
    }
}

int main(void){
    fread(Input, sizeof(unsigned char), InputSize, stdin);
    n = getInt(); set(); 
    unsigned int q = getInt();
    while(q--) query();
    return 0;
}


Measured memory_bytes: 6144
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()

table = dp2(0, 10, 10)

for i in range(1, N+1):
    head = int(str(i)[0])
    tail = int(str(i)[-1])
    table[head][tail] += 1
#print(table)
cnt = 0
for i in range(10):
    for j in range(10):
        cnt += table[i][j] * table[j][i]
        #if i == j:
            #cnt += table[i][j]

print(cnt)

Measured memory_bytes: 3064
#include"stdio.h"
#include"string.h"
#include"stack"
#include"map"
#include"math.h"
#include"iostream"
#include"vector"
#include"queue"
#include"algorithm"
using namespace std;
#define OK printf("\n");
#define Debug printf("this_ok\n");
#define INF 1e18
typedef long long ll;
#define scanll(a,b) scanf("%lld%lld",&a,&b);
#define scanl(a) scanf("%lld",&a);
#define printl(a,b) if(b == 0) printf("%lld ",a); else printf("%lld\n",a);
#define print_int(a,b) if(b == 0) printf("%d ",a); else printf("%d\n",a);
typedef pair<int,int> PII;

inline int read(){
    int s = 0, w = 1; char ch = getchar();
    while(ch < '0' || ch > '9')   { if(ch == '-') w = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') { s = (s << 3) + (s << 1) + (ch ^ 48); ch = getchar(); }
    return s * w;
}
const ll mod = 1e9+7;
const int N = 500010,M = 300010;
const  double pi = acos(-1);
const int inf = 1 << 29;
const int dirx[4] = {-1,0,1,0};

char str[N],t[N];
int a[N],sum[N];
int Find(int x){
    if(x == a[x]) return x;
    return a[x] = Find(a[x]);
}
int main(){
  int n = read(),m = read();
  for(int i = 1; i<= n; i ++) {a[i] = i;sum[i] = 1;}
  for(int i = 1; i <= m; i ++){
    int x = read(),y = read();
    int fx = Find(x),fy = Find(y);
    if(fx == fy) continue;
    a[fx] = fy;
    sum[fy] += sum[fx];
  }
  int ans = 0;
  for(int i = 1; i <= n; i ++){
    if(i != a[i]) continue;
    ans = max(ans,sum[i]);
  }
  printf("%d\n",ans);
}
/*
3
1 2 3
2
2 6
*/



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

class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){roll(1,2,4,3);}
  void roll_y(){roll(0,2,5,3);}
  void roll_x(){roll(0,1,5,4);}
  void roll(int i,int j,int k,int l){
      int t=f[i];f[i]=f[j];f[j]=f[k];f[k]=f[l];f[l]=t;
  }
};

int getRight(Cube c1,int f1,int f2){
    for(int i=0;i<6;i++){
        for(int j=0;j<4;j++){
            if(c1.f[0]==f1&&c1.f[1]==f2)return c1.f[2];
            c1.roll_z();
        }
        if(i%2==0)c1.roll_y();
        else c1.roll_x();
    }
    return -1;
}

int main(){
    Cube c;
    int f1,f2;
    
    for(int i=0;i<6;i++)cin>>c.f[i];
    int q; cin>>q;
    
    for(int i=0;i<q;i++){
        cin>>f1>>f2;
        cout<<getRight(c,f1,f2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104