akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


int main(){
    int a;
    string s;
    cin >> a >> s;
    
    cout << (a>=3200 ? s: "red") << endl;

}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a < b&&b < c){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	
	return (0);
}

Measured memory_bytes: 580
from operator import itemgetter
n = int(input())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort(key = itemgetter(1))
time = 0
for i in range(n):
    time += data[i][0]
    if time > data[i][1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 53720
#include<bits/stdc++.h>
#define N 500009
using namespace std;

int n,m,a[N]; long long dp[N]; bool ans[N];
int main(){
	scanf("%d%d",&n,&m);
	int i;
	for (i=1; i<=n; i++) scanf("%d",&a[i]);
	dp[n+1]=1;
	for (i=n; i; i--)
		if (a[i]>=(dp[i+1]<<1)) dp[i]=dp[i+1];
		else dp[i]=dp[i+1]+a[i];
	for (i=1; i<=n; i++){
		if (m>=dp[i+1]) ans[i]=1;
		m=min(m,abs(m-a[i]));
	}
	int cas; scanf("%d",&cas);
	while (cas--){
		scanf("%d",&i); puts(ans[i]?"YES":"NO");
	}
	return 0;
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long check(int x,int n,int ara[])
{
    long long ans=0;
    for(int i=0; i<n; i++)
    {
        ans+=((x-ara[i])*(x-ara[i]));
    }
    return ans;
}
int main()
{
    int n,i,sum=0,mini=INT_MAX,maxi=INT_MIN;
    cin>>n;
    int ara[n+5];
    for(i=0; i<n; i++)
    {
        cin>>ara[i];
        if(ara[i]<mini)
            mini=ara[i];
        if(ara[i]>maxi)
            maxi=ara[i];
    }
    long long ans1=INT_MAX;
    for(i=1; i<101; i++)
    {
        long long temp=check(i,n,ara);
        if(temp<ans1)
            ans1=temp;
    }
    cout<<ans1<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long 
const int MAX_N = 400010;
const int MAX_P = 60;

int A[3*MAX_N];
int nx[MAX_P][MAX_N];

signed main(void){ 
  
  int N,K;cin >> N >> K;
  
  for(int i = 0; i < N; i++){ cin >> A[i]; A[i+N] = A[i]; A[i+2*N] = A[i];}
  // next[0][i]を組み立てる
  
  map<int,int> mp;
  
  for(int i = 3*N-1; i >= 0; i--){
    int a = A[i];
    if( mp[a] > 0 ){ //
      if( i >= 2*N ){ mp[a] = i;}
      else{ nx[0][i] = mp[a]-i; mp[a] = i;}
    }
    else{
      mp[a] = i;
    }
  }
  
  for(int i = 0; i < N; i++){ nx[0][i]++;}

  
  //nxはイテレータではなく距離であることに注意
  
  for(int k = 1; k < MAX_P; k++){ 
    for(int i = 0; i < N; i++){
     nx[k][i] = nx[k-1][i]+nx[k-1][(nx[k-1][i]+i)%N];
    }
  }
  //ダブリング
  
  
  if(false){
  for(int i = 0; i < N; i++){ cout << nx[0][i] << " ";}
  cout << endl;
  }
  

  
  //確かめる //ここまでおk
  
  
  
  
  
  int pos = 0; //これは実際の位置
  
  while( pos < N*K ){
    int r = -1;
    while( pos+nx[r+1][pos%N] < N*K ){ r++;}
    if( r == -1 ){ break;} //もうこの先はダブリング使う必要なし
    pos += nx[r][pos%N]; //この時点で、posはギリギリN*Kを超えていない
    
   
  }
  
  //posより先は愚直に計算
  vector<int> vec;
  vector<bool> used(MAX_N,false);
  
  for(int i = pos; i < N*K; i++){
    
    int x = A[i%N];
   
    if(used[x]){ //xまで消す
     
      while(true){ 
        int r = *vec.rbegin();
        vec.pop_back();
        used[r] = false;
        if( r == x ){ break;}
      }
      used[x] = false;
      
    }//if
        
    
        
    else{ used[x] = true;  vec.push_back(x);} 
    //ここでいちいち全部消していたのがまずい ここさえ直せばどうにかなるはず
  }
   
  for(auto ans : vec){ cout << ans << " ";}
  cout << endl;
  
  return 0;
}
  

Measured memory_bytes: 208240
#include<iostream>
using namespace std;
int main(){
int n;cin>>n;
    if (n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9) {
        cout<<"hon";
    } else if (n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) {
        cout<<"pon";
    } else {
        cout<<"bon";
}    return 0;}





Measured memory_bytes: 3604
'use strict';
(function(stdin) {
  var EOF = '0';
  var inputs  = stdin.toString().split('\n');
  var data = inputs.slice(0,inputs.indexOf(EOF));
  
  // data.forEach(function(v,i,a) {
  //     // console.log('Case',i + 1 + ':',v);
  //     console.log(v,i,a[i],a);
  // });

  for (var index in data) {
//    console.log(data[index]);
      console.log('Case',parseInt(index,10) + 1 + ':',data[index]);
  }

  // for (var i = 0; i < data.length; i++) {
  //     console.log('Case',i + 1 + ':',data[i]);
  // }
  



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

Measured memory_bytes: 20840
#include<bits/stdc++.h>
//using fixed so that output doesnt comes like 1e9 type
#define pr(x)  cout<<fixed<<setprecision(10)<<x<<endl;
using namespace std;

double a[30001];
double n;
double dp[3001][3001];

double solve(int i,int x){
   if(x==0)
   return 1;
   if(i==0)
   return 0;
   
   if(dp[i][x]> -0.9)
   return dp[i][x];
   
   dp[i][x]=a[i]*solve(i-1,x-1) + (1-a[i])*solve(i-1,x);
   return dp[i][x];	
	
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	int x=(n+1)/2;
	memset(dp,-1,sizeof(dp));
	pr(solve(n,x));
}

Measured memory_bytes: 70912
#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}
};

map<ll, ll> factorize(ll n) {
    map<ll, ll> factors;
    for(ll i=2LL;i*i<=n&&n>1LL;++i) {
        while(n % i == 0LL) {
            ++factors[i];
            n /= i;
        }
    }
    if(n != 1LL) ++factors[n];
    return factors;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll  n;
    cin >> n;
    map<ll, ll> mp = factorize(n);
    ll ans = 0LL;
    for(auto itr=mp.begin();itr!=mp.end();++itr) {
        ll f = itr->first, m = itr->second;
        ll i = 1;
        while(i*(i+1)/2 <= m) {
            ++i;
        }
        --i;
        ans += i;
    }

    cout << ans << endl;
}


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

map< int64_t, int64_t > prime_factor(int64_t n) {
  map< int64_t, int64_t > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n]++;
  return ret;
}

int main(){
    int64_t n;
    cin >> n;
    int64_t ans=0;
    int64_t tmp;
    int64_t e;
    for(auto p : prime_factor(n)){
        tmp=1;
        e=p.second;
        while(tmp<=e){
            e-=tmp;
            ans++;
            tmp++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
	int n,d;
	cin >> n >> d;
	int c = 0;
	double el1,el2;
	while(n--){
		cin >> el1 >> el2;
		if(sqrt(pow(el1,2) + pow(el2,2)) <= d)
			c++;	
	}
	cout << c << endl;
}


Measured memory_bytes: 3788
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, x: usize);
    for i in 1..=360 {
        if (x * i) % 360 == 0 {
            println!("{}", i);
            return;
        }
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2100
/*input
4
1 2
2 3
2 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

vector<int> edge[maxn];
int deg[maxn];

set<pii> st;
bool vis[maxn];
int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n-1){
		int u,v;
		cin>>u>>v;
		u--;v--;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	REP(i,n) deg[i]=SZ(edge[i]);

	REP(i,n) st.insert(MP(deg[i],i));

	while(SZ(st)){
		pii cur=*st.begin();
		vis[cur.S]=1;
		//cout<<cur<<'\n';
		if(deg[cur.S]!=1){
			cout<<"First\n";
			return 0;
		}
		st.erase(st.begin());
		int ptr=-1;
		for(int v:edge[cur.S]) if(!vis[v]) ptr=v;
			//cout<<ptr<<'\n';
		vis[ptr]=1;
		for(int v:edge[ptr]) if(!vis[v]){
			st.erase(MP(deg[v],v));
			deg[v]--;
			st.insert(MP(deg[v],v));
		}
		st.erase(MP(deg[ptr],ptr));
	}
	cout<<"Second\n";
	return 0;
}


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

int lcs(string s, string t);
int main(){
  int n; cin >> n;
  string s, t;
  int ans[n];
  for(int i=0; i<n; i++){
    cin >> s >> t;
    ans[i]=lcs(s,t);
  }

  for(int i=0; i<n; i++) cout << ans[i] << endl;

  return 0;
}

int lcs(string s, string t){
  int ans=0;
  int sl=s.length(), tl=t.length();
  int dp[sl+1][tl+1];

  for(int i=0; i<=sl; i++) dp[i][0]=0;
  for(int j=0; j<=tl; j++) dp[0][j]=0;

  s=" "+s;
  t=" "+t;
  for(int i=1; i<=sl; i++){
    for(int j=1; j<=tl; j++){
      if(i==0 || j==0) dp[i][j]=0;
      else if(s[i]==t[j]) dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i][j-1], dp[i-1][j]);
    }

  }

  return dp[sl][tl];
}



Measured memory_bytes: 7004
#include <iostream>
#include <string>
using namespace std;
int main(){
string bad;
int a,b;
while(true){
 a=0;b=0;
 cin >> bad;
 if(bad=="0"){
      break;
 }
 for(int i=1;i<bad.size();i++){
       if(bad[i]=='A'){
              a++;
        }else{
              b++;
         }
 }
 if(a>b){
       a++;
 }else{
       b++;
 }
 cout << a << ' ' << b << endl;
 }
 return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    VL a;
    int zeros = 0;
    FOR(i, 0, n)
    {
        string s;
        cin >> s;
        int p = 0;
        while (p < SZ(s) && s[p] != '.')
            p++;
        if (p == SZ(s))
        {
            int v = atoi(s.c_str());
            if (v == 0)
                zeros++;
            else
                a.PB(v * 1000000000LL);
        }
        else
        {
            string ss = s.substr(p + 1);
            int v = atoi(ss.c_str());
            int u = atoi(s.substr(0, p).c_str());
            if (v == 0 && u == 0)
            {
                zeros++;
            }
            else
            {         
                FOR(j, SZ(ss), 9)
                    v *= 10;
                a.PB(u * 1000000000LL + v);
            }
        }
    }
    LL ans = 0;
    ans += ((LL)zeros * (zeros - 1)) / 2;
    ans += (LL)zeros * (n - zeros);
    map<PII, int> cnt;
    for (auto x : a)
    {
        int two = 0, five = 0;
        while (x % 2 == 0)
        {
            two++;
            x /= 2;
        }
        while (x % 5 == 0)
        {
            five++;
            x /= 5;
        }
        cnt[MP(two, five)]++;
    }
    for (auto it = cnt.begin(); it != cnt.end(); ++it)
    {
        if (it->F.F + it->F.F >= 18 && it->F.S + it->F.S >= 18)
            ans += ((LL)it->S * (it->S - 1)) / 2;
        for (auto it2 = next(it); it2 != cnt.end(); ++it2)
        {
            if (it->F.F + it2->F.F >= 18 && it->F.S + it2->F.S >= 18)
            {
                ans += (LL)it->S * it2->S;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5348
#pragma GCC optimize ("O3")

#pragma GCC optimize("Ofast")

#include   <bits/stdc++.h>
#include   <algorithm>
#include   <queue>
#include   <list>
#include   <map>
#include   <math.h>
#include   <numeric>
#include   <iomanip>
using      namespace        std;
#define    endl             '\n'
#define    FAST             ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define    ipfile           ifstream cin ("input.txt");std::cin.rdbuf(std::cin.rdbuf())
#define    pb(x)            push_back(x)
#define    int              long long int
#define    ull              unsigned long long int
#define    db               long double
#define    mod              1000000007
#define    vll              vector<int>
#define    all(v)           v.begin(),v.end()
#define    GCD(m,n)         __gcd(m,n)
#define    LCM(m,n)         m*(n/GCD(m,n))
#define    REVVEC(v)        reverse(v.begin(),v.end())
#define    REVARR(a)        reverse(a,a+n)
#define    maxc(v)          max_element(all(v))
#define    minc(v)          min_element(all(v))
#define    inputarr(a,n)    for(int xxx=0;xxx<n;++xxx) cin>>a[xxx]
#define    outputarr(a,n)   for(int xxx=0;xxx<n;xxx++) cout<<a[xxx]<<" "
#define    rep(i,m, n)      for(int i = m; i < (n); ++i)
#define    sp               setprecison(10)
#define    sz(v)            v.size()

clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}

vll v;

const int MAX=1e7+9;

bool prime[MAX];


void street1()
{
    int N;
    cin>>N;
    int *pp;
    int i,s[N+1],p1[N+1],v[N+1];int r[N+N],k=0;
    for( i=0;i<N;i++)
    {
        cin>>s[i]>>p1[i]>>v[i];
    }
    if(N==1)
    {
        cout<<"0\n";
    }
    else{
    
    for(i=0;i<N;i++)
    {
        if(p1[i]%(s[i]+1)==0)
        {
            
            r[k++]=((p1[i])*v[i])/(s[i]+1);
           
        }
        else{
            r[k++]=(p1[i]/(s[i]+1))*v[i];
        }
    }
    
    pp=max_element(r,r+k);
    cout<<*pp<<"\n";
    }
}
void serval()
{
    int n,k;
    cin>>n>>k;
    int i,a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(k>n)
    cout<<"0\n";
    else{
    sort(a,a+n);
    int sum=0;
    sum+=accumulate(a,a+(n-k),sum);
    cout<<sum<<"\n";
    }
}
signed main() {
	    
	    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	

    
  serval();


  	time();
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
#define scn(n) scanf("%d",&n)
#define print(a) printf("%d",a);
using namespace std;
using ll =int;
ll n;

ll dp[200005],a[200005]={1000000000};
ll invalid=1e9,k;
ll cnt=0;
int solve(ll i,ll p)
{ //cnt++;
    if(i==n-1)return dp[i]=0;
    if(i>=n)return 1e9;
    if(dp[i]!=-1)return dp[i];
    //what(p-a[i]);
    //cout<<i<<" GG "<<i+1<<endl;
    ll ans=1e9,x;
    fr(l,1,min(k,n)+1){
        //what(l);
    x=abs(a[i+l]-a[i])+solve( i+l,a[i]);

    ans=min(x,ans);

    }



    return dp[i]=ans;

}

int main()
{
    ll t;
    memset(dp,-1,sizeof dp);

    scn(n);
    scn(k);
    fr(i,0,n)cin>>a[i];

    solve(0,a[0]);

    printf("%d\n",dp[0]);
    //what(cnt);
    //fr(i,0,n)cout<<dp[i]<<" ";

}



























Measured memory_bytes: 11076
#include<cstdio>
#include<cstring>
using namespace std;
const int w=20003;
char s[10005];
int x,y,_x,len,p,sum,q,now=1;
bool ws[2][2][40009];
int main(void){
	register int i;
	scanf("%s%d%d",s+1,&x,&y),len=strlen(s+1),x+=w,y+=w;
	while(now<=len&&s[now]=='F')++now,++_x;
	ws[0][0][w+_x]=1,ws[1][0][w]=1;
	while(now<=len){
		++now,sum=0,p^=1,q^=p;
		while(now<=len&&s[now]=='F')++sum,++now;
		for(int i=w-len;i<=w+len;++i)
			ws[p][q][i]=ws[p][q^1][i+sum]|ws[p][q^1][i-sum];
	}
	if(p==1&&ws[0][q^1][x]&&ws[1][q][y]||p==0&&ws[0][q][x]&&ws[1][q][y])puts("Yes");
	else puts("No"); 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>a, out;
int n, m, flag;
void dfs(int step){
    if(flag)return;
    if(step >= n){
        int s = 0;
        for(int i = 0; i < a.size(); i++){
            s += a[i] * out[i];
        }
        if(s == m)
        flag = true;
        return;
    }
        out[step] = 0;
        dfs(step+1);
        out[step] = 1;
        dfs(step+1);
}
int main(){
    cin >> n;
    a.resize(n);
    out.resize(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q;
    cin >> q;
    while(q--){
        flag = 0;
        cin >> m;
        dfs(0);
        if(flag)cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3092
n = int(input())
ab_lst = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        ab_lst.append([i, n // i])
# print(ab_lst)
ans = 20
for i in range(len(ab_lst)):
    a = ab_lst[i][0]
    b = ab_lst[i][1]
    if a < b: f = len(str(b))
    else: f = len(str(a))
    # print(a, b, f)
    if f < ans:
        ans = f
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; ++i) cin >> vec[i];
    sort(vec.begin(), vec.end());

    int ans = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k < j; ++k) {
                if (vec[k] != vec[j] && vec[i] != vec[j] &&
                    vec[k] + vec[j] > vec[i]) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3584
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll n ;
	cin>> n ;
	for(ll i=1;i<=9;i++){
		for(ll j=1;j<=9 ; j++){
			if(i*j==n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<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;

int main(){
  int a,b;
  cin>>a>>b;
  
  if(a==b){
    cout<<"Draw";
  }else if(a==1 || a>b && b!=1){
    cout<<"Alice";
  }else{
    cout<<"Bob";
  }
  return 0;
}


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

using ll = long long;

int main() {
  int n;
  cin >> n;
  
  vector<ll> a(n);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  ll keep = 0, ans = 1e18;
  for(int i = 0; i < n - 1; i++){
    keep += a.at(i);
    ans = min(ans, abs(sum - 2 * keep));
  }
  
  cout << ans << endl;
}

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


void solve(long long N, std::vector<long long> a){
  ll all = 0;
  vector<ll> ret;
  rep(i,N) all ^= a[i];
  rep(i,N) ret.push_back(all^a[i]);
  for(int i=0; i<N; i++) {
    if(i==N-1) {
      std::cout << ret[i] << std::endl;
    } else {
      std::cout << ret[i] << ' ';
    }
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 6936
#include<bits/stdc++.h>
using namespace std;
long long n,q,cnt[100005],tot;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		long long a;
		cin>>a;
		cnt[a]++;
		tot+=a;
	}
	cin>>q;
	for(int i=0;i<q;i++)
	{
		long long b,c;
		cin>>b>>c;
		tot-=b*cnt[b];
		tot+=c*cnt[b];
		cnt[c]+=cnt[b];
		cnt[b]=0;
		cout<<tot<<"\n";
	}
	return 0;
}

Measured memory_bytes: 4400
#include <stdio.h>

#define MAX 100005
#define NIL -1

int p[MAX],left[MAX],right[MAX],d[MAX],h[MAX],sib[MAX];
int Depth(int n)
{
  int d=0;
  while(p[n]!=NIL)
  {
    n=p[n];
    d+=1;
  }
  return d;
}
void printChildren(int n)
{
  int child = left[n];
  while(child!=NIL)
  {
    printf("%d",child);
    child=right[child];
  }
}
int height(int u)
{
  int h1=0,h2=0;
  if(left[u]!=NIL)h1=height(left[u])+1;
  if(right[u]!=NIL)h2=height(right[u])+1;
  if(h1>h2)return h[u]=h1;
  else return h[u]=h2;
}
int sibling(int u)
{
  if(p[u]==NIL)return NIL;
  if(left[p[u]]!=u&&left[p[u]]!=NIL)return left[p[u]];
  if(right[p[u]]!=u&&right[p[u]]!=NIL)return right[p[u]];
  return NIL;
}
int main()
{
  int i,j,id,num,deg,root;
  scanf("%d",&num);
  for(i=0;i<num;i++)
  {
    p[i]=left[i]=right[i]=NIL;
  }
  for(i=0;i<num;i++)
  {
    scanf("%d",&id);
    scanf("%d%d",&left[id],&right[id]);
    if(left[id]!=NIL)p[left[id]]=id;
    if(right[id]!=NIL)p[right[id]]=id;
  }
  for(i=0;i<num;i++)if(p[i]==NIL)root=i;
  height(root);
  for(i=0;i<num;i++)
  {
    d[i]=Depth(i);
  }
  for(i=0;i<num;i++)
  {
    j=0;
    printf("node %d: parent = %d, sibling = %d, ",i,p[i],sibling(i));
    deg=0;
    if(left[i]!=NIL)deg++;
    if(right[i]!=NIL)deg++;
    printf("degree = %d, depth = %d, height = %d, ",deg,d[i],h[i]);
    if(p[i]==NIL)printf("root");
    else if(left[i]==NIL&&right[i]==NIL)printf("leaf");
    else printf("internal node");
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2112
#include<iostream>
using namespace std;
int main()
{
    int S,h,m,s;
    cin>>S;
    
    h= S/3600;
    m= (S%3600) /60;
    s= S%60;
    
    cout<<h<<":"<<m<<":"<<s<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
////////////////////////////////////////////////////////////
const int MAX_V = 100;
typedef struct edge_{int to,cost;}edge;
typedef pair<int,int> P; 	//firstは最短経路,secondは頂点番号
int V; 										//頂点数
vector<vector<edge>> G(MAX_V);
int dp[MAX_V];

void dijkstra( int s ){
	//最短経路の値の小さいものから取り出せる
	priority_queue<P,vector<P>,greater<P>> que;
	for(int i = 0 ; i < V ; i++ ) dp[i] = INF;
	dp[s] = 0;
	que.push(pair<int,int>(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if( dp[v] > p.first ) continue;
		for(int i = 0 ; i < G[v].size() ; i++ ){
			edge e = G[v][i];
			//cout << "here:" << i << " to:" << e.to << " cost:" << e.cost << endl;
			if( dp[e.to] > dp[v] + e.cost ){
				dp[e.to] = dp[v] + e.cost;
				que.push(pair<int,int>(dp[e.to],e.to));
			}
		}
	}
	return;
}
int main(){
	cin >> V;
		
	rep(i,0,V){
		int u,k;
		cin >> u >> k;
		rep(j,0,k){
			int v,c;
			cin >> v >> c;
			G[i].push_back(edge{v,c});
		}
	}
	
	dijkstra(0);

	rep(i,0,V){
		cout << i << " " << dp[i];
		if( i < V - 1 )
			cout << endl;
	}
	cout << endl;

	ret 0;
}


Measured memory_bytes: 3152
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      char[] s = sc.next().toCharArray();
      int k = sc.nextInt();
      int n = s.length;
      for(int i = 0;i < n;i++){
      	if(s[i]!='a'&&k>='z'-s[i]+1){
          k-='z'-s[i]+1;
          s[i]='a';
        }
      }
      k = (26+k-'z'+s[n-1])%26;
      if(k==0)s[n-1]='z';
      else s[n-1]=(char)(k+'a'-1);
      System.out.println(s);
    }
}

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


#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define print(x) cout << x << endl;
typedef long long ll;

constexpr ll INF = 1'010'000'000'000'000'017LL;\
constexpr ll MOD = 1'000'000'007LL;\
constexpr double EPS = 1e-12;\
constexpr double PI = 3.14159265358979323846;

int main()
{
    string S;
    cin >> S;
    ll Q;
    cin >> Q;
    bool rev = false;
    string mae = "";
    string ato = "";
    REP(i, Q) {
        ll T;
        cin >> T;
        if (T == 1) {
            rev = !rev;
        } else {
            ll F;
            string C;
            cin >> F >> C;
            if (rev) {
                if (F == 1) {
                    ato += C;
                } else {
                    mae += C;
                }
            } else {
                if (F == 1) {
                    mae += C;
                } else {
                    ato += C;
                }
            }
        }
    }
    reverse(ALL(mae));
    S = mae + S + ato;
    if (rev) {
        reverse(ALL(S));
        print(S);
    } else {
        print(S);
    }
    return 0;
}

Measured memory_bytes: 1348
n = int(input())
s = input()
ans = 0

for i in range(0, len(s)):
    if s[i] == "E":
        ans += 1

cur = ans

for i in range(0, len(s)):
    if s[i] == "W":
        cur += 1
    else:
        cur -= 1

    if cur < ans:
        ans = cur

print(ans)

Measured memory_bytes: 9608
#include <bits/stdc++.h>  
using namespace std;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
using ll = long long int;
 
int main() {
  ll k; cin>> k;
  if(k % 7  ==0){
    k /= 7;
  }
  ll x = k;
  int ans  = -1;
  rep(i, k){
    x = x* 10 + 1;
    x %= k; //cout<<x;
    if(x == 0){ans = i+ 1; break;}
  }
  cout<<ans;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define re(a,n) reverse(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
const int twx=+100;
const int inf=0x3f3f3f3f;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
ll POW[twx]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000};
ll d;
ll ans=0;
ll dfs(ll l,ll r,ll d)
{
    if(l>=r)
    {
        if(d==0)
        {
            return l==r?10:1;
        }
        return 0;
    }
    if(d%10==0)
    {
        if(l!=1)
        {
            return 10*dfs(l+1,r-1,d/10);
        }
        return 9*dfs(l+1,r-1,d/10);
    }
    ll differ=d%10-10;//选取的数一定要使l位进1否则取反之后的必定小与改数，那么显然不可能。所以differ是d%10-10
    ll Next=d-differ+differ*POW[r-l];//这里先让d进一位，然后由于对称性，r位+differ=l位+differ所以选择+differ*Power[r-l]，这样才能满足对称条件
    if(l==1)
    {
        return(9+differ)*dfs(l+1,r-1,abs(Next)/10);
    }
    return(10+differ)*dfs(l+1,r-1,abs(Next)/10);
}
void init()
{
	d=read();
    f1(2,18,i)
    {
        ans+=dfs(1,i,d);
    }
    printf("%lld\n",ans);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    init();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int p[N];
    REP(i, N){
        cin >> p[i];
    }

    sort(p, p+N, greater<int>());

    int ans = int(p[0]/2);

    FOR(i, 1, N-1){
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.14159265358979323846264
int main()
{
	int n;
	cin>>n;
	int x=1;
	while(x*1000<n)
	{
		x++;
	}
	cout<<x*1000-n;
	return 0;
}

Measured memory_bytes: 3620
n = int(input())
count=n
for i in range(0,n+1):
  temp=0
  temp6=i
  while temp6>0:
    temp=temp+temp6%6
    temp6=int(temp6/6)
  temp9=n-i
  while temp9>0:
    temp=temp+temp9%9
    temp9=int(temp9/9)
  count=min(count,temp)
print(count)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int h,a;
    scanf("%d%d",&h,&a);
    int k,sum=0;
   for(int i=0;i<a;i++){
    scanf("%d",&k);
    sum+=k;
   }
    if(sum<h)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python
H, W = map(int, input().split())

g = [[True] * (W+2)]
for _ in range(H):
    g.append([True] + [x == '#' for x in input()] + [True])
g.append([True] * (W+2))

l = []
for i in range(1, H+1):
    for j in range(1, W+1):
        if g[i][j]:
            l.append((i, j))

c = 0
while l:
    ll = []
    for i,j in l:
        if not g[i+1][j]:
            g[i+1][j] = True
            ll.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            ll.append((i-1, j))
        if not g[i][j+1]:
            g[i][j+1] = True
            ll.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            ll.append((i, j-1))
    c += 1
    l = ll

print(c-1)
    


Measured memory_bytes: 105968
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
 
typedef long long ll;
const int N = 200005;

 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	ll n;
	cin>>n;
	
	ll ans = 0;
	ll x = 10;
	if(n%2 == 0){
		while(x <= n){
			ans += n/x;
			x *= 5;
		}	
	
		cout<<ans;
	}
	else{
		cout<<0;
	}
	return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

bool valid = true;
int root = 0;

int dfs(int cv, int pv, vector<vector<int>> &G, vector<ll> &a){

    ll sum = 0;
    bool have_child = false;
    for(auto nv : G[cv]){
        if(nv == pv) continue;
        have_child = true;
        ll cost = dfs(nv, cv, G, a);
        if(a[cv] < cost) valid = false;
        if(cost < 0) valid = false;
        sum += cost;
    }

    if(cv == root){
        if(a[root] != sum) valid = false;
    }

    if(!have_child){
        return a[cv];
    }
    else{
        if(a[cv] < a[cv] * 2 - sum) valid = false;
        return a[cv] * 2 - sum;
    }
}

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

    int n; cin>>n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<vector<int>> G(n);
    for(int i=0; i<n-1; i++){
        int a, b; cin>>a>>b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    while(G[root].size() > 1) root++;

    dfs(root, -1, G, a);

    cout << (valid ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    std::vector<std::pair<long long, int> > AB;
    AB.resize(N);
    for(int i=0; i<N; i++)
        scanf(" %lld %d", &(AB[i].first), &(AB[i].second));
    
    std::sort(AB.begin(), AB.end());
    long long count = 0, price = 0;
    for(int i=0; i<N; i++){
        if(count + AB[i].second < M){
            count += AB[i].second;
            price += AB[i].first * AB[i].second;
        }
        else{
            price += AB[i].first * (M - count);
            break;
        }
    }
    std::cout << price << std::endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
typedef long long LL;
const int maxn = 200007;
struct thing
{
    int t;
    int e;
}a[maxn];

bool cmp(thing x, thing y){
    if(x.e >= y.e){
        return false;
    }
    else return true;
}

int main()
{
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i].t >> a[i].e;
    }
    sort(a, a + N, cmp);
    long long res = 0;
    int flag = 0;
    for(int i = 0; i < N; i++){
        res += a[i].t;
        if(res > a[i].e){
            flag = 1;
            break;
        }
    }
    if(flag){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

ll INF = 1000000007;
vector<vector<int>> g;
ll k;
ll ans;
vector<ll> ruijo;

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x); // 再帰的に解く
	y -= a / b * x;
	return d;
}

// 負の数にも対応した mod (a = -11 とかでも OK) 
inline long long mod(long long a, long long m) {
	return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)mod m
long long modinv(long long a, long long m) {
	long long x, y;
	extGCD(a, m, x, y);
	return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}


void dfs(int now, int p) {
  if(now==0){
	ans *= ruijo[k - 1];
	ans %= INF;
    if(k-sz(g[now])-1>=0){
     ans *= modinv(ruijo[k - sz(g[now])-1], INF);
    }else ans=0;
    ans%=INF;
  }else if(sz(g[now])>1){
    if(k-2>=0){
     ans*=ruijo[k-2];
    }else ans=0;
    ans%=INF;
    if(k-sz(g[now])-1>=0){
     ans*=modinv(ruijo[k-sz(g[now])-1],INF);
    }else ans=0;
    ans%=INF;
  }
    rep(i,sz(g[now])){
      if(g[now][i]==p) continue;
      dfs(g[now][i],now);
    }
}

int main() {
	int n;
	cin >> n >> k;
	g.resize(n);
	rep(i, n - 1) {
		int ai, bi;
		cin >> ai >> bi;
		ai--; bi--;
		g[ai].push_back(bi);
		g[bi].push_back(ai);
	}
	ruijo.resize(k+1);
	ruijo[0] = (ll)1;
	rep(i, k)ruijo[i + 1] = ruijo[i] * ((ll)i + 1) % INF;
    ans=k;
	dfs(0, -1);
	cout << ans << endl;
}


Measured memory_bytes: 9216
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        
        int min = 2000000000;
        for (int i = 0; i < n - (k - 1); i++) {
            int left = x[i];
            int right = x[i + k - 1];
            
            int length = Math.abs(left - right);
            int l = Math.abs(left);
            int r = Math.abs(right);
            if (l < r) {
                length += l;
            } else {
                length += r;
            }
            
            min = Math.min(min, length);
        }
        
        System.out.println(min);
    }
}

Measured memory_bytes: 51036
n = int(input())

t, h = 0, 0

for i in range(n):
    s1, s2 = input().split()
    if s1 > s2:
        t += 3
    elif s1 < s2:
        h += 3
    else:
        t += 1
        h += 1

print(t, h)

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

int main(){
	int r, g, b, n, x, y;
	int c = 0;
	cin >> r >> g >> b >> n;
	for (int i = 0; i <= n / r; i++){
		x = n - (r * i);
		for (int j = 0; j <= x / g; j++){
			y = x - (g * j);
			if (y % b == 0) c++;
		}
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int A,B,T;

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

    int ans=(int)((T+0.5)/A)*B;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LOCAL 1
typedef long long ll;
const int N = 1e5+100;
int fa[N];

int find(int x){
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int main(){
	#if LOCAL
//	freopen("E:\\in.txt","r", stdin);
	#endif
	int n, m;
	cin >> n >> m;
	for(int i = 0; i <= n; i++){
		fa[i] = i;
	}
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		int xr = find(x), yr = find(y);
		if(xr > yr) swap(xr, yr);
		fa[xr] = yr;
	}
	int res = 0;

	for(int i = 1; i <= n; i++){
		if(fa[i] == i) res++;
	}
	cout << max(res-1, 0) << endl;
}

Measured memory_bytes: 4024
N = int(input())
A = [int(n) for n in input().split()]

D = dict()
ans = 0
for i, a in enumerate(A):
    val = i - a
    if val in D.keys():
        ans += D[val]
        
    val = i + a
    if val not in D.keys():
        D[val] = 0
    D[val] += 1
    
print(ans)


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

int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int a1=a-b;
	if(a1>c){
		printf("0\n");
	}
	else{
		printf("%d\n",c-a1);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yay!\n":":(\n" );
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+9, LINF = 1e18;


int main()
{
    int a,b;
    cin>>a>>b;
    yn(a<9&&b<9);
    
    return 0;
}


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

#define int long long
 
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
  void update(int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};
  
signed main(){
  int n, q, a, b;
  cin >> n >> q >> a >> b;
  a--; b--;
  
  SegmentTree<int, int>::F f=[](int a,int b){return min(a,b);};
  SegmentTree<int, int>::G g=[](int a,int b){return a+b;};
  const int INF = 1e15;
  SegmentTree<int, int> sl(n,f,g,g,INF,0);
  SegmentTree<int, int> sr(n,f,g,g,INF,0);

  sl.update(a, -a);
  sr.update(a, +a);

  for ( int i = 0; i < q; i++ ) {
    int x;
    cin >> x;
    x--;
    int mi = min(sl.query(0, x+1)+x, sr.query(x, n)-x);
    sl.update(0, n, abs(b-x));
    sr.update(0, n, abs(b-x));
    sl.update(b, mi-b);
    sr.update(b, mi+b);
    b = x;
  }

  int ans = sl.query(0, 1);
  for ( int i = 1; i < n; i++ ) {
    ans = min(ans, sl.query(i, i+1)+i);  
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 18688
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int n;
ll a=0,b=0;
vector<ll> v;
bool used[10]={0};

void cal(int t=0,ll d=0){
    if(t==n){
        v.push_back(d);
    }
    for(ll i=1;i<=n;i++){
        if(!used[i]){
            used[i]=true;
            cal(t+1,d*10+i);
            used[i]=false;
        }
    }
}

int main(){
    
    cin >> n;
    rep(i,n){
        int t;cin>>t;
        a = a*10+t;
    }
    rep(i,n){
        int t;cin>>t;
        b = b*10+t;
    }
    
    cal();
    int a_n,b_n;
    rep(i,v.size()){
        if(v[i]==a)a_n=i;
        if(v[i]==b)b_n=i;
    }
    
    cout << abs(a_n-b_n)<<endl;
    
    return 0;
}


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

int letters[26];

int main(void)
{
	int H, W;
	cin >> H >> W;

	for (int i = 0; i < 26; i++) letters[i] = 0;

	for (int i = 0; i < H; i++) {
		string S;
		cin >> S;
		for (int j = 0; j < W; j++) {
			unsigned int pos = (char)S[j]-'a';
			letters[pos]++;
		}
	}

	bool odd = false;
	int cnt2 = 0;
	int cnt4 = 0;
	for (int i = 0; i < 26; i++) {
		int cnt = letters[i];
		if (cnt==0) continue;

		cnt4 += cnt/4;
		cnt -= cnt/4*4;

		cnt2 += cnt/2;
		cnt -= cnt/2*2;

		if (cnt%2==1) {
			if (odd) {
				cout << "No" << endl; return 0;
			} else {
				odd = true;
				cnt--;
			}
		}
	}
	
	int oddcnt = 0;
	if (H%2==1) oddcnt++;
	if (W%2==1) oddcnt++;

	int use2, use4;
	if (oddcnt==2) {
		if (!odd) {cout << "No" << endl; return 0;}
		use2 = H/2+W/2;
		use4 = (H*W-1-use2*2)/4;
	}
	if (oddcnt==1) {
		int evenval, oddval;
		if (H%2==1) {oddval=H; evenval=W;}
		else        {oddval=W; evenval=H;}
		use2 = evenval/2;
		use4 = (H*W-use2*2)/4;
	}
	if (oddcnt==0) {
		use2 = 0;
		use4 = (H*W)/4;
	}
	use2 -= cnt2;
	if (use2>0) cnt4 -= use2/2;
	if (use4==cnt4) cout << "Yes" << endl;
	else            cout << "No" << endl;

	return 0;
}


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

void dump(vector<int> A)
{
    vector<int>::size_type i;
    for (i = 0; i < A.size(); i++)
    {
        cout << A[i];
        if (i != A.size() - 1)
        {
            cout << " ";
        }
    }
    cout << endl;
}

int main()
{
    int n, q, query, x, t;
    cin >> n >> q;
    vector<vector<int>> A(n);
    for (int i = 0; i < q; ++i)
    {
        cin >> query;
        switch (query)
        {
        case 0:
            cin >> t >> x;
            A[t].push_back(x);
            break;
        case 1:
            cin >> t;
            dump(A[t]);
            break;
        case 2:
            cin >> t;
            A[t].clear();
            break;
        }
    }
}


Measured memory_bytes: 6908