akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
typedef long long ll;

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


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len, a, b, c;
	int *A, *B, C, Ntemp, M, K,num_R,num_G,num_B;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count, N;
	ll **dp;
	double ans;

	scanf("%d %d", &Ntemp ,&K);

	N = (ll) Ntemp;

	for (i = K; i <= N+1; i++){
		min =  i * (i - 1) / 2;

		max = (ll)N*(N + 1) / 2 - (ll)(N - i)*(N - i + 1) / 2;

		count = (max - min + 1);
		sum += count;
		sum %= 1000000007;

	
	}
	//sum++;
	printf("%lld\n", sum);


	return 0;

}
    

Measured memory_bytes: 3824
fun main(args: Array<String>) {
    var dict : MutableMap<Char,MutableList<Char>> = mutableMapOf()
    dict['a'] = readLine()!!.toMutableList()
    dict['b'] = readLine()!!.toMutableList()
    dict['c'] = readLine()!!.toMutableList()
    var turn = 'a'
    while(true){
        var list = dict[turn]
        if(list!!.size == 0){
            println(turn.toUpperCase())
            break
        } 
        turn = list[0]
        list.removeAt(0)
    }
}


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

#define ll long long
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForR(i,l,r) for(int i=l;i>=r;i--)

int main() {
	//freopen(".inp","r",stdin);
	//freopen(".out","w",stdout);
	ll n;
	cin >> n;
	ll a[n+5];
	For(i,1,n) cin >> a[i];
	sort(a+1,a+n+1);
	For(i,1,n-1) if(a[i]==a[i+1]) {
		cout << "NO";
		return 0;
	}
	cout << "YES";	
	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//        freopen("output.txt","w",stdout);
//    #endif
}
int main()
{
    vok();
    int a,b,c;
    IN a>>b>>c;
    OUT c<<" "<<a<<" "<<b;
    return 0;
}



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

int main() {
  int n, d, ans = 0;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  REP(i, n) REP(j, d) cin >> x[i][j];
  REP(i, n) {
    if (i == n) break;
    FOR(j, i+1, n) {
      double calc = 0;
      REP(k, d) calc += pow((double)(x[i][k] - x[j][k]), 2);
      calc = sqrt(calc);
      if (ceil(calc) == floor(calc)) ans++;
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, m; cin >> n >> m;

	vvl adj(n);
	while (m--) {
		ll a, b; cin >> a >> b;
		a--, b--;
		adj[a].pb(b), adj[b].pb(a);
	}
	
	vl c(n);
	for (ll i: adj[0]) c[i]++;
	for (ll i: adj[n-1]) c[i]++;
	
	FOR(i,1,n-1) if (c[i] == 2) {
		cout << "POSSIBLE" << endl;
		return 0;
	}
	cout << "IMPOSSIBLE" << endl;

}



Measured memory_bytes: 14312
#include<bits/stdc++.h>
#define LL long long
#define fo(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main(){
	//ios::sync_with_stdio(0);
	string s;
	cin>>s;
	if(s.find("7")!=-1)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for (int l = 0, r = n - 1; l < r; ) {
    if (s[l] == 'R') {
      l++;
      continue;
    }
    if (s[r] == 'W') {
      r--;
      continue;
    }

    ans++;
    l++;
    r--;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int t[200];
int a[200], b[200], c[200];

int dp[200][200];

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

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

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

    for (int i = 1; i < d; ++i) {
        for (int j = 0; j < n; ++j) { // i??\???
            if (a[j] <= t[i] && t[i] <= b[j]) {
                for (int k = 0; k < n; ++k) {
                    if (a[k] <= t[i - 1] && t[i - 1] <= b[k]) {
                        dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[j] - c[k]));
                    }
                }
            }
        }
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        ans = max(ans, dp[d - 1][i]);
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 1304
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long LL;

struct Dict {
    map<string,int> dict;

    int get(const string &str) {
        if(dict.count(str)) return dict[str];
        int id = dict.size();
        return dict[str] = id;
    }
};

int best = 0;
void dfs(int pos, LL used, int score, const vector<LL> &neighbors, const vector<LL> &neighbors_rem, const vector<int> &scores, const vector<int> &scores_rem) {
    const int N = neighbors.size();
    if(pos == N) {
        best = max(best, score);
        return; 
    }
    if(score + scores_rem[pos] <= best) {
        return;
    }
    LL mask = 1LL<<pos;

    if(!(used & mask)) {
        dfs(pos+1, used | neighbors[pos] | mask, score + scores[pos], neighbors, neighbors_rem, scores, scores_rem);
    }
    if((used & mask) || (pos+1 < N && (neighbors_rem[pos+1] & mask))) {
        dfs(pos+1, used, score, neighbors, neighbors_rem, scores, scores_rem);
    }
}

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

    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<LL> neighbors(N, 0);
        vector<int> scores(N, 0);
        Dict dict;
        for(int i = 0; i < N; ++i) {
            string name;
            int score, ncnt;
            cin >> name >> score >> ncnt;
            const int cid = dict.get(name);
            scores[cid] = score;
            while(ncnt--) {
                string nname;
                cin >> nname;
                const int nid = dict.get(nname);
                neighbors[cid] |= 1LL<<nid;
            }
        }

        vector<LL> neighbors_rem(N, 0);
        vector<int> scores_rem(N, 0);
        neighbors_rem[N-1] = neighbors[N-1];
        scores_rem[N-1] = scores[N-1];
        for(int i = N-2; i >= 0; --i) {
            neighbors_rem[i] = neighbors_rem[i+1] | neighbors[i];
            scores_rem[i] = scores_rem[i+1] + scores[i];
        }
        best = 0;
        dfs(1, neighbors[0] | 1, scores[0], neighbors, neighbors_rem, scores, scores_rem);
        cout << best << endl;
    }

    return 0;
}

Measured memory_bytes: 940
def OK(d1,d10,m):
    if d1>=2 and d10>=2 and d1*d10==m:
        return True
    else:
        return False
in1=input()
M1,D1=in1.split()
M=int(M1)
D=int(D1)
con=0
for m in range(M+1):
    for d in range(D+1):
        ones=d%10
        if D>=10:
            tens=d//10
        else:
            tens=0
        if OK(ones,tens,m):
            con+=1
print(con)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}

LL knapsackZeroOne(LL N, LL W, VI& weight, VI& value) {   // weight & value must be 1-indexed
    VVI dp(N + 1, VI(W + 1));   // dp[i][j] = max value sum with weight <= j using up to i-th objects
    FOR(i, 1, N + 1) {
        REP(j, W + 1) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);   // don't use object i
            if (j - weight[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]);   // use object i
        }
    }
    return dp[N][W];
}

LL knapsackUnbounded(LL N, LL W, VI& weight, VI& value) {   // weight & value must be 1-indexed
    VVI dp(N + 1, VI(W + 1));   // dp[i][j] = max value sum with weight <= j using up to i-th objects
    FOR(i, 1, N + 1) {
        REP(j, W + 1) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);   // don't use object i
            if (j - weight[i] >= 0) dp[i][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);   // use object i
        }
    }
    return dp[N][W];
}

int main() {
    LL N;
    cin >> N;
    VVI R(2, VI(3 + 1));
    REP(i, 2) {
        FOR(j, 1, 3 + 1) {
            cin >> R[i][j];
        }
    }

    VI weight(3 + 1), value(3 + 1);
    FOR(i, 1, 3 + 1) {
        weight[i] = R[0][i];
        value[i] = R[1][i] - R[0][i];   // consider the difference (how many N increases)
    }
    N += knapsackUnbounded(3, N, weight, value);   // A -> B
    FOR(i, 1, 3 + 1) {
        weight[i] = R[1][i];
        value[i] = R[0][i] - R[1][i];   // consider the difference (how many N increases)
    }
    N += knapsackUnbounded(3, N, weight, value);   // B -> A

    cout << N << endl;
	
    return 0;
}


Measured memory_bytes: 976996
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int a, b, x, tmp, ans;

int main() {

	cin >> a >> b >> x;

	if (x % 1000 > 500) {
		if (a - 2 * b > 0) {
			ans = x / 500 * b + b;
		}
		else {
			ans = x / 1000 * a + a;
		}
	}
	else if (x % 1000 == 0) {
		if (a - 2 * b > 0) {
			ans = x / 500 * b;
		}
		else {
			ans = x / 1000 * a;
		}
	}
	else if (x % 1000 == 500) {
		if (a - 2 * b > 0) {
			ans = x / 500 * b - b;
		}
		else {
			ans = x / 1000 * a;
		}
		if (a < b)ans += a;
		else ans += b;
	}
	else if (x % 1000 < 500) {
		if (a - 2 * b > 0) {
			ans = x / 500 * b;
		}
		else {
			ans = x / 1000 * a;
		}
		if (a < b)ans += a;
		else ans += b;
	}

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


Measured memory_bytes: 3120
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int n, m, X, Y;
  bool f=true;
  vector<int> x, y;
  cin >> n >> m >> X >> Y;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  for(int i=0;i<m;i++){
    int tmp;
    cin >> tmp;
    y.push_back(tmp);
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  int a=x[x.size()-1], b=y[0];
  if(a<b){
    for(int i=a+1;i<=b;i++){
      if(i>X&&i<=Y){
        f=false;
        break;
      }
    }
  }

  if(f)puts("War");
  else puts("No War");
  return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
p = mod 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

N, K = map(int, input().split())
A = sorted(map(int, input().split()))
R = sorted(A, reverse=True)

ans = 0

for i in range(N-K+1):
    
    t = cmb( N-i-1, K-1, mod)
    mi = A[i] * t % mod
    ma = A[N-(i+1)] * t % mod
    ans = ( ans + ma - mi ) % mod 

print(ans)

Measured memory_bytes: 26660
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int power(ll a, ll b) {
	ll result = 1;
	while(b) {
		if(b % 2) result = (result * a) % P;
		a = (a * a) % P;
		b /= 2;
	} 
	
	return result;
}

int divide(ll a, ll b) {
	return (a * power(b, P - 2)) % P;
}

int C(int n, int k) {
	ll result = 1, inv = 1;
	for(int i = n - k + 1; i <= n; i++) result = (result * i) % P;
	for(int i = 1; i <= k; i++) inv = (inv * i) % P;
	result = divide(result, inv);
	
	return result;
}

void solve() {
	int n, a, b;
	cin >> n >> a >> b;
	
	cout << (((power(2, n) - C(n, a) + P) % P - C(n, b) + P) % P - 1) % P << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
cards = [[ s+' '+str(n) for n in range(1,14)] for s in ['S','H','C','D']]
for _ in range(n):
    suit,num = input().split()
    if   suit=='S': cards[0][int(num)-1] = 0
    elif suit=='H': cards[1][int(num)-1] = 0
    elif suit=='C': cards[2][int(num)-1] = 0
    elif suit=='D': cards[3][int(num)-1] = 0
for s in cards:
    for n in s:
        if n!=0: print(n)


Measured memory_bytes: 5600
# coding: utf-8
# Your code here!
K=int(input())

mods=[0]*10**6

temp=7
ans=0
while mods[temp%K]==0 and mods[0]==0:
    mods[temp%K]=1
    ans+=1
    temp*=10
    temp+=7
    temp%=K

print(ans if mods[0]==1 else -1)

Measured memory_bytes: 16788
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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 res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<bool> f(n*2);
  rep(i, 2*n) f.at(i) = (s.at(i) == 'B');
  for(int i = 0; i < 2*n; i += 2){
    f.at(i) = !f.at(i);
  }

  int trc = 0, fac = 0;
  for(bool b : f){
    if(b == true) trc++;
    else fac++;
  }
  if(s.front() != 'B' || s.back() != 'B' || fac != trc){
    cout << 0 << endl;
    return 0;
  }

  mint ans = 1;
  int co = 0;
  rep(i, 2*n){
    if(i % 2 == 0) ans *= (i/2+1);
    if(f.at(i) == false) co++;
    else{
      ans *= co;
      co--;
    }
  }
  cout << ans.x << endl;

  return 0;
}

Measured memory_bytes: 3716
while True:
    try:
        s_inp = input()
        s_out = ""
        flag = 0
        for c in s_inp:
            if flag == 1:
                n = int(c)
                flag = 2
            elif flag == 2:
                for i in range(n):
                    s_out = s_out + c
                flag = 0
            elif c == "@":
                flag = 1
            else:
                s_out = s_out + c
        print(s_out)
    except:
        break



Measured memory_bytes: 5592
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  int m = 0;
  if (s[0] == '1') ++m;
  if (s[1] == '1') ++m;
  if (s[2] == '1') ++m;
  cout << m << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

class Main {
   public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		HashSet<String> Dic = new HashSet<String>();
		int n = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < n; i++){
			String[] meirei = br.readLine().split(" ");
			
			if(meirei[0].equals("insert")){
				Dic.add(meirei[1]);
			}else{
				if(Dic.contains(meirei[1])){
					System.out.println("yes");
				}else{
					System.out.println("no");
				}
			}
		}
	}
}

Measured memory_bytes: 189784
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(int n, vector<lli> const &hs) {
  vector<lli> dp(n+3, 0);
  dp[n] = dp[n+1] = dp[n+2] = infty<lli>;
  RREP(i, n-1) {
    dp[i] = min(
        abs(hs[i+2]-hs[i]) + dp[i+2],
        abs(hs[i+1]-hs[i]) + dp[i+1]);
  }
  cout << dp[0] << endl;
}

int main() {
  int N; cin >> N;
  vector<lli> hs;
  REP(i, N) {
    lli H;
    cin >> H;
    hs.push_back(H);
  }
  solve(N, hs);
  return 0;
}


Measured memory_bytes: 1908
n = int(input())
ans = [0 for i in range(20000)]
for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = i*i+j*j+k*k+i*j+j*k+k*i;
      if v<10050:
        ans[v]+=1
for i in range(n):
  print(ans[i+1])

Measured memory_bytes: 9172
#include<stdio.h>
#include<string.h>
#define LEN 500001
#define NIL -1
 
int trance_command(char []);
void insert(int);
int find(int, int);
int minimum(int);
int successor(int);
void delete(int);
void print();
void inorder(int);
void preorder(int);
 
int P[LEN], L[LEN], R[LEN], Key[LEN];
int root=NIL;
 
int main()
{
  char command[10];
  int n, id;
  int z=0;
  int i, j, k;
 
  //intelization
  for(i=0; i<LEN; i++)
    {
      P[i]=NIL;
      L[i]=NIL;
      R[i]=NIL;
      Key[i]=NIL;
    }
 
  //read
  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%s", command);
      //insert
      if(trance_command(command)==0)
    {
      scanf("%d", &id);
      Key[z]=id;
      insert(z);
      z++;
    }
      //print
      else if(trance_command(command)==1)
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
      //find
      else if(trance_command(command)==2)
    {
      scanf("%d", &id);
      j=find(root, id);
      if(j!=NIL)printf("yes\n");
      else printf("no\n");
    }
      //delete
      else if(trance_command(command)==3)
    {
      scanf("%d", &id);
      delete(find(root, id));
    }
    }
 
  return 0;
}
 

int trance_command(char c[])
{
  if(strcmp(c, "insert")==0)return 0;
  else if(strcmp(c, "print")==0)return 1;
  else if(strcmp(c, "find")==0)return 2;
  else if(strcmp(c, "delete")==0)return 3;
}
 
void insert(int z)
{
  int y=NIL;
  int x=root;
 
  while(x!=NIL)
    {
      y = x;
      if(Key[z]<Key[x])x = L[x];
      else x = R[x];
    }
  P[z]=y;
 
  if(y==NIL)root=z;
  else if(Key[z]<Key[y])L[y]=z;
  else R[y]=z;
}
 
int find(int x, int key)
{
  while(x!=NIL && key!=Key[x])
    {
      if(key < Key[x])x=L[x];
      else x=R[x];
    }
  return x;
}
 
int minimum(int x)
{
  while(L[x]!=NIL)x = L[x];
  return x;
}
int successor(int x)
{
  int y;
  if(R[x]!=NIL)return minimum(R[x]);
  y=P[x];
  while(y!=NIL && x==R[y])
    {
      x=y;
      y=P[y];
    }
  return y;
}
 
void delete(int z)
{
  int y;
  int x = z;
  if(L[x]==NIL || R[x]==NIL)y=z;
  else y=successor(z);
 
  if(L[y]!=NIL)x=L[y];
  else x=R[y];
 
  if(x!=NIL)P[x]=P[y];
  if(P[y]==NIL)root=x;
  else if(y==L[P[y]])L[P[y]]=x;
  else R[P[y]]=x;
 
  if(y!=z)Key[z]=Key[y];
  //return y;
}
 
void inorder(int t)
{
  if(t!=NIL)
    {
      inorder(L[t]);
      printf(" %d", Key[t]);
      inorder(R[t]);
    }
}
 
void preorder(int t)
{
  if(t!=NIL)
    {
      printf(" %d", Key[t]);
      preorder(L[t]);
      preorder(R[t]);
    }
}


Measured memory_bytes: 9556
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type Task struct {
	A, B int
}

func main() {
	N := ReadInt()
	tasks := make([]Task, N)
	for i := 0; i < N; i++ {
		tasks[i].A, tasks[i].B = ReadInt(), ReadInt()
	}
	sort.Slice(tasks, func(i, j int) bool {
		if tasks[i].B == tasks[j].B {
			return tasks[i].A > tasks[j].A
		}
		return tasks[i].B > tasks[j].B
	})
	now := tasks[0].B
	for i := 0; i < N; i++ {
		if now > tasks[i].B {
			now = tasks[i].B
		}
		now -= tasks[i].A
	}
	if now < 0 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int main()
{
  int A, B;
  cin >> A >> B;
  int r,s,t,u,v;
  int ans = 0;
  for (int i = A;i < B+ 1; i++){
    r = i;
    s = r % 10; r /= 10;
    t = r % 10; r /= 100;
    u = r % 10; r /= 10;
    v = r % 10;
    if(s == v && t == u) {
      ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

void showIntArray(int a[], int n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}

int ceil(int a) {
  if (a % 10 == 0) return a;
  else return (a / 10) * 10 + 10;
}

int main() {
  int a[5], lastIdx = 0, minLastDigit = 9, sumTime = 0;
  for (int i=0; i<5; i++) {
    cin >> a[i];
    if (((a[i] % 10) < minLastDigit) && (a[i] % 10) != 0) {
      minLastDigit = a[i] % 10;
      lastIdx = i;
    }
    sumTime += ceil(a[i]);
  }

  sumTime -= ceil(a[lastIdx]);
  sumTime += a[lastIdx];

  cout << sumTime << endl;

  return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

int main(){
    int n, k;
    cin >> n >> k;
    int w[n], sum = 0;
    rep(i,n){
        cin >> w[i];
        sum += w[i];
    }

    int l = 0, r = sum;
    while(l + 1 < r){
        //cout << l << " " << r;
        int m = (l + r) / 2, tmp = 0, track = 0;
        bool flag = 0;
        rep(i,n){
            flag |= w[i] > m;
            if(tmp + w[i] > m){
                tmp =  w[i];
                track++;
            }else tmp += w[i];
        }
        if(tmp)track++;
        if(track > k || flag)l = m;
        else r = m;
        //cout << "    " << tmp << " " << track << endl;
    }//cout << endl;

    cout << r << endl;
    return 0;
}


Measured memory_bytes: 3484
from operator import itemgetter
N = int(input())
T = []
for _ in range(N):
    T.append(tuple(map(int, input().split())))
T.sort(key=itemgetter(1))
A = [i[0] for i in T]
B = [i[1] for i in T]
sum = 0
for i in range(N):
    sum += A[i]
    if sum > B[i]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 137640
l=[]
m=[]
n=[]
a=0
for i in range(5):
  s=int(input())
  n.append(s)
  m.append(round(int(s+5),-1))
  if s%10 != 0:
    l.append(s%10)
    a+=1
if a ==0:
  print(sum(n))
else:
  print(sum(m)+min(l)-10)

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

#define INTEREST	5

int main() {
	int debt = 100000;
	int n;

	cin >> n;
	for( int i = 0; i < n; ++i ) {
		debt = debt * ( 1 + INTEREST * 0.01 );
		if( debt % 1000 != 0 ) {
			debt = debt - debt % 1000 + 1000;
		}
	}
		
	cout << debt << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int n, m, x;
  cin >> n >> m >> x;
  ++n;

  vector<int> a(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
  }

  int bef = 0, aft = 0;
  for (int i = 0; i < m; ++i) {
    if (a[i] < x) {
      ++bef;
    } else {
      ++aft;
    }
  }

  cout << min(bef, aft) << '\n';

  return 0;
}


Measured memory_bytes: 256
while True:
    HM = input()
    HM_list = HM.split(" ")
    H = int(HM_list[0])
    M = int(HM_list[1])
    if H == 0 and M == 0:
        break
    for x in range(H):
        print("#" * M)
        if x == H - 1:
            print()


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

using namespace std;

int digit_sum(int n) {
  static int8_t mem[100000];
  if (n < 10) {
    return n;
  }

  if (mem[n]) {
    return mem[n];
  }

  int ret = n % 10 + digit_sum(n / 10);
  mem[n] = ret;
  return ret;
}

int calc(int n) {
  int min_digit = INT_MAX;
  for (int a = 1; a <= n / 2; ++a) {
    int const b = n - a;
    min_digit = std::min(digit_sum(a) + digit_sum(b), min_digit);
  }
  return min_digit;
}

int main() {
  int n;
  std::cin >> n;
  auto ret = calc(n);
  std::cout << ret << std::endl;
  return 0;
}


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

typedef long long ll;
typedef std::pair<ll, ll> l_l;
typedef std::pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<double> A(N);
    double a = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        a += 1 / A[i];
    }

    cout << 1 / a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

ll d2[200010];

int main() {
	d2[0] = 1;
	for (int i = 1;i < 200010;i++) d2[i] = d2[i - 1] * 2 % MOD;
	int N;
	cin >> N;
	vector<ll> C(N);
	for (int i = 0;i < N;i++)cin >> C[i];
	sort(all(C));

	ll S, B, D, ans = 0;
	for (int i = 0;i < N;i++) {
		B = N - 1 - i;
		S = i;
		if (B == 0) {
			ans += C[i] * d2[S];
			ans %= MOD;
			continue;
		}
		ans += (C[i] * d2[S] % MOD) * (B * d2[B - 1] % MOD + d2[B]);
		ans %= MOD;
	}
	ans *= d2[N];
	ans %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 3328
n, x = map(int, input().split())
a = list(map(int, input().split()))
L = []
d = 0
for i in range(n):
    d += a[i]
    L.append(d)

cnt = 0
for j in range(len(L)):
    if L[j] <= x:
        cnt+=1
    else:
        break

print(cnt+1)


Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
  ll th,ts,ah,as;
  cin>>th>>ts>>ah>>as;
  bool possible=true;
  while(1)
  {
      if(possible)
      {
          ah=ah-ts;
          if(ah<=0)
          {
              cout<<"Yes"<<endl;
              break;
          }
          possible=false;
      }
      else
      {
          th=th-as;
          if(th<=0)
          {
              cout<<"No"<<endl;
              break;
          }
          possible=true;
      }
      
  }
  
   
   return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a)
		cout << k << en;
	else if (k - a <= b)
		cout << a << en;
	else
		cout << a - (k - a - b) << en;
}

int main()
{
	fast;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}

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

using namespace std;

long long MOD = 1000000000 + 7;
long long fact[1 << 20];

long long power(long long n, int p) {
  long long result = 1;
  for (; p; p >>= 1) {
    if (p & 1) {
      result *= n;
      result %= MOD;
    }
    n *= n;
    n %= MOD;
  }
  return result;
}

long long C(int n, int k) {
  long long result = fact[n];
  result *= power(fact[k], MOD - 2);
  result %= MOD;
  result *= power(fact[n - k], MOD - 2);
  result %= MOD;
  //cout << n << " C " << k << " = " << result << endl;
  return result;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < 1 << 20; ++i) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= MOD;
  }

  long long h, w, a, b;
  while (cin >> h >> w >> a >> b) {
    long long result = C(h + w - 2, h - 1);
    for (int y = h - a + 1; y <= h; ++y) {
      long long m = (C(y + b - 2, y - 1) * C(w - b + h - y - 1, h - y)) % MOD;
      //cout << y << ": " <<  C(y + b - 2, y - 1) << " * " << C(w - b + h - y - 1, h - y) << endl;
      result -= m;
      result += MOD;
      result %= MOD;
    }
    cout << result << endl;
  }
}


Measured memory_bytes: 8448
M = 10**6
N = int(input())
A = list(map(int, input().split()))


def solve():
    amax = max(A)+1
    memo = [0] * amax
    for a in A:
        i = 1
        while i*a < amax:
            memo[i*a] += 1
            i += 1

    count = 0
    for a in A:
        if memo[a] == 1:
            count += 1

    return count

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 104096
import java.util.*;

public class Main{

    public static List<Integer> P;
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int count = 0;
        for(int i=0; i<N; i++){
            int h = scanner.nextInt();
            if(K <= h){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 46868
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            int[] x = new int[n];

            int cnt = 0;

            for (int i = 0; i < n; i++) {
                x[i] = in.nextInt();
                cnt += x[i];
            }

            int dist = (int) Math.round((double) cnt / n);

            int power = 0;

            for (int i = 0; i < n; i++) {
                power += (x[i] - dist) * (x[i] - dist);
            }
            out.println(power);


        }

    }
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <algorithm>
#include <string>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int N;cin>>N;
	int V[N];
  	rep(i,N)cin>>V[i];
  	int C[N];
  	rep(i,N)cin>>C[i];
	int output;output=0;
  	rep(i,N){
    	if(V[i]-C[i]>0)output=output+V[i]-C[i];
    }
    cout<<output<<endl;
    return 0;
 
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1); m],
    }
    let mut g = vec![vec![true; n]; n];
    for (i, g) in g.iter_mut().enumerate() {
        g[i] = false;
    }
    for (a, b) in e {
        g[a][b] = false;
        g[b][a] = false;
    }
    let mut used = vec![false; n];
    let mut dp = vec![false; n + 1];
    dp[0] = true;
    for i in 0..n {
        if used[i] {
            continue;
        }
        let mut d = vec![0usize; n];
        let mut cnt = [0; 2];
        used[i] = true;
        let mut stack = vec![i];
        while let Some(v) = stack.pop() {
            cnt[d[v]] += 1;
            for (u, g) in g[v].iter().enumerate() {
                if !g {
                    continue;
                }
                if !used[u] {
                    d[u] = d[v] ^ 1;
                    used[u] = true;
                    stack.push(u);
                } else if d[u] == d[v] {
                    println!("-1");
                    return;
                }
            }
        }
        let mut next = vec![false; n + 1];
        for &c in cnt.iter() {
            for (x, p) in next.iter_mut().skip(c).zip(dp.iter()) {
                *x |= *p;
            }
        }
        dp = next;
    }
    let mut ans = std::usize::MAX;
    for (i, p) in dp.into_iter().enumerate() {
        if p {
            ans = std::cmp::min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

int main(){
  int result=0;
  string s;
  long long a,b,k;
  cin >> a>>b>>k;
  
//  if(aとbでも足りない){
  if(a+b<k){
  	cout << 0 << " " << 0 << endl;
//  if(aだけでOK){
  }else if(k<=a){
  	cout << a-k << " " << b << endl;
//  if(aとb){
  }else{
  	cout << 0 << " " << b-(k-a);
  }
  
  return 0;
}

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

main(){
  int count=0, i, k, j;
  int number[N]; 
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d", &number[i]);
    if(number[i] == 1)
      break;
  }
  
  for(i=0;i<k;i++){
    for(j=2; j <= sqrt(number[i]); j++)
      if(number[i] % j == 0){
	count += 1;
        break;
       }
      }
  printf("%d\n", k-count);
  return 0;
}

Measured memory_bytes: 632
from sys import stdin
input = stdin.readline

N, K = map(int, input().split())
a = tuple(map(int, input().split()))

dp = [False] * (K + 1)

for k, v in enumerate(dp):
    if not v:
        for i in a:
            if k + i <= K:
                dp[k + i] = True

print('First' if dp[K] else 'Second')

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, K; string S; cin >> N >> K >> S;
	vector<pair<int, int>> A;
	int prv = -1;
	for (int i = 0; i < N; i++) {
		if (i == N-1 || S[i] != S[i+1]) {
			A.emplace_back(i - prv, int(S[i] - '0'));
			prv = i;
		}
	}
	int ans = 0;
	int has = 0;
	for (int i = 0, j = 0; i < int(A.size()); i++) {
		while (j < int(A.size())) {
			if ((K - (1 - A[j].second)) < 0) {
				break;
			}
			K -= 1 - A[j].second;
			has += A[j].first;
			j++;
		}
		ans = max(ans, has);
		K += 1 - A[i].second;
		has -= A[i].first;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    ll x; cin >> x;
    ll count = 0;
    ll now = 100;
    while(true) {
       if(now>=x) {
            cout << count << endl;
            break;
        }
        now*=1.01;
        count++; 
    }
}


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

import sys
from math import factorial

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD

N = INT()
A = [0] + LIST()
B = [A[i+1] - A[i] for i in range(N)]

add = factorial(N-1) % MOD
# スライムが区間iを通る合計回数をそれぞれ求める
cnt = [0] * N
for i in range(1, N):
    cnt[i] = cnt[i-1] + add
    cnt[i] %= MOD
    add *= fermat(i ,i+1, MOD)
    add %= MOD

ans = 0
for i in range(1, N):
    # 区間長を掛ければ合計距離
    ans += B[i] * cnt[i]
    ans %= MOD
print(ans)


Measured memory_bytes: 69632
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main()
{
    int a, p, kakera = 0, pai = 0;

    cin >> a >> p;
 
    kakera = a * 3 + p;
    pai = kakera / 2;

    cout << pai;
    return 0;
}

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

int main() {
  int N,flg=0;
  string a;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a;
    if (a=="Y"){
      flg = 1;
      break;
    }
  }
  if(flg==1)
  cout << "Four" << endl;
  else
  cout << "Three" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin)
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x) cerr << #x << ": " << x << endl;
#define whatis2(x, y) wt(x); wt(y); cout << endl;
#define whatis3(x, y, z) wt(x); wt(y); wt(z); cout << endl;
#define whatis4(x, y, z, a) wt(x); wt(y); wt(z); wt(a); cout << endl;
using namespace std;

typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const ll MOD = 1000000007; const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

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

    string s;
    cin >> s;
    int q;
    cin >> q;
    int state = 0;
    vector<char> v[2];
    while(q--) {
        int x, type; char ch;
        cin >> x;
        if (x == 1) {
            state = !state;
        } else {
            cin >> type >> ch;
            type -= 1;
            v[state ^ type].push_back(ch);
        }
    }
    string ans = "";
    for (int i = v[0].size() - 1; ~i; --i) {
        ans += v[0][i];
    }
    ans += s;
    for (auto const &i : v[1]) ans += i;
    if (state) reverse(ans.begin(), ans.end());

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  ll n; cin >> n;
  vector <ll> c(n-1), s(n-1), f(n-1);
  rep(i, n-1) cin >> c.at(i) >> s.at(i) >> f.at(i);
  rep(i, n) {
    ll res = 0;
    for (ll j = i; j < n-1; j++) {
      if (res <= s.at(j)) res = s.at(j) + c.at(j);
      else if ((res-s.at(j))%f.at(j) == 0) res += c.at(j);
      else res = s.at(j) + ((res-s.at(j))/f.at(j)+1)*f.at(j) + c.at(j);
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3608