akhauriyash/Code-Regression huggingface dataset:
class TwoDimStack():
    def __init__(self, num_stack):
        self.stacks = [[] for i in range(0, num_stack, 1)]

    def push(self, t, x):
        self.stacks[t].append(x)
        return self

    def top(self, t):
        if len(self.stacks[t]) > 0:
            print(f'{self.stacks[t][len(self.stacks[t])-1]}')
        return self

    def pop(self, t):
        if len(self.stacks[t]) > 0:
            self.stacks[t].pop()
        return self


num_stack, num_queue = tuple(map(int, input().split(' ')))
stacks = TwoDimStack(num_stack)

for i in range(0, num_queue):
    queue = tuple(map(int, input().split(' ')))
    if queue[0] == 0:
        stacks.push(queue[1], queue[2])
    elif queue[0] == 1:
        stacks.top(queue[1])
    elif queue[0] == 2:
        stacks.pop(queue[1])


Measured memory_bytes: 13796
#include<iostream>
#include<cmath>
using namespace std;
int main(){
   int a,n;
   while(cin>>a)
   {
   for(int i=0;i<=6;i++)
    if(pow(2,i)<=a)
   n=pow(2,i);
   cout<<n<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            double exp = 0;
            if (N >= K)
            {
                exp = ((double)(N - K + 1) / (double)N);
                for (int i = 1; i < K; i++)
                {
                    double goal = (double)K / (double)i;
                    // Check if how many times 2x is needed?
                    double count = Math.Log(goal, 2);
                    exp += (1f / (double)N) * Math.Pow(0.5f, Math.Ceiling(count));
                }
            }
            else
            {
                for (int i = 1; i <= N; i++)
                {
                    double goal = (double)K / (double)i;
                    // Check if how many times 2x is needed?
                    double count = Math.Log(goal, 2);
                    exp += (1f / (double)N) * Math.Pow(0.5f, Math.Ceiling(count));
                }
            }
            Console.WriteLine(exp.ToString("F9"));
        }
    }
}


Measured memory_bytes: 11348
//BUGSBUNNY
//IIT ROORKEE
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007 
// #define mod 998244353
#define rep(i,n) for (ll i = 0; i < n; i++)
#define repp(i,a,b) for(ll i = a ; i<b ; i++)
#define reppr(i,a,b) for(ll i = a-1 ; i>=b ; i--)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    int fact[200010], factinv[200010] , first = 0;
    void Util_nCr()
    {
        fact[0] = 1 , factinv[0] = 1;
        repp(i,1,200010)
        {
            fact[i] = (fact[i-1] * i)%mod;
            factinv[i] = (factinv[i-1] * inverse(i))%mod;
        }
    }
    int nCr(int n , int r)
    {
        if(!first) first = 1 , Util_nCr();             
        return ((fact[n] * inverse(fact[n-r]) % mod * inverse(fact[r]))%mod) ;
    }

void solve();
signed main()
{
    //-------------------------------------------------------------------------------   
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        clock_t clk = clock();
    //-------------------------------------------------------------------------------   
    //-------------------------------------------------------------------------------
        int t = 1;
        // cin >> t;    
        rep(i,t)
            solve();
    //-------------------------------------------------------------------------------
        clk = clock() - clk;
        cerr << fixed << setprecision(12) << "Time: " << ((double)clk)/CLOCKS_PER_SEC;
    //-------------------------------------------------------------------------------
}

void solve()
{
    int a , b , c , d;
    cin >> a >> b >> c >> d;
    if((a+d-1)/d < (c+b-1)/b)
        cout << "No\n";
    else
        cout << "Yes\n";
} 

Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
 
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M, K; cin >> N >> M >> K;
 
    vector<int> D(N, -1);
    vector<int> v_n(M);  
    int v_count = 0;
    for (int i = 0;i < M;i++) {
        int d; cin >> d; d--; D[d] = v_count;
        v_n[v_count++] = d;
    }

    vector<vector<int>> Graph(N, vector<int>(K));
    for (int i = 0; i < N;i++) {
        for (int j = 0; j < K;j++) {
            cin >> Graph[i][j]; Graph[i][j]--;
        }
    }
 

    vector<int> dp(1 << M,INF);
    dp[(1 << M) - 1] = 0;  
    queue<int> q;
    q.push((1 << M) - 1); 
    while (!q.empty()) {
        int n = q.front(); q.pop();
 
        for (int k = 0;k < K;k++) {
            int n_ = n; 
            int next_n = 0; 
            for (int b = 0; b < M;b++) {
              
                if ((1 << b)&n_) {
                    n_ &= ~(1 << b); 
                    int next_room = Graph[v_n[b]][k]; 
                   
                    if (D[next_room] != -1) {
                        next_n |= (1 << D[next_room]);
                    }
                }
            }
 
            if (dp[next_n] > dp[n] + 1) {
                dp[next_n] = dp[n] + 1;
                q.push(next_n);
            }
        }
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 3496
import java.util.*;

public class Main{

	public static void main(String args[]){
	
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int m = a + b;
		
		if(m >= c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22868
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    string s,t;
    cin >> s >> t;
    int n = s.length(),c=0;
    for (int i = 0; i < n; i++)
    {
        if(s[i] != t[i]) c++;
    }
    
    cout << c << endl;
}


Measured memory_bytes: 3916
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <cmath>
using namespace std;

#define MAX 1000

int H, W;
char field[MAX][MAX];

int vectorX[4] = {-1,  0, 1, 0};
int vectorY[4] = { 0, -1, 0, 1};

void dfs( int x, int y){
  char kind = field[x][y];
  field[x][y] = 'X';
  for( int i = 0; i < 4; i++ ){
    int dx = x + vectorX[i];
    int dy = y + vectorY[i];
    if( dx >= 0 && dx < H &&
        dy >= 0 && dy < W &&
        field[dx][dy] == kind ){
      dfs(dx,dy);
    }
  }
}

main(){
  while( cin >> H >> W && H && W ){
    int counter = 0;
    for( int i = 0; i < H; i++ ) cin >> field[i];
    for( int i = 0; i < H; i++ ){
      for( int j = 0; j < W; j++ ){
        if( field[i][j] != 'X' ){
          counter++;
          dfs(i,j);
        }
      }
    }
    cout << counter << endl;
  }
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int h, w, n; 
int f (int i, int j) {
    return w * i + (i % 2 ? j : (w-1) - j);
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> n;
    vector<int> a(n); rep (i, n) cin >> a[i];
    rep (i, n - 1) a[i + 1] += a[i];
    int now = 0;
    vector<vector<int> > g(h, vector<int>(w));
    rep (i, h) {
        for (int j = (i % 2 ? 0 : w - 1); j != (i % 2 ? w : -1); j += (i % 2 ? 1 : -1)) {
            if (f(i, j) == a[now]) now++;
            g[i][j] = now;
        }
    }
    rep (i, h) {
        rep (j, w) cout << g[i][j] + 1 << (j != j_len - 1 ? ' ' : '\n');
    }
    return 0;
}

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

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

    sort(d.begin(), d.end());
    int m = d[N / 2 - 1], M = d[N / 2];
    cout << max(0, M - m) << endl;
}


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

int main() {
	int N;
	cin >> N;
	int ans = 0;
	int min = 2000000;
	for (int i = 0; i < N; i++) {
		int P;
		cin >> P;
		if (min >= P) {
			ans++;
			min = P;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
from collections import deque

N = int(input())

A = list(map(int, input().split()))
B = deque()

for i, a in enumerate(A):
    if i % 2 == 0:
        B.appendleft(a)
    else:
        B.append(a)

if N % 2 == 0:
    B.reverse()

B = list(map(str, list(B)))

print(" ".join(B))

Measured memory_bytes: 34628
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define int long long
using namespace std;
typedef pair<int,int> P;
constexpr int mod=1e9+7;
signed main(){
    int N;cin>>N;
    vector<vector<int>> a(N,vector<int>(N));
    REP(i,N) REP(j,N) cin>>a[i][j];
    vector<vector<int>> dp(N+1,vector<int>(1<<N,0));
    //dp[i][j]:男iまでにマッチングした女の集合がjになるような場合の数
    dp[0][0]=1;
    REP(i,N) REP(j,1<<N)if(dp[i][j]){
        REP(k,N) if(!(j>>k&1)&&a[i][k]) (dp[i+1][j^(1<<k)]+=dp[i][j])%=mod;
    }
    cout<<dp[N][(1<<N)-1]<<endl;
}

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

int main(){
	long long A, B, C, K;
	cin >> A >> B >> C >> K;
	if (A - B > 1E18 || A - B < -1E18) {
		cout << "Unfair" << endl;
		return 0;
	}
	if (K % 2) {
		cout << B-A << endl;
	}
	else {
		cout << A - B << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	int N, K;
	cin >> N;

	vector<int> vNum(N, 0);
	for (int i = 0; i < vNum.size(); i++)
	{
		cin >> vNum[i];
	}

	int result = 0;
	for (int i = 2; i < vNum.size(); i++)
	{
		if (vNum[i - 2] < vNum[i - 1] && vNum[i - 1] < vNum[i])
			++result;
		else if (vNum[i] < vNum[i - 1] && vNum[i - 1] < vNum[i - 2])
			++result;
	}

	cout << result << endl;

	return 0;
}

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

int main(){
	int n, m, s, c;
	int s1, s2, s3;
	s1 = s2 = s3 = -1;
	cin >> n >> m;
	rep(i, m){
		cin >> s >> c;
		if(s == 1 && (s1 == -1 || s1 == c)){
			s1 = c;
		}else if(s == 2 && (s2 == -1 || s2 == c)){
			s2 = c;
		}else if(s == 3 && (s3 == -1 || s3 == c)){
			s3 = c;
		}else{
			cout << -1 << endl;
			return 0;
		}
	}
	
	int ans = 0;
	if(m == 0){
		if(n == 3) ans = 100;
		else if(n == 2) ans = 10;
		else ans = 0;
	} else if(n == 3){
		if(s1 == 0){
			cout << -1 << endl;
			return 0;
		}
		if(s1 == -1 && s2 == -1){
			ans = 100 + s3;
		}else if(s1 == -1 && s3 == -1){
			ans = 100 + s2*10;
		}else if(s2 == -1 && s3 == -1){
			ans = s1*100;
		}else if(s1 == -1){
			ans = 100 + s2*10 + s3;
		}else if(s2 == -1){
			ans = s1*100 + s3;
		}else if(s3 == -1){
			ans = s1*100 + s2*10;
		}else{
			ans = s1*100 + s2*10 + s3;
		}
	}else if(n == 2){
		if(s1 == 0){
			cout << -1 << endl;
			return 0;
		}
		if(s1 == -1) ans = 10 + s2;
		else if(s2 == -1) ans = 10*s1;
		else ans = s1*10 + s2;
	}else if(n == 1){
		ans = s1;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    while(true){
        string str;
        int before, now;
        string right="yuiophjklnm";
        int cnt=0;
        cin >> str;
        if(str=="#") break;
        if(right.find(str[0])!=string::npos) before = 1;
        else before = 0;
        for(int i=1;i<str.size();++i){
            if(right.find(str[i])!=string::npos) now = 1;
            else now = 0;
            if(before!=now) ++cnt;
            before = now;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1192
N, K = map(int, input().split())

import math
def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
for j in range(K):
  if (K+j)>N:
    print(0)
  else:
    x = (nCr((K-1), j) * nCr(N-K+1, j+1))
    print(x%(10**9+7))

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main(){
    int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K;
    int a = 60*H1 + M1;
    int b = 60*H2 + M2;
    cout << (b-a-K) << endl;
}

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

bool isPalin(int n) {
	vector<int> vec;
	while (n > 0) {
		vec.push_back(n % 10);
		n /= 10;
	}
	vector<int> rvec = vec;
	reverse(rvec.begin(), rvec.end());
	return (rvec == vec);
}

int main() {
	int A, B;
	cin >> A >> B;
	int res = 0;
	for (int n = A; n <= B; ++n) {
		if (isPalin(n)) ++res;
	}
	cout << res << endl;
}


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

int main(){
    int N,K,R,S,P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    vector<char> re;
    ll cnt=0;
    rep(i,N){
        char c;
        c = T.at(i);
        if(i<K){
            if(c=='r'){
                cnt+=P;
                re.push_back('p');
            }else if(c=='s'){
                cnt+=R;
                re.push_back('r');
            }else{
                cnt+=S;
                re.push_back('s');
            }
        }else if(i>N-K-1){
            char k = re.at(i-K);
            if(c=='r'){
                if(k!='p'){
                    cnt += P;
                }
            }else if(c=='s'){
                if(k!='r'){
                    cnt += R;
                }
            }else{
                if(k!='s'){
                    cnt += S;
                }
            }
        }else{
            char k = re.at(i-K);
            if(c=='r'){
                if(k!='p'){
                    cnt+=P;
                    re.push_back('p');
                }else{
                    if(T.at(i+K)=='r'||T.at(i+K)=='s'){
                        re.push_back('s');
                    }else{
                        re.push_back('r');
                    }
                }
            }else if(c=='s'){
                if(k!='r'){
                    cnt+=R;
                    re.push_back('r');
                }else{
                    if(T.at(i+K)=='s'||T.at(i+K)=='p'){
                        re.push_back('p');
                    }else{
                        re.push_back('s');
                    }
                }
            }else{
                if(k!='s'){
                    cnt+=S;
                    re.push_back('s');
                }else{
                    if(T.at(i+K)=='r'||T.at(i+K)=='p'){
                        re.push_back('r');
                    }else{
                        re.push_back('p');
                    }
                }
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  ll ans=10000;
  FOR(i,1,n){
      ll a=0;
      ll b=0;
    FOR(j,0,n){
      	if(j<i) a+=A[j];
      	else b+=A[j];
    }
    ans=rM(ans,abs(a-b));
  }
  co(ans)
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,s[21];
    int max,tmp=1,i;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    
    max=s[0];
    for(i=1;i<n;i++){
        if(s[i]>=max){
            max=s[i];
            tmp++;
        }
    }
    
    printf("%d",tmp);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
#include <queue>
 

using namespace std;

int digit(long long x){
    int ans=0;
    while(x>0){
        x%=10;
        ans++;
    }
    return ans;
}

int main() {
    long long k;
    cin >> k;
    
    string s;
    cin >> s;
    
    if(s.length() > k){
        cout << s.substr(0,k) << "..." << endl;
    }
    else cout << s << endl;
    return 0;
 }


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

void push(int);
int pop(void);
int p[100],top=0;

int main(){
  int x,y;
  char st[100];

  while(scanf("%s",st)!=EOF){
    if(st[0]=='+'){
      x=pop();
      y=pop();
      push(x+y);
    }
    else if(st[0]=='-'){
      y=pop();
      x=pop();
      push(x-y);
    }
    else if(st[0]=='*'){
      x=pop();
      y=pop();
      push(x*y);
    }
    else push(atoi(st));
  }  

  printf("%d\n",pop());

  return 0;
}

void push(int q){
  p[++top] = q;
}

int pop (void){
  top--;
  return p[top+1];
}



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



int main(){

    int N , M; std::cin >> N >> M;

    int L_max = 1;
    int R_min = N;

    rep(i , M){
        int L , R; std::cin >> L >> R;
        L_max = std::max(L_max , L);
        R_min = std::min(R_min , R);
    }
    
    std::cout << std::max(R_min - L_max + 1 , 0);

    system("pause");

    return 0;

}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000+10;
const int dem = 2;
const long long INF = 1e18;
struct Point{
    long long x[dem];
}p[maxn];
int n;
long long minx[1<<dem], maxx[1<<dem];
long long solve() {
    int tmp = (1<<dem);
    for(int i=0; i<tmp; i++) {
        minx[i] = INF;
        maxx[i] = -INF;
    }
    for(int i=0; i<n; i++) {
        for(int j=0; j<tmp; j++) {
            int t = j;
            long long s = 0;
            for(int k=0; k<dem; k++) {
                if(t & 1) s += p[i].x[k];
                else s -= p[i].x[k];
                t >>= 1;
            }
            if(maxx[j] < s) maxx[j] = s;
            if(minx[j] > s) minx[j] = s;
        }
    }
    long long ans = -INF;
    for(int i=0; i<tmp; i++) {
        if(maxx[i] - minx[i] > ans)
            ans = maxx[i] - minx[i];
    }
    return ans;
}
int main(){
    while(scanf("%d", &n) != EOF){
        for(int i=0; i<n; i++) {
            for(int j=0; j<dem; j++) {
                scanf("%lld", &p[i].x[j]);
            }
        }
        printf("%lld\n", solve());
        return 0;
    }
}

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

int main(){
	string O,E;
	cin >> O >> E;
	int N=O.size()+E.size();
	for(int i=0;i<N;i++){
		if(i%2==0)cout << O[i/2];
		else cout << E[i/2];
	}
	return 0;
}

Measured memory_bytes: 384
import itertools
import math
import fractions
import functools

K = int(input())
 
res = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    gcd1 = math.gcd(i, j)
    for k in range(1, K+1):
      if gcd1 == 1:
        res += 1
      else:
        res += math.gcd(gcd1, k)
print(res)

Measured memory_bytes: 10308
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES";
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include<cmath>
#include <ctype.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <stack>
#define PI 3.14159265
#define ll long long
#define endl '\n'
#define sz(s) (int)(s.size())
#define all(v) v.begin(),v.end()
const int N = 1e6;
using namespace std;
void RUN() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
}
//vector<int>v1(10000), v2(100005), v3(100005);

int main() {
	RUN();

	double d, t, s;
	cin >> d >> t >> s;
	if ((d / s) <= t) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3756
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, []int) {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	return n, as
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int, as []int) int {
	// even is includes even item more than or equal to 1
	// all case - all odd
	all := pow(3, n)
	cases := 1
	for i := 0; i < len(as); i++ {
		if as[i]%2 == 0 {
			cases *= 2
		}
	}
	return all - cases
}

func pow(n, ex int) int {
	cur := 1
	for i := 0; i < ex; i++ {
		cur *= n
	}
	return cur
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1788
#include <iostream>

using namespace std;

bool kaibun(string s, int l, int r){
  bool ret = true;
  int i;
  for(i=l; i<r; i++){
    if(s[i] != s[r-i]){
      ret = false;
      break;
    }
  }
  return ret;
}

int main(void){
  string S;
  cin >> S;

  if(kaibun(S, 0, (S.length()-3)/2) &&
     kaibun(S, (S.length()+1)/2, S.length()-1) &&
     kaibun(S, 0, S.length()-1) )
     cout << "Yes" << endl;
     else
       cout << "No" << endl;
     
  return 0;
}


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

int main() {
    int x;
    int y;

    int m = 0;

    cin >> x >> y;

    if (x == 1)
        m += 300000;
    else if (x == 2)
        m += 200000;
    else if (x == 3)
        m += 100000;

    if (y == 1)
        m += 300000;
    else if (y == 2)
        m += 200000;
    else if (y == 3)
        m += 100000;

    if (x == 1 && y == 1)
    {
        m += 400000;
    }

    cout << m;

    return 0;
}


Measured memory_bytes: 256
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 100005
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;



int main() {
    ll n, sum = 0;
    cin >> n;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                //cout << i <<  " "<< j << " "<< k << endl;
                ll x = __gcd(i, j);
                sum += __gcd(k, x);
            }
        }
    }
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int mod=1e6+3,N=1e6+5;
int fac[N],inv[N];

int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod;
	return res;
}

void doit(){
	int x,d,n;
	read(x,d,n);
	if(!d){
		write(fpow(x,n));
		return ;
	}
	x=1ll*x*fpow(d,mod-2)%mod;
	if(x<=0||x+n-1>=mod) write(0);
	else write(1ll*fac[x+n-1]*inv[x-1]%mod*fpow(d,n)%mod);
}

signed main(){
	fac[0]=inv[0]=1;for(int i=1;i<mod;i++) fac[i]=1ll*fac[i-1]*i%mod,inv[i]=fpow(fac[i],mod-2);
	int t;
	read(t);
	while(t--) doit(),puts("");
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;


int main(){
  string S;cin >> S;
  int N = S.size();
  string T = "";
  vector<int> P(1,0);
  for(int i = 0;i < N;i++){
    if(S[i] != 'x'){
      T.push_back(S[i]);
      P.push_back(i);
    }
  }
  P.push_back(N);
  int m = T.size();
  //cout << m << endl;
  for(int i = 1;i <= m/2;i++){
    if(m % 2 == 0){
      if(T[m/2-i] != T[m/2+i-1]){
      cout << -1 << endl;
      return 0;
      }
    }else{
      if(T[m/2-i] != T[m/2+i]){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  /*for(int i = 0;i <= m;i++){
    cout << P[i] << ' ';
  }
  cout << endl;*/
  int ans = 0;
  //if(m % 2 == 1){
    int a = 1;
    //cout << m << endl;
    int lbase,rbase;
    if(m % 2 == 0){
      lbase = P[m/2]+1;rbase = P[m/2+1]+1;
      //cout << m/2+1 << endl;
    }else{
      a++;
      lbase = P[m/2+1]+1;rbase = P[m/2+1]+1;
    }
    bool lfrag = 0,rfrag = 0;
    int l = 0,r = 0;
    S = 'a' + S + 'a';
    //cout << S << endl;
    for(int i = 1;i <= m/2+a;i++){
      int l = 0,r = 0;
      int j = 0;
      //cout << lbase << ' ' << rbase << ' ' << l << ' ' << r << ' ' << ">>";
      while(rbase <= N){
        rbase++;
        if(S[rbase+j] != 'x'){
          break;
        }
        r++;
        
      }
      j = 0;
      while(lbase >= 0){
        lbase--;
        if(S[lbase-j] != 'x'){
          break;
        }
        l++;
        
      }
      //cout << lbase << ' ' << rbase << ' ' << l << ' ' << r <<  endl;
      ans += abs(r-l);
    }
  //}
  cout << ans << endl;
}


Measured memory_bytes: 1148
#include<iostream>
using namespace std;
int main()
{
	while (true)
	{
		int a, b;
		cin >> a >> b;
		if (cin.fail())
			break;
		int cnt = 0;
		int x = a + b;
		do {
			x /= 10;
			cnt++;
		} while (x);
		cout << cnt << endl;
	}
}


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	int N;
	string S;
	cin >> N >> S;
	int cnt = 0;
	for (int i = 1; i < N; i++) {
		if (S[i] == 'E') cnt++;
	}
	int ans = cnt;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'W') cnt++;
		if (S[i + 1] == 'E') cnt--;
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3880
#include <stdio.h>

int main()
{
	int i;
	int n, m;
	int a;
	
	scanf("%d", &a);
	scanf("%d %d", &n, &m);
	
	for(i = n; i <= m; i++)
	{
		if(i % a == 0)
		{
			printf("OK");
			return 0; 
		}
	}
	
	printf("NG");
}
	

Measured memory_bytes: 1728
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


/*
vvl comb(int n, int r) {
vvl v(n + 1,vl(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
*/

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}


int main(){
	int n,x,l;
	int ans=0;
	cin>>n;
	pair<int,int> p[M];
	rep(i,0,n){
		cin>>x>>l;
		p[i]=make_pair(x+l,x-l);
	}
	sort(p,p+n);
	int cur=-inf;
	rep(i,0,n){
		if(cur<=p[i].second){
			ans++;
			cur=p[i].first;
		}
	}
	print(ans);
}


Measured memory_bytes: 1920
#!/usr/bin/env python3
import sys


def solve(a: int, b: int):
    print("Even" if (a*b)%2==0 else "Odd" )
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#  X+DP-D(K-P)
# =X-DK+2DP
# =C+2DP
# C>=0?
#   P=0
# C<0?
#   P=~(-C/2D)

i = list(map(int, input().split()))
x = i[0]
k = i[1]
d = i[2]
c=x-d*k
if c>=0:
    print(c)
else:
    p=-c//(2*d)
    ans = 10000000000000000000000000000000000000000
    for i in range(-100,100):
        if 0<=p+i and p+i<=k:
            ans=min(ans,abs(c+2*d*(p+i)))
    if ans == 10000000000000000000000000000000000000000:
        print(abs(c+2*d*k))
    else:
        print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll w, h, n, a, s, x, y;
  in3(w, h, n);
  vector<vector<ll>> c(w, vector<ll> (h));
  rep(i, w){
    rep(j, h)
      c[i][j] = 0;
  }
  rep(k, n){
    in3(x, y, a);
    if(a == 1){
      rep(i, x){
        rep(j, h)
          c[i][j] = 1;
      }
    }
    if(a == 2){
      rep2(i, x, w){
        rep(j, h)
          c[i][j] = 1;
      }
    }
    if(a == 3){
      rep(i, w){
        rep(j, y)
          c[i][j] = 1;
      }
    }
    if(a == 4){
      rep(i, w){
        rep2(j, y, h)
          c[i][j] = 1;
      }
    }
  }
  s = 0;
  rep(i, w){
    rep(j, h){
      if(c[i][j] == 0)
        s++;
    }
  }
  out(s);
  memi;
}

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

int main() {
    int n,k=2,temp,min;
    cin>>n;
    int h[n],dp[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=0;
        min=INT_MAX;
        for(int j=1;j<=k;j++){
            if((i-j)<0)
                break;
            temp=dp[i-j]+abs(h[i]-h[i-j]);
            if(temp<min)
                min=temp;
        }
        dp[i]=min;
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
  int r,c,box[100][100],i,j,sum,sum1=0;
  scanf("%d%d",&r,&c);
  for(i=0;i<r;i++)
    for(j=0;j<c;j++)
      scanf("%d",&box[i][j]);
  for(i=0;i<r;i++)
    {
      for(j=0,sum=0;j<c;j++)
	{
	  printf("%d ",box[i][j]);
	  sum+=box[i][j];
	}
      sum1+=sum;
      printf("%d\n",sum);
    }
   for(i=0;i<c;i++)
    {
      for(j=0,sum=0;j<r;j++)
	sum+=box[j][i];
      printf("%d ",sum);
    }
   printf("%d\n",sum1);
  
  return 0;
}

Measured memory_bytes: 640
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
  kk=max(i-k,0)
  dp[i]=min(d+abs(hh-h[i])for d,hh in zip(dp[kk:i],h[kk:i]))
print(dp[n-1])


Measured memory_bytes: 54364
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 

typedef long long ll;

#define sc(x) scanf("%d",&x);
#define sc2(x,y) scanf("%d%d",&x,&y);
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z);
#define scl(x) scanf("%lld",&x);
#define scl2(x,y) scanf("%lld%lld",&x,&y);
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z);

#define pb push_back
#define mp make_pair
#define fi first
#define se second 


#define debug(x) cerr<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define debug4(x,y,z,a) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#a<<" :: "<<a<<"\n";


#define M 1000000007
#define inf 99999999999999999LL	//long long inf
#define LIM 1000003
ll power(ll x,ll y,ll z) {	ll ret = 1;	while(y > 0) {	if(y & 1) ret = (ret*x)%z;x = (x*x)%z;y >>= 1;}return ret;}

ll n, a[LIM+2],dp[LIM+2],k;

int main() {
	int i, j, t;
	scl2(n, k) ;
	for(i=1;i<=n;i++)
		scl(a[i]) ;
	dp[1] = 0 ;
	dp[2] = abs(a[1]-a[2]) ;
	for(i=3;i<=n;i++)
	{
		dp[i] = inf ;
		for(j=1;j<=k && ((i-j) >=1) ; j++ )
			dp[i] = min(dp[i], dp[i-j]+abs(a[i]-a[i-j]));
	}
	cout << dp[n] << endl ;
	return 0;
}




Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    priority_queue<pair<ll,int> > pq;
    int n,k;
    cin >> n >> k;
    rep(i,n){
        ll tmp;
        int p;
        cin >> p >> tmp;
        pq.push(MP(tmp,p));
    }
    ll ans = 0;
    ll sm=0;
    vector<int> cnt(n+1);
    ll q = 0;
    priority_queue<pair<ll,int> ,vector<pair<ll,int> >,greater<pair<ll,int> >  > pq2;
    int w = 0;
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        ll s = x.first;
        ll t = x.second;
        //cerr << s << " " << t << endl;
        w++;
        if(w<=k){
            if(cnt[t]==0){
                q++;
            }
            cnt[t]++;
            sm += s;
            ans = max(ans,sm+q*q);

            pq2.push(MP(s,t));
        }else{
            if(cnt[t]!=0)continue;
            while(!pq2.empty()){
                auto y = pq2.top();
                pq2.pop();
                if(cnt[y.second]==1){
                    continue;
                }else{
                    cnt[y.second]--;
                    sm -= y.first;
                    cnt[t]++;
                    q++;
                    sm += s;
                    ans = max(ans,sm+q*q);
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5232
intToFloat :: Int -> Float
intToFloat i = (fromIntegral(i::Int)) :: Float

effectiveVotes :: [Int] -> Float -> Int
effectiveVotes [] effective = 0
effectiveVotes (x:xs) effective | (intToFloat x) < effective = effectiveVotes xs effective
                                | otherwise = 1 + effectiveVotes xs effective

main = do
    [n,m] <- map read <$> (words <$> getLine) :: IO [Int]
    ai <- map read <$> (words <$> getLine) :: IO [Int]
    let votes = sum ai
    let effVotes = effectiveVotes ai ((intToFloat votes) / (4.00 * (intToFloat m)))
    if effVotes >= m
        then putStrLn "Yes"
        else putStrLn "No"

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;
ll dp[2][105][5];



int main(){
    string s;
    ll k;
    cin>>s>>k;
    dp[0][0][0]=1;
    s='#'+s;
    for(int i=1;i<s.size();i++){
        for(int before=0;before<=k;before++){
            for(int digit=0;digit<=9;digit++){
                int after=before;
                if(digit!=0){
                    after++;
                }
                if(char('0'+digit)<s[i]){
                    dp[1][i][after]+=dp[0][i-1][before];
                    dp[1][i][after]+=dp[1][i-1][before];
                }
                if(char('0'+digit)==s[i]){
                    dp[0][i][after]+=dp[0][i-1][before];
                    dp[1][i][after]+=dp[1][i-1][before];
                }
                if(char('0'+digit)>s[i]){
                    dp[1][i][after]+=dp[1][i-1][before];
                }
            }
        }
    }
    ll ans=0;
    ans+=dp[0][s.size()-1][k];
    ans+=dp[1][s.size()-1][k];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

bool comp(pair<string, int> a, pair<string, int> b){
  return a.second > b.second;
}

int main(){
  int n;
  std::cin >> n;

  vector<string> s(n);
  unordered_map<string, int> vote;
  for(int idx = 0; idx < n; idx++){
    std::cin >> s[idx];
    vote.insert(make_pair(s[idx], 0));
  }
  for(int idx = 0; idx < n; idx++) { vote[s[idx]] += 1; }

  vector<pair<string, int> > vote_vector;
  for(auto idx = vote.begin(); idx != vote.end(); idx++){
    vote_vector.push_back(make_pair(idx->first, idx->second));
  }

  sort(vote_vector.begin(), vote_vector.end(), comp);

  int max_vote_num = vote_vector[0].second;
  vector<string> ans;
  for(int i = 0; i< vote_vector.size(); i++){
    if(vote_vector[i].second == max_vote_num) ans.push_back(vote_vector[i].first);
  }
  sort(ans.begin(), ans.end());
  for(int idx = 0; idx < ans.size(); idx++){
    std::cout << ans[idx] << '\n';
  }
  return 0;
}


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

using namespace std;

// 2 で割り切れる回数を返す
int f(int x) {
	int res = 0;
	while (x % 2 == 0) {
		x /= 2;
		res++;
	}
	return res;
}

// 最大公約数を返す
long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

// 最小公倍数を返す
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}

int main() {

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

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

	// 入力を 2 で割る
	for (int i = 0; i < N; i++) {
		if (a[i] % 2 == 1) {
			cout << 0 << endl;
			return 0;
		}
		a[i] /= 2;
	}

	// 2 で割り切れる回数が a[0] から a[N - 1] まで、全部同じじゃないとダメ
	// 同じ場合は、2^t で割る
	int t = f(a[0]);
	for (int i = 0; i < N; i++) {
		if (f(a[i]) != t) {
			cout << 0 << endl;
			return 0;
		}
		// a[i] /= 2^t
		a[i] >>= t;
	}

	// M /= 2^t
	M >>= t;

	// 2^t で割った a[0] から a[N - 1] までの lcm を求める。
	// lcm が M を超えるとダメ
	long long lcm_ = 1;
	for (int i = 0; i < N; i++) {
		lcm_ = lcm(lcm_, a[i]);
		if (M < lcm_) {
			cout << 0 << endl;
			return 0;
		}
	}

	// 2^t で割った M = lcm * answer を満たす必要があり、
	// answer は奇数じゃないとダメなので、奇数の個数が答えになる
	M /= lcm_;
	int answer = (M + 1) / 2;

	cout << answer << endl;

	return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int h,w;
vvi a,dp;

int main(){
	cin>>h>>w;
	a=dp=vvi(h+1,vi(w+1));
	dp[1][0]++;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++){
		char c;
		cin>>c;
		a[i][j]=(c=='#'?1:0);
		if(c=='#') continue;
		dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
	}
	cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 8192
f=lambda:map(int,input().split())
n,m=f(); l=list(f())
import fractions as f
k=1
for i in l:
  i//=2; k=k*i//f.gcd(k,i)
  if (k//i)%2<1 or k>m: print(0); break
else: print(m//k-m//(k*2))

Measured memory_bytes: 14100
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;

ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
ll A[300005],mx[300005],mn[300005],cur[300005];
void assign(ll n)
{
	REP(i,1,n)
	{
		A[i]=mx[i]=mn[i]=cur[i]=i;
	}
}
double dist(pll p1,pll p2)
{
	return (1.0)*(p1.f-p2.f)*(p1.f-p2.f)+(1.0)*(p1.s-p2.s)*(p1.s-p2.s);
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s1,s2; 
	cin>>s1>>s2;
	s2+=s1;
	cout<<s2<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

def parse(inp):
    N=int(next(inp).split()[0])
    A=list(map(int,next(inp).split()))
    
    return N,A

def gcd(a,b):
    if(b==0): return a
    return gcd(b,a%b)
  
def main(inp):
    N,A=parse(inp)
    
    for i in range(len(A)-1):
        A[1]=gcd(A[0],A[1])
        del A[0]
        
    return A[0]

  
print(main(sys.stdin))

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

int main(){
    int N; cin >> N;
    vector<long long> A(N);
    long long mx = -1;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        mx = max(mx,A[i]);
    }
    
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(abs(mx/2 - A[i])<abs(mx/2 - ans)) ans = A[i];
    }
    cout << mx <<" "<<ans<< endl;
    
    
    
}


Measured memory_bytes: 4036
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> h;
    for(ll i = 0; i < N; ++i){
        ll tmp;
        cin >> tmp;
        h.push_back(tmp);
    }
    sort(h.begin(), h.end(), greater<ll>());
    ll diff = h[0] - h[K-1];
    for(ll i = 1; i <= N-K; ++i){
        ll tmp_diff = h[i] - h[K-1+i];
        if(tmp_diff < diff) diff = tmp_diff;
    }
    cout << diff << endl;
    return 0;
}

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

int main(){
    int N,X; cin >> N >> X;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    int cnt = 0;
    int D = 0;
    for(int i=0;i<N+1;i++){
        if(D<=X){
            cnt++;
            D=D+L[i];
        }else{
            break;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256