akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    vector <int> a(n), b(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &b[i]);
    }
    ll res = 0;
    vector <int> ind_a(n), ind_b(n);
    for (int i = 0; i < n; i++) ind_a[i] = i;
    for (int i = 0; i < n; i++) ind_b[i] = i;
    /*
    for (int bit = 0; bit < 28; bit++)
    {
        for (int x = 0; x <= 100; x++)
        {
            for (int y = 0; y <= 100; y++)
            {
                int a = x & ((1 << (bit + 1)) - 1);
                int b = y & ((1 << (bit + 1)) - 1);
                int l = (((x + y) >> bit) & 1);
                int r = ((1 << bit) <= a + b && a + b < (1 << (bit + 1))) || (a + b >= (1 << (bit + 1)) + (1 << bit));
                if (l != r)
                {
                    cout << a << ' ' << b << ' ' << bit << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
    */
    for (int bit = 0; bit <= 28; bit++)
    {
        vector <int> x, y;
        for (int i = 0; i < n; i++)
        {
            if ((a[ind_a[i]] >> bit) & 1)
            {
                x.push_back(ind_a[i]);
            }
            if (!((b[ind_b[i]] >> bit) & 1))
            {
                y.push_back(ind_b[i]);
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (!((a[ind_a[i]] >> bit) & 1))
            {
                x.push_back(ind_a[i]);
            }
            if ((b[ind_b[i]] >> bit) & 1)
            {
                y.push_back(ind_b[i]);
            }
        }
        ind_a = x;
        ind_b = y;
        for (int i = 0; i < n; i++)
        {
            x[i] = a[ind_a[i]] & ((1 << (bit + 1)) - 1);
            y[i] = b[ind_b[i]] & ((1 << (bit + 1)) - 1);
        }
        int j = -1;
        int k = -1;
        int t = -1;
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            while (j + 1 < n && y[j + 1] + x[i] < (1 << bit))
            {
                j++;
            }
            while (k + 1 < n && y[k + 1] + x[i] < (1 << (bit + 1)))
            {
                k++;
            }
            while (t + 1 < n && y[t + 1] + x[i] < (1 << bit) + (1 << (bit + 1)))
            {
                t++;
            }
            ans ^= (n - 1 - t) & 1;
            ans ^= (k - j) & 1;
        }
        if (ans) res += (1 << bit);
    }
    printf("%lld\n", res);
}


Measured memory_bytes: 6816
#include <stdio.h>
#include <iostream>
using namespace std;

const int MAX = 111;
const int INF =  1e5+10;
int a[2][MAX], n, tmp, mmax;
int max(int a, int b) {
	return a > b ? a : b;
}
int main() {
	while (cin >> n) {
		cin >> a[0][0];
		for (int i = 1; i < n; ++i) {
			cin >> tmp;
			a[0][i] = a[0][i-1] + tmp;
		}
		for (int i = 0; i < n; ++i) {
			cin >> a[1][i];
		}
		for (int i = n-2; i >= 0; --i) {
			a[1][i] += a[1][i+1];
		}
		mmax = -INF;
		for (int i = 0; i < n; ++i) {
			mmax = max(a[0][i]+a[1][i], mmax);
		}
		cout << mmax << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  string s;
  int a=0;
  int b=0;
  
  cin>>s;
  
  for(int i=0;i<3;i++)
  {
    if(s[i]=='A')
    {
      a=1;
    }
    if(s[i]=='B')
    {
      b=1;
    }
  }
  
  if(a==1&&b==1)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }

  return 0;
}

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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i, s.size()){
        s[i]=s[i]+n;
        if(s[i]>'Z'){
            s[i] = s[i]-26;
        }
    }
    cout << s<< endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll M=1e9+7;
ll fac[100005];
ll ifac[100005];
ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(void){
    // Your code here!
    ll N,K;
    cin>>N>>K;
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<100000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    rep(0,i,K){
        cout<<((comb(K-1,i)%M)*(comb(N-K+1,i+1)%M))%M<<endl;
    }
}

Measured memory_bytes: 1792
a,b,c,x,y=map(int,input().split())
P=[]
for i in range(2*(max(x,y))+1):
  I=int(i/2)
  p=a*(max(0,x-I))+b*(max(0,y-I))+c*i
  P.append(p)
print(min(P))

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

int n;
string s;
int cnt[26];
string a="abcdefghijklmnopqrstuvwxyz";

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

	cin>>n;
	REP(i,n) {
		int tmp[26]={0};
		cin>>s;
		REP(i,s.size()) {
			tmp[s[i]-'a']++;
		}
		if(i==0) {
			REP(i,26) cnt[i]=tmp[i];
		}
		else {
			REP(i,26) cnt[i]=min(tmp[i],cnt[i]);
		}
	}
	REP(i,26) {
		REP(j,cnt[i]) cout<<a[i]<<flush;
	}
	cout<<endl;

	return 0;
}


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

int main(){
int H,W;

cin>>H>>W;
char S[H][W];
int A[H][W];
for(int i=0;i<H;i++){
  for(int j=0;j<W;j++){
cin>>S[i][j];
  }
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(S[i][j]=='.'){
A[i][j]=1;
continue;
}
for(int k=0;k<4;k++){
int ni=i+dx[k];
int nj=j+dy[k];
  if(H<=ni||W<=nj||ni<0||nj<0){
  continue;
  }
if(S[ni][nj]=='#'){
A[i][j]=1;
}

}

}
}
int ans=0;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){  
ans=ans+A[i][j];    

}
}
if(ans==H*W){
cout<<"Yes"<<endl;
} else{
cout<<"No"<<endl;
} 
}
  



Measured memory_bytes: 3656
#include <stdio.h>

int main() {
  int A, B;
  int cnt = 0;
  int i;
  
  scanf("%d %d", &A, &B);
  for(i = A; i <= B; i++) {
    int tmpl1 = i / 10000;
    int tmpr1 = i % 10;
    int tmpl2 = (i / 1000) % 10;
    int tmpr2 = (i / 10) % 10;
    
    if(tmpl1 == tmpr1 && tmpl2 == tmpr2) cnt++;
  }
  
  printf("%d\n", cnt);
  
  return 0;
}
    

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int x,n,t,time1;
  
  scanf("%d%d%d",&n,&x,&t);
  
  time1 = n/x;
  
  if(n%x>0)
    time1++;
  
  printf("%d", time1*t);

  return 0;
}

Measured memory_bytes: 1724
N,M = map(int, input().split())
PY = [[0] * 2 for i in range(M)]

for i in range(M):
    p,y = map(int,input().split())
    PY[i][0] = p
    PY[i][1] = y

indices = list(range(M))
sorted_indices = sorted(indices, key=lambda i: PY[i])
PY.sort()

def calc(x):
    n = len(str(x))
    res = ""
    if n < 6:
        for i in range(6-n):
            res += "0"
    res += str(x)
    return res

before = 0
num = 1
ans = [0]*M
for i in range(M):
    if before != PY[i][0]:
        num = 1
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]
    else:
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]

for i in range(M):
    print(ans[i])

Measured memory_bytes: 33076
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

answer = 0
N = ir()
honest = [[] for _ in range(N+1)]
liar = [[] for _ in range(N+1)]
# bit全探索
for i in range(N):
    a = ir()
    for _ in range(a):
        x, y = lr()
        if y == 1:
            honest[i].append(x-1)
        else:
            liar[i].append(x-1)

for bit in range(1<<N):
    bl = True
    h = []
    for i in range(N):
        if (bit >> i) & 1:
            h.append(i)
    s = set(h)
    for person in h:
        for x in honest[person]:
            if x not in s:
                bl = False
                break
        for y in liar[person]:
            if y in s:
                bl = False
                break
        if not bl:
            break
    if bl:
        answer = max(answer, len(s))

print(answer)


Measured memory_bytes: 47084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FASTIO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define ll long long int
#define F first
#define S second
#define pll pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vpii vector<pair<int,int> >
#define vvpii vector<vpii >
#define vpll vector<pair<ll,ll> >
#define vvpll vector<vpll >
#define pb push_back
#define MOD 1000000007
#define brk cout<<"\n"

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

struct compare {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F));
		else return (a.F < b.F);
	}
};

void add_self(ll &a, ll b) {
	a += b;
	if (a >= MOD)a -= MOD;
}

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	FASTIO;
	string k; cin >> k;
	ll len = k.length(), d; cin >> d;
	vvl dp(d, vl(2));
	dp[0][0] = 1;
	for (ll where = 0; where < len; where++) {

		// cout << k[where] << endl;
		// for (ll i = 0; i < d; i++) {
		// 	cout << dp[i][0] << "," << dp[i][1] << " ";
		// }
		// cout << endl;
		vvl temp(d, vl(2));
		for (ll sum = 0; sum < d; sum++) {
			for (ll j : {0, 1}) {
				for (ll digit = 0; digit < 10; digit++) {
					if (digit > k[where] - '0' && !j) {
						break;
					}
					add_self(temp[(sum + digit) % d][j || (digit < k[where] - '0')], dp[sum][j]);
				}
			}
		}
		dp = temp;

		// for (ll i = 0; i < d; i++) {
		// 	cout << dp[i][0] << "," << dp[i][1] << " ";
		// }
		// cout << endl << endl;

	}

	ll ans = (dp[0][0] + dp[0][1]) % MOD;
	ans--;
	if (ans == -1) ans = MOD - 1;
	cout << ans; brk;

}

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

int ans;
//recursive function
void DFS(vector<int>A,int n,int m,int q,vector<int>a,vector<int>b,vector<int>c,vector<int>d){
    // end condition
    if(A.size()==n+1){
        // calc score
        int now = 0;
        for(int i=0; i<q; i++){
            if(A[b[i]]-A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans,now);
        return;
    }

    // main procedure
    A.push_back(A.back());
    while(A.back() <= m){
        DFS(A,n,m,q,a,b,c,d);
        A.back()++;
    }
}

int main(){
    int n,m,q;
    cin >> n >> m >> q;
    vector<int> a(q);
    vector<int> b(q);
    vector<int> c(q);
    vector<int> d(q);
    for(int i=0; i<q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    // full search
    DFS(vector<int>(1,1),n,m,q,a,b,c,d);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
//#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
typedef long long ll;

signed main()
{
    string s;
    cin>>s;
    int f=0;
    if(s=="KIHBR")f=1;
    if(s=="AKIHBR")f=1;
    if(s=="AKIHABR")f=1;
    if(s=="AKIHBAR")f=1;
    if(s=="AKIHBRA")f=1;
    if(s=="KIHABR")f=1;
    if(s=="KIHABAR")f=1;
    if(s=="KIHABARA")f=1;
    if(s=="KIHBAR")f=1;
    if(s=="KIHBARA")f=1;
    if(s=="KIHBRA")f=1;
    if(s=="AKIHABAR")f=1;
    if(s=="AKIHABRA")f=1;
    if(s=="KIHABARA")f=1;
    if(s=="AKIHABARA")f=1;
    if(f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int main()
{
    int N;
    std::cin >> N;

    std::vector<int> A(N);
    for (int i=0; i<N; ++i) {
        std::cin >> A[i];
    }
    std::vector<int> B(N);
    for (int i=0; i<N; ++i) {
        std::cin >> B[i];
    }
    std::vector<int> C(N-1);
    for (int i=0; i<N-1; ++i) {
        std::cin >> C[i];
    }
    int sum = 0;
    int preva = -2;
    for (int i=0; i<N; ++i) {
        int ai = A[i]-1;
        sum += B[ai];
        if (ai == preva + 1) {
            sum += C[preva];
        }
        preva = ai;
    }
    std::cout << sum << std::endl;
    return 0;
}

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

int main() {
  int n,m;
  cin >> n;
  int a[100001],b[50001];
  for(int i=0;i<n;i++) cin >> a[i];
  cin >> m;
  for(int i=0;i<m;i++) cin >> b[i];
  sort(b,b+m);
  
  int ima=0,ans = 0;
  for(int i=0;i<m;i++){
    while(a[ima] < b[i]) ima++;
    if(a[ima] == b[i]) ans++;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 1760
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <limits>
#include <iomanip>
#include <stdlib.h>
#include <stack>



using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define ll  long long int
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define f first
#define mp make_pair
#define mod 1000000007
#define s second
#define pb push_back
#define MOD 1000000007

/*
 * Author : Avish Cheetaram
 * Date: 26/3/2020
 * I think it is possible for ordinary people to choose to be extraordinary ~ Elon Musk
*/


int main()
{
    ios_base::sync_with_stdio(0);

        int a , b , c , d , e , k;

        cin >> a >> b >> c >> d >> e >> k;

        if(e - a <= k){
            cout << "Yay!";
        }else{
            cout << ":(";
        }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    ll n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n-1;i++){
        ans+=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/**
    In the name of Allah, the Most Gracious, the Most Merciful.
**/

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

typedef long long ll;

int matrix[11][11];
int cell[205][205];
int n, m;

int main() {
    #ifdef _OFFLINE_
        freopen("in.txt", "r", stdin);
    #endif /// _OFFLINE_

    cin >> n >> m;
    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            cin >> matrix[i][j];
        }
    }
    for(int k=0; k<10; k++) {
        for(int i=0; i<10; i++) {
            for(int j=0; j<10; j++) {
                if( matrix[i][j] > matrix[i][k] + matrix[k][j]) {
                    matrix[i][j] = matrix[i][k] + matrix[k][j];
                }
            }
        }
    }
    int ans = 0;
    for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
            cin >> cell[i][j];
            if( cell[i][j] != abs(1)) {
                ans += matrix[cell[i][j]][1];
            }
        }
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;
const long long INF = 1LL<<60; // 仮想的な無限大の値
vector<bool> seen;

Graph G;

int solve(ll a,ll b,ll c){

    for(int i=0;i < 1000;i++){

        if(a & 1) return i;
        if(b & 1) return i;
        if(c & 1) return i;

        ll ta,tb,tc;
        ta = (b + c)/2;
        tb = (a + c)/2;
        tc = (a + b)/2;

        a = ta;
        b = tb;
        c = tc;

    }
    return -1;
}


int main() {

    //累積和
    //区間kで長さを与えた時の累積わの最大値
    int n,k;
    

    while(cin >> n >> k){
        if(n ==0) break;
        vector<ll> a(n);
        for(int i=0;i < n;i++) cin >> a[i];

        //累積和作成
        vector<int> s(n+1,0);
        for(int i=0;i < n;i++) s[i + 1] = s[i] + a[i];

        ll res =-INF;
        ll val;

        for(int i=0;i + k <= n;i++ ){
            val = s[i + k] - s[i];
            if(res < val) res = val;
        }
        cout << res << endl;


    }
    


    return 0;

}


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

using namespace std;

int main() {
    
    string s;
    cin>>s;
    
    int c=0,mx=0;
    for(int i=0;i<3;++i)
    {
        if(s[i]=='R')
        {
            c++;
            if(i==2)
            {
                mx=max(mx,c);
            }
        }
        else
        {
            mx=max(mx,c);
            c=0;
        }
    }
    
    cout<<mx<<endl;
    
}

Measured memory_bytes: 3620
#include<iostream>
#include <string>
#include <regex>

using namespace std;

int main()
{
	string buf;

	// cin >> buf;

	cin >> buf;

	regex re("[aiueo]");

	if (regex_match(buf, re)){
		cout << "vowel ";
	}
	else
	{
		cout << "consonant";
	}
	
	// system("pause");

	return 0;
}



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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
    llin(n);
    llin(k);
    llin(q);
    vllin(a,q);
    vll b(n,0);
    FOR(i,0,q-1){
        b[a[i]-1]++;
    }
    FOR(i,0,n-1){
        if(b[i]>q-k) sal("Yes")
        else sal("No")
    }
}


Measured memory_bytes: 2176
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        dic = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
        print(dic[S])


# Run main
if __name__ == '__main__':
    AtCoder().main()

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

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int m = sc.NextInt();

        char[,] a = new char[n, n];
        for (int i = 0; i < n; i++)
        {
            string s = sc.Next();
            for (int j = 0; j < n; j++)
            {
                a[i, j] = s[j];
            }
        }

        char[,] b = new char[m, m];
        for (int i = 0; i < m; i++)
        {
            string s = sc.Next();
            for (int j = 0; j < m; j++)
            {
                b[i, j] = s[j];
            }
        }

        bool answer = false;
        for (int i = 0; i <= n - m; i++)
        {
            for (int j = 0; j <= n - m; j++)
            {
                bool tmpAnswer = true;
                for (int k = 0; k < m; k++)
                {
                    for (int l = 0; l < m; l++)
                    {
                        if (a[k + i, l + j] != b[k, l])
                        {
                            tmpAnswer = false;
                            break;
                        }
                    }
                }
                if (tmpAnswer)
                {
                    answer = true;
                    break;
                }
            }
        }

        Console.WriteLine(answer ? "Yes" : "No");
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

C = Counter(A)
for k in C.keys():
    C[k] -= 1

cnt = ceil(sum(C.values()), 2)
ans = N - cnt * 2
print(ans)


Measured memory_bytes: 18628
S = input()
T = input()

N = len(T)
ans = N

for i in range(len(S) - N + 1):
    s = S[i:i+N]
    count = 0
    for j in range(N):
        if s[j] == T[j]:
            pass
        else:
            count += 1
    if ans > count:
        ans = count

print(ans)

Measured memory_bytes: 9052
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

unordered_map<int, vector<int>> edges;
int indeg[100010], f[100010];
int n, m, x, y;

inline void work() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        edges[x].push_back(y);
        indeg[y]++;
    }

    queue<int> q;
    for (int i = 1; i <= n; ++i) {
        if (indeg[i] == 0) {
            q.push(i);
        }
    }

    int ans = 0;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (edges.count(u)) {
            for (int v : edges[u]) {
                ans = max(ans, f[v] = max(f[v], f[u] + 1));
                if (--indeg[v] == 0) {
                    q.push(v);
                }
            }
        }
    }
    cout << ans << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 9892
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int N, eSum[300005], wSum[300005], result = 987654321;

int main()
{
    scanf("%d ", &N);
    for(int i = 1; i <= N; i++)
    {
        char c;
        scanf("%c", &c);
        eSum[i] = eSum[i - 1];
        wSum[i] = wSum[i - 1];
        if(c == 'E')
        {
            eSum[i]++;
        }
        if(c == 'W')
        {
            wSum[i]++;
        }
    }
    for(int i = 1; i <= N; i++)
    {
        result = min(result, eSum[N] - eSum[i] + wSum[i - 1] - wSum[0]);
    }
    printf("%d", result);
}

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

using namespace std;

int main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	for (int i = 0; i < 2 * n; ++i)
		cout << (i & 1 ? t[i >> 1] : s[i >> 1]);
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

n, w = map(int, readline().split())
wv = [list(map(int, readline().split())) for i in range(n)]
dp = np.full(n * 1000 + 1, w + 1, dtype=int)
dp[0] = 0
for x, y in wv:
    dp[y:] = np.minimum(dp[y:], dp[:-y] + x)
print(np.max(np.where(dp <= w)))


Measured memory_bytes: 14840
S=input()
N=list(map(int, S))
DP=[[-1]*2 for _ in range(len(N)+1)]
DP[0][0]=0
for i in range(len(N)):
    for j in range(2):
        if DP[i][j] < 0:
            continue
        for k in range(10):
            ni=i+1
            nj=j
            if j==0:
                if k < N[i]:
                    nj=1
                elif k > N[i]:
                    continue
            DP[ni][nj]=max(DP[ni][nj],DP[i][j]+k)
print(max(DP[len(N)]))

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    // If n=1, then game is easily predetermined (odd -> player 1 wins)
    // If n>1, then player 1 can win by forcing all odd values to be even.
    //         If there are no odd values initiallly, then player 1 loses.

    int n;
    cin>>n;
    bool win = false;
    for (int i=0; i<n; i++) {
	int x;
	cin>>x;
	if (x%2==1) win=true;
    }

    cout<<(win ? "first\n" : "second\n");
    
    
    return 0;
}


Measured memory_bytes: 3504
import java.util.*;
public class Main {
	static Node[] list;
    public static void main(String[] args){
    	Scanner sc=new Scanner(System.in);
    	int n=sc.nextInt();
    	list =new Node[n];
    	
    	int num,ri,le;
    	for(int i=0;i<n;i++){
    		list[i]=new Node();
    	}
    	for(int i=0;i<n;i++){
    		num=sc.nextInt();
    		list[num].number=num;
    		le=sc.nextInt();
    		ri=sc.nextInt();
    		if(ri==-1){
    			list[num].right=null;
    		}else{
    			list[num].right=list[ri];
    			list[ri].pid=num;
    		}
    		if(le==-1){
    			list[num].left=null;
    		}else{
    			list[num].left=list[le];
    			list[le].pid=num;
    		}
    		
    	}
    	System.out.println("Preorder");
    	for(int i=0;i<n;i++){
    		if(list[i].pid==-1){
    			preorder(list[i]);
    		}
    	}
    	System.out.print("\n");
    	System.out.println("Inorder");
    	for(int i=0;i<n;i++){
    		if(list[i].pid==-1){
    			inorder(list[i]);
    		}
    	}
    	System.out.print("\n");
    	System.out.println("Postorder");
    	for(int i=0;i<n;i++){
    		if(list[i].pid==-1){
    			postorder(list[i]);
    		}
    	}
        System.out.println();
}
    static void preorder(Node node){
    	System.out.print(" ");
    	System.out.print(node.number);
    	if(node.left!=null){
    		preorder(node.left);
    	}
    	if(node.right!=null){
    		preorder(node.right);
    	}
    }
    static void inorder(Node node){
    	if(node.left!=null){
    		inorder(node.left);
    	}
    	System.out.print(" ");
    	System.out.print(node.number);
    	if(node.right!=null){
    		inorder(node.right);
        }
    }
    static void postorder(Node node){
    	if(node.left!=null){
    		postorder(node.left);
    	}
    	if(node.right!=null){
    		postorder(node.right);
        }
    	System.out.print(" ");
    	System.out.print(node.number);
    }	
}
class Node{
	int number;
	int pid;
	Node left;
	Node right;
	Node(){
		pid=-1;
		number=0;
		left=null;
		right=null;
	}
}



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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define _ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define sll(x) scanf("%I64d",&x)
#define sd(x)  scanf("%d",&x)
#define pll(x) printf("%I64d",x)
#define pd(x)  printf("%d",x)

#define clr(x) memset(x,0,sizeof x)
#define sf .second.first
#define ss .second.second
#define mid    ((l+r)>>1)
#define Pi acos(-1)
#define EPS 1e-12
#define MOD  1000000007
#define MOD1 1000000009
#define INF  1000000000

#define N 100005

int n,k,a[N][3],dp[N][3];


int main()
{
    memset(dp,0,sizeof dp);
    cin >>n;
    for(int i=0; i<n; i++)
        for(int j=0; j<3; j++)

            cin>>a[i][j];


    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    //cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl;
    for(int i=1; i<n; i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
        //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
    }


    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}


Measured memory_bytes: 2560
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

ll dp[45][2];

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(41);
    rep(i,41) {
        rep(j,n) {
            cnt[i] += a[j]>>i&1;
        }
    }
    
    rep(i,42)rep(j,2) dp[i][j] = -1;
    dp[41][0] = 0;

    ll t = pow(2,40);
    for (int i = 40; i >= 0; i--) {
        if (k>>i&1) {
            dp[i][0] = dp[i+1][0] + t*(n-cnt[i]);
            dp[i][1] = dp[i+1][0] + t*cnt[i];
        }
        else {
            dp[i][0] = dp[i+1][0] + t*cnt[i];
        }
        if (dp[i+1][1] != -1) {
            int d = max(cnt[i], n-cnt[i]);
            dp[i][1] = max(dp[i][1], dp[i+1][1] + t*d);
        }
        t /= 2;
    }
    ll ans = max(dp[0][0], dp[0][1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4032
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
  //indexのループを検出できますか、という問題
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i], A[i]--;
  vector<int> seen(n); seen[0] = true;
  //ループを検出するか目的地に辿り着くまでの回数を数える
  int cnt = 0, cur = 0;
  while(1){
      int nx = A[cur]; //次の目的地
      if(seen[nx])break;//2週目に入った
      seen[nx] = true;
      cnt++;
      if(nx==1)break; //目的地に到達
      cur = nx;
  }
  if(seen[1])cout << cnt << ln;
  else cout << -1 << ln;
}



Measured memory_bytes: 4540
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  string s;
  cin >> n >> s;
  vector<int> e(n + 1), w(n + 1);
  rep(i, 1, n) {
    e[i] = e[i - 1];
    if (s[i] == 'E')
      e[i]++;
  }

  repr(i, 0, n) {
    w[i] = w[i + 1];
    if (s[i] == 'W')
      w[i]++;
  }

  int ans = 1e9 + 7;
  rep(i, 0, n) { chmin(ans, (e[n - 1] - e[i]) + (w[0] - w[i])); }

  cout << ans << endl;
}


Measured memory_bytes: 2964
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2709
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<array>

using namespace std;

int log(int base, int n, int count)
{
    return n == 0 ? count : log(base, (n - 1) / base, count + 1);
}

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

  //  map<int, int> toDR{};
    vector<int> toDR(N, -1);


    vector<int> d(M);
    for(int i = 0; i < M; i++)
    {
        cin >> d[i];
//        toDR.insert(make_pair(d[i], i));
        toDR[d[i] - 1] = i;
    }

    vector< vector<int> > v(N, vector<int>(K));
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < K; j++)
        {
            cin >> v[i][j];
        }
    }

    //???????????????????????????????????????
    //?????§??????????????? ?????§????????????

    queue<int> que{};

    //?????????????????¨??????????????¨?±??????????
    //?????????
    que.push((1 << M) - 1);

    array<int, 1 << 16 > come;
    come.fill(-1);
    come[que.front()] = 0;

//    int loopCount = 0;
    while(que.front() != 0)
    {

        int dr = que.front();

        for(int i = 0; i < K; i++)
        {
            //loopCount++;

            int nextState = 0;
            for(int j = 0; j < M; j++)
            {
                if( dr & (1 << j) )
                {
                    if(toDR[v[d[j] - 1][i] - 1] == -1)continue;

                    //v[d[j]][i]????§????
                    nextState |= (1 << (toDR[v[d[j] - 1][i] - 1]) );
                }

            }

            if(nextState == 0)
            {
                //?????????

                cout << come[dr] + 1 << endl;
                return 0;
            }

            //que?????????
            if(come[nextState] == -1)
            {
                que.push(nextState);
                come[nextState] = come[dr] + 1;
            }
        }
        que.pop();
    }

    return 0;
}

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


int main(){
    ll n;
    cin >> n;
    ll d[n][2];
    for(ll i=0;i<n;i++){
        cin >> d[i][0] >> d[i][1];
    }
    bool flag=false;
    for(ll i=0;i<n-2;i++){
        if(d[i][0]==d[i][1]&&d[i+1][0]==d[i+1][1]&&d[i+2][0]==d[i+2][1]) flag=true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}  


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

vector< vector< int > > to(100005);
vector<int> group(100005, 0);

void DFS( int v, int g ) {
  group[v] = g;
  for ( auto nv: to[v] ) {
    if (group[nv] != 0 ) continue;
    DFS(nv,g);
  }
}

int main() {
  int N,M;
  cin >> N >> M;
  REP(i,M) {
    int x,y,z;
    cin >> x >> y >> z;
    x--; y--;
    to[x].emplace_back(y);
    to[y].emplace_back(x);
  }
  int grp = 1;
  REP(i,N) {
    if (group[i] != 0 ) continue;
    DFS( i, grp );
    grp++;
  }
  
  cout << grp-1 << endl;
  
}



Measured memory_bytes: 9216
/*
 ------------------------------------------------------Read question very carefully------------------------------------------------------
 
                       In every question first approach must be basic, atleast give 15 mins for try to solve in basic approach
*/
 #include<iostream>
 #include<cstring>
 #include<string>
 #include<vector>
 #include<utility>
 #include<stdlib.h>
 #include<limits.h>
 #include<cmath>
 #include<set>
 #include<initializer_list>
 #include<unordered_set>
 #include<unordered_map>
 #include<map>
 #include<iomanip>
 #include<algorithm>
 #include<queue>
 #include<stack>
#include <cstdint>
  
 #define sze 1000005
 #define ld long double
 //#define ll unsigned long long
 #define ll long long
 #define endl "\n"
 #define pb push_back
 #define mkp make_pair
 #define mod 1000000007
 #define ff first
 #define ss second
 #define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
 #define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
 #define all(c) (c).begin(),(c).end()
 #define pi                   pair<int,int>
 #define pll                  pair<ll,ll>
 #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
 using namespace std;

//cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
 //const ll inf=1ll<<60;
 //const double pi = 3.14159265358979323846;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res%mod * a%mod)%mod;
        a = (a%mod * a%mod)%mod;
        b >>= 1;
    }
    return res;
}
const ll int  N=2e5+5;
/*vector<ll> adj[N];
vector<ll> vis(N,0);
*/
//int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll n,k;
ll arr[N];
ll helper(ll x,ll curr)
{
    ll ans=0;
    F(i,1,n)
    {
        if(!curr)
        {
            ans++;
            curr^=1;
        }
        else
        {
            if(arr[i]<=x)
            {
                ans++;
                curr^=1;
            }
        }
    }
    return ans>=k;
}

 int main()
 {
     IOS;
     ll n,k; cin>>n>>k;
     ll arr[n+1];
     F(i,0,n-1)
     {
         cin>>arr[i];
     }
     sort(arr,arr+n);
     ll sum=0;
     F(i,0,k-1)
     {
         sum += arr[i];
     }
     cout<<sum<<endl;
 }



Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

class DisjointSet {
public: vector<int> rank, p;
		DisjointSet() {}
		DisjointSet(int size) {
			rank.resize(size, 0);
			p.resize(size, 0);
			for (int i = 0; i < size; i++) makeSet(i);
		}

		void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}

		bool same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			}
			else {
				p[x] = y;
				if (rank[x] == rank[y]) rank[y]++;
			}
		}

		int findSet(int x) {
			if (x != p[x]) {
				p[x] = findSet(p[x]);
			}
			return p[x];
		}
};

int main(){
	int n, q, t, a, b;
	cin >> n >> q;
	DisjointSet ds = DisjointSet(n);
	for (int i = 0; i < q; i++) {
		cin >> t >> a >> b;
		if (t == 0) ds.unite(a, b);
		else if (t == 1) {
			if (ds.same(a, b)) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
	return 0;
}


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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		double x[n],y[n];
		double d;
		cin>>d;
		int ct = 0;
		for(int i=0;i<n;++i)
		{
			cin>>x[i]>>y[i];
			double temp = sqrtl(x[i]*x[i]+y[i]*y[i]);
			if(temp<=d)
			++ct;
		}
		cout<<ct<<"\n";		
    }
    return 0;
}


Measured memory_bytes: 6884
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

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

void dfs(vector<vector<int>> &G, int v, vector<bool> &visit) {
  visit[v] = true;
  int N = G.size();
  for(int j = 0; j < N; j++) {
    if (j != v && !visit[j] && G[v][j]) {
      dfs(G, j, visit);
    }
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G_ori(N, vector<int>(N));
  vector<pair<int,int>> E;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G_ori[a][b] = G_ori[b][a] = 1;
    E.push_back(mp(a, b));
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    vector<vector<int>> G = G_ori;
    vector<bool> visit(N);
    G[E[i].first][E[i].second] = G[E[i].second][E[i].first] = 0;
    
    dfs(G, 0, visit);
    bool flag = true;
    for(int j = 0; j < N; j++) {
      if (!visit[j]) flag = false;
    }
    if (!flag) {
      ans++;
    }

  }
  cout << ans << endl;

  return 0;
}

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

#define INF 1000000000000000000

typedef long long ll;

int main()
{
   int N;
   cin>>N;
   ll y = 0;
   ll a[N];
   for(int i=0; i<N; i++)
   {
      cin>>a[i];
      y += a[i];
   }
   ll mn = INF;
   ll x = 0;
   for(int i=0; i<N-1; i++)
   {
      x += a[i];
      y -= a[i];
      mn = min(mn, abs(x-y));
   }
   cout<<mn<<endl;
   return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main(){
    ll a, b, c, x, y;   cin >> a >> b >> c >> x >> y;
    ll res = LINF;

    REP(i, max(x, y)+1){
        res = min(res, max(x-i, 0LL)*a+max(y-i, 0LL)*b + 2*i*c);
    }
    cout << res << endl;

}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    string s; int K; cin >> s >> K;
    set<string> se;

    for (int i = 0; i < s.size(); i++) {
        string tmp;
        for (int j = i; j < s.size() && j < i+K; j++) {
            tmp += s[j];
            se.insert(tmp);
        }
    }

    auto it = se.begin();
    for (int i = 0; i < K-1; i++) it++;
    
    string ans = *it;
    cout << ans << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 4760
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
ll min(ll x,ll y){return x<y?x:y;}
int main(void){
	ll Q,H,S,D,N,ans=0,q,h,s,d;
	scanf("%lld%lld%lld%lld%lld",&Q,&H,&S,&D,&N);
	H = min(H,2*Q);
	S = min(S,2*H);
	if(2*S<D)ans = N*S;
	else ans = N/2*D+S*(N%2);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	long long a[300][300];
	int n;
	int x = 0;
	int z = 0;
	long long s = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			scanf("%lld", &a[i][j]);
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = i+1; j < n; j++){
			z = 0;
			for (int k = 0; k < n; k++){
				if (i != k&&j != k){
					if (a[i][k] + a[k][j] < a[i][j])x = -1;
					if (a[i][k] + a[k][j] == a[i][j])z = 1;
				}
			}
			if (z == 0)s = s + a[i][j];
		}
	}
	if(x==0)printf("%lld\n",s);
	else printf("-1\n");

	return 0;
}


Measured memory_bytes: 896
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

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

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    
    if (p == 2 || p == 5) {
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % p == 0) ans += i + 1;
        }
        cout << ans;
        return;
    }
    vector<int> pw(n + 1);
    pw[0] = 1;
    for (int i = 1; i <= n; i++) {
        pw[i] = pw[i - 1] * 10 % p;
    }

    vector<int> pref(n + 1);
    for (int i = 1; i <= n; i++) {
        pref[i] = pref[i - 1];
        pref[i] = (pref[i] + (s[i - 1] - '0') * pw[n - i] % p) % p;
    }

    int ans = 0;
    vector<int> a(p);
    for (int i = 0; i <= n; i++) {
        ans += a[pref[i]];
        a[pref[i]]++;
    }
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 3732