akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <list>
#include <string>
#include <ios>
#include <algorithm>
using namespace std;

class DLL //Doubly Linked List
{
private:
    list<int> DL;

public:
    void judge(string comm); //stringの内容から処理を判断し、それぞれの処理を行う関数に値を渡す
    int element_count(void); //リストDLの要素数を返す
    int output_key(void);    //リストの最初の要素を返した後、最初の要素を削除する
    bool remove(int key);    //
    void delete_F_L(string comm);
    void in_and_out(string comm);
};

void DLL::delete_F_L(string comm)
{
    if (comm == "deleteFirst")
    {
        DL.pop_front();
    }
    else
    {
        DL.pop_back();
    }
}

void DLL::in_and_out(string comm)
{
    int key = stoi(comm.substr(7));
    if (comm.substr(0, 6) == "insert")
    {
        DL.push_front(key);
    }
    else // if (comm.substr(0, 6) == "delete")
    {
        auto temp = find(DL.begin(), DL.end(), key);
        if (temp != DL.end())
        {
            DL.erase(temp);
        }
    }
}

void DLL::judge(string comm)
{
    if (comm == "deleteFirst" || comm == "deleteLast")
    {
        delete_F_L(comm);
    }
    else
    {
        in_and_out(comm);
    }
}

int DLL::element_count()
{
    return DL.size();
}

int DLL::output_key()
{
    int output = DL.front();
    DL.pop_front();
    return output;
}

int main()
{
    ios_base::sync_with_stdio(false);
    DLL list;
    int command_num;
    string command;
    cin >> command_num;
    cin.ignore();
    for (int i = 0; i < command_num; i++)
    {
        getline(cin, command);
        list.judge(command);
    }
    int count = list.element_count();
    for (int i = 0; i < count - 1; i++)
    {
        cout << list.output_key() << " ";
    }
    cout << list.output_key() << endl;
}


Measured memory_bytes: 34284
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL;
const int MAxn = 2e5 + 5;
const int MA_N = 5e3 + 5;
 
int vis[MAxn] = {0};
 
int main(){
	int n, m;
	char s[MAxn];
	scanf("%s", s+1);
	int len = strlen(s + 1);
	for (int i = 1; i <= len; i++)
		if(i%2) printf("%c", s[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
ll score[100000],parents[100000];

ll root(int x){
  if(parents[x] < 0){
    return x;
  }else{
    return root(parents[x]);
  }
}

ll unite(ll x,ll y,ll n){
  x=root(x),y=root(y);
  if(x == y){
    return 0;
  }else{
    ll tmp1 = parents[x],tmp2=parents[y];
    if(parents[x] > parents[y]){
      //cout << a << " " <<  b << endl;
      swap(x,y);
    }
    parents[x] = parents[x] + parents[y];
    parents[y] = x;
    //for(ll i=0;i<n;i++){cout << parents[i] << " ";}
    //cout << endl;
    return tmp1*tmp2;
  }
}
int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> vec[n];
  ll x[m],y[m];
  for(int i=0;i<m;i++){
    cin >> x[i] >> y[i];
  }
  for(int i=0;i<n;i++){
    parents[i] = -1;
  }
  ll sum=0;
  for(int i=0;i<m;i++){
    sum += unite(x[m-i-1],y[m-i-1],n);
    score[m-i-1] = sum;
  }
  for(int i=1;i<m;i++){
    cout << n*(n-1)/2-score[i]<< endl;
  }
  cout << n*(n-1)/2 << endl;
}


Measured memory_bytes: 6784
#include<stdio.h>

int main()
{
	int point[31]={0},g[100]={0},r[31]={0};
	int i,d,n,j=0;
	char c;

	while(1)
	{
		scanf("%d%c%d",&d,&c,&n);
		if(!d&&!n)
			break;
		point[n]=1;/*点数記録*/
		g[d-1]=n;/*チームの点数*/
	}

	for(i=30;i>=0;i--)
	{
		if(point[i])
		{
			j++;
			r[j-1]=i;/*点数並び替え*/
		}
	}

	while(scanf("%d",&d)!=EOF)
	{
		for(i=0;i<31;i++)
		{
			if(g[d-1]==r[i])
			{
				printf("%d\n",i+1);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>

using namespace std;


int main()

{
	int h, w, n;
	scanf("%d%d%d", &n, &h, &w);
	
	int hDist, wDist;
	hDist = n - h + 1;
	wDist = n - w + 1;
	
	int ans = hDist * wDist;
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll N, K;
        is >> N >> K;
        if(!is) return;
        int count =0;
        for (int i = 0; i < N; ++i) {
            int b;
            is >> b;
            count += b >= K;
        } // end i
        os << count << endl;

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_B.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll k;
	cin >> k;
	Vec a(k);
	rep(i, k) cin >> a[i];
	reverse(all(a));

	ll mini = 2, maxi = 2;
	rep(i, k){
		if(a[i] > maxi){
			co(-1);
			return 0;
		}
		mini = ((mini-1)/a[i]+1)*a[i];
		maxi = maxi/a[i]*a[i]+a[i]-1;
		if(mini > maxi){
			co(-1);
			return 0;
		}
	}
	cosp(mini); co(maxi);

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353;
struct segt
{
	int l,r,sum,tg;
}tree[800010];
int mul[200010][2];
void push_down(int i)
{
	if(tree[i].tg)
	{
		tree[i<<1].sum=mul[tree[i<<1].r-tree[i<<1].l+1][1]*tree[i].tg%mod;
		tree[i<<1|1].sum=mul[tree[i<<1|1].r-tree[i<<1|1].l+1][1]*tree[i].tg%mod;
		tree[i<<1].tg=tree[i].tg;
		tree[i<<1|1].tg=tree[i].tg;
		tree[i].tg=0;
	}
}
void build(int le,int ri,int i)
{
	tree[i].l=le;
	tree[i].r=ri;
	tree[i].tg=0;
	tree[i].sum=mul[ri-le+1][1];
	if(le==ri)
		return;
	int mid=(le+ri)>>1;
	build(le,mid,i<<1);
	build(mid+1,ri,i<<1|1);
}
void change(int le,int ri,int x,int i)
{
	if(le<=tree[i].l&&tree[i].r<=ri)
	{
		tree[i].sum=mul[tree[i].r-tree[i].l+1][1]*x%mod;
		tree[i].tg=x;
		return;
	}
	push_down(i);
	if(tree[i<<1].r>=le)
		change(le,ri,x,i<<1);
	if(tree[i<<1|1].l<=ri)
		change(le,ri,x,i<<1|1);
	tree[i].sum=(tree[i<<1].sum*mul[tree[i<<1|1].r-tree[i<<1|1].l+1][0]%mod+tree[i<<1|1].sum)%mod;
}
int ask(int le,int ri,int i)
{
	if(le<=tree[i].l&&tree[i].r<=ri)
		return tree[i].sum;
	push_down(i);
	int cnt=0;
	if(tree[i<<1].r>=le)
		cnt=ask(le,ri,i<<1);
	if(tree[i<<1|1].l<=ri)
		cnt=(cnt*mul[ri-tree[i<<1].r][0]%mod+ask(le,ri,i<<1|1))%mod;
	return cnt;
}
signed main()
{
	int n,q,i,l,r,x;
	cin>>n>>q;
	mul[0][0]=1;
	for(i=1;i<n+3;i++)
	{
		mul[i][0]=mul[i-1][0]*10%mod;
		mul[i][1]=(mul[i-1][1]*10+1)%mod;
	}
	build(1,n,1);
	while(q--)
	{
		cin>>l>>r>>x;
		change(l,r,x,1);
		cout<<ask(1,n,1)<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    int N;
    cin >> N;
    vector<int> A(N), Asub(N);
    int tmp;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        A[i] = tmp;
        Asub[i] = tmp;
    }

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

    for(int i = 0; i < N; i++){
        if(A[i] == Asub[N-1]){
            cout << Asub[N-2] << endl;
        }else{
            cout << Asub[N-1] << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 3200
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	lld a,b,c;
	cin >> a >> b >> c;
	if(a%c==0)
		cout << b/c - a/c + 1;
	else
		cout << b/c - a/c;
}

Measured memory_bytes: 256
n, y = list(map(int, input().split()))
found = False
for i in range(n+1):
    for j in range(n+1):
        k = n-i-j
        if k < 0:
            continue
        if (i * 10000 + j * 5000 + k * 1000) == y:
            print("{} {} {}".format(i, j, k))
            found = True
            break
        if found:
            break
    if found:
        break
if not found:
    print("-1 -1 -1")

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(Math.min((n*a) , b));
    }
}


Measured memory_bytes: 23764
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
ans = []
zeroflag = False
neg = 0
for num in a:
    if num == 0:
        zeroflag = True
    if num < 0:
        neg+=1
    ans.append(abs(num))
if zeroflag:
    print(sum(ans))
else:
    ans.sort()
    if neg%2 == 0:
        print(sum(ans))
    else:
        print(sum(ans[1:])-ans[0])


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  map<string, int> ma;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (ma.count(s)) {
      ma[s]++;
    } else {
      ma[s] = 1;
    }
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string t;
    cin >> t;
    if (ma.count(t)) {
      ma[t]--;
    } else {
      ma[t] = -1;
    }
  }
  int max = 0;
  for (auto x : ma) {
    if (max < x.second) {
      max = x.second;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>

using namespace std;

int main() {
    

    
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    long long ret = 0;
    
    for (int i = 0; i <= (n / r); ++i)
    {
        for (int j = 0; j <= ((n - i * r) / g); ++j)
        {
            if (((n - i * r - j * g) % b) == 0)
            {
                ret++;
            }
        }
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)
#define MAX_N 100000
int par[MAX_N];  // 親
int rnk[MAX_N];  // 木の深さ
int mem[MAX_N];  // グループの要素数
// n要素で初期化
void init(ll n) {
	for (ll i = 0; i < n; i++) {
		par[i] = i; rnk[i] = 0; mem[i] = 1;
	}
}
// 木の根を求める
ll find(ll x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}
// xとyの属する集合を併合
void unite(ll x, ll y) {
	x = find(x); y = find(y);
	if (x == y) return;
	if (rnk[x] < rnk[y]) {
		par[x] = y; mem[y] += mem[x];
	} else {
		par[y] = x; mem[x] += mem[y];
		if (rnk[x] == rnk[y]) rnk[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same(ll x, ll y) {
	return find(x) == find(y);
}
// グループのサイズ
ll size(ll x) {
	return mem[find(x)];
}

int main() {
	ll N, M; cin >> N >> M;
	ll A[100000], B[100000];
	ll ans[100000];
	rep(i, M) {
		cin >> A[i]; A[i]--;
		cin >> B[i]; B[i]--;
	}
	init(N);
	ll a = N * (N-1) / 2;
	for (int i = M-1; i >= 0; i--) {
		if (i == M-1) {
			ans[i] = a; continue;
		}
		if (same(A[i+1], B[i+1])) {
			ans[i] = ans[i+1];
		} else {
			ans[i] = ans[i+1] - size(A[i+1])*size(B[i+1]);
			unite(A[i+1], B[i+1]);
		}
	}
	rep(i, M) {
		cout << ans[i] << endl;
	}
}

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

int main() {
    int n,m;
    cin >> n >> m;
    priority_queue<ll> pq;
    for(int i=0; i<n; i++){
        ll x;
        cin >> x;
        pq.push(x);
    }
    for(int i=0; i<m; i++){
        ll x;
        x = pq.top();
        pq.pop();
        pq.push(x/2);
    }
    ll ans = 0;
    while(pq.size() != 0){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
n = int(input())
a = [input().split() for _ in range(n)]
marks = ['S', 'H', 'C', 'D']
for i in range(n):
    a[i][1] = int(a[i][1])
a.sort(key=lambda x: marks.index(x[0])*100 + x[1])
for m in marks:
    for n in range(1, 14):
        if [m, n] not in a:
            print(m, n)



Measured memory_bytes: 5600
s = input()
x,y = map(int,input().split())

muki = "plus_x"

#info[muki][kaisu]

info=[["plus_x",0]]
count = 0
for i in range(len(s)):
  if s[i]=="F":
    if muki == "plus_x":
      info[0][1] += 1
    else:
      info[count][1] +=1
      
  if s[i] =="T":
    if muki =="plus_x" or muki=="x":
      muki ="y"
      info.append(["y",0])
      count += 1
    elif muki =="y":
      muki ="x"
      info.append(["x",0])
      count += 1
      
#print(info)
x_set=set([info[0][1]])
y_set=set([0])

for i in range(1,count+1):
  if info[i][0]=="x":
    x_set = set(map(lambda x: x+info[i][1], x_set))|set(map(lambda x: x-info[i][1], x_set))
  if info[i][0]=="y":
    y_set = set(map(lambda y: y+info[i][1], y_set))|set(map(lambda y: y-info[i][1], y_set))

if (x in x_set) and (y in y_set):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 5056
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  ll c = 0;
  int n = s.size();
  REP(i,0,n) {
    if(s[i] == 'p') {
      c++;
    }
  }
  cout << n / 2 - c << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t N, K;

	scanf("%zu %zu", &N, &K);

	puts((K <= (N + 1)/2 ? "YES" : "NO"));

	return 0;
}


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

const ll INF = 1e18;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N; cin >> N;
    ll A[N + 1];           // 各depthにおける葉の数を表す
    ll B[N + 1];           // 各depthにおいて、葉以外の頂点の最大数を表す 
    for(ll i = 0; i <= N; i++) {
        cin >> A[i];
        if (i == 0) B[i] = 1 - A[i];
        else B[i] = min(INF, B[i - 1] * 2 - A[i]);
        if (B[i] < 0) {
            cout << -1 << "\n";
            return 0;
        }
    }

    ll ans = 0, v = 0;
    for (ll i = N; i >= 0; i--) {
        v = min(v, B[i]) + A[i];
        ans += v;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 5232
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		
		for (int i=0; i<N; i++) {
			System.out.print(S.substring(i, i+1) + T.substring(i, i+1));
		}
		
	}
}

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


int main(){
    int n, x;
    
    while(1){
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int cnt = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                for(int k = j+1; k <= n; k++){
                    if (i+j+k == x) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <iomanip>
using namespace std;
#define ll long long
#define ld long double
void solve(){
	ll n;
	cin >> n;
	ld p[n];
	for(ll i=0;i<n;i++){
		cin >> p[i];
	}
	ld dp[n][n+1];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<=n;j++){
			dp[i][j]=0;
		}
	}
	dp[0][0]=1-p[0];
	dp[0][1]=p[0];
	for(ll i=1;i<n;i++){
		for(ll j=0;j<=n;j++){
			if(j<=i+1){
				dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
			}
		}
	}
	ld ans=0;
	for(ll i=n/2+1;i<=n;i++){
		ans+=dp[n-1][i];
	}
	cout << fixed << setprecision(10) << ans << "\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 144328
#include<stdio.h>

int w,h;
int a[20][20];

int curling(int sh,int sw,int n){
  int i,min,tmp;

  min = 11;
  if(n>10)return n;
  else{
    if(sw-1 >= 0 &&a[sh][sw-1]!=1){
      for(i=sw-1;i>=0;i--){
	if(a[sh][i]==1){
	  a[sh][i]=0;
	  tmp = curling(sh,i+1,n+1);
	  if(min > tmp)min = tmp;
	  a[sh][i]=1;
	  break;
	}
	if(a[sh][i]==3)return n;
      }
    }
    
    if(sw+1<w &&a[sh][sw+1]!=1){
      for(i=sw+1;i<w;i++){
	if(a[sh][i]==1){
	  a[sh][i]=0;
	  tmp = curling(sh,i-1,n+1);
	  if(min > tmp)min = tmp;
	  a[sh][i]=1;
	  break;
	}
	if(a[sh][i]==3)return n;
      }
    }
    
    if(sh-1>=0 && a[sh-1][sw]!=1){
      for(i=sh-1;i>=0;i--){
	if(a[i][sw]==1){
	  a[i][sw]=0;
	  tmp = curling(i+1,sw,n+1);
	  if(min > tmp)min = tmp;
	  a[i][sw]=1;
	  break;
	}
	if(a[i][sw]==3)return n;
      }
    }
    
    if(sh+1<h && a[sh+1][sw]!=1){
      for(i=sh+1;i<h;i++){
	if(a[i][sw]==1){
	  a[i][sw]=0;
	  tmp =  curling(i-1,sw,n+1);
	  if(min > tmp)min = tmp;
	  a[i][sw]=1;
	  break;
	}
	if(a[i][sw]==3)return n;
      }
    }
  }

  return min;
}


int main(void){
  int i,j;
  int sw,sh;
  int ans;
  
  while(1){
    scanf("%d %d ",&w,&h);
    if(!w && !h)break;
    
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        scanf("%d ",&a[i][j]);
        if(a[i][j]==2){
	  sh=i;
	  sw=j;
	}
      }
    }

    ans = curling(sh,sw,1);

    if(ans>10)printf("-1\n");
    else printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <string>
#include <algorithm> 
#include <set>
#include <sstream>
#include <list>
#include <bit>
#include <bitset>
#include <cstdint>
#include <iomanip>
#include <queue>
#include <initializer_list>
#include <stdio.h>
typedef long long int ll;
using namespace std;
int main() {
	int H, N; cin >> H >> N;
	vector<int>data(N);
	for (int i = 0; i < N; i++)cin >> data[i];
	int sum = 0;
	for (int i = 0; i < N; i++)sum += data[i];
	if (H <= sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3124
#include<stdio.h>
#include<string.h>
int main()
{
    char n[200010];
    int sum=0,r,i,k;
    scanf("%s",n);
    k=strlen(n);
    for(i=0;i<k;i++)
    {
        sum=sum+n[i]-48;
    }
    if(sum%9==0)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1924
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
const Int INF = 1e17;
struct edge{
  Int w,u,v,to;
  edge(){}
  edge(Int w,Int u,Int v,Int to):w(w),u(u),v(v),to(to){}
  bool operator<(const edge &a)const{
    if(w!=a.w) return w<a.w;
    if(u!=a.u) return u<a.u;
    return v<a.v;
  }
};

struct LowLink{
  Int n,cnt;
  vector<vector<edge> > G;
  vector<Int> sum,used,pre,low,par;
  
  LowLink(Int n):n(n),cnt(0),G(n),sum(n),used(n),pre(n),low(n),par(n){}

  void add_edge(Int u,Int v,Int w){
    G[u].emplace_back(w,u,v,v);
    G[v].emplace_back(w,u,v,u);
  }

  void dfs(Int v,Int p,Int d=0){
    pre[v]=low[v]=d;
    used[v]=1;
    for(auto e:G[v]){
      Int u=e.to;
      if(!used[u]){
	par[u]=v;
	dfs(u,v,d+1);
	low[v]=min(low[v],low[u]);
	sum[v]+=sum[u]+e.w;
      }else if(u!=p){
	low[v]=min(low[v],pre[u]);
        sum[u]+=e.w;
      }      
    }
  }
  
  edge build(){
    dfs(0,-1);
    edge ans(INF,0,0,0);
    Int all=sum[0];
    for(Int i=0;i<n;i++){
      for(edge e:G[i]){
	Int u=e.u,v=e.v;
	if(par[u]==v){	    
	  Int a=sum[u];
	  Int b=all-sum[u]-e.w;
	  edge e2(abs(a-b),u,v,-1);
	  if(pre[u]==low[u]&&e2<ans) ans=e2;
	}
	if(par[v]==u){
	  Int a=sum[v];
	  Int b=all-sum[v]-e.w;
	  edge e2(abs(a-b),u,v,-1);
	  if(pre[v]==low[v]&&e2<ans) ans=e2;
	}
	{
	  edge e2(all-e.w,u,v,-1);
	  if(e2<ans) ans=e2;	  
	}
      }
    }
    return ans;
  }
  
};



signed main(){
  Int n,m;
  cin>>n>>m;
  LowLink G(n);
  Int sum=0;
  for(Int i=0;i<m;i++){
    Int u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    G.add_edge(u,v,w);
    sum+=w;
  }
  edge ans=G.build();
  //cout<<sum<<":"<<G.sum[0]<<endl;
  //cout<<ans.w<<endl;
  assert(sum==G.sum[0]);
  cout<<ans.u+1<<" "<<ans.v+1<<endl;
  return 0;
}



Measured memory_bytes: 18296
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <set>
#define sf(n) scanf("%d",&n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define ll long long
#define MAXL 1000000
#define eps 1e-6
#define MAXV 10005
#define INF 1000000005
#define mod 998244353
using namespace std;
int a[1005][1005];
int step[4][2]={-1,0,1,0,0,1,0,-1};
struct node{
    int x;int y;
    int sum;
    bool operator <(const node a)const{
        return sum>a.sum;
    }
};
int main()
{
    int n,m;
    sff(n,m);
    memset(a,-1,sizeof(a));
    priority_queue<node>q;
    for(int i=1;i<=n;i++){
        string x;cin>>x;
        for(int j=1;j<=m;j++){
            if(x[j-1]=='.'){a[i][j]=0;}//cout<<"???"<<i<<j<<endl;}
            else {
                a[i][j]==1;
                node er;
                er.x=i;er.y=j;
                er.sum=0;
                q.push(er);
            }
        }
        //cout<<a[1][2]<<endl;
    }
    node now;
    //cout<<a[1][2]<<endl;
    while(!q.empty()){
        now=q.top();
        //cout<<now.x<<now.y<<now.sum<<endl;
        q.pop();
        for(int i=0;i<4;i++){
            int xx=now.x+step[i][0],yy=now.y+step[i][1];
            //cout<<xx<<yy<<a[xx][yy]<<"?"<<endl;
            if(a[xx][yy]==0){
                //cout<<xx<<"  "<<yy<<endl;
                node next;
                next.x=xx;next.y=yy;
                next.sum=now.sum+1;
                a[xx][yy]=1;
                q.push(next);
            }
        }
    }
    printf("%d\n",now.sum);
}


Measured memory_bytes: 18408
n, d = map(int, input().split())
x = [[int(i) for i in input().split()] for _ in range(n)]
c = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k]) ** 2
        s = s ** 0.5
        if s == int(s):
            c += 1
print(c)

Measured memory_bytes: 3060
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		for(int n = 0; n < N; n++){
			final int x = sc.nextInt();
			final int y = sc.nextInt();
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			
			final int n_cost = x * a + y * b;
			
			final int max_a = Math.max(5, a);
			final int max_b = Math.max(2, b);
			
			final int p_cost = (x * max_a + y * max_b) * 4 / 5;
			
			System.out.println(Math.min(n_cost, p_cost));
			
		}
	}

}

Measured memory_bytes: 23440
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        String S = in.next();

        int res = 0;
        for (int i = 0; i < 1000; i++) {
            String T = String.format("%03d", i);

            int j = 0;
            for (int n = 0; n < S.length(); n++) {
                if(T.charAt(j) == S.charAt(n)) {
                    j++;
                }

                if (j >= 3) {
                    res++;
                    break;
                }
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 25756
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
int main(){
  char d;
  while(cin>>d){
    vector<int>in(10);
    in[0]=d-'0';
    char d;
    rep(i,9){
      cin>>d;
      in[i+1]=d-'0';
    }
    while(in.size()!=1){
      rep(i,in.size()-1)
	in[i]=(in[i]+in[i+1])%10;
      in.pop_back();
    }
    cout<<in[0]<<endl;
  }
}

Measured memory_bytes: 1172
N,X = map(int,input().split())
siz = [1]
pat = [1]
for i in range(N):
    siz.append(siz[-1]*2 + 3)
    pat.append(pat[-1]*2 + 1)

def rec(n,x):
    if n==0:
        ret = int(x>0)
    elif x <= 1 + siz[n-1]:
        ret = rec(n-1, x-1)
    else:
        ret = pat[n-1] + 1 + rec(n-1, x-2-siz[n-1])
    return ret
print(rec(N,X))

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

int main()
{
  string N;
  int a=0;
  cin>>N;
  for(int i=0,max=(int)N.size();i<max;i++)
    a+=stoi(N.substr(i,1));  
  cout << (a%9==0?"Yes":"No");
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

int INF = 1e9+7;

pair<int, int> find_idx(vector<int>& cnt_vect){
  // (idx, cnt)
  int tmp_max = 0;
  int tmp_idx = -1;
  rep(i, cnt_vect.size()){
    if(tmp_max < cnt_vect[i]){
      tmp_max = cnt_vect[i];
      tmp_idx = i;
    }
  }
  if(tmp_idx != -1){
    cnt_vect[tmp_idx] = 0;
    return make_pair(tmp_idx, tmp_max);
  }else{
    return make_pair(-1, -1);
  }
}

int main(){

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

  priority_queue<int> pq;
  rep(i, N){
    int tmp;
    cin >> tmp;
    pq.push(tmp);
  }

  rep(i, M){
    int biggest = pq.top(); pq.pop();
    biggest /= 2;
    pq.push(biggest);
  }

  ll ans = 0;
  while(!pq.empty()){
    ans += pq.top(); pq.pop();
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 892
loop do
    m, n = gets.split.map &:to_i
    break if m == 0

    count = 0
    x = 1
    loop do
        y = x
        loop do
            z = y
            loop do
                count += 1if z >= m
                z *= 5
                break if z > n
            end
            y *= 3
            break if y > n
        end
        x *= 2
        break if x > n
    end
    
    p count
end

Measured memory_bytes: 8508
import java.util.Scanner;

public class Main {

    static int SENTINEL = 2000000000;
    static int MAX = 500000;
    static int[] A = new int[MAX];
    static int[] L = new int[MAX/2 + 1];
    static int[] R = new int[MAX/2 + 1];
    static int cnt;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 0 ; i < n; i++){
            A[i] = sc.nextInt();
        }

        mergeSort(A,n,0,n);

        for(int i = 0 ; i < n; i ++){
            System.out.print(A[i]);
            if(i < n - 1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    }


    static void mergeSort(int[] A,int n,int left,int right){
        if(left + 1 < right){
            int mid = (left + right) / 2;
            mergeSort(A,n,left,mid);
            mergeSort(A,n,mid,right);
            merge(A,n,mid,left,right);
        }
    }

    static void merge(int[] A,int n,int mid,int left,int right){
        int n1 = mid - left;
        int n2 = right - mid;
        for(int i = 0;i < n1;i++){
            L[i] = A[left + i];
        }
        for(int i = 0;i < n2;i++){
            R[i] = A[mid + i];
        }

        L[n1] = R[n2] = SENTINEL;

        int i = 0 ,j = 0;
        for(int k = left; k < right; k ++){
            cnt ++;
            if(L[i] <= R[j]){
                A[k] = L[i ++];
            }else{
                A[k] = R[j ++];
            }
        }
    }

}



Measured memory_bytes: 177304
#include<stdio.h>
int sort(a,b,c){
   int A, B, C;
  A = a+b;
  B = a+c;
  C = b+c;

int tmp=A;
if(B < tmp)
tmp =B;
if(C < tmp)
tmp =C;
return tmp;
}

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  printf("%d\n", sort(a,b,c));

  return 0;
}

Measured memory_bytes: 128
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int a = Integer.parseInt(str2[0]);
    int b = Integer.parseInt(str2[1]);
    System.out.println(a*b + " " + 2*(a + b));
  }
}

Measured memory_bytes: 24360
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

ll INF = LONG_LONG_MAX / 2;

vector<int> to;
vector<ll> score;

ll solve(const int start, const int N, const int K) {
    vector<ll> loop;
    ll max_for_loop = -INF;
    ll sum_for_loop = 0;
    int k1 = 0;
    {
        int cur = start;
        while (1) {
            cur = to[cur];
            sum_for_loop += score[cur];
            chmax(max_for_loop, sum_for_loop);
            k1++;
            if (cur == start || k1 == K) {
                break;
            }
        }
    }

    // in the case K is smaller than loop or repeating loop decreases the score
    if (k1 == K) {
#ifdef DEBUG
        printf("loop is small: %d\n", k1);
#endif
        return max_for_loop;
    }
    if (sum_for_loop <= 0) {
#ifdef DEBUG
        printf("negative loop: %lld\n", sum_for_loop);
#endif
        return max_for_loop;
    }

    assert(max_for_loop > 0);
    assert(sum_for_loop > 0);

    // repeating loop increases the score, so do it as many as possible
    const int loop_size = k1;
    const int loop_cnt = K / loop_size - 1;
    // assert(loop_cnt > 0);

#ifdef DEBUG
    printf("loop size is %d\n", loop_size);
#endif
    ll s = sum_for_loop * loop_cnt;

    ll ans = s;
    int k2 = loop_cnt * loop_size;
    if (k2 < K) {
        int cur = start;
        while (1) {
            cur = to[cur];
            s += score[cur];
            chmax(ans, s);
            k2++;
            if (k2 == K) {
                break;
            }
        }
    }

    assert(ans >= 0);

    return ans;
}

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

    to.resize(N);
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        p--;
        to[i] = p;
    }

    score.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> score[i];
    }

    ll ans = -INF;
    for (int start = 0; start < N; start++) {
        ll cand = solve(start, N, K);
#ifdef DEBUG
        printf("maximum is %lld from %d\n", cand, start);
#endif
        chmax(ans, cand);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3712
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll v[3][3];
    ll t[3][3];
    rep(i,3){
        rep(j,3){
            t[i][j]=0;
        }
    }
    rep(i,3) cin>>v[i][0]>>v[i][1]>>v[i][2];
    cin>>n;
    ll w[n];
    rep(i,n) cin>>w[i];
    rep(j,n){
        rep(i,3){
        if(v[i][0]==w[j]) t[i][0]=1;
        if(v[i][1]==w[j]) t[i][1]=1;
        if(v[i][2]==w[j]) t[i][2]=1;
        if(v[0][i]==w[j]) t[0][i]=1;
        if(v[1][i]==w[j]) t[1][i]=1;
        if(v[2][i]==w[j]) t[2][i]=1;
        }
    }
    if(t[0][0]==1&&t[0][1]==1&&t[0][2]==1) f=1;
    if(t[1][0]==1&&t[1][1]==1&&t[1][2]==1) f=1;
    if(t[2][0]==1&&t[2][1]==1&&t[2][2]==1) f=1;
    if(t[0][0]==1&&t[1][0]==1&&t[2][0]==1) f=1;
    if(t[0][1]==1&&t[1][1]==1&&t[2][1]==1) f=1;
    if(t[0][2]==1&&t[1][2]==1&&t[2][2]==1) f=1;
    if(t[0][0]==1&&t[1][1]==1&&t[2][2]==1) f=1;
    if(t[2][0]==1&&t[1][1]==1&&t[0][2]==1) f=1;

    rep(i,3){
        rep(j,3){
           // cout<<t[i][j]<<" ";
        }
        //ln;
    }
    if(f==1)Yes;
    else No;

    return 0;
}


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

int main()
{
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x.at(i);
    }

    vector<vector<vector<int64_t>>> dp(N + 1, vector<vector<int64_t>>(N + 1, vector<int64_t>(2501)));
    dp.at(0).at(0).at(0) = 1;
    for (int i = 1; i <= N; i++)
    {
        dp.at(i).at(0).at(0) = 1;
        for (int j = 1; j <= N; j++)
        {
            for (int k = 0; k <= 2500; k++)
            {
                dp.at(i).at(j).at(k) = dp.at(i - 1).at(j).at(k);
                if (k - x.at(i - 1) >= 0)
                    dp.at(i).at(j).at(k) += dp.at(i - 1).at(j - 1).at(k - x.at(i - 1));
            }
        }
    }

    int64_t res = 0;
    for (int j = 1; j <= N; j++)
    {
        res += dp.at(N).at(j).at(A * j);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 52224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>

using namespace std;

int main() {
    long long n, m;
    long long count = 0;
    cin >> n >> m;
    if (m < 2)
    {
        cout << 0 << endl;
    }
    else if (n <= m / 2)
    {
        count += n;

        m = m - n * 2;

        count += (m / 4);

        cout << count << endl;
    }
    else
    {
        cout << m / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl '\n'
#define dbg(a) cout << #a << "=" << a << endl
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<ll, ll>
#define vi vector<ll>
#define MX 600000
#define MXX 1000000000
using namespace std;

vl v;

ll cut(ll x)
{
    ll ct=0;
    for(int i=0;i<v.size();i++)
    {
        ct+=(v[i]+x-1)/x;
        ct--;
        // dbg(ct);
    }
    // dbg(ct);
    return ct;
}

void solve()
{
    ll n, k;
    cin >> n >> k;
    v.clear();
    v.resize(n);
    // dbg(n);
    for(auto &it:v) cin>>it;
    sort(v.begin(), v.end());
    ll l=1, r=v.back();
    while(l<r)
    {
        ll m=(l+r)/2;
        // dbg(m);
        // dbg(cut(m));
        if(cut(m)<=k)
        {
            r=m;
        }
        else l=m+1;
    }
    cout<<l<<endl;
}

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


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

int main(){
  long long n,k,ans=1,mod=1e9+7;
  cin >> n >> k;
  long long a[n-1],b[n-1];
  vector<long long> graph[n];
  for(int i=0;i<n-1;i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    graph[a[i]].push_back(b[i]);
    graph[b[i]].push_back(a[i]);
  }
  for(int i=0;i<n;i++){
    if(graph[i].size()+1>(size_t)k){
      cout << "0\n";
      return 0;
    }
  }
  queue<long long> que;
  bool used[n];
  for(int i=0;i<n;i++){
    used[i]=false;
  }
  long long paint[n];
  paint[0]=k;
  used[0]=true;
  for(size_t i=0;i<graph[0].size();i++){
    if(!used[graph[0][i]]){
      que.push(graph[0][i]);
      used[graph[0][i]]=true;
      paint[graph[0][i]]=k-i-1;
    }
  }
  while(!que.empty()){
    long long now=que.front(),cnt=2;
    que.pop();
    for(size_t i=0;i<graph[now].size();i++){
      if(!used[graph[now][i]]){
        que.push(graph[now][i]);
        used[graph[now][i]]=true;
        paint[graph[now][i]]=k-cnt;
        cnt++;
      }
    }
  }
  for(int i=0;i<n;i++){
    ans*=paint[i];
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9716
n,m = map(int,input().split())
l = list(input())
ll = [0 for i in range(n)]

for i in range(n-1):
    if l[i] == "A" and l[i+1] == "C":
        ll[i+1] += ll[i] + 1
    else:
        ll[i+1] += ll[i]
for i in range(m):
    a,b = map(int,input().split())
    k = ll[b-1] - ll[a-1]
    print(k)

Measured memory_bytes: 56568
import java.util.Scanner; 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        int newSum = 0;
        int orgSum = 0;
        for( char ch : n.toCharArray()) {
            orgSum += ch -'0';
        }
        newSum = (n.charAt(0) - '0' )-  1;
        for( int i =1; i < n.length(); i++) {
            newSum += 9;   
        }
        System.out.println(Math.max(newSum, orgSum));
    }
}

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

using namespace std;

const int DIV = 1000000007;

void solve(int test, istream &in) {
    int n;
    in >> n;
    n = n % 10;
    string result = "hon";
    if (n == 3) {
        result = "bon";
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8) {
        result = "pon";
    }
    printf("%s\n", result.c_str());
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
	return 0;
}



Measured memory_bytes: 3624
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let gcd x y =
    let rec aux x y = if y = 0L then x else aux y (x % y)
    aux (abs x) (abs y)

let lcm x y = if x = 0L || y = 0L then 0L else abs ((x / (gcd x y)) * y)

[<EntryPoint>]
let main _ =
    let [a;b;c;d] = reads int64
    let n = b - a + 1L
    let ca = (a + c - 1L) / c
    let cb = b / c
    let da = (a + d - 1L) / d
    let db = b / d
    let e = lcm c d
    let ea = (a + e - 1L) / e
    let eb = b / e

    let cc = cb - ca + 1L
    let dd = db - da + 1L
    let ee = eb - ea + 1L

    printfn "%i" (n - (cc + dd - ee))
    0

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

int main()
{
  const int INF = 1e9 + 10;
  int N; cin >> N;
  int tmp = INF;
  int ans = 0;
  for (int i = 0; i < N-1; i++)
  {
    int B; cin >> B;
    ans += min(tmp, B);
    tmp = B;
    if (i == N - 2) ans += B;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc126e()
}

fun abc126e() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val xyzList = (1..m).map { readLine()!!.split(' ').map { it.toInt() - 1 } }

    val uf = UnionFind(n)
    xyzList.forEach { uf.unite(it[0], it[1]) }

    val answer = (0 until n).map { uf.root(it) }.distinct().count()

    println(answer)
}

private class UnionFind(initSize: Int) {
    private val parent = IntArray(initSize) { it }
    private val size = LongArray(initSize) { 1L }

    fun root(x: Int): Int {
        if (x == parent[x]) return x

        val xr = root(parent[x])
        parent[x] = xr
        return xr
    }

    fun unite(x: Int, y: Int) {
        val xr = root(x)
        val yr = root(y)
        if (xr == yr) return

        if (size[xr] >= size[yr]) {
            size[xr] += size[yr]
            parent[yr] = xr
        } else {
            size[yr] += size[xr]
            parent[xr] = yr
        }
    }

    fun isSame(x: Int, y: Int): Boolean = root(x) == root(y)

    fun size(x: Int): Long = size[root(x)]
}


Measured memory_bytes: 67772
#include <iostream>
#include <map>

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

    unsigned long long res = 0ull;
    for (const auto mm: m) {
        if (mm.first > mm.second) {
            res += mm.second;
        } else {
            res += (mm.second - mm.first);
        }
    }

    std::cout << res << std::endl;
    return 0;
}

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

int main() {
	// your code goes here

	int n;
	cin>>n;
	int a[n+1];
	int b[n];

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

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

	long long ans=0;
	for(int i=0;i<n;i++)
	{
		 int temp=max(a[i] - b[i] , 0 );
		 b[i] -= a[i]-temp;
		 ans+=a[i]-temp;
		 a[i] = temp; 


		temp=max(a[i+1] - b[i] , 0 );
		b[i] -= a[i+1]-temp;
		ans+=a[i+1]-temp;
		a[i+1] = temp; 
	}
	
	cout<<ans<<endl;

	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - CODEFESTIVAL 2016
            var s = Console.ReadLine();

            Console.WriteLine(s.Substring(0, 4) + " " + s.Substring(4, 8));
        }
    }
}

Measured memory_bytes: 11092