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

int main() {
  ll N;
  cin >> N;

  int len = 0;
  ll sum = 0;
  ll base = 0;
  for (int i = 1; i < 12; i++) {
    ll product = 1;
    for (int j = 0; j < i; j++) {
      product = product * 26;
    }

    sum = sum + product;
    if (N <= sum) {
      len = i;
      base = sum - product;
      break;
    }
  }

  // 例えば N = 704 は aab である。
  // N = 704 から以下の値を求める。
  // ・文字列の長さ len = 3
  // ・文字列の長さ3文字の開始より前の番号 base = 702
  // ・703 を0番目と捉えて、N が何番目の数値かを確認する
  // 　・704 の場合は、704 - 702 - 1 = 1番目の数値となる
  // aaa = 0番目
  // aab = 1番目
  // となる。
  //
  // 文字列の長さ分、剰余を求めて、文字列に変換する
  //
  // 704 - 702 - 1 = 1
  // 1桁目 = 1 % 26               = 1 = a + 1 = b
  // 2桁目 = (1 / 26) % 26        = 0 = a + 0 = a
  // 3桁目 = ((1 / 26) / 26) % 26 = 0 = a + 0 = a
  ll k = N - base - 1;
  string ans = "";
  for (int i = 0; i < len; i++) {
    ll remainder = k % 26;
    ans = char('a' + remainder) + ans;

    ll quotient = k / 26;
    k = quotient;
  }

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

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

int main() {
    int x;
    cin >> x;
    for (int a = -1000; a <= 1000; a++) {
        ll a5 = 1;
        rep(i,5) a5 *= a;
        for (int b = -1000; b <= 1000; b++) {
            ll b5 = 1;
            rep(j,5) b5 *= b;
            if (a5-b5 == x) {
                printf("%d %d\n",a,b);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3692
n = gets.chomp.to_i
c = []
while s = gets
  c.push(s.chomp.split(""))
end
alp = ('a'..'z').to_a
for i in 0..25
  min = 50
  for j in 0..n-1 
    #p c[j]
    if min >= c[j].count(alp[i])
       min = c[j].count(alp[i])
    end
  end
  min.times do
    print alp[i]
  end
end
print "\n"

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;//0,Wなら左向き、1,Eなら右
    vector <int> p(n);
    for(int i=0;i<n;i++){
        char c;
        cin>>c;
        if(c=='W'){
            p[i]=0;
        }
        else{
            p[i]=1;
        }
    }
    vector <int> e(n);
    for(int i=n-1;i>0;i--){
        if(i==n-1) e[i]+=(p[i]==1);
        else e[i]+=e[i+1]+(p[i]==1);
    } 
    vector <int> w(n);
    for(int i=0;i<n;i++){
        if(i==0) w[i]=(p[i]==0);
        else w[i]=w[i-1]+(p[i]==0);
    }
    /*for(int i=0;i<n;i++){
        cout<<e[i]<<endl;
    }*/
    int ans=1e9;
    for(int i=0;i<n;i++){
        int tmp=0;
        int r=i+1;
        int l=i-1;
        if(i==0) tmp=e[r];
        else if(i==n-1) tmp=w[l];
        else tmp=e[r]+w[l];
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3712
n = gets.strip.chars.reverse.map(&:to_i)
l = n.size

dp = Array.new(l+1) { Array.new(2, 0) }

0.upto(l-1) do |i|
  dp[i+1][0] = [
      dp[i][0] + n[i],
      dp[i][1] + n[i] + 1,
    ].min
  
  if i != 0
    dp[i+1][1] = [
        dp[i][0] + 10 - n[i],
        dp[i][1] + 10 - (n[i] + 1),
      ].min
  else
    dp[i+1][1] = dp[i][0] + 10 - n[i] 
  end
end
  

puts [
    dp[l][0],
    dp[l][1] + 1
  ].min

Measured memory_bytes: 171788
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main()
{
	// 要素数
	int a, b, c;
	cin >> a >> b >> c;

	int _a, _b, _c;
	int count = 0;
	while( true )
	{
		// 奇数
		if( ( a & 1 ) != 0 || ( b & 1 ) != 0 || ( c & 1 ) != 0 )
			break;

		// 無限
		if( a == b && b == c )
		{
			count = -1;
			break;
		}

		// 交換
		++count;
		_a = a;
		_b = b;
		_c = c;
		a = ( _b + _c ) >> 1;
		b = ( _a + _c ) >> 1;
		c = ( _a + _b ) >> 1;
	}

	cout << count << endl;
}


Measured memory_bytes: 256
/*input
30 40 50
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=20000005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll inv[maxn];

int main(){
	IOS;
	int n,m,k;
	cin>>n>>m>>k;
	ll pren=1,prem=1;
	ll ans1=0,ans2=0;
	ll C1=1,C2=1;

	inv[1]=1;
	for(int i=2;i<maxn;i++) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
	for(int i=0;i<max(0,k-m);i++) pren=pren*(n-i)%MOD;
	for(int j=0;j<k-max(0,k-m);j++) prem=prem*(m-j)%MOD;

	REP(i,max(0,k-m)){
		C2=C2*(k-i)%MOD*inv[i+1]%MOD;		
	}
	if(max(0,k-m)==0) C1=0;
	else{
		REP(i,max(0,k-m)-1){
			C1=C1*(k-2-i)%MOD*inv[i+1]%MOD;
		}
	}

	for(int i=max(0,k-m),j=k-i;i<=n&&j>=0;i++,j--){
		// cout<<pren<<' '<<prem<<' '<<C1<<' '<<C2<<'\n';
		ans1+=pren*prem%MOD*C1%MOD;
		if(ans1>=MOD) ans1-=MOD;
		// cout<<ans1<<'\n';

		ans2+=pren*prem%MOD*C2%MOD;
		if(ans2>=MOD) ans2-=MOD;
		// cout<<ans2<<'\n';

		pren=pren*(n-i)%MOD;
		prem=prem*inv[m-j+1]%MOD;

		if(i==0) C1=1;
		else{
			C1=C1*(k-1-i)%MOD*inv[i]%MOD;
		}
		C2=C2*(k-i)%MOD*inv[i+1]%MOD;
	}
	ans1=ans1*k%MOD*(k+1)%MOD*(k-1)%MOD*inv[3]%MOD;
	ans2=ans2*k%MOD*(k+3)%MOD*inv[2]%MOD;
	ans1+=ans2;
	if(ans1>=MOD) ans1-=MOD;
	cout<<ans1<<'\n';
	return 0;
}


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

int main(){

    int n, max_num, max_num_2nd, temp;
    cin >> n;
    vector<int> a(n);
    vector<int> ans(n);
    bool flg = false;

    max_num = 0;
    max_num_2nd = 0;
    for (int i=0; i<n; i++){
        cin >> a.at(i);

        if (max_num < a.at(i)){
            max_num = a.at(i); 
            flg = true;
        }
        if ((a.at(i) > max_num_2nd) && (flg == false)){
            max_num_2nd = a.at(i);
        }
        flg = false;
    }

    for (int i=0; i<n; i++){

        if (a.at(i) == max_num){
            ans.at(i) = max_num_2nd;
        }
        else{
            ans.at(i) = max_num;
        }
    }

    for (int i=0; i<n; i++){
        cout << ans.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 4832
n, x = map(int, input().split())
a = list(map(int, input().split()))

if sum(a) < x:
    print(n-1)
    exit()
    
a = sorted(a)
ans = 0
for i in range(n):
    if a[i] <= x:
        ans += 1
        x -= a[i]
print(ans)

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;

int solve(int n) {
	int ma = 0, mi = 1e9;
	int sum = 0;
	rep(i, n) {
		int x; cin >> x;
		chmax(ma, x);
		chmin(mi, x);
		sum += x;
	}
	return (sum - ma - mi) / (n - 2);
}

signed main() {
	int n;
	while (cin >> n, n) cout << solve(n) << endl;
}




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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	int N, M; cin >> N >> M;
	vector<int> A(N);

	REP(i,N) cin >> A[i];

	map<int, int> mp;
	vector<int> sum(N+1);
	sum[0] = 0;
	REP(i,N+1){
		sum[i+1] = (sum[i] + A[i]) % M;
	}

	ll ans = 0;
	REP(i,N+1){
		ans += mp[sum[i]];
		mp[sum[i]]++;
	}

	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 3968
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
     
    while(x!=NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if(z->key < y->key) {
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for (i=0; i<n; i++) {
        cin >> com;
        if(com == "insert") {
            scanf("%d", &x);
            insert(x);
        }else if(com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  
  vector<int> tako;
  rep(i,0,n){
    int tmp;
    cin>>tmp;
    tako.emplace_back(tmp);
  }

  int ans=0;
  rep(i,0,n-1){
    rep(j,i+1,n){
      ans+=tako[i]*tako[j];
    }
  }
  
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,a=100000;
  cin>>n;
  for(int i=0;i<n;i++){
    a=(a+a*0.05);
    if(a%1000!=0){
    a/=1000;
    a++;
    }
    else a/=1000;
    a*=1000;
  }
    cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
        int h,w,p;
        cin >> h >> w >> p;
        vector<vector<ll>> dp(h+1,vector<ll>(w,0));
        dp.at(0).at(0) = 1;
        
        if(w == 1) {cout << 1 << endl; return 0;}
        
        rep(i,h){
                 rep(j,pow(2,w-1)){
                                   vector<int> line(w-1,0);
                        rep(k,w-1){
                                   if(j >> k & 1) line.at(k) = 1;
                        }
                        bool ok = true;
                        rep(k,w-2){
                                   if(line.at(k) == 1 && line.at(k+1) == 1) ok = false;
                        }
                        if(!ok) continue;
                        rep(k,w){
                                 if(k==0){
                                          if(line.at(k) == 1) dp.at(i+1).at(k+1) = (dp.at(i+1).at(k+1) + dp.at(i).at(k))%MOD; 
                                        else dp.at(i+1).at(k)  = (dp.at(i+1).at(k) + dp.at(i).at(k))%MOD;
                                }
                                else if(k==w-1){
                                        if(line.at(k-1) ==1) dp.at(i+1).at(k-1) = (dp.at(i+1).at(k-1) + dp.at(i).at(k))%MOD;
                                        else dp.at(i+1).at(k)  = (dp.at(i+1).at(k) + dp.at(i).at(k))%MOD;
                                }else{
                                        if(line.at(k) ==1) dp.at(i+1).at(k+1) = (dp.at(i+1).at(k+1) + dp.at(i).at(k))%MOD; 
                                        else if(line.at(k-1) == 1) dp.at(i+1).at(k-1) = (dp.at(i+1).at(k-1) + dp.at(i).at(k))%MOD;
                                        else dp.at(i+1).at(k)  = (dp.at(i+1).at(k) + dp.at(i).at(k))%MOD;
                                }
                        }
                }
        }
        
        cout << dp.at(h).at(p-1) << endl;
        return 0;   
}

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

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

int w,h,p;
int fie[1005][1005];
int pattern[110][110];
int tmp[110][110];

vector<ll> patvec[10];

void rotate_clockwise(int H,int W){
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			tmp[j][H-i-1]=pattern[i][j];
		}
	}
	for(int i=0;i<W;i++){
		for(int j=0;j<H;j++){
			pattern[i][j]=tmp[i][j];
		}
	}
}

void mirror(int H,int W){
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			tmp[i][W-j-1]=pattern[i][j];
		}
	}
	for(int i=0;i<W;i++){
		for(int j=0;j<H;j++){
			pattern[i][j]=tmp[i][j];
		}
	}
}

void register_pattern(int v){
	patvec[v].clear();
	for(int i=0;i<p;i++){
		ll bit=0;
		for(int j=0;j<p/2;j++){
			bit<<=1;
			bit+=pattern[i][j];
		}
		patvec[v].push_back(bit);
		bit=0;
		for(int j=p/2;j<p;j++){
			bit<<=1;
			bit+=pattern[i][j];
		}
		patvec[v].push_back(bit);
	}
}

int change(char g){
	if(g>='A' && g<='Z')return g-'A';
	if(g>='a' && g<='z')return (g-'a')+26;
	if(g>='0' && g<='9')return (g-'0')+52;
	if(g=='+')return 62;
	return 63;
}

ll sbit[1024][2];

bool check(int v,int size){
	for(int i=0;i<size;i++){
		bool flag=true;
		for(int j=0;j<p;j++){
			for(int k=0;k<2;k++){
				if(sbit[v+j][k]!=patvec[i][j*2+k])flag=false;
			}
		}
		if(flag)return true;
	}
	return false;
}

void solve(){
	if(p>w || p>h){
		printf("0\n");
		return;
	}
	int size=0;
	for(int i=0;i<2;i++){
		for(int j=0;j<4;j++){
			register_pattern(size++);
			rotate_clockwise(p,p);
		}
		mirror(p,p);
	}
	int ans=0;
	int len=p-(p/2);
	memset(sbit,0,sizeof(sbit));
	for(int i=0;i<h;i++){
		for(int j=0;j<p/2;j++){
			sbit[i][0]<<=1;
			sbit[i][0]+=fie[i][j];
		}
		for(int j=p/2;j<p;j++){
			sbit[i][1]<<=1;
			sbit[i][1]+=fie[i][j];
		}
	}
	for(int i=0;i<=w-p;i++){
		for(int j=0;j<=h-p;j++){
			if(check(j,size)){
				ans++;
			}
		}
		for(int j=0;j<h;j++){
			sbit[j][0]<<=1;
			sbit[j][1]<<=1;
			if(fie[j][i+p]==1){
				sbit[j][1]++;
			}
			if(fie[j][i+p/2]==1){
				sbit[j][1]-=1LL<<len;
				if(p/2>0)sbit[j][0]++;
			}
			if(fie[j][i]==1){
				if(p/2>0)sbit[j][0]-=1LL<<(p/2);
			}
		}
	}
	
	printf("%d\n",ans);
}

int main(void){
	while(1){
		scanf("%d%d%d",&w,&h,&p);
		if(w==0 && h==0 && p==0)break;
		for(int i=0;i<h;i++){
			string str;
			cin >> str;
			for(int j=0;j<(w+5)/6;j++){
				int v=change(str[j]);
				for(int k=5;k>=0;k--){
					fie[i][j*6+k]=v%2;
					v/=2;
				}
			}
		}
		for(int i=0;i<p;i++){
			string str;
			cin >> str;
			for(int j=0;j<(p+5)/6;j++){
				int v=change(str[j]);
				for(int k=5;k>=0;k--){
					pattern[i][j*6+k]=v%2;
					v/=2;
				}
			}
		}
		solve();
	}
	return 0;
}

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

int main() {
	// 変数の宣言
	int n, a;

	// 値の取得
	cin >> n >> a;

	// 判定
	if( n%500 == 0){
		// 500円玉のみで割り切れる場合
		cout << "Yes";
	}else if(n%500 >a){
		// 500円玉で払いきれなかった部分が払えない場合
		cout << "No";
	}else
	{
		cout << "Yes";
	}
	

}

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

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i ++)
#define Rep(i, j, k) for (int i = j; i >= k; i --)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template<typename t> t read() {
    t x = 0; int f = 1; char c = getchar();
    while (c > '9' || c < '0') f = c == '-' ? -1 : 1 , c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - 48 , c = getchar();
    return x * f;
}

template<typename t> void write(t x) {
    if (x < 0){
        putchar('-'), write(-x);
        return;
    }
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int P = 1e9 + 7;
const int N = 1e5 + 10;
int fac[N], facinv[N], a[N], n, pos, vis[N], id;

int power(int a, int b) {
    int c = 1;
    for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) c = 1ll * c * a % P;
    return c;
}

int C(int x, int y) {
    return 1ll * fac[x] * facinv[y] % P * facinv[x - y] % P;
}

int main() {
    n = rdi() + 1;
    for (int i = 1; i <= n; i ++) a[i] = rdi();
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i ++) fac[i] = 1ll * fac[i - 1] * i % P;
    facinv[n] = power(fac[n], P - 2);
    for (int i = n - 1; i >= 0; i --) facinv[i] = 1ll * facinv[i + 1] * (i + 1) % P;
    for (int i = 1; i <= n; i ++) {
        if (vis[a[i]]) {
            pos = i;
            id = a[i];
            break;
        }
        vis[a[i]] = i;
    }
    int len = n - pos + 1;
    for (int i = 1; i <= n; i ++) {
        int ans = C(n, i); 
        if (i - 1 <= len - 1 + vis[id] - 1) ans -= C(len - 1 + vis[id] - 1, i - 1);
        ans = (ans + P) % P;
        write(ans), putchar(10);
    } 
    return 0;
}

Measured memory_bytes: 2816
void main()
{
    string s = readln.chomp;
    string t = readln.chomp;

    long[][] alpha = new long[][](26);
    foreach (i, x; s)
    {
        alpha[x-'a'] ~= i + 1;
    }

    long n = s.length.to!long;
    long cnt;
    long index;
    foreach (x; t)
    {
        auto a = alpha[x-'a'].assumeSorted;

        if (a.empty)
        {
            cnt = -1;
            break;
        }

        auto l = a.upperBound(index);
        if (l.empty)
        {
            ++cnt;
            index = a[0];
        }
        else
        {
            index = l[0];
        }
    }

    writeln(cnt != -1 ? cnt * n + index: cnt);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

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

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()

print(kaijo(N))

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int N, M;
	cin >> N >> M;

	vector<int> A;
	int temp = 0;
	float sum = 0;
	for(int i=0; i<N; i++){
			cin >> temp;
			sum += temp;
			A.emplace_back(temp);
	}

	float border = sum / (4 * M);

	sort(A.begin(), A.end(), greater<int>());

	if(A[M-1] < border){
		cout << "No" << "\n";
	}
	else{
		cout << "Yes" << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 20){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}
*/


ll dp[3010][3010];//小さいのが何個残っているか
ll add[3010][3010];
void solve(){
  ll N;
  string S;
  cin >> N >> S;
  rep(i, N) dp[0][i] = 1;
  rep(i, N){
    if(S[i] == '<'){
      rep(j, N) add[i][j] = dp[i][j];
      rep(j, N){
        add[i][j+1] += add[i][j];
        add[i][j+1] %= MOD;
      }
      rep(j, N-i-1){
        dp[i+1][j] += add[i][j];
        dp[i+1][j] %= MOD;
      }
    }else{
      rep(j, N)if(j != 0) add[i][j-1] = dp[i][j];
      revrep(j, N){
        if(j == 0) continue;
        add[i][j-1] += add[i][j];
        add[i][j-1] %= MOD;
      }
      rep(j, N-i-1){
        dp[i+1][j] += add[i][j];
        dp[i+1][j] %= MOD;
      }
    }
  }
  cout << dp[N-1][0] << endl;
}

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


Measured memory_bytes: 141568
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int a;cin>>a;cout<<a*32<<endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
int ck[1000100];
int arr[1000100];
int main(void){
	int n;
	scanf("%d",&n);
	bool suc = true;
	int tot = n;
	for(int e=0;e<n;e++){
		scanf("%d",&arr[e]);
		if(arr[e]==1) tot--;
	}
	if(tot>100000) suc = false;
	int kk = 0;
	for(int e=0;e<n;e++){
		int r = arr[e];
		kk = __gcd(kk,r);
		if(r==1) continue;
		if(suc){
			int nn = sqrt(r);
			int tmp = r;
			for(int p=2;p<=nn;p++){
				if(tmp%p==0){
					while(tmp%p==0) tmp/= p;
					if(ck[p]){
						suc=  false;
						break;
					}
					ck[p] = 1;
				}
			}
			if(tmp!=1){
				if(ck[tmp]){
					suc = false;
				}
				ck[tmp] = 1;
			}
		}
	}
	if(suc) printf("pairwise coprime");
	else{
		if(kk==1) printf("setwise coprime");
		else printf("not coprime");
	}
	return 0;
}


Measured memory_bytes: 8020
program code_festival_2017_qualc_c
    use,intrinsic :: iso_fortran_env
    implicit none
    character(100000):: s, nox_s
    integer(int32):: ls, lnxs,i,j,ans

    read*, s
    ls = len_trim(s)
    nox_s = ''
    do i=1,ls
        if (s(i:i) == 'x') cycle
        nox_s = trim(nox_s) // s(i:i)
    end do
    lnxs = len_trim(nox_s)
    i=1
    j=lnxs

    do while(i <= j)
        if (nox_s(i:i) /= nox_s(j:j)) then
            print'(i0)', -1
            stop
        end if
        i=i+1
        j=j-1
    end do

    ans=0
    i=1
    j=ls
    do while(i <= j)
        if (s(i:i) == s(j:j)) then
            i=i+1
            j=j-1
            cycle
        else if (s(i:i) == 'x') then
            ans=ans+1
            i=i+1
        else
            j=j-1
            ans=ans+1
        end if
    end do
    print'(i0)', ans
end program code_festival_2017_qualc_c

Measured memory_bytes: 8744
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    scan(n);

    while (n > 0) {
        if (n % 10 == 9) {
            writeln("Yes");
            return;
        }

        n /= 10;
    }

    writeln("No");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()	{
  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x <= k; x++)
    for (int y = 0; y <= k; y++)	{
      int z = s - x - y;
      if (z >= 0 && z <= k)	{
        count++;
      }
    }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define forx(v) for(int x=0; x<v; x++)
#define ll long long
#define lll __int128
#define MAX (int)(4*pow(10,3) + 100)
#define pb(a) push_back(a)
#define ch (int)(4*pow(10,4) + 100)
#define ld long double
// #define cout out
// #define cin in
ll inf = pow(10,18);
ll modulo = pow(10,9)+7 ;
double eps = 1e-9;
ifstream in;
ofstream out;




void deal(){
	ll n , a,  b;
	cin>>n>>a>>b;
	if((b-a)%2 == 0){
		cout<<(b-a)/2;
		return;
	}
	cout<<min(a-1+(b-(a-1) - 1)/2 + 1, (n-b) + (n-(a+n-b))/2 + 1);
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}



/* 
6 8 
1 2
2 3
3 4
4 1
2 5
3 5
1 6
4 6
*/

Measured memory_bytes: 256
c = gets.chomp
arr = gets.chomp.split(' ').map(&:to_i)
count = 0
(1..arr.size-2).each do |i|
  if (arr[i-1] > arr[i] && arr[i+1] < arr[i]) || (arr[i-1] < arr[i] && arr[i+1] > arr[i])
    count = count + 1
  end
end
puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

void PR(bool f){
    cout << (f ? "YES" : "NO") << endl;
    exit(0);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    ll sum = accumulate(ALL(a), 0ll);
    if(sum % (n*(n+1)/2) != 0){
        PR(false);
    }
    ll m = sum / (n*(n+1)/2);
    vll diff(n);
    rep(i, n){
        diff[i] = m - (a[(i+1)%n]-a[i]);
        if(diff[i] % n != 0){
            PR(false);
        }
        diff[i] /= n;
    }
    rep(i, n){
        if(diff[i] < 0 || diff[i] > m){
            PR(false);
        }
    }
    PR(accumulate(ALL(diff), 0ll) == m);
    return 0;
}

Measured memory_bytes: 1792
import sys
from collections import Counter
s=input()
count=Counter(s)
alphabets=[chr(ord("a")+i) for i in range(26)]
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()

if len(count) <26:
    for i in range(26):
        if alphabets[i] not in count:
            print(s+alphabets[i])
            sys.exit()

for i in range(25):
    if ord(s[25-i])<ord(s[24-i]):
        continue
    else:
        memo=s[24-i]
        break
lst=sorted(list("qwertyuiopasdfghjklzxcvbnm"))
for j in range(24-i):
    lst.remove(s[j])
moji=lst[lst.index(memo)+1]
print(s[:24-i]+moji)
    
    

Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{

  int i,j,k;
  int N;
  scanf("%d",&N);

  int L[N+1];
  int count=0;
  int space;
    
  for(i=1;i<=N;i++){
    scanf("%d",&j);
    L[i] = j;
  }
  
  for(i=1;i<=N;i++){
    for(j=N;j>i;j--){
      if(L[j]>L[i]){
        space = L[i];
        L[i] = L[j];
        L[j] = space;
      }
      if(L[i]==L[j]){
          
      }
    }
  }

  int a,b,c;
  for(i=1;i<=N;i++){
    for(j=i+1;j<=N;j++){
      
      c = L[i];
      b = L[j];
      for(k=j+1;k<=N;k++){
        a = L[k];
        if(c<a+b){
          count++;  
        }
        else{
          break;
        }
      }
      
              
    }
  }
  
  
  printf("%d\n",count);
  
  return 0; 
}

Measured memory_bytes: 128
$w='(.{'.<>=~$"*$'.'})?';
$_=`dd`;
$%=y/.//;
s/./$c=chr 256/e;
do{
	$f=0;
	$f++while s/$c$w\K\./chr 1+ord$c/se|s/\.($w$c)/chr(1+ord$c).$1/se;
	$c=chr 1+ord$c
}while(/\.$/&&$f);
print-/\.$/||$%+255-ord$c


Measured memory_bytes: 700
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    ll n; cin>>n;
    for (ll i = sqrt(n); i>=0; i--) 
        if(n % i == 0) {
            cout<< (ll) log10(n/i)+1 <<endl;
            return;
        }
}

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

Measured memory_bytes: 768
#include<bits/stdc++.h>  
#define Max(x,y) ((x)>(y)?(x):(y))  
#define Min(x,y) ((x)<(y)?(x):(y))  
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)  
#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))  
#define ll long long  
#define Mem0(x) memset(x,0,sizeof(x))  
#define Mem1(x) memset(x,-1,sizeof(x))  
#define MemX(x) memset(x,0x3f,sizeof(x))  
#define pb push_back  
using namespace std;  
const int N=20;  
bool flag[N];  
  
int main(){  
  int k,i,x,j;  
  char n[N],s[N];  
  while(~scanf("%s%d",n,&k)){  
    Mem0(flag);  
    for(i=0;i<k;++i){  
      scanf("%d",&x);  
      flag[x]=1;  
    }  
    int len=strlen(n),f1=0,f2=0;  
    for(i=0;i<len;++i){  
      if(f2){  
        for(j=0;j<=9;++j){  
          if(flag[j]==0 && j>n[i]-'0'){  
            s[i]='0'+j;  
            n[i]=s[i];  
            break;  
          }  
        }  
        if(j==10){  
          if(!i){ f1=1; break; }  
          i-=2,f2=1;  
          continue;  
        }else{  
          f2=i;  
          break;  
        }  
      }  
      if(flag[n[i]-'0']){  
        for(j=0;j<=9;++j){  
          if(flag[j]==0 && j>n[i]-'0'){  
            s[i]='0'+j;  
            n[i]=s[i];  
            break;  
          }  
        }  
        if(j==10){  
          if(!i){ f1=1; break; }  
          f2=1,i-=2;  
          continue;  
        }else{  
          f2=i;  
          break;  
        }  
      }else s[i]=n[i];  
    }  
    if(f1){  
      for(i=1;i<=9;++i)  
        if(flag[i]==0){  
          printf("%d",i);  
          break;  
        }  
      for(i=0;i<=9;++i)  
        if(flag[i]==0){  
          while(len--)printf("%d",i);  
          break;  
        }  
    }else{  
      if(i==len)printf("%s",n);  
      else{  
        for(i=0;i<=f2;++i)  
          printf("%c",s[i]);  
        for(j=0;j<=9;++j)  
          if(flag[j]==0){  
            for(;i<len;++i)  
              printf("%d",j);  
            break;  
          }  
      }  
    }  
    puts("");  
  }  
}  

Measured memory_bytes: 256
s = int(input())
x2,y2 = 10**9,1
if s < 10**9:
  x3,y3 = s,0
else:
  y3 = (s // (10**9)) + 1
  x3 = 10**9 - (s % (10**9))
if s == 10**18:
  x2,y2,x3,y3 = 10**9,0,0,10**9
print(0,0,x2,y2,x3,y3)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin >> s;
    string temp = s;

    reverse(s.begin(),s.end()); 

    int count = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != temp[i]){
            count++;
        }
    }

    cout << count/2 << endl;
}

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

int main()
{
  string data[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int n;
  cin >> n;

  while( n-- ) {
    string s;
    cin >> s;

    int now_p = -1;
    char now_c = '0';
    for(int i=0; i<s.size(); i++) {
      if( s[i] == '0' ) {
	if( now_c == '0' ) continue;
	else {
	  cout << data[now_c-'0'][now_p];
	  now_c = '0';
	  now_p = -1;
	}
      } 
      else {
	now_c = s[i];
	now_p++;
	if( now_p >= data[now_c-'0'].size() ) {
	  now_p = 0;
	}
      }
    }

    cout << endl;
  }
}

Measured memory_bytes: 1212
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
//	int t;
//	cin>>t;
//	while(t--!=0){
//		//template
//	}  	
	long n,k;
	cin>>n>>k;
	if(n==k)
	cout<<0<<"\n";
	else{
		long x=n%k;
		long y=abs(x-k);
		if(y>x)
			cout<<x<<"\n";
		else
			cout<<y<<"\n";
	}
}

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

int main()
{
  vector<int> a(2);

  while(cin >> a[0] >> a[1]){
    if(a[0] == 0 && a[1] == 0) break;
    sort(a.begin(), a.end());
    cout << a[0] << " " << a[1] << endl;
  }

  return 0;

}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

    int count = 0;
    REP(i, 3)
        if (s[i] == '1')
            count++;
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd(int, int);
int lcm(int, int);

int main(void){
	for(int a, b; cin >> a >> b; cout << gcd(a, b) << " " << lcm(a, b) << endl);

	return 0;
}

int gcd(int a, int b){
	if(a < b) swap(a, b);
	while(a = a % b){
		if(a < b) swap(a, b);
	}
	return b;
}

int lcm(int a, int b){
	return a / gcd(a, b) * b;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


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

    int n;
    string s;
    cin >> n >> s;

    if(n <= 3){
        return cout << 0 << '\n',0;
    }

    vector<int> r(n+1), g(n+1), b(n+1);
    rep(i,n){
        r[i] += (s[i] == 'R');
        g[i] += (s[i] == 'G');
        b[i] += (s[i] == 'B');
        r[i+1] += r[i];
        g[i+1] += g[i];
        b[i+1] += b[i];
    }

    int res = 0;
    for(int j = 1; j < n-1; ++j){
        for(int i = 0; i < j; ++i){
            if(s[j] == 'R'){
                res += (s[i] == 'G') * (b[n] - b[j]);
                res += (s[i] == 'B') * (g[n] - g[j]);
                if(j - i + j < n){
                    res -= (s[i] == 'G') && (s[j-i+j] == 'B');
                    res -= (s[i] == 'B') && (s[j-i+j] == 'G');
                }
            }else if(s[j] == 'G'){
                res += (s[i] == 'R') * (b[n] - b[j]);
                res += (s[i] == 'B') * (r[n] - r[j]);
                if(j - i + j < n){
                    res -= (s[i] == 'R') && (s[j-i+j] == 'B');
                    res -= (s[i] == 'B') && (s[j-i+j] == 'R');
                }
            }else{
                res += (s[i] == 'R') * (g[n] - g[j]);
                res += (s[i] == 'G') * (r[n] - r[j]);
                if(j - i + j < n){
                    res -= (s[i] == 'R') && (s[j-i+j] == 'G');
                    res -= (s[i] == 'G') && (s[j-i+j] == 'R');
                }
            }
        }
    }

    cout << res << '\n';

    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

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

#define sz(x) ((int) (x).size())
#define TASK "text"

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

mt19937 mrand(random_device{} ()); 

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

void precalc() {
}

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

int mul(int a, int b) {
  return (long long) a * b % mod;
}

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

const int maxn = 105, maxx = (int) 1e4 + 5;
int n, k;

int read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return false;
  }
  return true;
}

int dp[maxn][maxx];
int cnt[maxn][maxx];

void solve() {
  memset(dp, 0, sizeof(dp));
  memset(cnt, 0, sizeof(cnt));
  cnt[n][0] = 1;
  for (int i = n; i > 0; i--) {
    for (int x = 0; x < maxx; x++) {
      auto curdp = dp[i][x];
      auto curcnt = cnt[i][x];
      for (int val = 0; val <= k; val++) {
        if (val > i) {
          add(cnt[i - 1][x], curcnt);
          add(dp[i - 1][x], curdp);
          add(dp[i - 1][x], mul(val, curcnt));
          continue;
        }
        int nx = x + (x + val) / i;
        add(cnt[i - 1][nx], curcnt);
        add(dp[i - 1][nx], curdp);
        add(dp[i - 1][nx], mul(val, curcnt));
      }
    }
  }
  int res = 0;
  for (int x = 0; x < maxx; x++) {
    add(res, dp[0][x]);
    add(res, mod - mul(x, cnt[0][x]));
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <array>
#include <iomanip>
#include <unordered_set>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0);
using namespace std;
const int N = 1e5;
const int M = 1e9+7;
int n, k;
ll dp[105][N+5];
int arr[105];


int main(){
    AC
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>arr[i];

    for(int i=0; i<=arr[0]; i++){
        dp[0][i] = 1;
    }

    for(int i=1; i<n; i++){
        dp[i][0] = 1;
        for(int j=1; j<=k; j++){
            if(j<=arr[i])
                dp[i][j] = (dp[i][j-1]+dp[i-1][j])%M;
            else{
                //if(j-1==arr[i])
                 //   dp[i][j] = ((dp[i][j-1]-dp[i][j-arr[i]-1])+dp[i-1][j])%M;
                dp[i][j] = (dp[i][j-1]-dp[i-1][j-arr[i]-1]+dp[i-1][j]+M)%M;
            }
            /*
            for(int z=j; z>=j-arr[i]&&z>=0; z--){
                dp[i][j]+=dp[i-1][z];
                dp[i][j]%=M;
            }
           */ 
        }
    }

    /*
    for(int i=0; i<n; i++){
        for(int j=0; j<=k; j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }
    */
    cout<<dp[n-1][k]<<endl;

}


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

int main(){
  int n, i, j, c=0, pn=0, N[10000];
  double k;

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

  for(i=0;i<n;i++){
    if(N[i]==2 || N[i]==3 || N[i]==5 || N[i]==7 || N[i]==11 || N[i]==13 || N[i]==17 || N[i]==19){
      pn++;
      continue;
    }
    else if(N[i]==1 || N[i]%2==0 || N[i]%3==0 || N[i]%5==0 || N[i]%7==0 || N[i]%11==0 || N[i]%13==0 || N[i]%17==0 || N[i]%19==0){
      continue;
    }
    k=N[i];
    k=sqrt(k);
    for(j=23;j<=k;j+=2){
      if(N[i]%j==0){
	c++;
	break;
      }
    }
    if(c==0){
      pn++;
    }
    c=0;
  }
  printf("%d\n",pn);

  return 0;
}

Measured memory_bytes: 632
x = int(input())
while True:
    if x == 2:
        break
    if x % 2 != 0:    
        for m in range(3,int(x**0.5) + 4 ,2):
            if x % m == 0 and x > m:
                break
        else:
            break
    x += 1
print (x)

Measured memory_bytes: 38384