akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
#define rep(i,n) ;for( int i =0; i < n ; i ++)
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int fiv(int n){
  if(n==0){
    return 0;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}
int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  vector<pair<ll,ll>> dflat(100001),dodd(100001);
  rep(i,n){
    cin>> a[i];
  }
  for(int i=0; i<=100000;i++){
    dodd[i] =make_pair(0,i);
    dflat[i]=make_pair(0,i);
  }

  for(int i=0;i<n;i++){
    if(i%2 ==0){
      dflat[a[i]].first ++;
    }
    else{
      dodd[a[i]].first ++;
    }
  }
  sort(dflat.begin(), dflat.end());
  sort(dodd.begin(), dodd.end());

  if(dodd[100000].second == dflat[100000].second){
    cout << min(n -dflat[100000].first-dodd[99999].first , n -dodd[100000].first-dflat[99999].first)<<endl;
  }
  else{
    cout << n -dflat[100000].first-dodd[100000].first<<endl;
  }

  
}



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

int main(){
  char s[10];
  int i,a,b,c,d;

  scanf("%s",s);
  a=s[0]-'0';
  b=s[1]-'0';
  c=s[2]-'0';
  d=s[3]-'0';
  if(a-b-c-d==7) printf("%d-%d-%d-%d=7",a,b,c,d);
  else if(a-b-c+d==7) printf("%d-%d-%d+%d=7",a,b,c,d);
  else if(a-b+c+d==7) printf("%d-%d+%d+%d=7",a,b,c,d);
  else if(a+b+c+d==7) printf("%d+%d+%d+%d=7",a,b,c,d);
  else if(a-b+c-d==7) printf("%d-%d+%d-%d=7",a,b,c,d);
  else if(a+b-c-d==7) printf("%d+%d-%d-%d=7",a,b,c,d);
  else if(a+b+c-d==7) printf("%d+%d+%d-%d=7",a,b,c,d);
  else if(a+b-c+d==7) printf("%d+%d-%d+%d=7",a,b,c,d);
  return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < i; j++) {
      if (s[j] == 'C' && s[i] == 'F') {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int P = sc.nextInt();
      	int Q = sc.nextInt();
        int R = sc.nextInt();
        
        int tmp[] = {P+Q, Q+R, R+P};
        Arrays.sort(tmp);
        System.out.println(tmp[0]);
    }
}

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

int main(){
	int h, w, n, x, y, tmp;
    string s, t;
	cin >> h >> w >> n >> x >> y >> s >> t;
	tmp = x;
	for (int i = 0; i < n; i++){
		if(s[i] == 'D'){
            tmp++;
        }
		if(tmp > h){
            cout << "NO";
            return 0;
        }
		if(t[i] == 'U'){
            tmp--;
        }
		tmp = max(tmp, 1);
	}
	tmp = x;
	for (int i = 0; i < n; i++){
		if(s[i] == 'U'){
            tmp--;
        }
		if(tmp <= 0){
            cout << "NO";
            return 0;
        }
		if(t[i] == 'D'){
            tmp++;
        }
		tmp = min(tmp, h);
	}
	tmp = y;
	for (int i = 0; i < n; i++){
		if(s[i] == 'R'){
            tmp++;
        }
		if(tmp > w){
            cout << "NO";
            return 0;
        }
		if(t[i] == 'L'){
            tmp--;
        }
		tmp = max(tmp, 1);
	}
	tmp = y;
	for (int i = 0; i < n; i++){
		if(s[i] == 'L'){
            tmp--;
        }
		if(tmp == 0){
            cout << "NO";
            return 0;
        }
		if(t[i] == 'R'){
            tmp++;
        }
		tmp = min(tmp, w);
	}
	cout << "YES";
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long a[200005];
long long ans=1;
int main()
{
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	if(k%2==0)
	{
		int p1=1,p2=n;
		while(p2>p1&&k)
		{
			if(a[p2]*a[p2-1]>=a[p1]*a[p1+1])
			{
				ans=ans*a[p2]%mod*a[p2-1]%mod;
				p2-=2;
				k-=2;
			}
			else
			{
				ans=ans*a[p1]%mod*a[p1+1]%mod;
				p1+=2;
				k-=2;
			}
		}
	}
	else if(k%2==1)//ÆæÊý¸ö
	{
		if(a[n]<0)
		{
			//×î´óÖ»ÄÜÎª¸ºÊý
		//	ans=a[n];
			for(int i=n;i>=n+1-k;i--)
			{
				ans=ans*a[i]%mod;
			}
		}
		else if(a[n]>=0)
		{
			//¿ÉÒÔÎªÕýÊý
			ans=a[n];
			k--;
			int p1=1,p2=n-1;
			while(p2>p1&&k)
			{
				if(a[p2]*a[p2-1]>=a[p1]*a[p1+1])
				{
					ans=ans*a[p2]%mod*a[p2-1]%mod;
					p2-=2;
					k-=2;
				}
				else
				{
					ans=ans*a[p1]%mod*a[p1+1]%mod;
					p1+=2;
					k-=2;
				}
			}
		}
	}
	cout<<(ans+mod)%mod;
}

Measured memory_bytes: 5136
#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

void solve() {
        ll x;
        cin >> x;
        if(x >= 30) {
                cout << "Yes";
        }
        else {
                cout << "No";
        }
}

int main() {
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


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

int D1[10] = {};
int D2[100] = {};
int D3[1000] = {};

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

    rep(i, S.size()) {
        int num = S[i] - '0';
        rep(d2, 100) if (D2[d2] == 1) D3[d2*10+num] = 1;
        rep(d1, 10)  if (D1[d1] == 1) D2[d1*10+num] = 1;
        D1[num] = 1;
    }

    int ans = 0;
    rep(i, 1000) if (D3[i] == 1) ans++;

    cout << ans << endl;

    return 0;
}



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

mod=10**9+7
ans=0
for i in range(k,n+2):
  
  sigma1=(i-1)*i//2
  sigma2=(n-i)*(n-i+1)//2
  sigma3=n*(n+1)//2
  ans+=sigma3-sigma2-sigma1+1
  ans%=mod
print(ans)


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

struct PersistentUnionFind{
  using T = pair<int, int>;
  int n;
  vector<int> r,p;
  stack<T> st;
  PersistentUnionFind(){}
  PersistentUnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return x==p[x]?p[x]:find(p[x]);
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    st.emplace(-1,-1);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    st.top()=T(x,y);
  }
  void undo(int t=1){
    for(int i=0;i<t;i++){
      int x,y;
      tie(x,y)=st.top();st.pop();
      if(x<0) continue;
      r[x]-=r[y];
      p[y]=y;
    }
  }
};

struct DynamicConnectivity{
  using edge = pair<int, int>;
  using range = edge;
  
  int n,q;
  PersistentUnionFind puf;
  vector<vector<edge> > edges;
  vector<pair<range, edge> > prc;
  map<edge, int> cnt,app;
  
  DynamicConnectivity(){}
  DynamicConnectivity(int n,int q_):n(n),q(1),puf(n){
    while(q<q_) q<<=1;
    edges.resize(q*2-1);
  }
  
  void insert(int t,int u,int v){
    edge e=minmax(u,v);
    if(cnt[e]++==0) app[e]=t;
  }
  
  void erase(int t,int u,int v){
    edge e=minmax(u,v);
    if(--cnt[e]==0) prc.emplace_back(range(app[e],t),e);
  }
  
  void add(int a,int b,const edge &e,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      edges[k].emplace_back(e);
      return;
    }
    int m=(l+r)>>1;
    add(a,b,e,k*2+1,l,m);
    add(a,b,e,k*2+2,m,r);
  }
  
  void add(range &r,const edge &e){
    add(r.first,r.second,e,0,0,q);
  }
  
  void build(){
    for(auto &e:cnt){
      if(!e.second) continue;
      prc.emplace_back(range(app[e.first],q),e.first);
    }
    for(auto &s:prc)
      add(s.first,s.second);
  }

  void exec(function<void(int)> &f,int k=0){
    for(auto &e:edges[k])
      puf.unite(e.first,e.second);

    if(k<q-1){
      exec(f,k*2+1);
      exec(f,k*2+2);
    }else{
      int x=k-(q-1);
      f(x);
    }
    
    puf.undo(edges[k].size()); 
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  DynamicConnectivity dc(n,q);
  vector<int> t(q),u(q),v(q);
  for(int i=0;i<q;i++){
    cin>>t[i]>>u[i]>>v[i];
    if(t[i]==1) dc.insert(i,u[i],v[i]);
    if(t[i]==2) dc.erase(i,u[i],v[i]);
  }
  dc.build();
  function<void(int)> f=[&](int x){
    if(x>=q||t[x]!=3) return;
    cout<<(dc.puf.same(u[x],v[x])?"YES":"NO")<<endl;
  };
  dc.exec(f);
  return 0;
}



Measured memory_bytes: 14764
#include<stdio.h>

int main(){
	int a,b;
	double result;
	char culc_let;

	while(1){
		scanf("%d %c %d",&a,&culc_let,&b);
		if(culc_let=='?'){
			break;
		}

		switch(culc_let){
		case '+':
			result=a+b;
			break;
		case '-':
			result=a-b;
			break;
		case '*':
			result=a*b;
			break;
		case '/':
			result=a/b;
			break;
		}

		printf("%.0f\n",result);
	}
	return 0;
}



Measured memory_bytes: 2056
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, sum = 0, cnt = 0, be;
  scanf("%lld", &n);
  ll a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), sum += a[i];
  be = a[0];
  if(sum % (n * (n + 1) / 2)) {
    printf("NO");
    return 0;
  }
  sum /= n * (n + 1) / 2;
  for(i = 1; i < n; ++i) {
    be += sum;
    if(be - a[i] < 0 || (be - a[i]) % n) {
      printf("NO");
      return 0;
    }
    cnt += (be - a[i]) / n;
    be = a[i];
  }
  be += sum;
  if(be - a[0] < 0 || (be - a[0]) % n) {
    printf("NO");
    return 0;
  }
  cnt += (be - a[0]) / n;
  printf("YES");
  return 0;
}

Measured memory_bytes: 896
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    dic = collections.Counter(a)
    als = 0
    exl = [0 for _ in range(n+1)]
    for key, value in dic.items():
        if value >= 3:
            choice = (value)*(value-1)//2
            choice1 = (value-1)*(value-2)//2
            als += choice
            exl[key] = choice1 - choice
        elif value == 2:
            choice = (value)*(value-1)//2
            als += choice
            exl[key] = -choice
    
    for ball in a:
        choices = als + exl[ball]
        print(choices)
main()            


Measured memory_bytes: 114896
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

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

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


int main(void) {
    Int N, K, Q; cin >> N >> K >> Q;
    vector<Int> A(Q);
    for (int i = 0; i < Q; i++) {
        cin >> A[i];
        A[i]--;
    }
    vector<Int> score(N, K);
    for (int i = 0; i < Q; i++) {
        score[A[i]]++;
    }
    for (int i = 0; i < N; i++) {
        score[i] -= Q;
    }

    for (int i = 0; i < N; i++) {
        if (score[i] <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc148/abc148_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int a, b;
  cin >> a >> b;

  set<int> x{1, 2, 3};
  x.erase(a);
  x.erase(b);

  cout << *x.begin() << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "limits.h"
#include "string"
using namespace std;
int main() {
	char s[5];
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]){
		cout << "Yes" << endl;
	}
	else if (s[1] == s[2] && s[2] == s[3]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
return 0;
}

Measured memory_bytes: 256
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int N, max = 0;
	int p[10000];
	int sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		max = (max < p[i]) ? p[i] : max;
		sum += p[i];
	}
	cout << sum - max / 2 << endl;

	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, ans = 0;
    string a, b, c;
    cin >> n >> a >> b >> c;
    REP(i,n){
        int cnt = 0;
        if(a[i]!=b[i])cnt++;
        if(a[i]!=c[i])cnt++;
        if(c[i]!=b[i])cnt++;
        if(cnt==2)ans++;
        if(cnt==3)ans += 2;
    }
    cout << ans << endl;
    return 0;
}


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

using Lint=long long;

vector<int> mul(vector<int>& a,vector<int>& b)
{
   const int N=a.size();
   vector<int> res(N);
   for(int i=0;i<N;i++) res[i]=b[a[i]];
   return res;
}

vector<int> pow(vector<int>& p,Lint K)
{
   const int N=p.size();
   vector<int> res(N);
   for(int i=0;i<N;i++) res[i]=i;
   while(K>0){
      if(K&1) res=mul(res,p);
      p=mul(p,p); K>>=1;
   }
   return res;
}

int main()
{
   int N; cin>>N;
   vector<Lint> x(N);
   for(int i=0;i<N;i++) cin>>x[i];
   Lint M,K; cin>>M>>K;
   vector<int> a(M);
   for(int i=0;i<M;i++) cin>>a[i],a[i]--;

   const int sz=N-1;
   vector<int> d(sz);
   for(int i=0;i<sz;i++) d[i]=x[i+1]-x[i];

   vector<int> p(sz);
   for(int i=0;i<sz;i++) p[i]=i;
   for(int i=0;i<M;i++){
      swap(p[a[i]-1],p[a[i]]);
   }
   vector<int> res=pow(p,K);
   for(int i=0;i<sz;i++){
      x[i+1]=x[i]+d[res[i]];
   }
   for(int i=0;i<N;i++) cout<<x[i]<<endl;
   return 0;
}


Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000001
using ll=long long;
using Graph=vector<vector<int>>;

vector<pair<int,int>> ab;
map<pair<int,int>,int> m;

bool dfs(Graph &G,int v,int p,int g,ll &c){
  for(auto nv:G.at(v)){
    if(nv==p){
      continue;
    }
    if(nv==g){
      ll k=m[make_pair(min(v,nv),max(v,nv))];
      c=1ull<<k;
      return true;
    }
    if(dfs(G,nv,v,g,c)){
      ll k=m[make_pair(min(v,nv),max(v,nv))];
      c+=(1ull<<k);
      return true;
    }
  }
  return false;
}

int main(){
  int N;
  cin>>N;
  Graph G(N);
  ab.resize(N-1);
  for(int i=0;i<N-1;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    ab.at(i)=make_pair(min(x,y),max(x,y));
    m[ab.at(i)]=i;
    G.at(x).push_back(y);
    G.at(y).push_back(x);
  }
  int M;
  cin>>M;
  vector<int> u(M),v(M);
  for(int i=0;i<M;i++){
    cin>>u.at(i)>>v.at(i);
    u.at(i)--;
    v.at(i)--;
  }

  vector<ll> constrain(M);
  for(int i=0;i<M;i++){
    dfs(G,u.at(i),-1,v.at(i),constrain.at(i));
  }

  ll ans=1ull<<((ll)N-1);
  for(int j=1;j<1<<M;j++){
    ll bit=0;
    ll count=0;
    for(int i=0;i<M;i++){
      if(((j>>i)&1)==1){
        count++;
        bit|=constrain.at(i);
      }
    }
    ll C=0;
    for(int i=0;i<64;i++){
      C+=bit%2;
      bit>>=1;
    }
    if(count%2==0){
      ans+=1ull<<(N-1-C);
    }else{
      ans-=1ull<<(N-1-C);
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,unroll-all-loops")
// #pragma GCC option("arch=native","tune=native")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>
using namespace std;

#define f(_i, _n) for (auto _i = 0; _i < _n; _i++)
#define F(_i, _k, _n) for (auto _i = _k; _i < _n; _i++)
#define re return
#define pb push_back
#define all(_v) _v.begin(), _v.end()
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define fi first
#define se second

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;


int main() {
  ll x, y;
  cin >> x >> y;
  if (x % y == 0) {
    cout << -1;
  } else {
    cout << x;
  }
}


Measured memory_bytes: 256
//38
#include<iostream>
#include<string>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    string nm[20];
    int m[20],d[20][30];
    int t[30]={};
    for(int i=0;i<n;i++){
      cin>>nm[i]>>m[i];
      for(int j=0;j<m[i];j++){
	cin>>d[i][j];
	t[d[i][j]]++;
      }
    }
    int p[20]={};
    for(int i=0;i<n;i++){
      for(int j=0;j<m[i];j++){
	p[i]+=n+1-t[d[i][j]];
      }
    }
    int mp=1<<30;
    int x;
    for(int i=0;i<n;i++){
      if(p[i]<mp||mp==p[i]&&nm[x]>nm[i]){
	mp=p[i];
	x=i;
      }
    }
    cout<<p[x]<<' '<<nm[x]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
import math
n, k = map(int,input().split())
ans = 0
for i in range(n):
    if i+1 < k:
        must = math.ceil(math.log2(k/(i+1)))
        ans += (1/n)*((0.5)**must)
    else:
        ans += (1/n)
print(ans)
    

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#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 rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000


void solve_abc144_c() {
	ll N;
	ll ans = 0;

	cin >> N;

	ll r = sqrt(N);

	for (int i = r; i >= 1; i--) {
		if (N % i == 0) {
			ans = (i - 1) + (N / i - 1);
			break;
		}
	}

	cout << ans << "\n";
}

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

	solve_abc144_c();

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class alds14a
{
    static void Main()
    {
        Console.ReadLine();
        List<int> S = read();
        Console.ReadLine();
        List<int> T = read();
        int ct = 0;
        foreach (int tgt in T)
        {
            if (S.Contains(tgt)) ct++;
        }
        Console.WriteLine(ct);
    }
    static List<int> read()
    {
        List<int> ret = new List<int>();
        string[] input = Console.ReadLine().Split(' ');
        foreach (string data in input)
        {
            int num;
            if (int.TryParse(data, out num))
            {
                ret.Add(num);
            }
        }
        return ret;
    }
}

Measured memory_bytes: 20412
/**
 *    author        : Saurav Paul 
 *    created       : August 21, 2020 12:13 PM
 *    Problem Name  : A - Calc
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc172/tasks/abc172_a
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

using ll = long long int ;

void solve(){
    ll a ;
    cin >> a;
    a = a + a * a + a * a * a;
    cout << a << endl ;

}

int main(){
    ios_base::sync_with_stdio(false);

    int testcases = 1;
    for(int i = 1 ; i <= testcases ; i ++){
        solve();
    }

    return 0 ;
}


Measured memory_bytes: 3628
n,m = map(int, input().split())
judge = [i for i in range(1, m+1)]
ans = [1 for i in range(m)]
for i in range(n):
    a = list(map(int, input().split()))
    a.pop(0)
    for j in judge:
        if not j in a:
            ans[j-1] = 0
print(sum(ans))

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

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

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

    reverse(H.begin(), H.end());

    for (int i = 0; i < N - 1; i++) {
        if (H[i + 1] > H[i])
            H[i + 1]--;
    }

    bool ok = true;
    for (int i = 0; ok == true && i < N - 1; i++) {
        if (H[i] < H[i + 1])
            ok = false;
    }

    if (ok == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

int main()
{ 
   int m[3];
   int ans=0;
   for(int i=0;i<3;i++) cin>>m[i];
   sort(m,m+3);
   bool flag=false;
   if((m[1]-m[0])%2==1) flag=true;
   for(int i=0;i<m[2]-m[1];i++) ans++;
   ans+=(m[2]-(m[0]+ans))/2;
   if(flag) ans+=2;
   cout<<ans<<endl;
   

}

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 MOD = 1e9 + 7;
const int MAXN = 1e5;
vector<vector<ll>> dp(MAXN, vector<ll>(2));
vector<vector<int>> to(MAXN);

ll dfs(int v, bool isBlack, int parent=-1){
	if(dp[v][isBlack] > 0) return dp[v][isBlack];
	
	ll res = 1;
	for(auto w : to[v]){
		if(w == parent) continue;
		
		ll tmp = 0;
		tmp = ( tmp + dfs(w, false, v) ) % MOD;
		if(!isBlack){
			tmp = ( tmp + dfs(w, true, v) ) % MOD;
		}
		
		res = ( res * tmp ) % MOD;
	}
	
	return dp[v][isBlack] = res;
}

int main(){
	
	int n;
	cin >> n;
	rep(i,n-1){
		int x,y;
		cin >> x >> y;
		--x; --y;
		to[x].push_back(y);
		to[y].push_back(x);
	}

	cout << ( dfs(0, true) + dfs(0, false) ) % MOD << endl;
	return 0;
}

Measured memory_bytes: 19584
local n=io.read("*n")
local a_map={}
for i=(n%2==0 and 1 or 0),n,2 do
    a_map[i]=(i==0 and 1 or 2)
end

local a={}
for i=1,n do
    local input=io.read("*n")
    a[input]=(a[input] or 0)+1
end

if #a~=#a_map then
    print(0)
    return
end

local counter=1
for k,v in pairs(a_map) do
    counter=(a[k]==a_map[k] and counter*v%1000000007 or 0)
end
print(counter)

Measured memory_bytes: 3256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

void pr(ll h, ll n, ll w) { cout << h << " " << n << " " << w << endl; }

int main() {
  //
  ll n;
  cin >> n;
  if ((n & 1) == 0) {
    pr(n, n, n / 2);
    return 0;
  }

  REP(h, 1, 3501) {
    REP(nn, 1, 3501) {
      if ((4 * h * nn - n * nn - n * h) > 0 &&
          (n * h * nn) % (4 * h * nn - n * nn - n * h) == 0) {
        ll w = (n * h * nn) / (4 * h * nn - n * nn - n * h);
        pr(h, nn, w);
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin>>n;
  map<ll,bool> mp;
  bool f=true;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    if(mp.find(a)!=mp.end()) f=false;
    else mp[a]=true;
  }
  cout<<(f?"YES":"NO")<<endl;
}


Measured memory_bytes: 12800
#include<stdio.h>
int main(){
  
  int x,y;
  int keep;
  
  while(1){
    scanf("%d %d",&x,&y);
    
    if(x == 0 && y == 0){
      break;
    }
    
    if(y < x){
      keep = y;
      y = x;
      x = keep;
    }
    
    printf("%d %d\n",x,y);
  }
  
  return(0);
  
}



Measured memory_bytes: 2032
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC164
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_A();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var l = Ex.ReadIntArray();
            var s = l[0];
            var w = l[1];
            var str = (s <= w) ? "unsafe" : "safe";
            str.Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {

        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

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

    if(A >= 13){
        cout << B << endl;
    }else if(A >= 6 && A <= 12){
        cout << B/2 << endl;
    }else{
        cout << '0' << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

bool is_prime(const unsigned n) {
    switch (n) {
        case 0:
        case 1:
            return false;
        case 2:
        case 3:
            return true;
    }
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false;
        if (n % (i + 2) == 0) return false;
    }
    return true;
}

// void solve() {
// int l, r;
// cin >> l >> r;
// int output = 0;
// for (int i = l; i <= r; i++) {
// if (is_prime(i) && is_prime((i + 1) / 2)) {
// output++;
// }
// }
// cout << output << endl;
// }

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

    int acc = 0;
    vector<int> primes(1e5 + 3, 0);
    for (int i = 1; i <= 100000; i++) {
        if (is_prime(i) && is_prime((i + 1) / 2)) {
            acc++;
        }
        primes[i] = acc;
    }

    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << primes[r] - primes[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

ll gcd(ll a, ll b) {
	if (a < b) gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	ll n, x;
	cin >> n >> x;
	cout << 3 * (n - gcd(n, x)) << endl;
}
	


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

#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol Mod=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r,q;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n;
  vector<int> x(n);
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >>x[i]>>l[i];
  }
  vector<pair<int,int>> p(n);
  for(int i=0;i<n;i++){
    p[i]=mp(x[i]+l[i]-1,x[i]-l[i]);
  }
  sort(p.begin(),p.end());
  lol place=p[0].fi;
  lol ans=1;
  for(int i=1;i<n;i++){
    if(p[i].se>place){
      ans++;
      place=p[i].fi;
    }
  }
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

bool compare(string T, string part)
{
    if (T.size() != part.size()) return false;
    rep (i, 0, T.size()) {
        if (part.at(i) == '?') continue;
        else if (T.at(i) == part.at(i)) continue;
        else return false;
    }
    return true;
}

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

    if (Sd.size() < T.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    // Sdのi文字目を固定して、そこから文字列長が|T|の部分文字列を抽出する
    vector<string> anss;
    rep (i, 0, Sd.size()) {
        string part = Sd.substr(i, T.size());
        if (compare(T, part)) {
            string ans;
            ans += Sd.substr(0, i);
            ans += T;
            ans += Sd.substr(ans.size(), Sd.size());
            replace(ans.begin(), ans.end(), '?', 'a');
            anss.push_back(ans);
        }
    }

    if (!anss.empty()) {
        sort(anss.begin(), anss.end());
        cout << anss[0] << endl;
        return 0;
    }

    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H = Integer.parseInt(scan.next());
		int W = Integer.parseInt(scan.next());
		char[][] a = new char[H][W];
		String str;
		for (int i = 0; i < H; i++) {
			str = scan.next();
			for (int j = 0; j < W; j++) {
				a[i][j] = str.charAt(j);
			}
		}
		boolean allWhite;
		//行の探索
		for (int i = 0; i < H; i++) {
			allWhite = true;
			for (int j = 0; j < W; j++) {
				if (a[i][j] == '#') {
					allWhite = false;
					break;
				}
			}
			if (allWhite) {
				for (int j = 0; j < W; j++) {
					a[i][j] = '_';
				}
			}
		}
		//列の探索
		for (int j = 0; j < W; j++) {
			allWhite = true;
			for (int i = 0; i < H; i++) {
				if (a[i][j] == '#') {
					allWhite = false;
					break;
				}
			}
			if (allWhite) {
				for (int i = 0; i < H; i++) {
					a[i][j] = '_';
				}
			}
		}
		//解の出力
		boolean allBlank;
		for (int i = 0; i < H; i++) {
			allBlank = true;
			for (int j = 0; j < W; j++) {
				if (a[i][j] != '_') {
					System.out.print(a[i][j]);
					allBlank=false;
				}
			}
			if (!allBlank) {
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 24968
n = gets.chomp.to_i

graph = Hash.new{ |h, k| h[k] = [] }

(n-1).times do
  a, b, c = gets.chomp.split.map(&:to_i)

  graph[a] << [b, c]
  graph[b] << [a, c]
end


# 全ての点からｋまでの最短距離を求める
# 辺の数がn-1しかないので、BFSでいけそう
# しかし10^5 * 10^5になる
# ダイクストラなら間に合いそうではある
# グラフでなく木なのでわざわざ複雑なアルゴリズムはいらなそう
# 
# !! Kから各点までの最短距離を求めればいいのでは！！
#
#
# p graph[k]

q, k = gets.chomp.split.map(&:to_i)

queue = []
queue << k

k_dist = Hash.new(0)
k_dist[k] = 0
visited = Hash.new(false)
visited[k] = true

until queue.empty?
  v = queue.shift

  graph[v].each do |l|
    x = l[0]
    d = l[1]
    next if visited[x]
    visited[x] = true

    k_dist[x] = k_dist[v] + d
    queue << x

  end
end

query = []

q.times do
  query << gets.chomp.split.map(&:to_i)
end


query.each do |a,b|
  puts k_dist[a] + k_dist[b]
end


Measured memory_bytes: 55032
a = int(input())
l = len(str(a))
s = l//2
t = 0
x = 0
if l%2 == 1:
    for i in range(s):
        t += 9*10**(2*i+1)
    x =a-t
else:
    for i in range(s-1):
        t += 9*10**(2*i+1)
    x = 10**(l-1)-1-t
print(x)

Measured memory_bytes: 3060
import sys
from collections import deque
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


def cal(e):
    if ans_array[e] != -1:
        return ans_array[e]
    ans = 0
    if e in node_dic:
        for x in node_dic[e]:
            ans = max(ans, cal(x) + 1)
    ans_array[e] = ans
    return ans


N, M = na()
node_dic = {}
no_in = [1] * N

for _ in range(M):
    x, y = na()
    if x-1 in node_dic:
        node_dic[x-1].append(y-1)
    else:
        node_dic[x-1] = [y-1]
    no_in[y-1] = 0


# print(node_dic, no_in)


ans_array = [-1] * N

edge = deque([])

for i, x in enumerate(no_in):
    if x == 1:
        cal(i)


print(max(ans_array))


Measured memory_bytes: 206808
using System;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで空白で区切って２つ受け取る。
	int g = int.Parse(input[1]);
	int b = int.Parse(input[2]);
      if((g * 10 + b) % 4 == 0)
	Console.WriteLine("YES");//WriteLineをWriteとすると、改行なしで出力。
      else
        Console.WriteLine("NO");
	}
}


Measured memory_bytes: 13140
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

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

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		printf("%d", A[i]);
		if (i != n - 1)
			printf(" ");
	}
	printf("\n");
}

void insertionSort(int A[], int N)
{
	int i, j,tmp;

	for (i = 1; i < N; i++)
	{
		j = i;
		while (j > 0 && A[j - 1] > A[j])
		{
			tmp = A[j - 1];
			A[j - 1] = A[j];
			A[j] = tmp;

			j--;
		}
		print(A, N);
	}
}

int main()
{
	int A[10000];
	int N, i;

	scanf("%d", &N);

	for (i = 0; i < N; i++)
		scanf("%d", &A[i]);

	print(A, N);

	insertionSort(A, N);

	return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define V vector
#define W V<long>
using namespace std;long E,M=2e17,a,b;W A;W S(V<W>p){if(!E)return{1,0};V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1)T[x[1]&1].push_back({x[0]/2,++x[1]/2});}for(long i;i<2;i++){a=0;for(W x:T[!i])a^=(2*x[0]+x[1])%3+1;if(!a){E--;A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p)v[0]++;A=S(p);A[0]--;return A;}int main(){cin>>E;V<W>p(E);while(E--,cin>>a>>b)p[E]={a+M,b+M};E=70;A=S(p);cout<<A[0]-M<<" "<<A[1]-M;}

Measured memory_bytes: 62908
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string s;
  int count1=0;
  int count2=0;
  cin >> N >> s;
  for(int i=0;i<N;i++){
    if(s.at(i) == 'R'){
      count1++;
    }
  }
    for(int j=0;j<N;j++){
      if(s.at(j) == 'B'){
        count2++;
      }
    }
  if(count1 > count2){
    cout << "Yes" << endl;
  }
    else{
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int MOD = 1000000007;
const int N = 200043;
int n;
int add(int x, int y)
{
	return (x + y) % MOD;
}

int sub(int x, int y)
{
	return add(x, MOD - y);
}

int mul(int x, int y)
{
	return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
	int z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}

int inv(int x)
{
	return binpow(x, MOD - 2);
}
vector<vector<int>>adj;
int fact[N];
int ifact[N];
int sz[N];
int dp[N];
int ans[N];
void dfs(int v, int p){
	dp[v]=1;
	sz[v]=1;
	for(auto u:adj[v]){
		if(u==p){
			continue;
		}
		dfs(u, v);
		sz[v]+=sz[u];
		dp[v]=mul(dp[u], dp[v]);
		dp[v]=mul(dp[v], ifact[sz[u]]);
	}
	dp[v]=mul(dp[v], fact[sz[v]-1]);
}

void dfs2(int v, int p){
	ans[v]=dp[v];
	for(auto u:adj[v]){
		if(u==p){
			continue;
		}
		
		dp[v]=mul(dp[v], ifact[n-1]);
		dp[v]=mul(dp[v], fact[n-1-sz[u]]);
		dp[v]=mul(dp[v], inv(dp[u]));
		dp[v]=mul(dp[v], fact[sz[u]]);
		dp[u]=mul(dp[u], fact[n-1]);
		dp[u]=mul(dp[u], ifact[sz[u]-1]);
		dp[u]=mul(dp[u], dp[v]);
		dp[u]=mul(dp[u], ifact[n-sz[u]]);
		sz[v]=sz[v]-sz[u];
		sz[u]=n;
		
		dfs2(u, v);
		sz[u]=sz[u]-sz[v];
		sz[v]=sz[v]+sz[u];
		
		dp[u]=mul(dp[u], fact[sz[v]-sz[u]]);
		dp[u]=mul(dp[u], inv(dp[v]));
		dp[u]=mul(dp[u], fact[sz[u]-1]);
		dp[u]=mul(dp[u], ifact[n-1]);
		dp[v]=mul(dp[v], ifact[sz[u]]);
		dp[v]=mul(dp[v], dp[u]);
		dp[v]=mul(dp[v], ifact[sz[v]-sz[u]-1]);
		dp[v]=mul(dp[v], fact[sz[v]-1]);
		
	}
}

main() {
	
	cin>>n;
	adj.resize(n+1);
	for(int i=0; i<n-1; i++){
		int u, v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	fact[0]=1;
	for(int i=1; i<N; i++){
		fact[i]=mul(fact[i-1], i);
	}
	for(int i=0; i<N; i++){
		ifact[i]=inv(fact[i]);
	}
	dfs(1, 1);

	ans[1]=dp[1];

	dfs2(1, 1);
	for(int i=1; i<=n; i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 23380
while True:
    n = int(input())
    if n ==0:
        break
    x = 1
    for i in range(1, n+1):
        x *= i
    y = 0
    while True:
        if x % 10 != 0:
            break
        x = x // 10
        y +=1
    print(y)


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

int n, t;
template <class T>
void readVector(int n, vector<T> &v){
    for(int i=0; i<n; ++i){
        T t;
        cin >> t;
        v.push_back(t);
    }
}
vector<int> a;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> t;
	readVector(n, a);
	int mi = 1e9+7;
	int difma = -1;
	int cnt = 0;
	for(int i=0; i<n; ++i){
		if(a[i] - mi > difma){
			difma = a[i] - mi;
			cnt = 1;
		}else if(a[i] - mi == difma){
			++cnt;
		}
		if(a[i] < mi) mi = a[i];
	}
	cout << cnt << "\n";
}

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

int N;
int64_t D_max;
int64_t D[30]={};
int64_t V[30]={};
std::pair<int64_t, int64_t> MEMO[2][14348907];//f:D_diff(B - A) s:V_diff(B - A)
auto MEMO_iter = MEMO[0];
template<int max>
void func(int i, int64_t D_diff, int64_t V_diff)
{
	if(max<=i){
		MEMO_iter->first = D_diff;
		MEMO_iter->second = V_diff;
		++MEMO_iter;
		return;
	}
	//A?????¨???
	func<max>(i+1, D_diff - D[i], V_diff - V[i]);
	//B?????¨???
	func<max>(i+1, D_diff + D[i], V_diff + V[i]);
	//???????????????
	func<max>(i+1, D_diff, V_diff);
}
const int64_t INF = 100000000000000000;

class seg_T
{
private:
	static constexpr inline int32_t get_child1(int32_t p){
		return p*2+1;
	}
	static constexpr inline int32_t get_parent(int32_t p){
		return (p-1)/2;
	}
public:
	static constexpr int32_t size_v = 16777216;//2????´????
	int64_t max_value[size_v*2 - 1];
	
	seg_T(){
		std::fill(std::begin(max_value), std::end(max_value), -INF);
	}
	void update(int32_t i, int64_t value)
	{
		i += size_v-1;
		while(i>=0){
			if(max_value[i] < value){ max_value[i] = value; }
			else{ break; }
			i = get_parent(i);
		}
	}
	
	int64_t get(int64_t begin, int64_t end,
		int64_t n_beg = 0, int64_t n_end = size_v, int32_t i = 0)
	{
		if(!(i<size_v*2 - 1)){
			std::cout << n_beg << ' ' << n_end << ' ' << i << std::endl;
			assert(false);
		}
		if(end <= n_beg || n_end <= begin){return -INF;}
		if(begin <= n_beg && n_end <= end){return max_value[i];}
		return std::max(
			get(begin, end, n_beg, (n_beg + n_end)/2, get_child1(i)),
			get(begin, end, (n_beg + n_end)/2, n_end, get_child1(i) + 1)
			);
	}
}seg;
#ifdef DEBUG
#define PASS std::cout<<"==============" << std::endl
#else
#define PASS
#endif
int main()
{
	std::cin.sync_with_stdio(false);
	std::cout.sync_with_stdio(false);
	
	std::cin >> N>>D_max;
	for(int i = 0;i < N; ++i){
		std::cin >> D[i] >> V[i];
	}
	MEMO_iter = MEMO[1];
	func<15>(0, 0,0);
	MEMO_iter = MEMO[0];
	func<30>(15, 0,0);
	
	PASS;
	using P = std::pair<int64_t, int64_t> ;
	std::sort(std::begin(MEMO[0]), std::end(MEMO[0]), std::greater<P>{});
	PASS;
	std::sort(std::begin(MEMO[1]), std::end(MEMO[1]));
	
	PASS;
	for(int32_t i = 0;i < 14348907; ++i){
		seg.update(i, MEMO[1][i].second);
	}
	PASS;
	#ifdef DEBUG
	for(int32_t i = 0;i < 14348907; i+=14348907/10){
		std::cout << seg.get(i,i+1) << ' ';
	}
	std::cout << std::endl;
	for(int32_t i = 0;i < 14348907; i+=14348907/10){
		std::cout << seg.get(i,i+14348907/10) << ' ';
	}
	std::cout << std::endl;
	#endif
	int64_t max = -INF;
	auto m1_iter_beg = std::begin(MEMO[1]);
	auto m1_iter_end = std::begin(MEMO[1]);
	auto m1_iter_begall = std::begin(MEMO[1]);
	auto m1_iter_endall = std::end(MEMO[1]);
	for(int32_t i = 0;i < 14348907; ++i){
		auto& bace = MEMO[0][i];
		m1_iter_end = std::upper_bound(m1_iter_end, m1_iter_endall, P{+D_max-bace.first,+INF});
		m1_iter_beg = std::lower_bound(m1_iter_beg, m1_iter_endall, P{-D_max-bace.first,-INF});
		
		max = std::max(max, bace.second + 
			seg.get(m1_iter_beg - m1_iter_begall, m1_iter_end - m1_iter_begall)
			);
			
	#ifdef DEBUG
	if(i==14348907/2){PASS;}
	#endif
	}
	
	
	std::cout << max << std::endl;
}

Measured memory_bytes: 713660
#include<cstdio>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<complex>
#define inf 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define pii pair<int,int> 
const int N=1e6+10;
const int mod=998244353;
using namespace std;

int v[N];
void solve(){
   int n; scanf("%d",&n);
   for(int i=1,x;i<n;++i) scanf("%d",&x),v[x]++;
   for(int i=1;i<=n;++i) printf("%d\n",v[i]);
}
int main() 
{
    int _=1;  //scanf("%d",&_);
    while(_--) solve();
return 0;
}
/*
*/
 

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

using namespace std;
#define ll long long
const int N=2e5+5;
int a[N];
bool ball[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    multiset<int>st;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i],st.insert(a[i]);
    for(int i=0;i<n;i++)
    {
       st.erase(st.find(a[i]));
       cout<<*st.rbegin()<<'\n';
       st.insert(a[i]);
    }
    return 0;
}


Measured memory_bytes: 11776
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S = sc.next();
		sc.close();
		if (K >= S.length()){
			System.out.println(S);
		}else{
			System.out.println(S.substring(0, K) + "...");
		}
    }
}

Measured memory_bytes: 38556
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 14232
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	pair<int, int> xy, a, b;
	cin >> xy.first >> xy.second;
	int i;
	vector<int> c(34, 1);
	for (i = 2; i < 34; ++i) c[i] = c[i - 2] + c[i - 1];
	for (i = 0; a.first > xy.first || a.second > xy.second || b.first < xy.first || b.second < xy.second; ++i) {
		if (0 == i % 4) {
			a.first += c[i];
			b.first += c[1 + i];
			b.second += c[1 + i] - c[i];
		}
		else if (1 == i % 4) {
			a.first += c[i] - c[1 + i];
			a.second += c[i];
			b.second += c[1 + i];
		}
		else if (2 == i % 4) {
			a.first -= c[1 + i];
			a.second += c[i] - c[1 + i];
			b.first -= c[i];
		}
		else {
			a.second -= c[1 + i];
			b.first += c[1 + i] - c[i];
			b.second -= c[i];
		}
	}
	cout << 1 + i % 3 << endl;
}


Measured memory_bytes: 3104
const main = (input: string) => {
  const lines = input.trim().split("\n");
  const N = parseInt(lines[0])
  let L = lines[1].split(" ").map(str => parseInt(str));
  const maxLength = Math.max(...L);
  let sum = 0;

  const compareFunc　=　(a: number, b: number) => {
    return a - b;
  }

  L.sort(compareFunc)

  for (let i = 0; i < N - 1; i++) {
    sum += L[i];
  }

  console.log(sum > maxLength ? "Yes" : "No")
}

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


Measured memory_bytes: 7372
open Hashtbl
let h, n, m = create 100100, read_int (), ref 1
let _ = for _ = 1 to n do let s = read_line () in replace h s @@ try let c = find h s + 1 in m := max !m c; c with _ -> 1 done; List.(fold (fun s c a -> if c = !m then s :: a else a) h [] |> sort compare |> iter print_endline)

Measured memory_bytes: 33024
from collections import Counter
def counter(li, n):
    count = Counter()
    count.update(li)
    return count[n]
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
li_AC = [0]*N
count_WA = [0]*N
count_WA_total = 0
for i in range(M):
    p, S = input().split()
    p = int(p)
    if li_AC[p-1] == 0:
        if S == "AC":
            li_AC[p-1] = 1
            count_WA_total += count_WA[p-1]
        if S == "WA":
            count_WA[p-1] += 1
print(counter(li_AC, 1), count_WA_total)

Measured memory_bytes: 42716