akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <queue>
#include <set>
using namespace std;

typedef struct{
	int bd[8];
} BD;

BD bd0;
queue<BD> q;
set<int> visited;
int tms[100000000] = { 0 };

void swap(int& a, int& b){
	int tmp = b;
	b = a;
	a = tmp;
}
int cal_index(BD b){
	int s = 0;
	for(int i = 0; i < 8; i++){
		s += (b.bd[i] << (3*i));
	}
	return s;
}
bool is_ok(BD b){
	for(int i = 0; i < 8; i++){
		if(b.bd[i] != i){
			return false;
		}
	}
	return true;
}

int find0(BD b){
	for(int i = 0; i < 8; i++){
		if(b.bd[i] == 0){
			return i;
		}
	}
	return -1;
}

bool exist(BD b){
	int v = cal_index(b);
	return visited.find(v) != visited.end();
}

int main(){
		for(int i = 0; i < 8; i++){
			bd0.bd[i] = i;
		}
		int times = 0;
		visited = set<int>();
		visited.insert(cal_index(bd0));
		q = queue<BD>();
		q.push(bd0);
		//make tms table
		int loopcont = true;
		while(loopcont){
			loopcont = false;
			int qsize = q.size();
			while(qsize != 0){
				//pop from que
				BD r = q.front(); q.pop();
				tms[cal_index(r)] = times;
				//make move
				int zero = find0(r);
				BD btmp;
				if(zero < 4){
					btmp = r;
					swap(btmp.bd[zero],btmp.bd[zero+4]);
					if(!exist(btmp)){
						q.push(btmp);
						visited.insert(cal_index(btmp));
						loopcont = true;
					}
				}
				else{
					btmp = r;
					swap(btmp.bd[zero],btmp.bd[zero-4]);
					if(!exist(btmp)){
						q.push(btmp);
						visited.insert(cal_index(btmp));
						loopcont = true;
					}
				}
				if(zero != 0 && zero != 4){
					btmp = r;
					swap(btmp.bd[zero],btmp.bd[zero - 1]);
					if(!exist(btmp)){
						q.push(btmp);
						visited.insert(cal_index(btmp));
						loopcont = true;
					}
				}
				if(zero != 3 && zero != 7){
					btmp = r;
					swap(btmp.bd[zero],btmp.bd[zero + 1]);
					if(!exist(btmp)){
						q.push(btmp);
						visited.insert(cal_index(btmp));
						loopcont = true;
					}
				}

				qsize--;
			}
			times++;
		}

	while(true){
		if(scanf("%d%d%d%d%d%d%d%d",&bd0.bd[0],&bd0.bd[1],&bd0.bd[2],&bd0.bd[3],&bd0.bd[4],&bd0.bd[5],&bd0.bd[6],&bd0.bd[7]) == EOF){
			break;
		}
		printf("%d\n",tms[cal_index(bd0)]);
	}
		//init
	return 0;
}



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

int main(void){
  string ref1 = "";
  string ref2 = "";
  string a;
  cin >> a;

  for (int i = 0;i < a.length(); i++){
    if (i %2 ==0){
      ref1 = "1" + ref1;
      ref2 = "0" + ref2;
    }
    else{
      ref2 = "1" + ref2;
      ref1 = "0" + ref1;
      // ref2 = ref2 + pow(10, i);
    }
  }

  int count1 = 0;
  int count2 = 0;

  for (int i = 0; i < ref1.length(); i++){
    if(ref1[i] != a[i]){
      count1 = count1 + 1;
    }  
  }  

  for (int i = 0; i < ref2.length(); i++){
    if(ref2[i] != a[i]){
      count2 = count2 + 1;
    }  
  }

  if (count1 < count2){
    cout << count1 << endl;
  }
  else{
    cout << count2 << endl;
  }
}


Measured memory_bytes: 784
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using namespace std;

string in;
bool a,b,c;

int main(){
	
	cin>>in;
	for(int x=0;x<3;x++){
		if(in[x]=='a')a=true;
		else if(in[x]=='b')b=true;
		else if(in[x]=='c')c=true;
	}
	if(a&&b&&c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define test int t; cin >> t; while (t--)
#define fast ios::sync_with_stdio(NULL); cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define ALL(v) v.begin(),v.end()
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC


int main(){
    fast;

 //    #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    //freopen("output.txt","w",stdout);
	// cout << "TIME ESCAPED: " << time << endl;
 //    #endif

    //test{}
	ll k,n;
	cin >> k>>n;
	vecll a(n);
	for(auto &x:a)cin>>x;
	ll ans =a[n-1]-a[0];
	for(int i=1;i<n;i++){
		ans=min(ans,k-a[i]+a[i-1]);
	}    
	cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
const main = (txt: any): void => {
  const input = txt.split('\n')
  const [k, s]: number[] = input[0].split(' ').map((i: string) => Number(i))
  let count: number = 0
  for (let x = 0; x <= k; x++) {
    for (let y = 0; y <= k; y++) {
      if ((s - x - y) <= k && (s - x - y) >= 0) {
        count++
      }
    }
  }
  console.log(count)
}



main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> PII;
#define MOD (1000000007ll)

int main(void){
	int n,i,f=0;
	cin >> n;
	i = n;
	while(i>0){
		f += i%10;
		i /= 10;
	}
	cout << ((n%f==0)?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int mi, la, se;

  while(1){
    scanf("%d %d %d",&mi,&la,&se);
    if(mi==-1 && la==-1 && se==-1) break;

    if(mi==-1 || la==-1) printf("F\n");
    else if(mi+la>=80) printf("A\n");
    else if(mi+la>=65) printf("B\n");
    else if(mi+la>=50) printf("C\n");
    else if(mi+la>=30){
      if(se>=50) printf("C\n");
      else printf("D\n");
    }
    else printf("F\n");
  }
  
  return 0;
}



Measured memory_bytes: 2064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include <iostream>
#include <algorithm>

using namespace std;
#define INF 0x3f3f3f3f

const int maxn = 1e6 + 100;

char s[maxn];



int main()
{
	while(scanf("%s",s)!= EOF){
		int len = strlen(s),ans = len;
		for(int i = 1;i < len;i++){
			if(s[i-1] != s[i])
				ans = min(ans,max(i,len-i));
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define LL long long

LL x, y;

int main()
{
      scanf("%lld%lld", &x, &y);
    if(abs(x - y) <= 1) printf("Brown\n");
    else printf("Alice\n"); 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long int com2(long long int n)
{
    return n * (n - 1) / 2;
}

int main()
{
    int N;
    scanf("%d", &N);
    int nums[200005];
    long long int times[200005];
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &nums[i]);
        times[i] = 0;
    }
    times[N] = 0;

    for (int i = 0; i < N; i++)
    {
        times[nums[i]]++;
    }
    long long int sum = 0;
    for (int i = 0; i <= N; i++)
    {
        sum += com2(times[i]);
    }
    for (int i = 0; i < N; i++)
    {
        printf("%lld\n", sum - com2(times[nums[i]]) + com2(times[nums[i]] - 1));
    }
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  int ans = 0;
  
  int cont;
  for (int i = 0; i < S.size(); i++) {
    cont = 0;
    while(i < S.size() && (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T')) {
      i++;
      cont++;
      
    }
    if (cont > ans) ans = cont;
  }
  cout << ans << endl;
}

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

using namespace std;

int solve(const vector<vector<int>> &v_positions,
          const vector<vector<int>> &h_positions, const pair<int, int> &pos) {
  int pos_x = pos.first, pos_y = pos.second, ans = 0;
  const vector<int> &v_pos = v_positions[pos_x], &h_pos = h_positions[pos_y];

  // up, down, left, right
  ans +=
      pos_y - *lower_bound(v_pos.rbegin(), v_pos.rend(), pos_y, greater<int>());
  ans += *lower_bound(v_pos.begin(), v_pos.end(), pos_y) - pos_y;
  ans +=
      pos_x - *lower_bound(h_pos.rbegin(), h_pos.rend(), pos_x, greater<int>());
  ans += *lower_bound(h_pos.begin(), h_pos.end(), pos_x) - pos_x;

  return max(0, ans - 3);
}

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  vector<vector<int>> v_positions(w), h_positions(h);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char ch;
      cin >> ch;
      if (ch == '#') {
        v_positions[j].push_back(i);
        h_positions[i].push_back(j);
      }
    }
  }

  for (int i = 0; i < h; ++i) {
    h_positions[i].push_back(-1);
    h_positions[i].push_back(w);
    sort(h_positions[i].begin(), h_positions[i].end());
  }

  for (int i = 0; i < w; ++i) {
    v_positions[i].push_back(-1);
    v_positions[i].push_back(h);
    sort(v_positions[i].begin(), v_positions[i].end());
  }

  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans = max(ans, solve(v_positions, h_positions, {j, i}));
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 34432
from collections import defaultdict
def comb(n,k):
    n1, k = n+1, min(k, n-k)
    numer = denom = 1
    for i in range(1,k+1):
        numer = numer*(n1-i)
        denom = denom*i
    return numer//denom
def main():
    N = int(input())
    a = list(map(int,input().split()))
    d = defaultdict(int)
    for A in a:
        d[A] += 1
    S = defaultdict(int)
    total = 0
    for v in d.items():
        key = v[0]
        n = v[1]
        if n < 2:S[key] = 0
        else:S[key] = comb(n,2)
        total += S[key]
    for A in a:
        m = d[A]-1
        if m < 2:
            print(total-S[A])
        else:
            t = comb(m,2)
            print(total-S[A]+t)
        
    
if __name__ == "__main__":
    main()

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N;
string S;

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

    size_t pos = 0;
    int count = 0;
    while (pos != string::npos) {
        pos = S.find("ABC", pos);
        if (pos != string::npos) {
            count++;
            pos += 3;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
int A[500005],N,c=0,i,tmp[2][250005];
void marge(int l,int m,int r)
{
    int i,j,c1=m-l,c2=r-m;
    for(i=0;i<c1;i++)tmp[0][i]=A[l+i];
    for(i=0;i<c2;i++)tmp[1][i]=A[m+i];
    tmp[0][c1]=tmp[1][c2]=INT_MAX;
    for(i=j=0;i<c1||j<c2;c++)
    {
        if(tmp[0][i]<tmp[1][j])
        {
            A[l+i+j]=tmp[0][i];
            i++;
        }
        else
        {
            A[l+i+j]=tmp[1][j];
            j++;
        }
    }
}
 
void margeSort(int l,int r)
{
    int m;
    if(l+1<r)
    {
        m=(l+r)/2;
        margeSort(l,m);
        margeSort(m,r);
        marge(l,m,r);
    }
}
 
int main()
{
    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",A+i);
    margeSort(0,N);
    for(i=0;i<N;i++)
        printf("%d%c",A[i],i==N-1?'\n':' ');
    printf("%d\n",c);
    return 0;
}


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

using namespace std;
#define sd(x) scanf("%d", &x);
#define sdl(x) scanf("%lld", &x);
#define pr(x) printf("%d\n", x);
#define prl(x) printf("%lld\n", x);

long long int mod = 1000000007;

long long int gcd(long long int a, long long int b)
{
    if (b < a)
        return gcd(b, a);
    else if (b % a == 0)
        return a;
    else
        return gcd(b % a, a);
}

long long fast_exp(long long a, long long n, long long mod1)
{

    if (n == 0)
        return 1;
    else if (n == 1)
        return a;
    if (n % 2 == 0)
        return fast_exp((a * a) % mod1, n / 2, mod1);
    else
        return (a * fast_exp((a * a) % mod1, n / 2, mod1)) % mod1;
}
bool is_square(long long a)
{
    long long int b = sqrt(a);
    if (b * b == a)
        return true;
    else
        return false;
}
long long n_fact[1000001];
void calc_fact(int n) // calculates the factorial % mod and stores in n_fact upto n
{
    n_fact[0] = 1;
    for (int c(1); c <= n; c++)
        n_fact[c] = (c * n_fact[c - 1]) % mod;
    return;
}
long long calc_inverse_mod(long long x, long long mod)
{
    return fast_exp(x, mod - 2, mod);
}
bool n_primes[100001] = {false};
void calc_primes(int n)
{
    for (int c(2); c <= 100000; c++)
    {
        if (n_primes[c] == true)
            continue;
        for (int c1(c + c); c1 <= 100000; c1 = c1 + c)
            n_primes[c1] = true;
    }
    return;
}
bool is_palindrome(string a)
{
    string b = a;
    reverse(b.begin(), b.end());
    if (b == a)
        return true;
    else
        return false;
}


double dp[100000];
int done[100000];
unordered_map<int,vector<int>>graph;

void dfs(int i,int prev)
{
   
    if (done[i]!=0)
        return;
    double e=0;
    done[i]=1;
    int siz=0;
    for (int c=0;c<graph[i].size();c++)
        {
            if (graph[i][c]==prev)
                continue;
            dfs(graph[i][c],i);
            e+=1+dp[graph[i][c]];
            siz++;
        }
      
      
        dp[i]=e/max(1,siz);
    return ;

}
int main()
{

    ios_base::sync_with_stdio(false);
    int t;
    t = 1;

    for (int tt = 0; tt < t; tt++)
    {
       int a;
       cin >> a;
       long long res = 1000*(a/500);
       a=a%500;
       res+=5*(a/5);
        cout << res << endl;
    
    }
    return 0;
}


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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x;
    cin >> n;
    set < int > Q;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        Q.insert(x);
    }
    if ((int)Q.size() == n) cout << "YES";
    else cout << "NO";
    return 0;
}



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

int main()
{
    int N, K;
    cin >> N >> K;

    int x;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> x;
        ans += 2 * min(abs(x), abs(x - K));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  char a;
  cin>>a;
  string b="ABCDEFGHIJKlMNOPQRSTUVWXYZ";
  rep(i,26){
    if(a==b[i]){
      cout<<'A'<<endl;
      return 0;
    }
  }
      cout<<'a'<<endl;
      return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

int h, w;
vector<string> s;
int sy, sx, sd, gy, gx, gd;

int toInt(int y1, int x1, int d1, int y2, int x2, int d2)
{
    return ((((y1 * w + x1) * 4 + d1) * h + y2) * w + x2) * 4 + d2;
}

vector<bool> memo;

bool isAccomplish(int y1, int x1, int d1, int y2, int x2, int d2)
{
    if(memo[toInt(y1, x1, d1, y2, x2, d2)])
        return false;
    memo[toInt(y1, x1, d1, y2, x2, d2)] = true;

    if(s[y2+dy[d2]][x2+dx[d2]] != '#')
        return false;

    while(s[y1+dy[d1]][x1+dx[d1]] != '#'){
        y1 += dy[d1];
        x1 += dx[d1];
    }

    while(s[y2][x2] != '#'){
        if(isAccomplish(y1, x1, (d1+1)%4, y2, x2, (d2+1)%4))
            return true;
        if(isAccomplish(y1, x1, (d1+3)%4, y2, x2, (d2+3)%4))
            return true;
        y2 -= dy[d2];
        x2 -= dx[d2];
    }

    y2 += dy[d2];
    x2 += dx[d2];
    if(y1 == gy && x1 == gx && y2 == gy && x2 == gx && d2 == gd)
        return true;

    return false;
}

bool isBring(int y, int x, int d)
{
    if(y == gy && x == gx)
        return true;

    if(memo[toInt(0, 0, 0, y, x, d)])
        return false;
    memo[toInt(0, 0, 0, y, x, d)] = true;

    while(s[y+dy[d]][x+dx[d]] != '#'){
        y += dy[d];
        x += dx[d];
    }

    return isBring(y, x, (d+1)%4) || isBring(y, x, (d+3)%4);
}

int main()
{
    for(;;){
        cin >> w >> h;
        if(w == 0)
            return 0;

        s.resize(h);
        for(int i=0; i<h; ++i)
            cin >> s[i];

        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                if(s[i][j] == 'K'){
                    sy = i;
                    sx = j;
                    sd = 0;
                    while(s[sy+dy[sd]][sx+dx[sd]] == '#')
                        ++ sd;
                }else if(s[i][j] == 'M'){
                    gy = i;
                    gx = j;
                    gd = 0;
                    while(s[gy+dy[gd]][gx+dx[gd]] == '#')
                        ++ gd;
                }

            }
        }

        memo.assign(h * h * w * w * 4 * 4, false);
        bool ret = false;
        for(int i=0; i<4; ++i)
            ret |= isAccomplish(sy, sx, sd, sy, sx, i);

        if(ret)
            cout << "He can accomplish his mission." << endl;
        else if(isBring(sy, sx, sd))
            cout << "He cannot return to the kitchen." << endl;
        else
            cout << "He cannot bring tea to his master." << endl;
    }
}

Measured memory_bytes: 4280
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;

double dot(P a, P b) {
    return real(conj(a) * b);
}

P project(P x, P d) {
    return dot(x, d) * d / abs(d) / abs(d);
}

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

    double x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    P p0(x0, y0), p1(x1, y1);
    int q;
    cin >> q;
    while (q--) {
        double x2, y2;
        cin >> x2 >> y2;
        P p2(x2, y2);
        P a = project(p2 - p0, p1 - p0) + p0;
        printf("%.10f %.10f\n", a.real(), a.imag());
    }

}

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

using namespace std;

int min (int x, int y) {
  if (x < y) {
    return x;  
  }  
  else {
    return y;  
  }
}

int main () {
  int D, G;
  cin >> D >> G;
  vector<int> p;
  vector<int> c;
  p.push_back(0);
  c.push_back(0);
  int sub, subsub;
  for (int i = 0; i < D; i++) {
    cin >> sub >> subsub;
    p.push_back(sub);
    c.push_back(subsub);    
  }  

  // dpを設定する.
  vector<vector<int> > dp;
  dp.resize(D + 1);
  for (int i = 0; i < (D + 1); i++) {
    
    // 0番目が0円...G/100番目がG円ということになる.    
    dp[i].resize(G/100 + 1);
  } 

  for (int i = 0; i <= D; i++) {
    for (int j = 0; j <= (G/100); j++) {
      dp[i][j] = 0;
      if (i == 0 && j != 0) {
        dp[i][j] = 1001;  
      }  
    }  
  }

  // 動的計画法を開始する.
  for (int i = 1 ; i <= D; i++) {
    for (int j = 0; j <= (G/100); j++) {
      
      // まずjが0円の時はそのまま採用するべし
      if (j == 0) {
        dp[i][0] = dp[i-1][0];  
      }  
      else {

          // 元の金額
          sub = j;
          for (int q = 1; q <= p[i]; q++) {
            if (sub == 0) {
              break;    
            }
            sub = sub - i;
            if (q == p[i]) {
              sub = sub - c[i]/100;  
            }  
            if (sub < 0 ) {
              sub = 0;  
            }
            dp[i][j] = min(dp[i-1][j],dp[i-1][sub] + q);
          }
      }
    }    
  } 

  // 最終的な出力
  cout << dp[D][G/100] << endl;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    string s;cin>>s;
    int n =s.length();
    int ma;cin>>ma;
    int dp [n+1][ma+1][2];
    rep(i,n+1)rep(j,ma+1)rep(k,2)dp[i][j][k]=0;
    dp[0][0][0]=1;
    rep(i,n)rep(j,4)rep(k,2){
        int nd =s[i]-'0';
        rep(d,10){
            int ni=i+1,nj=j,nk=k;
            if(d!=0)nj++;
            if(nj>ma)continue;
            if(k==0){
                if(nd>d)nk=1;
                if(nd<d)continue;
            }
            dp[ni][nj][nk]+=dp[i][j][k];
        }
    }
    cout<<dp[n][ma][0]+dp[n][ma][1]<<endl;
}

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

int main(void){
    char ch;
    while(1){
        scanf("%c",&ch);
        if(ch == '\n'){
            break;
        }
        if(islower(ch)){
            printf("%c",toupper(ch));
        } else if(isupper(ch)){
            printf("%c",tolower(ch));
        } else {
            printf("%c",ch);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  ll X;
  cin >> N >> X;
  vector<ll> w(N + 1), b(N + 1);
  w[0] = 1ll;
  b[0] = 1ll;
  for (int i = 1; i <= N; i++) {
    w[i] = (w[i - 1] * 2) + 3;
    b[i] = (b[i - 1] * 2) + 1;
  }
  ll ans = 0ll;
  function<void(int, ll)> dfs = [&](int level, ll x) {
    if (x <= 0ll) return;
    if (x >= w[level] - 1ll) {
      ans += b[level];
    } else if (x >= 2ll + w[level - 1]) {
      ans += b[level - 1] + 1ll;
      dfs(level - 1, x - 2ll - w[level - 1]);
    } else {
      dfs(level - 1, x - 1ll);
    }
  };
  dfs(N, X);
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  int N, K; scanf("%d%d", &N, &K);
  int plan[100];
  for(int i = 0; i < N; ++i) plan[i] = -1;
  for(int i = 0; i < K; ++i) {
    int A, B; scanf("%d%d", &A, &B); --A; --B;
    plan[A] = B;
  }
  int dp[2][3][3];
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      dp[0][i][j] = (i == 0 && j == 0);
  for(int day = 0; day < N; ++day) {
    for(int i = 0; i < 3; ++i) {
      for(int j = 0; j < 3; ++j) {
        int cnt = 0;
        for(int k = 0; k < 3; ++k) {
          if((plan[day] == j || plan[day] == -1) &&
             (day < 2 || i != k || j != k)) {
            cnt = (cnt + dp[day & 1][k][i]) % 10000;
          }
        }
        dp[(day + 1) & 1][i][j] = cnt;
      }
    }
  }
  int cnt = 0;
  for(int i = 0; i < 3; ++i) {
    for(int j = 0; j < 3; ++j) {
      cnt = (cnt + dp[N & 1][i][j]) % 10000;
    }
  }
  printf("%d\n", cnt);
  return 0;
}

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

int main(){
  string S, T; cin >> S >> T;
  int A, B; cin >> A >> B;
  string U; cin >> U;
  if (U == S) A--;
  else B--;
  cout << A << " " << B << endl;
}


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

int gcd(int x,int y) {
    int r = x%y;
    if(r==0){
        return y;
    }else{
        return gcd( y, r);
    }
}

int main(){
    int x, y;
    cin >> x >> y;
    cout << gcd(x,y) << endl;
    return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

int main(){

    ll n; cin >> n;
    vvll ba(n, vll(2));
    rep(i, n) cin >> ba[i][1] >> ba[i][0];

    sort(all(ba));
    ll t = 0;

    rep(i, n){
        ll a = ba[i][1], b = ba[i][0];
        t += a;
        if(t>b){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 14312
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);
        int a,b;
        cin>>a>>b;
        cout<<a*b;
        
        return 0;
}
/*

        creation time:  13.09.2020 09:23:27

*/                      



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
static const int N_MAX = 200000;
int main(){
    int n;
    int A[N_MAX+2];
    int L[N_MAX+2],R[N_MAX+2];
    L[0] = 0;
    cin >> n;
    R[n+1] = 0;
    for (int i=1;i<=n;i++){
        cin >> A[i];
    }
    for (int i=1;i<=n;i++){
        L[i] = max(L[i-1],A[i]);
        int j = n-i+1;
        R[j] = max(R[j+1],A[j]);
    }    
    for (int i = 0;i<n;i++){
        cout << max(L[i],R[i+2]) << endl;
    }

}

Measured memory_bytes: 3968
N = int(input())
A = [int(input()) for i in range(N)]
  
maxv = -20**9
minv = A[0]
for i in range(1, N):
    maxv = max(maxv, A[i] - minv)
    minv = min(minv, A[i])
  
print(int(maxv))


Measured memory_bytes: 13592
from collections import Counter
def solve():
    n = int(input())
    a = list(map(int, input().split()))

    if 0 in a: return 0
    l = Counter(a)
    ans = 1
    for i,j in l.items():
        ans *= i**j
        if ans > int(1e18):
            return -1

    return ans
    

print(solve())

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

int main() {
  int a,b;
  cin >> a >> b;
  if((a+b) % 2 == 0){
    cout << (a+b)/2;
  }
  else{
    cout << "IMPOSSIBLE";
  }
}

Measured memory_bytes: 3600
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }
string s[200], t[200];

int main(){
	
	int N,M;
	//string s[N], t[M];
	
	cin >> N;
	for(int i=0;i<N;i++) cin >> s[i];
	cin >> M;
	for(int i=0;i<M;i++) cin >> t[i];
	
	map<string, int> m;
	for(int i=0;i<N;i++) m[s[i]]++;
	for(int i=0;i<M;i++) m[t[i]]--;
	
	int ans = 0;
	for(auto &itr : m){
		ans = max(ans, itr.second);
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*-------------------------------"ANJAN AGARWALA"-----------------------------

         _/_/_/_/    _/_/    _/   _/_/_/_/   _/_/_/_/    _/_/    _/   
        _/    _/    _/ _/   _/         _/   _/    _/    _/ _/   _/        
       _/_/_/_/    _/   _/ _/         _/   _/_/_/_/    _/  _/  _/         
      _/    _/    _/    _/_/   _/    _/   _/    _/    _/    _/_/  
     _/    _/    _/      _/   _/_/_/_/   _/    _/    _/      _/   

-------------------------------------@anjn98---------------------------------*/

//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

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

typedef long long int ll;
typedef long long int LL;
typedef unsigned long long int ull;
ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int csrand(int l=0, int r=1e9){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define PR(a)           cout<<"("<<a<<")";
#define ED              cout<<'\n';
#define endl            '\n'
#define loop(j,a,n)     for(int j=a;j<=n;j++)
#define loop1(j,a,n)    for(int j=a;j>=n;j--)
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define SC(n)           scanf("%d",&n)
#define PB              push_back
#define MP              make_pair
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first
#define S               second 
#define binf            2000000000000000001
#define mod             1000000007


const int N=52;
ll mat[N][N],n,k,tmp[N][N];

void mul(ll mat[][N],ll tmp[][N])
{
    ll res[N][N];

    for(int i=0;i<n;i++)    
        for(int j=0;j<n;j++)res[i][j]=0;

    for(int i=0;i<n;i++)    
        for(int j=0;j<n;j++)    
            for(int k=0;k<n;k++)
                res[i][j]=(res[i][j]+ (mat[i][k]*tmp[k][j])%mod)%mod;
    
    for(int i=0;i<n;i++)    
        for(int j=0;j<n;j++)mat[i][j]=res[i][j];    
}

int main() 
{
    IO
    cin>>n>>k;

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>mat[i][j];

    fr(N) tmp[i][i]=1;
    while(k>0)
    {
        if(k%2) mul(tmp,mat);           
        mul(mat,mat);
        k=k>>1;
    }
    ll ans=0;

    for(int i=0;i<n;i++)    
        for(int j=0;j<n;j++)ans=(ans + tmp[i][j])%mod;    

    cout<<ans<<endl;

}




 

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

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

int main(){
  int n;
  vector<vector<int>> a(3,vector<int>(3));
   rep(i,3){
    rep(j,3){
      cin>>a[i][j];
    }
   }
  cin>>n;
  vector<int> b(n);
   rep(i,n){
   cin>>b[i];
  }

  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(b[i]==a[j][k]) a[j][k]=0;
      }
    }
  }

  rep(i,3){
    if(a[i][0]==0&&a[i][1]==0&&a[i][2]==0){
       cout<<"Yes";
       return 0;
    }
  }

    rep(i,3){
      if(a[0][i]==0&&a[1][i]==0&&a[2][i]==0){
        cout<<"Yes";
         return 0;
      }
    }
    if((a[0][0]==0&&a[1][1]==0&&a[2][2]==0)||(a[0][2]==0&&a[1][1]==0&&a[2][0]==0)){
       cout<<"Yes";
       return 0;
    }
  cout<<"No";
}



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

using namespace std;

typedef pair<int, int> P;

vector<int> G[10000];
int depth[10000];
bool used[10000];

void dfs(int v, int d){
    
    used[v] = true;
    depth[v] = d;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]) dfs(G[v][i], d+1);
    }
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int c[10000];
    for(int i = 0; i < N; i++) cin >> c[i];
    sort(c, c+N);
    vector<P> ans;
    dfs(0, 0);
    vector<P> buf;
    for(int i = 0; i < N; i++) buf.push_back(P(depth[i], i));
    sort(buf.begin(), buf.end(), greater<P>());
    for(int i = 0; i < N; i++){
        ans.push_back(P(buf[i].second, c[i]));
    }
    sort(ans.begin(), ans.end());
    int sum = 0;
    for(int i = 0; i < N-1; i++) sum += c[i];
    cout << sum << endl;
    for(int i = 0; i < N-1; i++) cout << ans[i].second << ' ';
    cout << ans[N-1].second << endl;
}

Measured memory_bytes: 1664
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
ll vis[5005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
  // cin>>t;
    for(int ok=1;ok<=t;ok++)
    {
        
        ll n,k;
        cin>>n>>k;
        ll p[n+3],cp[n+3];
        for(int i=1;i<=n;i++)
          cin>>p[i];
        for(int i=1;i<=n;i++)
          cin>>cp[i];
        ll cnt=0;
        std::vector<ll> v[n+3];
        for(int i=1;i<=n;i++)
        {
           if(vis[i])
            continue;
           else
           {
              ll x=i; 
              cnt++;
              while(1)
              {
                  if(!vis[x])
                  {
                     vis[x]=1;
                     v[cnt].pb(cp[p[x]]);
                     x=p[x];
                  }
                  else
                    break;
              }
           }
        }
        ll ans=-hell;
        for(int i=1;i<=n;i++)
          ans=max(ans,cp[i]);
        //cout<<ans;
        for(int i=1;i<=cnt;i++)
        {
            ll o=v[i].size();
            for(int j=0;j<o;j++)
              v[i].pb(v[i][j]);
            for(int j=1;j<v[i].size();j++)
              v[i][j]+=v[i][j-1];
        }
        //ll ans;
        for(int i=1;i<=cnt;i++)
        {

            ll o=v[i].size();
            o/=2;
            ll ox[o+2];
            for(int j=0;j<=o;j++)
              ox[j]=-hell;
            for(int j=1;j<=o;j++)
            {
               for(int l=0;l<=2*o-j;l++)
               {
                   if(l!=0)
                   ox[j]=max(ox[j],v[i][l+j-1]-v[i][l-1]);
                 else
                  ox[j]=max(ox[j],v[i][l+j-1]);
                //cout<<ox[j]<<" ";
               }
               //cout<<ox[j]<<endl;
            }
            ll cn=-hell;
            for(int j=1;j<=o;j++)
            {
                if(j>k)
                  break;
                ll op;
                op=ox[j];
                ll ok=k-j;
                op=max(op,op+(ok/o)*(v[i][o-1]));
                cn=max(cn,op);

            }
            ans=max(cn,ans);
        }
        cout<<ans;

    }
    return 0;
}

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

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

using namespace std;

int main(){
  int m,d;cin>>m>>d;cin>>m>>d;
  if(d==1){
    cout<<1;
  }else{
    cout<<0;
  }
  return 0;
}

Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*; 
import java.lang.*; 
import java.io.*;
import java.math.BigInteger; 
import java.math.*;

 public class Main {
    
	public static void main(String[] args) {
		
		InputStream inputStream = System.in;

		InputReader sc = new InputReader(inputStream);

				
		// int t=sc.nextInt();
		 long c=1000000007;
	
	    int n=sc.nextInt();
	    int dp[][]= new int[n][3];
	    int a[][]= new int[n][3];
	   
	 for(int i=0;i<n;i++){
	     a[i][0]=sc.nextInt();
	      a[i][1]=sc.nextInt();
	       a[i][2]=sc.nextInt();
	 }
	  dp[0][0]=a[0][0];
	       dp[0][1]=a[0][1];
	       dp[0][2]=a[0][2];
	  for(int i=1;i<n;i++){
	     dp[i][0]=Math.max(dp[i-1][1],dp[i-1][2])+a[i][0];
	      dp[i][1]=Math.max(dp[i-1][0],dp[i-1][2])+a[i][1];
	       dp[i][2]=Math.max(dp[i-1][1],dp[i-1][0])+a[i][2];
	 }
	 int ans=Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
System.out.println(ans);
	    
	}
	

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
				    tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
				    throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public float nextFloat() {
			return Float.parseFloat(next());
		}
		
		
	}
}

Measured memory_bytes: 51072
#include <stdio.h>
#include <stdlib.h>

int main (void) {
    int         i;
    int         n;
    long long   ans = 0;

    scanf("%d", &n);

    for ( i=1; i<=n; i++ ) {
        if ( i % 3 != 0 && i % 5 != 0 )
            ans += i;
    }

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 1688
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace BinarySearch
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var seq1 = ReadLine().Split(' ').Select(int.Parse).ToList();
            var q = int.Parse(ReadLine());
            var seq2 = ReadLine().Split(' ').Select(int.Parse);

            var count = 0;

            foreach (var s in seq2)
            {
                if (BinarySearch(seq1, s) != -1) count++;
            }
            WriteLine(count);
            
        }


        private static int BinarySearch(IReadOnlyList<int> seq, int key)
        {
            
            var left = 0;
            var right = seq.Count;
            while (left < right)
            {
                var mid = (left + right) / 2;
                if (seq[mid] == key)
                {
                    return mid;
                }else if (seq[mid] > key)
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            return -1;
        }
    }
}


Measured memory_bytes: 30064
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    int num;
    int *score;
    int sum;
    double ave;
    double var;
    double sdev;
    while(1)
    {
        std::cin >> num;

        if (num == 0) break;

        score = new int[num];
        sum = 0;
        for (int i = 0; i < num; i++)
        {
            std::cin >> score[i];
            sum += score[i];
        }
        ave = static_cast<double>(sum) / num;

        var = 0;
        for (int i = 0; i < num; i++)
        {
            var += pow(score[i] - ave, 2);
        }
        var /= num;

        sdev = sqrt(var);

        std::cout << std::fixed << std::setprecision(5) << sdev << std::endl;
    }
}


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

long long int calcMini(long long int nw, long long int nh)
{
    return (nw / 2) * nh;
}

long long int calcSizeDiff(long long int sq1, long long int sq2, long long int sq3)
{
    long long int choco[3]= {sq1,sq2,sq3};
    sort(choco, choco + 3);
    if(choco[0] <= 0)
    {
        return sq1 + sq2 + sq3;
    }
    return choco[2] - choco[0];
}

void debug(long long int size, long long int sq1, long long int sq2, long long int sq3)
{
    if(size < 50000)
    {
        cout << sq1 << " " << sq2 << " " << sq3 << endl;
    }
}

long long int calcComp(long long int sq1,long long int subH, long long int h,long long int w)
{
    long long int sq2hw = calcMini(subH, w);
    long long int sq3hw = h*w - sq1 - sq2hw;
    long long int sizeHw = calcSizeDiff(sq1,sq2hw,sq3hw);
    //debug(sizeHw, sq1, sq2hw, sq2hw);
    long long int sq2wh = calcMini(w,subH);
    long long int sq3wh = h*w - sq1 - sq2wh;
    long long int sizeWh = calcSizeDiff(sq1,sq2wh,sq3wh);
    //debug(sizeHw, sq1, sq2wh, sq2wh);
    return min(sizeHw, sizeWh);
}

long long int calc(long long int h, long long int w)
{
    long long int height;
    long long int ans = h * w;
    for(height = 1; height < h; ++height)
    {
        long long int subH = h - height;
        long long int sq1 = height * w;
        long long int tSize = calcComp(sq1, subH, h,w);
        ans = min(ans, tSize);
    }
    return ans;
}

int main()
{
    long long int h, w;
    cin >> h >> w;
    long long int ans1 = calc(h,w);
    long long int ans2 = calc(w,h);
    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var tokens = Console.ReadLine().Split(' ');
        var a = int.Parse(tokens[0]);
        var b = int.Parse(tokens[1]);

        var c = 1;
        var t = 0;
        for (int i = 0; i < 40; i++)
        {
            if (c >= b)
            {
                break;
            }
            c += a - 1;
            t++;
        }
        Console.WriteLine(t.ToString());
    }
}


Measured memory_bytes: 11092
// https://atcoder.jp/contests/abc133/tasks/abc133_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    vector<int> A(N), B(N + 1);
    REP(i, N) cin >> A[i];
    // 仮に山1が0リットルを計算して、辻褄を合わせる
    B[0] = 0;
    FOR(i, 1, N + 1) { B[i] = A[i - 1] - B[i - 1]; }
    // B[N]が0になるように辻褄を合わせる
    B[0] = B[N];
    FOR(i, 1, N) { B[i] = A[i - 1] * 2 - B[i - 1]; }
    REP(i, N) { cout << B[i] << (i == N - 1 ? "\n" : " "); }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

int main(void){
    int n;
    cin >> n;
    set<int> st;
    for(int i=0; i<n; i++){
        int aa;
        cin >> aa;
        st.insert(aa);
    }
    int s[110000];
    for(int i=0; i<110000; i++){
        s[i] = -1;
    }
    int ix = 0;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        s[ix] = *itr;
        ix++;
    }
    sort(s, s+110000);
    int q;
    cin >> q;
    int t[51000];
    for(int i=0; i<q; i++){
        cin >> t[i];
    }

    int count = 0;
    
    for(int i=0; i<q; i++){
        if(binary_search(s, s+110000, t[i])) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 8300
#include <stdio.h>
int main(){
  int n, x;
  int i, j, k, l;

  for(i=0; i<1000; i++){
    scanf("%d %d", &n, &x);
    if(n==0 && x==0){
      break;
    }else{
      int count_check=0;
      for(j=1; j<n+1; j++){
        for(k=j+1; k<n+1; k++){
          for(l=k+1; l<n+1; l++){
            if(j+k+l==x){
              count_check+=1;
              break;
            }
          }
        }
      }
      printf("%d\n", count_check);
    }
  }
  return 0;
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A + D - 1) / D >= (C + B - 1) / B)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<math.h>
 
int main(void)
{
	double x_p, y_p, r;
 	double x1, x2, x3, y1, y2, y3;
	double ecm[2][3]; //enlarged coefficient matrix:拡大係数行列
	double a, b, A;
	int i;
	int n;

	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
 		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);

		ecm[0][0] = x1 - x2;
		ecm[0][1] = y1 - y2;
		ecm[0][2] = (x2 * x2 + y2 * y2) - (x1 * x1 + y1 * y1);
		ecm[1][0] = x1 - x3;
		ecm[1][1] = y1 - y3;
		ecm[1][2] = (x3 * x3 + y3 * y3) - (x1 * x1 + y1 * y1);

		A = (ecm[0][0] * ecm[1][1]) - (ecm[0][1] * ecm[1][0]); 

		a = ((ecm[0][2] * ecm[1][1]) - (ecm[0][1] * ecm[1][2])) / A + 0;
		b = ((ecm[0][0] * ecm[1][2]) - (ecm[0][2] * ecm[1][0])) / A + 0;

		x_p = (a / -2.0);
		y_p = (b / -2.0);
		r = sqrt(pow(x1 - x_p, 2) + pow(y1 - y_p, 2));

		printf("%.3f %.3f %.3f\n", x_p, y_p, r); //四捨五入は自動的にされる
	}
	return 0;
}

Measured memory_bytes: 656
#include<bits/stdc++.h>
#include<algorithm>
using namespace std; 
#define float double
const int  LMT =1000000000+5;
#define int long long 
#define lp(i,n) for( i=0;i<n;i++)
const int N=3001,M=100005;
int n,m,a[N],i,j,k=0;
int dp[N][N][2];bool vis[N][M];
int  solve(int i ,int j,int turn){
if(i>j)return 0;
if(dp[i][j][turn]!=-1)return dp[i][j][turn];
if(turn==1) return dp[i][j][turn]=max(a[i]+solve(i+1,j,0),a[j]+solve(i,j-1,0));
return dp[i][j][turn]=min(solve(i+1,j,1),solve(i,j-1,1));
}
int32_t main(){
  #ifndef ONLINE_JUDGE 
  freopen("input.txt", "r", stdin); 
  freopen("output.txt", "w", stdout); 
 #endif
 cin>>n;
 memset(dp,-1,sizeof(dp));
 lp(i,n)cin>>a[i],k+=a[i];
 
 cout<<2*solve(0,n-1,1)-k<<endl;
} 

Measured memory_bytes: 144568