akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

struct Edge {
  int src, dst;
  Edge() { src = dst = -1; }
  Edge(int s, int d) : src(s), dst(d) {}
  Edge rev(void) const { return Edge(dst, src); }
};

inline
bool operator < (const Edge& a, const Edge& b)
{
  if (a.src != b.src) return a.src < b.src;
  return a.dst < b.dst;
}

inline
bool operator == (const Edge& a, const Edge& b)
{
  return a.dst == b.dst && a.src == b.src;
}

inline
bool operator != (const Edge& a, const Edge& b)
{
  return !(a == b);
}

inline
ostream& operator << (ostream& os, Edge e)
{
  os << make_pair(e.src, e.dst);
  return os;
}

const int N = 100 + 10;
vector<Edge> g[N];

map<Edge, lli> cap;

void add_edge(int src, int dst, lli c)
{
  Edge a(src, dst);
  Edge b = a.rev();
  g[a.src].push_back(a);
  g[b.src].push_back(b);
  cap[a] += c;
  return ;
}

lli max_flow(int src, int snk)
{
  lli sum = 0;
  while (true) {
    Edge path[N] = {Edge(), };
    set<int> vis({src});
    queue<int> q;
    for (q.push(src); q.size(); q.pop()) {
      each (e, g[q.front()]) {
        if (!vis.count(e.dst) && cap[e]) {
          q.push(e.dst);
          vis.insert(e.dst);
          path[e.dst] = e;
        }
      }
    }
    if (path[snk] == Edge()) {
      break;
    }
    lli mn = 1LL << 60;
    for (Edge e = path[snk]; e != Edge(); e = path[e.src]) {
      mn = min(mn, cap[e]);
    }
    for (Edge e = path[snk]; e != Edge(); e = path[e.src]) {
      cap[e] -= mn;
      cap[e.rev()] += mn;
    }
    sum += mn;
  }

  return sum;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    cap.clear();
    fill(g, g + N, vector<Edge>());

    vector<lli> a(n);
    each (i, a) cin >> i;

    const int src = N - 1;
    const int snk = N - 2;
    const lli inf = 1LL << 60;

    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if ((j + 1) % (i + 1) == 0) {
          add_edge(i, j, inf);
        }
      }
    }

    for (int i = 0; i < n; ++i) {
      if (0 <= a[i]) {
        add_edge(i, snk, a[i]);
      } else {
        add_edge(src, i, -a[i]);
      }
    }

    lli sum = 0;
    each (i, a) sum += (0 < i) * i;
    cout << sum - max_flow(src, snk) << endl;
  }

  return 0;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll mo=1000000007;
ll combi(ll N_, ll C_) {
    const int NUM_=400001;
    static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
    if (fact[0]==0) {
        inv[1]=fact[0]=factr[0]=1;
        for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
        for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
    }
    if(C_<0 || C_>N_) return 0;
    return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

int N;
int A[101010];
int num[101010];
vector<int> V;
void solve() {
    int i,j,k,l,r,x,y; string s;

    cin>>N;
    FOR(i,N+1) {
        cin>>A[i];
        num[A[i]]++;
    }
    FOR(i,N+1) if(num[A[i]]==2) V.push_back(i);
    int a=V[0];
    int b=V[1]-V[0]-1;
    int c=N-V[1];
    for(i=1;i<=N+1;i++) {
        if(i==1) {
            cout<<N<<endl;
            continue;
        }
        ll ret=0;
        // D=0
        ret += combi(N-1,i);
        // D=1
        ret += combi(a+c,i-1);
        ret += (combi(a+c+b,i-1)-combi(a+c,i-1))*2;

        // D=2
        ret += combi(N-1,i-2);

        cout<<(ret%mo+mo)%mo<<endl;

    }


}


int main(int argc,char** argv){
    string s;int i;
    if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
    FOR(i,argc-1) s+=argv[i+1],s+='\n';
    FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
    solve(); return 0;
}

Measured memory_bytes: 11392
/* DELAPAN.3gp */
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;

#ifdef DEBUG
	#define debug(...) printf(__VA_ARGS__)
	#define GetTime() fprintf(stderr,"Running time: %.3lf second\n",((double)clock())/CLOCKS_PER_SEC)
#else
	#define debug(...) 
	#define GetTime() 
#endif

//type definitions
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vint;

//abbreviations
#define A first
#define B second
#define MP make_pair
#define PB push_back

//macros
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n)-1; 0 <= i; --i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for (int i = (a); (b) <= i; --i)
#define FORIT(it,c) for (__typeof ((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define RESET(a,x) memset(a,x,sizeof(a))
#define EXIST(a,s) ((s).find(a) != (s).end())
#define MX(a,b) a = max((a),(b));
#define MN(a,b) a = min((a),(b));

inline void OPEN(const string &s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

/* -------------- end of DELAPAN.3gp's template -------------- */

ll n, k, x, y;
int main(){
	scanf("%lld%lld%lld%lld", &n, &k, &x, &y);
	ll ans = 0;
	FOR(i, 1, n) {
		if (i <= k) {
			ans += x;
		} else {
			ans += y;
		}
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
import sys
s = sys.stdin.readlines()

for e in s:
    input_l = list(map(int,e.split()))
    if input_l[0] == 0 and input_l[1] == 0:
        break
    else:
        input_l.sort()
        print(str(input_l[0]) + " " + str(input_l[1]))


Measured memory_bytes: 5872
N = int(input())
A = list(map(int, input().split()))

dp_g = A[1]
dp_k = A[0]
dp = [0, max(dp_g, dp_k)]

for i in range(2, N):
    if i % 2 == 1:
        dp_g = max(dp_k, dp_g) + A[i]
        dp_k += A[i - 1]
        dp.append(max(dp_g, dp_k))
    elif i % 2 == 0:
        dp.append(max(dp[i - 1], dp[i - 2] + A[i]))

print(dp[N - 1])

Measured memory_bytes: 31620
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	string s;
	cin>>s;
	int a=(s[0]-'0')*10+(s[1]-'0');
	int b=(s[2]-'0')*10+(s[3]-'0');
	bool yymm=(1<=b&&b<=12);
	bool mmyy=(1<=a&&a<=12);
	if(yymm){
		if(mmyy)puts("AMBIGUOUS");
		else puts("YYMM");
	}else{
		if(mmyy)puts("MMYY");
		else puts("NA");
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0)break;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    System.out.print("#");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 36440
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:i64 = read();
    let a:i64 = read();
    let ans = if n % 500 <= a {
        "Yes"
    } else {
        "No"
    };
    println!("{}",ans );
}

Measured memory_bytes: 4352
import sys
import collections
import itertools

N,M = map(int,input().split())
array_2 = []
for I in range(N):
    array_2.append(input().split())
for I in array_2:
    del I[0]

array_2 = itertools.chain.from_iterable(array_2)
array_2 = collections.Counter(array_2)
count = 0
for I in array_2:
    if array_2[I] == N: count += 1
print(count)    

Measured memory_bytes: 9396
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <sstream>

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

    std::vector<int64_t> prices(N);
    for (auto& price : prices) {
        std::cin >> price;
    }

    int64_t stock = 0;
    int64_t asset = 1000;

    if (prices.at(0) < prices.at(1)) {
        stock = asset / prices.at(0);
        asset = asset % prices.at(0);
    }

    for (int64_t i = 1; i < N-1; ++i) {
        int64_t temp_stock = 0;
        // buy
        if (prices.at(i-1) >= prices.at(i) && prices.at(i) < prices.at(i+1)) {
            temp_stock = asset / prices.at(i);
            if (temp_stock != 0) {
                stock += temp_stock;
                asset = asset % prices.at(i);
            }
        }
        // sell
        if (prices.at(i-1) <= prices.at(i) && prices.at(i) > prices.at(i+1)) {
            asset += stock * prices.at(i);
            stock = 0;
        }
    }

    if (prices.at(N-2) <= prices.at(N-1)) {
        asset += stock * prices.at(N-1);
        stock = 0;
    }

    std::cout << asset << std::endl;

    return 0;
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  
  cout << A.at(0) << B.at(0) << C.at(0) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3") 

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define test(t)		int t; cin >> t; while(t--)
#define f(i, a, b)	for(int (i) = (a); (i) < (b); ++(i))
#define all(a)		(a).begin(), (a).end()
#define endl 		"\n"
#define maxvec(vec)     *max_element(all(vec))
#define minvec(vec)     *min_element(all(vec))
#define maxarr(arr)     *max_element(arr, arr + n)
#define minarr(arr)     *min_element(arr, arr + n)
#define deb(x)		cout << #x << " is " << x << endl;
#define deb2(x,y)	cout << #x << " is " << x << " and " <<  #y << " is " << y << endl;
#define deba(arr)	cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)	cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast 		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007
#define PI		3.141592653589793238462643383279502884L

void solve()
{
    string s;
    cin >> s;
    if(int(s[0]) >= 65 && int(s[0]) <= 90)
        cout << 'A' << endl;
    else
        cout << 'a' << endl;
}

int main()
{
    fast;
    // test(t)
        solve();
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF INT_MAX/2

int N, M, CAP;

struct Comp {
	bool operator() (pair<int,int> a, pair<int,int> b) {
		return a.second > b.second;
	}
};

//map<int, ll> dist;
//set<int> done;

//int dist[6010][2010];
//bool done[6010][2010];

//vector<vector<int> > dist;
//vector<vector<bool> > done;



int solve()
{
	int idx = 0;
	map<string, int> m;

	vector<vector<int> > dist;
	vector<vector<bool> > done;

	vector<pair<int, int> > E[6010];
	set<int> gas;

	string src, dest;
	cin >> src >> dest;
	m[src] = 0; m[dest] = 1;
	idx = 2;

	rep(i, 0, 6010) E[i].clear();
	rep(i, 0, N)
	{
		string a, b;
		cin >> a >> b;
		if (m.find(a) == m.end()) m[a] = idx, idx++;
		if (m.find(b) == m.end()) m[b] = idx, idx++;
		int dd; cin >> dd;
		E[m[a]].push_back(make_pair(m[b], dd));
		E[m[b]].push_back(make_pair(m[a], dd));
	}

	gas.clear();
	rep(i, 0, M)
	{
		string s;
		cin >> s;
		if (m.find(s) == m.end()) m[s] = idx, idx++;
		gas.insert(m[s]);
	}

	//dist.resize(idx, vector<int>(CAP + 1, INF));
	//done.resize(idx, vector<bool>(CAP + 1, false));

	dist.resize(idx);
	done.resize(idx);
	rep(i, 0, idx) dist[i] = vector<int>(CAP + 1);
	rep(i, 0, idx) done[i] = vector<bool>(CAP + 1);

	rep(i, 0, idx) rep(j, 0, CAP + 1) dist[i][j] = INF;
	rep(i, 0, idx) rep(j, 0, CAP + 1) done[i][j] = false;

	/*rep(i, 0, 6010) rep(j, 0, 2010) dist[i][j] = INF;
	rep(i, 0, 6010) rep(j, 0, 2010) done[i][j] = false;*/

	priority_queue<pair<int, int>, vector<pair<int, int> >, Comp> que;

	//dist[CAP] = 0;
	dist[0][CAP] = 0;
	que.push(make_pair(CAP, 0));
	while (!que.empty())
	{
		auto q = que.top(); que.pop();

		int n = q.first / 10000;
		int c = q.first % 10000;

		if (n == 1)
		{
			return q.second;
		}

		/*if (done.find(q.first) != done.end()) continue;
		done.insert(q.first);*/

		if (done[n][c]) continue;
		done[n][c] = true;

		for (auto p : E[n])
		{
			if (c < p.second) continue;

			int nn = p.first;
			int nc = c - p.second;
			if (gas.find(nn) != gas.end()) nc = CAP;
			int nnn = nn * 10000 + nc;

			int ncost = q.second + p.second;
			/*if (dist.find(nnn) == dist.end()) dist[nnn] = INF;
			if (ncost < dist[nnn])
			{
				dist[nnn] = ncost;
				que.push(make_pair(nnn, ncost));
			}*/

			if (ncost < dist[nn][nc])
			{
				dist[nn][nc] = ncost;
				que.push(make_pair(nnn, ncost));
			}
		}
	}

	return -1;
}

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

	while (cin >> N >> M >> CAP)
	{
		if (N == 0) return 0;

		CAP *= 10;

		cout << solve() << endl;
	}
}

Measured memory_bytes: 52932
import collections as c
ip = lambda : map(int, input().split())

#################
N,Q = ip()
S = input()
l = [0]*N
for i in range(1,N):
    if S[i-1:i+1] == 'AC':
        l[i] = l[i-1] + 1
    else:
        l[i] = l[i-1]


for i in range(Q):
    ql,qr = ip()
    ql -= 1
    qr -= 1
    print(l[qr] - l[ql])

#d = {'A':'T','T':'A','C':'G','G':'C'}

Measured memory_bytes: 6412
#include <stdio.h>
#include <math.h>
#include <string.h>

int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}



/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}



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

    quick_sort(A,0,n-1);
    printf("%d\n",A[n-1]-A[0]);

    return 0;
}

Measured memory_bytes: 1680
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int color[9] = {};

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		color[min(8, a / 400)]++;
	}

	int n = 0;
	for (int i = 0; i < 8; i++)
		if (color[i] > 0)
			n++;

	if (n == 0 && color[8] > 0) {
		n++;
		color[8]--;
	}

	cout << min(8, n) << " " << n + color[8] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int a, b, c;
set<int> si;

int main(){
	bool f = 0;
	cin >> a >> b >> c;
	while (1){
		int now = c;
		now %= (a + b);
		if (now <= a){
			cout << c << endl;
			f = 1;
			break;
		}
		else{
			if (si.insert(now).second == false)break;
			c += 60;
		}
	}
	if (!f)cout << -1 << endl;
}

Measured memory_bytes: 1192
A,B,M = map(int, input().split())

la = list(map(int, input().split()))
lb = list(map(int, input().split()))

d = []
for i in range(M):
  d.append(list(map(int, input().split())))
           
for i in range(M):
  d[i] = la[(d[i][0]-1)] + lb[(d[i][1]-1)] - d[i][2]
  
o = min(la) + min(lb)
d.append(o)

print(min(d))

Measured memory_bytes: 38552
#include<stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}else if(a<b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
}


Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		b[i]=a[i];
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());

	if(a[0]==a[1])
	{
		for(int i=0;i<n;i++)
			cout << a[0] << endl;
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			if(b[i]==a[0])
				cout << a[1] << endl;
			else
				cout << a[0] << endl;
		}
	}



}


Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n-1];
    String[] str = in.readLine().split(" ");
    in.close();
    int[] boss = new int[n];
    for(int i=0; i<n-1; i++) {
      a[i] = Integer.parseInt(str[i]); 
      boss[a[i]-1]++;
    }
    PrintWriter pw = new PrintWriter(System.out);
    for(int i=0; i<n; i++) {
      pw.println(boss[i]);
    }
    pw.flush();
  }
}

Measured memory_bytes: 63268
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int K = sc.nextInt();
        
        for( int i = 0; i < K ; i++){
            System.out.print("ACL");
        }
        
    }
    
}


Measured memory_bytes: 26900
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Graph = vector<vector<int>>;

vector<ll> BFS(Graph G, ll V)
{                                  //引数はグラフ構造体G（2次元配列）と初期ノードV
    vector<ll> dist(G.size(), -1); //前頂点を-1（未訪問）に初期化
    queue<ll> que;

    dist[V] = 0; //頂点0を初期ノードとして、初期化
    que.push(V);

    //BFS開始

    while (!que.empty())
    {
        int v = que.front(); //頂点vを訪問（最初は頂点0）
        que.pop();

        for (int nv : G[v])
        { //頂点vから辿れる全頂点を訪問
            if (dist[nv] != -1)
            { //訪問済頂点は上書きしない
                continue;
            }
            else
            {
                dist[nv] = dist[v] + 1; //頂点nvの原点からの距離を更新
                que.push(nv);
            }
        }
    }
    //BFS完了
    return dist;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X, Y;
    cin >> N >> X >> Y;
    Graph G(N);
    vector<int> ans(N, 0);
    REP(i, N - 1)
    {
        G[i].push_back(i + 1);
        G[i + 1].push_back(i);
    }
    G[X - 1].push_back(Y - 1);
    G[Y - 1].push_back(X - 1);
    REP(i, N)
    {
        vector<ll> dist = BFS(G, i);
        /*        REP(i, N)
        {
            cout << i << ":" << dist[i] << endl;
        }*/
        REP(j, N)
        {
            if (dist[j] == -1)
                continue;
            else
            {
                ans[dist[j]]++;
            }
        }
    }

    for (int i = 1; i < N; i++)
    {
        if (ans[i] != 0)
            ans[i] /= 2;
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
	int a, b, temp=0;
	scanf("%d", &a);
	for (int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j==a){
				temp=1;
				break;
			}
		}
	}
	if(temp == 1){
        puts("Yes");
    }
	else{
        puts("No");	
    }
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        mut l: [i32;2*n],
    }
    // println!("{:?}", l);
    l.sort();
    let mut ans = 0;
    for i in 0..n {
        ans+=l[2*i];
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
// 三井住友信託銀行プログラミングコンテスト2019 B

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

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
 int x, n;

  cin >> n;

  for(int i = 0; i < n + 1; ++i) {
    x = i * 1.08;
    if (n == x) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
A = [int(input()) for i in range(n)]

A_np = np.asarray(A)
max = np.max(A_np)
idx = np.argmax(A_np)
A_temp = A_np
A_temp[idx] = 0

for i in range(n):
    if i == idx:
        print(np.max(A_temp))
    else:
        print(max)

Measured memory_bytes: 24272
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

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

using std::min;
using std::max;

using std::string;

using std::vector;

int main(void) {
    string s;
    cin >> s;

    string t;
    for(size_t i = 0; i < s.size(); i += 2){
        t.push_back(s[i]);
    }
    cout << t << endl;
    return 0;
}


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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s1;
    cin >> s1;
    ll q;
    cin >> q;
    ll g=0;
    vector<char>arr(10000000);
    ll j=0;
    for(int i=1000001;i<1000001+s1.size();i++){
        arr[i]=s1[j];
        j++;
    }
    ll s=1000001,e=s+s1.size()-1;
    ll t=0;

    while(q--){
        ll n;
        cin >> n;
        if(n==1){
            swap(s,e);
            t++;
            t%=2;
        }
        if(n==2){
            ll p;
            char c;
            cin >> p >> c;
            if(p==1){
                if(t){
                    arr[s+1]=c;
                    s++;
                }
                else{
                    arr[s-1]=c;
                    s--;
                }
                
            }
            else{
                if(t){
                    arr[e-1]=c;
                    e--;
                }
                else{
                    arr[e+1]=c;
                    e++;
                }
            }
        }
    }
    if(s<e){
        for(int i=s;i<=e;i++)
            cout<<arr[i];
    }
    else{
        for(int i=s;i>=e;i--)
            cout<<arr[i];
    }

    return 0;
        
}


Measured memory_bytes: 10576
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();

    int[] sums = new int[n+1];

    for(int i = 1; i <= n; i++){
      sums[i] = 0;
    }

    for(int x = 1; x < 101; x++){
      for(int y = 1; y < 101; y++){
        for(int z = 1; z < 101; z++){
          int nowsum = x * x + y * y + z * z + x * y + y * z + z * x;
          if(nowsum <= n){
            sums[nowsum]++;
          }
        }
      }
    }

    for(int i = 1; i <= n; i++){
      System.out.println(sums[i]);
    }

  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 28508
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
signed main(){
    int N,M;
    cin>>N>>M;
 
    vint sum(N);
    rep(i,M){
        string s;
        cin>>s;
        rep(j,N){
            if(s[j]=='W')sum[j]++;
        }
    }
 
    int allW=accumulate(all(sum),0ll);
 
    int mi=-1,mic=1001001001001001001ll;
    int cur=0;
    for(int i=0;i<=N;i++){
        int cost=0;
        cost+=M*i-cur;
        cost+=allW-cur;
        if(mic>cost){
            mi=i;
            mic=cost;
        }
        if(i<N)cur+=sum[i];
    }
 
    cout<<mi<<" "<<mi+1<<endl;
    return 0;
}

Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> gl(m), gr(m);
  rep(i,m) cin >> gl[i] >> gr[i];
  int l = 0;
  int r = INF;
  rep(i,m) {
    l = max(l, gl[i]);
    r = min(r, gr[i]);
  }
  cout << max(0, r-l+1) << endl;
}

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

Measured memory_bytes: 4052
i=61,f[],c,m,s;main(y){for(;s?++f[y*12+*f+"=>?2J13IK<@V&"[--s]]:~scanf("%d,%d,%d",f,&y,&s)?s=s*4+1:++i<180?i%12>1?(y=f[i])?y>m?m=y:1:++c:1:!printf("%d\n%d\n",c,m););if(m>20)return 1;if(m>15)puts("");return 0;}

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

 main() {
vector<int>a(3);
for(int i=0;i<3;i++){
    cin >> a.at(i);
}
int ans =0;
sort(a.begin(),a.end());
while(a.at(0)!=a.at(1)||a.at(1)!=a.at(2)){
    sort(a.begin(),a.end());
    if(a.at(2)==a.at(1)){
        a.at(0)+=2;
    }
    else{
        a.at(0)++;
        a.at(1)++;
    }
    ans++;
}
cout << ans <<endl;
 }




Measured memory_bytes: 256
x, y ,z = input()
if  x == "S" and y == "S" and z == "S":
    print(0)
elif x =="S" and y=="R" and z=="R":
    print(2)
elif x=="R" and y=="R" and z=="S":
    print(2)
elif x=="R" and y=="R" and z=="R":
    print(3)
else:
    print(1)
    

Measured memory_bytes: 9112
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int a,b,ss,wa=0;
	while(1){
		cin>>a>>b;
		if(a==0&&b==0) break;
		if(wa!=0) cout<<endl;
		wa++;
		ss=0;
		for(int sr=a;sr<=b;sr++){
			if(sr%4==0){
				if(sr%100!=0){
					cout<<sr<<endl;
					ss++;
				}
				else if(sr%400==0){
					cout<<sr<<endl;
					ss++;
				}
			}
		}
		if(ss==0) cout<<"NA"<<endl;
	}
}

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

#define ll long long
#define re register
#define il inline
#define gc getchar
#define pc putchar

template <class T>
void read(T &x) {
  re bool f = 0;
  re char c = gc();
  while ((c < '0' || c > '9') && c != '-') c = gc();
  if (c == '-') f = 1, c = gc();
  x = 0;
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = gc();
  f && (x = -x);
}

template <class T>
void print(T x) {
  if (x < 0) pc('-'), x = -x;
  if (x >= 10) print(x / 10);
  pc((x % 10) ^ 48);
}

#define priln(x) do{print(x);pc('\n');}while(0)
#define prisp(x) do{print(x);pc(' ');}while(0)



int main() {
  int n, m;
  read(n);
  read(m);
  if (n > m) puts("No");
  else puts("Yes");
}

Measured memory_bytes: 764
#include <stdio.h>

int main() {
	int W, a, b, ans = 0;
	scanf("%d %d %d", &W, &a, &b);
	if (a < b)
		ans = b - (a + W);
	else
		ans = a - (b + W);

	if (ans >= 1)	
		printf("%ld\n", ans);
	else
		printf("0\n");

	return 0;
}

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

int main() {
    int N, K, x, ans = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> x;
        ans += min(2 * x, 2 * (K - x));
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a, b;
  while( scanf("%d %d", &a, &b ) == 2 ){
    while( a != b ){
      if( a > b )
	a -= b;
      else
	b -= a;
    }
    printf("%d\n", a);
  }
  return 0;
}

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

s = []

for i in range(n):
	s.append((input()+' '+str(i)).split())

for i in range(n):
	s[i][1] = int(s[i][1])
    
s.sort(key=lambda x:x[1], reverse=True)
s.sort(key=lambda x:x[0])

for i in s:
	print(int(i[2])+1)

Measured memory_bytes: 9048
#include<iostream>
#include<cstring>

int X, Y;
int field[15][15];
int dp[15][15];

int main()
{
	while( std::cin >> X >> Y, X | Y )
	{
		memset( field, -1, sizeof( field ) );
		memset( dp, 0, sizeof( dp ) );

		for( int i = 0; i != Y; ++i )
			for( int j = 0; j != X; ++j )
				std::cin >> field[i][j];

		for( int i = 0; i != X; ++i )
			if( field[0][i] != 1 )
				dp[0][i] = 1;
		
		for( int i = 1; i != Y; ++i )
		{
			for( int j = 0; j != X; ++j )
			{
				if( i < Y && field[i][j] != 1 )
				{
					for( int k = -1; k <= 1; ++k )
					{	
						if( field[i][j] == 2 && k )
							continue;

						if( j + k >= 0 && j + k < X && !field[i-1][j+k] )
							dp[i][j] += dp[i-1][j+k];
					}
				}

				if( i - 2 >= 0 && field[i][j] != 1 && field[i-2][j] == 2 )
					dp[i][j] += dp[i-2][j];
			}
		}

		
		int ans = 0;
		for( int j = 0; j != X; ++j )
		{
			ans += dp[Y-1][j];

			if( Y >= 2 && field[Y-2][j] == 2 )
				ans += dp[Y-2][j];
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#define M 3009
#include <stdio.h>
char* F(char *b,int n,FILE *f){char *r=fgets(b,n,f);if(!r)return NULL;b[strlen(b)-1]=0;return r;}
#define max(a,b) ((a)>(b)?(a):(b))
int lcs[M][M];
char a[M],b[M],l[M];
backtrack(i,j){
	if(i==0||j==0);
	else if(a[i]==b[j])backtrack(i-1,j-1),putchar(a[i]);
	else if(lcs[i][j-1]>lcs[i-1][j])backtrack(i,j-1);
	else backtrack(i-1,j);
}
main(int argc, char **argv){
  if(argc>1)freopen(argv[1],"rb",stdin);
  int i,j,_a,_b;
  strcpy(a,"*"),strcpy(b,"*");
  F(l,M,stdin);strcat(a,l);
  F(l,M,stdin);strcat(b,l);
  _a=strlen(a+1);_b=strlen(b+1);
  for(i=1;i<=_a;i++)
    for(j=1;j<=_b;j++){
#if 1
      if(a[i]==b[j])lcs[i][j]=lcs[i-1][j-1]+1;
      else lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
#else
      lcs[i][j]=max(max(lcs[i-1][j],lcs[i][j-1]),lcs[i-1][j-1]+(a[i]==b[j]));
#endif
    }
  backtrack(_a,_b);puts("");
}


Measured memory_bytes: 35456
N,x = map(int, input().split())
*A, = map(int, input().split())

#貪欲法
ans = 0
for i in range(N-1):
    if (A[i]+A[i+1])<=x:
        continue
    #xより大きい分だけ食べる
    eat = (A[i]+A[i+1])-x
    if eat<=A[i+1]:
        A[i+1] -= eat
    else:
        A[i+1] = 0
        A[i] = A[i]-(eat-A[i+1])
    ans = ans + eat
print(ans)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 2005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
char s[1000005];
int sum[100005],N;
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    scanf("%s",s + 1);
    N = strlen(s + 1);
    for(int i = 1 ; i <= N ; ++i) {
	sum[i] = sum[i - 1];
	if(s[i] == '1') sum[i]++;
    }
    for(int K = N ; K >= 1 ; --K) {
	int r = K;
	int l = N - K + 1;
	if(l > r) {
	    out(K);enter;return 0;
	}
	if(sum[r] - sum[l - 1] == 0 || sum[r] - sum[l - 1] == r - l + 1) {
	    out(K);enter;return 0;
	}
    }
}


Measured memory_bytes: 768
n,k=map(int,input().split())
a=list(map(int,input().split()))

def gcd(x,y):
    if y==0:
        return x
    if x<y:
        return gcd(y,x)
    return gcd(y,x%y)

m=max(a)
g=a[0]
for i in range(n):
    g=gcd(g,a[i])
if k%g==0 and k<=m:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll D;
  cin >> D;
  rep(day, D) cout << rand()%26+1 << newl;
  return 0;
}

Measured memory_bytes: 3656
#UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
    
n,q = map(int,input().split())
uf = UnionFind(n+1)

for i in range(q):
    t,u,v = map(int,input().split())
    
    if t == 0:
        uf.union(u,v)
    else:
        if uf.find(u) == uf.find(v):
            print(1)
        else:
            print(0)

Measured memory_bytes: 11652
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();
	int Y = sc.nextInt();
	boolean result = false;
	for (int i=0;i<=X;i++) {
	    if (i * 2 + (X-i) * 4 == Y) {
		result = true;
		break;
	    }
	}
	if (result) System.out.print("Yes");
	else System.out.print("No");
    }
}


Measured memory_bytes: 35764
n = int(input())
a = list(map(int, input().split()))
cnt = 0
oddflg = False

while oddflg == False:
    for i in range(n):
        if (a[i] % 2) != 0:
            oddflg = True
    if oddflg == False:
        for i in range(n):
            a[i] = a[i]/2
        cnt += 1

print(cnt)


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

int main() {
  char c;cin>>c;
  if (c=='a' || c=='i' || c=='u' || c=='e' || c=='o') cout << "vowel";
  else cout << "consonant";
}


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

using namespace std;

const int NMAX = 200000;
vector<int> G[NMAX+5];
int viz[NMAX+5];
int freq[NMAX+5];

void dfs(int nod, int cnt)
{
    int i;
    viz[nod] = cnt;
    for(i= 0; i < G[nod].size(); i++)
    {
        if(viz[G[nod][i]] == 0)
            dfs(G[nod][i], cnt);
    }

}

int main()
{
  int n, m, x, y;
  int j, i;
  cin>>n>>m;
  for(i=1;i<=m;i++)
  {
      cin>>x>>y;
      G[x].push_back(y);
      G[y].push_back(x);
  }
  int cnt = 0;
  for(i=1;i<=n;i++)
  {
      if(viz[i] == 0)
      {
          cnt++;
          dfs(i, cnt);
      }
  }
  int sol = 0;
  for(i=1;i<=n;i++)
  {
      freq[viz[i]]++;
      if(freq[viz[i]] > sol)
        sol = freq[viz[i]];
  }
  cout<<sol<<"\n";

}

Measured memory_bytes: 24664
x = input()
x = int(x)
y = list(map(int, input().split()))

Max = y[0]
Min = y[0]
Sum = y[0]
for i in range((x-1)):
    if Max < y[(i+1)]:
        Max = y[(i+1)]
    if Min > y[(i+1)]:
        Min = y[(i+1)]
    Sum += y[(i+1)]
    
print(Min, Max, Sum)


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

int main()
{
    ll n,k,t,i,j;
    cin>>n>>k>>t;
    ll ans=0;
    if(n%k==0)
        ans=(n/k)*t;
    else
        ans=((n/k)+1)*t;
    cout<<ans<<endl;
}


Measured memory_bytes: 3592
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
		out.println(solve());
		out.flush();
	}

	static int solve(){
		int N = sc.nextInt();
		int M = sc.nextInt();
		if(N==1) return M;
		int rootM = (int)Math.sqrt(M);
		int div = M/N;
		int max = 1;
		for(int i=1;i<=rootM;i++){
			if(M%i==0){
				if(i<=div) max = Math.max(max, i);
				if(M/i<=div) max = Math.max(max, M/i);
			}
		}
		return max;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23248
#include<bits/stdc++.h>
#define pii pair<int,int>
#define endl "\n"
#define mod 1000000007
using namespace std;
int m[200001],minx[200001],maxx[200001];
bool ff[200001];
int main()
{
    ios_base::sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>m[i];
    set<int> s;
    for(int i=0;i<k-1;i++) s.insert(m[i]);
    for(int i=0;i<n-k+1;i++)
    {
        minx[i]=(*s.begin());
        maxx[i]=(*(--s.end()));
        s.erase(m[i]);
        s.insert(m[i+k-1]);
    }
    minx[n-k+1]=(*s.begin());
    maxx[n-k+1]=(*(--s.end()));
    int ans=n-k+1;
    int br=1; bool f=0;
    for(int i=1;i<n;i++)
    {
        if(m[i]>m[i-1])
        {
            br++;
            if(br>=k)
            {
                if(f) ans--;
                f=1; ff[i-k+1]=1;
            }
        }
        else br=1;
    }
    for(int i=0;i<n-k;i++)
    {
        if(ff[i+1]) continue;
        int a=m[i],b=m[i+k];
        if(a<minx[i+1]&&b>maxx[i+1]) ans--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10496
#include <stdio.h>
#define MAX 10000
#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
} Node;
Node T[MAX];
int n;

void preParse(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if(u==NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v1,v2,v3,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v1,&v2,&v3);
    T[v1].l=v2;
    T[v1].r=v3;
    if(v2!=NIL) T[v2].p=v1;
    if(v3!=NIL) T[v3].p=v1;
  }

  for(i=0;i<n;i++) if(T[i].p==NIL) root=i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}
    
  

Measured memory_bytes: 620
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<string>
#include<math.h>
using namespace std;

int main()
{
	int a[1000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		
		for (int s = 0; s < i; s++)
		{
			if (a[s]>=a[i])
			{
				int q = a[s];
				a[s] = a[i];
				for (int k = s; k < i ; k++)
				{
					int w = a[k + 1];
					a[k + 1] = q;
					q = w;
				}
			}
		}
		for (int s = 0; s < n; s++)
		{
			cout << a[s];
			if (s != n - 1)cout << " ";
		}cout << endl;
	}



}

Measured memory_bytes: 1164