akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

vector<int> tree[200005];
int ans[200005];

void dfs(int v, int p = -1){
  for(int u : tree[v]){
    if(u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main(){
  int N, Q;
  cin >> N >> Q;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  rep(i,Q){
    int p;
    int x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  dfs(0);
  rep(i,N){
    cout << ans[i] << " ";
  }
  cout << endl;
}



Measured memory_bytes: 23424
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

using namespace std;
const long long MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    long long a,b;
    cin >> a >> b;
    if((a+b)%3!=0) {
        cout << 0 << endl;
        return 0;
    }
    COMinit();
    long long n = (2*b-a)/3;
    long long m = (2*a-b)/3;
    cout << COM(n+m,n) << endl;
}


Measured memory_bytes: 23680
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int maxx=max(max(a,b),c);
    int sum=a+b+c;
    printf("%d\n",sum-maxx);
    return 0;
}


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

using namespace std;

int main() {
    int N;;
    string S;
    cin>>N>>S;
    if(N%2!=0){
        cout<<"No"<<endl;
    }else{
        string tmp="";
        string tmpp="";
        for(int i=0;i<N/2;i++){
            tmp+=S[i];
        }
        for(int i=N/2;i<N;i++){
            tmpp+=S[i];
        }
        if(tmp==tmpp){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        double d,t,s; cin >> d >>t >> s;
        double taken = d/s;
        if(taken > t){
            cout << "No";
        }
        else cout << "Yes";
    }    
}

Measured memory_bytes: 3736
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define		CH		ch=(getchar())

inline		int		IN(){
	int x=0,f=1;char ch;
	for (CH;ch>'9'||ch<'0';CH) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';CH) (x*=10)+=ch-'0';
	return x*f;
}

int i,j,k,l,n,m,a,b,c,d,r,ans;

int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	l=max(a,c);
	r=min(b,d);
	ans=r-l;
	if (ans<0) puts("0");
	else printf("%d",ans);
}


Measured memory_bytes: 128
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B;
	cin >> A >> B;

	rep(i, 0, 10001)
	{
		if (i * 8 / 100 == A && i * 10 / 100 == B)
		{
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define INF 1000000007
#define ull unsigned long long
#define PI 3.141592653589793238
#define pb push_back
#define max3(x, y, z) Max(x, Max(y, z))
#define min3(x, y, z) Min(x, Min(y, z))
#define mp make_pair
#define pre(a,b) cout << fixed << setprecision(a) << b  //a for precision b for answer
#define MAX 1e18
#define all(x) (x).begin(), (x).end()
#define lb lower_bound //lower_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘x’.
#define ub upper_bound //upper_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘x’.
#define maxe *max_element
#define mine *min_element
#define acc(x) accumulate(x.begin(), x.end(), 0)
#define dst distance
#define sz(x) (int)x.size()

template <typename T>
inline T const& Max (T const& a, T const& b)
{ 
	return a < b ? b:a; 
}

template <typename T>
inline T const& Min (T const& a, T const& b) { 
   return a < b ? a:b; 
}

ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}

ll SieveOfEratosthenes(int n) 
{  
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    {  
        if (prime[p] == true) 
        {   
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    /*for (int p=2; p<=n; p++) 
       if (prime[p]) 
          cout << p << " "; */
    return prime[n + 1];
}

int main()
{
	IOS;
	int h, w;
    cin >> h >> w;
    char a[h][w];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
    }
    int dp[h][w];
    memset(dp, 0, sizeof(dp));
    int i = 0, j = 0;
    while (i < h and a[i][0] == '.')
    {
        dp[i][0] = 1;
        i++;
    }
    while (j < w and a[0][j] == '.')
    {
        dp[0][j] = 1;
        j++;
    }

    for (int i = 1; i < h; i++)
    {
        for (int j = 1; j < w; j++)
        {
            if (a[i][j] == '.')
            {
                if (a[i - 1][j] == '.' and a[i][j - 1] == '.')
                {
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                }
                else if (a[i - 1][j] == '.')
                {
                    dp[i][j] = dp[i - 1][j];
                }
                else if (a[i][j - 1] == '.')
                {
                    dp[i][j] = dp[i][j - 1];
                }
                else
                {
                    dp[i][j] = 0;
                }
                dp[i][j] %= INF;
            }
        }
    }

    cout << dp[h - 1][w - 1] << '\n';
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define MAX 105

vector<vector<int> > vec;
vector<int> ve;
int dis[MAX];
queue<int> Q;
int n;

int search(int start, int end) {
	while(!Q.empty()) Q.pop();
	Q.push(start);
	for (int i = 1; i <= n; i++) {
		dis[i] = 0;
	}
	int now, len = 0;
	while (!Q.empty()) {
		now = Q.front();
		Q.pop();
		if (now == end)
			return dis[now];
		if (dis[now] == len)
			len++;
		for (int cnt = 1; cnt <= vec[now][0]; cnt++) {
			if (dis[vec[now][cnt]] == 0) {
				dis[vec[now][cnt]] = len;
				Q.push(vec[now][cnt]);
			}
		}
	}
	return -1;
}

int main(void) {
	vec.push_back(ve);
	int u, k, v, i;
	cin >> n;
	for (i = 1; i <= n; i++) {
		ve.clear();
		cin >> u >> k;
		ve.push_back(k);
		while (k--) {
			cin >> v;
			ve.push_back(v);
		}
		vec.push_back(ve);
	}

	for (i = 1; i <= n; i++) {
		cout << i << " " << search(1, i) << endl;
	}
	
}


Measured memory_bytes: 3172
n , k , q  = map(int,input().split())
lis = []
for i in range(n):
  lis.append(k)
b = []
for i in range(q):
  b.append(int(input()))

for i in range(len(b)):
  lis[b[i]-1]-=1

for i in range(n):
  lis[i]= k+(-q+(k-lis[i]))
  if lis[i]>0:
    print("Yes")
  else:
    print("No")  

Measured memory_bytes: 11744
#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<algorithm>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 101;
int a[N];
int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	forn(i,2 * n) cin >> a[i];
	sort(a, a + 2 * n);
	ll ans = 0;
	for(int i = 0; i < 2 * n; i+=2){
		ans += min(a[i],a[i + 1]);
	}
	cout << ans << endl;
  	return 0;
}


Measured memory_bytes: 384
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = [list(map(int, input().split())) for _ in range(m)]

lst = t.copy()

for i in range(m):
    lst[p[i][0]-1] = p[i][1]
    print(sum(lst))
    lst = t.copy()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
#define N 100010
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
priority_queue<int> q;
vector<int> c[N];
struct job{
	int t,val;
}a[N];
int n,m,ans=0;
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		a[i].t=read(),a[i].val=read();
		if(a[i].t>m)continue;
		c[m-a[i].t].push_back(a[i].val);
	}
	for(int i=m-1;i>=0;i--){
		for(int j=0;j<c[i].size();j++){
			q.push(c[i][j]);
		}
		if(!q.empty()){
			ans+=q.top();
			q.pop();
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6400
S = gets.chomp.split("")
T = gets.chomp.split("")

indexes = {
  'a' => [],
  'b' => [],
  'c' => [],
  'd' => [],
  'e' => [],
  'f' => [],
  'g' => [],
  'h' => [],
  'i' => [],
  'j' => [],
  'k' => [],
  'l' => [],
  'm' => [],
  'n' => [],
  'o' => [],
  'p' => [],
  'q' => [],
  'r' => [],
  's' => [],
  't' => [],
  'u' => [],
  'v' => [],
  'w' => [],
  'x' => [],
  'y' => [],
  'z' => []
}

S.each_with_index do |char, index|
  indexes[char].push(index)
end

pos = -1
loop_count = 0
T.each do |char|
  index = indexes[char].bsearch{ |i| i > pos }
  if index.nil?
    loop_count += 1
    index = indexes[char].first
    if index.nil?
      puts '-1'
      exit
    end
  end

  pos = index
end

puts loop_count * S.count + pos + 1

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

const int inf=1e9+7;
const ll longinf=1LL<<60;
const ll mod=1e9+7;


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

int main(){
    mod_build(1010101);
    ll x, y;
    cin >> x >> y;
    if((x+y)%3 != 0){
        cout <<"0"<<endl;
        return 0;
    }
    
    ll n,m;
    m = (-y+2*x)/3;
    n = x-2*m;

    if (n < 0 || m < 0){
        cout <<"0"<<endl;
        return 0;
    }
    ll ans = comb(n+m,n);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 23936
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    if(s=="Sunny")cout<<"Cloudy"<<endl;
    else if(s=="Rainy")cout<<"Sunny"<<endl;
    else cout<<"Rainy"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

struct Point{double x,y;};

void koch(int,struct Point ,struct Point);

int main(){
    struct Point a,b;
    int n;
    
    scanf("%d",&n);
    
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;
    
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    
    return 0;
}

void koch(int n,struct Point a,struct Point b){
    if(n == 0)return;
    struct Point s,t,u;
    double th = M_PI * 60/180;
    
    s.x = (2.0 * a.x + 1.0 * b.x)/3.0;
    s.y = (2.0 * a.y + 1.0 * b.y)/3.0;
    t.x = (1.0 * a.x + 2.0 * b.x)/3.0;
    t.y = (1.0 * a.y + 2.0 * b.y)/3.0;
    u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th)+s.x;
    u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th)+s.y;
    
    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}


Measured memory_bytes: 2080
#include <iostream>
#include <vector>
#include <algorithm>

#define MAX_FLOWERS 200001

using namespace std;

long long beauties[MAX_FLOWERS];
long long heights[MAX_FLOWERS];
long long dp[MAX_FLOWERS + 1]; // The dp in this case corresponds to the maximum beauty so far if the last taken flower has height i.

int main()
{
    long long nFlowers, pretty, height, ans = 0, base  = 1;
    cin >> nFlowers;

    while(base <= nFlowers)
        base *= 2; 

    vector<long long> tree(2 * base);

    for (long long i = 0; i < nFlowers; i++)
    {
        cin >> height;
        heights[i] = height;
    }

    for (long long i = 0; i < nFlowers; i++)
    {
        cin >> pretty;
        beauties[i] = pretty;
    }

    for(long long i = 0; i < nFlowers; i++)
    {   
        long long x = heights[i] + base;
        long long bestSoFar = 0;
        while(x > 1)
        {
            if(x % 2)
                bestSoFar = max(bestSoFar, tree[x-1]);
            x /= 2;
        }

        dp[heights[i]] = bestSoFar + beauties[i];

        for(long long j = base + heights[i]; j >= 1; j /= 2)
            tree[j] = max(tree[j], dp[heights[i]]);
    }

    for(long long i = 0; i <= nFlowers; i++)
    {
        if (dp[i] > ans)
            ans = dp[i];
    }
    cout << ans;
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
   int n;cin>>n;
   string s;cin>>s;
   s=to_string(n);
   if(s[0]==s[2])cout<<"Yes";
   else cout<<"No";
}

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

using namespace std;

struct node {
	int parent;
	int left;
	int right;
};

vector<node> tree;

void preorder_walk(int ind) {
	if (ind < 0) {
		return;
	}
	cout << " " << ind;
	preorder_walk(tree[ind].left);
	preorder_walk(tree[ind].right);
	return;
}

void inorder_walk(int ind) {
	if (ind < 0) {
		return;
	}
	inorder_walk(tree[ind].left);
	cout << " " << ind;
	inorder_walk(tree[ind].right);
	return;
}

void postorder_walk(int ind) {
	if (ind < 0) {
		return;
	}
	postorder_walk(tree[ind].left);
	postorder_walk(tree[ind].right);
	cout << " " << ind;
	return;
}


int main(void) {
	int n;
	cin >> n;
	tree = vector<node>(n);
	for (int i = 0; i < n; ++i) {
		tree[i].parent = -1;
	}
	int id;
	for (int i = 0; i < n; ++i) {
		cin >> id;
		cin >> tree[id].left >> tree[id].right;
		if (tree[id].left >= 0) {
			tree[tree[id].left].parent = id;
		}
		if (tree[id].right >= 0) {
			tree[tree[id].right].parent = id;
		}
	}
	int root;
	for (int i = 0; i < n; ++i) {
		if (tree[i].parent < 0) {
			root = i;
			break;
		}
	}
	cout << "Preorder" << endl;
	preorder_walk(root);
	cout << endl;
	cout << "Inorder" << endl;
	inorder_walk(root);
	cout << endl;
	cout << "Postorder" << endl;
	postorder_walk(root);
	cout << endl;
	return 0;
}



Measured memory_bytes: 3152
# -*- coding: utf-8 -*-
N,K = list(map(int,input().split()))
S = input().replace("10","1 0").replace("01","0 1").split()
#はじめと終わりの値を記録
S0 = int(S[0][0])
Send = int(S[-1][-1])

S = list(map(len,S))
if S0 == 0:
    S.insert(0,0)
if Send == 0:
    S.append(0)
#0010 -> S=[0,2,1,1,0],S0=0,Send=0

ret = 0

if (len(S)-1)//2<= K:
    #0の塊がK以下なら
    print(sum(S))
    import sys
    sys.exit()
else:
    window_size = 1 + K * 2
    ret = sum(S[0:window_size])
    cur_range_val = ret
    start_index = 2
    while start_index + window_size <= len(S):
        cur_range_val = cur_range_val - S[start_index-2] - S[start_index-1] + S[start_index+window_size-2] + S[start_index+window_size-1]
        start_index+=2
        if cur_range_val > ret:
            ret = cur_range_val
print(ret)


Measured memory_bytes: 5508
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p[2000005],inv[2000005],pre[3000005],hell=pow(10,9)+7;
ll exp(ll x,ll y){
    ll res=1;
    x%=hell;
    while(y>0){
        if(y&1)
        res=(res*x)%hell;
        y>>=1;
        x=(x*x)%hell;
    }
    return res;
}
ll bin(ll n,ll r){
    ll sum=p[n];
    sum*=inv[r];
    sum%=hell;
    sum*=inv[n-r];
    sum%=hell;
    return sum;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    ll r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    p[0]=1;
    inv[0]=1;
    for(ll i=1;i<2000005;i++){
        p[i]=(i*p[i-1])%hell;
        inv[i]=exp(p[i],hell-2);
    }
    ll res=bin(r1+c1,c1);
    for(ll i=c1+1;i<=c2;i++){
        res+=bin(r2+i,i);
        res%=hell;
    }
    for(ll i=r1+1;i<=r2;i++){
        res+=bin(i+c2,c2);
        res%=hell;
    }
    cout<<res;
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
	int n;
	cin >> n;
	rep(i, 0, n){
		int a[3];
		rep(j, 0, 3) cin >> a[j];
		sort(a, a + 3);
		if(a[0] * a[0] + a[1] * a[1] == a[2] * a[2]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 3040
N = int(input())
W = list(map(int, input().split()))

min_gap = None

for T in range(1, N):
    gap = abs(sum(W[:T]) - sum(W[T:]))

    if min_gap is None:
        min_gap = gap
    else:
        min_gap = min(min_gap, gap)

print(min_gap)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int arr[1000]={};
void primeN(int n){
	int x=n;
	for (int i=2; i<=n; i++){
		while (x%i==0){
			arr[i]++;
			x/=i;
		}
	}
}
int main(){
 
	int N;
	cin>>N;
	
	for (int i=2; i<=N; i++){
		primeN(i);
	}
	
	//for (int i=0; i<=N;i++){
	//	cout << arr[i] << " ";
	//}cout << endl;
	long long x = 1;
	for (int i=0; i<=N; i++){
		x*=(arr[i]+1);
		x%=1000000007;
	}
	cout << x << endl;
}


Measured memory_bytes: 256
#create date: 2020-06-28 21:45

import sys
stdin = sys.stdin
import numpy as np

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

def main():
    d = ni()
    c = np.array(na())
    s = list()
    for i in range(d):
        a = na()
        s.append(a)
    t = [i % 26 + 1 for i in range(d)]
    print(*t, sep="\n")

if __name__ == "__main__":
    main()

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

using namespace std;

int a[2][110];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[0][i];
  }
  for (int i = 0; i < n; i++) {
    cin >> a[1][i];
  }
  for (int i = 1; i < n; i++) {
    a[0][i] += a[0][i - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    a[1][i] += a[1][i + 1];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = a[0][i] + a[1][i];
    if (ans < sum) {
      ans = sum;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX_H 100
#define MAX_W 100
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int H, W;
char a[MAX_H][MAX_W];

int main(void)
{
  cin >> H >> W;
  REP(i, H) REP(j, W) cin >> a[i][j];

  map<int, int> h, w;
  for (int i = 0; i < H; i++) {
    bool f = true;
    for (int j = 0; j < W; j++) {
      if (a[i][j] != '.') {
        f = false;
        break;
      }
    }
    if (f) h[i]++;
  }

  for (int i = 0; i < W; i++) {
    bool f = true;
    for (int j = 0; j < H; j++) {
      if (a[j][i] != '.') {
        f = false;
        break;
      }
    }
    if (f) w[i]++;
  }

  if (w.size() == W || h.size() == H) {
    cout << "#" << endl;
    return 0;
  }

  for (int i = 0; i < H; i++) {
    if (h.count(i) > 0) continue;
    for (int j = 0; j < W; j++) {
      if (w.count(j) > 0) continue;
      cout << a[i][j];
    }
    cout << endl;
  }

  return 0;
}


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

typedef long long ll;
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; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
int main() {
	int N, ans=0, tmp=0;
	cin >> N;
	for (int i = 1; i <= N; i+=2) {
		tmp = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) {tmp++;}
		}
		if (tmp == 8) {ans++;}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <iostream>

using namespace std;

namespace {

struct Process {
  char name[10];
  // required time to process this task.
  int time;
};

// Ring-buffer based queue. Enqueue and dequeue run in O(1).
template <typename T, int N>
class Queue {
 public:
  // Note: leave one element empty so that we can distinguish
  // that the ring buffer is empty or full.
  Queue()
      : size_(N + 1),
        begin_((T*)data_),
        end_((T*)data_ + N + 1),
        head_((T*)data_),
        tail_((T*)data_) {}

  void Enqueue(T p) {
    assert(!IsFull());
    *tail_ = p;
    tail_ = next(tail_);
  }

  T Dequeue() {
    assert(!Empty());
    auto p = head_;
    head_ = next(head_);
    return *p;
  }

  bool IsFull() const { return head_ == next(tail_); }

  bool Empty() const { return head_ == tail_; }

 private:
  T* next(T* p) const { return p + 1 == end_ ? begin_ : p + 1; }

  char data_[sizeof(T) * (N + 1)];
  const int size_;
  T* const begin_;
  T* const end_;
  T* head_;
  T* tail_;
};

}  // namespace

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

  Queue<Process, 100000> queue;
  for (int i = 0; i < n; ++i) {
    Process p;
    cin >> p.name >> p.time;
    queue.Enqueue(p);
  }

  int current_time = 0;
  while (!queue.Empty()) {
    auto p = queue.Dequeue();
    const int used = min(p.time, q);
    p.time -= used;
    current_time += used;

    if (p.time <= 0) {
      printf("%s %d\n", p.name, current_time);
      continue;
    }
    queue.Enqueue(p);
  }
  return 0;
}

Measured memory_bytes: 4572
#include <iostream>

using namespace std;

int main()
{
    int a[5];
    for(int i=0;i<5;i++){
        cin>>a[i];
        
    }
    
    for(int j=0;j<5;j++){
        if(a[j]==0)
        cout<<j+1;
    }

    return 0;
}


Measured memory_bytes: 3564
#include <iostream>

int main(){
   int D;
   std::cin >> D;

   switch(D){
      case 22:
	 std::cout << "Christmas Eve Eve Eve" << std::endl;
	 break;
      case 23:
	 std::cout << "Christmas Eve Eve" << std::endl;
	 break;
      case 24:
	 std::cout << "Christmas Eve" << std::endl;
	 break;
      case 25:
	 std::cout << "Christmas" << std::endl;
	 break;
   }

   return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
typedef long long int ll;
#define forn for(int i=1;i<=n;i++) 
#define form for(int i=0;i<m;i++) 
#define pb push_back 
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<"\n" 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
const ll MOD = 1e9 + 7;
const int N = 1005;
const ll INF = 1e9;
using namespace std;
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
     double a,b;
     cin>>a>>b;
     cout<<ceil(a/b);
     return 0;
}

Measured memory_bytes: 764
package main

import "fmt"

func main() {
	var W, H, x, y int
	fmt.Scan(&W, &H, &x, &y)
	vert := W == x*2
	horz := H == y*2
	fmt.Printf("%.1f ", float64(W)*float64(H)/2.0)
	if x == 0 || x == W || y == 0 || y == H {
		fmt.Printf("0\n")
	} else if vert && horz {
		fmt.Printf("1\n")
	} else {
		fmt.Printf("0\n")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int num[102][102];

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

  int x=N*(N-1)/2;
  x/=2;

  for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) num[i][j]=1;

  int sum=0;
  for(int i=1;i<=N;i++){
    if(i==2) continue;
    if(sum==K) break;
    for(int j=i+1;j<=N;j++){
      if(sum==K) break;
      if(j==2) continue;

      num[i][j]=0;
      sum++;
    }
  }

  if(sum<K){
    cout<<-1<<endl;
    return 0;
  }

  int m=0;
  for(int i=1;i<=N;i++) for(int j=i+1;j<=N;j++) if(num[i][j]) m++;

  cout<<m<<endl;
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      if(num[i][j]) cout<<i<<" "<<j<<endl;
    }
  }



  return 0;
}


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

	    public static void main(String[] args) throws java.io.IOException{
	        Scanner scan = new Scanner(System.in);
	       
	        while(true){
	        	
	        	int n=scan.nextInt();
	        	if(n==0)break;
	        	int count=0;
	        	int sum=0;
	        	for(int i=2;;i++){
	        		if(prime(i)){
	        			count++;
	        			sum+=i;
	        			if(count==n)break;
	        		}
	        	}
	        	System.out.println(sum);
	        }
	    }
	     public static boolean prime (int n){
	            if(n==1)return false;
	            for(int i=2;i<=Math.sqrt(n);i++)
	                if(n%i==0)return false;
	            return true;
	        }
}
	    

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef  double ld;
vector<ld> p;
ld dp[3000][3000];
int n;
int main()
{
    
    cin>>n;
    p.resize(n);
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
    {ld x;
    cin>>x;
    p[i]=x;

        
    }
    dp[0][0]=1-p[0];
    dp[0][1]=p[0];
for(int i=1;i<n;i++)
{
    for(int j=0;j<=i+1;j++)
    {
        if(j==0)
        {
            dp[i][j]=(1-p[i])*dp[i-1][0];
        }
        else
        {
            dp[i][j]=p[i]*dp[i-1][j-1]+(1-p[i])*dp[i-1][j];
        }
    }
}
ld ans=0;
for(int j=(n/2)+1;j<=n;j++)
{
    ans+=dp[n-1][j];
}
cout<<setprecision(12)<<ans;
}

Measured memory_bytes: 74120
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

ll gcd(ll a,ll b){
	ll c = b;
	while(a%b!=0){
		c = b;
		b = a%b;
		a = c;
	}
	return b;
}
int main(void){
	ll A,B,C,D,E,F;
	cin >> A >> B >> C >> D;
	// C と D の最大公倍数は E
	E = C*D/gcd(C,D);
	ll a = (A-1)/C + (A-1)/D - (A-1)/E;
	ll b = B/C + B/D - B/E;
	ll ans = B - (A-1) - (b - a);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

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

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n, x; cin >> n >> x;
  vll a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  rep(i, n-1) {
    if (a[i] + a[i+1] > x) {
      ll diff = (a[i+1] + a[i]) - x;
      ans += diff;

      if (a[i+1] < diff) {
        diff -= a[i+1];
        a[i+1] = 0;
        a[i] -= diff;
      } else a[i+1] -= diff;
    }
  }

  cout << ans << endl;
  
  return (0);
}

Measured memory_bytes: 3964
#include<stdio.h>
#define N 200000
int A[N],n;


void Partition(int p,int r){
  int i,j,k,X;

  i=A[r];
  j=p-1;

  for(k=p;k<=r-1;k++){
    if(A[k]<=i){
      j++;
      X=A[j];
      A[j]=A[k];
      A[k]=X;
    }
  }

  X=A[j+1];
  A[j+1]=A[r];
  A[r]=X;

  for(k=0;k<n;k++){
    if(k==j+1)printf("[%d]",A[k]);
    else if(k!=n) printf("%d",A[k]);
    if(k!=n-1) printf(" ");
  }
  printf("\n");
}

int main(void){

  int j;

  scanf("%d",&n);

  for(j=0;j<n;j++){
    scanf("%d",&A[j]);
  }

 Partition(0,n-1);

  return 0;
}

Measured memory_bytes: 808
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(
        x: usize,
        y: usize,
        z: usize,
        k: usize,
        mut alist: [usize; x],
        mut blist: [usize; y],
        mut clist: [usize; z]
    );

    alist.sort_by(|a, b| b.cmp(&a));
    blist.sort_by(|a, b| b.cmp(&a));
    clist.sort_by(|a, b| b.cmp(&a));

    let mut ab = vec![];
    for i in 0..x {
        for j in 0..y {
            ab.push(alist[i] + blist[j]);
        }
    }
    ab.sort_by(|a, b| b.cmp(&a));
    // 上位K番目までを残し、他は切り捨て
    let ab: Vec<usize> = ab.iter().take(k).cloned().collect();

    let mut abc = vec![];
    for i in 0..ab.len() {
        for j in 0..z {
            abc.push(ab[i] + clist[j]);
        }
    }
    abc.sort_by(|a, b| b.cmp(&a));

    for i in 0..k {
        println!("{}", abc[i]);
    }
}


Measured memory_bytes: 44276
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void)
{
    int n, l[12];
    cin >> n;
    int ma = 0, sum = 0;
    for (int i = 0; i < n;i++)
    {
        cin >> l[i];
        ma = max(ma, l[i]);
        sum += l[i];
    }
    if(ma<sum-ma)
        cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    bool ans = true;
    rep(i,n){
        cin >> a[i];
        if(a[i]%2 == 0){
            if((a[i]%3) == 0 || (a[i]%5) == 0){}
            else ans = false;
        }
    }
    if (ans) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
d, g = map(int, input().split())

p = []
c = []

for i in range(d):
    pi, ci = map(int, input().split())
    p.append(pi)
    c.append(ci)

def two_list(d):
    if d == 1:
        return [[0],[1]]
    else:
        res = []
        prevlist = two_list(d-1)
        for l in prevlist:
            tmp = l + [0]
            res.append(tmp)
            tmp = l + [1]
            res.append(tmp)
        return res

s = []
for i in range(d):
    sump = 100 * (i+1) * p[i] + c[i]
    s.append(sump)

minp = sum(p)

for twolist in two_list(d):
    sumall = 0
    sumnum = 0
    for i in range(d):
        sumall += s[i] * twolist[i]
        sumnum += p[i] * twolist[i]
    if 0 in twolist:
        max0 = d - twolist[::-1].index(0)
    else:
        break
    if sumall >= g:
        minp = min(minp, sumnum)
    elif sumall < g and (g-sumall) < s[max0-1]:
        add = (g-sumall)//(100*max0)
        sumnum += add
        if (g-sumall)%(100*max0) != 0:
            sumnum += 1
        minp = min(minp, sumnum)

print(minp)



Measured memory_bytes: 40816
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 1000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define P pair<int,int> 
#define INF 1000000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	int a,b;
    cin>>a>>b;
    if(a<b) swap(a,b);
    REP(i,a){
        printf("%d",b);
    }
    printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	char ch[27];
	scanf("%s", ch);
	for(int i = 0; ch[i]; i++)
	for(int j = 0; j < i; j++) if(ch[i] == ch[j]){
		printf("no\n");
		return 0;
	}
	printf("yes\n");
	return 0;
}

Measured memory_bytes: 128
from itertools import permutations
N = int(input())
P = list(map(int,input().split()))
#s = [int(input()) for i in range(3)]
Q = list(map(int,input().split()))
per = [i for i in range(1,N+1)]
per = permutations(per)
count = 0
for i in per:
    count += 1
    if list(i) == P:
        p = count
    if list(i) == Q:
        q = count
print(abs(p-q))

Measured memory_bytes: 3064
N = int(input())
*A, = map(int, input().split())

B = [0] + A + [0]
s = 0

for i in range(N+1):
    s += abs(B[i+1] - B[i])

ans = []
for i in range(1, N+1):
    ans.append(s - abs(B[i] - B[i-1]) - abs(B[i+1] - B[i]) + abs(B[i+1] - B[i-1]))
print(*ans, sep='\n')

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  vector<int> P(0);
  int sum = 0;
  
  for(int i = 0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  
  for(int i = 0; i < N; i++){
    if(A[i]*4*M >= sum)
      P.push_back(A[i]);
  }
  
  if(P.size() >= M)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3624
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, p = sc.nextInt
  val ax = Array.fill(n)(sc.nextInt)
    
  def factUntil(n: BigInt, end: BigInt): BigInt = {
    if (n == end) 1
    else n * factUntil(n-1, end)
  }
    
  def comb(a: Long, b: Long): Long = {
    (factUntil(a, b) / factUntil(a-b, 0)).toLong
  }
    
  val ax01 = ax.map(_ % 2)
  val cnt0 = ax01.filter(_ == 0).size
  val cnt1 = ax01.size - cnt0
    
  val even = Math.pow(2, cnt0).toLong
    
  var ans: Long = 0
  for (i <- 0 to cnt1 if i % 2 == p) {
      
    ans += even * comb(cnt1, i)
  }

  println(ans)
}

Measured memory_bytes: 26016
local floor = math.floor
local min = math.min
local N = io.read("*n")

local function idiv(operand1, operand2)
	return floor(operand1 / operand2)
end

local function sumDigits(num)
	local sum = 0
	while num > 0 do
		sum = sum + num % 10
		num = idiv(num, 10)
	end
	return sum
end

local out = 100001
for A = 1, idiv(N, 2) do
	local B = N - A
	local sum = sumDigits(A) + sumDigits(B)
	out = min(out, sum)
end

print(out)


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, k; cin >> n >> k;
    vint a(n);
    rep(i,n) cin >> a[i];
    rep(i,k) {
        vint c(n+1,0);
        rep(j,n) {
            c[max(j-a[j],0)]++;
            c[min(j+a[j]+1,n)]--;
        }
        vint a_tmp(n);
        a_tmp[0] = c[0];
        REP(i,n) a_tmp[i] = a_tmp[i-1] + c[i];
        swap(a_tmp,a);
        bool ok = true;
        rep(i,n-1) {
            if (a[i] != a[i+1]) ok = false;
        }
        if (ok && a[0] == n) break;
    }
    rep(i,n) cout << a[i] << " ";
}

Measured memory_bytes: 5568
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<list>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 10000;

/*
  pos ã¯4åé£ç¶ã«ãªã£ãä½ç½®
 */
int solve(int n,int pos,vector<pair<int,int> > in){
  int l = pos,r = pos;
  int tmp = -in[pos].second;//ï¼åãããã
  while(0 <= l && (in[l].second == 0 || in[l].first == in[pos].first))tmp += in[l].second,l--;
  while(r < (int)in.size() && (in[r].second == 0 || in[r].first == in[pos].first) )tmp += in[r].second,r++;
  if (tmp < 4)return n;
  n -= tmp;

  while(true){
    if (l < 0 || r == in.size())break;
    if (in[l].first != in[r].first)break;
    if (in[l].second + in[r].second < 4)break;
    n = n -(in[l].second+in[r].second);
    l--;r++;
  }
  return n;
}

main(){
  int n;
  while(cin>>n &&n){
    int prev = -1,cnt=0;
    vector<pair<int,int> > a;
    rep(i,n){
      int tmp;
      cin>>tmp;
      if (tmp != prev){
	if (prev != -1){
	  a.push_back(make_pair(prev,cnt));
	}
	prev = tmp;
	cnt = 1;
      }else cnt++;
    }
    a.push_back(make_pair(prev,cnt));
    //rep(i,a.size())cout <<"(" << a[i].first <<"," << a[i].second <<") ";cout << endl;
    int mini = n;
    rep(i,(int)a.size()){
      if (i-1 >= 0){
	a[i].second--;a[i-1].second++;
	mini=min(mini,solve(n,i-1,a));
	a[i].second++;a[i-1].second--;
      }
      if (i+1 < a.size()){
	a[i].second--;a[i+1].second++;
	mini=min(mini,solve(n,i+1,a));
	a[i].second++;a[i+1].second--;
      }
    }
    cout << mini << endl;
  }
}

Measured memory_bytes: 1020
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
answer = 0
for i in range(N-1, -1, -1):
    x = A[i] + answer
    if x % B[i] == 0:
        continue
    answer += B[i] - (x % B[i])
print(answer)

Measured memory_bytes: 11048
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	n %= 10;
	if (n == 3)
		printf("bon\n");
	else if (n == 0 || n == 1 || n == 6 || n == 8)
		printf("pon\n");
	else
		printf("hon\n");
	return 0;
}

Measured memory_bytes: 1644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
     
    public static void main(String[] args) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
            String[] arr = str.split(" ");
            int a = Integer.parseInt(arr[0]);
            int b = Integer.parseInt(arr[1]);
            int c = Integer.parseInt(arr[2]);
             
            if(a < b && b < c) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}

Measured memory_bytes: 24200
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  vector<vector<char>> C(2, vector<char>(3));
  rep(i, 2) {
    rep(j, 3) { cin >> C[i][j]; }
  }

  bool yes = true;
  rep(i, 3) {
    if (C[0][i] != C[1][2 - i])
      yes = false;
  }
  if (yes)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
 ll n,a,b;
  cin>>n>>a>>b;
  if(a==0){
   cout<<0<<endl;
  }
  else{
   ll output=a*(n/(a+b))+min(n%(a+b),a);
    cout<<output<<endl;
  }
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <bitset>
#include <cmath>
#include <map>

using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
    int n; cin >> n;
    int a[n];
    vector<pair<int,int>> v(n);
    rep(i,n){
        cin >> a[i];
        v[i]=make_pair(a[i],i+1);
    }
    sort(v.begin(),v.end());
    rep(i,n) cout<<v[i].second << " ";
    
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k;
    long long int a,b,c,sum=0;
    while(cin>>a)
    {
        for(i=1;i<=a;i++)
        {
            sum=sum+i;
        }
        cout<<sum<<endl;
        sum=0;
    }
    return 0;
}


Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int i, j, cnt = 0;
  char hoge[5];
  scanf("%s", hoge);
  for (i = 0; i < 4; i++)
  {
    cnt = 0;
    for (j = 0; j < 4; j++)
    {
      if (hoge[i] == hoge[j])
        cnt++;
    }
    if (!(cnt == 2))
    {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 10e6
int cost[100][100];
bool used[100];
int mincost[100];
int n,m;

int prim(){
	for(int i=0;i<n;i++){
		mincost[i]=INF;
		used[i]=false;
	}
	mincost[0]=0;
	int res=0;
	while(true){
		int v=-1;
		for(int i=0;i<n;i++)
			if(!used[i]&&(v==-1||mincost[i]<mincost[v])) v=i;
		if(v==-1)
			break;
		used[v]=true;
		res+=mincost[v];
		for(int i=0;i<n;i++)
			mincost[i]=min(mincost[i],cost[i][v]);
	}
	return res;
}

int main(void){
	int a,b,d,result;
	char tem;
	while(cin >> n,n){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cost[i][j]=(i==j)?0:INF;
		cin >> m;
		for(int i=0;i<m;i++){
			cin >> a >> tem >> b >> tem >> d;
			cost[a][b]=cost[b][a]=d/100-1;
		}
		result=prim();	
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 1200