akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Numerics;

    class Program
    {
        static int dfs(string s, BigInteger N)
        {
            if (BigInteger.Parse(s) > N) return 0;
            var ret = 1;
            if (!(s.Contains('7') && s.Contains('5') && s.Contains('3'))) ret = 0;
            foreach (var c in "753")
            {
                ret += dfs(s + c, N);
            }
            return ret;
        }

        static void Main(string[] args)
        {
            var N = BigInteger.Parse(Console.ReadLine());
            Console.WriteLine(dfs("0", N));
        }
    }

Measured memory_bytes: 17468
# ABC134D - Preparing Boxes
def main():
    N, *A = map(int, open(0).read().split())
    A = [0] + A
    for i in range(N // 2, 0, -1):  # second half: no multiples
        A[i] = sum(A[i::i]) % 2
    ans = [i for i, j in enumerate(A) if j]
    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0;i < N; i++) {
     cin >> A[i];
  }
  sort(A.begin(), A.end());
 
  cout << abs(A.back() - A.front()) << endl;
  
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
const int Maxn=200005;
int x[Maxn],y[Maxn],n,pos[Maxn];
int par[Maxn],siz[Maxn];
int findset(int x){
	return par[x]=(par[x]==x)?x:findset(par[x]);
}
void Union(int x,int y){
	x=findset(x);y=findset(y);
	if (x==y) return;
	par[x]=y;
	siz[y]+=siz[x];
}
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		x[i]=read();y[i]=read();siz[i]=1;
		pos[x[i]]=i;
		par[i]=i;
	}
	vector<pair<int,pair<int,int> > > V;
	for (int i=1;i<=n;i++){
		int p=pos[i];
		int lo=y[p],hi=y[p],id=p;
		while (!V.empty() && V.back().second.first<hi){
			pair<int,pair<int,int> > tmp=V.back();
			V.pop_back();
			lo=min(lo,tmp.second.first);
			hi=max(hi,tmp.second.second);
			Union(tmp.first,id);
			id=findset(id);
		}
		V.pb(mp(id,mp(lo,hi)));
	}
	for (int i=1;i<=n;i++){
		printf("%d\n",siz[findset(i)]);
	}
	return 0;
}

Measured memory_bytes: 12028
n = int(input())
dic = {}
for i in range(1, n+1):
    n, p = input().split()
    if n not in dic.keys(): dic[n] = []
    dic[n].append([int(p), i])
keys = sorted(list(dic.keys()))
for key in keys:
    city = dic[key]
    city = sorted(city, key=lambda x: x[0], reverse=True)
    for city_i in city:
        print(city_i[1])

Measured memory_bytes: 3064
from collections import Counter

N = int(input())
S = input()
counter = Counter(S)
ans = counter['R'] * counter['G'] * counter['B']
for l in range(1, N):
    for i in range(N):
        if i + 2*l >= N: break
        a, b, c = S[i], S[i + l], S[i + 2*l]
        if a != b and a != c and b != c: ans -= 1
print(ans)

Measured memory_bytes: 9464
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>

using namespace std;

#define PI 3.14159265358979323846
#define INF 1e+9
#define DIV_NUM (1000000007)



int main() {

	string S, T;
	cin >> S >> T;
	int A, B;
	cin >> A >> B;
	string U;
	cin >> U;
	if (U == S) A--;
	if (U == T) B--;


	long long int N = 1000* 1000 * 1000 * 1000;
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		ans += 1;
	}

	ans *= 0;

	A = A - ans;

	cout << A << " " << B << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<string>
using namespace std;
long long int seiza[201][2],point[1001][2],n,m,dx,dy;
int main(){
    for(;;){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>seiza[i][0]>>seiza[i][1];
        }
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>point[i][0]>>point[i][1];
        }
        for(int i=0;i<m;i++){
            int j;
            dx=point[i][0]-seiza[0][0];
            dy=point[i][1]-seiza[0][1];
            for(j=1;j<n;j++){
                int x=seiza[j][0]+dx;
                int y=seiza[j][1]+dy;
                int k;
                for(k=0;k<m;k++){
                    if(point[k][0]==x&&point[k][1]==y)break;
                }
                if(k==m)break;
            }
            if(j==n){
                cout<<dx<<" "<<dy<<endl;
                break;
            }
        }
    }
return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <iomanip>

int main() {
	int L;
	std::cin >> L;
	double N = L;
	double res = (L % 3) / 3;
	std::cout << std::fixed << std::setprecision(12) << (N + res) * (N + res) * (N + res) / 27;
return 0;
}

Measured memory_bytes: 256
//░░░
// ░ anzim bin nasir
// ░
#include<stdio.h>
#include<math.h>
int main()
{
    int n;
    scanf("%d",&n);
    n=n%10;
    if(n==2||n==4||n==5||n==7||n==9)
    printf("hon\n");
    else if(n==0||n==1||n==6||n==8)
    printf("pon\n");
    else
    printf("bon\n");
    return 0;
}


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

int main(void){
    int a[5],time=0,log=9;
    vector<int> b;
    for(int i=0;i<5;i++){
        cin>>a[i];
        if(a[i]%10<log&&a[i]%10!=0){
            log=a[i]%10;
        }
    }
    int cnt=0;

    for(int i=0;i<5;i++){
        if(a[i]%10==0){
            time+=a[i];}
        else if(a[i]%10!=log){
            time+=a[i]/10*10+10;
        }else if(a[i]%10==log){
            cnt++;
            b.push_back(a[i]);
        }
    }
    if(cnt>0){
        for(int i=0;i<b.size()-1;i++){
            time+=b[i]/10*10+10;
        }
        cout<<time+b[b.size()-1]<<endl;
    }
    else
        cout<<time<<endl;

    return 0;
}


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

int count = 0;

void merge(std::vector<int> &a, int left, int mid, int right) {

  const int sentinel = 1000000000;

  int n1 = mid - left;
  int n2 = right - mid;

  std::vector<int> l(n1+1);
  std::vector<int> r(n2+1);

  for (int i = 0; i < n1; i++) {
    l[i] = a[left+i];
  }
  for (int i = 0; i < n2; i++) {
    r[i] = a[mid+i];
  }
  l[n1] = r[n2] = sentinel;

  int i = 0, j = 0;

  for (int k = left; k < right; k++) {
    count++;
    if (l[i] < r[j]) {
      a[k] = l[i];
      i++;
    } else {
      a[k] = r[j];
      j++;
    }
  }
}

void mergeSort(std::vector<int> &a, int left, int right) {
  if (left+1 < right) {
    int mid = (left + right) / 2;

    mergeSort(a, left, mid);
    mergeSort(a, mid, right);
    merge(a, left, mid, right);
  }
}

int main() {

  int n;
  std::cin >> n;

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

  mergeSort(a, 0, n);

  for (int i = 0; i < n; i++) {
    if (i) {
      std::cout << " ";
    }
    std::cout << a[i];
  }
  std::cout << std::endl;
  std::cout << count << std::endl;

  return 0;

}



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

int main() {
  int x,y;
  cin >> x >> y;
  int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if( a[x] == a[y] ) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int i,diff;
	char str[1200];
	for(i=0;i<1200;i++){
		scanf("%c",&str[i]);
		if(str[i]=='\n')break;
	}
	
	diff='a'-'A';
	
	for(i=0;i<1200;i++){
		if(str[i]>=65 && str[i]<=90)str[i]+=diff;
		else if(str[i]>=97 && str[i]<=122)str[i]-=diff;
		else if(str[i]=='\n')break;
	}
	
	for(i=0;i<1200; i++){
		printf("%c",str[i]);
		if(str[i]=='\n')break;
	}
	return 0;

}

Measured memory_bytes: 524
using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var stdin = Console.OpenStandardInput();
        var ss = new StreamScanner(stdin);
        var p = new Program();
        p.solve(ss);
        stdin.Close();
    }

    private void solve(StreamScanner ss)
    {
        var x = ss.Int;
        var n = ss.Int;
        var p = Enumerable.AsEnumerable(ss.IntArray(n));
        var seq = Enumerable.Range(0, 102).Except(p);
        var ans = 0;

        foreach (var i in seq)
        {
            if (Math.Abs(x - i) < Math.Abs(x - ans))
            {
                ans = i;
            }
        }
        Console.WriteLine(ans);
    }

    private int calcLegs(int tsuru, int kame) => 2 * tsuru + 4 * kame;


    class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char
        {
            get
            {
                byte b = 0;
                do b = read();
                while (b < 33 || 126 < b);
                return (char)b;
            }
        }

        public string Scan
        {
            get
            {
                var sb = new StringBuilder();
                for (var b = Char; b >= 33 && b <= 126; b = (char)read())
                    sb.Append(b);
                return sb.ToString();
            }
        }

        public long Long
        {
            get
            {
                long ret = 0; byte b = 0; var ng = false;
                do b = read();
                while (b != '-' && (b < '0' || '9' < b));
                if (b == '-') { ng = true; b = read(); }
                for (; true; b = read())
                {
                    if (b < '0' || '9' < b)
                        return ng ? -ret : ret;
                    else ret = ret * 10 + b - '0';
                }
            }
        }

        public int Int => (int)Long;

        public int[] IntArray(int n)
        {
            var arr = new int[n];
            for (var i = 0; i < n; ++i)
            {
                arr[i] = Int;
            }
            return arr;
        }

        public double Double => double.Parse(Scan, CultureInfo.InvariantCulture);
    }
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}
int no=1,n1;
int recu(int n,int k,int val){


	if(n==n1){
		return min(val*2,val+k);
	}
	return min( recu(n+1,k,2*val),recu(n+1,k,val+k)              );


}
int digit(int n){

	int temp=0;
	while(n){
		temp+=n%10;
		n=n/10;
		// temp++;
	}



	return temp;
}
int main() {
    int i,m,n,k,c=0,sum=0;
    c_p_c();
    // cout<<"Sd"<<endl;>
  	cin>>n;
 	int di = digit(n);
 	if(n%di==0)
 		cout<<"Yes"<<endl;
 	else
 		cout<<"No"<<endl;

   }

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

void line(char pt) {
  rep(i, 50) {
    cout << pt;
  }
}

void pv(int &target, char p1, char p2) {
  rep(j, 49) {
    if((j & 1) && target != 1) {
      cout << p2;
      target--;
    } else {
      cout << p1;
    }
  }
  cout << p1;
}

int main(){
  int in(w, b);
  char p1 = '#';
  char p2 = '.';
  out(99, 100);

  rep(i, 49) {
    line(p1);
    line(p2);
    out();

    pv(w, p1, p2);
    pv(b, p2, p1);
    out();
  }
  line(p1);
  line(p2);
  out();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

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

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

int main() {
    string s;
    vector<pair<string,int>> v;
    string ma="";
    for(int i=0;cin>>s;i++){
        if(ma.length()<s.length())ma=s;
        
        if(i==0)v.pb(mp(s,1));
        else {
            bool f=true;
            rep(j,0,v.size()){
                if(v[j].fi==s){
                    f=false;
                    v[j].se++;
                    break;
                }
            }
            if(f)v.pb(mp(s,1));
        }
    }
    
    string ans;
    int temp=0;
    rep(i,0,v.size()){
        if(temp<v[i].se){
            ans=v[i].fi;
            temp=v[i].se;
        }
    }
    cout<<ans<<" "<<ma<<endl;
    
  
    return 0;
}



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

int main(void){
	int s[31] = {1, 1, 2};
	int n;
	
	for(int i = 3; i <= 30; i++){
		s[i] = s[i-1] + s[i-2] + s[i-3];
	}

	while(true){
		cin >> n;
		if(!n) break;
		cout << (s[n] / 365 / 10) + 1 << endl;
	}

  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abc = scanner.nextLine().split(" ", 3);
        int a = Integer.parseInt(abc[0]);
        int b = Integer.parseInt(abc[1]);
        int c = Integer.parseInt(abc[2]);
        if (a == b) {
            System.out.println(c);
        } else if (a == c) {
            System.out.println(b);
        } else {
            System.out.println(a);
        }
    }
}


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

#define rep(i,s,e) for(int i = (s);i <= (e);i++)

typedef long long i64;

i64 n;
vector<i64> a;

int main()
{
	cin >> n;
	a.resize(n,0);
	rep(i,0,n - 1) cin >> a[i];
	i64 sum = 0;
	rep(i,0,n - 1) sum += a[i];

	if(sum % ( n * (n + 1) / 2) != 0)
	{
		cout << "NO" << endl;
		return 0;
	}

	i64 cou = sum / ( n * (n + 1) / 2);

	rep(i,0,n - 1)
	{
		i64 next = (i + 1) % n;
		i64 dif = a[next] - (a[i] + cou);
		if(dif > 0 || dif % n != 0)
		{
			cout << "NO" << endl;
			return 0;
		}
	}

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


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

int main()
{
	int N,K,res;
	int a[110];
	cin >> N>>K;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	sort(a, a + N, greater<int>());
	
	for (int i = 0; i < K; i ++ )
	{
		res += a[i];
	}
	
	cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class AOJ1
{
    public static void Main()
    {
        while (true)
        {
            string Input = Console.ReadLine();
            if (Input == null) break;
            string[] str = new string[3];
            int i = 0, j=0;
            while (Input[i] != '+') str[0] += Input[i++];
            ++i; // '+' 
            while (Input[i] != '=') str[1] += Input[i++];
            ++i; // '='
            while (i < Input.Length) str[2] += Input[i++];
            int ans = 0;
            string[] STR = new string[3];
            for (; ans <= 9; ans++)
            {
                STR[0] = STR[1] = STR[2] = "";
                for (j = 0; j < 3; j++)
                {
                    for (i = 0; i < str[j].Length; i++)
                    {
                        if (str[j][i] == 'X') STR[j] += (char)('0' + ans);
                        else STR[j] += str[j][i];
                    }
                }
                if ((STR[0].Length >= 2 && STR[0][0] == '0')
                    || (STR[1][0] == '0' && STR[1].Length >= 2)
                    || (STR[2][0] == '0' && STR[2].Length >= 2)) continue;
                bool flag = false; // 繰り上げ
                string TMP = "";
                for (i = STR[0].Length-1, j = STR[1].Length-1; i >= 0 || j >= 0; i--, j--)
                {
                    char ch = '0', CH = '0';
                    if (i>=0) ch = STR[0][i];
                    if (j>=0) CH = STR[1][j];
                    int sum = (ch - '0') + (CH - '0');
                    if (flag) { sum++; flag = false; }
                    if (sum >= 10) { flag = true; sum -= 10; }
                    TMP += (char)('0' + sum);
                }
                if (flag) TMP += '1';
                string rTMP = "";
                for (i = TMP.Length - 1; i >= 0; i--) rTMP += TMP[i];
                if (rTMP == STR[2]) break;
            }
            if (ans > 9) Console.WriteLine("NA");
            else Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 5788
import copy
n, m = map(int, input().split())
s = list(input())
s.reverse()
ans = []
cur_index = 0
while cur_index < n:
    pre = copy.deepcopy(cur_index)
    for i in range(min(m, n - cur_index), 0, -1):
        if s[cur_index + i] == '0':
            cur_index += i
            ans.append(i)
            break
    if pre == cur_index:
        print(-1)
        exit()
ans.reverse()
for i in ans:
    print("{} ".format(i), end = "")

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

int n;
long long x1, x2, ans=1;

long long gcd(long long a, long long b){
	while(a!=0){
		if(b>a){
			long long temp = a;
			a = b;
			b = temp;
		}
		a %= b;
	}
	return b;
}

int main(void){
	cin >> n >> x1 >> x2;
	ans = abs(x2-x1);
	x1 = x2;
	for(int i=1; i<n; i++){
		cin >> x2;
		ans = gcd(abs(x2-x1), ans);
		x1 = x2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

struct Node { int p, s, l, r; };

Node *u;

int dfs(int id, int height) {
	if (id == -1) return height;
	return max(dfs(u[id].l, height+1), dfs(u[id].r, height+1));
}

int main() {
	int n;
	cin >> n;
	u = new Node[n];
	for (int i = 0; i < n; i++)
		u[i].p = u[i].s = u[i].l = u[i].r = -1;
	for (int i = 0; i < n; i++) {
		int id, l, r;
		cin >> id >> l >> r;
		u[id].l = l;
		u[id].r = r;
		if (l != -1) {
			u[l].p = id;
			u[l].s = r;
		}
		if (r != -1) {
			u[r].p = id;
			u[r].s = l;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << "node " << i;
		cout << ": parent = " << u[i].p;
		cout << ", sibling = " << u[i].s;
		int degree = 0;
		if (u[i].l != -1) degree++;
		if (u[i].r != -1) degree++;
		cout << ", degree = " << degree;
		int depth = 0;
		for (int id = i; u[id].p != -1; depth++)
			id = u[id].p;
		cout << ", depth = " << depth;
		cout << ", height = " << max(dfs(u[i].l, 0), dfs(u[i].r, 0));
		if (u[i].p == -1)
			cout << ", root";
		else if (u[i].l == -1 && u[i].r == -1)
			cout << ", leaf";
		else
			cout << ", internal node";
		cout << endl;
	}

	delete[] u;
	return 0;
}

Measured memory_bytes: 1200
islands, requests = map(int, input().split(" "))
req = []
for r in range(requests):
    a, b = map(int, input().split(" "))
    req.append([a, b])
req = sorted(req, key = lambda x:x[1])
answer = 1
temp_end = req[0][1]
for r in req:
    if r[0] >= temp_end:
        temp_end = r[1]
        answer += 1
print(answer)

Measured memory_bytes: 22104
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            print("Bad")
            quit()
    print("Good")
    return

#B
def B():
    n,l = LI()
    a = [i+l for i in range(n)]
    ans = sum(a)
    m = n+l-1
    for i in a[::-1]:
        if i < 0:break
        m = min(m,i)
    ans -= m
    print(ans)
    return

#C
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
def C():
    a,b,c,d = LI()
    g = gcd(c,d)
    l = c*d//g
    sc = b//c-(a-1)//c
    sd = b//d-(a-1)//d
    sl = b//l-(a-1)//l
    print(b-a+1-sc-sd+sl)
    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > v[100010];
int bit[100010],n,m;

void add(int x,int k){
	while(x<=m+1){
		bit[x]+=k;
		x+=x&-x;
	}
}
int sum(int x){
	int s=0;
	while(x){
		s+=bit[x];
		x-=x&-x;
	}
	return s;
}
int main(){
	cin>>n>>m;
	memset(bit,0,m+1);
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		v[b-a+1].push_back(make_pair(a,b));
	}
	for(int k=1;k<=m;k++){
		for(int i=0;i<v[k-1].size();i++){
			add(v[k-1][i].first,1);
			add(v[k-1][i].second+1,-1);
			n--;
		}
		int cnt=n;
		for(int i=k;i<=m;i+=k){
			cnt+=sum(i);
		}
		cout<<cnt<<endl;
	}
	return 0;
}


Measured memory_bytes: 7936
//PDF解説に倣ってDP
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,m;
  cin>> n >> m;
  vector<bool> oks(n+1,true);
  int broken;
  for (int i=0; i<m; i++){
    cin>> broken;
    oks.at(broken)=false;
  }
  
  int mod=1000000007;
  vector<int> dp(n+1);
  dp.at(0)=1;
  for (int i=0; i<n; i++){
    for (int j=i+1; j<=min(n,i+2); j++){
      if (oks.at(j)){
        dp.at(j)+=dp.at(i);
        dp.at(j)%=mod;
      }
    }
  }
  cout<< dp.at(n) <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int cnt = 0;
  while(A>=B){
    B*=2;
    cnt++;
  }
  while(B>=C){
    C*=2;
    cnt++;
  }
  if(cnt>K){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

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

    constexpr ll T = 1LL << 20, X = 1 + T + T * T;

    ll r = 0;
    for (int k = 0; k < 20; k++) {
        ll c = 0;
        for (int i = 0; i < n; i++) {
            c += a[i] >> k & X;
        }
        for (int h = 0; h < 3; h++) {
            ll t = c & T - 1;
            c /= T;
            r += (1LL << (20 * h + k)) % P * t % P * (n - t) % P;
        }
    }
    r %= P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    sc.close();

    System.out.println(lcm(A, B));
  }

  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
  }

  private static long gcd(long m, long n) {
    if (m < n) return gcd(n, m);
    if (n == 0) return m;
    return gcd(n, m % n);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long> x;
    long long tmp;
    for(int i = 0;i<n;i++){
        cin >> tmp;
        x.push_back(tmp);
    }
    long l;
    cin >> l;
    x.push_back(1e12);
    int db[20][n+1];
    int db2[20][n+1];
    for(int i = 0;i<n;i++){
        db[0][i]=(--upper_bound(x.begin(),x.end(),x[i]+l)-x.begin());
        //cout << db[0][i] << endl;
    }
    db[0][n]=n;
    db[0][n-1]=n;
    for(int i = 0;i<19;i++){
        //cout << "db2[" << i << "][i]:::" << " ";
        //for(int j = 0;j<=n+1;j++) cout << db2[i][j] << " ";
        for(int j = 0;j<=n;j++){
            db[i+1][j]=db[i][db[i][j]];
        }
        //cout << endl;
    }
    int q;
    cin >> q;
    long a,b;
    long ans[q];
    fill_n(ans,q,0);
    for(int i = 0;i<q;i++){
        cin >> a >> b;
        a--;b--;
        if(a>b) swap(a,b);
        int cnt = 19;
        while(a!=b&&cnt>=0){
            if(db[cnt][a]<=b){
                ans[i]+=pow(2,cnt);
                a = db[cnt][a];
            }
            cnt--;
        }
        if(a!=b) ans[i]++;        
    }
    for(int i = 0;i<q;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 10356
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using pii=pair<int, int>;

#define int long long

signed main(void) {
	vector<int> pow2 = { 1 };
	rep(i, 0, 61) {
		pow2.push_back(pow2.back() * 2);
	}
	for (int n, I, J; cin >> n >> I >> J && n;) {
		I--, J--;
		string AB = "";
		for(int i = n - 1; i >= 0; i--){
			int AI = pow2[i] - 1 - I;
			int BI = I - pow2[i];
			if (AI >= 0) {
				AB.push_back('A');
				I = AI;
			}
			else {
				AB.push_back('B');
				I = BI;
			}
		}
		reverse(AB.begin(), AB.end());
		//cout << AB << endl;
		string LR = "";
		rep(i, 0, n) {
			if (J < pow2[n - i - 1]) {
				if(AB[i] == 'A'){
					LR.push_back('L');
					J = pow2[n - i - 1] - J - 1;
				}
				else {
					LR.push_back('R');
				}
			}
			else {
				if (AB[i] == 'A') {
					LR.push_back('R');
					J = pow2[n - i] - J - 1;
				}
				else {
					LR.push_back('L');
					J = J - pow2[n - i - 1];
				}
			}
		}
		cout << LR << endl;
	}
}


Measured memory_bytes: 3156
#include <iostream>
using namespace std;
int main(void){
    int n,r=0;
    long long b[200002],c[200002],m=0;
    cin>>n;
    b[0]=c[0]=0;
    for(int i=1;i<=n;i++){
        long long a;
        cin>>a;
        b[i]=a+b[i-1];
        c[i]=a^c[i-1];
    }
    for(int i=0;i<n;i++){
        r=max(i+1,r);
        while(r<n&&(c[r+1]^c[i])==b[r+1]-b[i]){
            r++;
        }
        m+=(long long)r-i;
    }
    cout<<m<<endl;
}


Measured memory_bytes: 3328
import bisect
import collections
s = input()
t = input()

table = collections.defaultdict(list)
table2 = collections.defaultdict(int)
last = t[-1]
last_id = []
for i, x in enumerate(s):
    table[x].append(i)

for i, x in enumerate(t):
    if x not in table:
        print(-1)
        exit(0)

tmp = 0
id = 0
ans = 0
for x in t:
    l = len(table[x])
    i = bisect.bisect_left(table[x], id)
    if l == i:
        id = 0
        ans += len(s)
        i = bisect.bisect_left(table[x], id)
    id = table[x][i]+1

ans += id


print(ans)


Measured memory_bytes: 8052
// Problem : D - No Need
// Contest : AtCoder - AtCoder Beginner Contest 056
// URL : https://atcoder.jp/contests/abc056/tasks/arc070_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}
int n,k;
vi v;
int arr[5001];
int dp[5001][5001];
int fun(int i,int sum)
{
	if(i==n) return sum>=k;
	if(sum>=k) return Pow(2,n-i);
	if(dp[i][sum]!=-1) return dp[i][sum];
	int x=fun(i+1,sum);
	int y=fun(i+1,v[i]+sum);
	if(x!=y)
	arr[i]=1;
	return dp[i][sum]=x+y;
}
void solve()
{
cin>>n>>k;
incd(v,n);
inin(dp);
cin>>v;
int x=fun(0,0);
int ans=0;
for(int i=0;i<n;i++)
{
	if(!arr[i])
	ans++;//,cout<<i<<" ";
}
//cout<<"\n";
cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


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

long long int N, a, b;
vector<long long int> edge[100101], c, d;

int main(){
    scanf("%lld", &N);
    for(int i = 1; i < N; ++i){
        scanf("%lld%lld", &a, &b);
        edge[a - 1].push_back(b - 1);
        edge[b - 1].push_back(a - 1);
    }
    b = -1;
    for(int i = 0; i < N; ++i){
        a = 0;
        if(edge[i].size() < 2)continue;
        for(auto j : edge[i]){
            if(edge[j].size() > 1)++a;
        }
        if(a > 2)return 0 & puts("-1");
        if(a == 1)b = i;
    }
    if(b == -1){
        cout << "1 ";
        for(int i = 2; i < N - 1; ++i){
            cout << i + 1 << " ";
        }
        cout << "2 " << N << " ";
        return 0;
    }
    stack<pair<long long int, long long int>> stc;
    stc.push({b, -1});
    c.push_back(0);
    d.push_back(0);
    c.push_back(edge[b].size() - 2);
    d.push_back(edge[b].size() - 2);
    while(!stc.empty()){
        auto i = stc.top();
        stc.pop();
        //cout << i.first << " " << i.second << endl;
        for(auto j : edge[i.first]){
            if(j != i.second && edge[j].size() > 1){
                c.push_back(edge[j].size() - 2);
                d.push_back(edge[j].size() - 2);
                stc.push({j, i.first});
            }
        }
    }
    c.push_back(0);
    d.push_back(0);
    reverse(d.begin(), d.end());
    if(c > d)swap(c, d);
    int i = 0;
    for(auto j : c){
        ++i;
        for(int k = 1; k <= j; ++k){
            cout << i + k << " ";
        }
        cout << i << " ";
        i += j;
    }
    return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m,x;
	cin >> n >> m >> x;
	int nn=max(n,m);
	
	int res=(x+nn-1)/nn;
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m,*ab = map(int,read().split())

UF = UnionFind(n)

it = iter(ab)
for i,j in zip(it,it):
    UF.merge(i-1,j-1)

from collections import Counter
d = Counter(UF.root(i) for i in range(n))
print(max(d.values()))







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


int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<string>  s(h);
  rep(i, h) cin >> s[i];

  int ans = 0;
  rep(is, 1<<h) rep(js, 1<<w) {
    int cnt = 0;
    rep(i, h)rep(j, w) {
      if (is>>i&1) continue;
      if (js>>j&1) continue;
      if (s[i][j] == '#') cnt++;
    }
    if (cnt == k) ans++;
  }

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


Measured memory_bytes: 3584
import sys

input = sys.stdin.readline


def main():
    R, G, B, N = map(int, input().split())

    dp = [0] * (N + 1)
    dp[0] = 1
    for c in [R, G, B]:
        for i in range(N - c + 1):
            dp[i + c] += dp[i]

    ans = dp[N]
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
	vector<int> a(3), b(2);
	for (int& i : a) cin >> i;
	for (int& i : b) cin >> i;
	cout << *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end()) - 50 << endl;
}


Measured memory_bytes: 3048
#include "bits/stdc++.h"
using namespace std;
int main(){
	long long n;
	cin>>n;
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	long long ans=0;
	for(long long i=1;i<=sqrt(n);i++){
		if(n%i==0&&n%((n-i)/i)!=0&&i<(n-i)/i){
			ans+=(n-i)/i;
			//printf("%lld * %lld + %lld = %lld ,sum is %lld\n",i,(n-i)/i,i,n,ans);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){

    string n;
    cin >> n;

    int c=0;
    rep(i,3){
        if(n[i]==n[i+1]) c++;
        else c=0;
        if(c==2){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n;

int main() {
	cin >> n;
	REP(i, 100)REP(j, 100) {
		if (i * 4 + j * 7 == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A = [format(a,'b').zfill(40) for a in A]
C = [0]*40
for i in range(40):
    cc = 0
    for a in A:
        keta = 39 - i
        if a[keta] == "1":
            cc += 1
    C[keta] = cc
ans = 0
for i in range(40):
    b = 39 - i
    if C[i] < N - C[i]:#0の方が個数が多い→1を採用したいとき
        if K < 2**b:
            ans += (2**b * C[i])
        else:
            ans += (2**b * (N-C[i]))
            K -= 2**b
    else:
        ans += (2**b * C[i])
print(ans)

Measured memory_bytes: 17820
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    public IDictionary<string, int> Items { get { return items; } }
    public IDictionary<string, IEnumerable<string>> Recipes { get { return recipes; } }

    Dictionary<string, int> items = new Dictionary<string, int>();
    Dictionary<string, IEnumerable<string>> recipes = new Dictionary<string, IEnumerable<string>>();

    static void Main() {
        for (string line; (line = Console.ReadLine()) != "0";) {
            var calc = new Program();

            var n = int.Parse(line);
            for (var i = 0; i < n; i++) {
                var l = Console.ReadLine().Split(' ');
                calc.Items.Add(l[0], int.Parse(l[1]));
            }

            n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++) {
                var l = Console.ReadLine().Split(' ');
                var name = l[0];
                var materials = l.Skip(2);
                calc.Recipes.Add(name, materials);
            }

            var item = Console.ReadLine();
            Console.WriteLine(calc.Calculate(item));
        }
    }

    public int Calculate(string item) {
        IEnumerable<string> materials;
        if (recipes.TryGetValue(item, out materials)) {
            var totalCost = 0;

            foreach (var material in materials) {
                var cost = Calculate(material);
                totalCost += cost;
            }

            return Math.Min(items[item], totalCost);
        }

        return items[item];
    }
}

Measured memory_bytes: 9744
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object Main extends App {


  //val a = List.empty[Int]
  val a = ArrayBuffer.empty[Int]

  // 2,147,483,647
  def pushBuck(x: Int) = a.append(x)

  def popBuck() = if(a.nonEmpty) a.remove(a.size - 1)

  def randomAccess(i: Int): Int = a(i)

  val q = StdIn.readLine().trim.toInt
  (0 until q).foreach { i =>
    val input = StdIn.readLine()
    val temp = if (input.startsWith("2")) Array(2, 0) else input.split(' ').map(_.toInt)
    val (cmd, x): (Int, Int) = (temp(0), temp(1))

    cmd match {
      case 0 =>
        pushBuck(x)
      case 1 => println(randomAccess(x))
      case 2 =>
        popBuck()
    }
  }
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    while (count <= 1e5) {
        if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) break;
        int aa = a / 2, bb = b / 2, cc = c / 2;
        a = bb + cc;
        b = aa + cc;
        c = aa + bb;
        count++;
    }
    cout << (count > 1e5 ? -1 : count);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
#define PI 3.141592653589

int main(){
    int n, x;
    cin >>n;
    int a[100];
    for(int i=0;i<n;i++){
        cin >>x;
        a[i]=x;
    }
    for(int i=n-1;0<=i;i--){
        cout <<a[i];
        if(i!=0)cout <<" ";
    }
    cout <<endl;
    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }
int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;
    const int sz = s.size();
    set<string> v;
    for (int i = 0; i < sz; i++) {
        for (int j = 1; j <= k; j++) {
            v.insert(s.substr(i, j));
        }
    }
    auto it = v.begin();
    for (int i = 0; i < k - 1; i++, it++) {
    }
    cout << *it << endl;

    return 0;
}


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



int main()
{
    int a,b,ans = 0;
    cin >> a >> b;
    for(int i = a; i <= b; i++){
        int r = 0,ii = i;
        while(ii){
            r = r * 10 + ii % 10;
            ii /= 10;
        }
        if(i == r) ans++;
    }

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

Measured memory_bytes: 256
possible_appearances = ->(dice) {
  table = 
     [[0, 1, 2, 3, 4, 5], [3, 1, 0, 5, 4, 2], [1, 5, 2, 3, 0, 4], [5, 1, 3, 2, 4, 0],
      [1, 2, 0, 5, 3, 4], [3, 5, 1, 4, 0, 2], [5, 4, 2, 3, 1, 0], [2, 1, 5, 0, 4, 3],
      [1, 0, 3, 2, 5, 4], [5, 2, 1, 4, 3, 0], [2, 4, 0, 5, 1, 3], [4, 5, 3, 2, 0, 1],
      [3, 4, 5, 0, 1, 2], [4, 0, 2, 3, 5, 1], [1, 3, 5, 0, 2, 4], [2, 0, 1, 4, 5, 3],
      [0, 4, 3, 2, 1, 5], [4, 2, 5, 0, 3, 1], [4, 3, 0, 5, 2, 1], [2, 5, 4, 1, 0, 3],
      [3, 0, 4, 1, 5, 2], [0, 3, 1, 4, 2, 5], [0, 2, 4, 1, 3, 5], [5, 3, 4, 1, 2, 0]]
  result = []
  table.each do |dice1|
    another = Array.new(6, 0)
    dice1.each_with_index {|n, i| another[n] = dice[i]}
    result << another
  end
  result.uniq
}

n = gets.to_i
dices = []
n.times {dices << gets.split.map(&:to_i)}
result = "Yes"
dices.combination(2) do |dice1, dice2|
  if possible_appearances.(dice1).include?(dice2)
    result = "No"
    break
  end
end
puts result



Measured memory_bytes: 9312
#include<stdio.h>

int main(void){
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '+'){
			printf("%d\n",a+b);
		}else if(op == '-'){
			printf("%d\n",a-b);
		}else if(op == '*'){
			printf("%d\n",a*b);
		}else if(op == '/'){
			printf("%d\n",a/b);
		}else if(op == '?'){
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1032
n = int(input())
s = input()
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = ''
# for i in range(len(alp)):
#     print(alp[i])
for i in range(len(s)):
    k = alp.index(s[i])
    # print(k, n, k + n - 26)
    ans += alp[k + n - 26]
# print(alp[-1])
print(ans)

Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if(Math.abs(x-a) > Math.abs(x-b)) System.out.println("B");
        else System.out.println("A");
    }
}

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

using namespace std;

int main(){
	int n,minv=1000001,sum=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int p=1;p<=100;p++){
		sum=0;
		for(int i=1;i<=n;i++){
			sum+=(a[i]-p)*(a[i]-p);
		}
		if(sum<minv)minv=sum;
	}
	cout<<minv;
	return 0;
}

Measured memory_bytes: 256