akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

typedef long long ll;

ll V[3002][3002];

ll MEMO[3002][3002][4];
ll R, C, K;


int main() {
    cin >> R >> C >> K;
    for (int i = 0; i <= R; i++) {
        for (int j = 0; j <= C; j++) {
            V[i][j] == 0;
            for (int k = 0; k <= 3; k++) {
                MEMO[i][j][k] = 0;
            }
        }
    }

    for (int i = 0; i < K; i++) {
        ll r, c, v;
        cin >> r >> c >> v;
        V[r][c] = v;
    }

    for (int r = R; r >= 1; r--) {
        for (int c = C; c >= 1; c--) {   
            if (V[r][c] == 0) {
                MEMO[r][c][3] = max(MEMO[r][c+1][3], MEMO[r+1][c][3]);
                MEMO[r][c][2] = max(MEMO[r][c+1][2], MEMO[r+1][c][3]);
                MEMO[r][c][1] = max(MEMO[r][c+1][1], MEMO[r+1][c][3]);
                MEMO[r][c][0] = max(MEMO[r][c+1][0], MEMO[r+1][c][3]);
            } else {
                MEMO[r][c][3] = max(MEMO[r][c+1][3], V[r][c] + max(MEMO[r][c+1][2], MEMO[r+1][c][3]));
                MEMO[r][c][2] = max(MEMO[r][c+1][2], V[r][c] + max(MEMO[r][c+1][1], MEMO[r+1][c][3]));
                MEMO[r][c][1] = max(MEMO[r][c+1][1], V[r][c] + max(MEMO[r][c+1][0], MEMO[r+1][c][3]));
                MEMO[r][c][0] = max(MEMO[r][c+1][0], MEMO[r+1][c][3]);
            }
        }   
    }

    cout << MEMO[1][1][3] << endl;
}

Measured memory_bytes: 355260
unittest
{
	assert( [ "2 3 3", "2 2", "1 1", "1 3" ].solve == 3 );
	assert( [ "3 3 4", "3 3", "3 1", "1 1", "1 2" ].solve == 3 );
	assert( [ "5 5 10", "2 5", "4 3", "2 3", "5 5", "2 2", "5 4", "5 3", "5 1", "3 5", "1 4" ].solve == 6 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto h = 0L;
	auto w = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s %s"( h, w, m );
	auto hws = new long[ 2 ][ m ];
	foreach( ref hw; hws )
	{
		input.popFront;
		hw = input.front.split.to!( long[] );
		hw[] -= 1;
	}
	
	// 行ごと、列ごとの爆破対象の合計と最大数を取る
	bool[ long ][ long ] pss;
	auto hts = new long[ h ];
	auto wts = new long[ w ];
	auto hm = 0L;
	auto wm = 0L;
	foreach( hw; hws )
	{
		pss[ hw[ 0 ] ][ hw[ 1 ] ] = true;
		hts[ hw[ 0 ] ]++;
		wts[ hw[ 1 ] ]++;
		hm = max( hm, hts[ hw[ 0 ] ] );
		wm = max( wm, wts[ hw[ 1 ] ] );
	}
	
	// 爆破対象数が最大の行と列を抽出
	long[] ys;
	foreach( y, ht; hts )
	{
		if( ht == hm ) ys ~= y;
	}
	long[] xs;
	foreach( x, wt; wts )
	{
		if( wt == wm ) xs ~= x;
	}
	
	// 爆破対象数の最大を判定
	foreach( y; ys )
	{
		foreach( x; xs )
		{
			if( y !in pss || x !in pss[ y ] ) return wm + hm;		// 爆破対象数は最大3*10^^5なので二重ループでもTLEしない
		}
	}
	return wm + hm - 1;		// 二重カウント分を除外
}


Measured memory_bytes: 95656
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

typedef vector<vector<int>> graph;

inline int get_index(int x, int y, int w) {
	return x + y * w;
}

inline void add_edge(graph &G, int a, int b) {
	G[a].emplace_back(b);
	G[b].emplace_back(a);
}

inline int bfs(int s, int g, vector<int> &dist, const graph &G, int ng_x = -1, int ng_y = -1) {
	const int n = G.size();

	dist.assign(n, -1);
	queue<int> que;

	dist[s] = 0;
	que.push(s);

	while(!que.empty()) {
		const int v = que.front();
		que.pop();

		if(v == g) return dist[v];

		for(const auto &to : G[v]) {
			if(v == ng_x && to == ng_y) continue;

			if(dist[to] == -1) {
				dist[to] = dist[v] + 1;
				que.push(to);
			}
		}
	}

	return -1;
}

vector<int> get_path(int v, const vector<int> &dist, const graph &G) {
	vector<int> res{v};
	while(dist[v] > 0) {
		for(const auto &to : G[v]) {
			if(dist[to] + 1 == dist[v]) {
				v = to;
				res.emplace_back(to);
				break;
			}
		}
	}
	reverse(res.begin(), res.end());
	return res;
}

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

	int w, h, n;
	cin >> w >> h >> n;

	vector<vector<bool>> wall_h(h, vector<bool>(w - 1, false));
	vector<vector<bool>> wall_v(h - 1, vector<bool>(w, false));

	for(int i = 0; i < n; ++i) {
		int sx, sy, dx, dy;
		cin >> sx >> sy >> dx >> dy;

		if(sx == dx) {
			if(sx == 0 || sx == w) continue;
			if(sy > dy) swap(sy, dy);

			for(int y = sy; y < dy; ++y) {
				wall_h[y][sx - 1] = true;
			}
		}
		else {
			if(sy == 0 || sy == h) continue;
			if(sx > dx) swap(sx, dx);

			for(int x = sx; x < dx; ++x) {
				wall_v[sy - 1][x] = true;
			}
		}
	}

	const int V = w * h;
	graph G(V);

	for(int y = 0; y < h; ++y) {
		for(int x = 0; x < w - 1; ++x) {
			if(!wall_h[y][x]) add_edge(G, get_index(x, y, w), get_index(x + 1, y, w));
		}
	}

	for(int y = 0; y < h - 1; ++y) {
		for(int x = 0; x < w; ++x) {
			if(!wall_v[y][x]) add_edge(G, get_index(x, y, w), get_index(x, y + 1, w));
		}
	}

	int ix, iy, ox, oy;
	cin >> ix >> iy >> ox >> oy;

	const int s = get_index(ix, iy, w);
	const int g = get_index(ox, oy, w);

	vector<int> dist;
	const int base = bfs(s, g, dist, G);
	const auto path = get_path(g, dist, G);

	int ans = 0;
	for(unsigned i = 1; i < path.size(); ++i) {
		chmax(ans, bfs(s, g, dist, G, path[i - 1], path[i]) - base);
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
//#define cin fin
//#define cout fout
using namespace std;

//ifstream fin("file.in");
//ofstream fout("file.out");

const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

int n;
pair<int,int>a[200005];


int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i].sc >> a[i].fr;
    }
    sort(a+1,a+n+1);
    int curr=0;
    for(int i=1;i<=n;i++){
        if(curr+a[i].sc>a[i].fr) rc("No");
        else curr+=a[i].sc;
    }
    rc("Yes");
}


Measured memory_bytes: 3328
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long mod = 1000000007;
long long dp[200][6][6][6][6];

bool problemIn(int i, int j, int k, int l) {
  int val1 = 100*i + 10*j + k;
  int val2 = 100*j + 10*k + l;
  if(val1 == 12 ||val2 == 12) return true;

  vector<int> A = {i, j, k, l};

  for(int i = 0;i < 3;i++) {
    swap(A[i], A[i+1]);
    int val1 = 100*A[0] + 10*A[1] + A[2];
    int val2 = 100*A[1] + 10*A[2] + A[3];
    if(val1 == 12 ||val2 == 12) return true;
    swap(A[i], A[i+1]);
  }

  return false;
}

long long NumCombinations(int N) {
  if(N == 3) return 61;

  for (size_t n = 4; n <= N; n++) {
    int count = 4;
    for (size_t i = 0; i < count; i++) {
      for (size_t j = 0; j < count; j++) {
        for (size_t k = 0; k < count; k++) {
          for (size_t l = 0; l < count; l++) {
            if (problemIn(i, j, k, l)) {
              dp[n][i][j][k][l] = 0;
            } else if (n == 4) {
              dp[n][i][j][k][l] = 1;
            } else {
              dp[n][i][j][k][l] = (dp[n-1][0][i][j][k]+dp[n-1][1][i][j][k]+dp[n-1][2][i][j][k]+dp[n-1][3][i][j][k]) % mod;
            }
          }
        }
      }
    }
  }

  long long ans = 0;
  int count = 4;
  for (size_t i = 0; i < count; i++) {
    for (size_t j = 0; j < count; j++) {
      for (size_t k = 0; k < count; k++) {
        for (size_t l = 0; l < count; l++) {
          ans = (ans + dp[N][i][j][k][l]) % mod;
        }
      }
    }
  }

  return ans;
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  int N;
  cin >> N;

  cout << NumCombinations(N);

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int p[10][10];

void F (int x, int y) {
    if (0 <= x && x < 10 && 0 <= y && y < 10) {
        p[x][y]++;
    }
}

int main (void) {
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            p[i][j] = 0;
        }
    }
    while (1) {
        int x, y, s;
        if (scanf("%d,%d,%d", &x, &y, &s) == EOF) break;
        if (cin.eof()) break;
        p[x][y]++;
        if (s == 1) {
            F(x + 1, y    );
            F(x - 1, y    );
            F(x    , y + 1);
            F(x    , y - 1);
        } else if (s == 2) {
            F(x + 1, y + 1);
            F(x + 1, y    );
            F(x + 1, y - 1);
            F(x    , y + 1);
            F(x    , y - 1);
            F(x - 1, y + 1);
            F(x - 1, y    );
            F(x - 1, y - 1);
        } else {
            F(x + 1, y + 1);
            F(x + 1, y    );
            F(x + 1, y - 1);
            F(x    , y + 1);
            F(x    , y - 1);
            F(x - 1, y + 1);
            F(x - 1, y    );
            F(x - 1, y - 1);
            F(x + 2, y    );
            F(x - 2, y    );
            F(x    , y + 2);
            F(x    , y - 2);
        }
    }
    int e = 0, m = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (p[i][j] == 0) e++;
            m = max(m, p[i][j]);
        }
    }
    cout << e << endl;
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(x,a) for(auto& (x) : (a) )
int main(){
  int n,m;
  cin>>n>>m;
  int ans =-1;
  int s[m],c[m];
  rep(i,m)cin>>s[i]>>c[i];
  rep(i,1000){
    string f = to_string(i);
    bool ff =true;
    rep(j,m){
      if(i<100&&s[j]>=3){
        ff=false;
        break;
      }
      if(i<10&&s[j]==2){
        ff=false;
        break;
      }
      if(i<10&&s[j]==3){
        ff=false;
        break;
      }
      if(f.at(s[j]-1)-'0'!=c[j])ff=false;
    }
    if(ff&&f.length()==n){
      ans=i;
      break;
    }
    
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
/*----------------------------------------------*/
int n;
int ans[100000];
vector<Edge> g[100000];


void dfs(int x,int p=-1){ //x from parent
  for(auto E:g[x]){       // E.to from x
    if(E.to==p) continue;
    if(E.weight%2) ans[E.to]=(ans[x]+1)%2;
    else ans[E.to]=ans[x];
    dfs(E.to,x);
  }
}


signed main(){
  cin>>n;
  rep(i,n-1){
    int u,v,w;
    cin >> u>>v>>w;
    --u;--v;
    g[v].push_back({u,w});
    g[u].push_back({v,w});
  }
  vector<int> d(n,-1);//-1,0,1
  queue<int> que;
  d[0]=0;
  que.push(0);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(auto nv:g[v]){
      if(d[nv.to]!=-1) continue;
      d[nv.to]=(d[v]+nv.weight)%2;
      que.push(nv.to);
    }
  }
  rep(i,n) cout<<d[i]<<endl;
  // dfs(0);
  // rep(i,n) cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    vint a(n), b(n);
    rep(i, n) {cin>>a[i];b[i] = a[i];}
    sort(all(b));
    m = b[n-1];int mm = b[n-2];
    rep(i, n){
        if(a[i]==m){
            cout << mm << endl;
        }else{
            cout << m << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
//
//  DPC-yo-5-b.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/11/24.
//

#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;

int main()
{
    ll n,k;
    ll a[2000];
    cin>>n>>k;
    for(ll i=0;i<n;i++) cin>>a[i];

    ll c[2000000];
    
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        ll tmp=0;
        for(int j=i;j<n;j++)
        {
            tmp+=a[j]*1ll;
            c[cnt]=tmp;
            cnt++;
        }
    }
    
    ll ans=0;
    for(int j=40;j>=0;j--)
    {
        ll num=0ll;
        ans+=(1ll<<j);
        for(int i=0;i<cnt;i++)
        {
            if((ans&c[i])==ans) num++;
        }
        if(num<k) ans-=(1ll<<j);
    }
    cout<<ans<<endl;
    
    return 0;
}


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

int factorial(int x) {
  int ans=0,point = 2,i=1;
  double p;
  while(point > 1) {
    point = x / pow(5.0,i);
    i++;
    ans += point;
  }
  return ans;
}

int main() {
  int a;
  while(cin >> a,a) {
     cout << factorial(a) << endl;
     // factorial(a);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;

i64 modpow(i64 a, i64 n, i64 mod) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        i64 t = modpow(a, n / 2, mod);
        return t * t % mod;
    }
    return a * modpow(a, n - 1, mod) % mod;
}

i64 modinv(i64 a, i64 mod) {
    // mod is prime
    return modpow(a, mod - 2, mod);
}

struct Combination {
    const int MAX_N = 1 << 21;
    vi fact = vi(MAX_N);
    vi factinv = vi(MAX_N);

    Combination() {
        fact[0] = 1;
        for (int i = 1; i < MAX_N; i++) {
            fact[i] = fact[i - 1] * i % MOD;
        }
        factinv[MAX_N - 1] = modinv(fact[MAX_N - 1], MOD);
        for (int i = MAX_N - 2; i >= 0; i--) {
            factinv[i] = factinv[i + 1] * (i + 1) % MOD;
        }
    }

    i64 ncr(i64 n, i64 r) {
        if (r < 0 || r > n) return 0;
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }

    i64 npr(i64 n, i64 r) {
        if (r < 0 || r > n) return 0;
        return fact[n] * factinv[n - r] % MOD;
    }

    i64 nhr(i64 n, i64 r) {
        if (n == 0 && r == 0) return 1;
        return ncr(n + r - 1, r);
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    Combination comb;
    cout << comb.nhr(k, n) << endl;
}


Measured memory_bytes: 35580
while input()!='0':
    n_std=float(0)
    n_l=list(map(int,input().split()))
    n_av=sum(n_l)/len(n_l)
    for i in n_l:
        n_std+=(i-n_av)**2
    n_std=(n_std/len(n_l))**0.5
    print(f'{n_std:.6f}')


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

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> p(n); 
    rep(i, n) cin >> p[i];
    rep(j, n - 1){
        int tmp1 = p[j];
        int tmp2 = p[j + 1];
        if (tmp1 == j + 1){
            ans ++;
            p[j] = tmp2;
            p[j + 1] = tmp1;
        }
    }
    if (p[n - 1] == n) ans ++;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000001

int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
	int catalan(int n){
		return mod(combination(2*n,n)*gyakugen(n+1));
	}
	
};
combi C(200001);

template <typename T,typename F0,typename F1>
struct rerooting{
	F0 func0;
	F1 func1;
	T init_value;
	
	vector<T> v;
	vector<T> ans;
	
	rerooting(vector<vector<int>> &E,F0 f0,F1 f1,T iv):func0(f0),func1(f1){
		init_value = iv;
		v.resize(E.size());
		ans.resize(E.size());
		dfs(E,0,-1);
		redfs(E,0,-1,init_value);
	}
	
	void dfs(vector<vector<int>> &E,int now,int p){
		v[now] = init_value;
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to==p)continue;
			dfs(E,to,now);
			v[now] = func0(v[now],v[to]);
		}
		v[now] = func1(v[now],now);
	}
	
	void redfs(vector<vector<int>> &E,int now,int p,T pv){
		vector<T> S(E[now].size(),init_value);
		if(S.size()>1){
			for(int i=S.size()-2;i>=0;i--){
				int to = E[now][i+1];
				T x = v[to];
				if(to==p)x = pv;
				S[i] = func0(x,S[i+1]);
			}
		}
		
		T temp = init_value;
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to!=p){
				redfs(E,to,now,func1(func0(temp,S[i]),now));
				temp = func0(temp,v[to]);
			}
			else{
				temp = func0(temp,pv);
			}
		}
		ans[now] = func1(temp,now);
	}
	
};

int main(){
	
	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	auto f0 = [](pair<int,int> a,pair<int,int> b){
		return make_pair(mod(mod(a.first * b.first) * C.combination(a.second + b.second,b.second)),b.second+a.second);
	};
	
	auto f1 = [](pair<int,int> a,int ind){
		return make_pair(a.first,a.second+1);
	};
	
	rerooting<pair<int,int>,decltype(f0),decltype(f1)> rr(E,f0,f1,{1,0});
	
	for(int i=0;i<N;i++){
		cout<<rr.ans[i].first<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 18648
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(j, m) for (int j = 0; j <= (int)(m); j++)

int main()
{
    int d;
    ll g;
    vector<ll> p, c;
    cin >> d >> g;
    p.resize(d);
    c.resize(d);
    rep(i, d)
    {
        cin >> p[i] >> c[i];
    }
    ll res = 1 << 29;
    for (int bit = 0; bit < (1 << d); ++bit)
    {
        ll sum = 0;
        ll num = 0;

        rep(i, d)
        {
            if (bit & (1 << i))
            {
                sum += c[i] + p[i] * 100 * (i + 1);
                num += p[i];
            }
        }
        if (sum >= g)
        {
            res = min(res, num);
        }
        else
        {
            for (int i = d - 1; i >= 0; i--)
            {
                if (bit & (1 << i))
                {
                    continue;
                }
                rep(j, p[i])
                {
                    if (sum >= g)
                    {
                        break;
                    }
                    sum += 100 * (i+1);
                    num++;
                } 
            }
            res = min(res, num);
        }
    }
    cout << res << endl;
}

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

const int N = 2e6 + 5;
#define int long long

string s;
int ans, h, x, y, n, s1[N];

signed main() {
	cin>>s;
	n = s.size();
	for(int i = 0; i < n; i++) {
		if(i) s1[i] = s1[i - 1];
		if(s[i] == 'A') s1[i]++;
	} 
	h = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'A') x = i;
		else {
			if(s[i] == 'B' && s[i + 1] == 'C') {
				y = i + 1;
				ans += s1[y];
				if(h) ans -= s1[h];
 				i++;
			}
			else 
				h = i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> t[i];
    }
    
    string u;
    cin >> u;
    
    int ans = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
        if (flag) ans += t[i];
        flag |= (s[i] == u);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args:Array[String]): Unit = {
    Iterator.continually(readLine())
      .map(s => {
        val xs = s.split(" ").map(_.toInt)  
        (xs(0), xs(1))
      })
      .takeWhile{
        case (0,0) => false
        case _ => true
      }
      .foreach(xs => {
        val h = xs._1
        val w = xs._2
       
        var st = ""
        for (i <- 1 to h){
          if (i == 1 || i == h) st += printWall(1 to w)("#") + "\n"
          else st += printVoid(1 to w)("#")(".") + "\n"
        }
        println(st)
      })
  }

  def printWall(r:Range)(wall:String): String = {
    r.foldLeft("")((a, _) => a + wall )
  }

  def printVoid(r:Range)(wall:String)(void:String): String = {
    r.foldLeft(""){
      case (a, 1) => a + wall    
      case (a, r.end) => a + wall
      case (a, _) => a + void
    }
  }
}

Measured memory_bytes: 110200
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int distance[]={6,7,5,5,20,15},money[6][6]={{300,500,600,700,1350,1650},{350,450,600,1150,1500},{250,400,1000,1350},{250,850,1300},{600,1150},{500}};
	int time[2][3];
	while(cin>>time[0][0],time[0][0]){
		for(int i=1;i<3;i++)cin>>time[0][i];
		for(int i=0;i<3;i++)cin>>time[1][i];
		int num=0;
		for(int i=time[0][0];i<time[1][0];i++)num+=distance[i-1];
		bool kawa=0;
		for(int i=0;i<2&&!kawa&&num<41;i++)if(time[i][1]==18||time[i][1]==17&&time[i][2]>29||time[i][1]==19&&time[i][2]<31)kawa=1;
		num=money[time[0][0]-1][time[1][0]-time[0][0]-1];
		if(kawa){
			num/=2;
			if(num%50!=0)num+=25;
		}
		cout<<num<<endl;
	}
}

Measured memory_bytes: 1160
N,K = map(int, input().split())
if K > (N-1)*(N-2)//2:
  print(-1)
  exit(0)
ANS = []
for i in range(2,N+1):
  ANS.append((1,i))
  
cnt = (N-1)*(N-2)//2
for i in range(2,N+1):
  if cnt == K:
    break
  for j in range(i+1,N+1):
    ANS.append((i,j))
    cnt -= 1
    if cnt == K:
      break
      
print(len(ANS))
for i,j in ANS:
  print(i,j)

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

using namespace std;

int main() {
  string s;
  cin >> s;
  
  if (s == "Sunny") cout << "Cloudy" << endl;
  else if (s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
#define ll long long
#define re register
using namespace std;
inline ll gi(){
	ll f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
ll n,x;
ll gcd(ll a,ll b){
	if(!b)return a;
	else return gcd(b,a%b);
}
int main(){
	n=gi();x=gi();
	ll k=gcd(n,x);
	printf("%lld\n",3*(n-k));
	return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> d(n,vector<ll> (n));
  ll ans=0;
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<n;j++) {
      cin >> d[i][j];
      ans+=d[i][j];
    }
  }
  vector<vector<bool>> flag(n,vector<bool> (n,true));
  for(ll k=0;k<n;k++) {
    for(ll i=0;i<n;i++) {
      for( ll j=0;j<n;j++) {
        if(d[i][j]>d[i][k]+d[k][j]) {
          cout << -1 << endl;
          return 0;
        }
        else if(flag[i][j]&&d[i][j]==d[i][k]+d[k][j]&&k!=i&&k!=j){
          ans-=2*d[i][j];
          flag[i][j]=false;
          flag[j][i]=false;
        }
      }
    }
  }
  ans/=2;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

#define N 3
#define N2 9

struct Puzzle {
	int f[N2];
	int space;
	string path;
	bool operator <(const Puzzle &p) const {
		for (int i = 0; i < N2; ++i) {
			if (f[i] != p.f[i]) {
				return f[i] > p.f[i];
			}
		}
		return false;
	}
};
bool isComplete(Puzzle p) {
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] != i + 1)
			return false;
	}
	return true;
}

const int dx[4] { -1, 0, 1, 0 };
const int dy[4] { 0, -1, 0, 1 };
const char dir[4] { 'u', 'l', 'd', 'r' };
string bfs(Puzzle p) {
	p.path = "";
	map<Puzzle, bool> M;
	M[p] = true;
	Puzzle u, v;
	queue<Puzzle> Q;
	Q.push(p);
	for (int i = 0; i < N2; ++i) {
		while (!Q.empty()) {
			u = Q.front();
			Q.pop();
			if (isComplete(u))
				return u.path;
			int sx = u.space / N;
			int sy = u.space % N;
			for (int r = 0; r < 4; ++r) {
				int tx = sx + dx[r];
				int ty = sy + dy[r];
				if (tx < 0 || ty < 0 || tx >= N || ty >= N)
					continue;
				v = u;
				swap(v.f[u.space], v.f[tx * N + ty]);
				v.space = tx * N + ty;
				if (!M[v]) {
					M[v] = true;
					v.path += dir[r];
					Q.push(v);
				}
			}
		}
	}
	return "unresolved";
}

int main() {

	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		scanf("%d", &p.f[i]);
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = bfs(p);
	cout << ans.size() << endl;

	return 0;
}

Measured memory_bytes: 30716
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


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

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    auto fail = []() {
        cout << "NO\n";
        exit(0);
    };
    
    // code here.
    string A = "AKIHABARA";
    int pos = 0;

    for (char ch: input<string>()) {
        if (pos == SZ(A))
            fail();

        if (ch == 'A') {
            if (A[pos] != 'A')
                fail();
            ++pos;
        } else {
            while (pos != SZ(A) and A[pos] == 'A')
                ++pos;

            if (pos == SZ(A) or A[pos] != ch)
                fail();
            ++pos;
        }
    }
    
    while (pos != SZ(A) and A[pos] == 'A')
        ++pos;

    if (pos != SZ(A))
        fail();

    cout << "YES\n";
    
    return 0;
}


Measured memory_bytes: 256
import numpy as np

n = int(input())
a, b = [int(x) for x in input().split(" ")]

p = np.array([int(x) for x in input().split(" ")])


m1 = np.sum(p <= a)
m2 = np.sum((p > a) & (p <= b))
m3 = np.sum(p > b)

print(np.min([m1, m2, m3]))


Measured memory_bytes: 21316
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

int main() {
    char At[8], S[100], Co[8];
    scanf("%s %s %s", At, S, Co);
    printf("A%cC\n", S[0]);
}

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

typedef pair<int, int> Pint;

int main(){
    int N, M;  cin >> N >> M;
    vector<vector<Pint>> cities;
    cities = vector<vector<Pint>>(N+1, vector<Pint>());
    for(int i=0; i<M; i++){
        int p, y;  cin >> p >> y;
        cities[p].push_back(Pint(y, i));
    }

    vector<string> ans(M);
    for(int p=1; p<=N; p++){
        sort(cities[p].begin(), cities[p].end());
        int n = cities[p].size();
        for(int i=0; i<n; i++){
            int num = cities[p][i].second;
            string prefID = to_string(p);
            string numID = to_string(i+1);
            while(prefID.length()<6) prefID = "0" + prefID;
            while(numID.length()<6) numID = "0" + numID;

            ans[num] = prefID + numID;
        }
    }

    for(int i=0; i<M; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 12416
package main

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

func main() {
	nextReader = newScanner()
	x, y, z := nextInt(), nextInt(), nextInt()
	fmt.Printf("%d %d %d\n", z, x, y)
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin >> s;
    string t=s;
    reverse(t.begin(),t.end());
    int ans=0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()

ans = 0
cnt = 0
for a, b in ab:
    if cnt+b >= m:
        ans += (m - cnt)*a
        break
    else:
        ans += b*a
    cnt += b
print(ans)

Measured memory_bytes: 27760
k,n = (int(x) for x in input().split())

first = 0
pre_x = None
max_num = 0 

for x in input().split():
  x = int(x)
  if pre_x != None:
    num = x - pre_x
    max_num = max(max_num,num)
  else:
    first = x
   
  pre_x = x

num = k - x + first 
max_num = max(max_num,num)
print(k-max_num)



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

/**
 * AIZU ONLINE JUDGE
 * 2805 Tournament
 *    2018/02/11
 */
public class Main {


	// メイン return falseでおしまい
	boolean main() throws IOException {

		int[] ir = readIntArray();
		int N = ir[0];
		int M = ir[1];

		log.printf("N,M = %d, %d\n", N, M);

		int[] a = new int[N];
		for(int i = 0; i < M; i++) {
	        ir = readIntArray();
            a[ir[0]] = 1;
	        log.printf("a = %d\n", ir[0]);
		}
		int cnt = 0;
		for(int n = N; n > 0; n /= 2) {
		    for(int i = 0; i + 1 < n; i += 2) {
		        if (a[i] == 0 && a[i + 1] == 0) {
		            cnt++;
		        }
		        int t = 0;
                if (a[i] != 0 && a[i + 1] != 0) {
                    t = 1;
                }
		        a[i / 2] = t;
		    }
		}

		result.printf("%d\n", cnt);

		return true; // 正常終了 次へ
	}



	static long time0;
	private final static boolean DEBUG = false; // release

    PrintStream log;
    PrintStream result;
    BufferedReader systemin;
    PrintStream DEVNULL = new PrintStream(new OutputStream() { public void write(int b) {} } );

    static Main instance = new Main();

    Main() {
        log = DEVNULL;
        systemin = new BufferedReader(new InputStreamReader(System.in)); // コンソールから
        result = System.out;
    }

	public static void main(String[] args) throws IOException {

		int N = Integer.MAX_VALUE;
		//int N = readIntArray()[0];

//		for(int i = 0; i < N; i++) {
			boolean b = instance.main();
//			if (!b)
//				break;
//		}

        instance.systemin.close();
	}


	// 標準入力より1行分の区切り文字区切りでの整数値を読む
	// EOFの場合はnullを返す
	private int[] readIntArray() throws IOException {

		String s = null;
		for(;;) {
			s = systemin.readLine();
//			log.printf("%s\n", s);
			if (s == null)
				return null;
			s = s.trim();
			if (s.length() != 0) // 突然空行を読むことがある。読み飛ばすとうまくいくらしい。。。。
				break;
		}

		String[] sp = s.split("[ ,]"); // 区切り文字はスペースかカンマ
		int[] a = new int[sp.length];
		for(int i = 0; i < sp.length; i++) {
			a[i] = Integer.parseInt(sp[i]);
		}
		return a;
	}

}






Measured memory_bytes: 26424
import java.util.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int D = sc.nextInt();
    int x = sc.nextInt();
    for(int i=0; i<10; i++){
      x = r * x - D;
      System.out.println(x);
    }
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 22996
N,x=map(int,input().split())
a=list(map(int,input().split()))
c=[[None]*N for i in range(N)]
for j in range(N):
    for i in range(N):
        if j==0:
            c[j][i]=a[i]
        else:
            c[j][i]=min(c[j-1][i-1],a[i])
ans=2*10**12
for i in range(N):
    ans=min(ans,sum(c[i])+x*i)
print(ans)

Measured memory_bytes: 136028
N, K = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
dp = Array.new(N, 0)
1.step(N-1) do |i|
  min = Float::INFINITY
  1.step(K) do |s|
    break unless i >= s
    p = (H[i-s] - H[i]).abs + dp[i-s]
    min = p if min > p
  end
  dp[i] = min
end
puts dp.last

Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int n;
	double a,sum=0;
	string s;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>s;
		if(s=="JPY")sum+=a;
		else sum+=a*380000.0;
	}
	cout<<setprecision(15)<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	cin >> K;
	N = s.size();
	vector<vector<vector<int>>>dp(N, vector<vector<int>>(N, vector<int>(K + 1, MOD)));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			for (int k = 0; k <= K; k++) {
				dp[i][j][k] = 0;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= K; j++) {
			dp[i][i][j] = 1;
		}
	}
	int ans = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j + i < N; j++) {
			for (int k = 0; k <= K; k++) {
				if (s[j] == s[j + i]) {
					dp[j][j + i][k] = dp[j + 1][j + i - 1][k] + 2;
				}
				else {
					dp[j][j + i][k] = max(dp[j + 1][j + i][k], dp[j][j + i - 1][k]);
					if (k)dp[j][i + j][k] = max(dp[j][j + i][k], dp[j + 1][j + i - 1][k - 1] + 2);
				}
				ans = max(ans, dp[j][i + j][k]);
				//cout << j << " " << j + i << " " << k << " " << dp[j][j + i][k] << endl;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 109568
#include<iostream>
#include<stack>
#include<algorithm>
#include<vector>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

int main(){
    string s;
    while(cin >> s, s != "."){
        string t = "";
        int i = 0;
        while(i < s.length()){
            if(s[i] == '-' || s[i] == '+'){
                int cnt = 0;
                while(i < s.length() && (s[i] != '?' && !inRange(s[i], 'A', 'Z'))){
                    cnt += s[i++] == '-' ? -1 : 1;
                }
                if(s[i] == '?') t += 'A';
                else            t += (char)('A' + (s[i]-'A'+cnt+26*100)%26);
            }else{
                t += (s[i] != '?' ? s[i] : 'A');
            }
            i++;
        }
        stack<char> q;
        for(i = 0; i < t.length(); i++){
            if(t[i] == ']'){
                vector<char> r;
                while(q.top() != '[')   r.push_back(q.top()), q.pop();
                q.pop();
                for(char c : r)   q.push(c);
            }else{
                q.push(t[i]);
            }
        }
        string ans = "";
        while(!q.empty()){
            ans += q.top();    q.pop();
        }
        reverse(ans.begin(), ans.end());
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private class Node<T> {
		T key;
		Node<T> left;
		Node<T> right;
		public Node(T key) {
			this.key = key;
			left = right = null;
		}
		public String toString() {
			return key.toString();
		}
	}
	
	private class BST {
		
		private Node<Integer> rootNode;
		public BST() {
			rootNode = null;
		}
		
		public void insert(Node<Integer> node) {			
			Node<Integer> parent = null;
			Node<Integer> cur = rootNode;
			while (cur != null) {
				parent = cur;
				if (node.key < cur.key) {
					cur = cur.left;
				} else {
					cur = cur.right;
				}
			}
			if (parent == null) {
				rootNode = node;
			} else if (node.key < parent.key) {
				parent.left = node;
			} else {
				parent.right = node;
			}
		}
		
		public void print() {
			printInOrder(rootNode);
			System.out.println("");
			printPreOrder(rootNode);
			System.out.println("");
		}
		
		private void printInOrder(Node<Integer> node) {
			if (node != null) {
				printInOrder(node.left);
				System.out.print(" " + node);
				printInOrder(node.right);
			}			
		}
		
		private void printPreOrder(Node<Integer> node) {
			if (node != null) {
				System.out.print(" " + node);
				printPreOrder(node.left);
				printPreOrder(node.right);
			}			
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		BST bst = new BST();
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			String cmd = st.nextToken();
			if (cmd.equals("insert")) {
				bst.insert(new Node<Integer>(Integer.parseInt(st.nextToken())));
			} else {
				bst.print();
			}
		}
		reader.close();
	}
}



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

long long int gcd(long long int a, long long int b){
    long long int tmp;
    while(1){
    if(a < b){
        tmp = a;
        a = b;
        b = tmp;
    }
    if(!b) break;
    a %= b;
  }
  return a;
}

int main(void){
    long long int n, i, j, ans=0;
    scanf("%lld", &n);
    long long int a[n];
    for(i=0; i<n; i++) scanf("%lld", &a[i]);
    long long int left[n], right[n];
    left[0] = a[0];
    for(i=1; i<n; i++) left[i] = gcd(left[i-1], a[i]);
    right[0] = a[n-1];
    for(i=1; i<n; i++) right[i] = gcd(right[i-1], a[n-1-i]);

    ans = left[n-2];
    if(right[n-2]>ans) ans = right[n-2];
    for(i=0; i<n-2; i++){
        if(gcd(left[i], right[n-i-3]) > ans) ans = gcd(left[i], right[n-i-3]);
    }
    /*for(i=0; i<n; i++) printf("%lld ", left[i]);
    printf("\n");
    for(i=0; i<n; i++) printf("%lld ", right[i]);
    printf("\n");*/
    printf("%lld", ans);
}

Measured memory_bytes: 2560
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    s = S()
    ans = ''
    for c in s:
        new = (ord(c) + N - ord('A')) % 26 + ord('A')
        ans += chr(new)
    print(ans)
main()



Measured memory_bytes: 7344
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 1 << 17;
int datm[2*MAX_N],data[2*MAX_N],n;
void init(int n_){
  n=1;
  while(n<n_) n*=2;
  for(int i=0;i<n*2;i++) datm[i]=data[i]=0;
}
void add(int a,int b,int x,int k=0,int l=0,int r=n){
  if(r<=a||b<=l) return;
  if(a<=l&&r<=b){
    data[k]+=x;
    return;
  }
  add(a,b,x,k*2+1,l,(l+r)/2);
  add(a,b,x,k*2+2,(l+r)/2,r);
  datm[k]=max(datm[k*2+1]+data[k*2+1],datm[k*2+2]+data[k*2+2]);
}
int query(int a,int b,int k=0,int l=0,int r=n){
  if(r<=a||b<=l) return 0;
  if(a<=l&&r<=b) return datm[k]+data[k];
  int vl=query(a,b,k*2+1,l,(l+r)/2);
  int vr=query(a,b,k*2+2,(l+r)/2,r);
  return max(vl,vr)+data[k];
}
signed main(){
  int N,Q;
  cin>>N>>Q;
  init(N);
  for(int i=0;i<Q;i++){
    int f;
    cin>>f;
    if(f){
      int x;
      cin>>x;
      cout<<query(x-1,x)<<endl;
    }else{
      int s,t,x;
      cin>>s>>t>>x;
      add(s-1,t,x);
    }
  }
  return 0;
}

Measured memory_bytes: 7204
#include <iostream>
#include <queue>
#include <algorithm>
#define INF 9999999
using namespace std;

class State {
public:
  int id;
  int cost;
  int tiket;
  bool operator <(const State &s) const {
    if(tiket != s.tiket) return tiket < s.tiket;
    return cost > s.cost;
  }
  State(int id, int cost, int tiket) : id(id), cost(cost), tiket(tiket) {}
};

int main() {
  while(1) {
    int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
    int data[n+1][n+1];
    fill(&data[0][0], &data[n][n]+1, INF);
    for(int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      data[a][b] = data[b][a] = f;
    }

    priority_queue<State> PQ;
    PQ.push(State(s, 0, c));
    bool visited[n+1][c+1];
    int cost[n+1][c+1];
    fill(&visited[0][0], &visited[n][c] + 1, false);
    fill(&cost[0][0], &cost[n][c] + 1, INF);
    cost[s][c] = 0;
    while(!PQ.empty()) {
      State s = PQ.top();
      PQ.pop();
      visited[s.id][s.tiket] = true;
      for(int i = 1; i <= n; i++) {
	if(!visited[i][s.tiket] && data[s.id][i] != INF) {
	  int newValue = cost[s.id][s.tiket] + data[s.id][i];
	  if(newValue < cost[i][s.tiket]) {
	    cost[i][s.tiket] = newValue;
	    PQ.push(State(i, newValue, s.tiket));
	  }
	}
	if(s.tiket >= 1 && !visited[i][s.tiket-1] && data[s.id][i] != INF) {
	  int newValue = cost[s.id][s.tiket] + data[s.id][i]/2;
	  if(newValue < cost[i][s.tiket-1]) {
	    cost[i][s.tiket-1] = newValue;
	    PQ.push(State(i, newValue, s.tiket-1));
	  }
	}
      }
    }
    int min = INF;
    for(int i = 0; i <= c; i++) {
      if(cost[d][i] < min) min = cost[d][i];
    }
    cout << min << endl;
  }
  return 0;
}

Measured memory_bytes: 964
temp=input().split(" ")
n=int(temp[0])
k=int(temp[1])
k2=2*k
tileb=[[0 for i in range(k2*2)] for j in range(k2*2)]
for i in range(n):
    temp=input().split(" ")
    x=int(temp[0])
    y=int(temp[1])
    c=temp[2]
    tempx=x%(k2)
    if c=='B':  
        tempy=y%(k2)
        
    elif c=='W':  
        tempy=(y+k)%(k2)

    tileb[tempy][tempx]+=1
    tileb[tempy+k2][tempx]+=1
    tileb[tempy][tempx+k2]+=1
    tileb[tempy+k2][tempx+k2]+=1
        
ans=0
for y in range(0,k2*2):
    for x in range(1,k2*2):
        tileb[y][x]+=tileb[y][x-1]

for x in range(0,k2*2):
    for y in range(1,k2*2):
        tileb[y][x]+=tileb[y-1][x]

def nijiruisekiwa(x,y,k): #左下(x,y) 長さkの正方形領域の和
    global tileb
    if x!=0 and y!=0:
        return tileb[y+k-1][x+k-1]-tileb[y+k-1][x-1]-tileb[y-1][x+k-1]+tileb[y-1][x-1]
    
    if x==0 and y==0:     
        return tileb[y+k-1][x+k-1]
    if y==0:     
        return tileb[y+k-1][x+k-1]-tileb[y+k-1][x-1]
    if x==0:     
        return tileb[y+k-1][x+k-1]-tileb[y-1][x+k-1]
    
for x in range(0,k2):
    for y in range(0,k2):
        temp=0
        a=nijiruisekiwa(x,y,k)
        b=nijiruisekiwa(x+k,y+k,k)

        temp=a+b
      #  print("temp="+str(temp))

        if temp>ans:
            # print(a)
            # print(b)
            # print("x={0}  y={1}  ".format(x,y))
            ans=temp
print(ans)


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

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,five = 5,ans = 0;
	cin >> n;
	if(n%2){
		cout << "0\n";
	}
	else{
		for(int i=1;i<=25;i++,five*=5)
		{
			ans += (n/(five*2));
		}
		cout << ans << "\n";
	}
}


Measured memory_bytes: 256