akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=1000010;
int a[maxn];
int war[maxn];
int main()
{
	int ans=0;
	int island=0;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<maxn;i++)
		war[i]=2*maxn;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		war[x]=min(war[x],y);
	}
	for(int i=1;i<n;i++)
	{
		if(war[i]==2*maxn)
			continue;
		if(island<i){
			ans++;
			island=war[i]-1;
		}
		else if(war[i]-1<island){
			island=war[i]-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    int N;cin>>N;
    vector<int> H(N);
    for (int i = 0; i < N; ++i) {
        cin>>H[i];
    }
    reverse(H.begin(),H.end());
    for (int i = 1; i < N; ++i) {
        if(H[i]<=H[i-1]) continue;
        if(H[i]-H[i-1]==1) H[i]--;
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	vi v(3);
	rep(i, 3) cin >> v[i];
	sort(all(v));
	if (v[0] + v[1] == v[2]) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int isprime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0)  return 0;
    }
    return 1;
}

int main(){
    int n, p1 = 0,i;
    while (1) {
        scanf("%d", &n);
        if(n==0) break;
        for(i = n; i >=2; i--){
            if(isprime(i - 2)&& isprime(i)/*&&p1<i*/){
                printf("%d %d\n", i - 2, i);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1736
n=input()
a=map(int,raw_input().split())
b=map(int,raw_input().split())
tot=sum(a)
for i in range(n):
    a[i],b[i]=a[i]-min(a[i],b[i]),b[i]-min(a[i],b[i])
    if b[i]>0:
        a[i+1]-=min(a[i+1],b[i])
print tot-sum(a)


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

const int INF = 1<<25;

int c[] = {10, 50, 100, 500};

int main() {
	int n, a = 0;
	while(cin >> n && n){
		if(a != 0)
			cout << endl;
		
		int s[4], csum = 0;
		for(int i = 0; i < 4; ++i){
			cin >> s[i];
			csum += s[i];
		}
			
		int ans = INF;
		map<int, int> ans_m;
		for(int i = 0; i <= s[3]; ++i){
			int sum = 0;
			for(int j = 0; j <= s[2]; ++j){
				for(int k = 0; k <= s[1]; ++k){
					for(int l = 0; l <= s[0]; ++l){
						int cnt[4] = {0}; // 0、 10yen, 1、 50yen ...
						sum = l * 10 + k * 50 + j * 100 + i * 500;
						if(sum >= n){
							int cs = csum - i - j - k - l;
							int msum = sum - n;
							while(msum >= 500){
								msum -= 500;
								cnt[3]++;
							}
							while(msum >= 100){
								msum -= 100;
								cnt[2]++;
							}
							while(msum >= 50){
								msum -= 50;
								cnt[1]++;
							}
							while(msum >= 10){
								msum -= 10;
								cnt[0]++;
							}
							
							int cnt_sum = cnt[3] + cnt[2] + cnt[1] + cnt[0];
							/*if(l == 8 && k == 19 && j == 13 && i == 0)
								cout << cnt_sum + cs << endl;*/
							if(ans > cnt_sum + cs){
								ans = cnt_sum + cs;
								ans_m[c[0]] = l - cnt[0];
								ans_m[c[1]] = k - cnt[1];
								ans_m[c[2]] = j - cnt[2];
								ans_m[c[3]] = i;
							}
						}
					}
				}
			}
		}
		for(int i = 0; i < 4; ++i){
			if(ans_m[c[i]] > 0)
				cout << c[i] << " " << ans_m[c[i]] << endl;
		}
		a++;
	}
	return 0;
}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 20011, inf = 1000111222;
const ll mod = 998244353;


ll powm(ll a, ll b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2 == 0) {
        return powm((a * a) % mod, b / 2);
    } else {
        return (a * powm(a, b - 1)) % mod;
    }
}

ll f[max_n];
ll rf[max_n];
ll p2[max_n];

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

    for (int i = 0; i < max_n; ++i) {
        rf[i] = powm(f[i], mod - 2);
    }
    p2[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        p2[i] = (p2[i - 1] * 2) % mod;
    }
}

ll c(ll n, ll k) {
    //cout << n << ' ' <<k << endl;
    if (k > n) return 0;
    //cout << (f[n] * rf[n - k]) % mod << endl;
    return ((f[n] * rf[n - k] % mod) * rf[k]) % mod;
}

int n, k;

ll numb(int sum) {
    if (sum % 2 == 1) {
        ll ans = 0;
        int csin = k;
        int cp = 0;
        for (int i = 1; i <= sum / 2; ++i) {
            if (i <= k && sum - i <= k) {
                csin -= 2;
                ++cp;
            }
        }
        int take = 0;
        if (csin == 0) {
            take = 1;
        }
        for (; take <= min(n, cp); ++take) {
            ll cur = (c(cp, take) * c(n - take + take + csin - 1, take + csin - 1)) % mod;
            cur = (cur * p2[take]) % mod;
            ans += cur;
            ans %= mod;
        }
        return ans;
    } else {
        ll ans = 0;
        int csin = k - 1;
        int cp = 0;
        for (int i = 1; i < sum / 2; ++i) {
            if (i <= k && sum - i <= k) {
                csin -= 2;
                ++cp;
            }
        }
        int take = 0;
        if (csin == 0) {
            take = 1;
        }
        for (; take <= min(n, cp); ++take) {
            ll cur = (c(cp, take) * c(n - take + take + csin - 1, take + csin - 1)) % mod;
            cur = (cur * p2[take]) % mod;
            ans += cur;
            ans %= mod;
        }
        --n;
        take = 0;
        if (csin == 0) {
            take = 1;
        }
        for (; take <= min(n, cp); ++take) {
            ll cur = (c(cp, take) * c(n - take + take + csin - 1, take + csin - 1)) % mod;
            cur = (cur * p2[take]) % mod;
            ans += cur;
            ans %= mod;
        }
        ++n;
        return ans;
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    precalc();
    cin >> k >> n;
    for (int cnt = 2; cnt <= 2 * k; ++cnt) {
        cout << numb(cnt) << "\n";
    }

    return 0;
}




Measured memory_bytes: 768
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
int A=scan.nextInt();
        int B =scan.nextInt();
        int M=1;
        for(int i=0;i<=A&&M==1;i++){if(i*2+(A-i)*4==B){M=0;}}
        if(M==0){System.out.println("Yes");}
        if(M==1){System.out.println("No");}

    }
    }




Measured memory_bytes: 35808
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = 0
    for c in N:
        ans += int(c)
    return 'Yes' if ans % 9 == 0 else 'No'


def main():
    N = read_str()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 78808
//IIT Kanpur FacelessMen India
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

ll a[N];
int n; 

int main(){
  // freopen("product.in","r",stdin);
  // freopen("product.out","w",stdout);
  cin>>n;
  a[n]=n;
  ll sum = n;
  for(int i = n-1;i>0;i--){
    a[i]=sum-a[i+2]+1ll*(n-1)*(n-1)%mod+mod;
    a[i]+=min(n-1,i+1);
    a[i]%=mod; 
    sum+=a[i];
  }
  printf("%lld\n",a[1]);
  return 0;
}


Measured memory_bytes: 8064
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    constexpr i64 LINF = i64(1e15);

    var(i64, X);

    i64 ok = LINF;
    i64 ng = 0;
    while (ok - ng > 1) {
        const i64 mid = (ok + ng) / 2;
        const i64 s = 5 * (mid / 2) + 6 * (mid - (mid / 2));
        if (s >= X)
            ok = mid;
        else
            ng = mid;
    }

    print(ok);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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

int main(){
  int n, m;
  cin >> n >> m;
  mint ans = 1;
  for(int i = 1; i <= n; ++i){
    ans *= i;
  }
  for(int i = 1; i <= m; ++i){
    ans *= i;
  }
  if(abs(n - m) >= 2) ans = 0;
  if(abs(n - m) == 0){
    ans *= 2;
  }
  cout << ans.x << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int N = Integer.parseInt(line[0]);
		int M = Integer.parseInt(line[1]);
		int C = Integer.parseInt(line[2]);
		
		line = sc.nextLine().split(" ");
		int[] B = new int[M];
		
		for(int i= 0;i<M;i++) {
			B[i] = Integer.parseInt(line[i]);
		}
		
		int[][] A = new int[N][M];
		for(int i= 0;i<N;i++) {
			line = sc.nextLine().split(" ");
			for(int j= 0;j<M;j++) {
				A[i][j] = Integer.parseInt(line[j]);
			}
		}
		sc.close();
		
		int count =0;
		
		for(int i= 0;i<N;i++) {
			int sum = C;
			for(int j= 0;j<M;j++) {
				sum += A[i][j] * B[j];
			}
			if (sum>0) {
				count ++;
			}
		}
		
		System.out.println(count);

	}

}


Measured memory_bytes: 23764
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		int[][] dp = new int[s.length+1][t.length+1];
		for(int i = 1; i <= s.length; i++) {
			for(int j = 1; j <= t.length; j++) {
				if(s[i-1] == t[j-1])
					dp[i][j] = dp[i-1][j-1] + 1;
				else
					dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
			}
		}
		StringBuilder ans = new StringBuilder();
		int i = s.length, j = t.length;
		while(i > 0 && j > 0){
			if(dp[i][j] == dp[i-1][j])
				i--;
			else if(s[i-1] == t[j-1]) {
				ans.append(s[i-1]);
				i--;
				j--;
			}
			else
				j--;
		}
		System.out.println(ans.reverse());
	}

}

Measured memory_bytes: 83020
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string str;
    string key1="dream";
    string key2="dreamer";
    string key3="erase";
    string key4="eraser";
    cin>>str;
    reverse(str.begin(),str.end());
    reverse(key1.begin(),key1.end());
    reverse(key2.begin(),key2.end());
    reverse(key3.begin(),key3.end());
    reverse(key4.begin(),key4.end());
    while(str.size()){
        if(str.substr(0,5)==key1){
            str=str.substr(5);
        }else if(str.substr(0,7)==key2){
            str=str.substr(7);
        }else if(str.substr(0,5)==key3){
            str=str.substr(5);
        }else if(str.substr(0,6)==key4){
            str=str.substr(6);
        }else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    
    cout<<"YES"<<endl;
}


Measured memory_bytes: 512
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    string ans="";
    cin>>s;
    for(auto x:s)
    {
        switch(x)
        {
            case '0':
            case '1':
            ans+=x;
            break;
            default:
            if(ans.size())ans.erase(ans.end()-1);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector <int>vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	reverse(vec.begin(), vec.end());
	for (int j = 0; j < N - 1; j++) {
		if (vec.at(j)<  vec.at(j + 1)) {
			vec.at(j+1)--;
		}
	}
	int cnt = 0;
	for (int k = 0; k < N - 1; k++) {
		if (vec.at(k) < vec.at(k + 1)) {
			cnt++;
		}
	}
	if (cnt == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

using namespace std;

#define pb push_back

const int N = 1e5 + 5;
int n, mod, dp[N], f[N];
vector<int> gr[N], pref[N], suff[N];

int add (int _a, int _b) {
    _a += _b;
    if (_a >= mod) _a -= mod;
    return _a;
}

int mult (int _a, int _b) { return 1LL * _a * _b % mod; }

void dfs (int u, int prv) {
    dp[u] = 1;
    for (int v : gr[u]) if (v != prv) {
        dfs(v, u);
        dp[u] = mult(dp[u], add(dp[v], 1) );
        pref[u].pb(1); suff[u].pb(1);
    }
    int i = 0;
    for (int v : gr[u]) if (v != prv) {
        if (i) pref[u][i - 1] = mult(pref[u][i - 1], add(dp[v], 1) );
        if (i + 1 < suff[u].size() ) suff[u][i + 1] = mult(suff[u][i + 1], add(dp[v], 1) );
        ++i;
    }
    for (i = 1; i < suff[u].size(); ++i) suff[u][i] = mult(suff[u][i], suff[u][i - 1]);
    for (i = (int)pref[u].size() - 2; i >= 0; --i) pref[u][i] = mult(pref[u][i], pref[u][i + 1]);
}

void dfs2 (int u, int prv) {
    int i = 0;
    for (int v : gr[u]) if (v != prv) {
        f[v] = add(1, mult(f[u], mult(pref[u][i], suff[u][i]) ) );
        ++i;
        dfs2(v, u);
    }
}

int main () {
    scanf("%d %d", &n, &mod);
    for (int i = 1; i < n; ++i) {
        int u, v; scanf("%d %d", &u, &v);
        gr[u].pb(v);
        gr[v].pb(u);
    }

    dfs(1, 1);
    f[1] = 1; dfs2(1, 1);

    for (int u = 1; u <= n; ++u) printf("%d\n", mult(dp[u], f[u]) );

    return 0;
}


Measured memory_bytes: 25472
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
    int n, m, k;
    while (cin>>n>>m>>k && n) {
        vector<vector<int> > dp(n+1, vector<int>(n*m+1, 0));
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n*m+1; j++) {
                if (dp[i][j] == 0) continue;
                for (int dice = 1; dice < m+1; dice++) {
                    dp[i+1][j+dice] += dp[i][j];
                }
            }
        }
        
        double ans = 0;
        for (int i = 0; i < n*m+1; i++) {
            if (dp[n][i] == 0) continue;
            if (i-k < 1) ans += 1 * dp[n][i];
            else ans += (i-k) * dp[n][i];
        }
        printf("%.12lf\n", ans / pow(m,n));
    }
}

Measured memory_bytes: 3324
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <random>

using namespace std;
using ll = long long;

ll N, M;

void input() {
    cin >> N >> M;
}

void solve() {
    ll ans = 0;
    for (ll n = 1; n <= min(double(M / N), sqrt(M)); n++) {
        if (M % n == 0) {
            if (n >= N) {
                ans = M / n;
                break;
            }
            ans = n;
        }
    }
    cout << ans << endl;
}




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



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

int main()
{
	int N;
	cin >> N;
	int i = 1;
	int maxSq = 1;
	while (i*i <= N)
	{
		maxSq = i * i;
		i++;
	}
	cout << maxSq << endl;
	return 0;
}

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

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

int main()
{
	char word;
	char ans[1200];

	int pos=0;
	int i=0;

	while (1)
	{
		scanf("%c", &word);

		if (word == '\n')
			break;
		
		if ((word >= 'a' && word <= 'z') || (word >= 'A' && word <= 'Z'))
			ans[pos] = word ^ 0x20;
		else
			ans[pos] = word;

		pos++;

	}

	for(i = 0; i < pos; i++)
		printf("%c", ans[i]);

	printf("\n");

	return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int K,X;
    cin >> K >> X;
    if(K*500>=X){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}

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

int main()
{
    // your code goes here
    string s;
    cin >> s;
    string p = "es";
    string z = "s";
    if ((int)s.at(s.length() - 1) == 's')
        s += p;
    else
        s += z;
    cout << s << endl;
    return 0;
}


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

int main() {
	int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
	if(e-a<=k) cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int l,r,d;
   int ans =0;
   cin>>l>>r>>d;
   for(int i =l;i<=r;i++)
   {
       if(i%d==0)
            ans++;
   }
   cout<<ans;
}


Measured memory_bytes: 3592
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    memset(a, 0, sizeof(a));
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int t;
            cin >> t;
            a[t-1]++;
        }
    }

    int ans=0;
    rep(i, n) {
        if (a[i]==0) {
            ans++;
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3588
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{
    class ProgramC
    {
        static void Main(string[] args)
        {

            //入力
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int[] odd = new int[100000];
            int[] even = new int[100000];

            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    odd[int.Parse(s[i]) - 1]++;
                    continue;
                }

                even[int.Parse(s[i]) - 1]++;

            }

            int em = 0;
            int ec = 0;
            int om = 0;
            int oc = 0;

            for (int i = 0; i < 100000; i++)
            {
                int temp1 = even[i];
                int temp2 = odd[i];

                if (ec < temp1)
                {
                    em = i;
                    ec = temp1;
                }
                if (oc < temp2)
                {
                    om = i;
                    oc = temp2;
                }

            }

            int em2 = 0;
            int ec2 = 0;
            int om2 = 0;
            int oc2 = 0;

            for (int i = 0; i < 100000; i++)
            {
                int temp1 = even[i];
                int temp2 = odd[i];

                if (ec2 < temp1 && em != i)
                {
                    em2 = i;
                    ec2 = temp1;
                }
                if (oc2 < temp2 && om != i)
                {
                    om2 = i;
                    oc2 = temp2;
                }

            }

            if(em == om)
            {
                Console.WriteLine(Math.Min(n - ec - oc2, n - ec2 - oc));
                return;
            }
 
            
            Console.WriteLine(n - ec - oc);
            

        }

        
    }

    

}


Measured memory_bytes: 19296
#include<iostream>
//#include<string.h>
using namespace std;
//cout << "Yes" << endl;
//cout << "No" << endl;
//int seiyaku_check(long i,int Min,long Max){
//	if(Min <= i && i <= Max){
	//	return 1;
	//}else{
		//exit(1);
	//}
//}

int main(){
	int i;
	string s[7][3]={
		
			{"SUN"},
		    {"MON"},
		    {"TUE"},
		    {"WED"},
		    {"THU"},
		    {"FRI"},
		    {"SAT"},

	};
	
	string t;
	cin >> t;
	
	i=0;
	while(1){
		if(t==*s[i])break;
		else i++;
		if(i == 7)exit(1);
	}
	
	
	for(i=0;i<7;i++){
		if(t==*s[i]){
			break;
		}
	}
	cout << 7-i << endl;
	
	
	/*
	for(int i=0;i<7;){
		cout << i <<" : " << s[i] << "  " << *s[i] << endl;
		i++;
	}
	*/
	
	/*
	for(int i=0;i<7;i++){
			cout << endl;
		    cout << "s[i]=" << i << endl;
		for(int j=0;j<3;j++){
			cout << s[i][j];
		}
	}
	*/
	
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>

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

char ToUpper(char cX) { return toupper(cX); }
char Tolower(char cX) { return tolower(cX); }

const long long INF = 1LL << 60;
const long long MOD = 1000000007;

using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

vector<vector<ll>> dp;
vector<ll>a;
vector<ll>l;


int main()
{
	ll n;
	cin >> n;
	ll res = -INF;
	vector<ll> r(n, 0);
	for (ll i = 0; i < n; i++) {
		cin >> r[i];
	}
	ll min = r[0];
	for (ll i = 1; i < n; i++) {
		chmax(res, r[i] - min);
		chmin(min, r[i]);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 4364
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline


N,A,B =MI()
if A+B<=N:
    max = 0
else:
    max = A+B-N

print(min(A,B),max)


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int dp[100010];

signed main()
{
  int n;
  string s;
  cin>>n>>s;
  vi a(n+1);
  vi b(n+1);
  rep(i,n){
    if(s[i]=='W')a[i+1]=a[i]+1;
    else a[i+1]=a[i];
  }
  for(int i=n; i>=1; i--){
    if(s[i-1]=='E')b[i-1]=b[i]+1;
    else b[i-1]=b[i];
  }
  int ans=INF;
  rep(i,n){
    int tmp=a[i]+b[i+1];
    // cout<<tmp<<endl;
    chmin(ans,tmp);
  }
  cout<<ans<<endl;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::vector<std::vector<std::pair<int, int> > > qs;
std::vector<int> res;

using Table = std::vector<std::pair<int, int> >;
Table merge(Table a, int cost, int profit) {
	int m = a.size();
	a.push_back({1000000000, 1000000000});
	int left = 0, right = 0;
	Table res;
	while (left < m || right < m) {
		bool consume_left = a[left].first < a[right].first + cost;
		auto tmp = consume_left ? a[left++] : a[right++];
		if (!consume_left) tmp.first += cost, tmp.second += profit;
		// while (res.size() && res.back().first == tmp.first && res.back().second < tmp.second) res.pop_back();
		// if (res.size() && res.back().second >= tmp.second) continue;
		res.push_back(tmp);
	}
	return res;
}

std::vector<std::pair<int, int> > info;
Table top{{0, 0}}, bottom{{0, 0}};
int threshold = 11;
int n;
void dfs(int i, int depth) {
	if (i >= n) return;
	Table bak;
	if (depth < threshold) bak = top, top = merge(top, info[i].first, info[i].second);
	else bak = bottom, bottom = merge(bottom, info[i].first, info[i].second);
	for (auto j : qs[i]) {
		int head = 0;
		int max = -1000000000;
		for (int k = bottom.size(); k--; ) {
			while (head < (int) top.size() && top[head].first + bottom[k].first <= j.first)
				max = std::max(max, top[head++].second);
			res[j.second] = std::max(res[j.second], max + bottom[k].second);
		}
	}
	for (int j = 1; j <= 2; j++) dfs((i << 1) + j, depth + 1);
	
	if (depth < threshold) top = bak;
	else bottom = bak;
}

int main() {
	n = ri();
	info.resize(n);
	for (int i = 0; i < n; i++) info[i].second = ri(), info[i].first = ri();
	
	int q = ri();
	qs.resize(n);
	res.resize(q);
	for (int i = 0; i < q; i++) {
		int x = ri() - 1;
		int l = ri();
		qs[x].push_back({l, i});
	}
	
	dfs(0, 0);
	
	for (auto i : res) printf("%d\n", i);
	
	return 0;
}


Measured memory_bytes: 15052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int MOD = 1e9 + 7;
#define INF ((1<<30)-1)
#define LINF (1LL<<30)


int N,W;
int v[110],w[110];
ll dp[110][110000];
int main() {
    cin >> N >> W;
    for(int i = 1;i <= N;i++)cin >> w[i] >> v[i];
    for(int j = 1;j < 110000; j++)dp[0][j] = LINF;

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

Measured memory_bytes: 88320
#pragma region Macros
#include <bits/stdc++.h>
#define int long long
using ll = long long;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b+a); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#pragma endregion

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int takahashi_attack = (c+b-1)/b;
  int aoki_attack = (a+d-1)/d;
  
  if (takahashi_attack <= aoki_attack)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3564
// https://atcoder.jp/contests/abc175/tasks/abc175_a
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	string s;
	cin >> s;
	vector<int> v;
	for (auto x:s) {
		if (x == 'R') {
			if (v.size()) {
				v.push_back(v.back()+1);
			} else {
				v.push_back(1);
			}
		} else v.push_back(0);
	}
	cout << max({v[0], v[1], v[2]}) << endl;
	return 0;
}
	


Measured memory_bytes: 3568
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
const int Max = 1e5;
const int MOD = 1e9 + 7;

int n;
int main()
{
	scanf("%d", &n);
	int sum = 1;
	for(int i = 1; i <= n; i++) {
		int ans = i;
		while(ans % 2 == 0 && ans != 1)
		{
			ans /= 2;
		}
		if(ans == 1) sum = max(i, sum);
	}
	printf("%d\n", sum);
	return 0;
}

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

#define ll long long
using namespace std;

int main() {
    ll s;
    cin >> s;
    if (s == 1e18) {
        cout << "0 1000000000 1000000000 0 1000000000 1000000000" << endl;
        return 0;
    }
    vector<ll> ret(6);
    ll mod = 1e9;
    ret[0] = 0;
    ret[1] = mod - (s % mod);
    ret[2] = s / mod + 1;
    ret[3] = 0;
    ret[4] = s / mod;
    ret[5] = mod;
    for (int i = 0; i < 6; i++) {
        if (i > 0)cout << " ";
        cout << ret[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 200001;
int main(){
	int n,q;
	cin>>n>>q;

	vector<pair<int,pair<int,int>>> pt;
	for(int i = 0; i < n; i++){
		int s,t,x;
		cin>>s>>t>>x;
		pt.push_back({x,{s-x,t-x}});
	}

	vector<int> res(N,-1);
	sort(pt.begin(),pt.end());

	set<int> st;
	map<int,int> mp;
	for(int i = 0; i < q; i++){
		int t;cin>>t;
		st.insert(t);
		mp[t] = i;
	}
	for(auto p : pt){
		int l = p.second.first;
		int r = p.second.second;
		int x = p.first;
		while(st.size()){
			auto it = st.lower_bound(l);
			if(it == st.end()) break;
			if(*it>=r) break;
			res[mp[*it]] = x;
			st.erase(it);
		}
	}

	for(int i = 0; i < q; i++) cout<<res[i]<<"\n";
}

Measured memory_bytes: 24176
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int n, m;
vector<P> key;
vector<int> dp;

int f(int x){
    if(x == ((1<<n)-1))return 0;
    if(dp[x] != -1)return dp[x];
    int res = 1e9;
    for(int i=0;i<m;i++){
        int a = key[i].first;
        int b = key[i].second;
        bool flg = false;
        for(int j=0;j<n;j++){
            if(((x>>j)&1)==0 && ((b>>j)&1)==1){
                flg = true;
                break;
            }
        }
        if(flg){
            res = min(res, a+f(x | b));
        }
    }
    return dp[x] = res;
}

int main(void){
    int ans;
    cin >> n >> m;
    dp.assign((1<<n), -1);
    for(int i=0;i<m;i++){
        int a, b, c = 0;
        cin >> a >> b;
        for(int j=0;j<b;j++){
            int t;
            cin >> t;
            c |= (1<<(--t));
        }
        key.push_back(P(a, c));
    }
    ans = f(0);
    if(ans == 1e9)ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<vector>
#define pb push_back
#define put(x,y) ans.pb((P){x,y})
using namespace std;
#define G getchar()
int read()
{
	int x=0; char ch=G;
	for (;!isdigit(ch);ch=G);
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}
#undef G

int n; char s[260];
typedef pair<int,int> P;
vector<P> ans;
void dfs(int x,int msk,bool rev){  //from the top 1 or bottom 0
	int tot=0,pos;
	for (int i=n;i;i--) if (msk>>i-1&1) tot++,pos=i;
//	printf("dfs %d %d %d  %d %d\n",x,msk,rev,tot,pos);
	for (int i=x+1;i<pos;i++) ans.pb((P){i,1});
	if (tot==1){
		if (rev) put(pos,1),put(pos,0),put(pos-1,0);
		else put(pos-1,0),put(pos,0),put(pos,1);
	}
	else{
		if (rev){
			put(pos,1);
			dfs(pos,msk^(1<<pos-1),1);
			put(pos-1,1); put(pos-1,0); put(pos,0); put(pos,1);
			dfs(pos,msk^(1<<pos-1),0);
			put(pos,0); put(pos-1,0);
		}
		else{
			put(pos-1,0); put(pos,0); put(pos,1);
			dfs(pos,msk^(1<<pos-1),1);
			put(pos,0); put(pos-1,0); put(pos-1,1); put(pos,1);
			dfs(pos,msk^(1<<pos-1),0);
		}
	}
	for (int i=pos-1;i>=x;i--) ans.pb((P){i,1});
}
int main()
{
	scanf("%d%s",&n,s);
	for (int i=0;i<(1<<n);i++)
		for (int j=0;j<(1<<n);j++)
			if ((i&j)==j&&s[j]=='0'&&s[i]=='1') return puts("Impossible"),0;
	puts("Possible");
	ans.pb((P){0,1});
	for (int i=0;i<(1<<n);i++){
		if (s[i]=='1') continue;
		int tot=0;
		for (int j=0;j<(1<<n);j++)
			if ((i&j)==j&&s[j]=='0') tot++;
		if (tot^1) continue;
//		printf("make %d\n",i);
		dfs(0,i,1);
//		printf("size %d\n",(int)ans.size());
	}
	printf("%d\n",(int)ans.size()-1);
	for (int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}

Measured memory_bytes: 512
n,k=map(int,input().split())
mod = 10**9+7
fac = [1]
caf = [1]

def pow(n,p):
    res=1
    while p >0:
        if p%2==0:
            n = n**2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

for i in range(1,2005):
    fac.append((fac[i-1]*i)%mod)
    caf.append(pow(fac[i],mod-2))

def ncr(n,r):
    if n < r: return 0
    return fac[n]*caf[r]*caf[n-r]

def main():
    global n,k
    for i in range(1,k+1):
        print(ncr(k-1,i-1)*ncr(n-k+1,i)%mod)
main()

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


int main(){
  string s;
  cin >> s;
  int n=s.size();
  for(int i=0;i<n;++i){
    if(s[i]=='?') s[i]='D';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double 
#define MOD 1000000007ll 
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
ll power(ll a,ll p,ll m)
{
    ll re=1;
    re%=m;
    for(;p;p>>=1){
        if(p&1) re=re*a%m;
        a=a*a%m;
    }
    return re;
}
ll inverseMOD(ll a,ll m)
{
    return power(a,m-2,m);
}
ll comb(ll n,ll x)
{
    ll ret = 1;
    for(ll i=1;i<=x;i++)
    {
        ret *= (n-i+1);
        ret %= MOD;
        ret *= inverseMOD(i,MOD);
        ret %= MOD;
    }
    return ret;
}
int main()
{
    ll s;
    cin>>s;
    ll ans = 0;
    for(ll i=1;i*3<=s;i++)
    {
        ll r = s-3*i;
        ans += comb(r+i-1,i-1);
        ans %= MOD;
    //    cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
n,m=map(int,input().split());d=[i+1 for i in range(m)]
def listdup(a,b):
  x=[]
  for i in a:
    if i in b:x.append(i)
  return sorted(x)
for i in range(n):
  a=list(map(int,input().split()));a=a[1:];a.sort()
  d=listdup(a,d)
print(len(d))

Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;
int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> sum(n, 0);

  ll ans = 0;
  for (size_t i = 1; i <= n; i++) {
    if (i < k) {
      continue;
    }
    ll small = (i - 1) * i /2;
    ll large = i * n - ((i - 1) * i / 2);
    ans += large - small + 1;
    ans %= MOD;
  }
  cout << ans + 1 << endl;
}

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

int main() {
	string s;
  	cin >> s;
  	int len = s.size();
  
  	vector<char> vec(len);
  
  	for(int i = 0; i < len; i++) {
     vec.at(i) = s.at(i);
    }
  
  	vector<int> ans(26,0);
  
  	for(int i = 0; i < len; i++) {
    	ans.at(vec.at(i) - 'a')++;
    }
  
  	bool all = true;
  
  	for(int i = 0; i < 26; i++) {
    	if(ans.at(i) == 0) {
        	cout << (char)(i + 'a') << endl;
          	all = false;
          	break;
        }
    }
  
  	if(all) cout << "None" << endl;
  
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
using namespace std;
int n,a,b;
int ans[300010],pos; 
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if (a+b>n+1||1ll*a*b<n) {printf("-1");return 0;}
//	for (int i=n-a+1;i<=n;i++) ans[++pos]=i;
//	int nw=n-a;b--;
	int nw=n;
	while (nw-a>=b-1&&nw-a>=0)
	{
		for (int i=nw-a+1;i<=nw;i++)
			ans[++pos]=i;
		nw-=a;b--;
		//cout<<nw<<" "<<b<<endl;
	}
	//if (nw==b) for (int i=1;i<=b;i++) ans[++pos]=i;
//	else
//	{
//	cout<<b<<endl; 
		for (int i=b;i<=nw;i++) ans[++pos]=i;
		for (int i=b-1;i>=1;i--) ans[++pos]=i;
//	}
	for (int i=1;i<=n;i++) printf("%d ",ans[i]);
} 

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

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

    ll l=-1,r=1000000000000000000LL;
    while(r-l>1)
    {
        ll m = (l+r)/2;

        ll rem = m;
        rep(i,n-1)
        {
            ll sub = rem/k+1;
            rem-=sub;
        }

        if(rem>=0) r=m;
        else l=m;
    }

    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3092
from itertools import product
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = 10 ** 30
def calc(p):
    if sum(list(set(p))) < 6:
        return INF
    a, b, c = 0, 0, 0
    ac, bc, cc = 0, 0, 0
    for i, v in enumerate(p):
        if v == 1:
            a += L[i]
            ac += 1
        elif v == 2:
            b += L[i]
            bc += 1
        elif v == 3:
            c += L[i]
            cc += 1
    return abs(A-a) + abs(B-b) + abs(C-c) + (ac+bc+cc-3) * 10

ans = INF
for p in product(range(4), repeat=N):
    ans = min(ans, calc(p))
print(ans)


Measured memory_bytes: 50524
#include<stdio.h>
int main(void){
   int n, i, wt[10000], key, j, WT, SUM, count;
   scanf("%d", &n);
   while ( n ) {
       count = 0;
       for ( i = 0; i < n; i++ ) { 
           scanf("%d", &wt[i]);
       }
       key = 1;
       for ( i = 0; key; i++ ) {
           key = 0;
           for ( j = n - 1; j > i; j-- ) {
               if ( wt[j] < wt[j - 1]) {
                   WT = wt[j];
                   wt[j] = wt[j - 1];
                   wt[j - 1] = WT;
                   key = 1;
                   count++;
               }
           }
       }
       printf("%d\n", count);
       scanf("%d", &n);
   }
   return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

const int INF=1001001001;
int dy[4]={-1,0,1,0};
int dx[4]={0,-1,0,1};

int H,W,K;
int sy,sx,gy,gx;
vector<string>fld;

vector<vector<vpint>>dist;

signed main(){
	cin>>H>>W>>K;
	cin>>sy>>sx>>gy>>gx;
	sy--;sx--;gy--;gx--;
	fld=vector<string>(H);
	rep(i,H){
		cin>>fld[i];
	}

	dist=vector<vector<vpint>>(H,vector<vpint>(W,vpint(4,{INF,0})));
	queue<tuple<int,int,int>>que[2];
	rep(i,4){
		dist[sy][sx][i]={1,0};
		que[1].emplace(sy,sx,i);
	}
	for(int k=1;que[k&1].size();k++){
		while(que[k&1].size()){
			int y,x,d;
			tie(y,x,d)=que[k&1].front();
			que[k&1].pop();
			rep(nd,4){
				int nc,ns;
				tie(nc,ns)=dist[y][x][d];
				if(d==nd&&ns+1<=K)ns++;
				else {
					nc++;
					ns=1;
				}
				int ny=y+dy[nd];
				int nx=x+dx[nd];
				if(ny<0||ny>=H||nx<0||nx>=W)continue;
				if(fld[ny][nx]=='@')continue;
				if(dist[ny][nx][nd]<=pint(nc,ns))continue;
				dist[ny][nx][nd]=pint(nc,ns);
				que[nc&1].emplace(ny,nx,nd);
			}
		}
	}

	int ans=INF;
	rep(d,4)chmin(ans,dist[gy][gx][d].fi);
	if(ans==INF)cout<<-1<<endl;
	else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 207436
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>

#define f(i,x) for(int i=0;i<x;i++)


using namespace std;

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

	if (c >= a && c <= b)cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256