akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 25;
const int mod = 1000000007;

string s[maxn];
int n,m;
int d[maxn][maxn];
int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int solve(int sx, int sy){
  memset(d,-1,sizeof(d));
  queue<int>qx,qy;
  d[sx][sy] = 0;
  qx.push(sx);
  qy.push(sy);
  int ret = 0;
  while(!qx.empty()){
    int x = qx.front();
    qx.pop();
    int y = qy.front();
    qy.pop();
    ret=max(ret, d[x][y]);
    for(int i=0;i<4;i++){
      int nx = x +dir[i][0];
      int ny = y+dir[i][1];
      if(nx<0||nx>=n||ny<0||ny>=m||d[nx][ny]!=-1||s[nx][ny]!='.')continue;
      d[nx][ny] = d[x][y]+1;
      qx.push(nx);
      qy.push(ny);
    }
  }
  return ret;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>s[i];
  int ret = 0;
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++){
      if(s[i][j]=='.')ret=max(ret, solve(i,j));
    }
  cout<<ret<<endl;
  return 0;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n){
  cin >> p.at(i);
  }
  
  double sum = 0, ans = 0;
  
  for(int i = 0; i < k; i++){
    sum += p.at(i);
  }
    ans = max(ans, (sum+k)/2);
  
  for(int i = 0; i < n-k; i++){
    sum = sum -p.at(i)+p.at(i+k);
    ans = max(ans, (sum+k)/2);    
  }
  
  printf("%.10f\n",ans);
  
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
vector<int> match = {-1,2,5,5,4,5,6,3,7,6};
void Main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> approval(m);//first:本数　second:数
    For(i,0,m) {
        cin >> approval[i].second;
        approval[i].first = match[approval[i].second];
    }
    sort(ALL(approval), [](auto const& l, auto const& r) {//数の大きい順にソート
       if(l.second != r.second) return l.second > r.second;
       else return l.first > r.first;
    });
    vector<vector<string>> dp(m+1,vector<string> (n+1));
    For(j,0,n+1) dp[0][j]="";
    For(i,0,m+1) dp[i][0]="";
    For(i,0,m){
        For(j,1,n+1){
            if(j<approval[i].first) dp[i+1][j]=dp[i][j];
            else{
                string str1 = dp[i][j];
                string str2 = dp[i+1][j-approval[i].first];
                if(str2 == "" && j != approval[i].first) dp[i+1][j]=str1;
                else{
                    str2.push_back(char(approval[i].second + '0'));
                    if(str1.size()>str2.size()) dp[i+1][j]=str1;
                    else if(str1.size()<str2.size()) dp[i+1][j]=str2;
                    else if(str1>str2) dp[i+1][j]=str1;
                    else dp[i+1][j]=str2;
                }
            }
        }
    }
    cout << dp[m][n] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 99840
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

int main() {
	int n=read(); double d=read(),x=read(),ans=0;
	while (n) {
		ans+=(2*d+(2*n-1)*x)/2;
		d=d+(2*d+5*x)/2/n;
		x=x+2.0*x/n;
		--n;
	}
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 3776
N,S = map(int,input().split())
*A, = map(int,input().split())

A.sort()

MOD = 998244353

dp = [[0]*(S+1) for _ in [0]*(N+1)]
dp[0][0] = 1
for i,a in enumerate(A):
    for s in range(S+1):
        dp[i+1][s] = dp[i][s]*2
        if s-a>=0:
            dp[i+1][s] += dp[i][s-a]
        dp[i+1][s] %= MOD
print(dp[-1][S])

Measured memory_bytes: 139200
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vl a(n);
  REP(i, n) { cin >> a[i]; }
  sort(a.rbegin(), a.rend());

  int ok = 0;
  int ng = n;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (mid <= p - 1 || a[p - 1] == a[mid]) {
      ok = mid;
      continue;
    }
    if (a[mid] + m < a[p - 1]) {
      ng = mid;
      continue;
    }

    ll count = 0LL;
    FOR(j, p - 1, mid) { count += a[j] - a[mid]; }
    if (count <= (n - v) * m) {
      ok = mid;
      continue;
    } else {
      ng = mid;
      continue;
    }
  }
  cout << ok + 1LL << endl;
}


Measured memory_bytes: 1024
s=int(input())
mod = 10**9+7

dp = [0]*(s+1)
dp[0] = 1
x = 0

for i in range(1,s+1):
  if i-3>=0:
    x += dp[i-3]
    x %= mod
  dp[i]=x
print(dp[s])
    

Measured memory_bytes: 9192
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

ll cal(ll a, ll b){
	if(a==b){
		return 2*(a-1);
	}
	long double g = a*b-1;
	ll N = ll(sqrt(g));
	if(N*(N+1)<=a*b-1){
		return 2*N-1;
	}
	else{
		return 2*N-1-1;
	}
}

void _main(istream &inp){
	ll Q,a,b;
	inp >> Q;
	rep(i,Q){
		inp >> a >> b;
		cout << cal(a,b) << endl;
	}
}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    int broj_djeljivih = 0;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (x % 2 != 0 or (x % 3 == 0 or x % 5 == 0))
            broj_djeljivih++;
    }
    if (broj_djeljivih == n)
        cout << "APPROVED";
    else
        cout << "DENIED";
}


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

int main()
{
	long long int X, Y;

	cin >> X >> Y;

	int ans = 0,f = 1;

	for (long long int i = X,m = 0; i <= Y; i++,f = 1) {
		m = i;
		for (;;) {
			if (m * 2 > Y)break;
			m *= 2;
			f++;
		}
		if (ans < f) {
			ans = f;
			break;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;
int main(){
int n,i=1,l;
cin>>n;
int n1=n;
if(n==3){
	cout<<"2 5 63"<<endl;
	return 0;
}
if(n%2==0){
	l=2;
}
else{
	l=3;
}

while(n>l&&i<=30000){
	if(i%3==0&&i%2==1){
		cout<<i<<" ";
		n--;
	}
	
	i++;
}
int sum=0,max=0;
for(int i=0;i<n-1;i++){
	cout<<(i+1)*2<<" ";
	sum=sum+(i+1)*2;
	max=(i+1)*2;
}
for(int i=max+2;i<=max+6;i=i+2){
	if((sum+i)%3==0){
		cout<<i<<endl;
		return 0;
	}
}
return 0;
}


Measured memory_bytes: 384
N,L=map(int,input().split())
apple_taste=[0]*N
eat_apple=0
for i in range(0,N):
    apple_taste[i]+=L+i
    if abs(apple_taste[eat_apple])>abs(apple_taste[i]):
        eat_apple=i

print(sum(apple_taste)-apple_taste[eat_apple])

Measured memory_bytes: 3060
class Acc2D:
    def __init__(self, H, W, tab=None):
        self.tab=[row[:] for row in tab] if tab else [[0]*W for _ in range(H)]
        self.H, self.W = H,W

    def add(self, x, y, val):
        self.tab[y][x]+=val
    
    def build(self):
        for y in range(self.H):
            for x in range(1,self.W):
                self.tab[y][x]+=self.tab[y][x-1]
        
        for y in range(1,self.H):
            for x in range(self.W):
                self.tab[y][x]+=self.tab[y-1][x]
    
    def query(self,x0,y0,x1,y1):
        """
        find number of points in [x0,x1)x[y0,y1)
        (x1>x0 and y1>y0)
        """
        return self.tab[y1][x1]-self.tab[y1][x0]-self.tab[y0][x1]+self.tab[y0][x0]
    
N,M,Q=map(int,input().split())
acc = Acc2D(N+1,N+1)

for _ in range(M):
    l,r = map(int,input().split())
    acc.add(l,r,1)

acc.build()

for _ in range(Q):
    p,q = map(int,input().split())
    print(acc.query(p-1,p-1,q,q))


Measured memory_bytes: 59620
#include <iostream>
#include <algorithm>

using namespace std;

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

    string x = s.substr(0, n / 2), y = s.substr(n / 2 + 1, n / 2);
    string a = x, b = y, t = s;
    reverse(a.begin(), a.end()), reverse(b.begin(), b.end()), reverse(t.begin(), t.end());

    cout << ((a == x) && (b == y) && (s == t) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;		     
}

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);

  Node y = x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;

  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->right=x;
  else y->parent->right=x;

  if(y!=z)z->key=y->key;


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;
  
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20468
import sys
readline = sys.stdin.readline
from operator import itemgetter

class UF():
    def __init__(self, num):
        self.par = [-1]*num
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            stack = []
            while self.par[x] >= 0:
                stack.append(x)
                x = self.par[x]
            for xi in stack:
                self.par[xi] = x
            return x
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] > self.par[ry]:
                rx, ry = ry, rx
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
        return rx

N = int(readline())
XY = []
for i in range(N):
    x, y = map(int, readline().split())
    XY.append((i, x, y))

_, _, Y = map(list, zip(*XY))

XY.sort(key = itemgetter(1))

T = UF(N)

stack = []
for i, _, y in XY:
    my = i
    while stack and Y[stack[-1]] < y:
        if Y[stack[-1]] < Y[my]:
            my = stack[-1]
        T.union(stack.pop(), i)
    stack.append(my)
ans = [-T.par[T.find(i)] for i in range(N)]
    
print('\n'.join(map(str, ans)))

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

using namespace std;

map<string,int> word;
string s;
int n,m;
int mv;

int main(){

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(word.count(s)==0){
            word.insert(make_pair(s,0));
        }
         word.at(s)++;
    }

    cin>>m;
    for(int i=0;i<m;i++){
        cin>>s;
        if(word.count(s)==0){
            word.insert(make_pair(s,0));
        }
         word.at(s)--;
    }

    map<string,int>::iterator ite;

    for(ite=word.begin(); ite!=word.end();ite++){
        if(ite->second>mv){
            mv=ite->second;
        }
    }

    if(mv<0){
        cout<<'0'<<endl;
    }else{
    cout<<mv<<endl;
    }
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define mp make_pair


int main () {
  long long n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll sub = 0;
  rep (i, 50) {
    if (i % 2) {
      sub -= pow(2, i);
    }
  }
  ll tar = n - sub;
  string ans;
  rep (i, 50) {
    if (i % 2 == 0) {  
      if ((1LL << i) & tar) {
        ans.push_back('1');
      }
      else {
        ans.push_back('0');
      }
    }
    else {
      if ((1LL << i) & tar) {
        ans.push_back('0');
      }
      else {
        ans.push_back('1');
      }
    }
  }
  reverse(all(ans));
  while (ans[0] == '0') {
    ans.erase(ans.begin());
  }
  cout << ans << endl;
}
      
  






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
const int MAX_N=100010;
struct UF{
    int par[MAX_N];
    int sizes[MAX_N];
    void init (int n){
        for (int i=0;i<n;i++){
            par[i]=i;
            sizes[i]=1;
        }
    }
    int find (int x){
        if (par[x]==x){
            return x;
        }
        else{
            return par[x] = find(par[x]);
        }
    }
    void unite (int x, int y){
        x=find(x);
        y=find(y);
        if (x==y) return;
        if (sizes[x] < sizes[y]) swap(x,y);
        par[y]=x;
        sizes[x]+=sizes[y];
    }
    bool same (int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return sizes[find(x)];
    }
};
UF uf;
int N,M;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M;
    uf.init(N);
    rep(i,0,M){
        int x,y,z;
        cin>>x>>y>>z;
        uf.unite(x-1, y-1);
    }
    set<int> root;
    rep(i,0,N){
        root.insert(uf.find(i));
    }
    cout <<sz(root)<<"\n";
}

Measured memory_bytes: 5760
n,m=gets.split.map(&:to_i)
to=Array.new(n+1){[]}
m.times do
  a,b=gets.split.map(&:to_i)
  to[a] << b
  to[b] << a
end
dist=0
d=[nil,0]
ans=[nil,1]
stock=[]
to[1].each do |j|
  stock << j
  ans[j]=1
end

while !stock.empty?
  s=stock.shift
  to[s].each do |t|
    unless ans[t]
      stock << t
      ans[t] = s
    end
  end
end

if ans[2..n+1].any? nil
  puts 'No'
else
  puts 'Yes'
  puts  ans[2..n+1]
end


Measured memory_bytes: 33048
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  bool ab[N + 1][N + 1];
  fill(ab[0], ab[N + 1], false);
  for (int i = 0; i < M; ++i) {
    int ai, bi;
    cin >> ai >> bi;
    ab[ai][bi] = true;
  }

  vector<int> nodes(N - 1, 0);
  for (int i = 2; i <= N; ++i) {
    nodes[i - 2] = i;
  }

  int ans = 0;
  do {
    if (!ab[1][nodes[0]]) {
      continue;
    }

    bool flag = true;
    for (int i = 0; i < N - 2; ++i) {
      int a = nodes[i], b = nodes[i + 1];
      if (a > b) {
        swap(a, b);
      }
      if (!ab[a][b]) {
        flag = false;
        break;
      }
    }

    if (flag) {
      ++ans;
    }
  } while (next_permutation(nodes.begin(), nodes.end()));

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
smonth, sday = 1,1
m,d = map(int,input().split())
total = 0

for i,j in zip(range(12),range(12)):
    if(smonth+i < m):
        total += 1
    elif(smonth+i == m):
        if(sday+i > d):
            break
        else:
            total +=1
            break
    else:
        break
print(total)

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


int main(){
  int N,K,ans=0;
  cin >> N >> K;
  vector <int>p(N);
  
  rep(i,N)
    cin >> p.at(i);
  
  sort(p.begin(),p.end());
  
  rep(i,K)
    ans+=p.at(i);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        ([]{lint n; cin>>n; return n;}())

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int H = in, W = in;

    vector<string> S( H+2, string(W+2, '#') );
    int countWhite = 0;
    for( int y=1; y<=H; y++ ) {
    for( int x=1; x<=W; x++ ) {
        cin >> S[y][x];
        if( S[y][x] == '.' ) countWhite ++;
    }
    }

    queue<tuple<int,int,int>> q;
    q.push( make_tuple(1,1,1) );

    while( !q.empty() ) {
        int step, y, x;
        tie(step, y, x) = q.front();
        q.pop();

        if( S[y][x] == '#' ) continue;
        S[y][x] = '#';

        if( y == H && x == W ) {
            cout << (countWhite - step) << "\n";
            return 0;
        }

        q.push( make_tuple(step+1, y, x+1) );
        q.push( make_tuple(step+1, y, x-1) );
        q.push( make_tuple(step+1, y+1, x) );
        q.push( make_tuple(step+1, y-1, x) );
    }

    cout << "-1\n";
}


Measured memory_bytes: 256
numbers = list()

for _ in range(3):
    lst = [int(s) for s in input().split()]
    numbers.append(lst[0])
    numbers.append(lst[1])

# 1-4の個数を数える
cnts = list()
for i in range(1,5):
    cnts.append(numbers.count(i))

# 1個が2個, 2個が2個
if cnts.count(1) == 2 and cnts.count(2) == 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int h, a;
    cin >> h >> a;

    cout << (h+a-1)/a << endl;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


vector<vector<int>> G;
vector<vector<int>> yoko;
vector<vector<int>> tate;

int solve_yoko(int i, int j, int n){
    if(yoko[i][j] != -1) return yoko[i][j];
    
    if(G[i+1][j] == '#'){
        yoko[i][j] = n;
        return n;
    }else{
        yoko[i][j] = solve_yoko(i+1,j,n+1);
        return yoko[i][j];
    }
}

int solve_tate(int i, int j, int n){
    if(tate[i][j] != -1) return tate[i][j];
    
    if(G[i][j+1] == '#'){
        tate[i][j] = n;
        return n;
    }else{
        tate[i][j] = solve_tate(i,j+1,n+1);
        return tate[i][j];
    }
}

int main() {
    int H,W; cin >> H >> W;
    G.assign(H+2, vector<int>(W+2,'#'));
    REP(i,H){
        string s; cin >> s;
        REP(j,W){
            G[i+1][j+1] = s[j];
        }
    }

    yoko.assign(H+2, vector<int>(W+2,-1));
    tate.assign(H+2, vector<int>(W+2,-1));

    int ans = 0;
    REP(i,H+2){
        REP(j,W+2){
            if(G[i][j] == '.'){
                ans = max(ans, solve_yoko(i,j,1) + solve_tate(i,j,1) - 1);              
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 50464
#include<stdio.h>
#include<string.h>

int getnum(char c);

int main(void){
  short flg[26];
  char chara='a',count[2];
  char str[11],ai[10];
  int i,j,k,l,m;
  
  count[0]=count[1]=0;
  memset(flg,0,sizeof(flg));
  printf("?a\n");
  fflush(stdout);
  for(i=1;i<50;i++){
    scanf("%s%*c",ai);
    if(ai[0]!=chara){
      printf("!OUT\n");
      fflush(stdout);
      break;
    }
    if(flg[getnum(ai[1])]!=0){
      printf("!OUT\n");
      fflush(stdout);
      break;
    }
    if(strlen(ai)==1 && ai[0]=='a'){
      printf("!OUT\n");
      fflush(stdout);
      break;
    }
    flg[getnum(ai[1])]=1;
    if(flg[0]==0 && ai[1]=='a'){
      printf("?aa\n");
      flg[0]=1;
      fflush(stdout);
    }else{
      count[0]++;
      if(count[0]>=26){
	count[0]%=26;
	count[1]++;
      }
      printf("?%c%c%c%c\n",ai[1],'a'+count[0],'a'+count[1],chara);
      fflush(stdout);
    }
  }
  return 0;
}

int getnum(char c){
  const char *alpha="abcdefghijklmnopqrstuvwxyz\0";
  return strchr(alpha,c)-alpha;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
    long int C,Q,R=0;
    long int j,h=0;
    scanf("%ld",&C);
    long int X[17];
    for(int i=0;i<17;i++){X[i]=0;}
    for(long int i=0;i<17;i++){
        X[i]=C%10;
        R+=X[i];
        C=(C-X[i])/10;
        if(C==0){j=i+1;break;}
    }
    Q=X[j-1]-1+9*(j-1);
    if(R==(Q+1)){
        printf("%ld\n",R);
    }else{
        printf("%ld\n",Q);
    }
    return 0;
}


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

int main()
{
	int h,w,a,b; cin>>h>>w>>a>>b;

	int A[1005][1005]={0};

	for(int i=1;i<=b;i++){
		for(int j=1;j<=a;j++){
			A[i][j]=1;
		}
	}

	for(int i=b+1;i<=h;i++){
		for(int j=a+1;j<=w;j++) A[i][j]=1;
	}

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++) cout<<A[i][j]<<"";
		cout<<endl;	
	}
}

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<b){
			System.out.println("a < b");
		}
		else if(a>b){
			System.out.println("a > b");
		}
		else{
			System.out.println("a == b");
		}
	}

}

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

int main(){
	int n;
	cin >> n;
	n %= 10;
	if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
		cout << "hon" << endl;
	}else if(n == 0 || n == 1 || n == 6 || n == 8){
		cout << "pon" << endl;
	}else{
		cout << "bon" << endl;
	}
	return 0;
}

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> point;

ll dp[55][2];

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

  dp[0][0] = 1;

  FOR(i, 1, n + 1) {
    int x; cin >> x;

    dp[i][0] += dp[i - 1][0];
    dp[i][1] += dp[i - 1][1];

    if(x % 2) {
      dp[i][0] += dp[i - 1][1];
      dp[i][1] += dp[i - 1][0];
    }

    else {
      dp[i][1] += dp[i - 1][1];
      dp[i][0] += dp[i - 1][0];
    }
  }

  cout << dp[n][p];
}


Measured memory_bytes: 256
import sys, math
sys.setrecursionlimit(10 ** 6)
from collections import deque, defaultdict, Counter
from operator import itemgetter

def main():
    N, M, X = map(int, sys.stdin.readline().rstrip().split())
    A = list(map(int, sys.stdin.readline().rstrip().split()))
    
    idx = -1
    for i in range(M+1):
        if A[i] < X:
            idx = i
        else:
            break
    
    print(min(len(A[:idx+1]), len(A[idx+1:])))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<int> a(N);
	
	set<int> notused,used;
	map<int,int> mp;
	
	for(int i=0;i<N;i++){
		cin>>a[i];
		a[i]--;
		mp[a[i]]++;
		notused.insert(i);
	}
	
	vector<int> ans;
	
	for(int i=0;i<N;i++){
		
		if(notused.size()<=3){
			vector<int> K;
			for(auto x:notused){
				K.push_back(x);
			}
			do{
				bool f = true;
					//cout<<f<<endl;
				if(ans.size()!=0){
					if(a[ans.back()]==K[0])f=false;
				}
			
				for(int j=1;j<K.size();j++){
					if(a[K[j-1]] == K[j])f=false;
				}
				if(f){
					for(int j=0;j<K.size();j++)ans.push_back(K[j]);
					break;
				}
			}
			while(next_permutation(K.begin(),K.end()));		
			
			break;
		}
		
		
		auto it = notused.begin();
		if(i!=0){
			if((*it)==a[ans.back()]){
				if(notused.size()==1){
					cout<<-1<<endl;
					return 0;
				}
				it++;
			}
		}
		
		int g = (*it);
		//cout<<g<<endl;
		if(i!=N-1){
			if(mp[a[g]] == N-1-i&&notused.count(a[g])){
				g = a[g];
			}
		}
		
		ans.push_back(g);
		mp[a[g]] --;
		
		if(!notused.count(g)){
			cout<<-1<<endl;
			return 0;
		}

		notused.erase(g);
		
	}
	
	if(ans.size()!=N){
		cout<<-1<<endl;
		return 0;
	}
	
	for(int i=0;i<N-1;i++){
		if(a[ans[i]] == ans[i+1]){
			cout<<-1<<endl;
			return 0;
		}
	}
	
	for(int i=0;i<N;i++){
		if(i!=0)cout<<' ';
		cout<<ans[i]+1;
	}
	cout<<endl;
	
    return 0;
}


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

int main() {
  
  int r;
  cin >> r;
  
  int d;
  cin >> d;
  
  int x;
  cin >> x;
  
  
  int y=x;
  for (int i=0; i<10; i++) {
    cout << r*y-d << endl;
    y=r*y-d;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FOD(i,a,b) for(int i=a; i>=b; i--)
#define pa pair<int,int>
#define fi first
#define se second
#define MOD xxx
#define getbit(n,i) ((n>>(i-1))&1)
#define offbit(n,i) ((n^(1<<(i-1))
#define onbit(n,i) (n|(1<<(i-1)))
#define cntone(x) (__builtin_popcount(x))

using namespace std;
int n,x,t;
int main()
{
    cin >> n >> x >> t;
    cout << ((n-1)/x +1)*t;
	return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;

 int main(){
	 int n;
	 cin>>n;
	 priority_queue<pii> pq;
	 priority_queue<pii> pq2;
	 map<int,int> mp;
	 map<int,int> mp2;
	 int a[101010]={};
	 FOR(i,0,n){
		 cin>>a[i];
		 if(i%2==0){
			 mp[a[i]]++;
		 }else{
			 mp2[a[i]]++;
		 }
	 }
	 mp[mod]=0;
	 mp2[mod+1]=0;
	 for(auto x:mp){
		 pq.push(MP(x.ND,x.ST));
	 }
	 for(auto x:mp2){
		 pq2.push(MP(x.ND,x.ST));
	 }
	 //cerr<<pq.size()<<" "<<pq2.size()<<endl;
	 int ans=n;
	 pii f=pq.top();
	 pq.pop();
	 pii s=pq.top();
	 pq.pop();
	 pii f2=pq2.top();
	 pq2.pop();
	 pii s2=pq2.top();
	 pq2.pop();
	 if(f.ND!=f2.ND){
		 ans=min(ans,n-f.ST-f2.ST);
	 }
	 if(s.ND!=f2.ND){
		 ans=min(ans,n-s.ST-f2.ST);
	 }
	 if(f.ND!=s2.ND){
		 ans=min(ans,n-f.ST-s2.ST);
	 }
	 if(s.ND!=s2.ND){
		 ans=min(ans,n-s.ST-s2.ST);
	 }
	 cout<<ans<<endl;

   return 0;
 }


Measured memory_bytes: 6520
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;

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

    int one = 0, zero = 0;
    for (int i = 0; i < s.size(); i++){
        if(s[i] == '1') one++;
        else zero++;
    }

    if(one >= zero) cout << zero * 2 << endl;
    else cout << one * 2 << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MAX 111
#define inf 1000000000000000007

map<char,long long> mp;
long long s[5]={0};
char a[MAX][MAX];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long  n,m,k,ans =0 ,rb,cb;
	cin>>n>>m;
	for(int i =0 ; i < n ;i ++){
		for(int  j =0 ; j < m ; j++){
			cin>>a[i][j];
			mp[a[i][j]]++;
		}
	}
	for(int i =0 ;i < n/2 ; i++){
		for(int j = 0 ;j < m/2 ; j++){
			s[4]++;
		}
	}
	if(n%2){
		for(int j =0 ;j < m /2 ;j++){
			s[2]++;
		}
	}
	if(m%2){
		for(int i =0 ; i < n/2 ;i++) s[2]++;
	}
	if(n%2 && m%2)s[1] = 1; 
	

	for(char i = 'a' ;i <= 'z' ;i++){
		if(s[4] == 0)break;
		if(4* s[4] < mp[i] ){
			mp[i] = mp[i] - 4 *s[4];
			s[4] = 0;
		}
		else{
			s[4] -= (mp[i]/4);
			mp[i]  = mp[i]%4; 
		}
	}
	for(char i = 'a' ;i <= 'z' ;i++){
		if(s[2] == 0)break;
		if(2* s[2] < mp[i] ){
			mp[i] = mp[i] - 2 *s[2];
			s[2] = 0;
		}
		else{
			s[2] -= (mp[i]/2);
			mp[i]  = mp[i]%2; 
		}
	}
	if(s[1] == 1){
		for(char i = 'a' ; i <= 'z' ;i++){
			if(mp[i] > 0){
				mp[i]--;
				s[1] = 0;
				break;
			}
		}
	}
	for(char i ='a' ; i <= 'z' ;i++){
		if(mp[i] > 0){
			cout<<"No";
			return 0;
		}
	}

	if(s[1] == 0 && s[2] == 0 && s[4] == 0)cout<<"Yes";
	else
		cout<<"No";
	return 0;	
}

Measured memory_bytes: 256
import bisect
oX = int(input())
K = int(input())
r= list(map(int,input().split()))

# a X-a
# min(max(0,a-r[0]))
#  a-r[0]+r[1]

def calc_time(t):
    val = bisect.bisect_left(t,r)
    diff= t- r[val]
    return val,diff


# [sep1,sep2,a<sep1,sep1<a<sep2,a>sep2  ]

last =(0,oX,0 ,0,oX)
res =[last]
for i,tr in enumerate(r):
    sep1,sep2,X,Y,Z=last
    dt = tr if i==0 else tr-r[i-1]
    if i%2==0: # a ->b

        X = max(0,X-dt)
        Y = Y-dt
        Z = max(0,Z-dt)
        sep1 = max(sep1,-Y)
    else: #b-> a
        X = min(oX,X+dt)
        Y= Y+dt

        Z = min(oX,Z+dt)
        sep2 = min(sep2,oX-Y)

    last = (sep1,sep2,X,Y,Z)
    res.append(last)

#print(res)


Q = int(input())

r_index=0
r.insert(0,0)
r.append(10000000000)
for i in range(Q):
    def calc(X,r_index,diff):
        tmp = 1 if r_index%2 else -1
        return min(oX,max(0,X +tmp* diff))
    t,a =list(map(int,input().split()))
    while r[r_index]< t:
        if r[r_index+1] >t:
            break
        r_index+=1
    sep1, sep2, X, Y, Z = res[r_index]
    diff = t -r[r_index]
    #print(t,diff,r_index,r[r_index])
    if a< sep1:
        print(calc(X,r_index,diff))
    elif a>sep2:
        print(calc(Z,r_index,diff))
    else:
        print(calc(a+Y,r_index,diff))



Measured memory_bytes: 29492
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint 
{
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};



struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) 
  {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb (200000);



class DP
{
public:
  mint dp; //辺の元のノードの DP値
  int  t ; //辺の元のノードより先のノード数
  DP(mint _dp = 1, int _t = 0){
    dp = _dp;
    t  = _t ;
  }
};


DP vtx_dp[200000];
vector<int> v_1ring[200000];


static void CalcDp_Dfs(
    int parent_vid, 
    int node_vid  )
{
  DP &piv_dp = vtx_dp[node_vid];

  for ( auto v : v_1ring[node_vid] )
  {
    if ( v == parent_vid ) continue;

    CalcDp_Dfs(node_vid, v);
    
    DP &ch = vtx_dp[v];
    piv_dp.dp *= ch.dp;
    piv_dp.dp *= comb(piv_dp.t + ch.t,  ch.t);
    piv_dp.t  += ch.t;
  }

  piv_dp.t += 1;
}

//上から下へ
static void CalcDp_Bfs(
    const int parent_id, 
    const int node_id  
    )
{

  for ( auto v : v_1ring[node_id] )
  {
    if ( v == parent_id) continue;

    DP tmp = vtx_dp[node_id];
    //辺 node_id - v が無かった状態に戻す
    tmp.t  -= vtx_dp[v].t ;
    tmp.dp /= comb( tmp.t + vtx_dp[v].t - 1, tmp.t - 1);
    tmp.dp /= vtx_dp[v].dp;
    
    //dfsと同様に追加する
    vtx_dp[v].dp *= tmp.dp;
    vtx_dp[v].dp *= comb( tmp.t + vtx_dp[v].t-1, tmp.t);
    vtx_dp[v].t  += tmp.t;

    CalcDp_Bfs(node_id, v);
  }

}
 

int main(void){
    
  int n;
  cin >> n;
    
  vector<pair<int,int>> edges(n);
    
  for( int i=0; i < n-1; ++i) 
  {
    cin >> edges[i].first >> edges[i].second;
    --edges[i].first; 
    --edges[i].second;
  }

  for( int i=0; i < n-1; ++i) {
    v_1ring[ edges[i].first ].push_back(edges[i].second);    
    v_1ring[ edges[i].second].push_back(edges[i].first );    
  }
  CalcDp_Dfs( -1, 0);
  CalcDp_Bfs( -1, 0);

  for( int i=0; i < n; ++i) cout << vtx_dp[i].dp.x << "\n";
     
  return 0;
}


Measured memory_bytes: 21748
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

  string s;
  cin >> s;
  string t = s.substr(0, s.size() - 8);
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
int a;
  int cal1 = 0,cal2 = 0,cal3 = 0;
  cin >> a ;
  cal1 = a / 100;
  cal2 = (a % 100) / 10;
  cal3 = (a % 100) % 10; 
    cout <<cal1 + cal2 + cal3 <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
};

//INSERT ABOVE HERE
using M = Mint<int>;
const int MAX = 303*303;
M dp[2][MAX];
M nx[2][MAX];
signed main(){
  int n;
  cin>>n;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin>>l[i];

  int s;
  cin>>s;

  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<MAX;j++) nx[0][j]=nx[1][j]=M(0);

    for(int j=0;j<MAX;j++){
      nx[0][j]+=dp[0][j];
      nx[1][j]+=dp[1][j];

      if(j+l[i]>=MAX) continue;
      
      nx[1][j+l[i]]+=dp[0][j];
      nx[0][j+l[i]]+=dp[1][j];
    }    

    for(int j=0;j<MAX;j++) dp[0][j]=nx[0][j];
    for(int j=0;j<MAX;j++) dp[1][j]=nx[1][j];
  }
  
  M ans(0);
  for(int x=0;x<=s;x++)
    ans+=(dp[0][x]-dp[1][x])*M(s-x).pow(n);
  
  cout<<ans.v<<endl;
  return 0;
}



Measured memory_bytes: 4560
import math
n = int(input())
a = [[int(j) for j in input().split()] for i in range(n)]
t = 0
for i in range(n-1):
    for j in a[i+1:]:
        t += math.sqrt((a[i][0]-j[0])**2 + (a[i][1]-j[1])**2)
print(t*2/n)

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

int main()
{
    while(1)
    {
        string r;
        string a;
        int hit = 0;
        int blow = 0;
        cin >> r >> a;
        if(r == "0" && a == "0")
        {
            break;
        }
        for(int i=0; i<4; i++)
        {
            for(int j=0; j<4; j++)
            {
                if(r[i] == a[j])
                {
                    if(i == j)
                    {
                        hit++;
                    }
                    else
                    {
                        blow++;
                    }
                }
            }
        }
        cout << hit << " " << blow << endl;
    }
    return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <string>
using namespace std;
int main(){
	string a;
	getline(cin,a);
	int l=0,k=a.length();
	for(int i=0;i<k/2;i++){
		if(a[i]!=a[k-i-1]){
			l++;
		}
	}
	cout<<l;
}


Measured memory_bytes: 256
// ARC084
// D - Small Multiple

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_K = 100000;
const int MAX_V = MAX_K;
const int INF = 1e9;

class Graph {
public:
    void add_edge(int from, int to, int cost);  // 有向辺を追加
    void dijkstra(int s);
    int dist[MAX_V];
    int V;  // <- 初期化忘れずに
private:
    vector<pii> g[MAX_V];  // cost, to
};

void Graph::add_edge(int from, int to, int cost) {
    g[from].push_back(pii(cost, to));
    return;
}

void Graph::dijkstra(int s) {
    priority_queue<pii, vector<pii>, greater<pii> > q;
    pii p, e;

    fill(dist, dist + V, INF);
    dist[s] = 0;
    q.push(pii(dist[s], s));
    while (!q.empty()) {
        p = q.top();
        q.pop();
        if (dist[p.second] < p.first) {
            continue;
        }
        for (int i = 0; i < (int)g[p.second].size(); i++) {
            e = g[p.second][i];
            if (dist[e.second] > dist[p.second] + e.first) {
                dist[e.second] = dist[p.second] + e.first;
                q.push(pii(dist[e.second], e.second));
            }
        }
    }
    return;
}

int K;
Graph g;

int main() {
    cin >> K;

    g.V = K;
    for (int i = 0; i < K; i++) {
        g.add_edge(i, (i + 1) % K, 1);
        g.add_edge(i, (i * 10) % K, 0);
    }
    g.dijkstra(1);

    cout << g.dist[0] + 1 << endl;

    return 0;
}


Measured memory_bytes: 6780
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

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);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string w;
    set<string> s;
    string a; cin >> a;
    s.insert(a);
    char b=a[(int)(a.length())-1];
    int ind=0;
    rep(i,n-1){
        cin >> w;
        /*cout << (int)(s.count(w)) << endl;*/
        if((int)(s.count(w))==0 && w[0]==b){
            ind++;
        }
        s.insert(w);
        b=w[(int)(w.length())-1];
        /*cout << b << endl;*/
    }
    if(ind==n-1) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct Test {
	int64_t b;
	int64_t l;
	int64_t u;
	int64_t pmin;
	int64_t gmax;
};

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

	int64_t n, x; cin >> n >> x;

	int64_t penalty = 0;
	vector<Test> tests(n);
	{
		for (auto& test : tests) {
			cin >> test.b >> test.l >> test.u;
			test.pmin = test.b * test.l;
			test.gmax = (x - test.b) * test.u + test.pmin;

			penalty += test.pmin;
		}
	}

	sort(tests.begin(), tests.end(), [](const Test& lhs, const Test& rhs) {
		return lhs.gmax > rhs.gmax;
	});

	vector<int64_t> vals(n);
	{
		int64_t sum = 0;
		FOR_LT(i, 0, n) {
			sum += tests[i].gmax;
			vals[i] = sum;
		}
	}

	int64_t min_s = INT64_MAX;
	FOR_LT(i, 0, n) {
		auto rem = tests[i];

		int64_t cur_remp = penalty - rem.gmax;
		auto it = lower_bound(vals.begin(), vals.end(), cur_remp);
		int  bi = it - vals.begin();

		cur_remp -= *it;

		int64_t s = (bi + 1) * x;
		if (i <= bi) {
			cur_remp += rem.gmax;
			s -= x;

			int ai = bi + 1;
			while (ai < n && cur_remp >= 0) {
				s += x;
				cur_remp -= tests[ai].gmax;
				ai++;
			}
		}

		cur_remp += rem.gmax;

		if (cur_remp < 0) continue;

		if (cur_remp < rem.pmin) {
			s += (cur_remp + rem.l - 1) / rem.l;
		}
		else {
			s += rem.b + (cur_remp - rem.pmin + rem.u - 1) / rem.u;
		}

		min_s = min(min_s, s);
	}


	cout << min_s << endl;


	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a,b,n,ans,i=1;
int main()
{
cin>>n;
while(i<=n)
{
	cin>>a>>b;
	ans+=max(a,b)-min(a,b)+1;
	i++;
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256