akhauriyash/Code-Regression huggingface dataset:
def COMB(a,b):
	if b > (a-b):
		b = a-b
	ans = 1
	for i in range(0,b):
		ans *= (a-i)
	for i in range(0,b):
		ans //= (b-i)

	return int(ans)

if __name__ == '__main__':
	N, A, B = map(int, input().split())
	v_lst = [int(p) for p in input().split()]

	v_lst.sort(reverse = True)

	count = 0

	for i in range(0,B-A+1):
		lst = v_lst[0:A+i]
		mean = sum(lst)/len(lst)
		if i == 0:
			nxt_mean = mean
		if mean == nxt_mean:
			a = v_lst.count(min(lst))
			b = lst.count(min(lst))
			count += COMB(a,b)
		else:
			break
		nxt_mean = mean

	print("{:.6f}".format(nxt_mean))
	print(count)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

int main()
{
	stack<int> s;
	string str;

	for (; cin >> str; )
	{
		if (str == "+")
		{
			int a = s.top();
			s.pop();

			int b = s.top();
			s.pop();

			s.push(b + a);
		}
		else if (str == "-")
		{
			int a = s.top();
			s.pop();

			int b = s.top();
			s.pop();

			s.push(b - a);
		}
		else if (str == "*")
		{
			int a = s.top();
			s.pop();

			int b = s.top();
			s.pop();

			s.push(b * a);
		}
		else
		{
			s.push(atoi(str.c_str()));
		}
		
	}
	cout << s.top() << endl;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec a(n);
    rep(i, n) cin >> a[i];

    rep(_, min(k, 1000)) {
        vec im(n+1);
        rep(i, n) {
            im[max(0, i-a[i])]++;
            im[min(n, i+a[i]+1)]--;
        }
        rep(i, n) im[i+1] += im[i];
        rep(i, n) a[i] = im[i];
    }

    rep(i, n) {
        if (i != 0) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}

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

using namespace std;

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

  vector<int> v;
  int P=0,min=0,count=0;


  for(int i=0;i<N;i++)
  {
    cin>>P;
    if(P<=min||i==0)
    {
      count+=1;
    }
    min=(P<=min||i==0) ? P:min;
  }
  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
int a(char *p){return((*p<'a')||(*p>'z'));}
char *decode (char *inbuf, int s) {
  int p = 0;
  while (inbuf[p] != 0) {
    if ((inbuf[p] >= 'a')&&(inbuf[p]<='z')) {
      int t = inbuf[p] + s;
      //inbuf[p] = inbuf[p] + (char)s;
      if (t > 'z')      inbuf[p] = (char)(t - 26);
      else if (t < 'a') inbuf[p] = (char)(t + 26);
      else              inbuf[p] = (char)t;
    }
    p++;
  }
  return (inbuf);
}

int main(){
  char inbuf[82];
  while(fgets(inbuf,80,stdin)){
    int s;
    char *p=inbuf;
    while(*p){
      s = 0;
      if(c(p,12)){
	if(c(p+1,3)){
	  if(a(p+3))
	    s = 't' - *p;
	}
	/* that */
	else if(c(p+1,7)){
	  //	else if (((*p-*(p+2))==19)||((*p-*(p+2))==-7)) {
	  if (*p-*(p+3) == 0)
	  if(a(p+4))
	      s = 't' - *p;
	}
	/* this */
	//	else if (((*p-*(p+2))==11)||((*p-*(p+2))==-15)) {
	else if(c(p+1,25)){
	  if (((*p-*(p+3))==1)||((*p-*(p+3))==-25))
	  if(a(p+4))
	      s = 't' - *p;
	}
      }
      if (s) break;
      p++;
    }
    printf("%s",decode(inbuf, s));
  }
  return 0;
}

Measured memory_bytes: 524
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
  int a, b, c, k;

  cin >> a >> b >> c >> k;

  for(int i = 0; i < k; i++){
    if(a > b && a > c)
      a *= 2;
    else if(b > a && b > c)
      b *= 2;
    else
      c *= 2;
  }

  cout << a + b + c << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;

using namespace std;
int main() {
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> val(M);
    for(ll i =0;i<M;i++){
        val[i] = vector<ll>(0);
    }
    for(ll i = 0; i < N; i++){
        ll A,B;
        cin >> A >> B;
        if(M - A >= 0)
        val[M - A].push_back(B);
    }
    priority_queue<int> q;
    ll rew = 0;
    for(ll i = M - 1; i >= 0; i--){
        for(ll tmp = 0; tmp < val[i].size(); tmp++){
            int v = val[i][tmp];
            q.push(v);
        }
        if(!q.empty()){
            rew += q.top();q.pop();
        }

    }
    cout << rew << endl;

}

Measured memory_bytes: 5632
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}

ll inverse(ll n)
{
	return exp(n,MOD-2);
}

int LIM=2e5+100;
void solve()
{
//Read Comments below main
	ll n,k;
	cin>>n>>k;
	ll m=n%k;
	cout<<min(m,abs(m-k))<<endl;
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int h,w;cin>>h>>w;
    char a[103][103];
    for(int i=1; i<=h;i++){
      for(int j=1; j<=w;j++){
        cin>>a[i][j];
      }
    }

    for(int i=0; i<=h+1;i++){
      for(int j=0; j<=w+1;j++){
        if(i==0||j==0||i==h+1||j==w+1){
          cout<<"#";
        }else{
          cout<<a[i][j];
        }
      }
      cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

main(){
  int N;
  float a,b,c;
  int x,y,z;  
  scanf("%d",&N);
  a = N/1.08;
  x = (int)a;
  b = x*1.08;
  c = (x+1)*1.08;
  y = (int)b;
  z = (int)c;   

   
  if(y == N){
  	printf("%d",x);
  }
  else if(z== N){
  	printf("%d",x+1);
  }
  else{
  	printf(":(");
  }
}

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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  int a;
  vector<int> c(n, k-q);
  for(int i=0; i<q; i++) {
    cin >> a;
    c.at(a-1)++;
  }
  for(int i=0; i<n; i++) {
    string ans = (c.at(i) > 0) ? "Yes" : "No";
    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(v1, v2)     cout << v1 << " " << v2 << endl
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << endl
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << endl

//----------------------------------------------------------------

int main(void) {
  int a[3][3];
  bool bin[3][3];
  rep(i,3){
    rep(j,3){
      cin >> a[i][j];
      bin[i][j]=false;
    }
  }

  int n;
  cin >> n;
  arr(b,n);

  rep(k,n){
    rep(i,3){
      rep(j,3){
        if(b[k]==a[i][j]){
          bin[i][j]=true;
        }
      }
    }
  }

  bool ans=false;
  rep(i,3){
    if(bin[i][0] && bin[i][1] && bin[i][2]){
      ans=true;
    }
  }
  rep(i,3){
    if(bin[0][i] && bin[1][i] && bin[2][i]){
      ans=true;
    }
  }

  if(bin[0][0] && bin[1][1] && bin[2][2]){
    ans=true;
  }
  if(bin[0][2] && bin[1][1] && bin[2][0]){
    ans=true;
  }

  if(ans){
    prt("Yes");
  } else {
    prt("No");
  }


}


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;
constexpr LL MOD = 1e9 + 7;

int S;
LL memo[700][2005];

LL dp(int x, int s) {
    if (s == 0) return 1;
    if (s < 3) return 0;

    LL &rv = memo[x][s];
    if (~rv) return rv;
    rv = 0;

    for (int i = 3; i <= s; i++) {
        rv += dp(x + 1, s - i);
        rv %= MOD;
    }

    return rv;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    cin >> S;
    memset(memo, -1, sizeof memo);

    LL res = dp(0, S);
    cout << res << endl;
}

Measured memory_bytes: 14636
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    while(cin>>a>>b>>c)
    {
        if(a+b<c)
            cout<<"dangerous"<<endl;
        else if(a+b>=c)
        {
            if(c<=b)
                cout<<"delicious"<<endl;
            else cout<<"safe"<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e4 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

vector<vector<int> > g;
int color[1005];

bool dfs(int i, int c){
    color[i] = c;
    bool ok = true;
    for(auto to : g[i]){
        if(color[to]==-1){
            ok &= dfs(to, (c+1)%2);
        }
        else{
            ok &= color[to] != c;
        }
    }
    return ok;
}

int main() {
    int n, m;
    while(cin >> n >> m, n){
        g.clear();
        g.resize(n);
        fill(color,color+n,-1);
        REP(i,m){
            int u, v;
            cin >> u >> v;
            u--; v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        if(dfs(0,0)){
            int cnt = 0;
            REP(i,n) cnt += color[i]%2;
            set<int> ans;
            if(cnt%2==0) ans.insert(cnt/2);
            if((n-cnt)%2==0) ans.insert((n-cnt)/2);
            cout << ans.size() << endl;
            for(auto i : ans) cout << i << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    return 0;
}



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

//素数判定
bool isPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort(s.begin(),s.end());
  s.erase(unique(s.begin(),s.end()),s.end());
  cout << s.size() << endl;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
for(char ch='a';ch<='z';ch++)
{
if(s1+ch==s2)
    {cout<<"Yes";
    return 0;
    }
}
cout<<"No\n";
return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int h[100001];
int dp[100002];
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>h[i];
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    rep(i,n)FOR(j,1,3){
        if(i+j<=n)dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main()
{
	int n = 0;
	int i;
	char tab[4];
	for(i = 0; i < 3; i++)
	{
		scanf("%s", tab);
		
		printf("%c", tab[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define N 1000
#define rep(i,n) for(int i=0;i<n;i++)
typedef struct{
    int num;
    int post;
}Data;
int comp(const void *a,const void *b){
    Data c = *(Data *)a;
    Data d = *(Data *)b;
    return d.post-c.post;
}
Data d[N];
int used[N]={0};
double map[N][N]={0};
int g[N][N]={0};
int len[N];
int n,m,cnt;
void init(){
    rep(i,n){
        used[i]=len[i]=0;
        rep(j,n){
            map[i][j]=g[i][j]=0;
        }
    }
}

void init2(){
    rep(i,n){
        used[i]=0;
    }
}

void dfs(int pos){//ラベル
    if(used[pos]) return;
    used[pos]=1;
    rep(i,n){
        if(used[i]) continue;
        if(map[pos][i]){
            dfs(i);
        }
    }
    d[pos].post=++cnt;
}
void dfs_init(){
    cnt=0;
    rep(i,n){
        dfs(i);
    }
}

void dfs2(int j,int pos){//強連結分解
    if(used[pos]) return;
    used[pos]=1; g[j][cnt++]=pos;
    len[j]=cnt;
    rep(i,n){
        if(used[i]) continue;
        if(map[i][pos]){
            dfs2(j,i);
        }
    }
}
void dfs2_init(){
    init2();
    int idx=0;
    rep(i,n){
        cnt=0;
        if(used[d[i].num]);
        else{
            dfs2(idx,d[i].num);
            idx++;
        }
    }
}
int wake(int i){
    int used2[N]={0};
    rep(j,len[i]) used2[g[i][j]]=1;
    rep(j,len[i]){
        rep(k,n){
            if(used2[k]) continue;
            if(map[k][g[i][j]]) return 0;
        }
    }
    return 1;
}
int main(void){
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        init();
        double p[N]={0};
        rep(i,n){
            double p_;
            int x,y;
            scanf("%lf%d",&p_,&x);
            p[i]=p_;
            rep(j,x){
                scanf("%d",&y);
                map[i][y-1]=1;
            }
        }
        rep(i,n){
            d[i].num=i;
            d[i].post=1;
        }
        dfs_init();
        //printf("%d\n",cnt); rep(i,n) printf("%d ",d[i].post); puts("\n");
        qsort(d,n,sizeof(Data),comp);
        dfs2_init();
        /*rep(i,n){
            if(len[i]==0) continue;
            rep(j,len[i]){
                printf("%d ",g[i][j]);
            }puts("");
        }puts("");*/
        /*rep(i,n){
            rep(j,n){
                printf("%6f ",map[i][j]);
            }puts("");
        }puts("");*/
        double sum=1;
        rep(i,n){
            if(len[i]==0) continue;
            double tmp=1;
            if(wake(i)){
                rep(j,len[i])
                tmp*=p[g[i][j]];
                sum*=(1-tmp);
            }
        }
        printf("%.9f\n",sum);
    }
    
}



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

int main(){
    const double EPS = 1e-12;
    double x[5];
    double y[5];
    double s;
    double t;
    double u;
    double v;
    double m;
    int n;
    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3];

        s = x[1] - x[0];
        t = y[1] - y[0];
        u = x[3] - x[2];
        v = y[3] - y[2];

        if(s * v - t * u > 0){
            m = s * v - t * u;
        }
        else{
            m = t * u - s * v;
        }

        if(m < EPS){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
SC=[]
n,m=map(int,input().split())
if n==1:
      r=range(0,10)
elif n==2:
      r=range(10,100)
else:
      r=range(100,1000)
for _ in range(m):
  s,c=map(int,input().split())
  s-=1
  SC.append((s,c))
for i in r:
      i=str(i)
      for s,c in SC:
            if i[s]!=str(c):
                break
      else:
            print(int(i))
            exit()

print(-1)

Measured memory_bytes: 38392
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    sort(ALL(v));
    ll ans = 0;
    REP(i,n-2) FOR(j,i+1,n-1) {
        auto it = lower_bound(ALL(v),v[i]+v[j]);
        int d = distance(v.begin(),it);
        ans += d-j-1;
    }

    cout << ans << '\n';

    return 0;
}

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

double thirdroot(double x,double q) {
  if(abs(x*x*x - q) < 0.00001 * q) {
    printf("%.6lf\n",x);
  }
  else if(abs(x*x*x - q) >= 0.00001 * q) {
    thirdroot(x - ((x*x*x - q) / (3 * x*x)),q);
  }
}

int main() {
  double q;
  while(cin >> q) {
    if(q == -1) break;
    thirdroot( q / 2.0,q);
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n) upper_bound(v.begin(),v.end(),n)-v.begin()
#define mod 1000000007
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
/*bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}*/
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a);
		}
		b>>=1;
		a=(a*a);
	}
	return ans;
}//prefixsums
void frooty()
{
	l a,b,c;
	cin>>a>>b>>c;
	l k;
	cin>>k;
	if(a<b&&b<c)
	{
		cout<<"Yes"<<"\n";
		return ;
	}
	l x=0;
	while(b<=a)
	{
		b*=2;
		x++;
	}
	while(c<=b)
	{
		c*=2;
		x++;
	}
	if(x<=k)
		cout<<"Yes"<<"\n";
	else
		cout<<"No"<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
	//cin>>q;
	while(q--)
	{
		frooty();
	}
}

Measured memory_bytes: 3644
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include <ctime>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>L(N);
	rep(i,N)cin >> L[i];
	int ans = 0;
	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			for (int k = j + 1; k < N; k++) {
				if (L[i] != L[j] && L[i] != L[k] && L[j] != L[k]) {
					int num = L[i] + L[j] + L[k];
					int mx = max({ L[i], L[j], L[k] });
					num -= mx;
					if (mx < num)ans++;
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int a,b;
bool flag;

bool cmp(char a,char b)
{
    return a > b;
}
bool cmpp(char a,char b)
{
    return a<b;
}
int main() {
    string A,B;
    cin >>A>>B;
    sort(&A[0],&A[A.size()],cmpp);
    sort(&B[0],&B[B.size()],cmp);
    
    
    
    
    if(A<B)
    {
        printf("Yes");
        
    }
    else
    {
        printf("No");
    }
    
    
}
    
    
    
       

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

ll cal(ll x,ll y,ll z)
{
    return max({x,y,z})-min({x,y,z});
}

int main()
{
    ll h,w;
    cin >> h >> w;

    ll ans = 1e18;
    ll s1,s2,s3;
    for(int i = 1; i < h; i++){
        s1 = i*w;
        s2 = (h-i)/2*w;
        s3 = h*w-s1-s2;
        ans = min(ans,cal(s1,s2,s3));
        s2 = (h-i)*(w/2);
        s3 = h*w-s1-s2;
        ans = min(ans,cal(s1,s2,s3));
    }
    for(int i = 1; i < w; i++){
        s1 = h*i;
        s2 = (w-i)*(h/2);
        s3 = h*w-s1-s2;
        ans = min(ans,cal(s1,s2,s3));
        s2 = (w-i)/2*h;
        s3 = h*w-s1-s2;
        ans = min(ans,cal(s1,s2,s3));
    }

    cout << ans << endl;

    return 0;
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int A, B, M;
    ist >> A >> B >> M;

    int a[A], b[B];
    int x[M], y[M], c[M];

    for (int i = 0; i < A; i++)
    {
        ist >> a[i];
    }

    for (int i = 0; i < B; i++)
    {
        ist >> b[i];
    }

    for (int i = 0; i < M; i++)
    {
        ist >> x[i] >> y[i] >> c[i];
    }

    /* ------- 計算 ------- */

    int min_a = 2 * 100000;
    int min_b = 2 * 100000;

    for (int i = 0; i < A; i++)
    {
        min_a = min(min_a, a[i]);
    }

    for (int i = 0; i < B; i++)
    {
        min_b = min(min_b, b[i]);
    }

    int minimum = min_a + min_b;

    for (int i = 0; i < M; i++)
    {
        int price = a[x[i]-1] + b[y[i]-1] - c[i];
        minimum = min(minimum, price);
    }

    ost << minimum << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 2176
import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val l = readInt()
  val history = readLine.trim.split(' ').map(_.toInt).toList
  println(search(history))
  @tailrec def search(history: List[Int], isIn: Array[Boolean] = Array.fill(101){false}, stack: List[Int] = Nil, count: Int = 1): String = {
    history match {
      case Nil ⇒ "OK"
      case h::t if h > 0 ⇒
        if (isIn(h)) count.toString
        else {
          isIn(h) = true
          search(t, isIn, h::stack, count + 1)
        }
      case h::t ⇒
        if (!isIn(-h)) count.toString
        else {
          stack match {
            case s::r if s == -h ⇒
              isIn(s) = false
              search(t, isIn, r, count + 1)
            case _ ⇒ count.toString
          }
        }
    }
  }
}



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

int main(){
  
  int N;
  scanf("%d\n",&N);
  
  int AC=0,WA=0,TLE=0,RE=0;
  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    if( S == "AC"){
        AC++;
    }else if( S == "WA" ){
        WA++;
    }else if( S =="TLE" ){
        TLE++;
    }else if( S =="RE" ){
        RE++;
    }
  }
   
  printf("AC x %d\n", AC );
  printf("WA x %d\n", WA );
  printf("TLE x %d\n", TLE );
  printf("RE x %d\n", RE );  
  return 0;
  
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll s, w;
    cin>>s>>w;
    if(w>=s)
    cout<<"unsafe";
    else
    cout<<"safe";
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3608
//cod2016_qualC_b.cpp
//Sat Nov 10 19:07:40 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int k,t;
	cin >> k >> t;

	int ans = 0;
	int a[t];
	for (int i=0;i<t;i++){
		cin >> a[i];
		if (k%2==0 && a[i]>k/2){
			ans = (a[i]-k/2-1)*2+1;
		}else if (k%2==1 && a[i]>(k-1)/2){
			ans = (a[i]-(k-1)/2-1)*2;
		}
	}

	cout << ans << endl;
}

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

#define MAX_V 100000
#define INF (1<<29)

using namespace std;

vector<int>G[MAX_V];
int par[MAX_V],pnum[MAX_V],lowest[MAX_V],num;
bool used[MAX_V];

void dfs(int v,int prev){
  pnum[v]=num,lowest[v]=num;
  num++;
  used[v]=true;

  for(int i=0;i<G[v].size();i++){
    int nx=G[v][i];
    if(!used[nx]){
      par[nx]=v;
      dfs(nx,v);
      lowest[v]=min(lowest[v],lowest[nx]);
    }
    else if(nx!=prev){
      lowest[v]=min(lowest[v],pnum[nx]);
    }
  }
}

int main(void){

  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  fill(pnum,pnum+MAX_V,INF);
  fill(lowest,lowest+MAX_V,INF);
  fill(used,used+MAX_V,false);

  dfs(0,-1);
  num=1;
  int cnt=0;
  vector<int>ans;
  for(int i=0;i<n;i++){
    if(par[i]==0 && i!=0)cnt++;
    if(par[i]>0 && lowest[i]>=pnum[par[i]])ans.push_back(par[i]);
  }

  if(cnt>=2)ans.push_back(0);
  sort(ans.begin(),ans.end());
  ans.erase(unique(ans.begin(),ans.end()),ans.end());
  for(int i=0;i<ans.size();i++)cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 5908
from collections import Counter
n=int(input())
S=[input() for _ in range(n)]

cnt=Counter(S)
cnt=cnt.most_common()
maxcnt=cnt[0][1]
ans=[]
for i in range(len(cnt)):
  if cnt[i][1]==maxcnt:
    ans.append(cnt[i][0])
  else:
    break
ans.sort()
print(*ans,sep='\n')

Measured memory_bytes: 45032
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int h = 1e9;
	Int s;
	cin >> s;

	Int x = (h - s % h) % h;
	Int y = (s + x) / h;
	cout << "0 0 1000000000 1 " << x << " " << y << endl;

	return 0;
}


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

const int MOD = 1e9 + 7;

int main(){
    int N;
    string S1, S2, arr;
    cin >> N >> S1 >> S2;
    rep(i, N) {
        if (S1[i]==S2[i]) {
            arr += 'X';
        } else {
            arr += 'Y';
            i++;
        }
    }
    ll ans;
    if (arr[0] == 'X') ans = 3;
    else ans = 6;
    for (int i=1; i<N; i++) {
        if (arr[i-1] == 'X' && arr[i] == 'X') {
            ans *= 2;
            ans %= MOD;
        } else if (arr[i-1] == 'X' && arr[i] == 'Y') {
            ans *= 2;
            ans %= MOD;
        } else if (arr[i-1] == 'Y' && arr[i] == 'Y') {
            ans *= 3;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N ,D = map(int, input().split())
X = []
tmp = []
ans = []
fans = 0
for _ in range(N):
    X.append(list(map(int, input().split())))
for i in range(N-1):
    for j in range(i+1, N):
        if D == 1:
            tmp.append((X[i][0]-X[j][0])**2)
        else:
            for k in range(D):
                tmp.append((X[i][k]-X[j][k])**2)
        ans.append(sum(tmp)**0.5)
        tmp = []
for A in ans:
    if A.is_integer():
        fans += 1
print(fans)


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

ll sum(ll n){
  return n*(n+1)/2;
}

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

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))


using namespace std;

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

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, K;
int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> K;
    if (K == 1) cout << 0 << endl;
    else cout << N-K << endl;
}


Measured memory_bytes: 256
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

S=input()
T=input()

def n2l(s):
    seen = {}
    ret = []
    idx = 0
    for ch in s:
        if ch not in seen:
            seen[ch] = idx
            idx += 1
        ret.append(seen[ch])
    return ret

yn(n2l(S)==n2l(T))
    


Measured memory_bytes: 6832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
	int n; cin>>n;
	int t[n],a[n];
	rep(i,n) cin>>t[i];
	rep(i,n) cin>>a[i];
	vector<int> berg(n,INF); berg[0]=berg[n-1]=1;

	for(int i=1;i<n;i++){
		if(t[i]==t[i-1]) berg[i]=min(t[i],berg[i]);
		else{
			if(t[i]>a[i]) berg[i]=0;
			else berg[i]=min(1,berg[i]);
		}
	}
	for(int i=n-2;i>=0;i--){
		if(a[i]==a[i+1]) berg[i]=min(a[i],berg[i]);
		else{
			if(t[i]<a[i]) berg[i]=0;
			else berg[i]=min(1,berg[i]);
		}
	}
	long long ans=1;
	rep(i,n){
		//cout<<berg[i]<<endl;
		ans=ans*berg[i]%MOD;
	}
	if(t[n-1]!=a[0]) ans=0;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    long long ans = 0;
    for(int i=0;i<n-1;i++){
        int cr = 0;
        int cg = 0;
        int cb = 0;
        if(s[i+1]=='R')cr++;
        else if (s[i+1]=='G')cg++;
        else cb++;
        for(int j=i+2;j<n;j++){
            int md = i+j;
            if(s[i]!=s[j]){
                if(s[i]=='R'){
                    if(s[j]=='G'){
                        /// r + g
                        ans+=cb;
                        if(md%2==0 and s[md/2]=='B')ans--;
                    }
                    else{
                        /// r + b
                        ans+=cg;
                        if(md%2==0 and s[md/2]=='G')ans--;

                    }


                }else if(s[i]=='G'){
                if(s[j]=='R'){
                                                /// r + g
                        ans+=cb;
                        if(md%2==0 and s[md/2]=='B')ans--;

                    }
                    else{

                        /// g+b
                        ans+=cr;
                        if(md%2==0 and s[md/2]=='R')ans--;


                    }


                }else{/// b
                if(s[j]=='G'){
                        /// b+g

                        ans+=cr;
                        if(md%2==0 and s[md/2]=='R')ans--;


                    }
                    else{
                                                /// r + g
                        ans+=cg;
                        if(md%2==0 and s[md/2]=='G')ans--;
                    }
                }





            }
            if(s[j]=='R')cr++;
            else if (s[j]=='G')cg++;
            else cb++;
        }
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  int n; cin >>n;
  vector<int> a(n); rep(i, n) cin >>a[i];
  map<int,int> cnt;
  rep(i, n){
    int buf = a[i]; cnt[buf]++;
    // 各番号が何回出てきたかをカウント
  }
  map<int,ll> score;
  // 各番号の番号が取り除かれたとき答えがどれだけ減るかを格納
  ll res = 0;
  for (auto p : cnt){
    int aa = p.first;
    ll b = p.second;
    ll pre = b * (b-1) / 2;
    ll nex = (b-1) * (b-2) / 2;
    score[aa] = pre - nex;
    res += pre;
  }
  rep(i, n){
    int aa = a[i];
    cout <<res - score[aa] <<endl;
  }
}


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

int minCost(int n,int* arr)
{
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    for(int i=2;i<n;i++)
    {
        int option1 = abs(arr[i] - arr[i-1]) + dp[i-1];
        int option2 = abs(arr[i] - arr[i-2]) + dp[i-2];
        dp[i] = min(option1,option2);
    }
    cout<<endl;

    return dp[n-1];
    
}

int main() 
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    cout<<minCost(n,arr);
    return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N, &S)
	r, g, b := 0, 0, 0
	for _, v := range S {
		if v == 'R' {
			r++
		} else if v == 'G' {
			g++
		} else {
			b++
		}
	}
	all := r * g * b
	sub := 0
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			if S[i] == S[j] {
				continue
			}
			k := j*2 - i
			if k >= N || S[k] == S[i] || S[k] == S[j] {
				continue
			}
			sub++
		}
	}
	fmt.Println(all - sub)

}


Measured memory_bytes: 1820
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) s=s*10+ch-'0',ch=getchar();
	return s;
}
typedef long long ll;
const int N=1e5+5;
int n;
int a[N];
ll b[N];
ll s[2];
ll S=0;
int main(){
	n=read();
	for(int i=1;i<=n;i++) {
		a[i]=read(),S+=a[i];
		if(i&1) s[1]+=a[i];
		else s[0]+=a[i];
	}
	b[1]=s[1]-S/2;
	for(int i=1;i<=n;i++) if(i==1) printf("%lld ",2*b[i]);
	else {b[i]=a[i-1]-b[i-1];printf("%lld ",2*b[i]);}

	return 0;
}


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

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

	N %= 26;
	rep(i, S.size()) {
		S[i] += N;
		if(S[i] > 'Z') S[i] -= 26;
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy


class UnionFind:

    def __init__(self, n: int):
        self._n = n
        self._parents = [i for i in range(n)]
        self._size = [1 for _ in range(n)]

    def unite(self, x: int, y: int) -> None:
        px = self.find(x)
        py = self.find(y)

        # 一致していないときはリンクをつける
        if px != py:
            self._link(px, py)

    def _link(self, x: int, y: int):
        if self._size[x] < self._size[y]:
            self._parents[x] = y
            self._size[y] += self._size[x]
        else:
            self._parents[y] = x
            self._size[x] += self._size[y]

    def same(self, x: int, y: int) -> bool:
        px = self.find(x)
        py = self.find(y)
        return px == py

    def find(self, x: int) -> int:
        if self._parents[x] == x:
            return x

        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def size(self, x: int):
        return self._size[self.find(self._parents[x])]

N, K, L = map(int, input().split())

road = UnionFind(N + 1)
rail = UnionFind(N + 1)
share = UnionFind(N + 1)

roads = [list(map(int, input().split())) for _ in range(K)]
rails = [list(map(int, input().split())) for _ in range(L)]

for i in range(K):
    p, q = roads[i]
    road.unite(p, q)

for i in range(L):
    r, s = rails[i]
    rail.unite(r, s)

m = {}

for i in range(1, N + 1):
    cnt = m.get((road.find(i), rail.find(i)), 0)
    m[(road.find(i), rail.find(i))] = cnt + 1

ans = [0] * N
for i in range(N):
    ans[i] = m[(road.find(i + 1), rail.find(i + 1))]

print(*ans)

Measured memory_bytes: 101292
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll MOD=1000000007;
int main(){
	vi fact(610);
	fact[0]=1;
	for(int i=2;i<610;i+=2)fact[i]=fact[i-2]*(i-1)%MOD;
	
	ll n,k;
	cin>>n>>k;
	vvi in(k,vi(2));
	rep(i,k)rep(j,2)cin>>in[i][j];
	vi used(2*n+1);
	rep(i,k)rep(j,2)used[in[i][j]]=1;
	rep(i,2*n)used[i+1]+=used[i];
	vvi dp(2*n,vi(2*n));
	ll out=0;
	// show1d(used);
	rep(i,2*n)for(int j=i-1;j>=0;j--)if((i-j)%2){//[j,i]
		bool h=true;
		rep(l,k){
			int s=j<=in[l][0]-1&&in[l][0]-1<=i,t=j<=in[l][1]-1&&in[l][1]-1<=i;
			if(s+t==1)h=false;
		}
		if(!h)continue;
		ll sum=fact[i-j+1-(used[i+1]-used[j])];
		// cout<<sum<<endl;
		loop(l,j+1,i)(sum+=MOD-dp[l][i]*fact[l-j-(used[l]-used[j])]%MOD)%=MOD;
		dp[j][i]=sum;
		// cout<<j<<" "<<i<<" "<<sum<<endl;
		(out+=sum*fact[2*n-(i-j+1)-(2*k-used[i+1]+used[j])]%MOD)%=MOD;
	}
	cout<<out<<endl;
}














Measured memory_bytes: 3072
import collections
N=int(input())
def prime_factorize(n):
    a = []
    b=[]
    c=[]
    d=[]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    for z in a:
        if not z in b:
            b.append(z)
    for z in b:
        c.append(a.count(z))
    for z in range(len(c)):
        for y in range(1,c[z]+1):
            d.append(b[z]**y)
    d=sorted(d)
    number=N
    answer=0
    for z in d:
        if number%z==0:
            number=int(number/z)
            answer+=1
    return answer
if N==1:
    print(0)
else:
    print(prime_factorize(N))
    

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<int> tabeta(n), manzokudo(n), tuika(n - 1);
  rep(i, n) {
    cin >> tabeta[i];
    tabeta[i]--;
  }
  rep(i, n) { cin >> manzokudo[i]; }
  rep(i, n - 1) { cin >> tuika[i]; }

  int manzoku = 0;
  for (int i = 0; i < n; i++) {
    manzoku += manzokudo[tabeta[i]];
    if (i > 0 && tabeta[i] == tabeta[i - 1] + 1) {
      manzoku += tuika[tabeta[i - 1]];
    }
  }
  cout << manzoku;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  string S,T;
  cin >> S >> T;
  int A,B; cin >> A >> B;
  string U; cin >> U;
  if(U.compare(S) == 0) A--;
  else B--;
  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007
#define mod 1000003
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(a,b) for (int i = a ; i < b ; i++)
#define PI 3.1415926536

using namespace std ;

int main(){

    ios_base::sync_with_stdio(0);
    ll sum = 0 ;
    int n ;
    cin >> n ;
    while (n--){
        ll x ;
        cin >> x ;
        while( x % 2 == 0 ){
                sum++;
        x/=2 ;

        }
    }
    cout << sum ;
    return 0 ;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

struct  UndirectedGraph{
   vector<vector<int>> g;
   vector<int> clr;
   vector<int> dis;
   int V;

   UndirectedGraph(int V) : V(V),
   g(vector<vector<int>>(V)),
   clr(vector<int>(V,0))
   {}
 
   //don't add (v,u) after adding (u,v)
   void add_edge(int u,int v){
       g[u].push_back(v);
       g[v].push_back(u);
   }
 
 
   //dfs for judging bipartite
   bool dfs_nib(int v,int c){
       clr[v]=c;
       for(auto x:g[v]){
           if(clr[x]==c) return false;
           if(clr[x]==0 && !dfs_nib(x,-c) ) return false;
       }
       return true;
   }
   bool isBipartite(){
       bool ret=true;
       for(int i=0;i<V;i++)if(clr[i]==0){
           if(!dfs_nib(i,1)){
               ret=false;break;
           }
       }
       return ret;
   }
 
   //distance
   void bfs(int st){
       dis=vector<int>(V,INF);
       vector<bool> checked(V,false);
       dis[st]=0;checked[st]=true;
       queue<int> q;
       q.push(st);
       while(!q.empty()){
           auto now=q.front();q.pop();
           for(auto x:g[now]){
               if(checked[x]) continue;
               checked[x]=true;
               dis[x]=dis[now]+1;
               q.push(x);
           }
       }
   }

   vector<int> color(){
       return clr;
   }
};

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

    ll n,m;cin>>n>>m;
    UndirectedGraph g(n);
    rep(i,m){
        int u,v;cin>>u>>v;u--,v--;
        g.add_edge(u,v);
    }
    if(g.isBipartite()){
        ll l=0,r=0;
        auto v=g.color();
        for(auto c:v){
            if(c==-1) l++;
            else      r++;
        }
        cout<<l*r-m<<endl;
    }else{
        cout<<n*(n-1)/2-m<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int bitcount(int val)
{
  int ret = 0;
  while (val > 0) {
    ret += (1 & val);
    val >>= 1;
  }
  return ret;
}

int main()
{
  int N; scanf("%d", &N);
  vector<int> shops(N, 0);
  int val = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 9; j >= 0; --j) {
      scanf("%d", &val);
      shops[i] |= (val << j);
    }
  }
  vector<vector<int> > P(N, vector<int>(11, 0));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= 10; ++j) {
      scanf("%d", &P[i][j]);
    }
  }
  int ans = -INF;
  for (int pat = 1; pat < (1 << 10); ++pat) {
    int sum = 0;
    for (int i = 0; i < N; ++i) {
      int cnt = bitcount(shops[i] & pat);
      sum += P[i][cnt];
    }
    ans = max(ans, sum);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256