akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
typedef long long ll;

const int MAXK=1e5+1+5;
ll X,K,Q;
ll r[MAXK];
ll t,a;

ll lot[MAXK],lov[MAXK],hit[MAXK],hiv[MAXK];

int main()
{
        cin >> X >> K;
        r[0] = 0; //redundant
        for (int i=1; i<=K; ++i)
                cin >> r[i];

        lot[0] = 0;
        lov[0] = 0;
        hit[0] = X;
        hiv[0] = X;
        for (int i=1; i<=K; ++i) {
                int del = r[i]-r[i-1];
                if (i%2) del *= -1;
                lot[i] = lot[i-1];
                lov[i] = lov[i-1]+del;
                if (lov[i] < 0) {
                        lot[i] -= lov[i];
                        lov[i] = 0;
                } else if (lov[i] > X)
                        lov[i] = X;

                hit[i] = hit[i-1];
                hiv[i] = hiv[i-1]+del;
                if (hiv[i] > X) {
                        hit[i] -= hiv[i]-X;
                        hiv[i] = X;
                } else if (hiv[i] < 0)
                        hiv[i] = 0;
        }

        cin >> Q;
        for (int query=0; query<Q; ++query) {
                cin >> t >> a;

                int lo=0,hi=K+1;
                while (hi-lo>1) {
                        int mid = (hi+lo)/2;
                        if (r[mid] <= t) lo=mid;
                        else hi=mid;
                }

                ll val;
                if (a <= lot[lo]) val = lov[lo];
                else if (a >= hit[lo]) val = hiv[lo];
                else val = lov[lo]+(a-lot[lo]);

                if (lo%2) {
                        val += t-r[lo];
                } else {
                        val -= t-r[lo];
                }

                val = max(0LL,val);
                val = min(X,val);
                cout << val << "\n";
        }
}

Measured memory_bytes: 5120
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

int main(){
	string str;
	while(cin >> str){
		string res;
		for(int i=0;i<str.size();i++){
			if(str[i]!='@') res.push_back(str[i]);
			else {
				char a = str[i+2];
				int n = str[i+1]-'0';
				string tmp="";
				for(int j=0;j<n;j++) tmp.push_back(a);
				res+=tmp;
				i+=2;
			}
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 0
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	int n, k;
	map<int, int> ma;
	cin >> n >> k;
	rep(i, n) {
		int x;
		cin >> x;
		ma[x]++;
	}
	int ans = 0;
	int size = ma.size();
	vector<int> sort_num;
	if (k > size) cout << 0 << endl;
	
	else {
		for (auto x : ma) {
			sort_num.push_back(x.second);
		}
		sort(sort_num.begin(), sort_num.end());
		rep(i, size - k) {
			ans += sort_num[i];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 10748
import Data.List hiding (find)
import Data.Array as A
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Data.Graph
import Control.Monad
import Control.Monad.ST

type DP s = STUArray s Int Int

--DFS
dp_i :: DP s -> Graph -> Vertex -> Int -> ST s Int
dp_i dparr graph v0 n | graph A.! v0 == [] = writeArray dparr v0 0 >> return 0
                      | otherwise = do
   let vs = graph A.! v0
   forM_ vs $ \v -> do
     dpv0 <- readArray dparr v0
     dpv  <- readArray dparr v
     dpv' <- if dpv == (-1) then dp_i dparr graph v n >> readArray dparr v else return dpv
     writeArray dparr v0 $ max dpv0 (dpv'+1)
   dpv0' <- readArray dparr v0
   return dpv0'

solve :: [Edge] -> Int -> Int -> ST s Int
solve ls n m = do
  let graph = buildG (1,n) ls
  dparr <- newArray (1,n) (-1)
  list  <- forM [1..n] $ \v0 -> dp_i dparr graph v0 n
  let ans = maximum list
  return ans

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  ls <- replicateM m $ do
    (x:y:e) <- map read.words <$> getLine
    return (x,y)
  putStrLn $ show $ runST $ solve ls n m


Measured memory_bytes: 92668
/*input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int T;
	cin>>T;
	while(T--){
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		if(a<b||d<b){
			cout<<"No\n";
			continue;
		}
		ll t=__gcd(b,d);
		ll x=c+(a-c%t+t)%t;
		if(x==c) x+=t;
		if(x>=b){
			cout<<"Yes\n";
		}
		else cout<<"No\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 5010
using namespace std;
LL p[maxn],c[maxn],t[maxn],d[maxn],mid[maxn];
int main(){
	int n,k,i,now,cnt;
	LL mx=-1000000000,val;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%lld",&p[i]);
	for(i=1;i<=n;i++)scanf("%lld",&c[i]);
	for(i=1;i<=n;i++){
		now=p[i],d[i]=c[now],t[i]=1,mid[i]=-1000000000,mid[i]=max(d[i],mid[i]);
		while(1){
			if(now==i)break;
			t[i]++,now=p[now],d[i]+=c[now],mid[i]=max(d[i],mid[i]);
		}
	}
	for(i=1;i<=n;i++){
		if(k/t[i]>0)mx=max(mx,mid[i]),mx=max(mx,(k/t[i]-1)*d[i]+mid[i]);
		if(k%t[i]==0)continue;
		val=k/t[i]*d[i];
		now=p[i],val+=c[now],mx=max(mx,val),cnt=1;
		while(1){
			if(k%t[i]==cnt)break;
			cnt++,now=p[now],val+=c[now],mx=max(mx,val);
		}					
	}
	printf("%lld\n",mx);
	return 0;
}

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

using namespace std;

template<int mod>
struct Ring_mod {
    int val;
    Ring_mod(): val(0) {}
    Ring_mod(long long x)
    {
        if (x < 0) x += mod;
        if (x >= mod) x -= mod;
        if (x >= mod) x %= mod;
        val = x;
    }
    explicit operator int() { return val; }
    Ring_mod operator+(const Ring_mod& b) { return Ring_mod(val + b.val); }
    Ring_mod operator-(const Ring_mod& b) { return Ring_mod(val - b.val); }
    void operator+=(const Ring_mod& b) { val = Ring_mod(val + b.val).val; }
    void operator-=(const Ring_mod& b) { val = Ring_mod(val - b.val).val; }
    Ring_mod operator*(const Ring_mod& b) { return Ring_mod((long long) val * b.val); }
};

const int MOD = 1e9 + 7;
typedef Ring_mod<MOD> int_mod;

template<typename T>
struct Matrix {
    Matrix(int r, int c) : _r(r), _c(c), a(r * c) {}
    T* operator[](int row) { return row * _c + a.data(); }
    int _r, _c;
    vector<T> a;
};

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

    Matrix<int_mod> p(n + 1, n + 1);

    for (int j = 1; j <= n; ++j)
        p[n][j] = j;

    for (int i = n - 1; i >= 1; --i)
        for (int j = 1; j <= i; ++j) {
            if (s[n - 1 - i] == '<')
                p[i][j] = p[i + 1][j];
            else
                p[i][j] = p[i + 1][i + 1] - p[i + 1][j];
            p[i][j] += p[i][j - 1];
        }

    cout << (int) p[1][1];
    return 0;
}


Measured memory_bytes: 38320
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<numeric>
#include<climits>
#include<tuple>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
template<class T> void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

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

	int lose_count = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'x') {
			lose_count++;
		}
	}

	if (7 >= lose_count) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
import numpy as np


def calDistance_dfs(aList, d, node):
    stack = [node]
    d[node] = 0
    while len(stack) != 0:
        current = stack.pop()
        for v in aList[current]:
            if d[v[0]] == -1:
                stack.append(v[0])
                d[v[0]] = d[current]+v[1]


n = int(input())
adjacencyList = [[] for i in range(n)]
d = [-1] * n

for i in range(n - 1):
    s = list(map(int, input().split()))
    adjacencyList[s[0] - 1].append((s[1] - 1, s[2]))
    adjacencyList[s[1] - 1].append((s[0] - 1, s[2]))


d[0] = 0
calDistance_dfs(adjacencyList, d, 0)
for i in d:
    print(i % 2)


Measured memory_bytes: 55392
#include <bits/stdc++.h>
using namespace std;
int n,m,a[100001];
int gcd(int x,int y) {
    if (x<y) swap(x,y);
    if (y==0) return x;
    else return gcd(y,x%y);
}
int main() {
    cin>>n>>m;
    for (int i=0; i<n; i++) cin>>a[i];
    long long lcm=0,p2=0;
    for (int i=0; i<n; i++) {
        long long num=a[i];
        long long cnt=0;
        while (num%2==0) {
            num/=2; cnt++;
        }
        if (i==0) {
            p2=cnt;
            lcm=num;
        }
        else if (cnt!=p2) {
            cout<<0<<'\n'; return 0;
        }
        else {
            lcm=(lcm*num/gcd(lcm,num));
        }
    }
    lcm=lcm*(long long)(pow(2LL,p2));
    long long ans=(2*m)/lcm;
    if (ans%2!=0) ans=ans/2+1;
    else ans/=2;
    cout<<ans<<'\n';
}

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

int main(){
  long int N;
  cin >> N;
  long int m = 0;
  long int a = 0;
  long int r = 0;
  long int c = 0;
  long int h = 0;
  long int x;
  string s;
  for(long int i = 0; i < N; i++){
    cin >> s;
    if(s[0] == 'M'){
      m++;
    }
    else if(s[0] == 'A'){
      a++;
    }
    else if(s[0] == 'R'){
      r++;
    }
    else if(s[0] == 'C'){
      c++;
    }
    else if(s[0] == 'H'){
      h++;
    }
  }
  x = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
  cout << x << endl;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n; cin>> n;
  vector<int> a(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
  }
  int cnt =0;
  for(int i=1;i<n;++i){
    if(a[i-1]==a[i]) {
      ++cnt;
      a[i] = 100*a[i]+1;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-03-25.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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 EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
const ll mod = 1000000007;

ll fact[200000];
ll invfact[200000];

inline ll take_mod(ll a) {
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b) {
    return take_mod(a + b);
}

inline ll sub(ll a, ll b) {
    return take_mod(a - b);
}

inline ll mul(ll a, ll b) {
    return take_mod(a * b);
}

inline ll mod_pow(ll x, ll n) {
    ll res = 1LL;
    while (n > 0) {
        if (n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x) {
    return mod_pow(x, mod - 2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k) {
    return mul(mul(fact[n], invfact[n - k]), invfact[k]);
}

ll N, K;
vector<vector<ll>> G;

ll dfs(ll now, ll from) {
    ll n_color = from == -1 ? K - 1 : K - 2;
    if (K < G[now].size()) return 0;
    ll n_case = 1;
    for (auto v : G[now]) {
        if (v == from) continue;
        n_case = mul(n_case, n_color);
        n_color--;
    }
    for (auto v : G[now]) {
        if (v == from) continue;
        n_case = mul(n_case, dfs(v, now));
    }
    return n_case;
}

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

    cout << mul(K, dfs(0, -1)) << endl;
    return 0;
}

Measured memory_bytes: 10368
#include <stdio.h>
int main(void){
	int n = 1;
    scanf("%d", &n);
  	int a[n];
  	int max=0;
  	int i_max=0;
    int secondmax=0;

  	for(int i=0;i<n;i++){
      scanf("%d", &a[i]);
      if(a[i] > max){
        max = a[i];
        i_max = i;
      }
      if(max>a[i] && a[i]>secondmax){
        secondmax = a[i];
      }
      if(max==a[i] && i_max != i){
        secondmax = a[i];
      }      
    }
  
  	for(int i=0;i<n;i++){
      if(a[i] == max){
         printf("%d\n", secondmax);
      }else{
         printf("%d\n", max);
      }
    }
  
  return 0;
}

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

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	
	vector<int>sunu(n);
	
	for (int i = 0; i < k; ++i) {
		int d;
		cin >> d;
		
		for (int j = 0; j < d; ++j) {
			int a;
			cin >> a;
			++sunu[a - 1];
		}
	}
	
	cout << count(sunu.begin(), sunu.end(), 0) << endl;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
typedef long long ll;
string s;
ll li[100001][13],mod=1e9+7;
int main(void){
    cin>>s;
    li[0][0]=1;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<13;j++){
            if(s[i]=='?'){
                for(int k=0;k<10;k++){
                    li[i+1][(j*10+k)%13]+=li[i][j];
                    li[i+1][(j*10+k)%13]%=mod;
                }
            }
            else{
                li[i+1][(j*10+(s[i]-'0'))%13]+=li[i][j];
                li[i+1][(j*10+(s[i]-'0'))%13]%=mod;
                
            }
        }
    }
    cout<<li[s.size()][5]<<endl;
}


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

using namespace std;

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

    int len = 0;
    bool ret = false;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a == b)len++;
        else len = 0;

        if (len >= 3)ret = true;
    }

    cout << (ret ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3640
N, M = map(int, input().split())
A = list(map(int, input().split()))

num = [[0,1] for i in range(M+N)]
for i in range(N):
    num[i][0] = A[i]
for i in range(M):
    B, C = map(int, input().split())
    num[N + i][0] = C
    num[N + i][1] = B
num.sort(reverse=True)

cnt = 0
ans = 0
while N > 0:
    ans += num[cnt][0] * min(N, num[cnt][1])
    N -= min(N, num[cnt][1])
    cnt += 1
print(ans)

Measured memory_bytes: 83096
#include "bits/stdc++.h"
    #define ALL(obj) (obj).begin(),(obj).end()
    #define RALL(obj) (obj).rbegin(),(obj).rend()
    #define REP(i, n) for(int i = 0; i < (int)(n); i++)
    #define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
    #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
    using namespace std;
    typedef long long ll;
    const int MOD = 1e9 + 7;
    const int INF = 1e9 + 6;
    const ll LLINF = 4e18;
     
    int main() {
        int n; cin >> n;
        vector<int> v(n);
        REP(i, n) {
            cin >> v[i];
        }
        sort(ALL(v));
        double ans = v[0];
        REP(i, n) {
            ans = (ans + v[i]) / 2;
        }
        cout << ans << endl;
        getchar(); getchar();
    }

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        r: f64
    }
    println!("{}", 2.0 * r * std::f64::consts::PI);
}


Measured memory_bytes: 2212
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 
vector<int> Zalgorithm(const vector<int> &s){
  vector<int> res(s.size(),0);

  res[0] = s.size();
  int i=1,j=0;
  while(i < s.size()) {
    while(i+j<s.size() && s[j] == s[i+j]) ++j;
    res[i] = j;
    if(j==0) {
      ++i;
      continue;
    }
    int k=1;
    while(i+k<s.size() && k+res[k] < j) res[i+k] = res[k], ++k;
    i += k, j -= k;
  }
  return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vector<int> a(N), b(N);
    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];

    vector<int> c;
    for(int i=0; i<N-1; i++){
        c.push_back(b[i] ^ b[i+1]);
    }
    for(int i=0; i<N*2-2; i++){
        c.push_back(a[i%N] ^  a[(i+1)%N]);
    }

    //for(auto e: c) cout << e << endl;
    vector<int> z = Zalgorithm(c);
    for(int i=0; i<N; i++){
        if(z[i+N-1] >= N-1){
            cout << i << " " << (b[0] ^ a[i]) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10080
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    h,w = LI()
    board = [["." for _ in range(w+2)]]
    for _ in range(h):
        line = list(S())
        board.append(["."] + line + ["."])
    board.append(["." for _ in range(w+2)])
    table = [[False]*(w+2) for _ in range(h+2)]
    exp = [[1,0],[0,1],[-1,0],[0,-1]]

    for i in range(h+2):
        for j in range(w+2):
            if board[i][j] == ".":
                table[i][j] = True
            else:
                for x,y in exp:
                    if board[i+x][j+y] == "#":
                        table[i][j] = True
    from functools import reduce
    def kakeru(lst):
        return reduce(lambda x,y: x and y,lst)
    ans = True
    for line in table:
        ans &= kakeru(line)
    print("Yes" if ans else "No")
main()                  


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

const int A = 100005, B = 100005, inf = 1e9;
int a, b, m, p[A], q[B], x, y, z, fp, mp = inf, mq = inf;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b >> m;
	for(int i = 1; i <= a; ++i) cin >> p[i], mp = min(mp, p[i]);
	for(int i = 1; i <= b; ++i) cin >> q[i], mq = min(mq, q[i]);
	fp = mp + mq;
	for(int i = 1; i <= m; ++i) {
		cin >> x >> y >> z;
		fp = min(fp, p[x] + q[y] - z);
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long ans = 100000000;
    int array[] = new int[N];
    for(int i=0;i<N;i++){
      array[i] = sc.nextInt();
    }
    int target;
    for(int i=-100;i<=100;i++){
      target = i;
      long cost = 0;
      for(int j=0;j<N;j++){
        cost += Math.pow(array[j]-target,2);
      }
      ans = Math.min(cost,ans);
    }
    System.out.println(ans);

  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long gcd(long long x, long long y){
    if(x < y) swap(x, y);
    if(x % y == 0) return y;
    return gcd(y, x % y);
}
long long lcm(long long x, long long y){
    long long g = gcd(x, y);
    return x / g * y;
}
int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] /= 2;
    }
    long long l = A[0];
    for(int i = 0; i < N; i++){
        l = lcm(l, A[i]);
        if(l > M){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++){
        long long t = l / A[i];
        if(t % 2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    long long cnt = M / l;
    cout << (cnt + 1) / 2 << endl;
}

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

const int INF = (int)2e9;
int n, cut[10000];
int dp[2][2][5001];//not use 0
int main()
{
  //chap1
  cin >> n;
  for(int i = 1; i < n; i++)
    cin >> cut[i];

  for(int i = 0; i < 2; i++)
    for(int j = 0; j < 2; j++)
      for(int k = 1; k <= n / 2; k++)
	dp[i][j][k] = INF;
  
  dp[0][0][1] = 0;
  
  //chap2
  for(int i = 1; i < n; i++){
    //chap2-1
    for(int j = 1; j <= n / 2; j++)
      if(dp[0][0][j] != INF){
	dp[1][1][j] = min(dp[1][1][j], dp[0][0][j] + cut[i]);
	if(j < n / 2)
	  dp[1][0][j + 1] = min(dp[1][0][j + 1], dp[0][0][j]);
      }
    //chap2-2
    for(int j = 1; j <= n / 2; j++)
      if(dp[0][1][j] != INF){
	dp[1][1][j] = min(dp[1][1][j], dp[0][1][j]);
	if(j < n / 2)
	  dp[1][0][j + 1] = min(dp[1][0][j + 1], dp[0][1][j] + cut[i]);
      }
    //chap2-3
    for(int i = 0; i < 2; i++)
      for(int j = 1; j <= n / 2; j++){
	dp[0][i][j] = dp[1][i][j];
	dp[1][i][j] = INF;
      }
  }
  cout << min(dp[0][0][n / 2], dp[0][1][n / 2]) << endl;
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

using Graph = vector<vector<int>>;
Graph G;

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

    ll n; cin >> n;
    ll ans = 0;
    vector<ll> a(n), b(n), c(n), sum(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sum[0] = 0;

    rep(i, n){
        auto pos = lower_bound(a.begin(), a.end(), b[i]);
        int index = distance(a.begin(), pos);
        sum[i + 1] = sum[i] + index;
    }
    rep(i, n){
        auto pos = lower_bound(b.begin(), b.end(), c[i]);
        int index = distance(b.begin(), pos);
        ans += sum[index];
    }
    cout << ans << endl;
}


Measured memory_bytes: 6328
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;


int main() {
	long long int a, b, c,d, n, m;
	string str;
	cin >> a >> b >> c >> d;
	if (a == 1 || b == 1 || c == 1 || d == 1) {
		if (a == 7 || b == 7 || c == 7 || d == 7) {
			if (a == 9 || b == 9 || c == 9 || d == 9) {
				if (a == 4 || b == 4 || c == 4 || d == 4) {
					cout << "YES"; return 0;
				}
			}
		}
	}
	cout << "NO";
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;

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

const double EPS = 1e-5;
const int MOD = 1e9+7;

const int N = 100;

vector<string> name(N);
map<string, vector<int>> point;
map<pair<string, int>, int> number;



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

  string a;
  int b;
  for(int i = 0; i < n; i++){
    cin >> a >> b;
    name[i] = a;
    point[a].emplace_back(b);
    number[make_pair(name[i],b)] = i+1;
  }

  sort(name.begin(), name.end(), [](const std::string& a, const std::string& b) {
       for (int i = 0 ; i < std::min(a.size(), b.size()) ; i++) {
         if (a[i] != b[i]) {
           return a[i] < b[i];
         }
       }
       return a.size() < b.size();
     });

  for(auto &elem: point){
    sort(elem.second.begin(), elem.second.end(), greater<int>());
    //cout << elem.first << endl;
  }

  for(auto &town: point){
    for(auto &elem: town.second){
      //cout << town.first << endl;
      //cout << elem << endl;
      cout << number[make_pair(town.first, elem)] << endl;
    }
  }




  return 0;
}


Measured memory_bytes: 3248
import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())

branch = [[] for _ in range(N)] # [[]]*N だと参照渡しになってしまう
X = [0,]*N
root = [False]*N
t = 0

for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a-1].append(b)
    branch[b-1].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x


def search(p):
    global t
    root[p-1] = True
    for q in branch[p-1]:
        if root[q-1]:
            continue
        X[q - 1] += X[p - 1]        # 各頂点に到達した際にどのような計算をすればいいかを意識
        search(q)



search(1)
print(*X)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


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

    int res = 0;
    rep(i,N-2) {
        if (S.substr(i, 3) == "ABC") res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
#include<climits>

using namespace std;
typedef unsigned long long ll;

const int mod=1000000007;

int m,n;
string g[129];
map<vector<string>,int>ma;

int dfs(vector<string>q,int de){
    if(q.size()<2)return 0;
    if(ma[q])return ma[q];
    int ret=INT_MAX;
    for(int i=0;i<m;i++){
        vector<string>zero,one;
        for(int j=0;j<q.size();j++){
            if(q[j][i]=='0'){
                zero.push_back(q[j]);
            } else {
                one.push_back(q[j]);
            }
        }
        if(zero.size()==q.size()||one.size()==q.size()){
            continue;
        }
        int o=dfs(one,de+1);
        int z=dfs(zero,de+1);
        if(max(o,z)+1<ret){
            ret=max(o,z)+1;
        }
        //ret=min(ret,min(dfs(one),dfs(zero))+1);
    }
    return ma[q]=ret;
}

int main(){
    while(cin>>m>>n,m){
        vector<string>q;
        for(int i=0;i<n;i++){
            cin>>g[i];
            q.push_back(g[i]);
        }
        cout<<dfs(q,0)<<endl;
    }
}

Measured memory_bytes: 36932
import java.util.*;

public class Main {
	static class Tree {
		public class Edge {
			int to, rev;

			public Edge(int to, int rev) {
				this.to = to;
				this.rev = rev;
			}
		}
		
		int V;
		ArrayList<ArrayList<Edge>> G;
		int root;
		int[] p;
		int[] path;
		int[] A;
		
		public Tree(int[] a, int[] b, int[] A) {
			this.V = a.length+1;
			p = new int[V];
			path = new int[V];
			this.A = A;
			
			G = new ArrayList<ArrayList<Edge>>();
			for(int i=0; i<V; i++) {
				G.add(new ArrayList<Edge>());
			}
			
			for(int i=0; i<V-1; i++) {
				G.get(a[i]).add(new Edge(b[i], G.get(b[i]).size()));
				G.get(b[i]).add(new Edge(a[i], G.get(a[i]).size()-1));
			}
			int root = 0;
			for(int i=0; i<V; i++)
				if(G.get(i).size()>1) {
					root=i;
					break;
				}
			setRoot(root);
		}
		
		public void setRoot(int root) {
			this.root = root;
			setRoot(root, -1);
		}
		public void setRoot(int cur, int parent) {
			p[cur] = parent; 
			for(int i=0; i<G.get(cur).size(); i++) {
				int next = G.get(cur).get(i).to;
				if(next!=parent) {
					setRoot(next, cur);
				}
			}
		}
		
		public boolean check(int cur) {
			if(G.get(cur).size()==1) {
				path[cur] = A[cur];
				return true;
			}

			long sum = 0;
			long max = -1;
			for(int i=0; i<G.get(cur).size(); i++) {
				int next = G.get(cur).get(i).to;
				if(next!=p[cur]) {
					if(!check(next))
						return false;
					sum += path[next];
					max = Math.max(max, path[next]);
				}
			}
			long maxPair = Math.min(sum/2, sum-max);
			if(sum<A[cur] || A[cur]<sum-maxPair)
				return false;
			
			path[cur] = A[cur] - (int)Math.max(0, sum-A[cur]);
			return true;
		}
	}
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		int[] a = new int[N-1];
		int[] b = new int[N-1];
		for(int i=0; i<N-1; i++) {
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
		}
		if(N==2) {
			System.out.println(A[0]==A[1] ? "YES" : "NO");
		} else {
			Tree tree = new Tree(a, b, A);
			System.out.println(tree.check(tree.root) && tree.path[tree.root]==0 ? "YES" : "NO");
		}
		sc.close();
	}
}


Measured memory_bytes: 96752
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll A,B;

//解法
void solve() {
	
	if (B%A == 0) {
		cout << A + B;
	}
	else {
		cout << B - A;
	}

	return;
}

int main() {

	//入力
	cin >>A>>B;

	solve();
	cout << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;
vector<pair<int,int>> E[405];
vector<int> dist(405);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    
    int n;
    cin>>n;
    vector<pair<int,int>> xy(n);
    for(auto &a : xy) cin>>a.first>>a.second;
    double sum = 0.0;
    for(int i=0;i<n;++i){
        double tmp = 0.0;
        for(int j=0;j<n;++j){
            tmp += hypot(xy[i].first - xy[j].first,xy[i].second - xy[j].second);
        }
        int num = 1;
        for(int k=n-1;k>1;k--)num *= k;
        sum += tmp*num;
    }
    for(int i=n;i>1;i--)sum /=i;
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define int long long
int32_t main(){
	ll h , w; cin>>h>>w;
	cout<<(h == 1  || w == 1 ? 1 : (h * w + 1) / 2)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	ll n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		ll l,r;
		cin>>l>>r;
		ans+=(r-l+1);
	}
	cout<<ans<<endl;
	return 0;
}

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

int N, M;
int A[100], B[100];
bool G[100][100];
bool visited[100];

void dfs(int v) {
   visited[v] = true;
   for (int v2 = 0; v2 < N; v2++) {
      if (G[v][v2] == false) continue;
      if (visited[v2] == true) continue;
      dfs(v2);
   }
}

int main() {
   cin >> N >> M;
   for (int i = 0; i < M; i++) {
      cin >> A[i] >> B[i];
      A[i]--, B[i]--;
      G[A[i]][B[i]] = G[B[i]][A[i]] = true;
   }

   int ans = 0;
   for (int i = 0; i < M; i++) {
      G[A[i]][B[i]] = G[B[i]][A[i]] = false;
      fill(visited, visited+N, false);
      dfs(0);
      if (count(visited, visited+N, true) < N) ans++;
      G[A[i]][B[i]] = G[B[i]][A[i]] = true;
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int N;
string X, Xtmp;
int D;

int main()
{
	cin >> N;
	cin >> X;
	cin >> D;

	Xtmp = X;

	int i = 0;
	
	//上から調べてハミング距離のこってるとき
	while (D > 0)
	{
		//0なら1に変えてハミング距離減らす
		if (X[i] - '0' == 0)
		{
			X[i] = '1';
			D--;
		}
		//毎回調べる添え字増やす
		i++;
		//添え字が下1桁以下までいったらbreak
		if (i == N) break;
	}

	//後ろから
	i = N - 1;

	while (D > 0)
	{
		//もともとXで0だったところだけ1にする
		if (Xtmp[i] - '0' == 1)
		{
			X[i] = '0';
			D--;
		}
		i--;
	}

	cout << X << endl;
}


Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a[300005];
int main()
{
    int n;
    ll ans=0,ans1 = 0,ans2=0,ans3=0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%lld",&a[i]);
        a[i] = a[i] - i - 1;
    }
    sort(a,a+n);
    int zho = (a[(n-1)/2]+a[n/2])/2;
    for(int i = 0; i < n; i++)
    {
        ans1 = ans1 + abs(a[i]-zho);
        ans2 = ans2 + abs(a[i]-zho-1);
        ans3 = ans3 + abs(a[i]-zho+1);
    }
    printf("%lld\n",ans1);
    return 0;
}


Measured memory_bytes: 1792
s=input()
n=len(s)

ans=[-1,-1]
for i in range(n-1):
  if s[i]==s[i+1]:
    ans[0],ans[1]=i+1,i+1+1

if n>=3:
  for i in range(n-2):
    if s[i]==s[i+2]:
      ans[0],ans[1]=i+1,i+2+1

print(ans[0],ans[1])

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

int main(){
  int k;
  string s="CODEFESTIVAL2016",s1;
  cin>>s1;
  k=0;
  for(int i=0;i<16;i++){
    if(s1[i]!=s[i])k++;
  }
  cout<<k<<endl;
  return 0;
}


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

struct Node {
    int key;
    Node* left;
    Node* right;
    Node* parent;
};

class Tree {
public:
    Node* nodes_;
    Node nil;
    Node* root_;
    int elements_;

    Tree(int n) {
        nodes_ = (Node *)malloc(n*sizeof(Node));
        nil = {-1, nullptr, nullptr, nullptr};
        root_ = &nil;
        elements_ = 0;
    }
    
    void insert(int k) {
        Node *y = nullptr;
        Node *x = root_;
        nodes_[elements_] = {k, nullptr, nullptr, nullptr};
        Node *z = &nodes_[elements_];

        while (x != nullptr and elements_ > 0) {
            y = x;
            if (z->key < x->key) {
                x = x->left;
            } else {
                x = x->right;
            }
        }
        z->parent = y;

        if (y == nullptr) {
            root_ = &nodes_[0];
        } else if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
        elements_++;
    }

    void find(int k, Node* n) {
        if (n->key == k) {
            std::cout << "yes\n";
        } else if (n->key > k) {
            if (n->left == nullptr) {
                std::cout << "no\n";
            } else {
                find(k, n->left);
            }
        } else {
            if (n->right== nullptr) {
                std::cout << "no\n";
            } else {
                find(k, n->right);
            }
        }
    }

    void inorder(Node* n) {
        if (n->left != nullptr) {
            inorder(n->left);
        }
        std::cout << " " << n->key;
        if (n->right != nullptr) {
            inorder(n->right);
        }
    }

    void preorder(Node* n) {
        std::cout << " " << n->key;
        if (n->left != nullptr) {
            preorder(n->left);
        }
        if (n->right != nullptr) {
            preorder(n->right);
        }
    }

    void print() {
        inorder(root_);
        std::cout << "\n";
        preorder(root_);
        std::cout << "\n";
    }
};


int main() {
    int n;
    std::cin >> n;
    Tree T(n);
    for (int i=0; i<n; i++) {
        std::string operation;
        int operand;
        std::cin >> operation;
        if (operation == std::string("insert")) {
            std::cin >> operand;
            T.insert(operand);
        } else if (operation == std::string("find")) {
            std::cin >> operand;
            T.find(operand, T.root_);
        } else {
            T.print();
        }
    }

    return 0;
}


Measured memory_bytes: 15512
#include <stdio.h>

int main(void){
    int n, a[100001], res[100001];

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d", &a[i]);
        res[a[i]] = i;
    }

    for(int i = 1; i <= n; ++i){
        printf("%d ", res[i]);
    }
    puts("\n");

    return 0;
}

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

int main(){
  int N,H,W,ans=0,te,mp;
  cin>>N>>H>>W;
  for(int i=0;i<N;i++){
  	cin>>te>>mp;
    if(te>=H && mp>=W)ans++;
  }
  cout<<ans<<endl;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// UnionFind 解説：https://youtu.be/TdR816rqc3s?t=8424
struct UnionFind {
	vi d;
	UnionFind(int n = 0) : d(n, -1) {}

	int find(int x) {
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);

		if (x == y) return false;

		if (d[x] > d[x]) swap(d[x], d[x]);
		d[x] += d[y];
		d[y] = x;
		return true;
	}

	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -d[find(x)]; }
};

// ──────────────────────────────────────────────────────────────────

constexpr int MAX = 100010;

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

	// エラトステネスの篩
	bitset<MAX> is_prime(0);
	for (int i = 2; i <= 100000; ++i) is_prime.set(i);
	for (int i = 2; i <= 100000; ++i) {
		if (is_prime[i]) {
			for (int j = i * 2; j <= 100000; j += i) {
				is_prime.reset(j);
			}
		}
	}

	vi rui(MAX);
	for (int i = 1; i <= MAX; i += 2) {
		if (is_prime[i] && is_prime[(i + 1) / 2])
			rui[i] = 1;
	}

	Rep(i, MAX) rui[i] += rui[i - 1];

	rep(i, q) {
		int ans = 0;
		int l, r;
		cin >> l >> r;

		cout << rui[r] - rui[l - 1] << endl;
	}
}

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

const int MAXN = 1e3+1;
const int MOD = 1e9+7;

int main()
{
	int a,b,c,d;
	cin >>a>>b>>c>>d;
	if((a*b)<(c*d)){
		cout << (c*d);
	}else if((a*b)==(c*d)){
		cout <<(a*b);
	}else{
		cout << (a*b);
	}
	return 0;
}


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

void funcB() {
  int n;
  std::cin >> n;
  std::string temp;
  int cnt[4] = { 0 };
  std::string status[4] = { "AC", "WA", "TLE", "RE" };
  for (int i = 0; i < n; i++) {
    std::cin >> temp;
    for (int j = 0; j < 4; j++) {
      if (temp == status[j])cnt[j]++;
    }
  }
  for (int i = 0; i < 4; i++) {
    std::cout << status[i] << " x " << cnt[i] << std::endl;
  }
}

int main(void) {
  funcB();
  return 0;

}

Measured memory_bytes: 3180
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	s := next()
	max := 0
	for i := 1; i < len(s); i++ {
		new := s[:len(s)-i]
		if len(new)%2 != 0 {
			continue
		}
		if new[:len(new)/2] == new[len(new)/2:] {
			max = len(new)
			break
		}
	}
	fmt.Println(max)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 640
def main():
    from collections import defaultdict
    from itertools import combinations

    N = int(input())

    d = defaultdict(int)
    for i in range(N):
        s = input()
        d[s[0]] += 1

    ans = 0
    for comb in combinations('MARCH', r=3):
        t = 1
        for char in comb:
            t *= d[char]
        ans += t
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T>
inline void remax(T& x, T y) { x = max(x, y); }

template<typename T>
inline void remin(T& x, T y) { x = min(x, y); }

constexpr int ms = 1e6 + 13;

int fd[ms];

int main() 
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    if(n % 2 == 0) cout << -1 << '\n';
    else {
        int cur_mod = (7 % n);
        int cur_v = 0;
        fd[cur_mod] = 1; 
        while(cur_mod != 0) {
            cur_mod = (cur_mod * 10 + 7) % n;
            cur_v++;
            if(fd[cur_mod] == 1) break;
            fd[cur_mod] = 1; 
        }
        if(cur_mod == 0) cout << cur_v + 1 << '\n';
        else cout << -1 << '\n';
    }
    return 0;
}





Measured memory_bytes: 7504