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

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const int MAX_N = 300000;
int par[MAX_N];
int t_rank[MAX_N];

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        t_rank[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;

    if (t_rank[x] < t_rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (t_rank[x] == t_rank[y]) t_rank[x]++;
    }
    return true;
}

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

ll N;
ll ans = 0;

void solve() {
    cin >> N;
    pair<ll,ll> X[N];// x, id  
    pair<ll,ll> Y[N];
    rep(i,N) {
        ll x, y;
        cin >> x >> y;
        X[i] = pair<ll,ll>(x,i);
        Y[i] = pair<ll,ll>(y,i);
    }
    sort(X,X+N);
    sort(Y,Y+N);
    vector<pair<ll, pair<ll,ll>>> E; // length, from, to
    REP(i,1,N) {
        pair<ll, pair<ll,ll>> p1(X[i].first-X[i-1].first, pair<ll,ll>(X[i].second, X[i-1].second));
        pair<ll, pair<ll,ll>> p2(Y[i].first-Y[i-1].first, pair<ll,ll>(Y[i].second, Y[i-1].second));
        E.push_back(p1);
        E.push_back(p2);
    }
    sort(E.begin(), E.end());
    init(N);
    rep(i,E.size()) {
        ll cost = E[i].first;
        ll from = E[i].second.first;
        ll to = E[i].second.second;
        if (!same(from, to)) {
            unite(from, to);
            ans += cost;
        }
    }
    cout << ans << endl;
}

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


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

using Vec = std::vector<int>;

int main(void) {
    int n;
    std::cin >> n;
    Vec vec_a{};
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        vec_a.push_back(a);
    }
    int m;
    std::cin >> m;
    Vec vec_b{};
    for (int j = 0; j < m; ++j) {
        int b;
        std::cin >> b;
        vec_b.push_back(b);
    }

    if (std::includes(vec_a.begin(), vec_a.end(), vec_b.begin(), vec_b.end()))
        std::cout << 1 << std::endl;
    else
        std::cout << 0 << std::endl;
}



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

#define MAX 200002

int n;
int k;

deque<int> d;

char buf[MAX];

string ans;


int main(){
	cin >> n >> k;
	scanf("%s", buf);
	for (int i = 0; i < n; i++){
		if (buf[i] - 'A' == 0){
			d.push_back((i & 1) ^ 1);
		}
		else{
			d.push_back((i & 1));
		}
	}
	if (n == 1){
		k %= 2;
		d.front() ^= k;
	}
	else{
		int C = 0;
		while (k&&C <= 10 * n){
			k--;
			C++;
			if (d.front() == 1){
				d.front() = 0;
				continue;
			}
			d.pop_front();
			d.push_back(((n - 1) & 1) ^ 1);
		}
		if (k == 0){

		}
		else{
			if (d.front() == 0){  //B
				
			}
			else{
				k %= 2;
				if (k){
					d.front() = 0;
				}
			}
		}
	}
	for (int i = 0; i < d.size(); i++){
		int go = ((i % 2) == d[i]);
		ans.push_back('A' + go);
	}
	printf("%s\n", ans.c_str());
	return 0;
}

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; ++i) {
        if(i%d==0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3520
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n,c,k;
  cin >> n >> c >> k;

  vector<int> t(n);
  REP(i,n) cin >> t[i];
  
  sort(t.begin(), t.end());

  int s = t[0];
  int i = 0,j = 0;
  int cnt = 0;

  while(i < n){
    cnt++;
    j = i + 1;
    while(j < n && j - i + 1 <= c && t[j] <= t[i] + k) j++;
    i = j;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll a;
  string s;
  cin>>a>>s;

  if(a>=3200) cout << s << endl;
  else cout << "red" << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 256
import collections

n = int(input())
a = [int(w) for w in input().split()]
q = int(input())

a_counter = collections.Counter(a)
now_sum = sum(a)
for i in range(q):
    b, c = [int(w) for w in input().split()]

    num = a_counter[b]
    a_counter[b] = 0
    a_counter[c] += num
    # print(a_counter)

    now_sum += (c - b) * num
    print(now_sum)


Measured memory_bytes: 24180
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	string t=s;
	reverse(all(t));
	s+=t;
	string mn=s.substr(0,n);
	rep(i,0,n+1){
		mn=min(mn,s.substr(i,n));
	}  
	--k;
	int rl=0;
	rep(i,0,n){
		if(mn[i]!=mn[0])
			break;
		else ++rl;
	}
	rep(i,0,min(k,15)){

		string app(rl,mn[0]);
		mn=app+mn;
		mn=mn.substr(0,n);
		rl*=2;
		rl=min(n,rl);
	}
	cout<<mn<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int X, A;
    std::cin >> X >> A;

    std::cout << ((A > X) ? 0 : 10) << std::endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const ll mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int main()
{
	IO;
	int n{},k{},ans{};
	cin>>n>>k;
	vector<int>v(n);
	For(i,0,n)cin>>v[i];
	sort(all(v));
	For(i,0,k)ans+=v[i];
	cout<<ans<<'\n';
//	system("pause");
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  int ans = INF;
  rep(i,n) {
    if (s[i] == 'R') {
      cnt++;
    }
  }
  chmin(ans, cnt);
  chmin(ans, n-cnt);
  int cnt2 = 0;
  rep(i,cnt) if (s[i] == 'R') cnt2++;
  chmin(ans, cnt-cnt2);
  cout << ans << endl;
  return 0;
}

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

using namespace std;
int res;
vector<int> vec(50);
int solve(int i,int m, int n){

  if(m==0){
    return 1;
  }
   if(i>=n){
    return 0;
  }

res =(solve(i +1 , m - vec[i], n) || solve(i+1, m , n));
return res;
}


int main(){
  int n=0;
  cin >> n;

  for(int i=0;i<n;i++){
    cin>> vec[i];
  }
  int q=0;
  cin >> q;
  vector<int> vec2(q);
  for(int i=0;i<q;i++){
    cin>> vec2[i];
  }

  for(int i=0; i< q ; i++){
    if(solve(0,vec2[i], n) == 1){
      cout<< "yes"<<endl;
    }
    else {
      cout<< "no"<<endl;
    }
  }


return 0;
}



Measured memory_bytes: 3104
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())

aa = [0, 300000, 200000, 100000]
ans=0
if n <4:
    ans += aa[n]
if m <4:
    ans += aa[m]


if n == 1 and m ==1:
    ans += 400000

print(ans)



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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while(0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll H,W,K;
vector<string> s;
vector<vector<ll>> v;

signed main() {
  cin>>H>>W>>K;
  s.resize(H);
  v.resize(H, vector<ll>(W, -1));

  rep(y,H) {
    cin>>s[y];
    rep(x,W) {
      if (s[y][x] == '#') {
        v[y][x]=K--;
      }
    }
  }

  rep(y,H) {
    rep(x,W) {
      ll c = v[y][x];
      for (ll nx = x-1; nx >= 0; nx--) {
        if (c == -1 && v[y][nx] != -1) {
          c = v[y][nx];
        }
      }
      for (ll nx = x+1; nx < W; nx++) {
        if (c == -1 && v[y][nx] != -1) {
          c = v[y][nx];
        }
      }
      v[y][x] = c;
    }
  }

  for (ll y=0; y<H; y++) {
    bool ok = true;
    rep(x,W)
      if (v[y][x] == -1)
        ok = false;

    if (ok)
      continue;

    if (y > 0)
      v[y] = v[y-1];
  }

  for (ll y=H-1; y>=0; y--) {
    bool ok = true;
    rep(x,W)
      if (v[y][x] == -1)
        ok = false;

    if (ok)
      continue;

    if (y < H-1)
      v[y] = v[y+1];
  }

  rep(y,H) {
    rep(x,W)
      cout << v[y][x] << " ";
    cout << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int a; cin >> a;
    cout << a + pow(a, 2) + pow(a, 3) << endl;
    return 0;
}

Measured memory_bytes: 4148
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int A = int.Parse(Console.ReadLine());
		int B = int.Parse(Console.ReadLine());
		int ans = 0;
		if(A*B==2){
			ans = 3;
		} else if(A*B==3){
			ans = 2;
		} else {
			ans = 1;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, s, e) for(int i = s; i < e; i++)
#define rrep(i, s, e) for(int i = s; i > (s)-(e); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  string a, b;
  cin >> a >> b;

  if (a.substr(0,1) == b.substr(2,1) && a.substr(1,1) == b.substr(1,1) && a.substr(2,1) == b.substr(0,1)) pr("YES");
  else pr("NO");


  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


set<int> A;
int main()
{
	int N;
	int tmp;
	set<int>::iterator it;

	cin >> N;

	rep(i, N)
	{
		cin >> tmp;
		it = A.find(tmp);
		if (it == A.end())
			A.insert(tmp);
		else
			A.erase(it);
	}


	cout << A.size() << endl;

	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second


ll n, m, a, b, A[100010], B[100010], C[100010], q;
vector<ll>v[100010];
ll dp[100010][11];



int main() {
	cin >> n >> m;
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= 10;j++) {
			dp[i][j] = -1;
		}
	}
	for (int i = 0;i < m;i++){
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	cin >> q;
	for (int i = 1;i <= q;i++) {
		cin >> A[i] >> B[i] >> C[i];
		dp[A[i]][B[i]] = i;
	}
	for (int z = 0;z < 10;z++) {
		for (int i = 1;i <= n;i++) {
			for (int j = 1;j <= 10;j++) {
				if (dp[i][j] != -1) {
					for (auto u : v[i])dp[u][j - 1] = max(dp[u][j - 1], dp[i][j]);
				}
			}
		}
	}
	for (int i = 1;i <= n;i++) {
		ll ans = 0;
		for (int j = 0;j <= 10;j++) {
			ans = max(ans, dp[i][j]);
		}
		cout << C[ans] << endl;
	}
	return 0;
}

Measured memory_bytes: 17780
#include<stdio.h>
const int MAX_V = 100000;
int main(){
	int prime[MAX_V+1];
	int i, j, v, n;
	for(i = 2; i <= MAX_V; i++){
		prime[i] = 1;
	}
	for(i = 2; i * i <= MAX_V; i++){ 
		if(prime[i]){
			for(j = 2 * i; j <= MAX_V; j += i){
				prime[j] = 0;
			}
		}
	}
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		for(i = n - 2; i >= 2; i--){
			if(prime[i] == 1 && prime[i + 2] == 1){
				printf("%d %d\n", i, i + 2);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2072
#include <iostream>
#include <cstring>
using namespace std;
int main(){
  int Amida[1001][101],a,n,m;
  while(cin >> n >> m >> a && n||m||a){
    memset(Amida,0,sizeof(Amida));
    for(int i=0,h,p,q;i<m;i++){
      cin >> h >> p >> q;
      Amida[h][p] = q;
      Amida[h][q] = p;
    }
    for(int i=1000;i>=0;i--){
      if(Amida[i][a] != 0) a = Amida[i][a];
    }
    cout << a << endl;
  }
}

Measured memory_bytes: 1560
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pllint a, pllint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	llint a, b, k;
	cin >> a >> b >> k;
	if (a < k) {
		cout << 0 << " " << max(b - (k - a), (llint)0) << endl;
	}
	else {
		cout << a - k << " " << b << endl;
	}
	return 0;
}


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


int main() {
  int n,k;
  cin>>n>>k;
  vector<int> h(n),dp(n,INT_MAX);
  for(int i = 0;i<n;i++) cin>>h[i];
  //printf("hello\n");
  //dp[i] is min cost to reach dp[n]
  //dp[i] = for all k min(h[i+k]-h[i] + dp[i+k])
  dp[n-1] = 0;
  for(int i = n-2;i>=0 ;i-- ) {
    for(int j = 1;j<=k;j++) {
      if(i+j < n) {
        dp[i] = min(dp[i],abs(h[i+j]-h[i])+ dp[i+j]);
       // printf("(i,dp[i])-> %d %d\n",i,dp[i]);
      } else {
        break;
      }
    }
  }
  cout<<dp[0]<<endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;


public class Main {
        public static void main(String[] args) {
        FastReader f = new FastReader();
        HashMap<Integer,Integer> histogram = new HashMap<>();
        // fill in the dictionary with the initial value
        String match = "No";
        String s = f.nextLine();
        String p = f.nextLine();
        int size = p.length();
        int len = s.length();
        for(int i = 0; i < len; i++){
            int endOne = i+size;
            int endTwo = 0;
            if(endOne >= len){
                 endTwo = endOne % len;
                 endOne = len;
            }
            String result = s.substring(i, endOne) + s.substring(0,endTwo);
            if(result.equals(p)){
                match = "Yes";
                break;
            }

        }

        System.out.println(match);
    }

    // Helper class to speed up IO
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}



Measured memory_bytes: 24400
import java.util.*;

public class Main {
    public static int Min(int arr[]){
      int max = arr[0];
      int min = arr[1];
      for (int i = 1; i < arr.length; i++) {
          int v = arr[i];
          if (v > max) {
              max = v;
          }
          if (v < min) {
              min = v;
          }
      }
      return min;
    }
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N = Integer.parseInt(sc.next());
      int M = Integer.parseInt(sc.next());
      int X = Integer.parseInt(sc.next());
      int[][]A = new int[N][M+1];
      for(int i = 0; i < N; i++){
        for(int j = 0; j < M+1; j++)
        A[i][j] = Integer.parseInt(sc.next());
      }
      int ans = Integer.MAX_VALUE;;
      for(int mask = 0; mask < Math.pow(2,N); mask++){
        int[]C = new int[M];
        int cst = 0;
        for(int i = 0; i < N; i++){
          if(((mask >> i) & 1) == 1){
            cst += A[i][0];
            for(int j = 1; j < M+1; j++){
              C[j - 1] += A[i][j];
            }
          }
        }
        boolean check = true;
  			for(int j = 0; j < M; j++) {
  				if(C[j] < X) {
  					check = false;
  				}
  			}
        if(check){
          ans = Math.min(ans, cst);
        }
      }
      if(ans < Integer.MAX_VALUE){
        System.out.println(ans);
      }
      else{
        System.out.println(-1);
      }

  }
}


Measured memory_bytes: 37168
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
    auto t = s;
    Reverse(t);
    CoutYN(
        (s.find("keyence") == 0 && t.find("") == 0) ||
        (s.find("keyenc") == 0 && t.find("e") == 0) ||
        (s.find("keyen") == 0 && t.find("ec") == 0) ||
        (s.find("keye") == 0 && t.find("ecn") == 0) ||
        (s.find("key") == 0 && t.find("ecne") == 0) ||
        (s.find("ke") == 0 && t.find("ecney") == 0) ||
        (s.find("k") == 0 && t.find("ecneye") == 0) ||
        (s.find("") == 0 && t.find("ecneyek") == 0)
    );
}





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

#define sz(s)               (int)s.size()
using namespace std;
int main()
{
	int k, s; cin >> k >> s;
	int c = 0;
	for (int i = 0; i <=k; ++i)
	{

		for (int j = 0; j <= k; ++j)
		{
			
			int z = s - (i + j);
			if (z >= 0 && z <= k && (i + j + z == s))
				{
					//cout << i << " " << j << " " << a << endl;
					c++;
				}
		}

	}
	cout << c;

	 
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = []
ans = 1000000001
for i in range(n):
    h.append(int(input()))
h.sort()
for j in range(n-(k-1)):
    if ans == 0:
        break
    elif ans > h[j+k-1]-h[j]:
        ans = h[j+k-1]-h[j]
print(ans)

Measured memory_bytes: 7384
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;
inline int read() {
	int x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

const int inf = 1e9; 
LL s,c;

int main() {
	scanf("%lld%lld",&s,&c);
	if( s*2>=c ) {
		printf("%lld\n",c/2);
		return 0;
	}
	c-=s*2;
	printf("%lld\n",s+c/4);
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000000;
#define MOD 1000000007LL;
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef int64_t i64;

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

int N; cin>> N;
VI A(N), B(N), C(N); 
rep(i, 0, N) cin >> A[i]; sort(ALL(A));
rep(i, 0, N) cin >> B[i]; sort(ALL(B));
rep(i, 0, N) cin >> C[i]; sort(ALL(C));

i64 cnt = 0;
for(int i = 0; B[i] < C[N-1] && i < N; ++i)
    cnt += distance(A.begin(), lower_bound(ALL(A), B[i]))
            * distance(upper_bound(ALL(C), B[i]), C.end());

cout << cnt << endl;



}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;

int main (void){  
    string n;
    int cnt = 0;
    cin >> n;
    for (int i = 0; i < n.length(); i++) {
        cnt++;
    }

    if (cnt == 1) {
        if (n[0] == '3') {
            cout << "bon" << endl;
        } else if (n[0] == '0' || n[0] == '1' || n[0] == '6'|| n[0] == '8') {
            cout << "pon" << endl;
        } else {
            cout << "hon" << endl;
        }
    } else if (cnt == 2) {
        if (n[1] == '3') {
            cout << "bon" << endl;
        } else if (n[1] == '0' || n[1] == '1' || n[1] == '6'|| n[1] == '8') {
            cout << "pon" << endl;
        } else {
            cout << "hon" << endl;
        }
    } else {
        if (n[2] == '3') {
            cout << "bon" << endl;
        } else if (n[2] == '0' || n[2] == '1' || n[2] == '6'|| n[2] == '8') {
            cout << "pon" << endl;
        } else {
            cout << "hon" << endl;
        }
    }
    return 0;
}

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

using P = pair<int, int>;

bool red[200][200];
bool blue[200][200];

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

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;

        red[a][b] = true;
    }

    for (int i = 0; i < N; i++) {
        int c, d;
        cin >> c >> d;

        blue[c][d] = true;
    }

    int counter[200] = {};
    int ans = 0;
    for (int x = 0; x < 2 * N; x++) {
        for (int y = 0; y < 2 * N; y++) {
            if (not blue[x][y]) continue;
            for (int z = y - 1; z >= 0; z--) {
                if (counter[z] > 0) {
                    ans++;
                    counter[z]--;
                    break;
                }
            }
        }
        for (int y = 0; y < 2 * N; y++) {
            if (red[x][y]) counter[y]++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
function main(input) {
  var args = input.split(' ');
  var a = parseInt(args[0]);
  var b = parseInt(args[1]);
  var t = parseInt(args[2]);
  var biscuit = Math.floor(t / a) * b;
  console.log(biscuit);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

const int MOD = 1000000007;
const int MAX = 2*1e5;

bool IsPrime(long long n){
  if(n == 1) return false;
  for(long long i = 2; i * i < n; i++){
    if(n%i == 0) return false;
  }
  return true;
}

vector<pair<long long, long long>> PrimeFactorize(long long n){
  vector<pair<long long, long long>> res;
  long long a = 0;
  for(long long i = 2; i * i <= n; i++){
    a = 0;
    if(n%i == 0){
      if(IsPrime(i)){
        while(n % i == 0){
          n /= i;
          a++;
        }
        res.push_back(make_pair(i, a));
    }}}
  if(n!= 1) res.push_back(make_pair(n, 1));
  return res;
}

long long fac[MAX], finv[MAX], inv[MAX];

void CombInit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }

}

long long Comb(long long n, long long k){
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
  long long n,m;
  cin >> n >> m;

  vector<pair<long long, long long>> res;
  res = PrimeFactorize(m);

  CombInit();

  long long ans = 1;
  long long size = res.size();
  for(long long i = 0; i < size; i++){
    long long num = Comb(res[i].second + n - 1, res[i].second);
    // ans = (ans * Comb(res[i].second + n - 1, res[i].second)) % MOD;
    ans = (ans * num) % MOD;
  }

  cout << ans << endl;

  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];
	sort(a, a + n);
  	sort(b, b + n);
  	sort(c, c + n);
    long long ans = 0;
    long numa = 0, numc = 0;
    for(int i = 0; i < n; i++){
        while(numa < n && a[numa] < b[i]) numa++;
        while(numc < n && c[numc] <= b[i]) numc++;
        ans += numa * (n - numc);
    }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin >> n;
  long long s =0;
  for(int i=0;i<n.size();i++){
    long long  a = n[i] - '0';
    s += a;
  }
  if(s%9 ==0)
  cout << "Yes" <<endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3716
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

LL x,y;

int main()
{
  scanf("%lld %lld",&x,&y);
  if (llabs(x-y) <= 1) puts("Brown");
  else puts("Alice");
  return 0;
}










Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {

  vector< double > x, y;
  double in_x, in_y;
  char in_c;

  while( cin >> in_x >> in_c >> in_y ) {

    x.push_back( in_x );
    y.push_back( in_y );

  }

  double ans = 0.00;

  for( long long int i = 0; i < x.size() - 2; i++ ) {

    double mx = x[0] - x[i+1];
    double my = y[0] - y[i+1];
    double a = sqrt( mx*mx + my*my );
    mx = x[0] - x[i+2];
    my = y[0] - y[i+2];
    double b = sqrt( mx*mx + my*my );
    mx = x[i+1] - x[i+2];
    my = y[i+1] - y[i+2];
    double c = sqrt( mx*mx + my*my );
    double z = ( a + b + c ) / 2;

    ans += sqrt(z*(z-a)*(z-b)*(z-c));

  }

  cout << fixed << setprecision(8) << ans << endl;
  return 0;

}

Measured memory_bytes: 1308
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	int num = A * 2 - 1, A_1 = A - 1;

	for (int i = 0;i < num;i++) {
		cout << B - A_1 + i << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct weighted_disjoint_set{
    vector<pair<int, int>> p;
    weighted_disjoint_set(int n){
        p.resize(n);
        for(int i = 0; i < n; i += 1) p[i] = {i, 0};
    }
    pair<int, int> fp(int u){
        if(u == p[u].first) return p[u];
        auto ppu = fp(p[u].first);
        return p[u] = {ppu.first, p[u].second + ppu.second};
    }
    //a[u] + w = a[v]
    void relate(int u, int v, int w){
        auto pu = fp(u), pv = fp(v);
        p[pu.first] = {pv.first, pv.second + w - pu.second};
    }
    bool diff(int u, int v, int& w){
        auto pu = fp(u), pv = fp(v);
        if(pu.first != pv.first) return false;
        return w = pu.second - pv.second, true;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    weighted_disjoint_set wds(n);
    for(int i = 0; i < q; i += 1){
        int com, u, v, w;
        cin >> com >> u >> v;
        if(com){
            if(not wds.diff(u, v, w)) cout << "?\n";
            else cout << w << "\n";
        }
        else{
            cin >> w;
            wds.relate(u, v, w);
        }
    }
    return 0;
}


Measured memory_bytes: 3988
#define C
typedef long long readtype;

/* Header {{{ */
#ifdef C
#include <stdio.h>
#include <math.h>
#include <string.h>
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
template<typename type> type abs(type a) { return a < 0 ? -a : a; }
template<typename type> type min(type a, type b) { return a < b ? a : b; }
template<typename type> type beMin(type &a, type b) { return a = (a < b ? a : b); }
template<typename type> type max(type a, type b) { return a > b ? a : b; }
template<typename type> type beMax(type &a, type b) { return a = (a > b ? a : b); }
template<typename type> void swap(type &a, type &b) { type c; c = a; a = b; b = c; }
#endif

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

typedef long long var;

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}
/* }}} */

const int N = 110005;

int n, h;
int fa[N];
int in[N], out[N];
bool mark[N];

int find(int t);

int main() {
  /*
#ifndef ONLINE_JUDGE
  freopen("source.in", "r", stdin);
  freopen("source.out", "w", stdout);
#endif
  */
  n = read(), h = read();
  for (int i = h << 1; i >= 1; --i) fa[i] = i;
  for (int i = 1; i <= n; ++i) {
    int a = read(), b = read(), c = read(), d = read();
    int x = c ? c + h : a, y = d ? d : b + h;
    out[x]++, in[y]++;
    x = find(x), y = find(y);
    if (x != y) fa[x] = y;
  }
  for (int i = 1; i <= h; ++i) {
    if (in[i] > out[i] || in[i + h] < out[i + h]) {
      puts("NO");
      return 0;
    }
  }
  for (int i = h << 1; i >= 1; --i) {
    if (in[i] != out[i] || (!in[i] && !out[i]))
      mark[find(i)] = true;
  }
  for (int i = h << 1; i >= 1; --i) {
    if (!mark[i] && fa[i] == i) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}

int find(int t) {
  if (fa[t] != t) fa[t] = find(fa[t]);
  return fa[t];
}


Measured memory_bytes: 128
n=int(input())
l0=[[] for _ in range(n)]
l1=[[] for _ in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        if y==0:
            l0[i].append(x)
        else:
            l1[i].append(x)
ans=0
for i in range(2**n):
    s0=set()
    s1=set()
    num=0
    num1=[]
    num0=[]
    for j in range(n):
        if (i>>j) & 1:
            num1.append(j+1)
            for k in range(len(l0[j])):
                s0.add(l0[j][k])
            for k in range(len(l1[j])):
                s1.add(l1[j][k])
        else:
            num0.append(j+1)
    for j in range(len(s1)):
        if s1.pop() in num0:
            num=1
            break
    if num==0:
        for j in range(len(s0)):
            if s0.pop() in num1:
                num=1
                break
    if num==0:
        ans=max(ans,len(num1))
print(ans)


Measured memory_bytes: 9228
#include <iostream>
    #include <string>
    #include <set>  
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
	#include <cassert>
    #include <iomanip>
    #include <sstream> 
    #include <cstdlib>
using namespace std;
const int MAXN=2e5+10;
const int INF=1e9+7;
vector<int> g[MAXN];
int n,m;
int dis[MAXN];
int main()
{
	cin>>n>>m;
	for(int i=0;i<=n;i++)
		dis[i]=INF;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	queue<int> Q;
	dis[1]=0;
	Q.push(1);
	while(!Q.empty())
	{
		int x=Q.front();
		//cout<<x<<endl;
		Q.pop();
		if(dis[x]>2)break;
		if(x==n)break;
		for(int i=0;i<g[x].size();i++)
		{
			//cout<<g[x][i]<<endl;
			if(dis[g[x][i]]>dis[x]+1)
			{
				dis[g[x][i]]=dis[x]+1;
				Q.push(g[x][i]);
			}
		}
	}
	//cout<<dis[n]<<endl;
	if(dis[n]<=2)cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vll a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    RSORT(a); RSORT(b); RSORT(c);
    vll ab;
    rep(i, x) rep(j, y) ab.pb(a[i]+b[j]);
    RSORT(ab);
    priority_queue<ll> q;
    int t = 0;
    rep(i, sz(ab)) {
        rep(j, z) {
            q.push(ab[i]+c[j]);
            ++t;
            if (t > k*k) break;
        }
        if (t > k*k) break;
    }
    rep(i, k) {
        ll val = q.top(); q.pop();
        cout << val << endl;
    }
    return 0;
}


Measured memory_bytes: 142356
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ld, ld> pdd;

void solve();

const int N = 1e5 + 10;

int main() {
    fast_cin();

    int t=1;
    // cin >> t;
    while(t--) {
        solve();
    }
}

void solve() {
    int h, n;
    cin >> h >> n;
    int a[N];
    for (int i=1; i <= n; i++) { 
        cin >> a[i];
    }

    sort(a+1, a+1+n, greater<int>());
    
    ll sum = 0;
    for (int i=1; i <= n; i++) {
        sum += a[i];
    }
    
    if (sum >= h) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        List<Set> pie = new ArrayList<>();
        int count = 0;
        
        while(true){
          pie.add(new Set (sc.nextInt(),sc.nextInt()));
          
          if(pie.get(count).x == 0 && pie.get(count).y == 0) break;
              
          count++;      
        }
        
        for(int i=0; i < pie.size()-1; i++){
            int root = 0;
            for(int x=1; x<=pie.get(i).x; x++){
              for(int y=1; y<=pie.get(i).x; y++){
                for(int z=1; z<=pie.get(i).x; z++){
                    if(x != y && x != z && y != z){
                        if(x <= pie.get(i).x || y <= pie.get(i).x || z <= pie.get(i).x ){
                            if(x+y+z == pie.get(i).y){
                                //System.out.println((x)+" "+(y)+" "+(z));
                                root ++;
                            }
                        }
                    }
                    
                }
              } 
            }
            
            System.out.println(root / 6);
            //System.out.println(pie.get(0).x);
        }
    }
}

class Set{
    int x = 0;
    int y = 0;
    
    Set(int x, int y){
       this.x = x;
       this.y =y;
    }
}



Measured memory_bytes: 27800