akhauriyash/Code-Regression huggingface dataset:
import sys
n = int(sys.stdin.readline().strip())
ar = [int(x) for x in sys.stdin.readline().split()]
f4, odd, even = 0, 0, 0
for num in ar:
	if num%4==0:
		f4 +=1
	elif num%2==0:
		even+=1
	else:
		odd+=1
if odd-f4 == 0:
	print "Yes"
elif odd-f4 <= 1 and even == 0:
	print "Yes"
else:
	print "No"

Measured memory_bytes: 11832
s = input()

if len(s) == 2 and s[0] == s[1]:
    print(1, 2)
    exit()

for i in range(len(s)-2):
    if len(set(s[i:i+3])) != 3:
        print(i+1, i+3)
        exit()
print(-1, -1)


Measured memory_bytes: 41196
// Half and Half

#include <iostream>

using namespace std;

int main(){
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	if (A+B >= 2*C){
		if (X <= Y)
			cout << 2*C*X + min(B, 2*C)*(Y-X) << endl;
		else
			cout << 2*C*Y + min(A, 2*A)*(X-Y) << endl;
	}else{
		cout << A*X + B*Y << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  double ans = 0;
  REP(_, n) {
    int a; cin >> a;
    ans += 1.0 / a;
  }
  printf("%.7f\n", 1.0 / ans);
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N=int(input())
A=list(map(int,input().split()))

log=[0]*10**5

for a in A:
    log[a-1]+=1


wa=sum([(i+1)*log[i] for i in range(len(log))])

for _ in range(int(input())):
    B,C=map(int,input().split())
    wa+=(C-B)*log[B-1]
    log[B-1],log[C-1]=0,log[B-1]+log[C-1]
    print(wa)



Measured memory_bytes: 20988
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

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

	for (int i = 0; i < n; i++) cout << a[i] << " ";
	cout << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>

int d[7];

int main()
{
  memset(d, 0, sizeof d);

  for(int i = 0; i < 6; i++) {
    int t;
    scanf("%d", &t);
    d[t]++;
  }

  int cnt = 0;
  for(int t = 0; t < 6; t++) if(d[t]&1) cnt++;

  puts(cnt<=2? "YES" : "NO");

  return 0;
}


Measured memory_bytes: 128
# coding: utf-8
# Your code here!
count = int(input())
line = input().split()
n = line[0]
m = line[1]
lis = []
for i in range(len(n)):
    lis.append(n[i])
    lis.append(m[i])

for j in lis:
    print(j,end = "")

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100;
int HH[MAXN];
int* H = HH+(MAXN/2);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, n;
    while (cin >> r >> n) {
        if (r == 0 && n == 0) break;
        memset(HH, 0, sizeof(HH));
        for (int i = 0; i < n; i++) {
            int xl, xr, h;
            cin >> xl >> xr >> h;
            for (int x = 2*xl; x < 2*xr; x++) {
                H[x] = max(H[x], h);
            }
            if (xr == r) H[2*xr] = max(H[2*xr], h);
            if (xl == -r) H[2*xl] = max(H[2*xl], h);
        }
        double ans = 1e9;
        for (int x = -2*r; x <= 2*r; x++) {
            if (x%2 == 0) {
                int X = x/2;
                double p = r-sqrt(r*r-X*X);
                ans = min(ans, H[x]+p);
            } else {
                int X = (x+1)/2;
                {
                    double p = r-sqrt(r*r-X*X);
                    ans = min(ans, p+H[x]);
                }
                X--;
                {
                    double p = r-sqrt(r*r-X*X);
                    ans = min(ans, p+H[x]);
                }
            }
        }
        printf("%.10lf\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1248
#include <iostream>

using namespace std;

char s[105],t[105];
int main()
{
    int lg,sp = 0;
    cin>>lg;
    cin>>s>>t;
    int best= 2*lg;

    for(int i = 0; i<lg; i++)
    {
        int a, c = 0;
        sp = 0;
        for(a = i; c<lg-i; a++,c++)
        {
            if(s[a]==t[c])
            {
                sp++;
            }
            else
                break;
        }
        if(a==lg)
        {
            if (best > (lg-sp)*2+sp)
                best = (lg-sp)*2 + sp;
        }
    }
    cout<<best<<'\n';
    return 0;
}


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

int main() {
    int N;  cin >> N;
    int ans = 0, x = 0;
    for (int i = 0; i < N; ++i) {
        char c;  cin >> c;
        if (c == 'I') ++x;
        else --x;
        ans = max(ans, x);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

void solve() {
  int N; cin >> N;
  string name;
  map<char, ll> initial;
  rep(i,N) {
    cin >> name;
    ++initial[name[0]];
  }
  
  string MARCH = "MARCH";
  ll ans = 0;
  for (int i=0; i<3; ++i) {
    char x = MARCH[i];
    for (int j=i+1; j<4; ++j) {
      char y = MARCH[j];
      for (int k=j+1; k<5; ++k) {
        char z = MARCH[k];
        ans += initial[x] * initial[y] * initial[z];
      }
    }
  }

  cout << ans << endl;
  return;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = map(int,input().split())
MOD = 1000000007

cur = [0,0,0]

dp = [0 for i in range(N+1)]
dp[0] = 1
for i, a in enumerate(A):

    cnt = 0
    for c in cur:
        if c==a:
            cnt+=1

    for i_c in range(3):
        if cur[i_c]==a:
            cur[i_c] += 1
            break
    dp[i+1] = (cnt*dp[i])%MOD

    # print(cur)

print(dp[N])

Measured memory_bytes: 55660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 5e5+5;
// check for forloop
// take input
// overflow
// intialize variable
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    int n,c,k;
    cin>>n>>c>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int i=0,j=0,ans=0;
    while(i<n){
        while(arr[i]+k>=arr[j]&&j-i<c)j++;
        ans++,i=j;
    }
    cout<<ans<<endl;
}

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

int main(){
	ll N;
	cin >> N;
	if(N==1){cout << 0 << endl; return 0;}
	vector<int> prime;
	vector<bool> is_prime(1e6+1,true);
	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<=1e6; i++){
		if(!is_prime[i])continue;
		for(int j=i; j<=1e6; j+=i) is_prime[j]=false;
		prime.push_back(i);
	}

	int ans = 0;
	ll n = N;
	for(int p : prime){
		int cnt = 0;
		while(n%p == 0){
			n /= p;
			cnt++;
		}
		for(int i=1; cnt>=i; i++) { ans++; cnt-=i;}
		if(n == 1) break;
	}
	if(n!=1)ans++;
	cout << ans << endl;
	return 0;

}


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

int p(int n){
	int i,j,x=0;
	for(i=2;i<=n;i++){
		int flag=0;
		for(j=2;j<=sqrt(i);j++){
			if(i%j==0) flag++;
		}
		if(flag==0) x++;
	}
	return x;
}

int main (void){
	int n,i,ans=0;
	cin >> n;
	if(n>=78) ans++;
	if(n==100) ans=ans+p((n-n%2)/2)-1;
	if(n>=54) ans=ans+p((n-n%2)/2)-1;
	if(n>=28) ans=ans+p((n-n%2)/2)-1;
	if(n>=91) ans=ans+p((n-n%4)/4)-1;
	if(n>=70) ans=ans+p((n-n%4)/4)-1;
	if(n>=30) ans=ans+p((n-n%4)/4)-1;
	if(n>=16) ans=ans+p((n-n%4)/4)-1;
	if(n==10||n==11){
		cout << "1" << endl;
		return 0;
	}
	if(n<=9){
		cout << "0" << endl;
		return 0;
	}
	ans=ans+((p((n-n%4)/4)*(p((n-n%4)/4)-1))/2)*(p((n-n%2)/2)-2);
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, k;
    cin>>k>>A>>B;
    int cur = 0;
    for(;cur<=B;cur+=k){
        if(cur>=A){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define WHITE 0
#define BLACK 1
#define GRAY 2
using namespace std;
const int MAXN = 10000 + 4;
const int INF = 0x3f3f3f3f;
int status[MAXN], d[MAXN];
int N;
vector< pair<int, int> > ADJ[MAXN];
void Dijkstra (  )
{
    priority_queue< pair<int, int> > PQ;
    memset( status, WHITE, sizeof(status) );
    for ( int i = 0; i < N; i++ ) d[i] = INF;
    d[0] = 0;
    status[0] = GRAY;
    PQ.push(make_pair(0, 0));

    while ( !PQ.empty() ) {
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        status[u] = BLACK;

        if ( d[u] < f.first * (-1) ) continue;

        for ( int j = 0; j < ADJ[u].size(); j++ ) {
            int v = ADJ[u][j].first;
            if ( status[v] == BLACK ) continue;
            if ( d[v] > d[u] + ADJ[u][j].second ){
                d[v] = d[u] + ADJ[u][j].second;
                PQ.push(make_pair(d[v] * (-1), v));
                status[v] = GRAY;
            }
        }
    }
    for ( int i = 0; i < N; i++ ) {
        cout<<i<<' '<<( d[i] == INF ? -1 : d[i] )<<endl;
    }
}

int main()
{
    int u, D, c, v;
    cin>>N;
    for ( int i = 0; i < N; i++ ) {
        cin>>u>>D;
        for ( int j = 0; j < D; j++ ) {
            cin>>v>>c;
            ADJ[u].push_back(make_pair(v, c));
        }
    }

    Dijkstra();
    return 0;
}



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

int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}


int main(void){
	int N,i,ans=0;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){scanf("%d",&A[i]);}
	qsort(A, N, sizeof(int), compare_int);
	int count[100000][2]={},j=0;
	count[0][0] = 1;
	count[0][1] = A[0];
	for(i=1;i<N;i++){
		if(A[i] == count[j][1]) count[j][0]++;
		else {
			j++;
			count[j][0]++;
			count[j][1] = A[i];
		}
	}
	
	for(i=0;i<N;i++){
		if(count[i][0] > count[i][1]) ans += count[i][0]-count[i][1];
		else if(count[i][0] < count[i][1]) ans += count[i][0];
	}
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 1400
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//cpp_int 多倍長


using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    cpp_int A[100000];
    cpp_int sum;
    int N;
    bool zf=false;

    cin>>N;

    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]==0) zf=true;
    }

    if(zf){
        cout<<"0"<<endl;
        return 0;
    }

    sum=A[0];
    for(int i=1;i<N;i++){
        sum*=A[i];
        if(sum>1000000000000000000){
            cout<<"-1"<<endl;
            return 0;
        }
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int in;
    cin >> in;
    for (int i = 1; i <= in ; i++) {
        if(i % 3 == 0) {
            cout << " " << i;
        } else if( i % 10 == 3) {
            cout << " " << i;
        } else {
            int x = i;
            while (x > 3) {
            x /= 10;
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
            } 
        }
        
    }
    cout << endl;
    return 0;
}

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}


Measured memory_bytes: 3092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int[][] math;
	static final int MATH_LENGTH = 10;

	public static void main(String[] args) throws IOException {
		//?????°????????????
		math = new int[10][10];
		int x = 0, y = 0;
		int scale = 0;

		//??\???????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String inputStr = null;
		while (true) {
			inputStr = br.readLine();
			if (inputStr == null || inputStr.isEmpty()) {
				break;
			}
			//??\???????????????","??§??????
			String[] inputSplitStr = inputStr.split(",");
			x = Integer.valueOf(inputSplitStr[0]);
			y = Integer.valueOf(inputSplitStr[1]);
			scale = Integer.valueOf(inputSplitStr[2]);

			// ???????????´???????????????????¨????
			switch (scale) {
			case 1: //???????????´????°????
				setSmallInk(x, y);
				break;
			case 2: //???????????´?????????
				setMediumInk(x, y);
				break;
			case 3: //???????????´?????§???
				setLargeInk(x, y);
				break;
			}
		}
		//???????????¶????????????????????¨?????????????????????????????????
		int whiteNumber = 0;
		int mostNumber = 0;
		for (int i = 0; i < MATH_LENGTH; i++) {
			for (int j = 0; j < MATH_LENGTH; j++) {
				if (math[i][j] == 0) {
					whiteNumber++;
				}
				if (mostNumber < math[i][j]) {
					mostNumber = math[i][j];
				}
			}
		}
		System.out.println(whiteNumber);
		System.out.println(mostNumber);
	}

	private static void setSmallInk(int x, int y) {
		//???
		if (0 <= x - 1) {
			math[x - 1][y]++;
		}
		//???
		if (0 <= y - 1) {
			math[x][y - 1]++;
		}
		math[x][y]++;

		if (MATH_LENGTH > y + 1) {
			math[x][y + 1]++;
		}
		//???
		if (MATH_LENGTH > x + 1) {
			math[x + 1][y]++;
		}
	}

	/**
	 * [??????] ???????????´????????????????????????????????¶???
	 * 
	 * @param x
	 * @param y
	 */
	private static void setMediumInk(int x, int y) {
		//??????
		if (0 <= x - 1 && 0 <= y - 1) {
			math[x - 1][y - 1]++;
		}
		//??????
		if (0 <= x - 1 && MATH_LENGTH > y + 1) {
			math[x - 1][y + 1]++;
		}
		//??????
		if (MATH_LENGTH > x + 1 && 0 <= y - 1) {
			math[x + 1][y - 1]++;
		}
		//??????
		if (MATH_LENGTH > x + 1 && MATH_LENGTH > y + 1) {
			math[x + 1][y + 1]++;
		}
		//???????????´????°?????????¨?????????????????¶???
		setSmallInk(x, y);
	}

	private static void setLargeInk(int x, int y) {
		//???
		if (0 <= x - 2) {
			math[x - 2][y]++;
		}
		//???
		if (0 <= y - 2) {
			math[x][y - 2]++;
		}
		//???
		if (MATH_LENGTH > y + 2) {
			math[x][y + 2]++;
		}
		//???
		if (MATH_LENGTH > x + 2) {
			math[x + 2][y]++;
		}

		//???????????´??????????????¨?????????????????¶???
		setMediumInk(x, y);
	}
}

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


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> L(N);
  for(auto& l : L){
    cin >> l;
  }
  sort(L.begin(), L.end());
  int sum = 0;
  for(int ii=N-K; ii<N; ii++){
    sum += L[ii];
  }
  cout << sum << endl;
  return 0;
}

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

struct Tstr {
	int len;
	string str;
};

const Tstr Tlist[]  = {
	{5, "dream"},
	{7, "dreamer"},
	{5, "erase"},
	{6, "eraser"}
};

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

	int left_len = S.length();
	bool possible;

	while (left_len > 0) {
		possible = false;
		for (int i = 0; i < sizeof(Tlist)/sizeof(Tstr); i++) {
			int strlen = Tlist[i].len;
			string str = Tlist[i].str;

			int startpos = left_len - strlen;
			if (startpos < 0) continue;
			string substr = S.substr(startpos, strlen);
			if (substr.compare(str) == 0) {
				possible = true;
				left_len -= strlen;
				break;
			}
		}
		if (!possible) break;
	}

	if (left_len == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  for (int i = 0; i < s.length(); i++){
    if(i%2 == 0 && s[i] == 'L'){
      printf("No\n");
      return 0;
    } else if(i%2 == 1 && s[i] == 'R'){
      printf("No\n");
      return 0;
    }
  }
  
  printf("Yes\n");
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n,i;
	double x,sum=0;
	char u[4];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf%s",&x,u);
		if(u[0]=='J')
			sum+=x;
		else
			sum+=x*380000;
	}
	printf("%lf",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<utility>
#include<queue>
using namespace std;
int main() {
	int n, m, x;
	cin >> n >> m >> x;
	int k = 0;
	int k2 = 0;
	vector<int>a(m);
	for (int i = 0; i < m; i++) {
		cin >> a.at(i);

		for (int j = x; j < n + 1; j++) {
			if (j == a.at(i)) {
				k++;
				//cout << "k" << endl;
			}
		}
		for (int k = x; k >= 0; k--) {
			if (k == a.at(i)) {
				k2++;
				//cout << "k2" << endl;
			}

		}
	}
	if (k <= k2) {
		cout << k << endl;
	}
	else {
		cout << k2 << endl;
	}

}

Measured memory_bytes: 256
from collections import Counter
def main():
    N = int(input())
    V = list(map(int, input().split()))
    c0 = Counter(V[::2])
    c1 = Counter(V[1::2])
    cc0 = sorted([(0, 0)] + [(v, k) for k, v in c0.items()], reverse=True)
    cc1 = sorted([(0, 0)] + [(v, k) for k, v in c1.items()], reverse=True)
    m0, v0 = cc0[0]
    m1, v1 = cc1[0]
    if v0 != v1:
        return N - m0 - m1
    return min(N - m0 - cc1[1][0], N - m1 - cc0[1][0])
print(main())


Measured memory_bytes: 27652
// zアルゴリズムを試してみる
// https://snuke.hatenablog.com/entry/2014/12/03/214243

#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

// まずtに対してZ配列を作成
vector<int> getZArr(const string& str) {
  int str_size = str.size();

  vector<int> a(str_size);
  a[0] = str_size; // 使ってないのでなんでもいい
  int i = 1, j = 0;
  while (i + j < str_size) {
    while (i + j < str_size && str[i+j] == str[j]) {
      j++;
    }
    a[i] = j;

    if (j == 0) {
      i++;
      continue;
    }

    int k = 1;
    while (k < j && a[k] + k < j) {
      a[i+k] = a[k];
      k++;
    }

    i += k;
    // k < jでbreakした場合は、k==jで全部チェック済みなので、次回はまた最初(j=0)から。
    // a[k] + k < j でbreakした場合は、a[k] + k >= j, a[k] >= j - kなので、次は最低でもj-k-1までは一致している。よって次はj-kからチェックする
    j -= k;
  }

  return a;
}

vector<bool> check_eq(const string& s, const string& t) {
  int s_size = s.size();
  int t_size = t.size();
  vector<bool> result(s_size - t_size + 1);

  const vector<int>& zarr = getZArr(t + "$" + s); // 先に検索文字列を入れて、長さが一致するかを調べる
  int zarr_size = zarr.size();
  // 照合
  for (int i = 0; i < zarr_size; i++) {
    int j = i - (t_size + 1);
    if (j < 0) {
      continue; // t+"$"はスキップ
    }
    if (j >= result.size()) {
      break;
    }
    result[j] = zarr[i] == t_size;
  }
  
  return result;
}

int main() {
  string s,t,s_origin;
  cin >> s >> t;
  s_origin = s;
  int s_origin_size = s_origin.size();
  int t_size = t.size();
  
  while(s.size() < t_size + s_origin_size - 1) {
    s += s_origin;
  }
  s = s.substr(0, t_size + s_origin_size - 1);
  
  const vector<bool>& eqs = check_eq(s,t);
  
  int max_length = 0;
  vector<int> length(s_origin_size, -1);

  for (int i = 0; i < s_origin_size; i++) {
    if (length[i] != -1) {
      continue;
    }

    if (!eqs[i]) {
      length[i] = 0;
      continue;
    }

    int current = i;
    int diff = 0;
    queue<int> q;
    while(eqs[current]) {
      if (!q.empty() && i == current) {
        // 無限に一致する
        max_length = -1;
        goto finish;
      }

      if (length[current] != -1) {
        diff = length[current]; // すでに到達済みの場合、計算済みの長さを加えて終了する
        break;
      }
      length[current] = 0; // 一旦到達マーク設定
      q.push(current);
      current = (current + t_size) % s_origin_size;
    }

    max_length = max(max_length, diff + (int)q.size());

    while(!q.empty()) {
      int len = q.size();
      int current = q.front();
      q.pop();
      length[current] = len + diff; // 正確な長さで上書き
    }
  }

finish:
  cout << max_length << endl;
  
  return 0;
}


Measured memory_bytes: 10104
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535
const long long int MOD = 2019;
#define pb push_back
#define mp make_pair
#define fill(a)  memset(a, 0, sizeof (a))
#define SORT(v)  sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 200000 + 5;
const long long int MINN = 2e5 + 5;
const long long int inf = 1e6;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;

ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// bool isl = binary_search(x.begin(), x.end(), 5);
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 10050;
const int MAXN = 105;
int binsearch(int lo, int hi){
	while(lo<hi){
		int mid=(lo+hi)/2;
		if((mid))   // check(mid)
			hi=mid;
		else
			lo=mid+1;
	}
	return lo;
}
ll power(ll x,ll y){
    ll res=1;
    while(y>0){
      if(y&1) res=((res*x));

      y/=2;
      x=((x*x));
    }
    return res;
}


int main(){
    FAST
    int n;
  cin>>n;
 	n= n%10;
  if(n==3){
    cout<<"bon";
  }
  else if(n==0 || n==1 || n==6 ||n==8) cout<<"pon";
  else cout<<"hon";

    return 0;
}


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

const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

const int N=2e5+50;
int n,col[N];
struct Tree {
    int stx,fa[N],dep[N];
    vector <int> edge[N];
    inline void dfs(int x,int f,int d=0) {
        fa[x]=f; dep[x]=d;
        for(auto v:edge[x]) if(v!=f) dfs(v,x,d+1);
    }
    inline void init() {
        for(int i=1;i<n;i++) {
            int x=rd(), y=rd();
            edge[x].push_back(y);
            edge[y].push_back(x);
        } dfs(stx,0);
    }
    inline bool valid(int x,int y,int rs=0) {
        while(dep[x]>dep[y]) if((x=fa[x],++rs)>=3) return false;
        while(dep[x]<dep[y]) if((y=fa[y],++rs)>=3) return false;
        while(x!=y) if((y=fa[y],x=fa[x],rs+=2)>=3) return false;
        return true;
    }
} A,B;
inline void dfs(int x) {
    if(A.dep[x]>=B.dep[x]) return;
    col[x]=1;
    for(auto v:A.edge[x]) if(v!=A.fa[x]) dfs(v);
}
int main() {
    n=rd(); A.stx=rd(); B.stx=rd();
    if(A.stx==B.stx) {puts("0"); return 0;}
    A.init(); B.init();
    dfs(A.stx);
    for(int i=1;i<=n;i++) 
        for(auto v:A.edge[i])
            if(col[i] && !B.valid(i,v)) {puts("-1"); return 0;}
    int ans=0;
    for(int i=1;i<=n;i++) 
        if(col[i]) ans=max(ans,B.dep[i]);
    cout<<(ans<<1)<<'\n';
}

Measured memory_bytes: 31740
/*
root the tree at node 1
dp(u,0) = no of ways to paint the subtree rooted at node u given that it can be painted either black or white
dp(u,1)  = no of ways to paint the subtree rooted at node u given that it can be painted with only white.
0 means no constarint
1 means constraint
base case:
dp(leaf,0) = 2
dp(leaf,1) = 1 
*/ 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
vector<ll> tree[100001];
ll dp[100001][2];
ll solve(ll u , bool constraint , ll par){
   if(dp[u][constraint] != -1){
       return dp[u][constraint];
   }
   ll ans = 0;
   ll w1 = 1;
   for(ll child : tree[u]){
       if(child != par){
           w1 = (w1*solve(child , 0 , u))%mod;
       }
   }
   ans += w1;
   if(!constraint){
     ll w2 = 1;
     for(ll child : tree[u]){
       if(child != par){
           w2 = (w2*solve(child , 1 , u))%mod;
       }
     }
     ans = (ans + w2)%mod;
   }
   return dp[u][constraint] = ans;
}
int main() {
    memset(dp , -1 , sizeof(dp));
    ll n;
    cin>>n;
    for(ll i=0 ; i<n-1 ; i++){
        ll x , y;
        cin>>x>>y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    cout<<solve(1 , 0  , -1);
    return 0;
}


Measured memory_bytes: 15616
#include<stdio.h>
#define PMAX 1000000000
int wmax=0;
int n,k,w[100000];
 
int check(int P){
    int i;
    int count=1,now=P;
    if(P<wmax) return 0;
    for(i=0;i<n;i++){
        if(now>=w[i]){
           now-=w[i];
        }else{
            count++;
            now=P-w[i];
        }
    }
    if(count>k) return 0;
    else return 1;
}
 
int main(void){
    int i;
    int left,right,mid;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
        if(w[i]>wmax) wmax=w[i];
    }
 
    left=0,right=PMAX;
    while(right-left>1){
        mid=(left+right)/2;
        if( check(mid) ) right=mid;
        else left=mid;
    }
    printf("%d\n",right);
    return 0;
}
 
  

Measured memory_bytes: 984
n=int(input())

line=[]

for i in range(n):
    sub=list(input().split( ))
    sub[1]=-int(sub[1])
    sub.append(i+1)
    line.append(sub)

line.sort(key=lambda x:(x[0],x[1]))

for i in range(n):
    print(line[i][2])

Measured memory_bytes: 38256
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad

main :: IO ()
main = breads >>= main'
    where
        main' [n, m] = replicateM 2 B.getLine >>= print . solve n m 

solve :: Int -> Int -> [B.ByteString] -> Int
solve n m [ss, ts] = check 0
    where
        check x
            | s >= n || t >= m = l
            | B.index ss s == B.index ts t = check $ x + 1 
            | otherwise = -1
            where
                s = i * x
                t = j * x
        l = lcm n m 
        i = l `div` m
        j = l `div` n 
        

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 764
package main
  
import (
    "fmt"
    "math"
)

var num int
var nc map[int]int
var ps []int
var ns [][]int
var sum int

func main() {
    fmt.Scan(&num)

    rn := int(math.Sqrt(float64(num)))
    makePl(rn)

    nc = make(map[int]int)
    pf(num)

    //fmt.Println(nc)

    ns = make([][]int, 0)
    for k, v := range nc {
        ns = append(ns, []int{k, v})
    }

    calc(0, 1)

    fmt.Println(sum)
}

// 2^3 = 8 0,2,4,8
// 3^2 = 9 0,3,9
func calc(k, n int) {
    if k >= len(ns) {
        if n > 2 && num%(n-1) != 0 && num/n < n-1 {
            //fmt.Println(n - 1)
            sum += (n - 1)
        }
        return
    }
    //fmt.Println(ns, k)
    p, cnt := ns[k][0], ns[k][1]
    calc(k+1, n) // 0
    for i := 1; i <= cnt; i++ {
        n *= p
        calc(k+1, n)
    }
}

func makePl(n int) {
    var npm = make(map[int]bool)
    for i := 2; i <= n; i++ {
        if b, ok := npm[i]; ok && b {
            continue
        }
        for j := i * 2; j <= n; j += i {
            npm[i] = true
        }
        ps = append(ps, i)
    }
}

func pf(n int) {
    if n <= 1 {
        return
    }
    for _, p := range ps {
        for n%p == 0 {
            nc[p]++
            n /= p
        }
    }
    if n != 1 {
        nc[n]++
    }
}


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


map<string,int>mp;
int main()
{
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string temp;
        cin>>temp;
        mp[temp]++;
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        string temp;
        cin>>temp;
        mp[temp]--;
    }
    int ans=0;
    for(auto x:mp)
    {
        ans=max(ans,x.second);
    }
    printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a = 1000,b = 5000,c = 10000;
 
void calc(int n,int y){
     
  for(int i = 0; i<=n; i++){
    for(int j = 0; j<=n-i;j++){
          
        int k= n-i-j;
        if(c * i + b * j + a * k == y){
          if(i + j + k == n){
            cout << i << " " << j << " " << k << endl;
            return;
          }
        }
    }
  }
  
  cout << -1 << " " << -1 << " " << -1 << endl;
  return;
} 
 
int main(){
 
  int n,y;
  cin >> n >> y;
 
  calc(n,y);
  
  return 0;
  
}

Measured memory_bytes: 504
#include <iostream>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b == c+d) {
    cout << "Balanced" << endl;
  } else if (a+b < c+d) {
    cout << "Right" << endl;
  } else {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderContest
{
    class Program
    {
        static void Main()
        {
            Console.ReadLine();
            var span = Console.ReadLine().ToCharArray().AsSpan();
            Console.WriteLine(Solve(span));
        }

        private static int Solve(Span<char> span)
        {
            if (span.Length == 0)
            {
                return 0;
            }

            var firstWhiteIndex = span.IndexOf(new ReadOnlySpan<char>(new char[] { 'W' }));
            var lastRedIndex = span.LastIndexOf(new ReadOnlySpan<char>(new char[] { 'R' }));

            if (firstWhiteIndex == -1 || lastRedIndex == -1)
            {
                return 0;
            }

            if (firstWhiteIndex > lastRedIndex)
            {
                return 0;
            }

            return 1 + Solve(span.Slice(firstWhiteIndex + 1, lastRedIndex - firstWhiteIndex - 1));
        }
    }
}


Measured memory_bytes: 45876
a=gets.chomp
if a.length%2==0
   b=a.scan(/.{1,#{2}}/)
   c=b.length
   o=0
   b.each do |x|
     if x=="hi"
       o+=1
     end
   end
  if o==c
    puts "Yes"
  else puts "No"
  end
  
  else puts "No"
end

Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>

#pragma warning(disable:4996)

using namespace std;

int main() {
  int n;
  cin >> n;
  cout << n * 800 - n / 15 * 200 << endl;
  return 0;
}

Measured memory_bytes: 256
//递归
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
typedef long long ll;
string s;
ll sum;
void dfs(vector<bool> b){
    if(b.size()==s.size()-1){
        ll tmp=0;
        // for(int i=0;i<b.size();++i)cout<<b[i];cout<<endl;
        for(int i=0;i<s.size();++i){
            tmp=tmp*10+s[i]-'0';
            if(i!=s.size()-1&&b[i]){/*cout<<tmp<<endl;*/sum+=tmp;tmp=0;}
        }
        sum+=tmp;
        return;
    }
    b.push_back(0);
    dfs(b);
    b.pop_back();
    b.push_back(1);
    dfs(b);
}
int main(){
    cin>>s;
    vector<bool> b;
    dfs(b);
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;
    int i = 0;
    while(i < s.size() && s[i] == '1'){
        i++;
    }
    
    if(k<i+1 || i == s.size())cout << '1' << endl;
    else cout << s[i] << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


sys.setrecursionlimit(10**9)
from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#

def main():
	mod=10**9+7
	n=II()
	G=[[] for _ in range(n+1)]
	p=[0]*(n+1)
	v=[0]*(n+1)


	for _ in range(n-1):
		a,b=MI()
		G[a].append(b)
		G[b].append(a)

	inv2=[1]*(n+1)
	t=pow(pow(2,n,mod),mod-2,mod)
	for i in range(n,-1,-1):
		inv2[i]=t
		t*=2
		t%=mod
	#print(inv2)

	def dfs(a):
		cnt=1
		for i in G[a]:
			if p[a]==i:
				continue
			else:
				p[i]=a
				cnt+=dfs(i)
		v[a]=cnt
		return cnt
	dfs(1)
	#print(v)

	def f(a):
		return (1-inv2[a])*(1-inv2[n-a])%mod

	ans=1-inv2[n]-n*inv2[1]
	for i in range(1,n+1):
		ans+=f(v[i])%mod
	print(ans%mod)



if __name__ == "__main__":
	main()

Measured memory_bytes: 206524
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e18;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;
const int K = 31;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

int32_t main()
{
 
   IOS
	int r;
    cin>>r;
    cout<<2*acos(-1)*r<<endl;
    
   

}

Measured memory_bytes: 3812
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int cnt = 0, streak = 0;
    repi(i, n, 0)
    {
        int p;
        cin >> p;
        if (p == i + 1)
        {
            streak++;
        }
        else if (streak > 1)
        {
            cnt += (streak + 1) / 2;
            streak = 0;
        }
        else
        {
            cnt += streak;
            streak = 0;
        }
    }
    if (streak > 1)
    {
        cnt += (streak + 1) / 2;
    }
    else if (streak > 0)
    {
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = i / 10000 + i % 10000 / 1000 
      + i % 10000 % 1000 / 100 
      + i % 10000 % 1000 % 100 / 10 
      + i % 10000 % 1000 % 100 % 10;
    if (x >= a && x <= b) ans += i;
  }

  cout << ans << endl;

  return 0;
}


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

void main_()
{
    string s;
    cin >> s;
    string s1, s2;

    // xを取り除いた状態で回文にならなければ、達成不可能
    remove_copy(begin(s), end(s), back_inserter(s1), 'x');
    reverse_copy(begin(s1), end(s1), back_inserter(s2));
    if (s1 != s2) {
        cout << -1 << endl;
        return;
    }

    auto count_x = [](auto it, auto n) {
        vector<ll> c;
        while (n--) {
            ll counter = 0;
            while (*it++ == 'x') {
                counter++;
            }
            c.push_back(counter);
        }
        return c;
    };

    ll half_len = s1.size() / 2 + 1;
    auto c1 = count_x(begin(s), half_len);
    auto c2 = count_x(rbegin(s), half_len);

    ll ans = 0;
    for (ll i = 0; i < half_len; ++i) {
        ans += abs(c1[i] - c2[i]);
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

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

Node root;

Node treeMinimum(Node x){


}

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

Node treeSuccessor(Node x){


}

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



}

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

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

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


}

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


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

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

	return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
char st[1000005];
int sr[1000005], sw[1000005];
int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", st + 1);
	for (int i = 1; i <= n; i ++) {
		sr[i] = sr[i - 1];
		sw[i] = sw[i - 1];
		if (st[i] == 'R') sr[i] ++;
		else sw[i] ++;
	}
	int ans = 1e9;
	for (int i = 0; i <= n; i ++) {
		int x = sw[i], y = sr[n] - sr[i];
		ans = min(ans, max(x, y));
	}
	printf("%d\n", ans);
	return 0;
}




Measured memory_bytes: 5540
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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 (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll C=0;
    string S;
    cin >> S;
    rep(i,S.size()){
        if(S[i]=='1'){
            C++;
        }
    }
    cout << C << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int x;
  cin>>x;
  if(x<=599){
  cout<<"8";
  }
  else if(x<=799){
    cout<<"7";
  }
  else if(x<=999){
    cout<<"6";
  }
  else if(x<=1199){
    cout<<"5";
  }
  else if(x<=1399){
    cout<<"4";
  }
  else if(x<=1599){
    cout<<"3";
  }
  else if(x<=1799){
    cout<<"2";
  }
  else{
    cout<<"1";
  }
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

const ll MOD = 1000000007;

// MOD を法とした a^n を計算する
ll modpow(ll a, ll n, ll MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
	ll N, K;
	cin >> N >> K;

	vector <ll> dp(K+1, 0);
	ll sum = 0;
	for (ll ii = K; ii >= 1; --ii){
		dp[ii] = modpow(K/ii, N, MOD);
		for (ll jj = 2*ii; jj <= K; jj+=ii){
			dp[ii] = (dp[ii] - dp[jj] + MOD) % MOD;
		}
		sum = (sum + dp[ii] * ii) % MOD;
	}

	cout << sum << endl;

	return 0;
}


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e9;
const int MB = 30;
const int MOD = 1e9 + 7;

void solve() {
	char c;
	cin >> c;
	if (c >= 'A' && c <= 'Z') cout << 'A';
	else cout << 'a';
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 3640
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
B = [int(input()) for i in range(N)]
BINGO = False
for j in range(3):
    for i in range(3):
        if A[i][j] in B:
            continue
        break
    else:
        BINGO = True
        
if not BINGO:
    for i in range(3):
        for j in range(3):
            if A[i][j] in B:
                continue
            break
        else:
            BINGO = True

if not BINGO:
    for i in range(3):
        if A[i][i] in B:
            continue
        break
    else:
        BINGO = True

if not BINGO:
    for i in range(3):
        if A[i][2-i] in B:
            continue
        break
    else:
        BINGO = True
        
print('Yes' if BINGO else 'No')

Measured memory_bytes: 3064
from collections import deque

n, q = [int(i) for i in input().split()]

tree = [[] for _ in range(n+1)]
for _ in range(n-1):
    a, b = [int(i) for i in input().split()]
    tree[a].append(b)
    tree[b].append(a)

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])


Measured memory_bytes: 119244
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int xa[110],ya[110];
int main()
{
	int N,M,X,Y;
	bool pd=true;
	cin>>N>>M>>X>>Y;
	for(int i=0;i<N;i++)
		cin>>xa[i];
	for(int i=0;i<M;i++)
		cin>>ya[i];
	sort(xa,xa+N);
	sort(ya,ya+M);
	if(X<Y)
	{
		int sum=Y-X;
		for(int K=X+1;K<=X+sum;K++)
		{
			if((xa[N-1]<K)&&(ya[0]>=K))
			{
				pd=false;
				break; 
			}	
				
		}	
	}
	if(pd)
	cout<<"War";
	else
	cout<<"No War";
	return 0;			
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author yoshizaki
 *131
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        long min = scanner.nextLong();
        long max = scanner.nextLong();
        long divider1 = scanner.nextLong();
        long divider2 = scanner.nextLong();
        long ans = 0l;
        
        if(min == max && (min == divider1 || min == divider2)) {
            ans = 0;
        } else {
            
        long min1 = min / divider1;
        if (min % divider1 == 0) min1 -=1;
        long max1 = max / divider1;
        
        long min2 = min / divider2;
        if (min % divider2 == 0) min2 -=1;
        long max2 = max / divider2;
        
        long crossDivider = lcm(divider1, divider2);
        long crossmin = min / crossDivider;
        if (min % crossDivider == 0) crossmin -=1;
        long crossmax = max / crossDivider;
        
        long mm = max1 - min1;
        long nn = max2 - min2;
        long cc = crossmax - crossmin;
        ans = (max - min + 1) -(mm + nn - cc);
        }
        
        System.out.println(ans);
    }
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 21972