akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

constexpr ll M = 1e9 + 7;
constexpr int MAX_K = 41;

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

struct LCM {
    using type = ll;
    static type id() {
        return 1;
    }
    static type op(type const& l, type const& r) {
        return lcm(l, r);
    }
};

template<typename Monoid>
class segment_tree {
    using T = typename Monoid::type;

public:
    segment_tree(std::vector<T> const& init)
        : sz(init.size()),
          n(expand(init.size()))
    {
        dat.assign(n*2, Monoid::id());
        std::copy(begin(init), end(init), begin(dat) + n);
        for(int i = n - 1; i >= 0; --i) {
            dat[i] = Monoid::op(dat[i * 2], dat[i * 2 + 1]);
        }
    }

    segment_tree(int const n, T const& init = Monoid::id())
        : segment_tree(std::vector<T>(n, init))
    {}

    void update(int p, T val) {
        assert(0 <= p && p < sz);
        dat[p += n] = val;
        while(p /= 2) {
            dat[p] = Monoid::op(dat[p * 2], dat[p * 2 + 1]);
        }
    }

    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= sz);
        l += n;
        r += n;
        T res1 = Monoid::id(),
          res2 = Monoid::id();
        while(l != r) {
            if(l & 1) {
                res1 = Monoid::op(res1, dat[l++]);
            }
            if(r & 1) {
                res2 = Monoid::op(dat[--r], res2);
            }
            l /= 2;
            r /= 2;
        }
        return Monoid::op(res1, res2);
    }

    int size() const {
        return sz;
    }

private:
    int expand(int n) const {
        assert(n >= 1);
        return n == 1 ? n : expand((n + 1) / 2) * 2;
    }

private:
    const int sz;
    const int n;
    std::vector<T> dat;
};


int main() {
    int N, Q;
    cin >> N >> Q;
    vector<ll> p(N);
    for(int i = 0; i < N; ++i) {
        cin >> p[i];
    }

    vector<ll> cycle(N);
    vector<vector<ll>> sum(MAX_K, vector<ll>(N + 1));
    for(int i = 0; i < N; ++i) {
        ll s = p[i];
        ll now = p[i];
        int k = 1;
        for(k = 1; k < MAX_K; ++k) {
            if(now != i + 1) {
                now = p[now - 1];
                s = (s + now) % M;
            } else {
                break;
            }
        }
        cycle[i] = k;
        sum[k][i + 1] = s;
        for(int k = 0; k < MAX_K; ++k) {
            sum[k][i + 1] = (sum[k][i] + sum[k][i + 1]) % M;
        }
    }
    segment_tree<LCM> lcm_seg(cycle);
    while(Q--) {
        int l, r;
        cin >> l >> r;
        l--;
        ll L = lcm_seg.query(l, r);
        ll res = 0;
        for(int k = 1; k < MAX_K; ++k) {
            if(L % k == 0) {
                (res += ((L / k) % M) * (sum[k][r] - sum[k][l] + M)) %= M;
            }
        }
        cout << res << endl;
    }
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll lcm(ll x, ll y){
    // cout<<x<<" "<<y<<endl;
    if (x>y)
        swap(x, y);
    if (x==0)
        return y;
    return lcm(y%x, x);
}
signed main() {
    ll N;
    cin>>N;
    vector<ll> v(N);
    rep(i,0,N)
        cin>>v[i];

    ll ans = v[0];
    rep(i,1,N){
        ans = lcm(ans, v[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<functional>
#define For(i, N) for (i = 0; i < N; i++)
#define rep(N) for (int i = 0; i < N; i++)

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using pib = pair<int, bool>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

int main() {
	int N, H;
	int a, b;
	int ans = 0;
	vector<pib> v;
	cin >> N >> H;
	rep(N) {
		cin >> a >> b;
		v.push_back({ a,true });
		v.push_back({ b,false });
	}
	sort(v.begin(), v.end(), greater<pib>());
	auto itr = v.begin();
	while (H > 0) {
		if ((*itr).second) {
			ans += H % (*itr).first == 0 ? H / (*itr).first : H / (*itr).first + 1;
			break;
		}
		H -= (*itr).first;
		itr++;
		ans++;
	}
	say(ans);
}

Measured memory_bytes: 2420
f :: (Int,Int) -> String
f (a,b) = show(a) ++ "x" ++ show(b) ++ "=" ++ show(a*b)

main = do
  let i = [ (x,y) | x <- [1..9], y <- [1..9] ]
      j = map f i
  mapM_ putStrLn j

Measured memory_bytes: 3576
def otoshidama(n, y):
    minus = 0
    tenthousand = range(n + 1)
    for i in tenthousand:
        for p in range(n + 1 - minus):
            o = n-(i+p)
            if (i*10000+p*5000+o*1000) == y:
                return str(i)+' '+str(p)+' '+str(o)
        minus += 1
    return '-1 -1 -1'
N, Y = map(int, input().split())
print(otoshidama(N, Y))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
vector<int> g[N];
int n;
int vis[N];
int dp[N];
int dfs(int i)
{
    if(vis[i]) return 0;
    vis[i] = 1;
    rep(j,0,sz(g[i])){
        if(vis[g[i][j]]){
            dp[i] = max(dp[i],dp[g[i][j]]+1);
        }
        else{
            dfs(g[i][j]);
            dp[i] = max(dp[i],dp[g[i][j]]+1);
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int m;
        cin>>n>>m;
        rep(i,0,m){
            int a,b;
            cin>>a>>b;
            g[a].pb(b);
        }
        rep(i,1,n+1){
            if(!vis[i]) {
                dp[i] = 0;
                dfs(i);
            }
        }
        // rep(i,1,n+1) cout<<dp[i]<<" ";
        // cout<<endl;
        cout<<*max_element(dp+1,dp+n+1)-*min_element(dp+1,dp+n+1);
    }   
}     

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

using namespace std;

int merge(vector<int>& v, int left, int mid, int right)
{
    vector<int> l(mid - left + 1);
    vector<int> r(right - mid);

    for (int i = 0; i < l.size(); ++i)
        l[i] = v[left+i];
    for (int i = 0; i < r.size(); ++i)
        r[i] = v[mid+1+i];

    int compare_count = 0;
    int idx = 0;
    int l_idx = 0;
    int r_idx = 0;
    while (l_idx < l.size() && r_idx < r.size()) {
        if (l[l_idx] <= r[r_idx]) {
            v[left+idx] = l[l_idx];
            ++l_idx;
        } else {
            v[left+idx] = r[r_idx];
            ++r_idx;
        }
        ++idx;
        ++compare_count;
    }
    while (l_idx < l.size()) {
        v[left+idx] = l[l_idx];
        ++l_idx;
        ++idx;
        ++compare_count;
    }
    while (r_idx < r.size()) {
        v[left+idx] = r[r_idx];
        ++r_idx;
        ++idx;
        ++compare_count;
    }
    return compare_count;
}

int merge_sort(vector<int>& v, int left, int right)
{
    int compare_count = 0;
    if (left < right) {
        int mid = (left + right) / 2;
        compare_count += merge_sort(v, left, mid);
        compare_count += merge_sort(v, mid+1, right);
        compare_count += merge(v, left, mid, right);
    }
    return compare_count;
}

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

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

    int compare_count = merge_sort(s, 0, n-1);

    cout << s[0];
    for (int i = 1; i < n; ++i)
        cout << ' ' << s[i];
    cout << '\n';
    cout << compare_count << '\n';
}



Measured memory_bytes: 6888
#include <iostream>
using namespace std;
int f(int a,int b,int c){
    
}

int main() {
int m,d;
cin>>m>>d;
 int count=0;
 for(int i=22;i<=d;i++){
     int a, b;
     a = i%10;
     b= i/10;
     
     if(a>=2 and b>=2){
         if(a*b<=m) count++;
     }
}
cout<<count<<endl;
	return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int N,D,X;
    cin >> N >> D >> X;

    vector<int> A(N);
    rep(i,N) cin >> A[i];

    rep(i,N)
    {
        ll time = 1;
        X++;

        while( time+A[i] <= D )
        {
            time += A[i];
            X++;
        }
        //cout << X << endl;
    }
    cout << X << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  for (int a, b; cin >> a >> b;) {
    if (a == 0 && b == 0) break;
    if (a > b) swap(a, b);
    cout << a << " " << b << endl;
  }
  return 0;
}


Measured memory_bytes: 3092
s = input()
len_s  = len(s)
t = input()
len_t = len(t)
q = []
for i in range(len_s - len_t + 1):
    s2 = s[i:i+len_t]
    n = 0
    for j in range(len_t):
        if t[j] != s2[j]:
            n += 1
    q.append(n)
print(min(q))

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

int count(int n){
  int res=0;
  while(n%2==0){
    n /= 2;
    res++;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  int ans=2147483647;
  rep(i,n){
    ans = min(ans,count(a[i]));
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n;
    float m,sum=0,range;
    cin>>n>>m;
    float arr[n],c=0;

    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }

    sort(arr,arr+n);
    range = (sum)/(4*m);//float naw if wrong

    for(int i=0;i<n;i++){
        if(arr[i]>=range)c++;
    }

    if(c>=m)cout<<"Yes";
    else cout<<"No";
    return 0;

}


Measured memory_bytes: 256
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,a[200001],b[200001],now;
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	for(int i=0;i<=30;++i)
	{
		now=0;
		for(int j=1;j<=n;++j)
		{
			now^=a[j]&(1<<i);
		}
		for(int j=1;j<=n;++j)
		{
			b[j]|=now^(a[j]&(1<<i));
		}
	}
	for(int i=1;i<=n;++i)
	{
		cout<<b[i]<<' ';
	}
	return 0;
}


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

import sys
import os
import math
import re

for s in sys.stdin:
    equation = s.strip()
    equation = equation.replace('=', '==')
    found = False

    for i in range(10):
        candidate = equation.replace('X', str(i))

        a = candidate.split('+')[0]
        b_c = candidate.split('+')[1]
        b = b_c.split('==')[0]
        c = b_c.split('==')[1]

        #print(a, b, c)

        # zero check
        if (a[0] == '0' and len(a) != 1) or (b[0] == '0' and len(b) != 1) or (c[0] == '0' and len(c) != 1):
            pass
        else:
            if eval(candidate):
                print(i)
                found = True
    if not found:
        print('NA')

Measured memory_bytes: 7828
#include<stdio.h>

int computeRPN( int *stack, int n, int opt )
{
	int res;

	res=0;
	if( '+'==opt ) {
		res=stack[n-1]+stack[n];
	} else if( '-'==opt ) {
		res=stack[n-1]-stack[n];
	} else if( '*'==opt ) {
		res=stack[n-1]*stack[n];
	} else if( '/'==opt ) {
		res=stack[n-1]/stack[n];	
	}
	
	return res;
}

int main( void ) 
{
	char inputs[1000001];
	int stack[201];
	int i,j;
	int res,num;

	fgets( inputs, 1000001, stdin );
	j=num=0;
	for( i=0; '\0' != inputs[i]; i++ ) {
		res=inputs[i];
		if( '0'<=res && res<='9' ) {		
			num*=10;
			num+=inputs[i]-'0';
		} else if( '*'<=res && res<='/' ) {
			num=computeRPN( stack, --j, res );
			j--;
		} else {
			stack[j++]=num;
			num=0;
		}
	}
	
	printf( "%d\n", stack[j-1] );
	
	return 0;
}

Measured memory_bytes: 524
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+5, mod = 1e9+7;
int N, dp[maxn];
vector<int> edge[maxn];

long long dfs(int node,int pre){
    if(dp[node])return dp[node];
    if(edge[node].size() == 0)return  dp[node]=2;
    
    long long son_ans = 1, gson_ans = 1;
    for(auto son_node: edge[node]){
        if(son_node!=pre){
            son_ans *= (dfs(son_node, node))%mod;
            son_ans %= mod;
            for(auto gson_node: edge[son_node]){
                if(gson_node!= node){
                    gson_ans *= (dfs(gson_node, son_node))%mod;
                    gson_ans %= mod;
                }
            }
        }
    }
    

    long long ans = (son_ans + gson_ans)%mod;
    return dp[node] = ans;
    
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>N;
    int x,y;
    for(int i = 0; i< N-1; i++){
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }


    cout<<dfs(1, -1)<<endl;
    
    
    return 0;
}



Measured memory_bytes: 15872
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double PI = 3.14159;

int n, m;
string ord[20000];
string sou[20000];
string des[20000];

bool match(string s1, string s2){
	for(int i = 0; i < (int)s1.size(); i++){
		if(s2[i] != '?' && s2[i] != s1[i]) return false;
	}
	return true;
}

bool ok(string s, string d){
	bool res = false;
	for(int i = 0; i < n; i++){
		if(match(s, sou[i]) && match(d, des[i])){
			if(ord[i] == "deny"){
				res = false;
			}else{
				res = true;
			}
		}
	}
	return res;
}

int main(){
	while(cin >> n >> m && (n || m)){
		for(int i = 0; i < n; i++){
			cin >> ord[i] >> sou[i] >> des[i];
		}
		vector<string> sources;
		vector<string> des;
		vector<string> messages;
		for(int j = 0; j < m; j++){
			string so, de, me;
			cin >> so >> de >> me;
			if(ok(so, de)){
				sources.push_back(so);
				des.push_back(de);
				messages.push_back(me);
			}
		}
		cout << des.size() << endl;
		for(int i = 0; i < (int)des.size(); i++){
			cout << sources[i] << " " << des[i] << " " << messages[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1304
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
 
const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		std::set<std::string> st;
		std::string str;
		std::cin >> str;
		for(int j = 0; j < str.length(); j++){
			std::string s[2];
			s[0] = str.substr(0, j);
			s[1] = str.substr(j);
			for(int k = 0; k < 4; k++){
				for(int l = 0; l < 2; l++){
					if(k & (1 << l)){
						std::reverse(s[l].begin(), s[l].end());
					}
				}
				for(int l = 0; l < 2; l++){
					//std::cout << j << " " << k << " " << l << " " <<  s[l] + s[(l+1)%2] << std::endl;
					/*
					if(st.count(s[l] + s[(l+1)%2]) == 0){
						printf("  Unique!\n");
					}
					//*/
					st.insert(s[l] + s[(l+1)%2]);
				}
				for(int l = 0; l < 2; l++){
					if(k & (1 << l)){
						std::reverse(s[l].begin(), s[l].end());
					}
				}
			}
		}
		printf("%ld\n", st.size());
	}
	return 0;
}



Measured memory_bytes: 3368
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#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 FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int a, b;
string c1, c2;
/**********************************************/

int main(){
    cin >> c1 >> c2;

    reverse(all(c1));
    if(c1 == c2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
from sys import exit, stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
num = [0]*K
for i in range(1, N+1):
    num[i%K]+=1
res = 0
for a in range(K):
    b = (K-a) % K
    c = (K-a) % K
    if ((b+c) % K != 0):
        continue
    res += num[a] * num[b] * num[c]
print(res)

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

#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())


int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int r;
	cin >> r;
	cout << r*r;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
using namespace std;
long long gcd(long long a,long long b){
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}
int main(){
  long long a,b;
  cin>>a>>b;
  long long c=gcd(a,b);
  long long e=2;
  set<long long> d;
  while(c>=e*e){
    if(c%e==0){
      d.insert(e);
      c=c/e;
    }else{
      e++;
    }
  }
  if(c!=1)
  d.insert(c);
  cout<<d.size()+1<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for x in range(N)]
ans = 0
for i in range(N):
    if i+1 < N and A[i] > 0 and A[i+1] > 0:
        if A[i] < A[i+1]:
            a = min(A[i], A[i+1])
            ans += a
            A[i] -= a
            A[i+1] -= a
        else:
            if A[i] > 1:
                a = A[i]//2
                A[i] -= a*2
                ans += a
            a = min(A[i], A[i+1])
            ans += a
            A[i] -= a
            A[i+1] -= a
    if A[i] > 1:
        a = A[i]//2
        A[i] -= a*2
        ans += a
    if i+1 < N and A[i+1] > 1:
        a = A[i+1]//2
        A[i+1] -= a*2
        ans += a
print(ans)

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


void solve(long long N){
  long long acc = N;
  string a;

  while(acc > 0) {
    acc -= 1;
    a += 'a'+acc%26;
    acc /= 26;
  }
  reverse(a.begin(), a.end());
  cout << a << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
    solve(N);
    return 0;
}


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

#define int long long
typedef long long ll;
using namespace std;
const int N = 2e5 + 10;
int n, k;
ll mod = 1e9 + 7;

vector<int> g[N];

int ans = 1;

ll f[N];

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

ll qpow(ll a, ll n) {
    ll ans = 1;
    for (; n; n >>= 1, a = a * a % mod) if (n & 1) ans = ans * a % mod;
    return ans;
}

ll C(int n, int m) {
    if (n < m)return 0;
    return f[n] * qpow(f[m] * f[n - m] % mod, mod - 2) % mod;
}

void dfs(int u, int from, int dep) {
    int t = 0;
    for (auto v:g[u]) {
        if (v == from)continue;
        t++;
    }
    if (dep >= 1)ans = ans * C(k - 2, t) % mod * f[t];
    if (dep == 0)ans = ans * C(k - 1, t) % mod * f[t];
    ans %= mod;
    for (auto v:g[u]) {
        if (v == from)continue;
        dfs(v, u, dep + 1);
    }
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0);
    init();
    cin >> n >> k;
    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    ans = k;
    dfs(1, -1, 0);
    cout << ans << endl;
}

Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    sort(ALL(a));
    int sum=0;
    REP(i,n-1)sum+=a[i];
    if(sum>a[n-1])OUT("Yes");
    else OUT("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}

long long qpow(long long a, long long b, int MOD) {
    if (b == 0) return 1;
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
const int MOD = 1e9 + 7;
const int maxn = 2e6;
int fac[maxn + 5];
int invfac[maxn + 5];
void init() {
    fac[0] = 1;
    for (int i = 1; i <= maxn; i++) fac[i] = 1LL * fac[i - 1] * i % MOD;
    invfac[maxn] = (int)(qpow(fac[maxn], MOD - 2, MOD));
    for (int i = maxn - 1; i >= 0; i--) invfac[i] = 1LL * invfac[i + 1] * (i + 1) % MOD;
}
int C(int n, int k) {
    assert(0 <= k && n >= k);
    int tmp = (int)(1LL * invfac[k] * invfac[n - k] % MOD);
    return (int)(1LL * fac[n] * tmp % MOD);
}

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

    init();
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    LL ans = C(r1 + c1, r1);
    for (int i = r1 + 1; i <= r2; i++) ans = (ans + C(c2 + i, c2)) % MOD;
    for (int j = c1 + 1; j <= c2; j++) ans = (ans + C(r2 + j, j)) % MOD;
    ans = ((ans % MOD) + MOD) % MOD;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 15872
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define track  1;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

const int N = 1e5+2;

int n;

int a[N][4];

int dp[N][4];

int sol(int day,int habbit)
{
	d(day,habbit);
	if(day==n+1)
	{
		return 0;
	}
	if(dp[day][habbit]!=-1)
	{
		return dp[day][habbit];
	}
	int ans=-1;
	for(int h=1;h<=3;h++)
	{
		if(h!=habbit)
		{
			ans= max(ans,(a[day][h] + sol(day+1,h)));
		}
	}
	return dp[day][habbit]=ans;
}

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j,cnt=0;
	bool flag=0;

	cin>>n;

	d(n);
	
	for(i=1;i<=n;i++)
	{
		cin>>a[i][1]>>a[i][2]>>a[i][3];
	}

	memset(dp,INT_MAX,sizeof(dp));

	int ans = sol(1,0);

	// for(i=1;i<=n;i++)
	// {
	// 	for(j=1;j<=3;j++)
	// 	{
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<ans<<endl;




	

}

Measured memory_bytes: 14336
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n){ int ret = 1; for(int i = 1; i < n + 1; ++i) { ret = ret * i; } return ret; }

/* 最大公約数 */
template <typename T>T gcd(T x, T y){ return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>T lcm_n(vector<T> &numbers) { T l; l = numbers[0]; for(int i = 1; i < numbers.size(); ++i) { l = lcm(l, numbers[i]); } return l; }

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

/*
 * グラフ
 */
class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;
 
    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }
 
    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }
 
        int res = 0;
 
        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }
 
        return dp[v] = res;
    }
};

#define layer_name(n) l ## n

int main(){
  mpint a, b, c;
  cin >> a >> b >> c;

  if(a>=c || b >= c){
    cout << "No" << endl;
    return 0;
  }

  if(4*a*b < (a*a + b*b + c*c + 2*a*b -2*a*c -2*b*c)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }



  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	int a = in.nextInt();
	int b = in.nextInt();

        
	System.out.printf("%d %d %.5f\n",a/b,a%b,(double)a/b);
    }
}



Measured memory_bytes: 26496
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef unsigned long ulong;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> l(n,0);
	rep(i, n) {
		cin >> l[i];
	}

	int c = 1;
	int d = 0;
	rep(i, n) {
		d = d + l[i];
		if (d > x) {
			break;
		}
		else {
			c++;
		}
	}
	cout << c;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

struct Line {
    ll m, b;
};

struct HullMono : deque<Line> { // min hull
    // increasing gradient
    void add(ll m, ll b) {
        //cout << "ADD " << m << " " << b << endl;
        int s;
        while ((s = size()) > 1) {
            auto x = at(0);
            auto y = at(1);
            if ((x.b - b) * (m - y.m) > (y.b - b) * (m - x.m))
                pop_front();
            else break;
        }
        push_front({m, b});
    }

    // decreasing query
    ll eval(ll x) {
        int s;
        while ((s = size()) > 1) {
            auto y = at(s-2);
            auto z = at(s-1);
            if (y.m * x + y.b <= z.m * x + z.b)
                pop_back();
            else break;
        }
        return back().m * x + back().b;
    }

    void dbg() {
        for (Line l : *this) {
            cout << l.m << " " << l.b << endl;
        }
    }
};

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; ll c; cin >> n >> c;
    int h[n];
    FOR(i,0,n-1){
        cin >> h[i];
    }

    ll dp[n];
    dp[n-1] = 0;
    HullMono ch;
    ch.add(-2*h[n-1], dp[n-1] + (ll)h[n-1]*h[n-1]);

    RFOR(i, n-2, 0){
        //dp[i] = min(dp[j] + (h[j] - h[i]) ** 2 + C);
        //dp[i] = min(dp[j] + h[j]*h[j] - 2*h[j]*h[i]) + h[i]*h[i] + C;
        dp[i] = ch.eval(h[i]) + (ll)h[i]*h[i] + c;
        //cout << i << " :: " << ch.eval(h[i]) << " " << h[i] << " :: " << dp[i] << endl;
        //ch.dbg();
        ch.add(-2*h[i], dp[i] + (ll)h[i]*h[i]);
    }

    cout << dp[0] << '\n';
}



Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  const int MOD = 1000000007;
  int N;
  cin >> N;

  vector<int> a(N);
  rep(i, N) {
    cin >> a[i];
  }

  vector<int> c(N);
  rep(i, N) {
    c[a[i]]++;
  }

  if (N == 1) {cout << 1 << endl; return 0;}

  if (N % 2 == 0 && c[0] != 0) {cout << 0 << endl; return 0;}
  else if (N % 2 != 0 && c[0] >= 2) {cout << 0 << endl; return 0;}

  long long sum = 1;
  for(int i=1; i<=N/2; i++) {
    if (c[i] > 2) {cout << 0 << endl; return 0;}
    sum *= 2;
    sum %= MOD;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    str S;
    cin >> S;
    S[5] = ' ';
    S[13] = ' ';
    out(S);
}

int main() {
    fast_io;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int n, k;
	ll sum = 0,ans=0;
	cin >> n>>k;
	vector<ll> v(n),v0(n),a,b;
	rep(i, n) {
		cin >> v[i];
		v0[i] = max(v[i], (ll)0);
	}
	a.push_back(0);
	b.push_back(0);
	rep(i, n) {
		sum += v[i];
		a.push_back(sum);
	}
	sum = 0;
	rep(i, n) {
		sum += v0[i];
		b.push_back(sum);
	}
	rep(i, n - k + 1) {
		sum = 0;
		sum = max(a[i+k] - a[i], (ll)0) + b[i] - b[0] + b[n] - b[i + k];
		ans = max(sum, ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long

using namespace std;

const ll N = 3e5 + 5, M = 1e6 + 5;

int arr[N];

int main()
{
    int n, k, mn = 1e9;
    scanf("%d%d", &n, &k);
    for(int i = 0 ; i < n ; i++) scanf("%d", arr + i);
    sort(arr, arr + n);
    for(int i = k - 1 ; i < n ; i++) mn = min(mn, arr[i] - arr[i - k + 1]);
    printf("%d\n", mn);
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
#include <tuple>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<std::pair<int, int>> ab(N), cd(N);
  for (auto& p: ab) scanf("%d %d", &p.first, &p.second);
  for (auto& p: cd) scanf("%d %d", &p.first, &p.second);

  std::sort(ab.begin(), ab.end());
  std::sort(cd.begin(), cd.end());

  int res = 0;
  std::set<int> s;
  for (size_t i = 0, j = 0; i < N; ++i) {
    int c, d;
    std::tie(c, d) = cd[i];
    while (j < N && ab[j].first < c) s.insert(ab[j++].second);

    if (s.empty()) continue;

    auto it = s.upper_bound(d);
    if (it == s.begin()) continue;
    s.erase(--it);
    ++res;
  }
  printf("%d\n", res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) a = b;
  return a > b;
}
template<class T> inline bool chmax(T&a, T b) {
  if (a < b) a = b;
  return a < b;
}

signed main() {
  int N, L, R;
  cin >> N >> L >> R;
  while (N+L+R != 0) {
    vector<int> A(N);
    int ans = 0;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int x = L; x <= R; x++) {
      int exists = 0;
      for (int i = 0; i < N; i++) {
        if (x % A[i] == 0) {
          if ((i+1) % 2 == 1) {
            ans++;
          }
          exists = 1;
          break;
        }
      }
      if (exists == 0 && N % 2 == 0) ans++;
    }
    cout << ans << endl;
    cin >> N >> L >> R;
  }
}



Measured memory_bytes: 3096
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = Integer.parseInt(sc.next());
		String[] s = new String[n];
		long[] march = new long[5];
        for(int i=0;i<n;i++){
            s[i] = sc.next();
            if(s[i].charAt(0) == 'M') march[0]++;
            else if(s[i].charAt(0) == 'A') march[1]++;
            else if(s[i].charAt(0) == 'R') march[2]++;
            else if(s[i].charAt(0) == 'C') march[3]++;
            else if(s[i].charAt(0) == 'H') march[4]++;
            else continue;
        }
        long ans = 0;
        for(int i=0; i<3; i++) {
            for(int j=i+1; j<4; j++) {
                for(int k=j+1; k<5; k++) {
                    ans += march[i]*march[j]*march[k];
                }
            }
        }
        System.out.println(ans);
	}
}

Measured memory_bytes: 52632
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 3e5 + 10;
int a[maxn];
int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  n *= 3;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

void solve() {
  sort(a, a + n);
  long long res = 0;
  for (int i = n - 2, it = 0; it < n / 3; ++it, i -= 2) {
    res += a[i];
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1408
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N, K;
int D[2001];
int E[4001], ne[4001], he[2001];
void dfs(int v, int d) {
	D[v] = d;
	for (int to = he[v]; to; to = ne[to]) {
		if (D[E[to]] < 0) dfs(E[to], d + 1);
	}
}

int dfs2(int v, int prev, int d) {
	int ret = 1;
	for (int to = he[v]; to; to = ne[to]) {
		if (E[to] != prev && d < K / 2) ret += dfs2(E[to], v, d + 1);
	}
	return ret;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	N = getint();
	K = getint();
	int tmp = 1;
	int jisuu[2001] = {};
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[tmp] = b;
		ne[tmp] = he[a];
		he[a] = tmp++;
		E[tmp] = a;
		ne[tmp] = he[b];
		he[b] = tmp++;
		jisuu[a]++;
		jisuu[b]++;
	}

	if (K == 1) {
		printf("%d\n", N - 2);
		return 0;
	}

	rep1(j, N) D[j] = -1;
	dfs(1, 0);
	int saidai = 0;
	int doko, doko2;
	rep1(i, N) if (saidai < D[i]) {
		saidai = D[i];
		doko = i;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko, 0);
	saidai = 0;
	bool muri[2001] = {};
	rep1(i, N) {
		if (saidai < D[i]) {
			saidai = D[i];
			doko2 = i;
		}
		if (D[i] < K / 2) {
			muri[i] = 1;
		}
	}
	if (saidai <= K) {
		printf("0\n");
		return 0;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko2, 0);
	rep1(i, N) {
		if (D[i] < K / 2) muri[i] = 1;
		if (jisuu[i] == 1) muri[i] = 1;
	}

	if (K % 2 == 0) {
		int kotae = N;
		rep1(i, N) {
			if (!muri[i]) {
				int kazu = dfs2(i, -1, 0);
				kotae = min(kotae, N - kazu);
			}
		}
		printf("%d", kotae);
	}
	else {
		int kotae = N;
		rep1(k, N - 1) {
			int i = E[k * 2];
			int j = E[k * 2 - 1];
			if (!muri[i] && !muri[j]) {
				int kazu = dfs2(i, j, 0) + dfs2(j, i, 0);
				kotae = min(kotae, N - kazu);
			}
		}
		printf("%d", kotae);
	}

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int x, y, a, b, c; scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	std::vector<int> A(a), B(b), C(c);
	for(int i = 0; i < a; i++) scanf("%d", &A[i]); sort(begin(A), end(A), std::greater<>());
	for(int i = 0; i < b; i++) scanf("%d", &B[i]); sort(begin(B), end(B), std::greater<>());
	for(int i = 0; i < c; i++) scanf("%d", &C[i]); sort(begin(C), end(C), std::greater<>());
	
	std::priority_queue<int, std::vector<int>, std::greater<int>> X, Y;
	for(int i = 0; i < x; i++) X.push(A[i]);
	for(int i = 0; i < y; i++) Y.push(B[i]);

	for(int i = 0; i < c; i++) {
		int yuduki = X.top();
		int kizuna = Y.top();
		if(C[i] <= std::min(yuduki, kizuna)) continue;

		if(yuduki > kizuna) {
			Y.pop();
			Y.push(C[i]);
		} else {
			X.pop();
			X.push(C[i]);
		}
	}

	i64 ans = 0;
	while(!X.empty()) {
		ans += X.top();
		X.pop();
	}
	X.swap(Y);
	while(!X.empty()) {
		ans += X.top();
		X.pop();
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2552
N, M = map(int, input().split())
flag = [1] * (M+1)
flag[0] = 0
for i in range(N):
    k = list(map(int, input().split()))[1:]
    for j in range(1, M+1):
        if j not in k:
            flag[j] = 0
print(sum(flag))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;

int dp[3005][3005] = {0};

int main()
{
  string s,t;
  cin >> s >> t;
  REP(i,s.size()){
    REP(j,t.size()){
      if(s[i]==t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  string ans = "";
  int ss = s.size();
  int tt = t.size();
  while(ss>0 && tt>0){
    if(dp[ss][tt] == dp[ss-1][tt]) ss--;
    else if(dp[ss][tt] == dp[ss][tt-1]) tt--;
    else{
      ans = s[ss-1] + ans;
      ss--, tt--;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

int main(){
    string c;
    cin >> c;
    string ans;
    if(c=="a") ans = "b";
    else if(c=="b") ans = "c";    
    else if(c=="c") ans = "d";
    else if(c=="d") ans = "e";    
    else if(c=="e") ans = "f";
    else if(c=="f") ans = "g";    
    else if(c=="g") ans = "h";
    else if(c=="h") ans = "i";    
    else if(c=="i") ans = "j";
    else if(c=="j") ans = "k";    
    else if(c=="k") ans = "l";
    else if(c=="l") ans = "m";    
    else if(c=="m") ans = "n";
    else if(c=="n") ans = "o";    
    else if(c=="o") ans = "p";
    else if(c=="p") ans = "q";    
    else if(c=="q") ans = "r";
    else if(c=="r") ans = "s";    
    else if(c=="s") ans = "t";
    else if(c=="t") ans = "u";    
    else if(c=="u") ans = "v";
    else if(c=="v") ans = "w";    
    else if(c=="w") ans = "x";
    else if(c=="x") ans = "y";    
    else if(c=="y") ans = "z";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    ll ga,sa,ba;
    cin>>ga>>sa>>ba;
    ll gb,sb,bb;
    cin>>gb>>sb>>bb;
    ll profit=0;
    {
        ll dp[n+1]={0};
        vector <pair<ll,ll>> v;
        v.pb(mp(ga,gb-ga));
        v.pb(mp(sa,sb-sa));
        v.pb(mp(ba,bb-ba));
        for(int i=1;i<=n;i++)
        {
            dp[i]=dp[i-1];
            for(auto it:v)
            {
                if(it.first>i)
                    continue;
                dp[i]=max(dp[i],dp[i-it.first]+it.second);
            }
        }
        profit=dp[n];
    }
    n+=profit;
    profit=0;
    {
        ll dp[n+1]={0};
        vector <pair<ll,ll>> v;
        v.pb(mp(gb,ga-gb));
        v.pb(mp(sb,sa-sb));
        v.pb(mp(bb,ba-bb));
        for(int i=1;i<=n;i++)
        {
            dp[i]=dp[i-1];
            for(auto it:v)
            {
                if(it.first>i)
                    continue;
                dp[i]=max(dp[i],dp[i-it.first]+it.second);
            }
        }
        profit=dp[n];
    }
    n+=profit;
    cout<<n<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 210676
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		  int A = sc.nextInt();
	    int B = sc.nextInt();
      int X = sc.nextInt();


      if(X <= (A + B) && X >= A){
      	System.out.println("YES");
      }else {
        System.out.println("NO");
      }
  }
}


Measured memory_bytes: 21844