akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n; cin >> n;
    vector<vector<ll>> G(n);
    vector<pair<int, int>> vp;
    for (int i=1; i<n; ++i) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        vp.push_back(make_pair(a, b));
    }
    int k=0;
    map<pair<int, int>, int> I;
    vector<int> cs(n, 0);
    vector<int> used(n, 0);
    queue<int> que;
    used[0] = 1;
    que.push(0);
    while(!que.empty()){
        int v = que.front(); que.pop();
        if (k<(int)G[v].size()) k=G[v].size();
        int cur = 1;
        for(int u : G[v]) {
            if(used[u]) continue;
            if(cur == cs[v]) cur++;
            cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
            used[u] = 1;
            que.emplace(u);
        }
    }
    cout << k << endl;
    for(auto p : vp){
        cout << I[p] << endl;
    }
}

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

int main(void) {
	int n;
	long long cnt,cnt2,a,b,ch;
	cnt = cnt2 = 0;

	cin >> n;
	ch = n-1;
	for (a = 1;a < n - n/2;a++) {
		for (b = ch;b > 0;b--) {
			if (a*b < n) {
				cnt += b;
				ch = b;
				//cout << a << "*" << b << endl;
				break;
			}
		}
	}
	cnt += n / 2;

	cout << cnt << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define REP(i, a, n) for(int i=a; i<n; i++)
using namespace std;

string s;
int main() {
    cin>>s;
    int ans=0;
    REP(i, 0, s.size()){
        if(s[i]=='+') ans++;
        else ans--;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    vector<int> N(3);
    for(int i=0;i<3;i++){
        cin >> N.at(i);
    }
    sort(N.begin(), N.end());
    cout << N.at(2) * 10 + N.at(1) + N.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  while(n>ans*1000)ans++;
  cout<<(ans*1000-n)<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int dp[100000];
int main() {
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
        int x;
		cin >> x;
        dp[x] = 1;
	}
	dp[0] = 1;
	for(int i = 1; i <= n; i++) {
        if(dp[i]) dp[i] = 0;
        else{
            dp[i] = dp[i-1];
            if(i >= 2) {
                dp[i] += dp[i-2];
                if(dp[i] >= mod) dp[i] -= mod;
            }
        }
	}
	cout << dp[n] << endl;
	return 0;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;

}

//O(n^(1/2j))
long long int euler_phi(long long int n){
    long long int res=n;
    for(long long int i=2; i*i<=n; ++i){
        if(n%i==0){
            res=res/i*(i-1);
            while(n%i==0) n/=i;
        }
    }
    if(n!=1) res=res/n*(n-1);
    return res;
}

//O(nloglogn)
void euler_phi2(vector<int> &euler,int n){
    for(int i=0; i<n; ++i) euler[i]=i;
    for(int i=2; i<n; ++i){
        if(euler[i]==i){
            for(int j=i; j<n; j+=i) euler[j]=euler[j]/i*(i-1);
        }
    }
}

void solve(){
    int n;
    cin >> n;
    if(n<1e7){
        vector<int> euler(n+1);
        euler_phi2(euler,n+1);
        cout << euler[n] << endl;
    }else cout << euler_phi(n) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 41712
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 5e+5+5;
const int INF = 1e+9;

int n,k;
int p[N];
int q[N];
struct node{
	int l,r,w,val,ad;
}tree[N*2];
int tot;
int ans[N];

void build(int &now,int l,int r){
	now=++tot;
	tree[now].w=l;tree[now].val=-INF;tree[now].ad=0;
	if (l==r)return;
	int mid=(l+r)/2;
	build(tree[now].l,l,mid);
	build(tree[now].r,mid+1,r);
}

void change(int now,int l,int r,int x,int v){
	if (l==r){tree[now].val=v;return;}
	if (tree[now].ad){
		tree[tree[now].l].ad+=tree[now].ad;
		tree[tree[now].l].val+=tree[now].ad;
		tree[tree[now].r].ad+=tree[now].ad;
		tree[tree[now].r].val+=tree[now].ad;
		tree[now].ad=0;
	}
	int mid=(l+r)/2;
	if (x<=mid)change(tree[now].l,l,mid,x,v);
	else change(tree[now].r,mid+1,r,x,v);
	if (tree[tree[now].l].val<=tree[tree[now].r].val)tree[now].w=tree[tree[now].l].w,tree[now].val=tree[tree[now].l].val;
	else tree[now].w=tree[tree[now].r].w,tree[now].val=tree[tree[now].r].val;
}

void add(int now,int l,int r,int x,int y,int v){
	if (x<=l&&r<=y){tree[now].val+=v;tree[now].ad+=v;return;}
	if (tree[now].ad){
		tree[tree[now].l].ad+=tree[now].ad;
		tree[tree[now].l].val+=tree[now].ad;
		tree[tree[now].r].ad+=tree[now].ad;
		tree[tree[now].r].val+=tree[now].ad;
		tree[now].ad=0;
	}
	int mid=(l+r)/2;
	if (x<=mid)add(tree[now].l,l,mid,x,y,v);
	if (y>mid)add(tree[now].r,mid+1,r,x,y,v);
	if (tree[tree[now].l].val<=tree[tree[now].r].val)tree[now].w=tree[tree[now].l].w,tree[now].val=tree[tree[now].l].val;
	else tree[now].w=tree[tree[now].r].w,tree[now].val=tree[tree[now].r].val;
}

int main(){
	n=get();k=get();
	fo(i,1,n){p[i]=get();q[p[i]]=i;}
	int rt=0;
	build(rt,1,n);
	fd(i,n,1){
		add(1,1,n,max(1,q[i]-k+1),min(n,q[i]+k-1),1);
		change(1,1,n,q[i],0);
	}
	fo(i,1,n){
		int x=tree[1].w;
		ans[x]=i;
		add(1,1,n,max(1,x-k+1),min(n,x+k-1),-1);
		change(1,1,n,x,INF);
	}
	fo(i,1,n)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;

int main() {
  int H, N;
  cin >> H >> N;
  int w[N], v[N];
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  
  // i番目以下の魔法で、体力の総和j以上のときの最小の魔力
  int dp[N+1][H+1];
  
  for (int i = 0; i <= N; i++) {
    dp[i][0] = 0;
  }
  
  for (int j = 1; j <= H; j++) {
    dp[0][j] = INF;
  }
  
  for (int i = 0; i <= N-1; i++) {
    for (int j = 1; j <= H; j++) {
      if (j < w[i]) {dp[i+1][j] = min(v[i], dp[i][j]);}
      else {dp[i+1][j] = min(dp[i][j], dp[i+1][j-w[i]]+v[i]);}
    }
  }
  
  cout << dp[N][H] << endl;
}

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

int main(){
    int n,A=0,B=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<n;i=i+2){
        A+=a[i];
    }
    for(int i=1;i<n;i=i+2){
        B+=a[i];
    }
    cout << A-B << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
///////////////////////___combination___////////////////////
vector<ll> fac, finv, inv;
void COMinit(const int MAX = 5000000, const ll &MOD = MOD){
  fac.resize(MAX);finv.resize(MAX);inv.resize(MAX);
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  repd(i,2,MAX){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
ll COM(int n, int k){
  if(n < k)return 0;
  if(n < 0 || k < 0)return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

///////////////////////////////////////////////////////////
int n,k,a[1100];queue<int> q, r;
signed main(){
  cin>>n>>k;
  rep(i,n)cin>>a[i];
  int sum = 0;
  rep(i,n){
    sum = 0;
    repd(j,i,n){
      sum += a[j];
      q.push(sum);
    }
  }
  for(int i = 63;i >= 0;i--){
    q.push(-1);
    while(q.front() != -1){
      if(q.front()&(1LL<<i)){
        q.push(q.front());q.pop();
      }else{
        r.push(q.front());q.pop();
      }
    }
    q.pop();
    if(q.size() >= k){
      while(!r.empty()){
        r.pop();
      }
    }else{
      while(!r.empty()){
        q.push(r.front());r.pop();
      }
    }
  }
  
  int ans = ~0;
  rep(i,k){
    ans &= q.front();q.pop();
  }
  cout << ans << endl;
}



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

using namespace std;

typedef long long ll;

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    set <pair <int, int> > s;
    int n;
    scanf("%d", &n);
    vector <int> a(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        s.insert({a[i], -i});
    }
    vector <ll> cnt(n);
    int die = 0;
    while (s.size() > 0)
    {
        auto it = *prev(s.end());
        if (s.size() == 1)
        {
            die++;
            cnt[-it.second] += it.first * (ll) die;
            s.erase(it);
        }
        else
        {
            die++;
            cnt[-it.second] += (it.first - prev(prev(s.end()))->first) * (ll) die;
            it.first = prev(prev(s.end()))->first;
            s.erase(--s.end());
            s.insert(it);
            auto kek = s.lower_bound({it.first, -n});
            s.erase(kek);
        }
    }
    for (int i = 0; i < n; i++)
    {
        printf("%lld\n", cnt[i]);
    }
}


Measured memory_bytes: 6912
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

lint d[300][300]; // MAX_V
lint d2[300][300];
int V,E;
void warshallfloyd(){
  rep(i,V) rep(j,V) rep(k,V) d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
  return;
}
void warshallfloyd2(){
  rep(i,V) rep(j,V) rep(k,V) d2[j][k]=min(d2[j][k],d2[j][i]+d2[i][k]);
  return;
}

int main(void){
  lint L;
  cin >> V >> E >> L;
  rep(i,V) rep(j,V) d[i][j]=LINF/2,d2[i][j]=LINF/2;
  rep(i,V) d[i][i]=0,d2[i][i]=0;
  rep(i,E){
    int A,B;
    lint C;
    cin >> A >> B >> C;
    A--,B--;
    d[A][B]=C;
    d[B][A]=C;
  }
  warshallfloyd();
  rep(i,V) rep(j,V) if(d[i][j]<=L && i!=j) d2[i][j]=1;
  warshallfloyd2();
  int Q;
  cin >> Q;
  rep(i,Q){
    int s,t;
    cin >> s >> t;
    s--,t--;
    if(d2[s][t]>=LINF/2) cout << "-1" << endl;
    else cout << d2[s][t]-1 << endl;
  }
}

Measured memory_bytes: 1920
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	static int N,M;
	static List<Edge> edgeList;
	static long minInf = -10000000000000;
	static bool infFound;
	static long[] maxArr;

	//辺を保存する構造体
	public struct Edge
	{
		public int Start;
		public int Goal;
		public long Point;

		public Edge(int s, int g, long p){
			this.Start = s;
			this.Goal = g;
			this.Point = p;
		}
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] S = Console.ReadLine().Split(' ');
		N = int.Parse(S[0]);
		M = int.Parse(S[1]);

		//初期化
		edgeList = new List<Edge>();
		maxArr = new long[N];
		for(int i=1; i<N; i++){
			maxArr[i] =minInf;
		}

		for(int i=0; i<M; i++){
				string[] line = Console.ReadLine().Split(' ');
				int a = int.Parse(line[0])-1;
				int b = int.Parse(line[1])-1;
				long c = long.Parse(line[2]);

				Edge e = new Edge(a,b,c);
				edgeList.Add(e);
		}

		//ループで最大値を更新（Bellman-Ford法）
		//各ノードへの到達最大値を更新し続ける
		for(int i=0; i<N; i++){
			for(int j=0; j<M; j++){
				int start = edgeList[j].Start;
				int goal = edgeList[j].Goal;
				long point = edgeList[j].Point;

				//最大値を更新できる場合
				if(maxArr[start]+point > maxArr[goal]){
					maxArr[goal] = maxArr[start]+point;

					//N回目でかつ最終地点が更新される場合、無限ループする
					if(goal == N-1 && i == N-1){
							infFound = true;
					}
				}
			}
		}

		//出力
		if(infFound){
			Console.WriteLine("inf");
		}
		else{
			Console.WriteLine(maxArr[N-1]);
		}
	}
}



Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int mod = 1000000007;
int n, p[N], fa[N], sz[N], tag[N], f[N][N];
int Find(int x) {
	return fa[x] == x ? x : fa[x] = Find(fa[x]);
}
void Union(int x, int y) {
	x = Find(x), y = Find(y);
	if (x == y) return;
	if (sz[x] < sz[y]) swap(x, y);
	fa[y] = x;
	sz[x] += sz[y];
}
int pw[N], fact[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1, tag[i] = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &p[i]);
		if (p[i] != -1) Union(p[i], i);
	}
	pw[0] = 1;
	fact[0] = 1;
	for (int i = 1; i <= n; i++) pw[i] = 1ll * pw[i - 1] * (n - 1) % mod, fact[i] = 1ll * fact[i - 1] * i % mod;
	int prd = 1;
	for (int i = 1; i <= n; i++) if (p[i] == -1) {
		tag[Find(i)] = 1;
		prd = 1ll * prd * (n - 1) % mod;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) if (fa[i] == i) {
		if (!tag[i]) {
			ans = (ans + prd) % mod;
		}
	}
	int c = 0;
	f[c][0] = 1;
	for (int i = 1; i <= n; i++) if (p[i] == -1) {
		int wt = sz[Find(i)];
		for (int j = 0; j <= c; j++) f[c + 1][j] = f[c][j];
		for (int j = 0; j <= c; j++) if (f[c][j]) {
			f[c + 1][j + 1] = (f[c + 1][j + 1] + 1ll * f[c][j] * wt) % mod;
		}
		c++;
	}
	for (int i = 1; i <= n; i++) if (p[i] == -1) {
		int wt = sz[Find(i)];
		ans = (ans + 1ll * (wt - 1) * pw[c - 1]) % mod;
	}
	for (int i = 2; i <= c; i++) {
		ans = (ans + 1ll * f[c][i] * fact[i - 1] % mod * pw[c - i]) % mod;
	}
	ans = (1ll * pw[c] * n % mod - ans + mod) % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 70616
{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray
import           Data.Array.IO
import           Data.Array.MArray
import           Text.Printf

readi :: B.ByteString -> Int
readi bs | Just (n, _) <- B.readInt bs = n

format :: String
format = "node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n"

getSib :: Int -> Array Int Int -> Array Int [Int] -> Int
getSib n pary cary
    | p == -1   = -1
    | otherwise = head $ filter (/= n) cs
  where
    p  = pary ! n
    cs = cary ! p

getDegree :: Int -> Array Int [Int] -> Int
getDegree n cary = length $ filter (/= -1) (cary ! n)

getDepth :: Int -> Array Int Int -> Int
getDepth n pary = go 0 n
  where
    go !d !k
        | p == -1   = d
        | otherwise = go (d + 1) p
      where
        p = pary ! k

getHeight :: Int -> Array Int [Int] -> Int
getHeight n cary
    | n == -1            = 0
    | l == -1 && r == -1 = 0
    | otherwise          = 1 + max (getHeight l cary) (getHeight r cary)
  where
    [l, r] = cary ! n

main :: IO ()
main = do
    n <- readLn :: IO Int
    let f (i:cs) = (i, cs)
    xss <- fmap (f . fmap readi . B.words) . B.lines <$> B.getContents
    -- xss :: [(Int, [Int])]

    paryM <- newArray (0, n - 1) (-1) :: IO (IOArray Int Int)
    forM_ xss $ \(i, cs) -> do
        forM_ cs $ \c -> do
            when (c /= -1) $ writeArray paryM c i

    let cary = array (0, n - 1) xss :: Array Int [Int]
    pary <- freeze paryM :: IO (Array Int Int)

    forM_ [0 .. n - 1] $ \i -> do
        let p = pary ! i
        let cs = filter (/= -1) (cary ! i)
        let typ = case () of
                _ | p == -1 -> "root"
                  | null cs -> "leaf"
                  | otherwise -> "internal node"

        printf format
            i
            p
            (getSib i pary cary)
            (getDegree i cary)
            (getDepth i pary)
            (getHeight i cary)
            typ



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

using namespace std;

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

    double total = 0;
    double input;
    for (int i = 0; i < N; i++)
    {
        cin >> input;
        total += (1/input);
    }

    cout << (1/total);
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;


int main() {

	int k, s;
	cin >> k >> s;

	int res = 0;
	for (int i = 0;i <= k;i++) {
		for (int j = 0;j <= k;j++) {
				if ((i + j)<=s && (i+j)>=s-k)
					res++;
		}
	}

	cout << res;
}

Measured memory_bytes: 256
def area(ls):
    return ls[0] * ls[1]

def per(ls):
    return (2 * ls[0]) + (2 * ls[1])


if __name__ == '__main__':
    data = list(map(int, input().split()))
    s = area(data)
    l = per(data)
    print(s, l)

Measured memory_bytes: 7612
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
//#define MXN 300000
#define N 100005
int dp[2005][2005];
int mod=1e9+7;
LL fra[10000005];
LL inv[10000005];
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
void build(){
    fra[0]=1;
    for(int i = 1;i<10000005;i++)
        fra[i]=fra[i-1]*i%mod;
    inv[10000000]=f_pow(fra[10000000],mod-2);
    for(int i = 9999999;i>=0;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
}
LL C(int a,int b){
    return fra[a]*inv[b]%mod*inv[a-b]%mod;
}
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    if(k==1){
        printf("1\n");
        return 0;
    }
    build();
    dp[0][0]=1;
    for(int i = 1;i<=n;i++){
        dp[0][i]=dp[0][i-1]*C(i*(k-1)-1,k-2)%mod*(n-i+1)%mod;
        //printf("%d ",dp[0][i]);
        for(int j=1;j<=i;j++){
            dp[j][i]=(dp[j-1][i]+dp[j][i-1]*C(i*(k-1)+j-1,k-2)%mod*(n-i+1)%mod)%mod;
           // printf("%d ",dp[j][i]);
        }
      //  printf("\n");
        
    }
    printf("%d\n",dp[n][n]);
}

Measured memory_bytes: 171264
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    cin>>N;
    vec v1(N/2), v2(N/2);
    rep(i,N/2) cin>>v1[i]>>v2[i];
    if(N == 2){
        cout<<(v1[0]==v2[0])<<endl;
        return 0;
    }

    vec ord1(100010,0),ord2(100010,0);
    rep(i,100010) ord1[i] = ord2[i] = i;

    vec memo1(100010,0),memo2(100010,0);
    rep(i,N/2) ++memo1.at(v1[i]);
    sort(ord1.begin(),ord1.end(),[&](ll x,ll y){
        return memo1[y] < memo1[x];
    });

    rep(i,N/2) ++memo2.at(v2[i]);
    sort(ord2.begin(),ord2.end(),[&](ll x,ll y){
        return memo2[y] < memo2[x];
    });

    if(ord1[0] != ord2[0]){
        cout<<N-(memo1[ord1[0]]+memo2[ord2[0]])<<endl;
    }else{
        cout<<N-max(memo1[ord1[0]]+memo2[ord2[1]],
                    memo1[ord1[1]]+memo2[ord2[0]])<<endl;
    }
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    vector<vector<int64_t>> dp(N + 1, vector<int64_t>(W + 1, 0));

    for (int i = 0; i < N; i++)
        cin >> w[i] >> v[i];
    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (w[i - 1] <= j)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
        }
    }
    cout << dp[N][W];
}

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

using namespace std;
const int MAXN = 100010;

int n;

namespace Tree {
	int head[MAXN], nxt[MAXN<<1], to[MAXN<<1], eidx = 0;
	void init() {
		memset( head, -1, sizeof(head) );
	}
	void adde( int u, int v ) {
		to[eidx] = v, nxt[eidx] = head[u], head[u] = eidx++;
		to[eidx] = u, nxt[eidx] = head[v], head[v] = eidx++;
	}
}

int dfs( int u, int fa ) {
	using namespace Tree;
	int sg = 0;
	for( int i = head[u]; ~i; i = nxt[i] ) {
		int v = to[i];
		if( v == fa ) continue;
		sg ^= dfs(v, u) + 1;
	}
	return sg;
}

int main() {
	scanf( "%d", &n );
	Tree::init();
	for( int i = 0; i < n-1; ++i ) {
		int x, y;
		scanf( "%d%d", &x, &y );
		Tree::adde(x, y);
	}
	puts( dfs(1, 0) ? "Alice" : "Bob" );
	return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int sum[100010];
int cnt[100010];
vector<int> w[100010];
int dfs(int now){
  if(w[now].size()==0)return 0;
  int ret=0;
  vector<int> p;
  int yy=w[now].size();
  int mi=1000000000;
  for(int i=0;i<w[now].size();i++){
    int u=dfs(w[now][i]);
    p.push_back(u);
  }
  sort(p.begin(),p.end());
  for(int i=0;i<p.size();i++)ret=max(ret,p[i]+yy-i);
  return ret;
}
int main(){
  int n;cin>>n;
  fill(cnt,cnt+n+1,0);
  for(int i=2;i<=n;i++){
    cin>>a[i];
    cnt[a[i]]++;
    w[a[i]].push_back(i);
  }
  vector<int> v;
  for(int i=1;i<=n;i++){
    if(cnt[i]==0)v.push_back(i);
  }
  fill(sum,sum+n+1,0);
  int ans=dfs(1);
  cout<<ans<<endl;
}

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

int main(){
    int n; cin>>n;
    int a[n]; rep(i,n) cin>>a[i];
    rep(i,n){
        cout<<a[i]<<(n-1-i?" ":"\n");
    }
    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        rep(i,n){
            cout<<a[i]<<(n-1-i?" ":"\n");
        }
    }

    return 0;
}



Measured memory_bytes: 3108
import numpy as np
import copy

# d日目の終わりで低下する満足度
def cost(c, d, lastdi):
    total = 0
    for i in range(26):
        total += c[i]*(d - lastdi[i])
    return total

# 日数
D = int(input())
# type毎の満足度の下がりやすさ
c = list(map(int, input().split()))

# [d,i]の満足度
s = [[] for _ in range(D)]
for d in range(D):
    si = list(map(int, input().split()))
    s[d] = si

# type毎の最後に開催された日を管理
lastdi = [0 for _ in range(26)]

for d in range(D):
    # その日の満足度リストをソートしてindexを取得    
    sd_sort = np.argsort(s[d])
    max_ans = 0
    typei = -1
    
    for i in range(26):
        tmp_lastdi = copy.deepcopy(lastdi)
        choicei = sd_sort[i]
        tmp_lastdi[choicei] = d+1 # 日付なので+1
        ans = s[d][choicei] - cost(c, d+1, tmp_lastdi)
        if ans > max_ans:
            # print("更新{}".format(ans))
            typei = choicei

    lastdi[typei] = d+1 # 日付なので+1
    typei = s[d].index(max(s[d])) + 1
    print(typei)


Measured memory_bytes: 27548
#145c Average length
#順列探索の勉強
import itertools
import math
n=int(input())
data=[]
for i in range(n):
  point=list(map(int,input().split()))
  data.append(point)
length=0
lis=[ x for x in range(n) ]
permutation=itertools.permutations(lis)
ansbig=0
for one_case in permutation:
  alldistance=0
  for k in range(n-1) :
    xk=data[one_case[k]][0]
    yk=data[one_case[k]][1]
    xknext=data[one_case[k+1]][0]
    yknext=data[one_case[k+1]][1]
    distance=((xk-xknext)**2+(yk-yknext)**2)**(1/2)
    alldistance+=distance
  ansbig+=alldistance
  
print(ansbig/math.factorial(n))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))
    diff = float('inf')
    ans = 0
    ave = sum(a) / n

    for i, ai in enumerate(a):
        if abs(ai - ave) < diff:
            diff = abs(ai - ave)
            ans = i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
  int a, b, c, d, n;
  int count = 0;

  while ( scanf("%d", &n) == 1 ) {

    for (a = 0; a <= 9; a++) {
      for (b = 0; b <= 9; b++) {
        for (c = 0; c <= 9; c++) {
          for (d = 0; d <= 9; d++) {
            if (a + b + c + d == n) {
              count++;
            }
          }
        }
      }
    }

    printf("%d\n", count);
    count = 0;
  }

  return 0;
}

Measured memory_bytes: 596
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if (4*h*n-N*(h+n)) != 0:
            w = N*h*n/(4*h*n-N*(h+n))
            if float.is_integer(w) and w > 0:
                print(h, n, int(w))
                exit()


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

using namespace std;

using ll = long long;
using Graph = vector< vector<int> >;

constexpr ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

constexpr int MAXN = 200000;

ll f[MAXN + 1], fi[MAXN + 1];

void init() {
    f[0] = 1;
    for (int i = 1; i <= MAXN; ++i) {
        f[i] = f[i - 1] * i % MOD;
    }

    fi[MAXN] = modpow(f[MAXN], MOD - 2);
    for (int i = MAXN; i > 0; --i) {
        fi[i - 1] = fi[i] * i % MOD;
    }
}

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

void dfs1(int cur, int par, const Graph& g, vector<int>& v, vector<ll>& dp1) {
    v[cur] = 1;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        dfs1(nex, cur, g, v, dp1);
        v[cur] += v[nex];
    }

    int rest = v[cur] - 1;
    dp1[cur] = 1;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        (dp1[cur] *= comb(rest, v[nex]) * dp1[nex] % MOD) %= MOD;
        rest -= v[nex];
    }
}

void dfs2(int cur, int par, ll par_dp, const Graph& g, const vector<int>& v, const vector<ll>& dp1, vector<ll>& dp2) {
    int n = g.size();

    int rest = n - 1;
    dp2[cur] = par_dp;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        (dp2[cur] *= comb(rest, v[nex]) * dp1[nex] % MOD) %= MOD;
        rest -= v[nex];
    }

    for (int nex : g[cur]) {
        if (nex == par) continue;
        ll tmp = dp2[cur] * modpow(comb(n - 1, v[nex]) * dp1[nex] % MOD, MOD - 2) % MOD;
        dfs2(nex, cur, tmp, g, v, dp1, dp2);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    
    Graph g(n);
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    init();

    vector<int> v(n);
    vector<ll> dp1(n);
    dfs1(0, -1, g, v, dp1);

    vector<ll> dp2(n);
    dfs2(0, -1, 1, g, v, dp1, dp2);

    for (int i = 0; i < n; ++i) {
        cout << dp2[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 20980
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

int main() {
  std::cout << std::setprecision(9);
  int l, r;
  cin >> l >> r;

  if (r - l >= 2018) {
    cout << 0 << endl;
  }
  else if (l % 2019 > r % 2019) {
    cout << 0 << endl;
  }
  else {
    int ans = 2019;
    int mod;
    for (int i=l; i<r; i++) {
      for (int j=i+1; j<=r; j++) {
        mod = ((i % 2019) * (j % 2019)) % 2019;
        if (ans > mod) {
          ans = mod;
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#define M_PIl 3.141592653589793238462643383279502884L

int main(int argc, char *argv[])
{
    double r;
    scanf("%lf", &r);
    const double area = M_PIl * r * r;
    const double circumference = 2 * M_PIl * r;
    printf("%.6f %.6f\n", area, circumference);
    return 0;
}



Measured memory_bytes: 2076
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
using pos = pair<int, int>;

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

int map[30][30];

const pos moves[] = {
    pos(0, 1),
    pos(1, 0),
    pos(0, -1),
    pos(-1, 0),
};

int max_distance(int y, int x, const int H, const int W) {
  // cout << "max_distance" << endl;
  queue<pos> qs;
  qs.push(pos(y, x));
  int tm[30][30] = {0};
  tm[y][x] = 1;
  int ans = 0;
  while(!qs.empty()) {
    auto p = qs.front();
    qs.pop();

    // cout << p.first << ", " << p.second << endl;
    if(map[p.first][p.second] > 0) {
      continue;
    }
    for(auto m : moves) {
      auto ny = m.first + p.first;
      auto nx = m.second + p.second;
      if(ny < 0 || H <= ny) {
        continue;
      }
      if(nx < 0 || W <= nx) {
        continue;
      }
      if(map[ny][nx] > 0) {
        continue;
      }
      if(tm[ny][nx] > 0) {
        continue;
      }
      int nv = tm[p.first][p.second] + 1;
      tm[ny][nx] = nv;
      chmax(ans, nv);
      qs.push(pos(ny, nx));
    }
  }
  // cout << "ans : " << y << ", " << x << " : " << ans << endl;
  return ans - 1;
}

int main() {
  int H, W;
  cin >> H >> W;
  for(int h = 0; h < H; ++h) {
    string s;
    cin >> s;
    for(int w = 0; w < W; ++w) {
      map[h][w] = (s[w] == '.' ? 0 : 1);
    }
  }
  int ans = 0;
  for(int h = 0; h < H; ++h) {
    for(int w = 0; w < W; ++w) {
      auto dist = max_distance(h, w, H, W);
      // cout << h << ", " << w << " : " << dist << endl;
      chmax(ans, dist);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

ll MOD;

int calc_lg(ll x) {
  int res = 0;
  while (x > 0) {
    ++res;
    x /= 10;
  }
  return res;
}

ll calc_ten(int e) {
  ll v = 1;
  for (int i = 0; i < e; i++) v *= 10;
  return v;
}

ll power(ll x, ll e) {
  x %= MOD;
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

typedef vector<ll> Vec;
typedef vector<Vec> Mat;

Mat eye(int n) {
  Mat I(n, Vec(n));
  for (int i = 0; i < n; ++i)
    I[i][i] = 1;
  return I;
}
Mat mul(Mat A, const Mat& B) {
  for (int i = 0; i < A.size(); ++i) {
    Vec x(A[0].size());
    for (int k = 0; k < B.size(); ++k)
      for (int j = 0; j < B[0].size(); ++j)
        (x[j] += A[i][k] * B[k][j] % MOD) %= MOD;
    A[i].swap(x);
  }
  return A;
}
Mat pow(Mat A, ll k) {
  Mat X = eye(A.size());
  for (; k > 0; k /= 2) {
    if (k & 1) X = mul(X, A);
    A = mul(A, A);
  }
  return X;
}
Vec mul(const Mat& A, const Vec& b) {
  Vec y(A.size());
  for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < A[0].size(); ++j)
      (y[i] += A[i][j] * b[j] % MOD) %= MOD;
  return y;
}

ll solveSub(ll A, ll B, ll L, ll ten) {
  A %= MOD;
  B %= MOD;
  ten %= MOD;
  Mat M = {
      {ten, A, B},
      {0, 1, 0},
      {0, 1, 1}};
  vector<ll> init = {0, 1, 0};
  auto goal = mul(pow(M, L), init);
  return goal[0];
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  ll L, A, B;
  while (cin >> L >> A >> B >> MOD) {
    ll res = 0, cur = 0;
    while (cur < L) {
      int lg = calc_lg(A);
      ll ten = calc_ten(lg);
      // x >= (ten - A) / B
      ll x = min(L - cur, (ten - A + B - 1) / B);
      res = res * power(ten, x) % MOD;
      res += solveSub(A, B, x, ten);
      res %= MOD;
      cur += x;
      A += B * x;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}

int main() {
  long long a, b;
  while (cin >> a >> b) {
    long long g = gcd(a, b);
    cout << g << " " << a * b / g << endl;
  }
  return 0;
}

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

int main() {

  int K, X;
  cin >> K >> X;

  vector<int> ans(K * 2 - 1);

  ans.at(0) = X - K + 1;
  cout << ans.at(0) << endl;

  for (int i = 1; i < ans.size(); i++) {
     ans.at(i) = ans.at(i - 1) + 1;
     cout << ans.at(i) << endl;
   }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
using ll = long long;

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

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

int main() {
	double a, b, c, d;
	std::cin >> a >> b >> c >> d;
	std::cout << std::setprecision(16) << sqrt((c - a)*(c - a) + (d - b)*(d - b)) << std::endl;
	return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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; }
const int INF = 1000100100;

int main() {
    string S, T;
    cin >> S >> T;

    S += S;
    REP(i, S.length() / 2) {
        if(S.substr(i, T.length()) == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int>e[N];
vector<int>fi,se;
int x,y,lc,a,b;
int n,u,v,par[N],dep[N],mx,dis;
void dfs(int now,int fa,int d)
{
	par[now]=fa;
	dep[now]=d;
	for(int i=0;i<e[now].size();++i)
	{
		int nex=e[now][i];
		if(nex==fa)continue;
		dfs(nex,now,d+1);
	}
}
void dfs2(int u,int fa,int d)
{
	par[u]=fa;
	dep[u]=d;
	mx=max(mx,dep[u]);
	for(int v:e[u])
	{
		if(v==fa)continue;
		if(u==a&&v==b)continue;
		if(u==b&&v==a)continue;
		dfs2(v,u,d+1);
	}
}
void lca(int u,int v)
{
	int a=u,b=v;
	if(dep[u]<dep[v])swap(u,v);
	for(;dep[u]!=dep[v];u=par[u]);
	if(u==v)
	{
		lc=u;
		dis=dep[a]+dep[b]-2*dep[u];
		return;
	}
	for(;u!=v;u=par[u],v=par[v]);
	if(u==v)
	{
		lc=u;
		dis=dep[a]+dep[b]-2*dep[u];
		return;
	}
}
int main()
{
	scanf("%d%d%d",&n,&u,&v);
	for(int i=1;i<n;++i)
	{
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1,0,0);
	//for(int i=1;i<=n;++i)
	//printf("dep%d:%d\n",i,dep[i]);
	lca(u,v);
	//printf("dis:%d\n",dis);
	a=v,b=u;
	for(;b!=lc;b=par[b])fi.push_back(b);
	for(;a!=lc;a=par[a])se.push_back(a);
	reverse(se.begin(),se.end());
	fi.push_back(lc);
	for(int v:se)fi.push_back(v);
	int id=(dis-1)/2;
	a=fi[id];b=fi[id+1]; 
	//printf("a:%d b:%d\n",a,b);
	memset(dep,0,sizeof dep);
	dfs2(a,0,0);
	if(dis%2==0)id++;
	printf("%d\n",id+mx);
	return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

ll dp[110][2][2][4];

int main(void){
	string s; int k;
	cin >> s >> k;
	const int n = s.size();

	dp[0][0][0][0] = 1LL;

	rep(i, n) rep(nz, 2) rep(le, 2) rep(a, k + 1) {
		rep(d, 10) {
			const int ni = i + 1;
			const int nnz = nz || (d != 0);
			if(le == 0 and d > s[i] - '0') continue;
			int nle = le;
			if(d < s[i] - '0') nle = 1;
			const int na = a + (d != 0);
			if(na > k) continue;
			dp[ni][nnz][nle][na] += dp[i][nz][le][a];
		}
	}

	cout << dp[n][1][0][k] + dp[n][1][1][k] << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
count = 0
for i in range(1000):
    j = i
    if(j<10):
        first = S.find('0')    
        if(first >= 0 and first < N):
            second = S[first+1:].find('0')    
            if(second >= 0 and first+second+2 < N):
                third = S[first+second+2:].find(str(j))
                if(third>=0):
                    count += 1
    elif(j<100):
        first = S.find('0')
        if(first >= 0 and first < N):
            second = S[first+1:].find(str((j%100)//10))
            if(second >= 0 and first+second+2 < N):
                third = S[first+second+2:].find(str(j%10))
                if(third>=0):
                    count += 1
    else:
        first = S.find(str(j//100))    
        if(first >= 0 and first < N):
            second = S[first+1:].find(str((j%100)//10))    
            if(second >= 0 and first+second+2 < N):
                third = S[first+second+2:].find(str(j%10))
                if(third>=0 ):
                    count += 1  
print(count)

Measured memory_bytes: 3188
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=0
for i in range(n):
  if n>=i and x>=a[i]:
    x-=a[i]
    c+=1
    if n==c and x==0:
      print(n)
    if n==c and x!=0:
      print(n-1)
  else:
    print(c)
    break

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



int main(void){
    int n,k;
    int sum=0;
    cin >> n;
    cin >> k;
    string s;
    cin >> s;
    
    rep(i,s.size()){
        if(s[i] == s[i+1]){
            sum++;
        }
    }
    cout << min(sum+2*k,n-1);
  
    return 0;
}






Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void c_p_c(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int minCost(ll *h,int n){
	ll dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
		dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
	return dp[n-1];
}
int main()
{
	c_p_c();
	int n;
	cin>>n;
	ll h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	cout<<minCost(h,n)<<"\n";
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N = in();
	map<int, int> ds;
	rep(i,N)ds[in()]++;
	int M = in();
	rep(i,M) {
		int T = in();
		if (ds[T] <= 0) {
			cout << "NO" << endl;
			return 0;
		}
		ds[T]--;
	}
	cout << "YES" << endl;
	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();

  map<string, int> count;
  REP(i, N) {
    string s; cin >> s;
    count[s]++;
  }
  for (string s: {"AC", "WA", "TLE", "RE"})
    cout << s << " x " << count[s] << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[2] = {0, 1};
ll dy[2] = {1, 0};

int main(void){
    ll n, m;
    cin >> n >> m;
    ll sum = 0;
    vector<ll> g(n+1, 0);
    bool ans = true;
    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        g[a]++; g[b]++;
    }
    for(ll i = 1; i <= n; i++){
        if(g[i]%2!=0) ans=false;
    }
    if(ans==true) cout << "YES" << endl;
    if(ans==false) cout << "NO" << endl;
    return 0;
}


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

int main(void){
  int n;
  cin >> n;
  int l[n];
  for(int i = 0; i < n; i++) cin >> l[i];
  for(int i = 0; i < n; i++)
    for(int j = i + 1; j < n; j++)
      if(l[i] < l[j])
	swap(l[i], l[j]);
  int sum = 0;
  for(int i = 1; i < n; i++) sum += l[i];
  if(l[0] < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,K;cin>>N>>K;
    map<ll,ll> MA;
    
    vector<ll> d;
    for(ll i=1;i*i<=N;i++){
        if(N%i) continue;
        d.push_back(i);
        if(i*i!=N) d.push_back(N/i);
    }
    
    sort(all(d));
    
    for(ll a:d){
        ll sum=rui(K,(a+1)/2);
        for(ll b:d){
            if(b>=a) break;
            if(a%b) continue;
            
            sum-=MA[b];
            sum+=mod;
        }
        sum%=mod;
        MA[a]=sum;
    }
    
    ll ans=0;
    
    for(auto a:MA){
        if(a.fi%2==0) ans+=a.fi*a.se/2;
        else ans+=a.fi*a.se;
        ans%=mod;
        //cout<<a.fi<<" "<<a.se<<endl;
    }
    
    cout<<ans<<endl;
    
}



Measured memory_bytes: 384