akhauriyash/Code-Regression huggingface dataset:
//ABC149 C

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint x;


int main() {
  cin >> x;
  
  
  reps(i,x,x*2){
    bool flag = true;
    reps(j,2,i){
      if(i%j == 0){
        flag = false;
      }
    }
    if(flag){
      printf("%d\n",i);
      return 0;
    }
  }

  //printf("%lld %lld\n",a,b);
}


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

int main() {
    int n;
    cin >> n;
    int cnt=0;
    for(int i=1; i<=n; i+=2){
        int div=0;
        //cout << i << endl;
        for(int j=1; j<sqrt(i); j++){
            if(i%j==0) div++;
        }
        if(div==4) cnt++;
        //cout << div << endl;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,m;
  cin >> n >> m;
  long long a[m],b[m];
  string ans[m];
  pair<pair<long long, long long>, int> p[m];
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
    p[i]=make_pair(make_pair(a[i],b[i]), i);
    ans[i]="";
  }
  sort(p,p+m);
  long long cnt=0,tmp=0;
  for(int i=0;i<m;i++){
    string l,r;
    if(tmp!=p[i].first.first){
      tmp=p[i].first.first;
      cnt=0;
    }
    cnt++;
    l=to_string(p[i].first.first);
    r=to_string(cnt);
    for(int j=0;j<6-l.size();j++){
      ans[p[i].second]+="0";
    }
    ans[p[i].second]+=l;
    for(int j=0;j<6-r.size();j++){
      ans[p[i].second]+="0";
    }
    ans[p[i].second]+=r;
  }
  for(int i=0;i<m;i++){
    cout << ans[i] << endl;
  }
  return 0;
}


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

int n,cnt;
int a[10005]={0};
double av,sum;

int main(){
  int i;
  while(1){
    cin >> n;
    if(n==0)break;
    sum = 0;
    cnt = 0;
    for(i=0;i<n;i++){
      cin >> a[i];
      sum += a[i];
    }
    av = sum/n;
    for(i=0;i<n;i++){
      if(av>=a[i])cnt++;
    }
    cout << cnt << endl;
  }
    
  return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <random>
using namespace std;

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

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

int main(){
	ll a,b,ans;
	scanf("%lld%lld",&a,&b);
	ans = 0;
	for(ll t=a;t<=b;t*=2){
		ans++;
	}
	printf("%lld\n",ans);
}













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

const int END = -1;
struct StNod
{
  int m_nKey;
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
    m_nKey(END), m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

void fnInput(vector<StNod> &rvoNod)
{
  StNod oNod;
  int nMaxSiz;

  cin >> nMaxSiz;
  rvoNod.resize(nMaxSiz, oNod);

  for (int i = 0; i < nMaxSiz; i++)
  {
    int nKey, nLeft, nRigt;
    cin >> nKey >> nLeft >> nRigt;

    rvoNod[nKey].m_nKey  = nKey;
    rvoNod[nKey].m_nLeft = nLeft;
    rvoNod[nKey].m_nRigt = nRigt;
    if (nLeft != END) rvoNod[nLeft].m_nParnt = nKey;
    if (nRigt != END) rvoNod[nRigt].m_nParnt = nKey;
  }
}

void fnPreOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  cout << " " << nx;
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnInOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  cout << " " << nx;
  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnPostOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
  cout << " " << nx;
}

void fnTreeWalk(const vector<StNod> &cnrvoNod)
{
  int nx = 0;
  while (cnrvoNod[nx].m_nParnt != END)
    nx = cnrvoNod[nx].m_nParnt;

  cout << "Preorder" << endl;
  fnPreOrder(cnrvoNod, nx);
  cout << endl;

  cout << "Inorder" << endl;
  fnInOrder(cnrvoNod, nx);
  cout << endl;

  cout << "Postorder" << endl;
  fnPostOrder(cnrvoNod, nx);
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StNod> voNod;

  fnInput(voNod);
  fnTreeWalk(voNod);
  return 0;
}

Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum=0,index=0,ans=99999;
  rep(i,n) {
    cin >> a[i];
    sum+=a[i];
  }

  rep(i,n){
    if(abs(sum-a[i]*n)<ans){
      chmin(ans,abs(sum-a[i]*n));
      index=i;
    }
  }
  cout << index << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int N, X;
    int m[100];
    
    
    cin >> N >> X;
    int num = N;
    int min = 100000;
    
    for(int i = 0; i < N; i++){
        cin >> m[i];
        if (min > m[i]) min = m[i];
        X -= m[i];
    }
    
    while(X >= min) {
        X -= min;
        num++;
    }

    
    cout << num;
    
    
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

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

    ll N;
    cin >> N;

    if (N%2 == 0) {
        cout << N << endl;
    } else {
        cout << N*2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
char s[111],t[111];
cin>>n;
  cin>>s>>t;
 
  
 // n=strlen(s);
  char a[221];
for(int i=0;i<n;i++)
{
cout<<s[i]<<t[i];
}

 
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int m[1000][1000];
typedef struct point{
	int x,y;
}POINT;
POINT q[3000],sq[3000];
int qn,sqn;
int main(){
	int i,j,t,n,x,y,ans;
	int dx[]={0,1,-1,1,-1,0},dy[]={1,1,0,0,-1,-1};
	while(1){
		scanf("%d%d",&t,&n);
		if(t==0 && n==0)break;
		memset(m,0,sizeof(m));
		for(i=0;i<n;i++){
			scanf("%d%d",&x,&y);
			m[y+300][x+300]=2;
		}
		scanf("%d%d",&x,&y);
		q[0].x=x+300,q[0].y=y+300;
		qn=1;sqn=0;ans=1;m[y+300][x+300]=1;
		while(t--){
			for(i=0;i<qn;i++){
				for(j=0;j<6;j++){
					if(m[q[i].y+dy[j]][q[i].x+dx[j]]==0){
						m[q[i].y+dy[j]][q[i].x+dx[j]]=1;
						sq[sqn].y=q[i].y+dy[j];
						sq[sqn].x=q[i].x+dx[j];
						sqn++;
						ans++;
					}
				}
			}
			qn=sqn;
			memcpy(q,sq,sizeof(POINT)*qn);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4368
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long

signed main(){
  

    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    int ans=INF;

    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    int x_count=-1;
    int y_count=-1;

    for(int i=0;i<=200000;i+=2){

        int tmp=0;

        x_count++;
        y_count++;

        // cout<<x_count<<" "<<y_count<<endl;

        int tmp_a=max(x-x_count,0);
        int tmp_b=max(y-y_count,0);





        // cout<<i<<" "<<x_count<<" "<<y_count<<" "<<tmp_a<<" "<<tmp_b<<endl;

        tmp=i*c+tmp_a*a+tmp_b*b;
        ans=min(ans,tmp);
        // cout<<ans<<endl;

    }

    cout<<ans<<endl;

    return 0;

}

// 97501500
// 100000000
// 103749000

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 200005
template<class T> ostream& operator<<(ostream &s,pair<T,ll> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
int main()
{
    fastread;
    ll T=1;
//    cin>>T;
    for(ll qq=1;qq<=T; qq++)
    {
        ll n;
        cin>>n;
        vii v(n);
        for(int i=0;i<n;i++)
        {
            cin>>v[i].fi;
            v[i].se=i;
        }
        sort(v.begin(),v.end());
        ll ans=1;
        ll l=0;
        for(int i=1;i<n;i++)
        {
            if(v[i].se<v[i-1].se)ans=max(ans,i-l),l=i;
        }
        ans=max(ans,n-l);
        cout<<n-ans<<endl;
    }
}

Measured memory_bytes: 3456
n,k,*l=map(int,open(0).read().split())
for _ in range(k):
  s=[0]*(n+1)
  for i in range(n):
    s[max(i-l[i],0)]+=1
    s[min(i+l[i]+1,n)]-=1
  s[0]=min(s[0],n)
  for i in range(1,n):
    s[i]=min(s[i-1]+s[i],n)
  if s==l: break
  l=s
print(*l[:n])

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

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}

ll f(ll val){
  ll res=0;
  cerr<<"val = "<<val<<endl;
  if(val==0){
    return res;
  }
  for(int i=1;i<64;i++){
    ll pow2=1LL<<i;
    cerr<<"pow2 = "<<pow2<<endl;
    if(val<pow2/2){
      break;
    }
    ll biti=(val/pow2*(pow2/2)+max(0LL,val%pow2-(pow2/2-1)))%2;
    res|=(biti<<(i-1));
  }
  cerr<<endl;
  cerr<<"res = "<<res<<endl;
  return res;
}
int main() {
  ll a,b;cin>>a>>b;
  ll ans=f(a-1)^f(b);
  cout<<ans<<endl;
  return 0;
}


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

int main(){
	string s;
	int a,b;
	for(int i = 0; i < 9; i++){
		cin >> s >> a >> b;
		cout << s << " " << a + b << " " << 200 * a + 300 * b << endl;
	}
	return 0;
}



Measured memory_bytes: 3132
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<numeric>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_ll = pair<ll, ll>;
int main() {
	int A, P; cin >> A >> P;
	cout << (A * 3 + P) / 2 << endl;

	cin >> A;
}

Measured memory_bytes: 256
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
--import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  s <- getLine
  putStrLn $ if n >= 3200 then s else "red"


Measured memory_bytes: 508
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
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 void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int n, ans = 0;

void dfs(int depth, bool flg, VI& A)
{
  if (depth > n)
  {
    if (flg) ++ans;
    return;
  }
  REP2(int, i, -1, 2) dfs(depth+1, (flg || (A[depth-1]+i)%2==0), A);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  VI A(n);
  INPUT(A);
  dfs(1, false, A);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pi          pair<ll,ll>
#define pii         pair<string,pi>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;
   bool cmp(const pii &a,
              const pii &b)
{ 
  if(a.first==b.first)
    return (a.second.F > b.second.F);
  return (a.first<b.first);
}

void solve()
{
 string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n;

  pii a[n];
  for (ll i = 0; i < n; ++i)
  {
      cin>>s>>x;
      a[i] = {s,{x,i+1}};

  }
  sort(a,a+n,cmp);
 for (int i = 0; i < n; ++i)
 {

   cout<<a[i].S.S<<"\n";
  }
}

signed main(){
   
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<Integer> List = new ArrayList<>();
		int n = sc.nextInt();
		int[] List = new int[n];
		
		for(int i=0;i<n;i++) 
				List[i] = sc.nextInt();
		
		for(int i=0;i<List.length;i++) {
			if(i == 0) {
				System.out.print(List[i]);
			}else {
				if(List[i - 1] != List[i]) {
					System.out.print(" " + List[i]);
				}
			}
			
			
		}
		System.out.println();
	}
}


Measured memory_bytes: 71264
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    int a = 0;
    for(char c : s) {
        if(a == 0 and c == 'C') a++;
        if(a == 1 and c == 'F') a++;
    }
    cout << ( a == 2 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int k=38,n=k*(k-1)+1;
int main()
{
	cout<<n<<" "<<k<<"\n";
	for(int i=1;i<n;i+=k-1)
	{
		cout<<1<<" ";
		for(int j=0;j<k-1;++j)
			cout<<i+j+1<<" ";
		cout<<"\n";
	}
	for(int r=1;r<k;++r)
	{
		for(int s=0;s<k-1;++s)
		{
			cout<<r+1<<" ";
			int p=s;
			for(int g=k;g<n;g+=k-1,p=(p+r)%(k-1))
				cout<<g+p+1<<" ";
			cout<<"\n";
		}
	}
}


Measured memory_bytes: 512
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    cin>>n;
    vi v(n),dp(n);
    rep(i,n){
        cin>>v[i];
        dp[i]=1;
    }
    sort(rall(v));
    int ans=0;
    for(int i=n-1;i>=0;i--){
        for(int j=i+1;j<n;j++){
            if(v[i]>v[j])dp[i]=max(dp[i],dp[j]+1);
        }
        ans=max(ans,dp[i]);
    }
    cout<<ans<<enl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll n;
    cin >> n;
    vector<ll> L(100, 0);
    L[0] = 2;
    L[1] = 1;
    rep2(i, 2, 100) {
      L[i] += L[i-1] + L[i-2];
    }
    cout << L[n] << endl;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
trees = []
for i in range(N):
    h = int(input())
    trees.append(h)
trees = list(sorted(trees))
ans = 10000000000
for q in range(N-K+1):
    ans = min(ans,trees[q+K-1]-trees[q])
print(ans)
    

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }

ll k;
void solve() {
    cin >> k;

    cout << 50 << endn;
    rep(i, 50) {
        ll res = k / 50 + 49;
        if (i < k % 50) res += 51;
        res -= k % 50;
        cout << res << " ";
    }
    cout << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    solve();

    cout << flush;

    return 0;
}


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

int main(){
    bool A=1;
    while(A){
        int H,W;
        cin >> H >> W;
        if (H==0 && W==0) {A=0;}
        else {
            for (int k=0; k<W; k++) {
                cout << "#";
                if (k==W-1) {cout << endl;}
            }
            for(int i=0; i<H-2; i++){
                cout << "#";
                for(int j=0; j<W-2; j++){
                    cout << ".";
                }
                cout << "#" << endl;
            }
            for (int k=0; k<W; k++) {
                cout << "#";
                if (k==W-1) {cout << endl;}
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3080
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 1<<20, mod = 924844033;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll i, o, t, j, l, s, z;
	cin >> i>> o >> t >> j >> l >> s >> z;
	ll o1 = o;
	o += (i/2)*2 + 2*(j/2) + 2*(l/2);
	o += 3*(i&j&l&1);
	if(i&&j&&l) o1 += 3, i--,j--,l--;
	o1 += (i/2)*2 + 2*(j/2) + 2*(l/2);
	cout << max(o, o1);
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int A,B;
string S;
inline void solve(){
  IN3(A,B,S);
  if(count(ALL(S),'-')!=1||S[A]!='-')OUT("No");
  else OUT("Yes");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

class Main {
	public static void main(String[] args) throws Exception{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String[] strAry = br.readLine().split(" ");
		int w = Integer.parseInt(strAry[0]);
		int h = Integer.parseInt(strAry[1]);
		int x = Integer.parseInt(strAry[2]);
		int y = Integer.parseInt(strAry[3]);
		int r = Integer.parseInt(strAry[4]);
		if (r <= x && x <= (w - r) && r <= y && y <= (h - r)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24272
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int main() {
	cin >> N;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (abs(v[i] - v[j]) % (N - 1) == 0) {
				cout << v[i] << " " << v[j] << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int n, slen, tlen;
int a[maxn], b[maxn], S[maxn], T[maxn], Next[maxn];
void getNext()
{
    int j, k;
    j = 0; k = -1; Next[0] = -1;
    while(j < tlen)
        if(k == -1 || T[j] == T[k])
            Next[++j] = ++k;
        else
            k = Next[k];
}
int KMP_Count()
{
    int ans = 0;
    int i, j = 0;

    if(slen == 1 && tlen == 1)
    {
        if(S[0] == T[0])
            return 1;
        else
            return 0;
    }
    getNext();
    for(i = 0; i < slen; i++)
    {
        while(j > 0 && S[i] != T[j])
            j = Next[j];
        if(S[i] == T[j])
            j++;
        if(j == tlen)
        {
        	printf("%d %d\n", i - n + 1, a[i - n + 1] ^ b[0]);	
            ans++;
            j = Next[j];
        }
    }
    return ans;
}
int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	a[n] = a[0];
	for(int i = 0; i < n; ++i) scanf("%d", &b[i]);
	b[n] = b[0];
	for(int i = 0; i < n; ++i) S[i] = a[i] ^ a[i + 1];
	for(int i = 0; i < n; ++i) T[i] = b[i] ^ b[i + 1];
	for(int i = n; i < (n << 1) - 1; ++i) S[i] = S[i - n];
	slen = (n << 1) - 1; tlen = n;
	KMP_Count();
	/*
	for(int i = 0; i < slen; ++i) cout << S[i] << ' ';
	puts("");
	for(int i = 0; i < tlen; ++i) cout << T[i] << ' ';
	puts(""); 
	printf("%d\n", KMP_Count());
	*/
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;
 
int main() {
  int N, M, A[60]={0}, B[60]={0}, K[60]={0};
  cin >> N >> M;
  for(int i=0; i<M; ++i){
    cin >> A[i] >> B[i];
  } 
  for(int i=0; i<M; ++i){
    ++K[A[i]];
    ++K[B[i]];
  }
  for(int i=1; i<=N; ++i){
    cout << K[i] << endl;
  }
}



Measured memory_bytes: 256
function main(s) {
	s = s.split("\n")[0];
	var z = true;
	for (var i = 2; i < s.length; i += 2) {
		for (var j = 0; j < (s.length - i) / 2; ++j) {
			if (s[j] != s[j + (s.length - i) / 2]) {z =false; break;}
		}
		if (z) {console.log("%d", s.length - i); return}
		z = true;
	}
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 20552
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;


bool is_possible(int arr[] , int n , int cuts , int len){


    int curr = 0;

    // db

    for(int i= 0 ;i<n ; i++){
        // db(i);
        curr += arr[i]/len;
        curr+= (arr[i]%len == 0 ? -1 : 0);
    }

    return curr<=cuts;

}

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n>>a;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum = max(sum , arr[i]);
    }

    int start = 1   ,end = sum;

    while(start <=end){

        int mid = (start + end)/2;

        if(is_possible(arr , n, a , mid)){

            ans  = mid;

            end = mid - 1;

        }

        else{

            start = mid + 1;
        }
    }

    cout<<ans<<endl;  
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 5112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		if (n>k) {
			System.out.println(k*x + (n-k)*y);		
		} else {
			System.out.println(n*x);
		}
	}		
}

Measured memory_bytes: 23636
# include <bits/stdc++.h>
#include <iostream>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
const int maxn = 23000000;
short dig[maxn+1];
inline void add(int &x, int y)
{
    x+=y;
    if(x>=mod) x-=mod;
}
int qmod(LL a, int b)
{
    LL res = 1;
    for(;b;b>>=1)
    {
        if(b&1) res=res*a%mod;
        a=a*a%mod;
    }
    return (int)res;
}
int main()
{
    for(int i=1; i<=maxn; ++i) dig[i] = dig[i/10]+1;
    int n, ans=0;
    scanf("%d",&n);
    for(int i=1, j=1, s=0; i<1e7; ++i)
    {
        while(s<n) s+=dig[j],++j;
        if(s==n) add(ans, 1);
        s -= dig[i];
    }
    for(int i=1; i<=n/8; ++i)
    {
        if(n%i==0) add(ans, ((qmod(10,n/i)-qmod(10,n/i-1)-i+1)%mod+mod)%mod);
        else add(ans, 1);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 45184
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;

int main(){
  string s; cin >>s;
  int n=s.length();

  if(n==1) {cout<<0<<endl; return 0;}
  else
  {
    int cnt1=0,cnt2=0;
    for(int i=0;i<n;i++){
      if(i%2==0 && s[i]=='1') cnt1++;
      else if(i%2==1 && s[i]=='0') cnt1++;
    }
    for(int i=0;i<n;i++){
      if(i%2==0 && s[i]=='0') cnt2++;
      else if(i%2==1 && s[i]=='1') cnt2++;
    }

    cout<<min(cnt1,cnt2)<<endl;

  }
  }


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


// factorial(階乗)の計算
const int N_MAX = 10000000;
ll fac[N_MAX+1] ={};
ll c_fac(int n=N_MAX) {
    if (fac[n]!=0) return fac[n];
    if (n==0) return fac[n]=1;
    return fac[n] = (c_fac(n-1)*n)%MOD;
}

// inverse(逆元)の計算
ll inv(ll a,ll m) {
    ll b = m, x = 1, y = 0;
    while (b!=0) {
        ll d = a/b;
        a -= b*d; swap(a, b);
        x -= y*d; swap(x, y);
    }
    return x>=0 ? x : x+m;
}

// combinataionの計算
ll nck(ll n, ll k) { 
    c_fac(n);
    if (n<k) return 0;
    ll nume = fac[n];
    ll deno = ( inv(fac[n-k],MOD) * inv(fac[k],MOD) ) % MOD;
    return ( nume * deno ) % MOD;
}


int main() {
    int X, Y;
    cin >> X >> Y;
    
    if ((X + Y) % 3 != 0 || 2 * X - Y < 0 || 2 * Y - X < 0) {
        cout << 0 << endl;
        return 0;
    }

    int n = (2 * X - Y) / 3;
    int m = (2 * Y - X) / 3;

    cout << nck(n+m, n) << endl;
    return 0;
}

Measured memory_bytes: 16768
from sys import stdin

def main():
    n = int(input())
    A = [int(x) for x in stdin.readline().rstrip().split()]

    humidai = 0
    pre_a = 0
    for a in A:
        if pre_a > a:
            humidai += pre_a -a 
        else:
            pre_a = a

    print(humidai)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 32188
#include<stdio.h>
#define NUM 2000



int solve(int,int);
int a[NUM],mi[NUM],n;

int main(){
  int i,q;
 

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
  }

  for(i=0;i<q;i++){
    if((solve(0,mi[i]))==1){
      printf("yes\n");
    }
    else printf("no\n");
  }
  

  

  return 0;
}


int solve(int i,int m){
  int res;
  if(m==0) return 1;

  if(i>=n) return 0;

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



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

int main() {
  vector<char> S(3);
  int M=700;
  for(int i=0; i<3; i++){
    cin>>S.at(i);
  if(S.at(i)=='o')
    M+=100;
  }
  cout<<M<<endl;
}

Measured memory_bytes: 256
import itertools

class UnionFind:
    def __init__(self, size):
        self.parent = [-1] * (size + 1)  # 非負なら親ノード，負ならグループの要素数

    def root(self, x):  # root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        elif self.parent[self.parent[x]] < 0:
            return self.parent[x]
        else:
            self.parent[x] = self.root(self.parent[x])  # xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y):  # merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]:  # xの要素数がyの要素数より「小さい」とき入れ替える
            x, y = y, x
        self.parent[x] += self.parent[y]  # xの要素数を更新
        self.parent[y] = x  # yをxにつなぐ
        return True

    def issame(self, x, y):  # same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)

    def size(self, x):  # size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]

import collections
N,K,L = list(map(int,input().split(" ")))
tree1 = UnionFind(N)
tree2 = UnionFind(N)
anss = collections.defaultdict(lambda :0)
querys = []
for _ in range(K):
    p,q = map(int,input().split(" "))
    tree1.merge(p,q)
for _ in range(L):
    r, s = map(int, input().split(" "))
    tree2.merge(r, s)

for i in range(1,N + 1):
    anss[(tree1.root(i),tree2.root(i))] += 1
temp = [0] * (N + 1)
for i in range(1,N + 1):
    temp[i] =  anss[(tree1.root(i),tree2.root(i))]
print(*temp[1:])



Measured memory_bytes: 42524
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;

int main() {
  int n;
  string s;
  int next=1;
  int ans=0;
  cin >> n >> s;

  for(int i=0;i<n;i++){
    for(int j=1;j<n;j++){
      if(s[i]==s[i+j]){
        continue;
      }
      else{
        ans++;
        i=i+j;
        i--;
        break;
      }
    }
  }
  if (n==1){
    ans=1;
  }

  cout << ans << endl;


  return 0;
}

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

int main() {

  while( true ) {
  long long int n, m, c_max, s, g;
  cin >> n >> m >> c_max >> s >> g;
  if ( n == 0 ) break;

  long long int l[101][101][21] = {0};

  for ( long long int i = 0; i < m; i++ ) {

    long long int x, y, d, c;
    cin >> x >> y >> d >> c;
    if ( l[x][y][c] == 0 ) {
      l[x][y][c] = d;
    }else {
      l[x][y][c] = min( l[x][y][c], d );
    }
    if ( l[y][x][c] == 0 ) {
      l[y][x][c] = d;
    }else {
      l[y][x][c] = min( l[y][x][c], d );
    }

  }

  for ( long long int i = 0; i <= n; i++ ) {
    for ( long long int j = 0; j <= n; j++ ) {
      l[i][j][0] = -1;
    }
  }

  long long int p[21];
  for ( long long int i = 1; i <= c_max; i++ ) {
    cin >> p[i];
  }
  long long int q[21][51], r[21][51];
  for ( long long int i = 1; i <= c_max; i++ ) {
    for ( long long int j = 0; j < p[i] - 1; j++ ) {
      cin >> q[i][j];
    }
    q[i][p[i]-1] = 1000000;
    for ( long long int j = 0; j < p[i]; j++ ) {
      cin >> r[i][j];
    }
  }

  for ( long long int i = 1; i <= c_max; i++ ) {

    for ( long long int x = 1; x <= n; x++ ) {

      bool flag[101] = {};

      long long int ds[101] = {0};
      for ( long long int j = 0; j <= n; j++ ) {
	ds[j] = -1;
      }
      ds[x] = 0;

      while( true ) {
	long long int nex = -1;
	for ( long long int j = 0; j <= n; j++ ) {
	  if ( ds[j] >= 0 && flag[j] == false ) {
	    if ( nex == -1 ) {
	      nex = j;
	    }else if ( ds[j] < ds[nex] ) {
	      nex = j;
	    }
	  }
	}
	if ( nex == -1 ) break;
	for ( long long int j = 0; j <= n; j++ ) {
	  if ( l[nex][j][i] > 0 ) {
	    if ( ds[j] == -1 || ds[j] > ds[nex] + l[nex][j][i] ) {
	      flag[j] = false;
	      ds[j] = ds[nex] + l[nex][j][i];
	    }
	  }
	}
	flag[nex] = true;
      }
      for ( long long int j = 0; j <= n; j++ ) {
	if ( ds[j] > 0 ) {
	  long long int w = 0;
	  long long int wl = ds[j];
	  for ( long long int k = 0; true; k++ ) {
	    if ( ds[j] <= q[i][k] ) {
	      w += r[i][k] * wl;
	      break;
	    }
	    if ( k == 0 ) {
	      w += r[i][k] * q[i][0];
	    }else {
	      w += r[i][k] * ( q[i][k] - q[i][k-1] );
	    }
	    wl = ds[j] - q[i][k];
	  }
	  if ( l[j][x][0] == -1 ) {
	    l[j][x][0] = w;
	  }else {
	    l[j][x][0] = min( l[j][x][0], w );
	  }
	  if ( l[x][j][0] == -1 ) {
	    l[x][j][0] = w;
	  }else {
	    l[x][j][0] = min( l[x][j][0], w );
	  }
	}
      }

    }

  }

    bool flag[101] = {};

    long long int ds[101] = {0};
    for ( long long int j = 0; j <= n; j++ ) {
      ds[j] = -1;
    }
    ds[s] = 0;

  while( true ) {
    long long int nex = -1;
    for ( long long int j = 0; j <= n; j++ ) {
      if ( ds[j] >= 0 && flag[j] == false ) {
	if ( nex == -1 ) {
	  nex = j;
	}else if ( ds[j] < ds[nex] ) {
	  nex = j;
	}
      }
    }
    if ( nex == -1 ) break;
    for ( long long int j = 0; j <= n; j++ ) {
      if ( l[nex][j][0] > 0 ) {
	if ( ds[j] == -1 || ds[j] > ds[nex] + l[nex][j][0] ) {
	  flag[j] = false;
	  ds[j] = ds[nex] + l[nex][j][0];
	}
      }
    }
    flag[nex] = true;
  }

  cout << ds[g] << endl;

  }

  return 0;

}

Measured memory_bytes: 2856
#include<stdio.h>
int N,i,l,r,p;
int G[30][2],pc[30]={0};
 
char S[4][100]={"Preorder","Inorder","Postorder"};
 
void pre(int n)
{
    if(n==-1)return;
    printf(" %d",n);
    pre(G[n][0]);
    pre(G[n][1]);
    return;
}
 
void ino(int n)
{
    if(n==-1)return;
    ino(G[n][0]);
    printf(" %d",n);
    ino(G[n][1]);
    return;
}
 
void pos(int n)
{
    if(n==-1)return;
    pos(G[n][0]);
    pos(G[n][1]);
    printf(" %d",n);
    return;
}
 
 
 
int main()
{
    void (*funcs[])(int)={pre,ino,pos};
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d%d%d",&p,&l,&r);
        pc[l]=pc[r]=1;
        G[p][0]=l;
        G[p][1]=r;
    }
    for(i=0;i<N;i++)if(!pc[i])p=i;
    for(i=0;i<3;i++)
    {
        puts(S[i]);
        (*(funcs[i]))(p);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll P, Q, R;
    cin >> P >> Q >> R;

    const auto pq = P + Q;
    const auto pr = P + R;
    const auto qr = Q + R;

    const auto ans = min(pq, min(pr, qr));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      String s = sc.next();
      String t = sc.next();
      
      int A = sc.nextInt();
      int B = sc.nextInt();
      String u = sc.next();
      
      if(s.equals(u)){
       System.out.println(A-1);
      System.out.println(B);
      }
      else if(t.equals(u)){
      System.out.println(A);
      System.out.println(B-1);
      }
    }
}

Measured memory_bytes: 20820
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;


constexpr int D = 365;
int c[26], d[D][26], t[D];
int now_score;

random_device rd;
mt19937 mt(rd());
uniform_int_distribution<> dist0(0, D - 1), dist1(0, 25), dist2(0, 1);
int day_rand() {return dist0(mt);}
int type_rand() {return dist1(mt);}
int b_rand() {return dist2(mt);}

int new_score(const int t0, const int t1, const int new_t[D]) {
    int ans = now_score;
    int last[26];
    rep(i, 26) last[i] = -1;
    rep(i, D) {
        if (new_t[i] == t0 || new_t[i] == t1) ans -= d[i][new_t[i]];
        last[new_t[i]] = i;
        ans += (i - last[t0]) * c[t0];
        ans += (i - last[t1]) * c[t1];
    }
    rep(i, 26) last[i] = -1;
    rep(i, D) {
        if (new_t[i] == t0 || new_t[i] == t1) ans += d[i][new_t[i]];
        last[new_t[i]] = i;
        ans -= (i - last[t0]) * c[t0];
        ans -= (i - last[t1]) * c[t1];
    }
    return ans;
}

int main() {
    using chrono::system_clock;
    using chrono::milliseconds;
    chrono::system_clock::time_point p = system_clock::now() + milliseconds(1950);
    
    
    cin >> c[0];
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> d[i][j];
    
    
    // 貪欲
    int last[26];
    rep(i, 26) last[i] = -1;
    rep(i, D) {
        int max_score = -inf, max_id = -1;
        rep(j, 26) {
            if (chmax(max_score, (j - last[i]) * c[j] + d[i][j])) max_id = j;
        }
        t[i] = max_id;
        last[max_id] = i;
    }
    rep(i, 26) last[i] = -1;
    now_score = 0;
    rep(i, D) {
        now_score += d[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) now_score -= c[j] * (i - last[j]);
    }
    
    while (system_clock::now() < p) {
        int new_t[D];
        rep(i, D) new_t[i] = t[i];
        if (b_rand()) {
            int d0 = day_rand(), d1 = day_rand();
            swap(new_t[d0], new_t[d1]);
            if (new_score(t[d0], t[d1], new_t) > now_score) swap(t[d0], t[d1]);
        } else {
            int d0 = day_rand(), t0 = type_rand();
            new_t[d0] = t0;
            if (new_score(t[d0], t0, new_t) > now_score) t[d0] = t0;
        }
    }
    
    
    rep(i, D) cout << t[i] + 1 << "\n";
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;

int main() {
    ll K, N;    cin >> K >> N;
    ll *A = new ll[N];
    for (ll i = 0; i < N; i++)
        cin >> A[i];

    sort(A, A+N);

    ll ans = 0;
    for (ll i = 0; i < N-1; i++)
        ans = max(ans, A[i+1]-A[i]);
    ans = max(A[0] + K-A[N-1], ans);

    cout << K - ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n, m, q, ans, sum;
vector<int> a(51);
vector<int> b(51);
vector<int> c(51);
vector<int> d(51);
vector<int> A(12);

void dfs(int num, int add)
{
    if (num == n + 1)
    {
        sum = 0;
        for (int i = 0; i < q; i++)
        {
            if (A[b[i]] - A[a[i]] == c[i])
            {
                sum += d[i];
            }
        }
        ans = max(ans, sum);
        return;
    }
    else
    {
        for (int i = add; i <= m; i++)
        {
            A[num] = i;
            dfs(num + 1, i);
        }
    }
}

int main()
{
    cin >> n >> m >> q;

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

    dfs(1, 1);

    cout << ans;
}

Measured memory_bytes: 3616