akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

ll dp[51][51][2510];
int main(){
    
    rep(i,51){
        rep(j,51){
            rep(k,2510){
                dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;

    int n,a;
    cin >> n >> a;
    vector<int> x(n);
    rep(i,n) cin >> x[i];

    rep(i,n+1){
        rep(j,i+1){
            rep(k,n * x[n-1]+1){
                if(i >= 1 && k < x[i-1]){
                    dp[i][j][k] = dp[i-1][j][k];
                }else if(i >= 1 && j >= 1 && k >= x[i-1]){
                    dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
                }else if(i == 0 && j == 0 && k == 0){
                    dp[i][j][k] = 1;
                }else{
                    dp[i][j][k] = 0;
                }
            }
        }
    }

    ll ans = 0;
    reps(i,1,n+1){
        ans += dp[n][i][i*a];
        //cout << i <<" " << dp[n][i][i*a] << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 54632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    
    ll ans=a[0]-1;
    ll now=2;
    
    FOR(i,1,n-1){
        if(a[i]==now) now++;
        ans+=(a[i]-1)/now;
    }
    cout<<ans<<endl;
}

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

void solve(long long N, long long K, long long C, std::string S)
{
    vector<ll> workDayL(K);
    for (ll i = 0, work = 0; i < N && work < K; i++) {
        if (S[i] == 'o') {
            workDayL[work] = i;
            work++;
            i += C;
        }
    }
    vector<ll> workDayR(K);
    for (ll i = 0, work = 0; i < N && work < K; i++) {
        if (S[N - i - 1] == 'o') {
            workDayR[K - work - 1] = N - i - 1;
            work++;
            i += C;
        }
    }

    bool exist = false;
    for (ll i = 0; i < K; i++) {
        if (workDayL[i] == workDayR[i]) {
            cout << workDayL[i] + 1 << "\n";
            exist = true;
        }
    }
    if (not exist) {
        cout << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long C;
    scanf("%lld",&C);
    std::string S;
    std::cin >> S;
    solve(N, K, C, S);
    return 0;
}


Measured memory_bytes: 6664
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#############
# Main Code #
#############

s = str(input())

if s == "hi" or s == "hihi" or s == "hihihi" or s == "hihihihi" or s == "hihihihihi":
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;
const int INF = 1000000000;

int main(){
	int n;
	cin >> n;
	ll d,a;
	cin >> d >> a;

	vector<pair<ll,ll>> xh;
	for(int i = 0;i < n;i++){
		ll x,h;
		cin >> x >> h;
		xh.push_back(make_pair(x,h));
	}

	sort(xh.begin(),xh.end());

	ll ans = 0;
	ll now_cnt = 0;
	queue<pair<ll,ll>> g;
	for(int i = 0;i < n;i++){
		ll x = xh[i].first;
		ll h = xh[i].second;
		while(g.size() && g.front().first < x){
			now_cnt -= g.front().second;
			g.pop();
		}
		h -= now_cnt * a;
		if(h > 0){
			g.push(make_pair(x+2*d,(h+a-1)/a));
			now_cnt += (h+a-1)/a;
			ans += (h+a-1) / a;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 6000
import sys, math, heapq
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()


# nomal
# L = [[0 for _ in range(W)] for _ in range(H)]
# R = [[0 for _ in range(W)] for _ in range(H)]
# U = [[0 for _ in range(W)] for _ in range(H)]
# D = [[0 for _ in range(W)] for _ in range(H)]
res = [[0 for _ in range(W)] for _ in range(H)]
grid = []

# numpy
import numpy as np
L, R, U, D = [np.zeros((H, W), int) for _ in range(4)]
grid_np = np.zeros((H,W), int)


for i in range(H):
    row = list(" ".join(input()).split())
    grid.append(row)
    grid_np[i] = np.array(row) == '.'

def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)

            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

def solve_np():
    ans = 0

    for j in range(W):
        # 本当は意味ない条件分岐
        if j == 0:
            L[:, j] = 1 * grid_np[:, j]
            R[:, -j - 1] = 1 * grid_np[:, -j - 1]
        else:
            L[:, j] = (L[:, j - 1] + 1) * grid_np[:, j]
            R[:, -j - 1] = (R[:, -j] + 1) * grid_np[:, -j - 1]

    for i in range(H):
        if i == 0:
            U[i] = 1 * grid_np[i]
            D[-i -1] = 1 * grid_np[-i -1]
        else:
            U[i] = (U[i - 1] + 1) * grid_np[i]
            D[-i - 1] = (D[-i] + 1) * grid_np[-i - 1]
    ans = np.max((L+R+U+D) -3)
    return ans

if __name__ == "__main__":
    # print(solve())
    print(solve_np())

# if __name__ == "__main__":
#     import timeit
#     loop = 1
#     n = 1000
#     time = timeit.timeit(lambda: solve(), number=loop)
#     print(time/loop)



Measured memory_bytes: 298804
#include<iostream>
using namespace std;
#define MAX 1000

main(){
  int T[MAX+1], S[MAX+1];
  int N, M;
  while(1){
    cin >> N >> M;
    if ( N == 0 && M == 0 ) break;

    for ( int i = 1; i <= N; i++ ) cin >> T[i];
    for ( int i = 1; i <= M; i++ ) cin >> S[i];

    int i = 1;

    bool goal = false;
    int cur = 1;

    while(1){
      cur += S[i];
      if ( cur >= N ) { goal = true; break; }
      cur += T[cur];
      if ( cur >= N ) { goal = true; break; }
      i++;
    }
    cout << i << endl;

  }
  
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, x, N) for (int i = x; i < (N); i++)
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<long> A(N), x(N);
    rep(i, 0, N)
    {
        cin >> A[i];
    }
    long sum = 0;
    rep(i, 0, N)
    {
        sum += A[i];
    }
    long a = 0;
    for (int i = 1; i < N; i += 2)
    {
        a += 2 * A[i];
        //    i += 2;
    }
    x[0] = sum - a;
    rep(i, 0, N - 1)
    {
        x[i + 1] = 2 * A[i] - x[i];
    }
    rep(i, 0, N)
    {
        cout << x[i] << endl;
    }
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;


int main(){
    int x, y;
    cin >> x >> y;
    int ch = y - 2 * x;
    if(ch < 0){
        cout << "No" << endl;
    } else {
        if(ch % 2 == 0){
            if(x - ch / 2 < 0){
                cout << "No" << endl;
            } else {
                cout << "Yes" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 3632
def resolve():
    n=int(input())
    s=[]
    total=0
    for i in range(n):
        tmp=int(input())
        total+=tmp
        s.append(tmp)
    if total%10!=0:
        print(total)
    else:
        s.sort()
        for i in range(n):
            if s[i]%10==0:
                if i == n - 1:
                    print(0)
                else:
                    continue
            else:
                total-=s[i]
                print(total)
                break


resolve()

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <queue>
#include <utility>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int k, t;
    cin >> k >> t;
    priority_queue<pair<int, int>> q;
    repi(i, t, 0)
    {
        int a;
        cin >> a;
        q.push({a, i});
    }
    int ans = 0, prev = -1;
    pair<int, int> tmp(0, -1);
    bool state = false;
    while (!state)
    {
        pair<int, int> cake = q.top();
        q.pop();
        if (cake.first > 0)
        {
            q.push(tmp);
            tmp = cake;
            tmp.first--;
        }
        if (cake.first == 0)
        {
            state = true;
        }
        else
        {
            ans++;
        }
    }
    cout << max(0, k - ans) << endl;
    return 0;
}

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

bool mas[11][11][4];
string s = "LURD";
const int dy[] = { 0, -1, 0, 1}, dx[] = { -1, 0, 1, 0};

void dfs( int y, int x, int pos){
  cout << s[pos];
  if(!y && !x){
    cout << endl;
    return;
  }
  for(int i = 0 ; i < 4 ; i++ ){
    int dd = ( pos + 3 + i ) % 4;
    int ny = y + dy[ dd], nx = x + dx[ dd];
    if(mas[y][x][dd]){
      dfs( y + dy[ dd], x + dx[ dd], dd);
      return;
    }
  }
}
int main(){
  char c;
  for(int i = 0 ; i < 9 ; i++ ){
    if(i & 1)
      for(int j = 0 ; j < 5 ; j++ ){
        cin >> c;
        if(c == '1') mas[i / 2][j][3] = mas[i / 2 + 1][j][1] = true;
      }
    else
      for(int j = 0 ; j < 4 ; j++ ){
        cin >> c;
        if(c == '1') mas[i / 2][j][2] = mas[i / 2][j + 1][0] = true;
      }
  }
  dfs( 0, 1, 2);
}

Measured memory_bytes: 1180
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();
		long K = sc.nextLong();
		long A = N%K;
		long ans = 0;
		if( N<K ){
			long a = K-N;
			ans = Math.min( a,N );
		}
		if( N%K==0 ){
			ans = 0;
		}
		if( !(N<K) && !(N%K==0) ){
			long a = A;
			long b = K-A;
			if( a<b ){
				ans = a;
			}else{
				ans = b;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int count =0;
    rep(i,n) {
        if(p[i] != i+1) count++;
    }
    if(count == 2 || count == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
N, x = map(int, raw_input().split())
candies = map(int, raw_input().split())
counter = 0
for i  in range(0, len(candies)-1):
    delta = candies[i+1] + candies[i] - x
    if delta > 0:
        counter += delta
        candies[i+1] = x - candies[i]
        if candies[i+1] < 0:
            candies[i+1] = 0
print counter

Measured memory_bytes: 11340
N = int(input())
A = list(map(int, input().split()))

A = sorted(A)

if A[0] == 0:
    print("0")
else:
    ans = 1
    for item in A:
        ans = ans*item
        if ans > 10**18:
            print("-1")
            exit()

    print(ans)





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

int main()
{
    int output_num[255];
    int output_id = 0;

    while(1) {
        int a, b;
        char op;
        cin >> a >> op >> b;

        if(op == '+') {
            output_num[output_id] = a+b;
            output_id++;
        } else if(op == '-') {
            output_num[output_id] = a-b;
            output_id++;
        } else if(op == '*') {
            output_num[output_id] = a*b;
            output_id++;
        } else if(op == '/') {
            output_num[output_id] = a/b;
            output_id++;
        } else {
            break;
        }
    }

    for(int oi = 0; oi < output_id; oi++) cout << output_num[oi] << endl;

    return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		while(true){
			int w = in.nextInt();
			int h = in.nextInt();
			if(w+h==0)break;
			new AOJ1166().doIt(w,h);
		}
	}

	class AOJ1166{
		int w,h;
		void doIt(int w,int h){
			this.w = w;this.h = h;
			boolean yoko[][] = new boolean[h][w-1];
			boolean tate[][] = new boolean[h-1][w];
			for(int i=0;i<h*2-1;i++){
				if(i%2==0){
					for(int s=0;s<w-1;s++){
						int a = in.nextInt();
						if(a==1)yoko[i/2][s] = false;
						else yoko[i/2][s] = true;
					}
				}else{
					for(int s=0;s<w;s++){
						int a = in.nextInt();
						if(a==1)tate[i/2][s] = false;
						else tate[i/2][s] = true;
					}
				}
			}
//			for(int i=0;i<h;i++){
//				for(int s=0;s<w-1;s++)System.out.print(yoko[i][s]+" ");
//				System.out.println();
//			}
//			for(int i=0;i<h-1;i++){
//				for(int s=0;s<w;s++)System.out.print(tate[i][s]+" ");
//				System.out.println();
//			}
			int sx[] = {1,0,-1,0};
			int sy[] = {0,1,0,-1};
			LinkedList<State> q = new LinkedList<State>();
			int max = Integer.MAX_VALUE/2;
			int[][] map = new int[h][w];
			for(int i=0;i<h;i++)Arrays.fill(map[i], max);
			q.add(new State(0, 0, 1));
			int result = 0;
			while(q.size()>0){
				State now = q.remove();
				int x = now.x,y = now.y;
				if(map[y][x]<=now.step)continue;
				map[y][x] = now.step;
				if(now.x == w-1&&now.y == h-1){
					result = now.step;
					break;
				}
				for(int i=0;i<4;i++){
					int nx = sx[i]+x, ny = sy[i]+y;
					if(nx<0||nx>=w||ny<0||ny>=h)continue;
					if(i==0){//右
						if(yoko[y][x]==false)continue;
					}else if(i==2){//左
						if(yoko[y][x-1]==false)continue;
					}else if(i==1){//下
						if(tate[y][x]==false)continue;
					}else if(i==3){//上
						if(tate[y-1][x]==false)continue;
					}
					q.add(new State(nx, ny, now.step+1));
				}
			}
			
//			for(int i=0;i<h;i++){
//				for(int s=0;s<w;s++)System.out.print(map[i][s]+" ");
//				System.out.println();
//			}
			
			System.out.println(result);
		}
		class State{
			int x,y,step;
			public State(int x,int y,int step) {
				this.x = x;
				this.y = y;
				this.step = step;
			}
		}
	}
}

Measured memory_bytes: 61296
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long

using namespace std;

inline ll in()
{
	ll Req = 0, wX = 0; char ch;
	while (!isdigit(ch)) {wX |= (ch == '-'); ch = getchar();}
	while (isdigit(ch)) {Req = (Req << 3) + (Req << 1) + (ch ^ 48); ch = getchar();}
	return wX ? -Req : Req;
}

inline void out(ll x)
{
	register short Pxn[20], Ry = 0;
	if (x == 0) putchar('0');
	if (x < 0) putchar('-'), x = -x;
	while (x != 0) Pxn[Ry] = x % 10, x /= 10, Ry++;
	for (int i = Ry - 1; i >= 0; i--) putchar(Pxn[i] + '0');
}

int main()
{

	int n = in();
	out(n * n * n);

  return 0;

}



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

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  int num = 1;
  int c = 0;
  while(true){
    if(num >= b){
      break;
    }else{
      c++;
      num += a - 1;
    }
  }
  cout << c << endl;
  
  return 0;
}


Measured memory_bytes: 256
void main() {
    int[] abc = readln.split.to!(int[]);
    abc.sort!"a > b";
    writeln(abc[0] * 10 + abc[1..$].sum);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

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

int sum(int a){
	int x = 0;
	while(a!=0){
		x+=a%10;
		a/=10;
	}
	return x;
}



int main(){
	int N;
	cin>>N;
	int mini = 99999999;
	for(int i=1;i<N;i++){
		mini = min(mini,sum(i)+sum(N-i));
	}
	cout<<mini<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
#include "string"

int n , k;
int dp[55][55][101],a[55];

int solve(int l,int r,int cnt) {
	if(cnt > k)
		return -inf;
	if(cnt == k or l>r)
		return 0;
	int &tmp = dp[l][r][cnt];
	if(tmp != - 1)
		return tmp;
	tmp  = 0;
	tmp = max(tmp,solve(l+1,r,cnt+1) + a[l]);
	tmp = max(tmp,solve(l,r-1,cnt+1) + a[r]);
	if(a[l] < 0)
		tmp = max(tmp,solve(l+1,r,cnt+2));
	if(a[r] < 0)
		tmp = max(tmp,solve(l,r-1,cnt+2));
	return tmp;
}

int32_t main() {
	int t=1;
	//cin>>t;
	while(t--) {
		cin >> n >> k;
		for(int i = 0;i < n;i++)
			cin>>a[i];
		memset(dp,-1,sizeof dp);
		int ans = solve(0,n-1,0);
		cout<<ans<<endl;
	}	
}

Measured memory_bytes: 6028
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*Coding Space*/
int main(){
  int n,h; cin >> n >> h;
  vi a(n);
  vi b(n);
  rep(i,n)  cin >> a[i] >> b[i];
  int a_max = 0, b_cnt = 0;
  ll b_sum = 0;
  rep(i,n){
    a_max = max(a_max, a[i]);
  }
  rep(i,n){
    if(a_max < b[i]){
      b_cnt++;
      b_sum += b[i];
    }
  }
  cerr << b_sum << endl;
  sort(ALL(b),greater<ll>());
  
  // 全部投げた方がいい場合
  if(b_sum >= h){
    ll nowh = 0;  int ans = 0;
    while(nowh < h){
      nowh += b[ans++];
    }
    cout <<ans<< endl;
  }else{
    int ans = b_cnt;
    h -= b_sum;
    ans += h/a_max + (!(!(h%a_max)));
    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
/* ex4_1
   shu_t */

#include<stdio.h>
#include<math.h>

int main(void){
  int tree_num, D;
  int ans;
  //input N and D
  scanf("%d %d",&tree_num,&D);
  //answer: round up to tree_num divided by 2*D+1
  ans = ceil((double) tree_num/(2*D+1));
  //output the answer
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int main(){
    string s,t;
    vector<char> S,T;
    cin >> s >> t;
    REP(i,s.length()) S.push_back(s[i]);
    REP(i,t.length()) T.push_back(t[i]);
    sort(S.begin(),S.end());
    sort(T.begin(),T.end(),greater<char>());
    if(S<T) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,s[104],r[104],n,i;main(j){for(scanf("%d",&n);~scanf("%d%d%d%d",&a,&b,s,r);)*s-*r?s[*s>*r?a:b]+=3:++s[a]-++s[b];for(;i++-n;)for(a=0;a++-n;)r[i]+=s[i]<s[a];for(;a=j<=n;)printf("%d\n",r[j++]+1);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll long long
#define endl '\n'
#define pi 3.14159265
ll n,k;
vector<ll> v(600001);
ll dp[500001];
ll f(ll i)
{
    if(i>=n)
        return 1e16;
    if(i==n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    ll ans=1e16;
    for(ll j=1;j<=k;j++)
    {
        if(i+j<n)
            ans=min(ans,abs(v[i+j]-v[i])+f(i+j));
    }
    return dp[i]=ans;
}
int main()
{
    IOS;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
        cin>>v[i];
    memset(dp,-1,sizeof(dp));
    cout<<f(0);
}

Measured memory_bytes: 15104
while True:
    inp = input()
    if inp == '0': break


    inp = inp.replace('11', '10')
    inp = inp.replace('12', '10')
    inp = inp.replace('13', '10')

    cards = tuple(map(int, inp.split()))
    ans = sum(cards)

    for i in range(cards.count(1)):
        if sum(cards) + 10 * (i+1) > 21:
            break
        elif ans < sum(cards) + 10 * (i+1):
            ans = sum(cards) + 10 * (i+1)

    if ans > 21: ans = 0
    print(ans)

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

E=[[] for i in range(N+1)]

for i in range(N-1):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

mod=10**9+7

from collections import deque
Q=deque()

USE=[0]*(N+1)
Q.append(1)
H=[0]*(N+1)
H[1]=1
USE[1]=1

while Q:
    x=Q.pop()
    for to in E[x]:
        if USE[to]==0:
            USE[to]=1
            H[to]=H[x]+1
            Q.append(to)

EH=[(h,ind+1) for ind,h in enumerate(H[1:])]
EH.sort(reverse=True)

COME=[1]*(N+1)
USE=[0]*(N+1)

for h,ind in EH:
    USE[ind]=1
    for to in E[ind]:
        if USE[to]==0:
            COME[to]+=COME[ind]

ANS=0

POW2=[1]
for i in range(N+1):
    POW2.append(POW2[-1]*2%mod)

for i in range(1,N+1):
    SCORE=[]
    for j in E[i]:
        if COME[j]<COME[i]:
            SCORE.append(COME[j])

    if sum(SCORE)<N-1:
        SCORE.append(N-sum(SCORE)-1)

    AV=1

    for s in SCORE:
        AV+=POW2[s]-1

    ANS+=POW2[N-1]-AV
    #print(SCORE,AV)

print((ANS*pow(POW2[N],mod-2,mod))%mod)

Measured memory_bytes: 111640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		Set<Integer> T = new TreeSet<Integer>();
		for(int i = 0; i < n; i++){
			T.add(sc.nextInt());
		}
		
		final int q = sc.nextInt();
		int count = 0;
		for(int i = 0; i < q; i++){
			final int t = sc.nextInt();
			
			if(T.contains(t)){
				count++;
			}
		}
		
		System.out.println(count);
	}
	
	public static class Scanner {
	    private BufferedReader br;
	    private StringTokenizer tok;

	    public Scanner(InputStream is) throws IOException {
	        br = new BufferedReader(new InputStreamReader(is));
	    }

	    private void getLine() throws IOException {
	        while (!hasNext()) { tok = new StringTokenizer(br.readLine()); }
	    }

	    private boolean hasNext() {
	        return tok != null && tok.hasMoreTokens();
	    }

	    public String next() throws IOException {
	        getLine(); return tok.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	    
	    public void close() throws IOException {
	        br.close();
	    }
	}

}

Measured memory_bytes: 39936
#include<iostream>
#include<string>
using namespace std;
 
int main(){
double a[10]={48,51,54,57,60,64,69,75,81,91};
string c[11]={"light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"};
double b;
bool ans;
while(cin>>b){
ans=false;
for(int i=0;i<10;i++){
if(b<=a[i]){cout<<c[i]<<endl; ans=true; break;}}
if(!ans)cout<<c[10]<<endl;}}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int a[101];
int main(){
	int N;
	cin>>N;
	REP(i,N){
	   cin>>a[i];
	}
	long long ans=100000000;
	for(int i=-100;i<101;i++){
	   long long temp=0;
	   REP(j,N){
	      temp+=(i-a[j])*(i-a[j]);
	   }
	   ans=min(ans,temp);
	}
        cout<<ans<<endl;
	return(0);
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

const int mod = 1e9+7;

long long binpow(long long b, int e) {
    if (e == 0) return 1;
    if (e&1) return b*binpow(b, e-1)%mod;
    return binpow(b*b%mod, e/2);
}

int sub(int a, int b) {
    return (a-b+mod)%mod;
}

int div(long long a, int b) {
    return a*binpow(b, mod-2)%mod;
}

long long choose(int n, int k) {
    long long res = 1;
    for (int i = n-k+1; i <= n; ++i) {
        res = (res*i)%mod;
    }
    for (int i = 2; i <= k; ++i) {
        res = div(res, i);
    }
    return res%mod;
}

void solve() {
    int n, a, b; scanf("%d%d%d", &n, &a, &b);
    int ans = binpow(2, n)-1;
    printf("%d", sub(sub(ans, choose(n, a)), choose(n, b)));
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

int main()
{
  int k,x;
  cin >> k >> x;

  if(k * 500 < x){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;

}


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

int main(){

  int n,i,k,j;
  double a[1005];
  double t,s;

  scanf("%d", &n);

  for(i = 0;i < n;i++) scanf("%lf", &a[i]);

  for(i = 0;i < n - 1;i++){
    for(j = n - 1;j > i;j--){
      if(a[j] < a[j - 1]){
        t = a[j]; a[j] = a[j - 1]; a[j - 1] = t;
      }
    }
  }

  for(i = 0;i < n - 1;i++){
    s = (double)(a[i] + a[i + 1])/2;
    a[i] = 0;
    k = i + 1;
    while(k < n - 1 && a[k + 1] < s) k++;

    for(j = k - 1;j > i;j--){
      t = a[j]; a[j] = a[j - 1]; a[j - 1] = t;
    }
    a[k] = s;
  }

  printf("%.9f\n", a[k]);

  return 0;
}


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

int main(){
    int n, m, i, j;
    cin >> n >> m;
    int a, b;
    set<int> connect[8];
    vector<int> v;
    for(i = 0; i < m; i++){
        cin >> a >> b;
        connect[a-1].insert(b-1);
        connect[b-1].insert(a-1);
    }
    for(i = 0; i < n; i++){
        v.push_back(i);
    }

    int c = 0;
    do{
        if(v[0] != 0) continue;
        for(i = 0; i < n-1; i++){
            if(connect[v[i]].count(v[i+1]) != 1) break;
        }
        if(i == n-1) c++;
    }while(next_permutation(v.begin(), v.end()));
    cout << c << endl;

}

Measured memory_bytes: 256
let yes s i =
  if i mod 2 = 1 then false 
  else
  if String.sub s 0 (i / 2) = String.sub s (i / 2) (i / 2)
  then true else false

let () =
  let rec f s i = 
    if yes (String.sub s 0 i) i then i
    else f s (i - 1)
  in
  let str = read_line () in
  (f str ((String.length str) - 1)) |> Printf.printf "%d\n"

Measured memory_bytes: 384
k= int(input())
s=input()
ans = ['']*(k+3)
if len(s)<=k:
    print(s)
else:
    for i in range(k):
        ans[i]=s[i]
    ans[k]='.'
    ans[k+1] = '.'
    ans[k+2] = '.'
    for i in range(k+2):
        print(ans[i],end='')
    print(ans[k+2])

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,K,q;cin >> n >> K >> q;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans=inf;
    for(int i=0;i<n;i++){
        int cnt=0,m=-1;
        vector<int> b(n);
        for(int j=0;j<n;j++){
            if(a[j]<a[i]){
                if(m==-1){
                    continue;
                }
                b[m]=cnt;
                m=-1;
                cnt=0;
            }
            else{
                if(m==-1){
                    m=j;
                }
                cnt++;
            }
        }
        if(m!=-1){
            b[m]=cnt;
        }
        vector<int> u;
        for(int j=0;j<n;j++){
            if(!b[j]){
                continue;
            }
            vector<int> v;
            for(int l=0;l<b[j];l++){
                v.push_back(a[j+l]);
            }
            sort(v.begin(),v.end());
            for(int l=0;l<b[j]-K+1;l++){
                u.push_back(v[l]);
            }
            j+=b[j];
        }
        if(u.size()<q){
            continue;
        }
        sort(u.begin(),u.end());
        int t=0;
        for(int j=0;j<q;j++){
            chmax(t,u[j]);
        }
        chmin(ans,t-a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
($A,$B,$C)=glob<>;
if($A==$B and $B==$C){
    if($A%2){
        print "0";
    }else{
        print "-1";
    }
    exit;
}
$i=0;
until($A%2 or $B%2 or $C%2){
    $i++;
    $s=($A+$B)/2;
    $t=($B+$C)/2;
    $u=($C+$A)/2;
    $A=$s;$B=$t;$C=$u;
}
print $i

Measured memory_bytes: 768
#include<stdio.h>

int main() {
  int A[100];
  int n, i, j, temp, min=1000, cout=0, k;

  scanf("%d\n",&n);
  
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);

  for (i=0; i<n; i++) {
    for (j=i+1; j<n; j++) {
      if (min>A[j]) {
        min=A[j];
        k=j;
      }
    }
    if (min<A[i]) {
        temp=A[i];
        A[i]=min;
        A[k]=temp;
        cout++;
    }
    min=1000;
  }
  for (i=0; i<n-1; i++)
    printf("%d ",A[i]);
  printf("%d",A[n-1]);
 
  printf("\n");
  printf("%d\n",cout);
  return 0;

}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
string s;
int d;
int dp[10010][110][2];
signed main(){
	cin>>s>>d;
	dp[0][0][1]=1;
	rep(i,s.size()){
		rep(j,d){
			rep(k,2){
				rep(l,10){
					if(k&&s[i]-'0'==l){
						dp[i+1][(j+l)%d][1]+=dp[i][j][1];
						dp[i+1][(j+l)%d][1]%=MOD;
						break;
					}
					else{
						dp[i+1][(j+l)%d][0]+=dp[i][j][k];
						dp[i+1][(j+l)%d][0]%=MOD;
					}
				}
			}
		}
	}
	cout<<(dp[s.size()][0][0]+dp[s.size()][0][1]-1+MOD)%MOD<<endl;				
	return 0;
}


Measured memory_bytes: 18688
#072_D
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        cnt += 1
if p[n-1] == n:
    cnt += 1
print(cnt)

Measured memory_bytes: 13880
N = input()
#print(N[-1])
if int(N[-1])==2 or int(N[-1])==4 or int(N[-1])==5 or int(N[-1])==7 or int(N[-1])==9:
  print('hon')
elif int(N[-1])==0 or int(N[-1])==1 or int(N[-1])==6 or int(N[-1])==8:
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9200
#include <iostream>

using namespace std;

int main()
{
	int64_t N, A, B, tmp;
	cin >> N >> A >> B;
	tmp = A + B;
	if (A > N)
	{
		cout << N << endl;
	}
	else
	{
		int64_t times = N / tmp;
		if (N % tmp > A)
		{
			cout << A * (times + 1) << endl;
		}
		else
		{
			cout << A * times + (N % tmp) << endl;
		}
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int r = scan.nextInt();
        int g = scan.nextInt();
        int b = scan.nextInt();
        int num = 100*r + 10*g + b;
        int cal = num % 4;
        if(cal == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str1 = sc.nextLine();
		String[] str2 = sc.nextLine().split(" ");

		int n = Integer.parseInt(str1);
		int d = Integer.parseInt(str2[0]);
		int x = Integer.parseInt(str2[1]);

		for (int i = 0; i < n; i++) {
			String stra = sc.nextLine();
			int a = Integer.parseInt(stra);

			int choco = (d - 1) / a;
			x += choco;

		}
		x += n;

		System.out.println(x);

		sc.close();
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)

#define repv(v, values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0)
#define srt(vec) sort(vec_all(vec))

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

template <typename T, typename S>
void dump_dic(map<T, S> dic)
{
    for (auto v : dic)
    {
        cout << v.first << ": " << v.second << endl;
    }
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n, k;
    cin >> n >> k;
    vector<char> d(k);
    rep(i, k) {
        cin >> d[i];
    }

    bool is_include;
    while(true) {
        is_include = false;
        repv(v, d) {
            if (to_string(n).find(v) != string::npos) {
                is_include = true;
                break;
            }
        }
        if (!is_include) {
            break;
        }
        n++;
    }

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 764
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0096
"""
import sys


Memo = [0 for _ in range(2001)]
def init_memo():
    global Memo
    # a, b??????????????°?????§ 0???2000?????????????????????????????°??????????????????
    for a in range(1000+1):
        for b in range(1000+1):
            Memo[a+b] += 1


def solve(target):
    global Memo
    ans = 0
    for ab in range(min(target+1, 2001)):
        cd = target - ab
        if 0 <= cd <= 2000:
            ans += Memo[ab] * Memo[cd]
    return ans


def main(args):
    init_memo()
    for line in sys.stdin:
        target = int(line.strip())
        result = solve(target)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

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

namespace AtCoder.AtCoderBeginnerContest_117
{
    public class B_Polygon
    {
        public static void Main(string[] args)
        {
            var Nstr = Console.ReadLine();
            int N = int.Parse(Nstr);

            var line = Console.ReadLine();
            var str = line.Split(' ');
            int[] L = new int[N];

            for (int i = 0; i < N; i++)
            {
                L[i] = int.Parse(str[i]);
            }

            int max = L[0];
            int tmp = 0;
            for (int i = 1; i < N; i++)
            {
                if (max < L[i])
                {
                    max = L[i];
                    tmp = i;
                }
            }

            int sum = 0;

            int tmpn = 0;

            tmpn = L[0];
            L[0] = L[tmp];
            L[tmp] = tmpn;

            for (int i = 1; i < N; i++)
            {
                sum += L[i];
            }

            if (L[0] >= sum)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}


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

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

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

  char a, b;
  cin >> a >> b;

  if (a == 'H') {
    if (b == 'H') {
      cout << "H" << endl;
    } else {
      cout << "D" << endl;
    }
  } else {
    if (b == 'H') {
      cout << "D" << endl;
    } else {
      cout << "H" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

co = Combination(200006)
n,m = inpl()
if m >= n:
    m = n-1
res = 1
if m == 1:
    print(co(n-1,n-2) * n)
    quit()
else:
    for i in range(m):
        tmp = i+1
        res += co(n-1,n-tmp-1) * co(n,tmp)
        res %= mod
        # print(res)
print(res)

Measured memory_bytes: 94572
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策


void solve()
{
	int A, B;
	cin >> A >> B;

	int res = B;

	if (A <= 5) {
		res = 0;
	}
	else if (A <= 12) {
		res = B / 2;
	}

	cout << res << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<ll> res(n,0);
    vector<ll> b={};
    for(ll i=n; i>0; i--){
        if(res[i-1]%2!=a[i-1]){
            b.push_back(i);
            for(ll j=1; j*j<=i; j++){
                if(i%j!=0) continue;
                res[j-1]++;
                if(j != i/j) res[i/j - 1]++;
            }
        }
    }
    sort(b.begin(), b.end());
    cout<<b.size()<<endl;
    rep(i, b.size()){
        if(i>0) cout<<' ';
        cout<<b[i];
    }
    if(b.size()>0) cout<<endl;
    return 0;
}

Measured memory_bytes: 4980
loop do
  h,w = gets.split.map(&:to_i)
  break if h==0 && w==0
  w.times do
    print "#"
  end
  puts
  (h-2).times do
    print "#"
    (w-2).times do
      print "."
    end
    print "#"
    puts
  end
  w.times do
    print "#"
  end
  puts
  puts
end


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

int main() {
  IN(string, N);
  int ans = 0;
  REP(i, N.size()) {
    int a = N.at(i) - '0';
    ans += a;
  }
  if (ans % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<fstream>
using namespace std;

const int INF=INT_MAX/3;
typedef unsigned long long ull;

ull NumberofWindow(ull N, vector<ull>&a_list, ull S){
	ull i=0;
	ull j=0;
	ull tmpS = a_list[0];
	ull res = 0;
	while (j < N){
		while ( ( tmpS <=S )&&(i < N-1 ) ){
			i++;
			tmpS += a_list[i];
		} 
		if (i == N-1){
			if (tmpS > S) {
				res += i - j;
			}else{
				res += i-j+1;
			}
		}else{
			res += i-j;
		}
		tmpS -= a_list[j];
		j++;
	}
	return res;
}

int main(){
	
	int N, Q;
	ull x;
	cin >> N >> Q;
	vector<ull> a_list(N);
	for (int i=0;i<N;i++){
		cin >> a_list[i];
	}
	/*
	ull N, Q;
	ull x;
	ifstream ifs("DSL_3_C-in21.txt");
	ifs >> N >> Q;
	cout << N << Q << endl;
	vector<ull> a_list(N);
	for (int i=0;i<N;i++){
		ifs >> a_list[i];
	}
	*/
	for (int i=0;i<Q;i++){
		cin >> x;
		cout <<  NumberofWindow(N, a_list, x) << endl;
	}
	return 0;
}

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


int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int score;
    int xa = min(k,a);
    k -= xa;
    int xb = min(k,b);
    k -= xb;
    int xc = min(k,c);
    cout << 1*xa -1*xc << endl;
    return 0;
}


Measured memory_bytes: 3676
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
l = []
for key in A:
  d[key] += 1
  if d[key] == 2:
    l.append(key)
    d[key] = 0
if len(l) < 2:
  print(0)
else:
  l.sort(reverse=True)
  print(l[0]*l[1])

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

int main() {
    int N, K, Q, tmp;
    cin >> N >> K >> Q;
    vector<int> a(N, 0);
    vector<int> m(N, K);

    for(int i=0; i<Q; i++){
	cin >> tmp;
	tmp--;
	a[tmp]++;
    }

    for(int i=0; i<N; i++){
	tmp = Q - a[i];
	m[i] -= tmp;
    }

    for(int i=0; i<N; i++){
	cout << (m[i]>0 ? "Yes": "No") << endl;
    }


}



Measured memory_bytes: 1408
N = int(input())
S = input()

char2count = {}
for s in S:
    if s not in char2count:
        char2count[s] = 0
    char2count[s] += 1

total = 1
for x in char2count.values():
    total *= (x + 1)
print((total - 1) % (1000000000 + 7))


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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    rep(i, n) cin >> m.at(i);

    int sum = 0;
    rep(i, n) sum += m.at(i);

    x = x - sum;

    int mini = 1001;
    rep(i, n) mini = min(mini, m.at(i));

    int N = x / mini;

    cout << n + N << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 128;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1e15;
const int MOD = 1000000007;

int F[MAX][10], P[MAX][11];

void solve(void){
    int N;
    cin >> N;
    rep(N, i) {
        rep(10, j) scanf("%d ", &F[i][j]);
        scanf("\n");
    }
    rep(N, i) {
        rep(11, j) scanf("%d ", &P[i][j]);
        scanf("\n");
    }
    ll ans = -INF;
    Rep(1, (1<<10)-1, i) {
        ll temp = 0LL;
        rep(N, n) {
            int common = 0;
            rep(10, j) {
                if (i >> j & 1 and F[n][j]) common++;
            }
            temp += P[n][common];
        }
        ans = max(ans, temp);
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 256