akhauriyash/Code-Regression huggingface dataset:
H, W, K = map(int,input().split())
B = [list(map(int, input())) for _ in range(H)]

CHOCO = [[] for _ in range(1<<(H-1))]
cnt = [10**9] * (1<<(H-1))

for i in range(1<<(H-1)):
    S = 0
    ret = []
    flag = True
    for j in range(H - 1):
        S += B[j][0]
        if i & (1<<j):
            if S > K:
                flag = False
            ret.append(S)
            S = 0
    S += B[-1][0]
    if S > K:
        flag = False
    ret.append(S)
    if flag:
        CHOCO[i] = ret[:]
        cnt[i] = len(ret) - 1


for w in range(1,W):
    for i in range(1 << (H - 1)):
        if not CHOCO[i]: continue

        S = 0
        ret = []
        flag1 = True
        for j in range(H - 1):
            S += B[j][w]
            if i & (1 << j):
                if S > K:
                    flag1 = False
                ret.append(S)
                S = 0
        S += B[-1][w]
        ret.append(S)

        flag2 = True

        for j in range(len(ret)):
            if ret[j] + CHOCO[i][j] > K:
                flag2 = False

        if flag1:
            if flag2:
                for j in range(len(ret)):
                    CHOCO[i][j] += ret[j]
            else:
                CHOCO[i] = ret[:]
                cnt[i] += 1
        else:
            CHOCO[i] = []

print(min(cnt))

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long n; scan(n);
      printf("ABC%ld\n", n);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 256
n = int(input())
if n == 3:
    print(2,5,63)
elif n == 4:
    print(2,5,20,63)
else:
    l = set([2,4,3,9])
    x = n-4
    for i in range(1,min(5000,x//2)):
        l.add(6*i+2)
        l.add(6*i+4)
    
    if len(l) != n:
        x = n-len(l)
        if x > 4998:
            for j in range(x-4998):
                l.add(6*(j+1))
            x = 4998
        elif x%2:
            l.add(6)
            x -= 1
        for i in range(2,x+2):
            l.add(6*i+3)
    print(*l)
    

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;

int A[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, c, k;
	scanf("%d%d%d", &n, &c, &k);
	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);
	}

	sort(A, A+n);

	int res = 0;
	int ind = 0;
	while(ind < n)
	{
		int x = A[ind] + k;
		FOR (it, 0, c)
		{
			if (ind >= n) break;
			if (A[ind] <= x) ind++;
			else break;
		}

		res++;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define si(a) scanf("%d", &a)
#define fore(i,a,b) for(int i = a; i < b; ++i)
#define M 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
int n,k;
vi v;
vi dp;
char s[1005][1005];
void solve(){
	int n,m;
    si(n);si(m);
    fore(i,0,n)
        scanf("%s",s[i]);
    vector<ll> a(m+1),b(m+1);
    int sw = 1;
    a[0] = 1;
    fore(i,0,n){
        fore(j,0,m){
            if(sw){
                if(s[i][j] == '#')
                    a[j+1] = 0;
                else
                    a[j+1] = (a[j]+b[j+1])%M;
                //printf("%lld(%c) ", a[j+1],s[i][j]);
                a[0] = 0;
            }
            else{
                if(s[i][j] == '#')
                    b[j+1] = 0;
                else
                    b[j+1] = (b[j]+a[j+1])%M;
                //printf("%lld ", b[j+1]);
            }
        }
        //printf("\n");
        sw = (sw+1)%2;
    }
    if(n&1)
        printf("%lld\n", a[m]);
    else
        printf("%lld\n", b[m]);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    int n,k; cin >> n >> k;
    vector<int> v;
    for(int i = 0;i < n;i++){
        int x; cin >> x; v.push_back(x);
    }
    sort(v.begin(),v.end(),greater<int>());
    if(v.size() <= k){
        cout << 0;
    }else{
        ll ans = 0;
        for(int i = k;i < n;i++){
            ans += v[i];
        }
        cout << ans;
    }
    
}




Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define vinn(n,v) int n;cin>>n;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define vinm(n,m,v) int n,m;cin>>n>>m;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define debug(x) cerr<<#x<<" : "<<x<<endl;
int expo(int base,int x)
{
    int res = 1;    
    base = base % MOD; 
    while (x > 0)
    {
        if (x & 1)
            res = (res*base) % MOD;
        x= x>>1;
        base = (base*base) % MOD;  
    }
    return res;
}
signed main() 
{
	fastio();

	int n;
	cin>>n;
	vector<int>v(n,0);
	loop(i,0,n)cin>>v[i];
	sort(all(v));

	vector<int>co(n,1),cz(n,1);
	for(int i = n-1;i>=2;i--)
	{
		co[0] = (co[0]*i)%MOD;
		co[0]%=MOD;
	}
	for(int i = 1;i<n-1;i++)
	{
		co[i] = co[i-1] + (co[0]*(expo((i+1),MOD-2))%MOD)%MOD;
		// co[i] = co[i-1] + (co[0]/expo((i+1),MOD-2);
		co[i]%=MOD;
		co[i]+=MOD;
		co[i]%=MOD;
	}
	// loop(i,0,n-1)cout<<co[i]<<" ";nl;
	int ans = 0;
	for(int i = 0;i<n-1;i++)
	{
		ans+=(co[i]*(v[i+1]-v[i]))%MOD;
		ans%=MOD;
		ans+=MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;


	


	return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			int n=sc.nextInt();
			int d=10000;
			String[] ans=new String[5];
			String[] table={"* = ****", "* =* ***", "* =** **", "* =*** *",
					"* =**** ", " *= ****", " *=* ***", " *=** **", " *=*** *",
					" *=**** ",};
			for(int i=0; i<5; i++){
				int m=(n/d)%10;
				ans[i]=table[m];
				d/=10;
			}
			for(int j=0; j<8; j++){
				for(int i=0; i<5; i++){
					print(ans[i].charAt(j)+"");
				}
				println("");
			}
			if(sc.hasNext())
				println("");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
import heapq

N , M = map(int,input().split())
A = list(map(lambda x:-int(x),input().split()))

heapq.heapify(A)
for _ in range(M):
    largest = heapq.heappop(A)
    largest = -((-largest)//2)
    heapq.heappush(A, largest)

print(-sum(A))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
#define deb3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	
int gcd(int a, int b){ if(a==0) return b; return gcd(b%a, a);}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc=1;
	//ci(tc);
	while(tc--){
		string n;
		ci(n);
		ll sum=0;
		for(int i=0;i<n.size();i++){
			sum+=(n[i]-'0');
		}
		if(sum%9==0) co("Yes");
		else co("No");		
	}
	return 0;
}


Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		scn.nextLine();
		String s = scn.nextLine();
		System.out.println((N < 3200)?"red":s);
	}

}


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

// ************* All the directives ***********************
#define bk back()              // back function for vector
#define co cout <<             // std output
#define ci cin >>              // std input
#define ft front()             // front function for vector
#define gl getline             // string input
#define mp make_pair           // function to get a pair
#define pb push_back           // push_back function for vector
#define ss stringstream        // use string as a stream instead of std input/output
#define wt while(t--)          // while loop for t test-cases

// ************* All the typedefs *************************
typedef pair<int, string> pis     ;    // pair of integer-string
typedef pair<int, int> pii        ;    // pair of integer-integer
typedef map<string, int> msi      ;    // map of string-int
typedef map<int, string> mis      ;    // map of int-string
typedef multimap<int, string> mmis;    // multimap of int-string
typedef list<int> li              ;    // list of integers
typedef queue<int, li> qul        ;    // queue of integers
typedef queue<int> qu             ;    // queue of integers (with deque underlying)
typedef vector<int> vi            ;    // vector of integers
typedef vector<pii> vpii          ;    // vector of pairs(int-int)
typedef vi::iterator itvi         ;    // iterator to vector of integers
typedef msi::iterator itmsi       ;    // iterator to map of string-int
typedef vector<char> vc           ;    // vector of chars
typedef long long ll              ;    // long long
typedef vector<ll> vll            ;    // vector of long long
// ************** Insert code here ************************

int main(void){

    ll n;

    cin >> n;

    vll a(n+1, -1);
    vll b(n, -1);

    for (auto i=0; i<n+1 ; i++){
        cin >> a[i];
    }

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

    ll mons = 0;
    for (auto i = 0; i<n ; i++){
        if (b[i] >= a[i]){
            mons += a[i];
            b[i] -= a[i];
            a[i]  = 0;
        }
        if(b[i] < a[i]){
            mons += b[i];
            a[i] -= b[i];
            b[i] = 0;
        }
        if (b[i] >= a[i+1]){
            mons += a[i+1];
            b[i] -= a[i+1];
            a[i+1]  = 0;
        }
        if(b[i] < a[i+1]){
            mons += b[i];
            a[i+1] -= b[i];
            b[i] = 0;
        }
    }
    cout << mons;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
#include<cstdint>

// ==========================

using namespace std;

// ==========================
//ライブラリ

//aからbまでの合計
int total(int a,int b) {
	int ans = 0;
	for (int i = a; i <= b; i++) {
		ans += i;
	}
	return ans;
}

// ==========================
//マクロ
#define rep(i,n) for(int i=0;i<n;i++)

// ==========================
//本文
int main() {
	int n;
	cin >> n;
	bool ans = false;
	int c = 0;
	vector<int> d1(n);
	vector<int> d2(n);
	rep(i, n) {
		cin >> d1[i] >> d2[i];
	}
	rep(i, n) {
		if (d1[i] == d2[i]) {
			c += 1;
			if (c >= 3)ans = true;
		}
		else c = 0;
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
using namespace std;
long long h;
long long f(long long a)
{
	if(a==1)
	{
		return 1;
	}
	long long tmp=f(a>>1);
	return tmp*2+1;
}
int main()
{
	scanf("%lld",&h);
	printf("%lld",f(h));
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split();
        int[] list = new int[N];
        for(int i = 0; i < N; i++)
        {
            list[i] = int.Parse(input[i]);
        }
        Array.Sort(list);
        Console.WriteLine(list[N / 2] - list[N / 2 - 1]);
    }
}


Measured memory_bytes: 18912
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
     String[] nyu=sc.nextLine().split(" ");

//     String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu);


//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);


if(A-B>=0){
//double res=Math.ceil((AB)/2);

System.out.println(A-B);
//}else if((int)c[0]>(int)c[2]){
//System.out.println(">");

}else{
System.out.println("0");

}




	}
}

Measured memory_bytes: 20692
def bomb(x,y):
    global M
    s=M[y]
    R=[-3,-2,-1,1,2,3]
    if s[x]=="0":return
    M[y]=s[:x]+"0"+s[x+1:]
    for d in R:
        bomb(x+d,y)
        bomb(x,y+d)
    return

A=range(14)
B=range(3,11)
M=["00000000000000" for i in A]
z="000"
n=input()
for i in range(n):
    s=raw_input()
    for j in B:
        M[j]=z+raw_input()+z
    x=input()+2
    y=input()+2
    bomb(x,y)
    print "Data %d:" %(i+1)
    for j in B:
        print M[j][3:-3]

Measured memory_bytes: 4288
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int ans = min(n * a, b);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[105];
	int i,j,n,f=1;
	gets(a);
	n=strlen(a)-1;
	for(i=0;i<=n;i++){
	  if(f==1&&a[i]=='C')
	    f=2;
	  if(f==2&&a[i]=='F'){
	  	cout<<"Yes";return 0;
	  }
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

SUM = sum(As)
ans = 0
for i, a in enumerate(As, 1):
    ans += a*(SUM-a)
    ans %= mod
print(ans*pow(2, mod-2, mod)%mod)

Measured memory_bytes: 94116
class Train:
    def __init__(self, left, right):
        self.left = left
        self.right = right


class Question:
    def __init__(self, p, q):
        self.p = p
        self.q = q


N, M, Q = map(int, input().split())
trains = []
questions = []
for _ in range(M):
    left, right = map(int, input().split())
    trains.append(Train(left, right))
for _ in range(Q):
    p, q = map(int, input().split())
    questions.append(Question(p, q))

m = {}
cm = {}
for i in range(N+1):
    for j in range(N+1):
        m.setdefault(i, {})
        m[i][j] = 0
        cm.setdefault(i, {})
        cm[i][j] = 0

for train in trains:
    m[train.left][train.right] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        cm[i][j] = m[i][j] + cm[i][j-1]

for i in range(1, N+1):
    for j in range(1, N+1):
        cm[i][j] += cm[i-1][j]
for question in questions:
    print(cm[question.q][question.q] + cm[question.p-1][question.p-1] -
          cm[question.p-1][question.q]-cm[question.q][question.p-1])


Measured memory_bytes: 101244
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int N;
vector<int> G[200000];
bool visited[200000];

const int BOUND = 100000;

/*
頂点Xi とYiをもつ二部グラフを考える
点(x, y)　が存在するとき、XxとYyの間に辺を張ると

辺a-b a-d c-b c-dのうちちょうど3辺が存在するようなとき、
もう一つを追加するという操作を何回行えるか

異なる連結成分間では辺が結ばれないことが分かり、
また連結成分では二部グラフの両側に必ず辺が結ばれる
*/

void _dfs(int* x, int* y, int i) {
    visited[i] = true;
    for (int k = 0; k < G[i].size(); k++) {
        int next = G[i][k];
        if (!visited[next]) {
            if (next <= BOUND - 1) {
                (*x)++;
                _dfs(x,y,next);
            } else {
                (*y)++;
                _dfs(x,y,next);
            }
        }
    }
}

ll dfs(int i) {
    int x=0,y=0;
    if (i <= BOUND-1) x++;
    else y++;
    _dfs(&x,&y,i);
    return (ll) x * y;
}

//連結成分内の二部グラフ組み合わせ数を返す
ll solve() {
    ll res = 0;
    for (int i = 0; i < 2 * BOUND; i++) {
        if (!visited[i]) {
            res += dfs(i);
        }
    }
    return res;
}

int main() {
    cin >> N; 
    int x,y;
    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        G[x-1].push_back(y - 1 + BOUND);
        G[y-1+BOUND].push_back(x - 1);
    }
    ll res = solve();
    //既にある辺は除いて考える
    cout << res - (ll) N << "\n";
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10, mod = 1e9+7;
int n,x[N];

inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}

int main(){
	n=read();
	For(i,1,n) x[i]=read();
	int ans=0,s=0;
	For(i,2,n){
		s=(s+power(i-1,mod-2))%mod;
		ans=(ans+1ll*s*(x[i]-x[i-1]))%mod;
	}
	FOR(i,1,n) ans=1ll*ans*i%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
int main(){
  long A,B,ans = 1;
  cin>>A>>B;
  while(1){
    if(B>=2*A){
      ans++;
      A = 2*A;
    }
    else{
      break;
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#define SIZE 1002
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

typedef pair<int, int> P;
typedef long long ll;

// グローバル変数
ll n;
ll ret;

int main(void) {

// 入力

	cin >> n;
	vector<vector<int>> a(n, vector<int>(n - 1));
	rep(i, n)
	{
		rep(j, n - 1)
		{
			cin >> a[i][j];
			a[i][j]--;
		}
		reverse(a[i].begin(), a[i].end());
	}
	
// 処理

	bool playedFlag[1002];
	rep(i, 1000)
	{
		playedFlag[i] = false;
	}
	vector<int> q;
	rep(i, n)
	{
		q.push_back(i);
	}
	int day = 0;
	while (1) {
		day++;
		vector<int> prevQ;
		q.swap(prevQ);
		for(int i : prevQ)
		{
			// 本日未対戦 
			if (!playedFlag[i])
			{
				int j = a[i].back();
				// 順番通りに対戦を行える場合
				if (a[j].back() == i && !playedFlag[j])
				{
					a[i].pop_back();
					a[j].pop_back();
					// 次の日のチェックの必要性あり
					q.push_back(i);
					q.push_back(j);
					// 本日対戦済み
					playedFlag[i] = playedFlag[j] = true;
				}
			}
		}
		bool breakFlag = true;
		for (int i : q)
		{
			if (!a[i].empty())
			{
				playedFlag[i] = false;
				breakFlag = false;
			}
		}
		if (breakFlag)
		{
			break;
		}
	}

// 出力

	rep(i, n)
	{
		if (a[i].size() != 0)
		{
			cout << -1;
			return 0;
		}
	}
	cout << day;
	return 0;
}

Measured memory_bytes: 4224
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""


s = input()
t = input()
ans = len(t)

for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        if (t[j] != s[i+j]): cnt+=1
    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 9120
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){
  long long int N;
  scanf("%lld", &N);

  std::cout << (N+1)/2 << std::endl;
  return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long N;
    std::cin >> N;
    VV<int> g(N);
    for (int i = 0; i < N - 1; i++) {
        int x, y;
        std::cin >> x;
        std::cin >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    VV<int> du(2);
    auto dfs = [&](auto self, int i, int p, int c) -> void {  // p: parent
        du[c].push_back(i);
        for (auto a : g[i]) {
            if (a == p) continue;
            self(self, a, i, 1 - c);
        }
    };
    dfs(dfs, 0, -1, 0);

    if (du[0].size() > du[1].size()) swap(du[0], du[1]);
    int l = du[0].size();
    int r = du[1].size();

    V<int> ans(N);

    // 3つに分割する
    int one = (N + 2) / 3;
    int two = (N + 1) / 3;
    int thr = N / 3;

    if (l <= thr) {
        // 多い方にone, twoを割り振る．
        rep(i, one) ans[du[1][i]] = 1;
        rep(i, two) ans[du[1][i + one]] = 2;
    } else {
        // 両者にone，twoを割り振る．
        rep(i, one) ans[du[0][i]] = 1;
        rep(i, two) ans[du[1][i]] = 2;
    }
    int num[] = {3, 1, 2};
    for (int i : ans) {
        cout << num[i] << " ";
        num[i] += 3;
    }
    cout << endl;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    bool flg = false;

    for(int c = 0; c <= N / 4; ++c){

        for(int d = 0; d <= N / 7; ++ d){

            if(c * 4 + d * 7 == N) flg = true;
        }
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, W; cin >> N >> W;
    vl w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];
    
    vvl dp(N+1, vl(101000, LINF));
    dp[0][0] = 0;
    REP(i, N){
        REP(vv, 101000){
            if(vv - v[i] >= 0){
                dp[i+1][vv] = min(dp[i+1][vv], dp[i][vv-v[i]] + w[i]);
            }
            dp[i+1][vv] = min(dp[i+1][vv], dp[i][vv]);
        }
    }
    ll ans = 0;
    for (ll vv = 100000; vv >= 0; vv--) {
        if(dp[N][vv] <= W){
            ans = vv; break;
        }
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 81024
use itertools::Itertools;
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        n: usize,
        m: usize,
        q: usize,
        qs: [(Usize1, Usize1, usize, usize); q],
    }

    let iter = (1..=m).combinations_with_replacement(n);
    let mut result = 0;

    for v in iter {
        let mut score = 0;
        for e in qs.iter() {
            if v[e.1] - v[e.0] == e.2 {
                score += e.3;
            }
        }
        if score > result {
            result = score;
        }
    }

    echo!(result);
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100003;
ll n,k;
ll go(ll n,ll k)
{
    if(k == 0)
        return 0;
    if(n == 0)
        return 1;
    ll g = modexp(2LL,n + 2) - 3;
    if(k == g)
        return modexp(2LL,n + 1) - 1;
    g /= 2;
    ll res;
    if(k <= g)
        res = go(n - 1,k - 1);
    else
        res = go(n - 1,g - 1) + 1 + go(n - 1,k - g - 1);
    return res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k;
    cout<<go(n,k);
    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, K;
int a[100010];
int ret;
vi g[100010];

int dfs(int v)
{
    int t = 0;

    for (int to : g[v]) {
	int u = dfs(to);
	if (u == K - (v != 0)) {
	    ++ret;
	} else t = max(t, u + 1);
    }

    return t;
}

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

    rep(i, N) {
	cin >> a[i];
	--a[i];

	if (i == 0 && a[0] != 0) {
	    ret = 1;
	    a[0] = 0;
	}

	if (i > 0) {
	    g[a[i]].pb(i);
	}
    }

    dfs(0);
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] += 0x20;
    PRINT(s);
}


Measured memory_bytes: 256
N = int(input())

c = ['a' for _ in range(N)]
def f(i, k):
    if i == N:
        print(''.join(c))
        return
    for j in range(k + 1):
        c[i] = chr(ord('a') + j)
        f(i + 1, max(j + 1, k))

f(0, 0)



Measured memory_bytes: 4412
#include <iostream>
using namespace std;
int main(void){
    int floor [4][3][10]={{{}}},n,b,f,r,v;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        floor [b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
    for(int k=0;k<10;k++){
        cout<<" "<<floor[i][j][k];
    }
    cout<<endl;
    }
    if(i!=3)
    cout<<"####################"<<endl;
    }  
}


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

using namespace std;

int solve(vector<array<int, 3>> vmed, int a, int b, int offset,
          vector<vector<vector<int>>> &memo) {
  if (offset == vmed.size()) {
    return a == 0 && b == 0 ? 0 : -1;
  }

  if (a < 0 || b < 0) {
    return -1;
  }

  if (memo[a][b][offset] == -2) {
    auto &med = vmed[offset];
    int ans1 = solve(vmed, a, b, offset + 1, memo);
    int ans2 = solve(vmed, a - med[0], b - med[1], offset + 1, memo);
    if (ans2 >= 0) {
      ans2 += med[2];
    }

    if (ans1 >= 0 && ans2 >= 0) {
      memo[a][b][offset] = min(ans1, ans2);
    } else {
      memo[a][b][offset] = ans1 < 0 ? ans2 : ans1;
    }
  }

  return memo[a][b][offset];
}

int main(int argc, const char *argv[]) {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<array<int, 3>> vmed(n);
  for (auto &med : vmed) {
    cin >> med[0] >> med[1] >> med[2];
  }

  vector<vector<vector<int>>> memo(
      500, vector<vector<int>>(500, vector<int>(n + 1, -2)));

  int ans = -1;
  for (int i = 1; i <= 400 && max(ma, mb) * i <= 400; ++i) {
    int res = solve(vmed, ma * i, mb * i, 0, memo);
    if (res != -1 && (ans < 0 || res < ans)) {
      ans = res;
    }
  }

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

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

int main(){
    int N;
    cin>>N;
    int a[100];
    for(int i=0;i<N;i++) cin>>a[i];
    
    sort(a,a+N,greater<int>());
    int Alice=0;
    int Bob=0;
    for(int i=0;i<N;i++){
        if(i%2==0){
            Alice+=a[i];
        }
        else{
            Bob+=a[i];
        }
    }
    cout<<Alice-Bob<<endl;
    
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 10005;

int n;
string s[maxn],t;

bool mustSmall(string& s,string&t) {
  for(int i=0;i<min(s.size(),t.size());i++){
    if(s[i]=='?'){
      if(t[i]!='z')return false;
    }else{
      if(s[i]<t[i])return true;
      if(s[i]>t[i])return false;
    }
  }
  return s.size()<t.size();
}
bool mustLarge(string&s,string&t) {
  for(int i=0;i<min(s.size(),t.size());i++){
    if(s[i]=='?'){
      if(t[i]!='a')return false;
    }else {
      if(s[i]>t[i])return true;
      if(s[i]<t[i])return false;
    }
  }
  return s.size()>t.size();
}

int main() {
  //freopen("in.cpp","r",stdin);
  cin>>n;
  for(int i=0; i<n; i++)cin>>s[i];
  cin>>t;
  int l=0,r=0;
  for(int i=0; i<n; i++) {
    l+=mustSmall(s[i],t);
    r+=mustLarge(s[i],t);
  }
 // cout<<l<<" "<<r<<endl;
  for(int i=l+1;i<=n+1-r;i++)printf("%d%c",i,i==n+1-r?'\n':' ');
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    bool isPrime[100005];
    memset(isPrime, true, sizeof(isPrime));
    for(int p=2; p*p < 100005; p++){
        if(isPrime[p]){
            for(int j=p*p; j<=100005; j += p)
                isPrime[j] = false;
        }
    }
    int n;
    cin>>n;
    for(int i=n; i<=100005; i++){
        if(isPrime[i]){
            cout<<i;
            return 0;
        }
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
char s[maxn];
stack<char> ss;
int main() {
	scanf("%s", s);
	int n = strlen(s);
	ss.push(s[0]);
	int ans = 0;
	for(int i = 1; i < n; i++) {
		if(!ss.empty() && ss.top() != s[i]) {
			ss.pop();
			ans++;
		} else {
			ss.push(s[i]);
		}
	}
	cout << ans * 2 << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <ctype.h>
	
int main()
{
	int i, alp;
	int count['z'-'a'+1] = {0};
	char str[1200];
	
	for(i=0; i<1200; i++)
	{
		str[i] = getchar();
		if(str[i]==EOF) { break; }
	}
	
	for(i=0; str[i]!=EOF; i++)
	{
		str[i] = tolower(str[i]);
		
		for(alp='a'; alp<='z'; alp++)
		{
			if(str[i] == alp)
			{
				count[alp-'a']++;
			}
		}
		
	}
	
	for(i=0; i<='z'-'a'; i++)
	{
		printf("%c : %d\n",'a'+i,count[i]);
	}
	
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vector<double> v(n);
  rep(i,n){
    cin >> v[i];
  }
  sort(all(v));
  rep(i, n - 1){
    v[i + 1] = (v[i + 1] + v[i]) / (double)2;
  }
  cout<< fixed << setprecision(10) << v[n - 1] << endl;
}

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

const int MOD=1e9+7;

void addmod(int& x,int y){
  x=(x+y)%MOD;
}

int as[21][21];

int dp[1<<21];
int pop[1<<21];
std::vector<int> rpop[22];

int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<(1<<N);i++){
    pop[i]=pop[i>>1]+(i&1);
    rpop[pop[i]].push_back(i);
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      scanf("%d",&as[i][j]);
    }
  }
  dp[0]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(as[i][j]){
	for(int mask:rpop[i]){
	  //printf("dp[%d]=%d\n",mask,dp[mask]);
	  if(mask&(1<<j)) continue;
	  addmod(dp[mask|(1<<j)],dp[mask]);
	}
      }
    }
  }
  printf("%d\n",dp[(1<<N)-1]);
  return 0;
}


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

using namespace std;

int main(){
    int h,n;
    cin >> h >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int sum = 0;
    rep(i,n) sum += a[i];
    cout << (sum >= h ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
li = list(map(int,input().split()))
sum = 0
ans = []
for i in li:
    sum += i

x1_a = 0
count = 1
for i in li:
    if(count % 2 == 0):
        x1_a += i
    count += 1
x1 = sum - 2 * x1_a
ans.append(x1)

for i in range(1,n):
    ans.append(2*li[i-1]-ans[i-1])
print(" ".join([str(n) for n in ans]))

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

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

    int ans=0;
    int m=0;

    for(int i=0;i<5;i++)
    {
        int a;
        cin>>a;

        ans+=(a-a%10)+min(10,(a%10)*10);
        m=max(m,10-((a-1)%10+1));
    }

    ans-=m;

    cout<<ans<<"\n";

    return 0;
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  string s=(a+b+c<22)?"win":"bust";
  cout<<s<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)

//非再帰fft
void fft(ll*f,int n,ll g){
	ll p=7*(1<<26)+1;
	ll*x=f,*y=(ll*)malloc(n*sizeof(ll)),*temp;
	for(int t=1;n>>t;t++){
		ll s=1;
		ll gg=pom(g,n>>t,p);
		rep(k,0,1<<(t-1)){
			rep(j,0,n>>t){
				y[(j<<t)+k           ]= (x[(j<<(t-1))+k]+s*x[(j<<(t-1))+n/2+k])%p;
				y[(j<<t)+k+(1<<(t-1))]=((x[(j<<(t-1))+k]-s*x[(j<<(t-1))+n/2+k])%p+p)%p;
			}
			s=s*gg%p;
		}
		temp=x;x=y;y=temp;
	}
	if(x!=f){
		rep(i,0,n)f[i]=x[i];
		free(x);
	}else{
		free(y);
	}
}

ll*comb(ll*a,int n,ll*b,int m){
	//0詰め
	ll p=7*(1<<26)+1;
	int t=1;
	while(n+m-1>t)t*=2;
	if(t>(1<<26)){puts("error");exit(0);}
	ll*c=(ll*)calloc(t,sizeof(ll));
	memcpy(c,a,n*sizeof(ll));
	ll*d=(ll*)calloc(t,sizeof(ll));
	memcpy(d,b,m*sizeof(ll));
	//fft
	fft(c,t,pom(3,(p-1)/t,p));
	fft(d,t,pom(3,(p-1)/t,p));
	//掛け算
	rep(i,0,t)c[i]=c[i]*d[i]%p;
	free(d);
	//復元
	fft(c,t,pom(3,(p-1)-(p-1)/t,p));
	ll coef=invp(t,p);
	rep(i,0,t)c[i]=(c[i]*coef)%p;
	return c;
}

char s[200010],t[200010];
ll snum[200010],tnum[200010];
ll ans[400010];
int main(){
	scanf("%s %s",s,t);
    int sm=(s[0]=='-'),tm=(t[0]=='-');
    int sn=strlen(s+sm),tn=strlen(t+tm);
	for(int i=0;i<sn;i++)snum[i]=s[sn+sm-1-i]-'0';
	for(int i=0;i<tn;i++)tnum[i]+=t[tn+tm-1-i]-'0';
	ll*p=comb(snum,sn,tnum,tn);
	for(int i=0;i<sn+tn-1;i++)ans[i]=p[i];
	for(int i=0;i<400010;i++)ans[i+1]+=ans[i]/10,ans[i]%=10;
	int digit=0;
	for(int i=0;i<400010;i++)if(ans[i])digit=i;
	if((sm^tm)&&(digit>0||ans[0]!=0))printf("-");
	for(int i=digit;i>=0;i--)printf("%lld",ans[i]);
	puts("");
}


Measured memory_bytes: 17264
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------





void _main() {
	int N, A, B;
	cin >> N >> A >> B;
	if (A > B) {
		int max = B;
		int min = A + B - N;
		if (min < 0) {
			min = 0;
		}
		cout << max << " " << min << endl;
	}
	else {
		int max = A;
		int min = A + B - N;
		if (min < 0) {
			min = 0;
		}
		cout << max << " " <<min << endl;
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
using namespace std;

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

  int r = a % b;
  while(true){
    if(r == c){
      cout << "YES" << endl;
      break;
    }
    r += a % b;
    r = r % b;
    if(r == a % b){
      cout << "NO" << endl;
      break;
    }  
  }
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
B = [int(i) for i in input().split()]
A = [list(map(int, input().split())) for i in range(n)]

count = 0
for low in range(n):
    Sum = c
    for col in range(m):
        Sum += A[low][col]*B[col]

    if Sum > 0:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
int main()
{
  int n, m;
  cin >> n >> m;
  vecint s(m), c(m);
  REP(i,m)cin >> s[i] >> c[i];
  bool ok = true;
  int l = (n == 1)?0:pow(10,n - 1);
  for(int i = l; i <= pow(10, n) - 1; i++){
    string tmp = to_string(i);
    ok = true;
    REP(j,m){
      if((int)(tmp[s[j] - 1] - '0') != c[j]){
	ok = false;
	break;
      }
    }
    if(ok){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
# あなたは、電車とバスを乗り継いで旅行をする計画を立てました。
# 電車は旅程に沿って通常のきっぷを買うと A 円かかり、乗り放題きっぷを買うと B 円かかります。
# バスは旅程に沿って通常のきっぷを買うと C 円かかり、乗り放題きっぷを買うと D 円かかります。
# 電車およびバスについて通常の切符を買うか乗り放題きっぷを買うかをうまく選んだときの、
# 運賃の合計の最小値を求めてください。

a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i

train = a < b ? a : b
bus = c < d ? c : d

puts train + bus

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>

#define pb(s) push_back(s)

#define MAX_N 30
#define MAX_M 1000
#define MAX_V 30

using namespace std;

struct edge{
	int to, len, limit;
	edge(int a, int b, int c):to(a),len(b),limit(c){}
};
vector<edge> G[MAX_M+1];//n?????????????????\?¶??????????????????????

struct state{
	int from, now, v;
	double times;
	state(int a, int b, int c, double d):from(a),now(b),v(c),times(d){}
};

double times[MAX_N+1][MAX_N+1][MAX_V+1];

int N, M, S, g;
int inf = 1<<29;

bool operator<(const state& a, const state& b){ return a.times > b.times; }

double solve() {
	for (int i = 0; i <= MAX_N; i++)for(int j = 0; j <= MAX_N; j++)for(int k = 0; k <= MAX_V; k++){
		times[i][j][k] = (double)inf;
	}
	priority_queue<state> que;
	que.push(state(0,S,0,0.0));

	while(!que.empty()){
		state ns = que.top(); que.pop();
		if(ns.now == g && ns.v == 1) return ns.times;
		if(times[ns.from][ns.now][ns.v] != inf) continue;
		times[ns.from][ns.now][ns.v] = ns.times;
		for (int i = 0; i < G[ns.now].size(); i++)
		{
			edge e = G[ns.now][i];
			if(ns.from != e.to){
				for (int dv = -1; dv <= 1 ; dv++)
				{
					if(ns.v+dv > e.limit) break;
					if(ns.v+dv < 1) continue;
					que.push(state(ns.now, e.to, ns.v+dv, times[ns.from][ns.now][ns.v]+(double)e.len/(ns.v+dv)));
				}
			}
		}
	}
	return -1;
}

int main(){
	while(1){
		cin >> N >> M;
		if(N == 0)break;
		cin >> S >> g;
		for (int i = 0; i < MAX_M+1; i++)
		{
			G[i].clear();
		}
		for(int i = 0; i < M; i++){
			int x, y, d, c;
			cin >> x >> y >> d >> c;
			edge e = edge(y, d, c);
			G[x].pb(e);
			e = edge(x, d, c);
			G[y].pb(e);
		}
		double res = solve();
		if(res == -1) cout << "unreachable" << endl;
		else printf("%f\n", res);
	}
	return 0;
}

Measured memory_bytes: 22356
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100005
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
//int cmp(const void* a,const void* b){return *(int*)a-*(int*)b;}

typedef struct{int A,B;}P;

int cmp(const void *x,const void *y){
  return ((P*)x)->B-((P*)y)->B;
}

int main() {
  int N,i,ans=0;
  LL n=0;
  scanf("%d",&N);
  P p[N];
  FOR(i,0,N)scanf("%d%d",&p[i].A,&p[i].B);
  qsort(p,N,sizeof(P),cmp);
  FOR(i,0,N){
    n+=p[i].A;
    if(p[i].B<n)ans=1;
  }
  if(ans==1)printf("No");
  else printf("Yes");

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


Measured memory_bytes: 3324
#include<stdio.h>
int main() {
	int i=1;
	int x;
	while (1) {
		scanf("%d", &x);
		if (x == 0) {
			break;
		}
		printf("Case %d: %d\n", i, x);
		i = i + 1;
	}
		return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=300005,INF=1<<30;

struct point{
    double pos;
    int id;
    int dir;
    
    bool operator<(const point &another) const
    {
        return pos<another.pos;
    };
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,L;cin>>N>>L;
        if(N+L==0) break;
        
        vector<point> S(N);
        
        for(int i=0;i<N;i++){
            char a;cin>>a;
            if(a=='L') S[i].dir=0;
            else S[i].dir=1;
            
            cin>>S[i].pos;
            S[i].id=i;
        }
        
        for(int t=1;;t++){
            for(int i=0;i<N;i++){
                if(S[i].dir==0) S[i].pos-=0.5;
                else S[i].pos+=0.5;
            }
            
            sort(all(S));
            
            for(int i=0;i<N-1;i++){
                if(S[i].pos==S[i+1].pos){
                    if(int(S[i].pos*2)%2==0){
                        swap(S[i].id,S[i+1].id);
                    }
                }
            }
            
            int cnt=0;
            
            for(int i=0;i<N;i++){
                if(S[i].pos<=0.0||S[i].pos>=L) cnt++;
            }
            
            if(cnt==N){
                int ans=-1;
                for(int i=N-1;i>=0;i--){
                    if(S[i].pos==0.0) ans=S[i].id;
                    if(S[i].pos==L) ans=S[i].id;
                }
                
                cout<<t/2<<" "<<ans+1<<endl;
                break;
            }
        }
    }
}




Measured memory_bytes: 3112