akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.datetime;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto Q = s[2];
    auto A = readln.split.map!(to!long).array;
    auto B = A.dup;
    B.sort();
    B = B.uniq().array;
    int M = B.length.to!int;
    long ans = 1L << 59;

    foreach (i; 0..M) {
        long[] ok;
        long[] tmp;
        foreach (j; 0..N) {
            if (A[j] < B[i]) {
                if (tmp.length >= K) {
                    tmp.sort();
                    ok ~= tmp[0..tmp.length.to!int-K+1].dup;
                }
                tmp = [];
            } else {
                tmp ~= A[j];
            }
        }
        if (tmp.length >= K) {
            tmp.sort();
            ok ~= tmp[0..tmp.length.to!int-K+1].dup;
        }
        ok.sort();
        if (ok.length >= Q) {
            ans = min(ans, ok[Q-1] - B[i]);
        }
    }

    ans.writeln;
}


Measured memory_bytes: 5372
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input())
    a = list(map(int, input().rstrip().split()))
    b = list(map(int, input().rstrip().split()))
    minus_sum = 0
    pluses = []
    ans = 0
    for i in range(n):
        if a[i] < b[i]:
            minus_sum += b[i] - a[i]
            ans += 1
        else:
            pluses.append(a[i] - b[i])
    pluses.sort(reverse=True)
    for v in pluses:
        if minus_sum <= 0:
            break
        minus_sum -= v
        ans += 1
    if minus_sum > 0:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n; cin >> n;
    ll sum = 0;
    for(ll i=1; i<=n; ++i){
        if((i%3==0)||(i%5==0)){continue;}
        sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
 
using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;
 
 
 
int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,c;
	cin >>a >>b >>c;
	
	if(b-a == c-b) puts("YES");
	else  puts("NO");
	return 0;
}

Measured memory_bytes: 256
A, B, C = list(map(int, input().split())) 
K = int(input())
N = 0

while B <= A:
    B = B * 2
    N = N + 1

while C <= B:
    C = C * 2
    N = N + 1

if K >= N:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n, m, a, b, p[100005], dist[100005];
vector<int> adj[100005];
queue<pi> q;

int main() {
	fastio; cin >> n >> m;
	FOR(i, 1, m) {
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	memset(dist, -1, sizeof dist);
	dist[1] = 0; q.push(pi(1, 0));
	while (!q.empty()) {
		auto [x, d] = q.front(); q.pop();
		dist[x] = d;
		for (auto it:adj[x]) {
			if (dist[it] == -1 or dist[it] > d + 1) {
				dist[it] = d + 1;
				p[it] = x;
				q.push(pi(it, d+1));
			}
		}
	}
	bool ok = true;
	FOR(i, 2, n) if (p[i] == 0) ok = false;
	if (ok) {
		cout << "Yes\n";
		FOR(i, 2, n) cout << p[i] << "\n";
	} else cout << "No";
}


Measured memory_bytes: 11088
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]

    for i in range(n+1):
        S[i]-=i
        S[i]%=k

    C=defaultdict(list)
    for i in range(n+1):
        C[S[i]].append(i)

    ans=0
    C=list(C.values())
    for d in range(len(C)):
        n=len(C[d])
        if(n<=1): continue
        r=0
        for l in range(n):
            while(r+1<n and C[d][r+1]-C[d][l]<k):
                r+=1
            ans+=r-l
            if(r==l): r+=1
    print(ans)
resolve()

Measured memory_bytes: 120424
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

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

    if(a=='H' && b=='H'){
        cout << "H" << endl;
    }
    if(a=='H' && b=='D'){
        cout << "D" << endl;
    }
    if(a=='D' && b=='H'){
        cout << "D" << endl;
    }
    if(a=='D' && b=='D'){
        cout << "H" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n")[0].split(""),t=0,n=r.length-2;n>=0;n--){for(var o=!1,u=0;u<=n;u++){if(r.slice(0,u).join("")==r.slice(u,n+1).join("")){o=!0;break}}if(o)return t=n+1,void console.log(t)}}},function(e,r){e.exports=require("fs")}]);

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

int main() {
  	
  	int n, r;
  	cin >> n >> r;
  	if(n > 10) {
    	cout << r << '\n';
        return 0;
    }
  	int k = (100 * (10-n));
  	cout << k + r << '\n';
  
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//






ll h[100010];
ll dp[100010];

int main(){
        ll n,k;
        cin >> n >> k;
        for(int i = 1; i <= n; i++) cin >> h[i];

        dp[1] = 0;
        for(int i = 2; i <= n; i++){
                dp[i] = 1e18;
                for(int j = 1; j <= k; j++){
                        if(i-j <= 0) break;
                        dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
                }
        }
        
        cout << dp[n] << endl;
        return 0;


















































}


Measured memory_bytes: 1792
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4,sse4.1,sse4.2,avx,tune=native")
#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){if(a > b) a = b;}


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI a(n), b(n);
	vector<VI> z(100005);
	rep(i, n){
		int a, b;
		cin >>a >>b;
		z[a].push_back(b);
	}
	ll ans = 0;
	priority_queue<int> pq;
	rep(i, m+1) {
		for(auto x: z[i]) pq.emplace(x);
		if(sz(pq)){ ans += pq.top(); pq.pop();}
	}
	
	cout << ans<<"\n";
	return 0;
}


Measured memory_bytes: 6400
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int n, k; cin >> n >> k;
    vi v(n); 
    rep (i, 0, n-1) cin >> v[i];

    vector<ll> dp(n, INT_MAX);
    dp[0] = (ll) 0;

    rep (i, 1, n-1) {
        repD (j, i-1, i-k) {
            if (j < 0) break;
    	    
            dp[i] = min (dp[j] + abs(v[j]-v[i]), dp[i]);
        }
    }

    cout << dp[n-1];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main()
{
    int n;
    cin>>n;
    map<long long int,long long int> m;
    vector<long long int> vec;
    pair<long long int,long long int> p(0,0);
    m.insert(p);
    vec.push_back(1);
    long long int flag=1,rst=0;
    long long int in,sum=0;
    for(int i=0;i<n;++i)
    {
        cin>>in;
        sum+=in;
        if(m.find(sum)==m.end())
        {
            pair<long long int,long long int> p0(sum,flag);
            m.insert(p0);
            vec.push_back(0);
            ++flag;
        }
        rst+=vec[m[sum]];
        ++vec[m[sum]];
    }
    cout<<rst<<endl;
    return 0;
}

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

typedef long long ll;
const int N = 105, MOD = 1e9 + 7;
int n, m, k, fac[N << 1], ifac[N << 1];

int fpow(int a, int m) {
	int ans = 1;
	for(; m; m >>= 1) {
		if(m & 1) ans = ans * 1ll * a % MOD;
		a = a * 1ll * a % MOD;
	}
	return ans;
}

struct Edge {
	int nxt, v;
}e[N << 1];
int bccno[N], bcc_cnt,siz_e[N], siz_p[N], dfs_clock, low[N], pre[N], head[N], cnt, top;
pair<int, int> stk[N];

void add(int u, int v) {
	e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
	e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}
void dfs(int u, int fa) {
    low[u] = pre[u] = ++dfs_clock;
    for(int i = head[u]; ~i; i = e[i].nxt) {
    	int v = e[i].v;
    	if(v == fa) continue;
    	if(!pre[v]) {
    		stk[++top] = make_pair(u, v);
    		dfs(v, u);
    		low[u] = min(low[u], low[v]);
    		if(low[v] >= pre[u]) {
    			bcc_cnt++;
    			while(523) {
                    int x = stk[top].first, y = stk[top].second;
    			    top--;
    			    siz_e[bcc_cnt]++;
    			    if(bccno[x] != bcc_cnt) {bccno[x] = bcc_cnt; siz_p[bcc_cnt]++;}
    			    if(bccno[y] != bcc_cnt) {bccno[y] = bcc_cnt; siz_p[bcc_cnt]++;}
    			    if(x == u && y == v) break;
    			}
    		}
    	}
    	else if(pre[v] < pre[u]) {stk[++top] = make_pair(u, v); low[u] = min(low[u], pre[v]);}
    }
}
int C(int n, int m) {
	return fac[n] * 1ll * ifac[m] % MOD * ifac[n - m] % MOD;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
    memset(head, -1, sizeof head);
    scanf("%d %d %d", &n, &m, &k);
    fac[0] = ifac[0] = ifac[1] = 1;
    for (int i = 1; i <= m + k; ++i) fac[i] = fac[i - 1] * 1ll * i % MOD;
    for (int i = 2; i <= m + k; ++i) ifac[i] = (MOD - MOD / i) * 1ll * ifac[MOD % i] % MOD;
    for (int i = 2; i <= m + k; ++i) ifac[i] = ifac[i - 1] * 1ll * ifac[i] % MOD;
    for(int i = 1; i <= m; i++) {
    	int u, v;
    	scanf("%d %d", &u, &v);
    	add(u, v);
    }
    for(int i = 1; i <= n; i++) {
    	if(!pre[i]) dfs(i, 0);
    }
    int ans1 = 1, ans2 = 1, ans3 = 1;
    for(int i = 1; i <= bcc_cnt; i++) {
    	if(siz_e[i] == 1) ans1 = ans1 * 1ll * k % MOD;
    	else if(siz_e[i] == siz_p[i]) {
            int sum = 0;
            for(int j = 0; j < siz_e[i]; j++) {
                sum += fpow(k, gcd(siz_p[i], j));
                if(sum >= MOD) sum -= MOD;
            }
            ans2 = ans2 * 1ll * sum % MOD * fpow(siz_e[i], MOD - 2) % MOD; 
    	} else ans3 = ans3 * 1ll * C(siz_e[i] + k - 1, k - 1) % MOD;
    }
    printf("%lld\n", ans1 * 1ll * ans2 % MOD * ans3 % MOD);
    return 0;
}

Measured memory_bytes: 3808
def root(lista, S, G, M, N, memory):
  if(S == G and memory == set(range(1, N+ 1))):
    return 1
  elif(S == G and memory != set(range(1, N+ 1))):
    return 0
  elif(lista == []):
    return 0
  else:
    roots = 0
    possibilities = 0
    possibleroots = []
    for i in range(M):
      if(S in lista[i]):
        q = list(filter(lambda x: x != S, lista[i])).pop()
        if(q in memory):
          continue
        else:
          possibleroots.append(q)
    if(possibleroots == []):
      return 0
    else:
      for q in possibleroots:
        newlista = list(filter(lambda x: x != {S, q}, lista))
        newmemory = memory| {q}
        
        roots+= root(newlista, q, G, M- 1, N, newmemory)
      return roots


N, M = map(int, input().split())
lista = []
for i in range(M):
  lista.append(set(map(int, input().split())))
  
ans = 0
for i in range(2, N+ 1):
  ans+= root(lista, 1, i, M, N, {1})
  
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR(i,x,y) for(int i=(x),i##END=(y);i<=i##END;++i)
#define DOR(i,x,y) for(int i=(x),i##END=(y);i>=i##END;--i)
template<typename T,typename _T>inline bool chk_min(T &x,const _T y){return y<x?x=y,1:0;}
template<typename T,typename _T>inline bool chk_max(T &x,const _T y){return x<y?x=y,1:0;}
typedef long long ll;

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	printf("%d\n",(n+2*m)/(2*m+1));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, m; scanf("%d%d", &n, &m);

	if(n == m) printf("Yes\n");
	else printf("No\n");	
	return 0;
}


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

int main() {
    int N; cin >> N;
    ll maz = -1e10, miz = INT64_MAX;
    ll maw = -1e10, miw = INT64_MAX;
    vector<pair<int,int>> P(N);
    rep(i,N) {
        ll x, y; cin >> x >> y;
        ll z = x + y;
        if (maz < z) maz = z;
        if (miz > z) miz = z;
        ll w = x - y;
        if (maw < w) maw = w;
        if (miw > w) miw = w;
    }
    cout << max(maz - miz, maw - miw) << endl;
}


Measured memory_bytes: 4804
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
	ssd
	#define task "TASK"
	 //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    ll n,sum=0;

    cin>>n;
    vector<ll>v(n);
    cin>>v[0];
    ll max=v[0];
    for(ll i=1;i<n;i++)
    {
        cin>>v[i];
        if(max<v[i])
        {
            max=v[i];
        }
        else
        {
            sum+=(max-v[i]);
        }
           // cout<<max<<" "<<v[i]<<endl;


    }
    cout<<sum<<endl;


	return 0;
}


Measured memory_bytes: 4792
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
	int N; cin >> N;
	unsigned long long a = 1;
	for (int i = 1; i <= N; ++i) {
		a = a * i % (1000 * 1000 * 1000 + 7);
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 3160
import sys
from collections import deque
sys.setrecursionlimit(10**9)
 
K = int(input())
 
lis = deque()
def dfs(nowD, maxD, x):
    if nowD == maxD:
        lis.append(x)
        if len(lis) >= K:
            print(lis.pop())
            exit()
    else:
        y = x%10
        x *= 10
        if y-1 >= 0:
            dfs(nowD+1, maxD, x+y-1)
        dfs(nowD+1, maxD, x+y)
        if y+1 <= 9:
            dfs(nowD+1, maxD, x+y+1)
 
for d in range(1, 11):
    for x in range(1, 10):
        dfs(1, d, x)

Measured memory_bytes: 7496
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in(), c = in();
	cout << (
		a == b ? c
		: b == c ? a
		: b
		) << endl;
}

Measured memory_bytes: 384
a= list(map(int,input().split()))
W = a[0] 
H = a[1] 
x = a[2]
y = a[3]
r = a[4]

if x-r < 0:
    print ("No")
elif x + r > W:
    print ("No")
elif y-r < 0:
    print ("No")
elif y+r > H:
    print ("No")
else:
    print ("Yes")


Measured memory_bytes: 5596
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXN = 1e5;
int ans[MAXN], k[MAXN];
char ch[3] = { 'A', 'B', 'C' };

int main() {
  int N, ABC[3]; std::cin >> N >> ABC[0] >> ABC[1] >> ABC[2];
  for(int i = 0; i < N; ++i) {
    std::string s; std::cin >> s;
    if(s == "AB") k[i] = 0;
    else if(s == "BC") k[i] = 1;
    else k[i] = 2;
  }
  for(int i = 0; i < N; ++i) {
    int x = k[i], y = (x+1)%3, z = (x+2)%3;
    if(ABC[x] + ABC[y] == 0) fin("No");
    if(ABC[x] > ABC[y]) ans[i] = y;
    else if(ABC[x] < ABC[y]) ans[i] = x;
    else if(i < N-1 && k[i+1] == k[i]) {
      if(ABC[x] > 0) { ans[i] = y; ans[i+1] = x; }
      else           { ans[i] = x; ans[i+1] = y; }
      ++i; continue;
    } else if(i < N-1) {
      if(k[i+1] == y) ans[i] = y;
      else            ans[i] = x;
    } else ans[i] = x;
    if(ans[i] == x) { ++ABC[x]; --ABC[y]; }
    else            { ++ABC[y]; --ABC[x]; }
  }
  std::cout << "Yes\n";
  for(int i = 0; i < N; ++i) std::cout << ch[ans[i]] << "\n";
  return 0;
}


Measured memory_bytes: 4408
#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>
#include <string.h>
#include <algorithm>
#define mod 1000000007
#define inf 1LL<<61
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(a+b < 10)
		cout << a+b;
	else
		cout << "error";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	long long sum=0;
	cin>>n;
	if(n&1)
	cout<<0;
	else{
	n/=2;
	while(n) {
		n/=5;
		sum+=n;
	}
	cout<<sum;}
	return 0;
}

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

int main() {
	int n, m;
	std::cin >> n >> m;

	std::vector<int> imos(n + 1);
	for (int i = 0; i < m; ++i) {
		int l, r;
		std::cin >> l >> r;

		++imos[l - 1];
		--imos[r];
	}

	for (int i = 1; i < imos.size(); ++i)
		imos[i] += imos[i - 1];

	std::cout << std::count(imos.begin(), --imos.end(), m) << std::endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define rep(i,a,n) for(long long i=a;i<=n;i++)
typedef long long ll;

#define NDEBUG
#ifdef  NDEBUG
#define dbg(...)
#else
#include"debug.cpp"
#endif

const int N=2e7+10;
long long T, n, m, k, x, y, z, l, r, q, ans, a[N], b[N], mod = 1e9+7;

void solve(){
	cin >> n;
	int cnt=0;
	rep(i,1,n) cin >> a[i];
	rep(i,1,n){
		if(i%2 && a[i]%2) cnt++;
	}
	cout<<cnt;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//cin >> T; while(T--)
	solve();
}


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

int main()
{
int n;
int l[200];
cin>>n;
for(int i=0;i<n;i++)
cin>>l[i];

sort(l,l+n);
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
    {
    for(int k=j+1;k<n;k++)
    if(l[i]+l[j]>l[k] && l[i]!=l[j] && l[j]!=l[k])ans++;
        
    }

}


cout <<ans;
}

Measured memory_bytes: 3624
n,m=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
c=0
for _ in range(2**n):
  s=format(_,'0{}b'.format(n))
  f=1
  for i in range(m):
    a=0
    for j in range(1,k[i][0]+1):
      a+=int(s[k[i][j]-1])
    if a%2!=p[i]:
      f=0
      break
  if f:
    c+=1
print(c)

Measured memory_bytes: 3064
Q, H, S, D=map(int,input().split())
N=int(input())
Q_1liter=4*Q
H_1liter=2*H
S_1liter=S
min_QHS=min(Q_1liter,H_1liter,S_1liter)
min_QHS2=min(min_QHS*2,D)
if N%2==0:
    output=min_QHS2*int(N/2)
    print(int(output))
else:
    output=(int(N/2)*min_QHS2+min_QHS)
    print(int(output))

Measured memory_bytes: 3064
<?php
    const INPUT_DELIMITER = " ";
    const OUTPUT_DELIMITER = " ";

    // 標準入力
//    echo "値を入力してください\n";
    $input = fgets(STDIN);
    $inputArray = explode(INPUT_DELIMITER, $input);

    // 変数代入

    // メイン処理
    $count = $inputArray[0];
    $start = $inputArray[1];

    $points = [];
    for ($i = 0; $i < $count; $i++) {
        $points[] = $start + ($i + 1) - 1;
    }

    $nearZeroPoint =  abs($points[0]);
    foreach ($points as $point) {
        if ((int)$nearZeroPoint >= abs($point)) {
            $nearZeroPoint = abs($point);
        }
    }
    $output = 0;
    foreach ($points as $point) {
        if ((int)$nearZeroPoint != abs($point)) {
            $output += $point;
        }
    }

    // 標準出力
    echo $output;

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

class BIT
{
public:
    vector<int> bit;
    int M;

    BIT(int M):
        bit(vector<int>(M+1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

signed main(){

    int N, K; cin >> N >> K;
    vec a(N); readvec(a);
    REP(i, N) a[i] -= K;

    vec asum(N + 1);
    asum[0] = 0;
    REP(i, N){
        asum[i + 1] = asum[i] + a[i];
    }

    vector<Pii> p(N + 1);
    REP(i, N + 1) p[i] = Pii(asum[i], i);
    SORT(p);
    int tmp = -1 * INF;
    int i0 = -1;
    vec index(N + 1);
    REP(i, N + 1){
        if(tmp < p[i].first){
            tmp = p[i].first;
            i0++;
        }
        index[p[i].second] = i0;
    }

    BIT bit(N + 1);
    int ans = 0;
    REP(i, N + 1){
        int n = index[i];
        ans += bit.sum(n + 1);
        bit.add(n + 1, 1);
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    int ans = 0;
    rep(i, n+1) {
        ans += i;
    }
    cout << ans << endl;

    return 0;
}


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

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        System.out.println(factorial(Integer.parseInt(inputReader.readLine())));
    }
    public static long factorial(long n) {
        if (n <= 1) return 1;
        return n * factorial(n - 1);
    }
}

Measured memory_bytes: 9104
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

string s;
LL pw[15];
int nextZero;
int cnt = 0;

bool no() {
  return s[0] == 'N';
}

bool yes() {
  return !no();
}

void check(LL x) {
  cnt++;
  assert(cnt < 65);
  cout << "? " << x << "\n";
  fflush(stdout);
  cin >> s;
}

void putAns(LL x) {
  cout << "! " << x << "\n";
  fflush(stdout);
  exit(0);
}

int findDigits() {
  for(int i = 9; i >= 1; i--) {
    check(pw[i] - 1);
    if(no()) {
      return i + 1;
    }
  }

  for(int i = 1; i <= 9; i++) {
    check(pw[i]);
    if(no()) {
      return i;
    }
  }
  return 0;
}

int getDigit(int f, LL cur) {
  if(nextZero) return 0;
  nextZero = 0;
  int lo = f, hi = 8;
  int idx = f;
  
  while(lo <= hi) {
    int mi = (lo + hi) >> 1;
    LL tmp = cur * 10 + mi;
    while(tmp < 1e12) tmp *= 10;
    check(tmp);
    if(no()) {
      idx = mi;
      lo = mi + 1;
    } else {
      hi = mi - 1;
    }
  }

  // check idx and idx + 1
  LL tmp = cur * 10 + idx + 1;
  while(tmp < 1e12) tmp *= 10;
  check(tmp - 1);
  if(yes()) {
    return idx;
  }
  // nextZero means next number is 0
  // nextZero = 1;
  return idx + 1;
}

int main() {
  pw[0] = 1;
  rep(i,1,15) pw[i] = pw[i - 1] * 10;
  int x = findDigits();
  if(!x) {
    putAns(1);
  } else if(x == 10) {
    putAns(pw[9]);
  }
  LL ans = 0;
  rep(i,1,x+1) {
    int d = getDigit(i == 1, ans);
    ans = ans * 10 + d;
  }
  putAns(ans);
  return 0;
}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
string S;

void solve(){
    if(S[2]==S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    cin >> S;

    solve();
}


Measured memory_bytes: 256
e = list(map(int,input().split()))
a,b,c,d = e

def gcd(x,y):
    while y !=0:
        x,y = y,x%y
    return x

def sums(x):
    S1 = x//c
    S2 = x//d
    S3 = x// (c*d//gcd(c,d))
    return x - S1 - S2 + S3


print(sums(b)-sums(a-1))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void)
{
    int A, B, C, x, y, i=2, judge=1;

    cin >> A >> B >> C;

    x = A % B;

    if(x == C){
        cout << "YES" << endl;
    }

    else{
        y = x;

        while(y != C){
            y = (A*i) % B;

            if(y == x){
                judge = 0;

                break;
            }

            i++;
        }
    }

    if(judge == 0){
        cout << "NO" << endl;
    }

    else{
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;

void main(){
	auto inputs = readln.chomp.split.map!(to!int).array;
    auto answer = iota(inputs[0],inputs[1]+1).map!(to!string).filter!is_palindromic.array.length;
    writeln(answer);
}

bool is_palindromic(string target){
    foreach(i,c; target) {
        if(c != target[$-i-1]){return false;}
    }
    return true;
}

Measured memory_bytes: 1276
#include <cstring>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N;
ll A[3002], B[3002];
ll DP[3001][3001]; //　Aのindexがどれぐらいすすんだのか、Bのindexがどれぐらいすすんだのか
bool U[3001][3001];
ll dfs_s(int, int);
ll dfs_t(int, int);

ll dfs_s(int a_idx, int b_idx){
  if (U[a_idx][b_idx]) return DP[a_idx][b_idx];
  if ((a_idx+b_idx) == N) return 0;
  ll c_s = dfs_t(a_idx+1, b_idx) + A[a_idx];
  ll c_t = dfs_t(a_idx, b_idx+1) + B[b_idx];
  ll res = max(c_s, c_t);
  DP[a_idx][b_idx] = res;
  U[a_idx][b_idx] = true;
  return res;
}

ll dfs_t(int a_idx, int b_idx){
  if (U[a_idx][b_idx]) return DP[a_idx][b_idx];
  if ((a_idx+b_idx) == N) return 0;
  ll c_s = dfs_s(a_idx+1, b_idx) - A[a_idx];
  ll c_t = dfs_s(a_idx, b_idx+1) - B[b_idx];
  ll res = min(c_s, c_t);
  DP[a_idx][b_idx] = res;
  U[a_idx][b_idx] = true;
  return res;
}

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

  cin >> N;
  ll a = 0;
  rep(i, N){
    cin >> a;
    A[i] = a;
    B[N-1-i] = a;
  }

  ll ans = dfs_s(0, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 78464
#include<stdio.h>

int main(void)
{
  int a,b,c,d;
  int s=0;

  scanf("%d %d %d %d",&a,&b,&c,&d);

  if(a<=b)
    s=a*c;

  else
    s=b*c+d*(a-b);

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


  return 0;
}


Measured memory_bytes: 128
def solve(x, n, nums):
	if not nums or x not in nums:
		return x
	a = x - 1
	b = x + 1
	while True:
		if a not in nums:
			return a
		if b not in nums:
			return b
		a -= 1
		b += 1

x, n = map(int, input().split())
A = None
if n > 0:
	A = set(list(map(int, input().split())))
print(solve(x, n, A))

Measured memory_bytes: 9132
#include<iostream>
using namespace std;
const long long mod = 1000000007;
long long fact[300000], inv[300000], factinv[300000], n, p[100009], a[100009], l, r;
long long ncr(int n, int r) { return (n - r >= 0 && r >= 0) ? 1LL * fact[n] * factinv[r] % mod * factinv[n - r] % mod : 0; }

int main() {
	fact[0] = 1;
	for (int i = 1; i < 300000; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
	inv[1] = 1;
	for (int i = 2; i < 300000; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	factinv[0] = 1;
	for (int i = 1; i < 300000; i++) factinv[i] = 1LL * factinv[i - 1] * inv[i] % mod;

	cin >> n;
	for (int i = 1; i <= n + 1; i++) {
		cin >> a[i];
		if (p[a[i]] == 0)p[a[i]] = i;
		else { l = p[a[i]]; r = i; }
	}
	for (int i = 1; i <= n + 1; i++) {
		cout << (ncr(n + 1, i) - ncr((l - 1) + (n + 1 - r), i - 1) + mod) % mod << endl;
	}
	return 0;
}

Measured memory_bytes: 9856
#include <stdio.h>

int S[1000000],n;

int binarySearch(int T){
	int left = 0;
	int right = n;
	int mid;
	while (left < right){
		mid = (left + right) / 2;
		if (S[mid] == T){
			return 1;
		}
		
		if(T<S[mid]){
            right = mid;
		}else if(T>S[mid]){
            left = mid + 1;
		}
	}
    return 0;
}

int main(void){
	int q,i,T;
	int count=0;
	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);
		count+=binarySearch(T);
	}
	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 2128
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int number=0;
            int upstatus=0;
            boolean nowFloor = true;
            ArrayList<String> action = new ArrayList<String>();
            int up=sc.nextInt();
            if(up==0){break;}
            for (int i = 0; i <up; i++) {
                action.add(sc.next());
                if (action.get(i).equals("lu") || action.get(i).equals("ru")) {upstatus++;} else {upstatus--;}
                if (nowFloor && upstatus == 2) {nowFloor = false;number++;}
                if (!nowFloor && upstatus == 0) {nowFloor = true;number++;}
            }System.out.println(number);
        }
    }
}

Measured memory_bytes: 38332
#include <iostream>
#include <string>
#include <stack>
#include <queue>
using namespace std;
int N;
stack<int> st;
int main()
{
    string S;
    cin >> S;
    N = S.length();
    int SS[N];

    for (int i = 0; i < N; i++)
    {
        SS[i] = (int)S[i];
    }
     st.push(SS[0]);
     int del=0;
    for (int i = 1; i < N; i++)
    {
        if(st.size()==0 ||st.top()==SS[i]){
            st.push(SS[i]);
        }
        else{
            st.pop();
            del+=2;
        }
    }

    cout << del << endl;
}


Measured memory_bytes: 1152
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

const string YES = "Yes";
const string NO = "No";

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long x, long long y){
    for(int i = 0; i < 1e3; ++i){
        for(int j = 0; j < 1e3; ++j){
            if(i + j == x && 2 * i + 4 * j == y){
                cout << YES << endl;
                return;
            }
        }
    }
    cout << NO << endl;
}


signed main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include <string.h>
int main()
{

char str[21]={};
char ch;
int n;
scanf("%s",str);
n = strlen(str);
for(int i=0;i<n;i++)
{
printf("%c",str[n-i-1]);
}
printf("\n");
return 0;
}

Measured memory_bytes: 932
n = int(input())
from operator import itemgetter
t = 0
ab = [list(map(int,input().split()))for i in range(n)]
ab.sort(key = itemgetter(1))
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]

    t += a
    if t > b:
        print('No')
        break
else:print("Yes")
 

Measured memory_bytes: 89688
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);

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

  ll cur = X;
  int ans = 0;

  while (cur <= Y){
    ans++;
    cur *= 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
def kaibun(s):
  len_s = len(s)
  for i in range(len_s//2):
    if s[i] != s[-i-1]:
      return False
  return True

s = input()
n = len(s)

if kaibun(s) and kaibun(s[:(n-1)//2]) and kaibun(s[(n+3)//2-1:]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, tmp, time; sc(n)
    vector<int> t(n+1), x(n+1), y(n+1);
    t[0] = x[0]= y[0] = 0;
    for (int i = 1; i <= n; i++){
        sc(t[i]) sc(x[i]) sc(y[i]) 
    }
    bool check = true;
    for (int i = 0; i < n; i++){
        tmp = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        time = t[i+1] - t[i];
        if (time < tmp){
            check  = false;
            break;
        }else{ 
            if ((time - tmp) % 2 != 0){
                check  = false;
                break;
            }
        }
    }
    if (check) cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1408
import numpy
H = int(input())
sum = 0
cnt = 0
if(H == 1):
	print(1)
	exit()
while H > 1:
	#print(H)
	sum += 2**cnt
	H/=2
	numpy.ceil(H)
	H = int(H)
	cnt+=1
print(sum+2**(cnt))

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

#pragma warning( disable : 4996 )

#define si(n) scanf("%d", &n)
#define sll(n) scanf("%lld", &n)
#define ss(s) scanf("%s", &s)
#define pi(n) printf("%d\n", n)
#define pll(n) printf("%lld\n", n)
#define ps(s) printf("%s\n", s)
#define FOR(i, a, b) for (int i=a;i<=b;i++)


typedef long long ll;

int find(int parent[], int i)
{
	if (parent[i] == -1)
		return i;
	return find(parent, parent[i]);
}


void Union(int parent[], int x, int y)
{
	int xset = find(parent, x);
	int yset = find(parent, y);
	if (xset != yset)
	{
		parent[xset] = yset;
	}
}

void solve() {
	int N, Q;
	cin >> N >> Q;
	
	int* parent = new int[N * sizeof(int)];

	memset(parent, -1, sizeof(int) * N);

	while (Q--) {
		int t, u, v;
		cin >> t >> u >> v;
		if (t) {
			if (find(parent, u) == find(parent, v)) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
		else {
			Union(parent, u, v);
		}
	}
}


int main() {
	solve();
}

Measured memory_bytes: 4220
N,A = map(int,input().split())
X = [0]+list(map(int,input().split()))
dp = []
for i in range(N+1):
  K = []
  for j in range(N+1):
    J = [0]*(N*max(X)+1)
    K.append(J)
  dp.append(K)
for j in range(N+1):
  for k in range(N+1):
    for s in range(N*max(X)+1):
      if j >= 1:
        if s < X[j]:
          dp[j][k][s] = dp[j-1][k][s]
        elif s >= X[j] and k >= 1:
          dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-X[j]]
        else:
          dp[j][k][s] = 0
      else:
        if k == 0 and s == 0:
          dp[j][k][s] = 1
        else:
          dp[j][k][s] = 0
ans = 0
for i in range(1,N+1):
  if i*A <= N*max(X):
    ans += dp[N][i][i*A]
print(ans)

Measured memory_bytes: 93660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  string s;cin >> s;
  int ans=0;
  for(int i=0;i<n-2;i++){
    if(s.substr(i,3)=="ABC"){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"

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

int ch_A(int n,int m,long long int*A,long long int B){
  if(m==n){
    if(A[m]==B){
      return m;
    }else{
      return -1;
    }
  }
  if (B<A[n]||A[m]<B) {
    return -1;
  }
  int k=(int)((n+m)/2);
  if(A[k]>B){
    return ch_A(n,k-1,A,B);
  }
  if(A[k]<B){
    return ch_A(k+1,m,A,B);
  }
  if(A[k]==B){
    return k;
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  int N;
  int i;
  scanf("%d", &N);
  long long int A[N];
  for (i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  qsort(A, N, sizeof(long long int), compare_int);

  int B[N];
  int A_B[N];
  int t=1;
  int ind=0;
  A_B[0]=0;
  for (i = 0; i < N-1; i++) {
    if (A[i+1]==A[i]) {t++;A_B[i]=ind;}
    if (A[i+1]!=A[i]) {B[ind]=t;A_B[i]=ind;ind++;t=1;}
  }
  B[ind]=t;A_B[N-1]=ind;ind++;


  // printf("ind %d\nB ", ind);
  // for ( i = 0; i < ind; i++) {
  //   printf("%d ", B[i]);
  // }
  // printf("\nA_B ");
  // for (i = 0; i < N; i++) {
  //   printf("%d ", A_B[i]);
  // }
  // printf("\n");

  long long int C[N];
  long long int k;
  for ( i = 0; i < N; i++) {
    k=2;
    while (k<=A[i]) {k=k*2;}
    C[i]=k-A[i];
  }

  int temp;
  int ans=0;
  for (i = N-1; i >=1; i--) {
    temp=ch_A(0,i-1,A,C[i]);
    B[A_B[i]]--;
  //  printf("%d %d\n",i, temp);
    if(temp!=-1){
      if(B[A_B[temp]]>=1 && B[A_B[i]]>=0){
        B[A_B[temp]]--;
        ans++;
      }
    }
    //printf("%lld %lld %d %d\n",A[i],k-A[i],temp,ans);
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 4832
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s, p;
	string::size_type d;
	cin >> s >> p;
	s = s + s;
	d = s.find(p);
	if (d == string::npos){
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3144
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    A,B,C = MAP()
    answer = A*B*(-(-C//2)-C//2)

    answer = min(answer,C*B*(-(-A//2)-A//2))
    answer = min(answer,C*A*(-(-B//2)-B//2))
    print(answer)
    return

if __name__ == '__main__':
    main()


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

int main(){

  int64_t N,D;
  cin >> N >> D;

  vector<int64_t> X(N);
  vector<int64_t> Y(N);
  
  for(int i=0;i<N;i++)
    cin >> X[i] >> Y[i];

  int count=0;
  for(int i=0;i<N;i++)
    if( (X[i] * X[i] + Y[i] * Y[i]) <= (D * D))
      count++;

  cout << count << endl;

}


Measured memory_bytes: 6404
r, g, b, n = gets.split.map(&:to_i)
count = 0
0.upto(n) do |i|
  0.upto(n) do |j|
    break if r * i + g * j > n
    count += 1 if ((n - r * i - g * j) % b).zero?
  end
end
puts count


Measured memory_bytes: 3836
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int M = scn.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = scn.nextLong();
		}
		Card[] C = new Card[M];
		for (int i = 0; i < M; i++) {
			int B = scn.nextInt();
			long ci = scn.nextLong();
			C[i] = new Card(B, ci);
		}
		Arrays.sort(A);
		Arrays.sort(C);

		long[] buf = new long[N];
		int nowS = 0;
		for (int i = M - 1; i >= 0 && nowS < N; i--) {
			Card c = C[i];
			Arrays.fill(buf, nowS, Math.min(nowS + c.num, N), c.C);
			nowS += c.num;
		}
		Arrays.sort(buf);
		long ans = 0;
		int a = N - 1, b = N - 1;
		for (int i = 0; i < N; i++) {
			if (A[a] > buf[b]) {
				ans += A[a];
				a--;
			} else {
				ans += buf[b];
				b--;
			}
		}
		System.out.println(ans);
	}
}

class Card implements Comparable<Card> {
	int num;
	long C;

	public Card(int b, long c) {
		this.num = b;
		this.C = c;
	}

	@Override
	public int compareTo(Card o) {
		if (this.C > o.C) {
			return 1;
		}
		if (this.C < o.C) {
			return -1;
		}
		return 0;
	}

}


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

int main(){
  int x, y;
  cin >> x >> y;
  for(int i = 0; i <= x; ++i){
    if(2 * i + 4 * (x - i) == y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3580
{-# LANGUAGE BangPatterns #-}

import Control.Applicative ((<$>))
import Data.Maybe (fromJust)
import Data.Vector.Unboxed (Vector, (!), unsafeFreeze, unsafeThaw, fromList, toList)
import Data.Vector.Unboxed.Mutable (IOVector, unsafeRead, unsafeSwap)
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main
    =   getLine
    >>  fromList . map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    >>= unsafeThaw
    >>= partition
    >>= forAnswer
    >>= putStrLn


partition :: IOVector Int -> IO (Int, Vector Int)
partition !inputs = do
    pivot   <- unsafeRead inputs (MV.length inputs - 1)
    pos     <- checkAndSwap inputs pivot (-1) 0 (MV.length inputs - 1)
    inputs' <- unsafeFreeze inputs
    return (pos, inputs')


checkAndSwap :: IOVector Int -> Int -> Int -> Int -> Int -> IO Int
checkAndSwap !inputs !pivot !i !j !end
    | j == end  = do
        unsafeSwap inputs (i + 1) end
        return (i + 1)

    | otherwise = do
        v <- unsafeRead inputs j
        case v <= pivot of
            True -> do
                unsafeSwap inputs (i + 1) j
                checkAndSwap inputs pivot (i + 1) (j + 1) end

            False -> do
                checkAndSwap inputs pivot i (j + 1) end

forAnswer :: (Int, Vector Int) -> IO String
forAnswer (i, xs) = return $ before ++ mid ++ after
  where
    before = unwords . map show . toList $ V.take i xs
    after  = unwords . map show . toList $ V.drop (i + 1) xs
    mid    = " [" ++ show (xs ! i) ++ "] "


Measured memory_bytes: 8636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

ll N,M;
VL A;
ll sum=0;
ll vot=0;
int main(){
    cin>>N>>M;
    A=VL (N);
    rep(i,0,N){
        cin>>A[i];
        sum+=A[i];
    }
    rep(i,0,N){
      	if(sum%(4*M)==0){if(A[i]>=(sum)/(4*M))vot++;}
    	else{if(A[i]>(sum)/(4*M))vot++;}
    }
    if(vot>=M)cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 256