akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
using namespace std;


int main() {
	long long int N,M;

	cin >> N >> M;
	if (N == 1 && M == 1) {
		cout << 1 << endl;
	}
	else if ((N == 1 && M >1)||(N>1&&M==1)) {
		cout << abs(N-M)-1 << endl;
	}
	else if ((N == 2 && M>1 )||(M==2&&N>1)) {
		cout << 0 << endl;
	}
	else {
		cout << (4+(N*M)-(2*N)-(2*M)) << endl;
	}



	return 0;
}







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

int main(){
  ll N,K,S;
  cin>>N>>K>>S;
  rep(i,K){cout<<S<<' ';}
  if(S!=1000000000){
  	rep(i,N-K){cout<<S+1ll<<' ';}
  }
  else{
  	rep(i,N-K){cout<<1<<' ';}
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pi pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int n,k;
  cin>>n>>k;
  int ans=0;
  for(int l=k;l<=n+1;l++){
    int c=0;
    // rep(i,l){
    //   c+=n-2*i;
    //   c%=MOD;
    // }
    ans+=l*(n-l+1);
    ans%=MOD;
    // ans+=15*MOD-l*(l-1);
    // ans%=MOD;
    ans++;
    ans%=MOD;

  }

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


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>
#include<queue>

int main()
{
	int a, b, c, x, count{};
	scanf("%d%d%d%d", &a, &b, &c, &x);
	x /= 50;
	for (int i = 0; i <= a; i++)
	{
		int tmp = x - i * 10;
		if (tmp < 0) continue;
		tmp += 2;
		for (int j = 0; j <= b; j++)
		{
			tmp -= 2;
			if (tmp < 0) break;
			if (tmp > c) continue;
			count++;
		}
	}
	printf("%d\n", count);

	return 0;
}

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

int main()
{
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int a[n];
    for(int i = 0; i < n; i++){
        a[i] = 0;
    }
    int k = 0;
    for(int i = 1; i < n; i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            k++;
        }
        a[i] = k;
    }
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        cout << a[r-1]-a[l-1] << endl;
    }
}

Measured memory_bytes: 1408
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>

using namespace std;

int main(){
    long long a,b,n;
    
    cin>>a>>b>>n;
    long long max;
    long long tmp1,tmp2,tmp3;
    long long i;
    
    /*
    if(b<=n){
        for(int i=0;i<=n;i++){
            tmp1=(int)(a*i/b);
            tmp2=(int)(i/b);
            tmp3=tmp1-tmp2;
            
            if(i==0){
                max=tmp3;
            }
            if(max<tmp3){
                max=tmp3;
            }
        }
    }else{
        for(int i=0;i<=b-1;i++){
            tmp1=(int)(a*i/b);
            tmp2=(int)(i/b);
            tmp3=tmp1-tmp2;
            
            if(i==0){
                max=tmp3;
            }
            if(max<tmp3){
                max=tmp3;
            }
        }
    }
    */
    if(b<=n){
        i=b-1;
    }else{
        i=n;
    }
    tmp1=(long long)(a*i/b);
    tmp2=(long long)(i/b);
    tmp3=tmp1-a*tmp2;
    cout<<tmp3<<"\n";
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
 
using namespace std;
template <typename T> T max(T a, T b) {return a>b?a:b;}
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
#define ll long long
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))

const double eps = (double)1e-6;
const int maxn = 1e5+5;
const ll mod = 1e9+7;

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

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

ll arr[maxn];

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

    int n,m; cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    ll tmp = arr[1];
    for (int i = 2; i <= n; i++) {
        arr[1] = lcm(arr[1], arr[i]);
    }
    swap(tmp, arr[1]);
    tmp /= 2;
    for (int i = 1; i <= n; i++) {
        if (tmp % arr[i] != arr[i]/2) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (m < tmp) { cout << 0 << endl; return 0; }
    cout << (m-tmp)/(2*tmp)+1 << endl;
    
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int A, B, M;
  cin >> A >> B >> M;
  
  int a[100000], b[100000];
  int min_a = 100000;
  int min_b = 100000;
  for (int i = 0; i < A; i++) {
  	cin >> a[i];
    min_a = min(min_a, a[i]);
  }
  for (int i = 0; i < B; i++) {
  	cin >> b[i];
    min_b = min(min_b, b[i]);
  }
 
  int ans = min_a + min_b;
  int x, y, c;
  for (int i = 0; i < M; i++) {
  	cin >> x >> y >> c;
    ans = min(ans, a[x-1] + b[y-1] - c);
  }
  cout << ans << "\n";

  return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	for(int i=0; i<n; i++) cin >> s[i];

	for(int i=0; i<n; i++){
		sort(s[i].begin(), s[i].end());
	}

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

	string res = s[0];
	string tmp = "";
	int tmpi;
	for(int i=1; i<n; i++){
		tmpi = 0;
		tmp = "";
		for(int j=0; j<res.length(); j++){
			for(int k=tmpi; k<s[i].length(); k++){
				if(res[j] == s[i][k]){
					tmpi = k+1;
					tmp.push_back(res[j]);
					break;
				}
			}
		}
		res = tmp;
	}
	cout << res << endl;
}



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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int A[100010];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K;
  cin >> N >> K;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    A[a] += b;
  }
  rep(i, 100000) A[i+1] += A[i];
  rep(i, 100010) {
    if(A[i] >= K) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
#include <boost/integer/common_factor_rt.hpp> // gcd, lcm


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

int64_t N;cin >> N;
VI abcde(5); rep(i, 0, 5) cin >> abcde[i];
VI::iterator neck = min_element(ALL(abcde));

if (N <= *neck){
    cout << "5\n";
    return 0;
}
int64_t t = distance(abcde.begin(), neck);
t += 5 - t + (N + *neck -1) / *neck;

cout << t - 1 << endl;

}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, m, q = map(int, input().split())
path = []
points = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1; b -= 1
    points.append((a, b, c, d))

def dfs(p):
    if len(p) == n:
        path.append(p)
        return
    last = p[-1]
    for i in range(last, m):
        dfs(p + [i])

dfs([0])

ans = 0
for p in path:
    score = 0
    for a, b, c, d in points:
        if p[b] - p[a] == c:
            score += d
    ans = max(ans, score)
print(ans)

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

int count(int n, vector<int>e){
    int cnt = 0;
    for(int i = 0; i < e.size(); i++){
        if(e[i] >= n - 1)cnt++;
    }
    return cnt;
}

int main(){
    int n;
    cin >> n;
    vector<int> e(n+1, 0);

    for(int i = 2; i <= n; i++){
        int tmp = i;
        for(int j = 2; j <= i; j++){
            while(tmp % j == 0){
                e[j]++;
                tmp /= j;
            }
        }
    }
    int ans = count(75, e) + count(25, e) * (count(3, e) - 1) + count(15, e) * (count(5, e) - 1) + count(5, e) * (count(5, e) - 1) * (count(3, e) - 2) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <tuple>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const ll INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}
template<class T>
void printp(vector<pair<T,T>> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}
template<class T>
void printp(map<T,T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main() {
    ll N;
    map<ll,ll> mp;
    cin>>N;
    rep(i,N){ll tmp;cin>>tmp;mp[tmp]++;}
    ll res = 0;
    for (auto const& [k, v] : mp) {
        if(k==v) continue;
        if(k>v) res+=v;
        if(k<v) res+=v-k;
    }
    // printp(mp);
    cout << res;
}

Measured memory_bytes: 9536
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,k,ans=0;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	ans+=min(a,k);
	k-=min(a,k);
	if(k){
		k-=min(b,k);
		if(k){
			ans-=min(c,k);
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 1728
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int p[10], c[10];
int main() {
	int D, G;
	cin >> D >> G;
	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
	}
	int ans = 1 << 30;
	for (int bit = 0; bit < (1 << D); bit++) {
		int sum = 0;
		int cnt = 0;
		for (int i = 0; i < D; i++) if (bit&(1 << i)) sum += (i + 1) * 100 * p[i] + c[i], cnt += p[i];
		for (int i = D - 1; i >= 0; i--) {
			if (bit&(1 << i)) continue;
			if (sum >= G) break;
			int add = min((G - sum) / ((i + 1) * 100), p[i]);
			sum += add*(i + 1) * 100;
			cnt += add;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int x;
    cin>>x;
    
    int ans=0;
    rep(i,1,100000){
        if(x<=0) break;
        x-=i;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b, i, j, flag = 0;
    int ans[10000];
    char op;

    for(i = 0; ; i++){
        scanf("%d %c %d", &a, &op, &b);
        switch(op){
            case '+': 
                ans[i] = a + b;
                break;
            
            case '-':
                ans[i] = a - b;
                break;

            case '*':
                ans[i] = a * b;
                break;

            case '/':
                ans[i] = a / b;
                break;

            case '?':
                flag++;
                break;
        }
        if(flag == 1) break;
    }

    for(j = 0; j < i; j++) printf("%d\n", ans[j]);

    return 0;
}


Measured memory_bytes: 2132
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int mod=1000000007;
char A[11000];
char B[11000];
char C[1100];
long long pow10[11000];
long long aval[11000];
long long bval[11000];
int main(){
	scanf("%s%s%s",B,A,C);
	pow10[0]=1;
	for(int i=1;i<11000;i++)pow10[i]=pow10[i-1]*10%mod;
	int a=strlen(A);
	int b=strlen(B);
	int c=strlen(C);
	long long r1=0;
	long long tmp=0;
	for(int i=0;i<a;i++){
		aval[i+1]=(aval[i]+pow10[i]*(A[a-1-i]-'0')%mod)%mod;
	}
	for(int i=0;i<b;i++){
		bval[i+1]=(bval[i]+pow10[i]*(B[b-1-i]-'0')%mod)%mod;
	}
	for(int i=0;i<a-c+1;i++){
		int ok=0;
		for(int j=0;j<c;j++){
			if(A[i+j]>C[j]){ok=1;break;}
			if(A[i+j]<C[j]){ok=-1;break;}
		}
		if(C[0]=='0')r1=(r1+mod-pow10[a-c-i])%mod;
		if(ok==1)r1=(r1+pow10[a-c-i])%mod;
		else if(~ok)r1=(r1+aval[a-c-i]+1)%mod;
		r1=(r1+pow10[a-c-i]*tmp)%mod;
		tmp=(tmp*10+A[i]-'0')%mod;
	//	printf("%lld\n",r1);
	}
	long long r2=0;
	tmp=0;
	for(int i=0;i<b-c+1;i++){
		int ok=0;
		for(int j=0;j<c;j++){
			if(B[i+j]>C[j]){ok=1;break;}
			if(B[i+j]<C[j]){ok=-1;break;}
		}
		if(C[0]=='0')r2=(r2+mod-pow10[b-c-i])%mod;
		if(ok==1)r2=(r2+pow10[b-c-i])%mod;
		else if(~ok)r2=(r2+bval[b-c-i]+1)%mod;
		r2=(r2+pow10[b-c-i]*tmp)%mod;
		tmp=(tmp*10+B[i]-'0')%mod;
	//	printf("%lld\n",r1);
	}
	long long r3=0;
	for(int i=0;i<b-c+1;i++){
		bool ok=true;
		for(int j=0;j<c;j++){
			if(B[i+j]!=C[j]){ok=false;break;}
		}
		if(ok)r3++;
	}
	printf("%lld\n",(r1+mod-r2+r3)%mod);
}

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

int main(){
    int n; cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];

    long long ans=0;
    for(int i=1;i<=n;i++){
        if(i==a[a[i]]) ans++;
    }
    cout<<ans/2<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int x[4], y[4];
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    x[2] = x[1] - (y[1]-y[0]);
    y[2] = y[1] + (x[1]-x[0]);
    x[3] = x[2] - (y[2]-y[1]);
    y[3] = y[2] + (x[2]-x[1]);
    cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;
    return 0;
}


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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int t,k,l,r;
    cin>>t>>k>>l>>r;
    bool al=true;
    if(r==-1 || l==-1){
        if(t>k) al=false;
        if(t==k){
            cout << "Draw" << endl;
            return 0;
        }
    }
    else if(r==l){
        cout << "Draw" << endl;
        return 0;
    }
    else if(l<r){
        al=false;
    }
    if(al){
        cout << "Alice" << endl;
    }
    else cout << "Bob" << endl;

    
}


Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef long long ll;
typedef vector<int> vi;

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

    int ans = b[a[0]-1];
    for(int i = 1; i < n; i++){
        ans += b[a[i]-1];
        if(a[i-1]+1 == a[i])
            ans += c[a[i-1]];
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool is_prime(int n)
{
    int r;
    r = sqrt(n);
    for(int i=2;i<=r;i++)
    {
        if(n%i==0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    ll x;
    cin>>x;
    while(!is_prime(x))
    {
        x++;
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"

using namespace std;

const int N = 2e5 + 5;

int main() {
  vector< string> sa, bs, xx;
  string s;

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
  	string x;
  	cin >> x;
  	if (x[0] == 'B' and x.back() == 'A') s += x;
  	else if (x[0] == 'B') bs.emplace_back(x);
  	else if (x.back() == 'A') sa.emplace_back(x);
  	else xx.emplace_back(x);
  }
  if (!sa.empty()) {
  	s = sa.back() + s;
  	sa.pop_back();
  }
  if (!bs.empty()) {
  	s += bs.back();
  	bs.pop_back();
  }

  while (!sa.empty() and !bs.empty()) {
  	string x = sa.back() + bs.back();
  	xx.push_back(x);
  	sa.pop_back();
  	bs.pop_back();
  }

  for (auto& x: bs) s += x;
  for (auto& x: sa) s = x + s;
  for (auto& x: xx) s += x;

  int res = 0;
  for (int i = 0; i + 1 < s.size(); i ++) {
  	if (s[i] == 'A' && s[i + 1] == 'B') res ++;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long 
#define pb push_back
using namespace std;

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=2e5+5;
const int mod=1e9+7;

int n,m,a,b,ans,jc[N],inv[N];

inline int ksm(int x,int y)
{
	int ret=1ll;
	while(y)
	{
		if(y&1) ret=ret*x%mod;
		x=x*x%mod;
		y>>=1ll;
	}
	return ret;
}

inline int C(int x,int y)
{
	return jc[x]%mod*inv[y]%mod*inv[x-y]%mod;
}

signed main()
{
	n=read();
	m=read();
	a=read();
	b=read();
	jc[0]=1,inv[0]=1;
	for ( int i=1;i<=max(n,m)*2;i++ ) jc[i]=jc[i-1]*i%mod;
	for ( int i=1;i<=max(n,m)*2;i++ ) inv[i]=ksm(jc[i],mod-2)%mod;
	for ( int i=1;i<=n-a;i++ )
		ans=(ans+C(i-1+b-1,i-1)*C(n-i+m-b-1,m-b-1)+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}
	

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;

// #define int long long
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  int M;
  array<int, 10000> A;
  // string S;
  // string T;

  cin >> N >> M;

  if (N % M == 0) cout << 0 << endl;
  else cout << 1 << endl;
  
  
  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   cin >> *it;

  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   if (*it % 2 == 0) ++num;

  // cout << num << end;
  
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
t = [-1]*N
for i in range(M):
    s, c=map(int, input().split())
    s -= 1
    if t[s] != -1 and t[s] != c:
        print(-1)
        exit()
    t[s] = c
if N != 1:
    if t[0] == 0:
        print(-1)
        exit()
    if t[0] == -1:
        t[0] =1
    for i in range(1,N):
        if t[i] == -1:
            t[i] = 0
else:
    if t[0] == -1:
        t[0] = 0
print("".join(map(str,t)))
        


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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

long long p = 1e9+7.5;

ll pwr(ll a, ll n) {
    ll res = 1;
    while(n){
        if(n%2)
            res=res*a%p;
        a=a*a%p;
        n>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    cout<<(5*p+pwr(10,n)-2*pwr(9,n)+pwr(8,n))%p<<'\n';
    
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << ((b-a)==(c-b)?"YES":"NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int binary(long long bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

int main(){
  string s;
  cin >> s;
  int a = 0,b = 0;
  for(int i = 0;i<s.size();i++) {
    if(s[i] == '0') {
      a++;
    }else {
      b++;
    }
  }
//  a = a/2*2;
//  b = b/2*2;
  if (a>=b) {
    cout <<b*2;
  } else {
    cout <<a*2;
  }
} 

Measured memory_bytes: 512
#include<bits/stdc++.h>   
using namespace std;    
int main(){
  int n;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }

  sort(p.begin(),p.end());
  p[n-1]=p[n-1]/2;
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=p[i];
  }

  cout<<ans<<endl;
}



  
  

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		String t = scan.next();
		String p = scan.next();

		nFind(t, p);

		scan.close();
		System.exit(0);
	}

	private static void nFind(String t, String p){
		for(int st = 0; st < t.length() - p.length()+1; st++) //t?????????-p?????????+1??????????¢??????????
			if(isEqual(t, p, st))
				System.out.println(st);
	}

	private static boolean isEqual(String t, String p, int st){
		for(int i = 0; i < p.length(); i++)
			if(t.charAt(st + i) != p.charAt(i))
				return false;
		return true;
	}
}

Measured memory_bytes: 26268
/******************************************
* AUTHOR : AAYUSH GARG*
* NICK : aayushgarg_03 *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define for0(i, n) for(ll i = 0; i < n; i++)
#define for2(a,b,c) for(ll i=a;i<b;i+=c)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define VP vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define ascii(c) (int)char (c)
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define N 1000000

ll prime[N];

ll mulmod(ll a, ll b, ll m) 
{ 
    ll res = 0;  
    a = a % m; 
    while (b > 0) 
    { 
       
        if (b % 2 == 1) 
            res = (res + a) % m; 
  
        
        a = (a * 2) % m; 
  
        
        b /= 2; 
    } 
  
    return res % m; 
} 

ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        
        ll q = a / m; 
        ll t = m; 
  
        m = a % m, a = t; 
        t = y; 
  
        
        y = x - q * y; 
        x = t; 
    } 
  
    
    if (x < 0) 
       x += m0; 
  
    return x; 
} 

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;  
  
    while (y > 0) 
    { 
        
        if (y & 1) 
            res = (res*x) % p; 
  
         
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
}

void sieve() {
    for(ll i = 0;i < N;i++)
        prime[i] = 1;
    prime[0] = 0;
    prime[1] = 0;
    for(ll i = 2;i*i < N;i++) {
        if(prime[i] == 0)
            continue;
        for(ll j = i*i;j < N;j+=i) {
            prime[j] = 0;
        }
    }
    for(ll i = 1;i < N;i++)
        prime[i] += prime[i-1];
}



bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

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

ll n;
cin>>n;
ll a[n];
for0(i,n)
 cin>>a[i];

ll dp[n];
dp[0] = 0;
dp[1] = abs(a[1]-a[0]);

for(ll i=2;i<n;i++)
	dp[i] = min(dp[i-2] + abs(a[i]-a[i-2]),dp[i-1] + abs(a[i]-a[i-1])); 

cout<<dp[n-1]<<endl;





return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	multiset<int> st;
	int n;
	cin >> n;
	int a;
	cin >> a;
	st.insert(a);
	for (int i = 0; i < n-1; i++) {
		int a;
		cin >> a;
		auto o = st.multiset::lower_bound(a);
		if (o == st.begin()) {
			st.insert(a);
		}
		else {
			st.erase(--o);
			st.insert(a);
		}
	}
	cout << st.size() << endl;
	return 0;
}


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

using namespace std;

int arr[1000000],cost[1000000];

int modu(int a)
{
	if(a>0)
		return  a;
	else
		return -1*a;
}

int  main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n,a,b,c,d;
	cin>>n;

	for (int i = 1; i <=n; ++i)
	{
		cin>>arr[i];
		cost[i]=1000000001;
	}

	cost[1]=0;
	cost[2]=modu(arr[2]-arr[1]);

	for (int i = 3; i <=n; ++i)
	{
		a=modu(arr[i]-arr[i-1])+cost[i-1];
		b=modu(arr[i]-arr[i-2])+cost[i-2];
		cost[i]=min(a,b);
	}
	cout<<cost[n];
	return 0;
}

Measured memory_bytes: 4736
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

const int mod = 1000000007;
struct mint{
    ll x;
    mint(ll x=0):x(x%mod){}
    mint& operator+=(const mint a){
        if ((x+= a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if ((x+= mod - a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a) const{
        mint ans(*this);
        return ans+= a;
    }
    mint operator-(const mint a) const{
        mint ans(*this);
        return ans-= a;
    }
    mint operator*(const mint a) const{
        mint ans(*this);
        return ans*= a;
    }
};

mint dp0[2005][2005];
mint dp1[2005][2005];


int main(){
    int n,m;
    cin >> n >> m;
    vector<int> s(n+1), t(m+1);
    rep(i,n) cin >> s[i];
    rep(i,m) cin >> t[i];
    dp0[0][0] = 1;
    rep(i,n+1) rep(j,m+1){
        dp0[i+1][j] += dp0[i][j];
        dp1[i][j] += dp0[i][j];
        dp1[i][j+1] += dp1[i][j];
        if (s[i] == t[j]) dp0[i+1][j+1] += dp1[i][j];
    }
    mint ans = dp1[n][m];
    cout << ans.x;
    rn 0;
}

Measured memory_bytes: 63104
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <cassert>
#include <random>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}
const int N = 1e6 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	ll n, x, m; cin>>n>>x>>m;
	int seen[m] = {};
	ll res = x;
	seen[x] = 0;
	vector<int> vec(1, x);
	int ptr = 0;
	for(int i = 1; !seen[x*x%m]; i++){
		x = x*x%m;
		seen[x] = i;
		vec.pb(x);
	}
	if(n < vec.size()){
		ll sum = 0;
		for(int i = 0; i < n; i++) sum += vec[i];
		cout<<sum<<"\n";
		return 0;
	}
	int start = seen[x*x%m];
	int end = vec.size();
	n -= start;
	end--;
	int kalan = n % (end - start + 1);
	ll carp = n / (end - start + 1);
	ll sum = 0;
	for(int i = 0; i < start; i++) sum += vec[i];
	ll loop = 0;
	for(int i = start; i <= end; i++) loop += vec[i];
	loop *= max(1ll, carp);
	for(int i = start; i < start + kalan; i++) sum += vec[i];
	cout<<sum + loop<<"\n";
}

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

int main()
{
    int d;
    cin >> d;

    cout << "Christmas";
    for (int i = d; i < 25; i++)
        cout << " Eve";
    cout << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

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

  int M, D;
  cin >> M >> D;
  int ans = 0;
  for(int i = 1; i <= M; i++){
    for(int j = 1; j <= D; j++){
      int d10 = j / 10;
      int d1  = j % 10;
      if(d10 > 1 && d1 > 1 && (i == d10 * d1)){
        ans++;
      }
    }
  }

  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const int INFI = 1000000000;
 const ll INFL = (1LL << 60);

 int main() {
     string S;
     cin >> S;
     vector<vector<ll>> dp(S.size()+1, vector<ll>(13, 0));
     dp[0][0] = 1;
     for (int i = 0; i < S.size(); i++) {
         for (int j = 0; j < 13; j++) {
             if (S[i] == '?') {
                 for (int k = 0; k < 10; k++) {
                     dp[i+1][(j * 10 + k) % 13] += dp[i][j];
                     dp[i+1][(j * 10 + k) % 13] %= MOD;
                 }
             }
             else {
                 int k = S[i] - '0';
                 dp[i+1][(j * 10 + k) % 13] += dp[i][j];
                 dp[i+1][(j * 10 + k) % 13] %= MOD;
             }
         }
     }
     cout << dp[S.size()][5] << endl;
 }


Measured memory_bytes: 13696
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++)arr[i] = scan.nextInt();
        scan.close();
        int[] dp = new int[n+1];
        Arrays.fill(dp,1000000005);
        dp[0] = 0;
        for(int i= 0;i<n;i++){
            for(int j=1;j<=k;j++){
                if(i+j < n)dp[i+j] = Math.min(dp[i+j],dp[i] + Math.abs(arr[i]- arr[i+j]));
            }
        }
        System.out.println(dp[n-1]);
        }
}


Measured memory_bytes: 50044
# coding: utf-8
while 1:
    m,n_min,n_max=map(int,input().split())
    if m==0:
        break
    data=[]
    for i in range(m):
        data.append(int(input()))
    data=sorted(data,reverse=True)
    mx=(-1,-1)
    for i in range(n_min,n_max+1):
        if data[i-1]-data[i]>=mx[0]:
            mx=(data[i-1]-data[i],i)
    print(mx[1])


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a.back() == b[0] && b.back() == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,b,f,r,v,i,x,y,z;
    int a[4][3][10] = {{{0}}};
    
    scanf("%d\n",&n);
    
    for (i=0; i<n; i++)
    {
    scanf("%d %d %d %d\n",&b,&f,&r,&v);
    a[b-1][f-1][r-1] = v + a[b-1][f-1][r-1];
    }

    for (x=0; x<4; x++)
    {
        for (y=0; y<3; y++)
        {
            for (z=0; z<10; z++)
            {
            printf(" %d",a[x][y][z]);
            }
            printf("\n");
        }
        if (x==0 || x==1 || x==2)
        printf("####################\n");
    }
    return 0;
}



Measured memory_bytes: 2124
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
ans = 1000
for i in range(1 << d):
    score = 0
    num = 0
    rest = 0
    for j in range(d):
        if ((i >> j) & 1) == 1:
            score += pc[j][0]*100*(j+1) + pc[j][1]
            num += pc[j][0]
        else:
            rest = j
    if score < g:
        need = (g-score-1)//(100*(rest+1))+1
        if need > pc[rest][0]-1:
            continue
        else:
            num += need
    ans = min(ans, num)
print(ans)

Measured memory_bytes: 3064
N=int(input())

answer=0
num_ba=0
num_a=0
num_b=0
for _ in range(N):
  s=input()
  for i in range(1,len(s)):
    if s[i-1]=="A" and s[i]=="B":
      answer+=1
  
  if s[0]=="B" and s[-1]=="A":
    num_ba+=1
  elif s[0]=="B":
    num_b+=1
  elif s[-1]=="A":
    num_a+=1

if num_ba>0:
  answer+=num_ba-1
  if num_b>0:
    answer+=1
    num_b-=1
  if num_a>0:
    answer+=1
    num_a-=1
  
answer+=min(num_a,num_b)
print(answer)

Measured memory_bytes: 9252
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	lli a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max({a * c,a * d,b * c,b * d}) << newl;
	

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
int a[214514];
signed main(){
	int n;
	cin>>n;
	int sum=n;
	rep(0,i,n)cin>>a[i];
	rep(0,i,n){
		if(a[i+1]>a[i])sum-=1;
	}
	c(sum)
	c(n)
}		



Measured memory_bytes: 3900
import sys

INF = float('inf')

def Bellmanford(n, edges, r):
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        flag = False
        
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                flag = True
                
        if flag and i == n-1:
            return ['NEGATIVE CYCLE']
        
    d = [di if di < INF else 'INF' for di in d]
    return d

V, E, R = map(int, sys.stdin.readline().split())
Edges = [None] * E

for i in range(E):
    si, ti, di = map(int, sys.stdin.readline().split())
    Edges[i] = (si, ti, di)
    
ans = Bellmanford(V, Edges, R)

print(*ans, sep = '\n')

Measured memory_bytes: 8236
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

vector<ll> prime;

bool Prime_Check(ll a){
	if(a==1)return false;
	ll dim=ll(sqrt(a));
	for (int i=2;i<=dim;i++){
		if(a%i==0)return false;
	}
	return true;
}

void Prime(){
	for(int i=2;i<=55555;i++){
		if(Prime_Check(i)){
			prime.push_back(i);
		}
	}
}
int main(){
	int n,count=0;
	cin>>n;
	Prime();
	for(int i=0;count!=n;i++){
		if(prime[i]%5==1){
			cout<<prime[i];
			count++;
			if(count!=n)cout<<" ";
		}
		
	}
	return 0;
}


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

int main() {
  string str;
  while(cin >> str) {
    for(int i = 0; i < str.length(); ++i) {
      if(str[i] == '@') {
        ++i;
        for(int j = 0; j < str[i] - '0'; ++j) {
          cout << str[i + 1];
        }
        ++i;
      } else {
        cout << str[i];
      }
    }
    cout << endl;
  }
  return 0;
}

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

int G[11][11];
int main() {
  for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) cin >> G[i][j];
  int res = 0;
  for (int num = 0; num < 10000; ++num) {
	vector<int> vec;
	int tnum = num;
	while (tnum > 0) vec.push_back(tnum%10), tnum /= 10;
	while (vec.size() < 4) vec.push_back(0);
	reverse(vec.begin(), vec.end());
	int e = G[G[G[G[0][vec[0]]][vec[1]]][vec[2]]][vec[3]];
	vec.push_back(e);

	//cout << num << ": ";

	bool ok = true;
	for (int it = 0; it < 5; ++it) {
	  for (int a = 0; a < 10; ++a) {
		if (vec[it] == a) continue;
		vector<int> nvec = vec;
		nvec[it] = a;
		int check = G[G[G[G[G[0][nvec[0]]][nvec[1]]][nvec[2]]][nvec[3]]][nvec[4]];
		if (check == 0) ok = false;
	  }
	}
	for (int it = 0; it < 4; ++it) {
	  vector<int> nvec = vec;
	  swap(nvec[it], nvec[it+1]);
	  if (nvec == vec) continue;
	  int check = G[G[G[G[G[0][nvec[0]]][nvec[1]]][nvec[2]]][nvec[3]]][nvec[4]];
	  if (check == 0) {
		ok = false;
	  }
	}
	
	if (!ok) ++res;
  }
  cout << res << endl;
}



Measured memory_bytes: 3160
<?php
fscanf(STDIN, '%d %d %d %d', $h, $w, $a, $b);
for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
        if ($i <= $b - 1 && $j <= $a - 1) echo '0';
        elseif ($i > $b - 1 && $j <= $a - 1) echo '1';
        elseif ($i <= $b - 1 && $j > $a - 1) echo '1';
        else echo '0';
    }
    echo PHP_EOL;
}

Measured memory_bytes: 5624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 1e9+7;
 
vector<ll> fact,ifact,inv,pow2;
ll add(ll a,ll b)
{
	a%=MOD; b%=MOD;
	a+=b;a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	a%=MOD; b%=MOD;
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
ll inverse(ll a)
{
	return pw(a,MOD-2);
}
ll choose(ll a, ll b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
void init(ll _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1); ifact.resize(_n+1); inv.resize(_n+1); pow2.resize(_n+1);
	pow2[0]=1; ifact[0]=1; fact[0]=1;
	for(int i=1;i<=_n;i++){
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--){
	    ifact[i] = mult(ifact[i+1], i+1);
	}
	for(int i=1;i<=_n;i++){
	    inv[i] = mult(fact[i-1], ifact[i]);
	}
}
void getpf(vector<ii>& pf, ll n)
{
	for(ll i=2; i*i<=n; i++)
	{
		int cnt=0;
		while(n%i==0){
			n/=i; cnt++;
		}
		if(cnt>0) pf.pb({i,cnt});
	}
	if(n>1) pf.pb({n,1});
}
 
const int MAXN = 100005;
 
ll X,Y;
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	init(1e6+5);
	
	cin>>X>>Y;
	if(X>Y) swap(X,Y);
	
	ll cnt=0;
	while(Y>X && Y>0){
		Y-=2; X--;
		cnt++;
	}
	if(Y>X || X%3!=0){ cout<<0<<'\n'; exit(0); }
	
	cout<<choose(X/3*2+cnt, cnt+X/3)<<'\n';
	
	return 0;
}

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

 int main(){
     int n;
      cin >> n;
      for(int i=0;i<n*2+10;i++){
          int to=i+(i*8)/100;
          if(to==n){
              cout << i << endl;
              break;
          }
          if(to>n){
              cout << ":(" << endl;
              break;
          }
      }
      return 0;
 }

Measured memory_bytes: 3556
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n + 1), b;
  rep(i, n + 1) cin >> a[i];
  b.push_back(0);
  rep(i, n) {
    int tmp;
    cin >> tmp;
    b.push_back(tmp);
  }
  b.push_back(0);
  ll ans = 0;
  rep(i, n + 1) {
    ll toubatsu = min(a[i], b[i]);
    ans += toubatsu;
    a[i] -= toubatsu;
    toubatsu = min(a[i], b[i + 1]);
    ans += toubatsu;
    b[i + 1] -= toubatsu;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	string s;
	cin>>s;
	for(int i=0;i<=s.size()-1;i++)
	{
		if(s[i]=='?')
			cout<<'D';
		else
			cout<<s[i];
	}
	return 0;
}




Measured memory_bytes: 3788
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e5+5,INF=1e18;

void solve()
{
    ll a,b;
    cin >> a >> b;
    cout << a*b/__gcd(a,b);
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 256