akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
#define a_macro(args...) sum(args)
#define mp make_pair
#define eb emplace_back
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

typedef long long ll;
const ll mod = 1e9+7;


int sum() { return 0; }

template<typename T, typename... Args>
auto sum(T a, Args... args) { return a + sum(args...); }
template<class T> bool uin(T &a,T b) {return a > b ? (a == b, true) : false; }
template<class T> bool uax(T &a,T b) {return a < b ? (a == b, true) : false; }

int main(int argc, const char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

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

    int dp[1<<n]={0};
    dp[0] = 1;

    for(i = 0;i < (1<<n)-1;++i){
    	int b = __builtin_popcount(i);
    	for(j = 0;j < n;++j)
    		if(a[b][j] && !(i&(1<<j))){
    			int m = i^(1<<j);
    			dp[m] = (dp[m] + dp[i]) % mod;
    		}
    }
    cout<<dp[(1<<n) - 1]<<"\n";
#ifndef LOCAL_DEFINE
    cerr << "Time elapsed: "<< 1e1 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif // LOCAL_DEFINE
    return 0;
}

Measured memory_bytes: 8448
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define int ll


signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    int dpc[51][51];
    rep(i,51)rep(j,51)dpc[i][j]=0;
    dpc[0][0] = 1;
    int dp[51][51];
    rep(i,51)rep(j,51)dp[i][j] = -INF;
    dp[0][0]=0;
    
    for(int i=1;i<=n;i++){
        for(int j=0;j<=b;j++){
            dp[i][j] = dp[i-1][j];
            dpc[i][j]=dpc[i-1][j];
            if(j-1<0)continue;
            if(dp[i][j]==dp[i-1][j-1]+v[i-1]){
                dpc[i][j]+=dpc[i-1][j-1];
            }
            else if(dp[i][j]<dp[i-1][j-1]+v[i-1]){
                dp[i][j] = dp[i-1][j-1]+v[i-1];
                dpc[i][j] = dpc[i-1][j-1];
            }
        }
    }
    double maxv=0;
    int c=0;
    for(int i=a;i<=b;i++){
        if(maxv*i==(double)dp[n][i]){
            c+=dpc[n][i];
        }
        else if(i*maxv<(double)dp[n][i]){
            c=dpc[n][i];
            maxv = (double)dp[n][i]/i;
        }
    }
    printf("%.20lf\n%ld\n",maxv,c);
}

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

int main() {
  int x1,x2,x3,x4,x5,answer;
  cin >> x1>>x2>>x3>>x4>>x5;

  if (x1==0) {
    /* code */answer = 1;
  }
  else if (x2==0) {
    answer = 2;
    /* code */
  }
  else if (x3==0) {
    /* code */answer = 3;
  }
  else if (x4==0) {
    /* code */answer = 4;
  }
  else{
    answer = 5;
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define sz(x) (ll)(x).size()
#define mpa make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"

const int mod=1e7;
const int mxN=1e5;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a*c,a*d), max(b*c,b*d));
}


Measured memory_bytes: 3648
n = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(n-1):
    if P[i] == i+1:
        P[i],P[i+1] = P[i+1],P[i]
        cnt += 1
if P[-1] == n:
    cnt += 1  
print(cnt)

Measured memory_bytes: 13880
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;
 
int main(){
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;scanf("%d",&k);
    printf("%d\n",a[k-1]);
}

Measured memory_bytes: 128
/**
 *    author:  FromDihPout
 *    created: 2020-07-28
**/

#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;

long long min_diff(long long h, long long w) {
    long long diff1 = (h % 3 != 0) * w;
    
    long long w1 = w / 2, w2 = (w + 1) / 2;
    long long l = 0, r = h, diff2 = INF;
    while (l <= r) {
        long long mid = (l + r) / 2;
        long long a1 = mid * w, a2 = (h - mid) * w1, a3 = (h - mid) * w2;
        diff2 = min(diff2, max({a1, a2, a3}) - min({a1, a2, a3}));
        
        if (a1 > max(a2, a3)) {
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    return min(diff1, diff2);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long h, w;
    cin >> h >> w;
    
    cout << min(min_diff(h, w), min_diff(w, h)) << '\n';
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s = " "){
  for(int i=0;i<(int)a.size();i++)cout<<(i? s:"")<<a[i];cout<<endl;
}


signed main(){
  int x,y;
  cin>>x>>y;
  int a = x;
  int ans = 0;
  while(y >= a){
    ans++;
    a += a;
  }
  cout<<ans<<endl;
  
  return 0;
}


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

int main(){
  int i, n, j, x, lim, count = 0;
  scanf("%d", &n);

  for (i = 0; i < n; i++){
    scanf("%d", &x);
    lim = sqrt(x);
    for (j = 2; j <= lim; j++){
      if(x % j == 0){
        count++;
        break;
      }
    }
  }
  printf("%d\n", n - count);
}



Measured memory_bytes: 3200
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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

	vector<string> grid(H);
	rep(i,H) cin >> grid[i];

	rep(i, W+2) cout << "#";
	cout << endl;
	
	rep(i,H) cout << "#" << grid[i] << "#" << endl;
	
	rep(i, W+2) cout << "#";
	cout << endl;

	return 0;
}

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


ll powmod(ll x, ll n, ll mod) {
    ll res = 1;
    if (n > 0) {
        res = powmod(x, n / 2, mod);
        if (n % 2 == 0) {
            res = (res * res) % mod;
        } else {
            res = (((res * res) % mod) * x) % mod;
        }
    }
    return res;
}


int main() {
    ll n;
    cin >> n;
    const ll mod = 1000000007;
    ll ans = powmod(10, n, mod) - powmod(9, n, mod) - powmod(9, n, mod) + powmod(8, n, mod);
    ans %= mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main()
{
	long long int n, k;
	scanf("%lld %lld", &n, &k);
	long long int i, j;
	int a[2003];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	long long int p = 1e9 + 7;
	long long int ans = 0;
	long long int c, d;
	for (i = 0; i < n; i++)
	{
		c = 0;
		for (j = i + 1; j < n; j++)
			if (a[j] < a[i])
				c++;
		d = 0;
		for (j = 0; j < n; j++)
			if (a[j] < a[i])
				d++;
		ans += c * k % p + d * ((k - 1) * k / 2 % p) % p;
		ans %= p;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
void swap(int a, int b){
    int temp = a;
    a = b;
    b = temp;
}

int main(void){
    long a = 0, b = 0, c = 0;
    cin >> a >> b >> c;
    if(a < b){
        swap(a, b);
    }
    if(a < c){
        swap(a, c);
    }
    if(b < c){
        swap(b, c);
    }
    cout << c << " " << a << endl;
    return 0;
}



Measured memory_bytes: 3104
import sys
input = sys.stdin.readline
#import math #python 3.5~
import fractions #fractions.gcd() python~3.4
sys.setrecursionlimit(1000000)

def main(): 
    N = int(input())
    H = list(map(int,input().split()))
    max=H[0]
    ans=1
    for i in range(1,N):
        if max <= H[i]:
            ans+=1
            max=H[i]
    print(ans)


if __name__ == "__main__":
    main()
    

Measured memory_bytes: 5048
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int ma, mi, ans=0, a, b=0;
	ma = max(h, w);
	mi = min(h, w);
	a = n;
	for (int i = 0;i < mi;i++) {
		if (b >= a)break;
		if(n-ma>=0)n -= ma;
		ans++;
		b +=ma;
	}
	if (b >= a) {
		cout << ans << endl;
		return 0;
	}
	for (int i = 0;i < ma;i++) {
		if (b >= a)break;
		if (n - mi >= 0)n -= mi;
		ans++;
		b += mi;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  map<int, int> mp;
  for(int i=0; i<n; i++){
    mp[a[i]] = 0;
  }
  for(int i=0; i<n; i++){
    mp[a[i]]++;
  }
  vector<int> num(2);
  for(auto p : mp){
    if(p.second>=2) num.push_back(p.first);
  }
   sort(num.rbegin(), num.rend());
   if(mp[num[0]]>=4) cout << (ll)num[0]*num[0] << endl;
   else cout << (ll)num[0] * num[1] << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

lli ps[440];
lli cache[440][440];

lli dp(lli l, lli r ) {

    if(l == r) {
        cache[l][r] = 0;
        return 0;
    }

    lli &ans = cache[l][r];

    if(ans != -1) {
        return ans;
    }
    ans = inf;

    for(int i = l; i < r; i ++) {
        ans = min(ans, dp(l, i) + dp(i + 1, r) + ps[r] - ps[l - 1]);
    }
    return ans;

}

void solve()
{

    memset(cache, -1, sizeof cache);
    lli n;
    cin>>n;
    lli a[n + 1];
    for(int i = 1; i <= n; i ++) {
        cin>>a[i];
        ps[i] = a[i] + ps[i - 1];
    }
    lli ans = dp(1, n);
    cout<<ans;
    cout<<"\n";
    return ;
}

/*
*/

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

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


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

int main() {
    int N, M; cin >> N >> M;
    vector<long long> X(M);
    for (int i = 0; i < M; ++i) cin >> X[i];
    sort(X.begin(), X.end());
        
    vector<long long> diffs;
    for (int i = 1; i < X.size(); ++i) diffs.push_back(X[i] - X[i-1]);
    sort(diffs.begin(), diffs.end(), greater<long long>());
        
    long long res = X.back() - X[0];
    for (int i = 0; i < min((int)diffs.size(), N-1); ++i) res -= diffs[i];
    cout << res << endl;
}

Measured memory_bytes: 5036
N = int(input())
a = [0] + list(map(int, input().split()))

b = [0] * (N + 1)
ans = []
for i in range(1,N+1)[::-1]:
    s = sum(b[i+i::i]) % 2
    if a[i] != s:
        b[i] = 1
        ans.append(i)

if ans == []:
    print(0)
else:
    print(len(ans))
    print(" ".join(map(str, ans)))

Measured memory_bytes: 19936
#include <bits/stdc++.h>
	#include <set>
	#define ll long long 
	#include <string>
	#define pb push_back
	#define mp make_pair
	# define pi 3.14159265358979323846
	#define mod 1000000007
	#define rep(i,n) for(i=0;i<n;i++)
	#define repk(i,k,n) for(i=k;i<n;i++)
	using namespace std;
	void fastio()
	{
		#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	    #endif
	    ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    cout.tie(NULL);

	}
	ll int multiply(ll int a,ll int b)
	{
		ll int ans=(a%mod*b%mod)%mod;
		return ans;
	}
	ll int add(ll int a, ll int b)
	{
		ll int ans=(a%mod+b%mod)% mod;
		return ans;
	}


	void solve()
	{
		ll int n;
		cin>>n;
		string s="ACL";
		ll int i;
		string ans;
		rep(i,n)
		ans+=s;
		cout<<ans<<endl;
		

	}
		
	int main()
	{ 
		fastio();
	    ll int t;
	    // cin>>t;
	    t=1;
	    while(t--)
	    {
	    	solve();
	    }
	}

		
			
		
		
		
		





Measured memory_bytes: 3612
N=int(input())
c=[[0 for z in range(10)] for z in range(10)] #c[i][j]=1以上N以下の整数で先頭i末尾jとなる数字の個数
for i in range(1,10):
  for j in range(1,10):
    for k in range(1,N+1):
      k=str(k)
      if k[0]==str(i) and k[-1]==str(j):
        c[i][j]=c[i][j]+1
S=0
for i in range(1,10):
  for j in range(1,10):
    S=S+c[i][j]*c[j][i]
print(S)


Measured memory_bytes: 44336
h,w = map(int,input().split())
a = [[] for i in range(0,h)]
for i in range(0,h):
    A = list(map(int, input().split()))
    a[i].extend(A)
way = []
for i in range(0,h):
    for j in range(0,w):
        if i%2==0:
            way.append((i,j))
        else:
            way.append((i,w-j-1))
ans = []
for num in range(0,h*w-1):
    i,j = way[num]
    ni,nj = way[num+1]
    if a[i][j]%2 == 1:
        a[ni][nj] += 1
        ans.append((i,j,ni,nj))
print(len(ans))
for num in range(0,len(ans)):
    i,j,ni,nj= ans[num]
    print(i+1,j+1,ni+1,nj+1)


Measured memory_bytes: 40612
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, a[100009]; vector<int> g[100009];
long long calc(int pos, int pre) {
	if (g[pos].size() == 1) return a[pos];
	long long mx = 0, sum = 0;
	for (int i : g[pos]) {
		if (i == pre) continue;
		long long res = calc(i, pos);
		if (res == -1) return -1;
		sum += res;
		mx = max(mx, res);
	}
	long long ops = sum - a[pos];
	long long lim = min(sum - mx, sum / 2);
	if (ops < 0 || ops > lim) return -1;
	return sum - ops * 2;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N - 1; i++) {
		int x, y;
		cin >> x >> y; x--, y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int root = 0;
	for (int i = 1; i < N; i++) {
		if (g[i].size() >= 2) root = i;
	}
	long long ret = calc(root, -1);
	cout << ((N == 2 && a[0] == a[1]) || (N >= 3 && ret == 0) ? "YES\n" : "NO\n");
	return 0;
}

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


main()
{
long long int sum;
int n,m,min,max;

scanf("%d %d",&n,&m);
min=m;
max=m;
sum=m;
n--;
while(n--){
	scanf("%d",&m);
	if(min>m)min=m;
	if(max<m)max=m;
	sum+=m;
}
printf("%d %d %lld\n",min,max,sum);
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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


int dp[44][444][444];

int main()
{
	int n,a,b;
	cin >> n >> a >> b;
	REP(k,44)REP(i,444)REP(j,444)dp[k][i][j] = INF;
	dp[0][0][0] = 0;
	
	REP(i,n){
		int x,y,z;cin >> x >> y >> z;
		REP(j,444){
			REP(k,444){
				if(dp[i][j][k] != INF){
					dp[i+1][j][k] = min(dp[i][j][k],dp[i+1][j][k]);
					dp[i+1][j+x][k+y] = min(dp[i+1][j+x][k+y],dp[i][j][k]+z);
				}
			}
		}
	}
	int ans = INF;
	REP(i,444)REP(j,444){
		if(i != 0 && j != 0 && i * b == j * a){
			ans = min(ans,dp[n][i][j]);
		}
	}
	
	
	if(ans == INF){
		cout << -1 << endl;
	}
	else{
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 34176
s = list(input())
n = len(s)
s_1 = s[0:int((n-1)/2)]
s_2 = s[int((n+3)/2-1):n]

if s == list(reversed(s)) and s_1 == list(reversed(s_1)) and s_2 == list(reversed(s_2)):
  print("Yes")

else:
  print("No")

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	var inputs []string
	for i := 0; i <= 1; i++ {
		sc.Scan()
		inputs = append(inputs, sc.Text())
	}
	a, _ := strconv.Atoi(inputs[0])
	b := inputs[1]

	str := ""
	if len(b) > a {
		str += b[:a]
		str += "..."
	} else {
		str += b
	}
	fmt.Println(str)
}

Measured memory_bytes: 1760
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
int n,k,b;
ll vis[100005];
ll sum;
int solve(ll T)
{
    ll t=T;
    for(int i=0;i<n;i++)
    {
        ll x=vis[i]-T*b;
        if(x>0)
            t-=ceil(x*1.0/(k-b));
    }
    if(t>=0)
        return 1;
    else
        return 0;
}
int main()
{
        scanf("%d%d%d",&n,&k,&b);
        sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&vis[i]);
            sum+=vis[i];
        }
        sort(vis,vis+n);
        if(k==1)
            printf("%lld\n",vis[n-1]);
        else
        {
            ll l=1;
            ll r=vis[n-1];
            while(l<=r)
            {
                ll mid=(l+r)/2;
                if(solve(mid))
                   r=mid-1;
                else
                   l=mid+1;
            }
            printf("%lld\n",l);
    }
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>

int main(){
int a,b;
while(true){
scanf("%d %d",&a,&b);
if(a==0) break;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){

if((i!=0)&&(j!=0)&&(i!=a-1)&&(j!=b-1))printf(".");
else printf("#");

}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
bool isPrime(int x){
for(int i=2;i*i<=x;i++){
if(x%i==0)return false;
}
  return true;
}
int main(){
  fast();
 ll n;
  cin>>n;int total = 0;
  for(int i=0;i<n;i++){
    total = (total*10+7)%n;
      if(total==0){cout<<i+1;return 0;}
    
  }
  cout<<-1;
 return 0;
  
}




Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		long result = 1;
		long limit = 1_000_000_000_000_000_000L;

		long a[] = new long[n];

		for(int i = 0; i < n; i++){
			a[i] = sc.nextLong();

			if(a[i] == 0){
				System.out.println(0);
				return;
			}
		}
		for(int i = 0; i < n; i++){

			if(limit/result < a[i]){
				System.out.println(-1);
				return;
			}
//			System.out.println(result);
			result *= a[i];
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 50804
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm(numbers):
    x = numbers[0]
    for y in numbers:
        x = lcm_base(x, y)
    return x

N, M = map(int, input().split())
aaa = list(map(int, input().split()))
a = aaa[0]
cnt = 0
while a % 2 == 0:
    cnt += 1
    a //= 2
for a in aaa:
    if a % 2 ** cnt != 0 or a % 2 ** (cnt + 1) == 0:
        print(0)
        exit()        
bbb = [a // 2 for a in aaa]
lc = lcm(bbb)
q, r = divmod(M // lc , 2)
print(q + r)


Measured memory_bytes: 21904
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i = 0; i<n;i++){
			a[i] = scanner.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n-1] - a[0]);
	}
}


Measured memory_bytes: 21844
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int N, D;

int main() {
    cin >> N >> D;
    
    int ans = 1;
    int i = D+1+D;
    while(i < N) {
        ans += 1;
        i += (D * 2) + 1;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
vector<vector<ll>>to, cost;
ll dist[101010];
bool flag[101010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	to.resize(n);
	cost.resize(n);
	rep(i, n - 1) {
		ll u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		to[u].push_back(v);
		to[v].push_back(u);
		cost[u].push_back(w);
		cost[v].push_back(w);
	}
	vector<ll>ans(n, -1);
	queue<ll>q;
	ans[0] = 0;
	q.push(0);
	while (!q.empty()) {
		ll v = q.front();
		q.pop();
		rep(i, to[v].size()) {
			ll u = to[v][i];
			ll w = cost[v][i];
			if (ans[u] != -1)continue;
			ans[u] = (ans[v] + w) % 2;
			q.push(u);
		}
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 15944
N = int(input())
orgN = N
div = []

def bitsoncount(x):
    return bin(x).count('1')

for d in range(2, N):
    if d*d > N:
        break
    if N % d == 0:
        div.append(d)
        while N % d == 0:
            N = N // d
if N != 1: div.append(N)

M = len(div)
ans = 0
for i in range(1, 2 ** M): # divを因数にもちうるものであるため、i=0は不適
    mul = 1
    bc = bitsoncount(i)
    for m in range(M):
        if i >> m & 1:
            mul *= div[m]
    if bc % 2 == 1:
        ans += orgN // mul
    else:
        ans -= orgN // mul

ans = orgN - ans
print(ans)


Measured memory_bytes: 5600
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long
const int M = 1000 * 1000 * 1000 + 7;

int32_t main(){
	int n;
	cin >> n;
	int a[n], cnt[n] = {};
	for (int i = 0; i < n; i++){
		cin >> a[i];
		cnt[a[i]] ++;
	}
	bool f = true;
	for (int i = (n) % 2 + 1; i < n; i += 2){
		if (cnt[i] != 2)
			f = false;
	}
	if (n % 2 == 1){
		if (cnt[0] != 1)
			f = false;
	}
	if (!f){
		cout << 0;
	}else{
		int x = 1;
		for (int i = 0; i < n / 2; i++){
			x *= 2;
			x %= M;
		}
		cout << x;
	}
}


Measured memory_bytes: 5116
import copy

# 約数列挙
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 2
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1] + [n]

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


n = int(input())
if n == 2:
    print(1)
    exit()

div1 = make_divisors(n-1)
cnt = len(div1)

div2 = make_divisors(n)


for i in div2:
    x = copy.deepcopy(n)
    while x >= i:
        if x % i == 0:
            x //= i
        else:
            break
    if x == 1 or x % i == 1:
        cnt += 1

print(cnt)

Measured memory_bytes: 9424
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#include<math.h>
//#include "Ants.h"
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef pair < int, int> P;
/****Union-Ford-Tree***/
int par[int(0x7ffffff)];//Parent
int Rank[int(0x7ffffff)];//Deep_of_the_Tree

//int a[100] = { 4,2,3,1,5 }, m[100] ={3,2,2};
//int n = 0;
//const ll mod = 1000000007;


//n要素で初期化
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		Rank[i] = 0;
	}
}
//木の根探し
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;

	if (Rank[x] < Rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}
/************************************************************************************/
//int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
/**************/
ll dp[101][int(1e5) + 1];
int n, W;
int w[101], v[101];
int main()
{
	cin >> n >> W;
	for (int i = 0; i < n; i++)cin >> w[i] >> v[i];
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i]) {
				dp[i][j] = dp[i + 1][j];
			}
			else {
				dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[0][W] << endl;
}

Measured memory_bytes: 80128
package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	race1 := make([]player, 8)
	race2 := make([]player, 8)
	race3 := make([]player, 8)
	rest := make([]player, 6)
	for i := 0; i < 8; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		no, _ := strconv.Atoi(input[0])
		time, _ := strconv.ParseFloat(input[1], 64)
		race1[i] = player{no, time}
	}
	for i := 0; i < 8; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		no, _ := strconv.Atoi(input[0])
		time, _ := strconv.ParseFloat(input[1], 64)
		race2[i] = player{no, time}
	}
	for i := 0; i < 8; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		no, _ := strconv.Atoi(input[0])
		time, _ := strconv.ParseFloat(input[1], 64)
		race3[i] = player{no, time}
	}
	for i := 1; i <= 7; i++ {
		for k := 7; k >= i; k-- {
			if race1[k].time < race1[k-1].time {
				race1[k], race1[k-1] = race1[k-1], race1[k]
			}
			if race2[k].time < race2[k-1].time {
				race2[k], race2[k-1] = race2[k-1], race2[k]
			}
			if race3[k].time < race3[k-1].time {
				race3[k], race3[k-1] = race3[k-1], race3[k]
			}
		}
	}
	rest[0] = race1[2]
	rest[1] = race1[3]
	rest[2] = race2[2]
	rest[3] = race2[3]
	rest[4] = race3[2]
	rest[5] = race3[3]
	for i := 1; i <= 5; i++ {
		for k := 5; k >= i; k-- {
			if rest[k].time < rest[k-1].time {
				rest[k],rest[k-1] = rest[k-1], rest[k]
			}
		}
	}
	fmt.Printf("%d %.2f\n", race1[0].no, race1[0].time)
	fmt.Printf("%d %.2f\n", race1[1].no, race1[1].time)
	fmt.Printf("%d %.2f\n", race2[0].no, race2[0].time)
	fmt.Printf("%d %.2f\n", race2[1].no, race2[1].time)
	fmt.Printf("%d %.2f\n", race3[0].no, race3[0].time)
	fmt.Printf("%d %.2f\n", race3[1].no, race3[1].time)
	fmt.Printf("%d %.2f\n", rest[0].no, rest[0].time)
	fmt.Printf("%d %.2f\n", rest[1].no, rest[1].time)
}

type player struct {
	no int
	time float64
}


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

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

const int M = 1e9 + 7;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

using vi = vector<int>;
using vvi = vector<vi>;

template<class T>
void add(T& a, const T& b) {
	a += b;
	if (a >= M) a -= M;
}

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

	string k; int d; cin >> k >> d;
	vvi f(d, vi(2)); f[0][0] = 1;
	rep(i, 0, sz(k)) {
		vvi g(d, vi(2));
		rep(x, 0, d) {
			rep(c, 0, 10) add(g[(x + c) % d][1], f[x][1]);
			rep(c, 0, k[i] - '0') add(g[(x + c) % d][1], f[x][0]);
			add(g[(x + k[i] - '0') % d][0], f[x][0]);
		}
		swap(f, g);
	}
	cout << (f[0][0] + f[0][1] + M - 1) % M;
}

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

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

typedef struct node * Node;

Node root,NIL;
int maxh;

void insert(int x){
  int H;
  Node b=NIL;
  Node a = root;
  Node c;

  c = malloc(sizeof(struct node));
  c->key =x;
  c->left = NIL;
  c->right = NIL;

  while(a!=NIL){
    b=a;
    if(c->key < a->key){
      a = a->left;
    }
    else{
      a = a->right;
    }
  }

  c ->parent = b;

  if(b ==NIL){
    root =c;
  }
  else{
    if(c->key < b->key){
      b->left =c;
    }
    else{
      b->right =c;
    }
  }
}
 
void inorder(Node x){
  if(x == NIL){
    return;
  }
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}
void preorder(Node x){
  if( x ==NIL) {
    return;
  }
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}

int main(){
  int i,num,x;
char com[20];
scanf("%d",&num);
maxh=0;
for(i=0;i<num;i++){
  scanf("%s",com);
  if(strcmp(com,"insert")==0){
    scanf("%d",&x);
    insert(x);
  }
  else if(strcmp(com,"print")==0){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
  }
 }
return 0;
}



Measured memory_bytes: 25220
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;

int main()
{
	int d, e;
	while (cin >> d >> e&&d&&e)
	{
		double ans = 1000;
		for (int i = 0; i <= d; i++)
		{
			double x = sqrt(i*i + (d - i)*(d - i));
			ans = min(ans, fabs(x - (double)e));
		}
		printf("%.8f\n", ans);
	}
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  string s, t;
  cin >> s >> t;

  u32 ans = UINT32_MAX;

  rep(i, s.size() - t.size()+1) {
    u32 diff = 0;
    rep(j, t.size()) {
      if (t[j] != s[j + i])
        diff++;
    }
    if (diff < ans)
      ans = diff;
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 3592
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 1000005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,h,d;
int fact[MAXN],sfact[MAXN],dp[MAXN],sum[MAXN];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int get_sum(int x,int y)
{
    if(x<=0) return sum[y];
    int ret=sum[y];
    dec(ret,sum[x-1]);
    return ret;
}
int main()
{
    fact[0]=1;
    for(int i=1;i<=1000000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    for(int i=1;i<=1000000;i++) {sfact[i]=fact[i]; add(sfact[i],sfact[i-1]);}
    dp[0]=1;
    sum[0]=1;
    scanf("%d%d%d",&n,&h,&d);
    for(int i=1;i<=h-1;i++)
    {
        dp[i]=get_sum(i-d,i-1);
        dp[i]=1LL*dp[i]*sfact[n]%MOD;
        sum[i]=sum[i-1]; add(sum[i],dp[i]);
    }
    dp[h]=get_sum(h-d,h-1);
    dp[h]=1LL*dp[h]*fact[n]%MOD;
    printf("%d\n",dp[h]);
    return 0;
}



Measured memory_bytes: 15872
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 3 * 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
if __name__ == "__main__":
  H, W, A, B = map(int, input().split())
  #HW = [[0] * W for i in range(H)]
  p = 10 ** 9 + 7
  #print(HW)
  #visited = [[0] * W for i in range(H)]
  ans = 0
  for i in range(H - A):
    if i == 0:
      ans += cmb(B + i, i, p) * cmb(H + W - B - 2 - i, H - 1 - i, p)
      ans %= p
    else:
      ans += cmb(B + i - 1, i, p) * cmb(H + W - B - 2 - i, H - 1 - i, p)
      ans %= p
  print(ans)
  
  

Measured memory_bytes: 44420
l = list(input())
n = len(l)


for i in range(2**(n-1)):
    val = l[0]
    for j in range(n - 1):
        if (i >> j)&1 == 0:
            val += '-'
        elif (i >> j)&1 == 1:
            val += '+'
        
        val += l[j + 1]
    
    num = eval(val)
    if num == 7:
        print(val + '=7')
        break

Measured memory_bytes: 8920
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string s; cin >> s;
  long long K; cin >> K;

  for ( int i = 0; i < s.size(); ++i )
  {
    char tmp = s[i] - 'a';
    if ( ( tmp != 0 ) && ( tmp + K >= 26 ) )
    {
      K -= 26 - tmp;
      s[i] = 'a';
    }
  }
  s.back() = ( ( s.back() - 'a' ) + K ) % 26 + 'a';

  cout << s << endl;

  return ( 0 );
}


Measured memory_bytes: 576
#light "off"
open System;;
open System.IO;;

let reader = new StreamReader(new BufferedStream(Console.OpenStandardInput ()))
let writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput ()))

let skipSpaces () = while reader.Peek () <= int ' ' do reader.Read () |> ignore done;;
let read f = skipSpaces (); [|while reader.Peek () > int ' ' do yield char (reader.Read ()) done |] |> System.String |> f;;
let readint () = skipSpaces (); let s = if reader.Peek() = int '-' then (ignore (reader.Read()); -1) else 1 in let mutable ans = 0 in while reader.Peek () > int ' ' do ans <- ans * 10 + (reader.Read () - int '0'); done; s * ans;;
let write (s : string) = writer.Write s;;
let writeln (s : string) = writer.WriteLine s;;


let MOD = 998244353;;
type Mint = Mint of int
  with
    static member (+) (Mint x, Mint y) = Mint (let z = x + y in if z < MOD then z else z - MOD)
    static member (-) (Mint x, Mint y) = Mint (let z = x - y in if z >= 0 then z else z + MOD)
    static member (*) (Mint x, Mint y) = int64 x * int64 y % int64 MOD |> int |> Mint
    override this.ToString() = match this with | Mint x -> x.ToString()
  end;;

type BIT = { dat : int [] }
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module BIT =
  begin
    let create n : BIT = { dat = Array.create (n + 1) 0 }
    let update ({dat=dat} : BIT) (k : int) (v : int) =
      let mutable i = k + 1 in
      while i < Array.length dat do dat.[i] <- dat.[i] + v; i <- i + (i &&& -i) done
    let query ({dat=dat} : BIT) (k : int) : int =
      let mutable i = k in
      let mutable ans = 0 in
      while i > 0 do ans <- ans + dat.[i]; i <- i - (i &&& -i) done;
      ans
  end;;

let N = readint ();;
let X, Y = Array.init N (fun _ -> readint (), readint ()) |> Array.sort |> Array.unzip;;

// Watasi ha Array.distinct no time complexity wo siranai.
// I don't know the time complexity of Array.sort.
let YD = Array.copy Y |> Array.distinct |> Array.sort;;

let where (a : int []) (k : int) : int =
  let mutable l = -1 in
  let mutable r = Array.length a in
  while r - l > 1 do
    let mutable x = (l + r) / 2 in
    if a.[x] >= k then r <- x else l <- x
  done;
  r;;

for i in 0..N-1 do
  Y.[i] <- where YD Y.[i];
done;;

let L = BIT.create (Array.length YD);;
let R = BIT.create (Array.length YD);;

for i in 0..N-1 do BIT.update R Y.[i] 1 done;;

let two = Array.replicate N (Mint 2) |> Array.scan (*) (Mint 1);;
let sub (x : byref<Mint>) (y : Mint) = x <- x - y;;

let mutable ans = two.[N] * (Mint N);;
for i in 0..N-1 do
  BIT.update R Y.[i] (-1);
  let d = BIT.query L Y.[i] in
  let c = BIT.query R Y.[i] in
  let a = i - d in
  let b = (N-1-i-c) in
  sub &ans <| (Mint 1);
  sub &ans <| two.[a] - Mint 1;
  sub &ans <| two.[b] - Mint 1;
  sub &ans <| two.[c] - Mint 1;
  sub &ans <| two.[d] - Mint 1;
  sub &ans <| (two.[a] - Mint 1) * (two.[b] - Mint 1);
  sub &ans <| (two.[b] - Mint 1) * (two.[c] - Mint 1);
  sub &ans <| (two.[c] - Mint 1) * (two.[d] - Mint 1);
  sub &ans <| (two.[d] - Mint 1) * (two.[a] - Mint 1);
  BIT.update L Y.[i] 1;
done;;

printfn "%O" ans;;

reader.Close();;
writer.Close();;

Measured memory_bytes: 48952
#include<stdio.h>
#define MAX 1000
 
typedef struct
{
  int p;
  int l;
  int r;
}Binary;
 
Binary tree[MAX];
 
int main()
{
  int i, n, k;
  int id;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    tree[i].l = tree[i].r = tree[i].p = -1;
  
  for(i = 0; i < n; i++)
    {
      scanf("%d", &id);
      scanf("%d%d", &tree[id].l, &tree[id].r);
      if(tree[id].l != -1) tree[tree[id].l].p = id;
      if(tree[id].r != -1) tree[tree[id].r].p = id;
    }
 
  for(i = 0; i < n; i++)
    print( i );
  return 0;
}
 
 
void print(int);
 
int getheight(int i){
  int x=0,y=0;
  if(tree[i].l!=-1)
    x=getheight(tree[i].l)+1;
  if(tree[i].r!=-1)
    y=getheight(tree[i].r)+1;
  if(x>y)
    return x;
  else
    return y;
}
 
int getdepth(int i){
  int d=0;
  while(tree[i].p>=0){
    i=tree[i].p;
    d++;
  }
  return d;
}
 
int getsibling(int i){
  if(tree[i].p==-1)
    return -1;
  else if(tree[tree[i].p].r==i)
    return tree[tree[i].p].l;
  else
    return tree[tree[i].p].r;
}
 
int getdeg(int i){
  int d=0;
  if(tree[i].l!=-1)
    d++;
  if(tree[i].r!=-1)
    d++;
  return d;
}
 
 
void print(int i){
    int h=getheight(i);
    int dep=getdepth(i);
 
    printf("node %d: parent = %d, sibling = %d, degree = %d, ",i,tree[i].p,getsibling(i\
),getdeg(i));
 
    printf("depth = %d, height = %d, ",dep,h);
    if(dep==0)
      printf("root\n");
    else if(h==0)
      printf("leaf\n");
    else
      printf("internal node\n");
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'


int32_t main()
{
	ninja
	int x; cin>>x;
	int a,b;
	for(int i=-1000;i<=1000;i++){
		for(int j=-1000;j<=1000;j++){
			if((pow(i,5)-pow(j,5))==x){
				cout<<i<<" "<<j;return 0;
			}
			else if((pow(j,5)-pow(i,5))==x){
				cout<<j<<" "<<i;return 0;
			}
		}
	}
}



Measured memory_bytes: 4016
/*
name:       Egyptian Tourist
PlatForm:   CodeForces/SPOJ...etc
LANG:       C++
DIV:        Training
TIME:       *
RATE:       *
*/

/*
Time Consumed:*
Problem Topics: *
*/

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

//-------------------------------------------------------//
#define rep(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define repr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define lp(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define lpr(i,n) for (int i = (n) - 1; ~i; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
//-------------------------------------------------------------------------------------//

#define clr(ar, val) memset(ar, val, sizeof(ar))
//----------------------------------------------//

#define inn freopen("in.in","r",stdin)
#define outt freopen("out.out","w",stdout)
#define PI 3.1415926535897932385
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define pob pop_back
#define bit(n) (1<<(n))
#define Last(i) ( (i) & (-i) )
#define all(v) ((v).begin()), ((v).end())
#define sq(x) ((x) * (x))
#define INF INT_MAX
#define Ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

//-------------------------------------------------------------//
#ifndef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1<<" | ";
    __f(comma+1, args...);
}
#else
#define debug(...)
#endif
#define _ist_ cout << "\nSTART OF INPUT DISPLAYING CHECK\n";
#define _iend_ cout << "\nEND OF INPUT DISPLAYING CHECK\n";
//------------------------------------------------------------//
#define mod (int)(1e9 + 7)
//#define N (int)2e5 + 5
#define N (int)1e5 + 5
//----------------------------------//
typedef pair<int, char> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
//---------------------------------//
template<class T, class T2>
T _f_pow(T a, T2 b)
{
    T res = 1LL;
    //a%=mod;
    while (b > 0)
    {
        if (b & 1)
            res = (res*a);//res = (res * a)%mod;
        a = (a * a);
        //a%=mod;
        b >>= 1;
    }
    return (res);
}
template<class T>
T gcd(T a, T b)
{
    while(a && b)
        if(a > b)
            (a%=b);
        else(b%=a);

    return a + b;
}
template<class T>
T lcm(T a, T b)
{
    return (a * b) / gcd(a, b);
}
string x;
int main()
{
    Ios;
    //inn;outt;
    //auto tt = clock();
    cin >> x;
    string s = "";
    for(auto c:x)
    {
        if(c != 'B')
            s += c;
        else if (s.size())
        {
            s.pop_back();
        }
    }
    cout << s << endl;
    //cout << (double(clock() - tt)/CLOCKS_PER_SEC * 1.00) << endl;
    //system("sleep 50");
    return 0;
}


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

using namespace std;

typedef long long int lli;

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

    int n, p, cont = 0;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> p;
        cont += (p != i+1) ? 1 : 0;
    }

    cout << ((cont <= 2) ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256