akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, t, res[333333];

int main() {
	cin >> N;
	for (t = 0; (1 << t) < N; ++t);
	if ((1 << t) == N) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	if ((1 << t) - 1 == N) {
		for (int i = 1; i < N + N; ++i) {
			cout << i << sp << i + 1 << endl;
		}
		return 0;
	}
	--t;
	t = (1 << t);
	for (int i = 1; i < t - 1; ++i) {
		cout << i << sp << i + 1 << endl;
	}
	cout << t - 1 << sp << 1 + N << endl;
	for (int i = 1 + N; i < t - 1 + N; ++i) {
		cout << i << sp << i + 1 << endl;
	}
	cout << t + 1 << sp << 1 << endl;
	cout << t << sp << t + 1 << endl;
	cout << t + N << sp << N + 1 << endl;
	cout << t + N + 1 << sp << t + N << endl;
	for (int i = t + 2; i <= N; ++i) {
		cout << i + N << sp << t + N << endl;
	}
	int p = 0;
	for (int i = 1; i < t; ++i) {
		p ^= i;
		res[t + p] = i + N;
	}
	p = 1;
	for (int i = t - 1; i > 0; --i) {
		p ^= i;
		res[t + p] = i;
	}
	for (int i = t + 2; i <= N; ++i) {
		cout << i << sp << res[i] << endl;
	}
}

Measured memory_bytes: 3072
import java.util.Scanner;
     
    public class Main {
     
    static Scanner sc = new Scanner(System.in);
    static int N, K, R;
    static int[][] m;
    static boolean hate[][];
     
    static int solve() {
    int ans = 0;
    for (int i = 0; i < K; ++i) {
    for (int j = 0; j < m[i].length; ++j) {
    int r = m[i][j];
    for (int k = 0; k < m[i].length; ++k) {
    if (hate[r][m[i][k]]) {
    ++ans;
    break;
    }
    }
    }
    }
    return ans;
    }
     
    public static void main(String[] args) {
    N = sc.nextInt();
    K = sc.nextInt();
    m = new int[K][];
    for (int i = 0; i < K; ++i) {
    int mi = sc.nextInt();
    m[i] = new int[mi];
    for (int j = 0; j < mi; ++j) {
    m[i][j] = sc.nextInt() - 1;
    }
    }
    R = sc.nextInt();
    hate = new boolean[N][N];
    for (int i = 0; i < R; ++i) {
    int p = sc.nextInt() - 1;
    int q = sc.nextInt() - 1;
    hate[p][q] = hate[q][p] = true;
    }
    System.out.println(solve());
    }
    }

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
using namespace std;

long long int n, m;
vector<long long int> a;

long long int gcd(long long int a, long long int b)
{
  // Everything divides 0
  if (a == 0)
    return b;
  if (b == 0)
    return a;

  // base case
  if (a == b)
    return a;

  // a is greater
  if (a > b)
    return gcd(a - b, b);
  return gcd(a, b - a);
}

int main()
{
  cin >> n >> m;
  a.resize(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    a[i] /= 2;
  }

  // a[0]が2で何回割れるか
  long long int divByTwo_0 = 0;
  long long int num = a[0];
  while (num % 2 == 0)
  {
    num /= 2;
    divByTwo_0++;
  }

  // a[0]~a[n-1]は、2で割れる回数が一致していることが半公倍数が存在する必要十分条件
  for (int i = 1; i < n; i++)
  {
    long long int divByTwo_i = 0;
    num = a[i];
    while (num % 2 == 0)
    {
      num /= 2;
      divByTwo_i++;
    }
    if (divByTwo_0 != divByTwo_i)
    {
      cout << 0 << endl;
      return 0;
    }
  }

  // cout << "divByTwo: " << divByTwo_0 << endl;

  long long int min = a[0];
  for (int i = 1; i < n; i++)
  {
    min = min / __gcd(min, a[i]) * a[i];
    // for (int j = 1; j <= a[i]; j += 2)
    // {
    //   if (min * j % a[i] == 0)
    //   {
    //     min *= j;
    //     break;
    //   }
    // }
  }

  // cout << "min: " << min << endl;

  num = m / min;
  if (num % 2 == 0)
  {
    num--;
  }
  cout << (num + 1) / 2 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define MAX 100

bool gridfilled(int x[], int k, int n)
{
	for (int i = 0; i < n; i++) {
		if (x[i] == k) {
			return true;
		}
	}
	return false;
}

int main()
{
	int m, n;
	int x[MAX] = { 0 };
	int a[MAX] = { 0 };

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}

	for (int j = 0; j < m; j++) {
		if ((gridfilled(x, x[a[j] - 1] + 1, n)) || (x[a[j] - 1] + 1 == 2020)) {
			;
		}
		else
		{
			x[a[j] - 1]++;
		}
	}

	for (int i = 0; i < n; i++) {
		cout << x[i] << endl;
	}

	return 0;
}


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

const int V_MAX=100000;
const int E_MAX=100000;

vector<int> G[V_MAX];
int used[V_MAX]={};
int flag=false;
vector<int> sorted;

void dfs(int s){
	if(used[s]==1){return;}
	used[s]=2;
	for (int i=0;i<G[s].size();i++){
		if(used[G[s][i]]==2){
			flag=true;
		}
		if(used[G[s][i]]==0)
		dfs(G[s][i]);
	}
	used[s]=1;
	sorted.push_back(s);
	
}

int main(){
	int V,E,s,t;
	cin>> V >> E;
	for (int i=0;i<E;i++){
		cin >> s >> t;
		G[s].push_back(t);
	}
	
	for(int i=0;i<V;i++){
		dfs(i);
	}
	
	for(int i=sorted.size()-1;i>-1;i--){
		cout << sorted[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4100
import Data.List

main :: IO ()
main = do
    n <- read <$> getLine
    as <- map read . words <$> getLine
    print $ go as n
    return ()

go as n = sum [abs(x - median) | x <- xs]
    where
        xs = zipWith (-) as [1..]
        median = sort xs !! (n `div` 2)

Measured memory_bytes: 105852
N = int(input())
total = 0
for i in range(1,N+1):
    if i % 3 == 0 and i % 5 == 0:
        continue
    elif i % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    else:
        total += i
    

print(total)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r; cin>>r;
    cout<<3*r*r<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const int MAX=1e5+1;
const ll INF=1e9;

int main()
{
    int a[5];
    int k;
    rep(i,5)
    {
        cin>>a[i];
    }
    cin>>k;
    rep(i,5)rep(j,5)
    {
        if(abs(a[i]-a[j])>k)
        {
            cout<<":(";
            return 0;
        }
    }
    cout<<"Yay!";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,k;
    cin >> a >> b >> k;
    intl i = 1;
    vector<intl> v(100);
    while(true){
        if((!(a % i))&&(!(b % i))){
            v.pb(i);
        }
        if(i > gcd(a,b))break;
        i++;
    }
    sort(all(v),greater<>());
    cout << v[k - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int, input().split())


if a*b <= 0 and c*d <= 0:
    print(max([a*c, b*d]))
elif a*b <= 0 and c >= 0:
    print(b*d)
elif a*b <=0 and d <=0:
    print(a*c)
elif a>=0 and c*d<=0:
    print(b*d)
elif a>=0 and c>=0:
    print(b*d)
elif a>=0 and d<=0:
    print(a*d)
elif b<=0 and c*d<=0:
    print(a*c)
elif b<=0 and c>=0:
    print(b*c)
elif b<=0 and d<=0:
    print(a*c)

Measured memory_bytes: 9108
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

//block linked list
#define Bsize 1000 /*2sqrt(n)*/
typedef struct block{
	int cnt;
	ll a[Bsize+1];
	struct block*pre;
	struct block*nxt;
}block;
void Bpush(block*b,ll x){
	//リストにxを追加する
	if((*b).nxt&&(*(*b).nxt).a[0]<x){
		//次へ
		Bpush((*b).nxt,x);
		return;
	}
	int i=(*b).cnt;
	for(;i>0&&(*b).a[i-1]>x;i--)(*b).a[i]=(*b).a[i-1];
	(*b).a[i]=x;
	(*b).cnt++;
	if((*b).cnt>=Bsize){
		//分割
		block*nn=(block*)malloc(sizeof(block));
		(*nn).cnt=Bsize-Bsize/2;
		rep(i,0,Bsize-Bsize/2)(*nn).a[i]=(*b).a[i+Bsize/2];
		(*nn).pre=b;
		(*nn).nxt=(*b).nxt;
		if((*b).nxt)(*(*b).nxt).pre=nn;
		(*b).cnt=Bsize/2;
		(*b).nxt=nn;
	}
}
void con(block*p,block*q){
	//qをpにマージしてqを消す
	rep(i,0,(*q).cnt)(*p).a[(*p).cnt+i]=(*q).a[i];
	(*p).cnt+=(*q).cnt;
	(*p).nxt=(*q).nxt;
	if((*q).nxt)(*(*q).nxt).pre=p;
	free(q);
}
void Bdel(block*b,int idx){
	//idx番目を削除する(必ずidx個以上ある)
	for(;idx<(*b).cnt-1;idx++)(*b).a[idx]=(*b).a[idx+1];
	(*b).cnt--;
	
	if((*b).cnt==0&&(*b).pre)con((*b).pre,b);
	else if((*b).pre&&(*(*b).pre).cnt+(*b).cnt<Bsize/4)con((*b).pre,b);
	else if((*b).nxt&&(*(*b).nxt).cnt+(*b).cnt<Bsize/4)con(b,(*b).nxt);
}
ll Bans(block*b,int k,int flag){
	//リストのk番目を返す
	//リストにk個未満しかなければ適当に返す
	//flagがtrueなら削除する
	if((*b).cnt<=k){
		if((*b).nxt)return Bans((*b).nxt,k-(*b).cnt,flag);
		else return -1;//<-例外
	}
	ll ans=(*b).a[k];
	if(flag)Bdel(b,k);
	return ans;
}
int Bfind(block*b,ll k,int flag){
	//リストにkより大きいものが存在すればそれを返す
	//flagがtrueなら削除する
	if((*b).cnt==0||(*b).a[(*b).cnt-1]<=k){
		if((*b).nxt)return Bfind((*b).nxt,k,flag);
		else return 1;
	}
	int i=0;
	for(;(*b).a[i]<=k;i++);
	ll ans=(*b).a[i];
	if(flag)Bdel(b,i);
	return ans;
}
#undef Bsize

block*B1,*B2,*B3,*temp;
int main(){
	int n;
	scanf("%d",&n);
	B1=(block*)malloc(sizeof(block));
	B2=(block*)malloc(sizeof(block));
	B3=(block*)malloc(sizeof(block));
	rep(i,0,1<<n){
		int t;
		scanf("%d",&t);
		Bpush(B3,-t);
	}
	ll t=Bans(B3,0,1);
	Bpush(B1,t);
	rep(i,0,n){
		rep(j,0,1<<i){
			ll t=Bans(B1,0,1);
			ll tt=Bfind(B3,t,1);
			if(tt==1){
				puts("No");
				return 0;
			}
			Bpush(B2,tt);
			Bpush(B2,t);
		}
		temp=B1;B1=B2;B2=temp;
	}
	puts("Yes");
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  int c,n,m,s,e,min,a,b,co,mi,i,j,k;
  while(scanf("%d %d %d %d %d",&c,&n,&m,&s,&e),c||n||m||s||e){
    s--;
    e--;
    int d[100][100]={0};
    int p[11][100]={0};
    while(m--){
      scanf("%d %d %d",&a,&b,&co);
      a--;
      b--;
      d[a][b]=d[b][a]=co;
    }
    for(i=0;i<=c;i++){
      mi=s;
      int f[100]={0};
      for(j=0;j<n;j++){
	f[mi]=1;
	for(k=0;k<n;k++){
	  if(d[mi][k]==0||f[k])continue;
	  if(p[i  ][k]==0||p[i  ][k]>p[i][mi]+d[mi][k]){
	    p[i  ][k]=p[i][mi]+d[mi][k];
	  }
	  if(p[i+1][k]==0||p[i+1][k]>p[i][mi]+d[mi][k]/2){
	    p[i+1][k]=p[i][mi]+d[mi][k]/2;
	  }
	}
	min=210000000;
	for(k=0;k<n;k++){
	  if(p[i][k]==0||f[k])continue;
	  if(min>p[i][k]){
	    min=p[i][k];
	    mi=k;
	  }
	}
      }
      /*for(j=0;j<=c;j++){
	for(k=0;k<n;k++)printf("%d\t",p[j][k]);printf("\n");
	}printf("\n");//*/
    }
    min=210000000;
    for(i=0;i<=c;i++){
      if(p[i][e]==0)continue;
      if(min>p[i][e])min=p[i][e];
    }
    printf("%d\n",min);
  }
  return 0;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    int n,s;cin>>n>>s;
    if(s % 1000 != 0) {
        printf("-1 -1 -1\n");
    } else {
        s /= 1000;
        bool flg = false;
        for(int i = 0;i <= 20000;i++) {
            for(int j = 0;j <= 10000;j++) {
                if(i + j*5 > s) {
                    continue;
                }
                if( ((s - (i + j*5)) % 10 == 0 ) ) {
                    if(i + j + ((s - (i + j*5))/10) == n) {
                        printf("%d %d %d\n",((s - (i + j*5))/10),j,i);
                        return 0;
                    }
                }
            }
        }
        printf("-1 -1 -1\n");
    }

    return 0;
}

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

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

	vector<int> p(n);
	vector<int> q(n);
	
	for (int i = 0; i < n; i++) {
		cin >> p[i]; 
		q[i] = p[i]; 
	}
	sort(p.begin(), p.end());

	int count = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != q[i]) {
			count ++;
		}  
	}

	if (count > 2) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	return 0;
}

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

char S[222222];

int main(void) {
	int i, len;
	uint64_t kugyu = 0, kitaeri = 0;
	if (scanf("%222221s", S) != 1) return 1;
	len = (int)strlen(S);
	for (i = 0; i < len; i++) {
		if (S[i] == 'B') {
			kitaeri++;
		} else if (S[i] == 'W') {
			kugyu += kitaeri;
		}
	}
	printf("%" PRIu64 "\n", kugyu);
	return 0;
}

/*

BWBWBW
BWBWWB
BWWBWB
WBWBWB
WBWWBB
WWBWBB
WWWBBB

→ バブルソートの交換回数

*/


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s;
	cin >> s;
	rep (i, s.size()) cout << (char)'x';
	cout << endl;
    
    return 0;
}



Measured memory_bytes: 3636
S = input()

ans = 0
if S == 'SUN':
    ans = 7
elif S == 'MON':
    ans = 6
elif S == 'TUE':
    ans = 5
elif S == 'WED':
    ans = 4
elif S == 'THU':
    ans = 3
elif S == 'FRI':
    ans = 2
elif S == 'SAT':
    ans = 1

print('{}'.format(ans))


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

using namespace std;
int sumnum(int tmpx);
int n;
vector<int> x;

int main(void) {
    cin >> n;
    x.resize(n);
    int ave = 0;
    for(int i = 0; i < n; ++i) {
        cin >> x[i];
        ave +=  x[i];
    }
    ave /= n;
    
    int oldsum = sumnum(0);
    int newsum;

    for(int i = 1; i <= 100; i++) {
        newsum = sumnum(i);   
        if(newsum > oldsum){
            break;
        }
        oldsum = newsum;
    }

    cout << oldsum << endl;
    return 0; 
}


int sumnum(int tmpx) {
    int tmpsum = 0;
    for(int i = 0; i < n; ++i) {
        tmpsum += (tmpx-x[i]) * (tmpx-x[i]);
    }
    return tmpsum;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int res = k;
    for (int i = 0; i < n - 1; i++) {
        res *= k - 1;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

using ll = long long int;

int main() {
    ll L, R;

    cin >> L >> R;

    const int md = 2019;
    int res;
    int min = md - 1;

    if (L == 0) {
        min = 0;
        goto end;
    }


    for (ll i=L; i<=R - 1;i++){
        for (ll j=i+1; j<=R; j++){
            res = ((i % md) * (j % md)) % md;

            if (res < min) {
                min = res;

                if (min == 0)
                    goto end;
            }
        }
    }

    end:

    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
N = input()
if N[-1] == "2" or N[-1] == "4" or N[-1] == "5" or N[-1] == "7" or N[-1] == "9":
    print("hon")
elif N[-1] == "0" or N[-1] == "1" or N[-1] == "6" or N[-1] == "8":
    print("pon")
elif N[-1] == "3":
    print("bon")


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

max_len = 2 * n - 1  # 適宜変更する
mod = 10**9 + 7


def modinv(x):
    '''
    xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
    Python標準のpowは割った余りを出すことも可能。
    '''
    return pow(x, mod-2, mod)


# 二項係数の左側の数字の最大値を max_len　とする。nとかだと他の変数と被りそうなので。
# factori_table = [1, 1, 2, 6, 24, 120, ...] 要は factori_table[n] = n!
# 計算時間はO(max_len * log(mod))
modinv_table = [-1] * (max_len + 1)
modinv_table[0] = None  # 万が一使っていたときにできるだけ早期に原因特定できるようにしたいので、Noneにしておく。
factori_table = [1] * (max_len + 1)
factori_inv_table = [1] * (max_len + 1)
for i in range(1, max_len + 1):
    factori_table[i] = factori_table[i-1] * (i) % mod

modinv_table[1] = 1

for i in range(2, max_len + 1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
    factori_inv_table[i] = factori_inv_table[i-1] * modinv_table[i] % mod


def binomial_coefficients(n, k):
    '''
    n! / (k! * (n-k)! )
    0 <= k <= nを満たさないときは変な値を返してしまうので、先にNoneを返すことにする。
    場合によっては0のほうが適切かもしれない。
    '''
    if not 0 <= k <= n:
        return None
    return (factori_table[n] * factori_inv_table[k] * factori_inv_table[n-k]) % mod


def binomial_coefficients2(n, k):
    '''
    (n * (n-1) * ... * (n-k+1)) / (1 * 2 * ... * k)
    '''
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans



if k >= n-1:
    # nHn = 2n-1 C n
    print(binomial_coefficients(2 * n - 1, n))
else:
    # 移動がk回←→ 人数0の部屋がk個以下
    # 人数0の部屋がちょうどj個のものは
    # nCj(人数0の部屋の選び方) * jH(n-j) (余剰のj人を残りの部屋に入れる)
    ans = 0
    for j in range(k+1):
        if j == 0:
            ans += 1
        else:
            ans += binomial_coefficients(n, j) * binomial_coefficients(n-1, j) 
            ans %= mod
    print(ans)


Measured memory_bytes: 50536
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] strings = line.split(" ");
		int W = Integer.parseInt(strings[0]);
		int H = Integer.parseInt(strings[1]);
		int x = Integer.parseInt(strings[2]);
		int y = Integer.parseInt(strings[3]);
		int r = Integer.parseInt(strings[4]);
		if (W >= x + r && H >= y + r && x - r >= 0 && y - r >= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main(){
  int a=0,b=0,c,m,A=1000000,n;
  cin>>n;
  vector<int> s(n);
  for(int i=0;i<n;i++){
    cin>>s.at(i);
  }
  for(int i=1;i<n;i++){
    for(int j=0;j<i;j++){
      a+=s[j];
    }
    for(int j=i;j<n;j++){
      b+=s[j];
    }
    c=a-b;
    if(c<0){
      c=0-c;
    }
    if(A>c){
      A=c;
    }
    a=0;b=0;
  }
  cout<<A<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
short N,M;
long cnt = 0;
VVI edge;

void dfs(long node,bitset<8> used){
	//dump(node);
	//dump(used.to_ulong());
	if (used[node]) return;

	used.set(node);
	if(used.count() == N){
		cnt++;
		return;
	} 

	REP(i,edge[node].size()){
		dfs(edge[node][i],used);
	}
	return;
}

int main(void){
	cin >> N >> M;
	edge = VVI(N,VI(0));
	short a,b;
	REP(i,M){
		cin >> a >> b;
		edge[a-1].push_back(b-1);
		edge[b-1].push_back(a-1);
	}

	dfs(0,bitset<8>(0));

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = [0] + list(map(int, input().split()))
p = 10**9 + 7
l = Counter(A)

flag = True
for i in range(N%2 == 0,N,2):
  if l[i] != 2:
    flag = False
    break
if flag:
  print(pow(2,N//2,p))
else:
  print(0)

Measured memory_bytes: 14796
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    string N; cin >> N;
    int K; cin >> K;
    int n = N.size();

    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(2, vector<ll>(105,0)));
    dp[0][0][0] = 1;

    rep(i,n){
        rep(j,10){
            rep(k,10){
                if (k != 0){
                    dp[i+1][1][j+1] += dp[i][1][j];
                }
                else{
                    dp[i+1][1][j] += dp[i][1][j];
                }
            }

            int num = N[i]-'0';

            rep(k,num){
                if (k != 0){
                    dp[i+1][1][j+1] += dp[i][0][j];
                }
                else{
                    dp[i+1][1][j] += dp[i][0][j];
                }
            }
            if (num != 0) dp[i+1][0][j+1] += dp[i][0][j];
            else dp[i+1][0][j] += dp[i][0][j];
        }
    }
    ll ans = 0;
    ans += dp[n][0][K];
    ans += dp[n][1][K];

    cout << ans << endl;

}

Measured memory_bytes: 3740
#include<stdio.h>
int main()
{

  int a=0,b=0;
  scanf("%d%d",&a,&b);
  
  if(a>=b)
  {
    for(int i=0;i<a;i++)
    {
      printf("%d",b);
    }
  }else{
     for(int i=0;i<b;i++)
    {
      printf("%d",a);
    };
  };
    return 0;
};
    




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

int n;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    string s;
    map <string,int> m;
    for (int i=0; i<n; i++){
        cin>>s;
        m[s]=1;
    }
    int res=0;
    for (auto em:m){
        res+=em.second;
    }
    
    cout<<res;
    
    
    return 0;
}

Measured memory_bytes: 19200
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

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

int main() {
	ll a,b,c,d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

	ll divC = b / c - (a - 1) / c;
	ll divD = b / d - (a - 1) / d;
	ll cd = c/gcd(c, d)*d;
	ll divCD = b / cd - (a - 1) / cd;
	//printf("%lld %lld %lld %lld\n", divC, divD, divCD);


	PRINTL(b - a + 1 - (divC + divD - divCD));
}


Measured memory_bytes: 128
#include <cstdlib>
#include <cstdio>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pi pair<ll,ll>
using namespace std;
int main(){
	//	freopen("in.txt","r",stdin);
  char a,b;
  scanf("%c %c",&a,&b);
  if(a==b) printf("H\n");
  else printf("D\n");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = [0] * m
x = [0] * m
for i in range(m):
    p[i], x[i] = list(map(int, input().split()))

for i in range(m):
    tt = t[:]
    tt[p[i] - 1] = x[i]
    print(sum(tt))

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        char[] inpt = Reader.ReadLine().ToArray();
        inpt[3] = '8';
        string ans = string.Join("", inpt);
        Console.WriteLine(ans);
        
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



2017/01/31

";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13268
using System;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

class program{
  static void Main(string[] args){
    program p= new program();
      p.Run();
  }
  void Run(){
    int[] inp=Readint();
    int n=inp[0];
    int m=inp[1];
    int l=1;
    int r=n;
    for(int i=0;i<m;i++){
      inp=Readint();
      if(inp[0]>l){
        l=inp[0];
      }
      if(inp[1]<r){
        r=inp[1];
      }
      if(l>r)
        break;
    }
    if(l<=r)
      WriteLine((r-l+1).ToString());
    else
      WriteLine(0);
  }
  int[] Readint(){
    string[] inp= ReadLine().Split();
    int n=inp.Length;
    int[] res=new int[n];
    for(int i=0;i<n;i++){
      res[i]=int.Parse(inp[i]);
    }
    return res;
  }
}

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

typedef long long ll;

int cnt_digits(ll X){
	int cnt=0;
	while(X>0){
		X/=10;
		cnt++;
	}
	return cnt;
}

int main() {
	ll N;
	cin>>N;
	int ans=cnt_digits(N);
	rep1(A,1e5+1){
		if(N%A==0){
			ll B=N/A;
			int C=max(cnt_digits(A),cnt_digits(B));
			ans=min(ans,C);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  ll n;
  cin >>n;
  vector<ll> vec(n);
  rep(i,n-1){
    int a;
    cin >>a;
    vec[a-1]++;
}
  rep(i,n){
    cout <<vec[i]<<endl;
  }
}

Measured memory_bytes: 4840
import sys

S = list(input())
n = len(S)
for i in range(n) :
    if S[2*i] == "L" :
        print("No")
        sys.exit()
    if 2*i == n-1 :
        break
    if S[2*i+1] == "R" :
        print("No")
        sys.exit()
    if 2*i + 1 == n-1 :
        break
print("Yes")


Measured memory_bytes: 2940
#include <iostream>
// #include <vector>
// #include <string>
// #include <set>
// #include <algorithm>

using namespace std;
typedef unsigned long long ull;

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}


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

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

int main(int argc, char const *argv[]) {
    ull A, B, C, D;
    cin >> A >> B >> C >> D;
    ull CD = lcm(C, D);

    ull n_c = B / C - (A + C - 1) / C + 1;  // floor(B/C) - ceil(A/C) + 1
    ull n_d = B / D - (A + D - 1) / D + 1;  // floor(B/D) - ceil(A/D) + 1
    ull n_cd = B / CD - (A + CD - 1) / CD + 1;  // floor(B/CD) - ceil(A/CD) + 1

    // p(n_c, n_d, n_cd);
    cout << B - A + 1 - (n_c + n_d - n_cd) << endl;

    return 0;
}


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


	

int main(){
	vector<ll> dp(100001);
	dp[0]=1;
	dp[1]=1;

	for(int i=2; i<=100000; i++){
		dp[i]=(dp[i-2]+dp[i-1])%DIV;
	}


	int n,m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i,m){
		cin >> a[i];
		if(i>=1){
			if(a[i]-a[i-1] == 1){
				cout << 0 << endl;
				return 0;
			}
		}
	}
	ll res=1;
	int before = 0;
	int after = n;
	rep(i,m+1){
		if(i==m){ after=n;
		}else{ after=a[i]-1;
		}

		int c = after-before;
		ll tmp = dp[c];
		//cout << "tmp " << tmp << endl;
		res = (res * tmp)%DIV;
		before = after+2;
	}
	res = res%DIV;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
int l,i,p,x,j;
	l=3000;
	for(i=0;i<3;i++){
		scanf("%d",&p);
		if(p<l){
		l=p;
		}
		}
	j=3000;
		for(i=0;i<2;i++){
			scanf("%d",&p);
			if(p<j){
		j=p;
			}
			}
	x=0;
	x=l+j-50;
	printf("%d\n",x);
	return 0;
}

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

cnt = [0] * 1000005
for x in a:
    if cnt[x] != 0: 
        cnt[x] = 2
    else: 
        for i in range(x,1000005,x):
            cnt[i] += 1

ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1

print(ans)

Measured memory_bytes: 132848
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <bitset>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<long long> VI;
typedef unsigned long long ull;
const ll inff = 0x3f3f3f3f3f3f3f3f;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define SZ(x) ((long long)(x).size())
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod ll(998244353)
#define pb push_back
#define eps 1e-6
#define lc d<<1
#define rc d<<1|1
#define Pll pair<ll,ll>
#define P pair<int,int>
#define pi acos(-1)
string a;
int main()
{
    cin.tie(0);
    cout.tie(0);
    cin>>a;
    sort(a.begin(),a.end());
    if(a[0]==a[1]&&a[2]==a[3]&&a[1]!=a[2]) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    ll a=n,b=1;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0){
            a=i;b=n/i;
        }
    }
    string A=to_string(a),B=to_string(b);
    int An=A.size(),Bn=B.size();
    int res=max(An,Bn);
    cout<<res<<endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

//#define int ll

int main(){

    ll n,k;cin>>n>>k;
    ll a[n+1];rep(i,1,n)cin>>a[i];
    a[0]=0;rep(i,1,n)a[i]=a[i-1]+a[i];
    vector<ll>v;
    rep(i,1,n){
        rep(j,0,i-1){
            v.pb(a[i]-a[j]);
        }
    }
    //sort(v.begin(),v.end());
    /*for(auto x:v){
        cout<<x<<" ";
    }*/
    ll ans=0;
    int N=40;
    for(int i=N;i>=0;i--){
        ll p=(ll)1<<i;
        vector<ll>ok;
        for(auto x:v){
            if((x&p)==p){
                ok.pb(x);
            }
        }
        if(ok.size()>=k){
            ans+=p;
            v.clear();
            v=ok;
        }
       // cout<<i<<" "<<v.size()<<" "<<ok.size()<<endl;
        ok.clear();
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 6256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;
 
const int maxN = 1 << 24, mod = 998244353;

long long fact[maxN], tcaf[maxN];

inline void addMod(long long& a, long long b)	{   a = (a + b) % mod;  }
inline void multMod(long long& a, long long b)	{   a = a * b % mod;    }

long long qpow(long long a, long long b)
{
    long long res0 = 1;
    for (; b!=0; b>>=1)
    {
        if (b & 1)  multMod(res0, a);
        multMod(a, a);
    }
    return res0;
}

long long cf(int n, int k)
{
	bool static initd = false;
	if (!initd)
	{
		fact[0] = 1;
		FOR(i, 1, maxN)
			fact[i] = fact[i - 1] * i % mod;
		tcaf[maxN - 1] = qpow(fact[maxN - 1], mod - 2);
		for (int i=maxN-1; i>0; i--)
			tcaf[i - 1] = tcaf[i] * i % mod;
		initd = true;
	}
	if (k < 0 or k > n)
		return 0;
	long long res0 = fact[n];
	multMod(res0, tcaf[k]);
	multMod(res0, tcaf[n-k]);
	return res0;
}

void solve()
{
	int n;
	scanf ("%d", &n);
	cf(0, 0);
	long long res = 0, p2 = 1;
	FOR(i, 0, n/2)
	{
		addMod(res, cf(n, i) * p2);
		multMod(p2, 2);
	}
	
	multMod(res, 2);
	multMod(res, mod-1);
	addMod(res, qpow(3, n));
		
	printf("%lld\n", res);
}
 
int main()
{
	int t;
	t = 1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


Measured memory_bytes: 262400
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
 
int main() {
	//int n = ri();
  int n;
	std::string s;
	std::cin >> n >> s;
	int64_t res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (s[i] == s[j]) continue;
			for (int k = 0; k < j; k++) if (j - k != i - j && s[k] != s[i] && s[k] != s[j]) res++;
		}
	}
	printf("%" PRId64 "\n", res);
	return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    int N;
    cin >> N;
    vector<vector<int>> tree(N);
    map<pair<int,int>, int> tree_c;
     vector<pair<int,int>> vp;

    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;b--;

        tree.at(a).push_back(b);
        tree.at(b).push_back(a);
        vp.push_back(make_pair(a,b));

    }

    int max_color = -1;
    queue<pair<int,int>> q;
    q.push(make_pair(0,-1));
    while(!q.empty()){
        int color = 1;
        auto e = q.front();q.pop();

        max_color = max((int)tree.at(e.first).size(), max_color);
        
        rep(i, tree.at(e.first).size()) {
            int j = tree.at(e.first).at(i);
            if (tree_c.count(make_pair(e.first,j)) == 0){
                //cout << e.first << "," << j << endl;
                if (color == e.second) {
                    color++;
                }
                tree_c[make_pair(e.first,j)] = color;
                tree_c[make_pair(j,e.first)] = color;
                q.push(make_pair(j, color));

                //max_color = max(max_color, color);
                color++;
            }
        }
    }

    cout << max_color << endl;

    
    for(auto v:vp){
        cout << tree_c[v] << endl;
    }


    return 0;
}


Measured memory_bytes: 19316
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	ll X;
	cin >> X;

	ll S = 100;
	int i;
	for (i = 0; S < X; i++)
	{
		S *= 1.01;
	}
	cout << i << endl;
}



Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const double PI = 3.14159265358979323846;
const int MAX = 1e10;
const int MOD = 1e9+7;

const int MAX_N = 100005;



int main(int argc, char *args[]) {
	int n, a; cin >> n >> a;
	int res = 0;
	while (n > 0) {
		n -= a;
		res++;
	}
	cout << res << endl;
}

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

int main(){
	int n;
  	cin >> n;
  	
  	vector<int> P(n);
  	rep(i, n) cin >> P[i];
  
  	int cnt = 0;
  	int mini = 200005;
	rep(i, n){
		if(mini > P[i]){
        	mini = P[i];
          	cnt++;
        }
    }
  
  	cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
ll kaijou(ll a, ll b){
    ll re = 1;
    rep(i, b){
        re *= a;
        re %= mod;
    }
    return re;
}
int main(){
    int n; cin >> n;
    vector<int> count(100010, 0);
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
        count[a[i]]++;
    }
    for(int i = n; i > 0; i -= 2){
        if((count[i - 1] != 2) and (i - 1 != 0)){
            cout << 0 << endl;
            return 0;
        }else if((count[i - 1] != 1) and (i - 1 == 0)){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << kaijou(2, n / 2) << endl;
}

Measured memory_bytes: 1024
import numpy as np

D = int(input())
c = np.array( list(map(int, input().split())) )
s = [[] for i in range(365)]
for i in range(D):
  s[i] = np.array( list(map(int, input().split())) )
#
last = np.array( [-1]*26 )
av = np.array( [0]*26 )
id = np.identity(4,dtype=int)

def fav(d):
  return( s[d] - sum( c*(d-last) ) + c*(d-last) )
#
  
v = 0
for d in range(D):
  av = fav( d )
  m = max(av)
  for t in range(26):
    if av[t] == m:
      last[t] = d
      v += av[t]
      print(t+1)
      break
#


Measured memory_bytes: 27312
n,y=[int(i) for i in input().split()]

y-=n*1000
ans=[-1,-1]

for i in range(n+1):
        for j in range(n+1-i):
                if 9000*i+4000*j==y:
                        ans[0]=i
                        ans[1]=j
                        break
        if ans[0]!=-1:
                break
if ans[0]==-1:
        print("-1 -1 -1")
else:
        print(str(ans[0])+" "+str(ans[1])+" "+str(n-ans[0]-ans[1]))

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

#define INF 0x3f3f3f3f
#define MAXN 100010
#define endl "\n"
#define abs(a, b) ((a > b) ? a-b : b-a)

typedef long long int ll;

/* End */

int n;
ll a[MAXN];
ll b[MAXN];
ll c[MAXN];
ll pd[2][3];

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i] >> b[i] >> c[i];

	int m = 0;
	pd[m][0] = max(b[n], c[n]);
	pd[m][1] = max(a[n], c[n]);
	pd[m][2] = max(a[n], b[n]);
	m = !m;

	for (int i = n-1; i >= 0; i--) {
	        pd[m][0] = max(b[i] + pd[!m][1], c[i] + pd[!m][2]);
		pd[m][1] = max(a[i] + pd[!m][0], c[i] + pd[!m][2]);
		pd[m][2] = max(a[i] + pd[!m][0], b[i] + pd[!m][1]);
		m = !m;
	}

	cout << max(pd[m][0], max(pd[m][1], pd[m][2])) << endl;

	return 0;
}


Measured memory_bytes: 2560
package main

import "fmt"

func main() {
	G := false
	W := false
	Y := false
	P := false

	var N int
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		var po string
		fmt.Scan(&po)
		if po == "G" {
			G = true
		}
		if po == "W" {
			W = true
		}
		if po == "Y" {
			Y = true
		}
		if po == "P" {
			P = true
		}
	}

	ans := 0
	if G {
		ans++
	}
	if W {
		ans++
	}
	if Y {
		ans++
	}
	if P {
		ans++
	}
	if ans == 3 {
		fmt.Println("Three")
	}
	if ans == 4 {
		fmt.Println("Four")
	}

}


Measured memory_bytes: 512
# include <stdio.h>
# include <algorithm>


long long N, A, B;

int main(void){
    // Here your code !
    scanf("%lld%lld%lld",&N,&A,&B);

    long long D = B - A;

    if (D < 0) {printf("%d\n", 0);}
    else if (N == 1) {
        if (D == 0) {printf("%d\n", 1);}
        else {printf("%d\n", 0);}
    }
    else {
        if (N == 1) {printf("%d\n", 0);}
        else {printf("%lld\n", (1 + (N - 2) * D));}
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, k;
#include <cassert>
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

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

  cin >> n >> k;

  mint ans = 0;
  REP(i, min(n, k + 1)) {
    ans += c(n, i) * c(n - 1, n - i - 1);
  }

  cout << ans << endl;
}


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

int main(){
  char a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans=0;
  if(a=='2')
    ans++;
  if(b=='2')
    ans++;
  if(c=='2')
    ans++;
  if(d=='2')
    ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    X, Y = map(int, input().split())

    tsuru = 0
    kame = 0

    for i in range(X+1):
        tsuru = X - i
        kame = i
        if tsuru*2 + kame*4 == Y:
            print("Yes")
            return

    print("No")



if __name__ == '__main__':
    main()


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

long long cnt[27];
string MARCH = "MARCH";

int main(){
  int N;cin>>N;
  for(int i=0;i<N;i++){
	string s;cin>>s;
    cnt[s[0] - 'A']++;
  }
  
  long long ans = 0;
  for(int i=0;i<5;i++){
	for(int j=i+1;j<5;j++){
	  for(int k=j+1;k<5;k++){
		ans += cnt[MARCH[i]-'A'] * cnt[MARCH[j]-'A'] * cnt[MARCH[k]-'A'];
      }
	}
  }
  
  cout<<ans<<endl;
  
  return 0;
}


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

int main(void)
{
int a,x,i;
cin >> x;

if (x%10==3)
	cout << "bon" <<endl;
else if(x%10==0||x%10==1||x%10==6||x%10==8)
	cout << "pon" << endl;
else
	cout << "hon" <<endl;

	return 0;
}

Measured memory_bytes: 3672