akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAXN	200005
#define MAXLOG	20
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, x, y, u[MAXN], v[MAXN];
int depth[MAXN], father[MAXN][MAXLOG];
vector <int> a[MAXN], b[MAXN];
bool mark[MAXN], visited[MAXN];
void work(int pos, int fa) {
	depth[pos] = depth[fa] + 1;
	father[pos][0] = fa;
	for (int i = 1; i < MAXLOG; i++)
		father[pos][i] = father[father[pos][i - 1]][i - 1];
	for (unsigned i = 0; i < a[pos].size(); i++)
		if (a[pos][i] != fa) work(a[pos][i], pos);
}
int lca(int x, int y) {
	if (depth[x] < depth[y]) swap(x, y);
	for (int i = MAXLOG - 1; i >= 0; i--)
		if (depth[father[x][i]] >= depth[y]) x = father[x][i];
	if (x == y) return x;
	for (int i = MAXLOG - 1; i >= 0; i--)
		if (father[x][i] != father[y][i]) {
			x = father[x][i];
			y = father[y][i];
		}
	return father[x][0];
}
int dist(int x, int y) {
	return depth[x] + depth[y] - 2 * depth[lca(x, y)];
}
void work(int pos, int fa, int step) {
	if (step >= depth[pos]) return;
	visited[pos] = true;
	for (unsigned i = 0; i < b[pos].size(); i++)
		if (b[pos][i] != fa) work(b[pos][i], pos, step + 1);
}
int main() {
	read(n), read(x), read(y);
	for (int i = 1; i < n; i++)
		read(u[i]), read(v[i]);
	for (int i = 1; i < n; i++) {
		int x, y;
		read(x), read(y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	depth[0] = -1;
	work(y, 0);
	for (int i = 1; i < n; i++)
		if (dist(u[i], v[i]) >= 3) mark[u[i]] = mark[v[i]] = true;
		else {
			b[u[i]].push_back(v[i]);
			b[v[i]].push_back(u[i]);
		}
	work(x, 0, 0);
	int ans = 0;
	for (int i = 1; i <= n; i++)
		if (visited[i]) if (mark[i]) {
			printf("-1\n");
			return 0;
		} else ans = max(ans, depth[i] * 2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 48384
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N,M;cin>>N>>M;
    if(N%2==1){
        REP(i,M){
            cout<<1+i<<" "<<2*M-i<<endl;
        }
    }
    else{
        REP(i,M){
            int z=2*M-i;
            int a=1+i;
            if(z-a>=N/2)z++;
            cout<<z<<" "<<a<<endl;
        }
    }
}

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

using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll s;
    std::cin >> s;
    if(s <= 2){
        std::cout << 0 << std::endl;
        return 0;
    }
    std::vector<ll> dp(s + 1, 0);
    dp[0] = 1;
    for(int i = 1; i <= s; i++){
        for(int j = i - 3; j >= 0; j--){
            dp[i] += dp[j];
            dp[i] %= MOD;
        }
    }
    std::cout << dp[s] << std::endl;
    return 0;
}


Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    int P = 0;
    char tmp[100000];
    if (scanf("%s", tmp) < 1) return 0;

    for (int i = 0; i < strlen(tmp); i++)
        if (tmp[i] == 'p') P++;

    printf("%d\n", strlen(tmp) / 2 - P);
    return 0;
}


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

using namespace std;
using ll =long long;
using db = double;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める

int main()
{
	cout << setprecision(10);
	int n;
	cin >> n;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	ll ans = -n;
	rep(i,n){
		ans += v[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
 
int main(){
    int N;
    cin >> N;
    vector<int> odd,even;
    rep(i,N){
        int v;
        cin >> v;
        if(1&i) odd.push_back(v);
        else even.push_back(v);
    }
    //最頻値を取り出す
    int odd_mode1 = 0,odd_mode2 = 0,even_mode1 = 0,even_mode2 = 0;
    map<int,int> mapo,mape;
    rep(i,N/2){
        mapo[odd[i]]++;
        if(mapo[odd_mode1] < mapo[odd[i]]){   
            odd_mode2 = odd_mode1;
            odd_mode1 = odd[i];
        }
        if(odd_mode1 != odd[i] && mapo[odd_mode2] < mapo[odd[i]]){
            odd_mode2 = odd[i];
        }
 
        mape[even[i]]++;
        if(mape[even_mode1] < mape[even[i]]){
            even_mode2 = even_mode1;
            even_mode1 = even[i];
        }
        if(even_mode1 != even[i] && mape[even_mode2] < mape[even[i]]){
            even_mode2 = even[i];
        }
    }
    int res = 0;
    if(odd_mode1 == even_mode1){
        res = min(N-mapo[odd_mode1]-mape[even_mode2],N-mapo[odd_mode2]-mape[even_mode1]);
    }else{
        res = (N/2 - mapo[odd_mode1]) + (N/2 - mape[even_mode1]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5372
N = int(input())
moji = input()
moji_len = []
moji_len.append(moji)
flag = "Yes"
for i in range(N-1):
	siri = input()
	if(siri in moji_len):
		flag = "No"
	if not(moji[-1]==siri[0]):
		flag = "No"
	moji_len.append(siri)
	moji = siri
print(flag)

Measured memory_bytes: 3064
s = input()
sn = len(s)
t = input()
tn = len(t)
ans = 10000
for i in range(sn-tn+1):
    cou = 0
    for j in range(tn):
        if s[i+j] != t[j]:
            cou += 1
    ans = min(ans,cou)
print(ans)

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


int main() {
    int n;
    cin>>n;
    double a,ans;
    rep(i,n){
        cin>>a;
        ans+=1/a;
    }
    cout << 1/ans <<endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

S = input().strip()
T = input().strip()
T = T[:-1]

if S == T:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9276
/*
 * ID: 0587
 * Problem: tunnnel
 */

#include <stdio.h>

int main(void)
{
    int term, car;
    scanf("%d", &term);
    scanf("%d", &car);

    int max = car;
    for (int i = 0; i < term; i++) {
        int in, out;
        scanf("%d %d", &in, &out);
        car = car + in - out;
        max = max > car ? max : car;
        if (car < 0) {
            max = 0;
            break;
        }
    }

    printf("%d\n", max);
    
    return 0;
}



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

using namespace std;

const int NMAX = 3000;
const int MOD = 1e9 + 7;

int N;
string s;

int dp[NMAX + 5][NMAX + 5]; ///dp[i][j] -> nr de permutari de lungime i cu ultimul element j
int sp[NMAX + 5][NMAX + 5]; ///sp[i][j] -> suma dp[i][1] + dp[i][2] + ... + dp[i][j]

int main()
{
    cin >> N >> s;

    dp[1][1] = sp[1][1] = 1;

    for(int l = 2; l <= N; l++)
        {
            for(int c = 1; c <= l; c++)
                {
                    if(s[l - 2] == '<')
                        dp[l][c] = sp[l - 1][c - 1];
                    else
                        dp[l][c] = (sp[l - 1][l - 1] - sp[l - 1][c - 1] + MOD) % MOD;
                }

            ///sp
            for(int c = 1; c <= l; c++)
                sp[l][c] = (sp[l][c - 1] + dp[l][c]) % MOD;
        }

    cout << sp[N][N] << '\n';

    return 0;
}


Measured memory_bytes: 69504
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int cnt[100010],mcnt[100010],n,m;
int main(){
    lol(i,100010)cnt[i]=0;
    cin>>n>>m;
    lol(i,n){
	int x;cin>>x;
	cnt[x]++;
	mcnt[x%m]++;
    }
    lol(i,100010){
	if(i<m)cnt[i]/=2;
	else cnt[i%m]+=cnt[i]/2;
    }
    int ans=mcnt[0]/2;
    for(int i=1;i<m;i++){
	int to=m-i;
	if(i>to)break;
	if(i==to){
	    ans+=mcnt[i]/2;
	    break;
	}
	if(mcnt[i]<mcnt[to]){
	    ans+=mcnt[i]+min((mcnt[to]-mcnt[i])/2,cnt[to]);
	}
	else{
	    ans+=mcnt[to]+min((mcnt[i]-mcnt[to])/2,cnt[i]);
	}
    }
    cout<<ans<<endl;
    //lol(i,m)cout<<cnt[i]<<" "<<mcnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int num[(1<<5)+1];
int ZZ(int a)
{
	int o=0;
	while(a)
	{
		a-=a&-a;
		o++;
	}
	return o;
}
int main()
{
	int n,i,check=0,tmp;
	long long s,sum=0;
	char c[11];
	scanf("%d",&n);
	for(i=0;i<n;i++)	
	{
		scanf("%s",c);
		switch(c[0])
		{
			case 'M':
				check|=1<<4;
				num[1<<4]++;
				break;
			case 'A':
				check|=1<<3;
				num[1<<3]++;
				break;
			case 'R':
				check|=1<<2;
				num[1<<2]++;
				break;
			case 'C':
				check|=1<<1;
				num[1<<1]++;
				break;
			case 'H':
				check|=1<<0;
				num[1<<0]++;
				break;
		}
	}
	for(i=0;i<(1<<5);i++)
	{
		if(ZZ(i)!=3)
			continue;
		if(check&i!=i)
			continue;
		tmp=i;
		s=1;
		while(tmp)
		{
			s*=num[tmp&-tmp];
			tmp-=tmp&-tmp;
		}
		sum+=s;
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 256
// 0030.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int bit(int n, int s, int now)
{
	if (s < 0) { return 0; }
	if ((s != 0 || n != 0) && now == 10)
	{
		return 0;
	}
	if (s == 0 && n == 0 && now == 10)
	{
		return 1;
	}
	return bit(n - 1, s - now, now + 1) + bit(n, s, now + 1);
}
int main()
{
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, s;
	while (true) {
		cin >> n >> s;
		if (n == s&&n == 0) { break; }
		//vector<int>a;
		cout <<bit(n,s,0) << endl;
	}
	return 0;
}



Measured memory_bytes: 3168
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c,d[100]={0},e,f;
	long long D[100][21]={0};
	cin>>a;
	int Z=0;
	for (b=0;b<a;b++)
	{
		cin>>c;
		d[b]=c;
		if (b==0)
		{
			D[b][c]=1;
		}
		else
		{
			for (e=0;e<21;e++)
			{
				if (D[b-1][e]>0)
				{
					f=e-c;
					if (f>=0)
					{
						D[b][f]+=D[b-1][e];
					}
					f=e+c;
					if (f<=20)
					{
						D[b][f]+=D[b-1][e];
					}
					
				}
				
			}
		}
		
	}
	cout<<D[a-2][d[a-1]]<<endl;
	return 0;
}
		

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

int main(){
    double N,M,sum=0,ans=0;
    cin>>N>>M;
    vector<double> A(N),B(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
        sum +=A.at(i);
    }
    for(int i=0;i<N;i++){
        if(A.at(i)>=sum/(4*M)){
            B.at(i)=1;
        }else{
            B.at(i)=0;
        }
        ans +=B.at(i);
    }
    if(ans>=M){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;

int N = 100002;
int tree[210005];

void update(int l, int r, int v){
	for(l += N,  r += N;l < r;l >>= 1,r >>= 1){
		if(l&1) tree[l++] += v;
		if(r&1) tree[--r] += v;
	}
}
int query(int i){
	int res = 0;
	for(i += N;i;i >>= 1) res += tree[i];
	return res;
}

int arr[100005];
signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	for(int i = 0;i <= n;i++) cin >> arr[i];
	
	if(n == 0){
		if(arr[0] == 1) cout << 1;
		else cout << -1;
		return 0;
	}
	if(arr[0] != 0){
		if(n == 0 && arr[0] == 1) cout << 1;
		else cout << -1;
		return 0;
	}
	
	int total = 0;
	for(int i = 0;i <= n;i++) total += (i+1)*arr[i];
	
	for(int i = 1;i <= n;i++){
		if(arr[i] != 0){
			arr[i]--;
			update(0, i, 1);
			break;
		}
	}
	
	int level = 0;
	for(int i = 1;i <= n;i++){
		if(arr[i] == 0) continue;
				
		int left = query(level);
		if(level == i){
			cout << -1;
			return 0;
		}
		
		if(left >= arr[i]){
			update(level,level+1,-arr[i]);
			total -= arr[i]*(level+1);
			update(level+1, i, arr[i]);
			//cout << i << " " << arr[i] << " " << level << "\n";
			
			left -= arr[i];
		}
		else{
			update(level,level+1,-left);
			total -= (left)*(level+1);
			update(level+1, i, left);
			//cout << i << " " << left << " " << level << "\n";
			
			arr[i] -= left;
			
			level++;
			i--;
		}
	}
	
	cout << total;
	
	
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll X;
    cin >> X;

    ll N = X / 100;
    if(100*N <= X && X <= 105*N) PR(1);
    else PR(0);

    return 0;
}

/*



*/

Measured memory_bytes: 3636
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let h = it.next().unwrap().parse::<usize>().unwrap();
    let w = it.next().unwrap().parse::<usize>().unwrap();
    let m = it.next().unwrap().parse::<usize>().unwrap();
    let b = (0..m).map(|_| (it.next().unwrap().parse::<usize>().unwrap(), it.next().unwrap().parse::<usize>().unwrap())).collect::<Vec<_>>();
    let mut cnt_h = vec![0; h+1];
    let mut cnt_w = vec![0; w+1];
    for &p in &b {
        cnt_h[p.0] += 1;
        cnt_w[p.1] += 1;
    }
    let max_h = *cnt_h.iter().max().unwrap();
    let max_w = *cnt_w.iter().max().unwrap();
    let overlap = cnt_h.iter().fold(0, |a, &x| a + if x == max_h { 1 } else { 0 }) * cnt_w.iter().fold(0, |a, &x| a + if x == max_w { 1 } else { 0 });
    let cover = b.iter().fold(0, |a, &(x, y)| a + if cnt_h[x] == max_h && cnt_w[y] == max_w { 1 } else { 0 });
    println!("{}", max_h + max_w - if cover == overlap { 1 } else { 0 });
}


Measured memory_bytes: 12920
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N;
    scan(N);
    int sum    = 0;
    auto check = [](string now) {
        bool a = false;
        bool b = false;
        bool c = false;
        REP(i, now.size()) {
            if (now[i] == '7')
                a = true;
            if (now[i] == '5')
                b = true;
            if (now[i] == '3')
                c = true;
        }
        return (a & b & c);
    };

    auto dfs = [&](auto f, string nxt) {
        if (nxt != "") {
            ll now = stoll(nxt);
            if (N < now)
                return;
            if (check(nxt))
                sum++;
            if (N == now)
                return;
        }
        f(f, nxt + "7");
        f(f, nxt + "5");
        f(f, nxt + "3");
    };
    dfs(dfs, "");
    print(sum);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define Int int64_t
using namespace std;
const Int M=(Int)(1e9+7);


Int N;

int main()
{
   int t;t=1;
   while(t--){
       cin>>N;
       cout<<N+(N*N)+(N*N*N)<<"\n";
   }
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	char s[5];
	scanf("%s",s);
	if(s[0]=='A'&&s[1]=='A'&&s[2]=='A'){
		printf("No\n");
	}
	else if(s[0]=='B'&&s[1]=='B'&&s[2]=='B'){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
} 

Measured memory_bytes: 888
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int n, k;
  cin >> n >> k;
  if (n >= 10) {
    cout << k << endl;
  } else {
    int ans = k + (10 - n) * 100;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int seen[200010],ans[200010];
vector<vector<int> > g(200010);
int dfs(int x){
  seen[x]=1;
  int i;
  for(i=0;i<g[x].size();i++){
    if(seen[g[x][i]]==0){
      ans[g[x][i]]+=ans[x];
      dfs(g[x][i]);
    }
  }
};
int main(){
  int i,n,q,a,b,p,x;
  scanf("%d %d\n",&n,&q);
  for(i=0;i<n;i++){
    ans[i]=0,seen[i]=0;
  }
  for(i=0;i<n-1;i++){
    scanf("%d %d\n",&a,&b);
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for(i=0;i<q;i++){
    scanf("%d %d\n",&p,&x);
    p--;
    ans[p]+=x;
  }
  for(i=0;i<n;i++){
    if(seen[i]==0){
      dfs(i);
    }
  }
  for(i=0;i<n;i++){
    if(i==0){
      printf("%d",ans[i]);
    }
    else{
      printf(" %d",ans[i]);
    }
  }
  printf("\n");
  return 0;
}

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

int main() {
  int x, y;
  cin >> x >> y;
  int conx;
  int cony;
  if (x == 2) {
    conx = 2;
  }
  else if (x == 4 || x == 6 || x == 9 || x == 11) {
    conx = 1;
  }
  else {
    conx = 0;
  }
  if (y == 2) {
    cony = 2;
  }
  else if (y == 4 || y == 6 || y == 9 || y == 11) {
    cony = 1;
  }
  else {
    cony = 0;
  }
  if (conx == cony) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main() {


string n;
cin>>n;
bool t=true;
for(int i=0;i<3;i++){

    if(n[i]=='7'){
        cout<<"Yes"<<endl;
        t=false;
        break;

    }
}
if(t)
cout<<"No"<<endl;



}

Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>

int main() {

	int i, length, head = -1, tail = -1;
	char s[100000];
	scanf("%s", &s);

	length = strlen(s);

	if (s[0] == s[1]) {
		head = 1;
		tail = 2;
	}
	else {
		for (i = 2; i < length; i++) {
			if (s[i - 2] == s[i]) {
				head = i - 1;
				tail = i + 1;
			}
			if (s[i - 1] == s[i]) {
				head = i;
				tail = i + 1;
			}
		}
	}
	
	printf("%d %d\n", head, tail);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
    boost;
    ll n;double d;
    cin>>n>>d;
    ll ans = 0;
    for(ll i=0; i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        double z = sqrt(x*x + y*y);
        if(z <= d)
        ans++;
    }
    cout<<ans<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3800
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		String[] s = new String[n];
		for (i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		sc.close();
		HashMap<String, Integer> map = new HashMap<>();
		for (i = 0; i < n; i++) {
			if(map.get(s[i])==null) {
				map.put(s[i], 1);
			} else {
				map.put(s[i], map.get(s[i])+1);
			}
		}
		ArrayList<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(map.entrySet());
		list.sort((e1,e2)->e1.getValue()==e2.getValue()?e1.getKey().compareTo(e2.getKey()):e2.getValue()-e1.getValue());
		int mx = list.get(0).getValue();
		PrintWriter pw = new PrintWriter(out);
		for (Entry<String, Integer> entry : list) {
			if(entry.getValue() != mx) break;
			pw.println(entry.getKey());
		}
		pw.flush();
	}
}


Measured memory_bytes: 73216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    pair<pair<string,int>,int> p[101];
    for(int i=0;i<N;i++){
        string s;
        int q;
        cin >> s >> q;
        p[i] = make_pair(make_pair(s,-q),i);
    }
    sort(p, p+N);
    for(int i=0;i<N;i++){
        cout<<p[i].second + 1<<endl;
    }
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;

int main() {
  int n, k;
  cin >> n >> k;
  VI v(k);
  for (int i = 0; i < n; i++) {
    v[i % k]++;
  }
  int mx = 0, mi = 1e9;
  for (int i = 0; i < k; i++) {
    mx = max(mx, v[i]);
    mi = min(mi, v[i]);
  }
  cout << mx - mi << endl;
}


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



int main(){
    string s;
    cin >> s;
    int n=s.size();
    bool flag=true;
    int maenaka=(n-1)/2;
    char mae[maenaka],ushiro[maenaka];
    for(int i=0; i<maenaka; i++){
        mae[i]=s[i];
        ushiro[i]=s[n-1-i];
        if(mae[i]!=ushiro[i]){
            flag=false;
            break;
        }
    }
    if(flag){
        int t=maenaka;
        if(t%2==1){
            int naka1=(maenaka-1)/2;
            char mae2[naka1],ushiro2[naka1];
            for(int i=0; i<naka1; i++){
                mae2[i]=mae[i];
                ushiro2[i]=mae[((n-1)/2)-1-i];
                if(mae2[i]!=ushiro2[i]){
                    flag=false;
                    break;
                }
            }
        }
        else{
            int naka1=maenaka/2;
            char mae2[naka1],ushiro2[naka1];
            for(int i=0; i<naka1; i++){
                mae2[i]=mae[i];
                ushiro2[i]=mae[((n-1)/2)-1-i];
                if(mae2[i]!=ushiro2[i]){
                    flag=false;
                    break;
                }
            }

        }
        
    }
    if(flag)cout << "Yes";
        else cout << "No";

}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    ll L[n + 1];

    L[0] = 2, L[1] = 1;
    for (int i = 2; i <= n; i++)
        L[i] = L[i - 1] + L[i - 2];

    OP(L[n]);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x_1 = list(map(int, input().split()))
x_2 = sorted(x_1)
median_1 = x_2[n//2-1]
median_2 = x_2[n//2]
for v in x_1:
    if v <= median_1:
        print(median_2)
    else:
        print(median_1)

Measured memory_bytes: 104724
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

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

if(a+b == 4) cout << '2' << endl;
else if(a+b == 3) cout << '3' << endl;
else cout << '1' << endl;

//////////////////////////////////////////////////////
return 0;}

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

namespace ConsoleApplication1
{
    struct Rectangle
    {
        internal int height, pos;
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                if (input.All(a => a == 0)) break;

                int H = input[0];
                int W = input[1];

                int[,] dp = new int[H, W + 1];

                for (int i = 0; i < H; i++)
                {
                    string line = Console.ReadLine();

                    for (int j = 0; j < W; j++)
                    {
                        if (line[j] == '*') dp[i, j] = 0;
                        else dp[i, j] = i > 0 ? dp[i - 1, j] + 1 : 1;
                    }
                }

                Stack<Rectangle> stk = new Stack<Rectangle>();
                int maxArea = 0;

                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j <= W; j++)
                    {
                        Rectangle rect;
                        rect.height = dp[i, j];
                        rect.pos = j;

                        if (stk.Count == 0)
                        {
                            stk.Push(rect);
                        }
                        else
                        {
                            if (stk.Peek().height < rect.height)
                            {
                                stk.Push(rect);
                            }
                            else if (stk.Peek().height > rect.height)
                            {
                                int target = j;

                                while (stk.Count > 0 && stk.Peek().height >= rect.height)
                                {
                                    Rectangle pre = stk.Pop();
                                    int area = pre.height * (j - pre.pos);
                                    maxArea = Math.Max(maxArea, area);
                                    target = pre.pos;
                                }
                                rect.pos = target;
                                stk.Push(rect);
                            }
                        }
                    }
                }
                sb.AppendLine(maxArea.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int a, b;	cin >> a >> b;
  	if((1<= a && a <= 9)&&(1<= b && b <= 9)) cout << a*b << endl;
  	else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, a, b;
	cin >> n >> a >> b;
	string s; cin >> s;
	int sum1 = 0, sum2 = 0;
	REP(i, n)
	{
		if (s[i] == 'a')
		{
			if (sum1 < a + b)
			{
				sum1++;
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else if(s[i] =='b')
		{
			if (sum1 < a + b && sum2 < b)
			{
				sum1++; sum2++;
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else
		{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 848
#define RUN
#ifdef RUN
#include <bits/stdc++.h>
using namespace std;

#define int long long

int H;

signed main() {
    cin >> H;
    int cp = 1;
    int ans = 0;
    while (H) {
        ans += cp;
        cp = (cp << 1);
        H /= 2;
    }
    cout << ans << endl;
    return 0;
}
#endif


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

template<typename T>
inline void scan(std::deque<T>&v){for(auto&& sv:v){scan(sv);}}

using namespace std;

int n_max = 200005;
void solve() {
  int n;
  scan(n);
  vll a(n);
  scan(a);
  vll cnt(n_max, 0);
  ll ans = 0;
  rep (i, n) {
    ll target = i - a[i];
    if (0 <= target && target < n_max) {
      ans += cnt[target];
    }
    ll idx = i + a[i];
    if (0 <= idx && idx < n_max) {
      cnt[idx] += 1;
    }
  }
  print(ans);
}

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


Measured memory_bytes: 6044
N = int(input())
S = [input() for i in range(N)]
ab = x_a = b_x = b_a = 0
for s in S:
    ab += s.count('AB')
    if s[-1]=='A' and s[0]=='B':
        b_a += 1
    elif s[-1]=='A':
        x_a += 1
    elif s[0]=='B':
        b_x += 1

ans = ab
if b_a:
    ans += b_a - 1
    if x_a:
        ans += 1
        x_a -= 1
    if b_x:
        ans += 1
        b_x -= 1

ans += min(x_a, b_x)
print(ans)

Measured memory_bytes: 3700
#include<stdio.h>
int main(){
  int i,j,k=0,n,q,S[10000],T[500];

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&T[i]);

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]){
	k++;
	break;
      }
    }
  }

  printf("%d\n",k);


  return 0;
}

Measured memory_bytes: 2788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans=0,N;
  cin>>N;
  for(int n=1;n<=N;n++){
    int cnt=0;
    for(int i=1;i<=n;i++)
      if(n%i==0)cnt++;
    if(cnt==8&&n%2)ans++;
  }
  cout<<ans;
  return 0;
}

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

using namespace std;


bool check_understanding(int X, vector<int> understanding);
pair<bool, int> solve(int X, int N, const vector<vector<int>> & A, const vector<int> & C, int i, vector<int> understanding, int cost);

inline bool check_understanding(int X, vector<int> understanding){
  bool ret = true;
  for(unsigned long i = 0; i < understanding.size(); i++){
    if(understanding[i] < X)
      ret = false;
  }
  
  return ret;
}

pair<bool, int> solve(int X, int N, const vector<vector<int>> & A, const vector<int> & C, int i, vector<int> understanding, int cost){
  if(i == N)
    return make_pair(check_understanding(X, understanding), cost);
  
  pair<bool, int> p, q;
  p = solve(X, N, A, C, i + 1, understanding, cost);
  
  for(int j = 0; j < understanding.size(); j++)
    understanding[j] += A[i][j];
  q = solve(X, N, A, C, i + 1, understanding, cost + C[i]);
  
  if(p.first == false)
    return q;
  else if(q.first == false)
    return p;
  return p.second < q.second ? p : q;
  
}

int main(void){
  int N, M;
  int X;
  cin >> N >> M >> X;
  
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for(int i = 0; i < N; i++){
    cin >> C[i];
    for(int j = 0; j < M; j++)
      cin >> A[i][j];
  }

  vector<int> understanding(M, 0);
  pair<bool, int> ret = solve(X, N, A, C, 0, understanding, 0);
  
  cout << (ret.first ? ret.second : -1) << endl;
    
  return 0;
}


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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_debug(...) do { printf("DEBUG: line %d: %s: ", __LINE__, __PRETTY_FUNCTION__); printf(__VA_ARGS__); } while(0)
  #define pr_vars(...) do { pr_debug(" "); pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_debug(...) do { } while(0)
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;
#define X first
#define Y second

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (const auto &el : vec) fout << el << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return move(v); }

void pr_var(vector<string>::iterator it) { (void) it; cout << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cout << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr double INF = 2e18;

using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

constexpr ll MAX = 1e5 + 5;

int main()
{
    ll res = INF;
    string s; cin >> s;
    ll dat[256] = {0};
    for (ull i = 0; i < s.size(); i++)
        dat[s[i]]++;
    ll mx = -1;
    ll cch = 'a';
    for (ll i = 'a'; i <= 'z'; i++) {
        if (dat[i] > mx) { mx = dat[i]; cch = i; }
    }
    for (ll ch = 'a'; ch <= 'z'; ch++) {
        ll m_res = 0;
        string ss = s;
        while (ss.size()) {
            bool tr = false;
            for (ull i = 0; i < ss.size() - 1; i++) {
                if (ss[i] == ch) continue;
                tr = true;
                if (ss[i + 1] == ch) ss[i] = ch;
            }
            if (!tr && ss[ss.size() - 1] == ch) break;
            //pr_vars(ss);
            m_res++;
            ss.pop_back();
        }
        //if (m_res < res) { pr_vars(m_res, ss); }
        res = min(res, m_res);
    }

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

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,a,b) for (int i = a; i < (b); i++)
#define sz(t) int(t.size())
using namespace std;
typedef long long ll;


vector<vector<int> > is(26);

int lower_bound(vector<int> &a, int t) {
    int x = 0;
    int y = a.size() - 1;

    while (x <= y) {
        int z = (x + y) / 2;
        if (a[z] < t)
            x = z + 1;
        else if (a[z] >= t)
            y = z - 1;
    }

    return x;
}

int main(void) {

    string s, t;
    cin >> s >> t;
    int n = sz(s);
    int m = sz(t);

    REP(i, 0, n) {
        int c = s[i] - 'a';
        is[c].push_back(i);
    }
    REP(i, 0, n) {
        int c = s[i] - 'a';
        is[c].push_back(i + n);
    }

    ll ans = 0;
    int p = 0;
    REP(i, 0, m) {
        int c = t[i] - 'a';
        if (sz(is[c]) == 0) {
            cout << - 1 << endl;
            return 0;
        }

        p = is[c][lower_bound(is[c], p)] + 1;
        if (p >= n) {
            p -= n;
            ans += n;
        }
    }

    ans += p;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1852
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vint cnt(n);
    REP(i,n){
        int a;
        cin >> a;
        a--;
        cnt[a]++;
    }
    sort(ALL(cnt));
    int st=0;
    REP(i,k){
        st+=cnt[n-1-i];
    }
    cout << n-st << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
using namespace std;
double BMI(double Kg,double m){
  double bmi;
  bmi = Kg / (m * m);
  return bmi;
}

int main(){
  double Kg,m;
  int student;
  while(scanf("%d,%lf,%lf",&student,&Kg,&m) != EOF){
    if(BMI(Kg,m) >= 25){
      cout << student << endl;
    }
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
	int H, W;
	int m, n;

	do{
	scanf("%d%d", &H, &W);
	if(H == 0 && W == 0) break;
	for(m = 0; m < H; m++){
		if(m % 2 == 0){
		for(n = 0; n < W; n++){
			if(n % 2 == 0) printf("#");
			else printf(".");
		}
		} else{
		for(n = 0; n < W; n++){
			if(n % 2 == 0) printf(".");
			else printf("#");
		}
		}

		printf("\n");
	}
	printf("\n");
	} while (H != 0 || W != 0);

	return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n, m; cin >> n >> m;
    priority_queue<pair<int, int>> q;
    rep(i,n){
        int num; cin >> num;
        q.push({num, 1});
    }
    rep(i,m){
        int a, b; cin >> a >> b;
        q.push({b, a});
    }

    ll ans = 0;
    rep(i,n){
        auto P = q.top(); q.pop();
        ans += P.first;
        if(P.second>1){
            P.second--;
            q.push(P);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  string S;
  cin >> S;
  int b[26] = {0}; //バケット
  FOR(i, 0, S.size()) {
    b[S[i] - 'a']++;
  }
  //FOR(i, 0, 26) cout << b[i] << endl;
  FOR(i, 0, 26) {
    if (b[i] == 0) {
      cout << char('a' + i) << endl;
      return 0;
    }
  }
  cout <<  "None" << endl;
  return 0;
}



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

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0 ; i < s.size() ; i++)
	{
		if(s[i] == '2')
			ans++;
	}
	cout << ans << endl;
}

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

class Solution
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var set = new HashSet<long>();
        for (int i = 0; i < n; i++)
        {
            var x = long.Parse(Console.ReadLine());
            if(set.Contains(x))
            {
                set.Remove(x);
            }
            else
            {
                set.Add(x);
            }
        }

        Console.WriteLine(set.Count);
    }
}

Measured memory_bytes: 23644
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int n; cin >> n;
    vector<P> mt(n);
    rep(i, n) {
        cin >> mt[i].first >> mt[i].second;
    }
    // iからjまでの区間で最小の数
    vector<vector<int>> dp(n, vector<int>(n));

    // 区間を小さい方から始める
    repr(i, 2, n+1) {
        // iは区間の大きさ 2 <= i <= nまで
        int wj = i-1;
        rep(sj, n+1-i) {
            // jは区間の始める点, i = 2のとき、jは 0 <= j < n+1 - 2
            int lj = sj + wj;
            // [sj, wj]間を二つに分割して一番最小なコストを探索する
            // 分割点の候補は [sj, K), [K, lj]で、sj+1 < K < lj
            int min_cost = 100000001;
            repr(fk, sj+1, lj+1) {
                // fkは 分割するkの場所
                min_cost = min(min_cost, dp[sj][fk-1] + dp[fk][lj] + mt[sj].first * mt[fk].first * mt[lj].second);
            }
            dp[sj][lj] = min_cost;
        }
    }

    cout << dp[0][n-1] << endl;

    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
int main()
{
    int a1,a2,a;
    cin >> a;
    a1=a/100;
    a2=a%100;

               
    if((a1>0 && a1<13) && (a2>0 && a2<13)){
        cout << "AMBIGUOUS" << endl;
    }
    else if((a2>0 && a2<13)){
        cout << "YYMM" << endl;
    }
    else if((a1>0 && a1<13)){
        cout << "MMYY" << endl;
    }
    else{
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[225];
int main(){
	cin>>n;
	for(int i=1;i<=2*n;i++)cin>>a[i];
	sort(a+1,a+2*n+1);
	int summ=0;
	for(int i=2*n;i>=1;i-=2){
		summ+=a[i-1];
	}
	cout<<summ;
}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    var ans = Pair(1,100000)
    for (i in 0 until m) {
        val (l,r) = readLine()!!.split(" ").map { it.toInt() }
        ans = Pair(Math.max(l, ans.first), Math.min(r, ans.second))
    }
    println(Math.max(ans.second-ans.first + 1, 0))
}


Measured memory_bytes: 53476