akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char s[500010],t[100010];
int main(){
	scanf("%s",t);
	int len=strlen(t);
	int l=200001,r,flag=1,q,tt,f;
	char c[5];
	for(int i=0;i<len;i++){
		s[l+i]=t[i];
	}
	r=l+len-1;
	scanf("%d",&q);
	while(q--){
		scanf("%d",&tt);
		if(tt==1){
			flag*=-1;
		}
		else{
			scanf("%d %s",&f,c);
			if(f==1){
				if(flag==1){
					l--;
					s[l]=c[0];
				}
				else{
					r++;s[r]=c[0];
				}
			}
			else{
				if(flag==1){
					r++;
					s[r]=c[0];
				}
				else{
					l--;s[l]=c[0];
				}
			}
		}
	}
	if(flag==1){
		for(int i=l;i<=r;i++){
			printf("%c",s[i]);
		}
	}
	else{
		for(int i=r;i>=l;i--){
			printf("%c",s[i]);
		}
	}
	printf("\n");
	return 0;
} 

Measured memory_bytes: 896
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
import time
# stdin = open("sample.txt")


MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    S = stdin.readline().rstrip()
    T = stdin.readline().rstrip()
    now = 0
    ans = INF
    for i in range(len(S)-len(T)+1):
        S2 = S[i:i+len(T)]
        now = 0
        for j in range(len(T)):
            if T[j] != S2[j]:
                now += 1
        ans = min(now,ans)
    print(ans)
main()

Measured memory_bytes: 27252
let () =
  let n = read_int () in
  Printf.printf "%d:" n;
  let rec doit i x acc =
    if i*i > n then
      if x <> 1 then (x :: acc)
      else acc
    else if x mod i = 0 then doit i (x / i) (i :: acc)
    else doit (i + 1) x acc in
  doit 2 n [] |> List.rev |> List.iter (fun e -> Printf.printf " %d" e);
  print_newline ()

Measured memory_bytes: 2332
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int abc[N][3], dp[N][3];
  for (int i = 0; i < N; i++) {
    cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
  }
  dp[0][0] = abc[0][0];
  dp[0][1] = abc[0][1];
  dp[0][2] = abc[0][2];
  for (int i = 1; i < N; i++) {
    dp[i][0] = max(dp[i-1][1]+abc[i][0],dp[i-1][2]+abc[i][0]);
    dp[i][1] = max(dp[i-1][0]+abc[i][1],dp[i-1][2]+abc[i][1]);
    dp[i][2] = max(dp[i-1][0]+abc[i][2],dp[i-1][1]+abc[i][2]);
  }
  cout << max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2]));
}

Measured memory_bytes: 5924
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>
#include<iomanip>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define pi 3.14159265358979

int a[1010][110];

int main(void){

	int n,m,x;
	vector<pair<int,int> >q;
	for(;;){
	cin >> n >> m;
	if(n==0 && m==0) break;

	rep(i,m) q.push_back(make_pair(0,i+1));

	rep(i,n){
	rep(j,m){
	cin >> x;
	q[j].first-=x;
	}
	}

	sort(q.begin(),q.end());

	rep(i,m){
	cout << q[i].second;
	if(i<m-1) cout << " ";
	else cout << endl;
	}

	q.clear();

	}

	return 0;
}

Measured memory_bytes: 1200
K=gets.to_i

if K < 10
  p K
  exit 0
end

@c = K - 9

def g(n,m,i)
  if i == 0
    @c -= 1
    if @c == 0
      p n
      exit 0
    end
  else
    g(n*10+m-1,m-1,i-1) if m != 0
    g(n*10+m,m,i-1)
    g(n*10+m+1,m+1,i-1) if m != 9
  end
end

i = 2
loop do
  9.times do |j|
    g(j+1,j+1,i-1)
  end
  i += 1
end


Measured memory_bytes: 3836
s = input()
t = input()
res = 1000
for i in range(len(s)-len(t)+1):
  st = s[i:i+len(t)]
  #print(st)
  #print(t)
  count=0
  for j in range(len(t)):
    #print(st[j], t[j])
    if st[j] != t[j]:
      count+=1
  if res > count:
    res = count
print(res)

Measured memory_bytes: 82292
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut k: usize,
        mut xs: [i64; n],
    }
    if let Some(_) = xs.iter().find(|x| **x == 0) {
        k -= 1;
    } else {
        k += 1;
        xs.push(0);
        xs.sort();
    }
    let ans = if k == 0 {
        0
    } else {
        xs.windows(k)
            .map(|w| {
                if w[0] == 0 {
                    w[k - 1]
                } else if w[k - 1] == 0 {
                    -w[0]
                } else if w[0] * w[k - 1] > 0 {
                    i64::max_value()
                } else {
                    let a = -w[0];
                    let b = w[k - 1];
                    std::cmp::min(a + 2 * b, 2 * a + b)
                }
            })
            .min()
            .unwrap()
    };
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define MODNUMBER (long long)1000000007

long long pow_mod(long long a, long long n)
{ // a^n mod MODNUMBER
	long long result = 1;
	long long a_i = a;
	long long n_tmp = n;
	while (n_tmp > 0)
	{
		if (n_tmp & 0b1)
		{
			result = (result * a_i) % MODNUMBER;
			// cout << result << "\n";
		}
		a_i = a_i * a_i % MODNUMBER;
		n_tmp = n_tmp >> 1;
	}
	return result;
}

long long fact_mod(long long k)
{ // k! mod MODNUMBER

	long long result = 1;
	for (int i = 1; i <= k; i++)
	{
		result = (result * i) % MODNUMBER;
	}
	return result;
}
vector<long long> fact_mod_vector(long long k)
{ // k! mod MODNUMBER

	vector<long long> result(k + 1, 1);
	result[0] = 1;
	for (int i = 1; i <= k; i++)
	{
		result[i] = (result[i - 1] * i) % MODNUMBER;
	}
	return result;
}

long long inv_mod(long long k)
{ // k^(-1) mod MODNUMBER

	return pow_mod(k, MODNUMBER - 2);
}

/* DONE: fact_mod()の途中経過を使いまわす実装にすれば早くなるらしい */
/* ↓ */
/* fact_mod_vector()を使ってfact_resultをあらかじめ作っておく */
/*(nの最大値で作っておく)*/
long long comb_mod(long long n, long long k, vector<long long> *fact_result)
{ // nCk mod MODNUMBER
	return ((*fact_result)[n] *
			inv_mod(((*fact_result)[k] * (*fact_result)[n - k]) % MODNUMBER)) %
		   MODNUMBER;
}

long long my_gcd(long long A, long long B)
{
	while (A > 0 && B > 0)
	{
		if (A > B)
		{
			A = A % B;
		}
		else
		{
			B = B % A;
		}
	}
	// A or B =0
	return A + B;
}

int main()
{
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int N;
	scanf("%d", &N);

	map<pair<long long, long long>, pair<long long, long long>> c; // 既約分数にして、A/Bがindex(B>0)

	int zeronum = 0;
	for (int i = 0; i < N; i++)
	{
		long long A, B;
		scanf("%lld %lld", &A, &B);
		// cout << A << " " << B;
		if (A == 0 && B == 0)
		{
			zeronum++;
			continue;
		}
		if (A == 0)
		{
			c[make_pair(1, 0)].first++;
			continue;
		}
		if (B == 0)
		{
			c[make_pair(1, 0)].second++;
			continue;
		}

		long long gcd = my_gcd(abs(A), abs(B));
		// cout << gcd;
		A = A / gcd;
		B = B / gcd;
		if (B < 0)
		{
			A = -A;
			B = -B;
		}
		if (A > 0)
		{
			c[make_pair(A, B)].first++;
		}
		else
		{
			c[make_pair(B, -A)].second++;
		}
	}

	long long result = 1;
	for (auto i : c)
	{
		// cout << i.first.first << " " << i.first.second << " " << i.second.first << " " << i.second.second << "\n";
		// cout << i.second.first << " " << i.second.second << "\n";
		long long tmp = ((pow_mod((long long)2, i.second.first) - (long long)1) + (pow_mod((long long)2, i.second.second) - (long long)1) + (long long)1) % MODNUMBER;
		// cout << tmp << "\n";
		result = ((result * tmp) + MODNUMBER) % MODNUMBER;
	}
	cout << ((result - (long long)1 + zeronum) + MODNUMBER) % MODNUMBER; //0
	return 0;
}
/*
Ai/Bi +Bj/Aj=0

Ci=Ai/Bi

Ci+1/Cj=0
Ci=-1/Cj
*/

Measured memory_bytes: 19148
#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 int long long

signed main(){
    string S;
    cin>>S;
    if(S=="Sunny"){
        cout <<"Cloudy"<<endl;
    }
    else{
        if(S=="Rainy"){
            cout <<"Sunny"<<endl;
        }
        else{
            cout <<"Rainy"<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	string ans = "";
	int in;
	map <string ,vector <int> > mp;
	while(cin >> s >> in){
		mp[s].push_back(in);
	}
	for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
		cout << (*itr).first << endl;
		sort((*itr).second.begin(),(*itr).second.end());
		for(int i = 0; i < (*itr).second.size() ; i++)
			cout << (*itr).second[i] << (i == (*itr).second.size() - 1 ? "" : " ");
		cout << endl;
	}
}

Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

queue<int> que;

void bfs(vector<vector<int> > &G, int s, int *seen) {
    seen[s] = 0;
    que.push(s);
    
    while (!que.empty()) {
        int u = que.front();
        que.pop();

        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];

            if (seen[v] != -1)  
                continue;

            seen[v] = seen[u] + 1;
            que.push(v);
        }
    }
}

int main() {
    vector<vector<int> > G;
    int n;  cin >> n;
    G.resize(n);
    for (int i = 0; i < n; i++) {
        int u, k;   cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int x;  cin >> x;
            G[u-1].push_back(x-1);
        }
    }

    int *seen = new int[n];
    for (int i = 0; i < n; i++)
        seen[i] = -1;
    seen[0] = 0;

    bfs(G, 0, seen);

    for (int i = 0; i < n; i++)
        cout << i+1 << " " << seen[i] << endl;

    return 0;
}


Measured memory_bytes: 3180
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int n;
    cin >> n;
    int ans;
    double now = 100000;
    for(int i = 0 ; i < n ; ++i){
        now *= 1.05;
        int t = now;
        if(t == now && t % 1000 == 0){
            ans = t;
            continue;
        }
        t = t / 1000 * 1000 + 1000;
        ans = t;
        now = ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3112
N, M = [int(i) for i in input().split()]

Mark = [0 for _ in range(N+1)]
path = {k: [] for k in range(1, N+1)}
for i in range(M):
    A, B = [int(i) for i in input().split()]
    path[A].append(B)
    path[B].append(A)
next = [1]
while True:
    n = next.pop(0)
    for x in path[n]:
        # n -> x
        if Mark[x] == 0:
            Mark[x] = n
            next.append(x)
    if not next: break
if 0 in Mark[2:]:
    print("No")
else:
    print("Yes")
    print("\n".join([str(i) for i in Mark[2:]]))


Measured memory_bytes: 48880
#include <bits/stdc++.h>
using namespace std;
int ans;
int f(int r){
	while(r){
		r/=10;
		ans++;
	}
	return ans;
}
int main(){
	int m,n,i,tot1,tot2,sum;
	cin>>m>>n;
	tot2=f(n);
	sum=m;
	for(i=1;i<=tot2;i++){
		sum*=10;
	}
	sum+=n;
	if(sqrt(sum)==ceil(sqrt(sum)))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

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

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

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 90;

ll L[N];

int main(){
	L[0] = 2;
	L[1] = 1;
	for(int i=2; i<N; i++) L[i] = L[i-1] + L[i-2];
	int n;
	ri(n);
	printf("%lld\n",L[n]);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)

#define repv(v, values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0)
#define srt(vec) sort(vec_all(vec))
#define rev(vec) reverse(vec_all(vec))
#define revsrt(vec) srt(vec); rev(vec)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

template <typename T, typename S>
void dump_dic(map<T, S> dic)
{
    for (auto v : dic)
    {
        cout << v.first << ": " << v.second << endl;
    }
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    srt(a);

    vector<p_i> change(m);
    int tmp1, tmp2;
    rep(i, m) {
        cin >> tmp1 >> tmp2;
        change[i] = p_i(tmp1, tmp2); 
    }

    sort(change.begin(), change.end(), [](p_i p1, p_i p2) {
        return p1.second > p2.second;
    });

    int change_i = 0;
    ll cnt = 0;
    repv(v, a) {
        if (change[change_i].second > v) {
            cnt += change[change_i].second;
            change[change_i].first--;
        } else {
            cnt += v;
        }

        if (change[change_i].first == 0) {
            change_i++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int main(){
	int p1, p2;
	cin >> p1 >> p2;
	if(p1 == 1){
		if(p2 == 2){
			cout << "3";
		}
		else{
			cout << "2";
		}
	}
	else if(p1 == 2){
		if(p2 == 1){
			cout << "3";
		}
		else
			cout << "1";
	}
	else{
		if(p2 == 1){
			cout << "2";
		}
		else 
			cout << "1";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

class UnionFind{
    public:
    UnionFind(lint n){
        par.resize(n);
        //d.resize(n, 1);
        REP(i, n) par[i] = i;
    }
    lint root(lint x){
        if(par[x]==x) return x;
        else return par[x] = root(par[x]);
    }
    void merge(lint x, lint y){
        lint px, py;
        px = root(x);
        py = root(y);
        if(py==px) return;
        else{
            // y become x's parent
            par[root(x)] = root(y);
        }
    }
    vector<lint> par;
};
signed main(){
    lint N, K, L;
    cin >> N >> K >> L;
    UnionFind ufl = UnionFind(N);
    UnionFind ufr = UnionFind(N);
    vector<lint> res(N, 1);
    REP(i, K){
        lint s, g;
        cin >> s >> g;
        s--, g--;
        ufl.merge(s, g);
    }
    vector<P> Lin(L);
    REP(i, L){
        lint s, g;
        cin >> s >> g;
        s--, g--;
        Lin[i] = P(s, g);
        ufr.merge(s, g);
    }
    map<P, lint> m;
    REP(i, N){
        m[P(ufl.root(i), ufr.root(i))]++;
    }
    REP(i, N){
        cout << m[P(ufl.root(i), ufr.root(i))] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 18176
Q,H,S,D=map(int,input().split())
N=int(input())

Q=4*Q
H=2*H
if N%2==0:
	ans=(N//2)*min(2*Q,2*H,2*S,D)
else:
	ans=(N//2)*min(2*Q,2*H,2*S,D)+(N%2)*min(Q,H,S)

# ans=(N//2)*min(2*Q,2*H,2*S,D)+(N%2)*min(Q,H,S)

print(ans)

Measured memory_bytes: 3060
n,m = map(int,input().split())
A = [0]*(m+1)
ans=0
k = []
a = []
for i in range(n):
    s = list(map(int, input().split()))
    k.append(s[0])
    a.append(s[1:])
    for j in range(s[0]):
        A[s[j+1]] +=1
for i in range(m):
  if A[i+1]==n:
    ans+=1
print(ans)

Measured memory_bytes: 3064
module module_sort
    use iso_fortran_env
    implicit none

    interface quicksort
        module procedure :: int32_qsort
        module procedure :: int64_qsort
    end interface quicksort
contains

    recursive function int32_qsort(m) result(res)
        integer(int32), intent(in) :: m(:)
        integer(int32) :: n, pm, pn, pv, res(size(m))

        n = size( m, 1 )

        if (n <= 1) then
          res = m
        else
          pv = m( n/2 )
          pm = max( m(1), m(n) )
          pn = min( m(1), m(n) )
          if ( pv > pm ) pv = pm
          if ( pv < pn ) pv = pn
          res = [ int32_qsort( pack(m(:), m(:) > pv) ), &
                               pack(m(:), m(:) == pv), &
                  int32_qsort( pack(m(:), m(:) < pv) ) ]
        endif

    end function int32_qsort

    recursive function int64_qsort(m) result(res)
        integer(int64), intent(in) :: m(:)
        integer(int64) :: n, pm, pn, pv, res(size(m))

        n = size( m, 1 )

        if (n <= 1) then
          res = m
        else
          pv = m( n/2 )
          pm = max( m(1), m(n) )
          pn = min( m(1), m(n) )
          if ( pv > pm ) pv = pm
          if ( pv < pn ) pv = pn
          res = [ int64_qsort( pack(m(:), m(:) > pv) ), &
                               pack(m(:), m(:) == pv), &
                  int64_qsort( pack(m(:), m(:) < pv) ) ]
        endif

    end function int64_qsort

end module module_sort

program main
    use module_sort
    use iso_fortran_env
    implicit none
    integer(int64) :: n
    integer(int64), allocatable :: ai(:)
    integer(int64) :: i, ie
    integer(int64) :: ans

    read *, n
    allocate( ai(n) )
    read *, ai( 1:n )
    ai = quicksort( ai )

    if ( mod((n-1), 2) == 0 ) then
        ie = (n-1) / 2
        ans = ai(1) + ai(ie + 1)
    else
        ie = n / 2
        ans = ai(1)
    endif

    do i = 2, ie
        ans = ans + ai(i) * 2
    enddo

    print *, ans

end program main

Measured memory_bytes: 11020
n = gets.chomp.to_i

arr = []
n.times do |i|
  a,b,c = gets.chomp.split.map(&:to_i)
  arr.push([a,b,c])
end

dp = Array.new(n+1) { Array.new(3, 0) }

A = 0
B = 1
C = 2

1.upto(n) do |i|
  [A,B,C].each do |e|
    dp[i][e] = [A,B,C].reject{|t| t == e}.map{|t| dp[i-1][t]}.max + arr[i-1][e]
  end
end

p dp[n].max


Measured memory_bytes: 16124
n=int(input())
t=list(map(int,input().split()))
m=int(input())
drink=[]
for i in range(m):
    p,x=map(int,input().split())
    drink.append([p,x])

for i in range(m):
    s=t.copy()
    s[((drink[i][0])-1)]=drink[i][1]
    print(sum(s))
    
    
    


Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    unordered_set<int> v;
    vector<long> cnt(n + 1, 0);
    vector<long> comb(n + 1, 0);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v.insert(a[i]);
        cnt[a[i]] += 1;
    }

    for (int i: v) {
        comb[i] = cnt[i] * (cnt[i] - 1) / 2;
    }

    long comb_sum = 0;
    for (int i: v) {
        comb_sum += comb[i];
    }


    for (int i = 0; i < n; i++) {
        cout << comb_sum - comb[a[i]] * 2 / cnt[a[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 11464
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]


a,b = map(int, input().split())

print((a-1)*(b-1))



Measured memory_bytes: 9152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int a[1000][1000];
int cnt[1000];
int us[1000];
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void){
  while(1){
  int n,c=0,a,flg=1;
  scanf("%d",&n);
    if(!n)return 0;
  FOR(n){
    scanf("%d",&a);
    if(!a)c++;
    if(a>1)flg=0;
  }
  if(flg){
    PRS("NA");
  }else{
    PRN(n+1-c);
  }
  }
  return 0;
}



Measured memory_bytes: 2072
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

D = int(readline())
C = list(map(int,readline().split()))
S = [list(map(int,readline().split())) for i in range(D)]
t = [int(readline()) for i in range(D)]

ans = 0
minus = 0
last = [0]*26
for i in range(D):
    ans += S[i][t[i]-1]
    minus = 0
    last[t[i]-1] = i+1
    for j in range(26):
        minus += C[j]*(i-last[j]+1)
    ans -= minus
    print(ans)



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

using namespace std;

int N;
set<int> Cards1, Cards2;

void solve() {
	int rearNum, cnt;
	set<int>::iterator pos;

	cnt = 1;
	rearNum = -1;
	while (true) {
		for (pos = Cards1.begin(); pos != Cards1.end(); ++pos) {
			if (*pos > rearNum) {
				rearNum = *pos;
				break;
			}
		}
		if (pos == Cards1.end()) {
			rearNum = -1;
		}
		else {
			Cards1.erase(pos);
			if (Cards1.empty()) {
				break;
			}
		}
		swap(Cards1, Cards2);
		++cnt;
	}

	if ((cnt & 1) == 1) {
		cout << Cards2.size() << endl << "0" << endl;
	}
	else {
		cout << "0" << endl << Cards2.size() << endl;
	}
}

int main() {
	int num;

	while (cin >> N, N) {
		Cards1.clear();
		Cards2.clear();
		for (int i = 0; i < N; ++i) {
			cin >> num;
			Cards1.insert(num);
		}
		for (int i = 1; i <= (N << 1); ++i) {
			if (Cards1.count(i) != 0) {
				continue;
			}
			Cards2.insert(i);
		}
		solve();
	}

	return 0;
}


Measured memory_bytes: 3008
#include <iostream>
using namespace std;
int main() {
	int A, B;

	cin >> A >> B;
	if (A + B > 16) {
		cout << ":(" << endl;
	}
	else {
		if (A > 8 || B > 8) {
			cout << ":(" << endl;
		}
		else {
			cout << "Yay!" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<bits//stdc++.h>
#include<functional>
using namespace std;
struct P{
	int cost,pos;
};
bool operator<(P a,P b) {return a.cost<b.cost;}
bool operator>(P a,P b) {return a.cost>b.cost;}
long long a[101];
const long long inf=800000000;
vector<long long>e[101];
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int r,k,c;
		cin>>r>>k;
		for(int i=0;i<k;i++){
			cin>>c;
			e[r].push_back(c);
		}
	}
	int p;
	cin>>p;
	for(int z=0;z<p;z++){
		int s,d,v;
		cin>>s>>d>>v;
		fill(a,a+n+1,inf);
		priority_queue<P>p;
		p.push(P{1,s});
		a[s]=1;
		while(!p.empty()){
			P t=p.top();p.pop();
			for(int i=0;i<(int)e[t.pos].size();i++){
				if(a[t.pos]+1<a[e[t.pos][i]]){
					a[e[t.pos][i]]=a[t.pos]+1;
					p.push(P{a[t.pos]+1,e[t.pos][i]});
				}
			}
		}
		if(a[d]<=v) cout<<a[d]<<endl;
		else cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 3160
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>
#include<stack>
#include <cstdlib>

//#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	if (n == m) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x)	cout <<#x <<" = "<< x <<"\n"
#define ff              first
#define ss              second
#define ll             	long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
		int a, l;
		cin >> a >> l;
		if( !(l & 1) && (l > a) && l >= a * 2 && l <= a * 4){
			cout << "Yes";
		}
		else
			cout << "No";
	
    
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

bool next_array(vector<int> & a, int b) {
	int d = a.size();
	inc(i, d + 1) {
		if(i == d) { return false; }
		a[i]++;
		if(a[i] == b) { a[i] = 0; } else { break; }
	}
	return true;
}

int main() {
	int n;
	cin >> n;
	
	int ans = 0;
	incII(d, 3, 9) {
		vector<int> a(d);
		do {
			if(
				count(ALL(a), 0) == 0 ||
				count(ALL(a), 1) == 0 ||
				count(ALL(a), 2) == 0
			) { continue; }
			
			int v = 0, x[] = { 3, 5, 7 };
			dec(i, d) { v = 10 * v + x[a[i]]; }
			
			if(v <= n) { ans++; } else { break; }
		} while(next_array(a, 3));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main Code
void zero() {cout << 0 << "\n"; exit(0);}

struct edge {int to; ll s;};
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> g(n);
    rep(i, m) {
        int u, v; ll s;
        cin >> u >> v >> s;
        --u; --v;
        g[u].push_back(edge{v, s}); g[v].push_back(edge{u, s});
    }
    
    vector<pair<ll, ll>> val(n, pair<ll, ll>(INF, INF));
    val[0] = pair<ll, ll>(1, 0);
    ll x = INF;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (edge e: g[v]) {
            if (val[e.to] != pair<ll, ll>(INF, INF)) {
                pair<ll, ll> p(val[v].first + val[e.to].first, val[v].second + val[e.to].second);
                if (p.first) {
                    if ((e.s - p.second) % p.first) zero();
                    ll y = (e.s - p.second) / p.first;
                    if (y <= 0) zero();
                    if (x == INF) x = y;
                    else if (x != y) zero();
                } else {
                    if (p.second != e.s) zero();
                }
            } else {
                val[e.to] = pair<ll, ll>(-val[v].first, e.s - val[v].second);
                q.push(e.to);
            }
        }
    }
    
    if (x != INF) {
        bool judge = true;
        rep(i, n) {
            if (x * val[i].first + val[i].second <= 0) judge = false;
        }
        if (!judge) zero();
        cout << 1 << "\n";
        return 0;
    }
    ll mn = -INF, mx = INF;
    rep(i, n) {
        if (val[i].first == 1) {
            chmax(mn, -val[i].second + 1);
        } else {
            chmin(mx, val[i].second - 1);
        }
    }
    if (mn > mx) zero();
    cout << mx - mn + 1 << "\n";
    return 0;
}


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

int main(){
  
  int N;
  cin >> N;
  long long Total=1;
  bool ok=true;
  for(int i=0;i<N;i++){
    long long tmp;
    cin >> tmp;
    if(tmp==0){
      ok =true;
      Total =0;
      break;
    }
    if(tmp > static_cast<long long>(1000000000000000000)/Total){
      ok = false;
      tmp = 1000000000000000001;
    }
    else Total *= tmp;
  }
  
  if(!ok) cout << -1 << endl;
  else cout << Total << endl;
  
}

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



int main(){

    int n;
    cin>>n;

    int a[n],b[n];

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

    int e=0;
    for(int i=0 ; i<n-2 ; i++){
        if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2]){
            e=1;
            break;
        }

    }

    if(e==0)
        cout<<"No"<<endl;

    else
        cout<<"Yes"<<endl;





    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define elif else if
#define endl "\n"
#define _  <<" "<<
#define eb(x) emplace_back(x)
#define maxelem(v) *max_element(v.begin(),v.end())
#define minelem(v) *min_element(v.begin(),v.end())
#define FOR(a,b) for(int i=int(a);i<int(b);++i)

using namespace std;

const int mod = 1e9+7;

void izlaz(string br)
{
  if(!br.size())
    exit(EXIT_SUCCESS);
  cout<<br;
  exit(EXIT_SUCCESS);

}

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(max(a*d,a*c),max(b*d,b*c));
 return 0;
}


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

const double kEps = 1e-8;

int N, M;
double xi[500], yi[500], zi[500];
double sx[50], sy[50], sz[50], sa[50];

bool check(int, int);

int main() {
  while (cin >> N, N) {
    for (int i = 0; i < N; ++i)
      cin >> xi[i] >> yi[i] >> zi[i];

    cin >> M;
    for (int i = 0; i < M; ++i)
      cin >> sx[i] >> sy[i] >> sz[i] >> sa[i];

    int res = 0;

    for (int i = 0; i < N; ++i)
      for (int j = 0; j < M; ++j)
        if (check(i, j)) {
          ++res;
          break;
        }

    cout << res << "\n";
  }

  return 0;
}

bool check(int i, int j) {
  double d, d1, d2, a;

  d = xi[i] * sx[j] + yi[i] * sy[j] + zi[i] * sz[j];
  d1 = sqrt(xi[i] * xi[i] + yi[i] * yi[i] + zi[i] * zi[i]);
  d2 = sqrt(sx[j] * sx[j] + sy[j] * sy[j] + sz[j] * sz[j]);
  a = acos(d / (d1 * d2));

  return a < sa[j] + kEps;
}

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

using namespace std;

int main(){
	while(true){
		int n,m; cin >> n >> m;
		if(n == 0) break;
		vector<int> nc(n),mc(m);
		pair<int,int> csum(0,0);
		for(int i = 0; i < n; ++i){
			cin >> nc[i];
			csum.first += nc[i];
		}
		for(int i = 0; i < m; ++i){
			cin >> mc[i];
			csum.second += mc[i];
		}
		sort(nc.begin(), nc.end());
		sort(mc.begin(), mc.end());
		pair<int,int> ans(1000000,1000000);
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j){
				pair<int,int> temp(nc[i],mc[j]);
				if(csum.first - nc[i] + mc[j] == csum.second - mc[j] + nc[i]\
					&& temp.first + temp.second < ans.first + ans.second){
					ans = temp;
				}
			}
		}
		if(ans == make_pair(1000000,1000000)){
			cout << -1 << endl;
		}
		else{
		cout << ans.first << " " << ans.second << endl;
		}
	}
				
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



/*int main(){
    int n,m;
    cin >> n >> m;
    int s[m];
    int c[m];
    int ans[n];
    rep(i,m){
        cin >> s[i] >> c[i];
    }
    //ans syokika
    rep(i,n){
        ans[i]=10;
    }

    rep(i,m){
        if(ans[s[i]-1]==10){
            ans[s[i]-1]=c[i];
        }else if(ans[s[i]-1]!=c[i]){
            cout << "-1" << endl;
            return 0;
        }
    }

    rep(i,n){
        if(ans[i]==10){
            ans[i]=0;
        }
    }

    int check=0;
    
    rep(i,n){
        check+=ans[i];
    }

    if(check==0 and n==1){
        cout << 0 << endl;
        return 0;
    }else{
        cout << -1 << endl;
        return 0;
    }

    bool x=false;

    
    rep(i,n){
        if(x && ans[i]==0){

        }else{
            cout << ans[i];
            x=true;
        }
    }
    cout << endl;
    return 0;
}*/


//string ver.
int main(){
    int n,m;
    int ans=1000;
    cin >> n >> m;
    vector<int> ss(m);
    vector<char> cc(m);
    rep(i,m){
        int s;
        char c;
        cin >> s >> c;
        ss[i]=s-1;
        cc[i]=c;
    }

    for(int i=0;i<pow(10,n);i++){
        string t=to_string(i);
        if(t.size()<n) continue;
        bool ac = true;
        for(int k=0;k<m;k++){
            char c;
            int s;
            s=ss[k];
            c=cc[k];
            ac = ac and (c==t[s]);
        }
        if(ac){
            cout << i << endl;
            return 0;
        } 
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1
typedef struct node{
    int parent;
    int left;
    int right;
}Node;

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
    if(u == NIL)
        return;
    D[u]=d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}

int setHeight(int u){
    int h1=0,h2=0;
    if(T[u].left != NIL)
        h1=setHeight(T[u].left)+1;
    if(T[u].right != NIL)
        h2=setHeight(T[u].right)+1;
    return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u){
    if(T[u].parent == NIL)
        return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg=0;
    if(T[u].left != NIL)
        deg++;
    if(T[u].right != NIL)
        deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);

    if(T[u].parent == NIL)
        printf("root\n");
    else if(T[u].left == NIL && T[u].right == NIL)
        printf("leaf\n");
    else
        printf("internal node\n");
}

int main(void){
    int v,l,r,root=0,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        T[i].parent=NIL;
    for(i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].left=l;
        T[v].right=r;
        if(l != NIL)
            T[l].parent=v;
        if(r != NIL)
            T[r].parent=v;
    }
    for(i=0;i<n;i++)
        if(T[i].parent == NIL)
            root=i;
    setDepth(root,0);
    setHeight(root);
    for(i=0;i<n;i++)
        print(i);
    return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
using PP = pair<int, int>;

class BIT {
  const int n;
  vector<int> v;
public:
  BIT(int n) : n(n), v(n + 1) {}
  void add(int i, int d) {
    for (++i; i <= n; i += i & -i) {
      v[i] += d;
    }
  }
  int get(int i) const {
    int sum = 0;
    for (; i > 0; i -= i & -i) {
      sum += v[i]; 
    }
    return sum;
  }
};

int n, m;
vector<PP> ps;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    ++r;
    ps.push_back(PP(l, r));
  }
  
  sort(ps.begin(), ps.end(), [](PP a, PP b) {
    return a.second - a.first < b.second - b.first;
  });
  
  BIT bit(m + 2);
  int i = 0;
  for (int j = 1; j <= m; ++j) {
    while (i < n && (ps[i].second - ps[i].first) < j) {
      bit.add(ps[i].first, 1);
      bit.add(ps[i].second, -1);
      ++i;
    }

    int ans = n - i;
    for (int k = 0; k <= m; k += j) {
      ans += bit.get(k + 1);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 6512
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int main(int argc, char const* argv[]) {
	int N, A;
	scanf("%d %d", &N, &A);
	printf(N % 500 <= A ? "Yes\n" : "No\n");

	return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}

// #define ncr_nikalo
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int t=1;
    //cin>>t;
    #ifdef ncr_nikalo
        initialvalues();
    #endif
        
    for(ll int g=0;g<t;g++)
    {
    	ll int ans=0;
    	string s,t;
    	cin>>s>>t;
    	for(ll int i=0;i<s.length();i++)
    	{
    		if(s[i]!=t[i])
    			ans++;
    	}
    	cout<<ans;



    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int a1, a2, a3;
  CIN(a1 >> a2 >> a3);

  if (22 <= (a1 + a2 + a3)) {
    COUT("bust");
  } else {
    COUT("win");
  }

  return 0;
}


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

string S;
int A[1000006];

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int N, Q;
    cin >> N >> S >> Q;
    
    for(int i=0; i<N; i++)
    {
        if(S[i] == 'D')
            A[i+1] = 1;
        if(S[i] == 'M')
            A[i+1] = 2;
        if(S[i] == 'C')
            A[i+1] = 3;
    }
    
    for(int i=1; i<=Q; i++)
    {
        int K;
        cin >> K;
        
        long long s = 0, e = 0, pairs = 0, ans = 0;
        
        for(int j=1; j<=N; j++)
        {
            if(A[j] == 1)
                s++;
            if(A[j] == 2)
                e++, pairs += s;
            
            if(j > K && A[j-K] == 1)
                pairs -= e, s--;
            if(j > K && A[j-K] == 2)
                e--;
            
            if(A[j] == 3)
                ans += pairs;
        }
        
        cout << ans << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 5276
def merge(A, n, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]

    L.append(2000000000)  # これをしないとマージするとき、最後の１回でリスト外アクセスでエラー。
    R.append(2000000000)

    global count
    i, j = 0, 0

    # print('left, mid, right')
    # print(left, mid, right)

    for k in range(left, right, 1):
        count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end')


def merge_sort(A, n, left, right):
    if right - left > 1:
        mid = (left + right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right)


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

merge_sort(A, N, 0, N)

print(' '.join(map(str, A)))
print(count)



Measured memory_bytes: 66768
import sys

def parse(inp):
    n,m,c=map(int,next(inp).split())
    B=list(map(int,next(inp).split()))
    A=[[] for _ in range(n)]
    
    for i in range(n):
        A[i]=list(map(int,next(inp).split()))
        
    return n,m,c,A,B
  
def main(inp):
    n,m,c,A,B=inp
    ans=0
    
    for i in range(n):
        code=0
        for j in range(m):
            code += A[i][j]*B[j]
            
        if(code+c>0): ans+=1
            
    return ans
  
print(main(parse(sys.stdin)))

Measured memory_bytes: 3064
#include <stdio.h>

int MAX = 2147483647;

int D[20000000];
int n, n_;
int l;


int min(int a, int b)
{
    if(a < b) return a;
    else return b;
}


int initRMQ(int n)
{
    int n_ = 1;

    while(n_ < n)
        n_ *= 2;

    for(int i = 0; i < 2*n_ - 1; i++)
        D[i] = MAX;

    return n_;
}


void update(int k, int a)
{
    k += n_ - 1;
    D[k] = a;

    while(k > 0)
    {
        k = (int)((k - 1) / 2);
        D[k] = min(D[k*2 + 1], D[k*2 + 2]);
    }
}


int query(int a, int b, int k, int l, int r)
{
    if(r <= a || b <= l) return MAX;
    if(a <= l && r <= b) return D[k];

    int vl = query(a, b, k*2 + 1, l, (int)((l + r)/2));
    int vr = query(a, b, k*2 + 2, (int)((l + r)/2), r);

    return min(vl, vr);
}


int findMin(int a, int b)
{
    return query(a, b, 0, 0, n_);
}


int main(int argc, char const* argv[])
{
    scanf("%d %d", &n, &l);

    int A[1000000];

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

    n_ = initRMQ(n);

    for(int i = 0; i < n; i++)
    {
        update(i, A[i]);
    }

    for(int i = 0; i < n-l; i++)
    {
        printf("%d ", findMin(i, i+l));
    }
    printf("%d\n", findMin(n-l, n));
}



Measured memory_bytes: 13940