akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  int w,h;
  cin >> w >> h;
  priority_queue<pair<ll,bool>,vector<pair<ll,bool>>,greater<pair<ll,bool>>> pque;
  for(int i=0;i<w;i++){
    ll p;cin >> p;
    pque.push({p,0});
  }
  for(int i=0;i<h;i++){
    ll p;cin >> p;
    pque.push({p,1});
  }
  w++;
  h++;
  ll ans = 0;
  while(w > 1 || h > 1){
    auto t = pque.top();
    pque.pop();
    if(t.second){
      if(h > 1){
        ans += t.first * w;
        h--;
      }
    }
    else{
      if(w > 1){
        ans += t.first * h;
        w--;
      }    
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7396
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
#define PI 3.14159265359
typedef long long ll;
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(*(s.end()-1)=='3'){
		cout<<"bon"<<endl;
	}
	else if(*(s.end()-1)=='0'||*(s.end()-1)=='1'||*(s.end()-1)=='6'||*(s.end()-1)=='8'){
		cout<<"pon"<<endl;
	}
	else{
		cout<<"hon"<<endl;
	}

}

Measured memory_bytes: 3040
N, H = [int(_) for _ in input().split()]
katana = [[int(_) for _ in input().split()] for _ in range(N)]

katana.sort(key=lambda x:x[1], reverse=True)
a_max_katana = max(katana)

a_max = a_max_katana[0]
a_max_b = a_max_katana[1]
katana.pop(katana.index(a_max_katana))

count = 0

for katana_use in katana:
    if katana_use[1] > a_max:
        H -= katana_use[1]
        count += 1
        if H > a_max_b:
            continue
        else:
            count += 1
            break
    else:
        count += -(-(H - a_max_b) // a_max) + 1
        break

else:
    count += -(-(H - a_max_b) // a_max) + 1

print(count)



Measured memory_bytes: 22736
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    ll n,k,q;cin>>n>>k>>q;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=inf;
    rep(i,0,n-1){
        ll B[n];
        rep(j,0,n-1){
            if(a[j]<a[i])B[j]=0;
            else B[j]=1;
        }
        ll ok=inf,ng=a[i]-1;
        while(abs(ok-ng)>1){
            ll b[n];rep(i,0,n-1)b[i]=B[i];
            ll mid=(ok+ng)/2;
            rep(j,0,n-1){
                if(a[j]>mid)b[j]=2;
            }
            ll cnt=0;
            rep(j,0,n-1){
                ll s=0,s2=0;
                while(j<=n-1&&b[j]!=0){
                    s++;
                    if(b[j]==2)s2++;
                    j++;
                }
                if(s<k)continue;
                cnt+=s+1-k-max(0,s2+1-k);
            }
            if(cnt>=q)ok=mid;
            else ng=mid;
        }
        Min(ans,ok-a[i]);
        //cerr<<ans<<endl;
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int, int>;
     
const int MOD = 1e9 + 7;


int main(){
   int n;
   cin >> n;
   map<ll, int> mp;
   REP(i, 1, 100){
      REP(j, 1, 100){
         REP(k, 1, 100){
            ll now = i * i + j * j + k * k + i * j + j * k + k * i;
            mp[now]++;
         }
      }
   }
   REP(i, 1, n){
      cout << mp[i] << endl;
   }
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;


int main(){
  ll h, w;
  cin >> h >> w;
  vector<vchar> s(h, vchar(w));
  rep(i, 0, h){
    st str;
    cin >> str;
    rep(j, 0, w) s.at(i).at(j) = str.at(j);
  }

  rep(i, 0, h)rep(j, 0, w){
    if(s.at(i).at(j) == '.'){
      ll count = 0;
      rep(x, -1, 2)rep(y, -1, 2){
        if(i + x >= 0 && i + x < h && j + y >= 0 && j + y < w)if(s.at(i + x).at(j + y) == '#') count++;
      }
      s.at(i).at(j) = '0' + count;
    }
  }
  rep(i, 0, h){
    rep(j, 0, w) cout << s.at(i).at(j);
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main() {
    int n, m, mi, ma;
    mi = 10000000;
    ma = 0;
    int l,r;

    cin >> n >> m;
    for(int i = 0; i<m;i++) {
        cin >> l >> r;
        mi = min(mi, r);
        ma = max(ma, l);
    }

    int ans = mi - ma;
    if(ans < 0) {
        ans = 0;
    } else {
        ans+=1;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    int N;
    long long int M;
    cin >> N >> M;
    vector<long long int> A(N);
    long long int S=0;
    map<long long int, long long int> mp;
    mp[S]++;
    for(int n=0; n<N; n++) {
        cin >> A[n];
        S += A[n];
        mp[S%M]++;
    }
    
    long long int ans=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        ans += itr->second*(itr->second-1)/2;
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>

using namespace std;

int mod = 1000000007;
int a[9];

long long powmod(long long x, long long y) {
    long long ans = 1;
    
    while (y > 0) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    
    return ans;
}

int main() {
    int s, i, j;
    long long ans = 0;
    
    scanf("%d", &s);
    
    a[1] = 9;
    for (i = 2; i <= 8; i++) a[i] = a[i - 1] * 10;
    
    for (i = 1; i <= min(s, 7); i++) {
        int r = s, p = 0, q;
        
        for (j = i; ; j++) {
            int x = a[j];
            
            if (r >= j * x) {
                r -= j * x;
            } else {
                q = r / j;
                r %= j;
                
                break;
            }
        }
        
        while (1) {
            if (r == 0) ans++;
            
            r -= j;
            q++;
            
            if (q == a[j]) {
                j++;
                q = 0;
            }
            
            p += -r / i;
            r += -r / i * i;
            
            if (p >= a[i]) break;
        }
    }
    
    for (i = 8; i <= s; i++) {
        int c = s / i;
        int x = s % i;
        
        if (x == 0) ans += powmod(10, i - 1) * 9 - c + 1;
        
        if (c > x) {
            if (x > 0) ans++;
            ans += (c - x - 1) / (i + 1);
        }
    }
    
    printf("%lld\n", ans % mod);
    
    return 0;
}


Measured memory_bytes: 128
import sys
def main():
    input = sys.stdin.readline

    N, M, K=map(int, input().split())
    friend_or_block = [0] * N
    friends_chain = UnionFindTree(N)

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        friends_chain.union(a, b)
        friend_or_block[a] += 1
        friend_or_block[b] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if friends_chain.same(c, d):
            friend_or_block[c] += 1
            friend_or_block[d] += 1

    print(*[friends_chain.size(i) - friend_or_block[i] - 1 for i in range(N)])

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x

    def same(self, x, y): return self.find(x) == self.find(y)
    def size(self, x): return -self.parent[self.find(x)]

if __name__ == '__main__':
    main()



Measured memory_bytes: 60636
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;

	cout << (n - 1) * (m - 1) << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define ARRAY_LENGTH( array ) ( sizeof( array ) / sizeof( array[ 0 ] ))

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N, K;
	cin >> N >> K;
	double ans = 0.0;
	rep( i, 1, N + 1 ){
			ans += 1.0 / pow( 2 , ceil(log2(ceil((double)K / i) )) );
	}
	printf( "%1.16lf\n", ans / N );
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}


Measured memory_bytes: 384
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   998244353
#define    inf  9223372026854775807
#define    ninf   -inf
#define    ima   2047483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(12)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
#define    fbo    find_by_order
#define    ook    order_of_key
#define    upb    upper_bound
#define    lowb   lower_bound 
#define    lte(v,x)   upb(all(v),x)-v.be()
#define    gte(v,x)   v.end()-lowb(all(v),x)
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(x==0)return 0;if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}



int main()
{       io 
int testcases=1;     //   cin>>testcases;
while(testcases--)
{

ll n;
cin>>n;

ll c=0;

if(n==1)
cout<<0;

else
{

for(ll i=2;i<=sqrt(n);i++)
{ll k=0;
	if(n%i==0)
	{
		
		while(n%i==0)
		{
			n/=i;
			k++;
		}
	}
ll p=1;
while(true)
{
	if(k>=p)
	{
		k-=p;
		c++;
	}
	else
	break;
	p++;
}
}

if(n>1)
c++;
cout<<c;

}






}return 0;}

Measured memory_bytes: 3696
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;

char S[200001];
int main() {
	scanf("%s", S);
	int N;
	for (int i = 0; i < 200001; i++) {
		if (S[i] == 0) {
			N = i;
			break;
		}
	}
	char b = 0;
	int res = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] != b) {
			b = S[i];
			res++;
		}
		else if (i != N - 1) {
			b = 0;
			i++;
			res++;
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std ;
//バケット法を練習してみる
int main(){
  int N ;
  cin >> N ;
  int ans = 0 ;
  vector<int> D(110) ;
  vector<int> num(110) ;
  for(int i =0; i<N ; i++) cin >> D[i] ;
  for(int j =0 ; j<N ; j++){
   num[D[j]]++;
  }
  sort(num.begin(),num.end()) ;
  reverse(num.begin(),num.end()) ;
  for(int x = 0 ; x<N; x++){
    if(num[x]>0) ans++;
  }
  
  cout << ans << endl;
  
}
 
  

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: u32,
        mut h: [u32; n]
    }

    solve(k, &mut h);
}

fn solve(k: u32, h: &mut [u32]) {
    h.sort();
    h.reverse();

    for (i, x) in h.iter().enumerate() {
        if x < &k {
            println!("{}", i);
            return;
        }
    }
    println!("{}", h.len());
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, m;
string s, t;
map<int, char>mp;
signed main() {
	cin >> n >> m >> s >> t;
	int l = lcm(n, m);
	int p = lcm(l / n, l / m);
	for (int i = 0; i < l; i += p) {
		if (s[i / (l / n)] != t[i / (l / m)]) {
			cout << -1 << endl;
			endre;
		}
	}
	cout << l << endl;
	endre;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int N,t,x,y;
    bool flag = true;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>t>>x>>y;
        if(t<x+y||((x+y)%2==0&&t%2!=0)||((x+y)%2!=0&&t%2==0)){
            flag = false;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{cout<<"No"<<endl;}
    return 0;
}

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

const int N = 1e5 + 10;

int a[N], b[N];

int main(){
	int n, k, x, cnt1, cnt2, ans, rec;
	scanf("%d %d",&n,&k);
	cnt1 = cnt2 = 0;
	for (int i = 1; i <= n; i++){
		scanf("%d",&x);
		if (x >= 0) a[++cnt1] = x;
		else b[++cnt2] = -x;
	}
	reverse(b + 1, b + cnt2 + 1);
	a[0] = b[0] = 0;
	ans = 1e9;
	for (int i = 0; i <= k; i++){
		if (i > cnt1 || k - i > cnt2) continue;
		rec = a[i] + b[k - i] + min(a[i], b[k - i]);
		ans = min(ans, rec);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,m,l[SZ],r[SZ],qzh[SZ];
char s[SZ];
ll dp[3003][3003],MOD=1e9+7;
ll tmp[3003];
int sum(int l,int r)
{
	if(l<=r)
	return qzh[r]-qzh[l-1];
	return 0;
}
ll fac[SZ],rfac[SZ];
ll qp(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD; b>>=1;
    }
    return ans;
}
ll C(int a,int b)
{
	if(b>a) return 0;
	return fac[a]*rfac[b]%MOD*rfac[a-b]%MOD;
}
int main()
{
	fac[0]=rfac[0]=1;
	for(int i=1;i<=200000;i++)
	fac[i]=fac[i-1]*i%MOD, rfac[i]=rfac[i-1]*qp(i,MOD-2)%MOD;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) qzh[i]=qzh[i-1]+s[i]-48;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",l+i,r+i);
		if(r[i]<r[i-1]) {--i; --m; continue;}
	}
	l[m+1]=n+1; r[m+1]=n+1;
	dp[0][0]=1;
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<=n;j++) tmp[j]=0;
		int s=sum(max(r[i-1]+1,l[i]),r[i]);
		for(int j=0;j<=n;j++) tmp[j+s]+=dp[i-1][j];
		int ol=max(r[i]-l[i+1]+1,0),p=r[i]-l[i]+1-ol;
		for(int j=0;j<=ol;j++)
		for(int k=j;k<=n&&k-j<=p;k++)
			dp[i][j]=(dp[i][j]+C(p,k-j)*tmp[k]%MOD)%MOD;
	}
	ll ans=dp[m][0];
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",int(ans));
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;

  bool ok = false;
  rep(i, s.length()-1){
    if(s.substr(i, 2) == "AC"){
      ok = true;
      break;
    }
  }

  if(ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

int n;
vector<int> a;

bool check(int x, int d){
    int u = ub(a,x+d);
    int l = lb(a,x-d);
    return u-l <= n-u;
}

int main(void){
    int q;
    cin >> n >> q;
    a.resize(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n+1), t_sum(n+1);
    rep(i,n){
        sum[i+1] = sum[i] + a[i];
        if (i % 2 != n % 2) {
            t_sum[i+1] = t_sum[i] + a[i];
        } else {
            t_sum[i+1] = t_sum[i];
        }
    }
    rep(_,q){
        int x;
        cin >> x;
        int l = 0, r = 1e9;
        while (l + 1 < r) {
            int m = (l+r)/2;
            if (check(x, m)) l = m;
            else r = m;
        }
        ll d = l;
        // debug(d);
        // debug(a[ub(a,x+d)]);
        // debug(a[lb(a,x-d)]);
        // debug(n - ub(a,x+d));
        // debug(ub(a,x+d) - lb(a,x-d));

        int dif = (n - ub(a,x+d)) - (ub(a,x+d) - lb(a,x-d));
        ll tmp = 0;
        if (dif == 0 || dif == 1) {

        } else if (dif == 2) {
            tmp = - a[(lb(a,x-d)-1)];
        } else if (dif == -1) {
            tmp = + a[n-1];
        }

        cout << sum[n]-sum[ub(a,x+d)]+t_sum[lb(a,x-d)] + tmp << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
origin_cards = raw_input()

while origin_cards != '-':
	
	shuffle_number = int(raw_input())

	for x in xrange(shuffle_number):
		h = int(raw_input())
		temp = origin_cards[h:len(origin_cards)+1] + origin_cards[0:h]
		origin_cards = temp
	print origin_cards

	origin_cards = raw_input()

Measured memory_bytes: 4204
import sys
input = sys.stdin.readline

_x, _y = map(int, input().split())


def chker(x, y):
    x = x if x < 4 else 4
    y = y if y < 4 else 4
    syokin = {
        1: 300000,
        2: 200000,
        3: 100000,
        4: 0
    }

    if x == y == 1:
        print('1000000')
        return

    print(syokin[x] + syokin[y])


chker(_x, _y)


Measured memory_bytes: 3060
import java.util.*;

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

    if (b >= a) {
      System.out.println(a);
    } else {
      System.out.println(a-1);
    }
  }
}

Measured memory_bytes: 21844
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
T = LI()
A = LI()
mod = 10**9+7

minimum = [1]*N
maximum = [0]*N

for i in range(N):
    if i == 0:
        minimum[i] = T[i]
        maximum[i] = T[i]
    else:
        if T[i] != T[i-1]:
            minimum[i] = T[i]
            maximum[i] = T[i]
        else:
            maximum[i] = T[i]

for i in range(N-1,-1,-1):
    if i == N-1:
        minimum[i] = max(minimum[i],A[i])
        maximum[i] = min(maximum[i],A[i])
    else:
        if A[i] != A[i+1]:
            minimum[i] = max(minimum[i],A[i])
            maximum[i] = min(maximum[i],A[i])
        else:
            maximum[i] = min(maximum[i],A[i])

ans = 1
for i in range(N):
    if maximum[i] >= minimum[i]:
        ans *= maximum[i]-minimum[i]+1
        ans %= mod
    else:
        print(0)
        exit()
print(ans)


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

const int N = 1e5 + 100;

int n, W;
long long w[N], v[N], dp[200][N];


int main(){
    # ifdef FILEs
        freopen( "input.txt", "r" ,stdin );
        freopen( "output.txt", "w", stdout );
    # endif
    ios_base::sync_with_stdio(false);
    cin >> n >> W;
    for( int i = 1; i <= n; i ++ ){
        cin >> w[i] >> v[i];
    }
    for( int i = 1; i <= n; i ++ ){
        for( int j = 0; j <= 1e5; j ++ ){
            if( j < v[i] )
                dp[i][j] = dp[i-1][j];
            if( j == v[i] ){
                dp[i][j] = w[i];
                if( dp[i-1][j] > 0 )
                    dp[i][j] = min( dp[i-1][j], w[i] );
            }
            else if( j > v[i] ){
                if( dp[i-1][j-v[i]] > 0 && dp[i-1][j] > 0 )
                    dp[i][j] = min( dp[i-1][j], dp[i-1][j-v[i]] + w[i] );
                else if( dp[i-1][j-v[i]] > 0 )
                    dp[i][j] = dp[i-1][j-v[i]] + w[i];
                else if( dp[i-1][j] > 0 )
                    dp[i][j] = dp[i-1][j];
            }
        }
    }
    int mx = 0;
    for( int i = 1; i < N; i ++ ){
        if( dp[n][i] <= W && dp[n][i] > 0)
            mx = max( mx, i );
    }
    cout << mx;
}   

Measured memory_bytes: 80128
import  numpy as np
h,w=map(int,input().split())
s = [[0]*(w+2)]
for i in range(h):
    s.append([0]+list(input())+[0])
s.append([0]*(w+2))

t = np.array(s)
c = 0
b = 0

def sirabe(t,i,j):
    if t[i-1][j] != "#" and t[i][j-1] != "#" and t[i+1][j] != "#" and t[i][j+1] != "#":
        return False
    else:
        return True


for i in range(1,h+1):
    for j in range(1,w+1):
        if t[i][j] == "#":
            if sirabe(t,i,j):
                continue
            else:
                c = 1
                break
    if c == 1:
        break


if c == 0:
    print("Yes")
else:
    print("No")


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=100100100;
const int mod=(int)1e9+7;

int main(){
    int n;
    cin>>n;
    vector<int>p(n),q(n),v(n);
    rep(i,0,n){
        cin>>p.at(i);
        v.at(i)=i+1;
    }
    rep(i,0,n){
        cin>>q.at(i);
    }
    int c=0;
    int a=0;
    int b=0;
    do{
        c++;
        bool c1=true;
        bool c2=true;
        rep(i,0,n){
            if(p.at(i)!=v.at(i)) c1=false;
            if(q.at(i)!=v.at(i)) c2=false;
        }
        if(c1) a=c;
        if(c2) b=c;
    }
    while(next_permutation(all(v)));
    cout<<abs(b-a)<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
using namespace std;
typedef long long llint;
typedef long double ld;
#define inf 1e18

llint n;
string s;
void solve(){
	cin >> s;
	if(s=="keyence"){
		cout << "YES" << endl;
	}
	else{
		bool f=false;
		for(int i=0;i<s.size();i++){
			if(f)break;
			for(int j=0;j<s.size();j++){
				if(i>j)continue;
				if(s.substr(0,i)+s.substr(j+1)=="keyence"){
					cout << "YES" << endl;
					f=true;
					break;
				}
			}
		}
		if(!f)cout << "NO" << endl;
	}

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
#define N 100000
#define Q 50000
 
int binarySearch(int*, int);
int n;
 
int main(){
 
  int q,i,j,c=0,temp=Q;
  int S[N],T[Q];
 
  scanf("%d", &n);
 
  for(i=0 ; i<n ; i++){
    scanf("%d", &S[i]);
  }
 
   scanf("%d", &q);
 
  for(i=0 ; i<q ; i++){
    scanf("%d", &T[i]);
  }
 
  for(i=0 ; i<q ; i++){
    c+=binarySearch(S,T[i]);
  }
 
  printf("%d\n",c);
 
  return 0;
}
 
int binarySearch(int *A, int key){
 
  int c=0,left=0,right,mid;
 
  right=n;
 
  while(left<right){
    mid=(left+right)/2;
 
    if(key==A[mid]) {
      c++;
      break;
    }
    if(key>A[mid]) left=mid+1;
    else if (key<A[mid]) right = mid;
  }
 
  return c;
}


Measured memory_bytes: 2264
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF 1001001001
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

#define MAX_V 200
int d[MAX_V][MAX_V];
int V;

void warshall_floyd()
{
  int i,j,k;
  rep(k,V)rep(i,V)rep(j,V)
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

struct Edge
{
  int s;
  int t;
  int c;
};

signed main(void)
{
  int i,j,k;
  rep(i,MAX_V)rep(j,MAX_V)
    d[i][j]=i==j?0:INF;
  Edge e[2000]={};

  cin>>V;
  in(int,M);
  rep(i,M)
    {
      in(int,a,b,c);
      if(a>b)swap(a,b);
      e[i]=(Edge){a-1,b-1,c};
      d[a-1][b-1]=c;
      d[b-1][a-1]=c;
    }

  warshall_floyd();

  drep(i,V)
    {
      drep(j,V)
	dprintf("%4d,",d[i][j]);
      puts("");
    }

  int count=M;
  rep(k,M)
    {
      bool flg=false;
      for(i=0;i<V;i++)
	{
	  for(j=0;j<V;j++)
	    {
	      if(d[i][e[k].s]+e[k].c+d[e[k].t][j]==d[i][j])
		flg=true;
	    }
	}
      count-=flg;
    }
  putv(count);
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }
const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long V, long long B, long long W, long long T){
    if(V <= W){cout<<NO<<endl; return;}
    if(abs(B-A) > T*(V-W)){cout<<NO<<endl; return;}
    cout<<YES<<endl;
}
int main(){
    long long A;
    scanf("%lld",&A);
    long long V;
    scanf("%lld",&V);
    long long B;
    scanf("%lld",&B);
    long long W;
    scanf("%lld",&W);
    long long T;
    scanf("%lld",&T);
    solve(A, V, B, W, T);
    return 0;
}


Measured memory_bytes: 3192
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 c=scan.nextInt();
		int s=b/a;
		if(s<=c) {
			System.out.println(s);
		}
		else {
			System.out.println(s-1);
		}
	}

}

Measured memory_bytes: 35724
def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])

print(a if a<=b else a-1)

Measured memory_bytes: 3060
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors


def check(a, b, x):
    if a ** 5 - b ** 5 == x:
        return True
    else:
        return False


def main():
    x = int(input())
    l = make_divisors(x)
    for a in range(1000):
        for b in range(-1000, 1000):
            if check(a, b, x):
                print(a, b)
                exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 65068
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<vector>
using namespace std;

int main() {
	int A, B, C, X, Y, i, j, k;
	int W = 15000000000;
	cin >> A >> B >> C >> X >> Y;

	for (i = 0; i <= 100000; i++) {
		int a, b;
		a = max(0, X - i);
		b = max(0, Y - i);
		int Z = A * a + B * b + C * 2 * i;
		W = min(W, Z);
	}
	cout << W << endl;
	return 0;
}




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

namespace ALDS1_9_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] line = ReadIntAr();

            CompleteBinaryTree<int> cbt = new CompleteBinaryTree<int>(n);
            for (int i = 0 ; i < n ; i++)
            {
                cbt.BinaryHeap[i] = line[i];
            }

            for (int i = 0 ; i < n ; i++)
            {
                Console.Write("node {0}: key = {1}, ", i + 1, cbt.BinaryHeap[i]);
                if (cbt.GetParent(i) != -1) Console.Write("parent key = {0}, ", cbt.BinaryHeap[cbt.GetParent(i)]);
                if (cbt.LeftChild(i) != -1) Console.Write("left key = {0}, ", cbt.BinaryHeap[cbt.LeftChild(i)]);
                if (cbt.RightChild(i) != -1) Console.Write("right key = {0}, ", cbt.BinaryHeap[cbt.RightChild(i)]);
                Console.Write(Environment.NewLine);
            }
        }

        class CompleteBinaryTree<T>
        {
            public T[] BinaryHeap { get; private set; }
            public int Count { get; private set; }

            public CompleteBinaryTree(int n)
            {
                BinaryHeap = new T[n];
                Count = 0;
            }

            public int GetParent(int i)
            {
                return ((i + 1) / 2) - 1;
            }
            public int LeftChild(int i)
            {
                int tmp = (i + 1) * 2 - 1;
                if (tmp < BinaryHeap.Count()) return tmp;
                else return -1;
            }
            public int RightChild(int i)
            {
                int tmp = (i + 1) * 2;
                if (tmp < BinaryHeap.Count()) return tmp;
                else return -1;
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 16244
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//???????????°?????????
		int n = sc.nextInt();

		//???????????£?¨?
		int list [] = new int[n];

		//?????????????´?
		for(int i = 0; i < n; i++){
			list[i] = sc.nextInt();
		}
		//?????????????????§???????????????
		for(int i = n - 1;i >= 0; i--){
			if(i > 0){
				System.out.print(list[i] + " ");
			}else{
				System.out.print(list[i]);
			}
		}
		//??????
		System.out.println();
	}
}

Measured memory_bytes: 26288
N,K=map(int,input().split())
mod=10**9+7

factorial=[1 for i in range(N+1)]
for i in range(1,N+1):
    if i==1:factorial[i]=1
    else:factorial[i] = factorial[i-1]*i % mod

def comb(n,k):
    return factorial[n]*pow(factorial[n-k]*factorial[k], -1, mod)

for i in range(1,K+1):
  if i > N-K+1:print(0)
  else:print(comb(K-1,i-1)*comb(N-K+1,i)%mod)

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    cout << min({n+m, n+x, m+x}) << endl;
}


Measured memory_bytes: 256
'use strict';

(function(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  const N=input.shift();
  const dp=[0,Math.abs(input[1]-input[0])];
  for(let i=0;i<N-2;i++){
    let c1=dp[i+1]+Math.abs(input[i+2]-input[i+1]);
    let c2=dp[i]+Math.abs(input[i+2]-input[i]);
    dp[i+2]=Math.min(c1,c2);
  }
  console.log(dp[N-1]);
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 25420
mn :: [String] -> [String]
mn (a:b:c:d:e:f:_) = [b,f,c,d,a,e]
me :: [String] -> [String]
me (a:b:c:d:e:f:_) = [d,b,a,f,e,c]
ms :: [String] -> [String]
ms (a:b:c:d:e:f:_) = [e,a,c,d,f,b]
mw :: [String] -> [String]
mw (a:b:c:d:e:f:_) = [c,b,f,a,e,d]

move :: Char -> [String] -> [String]
move c xs
    | c == 'N'  = mn xs
    | c == 'E'  = me xs
    | c == 'S'  = ms xs
    | otherwise = mw xs

walk :: String -> [String] -> String
walk [] (y:ys) = y
walk (x:xs) ys = walk xs $ move x ys

solve :: [String] -> String
solve (a:b:c:d:e:f:xs:_) = walk xs ys
    where
        ys = [a,b,c,d,e,f]

main :: IO ()
main = interact $ (++"\n") . solve . words


Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))

all = abs(A[0]) + abs(A[N-1])
for i in range(N-1):
    all += abs(A[i+1] - A[i])

print(all - (abs(A[0]) + abs(A[1]-A[0])) + abs(A[1]))

for i in range(1, N-1):
    print(all- (abs(A[i+1]-A[i]) + abs(A[i-1] - A[i])) + abs(A[i+1]-A[i-1]))
    
print(all - (abs(A[N-1])+abs(A[N-1]-A[N-2])) + abs(A[N-2]))


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

int main(){
  int i,n;
  char a[3],b[3],c[3];
  //printf("nyuuryoku\n");

  scanf("%s",a);

  scanf("%s",b);

  scanf("%s",c);

  printf("%c%c%c\n",a[0],b[1],c[2]);

  //printf("%c%c%c",a[0][0],a[1][1],a[2][2]);


  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

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

	long long total_monsters = 0;
	for (int i = 0; i < n; ++i) {
		int m = min(b[i], a[i]);
		b[i] -= m;
		a[i] -= m;
		int m_next = min(b[i], a[i + 1]);
		a[i + 1] -= m_next;
		total_monsters += m_next + m;
	}

	cout << total_monsters << "\n";

	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;
int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	vector<int>x(N);
	vector<int>y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	int ans = MOD;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j)
				continue;
			int cx = x[j] - x[i];
			int cy = y[j] - y[i];
			int cnt = 0;
			for (int k = 0; k < N; k++) {
				for (int l = 0; l < N; l++) {
					if (cx == x[l] - x[k] && cy == y[l] - y[k])
						cnt++;
				}
			}
			ans = min(ans, N - cnt);
		}
	}
	cout <<ans<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
struct kDtree{
  class Node{
    public:
      int location;
      int p,l,r;
      explicit Node(){}
  };
  class Point{
    public:
      int id,x,y;
      explicit Point(){}
      explicit Point(int id, int x, int y): id(id),x(x),y(y){}
      bool operator<(const Point &p)const{
        return id < p.id;
      }
      void print(){
        printf("%d\n",id);
      }
  };

  static const int NIL = -1;

  int N;
  vector<Point> P;
  vector<Node> T;
  int np;

  kDtree(){}
  kDtree(int N){init(N);}

  void init(int N_){
    N=N_;
    P.clear();
    T.clear();
    P.resize(N);
    T.resize(N);
  }

  static bool lessX(const Point &p1, const Point &p2){return p1.x<p2.x;}
  static bool lessY(const Point &p1, const Point &p2){return p1.y<p2.y;}

  int makekDtree(int l, int r, int depth){
    if(!(l<r)) return NIL;
    int mid=(l+r)/2;
    int t = np++;
    // 2次元なので2で割った余りで次元ごとに分けて行く
    if(depth%2==0){
      sort(P.begin()+l,P.begin()+r,lessX);
    } else {
      sort(P.begin()+l,P.begin()+r,lessY);
    }
    T[t].location=mid;
    T[t].l=makekDtree(l,mid,depth+1);
    T[t].r=makekDtree(mid+1,r,depth+1);
    return t;
  }

  void find(int v,int sx, int tx, int sy, int ty, int depth, vector<Point> &ans){
    int x = P[T[v].location].x;
    int y = P[T[v].location].y;
    if(x>=sx&&x<=tx&&y>=sy&&y<=ty) ans.push_back(P[T[v].location]);
    // 子はxで分割されている
    if(depth % 2 == 0) {
      if(T[v].l != NIL) {
        if(x>=sx) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
      }
      if(T[v].r != NIL) {
        if(x<=tx) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
      }
    } else {
      if(T[v].l != NIL) {
        if(y>=sy) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
      }
      if(T[v].r != NIL) {
        if(y<=ty) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
      }
    }
  }
};
int main()
{
  int x,y;
  int N;
  cin >> N;
  kDtree kd(N);
  FOR(i,0,N) {
    scanf("%d %d", &x, &y);
    kd.P[i] = kDtree::Point(i, x, y);
    kd.T[i].l = kd.T[i].r = kd.T[i].p = kd.NIL;
  }
  kd.np = 0;
  int root = kd.makekDtree(0, N, 0);

  int q;
  cin >> q;
  int sx,tx,sy,ty;
  vector<kDtree::Point> ans;
  FOR(i,0,q) {
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    kd.find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(), ans.end());
    for(auto a : ans) a.print();
    cout << endl;
  }
}


Measured memory_bytes: 15992
n, x = gets.chomp.split(' ').map(&:to_i)
l = gets.chomp.split(' ').map(&:to_i)
d = 0
c = 1

l.each do |i|
  d += i
  if d > x
    print(c)
    exit
  end
  c += 1
end

print(c)


Measured memory_bytes: 1788
import math

x,k,d = map(int,input().split())

ans = 0
if x == 0:
    if k%2 == 0:
        ans = 0
    elif k%2 == 1:
        ans = abs(d)
else :
    if abs(x) - k*d >= 0:
        ans = abs(abs(x) - k*d)
        #if abs(x) - k*d == 0:
            #if k - (abs(x) / (k * d)) % 2 == 0:
                #ans = 0
            #else:
                #ans = abs(x)
    elif abs(x) - k*d < 0:
        if  abs(x) - d*(abs(x) // d) != 0:
            if (k - (math.ceil(abs(x) / d) )) % 2 == 1:
                ans = abs(abs(x) - d*(abs(x) // d))
            else:
                ans = abs(abs(x) - d*(abs(x) // d + 1))
        else:
            if (k - (math.ceil(abs(x) // d) ) ) % 2 == 1:
                ans = d
            else:
                ans = 0
print(ans)


Measured memory_bytes: 9176