akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
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; }
 
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
 
int h,w;
vector<string> g(25);
 
int bfs(int y, int x){
  int cost[25][25];
  rep(i,h) rep(j,w) cost[i][j]=-1;
  cost[y][x]=0;
  queue<pii> q;
  q.push(pii(y,x));
  int res=0;
  while(!q.empty()){
    pii now=q.front();
    q.pop();
    rep(i,4){
      int ny=now.first+dy[i];
      int nx=now.second+dx[i];
      if(inside(ny,nx,h,w) && g[ny][nx]=='.' && cost[ny][nx]==-1){
        q.push(pii(ny,nx));
        cost[ny][nx]=cost[now.first][now.second]+1;
        chmax(res,cost[ny][nx]);
      }
    }
  }
  return res;
}
 
signed main()
{
  cin>>h>>w;
  rep(i,h) cin>>g[i];
  
  int ans=0;
  rep(i,h){
    rep(j,w){
      if(g[i][j]=='#')continue;
      chmax(ans,bfs(i,j));
    }
  }
  cout<<ans<<endl;
}

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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll big = 10e10 + 11 ;

int  main (  ) {

    FASTIO ;

    string s ;
    cin >> s ;

    int l = s.size( ) ;

    while( l-- )cout << "x" ;

    return  0 ;
}



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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m,K;

int ned[22][22][2];

ll f[(1<<19)+5],g[(1<<19)+5];

void Work(){
	f[0]=1;
	REP(i,0,m-1)
		REP(j,0,n-1){
			memcpy(g,f,sizeof(f));memset(f,0,sizeof(f));
			REP(sta,0,(1<<n)-1)if(g[sta]%=mod){
				int c=(sta>>j)&1;
				if(c){
					if(!ned[i][j][0])f[sta]+=g[sta];
				}
				else{
					if(!ned[i][j][1])f[sta]+=g[sta];
					if(!ned[i][j][0]){
						int nxt=sta;
						nxt&=((1<<n)-1)^((1<<j)-1);
						int pos=nxt&(-nxt);
						nxt=sta^pos;
						nxt^=1<<j;
						f[nxt]+=g[sta];
					}
				}
			}
		}
	ll ans=0;
	REP(sta,0,(1<<n)-1)ans+=f[sta]%mod;
	iout(ans%mod);
}

void Init(){
	read(n,m,K);n--;
	REP(i,1,K){
		int x,y,z;
		read(x,y,z);
		ned[x-1][y-1][z]=1;
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll a,b,c,k; cin>>a>>b>>c>>k;
    ll ans = 0;
    ll t = min(a,k);
    ans += t;
    k -= t;
    k -= b;
    ans -= max(k,0ll);

    cout << ans << '\n';
    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);

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

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

    int ali = 0, bob = 0;
    for(int i = 0; i < n; i++){
        if(i % 2 == 0)  ali += a[i];
        else    bob += a[i];
    }

    cout << abs(ali - bob) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

int main() {
	int n; cin >> n;
	vector<string> s(3);
	for (int i = 0; i < 3; i++) cin >> s[i];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < 3; j++) {
			cnt += s[j][i] != s[(j + 1) % 3][i];
		}
		if (cnt > 0) ans += cnt - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
main = do
  a <- readLn
  b <- readLn
  print $ func a b

func a b 
  | (a == 1 && b == 2) || (a == 2 && b == 1) = 3
  | (a == 1 && b == 3) || (a == 3 && b == 1) = 2
  | otherwise = 1

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

#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()

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() {

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N)cin >> A[i];

    sort(all(A));
    deque<pair<int, int>> que;
    que.push_back(make_pair(A[0], false));
    rep(i, N - 1) {
        --que[0].first;
        int dif = A[i + 1] - A[i];
        if(dif % 2 == 0) {
            que.back().first++;
            que.back().second ^= true;
            if(dif > 0)que.push_back(make_pair(dif, false));
        } else que.push_back(make_pair(dif + 1, false));
        if(que[0].first == 0)que.pop_front();
    }

    int num;
    bool flag;
    tie(num, flag) = que.front();
    cout << (num % 2 == 1 xor flag ? "Second\n" : "First\n");
    return 0;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
	// Your code goes here.
	int n, k;
	cin>>n>>k;
	if (k%2 ==1)
    {
        cout<<"No"<<endl;
        return;
    }else
    {
        int x=0;

        if (k%4 == 0)
        {
            for (int i=(k/4); i<=(k/2); i++)
            {
                if (i==n)
                {
                    //cout<<i<<" "<<n<<endl;
                    x=1;
                    cout<<"Yes"<<endl;
                    return;
                }
            }
        }else
        {
            for (int i=((k/4)+1); i<=(k/2); i++)
            {
                if (i==n)
                    {
                        x=1;
                        cout<<"Yes"<<endl;
                        return;
                    }
            }
        }



    if (x==1)
        {
            cout<<"Yes"<<endl;
        }else if (x==0)
        {
            cout<<"No"<<endl;
        }else
        {
            return;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T; // If only one test case then you can comment this line out.

    while (T--)
    {
        solve();
    }

    return 0;
}


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

int x,y,s;
int tax(int r,int p);

int tax(int r,int p){ //r????¨????(%)???p????¨??????????
	return floor(p*(100+r)/100);
}

int main(){
	int maximum;
	while(cin>>x>>y>>s && x>0){
		maximum = 0;
		for(int i=1; i<s; i++){
			for(int j=1; j<s; j++){
				if((tax(x,i)+tax(x,j))==s){
					maximum = max(maximum, tax(y,i)+tax(y,j));
				}
			}
		}
	cout << maximum << endl;
	}
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		pr.println(Math.min(a * n,  b));
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 20948
#include<stdio.h>
#include<stdlib.h>
int sort(const int *a,const int *b){
return *a-*b;
}
int main(void){
int n;
  scanf("%d",&n);
  int d[n];
  for(int i=0;i<n;i++){
    	scanf("%d",&d[i]);
  }
qsort(d,n,sizeof(int),sort);
  
  printf("%d",d[n/2]-d[n/2-1]);
  return 0;
}     

Measured memory_bytes: 892
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define forn(i, n) for(int i=0;i<(n);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int main() {
	fastio;
	ll n, k;
	cin >> n >> k;
	int cnt = 0;
	while(n>0) {
		n /= k;
		cnt++;
	}
	cout << cnt;
}

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

vector<int> factor(int n) {
    vector<int> factors;
    for (int p = 2; p * p <= n; ++p) {
        while (n % p == 0) {
            factors.push_back(p);
            n /= p;
        }
    }
    if (n > 1) {
        factors.push_back(n);
    }
    return factors;
}

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


    li n;
    cin >> n;
    li ans = 0;
    for (li c = 1; c < n; ++c) {
        li ab = n - c;
        map<li, li> factors;
        for (auto p: factor(ab)) {
            factors[p]++;
        }
        li sub = 1;
        for (auto p: factors) {
            sub *= p.second + 1;
        }
        ans += sub;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int n, ans = 0;
string s;

int main(){
    cin >> n >> s;
    rep(i, n-1) {
        if(s[i] != s[i+1]) ++ans;
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long a, b, c;
    cin >> a >> b >> c;

    long long A = 4 * a * b;
    long long B = c - a - b;
    bool res = false;
    const long long MX = 2LL * 1000000001LL;
    if (B >= 0) {
        if (B >= MX) {
            res = true;
        } else {
            B *= B;
            if (B > A) {
                res = true;
            }
        }
    } else {

    }

    if (res) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final long MOD = 1000000007;
	public static final int TEN = 10;
	public static void main(String[] args) {
		int i=0,j=0;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int k = parseInt(sc.next());
		boolean[] f = new boolean[TEN];
		for (i = 0; i < k; i++) {
			f[parseInt(sc.next())]=true;
		}
		sc.close();
		int tmp=n;
		while(true) {
			tmp=n;
			while(tmp!=0) {
				if(f[tmp%10]) break; 
				tmp/=10;
			}
			if(tmp==0)break;
			n++;
		}
		out.println(n);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
ll fact[50];
#define eps 1e-9
#define INF 1e18
ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=ans*a%c;
    }
    a=a*a%c;
    b=b/2;
  }
  return ans;
}
ll ncr(ll n,ll r){
    if(r>n)return 0;
    if(r==n)return 1;
    ll z=fact[n];
    z=z*power(fact[r],mod-2,mod)%mod;
    z=z*power(fact[n-r],mod-2,mod)%mod;
    return z;
}
ll min(ll a,ll b){return a<b?a:b;}
ll max(ll a,ll b){return a>b?a:b;}
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
       
            int r; cin>>r;
            double res=2*22*r/7.0;
            printf("%.18lf\n",res );
        
        return 0;
}


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

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define seq vector
signed main(){
    
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    for (int i =0; i< tx -sx;i++){
        cout << "R";
    }
    for (int i =0; i< ty -sy;i++){
        cout << "U";
    }

    for (int i =0; i< tx -sx;i++){
        cout << "L";
    }
    for (int i =0; i< ty -sy;i++){
        cout << "D";
    }


    cout << "D";

    for (int i =0; i<= tx -sx;i++){
        cout << "R";
    }
    for (int i =0; i<= ty -sy;i++){
        cout << "U";
    }
    cout << "L";

    cout << "U";
    for (int i =0; i<= tx -sx;i++){
        cout << "L";
    }
    for (int i =0; i<= ty -sy;i++){
        cout << "D";
    }

    cout << "R" << endl;



}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
	int h,r;
	cin>>h>>r;
	if(h>=0)
		cout<<'1'<<endl;
	else if(r+h<0)
		cout<<"-1"<<endl;
	if(r+h==0)
		cout<<"0"<<endl;
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MK make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;
const int N=1010, dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
char s[N][N];
int n,m, d[N][N];
bool vis[N][N];
int main(){
	scanf("%d%d", &n, &m);
	for (int i=0; i<n ; ++i) scanf("%s", s[i]);
	queue<PII> q;
	for (int i=0; i<n; ++i)
		for (int j=0; j<m; ++j)
			if ( s[i][j] =='#')	q.push(MK(i,j)), d[i][j]=0, vis[i][j]=true;
	int ans=0;
	while ( q.size()){
		int x=q.front().fi, y=q.front().se; q.pop();
		for (int i=0, _x, _y; i<4; ++i){
			_x=x+dx[i]; _y=y+dy[i];
			if ( _x<0 ||_x>=n ||_y<0 || _y>=m || vis[_x][_y]) continue;
			d[_x][_y] = d[x][y]+1;
			ans= max(ans, d[_x][_y]);
			vis[_x][_y]=true;
			q.push(MK(_x,_y));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 14352
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Created by vikas.k on 25/12/16.
 */
public class Main {
    public static void main(String[] args){
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = sc.nextInt();

        List<Integer> lst = new ArrayList<>();
        for(int i=0;i<2*n;i++){
            lst.add(sc.nextInt());
        }

        Collections.sort(lst);
        int cnt = 0;
        for(int i=0;i<lst.size();i+=2){
            cnt+= Math.min(lst.get(i),lst.get(i+1));
        }
        out.println(cnt);
        out.close();
    }
    public static PrintWriter out;

    private static class MyScanner{
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private MyScanner(){
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next(){
            if(stringTokenizer == null || !stringTokenizer.hasMoreElements()){
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt(){
            return Integer.parseInt(next());
        }
        private String nextLine(){
            String ret= "";
            try {
                ret= bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }
}


Measured memory_bytes: 8404
import java.util.Scanner;
public class Main {

	static int r;
	static int s;
	static int p;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		r = sc.nextInt();
		s = sc.nextInt();
		p = sc.nextInt();
		
		char []hand = sc.next().toCharArray();
		
		int [][]dp = new int [n+1][2];
		
		for(int i = 0 ; i < n ;i++) {
			if(i - k < 0) {
				dp[i][1] += jdg(hand[i]);
			}
			else {
				if(hand[i] != hand[i-k]) {
					dp[i][1] += jdg(hand[i]) + Math.max(dp[i-k][0], dp[i-k][1]);
				}
				else{
					dp[i][1] += dp[i-k][0] + jdg(hand[i]);
					dp[i][0] += dp[i-k][1];
				}
			}
		}
		
		
		int ans = 0;
		
		for(int i = 0 ; i < k ;i++) {
			ans += Math.max(dp[n-1-i][0], dp[n-1-i][1]);
		}
		
		System.out.println(ans);
		
	}
	static int jdg(char k) {
		if(k == 'r') {
			return p;
		}
		if(k == 's') {
			return r;
		}
			return s;
	}
		

}


Measured memory_bytes: 30344
n = STDIN.gets.to_i
sequence = STDIN.gets.split[0...n].map(&:to_i)
m = STDIN.gets.to_i
questions = STDIN.gets.split[0...m].map!(&:to_i)

combined = []
1.upto(n) do |i|
	sequence.combination(i).each { |e| combined << e.inject(:+) }
end
questions.each { |q| puts combined.include?(q) ? "yes" : "no" }

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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<vector<ll>> G(n);
    for(ll i=0; i<n-1; i++) {
        ll u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    vector<ll> idx(n, -1);
    {
        auto dfs = [&](auto dfs, ll cur, ll pre, ll i) -> void {
            idx[cur] = i;
            for(auto &v: G[cur]) {
                if(v == pre) continue;
                dfs(dfs, v, cur, i^1);
            }
        };
        dfs(dfs, 0, -1, 0);
    }

    vector<ll> t(2);
    for(auto x: idx) t[x]++;
    ll m = min(t[0], t[1]);
    if(3*m >= n) {
        ll ma = t[0] < t[1] ? 1 : 0;
        ll x = 1, y = 2, z = 3;
        for(ll i=0; i<n; i++) {
            auto &w = idx[i] == ma ? x : y;
            cout << (w <= n ? w : z) << ' ';
            (w <= n ? w : z) += 3;
        }
        cout << endl;
    } else {
        ll mi = t[0] < t[1] ? 0 : 1;
        ll x = 1, y = 2, z = 3;
        for(ll i=0; i<n; i++) {
            auto &w = idx[i] == mi ? z : (x <= n ? x : y <= n ? y : z);
            cout << w << ' ';
            w += 3;
        }
    }
}


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

char s1[10] , s2[10] ,s3[10] ;
scanf ("%s%s%s", s1,s2,s3)  ; 
char c1,c2,c3;

c1=s1[0] ;
c2=s2[0] ;
c3=s3[0] ;

 putchar(toupper(c1) ) ;
 
putchar(toupper(c2)); 
putchar(toupper(c3)); 






return 0;
}

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

using namespace std;

int main(){
    int n;
    while(cin >> n, n != -1){
	int res = 1150;
	n -= 10;
	res += 125 * max(0, min(10, n));
	n -= 10;
	res += 140 * max(0, min(10, n));
	n -= 10;
	res += 160 * max(0, n);
	cout << 4280 - res << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void)
{
    int S,A,B,C,D;
    scanf("%d",&S);
    A = S/1000;
    B = S/100-A*10;
    C = S/10-A*100-B*10;
    D = S%10;
    if(A == B || B == C || C == D){
        printf("Bad");
    }else{
        printf("Good");
    }
}

Measured memory_bytes: 1736
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int* A = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int mini = i;
    for (int j = i+1; j < N; j++) {
      if (A[j] < A[mini]) {
        mini = j;
      }
    }

    if (i != mini) {
      int tmp = A[i];
      A[i] = A[mini];
      A[mini] = tmp;
      cnt++;
    }
  }

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

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1188
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1e9 + 7;
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

const int MX = 1e7;

ll s;
ll ans = 0;

ll get(ll x) {
	ll lb = 1;
	ll rb = 9;
	ll ans = 0;
	for (int i = 1; lb <= x; ++i, lb *= 10, rb = rb * 10 + 9) {
		ans += (min(x, rb) - lb + 1) * i;
	}
	return ans;
}

int get2(ll x) {
	int cnt = 0;
	while (x)
		x /= 10, ++cnt;
	return cnt;
}

int main() {
	cin >> s;
	//s = ll(1e8);
	vector<int> vv;
	for (int i = 1; i * i <= s; ++i)
		if (s % i == 0) {
			vv.push_back(i);
			if (i * i != s)
				vv.push_back(s / i);
		}
	sort(vv.begin(), vv.end());
	for (int i: vv) {
		if (i < 8)
			continue;
		ll go = 9 * pw(10, i - 1) % MOD;
		ans = (ans + go - (s / i)) % MOD;
	}
	ans = (ans + s / 8) % MOD;
	ll lb = 1;
	ll rb = ll(1e8);
	while (rb - lb > 1) {
		ll mid = (lb + rb) >> 1;
		if (get(mid) <= s)
			lb = mid;
		else
			rb = mid;
	}
	ll cur = get(lb);
	ll now = lb;
	for (int i = 1; i < MX; ++i) {
		while (cur < s)
			++now, cur += get2(now);
		if (cur == s)
			++ans;
		cur -= get2(i);
	}
	ans %= MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
a = [input() for _ in range(N)]
b = [input() for _ in range(M)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            for l in range(M):
                if a[i + k][j + l] != b[k][l]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int a[5][5];
int vis[100][100];
int main()
{
	int number;
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> number;
		for(int j=1;j<=3;j++)
		{
			for(int k=1;k<=3;k++)
			{
				if(number==a[j][k])
				{
					vis[j][k] = 1;
				}
			}
		}
	}
	int flag = 0;
	if(vis[1][1]&&vis[2][2]&&vis[3][3]) flag=1;
	if(vis[1][3]&&vis[2][2]&&vis[3][1]) flag=1;
	if(vis[1][1]&&vis[1][2]&&vis[1][3]) flag=1;
	if(vis[2][1]&&vis[2][2]&&vis[2][3]) flag=1;
	if(vis[3][1]&&vis[3][2]&&vis[3][3]) flag=1;
	if(vis[1][1]&&vis[2][1]&&vis[3][1]) flag=1;
	if(vis[1][2]&&vis[2][2]&&vis[3][2]) flag=1;
	if(vis[1][3]&&vis[2][3]&&vis[3][3]) flag=1;
	if(flag) cout <<"Yes";
	else cout <<"No";
	return 0;
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

signed main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << nl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

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

  sort(v.begin(), v.end());
  double ans = (v[0] + v[1]) / 2.0;
  //cout << ans << endl;
  for (int i=2; i<n; i++) {
    ans = (ans + v[i]) / 2.0;
  }
  cout << ans << endl;
}


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

int main()
{
    string s;
    cin >> s;
    if (s[s.size()-1] != 's') cout << s + 's' << endl;
    else cout << s + "es" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	ll n, x[100], y[100], h[100], cnt=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> x[i] >> y[i] >> h[i];
		if(h[i]>0){
			cnt++;
		}
	}
	if(n==1){
		cout << x[0] <<" "<< y[0] <<" "<< h[0] << endl;
		return 0;
	}
	if(n==2){
		if(h[0]>h[1]){
			cout << x[0] <<" "<< y[0] <<" "<< h[0] << endl;
		} else {
			cout << x[1] <<" "<< y[1] <<" "<< h[1] << endl;
		}
		return 0;
	}
	bool flag;
	for(int i=0; i<=100; i++){
		for(int j=0; j<=100; j++){
			ll a=0;
			flag=true;
			for(int k=0; k<n; k++){
				if(h[k]>0){
					if(a==0){
						a=abs(x[k]-i)+abs(y[k]-j)+h[k];
						if(cnt==1){
							cout << x[k] <<" "<< y[k] <<" "<< h[k] << endl;
							return 0;
						}
					} else {
						ll b=abs(x[k]-i)+abs(y[k]-j)+h[k];
						if(a!=b){
							flag=false;
						}
					}
				}
			}
			if(flag){
				cout << i <<" "<< j <<" "<< a << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void){ 
  int n;
  cin >> n;
  int a,b;
  cin >> a >> b;
  
  if(n == 1) cout << "Hello World";
  else cout << a + b;
  
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	vector<ll>a(n); REP(i, n)a[i] = in();
	vector<bool>light(n, false);
	ll now = 1;
	ll cnt = 0;
	while (true) {
		if (light[now - 1]) {
			cout << -1 << endl;
			return 0;
		}
		light[now - 1] = true;
		now = a[now - 1];
		++cnt;
		if (now == 2) {
			cout << cnt << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1152
n, m = map(int, input().split())

rl = [[] for x in range(n + 1)]

for _ in range(m):
    a, b = map(int, input().split())
    rl[a].append(b)
    rl[b].append(a)

now = 1
next_node = rl[now]
if n in next_node or n == 1:
    print("POSSIBLE")
    __import__("sys").exit()


for node in next_node:
    if n in rl[node]:
        print("POSSIBLE")
        __import__("sys").exit()
print("IMPOSSIBLE")


Measured memory_bytes: 38296
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define ci(n) cin >> n
#define ci2(n, o) cin >> n >> o
#define ci3(n, o, p) cin >> n >> o >> p
#define co(n) cout << n << endl
#define mp(n, o) map<n, o>

int main() {
  int N, D, a = 0;
  ci2(N, D);
  ve(ve(int)) X(N, ve(int)(D));
  rep(i, N) {
    rep(j, D) {
      cin >> X.at(i).at(j);
    }
  }
  rep(i, N) {
    repi(j, i + 1, N) {
      int p = 0;
      rep(k, D) {
        p += pow((X.at(i).at(k) - X.at(j).at(k)), 2.0);
      }
      rep(k, p + 1) {
        if(k * k == p) {
        a++;
        }
      }
    }
  }
  co(a);
} 

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Data.List (foldl')

main :: IO ()
main = do
  n <- readLn
  unless (n==0) $ do
    solve <$> map read <$> words <$> getLine >>= putStrLn
    main

solve :: [Int] -> String
solve (x:xs) = unwords $ g $ foldl' f ((x,x),[]) xs
  where f ((a,b),ys) z | b+1 == z = ((a,z),ys)
                       | otherwise = ((z,z),(a,b):ys)
        g (x,y) = map h $ reverse (x:y)
        h (x, y) | x == y = show x
                 | otherwise = show x ++ "-" ++ show y



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

int main() {
  using std::vector;
  int n, m, l;
  std::cin >> n >> m >> l;
  vector<vector<int>> a(n, vector<int>(m, 0)), b(m, vector<int>(l, 0));
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      std::cin >> a[i][j];
    }
  }
  
  for (int j = 0; j < m; j++) {
    for (int k = 0; k < l; k++) {
      std::cin >> b[j][k];
    }
  }
  
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < l; k++) {
      long long cik = 0;
      for (int j = 0; j < m; j++) {
        cik += a[i][j]*b[j][k];
      }
      if (k != 0) std::cout << " ";
      std::cout << cik;
    }
    std::cout << "\n";
  }
  
  return 0;
}

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

int main(){
    string s;cin>>s;
    int ans=0;
    if(s.find("R")!=string::npos){
        ans=1;
    }
    if(s.find("RR")!=string::npos){
        ans=2;
    }
    if(s.find("RRR")!=string::npos){
        ans=3;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3520
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ans = (((n+m)*(n+m-1))/2) - (n*m);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;


#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(),i.end()
#define debug(i) std::cout << i << "\n"



const int INF = 100000000;
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;
    if(y%2){
        return (x*pow_mod(x,y-1,mod))%mod;
    }else{
        return pow_mod(x*x,y/2,mod);
    }
}

int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
    ll n;
    std::cin >> n;
    std::vector<ll> a(n);
    rep(i,0,n){
        std::cin >> a[i];
    }
    ll ans = 0, max = -1;
    rep(i,1,n){
        if(ans<a[i]){
            ans = a[i];
            max = i;
        }
    }
    std::cout << ans << "\n";
    if(a[0]>=ans){
        rep(i,1,n){
            std::cout << a[0] << "\n";
        }
    }else{
        rep(i,1,n){
            if(i!=max){
                std::cout << ans << "\n";
            }else{
                ll ans2 = 0;
                rep(j,0,n){
                    if(j!=max){
                        ans2 = std::max(ans2, a[j]);
                    }
                }
                std::cout << ans2 << "\n";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<int, int, int> T;
// get<K>(tuple型の変数)



class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;
    int count;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
        count = n;
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;
        --count;

        return true;
    }
};

const ll MAX=110000;

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

    int n; cin >> n;
    UnionFind uni(2*MAX);
    vector<int> x(n), y(n);
    rep(i, n){
        cin >> x[i] >> y[i];
        uni.connect(x[i], y[i]+MAX);
    }

    map<int, ll> mx, my;
    rep(i, MAX) ++mx[uni.root(i)];
    repr(i, MAX, 2*MAX) ++my[uni.root(i)];
    ll res=0;
    rep(r, 2*MAX) res += mx[r]*my[r];
    cout << res-n << endl;

    return 0;
}


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

// 構造体を宣言
struct Node {
    // 自分のなまえ
    int key;
    // 子(右) 子(左) 親 のポインタ
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
    // 構造体yに構造体NILを代入
    Node *y = NIL;
    // 構造体xに構造体rootを代入
    Node *x = root;
    // 構造体zを出す
    Node *z;

    // 構造体zと構造体分のメモリを確保して新しく宣言した構造体を対応させる
    z = (Node *)malloc(sizeof(Node));
    // 構造体zのkeyにkを入力する
    z->key   = k;
    // 構造体zの子を両方NILにする
    z->left  = NIL;
    z->right = NIL;

    // 一番下に行くまで(番兵が出るまで)分岐して行く
    while(x != NIL) {
        // 構造体yに構造体xを代入する
        y = x;
        // 参照するキーより小さかったら左に、大きかったら右の子へ移動する
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    // 構造体yを構造体zのparentに入れる
    // z->parent = y;
    // 構造体yがNILだった場合(木が空の場合)rootにzを代入する
    if(y == NIL) {
        root = z;
    }
    // 挿入するところのノードと挿入するやつでどっちが大きいかによって左右分ける
    // 挿入するやつの方が小さかったら左、大きかったら右
    else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

// 中間順巡回 (Inorder Tree Walk)
void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
// 先行順巡回 (Preorder Tree Walk)
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(void) {
    int n, i, x;
    // 文字列を取得するための配列を宣言
    char com[16];
    // ノードの個数を取得
    scanf("%d",&n);

    for(i=0;i<n;i++) {
        // 文字列を取得
        scanf("%s",com);
        // 文字列がinsertだった場合
        if(!strcmp(com,"insert")) {
            // 挿入する数字を取得
            scanf("%d",&x);
            // 挿入する
            insert(x);
        }
        // 文字列がprintだった場合
        else if(!strcmp(com,"print")) {
            // 中間順巡回(inorder tree walk)を出力
            inorder(root);
            printf("\n");
            // 先行順巡回(preorder tree walk)を出力
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}

/*
8
insert 30
insert 88
insert 12
insert 1
insert 20
insert 17
insert 25
print
*/


Measured memory_bytes: 25228
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<string>in(n);
		rep(i,n)cin>>in[i];
		int co=0;
		int x=0,y=0;
		while(co!=1e6){
			co++;
			if(in[x][y]=='>')y++;
			else if(in[x][y]=='<')y--;
			else if(in[x][y]=='^')x--;
			else if(in[x][y]=='v')x++;
			else break;
		}
		if(co==1e6)cout<<"LOOP"<<endl;
		else cout<<y<<" "<<x<<endl;
	}
}

Measured memory_bytes: 1236
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

void solve() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  string s;
  cin >> s;

  vector<ull> b; // orthogonal vectors of valid set.
  for (int i = n-1; i >= 0; --i) {
    ull v = a[i];
    for (ll x : b) { chmin(v, v^x); }
    if (v > 0) { // Here, a[i] is not in valid set.
      if (s[i] == '1') { // player 1. not reachable to 0.
        cout << 1 << endl;
        return;
      } else { // player 0.
        b.push_back(v);
      }
    }
  }
  cout << 0 << endl;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll t;
  cin >> t;
  rep(iter,t) {
    solve();
  }
}


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

int main() {
 int N,X;
 cin >> N;
 X = N % 10;
  
  if(X == 2||X == 4||X == 5||X == 7||X == 9){
    cout << "hon" << endl;
  }
  if(X == 0||X == 1||X == 6||X == 8){
    cout << "pon" << endl;
  }
  if(X == 3){
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl;
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl;
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl;
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl;
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl;
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl;
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class DiameterOfTree{
public:
  typedef pair<int,int> P;
  int V;
  vector<vector<P> > G;
  int start, end, length;
  DiameterOfTree():V(-1){}
  DiameterOfTree(int V):V(V),G(V){};
  
  void add_edge(int a,int b,int c = 1){
    assert(a < V && b < V);
    assert(a >= 0 && b >= 0);
    G[a].push_back(P(b,c));
    G[b].push_back(P(a,c));
  }
  
  P dfs(int pos,int pre = -1,int len = 0){
    if(pre == -1) start = pos, length = -1;
    if(len > length) length = len, end = pos;
    for(P p:G[pos]) if(p.first != pre) dfs(p.first, pos, len+p.second);
    return P(end,length);
  }

  //O(N);
  P get(){return dfs(dfs(0).first);}
};


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  int n;
  cin>>n;
  DiameterOfTree A(n);
  for(int i=0;i<n-1;i++){
    int a,b,c;
    cin>>a>>b>>c;
    A.add_edge(a,b,c);
  }

  int ans = A.get().second;
  cout<<ans<<endl;
  return 0;
}



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

int main()
{
    char s[100],t[100],st[100] = {'\0'};
    cin >> s >> t;
    int ls = strlen(s);
    int lt = strlen(t);
    if(ls < 1 || ls > 10 || lt < 2 || lt > 11 || ls + 1 != lt)
    {
        cout << "No" << endl;
    }
    else
    {
        strncpy(st,t,lt-1);
        if(strcmp(st,s) != 0)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;
 
int main(){
    long long N;

    cin >> N;
    long long now = N;
    int f = 11;

    for(long long i = 1; i <= now; i++){
        if(N%i == 0){
            int f1 = to_string(N/i).length();
            int f2 = to_string(i).length();
            if(f1 >= f2 && f1 < f){
                f = f1;
            }else if(f1 < f2 && f2 < f){
                f = f2;
            }
        }
        now = N/i;
    }

    cout << f << endl;

    return 0;
}

Measured memory_bytes: 256