akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
const ll INFLL=(ll)4e18, MOD=1e9+7; const int INF=0x3f6f6f6f;
//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color, level; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

int n;
ll tree[(int)9e5+100];
ll query(int cur, int s, int e, int l, int r){
	if(s>=l && e<=r) return tree[cur];
	else if(e<l || r<s) return -1;
	int mid=(s+e)>>1;
	return max(query(2*cur, s, mid, l, r), query(2*cur+1,mid+1,e,l,r));
}
ll query(int l, int r){
	return query(1,0,n, l, r);
}
void update(int cur, int s, int e, int pos, ll val){
	if(pos<s || pos>e) return ;
	else if(s==e) {
		tree[cur]=max(tree[cur],val);
		return ;
	}
	int mid=(s+e)>>1;
	update(2*cur, s,mid,pos, val);
	update(2*cur+1, mid+1,e, pos, val);
	tree[cur]=max(tree[cur*2], tree[cur*2+1]);
	return ;
}
void update(int pos, ll val){
	update(1, 0, n, pos, val);
}
///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

cin>>n;
vv<ll> h(n), a(n);
for(int i=0;i<n;++i) cin>>h[i];
for(int i=0;i<n;++i) cin>>a[i];
//for(int i=0;i<n;++i) DD(h[i], a[i]);
for(int i=0;i<n;++i){
	ll val=query(0,h[i]-1)+a[i];
	update(h[i], val);	
//	cerr<<val<<el;
}
cout<<query(0,n)<<el;

return 0;
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    reverse(str.begin(), str.end());
    int n = str.size();
    vector<int> a(n), s(n+1);
    int pow_10_mod = 1;
    s[0] = 0;
    rep(i, n) {
        a[i] = ((str[i]-'0')*pow_10_mod)%2019;
        s[i+1] = (s[i] + a[i])%2019;
        pow_10_mod = (pow_10_mod*10)%2019;
    }
    vector<int> cnt(2019);
    int ans = 0;
    rep(i,n+1) {
        ans += cnt[s[i]];
        cnt[s[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
  ll n,m;cin >> n >> m;
  UnionFind uf(n);
  vector<vector<int>> a(m+1);
  for(int i = 0; i < n; ++i){
    int k;cin >> k;
    for(int j = 0; j < k; ++j){
      int l;cin >> l;
      a[l].push_back(i);
      uf.merge(a[l].front(),i);
    }
  }
  string ans= "NO";
  if(uf.size(0)==n)ans = "YES";
  cout << ans << endl;
}


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

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

  if (A >= 499){
    cout << "Yes" << endl;
  }
  else if (N % 500 <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)

class UnionFind:
    def __init__(self,N):
        self.par = [i for i in range(N)]
 
    def root(self,x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
 
    def unite(self,x,y):
        self.rx = self.root(x)
        self.ry = self.root(y)
        if self.rx == self.ry:
            return
        self.par[self.rx] = self.ry
 
    def same(self,x,y):
        self.rx = self.root(x)
        self.ry = self.root(y)
        return self.rx == self.ry
 
N,M = [int(i) for i in input().split()]
uf = UnionFind(N)
 
for _ in range(M):
    x,y,_ = [int(i)-1 for i in input().split()]
    uf.unite(x,y)
 
ans = set()
for i in range(N):
    ans.add(uf.root(i))
 
print(len(ans))


Measured memory_bytes: 30248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000;
const ll mod = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> pair;
bool seen[100000];
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
 
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

//dpTable
int dp[100050];

int main(){
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    ll E = C * D  / __gcd(C,D);
    ll F = B / C - (A - 1) / C;
    ll G = B / D - (A - 1) / D;
    ll H = B / E - (A - 1) / E;
    cout << B - A + 1 - F - G + H << endl;
    return 0;
}


Measured memory_bytes: 3600
N, X = map(int, input().split())

m = [0] * N

num = 0

for i in range(N):
    m[i] = int(input()) 

sum = 0    

for i in range(N):
    sum += m[i]
    X -= m[i]

m = sorted(m)

while m[0]<=X:
    sum += m[0]
    X -= m[0]
    num += 1

print(num + N)    




Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
int main(){
	LL n;
	cin>>n;
	LL a[n];
	for(LL i=0;i<n;i++){
		cin>>a[i];
	}
	LL dp[n+1][n+1][2];
	for(LL i=0;i<n;i++){
		for(LL j=0;j<n;j++){
			dp[i][j][0]=dp[i][j][1]=0;
		}
	}
	
	
	for(LL i=0;i<n;i++){
		for(LL j=0,k=j+i;k<n;j++){
			
			if(i==0){
				dp[j][k][0]=a[j];
			}
			else {
				if(a[j]+dp[j+1][k][1]>a[k]+dp[j][k-1][1]){
					
					dp[j][k][0]=a[j]+dp[j+1][k][1];
					dp[j][k][1]=dp[j+1][k][0];
				}
				else{
					
					dp[j][k][0]=a[k]+dp[j][k-1][1];
					dp[j][k][1]=dp[j][k-1][0];
				}
			}
//			k=j+i+1;
//			cout<<j<<" "<<k<<" "<<dp[j][k][0]<<" "<<dp[i][j][1]<<endl;
			k+=1;
		}
	}
	cout<<(dp[0][n-1][0]-dp[0][n-1][1])<<endl;
	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 2005;

int n,m,hor[N][N],ver[N][N],a[N][N];
string s[N];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;

    for(int i=1;i<=n;i++){
        cin>>s[i];
        s[i]="#"+s[i];

        for(int j=1;j<=m;j++){
            if(s[i][j]=='#')a[i][j]=0;
            else a[i][j]=1;
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            hor[i][j]=(hor[i][j-1]+a[i][j])*a[i][j];
        }
    }

    for(int j=1;j<=m;j++){
        for(int i=1;i<=n;i++){
            ver[i][j]=(ver[i-1][j]+a[i][j])*a[i][j];
        }
    }

    int ans=0,l,r,ind;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(!a[i][j])continue;
            int sol=0;
            //left
            l=1;
            r=j;
            ind=-1;
            while(l<=r){
                int mid=(l+r)>>1;
                if(hor[i][j]-hor[i][mid-1]==j-mid+1){
                    ind=mid;
                    r=mid-1;
                }else{
                    l=mid+1;
                }
            }
            if(ind!=-1)sol+=j-ind;


            //right
            l=j;
            r=m;
            ind=-1;
            while(l<=r){
                int mid=(l+r)>>1;
                if(hor[i][mid]-hor[i][j-1]==mid-j+1){
                    ind=mid;
                    l=mid+1;
                }else{
                    r=mid-1;
                }
            }
            if(ind!=-1)sol+=ind-j;


            //top
            l=1;
            r=i;
            ind=-1;
            while(l<=r){
                int mid=(l+r)>>1;
                if(ver[i][j]-ver[mid-1][j]==i-mid+1){
                    ind=mid;
                    r=mid-1;
                }else{
                    l=mid+1;
                }
            }
            if(ind!=-1)sol+=i-ind;


            //top
            l=i;
            r=n;
            ind=-1;
            while(l<=r){
                int mid=(l+r)>>1;
                if(ver[mid][j]-ver[i-1][j]==mid-i+1){
                    ind=mid;
                    l=mid+1;
                }else{
                    r=mid-1;
                }
            }
            if(ind!=-1)sol+=ind-i;


            ans=max(ans,sol+1);
        }
    }


    cout<<ans;
    return 0;
}


Measured memory_bytes: 51456
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=300000;
char s[N], x[N];

int main() {
    int i, sp=0;
    scanf("%s", s);
    for(i=0; s[i]; i++) {
        if(sp>0 && x[sp-1]=='S' && s[i]=='T') sp--;
        else x[sp++]=s[i];
    }
    printf("%d\n", sp);
    return 0;
}

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

string s;
int m = 0;

int main()
{
	cin >> s;

	int n = s.size();

	for (int i = 0; i < n / 2; i++)
		if (s[i] != s[n - i - 1])
			m++;

	cout << m << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll K;
  cin >> K;

  ll x = 0;
  rep(i,5*K){
    x *= 10;
    x += 7;
    x %= K;
    if(x == 0){
      cout << i+1 << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  
  return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=3009;
ll  n ;
string str; 
ll  dp[mx][mx]; ///number of way to solve upto prefix i when last digit is j
ll sum[mx]; 
int   main()
{
	cin>>n>>str; 
	dp[1][1]=1; 
	sum[1]=1 ; 
	for(ll  i=2;i<=n;i++)
	{
		for(ll  last=1;last<=i;last++)
		{
			int suru,ses; 
			if(str[i-2]=='<')
			{
				suru=1; ses=last-1; 
			}
			else 
			{
				suru=last; ses=i-1; 
			}
			ll rem=(sum[ses]-sum[suru-1])%mod  ; 
			rem=(rem+mod)%mod; 
			dp[i][last]+=rem;  
			dp[i][last]%=mod; 
		}

		for(int j=1;j<=i;j++) sum[j]=sum[j-1]+dp[i][j],sum[j]%=mod; 
	}
	ll  ans=0;
	for(ll  i=1;i<=n;i++)
	{
		ans+=dp[n][i]; 
		ans%=mod; 
	}
	cout<<ans<<endl; 
	
}


Measured memory_bytes: 69248
#!/usr/bin/python

import sys

def main(argv):
    for line in sys.stdin:
        a, op, b = line.strip().split()
        a = int(a)
        b = int(b)
        if op == "+":
            print a + b
        else:
            print a - b

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2696
#include<stdio.h>
#include<string.h>
char ch[200];
int main()
{
	int S=0,N=0,W=0,E=0,i,s,f,g;
	scanf("%s",ch);
		int l=strlen(ch);
		if(l==1)
			printf("No\n");
		else
		{
				for(i=0;i<l;i++)
			{
				if(ch[i]=='S') S++;
				if(ch[i]=='E') E++;
				if(ch[i]=='W') W++;
				if(ch[i]=='N') N++;
			}
		if(S>0&&N==0||N>0&&S==0||W>0&&E==0||E>0&&W==0)
			printf("No\n");
		else
		printf("Yes\n");
		}
		return 0;
} 

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e-a > k) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  map<int, int> count;
  rep(i, N)
  {
    int a;
    cin >> a;
    count[a]++;
  }
  long long ans = 0;
  for (pair<int, int> p : count)
  {
    if (p.second >= p.first)
      ans += (long long)p.second - p.first;
    else
      ans += (long long)p.second;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
int main(void){
	int n=0,x=0,count,i,j,k;
	while(1){
		scanf("%d %d",&n,&x);
		if(n==0&&x==0) break;
		count=0;	//loop nai deno syokika ga hituyo
		for(i=1;i<=n-2;i++){
			for(j=i+1;j<=n-1;j++){
				for(k=j+1;k<=n;k++){
					if((i+j+k)==x) count++;
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int get_rand(int a, int b) {  // [a, b]
    return uniform_int_distribution<int>(a, b)(rng);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d = 365, n = 26;
    vector<int> c(n);
    vector<vector<int>> s(d, vector<int>(n));
    if (true) {
        cin >> d;
        for (int i = 0; i < n; i++) {
            cin >> c[i];
        }
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < n; j++) {
                cin >> s[i][j];
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            c[i] = get_rand(0, 100);
        }
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < n; j++) {
                s[i][j] = get_rand(0, 20000);
            }
        }
    }
    auto beg = clock();
    int cnt = 0;
    int wid = 15;
    int lrand = 20;
    vector<vector<int>> que(wid, vector<int>(d));
    for (int i = 0; i < wid; i++) {
        for (int j = 0; j < d; j++) {
            que[i][j] = get_rand(0, n - 1);
        }
    }
    auto get = [&](int id) {
        int res = 0;
        vector<int> last(n, -1);
        for (int i = 0; i < d; i++) {
            res += s[i][que[id][i]];
            int x = i - last[que[id][i]] - 1;
            res -= c[que[id][i]] * x * (x + 1) / 2;
            last[que[id][i]] = i;
        }
        for (int i = 0; i < n; i++) {
            int x = d - last[i] - 1;
            res -= c[i] * x * (x + 1) / 2;
        }
        return res;
    };
    while (true) {
        cnt++;
        if (clock() - beg > 1919191) {
            break;
        }
        vector<pair<int, vector<int>>> nxt(wid + 1);
        for (int i = 0; i < wid; i++) {
            nxt[i].first = -1e9;
        }
        for (int i = 0; i < wid; i++) {
            for (int j = 0; j < lrand; j++) {
                int p = get_rand(0, n - 1);
                int q = get_rand(0, d - 1);
                swap(p, que[i][q]);
                nxt[wid] = make_pair(get(i), que[i]);
                for (int k = wid - 1; k >= 0; k--) {
                    if (nxt[k].first < nxt[k + 1].first) {
                        swap(nxt[k], nxt[k + 1]);
                    } else {
                        break;
                    }
                }
                swap(p, que[i][q]);
            }
        }
        for (int i = 0; i < wid; i++) {
            que[i] = nxt[i].second;
        }
    }
    for (int i = 0; i < d; i++) {
        cout << que[0][i] + 1 << '\n';
    }
    cerr << get(0) << '\n';
    cerr << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    string s;
    cin >> s;

    map<int, int> num;
    ll ans = 0;
    rep(i, s.size()){
        if (num.find(s[i]-'a') == num.end()){
            num.insert({s[i]-'a', 1});
        } else {
            num[s[i]-'a']++;
        }
        ans += i+1-num[s[i]-'a'];
    }
    cout << ans+1 << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
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); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<vector<ll>> g(n);
  REP(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<ll> c(n+1);
  c[2] = 1;
  for(ll i=4; i<=n; i+=2) {
    (c[i] = c[i-2] * (i-1)) %= MOD;
  }
  // cout << c << endl;

  // 2乗の木DP
  function<vector<vector<ll>>(ll,ll)> dfs = [&](ll v, ll par) {
    auto ret = make_v<ll>(2,2);
    fill_v(ret, 0);
    ret[1][0] = 1;
    for(auto to: g[v]) {
      if(to == par) continue;
      auto tmp = dfs(to, v);
      auto nret = make_v<ll>(ret.size()+tmp.size()-1, 2);
      fill_v(nret, 0);
      REP(i, ret.size()) REP(j, tmp.size()) {
        // vからtoまでの辺を切断
        (nret[i][0] += ret[i][0] * tmp[j][1] % MOD * c[j] % MOD + ret[i][1] * tmp[j][0] % MOD * c[j] % MOD) %= MOD; 
        (nret[i][1] += ret[i][0] * tmp[j][0] % MOD * c[j] % MOD + ret[i][1] * tmp[j][1] % MOD * c[j] % MOD) %= MOD;
        // vからtoまでの辺をつないだまま
        (nret[i+j][0] += ret[i][0] * tmp[j][0] % MOD + ret[i][1] * tmp[j][1] % MOD) %= MOD;
        (nret[i+j][1] += ret[i][0] * tmp[j][1] % MOD + ret[i][1] * tmp[j][0] % MOD) %= MOD;
      }
      ret = nret;
    }
    return ret;
  };

  auto ret = dfs(0, -1);
  
  ll ans = 0;
  REP(i, ret.size()) {
    (ans += ret[i][0] * c[i] % MOD) %= MOD;
    (ans -= ret[i][1] * c[i] % MOD) %= MOD;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2176
n1 = int(input())
n2 = int(input())
 
#print(n1)
#print(n2)
 
if n1 == 1:
  if n2 == 2:
    print("3")
  else:
    print("2")
elif n1 == 2:
  if n2 == 1:
    print("3")
  else:
    print("1")
elif n1 ==3:
  if n2 == 1:
    print("2")
  else:
    print("1")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vint x(m);
  rep(i,m){
    cin>>x[i];
  }
  sort(all(x));
  vint sa;
  REP(i,1,m){
    sa.push_back(abs(x[i]-x[i-1]));
  }
  ll sum=0;
  sort(all(sa),greater<int>());
  REP(i,n-1,m-1){
    sum+=sa[i];
  }
  cout<<sum<<'\n';
  return(0);
}


Measured memory_bytes: 1276
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
using namespace std;

char s[2000];

int main(){
	int ans = 1,flag = 0,t;
	scanf("%s",s + 1);
	int len = strlen(s + 1);
	t = len;
	len = len - 1;
	while(1){
		if(len % 2 == 1){
			len = len - 1;
			ans++;
		}
		for(int i = 1;i <= len / 2;i++){
			if(s[i] != s[len / 2 + i]) break; 
			if(i == len / 2){
				printf("%d",t - ans);
				return 0;
			}
		}
		ans++;
		len = len - 1;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

const int MOD= 1e9 + 7;

signed main(){

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

  static int dp[101][100001];
  dp[0][0] = 1;
  for(int i = 0; i < n; i++){
    vector<int> dp2(k+2,0);
    for(int j = 0; j <= k; j++){
      dp2[j+1] = (dp2[j] + dp[i][j]) % MOD;
    }
    for(int j = 0; j <= k; j++){
      dp[i+1][j] += dp2[j+1] - dp2[max(0LL,j-a[i])] + MOD;
      dp[i+1][j] %= MOD;
    }
  }
  cout << dp[n][k] << endl;

  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll a, b, c;

int main() {
	cin >> a >> b >> c;
	if (a%2==0 || b%2==0 || c%2==0) cout << 0 << ln;
	else cout << min(a*b, min(b*c, c*a)) << ln;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int n, a, b, c, d;
    string s;
    cin>>n>>a>>b>>c>>d;
    cin>>s;

    s += "##";

    if(c < d)
    {
        int j = a-1;
        while(j < c-1)
        {
            if(s[j+1] == '#' && s[j+2] == '#')
            {
                cout<<"No\n";
                return 0;
            }
            if(s[j+1] == '#')
                j += 2;
            else
                j++;
        }

        j = b-1;
        while(j < d-1)
        {
            if(s[j+1] == '#' && s[j+2] == '#')
            {
                cout<<"No\n";
                return 0;
            }
            if(s[j+1] == '#')
                j += 2;
            else
                j++;
        }
    }
    else
    {
        int j = b-1;
        bool van = false;
        while(j < d-1)
        {
            if(j > 0 && s[j-1] == '.' && s[j+1] == '.')
                van = true;
            if(s[j+1] == '#' && s[j+2] == '#')
            {
                cout<<"No\n";
                return 0;
            }
            if(s[j+1] == '#')
                j += 2;
            else
                j++;
        }

        if(j > 0 && s[j-1] == '.' && s[j+1] == '.')
            van = true;

        if(!van)
        {
            cout<<"No\n";
            return 0;
        }

        j = a-1;
        while(j < c-1)
        {
            if(s[j+1] == '#' && s[j+2] == '#')
            {
                cout<<"No\n";
                return 0;
            }
            if(s[j+1] == '#')
                j += 2;
            else
                j++;
        }

    }

    cout<<"Yes\n";

    return 0;
}


Measured memory_bytes: 592
n, k = map(int, input().split())
s = input()


#count happy people
def count_happy(s):
    counter=False
    happy = 0
    for si in s:
        if si == "R" and counter:
            happy += 1
        elif si == "R":
            counter=True
        else:
            counter=False
    counter = False
    for si in s[::-1]:
        if si == "L" and counter:
            happy += 1
        elif si == "L":
            counter=True
        else:
            counter=False
    return happy

#group
happy = count_happy(s)

new_s = [s[0]]
last_char = s[0]
for si in s[1:]:
    if si == last_char:
        continue
    else:
        new_s.append(si)
        last_char = si

happy += min(len(new_s)//2, k)*2

if len(new_s)%2 == 0 and len(new_s)//2 <= k:
    happy -= 1

print(happy)


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll L, R;
    cin >> L >> R;

    if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    ll min_val = 2019;
    for (ll i = L; i <= R; i++) {
        for (ll j = i+1; j <= R; j++) {
            min_val = min(min_val, (i*j) % 2019);
        }
    }

    cout << min_val << endl;

    return 0;
}


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

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

int main() {
    int h, w; cin >> h >> w;
    vector<string> grid(h);
    int cnt_B = 0;
    vector<pair<int, int>> cur;
    for (int i = 0; i < h; i++) {
        cin >> grid[i];
        for (int j = 0; j < w; j++) {
            if (grid[i][j] == '#') {
                cnt_B++;
                cur.emplace_back(i, j);
            }
        }
    }
    int cnt = 0;
    while (cnt_B != h * w) {
        vector<pair<int, int>> nxt;
        for (auto p : cur) {
            for (int k = 0; k < 4; k++) {
                int ni = p.first + dx[k], nj = p.second + dy[k];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (grid[ni][nj] == '.') {
                    grid[ni][nj] = '#';
                    cnt_B++;
                    nxt.emplace_back(ni, nj);
                }
            }
        }
        swap(cur, nxt);
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 13188
#include <bits/stdc++.h>
using namespace std;
 
#define DEBUG if(1)
#define MAX INT_MAX
#define MAXLL LLONG_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
map<string, int> vis;
vector<string> vec;

void no(){
	cout << "No" << endl;
	exit(0);
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=0;i<n;i++){
  	string s;
  	cin >> s;
  	if(!i) vis[s] = 1, vec.pb(s);
  	else{
  		if(vis[s]) no();
  		vis[s] = 1;
  		string aux = vec[sz(vec)-1];
  		if(aux[sz(aux)-1] != s[0]) no();
  		vec.pb(s);
  	}
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
 
 
const int N = 100002;
int n, subsize[N], parent_[N];
vector<ii> adj[N];
 
 
void dfs(int v, int par){
    subsize[v] = 1;
    parent_[v] = par;
    for(auto it : adj[v])
        if(it.ff != par){
            dfs(it.ff, v);
            subsize[v] += subsize[it.ff];
        }
}
 

int dfs2(int v, int par, int tot){
    for(auto it : adj[v])
        if(it.ff != par && subsize[it.ff] > (tot/2))
            return dfs2(it.ff, v, tot);
    return v;
}

 
int main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin>>n;
    int e = n-1;
    while(e--){
        int a, b, c;
        cin>>a>>b>>c;
        adj[a].pb(ii(b, c));
        adj[b].pb(ii(a, c));
    }
 
    dfs(1, -1);
 
// cout<<"subsize: ";for(int i=1;i<=n;i++) cout<<subsize[i]<<" ";cout<<endl;
 
    ll ans = 0;
    for(int i=1;i<=n;i++)
        for(auto it : adj[i])
            if(it.ff > i){
                ll s = min(subsize[i], subsize[it.ff]);
                s = min(s, n-s);
                ans += 2LL * s * it.ss;
            }
 
    for(int i=1;i<=n;i++)
        if(2*subsize[i] == n){
            for(auto it : adj[i])
                if(it.ff == parent_[i]){
                    cout<<ans-it.ss;
                    return 0;
                }
        }

    int centroid = dfs2(1, -1, n), minval = MOD;
// cout<<centroid<<endl;
    for(auto it : adj[centroid])
        minval = min(minval, it.ss);

    cout<<ans - minval;
    return 0;
}
 




Measured memory_bytes: 11904
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
   long long a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   bool flag=true;
   rep(i,a){
      if(s.at(i)=='-'){
         flag=false;
      }
   }
   if(s.at(a)!='-'){
      flag=false;
   }
   for(int i=a+1;i<s.size();i++){
      if(s.at(i)=='-'){
         flag=false;
      }
   }
   if(flag){
      cout<<"Yes"<<endl;
   }
   else{
      cout<<"No"<<endl;
   }
   
}



Measured memory_bytes: 256
// binary tree walk
#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 30

struct Node{
    int p,l,r;
};

Node T[MAX];

void pre(int u);
void in(int u);
void post(int u);

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

    for(int i = 0; i < n; i++){
        int id, left, right;
        cin >> id >> left >> right;
        T[id].l = left; T[id].r = right;
        T[left].p = id; T[right].p = id; 
    }

    int root;
    for(int i = 0; i < n; i++){
        if(T[i].p == NIL) root = i;
    }
    
    cout << "Preorder" << endl;
    pre(root);
    cout << endl;
    cout << "Inorder" << endl;
    in(root);
    cout << endl;
    cout << "Postorder" << endl;
    post(root);
    cout << endl;

}

void pre(int u){
    if(u == NIL) return;
    cout << " " << u;
    pre(T[u].l);
    pre(T[u].r);
}

void in(int u){
    if(u == NIL) return;
    in(T[u].l);
    cout << " " << u;
    in(T[u].r);
}

void post(int u){
    if(u == NIL) return;
    post(T[u].l);
    post(T[u].r);
    cout << " " << u;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  int tmp = A[0];
  FOR(i, 1, N) { tmp = gcd(tmp, A[i]); }
  sort(rall(A));
  int big = A[0];
  if(K <= big && K % tmp == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)

unsigned GetDigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
  ll n;
  cin >> n;
  ll a[n];

  ll ans = 1;
  int flag =0;
  rep(i,0,n){
    cin >> a[i];
    if(a[i]==0){
      cout << 0 << endl;
      flag = 2;
      break;
    }
    if(GetDigit(ans)+GetDigit(a[i])>=20&&ans*a[i]!=1000000000000000000){
      ans = 1000000000000000001;
      flag = 1;
    }
    if(flag==0){
      ans = ans*a[i];
    }
  }
  if(flag==0||flag==1){
    if(ans<=1000000000000000000){
      cout << ans << endl;
    }
    else{
      cout << "-1" << endl;
    }
  }



}


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

using namespace std;

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

    vector<int> v(n);

    for(int i=0;i<n;i++)
        cin>>v[i];

    sort(v.begin(), v.end());

    int sum = 0;

    for(int i =0;i<k;i++)
        sum += v[i];

    cout << sum;

}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
int main()
{
		string s1,s2;
		cin>>s1>>s2;
int k,count,temp=99999,l=s2.size();
		for(int i=0;i<s1.size()-s2.size()+1;i++)
		{ 
			count=0;k=0;
			for(int j=i;j<l+i;j++)
			{
				if(s1[j]!=s2[k]) count++;
				k++;
			}
			if(count<temp) temp=count;
		}
cout<<temp<<endl;
	return 0;
}

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

int n;
int a[100005];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nowh=0x3f3f3f3f;
	int ans=0;
	int nowa=0;
	for(int i=1;i<=n;i++){
		if(a[i]<=nowh){
			nowh=a[i];
			nowa++;
			ans=max(ans,nowa);
		}
		else{
			nowa=1;
			nowh=a[i];
			ans=max(ans,nowa);
		}
	}
	cout<<ans-1;
}

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

int main()
{
  int N, L;
  cin >> N >> L;
  int min = 999;
  int min_ent = 999;
  int sum = 0;
  for(int i = 0; i < N; i++) {
    int temp = (L + i) > 0? L + i : -(L + i);
    if(temp < min) {
      min =  temp;
      min_ent = L + i;
    }
    sum += L + i;
  }
  cout << sum - min_ent;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;

#define pb 					push_back

template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}

template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<" ";

	return os;
}




vector<int>  adj[100002];
int deg[100002];
set<int> col[100002];
map<pair<int,int> ,int> m;
int ans[100002];

bool has(set<int> &s, int x ){
	return s.find(x)!=s.end();
}
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int k= 0;
	for(int i =1 ;i<=n-1;i++){
		int a, b;
		cin >> a>> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		deg[a]++;
		deg[b]++;
		m[{min(a, b), max(a, b)}]=i;
	}

	for(int i=1 ;i<=n;i++)
		k = max(k, deg[i]);

	for(int i= 1;i<=n;i++){
		int nc = 1;
		for(auto j: adj[i]) {
			if(j<i)
				continue;

			int mi = min(i, j);
			int ma = max(i, j);
			int in = m[{mi, ma}];
			// cout << i <<" "<<j<<",  "<<in<<"\n";
			while(has(col[i], nc) || has(col[j], nc))
				nc++;
			// cout << "col: "<<nc<<"\n";
			ans[in] =nc;
			col[i].insert(nc);
			col[j].insert(nc);
		}
	}
	cout << k << "\n";

	for(int i  =1 ;i<=n-1;i++)
		cout << ans[i]<<"\n";


	return 0;
}



Measured memory_bytes: 27136
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		string[] str2 = Console.ReadLine().Split();
		int GA = int.Parse(str[0]);
		int SA = int.Parse(str[1]);
		int BA = int.Parse(str[2]);
		int GB = int.Parse(str2[0]);
		int SB = int.Parse(str2[1]);
		int BB = int.Parse(str2[2]);
		double GC = GB/(double)GA;
		double SC = SB/(double)SA;
		double BC = BB/(double)BA;
		double GD = GA/(double)GB;
		double SD = SA/(double)SB;
		double BD = BA/(double)BB;
		long GN = 0;
		long SN = 0;
		long BN = 0;
		long ans = 0;
		long mct1 = N/GA;
		if(GC<=1){
			mct1 = 0;
		}
		for(var i=0;i<=mct1;i++){
			GN = i;
			long N01 = N;
			N01 -= GN*GA;
			long mct2 = N01/SA;
			if(SC<=1){
				mct2 = 0;
			}
			for(var j=0;j<=mct2;j++){
              	long N0 = N01;
				SN = j;
				N0 -= SN*SA;
				if(BC>1){
					BN = N0/BA;
					N0 -= BN*BA;
				} else {
					BN = 0;
				}
				N0 += SN*SB;
				N0 += BN*BB;
				N0 += GN*GB;
				ans = Math.Max(ans,N0);
			}
		}
		long N04 = ans;
		long mct3 = N04/GB;
		if(GD<=1){
			mct3 = 0;
		}
		for(var k=0;k<=mct3;k++){
			long N02 = N04;
			GN = k;
			N02 -= GN*GB;
			long mct4 = N02/SB;
			if(SD<=1){
				mct4 = 0;
			}
			long nct4 = 0;
			if(BD<=1){
				nct4 = N02/SB;
			}
			for(var l=nct4;l<=mct4;l++){
				long N03 = N02;
				SN = l;
				N03 -= SN*SB;
				if(BD>1){
					BN = N03/BB;
					N03 -= BN*BB;
				} else {
					BN = 0;
				}
				N03 += SN*SA;
				N03 += GN*GA;
				N03 += BN*BA;
				ans = Math.Max(ans,N03);
			}
		}
		Console.WriteLine(ans);
	}
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s,t; int i; cin >>s >>t;
	if (sz(t)-sz(s)!=1) {
		cout <<"No";
		return 0;
	}
	for (i=0;i<sz(s);i++) {
		if (t[i]!=s[i]) {
			cout <<"No";
			return 0;
		}
	}
	cout <<"Yes";
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int res = 0;
		
		for (int i = a; i <= b; i++) {
			if (isPalindromic(i)) {
				res++;
			}
		}
		System.out.println(res);
	}
  
	private static boolean isPalindromic(int n) {
		int num = n;
		int total = 0;
		while (num != 0) {
			total *= 10;
			total += (num % 10);
			num /= 10;
		}
		return n == total;
	}
	
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 23252
import java.io.*;
import static java.lang.Math.max;
import static java.lang.Integer.parseInt;

class Main {
   final static PrintWriter out = new PrintWriter( System.out );

   final static BufferedReader in =
         new BufferedReader( new InputStreamReader( System.in ) );

   final static StringBuilder sb = new StringBuilder("");

   static int lcs(char[] a, char[] b){
      final int alen = a.length;
      final int blen = b.length;
      int dp[][] = new int[alen+1][blen+1];

      for(int i=0; i<alen; ++i){
         for(int j=0; j<blen; ++j){
            if(a[i] == b[j])
               dp[i+1][j+1] = dp[i][j] + 1;
            else
               dp[i+1][j+1] = max( dp[i][j+1], dp[i+1][j] );
         }
      }
      return( dp[alen][blen] );
   }

   public static void main(String[] args) throws IOException {
      final int N = parseInt( in.readLine() );
      for(int i=0; i<N; ++i){
         char[] a = in.readLine().toCharArray();
         char[] b = in.readLine().toCharArray();
         sb.append( lcs(a,b) );
         sb.append('\n');
      }
      System.out.print(sb);
   }
}




Measured memory_bytes: 63280
import numpy as np
from numba import njit

@njit #処理の並列化

def imos(n, a):
    
    l=np.zeros((n+1), dtype = np.int64)

    for i in range(n):
        ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
        start = max(0, i - ai) #StartIndex_照らせる範囲
        end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
        l[start] += 1 # 各々を'+1'と'-1'で表し...
        l[end] -= 1
    return np.cumsum(l)[:n] # 累積和をとる_cumulative sum

n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    a = imos(n, a)
    if a.min() == n: # すべての要素が最大値'n'になるとbreak
        break

print(*a)


Measured memory_bytes: 124152
use proconio::input;
use itertools::Itertools;
use std::cmp::min;

//#[proconio::fastout]
fn main() {
    input! {
    n:usize,
    m:usize,
    x:i64,
    ca:[[i64;m+1];n],
    }

    let mut ans: Option<i64> = None;
    for i in 1..=n {
        for books in ca.iter().combinations(i) {
            let mut ul = vec![0i64; m + 1];
            for book in books {
                for j in 0..=m {
                    ul[j] += book[j];
                }
            }
            if ul[1..].iter().all(|u| u >= &x) {
                ans = Some(ans.map_or(ul[0], |cur| min(cur, ul[0])));
            }
        }
    }
    println!("{}", ans.unwrap_or(-1));
}


Measured memory_bytes: 2196
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    cout<<n/3<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc158/tasks/abc158_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string S = Console.ReadLine();
            string result = "";
            if (S == "AAA" || S == "BBB")
            {
                result = "No";
            }
            else
            {
                result = "Yes";
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
string a;
  
 
  cin >> a ;

  if(a[0] == 'S'){
    cout << "Cloudy" << endl;
  }
  else if(a[0] =='C'){
    cout <<"Rainy" << endl;
  }
    else{
      cout << "Sunny" << endl;
    }
}
      


Measured memory_bytes: 256