akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

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

static const double EPS = 1e-8;
static const double PI = 3.141592653589;
static ll INF = 9999999;
int mod = 1000000007;

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define MIN(a,b)    (a) < (b) ? (a):(b)
#define MAX(a,b)    (a) > (b) ? (a):(b)
#define debug(x) cerr << #x << " = " << x << endl;
int dx[] = {1,-1,0,0,1,-1,1,-1};
int dy[] = {0,0,1,-1,-1,1,1,-1};

using namespace std;


int stok[12] = {0};
int ok(int hen){


    while(hen > 0){
        if(stok[hen % 10] == 1)return 0;
        hen /= 10;
    }

    return 1;

}




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

    REP(i,K){
        int a;
        cin >> a ;
        stok[a] = 1;
    }
    int i = N;
    while(1){
        if(ok(i) == 1)break;
        i++;
    }


    cout << i << endl;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
int main()
{
    fastio();
    
    ll n,k;
    cin>>n>>k;
    ll sum=0,ans=0;
    ll arr[k+1]={0};
    for(ll i=2;i<=k;i++)
    {
        ll div = k/i;
        arr[i]= mpowe(div,n,MOD1);
    }
    for(ll i=k;i>1;i--)
    {
        ll j = i*2;
        while(j<=k)
        {
            arr[i] = (arr[i] - arr[j] + MOD1)%MOD1;
            j=j+i;
        }
    }
    for(ll i=2;i<=k;i++)
    {
        sum = (sum+arr[i])%MOD1;
        ans = (ans + (i*arr[i])%MOD1)%MOD1;
    }
    //cout<<sum<<endl;
    sum = (mpowe(k,n,MOD1)-sum+MOD1)%MOD1;
    //cout<<mpowe(k,n,MOD1)<<" "<<sum<<endl;
    //cout<<ans<<endl;
    ans = (ans+sum)%MOD1;
    cout<<ans<<endl;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, h,w;
	cin >> n >> h >> w;
	int cnt = 0;
	long long a,b;
	for(long long i = 0; i < n; ++i) {

		cin >> a >> b;

		if(a >= h && b >= w) {

			++cnt;
		}
	}

	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a;
	while(scanf("%d",&a),a){
		int last=0;
		int first=0;
		int now=0;
		bool space=false;
		scanf("%d",&now);
		last=now;
		first=now;
		for(int i=1;i<a;i++){
			scanf("%d",&now);
			if(now==last+1);
			else{
				if(first!=last){
					printf(space?" %d-%d":"%d-%d",first,last);
					space=true;
				}else{
					printf(space?" %d":"%d",last);
					space=true;
				}
				first=now;
			}
			last=now;
		}
		
		if(first!=last){
			printf(space?" %d-%d":"%d-%d",first,last);
			space=true;
		}else{
			printf(space?" %d":"%d",last);
			space=true;
		}
		first=now;

		printf("\n");
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b)
        cout<<"a < b\n";
    else if(a>b)
        cout<<"a > b\n";
    else
        cout<<"a == b\n";
    return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 55;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};
vec G[NMAX];
string S;
vec v;

ll ans = 0;

void solve(){
  // main algorithm

}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  for (int i = 1; i <= N; ++i)
  {
    cout << G[i].size() << endl;
  }
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  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);
  }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
num = int(input())
root = [None, None, None]   #[前の値、次の値、カーソル部のデータ]
root[1] = [root, None, None]
cursor = root[1]

def insert(x):
    global cursor

    cursor[0][1]= cursor[0] = cursor = [cursor[0], cursor, x]

def move(d):
    global cursor
    if d > 0:
        for i in range(d):
            cursor = cursor[1]  #d回だけcursorをたどる
    else:
        for i in range(-d):
            cursor = cursor[0]

def erase():
    global cursor
    cursor[1][0] = cursor[0]
    cursor = cursor[1]
    cursor[0][1] = cursor

for j in range(num):
    queryi = list(map(int, input().split()))

    if queryi[0] == 0:
        insert(queryi[1])
    elif queryi[0] == 1:
        move(queryi[1])
    else:
        erase()

root = root[1]
while root[1]:
    print(root[2])
    root = root[1]



Measured memory_bytes: 51916
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <algorithm>
using namespace std;

char tolower(char c) {
  return (c + 0x20);
}

int main(){
	int n,m;
	string str;
	cin>>n>>m;
	cin>>str;
	str.at(m-1)=tolower(str.at(m-1));
	cout<<str<<endl;
	return 0;
	}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int l = 0;
  int r = 0;
  vector <int> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    r += W[i];
  }
  
  int ans = r;
  for (int T = 0; T < N; T++) {
    l += W[T];
    r -= W[T];
    ans = min(ans, abs(l-r));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# Aizu Problem ITP_1_3_D: How Many Divisors?
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


a, b, c = [int(_) for _ in input().split()]
print(sum([c % k == 0 for k in range(a, b + 1)]))

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

using namespace std;

const int N = 1001;
const int inf = 1e9;

vector<int> g[N];
int X[N], Y[N];
bool flag = true;

void dfs(int u) {
  vector<int> a(5001);
  for (auto v : g[u]) {
    dfs(v);
    vector<int> b(5001, inf);
    for (int i = 0; i <= 5000; i++) {
      if (i + X[v] <= 5000) b[i + X[v]] = min(b[i + X[v]], a[i] + Y[v]);
      if (i + Y[v] <= 5000) b[i + Y[v]] = min(b[i + Y[v]], a[i] + X[v]);
    }
    Y[u] = inf;
    for (int i = 0; i <= X[u]; i++) {
      Y[u] = min(Y[u], b[i]);
    }
    a = b;
  }
  if (Y[u] == inf) flag = false;
  //  cout << u <<  " " << X[u] << " " << Y[u] << endl;
}

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int u;
    cin >> u;
    g[u].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> X[i];
  }
  dfs(1);
  cout << (flag ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 8748
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include <queue>
#include <iomanip>

#include <string.h>

typedef unsigned long long u64; 
typedef unsigned int uint;

using namespace std;

#define MIN(a, b) a < b ? a : b

#define MOD 1000000007

bool isReach(uint t0, uint t1, uint x0, uint x1, uint y0, uint y1)
{
	int dt = abs((int)t0 - (int)t1);
	int dx = abs((int)x0 - (int)x1);
	int dy = abs((int)y0 - (int)y1);
	int d = dx+dy;
	if(dt < d) return false;
	
	if( ((dt - d) % 2) == 0 )
	{
		return true;
	}
	
	return false;
}

int main()
{
	int n;
	vector<int> a;
	vector<int> t;
	vector<int> x;
	vector<int> y;

	cin >> n;

	t.reserve(n+1);
	x.reserve(n+1);
	y.reserve(n+1);

	t.push_back(0);
	x.push_back(0);
	y.push_back(0);

	for(uint i = 0; i < n; i++)
	{
		uint _t, _x, _y;
		cin >> _t >> _x >> _y;
		t.push_back(_t);
		x.push_back(_x);
		y.push_back(_y);
	}

	bool result = true;
	for(uint i = 0; i < n; i++)
	{
		if( ! isReach(t[i], t[i+1], x[i], x[i+1], y[i], y[i+1]))
		{
			result = false;
			break;
		}
	}

	if(result)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct UF
{
	int par[SIZE],nd[SIZE];
	
	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			nd[i]=1;
		}
	}
	int find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(nd[x]<nd[y]) swap(x,y);
		par[y]=x;
		nd[x]+=nd[y];
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf1,uf2;
int cnt[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	uf1.init(n+2);
	uf2.init(2*n+2);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		uf1.unite(a,b);
		uf2.unite(a,b+n);
		uf2.unite(a+n,b);
	}
	for(int i=0;i<n;i++)
	{
		int p=uf1.find(i);
		if(uf2.same(p,i)) cnt[p]++;
	}
	ll ret=0;
	for(int i=0;i<n;i++)
	{
		if(uf1.find(i)==i)
		{
			if(uf2.same(i,i+n))
			{
				int d=uf1.nd[i];
				ret+=(ll) d*(ll) (d-1)/2LL;
			}
			else
			{
				int a=cnt[i],b=uf1.nd[i]-a;
				ret+=(ll) a*(ll) b;
			}
		}
	}
	printf("%lld\n",ret-m);
	return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int coin = 0;
    if (a < b) {
        coin += b;
        b--;
    } else {
        coin += a;
        a--;
    }
    coin += max(a, b);
    cout << coin << endl;
    return 0;
}


Measured memory_bytes: 256
const main = (input) => {
  const args: string[] = input.split('');
  let cnt = 0;
  if (args[0] === '1') {
    cnt++;
  }
  if (args[1] === '1') {
    cnt++;
  }
  if (args[2] === '1') {
    cnt++;
  }
  console.log(cnt);
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#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)

typedef long long ll;

int main() {
	ll n, x;
	cin >> n >> x;
	
	ll ans = 0;
	ll a = x, b = n - x; //a < b
	
	ans = a + b;
	while (true) {
		ans += (b / a) * 2 * a;
		if (b % a == 0) break;
		
		ll tmp = a;
		a = b % a;
		b = tmp;
	}
	ans -= a;
	
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N = 0;
    string S = "";
    bool p, w, g, y = false;
    cin >> N;
    
    for(int i=0; i<N; i++){
        cin >> S;
        if(S == "P" && !p){
            p = true;
        }else if(S == "W" && !w){
            w = true;
        }else if(S == "G" && !g){
            g = true;
        }else if(S == "Y" && !y){
            y = true;
        }
    }

    int r = p + w + g + y;
    if(r == 3)
        cout << "Three" << endl;
    if(r == 4)
        cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

void rec(int v, vector<vector<int>> &edges, vector<bool> &visited, vector<int> &order) {
    visited[v] = true;
    for (int u : edges[v]) {
        if (visited[u]) continue;
        rec(u, edges, visited, order);
    }
    order.push_back(v);
}

int main() {

    int N, M;
    cin >> N >> M;
    vector<int> count_dest(N, 0);
    vector<vector<int>> edges(N), edges_rev(N);

    rep(i,N-1+M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        count_dest[B]++;
        edges[A].push_back(B);
        edges_rev[B].push_back(A);
    }

    int root = -1;
    rep(i,N) if (count_dest[i] == 0) root = i;

    vector<int> order;
    vector<bool> visited(N, false);

    rec(root, edges, visited, order);
    reverse(order.begin(), order.end());

    vector<int> order_c(N);
    rep(i,N) order_c[order[i]] = i;
    
    rep(i,N) {
        if (i == root) {
            cout << 0 << endl;
            continue;
        }
        int nearest = edges_rev[i][0];
        for (int v : edges_rev[i]) {
            if (order_c[v] > order_c[nearest]) nearest = v;
        }

        cout << nearest + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 23012
/*
    It is time for a counter-attack
*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
typedef long long ll;
const ll N=1e5+10,M=10000,mod=1000000;
const ll OO=1e16;
#define SARAH ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define scan(A,n) for (int i=0;i<n;++i) cin>>A[i];
#define pb push_back
#define bg begin
#define des(A,n) sort(A,A+n);reverse(A,A+n)
#define en end
#define f first
#define s second
#define bs binary_search
#define fill2(A, x) for(int i=0;i<N;++i) for(int j=0;j<N;++j) A[i][j]=x;
#define set2(A, x) fill(A,A+N,x);
#define scan2(A, n, m) for(int i=0;i<n;++i) for(int j=0;j<m;++j) cin >> A[i][j];
#define set(A, x) memset(A, x, sizeof(A))
#define print(A, x) for (int i=0;i<x;++i) cout<<A[i]<< " ";
#define pii pair<int, int>
#define pll pair<ll, ll>
#define low lower_bound
#define high upper_bound
#define bits(x) __builtin_popcountll(x)
#define sz size
#define cl clear
#define all(A) A.bg(), A.en()
#define REPEAT main()
#define dig(n) log10(n)+1;
#define vi vector<int>
#define vl vector<ll>
int n,m,u,v,par[N];
vi adj[N];
ll dis[N];
void bfs(){
    fill(dis,dis+N,OO);
    queue<int>q;
    q.push(1);
    dis[1]=0;
    par[1]=-1;
    while(q.sz()){
        int u=q.front();
        q.pop();
        for(int i:adj[u]){
            ll nw=dis[u]+1;
            if(dis[i]>nw){
                dis[i]=nw;
                par[i]=u;
                q.push(i);
            }
        }
    }
}
int main(){
    cin>>n>>m;
    while(m--){
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    bfs();
    for(int i=2;i<=n;++i){
        if(dis[i]==OO){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    for(int i=2;i<=n;++i){
        cout<<par[i]<<"\n";
    }
    
}

Measured memory_bytes: 11228
#include<stdio.h>

int main() {
  int N, D, X, A[100], sum;
  scanf("%d", &N);
  scanf("%d", &D);
  scanf("%d", &X);
  sum = X;
  for (int i=0 ; i<N ; i++) {
    scanf("%d", &A[i]);
    for (int j=1 ; j<=D ; j = j+A[i]) {
      sum += 1;
    }
  }
  printf("%d\n", sum);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(int argc, char **argv)
{
	int A, B, i, flag;
	char S[12];
	scanf("%d %d",&A,&B);
	scanf("%s",&S);
	flag = 1;
	for(i=0; i<A; i++)
	{
		if(!(S[i] >= 48 && S[i] <= 57))  flag = 0;
	}
	if(flag == 1)
	{
		if(S[A] != '-') flag = 0;
	}
	if(flag == 1)
	{
		for(i = A+1; i < A+B+1; i++)
		{
			if(!(S[i] >= 48 && S[i] <= 57))  flag = 0;
		}
	}
	printf("%s\n", (flag == 1)? "Yes\n":"No\n");
	return 0;
}

Measured memory_bytes: 128
def gcd(a,b)
	t=0
	while a%b!=0
		t=b
		b=a%b
		a=t
	end
	return b
end

def lcm(a,b)
	return a*b/gcd(a,b)
end

if __FILE__==$0
	inf=Float::INFINITY
	
	readln_i=lambda{|dl|gets.chomp.split(dl).map(&:to_i)}
	read_i=lambda{gets.chomp.to_i}
	readln_s=lambda{|dl|gets.chomp.split(dl)}
	read_s=lambda{gets.chomp}
	
	n=read_i[]
	t=[]
	for i in 0..n-1
		t.push(read_i[])
	end
	
	t.sort!
	mx=t[t.length-1]
	lc=Array.new(t.length)
	
	for i in 0..t.length-1
		lc[i]=lcm(mx,t[i])
	end
	
	while lc.uniq.length>1
		t=lc.dup
		t.sort!
		mx=t[t.length-1]
		for i in 0..t.length-1
			lc[i]=lcm(mx,t[i])
		end
	end
	p lc[0]
end

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();
    int n,k;
    cin>>n>>k;
    for (int i=1;i<k+1;i++){
        if (n-k<i-1){
            cout<<0<<endl;
        }
        else{
            long ans=1;
            ans*=COM(k-1,i-1);
            if (n-k==i-1){
                cout<<ans<<endl;
            }
            else{
            ans*=COM(n-k+1,i);
            ans%=MOD;
            cout<<ans<<endl;
            }
        }


    }

    return 0;
}

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

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

    vector<long long int> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }

    vector<int> cand = {k};
    for(int i=30; i>=0; i--){
        if(k >> i & 1){
            int c = k;
            c ^= (1<<i);
            for(int j=i-1; j>=0; j--){
                c |= (1<<j);
            }
            cand.push_back(c);
            //cout << i << " " << c << endl;
        }
    }

    long long int ans = 0;
    for(int c : cand){
        long long int test = 0;
        for(int i=0; i<n; i++){
            bool flag = true;
            for(int j=0; j<30; j++){
                if((a[i] >> j & 1) && !(c >> j & 1)) flag = false;
            }
            if(flag == true) test += b[i];
        }
        ans = max(ans, test);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict
    N = int(readline())
    a = list(map(int, readline().split()))

    d = dict()

    for i, x in enumerate(a, 1):
        d[i] = x

    ans = 0
    for i, x in enumerate(a, 1):
        if d[x] == i:
            ans += 1

    ans //= 2

    print(ans)


if __name__ == '__main__':
    main()


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

vector<int> edge[100000];
int acost[100000];
int tcost[100000];

void dfs1(int pos) {
  rep(i, edge[pos].size()) {
    int next = edge[pos][i];
    if (tcost[next] == INF) {
      tcost[next] = tcost[pos] + 1;
      dfs1(next);
    }
  }
}

void dfs2(int pos) {
  rep(i, edge[pos].size()) {
    int next = edge[pos][i];
    if (acost[next] == INF) {
      acost[next] = acost[pos] + 1;
      dfs2(next);
    }
  }
}

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].eb(b);
    edge[b].eb(a);
  }

  rep(i, n) acost[i] = tcost[i] = INF;

  tcost[u] = acost[v] = 0;
  dfs1(u);
  dfs2(v);

  int ans = -1;
  //  rep(i, n) cout << tcost[i] << ' ' << acost[i] << endl;
  rep(i, n) {
    if (edge[i].size() > 1) continue;
    if (tcost[i] > acost[i]) continue;
    int bef = edge[i][0];
    ans = max(ans, acost[bef]);
  }

  cout << ans << endl;
}


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

typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii > vii;
typedef vector<vi > vvi;


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

ll lcm(ll a, ll b) {
    ll fat = gcd(a, b);
    return fat ? (a / fat * b) : 0;
}

int a, i;
vector<ll> v;
ll afs, j;
int main(){
    cin >> a;
    for(i = 0; i < a; i++) {
        cin >> j;
        v.push_back(j);
    }
    afs = accumulate(v.begin(), v.end(), 1LL, lcm);
    cout << afs << endl;
    return 0;
}

Measured memory_bytes: 256
# Coloring Colorfully
S = gets.chomp.to_s
ansfblack = 0
ansfwhite = 0
if S.length == 1
    puts ansfblack
else
    for i in 0..S.length-1 do #最初白
        if i % 2 == 0 #偶数check
            if S[i] == "0" 
                ansfwhite = ansfwhite + 1
            end
        elsif i % 2 == 1 #奇数check
            if S[i] == "1"
                ansfwhite = ansfwhite + 1
            end
        end
    end
    for i in 0..S.length-1 do #最初黒
        if i % 2 == 0 #偶数check
            if S[i] == "1"
                ansfblack = ansfblack + 1
            end
        elsif i % 2 == 1 #奇数check
            if S[i] == "0"
                ansfblack = ansfblack + 1
            end 
        end
    end
end

if ansfblack <= ansfwhite && S != "0" && S != "1"
    puts ansfblack
elsif ansfblack >= ansfwhite && S != "0" && S != "1"
    puts ansfwhite
end

Measured memory_bytes: 2044
s=input()
l=len(s)
a=0
b=0
for x in range(l):
    if s[x]=='A':
        a=x
        break

for x in range(l):
    if s[l-x-1]=='Z':
        b=l-x-1
        break
c=b-a+1
print(c)


Measured memory_bytes: 3512
#include <iostream>
using namespace std;
int s[100100];
int linesearch(int a[], int n,int key)
{
	for (int i = 0; i < n; i++) {
		if (a[i] == key) return 1;
	}
	return false;
}

int main()
{
	int n, q,t,sum=0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> t;
		sum += linesearch(s, n, t);
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
  int64_t n;
  std::cin >> n;

  std::unordered_multimap<int64_t, int64_t> c;
  std::vector<bool> m(n, true);
  c.reserve((n - 1) * 2);
  for (int64_t i = 0; i < n - 1; i++) {
    int64_t a, b;
    std::cin >> a >> b;
    a--;
    b--;
    c.insert({a, b});
    c.insert({b, a});
  }

  int64_t f = 0, s = 0;
  std::set<int64_t> fs, ss;
  fs.insert(0);
  ss.insert(n - 1);
  m[0] = false;
  m[n - 1] = false;

  while (!fs.empty() || !ss.empty()) {
    f += fs.size();
    std::set<int64_t> f_tmp;
    for (const auto i : fs) {
      const auto itr = c.equal_range(i);
      for (auto j = itr.first; j != itr.second; j++) {
        if (m[j->second]) {
          f_tmp.insert(j->second);
          m[j->second] = false;
        }
      }
    }
    std::swap(fs, f_tmp);

    s += ss.size();
    std::set<int64_t> s_tmp;
    for (const auto i : ss) {
      const auto itr = c.equal_range(i);
      for (auto j = itr.first; j != itr.second; j++) {
        if (m[j->second]) {
          s_tmp.insert(j->second);
          m[j->second] = false;
        }
      }
    }
    std::swap(ss, s_tmp);
  }

  if (f <= s) {
    std::cout << "Snuke" << std::endl;
  } else {
    std::cout << "Fennec" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 9728
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DNotDivisible {
public:

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      vector<int> cnt(1000005);
      rep(i, n) {
        cnt[a[i]]++;
      }
      int ret = 0;
      rep(j, n) {
        int tmp = a[j];
        bool flag = true;
        for(int i=1; i*i<=tmp; i++) {
          if (tmp%i == 0) {
            if (i != tmp && cnt[i] > 0) {
              flag = false;
              break;
            }
            int k = tmp/i;
            if (k != tmp && cnt[k] > 0) {
              flag = false;
              break;
            }
          }
        }
        if (cnt[tmp] > 1) {
          flag = false;
        }
        if (flag) {
          ret++;
        }
      }
      cout << ret << endl;
    }
};

signed main() {
  DNotDivisible solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 7988
using System;
using System.Linq;

class sample4{
    static void Main(string[] args){

            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            if((a <= -1000) || (b <= -1000)){
                Console.WriteLine("数値は-1000以上の値を入力してください。");
                Environment.Exit(0);
            }else if((a >= 1000) || (b >= 1000)){
                Console.WriteLine("数値は1000以下の値を入力してください。"); 
                Environment.Exit(0);
            }
            
            if( a < b){
                Console.WriteLine("a < b");
            }else if( a > b){ 
                
                 Console.WriteLine("a > b");
            }else if(a == b){ 
           
                 Console.WriteLine("a == b");
            }
    }
}



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

int main() {
    int N;
    cin >> N;
    bool possible = false;
    for (int a = 1; a <= 9; a++) {
        for (int b = 1; b <= 9; b++) {
            if (a * b == N) {
                possible = true;
            }
        }
    }
    if (possible) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int k,s;
    cin>>k>>s;
    ll ans=0;
    REP(x,k+1){
        REP(y,k+1){
            if(0<=s-x-y && s-x-y<=k){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
 
l = [0]
curr = '1'
 
#0と1の塊を探索
for c in S:
    if c != curr:
        l.append(1)
        curr = c
    else:
        l[-1] += 1
if curr == '0':
    l.append(0)
 
n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
 
#初期値として左端から1の塊を算出
for i in range(k):
    sum_ += l[2 * i] + l[2 * i + 1]
sum_ += l[2 * k]
max_ = sum_
 
#左端から0の塊を１つずつ取り替えて、最大値を算出
for i in range(k, n_group):
    sum_ -= l[2 * i - 2 * K] + l[2 * i + 1 - 2 * K]
    sum_ += l[2 * i + 1] + l[2 * i + 2]
    max_ = max(max_, sum_)
 
print(max_)

Measured memory_bytes: 4212
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tpl;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };




/******************************************************************************************/



//素数判定
bool is_prime(ll n) {
	for (ll i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return n != 1;//1の場合は除外
}



//約数の列挙
template<typename T>
vector<T> divisor(T n) {
	vector<T> res;
	for (T i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}




//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}



//繋げる方向を一方向にする
typedef struct union_find {

	vector<ll> pa;//親
	vector<ll> ra;//木の深さ
	vector<ll> siz;
	//n要素で初期化
	void init(ll n) {
		pa.resize(n);
		ra.resize(n);
		siz.resize(n);
		for (ll i = 0; i < n; i++) {
			pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
			ra[i] = 0LL;/*各ノード自体の高さは0*/
			siz[i] = 1LL;
		}
	}
	//木の根を求める
	ll find(ll x) {
		if (pa[x] == x) {
			return x;/*根ならそのノードの番号を返す*/
		}
		else {
			return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
		}
	}

	//xとyの属する集合を併合する
	void unite(ll x, ll y) {
		x = find(x);//xの根の番号を探す
		y = find(y);//yの根の番号を探す
		if (x == y) {//一致すればつながっている
			return;
		}
		pa[y] = x;
		siz[x] += siz[y];
	}

	//xとyが同じ集合に属するか判定
	bool same(ll x, ll y) {
		return find(x) == find(y);//同じ集合なら1、違うなら0が返る
	}
}UF;




int main() {


	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> cnt(n + 10, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		cnt[a[i]]++;
	}
	
	
	bool flag = true;
	for (int i = n-1; i >= 0; i-=2)
	{
		if (i == 0) {
			if (cnt[i] != 1) {
				flag = false;
			}
		}
		else
		{
			if (cnt[i] != 2) {
				flag = false;
			}
		}
	}

	if (flag) {
		int ans = 1;
		for (int i = 0; i < n/2; i++)
		{
			ans *= 2;
			ans %= MOD;
		}
		cout << ans << endl;
	}
	else
	{
		cout << 0 << endl;
	}
	


	

	
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main
{
	public static void main(String Args[])
	{
		int a;
		Scanner s1=new Scanner(System.in);
		a=s1.nextInt();
		if(a%2==0)
		{
			System.out.println(a/2);
		}
		else
		{
				System.out.println(a/2+1);
		}
	}
}

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

int main(){
	int n, c, k;
	cin >> n >> c >> k;
	vector<int> t(n);
	for(auto& x: t){
		cin >> x;
	}
	sort(t.begin(), t.end());
	t.push_back(0);
	int count_time = 0;
	int count_bus = 0;
	int count_people = 0;
	bool begin_flag = 1;
	for(int i = 0;i < n; i++){
		if(begin_flag == 0){
			count_time += t.at(i) - t.at(i-1);
			count_people++;
		}
		if(begin_flag == 1){
			count_people++;
			begin_flag = 0;
		}
		if(count_time > k || count_people > c){
			count_bus++;
			count_time = 0;
			count_people = 0;
			begin_flag = 1;
			i--;
		}
	}
	cout << count_bus+1 << endl;
}


Measured memory_bytes: 1024
n=int(input())
l=list(map(int,input().split()))
l1=[0 for i in range(n)]
for i in range(1,1+(n+1)//2):
  if l[-i]==1:
    l1[-i]=1
  else:
    pass
for i in range((n+1)//2-1,-1,-1):
  s=0
  for j in range(2,n//(1+i)+1):
    if l1[(i+1)*j-1]==1:
      s+=1
  if s%2==1:
    if l[i]==0:
      l1[i]=1
  else:
    if l[i]==1:
      l1[i]=1
l2=[]
s=0
for i in range(n):
  if l1[i]==1:
    s+=1
    l2.append(str(i+1))
print(s)
print(" ".join(l2))


Measured memory_bytes: 17204
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set> 
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define f(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
#define sz(a) (int)(a).size()
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
int x[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int y[] = { -1, 0, 1, -1, 1, -1, 0, -1 };
const int MOD = 1e9 + 7, N = 2e5 + 5;
const double pi = acos(-1);

ll arr[N];
int main()
{
	assem99;

	ll n; cin >> n;
	ll cntr = 0;
	f(i, 0, n) cin >> arr[i];
	f(i, 0, n)
	{
		if (arr[i] < 0)cntr++;
	}
	ll ans = 0;
	if (cntr % 2)
	{
		ll mn = 1e9;
		f(i, 0, n)
		{
			ans += abs(arr[i]);
			mn = min(mn, abs(arr[i]));
		}
		cout << ans - 2 * mn;
	}
	else
	{
		f(i, 0, n) ans += abs(arr[i]);
		cout << ans;
	}


	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define MAX 2000000
int H,A[MAX+1];

void max(int i){
    int l,r,lmax;
    l=2*i;
    r=2*i+1;
    if(l<=H&&A[l]>A[i])lmax=l;
    else lmax=i;
    if(r<=H&&A[r]>A[lmax])lmax=r;
    if(lmax!=i){
        swap(A[i], A[lmax]);
        max(lmax);
    }
}
int main(){
    cin>>H;
    for(int i=1; i<=H; i++)cin>>A[i];
    for(int i=H/2; i>=1; i--)max(i);
    for(int i=1; i<=H; i++){
        cout<<" "<<A[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 5016
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

class UnionFind
{
public:
    UnionFind(int size)
    : p(size, -1)
    {}

    int find(int x)
    {
        if (p[x] < 0) return x;
        else return p[x] = find(p[x]);
    }

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

    void unite(int x, int y)
    {
        int rx = find(x);
        int ry = find(y);
        if (rx == ry) return;

        if (p[rx] > p[ry]) swap(rx, ry);
        p[rx] += p[ry];
        p[ry] = rx;
    }

    vs32 p;
};

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

    int n, k, l;
    cin >> n >> k >> l;
    UnionFind A(n);

    rep (i, k)
    {
        int p, q;
        cin >> p >> q;
        --p, --q;
        A.unite(p, q);
    }

    UnionFind B(n);
    rep (i, l)
    {
        int r, s;
        cin >> r >> s;
        --r, --s;
        B.unite(r, s);
    }

    map<P, int> m;
    rep (i, n)
    {
        ++m[P{A.find(i), B.find(i)}];
    }

    rep (i, n)
    {
        if (i > 0) cout << " ";
        cout << m[P{A.find(i), B.find(i)}];
    }
    cout << "\n";

    return 0;
}



Measured memory_bytes: 13568
from operator import itemgetter, attrgetter

class P:
    def __init__(self, x, y):
        self.x, self.y = x, y
    def __add__(self, p): return P(self.x + p.x, self.y + p.y)
    def __sub__(self, p): return P(self.x - p.x, self.y - p.y)
    def dot(self, p): return (self.x*p.x + self.y*p.y)
    def cross(self, p): return (self.x*p.y - self.y*p.x)
    def abs(self): return (abs(self.x) + abs(self.y))

def convex_hull(Ps):
    Ps.sort(key=attrgetter('x', 'y'))
    ret1, ret2 = list(), list()
    for i in range(len(Ps)):
        k = len(ret1)
        while k>=2 and (Ps[i]-ret1[k-1]).cross(ret1[k-1]-ret1[k-2]) <= 0:
            ret1.pop()
            k = len(ret1)
        ret1.append(Ps[i])
    for i in range(len(Ps)):
        k = len(ret2)
        while k>=2 and (Ps[i]-ret2[k-1]).cross(ret2[k-1]-ret2[k-2]) >= 0:
            ret2.pop()
            k = len(ret2)
        ret2.append(Ps[i])
    return ret1 + ret2[::-1]

N = int(input())
Ps = list()
for i in range(N):
    x, y = list(map(int, input().split()))
    Ps.append(P(x, y))

# produce convex hull
CPs = convex_hull(Ps)

# brute force
ans = 0
for i in range(len(CPs)):
    for j in range(i, len(CPs)):
        mdis = (CPs[i]-CPs[j]).abs()
#        print(i, j, mdis)
        if ans < mdis: ans = mdis

print (ans)


Measured memory_bytes: 124284
#include <stdio.h>

int main(void){
    
    char str[1200];
    int count=0;
    int i;
    
    while (1) {
		scanf("%c", &str[i]);
		
		if (str[i] == '\n')break;
		count++;
		i++;
		
	}
	for (i = 0; i<count; i++) {
		if (65 <= str[i] && str[i] <= 90) {
			printf("%c", str[i] + 32);
		}
		else if (96 <= str[i] && str[i] <= 122) {
			printf("%c", str[i] - 32);
		}
		else printf("%c", str[i]);


	}
    
    printf("\n");
    
    
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, x;
  cin >> a >> b >> x;
  if (a <= x && a + b >= x) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{ 
// freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
   vector<int>v[4];
    for(int i=0;i<3;i++)
     { int x,y;
     	 cin>>x>>y;
     	 v[x-1].push_back(y-1);
     	 v[y-1].push_back(x-1);
	 }
	bool vis[4];
	 for(int i=0;i<4;i++)
	   vis[i]=0;
	 vis[0]=1;
	 queue<int>q;
	 q.push(0);
	 while(!q.empty())
	 {   int p=q.front();
	   q.pop();
	    for(int i=0;i<v[p].size();i++)
		{  if(vis[v[p][i]]!=1)
		  {  
		  	 vis[v[p][i]]=1;
			   q.push(v[p][i]);
			   break;  
		  } 
		   }   
	  	 
	   }
	   int flag=0;
	   for(int i=0;i<4;i++)
	   { //cout<<vis[i]<<" "; 
	     if(vis[i]==0)
	      {
	         flag=1;   cout<<"NO";
	      	  break;
		  }
	   	 
		 }
	 if(flag==0)
	   cout<<"YES";	   
 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

// for(auto && i : Range(l,r))
// -> i = [l..r)
class Range {
private: struct It{ int x; int operator*(){return x;}
 bool operator!=(It& lhs){ return x<lhs.x;} void operator++(){++x;} }; It l,r;
public: Range(int n):l({0}),r({n}){} Range(int i,int n):l({i}),r({n})
 {}It& begin(){return l;} It& end(){return r;} };

void solve(istream& cin) {
    int N, A, B;
    ll chois[51][51] ;

    for (int i = 0; i < 51; ++i) {
        chois[i][0] = 1;
        chois[i][i] = 1;
        for (int j = 1; j < i; ++j) {
            chois[i][j] = chois[i-1][j] + chois[i-1][j-1];
        }
    }

    while(cin >> N >> A >> B){
        vector<ll> v;
        for (int i = 0; i < N; ++i) {
            ll tmp;
            cin >> tmp;
            v.push_back(tmp);
        }
        sort(v.begin(), v.end());
        ll m = v[v.size() - A ];
        ll ansM = 0;
        for (int i = 0; i < A; ++i) {
            ansM += v[v.size() - i - 1];
        }
        double ans = ansM / double(A);
        ll ansN = 0;
        auto up = upper_bound(v.begin(), v.end(), m);
        auto lb = lower_bound(v.begin(), v.end(), m);
        int n = up - lb;
        if(up == v.end()){
            for (int i = A; i <= min(B, n); ++i) {
                ansN += chois[n][i];
            }
        }
        else {
            int l = v.end() - up;
            ansN = chois[n][A-l];
        }
        cout << setprecision(10)  << scientific << ans << '\n' << ansN << endl;
    }

}

int main(int argc, char *argv[]) {
    string FileName("D2"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());
    cerr << sub << endl;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {
        string inFile = "sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{

    public static void main(String args[])
    {
        Scanner kb = new Scanner(System.in);
        String inp = kb.nextLine();

        inp.trim();

        if(inp.charAt(inp.length() - 1) == 's')
            System.out.println(inp + "es");
        else
            System.out.println(inp + "s");

    }
}

Measured memory_bytes: 38596
<?php

fscanf(STDIN, "%d %d", $n, $k);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = 0; $i < $n; ++$i) {
    --$A[$i];
}
const K_MAX = 61;

$to = [];
$to[0] = $A;
for ($i = 1; $i < K_MAX; ++$i) {
    for ($j = 0; $j < $n; ++$j) {
        $to[$i][$j] = $to[$i - 1][$to[$i - 1][$j]];
    }
}

$v = 0;
for ($i = 0; $i < K_MAX; ++$i) {
    if ($k & 1<<$i) {
        $v = $to[$i][$v];
    }
}

echo $v + 1;


Measured memory_bytes: 406980
import java.util.Scanner;
import java.util.stream.Stream;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String[] c = s.split(" ");
    int[] n = Stream.of(c).mapToInt(Integer::parseInt).toArray();
    int ans = n[0] * n[1];
    if (ans % 2 == 0) {
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 36060
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
	int N, H;
	cin >> N >> H;

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

	int ma = *max_element(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());

	int ret = 0;
	int hp = H;
	for(int i=0; i<b.size(); i++){
		if(hp > 0 && b[i] > ma){
			hp -= b[i];
			ret++;
		}
		else
			break;
	}

	if(hp > 0)
		ret += (hp + ma-1)/ma;

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        for (int i = x - k + 1; i <= x + k - 1; i++) {
            System.out.println(i + " ");
        }
        System.out.println();
        sc.close();
    }
}

Measured memory_bytes: 22100
import scala.util.control.Breaks.{ break, breakable }

object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val mList = collection.mutable.MutableList.empty[(String, List[Int])]

    breakable {
      while (true) {
        val word = sc.next()
        if (word == "-") break
        val n = sc.nextInt()
        val numbers = List.fill(n)(sc.nextInt)
        mList += (word -> numbers)
      }
    }

    for {
      (word, numbers) <- mList
    } yield {
      val target = numbers.foldLeft(word)((w, n) => w.drop(n) + w.take(n))
      println(target)
    }
  }
}

Measured memory_bytes: 45496