akhauriyash/Code-Regression huggingface dataset:
//Name: JOI Flag
//Level: 4
//Category: 数え上げ,動的計画法,DP,ビットDP
//Note:

/*
 * あり得る全ての旗から、JOIが含まれないものの個数を引けばよい。
 *
 * JOIが含まれないものの個数は、直前N文字を覚えておけばDPで求められるが、単純にJ,O,Iを覚えるのでは
 * 状態数が多くなりすぎてしまう（最大ケースで O(MN 3^M) = 約1.3兆状態）。
 * しかし、JOIが構成されるかどうかは、真上の行でJOという並びが存在しているかどうかのみに依存するため、
 * 1マスについて覚えなければならない情報は「Jがあり、その右にOがあるかどうか」の1bitだけになる。
 * また、JOができたことを判定するためには、直前にJを置いたかどうかを覚えておく必要があるが、これは1bitのみでよい。
 *
 * 以上より、状態数は O(MN 2^M) = 約4億状態になるため、ビットDPで間に合う。
 * 実際には、1のビットが連続することはあり得ないため、状態数は半分以下になる。
 * また、メモリの制約上すべての状態を保持しておくのは難しいので、1マスずつ状態を進めながらバッファを使いまわす必要がある。
 *
 * オーダーは O(MN 2^M)。
 */
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;

const int MOD = 100000;

bool solve() {
    int N, M;
    if(!(cin >> N >> M)) return false;
    if(!N && !M) return false;

    vector<string> field(N);
    for(int i = 0; i < N; ++i) {
        cin >> field[i];
    }

    vector<int> dp[2];
    dp[0].resize(1<<(M+1));
    dp[1].resize(1<<(M+1));

    const int MASK = (1<<(M+1))-1;
    vector<int> states[2];
    fill(begin(dp[0]), end(dp[0]), 1);
    states[0].push_back(0);
    int allpat = 1;
    for(int r = 0; r < N; ++r) {
        for(int c = 0; c < M; ++c) {
            const char fc = field[r][c];
            if(fc == '?') {
                allpat *= 3;
                allpat %= MOD;
            }
            fill(begin(dp[1]), end(dp[1]), 0);
            states[1].clear();
            for(int s : states[0]) {
                //cout << r << ' ' << c << ' ' << s << endl;
                const int prev_j = s & 1;
                const int pat = dp[0][s];
                s ^= prev_j;

                // Put J
                if(fc == '?' || fc == 'J') {
                    const int sj = ((s << 1) & MASK) | (1 && (c < M-1));
                    dp[1][sj] += pat;
                    dp[1][sj] %= MOD;
                    states[1].push_back(sj);
                }
                // Put O
                if(fc == '?' || fc == 'O') {
                    const int so = ((s << 1) & MASK) | (prev_j ? 4 : 0);
                    dp[1][so] += pat;
                    dp[1][so] %= MOD;
                    states[1].push_back(so);
                }
                // Put I
                if(fc == '?' || fc == 'I') {
                    if(!(s & (1<<M))) {
                        const int si = (s << 1) & MASK;
                        dp[1][si] += pat;
                        dp[1][si] %= MOD;
                        states[1].push_back(si);
                    }
                }
            }
            sort(begin(states[1]), end(states[1]));
            states[1].erase(unique(begin(states[1]), end(states[1])), end(states[1]));
            dp[0].swap(dp[1]);
            states[0].swap(states[1]);
        }
    }

    const int invalid = accumulate(begin(dp[0]), end(dp[0]), 0, [](int a, int b){return (a+b) % MOD;});
    cout << (allpat + MOD - invalid) % MOD << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 18012
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n, r; cin >> n >> r;
		if (n == 0) break;
		vector<int> a(n);
		for (int i = 0; i < n; i++) a[i] = n - i;
		while (r--) {
			int p, c; cin >> p >> c;
			vector<int> _a = a;
			for (int i = 0; i < p + c - 1; i++)
				_a[i] = a[i < c ? p + i - 1 : i - c];
			a = _a;
		}
		cout << a[0] << endl;
	}
}

Measured memory_bytes: 1220
let quick_sort (a : (int * char * int) array) cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let rec exchange = function
      | (i, j) when j = r -> swap i r; i
      | (i, j) when cmp a.(j) a.(r) <= 0 -> swap i j; exchange (i + 1, j + 1)
      | (i, j) -> exchange (i, j + 1) in
    exchange (p, p) in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end in
  doit 0 (Array.length a - 1)

let stable_p (a : (int * char * int) array) n =
  let rec doit i =
    if i = n then true
    else if (fun (xi, _, xd) (yi, _, yd) -> xd = yd && xi > yi) a.(i-1) a.(i) then false
    else doit (i + 1) in
  doit 1

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let () =
  let n = read_int () in
  let read i =
    match split (read_line ()) ' ' with
    | [c; d] -> (i, c.[0], int_of_string d)
    | _ -> exit 1 in
  let a = Array.init n read in
  quick_sort a (fun (_, _, x) (_, _, y) -> compare x y);
  print_endline (if stable_p a n then "Stable" else "Not stable");
  Array.iter (fun (_, c, d) -> Printf.printf "%c %d\n" c d) a

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

int main()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    a[0]=0;
    for(int i=1 ; i<=n ; i++)
    {
        cin>>a[i];
    }
    sort( a.begin() , a.end() );
    int C=0;
    for(int i=1 ; i<=n-2 ; i++)
    {
        long long l , r , mid ;
        for(int j=i+1 ; j<=n-1 ; j++)
        {
            l=j+1 , r=n ;
            long long J=j;
            while( l <= r )
            {
                mid = ( l + r  )/2;
                if( a[i] + a[j] > a[mid]  ){
                    J=mid;
                    l=mid+1;}
                else if( a[i] + a[j] <= a[mid] )
                    r=mid-1;
            }
                C+=( J - j );
        }
    }
    cout<<C<<endl;
    return 0;
}


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

int main(){
    int D;
    cin >> D;
    vector<int> c(27, 0);
    vector<int> sum(27, 0);
    rep(j, 26){
        cin >> c[j+1];
        sum[j+1] = sum[j] + c[j+1];
    }

    int s[D+1][27];
    rep(i, D){
        rep(j, 26){
            cin >> s[i+1][j+1];
        }
    }
    // vector<int> t(D+1, 0);
    // rep(i, D) cin >> t[i+1];
    int val;
    int now;

    rep(i, D){
        val = rand() % sum[26];
        // cout << val;
        now = 1;
        while( (sum[now] < val) && (now <= 25) ){
            now++;
        }
        cout << now << endl;
    }

    // int M;
    // M = 0;
    // // cin >> M;
    // vector<int> d(M+1, 0);
    // vector<int> q(M+1, 0);
    // // rep(i, M) cin >> d[i+1] >> q[i+1];

    // ll ans = 0;
    // vector<int> lastday(27, 0);

    // for(int day = 1; day <= D; day++){
    //     ans += s[day][t[day]];
    //     lastday[t[day]] = day;
    //     for(int j = 1; j <= 26; j++){
    //         ans -= c[j] * (day - lastday[j]); 
    //     }
    // }

    // for(int que = 1; que <= M; que++){
    //     ans -= s[d[que]][t[d[que]]];
    //     ans += s[d[que]][q[que]];

    //     int before = 0;
    //     for(int pos = d[que] - 1; pos >= 1; pos--){
    //         if (t[pos] == t[d[que]]){
    //             before = pos;
    //             break;
    //         }
    //     }
    //     int after = D+1;
    //     for(int pos = d[que] + 1; pos <= D; pos++){
    //         if (t[pos] == t[d[que]]){
    //             after = pos;
    //             break;
    //         }
    //     }
    //     ans += c[t[d[que]]] * (after - d[que]) * (before - d[que]);

    //     before = 0;
    //     for(int pos = d[que] - 1; pos >= 1; pos--){
    //         if (t[pos] == q[que]){
    //             before = pos;
    //             break;
    //         }
    //     }
    //     after = D+1;
    //     for(int pos = d[que] + 1; pos <= D; pos++){
    //         if (t[pos] == q[que]){
    //             after = pos;
    //             break;
    //         }
    //     }
    //     ans -= c[q[que]] * (after - d[que]) * (before - d[que]);

    //     t[d[que]] = q[que];
    //     // cout << ans << endl;
    // }

    // rep(i, D){
    //     cout << t[i+1] << endl;
    // }
    // cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3672
/*  Name: Abu Hurayra
    Handle: HurayraIIT
    Institute: IIT_JU   */

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

typedef long long LL;
typedef string S;
typedef double D;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;

#define pi acos(-1.0)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Fin freopen("input.txt","r",stdin)
#define Fout freopen("output.txt","w",stdout)

int main()
{
	off;
    int n;
    cin >> n;
    cout << 3*n*n << endl;
    


	return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define RFOR(i,a,b) for(ll i=b-1;i>=a;i--)
#define rsort(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;

ll mod=1000000007;
set<ll>S;
signed main() {
   ll n,m,a,b,ans=1;
   cin>>n;
   rep(i,n){
       cin>>a;
    S.insert(a);
   }
   cin>>m;
   rep(i,m){
    cin>>b;
    if(S.find(b)==S.end()){
        ans=0;
    }
   }
   cout<<ans<<endl;
}



Measured memory_bytes: 12472
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <bitset>
#include <numeric>

using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};



int main(){
    string s;
    int p, ans;
    p = ans = 0;
    cin >> s;
    REP(i, s.length()){
        if(s[i] == 'g'){
            if(p > 0){
                ans++;
                p--;
            }else{
                p++;
            }
        }else{
            if(p > 0){
                p--;
            }else{
                p++;
                ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  int q;
  cin>>q;
  int t[q];
  for(int i=0;i<q;i++) cin>>t[i];
  int ans=0;
  int used[q];
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++){
    for(int j=0;j<q;j++){
      if(used[j]) continue;
      if(s[i]==t[j]){
	ans++;
	used[j]=1;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

const int N=2010;
int x,n,sum=0,ans;
bitset<N*N> S;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&x),S|=S<<x,S[x]=1,sum+=x;
    for(ans=(sum+1)/2;ans<=sum;ans++) if(S[ans]) break;
    printf("%d\n",ans);
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end

ll mod=998244353;
struct Mint {
    ll val;
    Mint inv() const{
        ll tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x):val(x>=0?x%mod:x%mod+mod){}
    int mtoi(){return this->val; }
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this*=x.inv();}
    bool operator==(const Mint& x) const{return val==x.val;}
    bool operator!=(const Mint& x) const{return val!=x.val;}
    bool operator<(const Mint& x) const{return val<x.val;}
    bool operator<=(const Mint& x) const{return val<=x.val;}
    bool operator>(const Mint& x) const{return val>x.val;}
    bool operator>=(const Mint& x) const{return val>=x.val;}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*Mint(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*Mint(i);
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
    int n; scanf("%d",&n);
    factorial fact(10000010);
    Mint ans=Mint(3).pow(n),mul=Mint(2).pow(n/2-1);
    rep(i,n/2+1,n+1)ans-=fact.nCr(n,i)*mul*2,mul/=2;
    printf("%d\n",ans.val);
    return 0;
}


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

const int INF = (int)1e9;
typedef pair<int, int> P;

int H, W;
char grid[50][50];
int d[50][50];
int cnt = 0, ans = -1;

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

int bfs() {
    queue<P> que;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) d[i][j] = INF;
    }
    que.push(P(0, 0));
    d[0][0] = 0;
    
    while (que.size()) {
        P p = que.front(); que.pop();
        if (p.first == H-1 && p.second == W-1) break;

        for (int i = 0; i < 4; i++) {
            int nx = p.first+dx[i], ny = p.second+dy[i];

            if (0 <= nx && nx < H && 0 <= ny && ny < W && grid[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second]+1;
            }
        }
    }

    return d[H-1][W-1];
}

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

    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
            if (grid[i][j] == '.') cnt++;
        }
    }

    if (bfs() != INF) ans = cnt-bfs()-1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

//range min
struct segmentTree{
	vector<long long int> node;
	int n;
	
	segmentTree(vector<long long int> v){
		int s = v.size();
		n = 2;
		while(n < s) n *= 2;
		node = vector<long long int>(2*n -1, inf);
		for(int i=0; i<s; i++){
			node[i +n-1] = v[i];
		}
		for(int i=n-2; i>=0; i--){
			node[i] = min(node[2*i +1], node[2*i +2]);
		}
	}
	
	void Set(long long int val, int pos){
		int idx = n-1 + pos;
		node[idx] = val;
		do{
			idx = (idx -1)/2;
			node[idx] = min(node[2*idx +1], node[2*idx +2]);
		}while(idx != 0);
	}
	long long int Get(int l, int r){
		return _get(l, r, 0, 0, n);
	}
	long long int _get(int l, int r, int k, int cl, int cr){
		if(l <= cl && cr <= r){
			return node[k];
		}
		if(r <= cl || cr <= l){
			return inf;
		}
		int m = (cl +cr)/2;
		return min(_get(l, r, 2*k+1, cl, m), _get(l, r, 2*k+2, m, cr));
	}
};

signed main(){
	long long int n;
	cin >> n;
	vector<int> x(n);
	for(int i=0; i<n; i++){
		cin >> x[i];
	}
	segmentTree segtree(vector<long long int>(n+1, 0));
	for(int i=0; i<n; i++){
		segtree.Set(segtree.Get(0, x[i]) -x[i], x[i]);
	}
	cout << n*(n+1)/2 +segtree.Get(1, n+1) << endl;
	return 0;
}


Measured memory_bytes: 8176
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc166_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000


const int nax = 100005;
vector<vector<int>> g(nax);
vector<int> h(nax);
vector<bool> vis(nax, false);
int n, m, rs;

void dfs(int v) {
    if(vis[v]) return;
    vis[v] = true;
    bool ok = true;
    for(int u: g[v]) {
        if(h[v]<=h[u]) {
            ok = false;
        }
        if(!vis[u]) {
            dfs(u);
        }
    }
    if(!ok) rs--;
}

int main() {
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%d", &h[i]);
    }
    for(int i=0; i<m; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    rs = n;
    for(int i=1; i<=n; i++) {
        if(!vis[i]) {
            dfs(i);
        }
    }
    printf("%d\n", rs);
}


Measured memory_bytes: 10384
n, q = [int(x) for x in input().split()]
pro = [[0, 0]]* n
for i in range(n):
    pro[i] = [str(x) for x in input().split()]

cnt = 0
while bool(pro):
    a = pro.pop(0)
    if int(a[1]) - q <= 0:
        cnt += int(a[1])
        print('{} {}'.format(a[0], cnt))
    else:
        cnt += q
        a[1] = str(int(a[1]) - q)
        pro.append(a)


Measured memory_bytes: 13684
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Main atc = new Main();
        
        System.out.println(atc.questionA());
    }
    
    public int questionA(){
        Scanner scan =new Scanner(System.in);
        String input = scan.nextLine();
        
        String[] point = input.split(" ");
        int kankaku = Integer.parseInt(point[0]);
        int maisu = Integer.parseInt(point[1]);
        int time = Integer.parseInt(point[2]);
        return (time / kankaku) * maisu;
    }
    
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>

using namespace std;
int64_t Len[51], Pat[51];

int64_t rec(int64_t k, int64_t x){
  if(x == Len[k]) return Pat[k];
  int64_t ans = 0;

  x--; //下のバンズ
  if(x > 0){
    int64_t l = min(x, Len[k-1]);
    ans += rec(k-1, l);
    x -= l;
  }

  if(x > 0){ // 真ん中のパテ
    ans++;
    x--;
  }
  if(x > 0){
    int64_t l = min(x, Len[k-1]);
    ans += rec(k-1, l);
    x -= l;
  }
  return ans;
}

int main(){
  int64_t N, X;
  cin >> N >> X;

  Len[0] = Pat[0] = 1;
  for(int i = 1; i <= N; i++){
    Len[i] = Len[i-1] * 2 + 3;
    Pat[i] = Pat[i-1] * 2 + 1;
  }
  cout << rec(N, X) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = list(input().strip())
L = []

for i in range(len(S)):
    if ord(S[i])+N > 90:
        L.append(ord(S[i])+N-26)
    else:
        L.append(ord(S[i])+N)

for i in range(len(S)):
    print(chr(L[i]), end="")

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

int main(){
    int N, K;
    std::cin >> N >> K;
    std::vector< int > V(N);
    for(int i=0; i<N; i++){
        std::cin >> V[i];
    }
    
    int max = 0;
    for(int i=0; i<=K; i++){
        for(int j=0; j<=K-i; j++){
            int cnt = 0;
            std::priority_queue<int> que;
            if(N < i + j){
                break;
            }
            for(int l=0; l<i; l++){
                cnt += V[l];
                if(V[l] < 0){
                    que.push(-1 * V[l]);
                }
            }
            for(int r=0; r<j; r++){
                cnt += V[N - r - 1];
                if(V[N - r - 1] < 0){
                    que.push(-1 * V[N - r - 1]);
                }
            }
            for(int p=0; p<K-i-j; p++){
                if(!que.empty()){
                    cnt += que.top();
                    que.pop();
                }
            }
            //std::cout << i << " " << j << " " << cnt << std::endl;
            if(max < cnt){
                max = cnt;
            }
        }
    }
    
    std::cout << max << std::endl;
    
    return 0;
}



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

int main()
{
    int N, M;
    cin >> N >> M;
    int A[M], B[M];
    REP(i, M) cin >> A[i] >> B[i];

    int pat[N];
    pat[0] = 1;
    iota(pat+1, pat+N, 2);

    int ret = 0;
    do
    {
        REP(i, N-1)
        {
            REP(j, M)
            {
                if (A[j] == pat[i] && B[j] == pat[i+1] ||
                    B[j] == pat[i] && A[j] == pat[i+1])
                {
                    goto esc1;
                }
            }
            goto esc2;
esc1:;
        }
        ++ret;
esc2:;
    }
    while (next_permutation(pat+1, pat+N));

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef pair<P,bool> Q;
D eps=1e-11;
D cro(P a,P b){return imag(conj(a)*b);}
bool eq(D a,D b){return abs(a-b)<eps;}
bool comp(const Q& xx,const Q& yy){
	P x=xx.fs,y=yy.fs;
	if(abs(x.real()-y.real())<eps){
		return x.imag()<y.imag();
	}else{
		return x.real()<y.real();
	}
}
int ccw(P a,P b,P c){
	if(cro(b-a,c-a)>eps) return 1;
	if(cro(b-a,c-a)<-eps) return -1;
	if(eq(abs(a-c)+abs(c-b),abs(a-b))) return 0;
	if(eq(abs(a-b)+abs(b-c),abs(a-c))) return -2;
	return 2;
}
bool iSS(L a,L b){
	return ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0&&ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0;
}
P intLL(L a,L b){
	D t=cro(a.sc-a.fs,a.sc-b.fs)/cro(a.sc-a.fs,b.sc-b.fs);
	return b.fs+t*(b.sc-b.fs);
}
int main(){
	int T;
	cin>>T;
	rep(tt,T){
		vector<Q> vc;
		D ax,ay,bx,by;
		int N;
		cin>>ax>>ay>>bx>>by>>N;
		L l=L(P(ax,ay),P(bx,by));
		rep(i,N){
			D a,b,c,d;
			bool e,f;
			cin>>a>>b>>c>>d>>e>>f;
			L s=L(P(a,b),P(c,d));
			if(iSS(l,s)){
				vc.pb(Q(intLL(l,s),e^f));
			}
		}
		if(vc.size()==0){
			puts("0");
			continue;
		}
		sort(all(vc),comp);
		int ans=0;
		bool now=vc[0].sc;
		rep(i,vc.size()){
			if(now^vc[i].sc){
				ans++;
				now=vc[i].sc;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	short f=1;x=0;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
int main(){
    int n;read(n);
    set <int> s;
    while(n--){
        int x;read(x);
        if(s.find(x)!=s.end()) s.erase(x);
        else s.insert(x);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=998244353;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi fac,finv,inv;
void init(ll n) {
    fac=vi(n+5);finv=vi(n+5);inv=vi(n+5);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    REP(i,2,n+5){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
long long modcom(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
    ll n,m;cin>>n>>m;
    init(3*m/2+n);
    ll ans=0;
    for(ll k=m%2;k<=n&&k<=m;k+=2){
        ll s=(3*m-k)/2;
        ll res=modcom(s+n-1,n-1);
        res+=mod-n*modcom(s-m+n-1,n-1)%mod;
        res+=(n-k)*modcom(s-m+n-2,n-2)%mod;
        ans+=res%mod*modcom(n,k)%mod;
        ans%=mod;
    }
    out(ans);
}

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

int main() {
    // input
    int H, W;
    cin >> H >> W;

    // solve & output
    string S;
    for (int i = 0; i < H; ++i) {
        cin >> S;
        cout << S << endl;
        cout << S << endl;
    }

    return 0;
}


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

using namespace std;
struct Edge
{
    int to;
    Edge(int t) : to(t) {}
};

// Digraph
using Graph = vector<vector<Edge>>;

vector<int> topological_sort(const Graph &G)
{
    vector<int> order;
    int n = (int)G.size();
    vector<int> indegree(n);
    for (int e = 0; e < n; e++)
        for (auto &&ne : G[e])
            indegree[ne.to]++;

    queue<int> que;
    for (int i = 0; i < n; i++)
        if (indegree[i] == 0)
            que.push(i);

    while (!que.empty())
    {
        int now = que.front();
        order.push_back(now);
        que.pop();
        for (auto &&e : G[now])
        {
            indegree[e.to]--;
            if (indegree[e.to] == 0)
                que.push(e.to);
        }
    }
    return order;
}

int main()
{
    int N;
    cin >> N;
    int graphsize = N * (N - 1) / 2;
    Graph dg(graphsize);

    auto toIndex = [N](int i, int j) {
        if (i > j)
            swap(i, j);
        return j - i - 1 + i * (2 * N - i - 1) / 2;
    };

    for (int i = 0; i < N; i++) // 0-indexed
    {
        int j;
        cin >> j;
        j--;
        int prevnode = toIndex(i, j);
        for (int l = 1; l <= N - 2; l++)
        {
            cin >> j;
            j--;
            dg[prevnode].push_back(Edge(toIndex(i, j)));
            prevnode = toIndex(i, j);
        }
    }

    auto top_order = topological_sort(dg);
    if (top_order.size() != graphsize)
    {
        cout << -1 << endl;
        return 0;
    }

    vector<int> maxdist(graphsize, 0);
    for (size_t v = 0; v < graphsize; v++)
    {
        int tv = top_order[v];
        for (auto &&ne : dg[tv])
            maxdist[ne.to] = max(maxdist[ne.to], maxdist[tv] + 1);
    }

    int ans = maxdist[top_order.back()];
    cout << ans + 1 << endl;
    return 0;
}

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

using namespace std;

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

    int mi = 114541919, ret = 0;
    for (int i = 0; i < n; i++) {
        if (abs(mi) > abs(l + i))mi = l + i;
        ret += l + i;
    }

    cout << ret - mi << endl;
    return 0;
}

Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define endl "\n"
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   

      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
          string a,b;
        cin>>a>>b;
        ll p = b.size();
        if(a==b.substr(0,p-1))
          cout<<"Yes\n";
        else
          cout<<"No\n";
         

         

      }
      






}



























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

int N,A,B,C;
int l[11];
int INF = 1000000007;

int dfs (int depth, int a, int b, int c) {
     if(N == depth) {
        if(min(min(a,b),c) > 0) return abs(A-a) + abs(B-b) + abs(C-c) - 30;
        else return INF;
     }
     int cost1 = dfs(depth+1,a,b,c);
     int cost2 = dfs(depth+1,a+l[depth],b,c) + 10;
     int cost3 = dfs(depth+1,a,b+l[depth],c) + 10;
     int cost4 = dfs(depth+1,a,b,c+l[depth]) + 10;
     return min(min(min(cost1,cost2),cost3),cost4);
}


int main () {
    cin >> N >> A >> B >> C;
    for(int i=0; i<N; i++) cin >> l[i];
    cout << dfs(0,0,0,0) << endl;
    return 0;
}

// editorial AC


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

using namespace std;

const int N = int(1e5 + 10);
int con[N];

int main(){
	int n;

	scanf("%d", &n);

	int st = 1, en = 0;

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

		scanf("%d", &ai);

		int lo = st;
		int hi = en;
		int r = -1;

		while(lo <= hi){
			int mid = (lo + hi) >> 1;

			if(con[mid] < ai){
				r = mid;
				hi = mid - 1;
			}else{
				lo = mid + 1;
			}
		}

		if(r == -1){
			en++;
			con[en] = ai;
		}else{
			con[r] = ai;
		}
	}

	printf("%d\n", en - st + 1);

	return 0;
}

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

bool isPrime(long long int n){
        if(n == 1 || n == 0) return false;
        for(int i=2;i<=sqrt(n);i++){
                if(n%i==0) return false;
        }
        return true;
}

int main(){
        long long int a,d,n;
        while(cin >> a >> d >> n,a){
                while(1){
                        if(isPrime(a)){
                                n--;
                                if(n==0) {
                                        cout << a << endl;
                                        break;
                                }
                        }
                        a+=d;
                }
        }
        return 0;
}

Measured memory_bytes: 2972
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int a, b, c;

	while(scanf("%d%d%d", &a, &b, &c)==3)
	{
		printf("%d\n", min(b/a, c));
	}

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;

int abc[3];

int asc(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

int main()
{
	for (int i = 0; i < 3; i++)cin >> abc[i];

	qsort(abc, sizeof(abc) / sizeof(int), sizeof(int), asc);

	cout << abc[2] * 10 + abc[1] + abc[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==c and a!=b)
	{
		cout<<"Yes";
	}
	else
	if(a==b and a!=c)
	{
		cout<<"Yes";
	}
	else
	if(b==c and b!=a)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
//using point = pair< int,int >;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    OUT((a + b) % 24);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;
using ll = long long;
using ii = pair<int,int>;
constexpr int MOD = 998244353;
constexpr int MAXN = 5+2e5;
int f[MAXN], fac[MAXN];

int add(int a, int b) {
  int ans = a + b;
  if (ans >= MOD) ans -= MOD;
  return ans;
}

int mul(int a, int b) {
  return (int)((1LL*a*b) % MOD);
}

int fpow(int b, int e) {
  int ans = 1, p = b;
  for (; e; e >>= 1) {
    if(e & 1) ans = mul(ans, p);
    p = mul(p, p);
  }
  return ans;
}

int choose(int n, int k) {
  n += k-1;
  k--;
  return mul(fac[n], fpow(mul(fac[n-k], fac[k]), MOD-2));
}

int n;
int solve(int j, int m) {
  return mul(mul(m, f[j-1]), choose(n-j,j));
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int m,k; cin >> n >> m >> k;
  int ans = 0;

  f[0] = 1;
  fac[0] = 1;
  foi (i,1,MAXN) {
    f[i] = mul(m-1, f[i-1]);
    fac[i] = mul(i, fac[i-1]);
  }

  for (int j = n-k; j <= n; ++j)
    ans = add(ans, solve(j,m));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5164
n = int(input())
s = input()
r, g, b = s.count("R"), s.count("G"), s.count("B")
ans = r * g * b
for i in range(n):
    for j in range(i + 1, n):
        k = j + (j - i)
        if k >= n:
            break
        if s[i] != s[j] != s[k] != s[i]:
            ans -= 1
print(ans)

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

int main()
{
    int n; 
    cin >> n;
    int rem = n % 111;
    int quo = n / 111;
    if(rem > 0){
        cout << (quo + 1) * 111 << endl;
    }else{
        cout << quo * 111 << endl;
    }
}

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

void bingocheck(vector<vector<bool>> &C);

int main(){
  vector<vector<int>> A(3,vector<int>(3));
  int N;
  vector<int> b;
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> A.at(i).at(j);
    }
  }
  cin >> N;
  int tmp;
  for(int i=0; i<N; i++){
    cin >> tmp;
    b.push_back(tmp);
  }
  
  vector<vector<bool>> C(3,vector<bool>(3,false));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      for(int &bk : b){
        if(A.at(i).at(j) == bk) C.at(i).at(j)=true;
      }
    }
  }
  
  bingocheck(C);
  
}

void bingocheck(vector<vector<bool>> &C){
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(!C.at(i).at(j)) break;
      else if(j==3-1){
        cout << "Yes" << endl;
        return;
      }
    }
  }
  
  for(int j=0; j<3; j++){
    for(int i=0; i<3; i++){
      if(!C.at(i).at(j)) break;
      else if(i==3-1){
        cout << "Yes" << endl;
        return;
      }
    }
  }
  
  if(C.at(0).at(0)&&C.at(1).at(1)&&C.at(2).at(2) 
     || C.at(0).at(2)&&C.at(1).at(1)&&C.at(2).at(0)){
    cout << "Yes" << endl;
    return;
  }
  
  cout << "No" << endl;
  return;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,popcnt,sse4.1,sse4.2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 105, mod = 1e9 + 7;
const ld tau = 6.28318530717958647692;
const ld A = 2.5*tau - 20.;
const ld B = 5.0*tau - 20.;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	h = min(h, 2*q);
	s = min(s, 2*h);
	d = min(d, 2*s);
	cout << (n/2)*d + (n&1)*s;
}


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

int main(void)
{
    int N, K;
    int d[101];
    int A[101][101];
    int i, j;
    int count = 0;

    scanf("%d %d\n", &N, &K);
    int flag[N+1];
    memset(flag, 0, sizeof(flag));

    for (i = 0; i < K; i++) {
        scanf("%d\n", &d[i]);
        for (j = 0; j < d[i]; j++) {
            scanf("%d", &A[i][j]);
            flag[A[i][j]-1] = 1;
        }
    }
    for (i = 0; i < N; i++) {
        if (flag[i] == 0) {
            count++;
        }
    }
    printf("%d", count);

    return 0;
}

Measured memory_bytes: 1764
import numpy as np


n,m,x = map(int,input().split())
mat = []
for _ in range(n):
    mat.append(list(map(int, input().split())))
mat = np.array(mat)
c_arr = mat[:,0]
a_arr = mat[:,1:]
money = -1
for i in range(1, 2**n):
    l = [bool(x) for x in map(int, format(i, f'0{n}b'))]
    money_tmp = sum(c_arr[l])
    if money != -1 and money < money_tmp:
        continue
    
    sum_li = np.sum(a_arr[l].reshape(-1, m), axis=0)
    if all(sum_li>=x):
        money = money_tmp

print(money)

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N, W;
    cin >> N >> W;
    vector<lint> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    // 状態 (i,j) : a[0]~a[i-1] から選んだ時 v の総和が j である
    // mi(i,j) : 状態 (i,j) でのwの総和の最小値
    vector<vector<lint>> mi(N + 1, vector<lint>(1e5 + 100, LINF));
    mi[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 1e5 + 1; j++) {
            if (mi[i][j] == LINF) continue;
            mi[i + 1][j] = min(mi[i + 1][j], mi[i][j] + 0);
            if (j + v[i] <= 1e5)
                mi[i + 1][j + v[i]] = min(mi[i + 1][j + v[i]], mi[i][j] + w[i]);
        }
    }

    lint ans = -1;
    for (lint j = 0; j <= 1e5; j++) {
        if (mi[N][j] <= W) { ans = max(ans, j); }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 83208
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(n%2 == 1)
	{
		cout<<"No";
		return 0;
	}
	int flag = 1;
	for(int i = 0 ; i < (int)n/2 ; i++)
	{
		if(s[i] != s[i + (int)n/2])
		    flag = 0;
	}
	if(flag)cout<<"Yes";
	else cout<<"No";
	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    string s;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> s;
            if(s=="snuke"){
                char a = 'A' + j;
                cout <<  a << ++i << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3628
import java.io.PrintWriter
import kotlin.math.max

//private val inp = java.io.File("in")
private val inp = System.`in`
private val reader = inp.bufferedReader()
private val wr = PrintWriter(System.out.bufferedWriter())

private fun readLn(): String = reader.readLine()
private fun readInt(): Int = readLn().toInt()
private fun readStrs(): List<String> = readLn().split(" ")
private fun readInts(): IntArray = readStrs().map { it.toInt() }.toIntArray()
private fun readChars(): CharArray = readStrs().map { it.single() }.toCharArray()
private fun readLongs(): LongArray = readLn().map { it.toLong() }.toLongArray()

fun main() {
//    val (n, m) = readInts()
//    val a = readInts()
//
//    var sum = 0L;
//    for (i in a) sum += i
//    val r = n - sum
//
//    println(if (r < 0) -1 else r)

    val (n, m) = readInts()
    val a = readInts()

    var res = n
    a.forEach { res -= it }
    println(max(res, -1))
}

Measured memory_bytes: 38468
A,B=map(int,input().split())
ans=0
if A%2==0:
    if B%2==0:
        a=B-A
        a=a//2
        a=a%2
        if a==1:
            print(B+1)
        else:
            print(B)
    else:
        a=B-A+1
        a=a//2
        if a%2==0:
            print(0)
        else:
            print(1)
else:
    if B%2==1:
        a=B-A
        a=a//2
        if a%2==0:
            print(A)
        else:
            print(A-1)
    else:
        a=B-A-1
        a=a//2
        if a%2==1:
            A=A-1
        for i in range(60):
            a1=A%2
            b1=B%2
            ans+=((a1+b1)%2)*2**(i)
            A=A//2
            B=B//2
        print(ans)

Measured memory_bytes: 3064
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, X, T = read_ints()
    return (N//X+(1 if N%X != 0 else 0))*T


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


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

int main() {
    int n, a, b, c, d;
    cin >> n;
    a=n/1000;
    n %= 1000;
    b=n/100;
    n %= 100;
    c=n/10;
    n %= 10;
    d=n;
    if(a+b+c+d==7) {
        cout << a << "+" << b << "+" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a-b+c+d==7) {
        cout << a << "-" << b << "+" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a+b-c+d==7) {
        cout << a << "+" << b << "-" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a-b-c+d==7) {
        cout << a << "-" << b << "-" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a-b-c-d==7) {
        cout << a << "-" << b << "-" << c << "-" << d << "=" << 7 << endl;
    }
    else if (a-b+c-d==7) {
        cout << a << "-" << b << "+" << c << "-" << d << "=" << 7 << endl;
    }
    else if (a+b-c-d==7) {
        cout << a << "+" << b << "-" << c << "-" << d << "=" << 7 << endl;
    }
    else if (a+b+c-d==7) {
        cout << a << "+" << b << "+" << c << "-" << d << "=" << 7 << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

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

vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}
/// template end ///

void solve()
{
	while (true)
	{
		string s;
		getline(cin, s);
		if (s == ".") { break; }
		stack<char> st;
		bool ok = true;
		for (char c : s)
		{
			switch (c)
			{
			case '(': case '[': st.push(c); break;
			case ')': ok &= !st.empty() && st.top() == '('; if (!st.empty()) st.pop(); break;
			case ']': ok &= !st.empty() && st.top() == '['; if (!st.empty()) st.pop(); break;
			}
		}
		ok &= st.empty();
		write(ok ? "yes" : "no");
	}
}

Measured memory_bytes: 1180