akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

int N,A;
inline void solve(){
  IN2(N,A);
  OUT(N%500<=A?"Yes":"No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

int main(){
	int N;
	cin >> N;
	vector< long long > A(N);
  	long long result = 1;
  	for(int i=0;i < N;i++){
  		cin >> A.at(i);
    	if(A.at(i) == 0 || result ==0){
     		result = 0;
    	}else if(A.at(i) <= 1000000000000000000/result){
         	result *= A.at(i); 
        } else {
         	result = -1;
        }
  	}	
   	cout << result << endl; 
  	
}

Measured memory_bytes: 4044
#include <iostream>

using namespace std;

int bubblesort(int A[], int N) {
  int count = 0;
  int flag = 1;

  while (flag) {
    flag = 0;
    for (int i = N-1; i > 0; i--) {
      if (A[i] < A[i-1]) {
	swap(A[i], A[i-1]);
	flag = 1;
	count++;
      }
    }
  }
  
  for (int j = 0; j < N; j++) {
    if (j != N -1) cout << A[j] << " ";
    else cout <<A[j] << "\n";
 
  }

  cout << count << "\n";
}

int main() {
  
  int A[100];
  int N;

  cin >> N;

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

  bubblesort(A, N);
  return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.00000001
using namespace std;

struct Info{
	double r;
};

double*** dp;

void func(char buf[300]){

	double length;
	int tmp;

	int index;

	tmp = 0;
	for(index = 0;buf[index] != ' ' && buf[index] != '\0'; index++){
		tmp = 10*tmp + buf[index] - '0';
	}

	length = (double)tmp;

	Info info[15];
	int info_index = 0;

	while(buf[index] != '\0'){

		tmp = 0;
		for(++index;buf[index] != ' ' && buf[index] != '\0';index++){
			tmp = 10*tmp + buf[index] - '0';
		}
		info[info_index].r = (double)tmp;
		info_index++;
	}

	double sum = 0;

	for(int i = 0; i < info_index; i++){
		sum += info[i].r;
	}

	if(length > 2*sum+EPS){
		printf("OK\n");
		return;
	}

	double distance[info_index][info_index];

	for(int i = 0; i < info_index;i++){
		for(int k = 0; k < info_index; k++){
			if(i != k){
				distance[i][k] = sqrt((info[i].r+info[k].r)*(info[i].r+info[k].r)-(info[i].r-info[k].r)*(info[i].r-info[k].r)); //i??????k???
			}
		}
	}

	int limit = pow(2,info_index);


	double minimum = 4000.0;



	for(int i = 0; i <= info_index; i++){
		for(int k = 0; k < info_index;k++){
			for(int p = 0; p < limit; p++)dp[i][k][p] = 3000.0;
		}
	}

	int next_state;

	for(int i = 0; i < info_index;i++){
		next_state = pow(2,i);

		dp[0][i][next_state] = info[i].r;
	}

	for(int i = 1; i <= info_index-1; i++){
		for(int k = 0; k < info_index; k++){
			for(int state = 0; state < limit; state++){
				if(dp[i-1][k][state] < 2000.0){
					for(int a = 0; a < info_index; a++){
						if(state & (1 << a)){
							//Do nothing
						}else{
							next_state = state + pow(2,a);
							if(i != info_index-1){
								dp[i][a][next_state] = min(dp[i][a][next_state],dp[i-1][k][state]+distance[k][a]);
							}else{
								dp[i][a][next_state] = min(dp[i][a][next_state],dp[i-1][k][state]+distance[k][a]+info[a].r);
							}
						}
					}
				}
			}
		}
	}

	for(int i = 0; i < info_index; i++){
		minimum = min(minimum,dp[info_index-1][i][limit-1]);
	}

	if(minimum < length || fabs(minimum-length) < EPS){
		printf("OK\n");
	}else{
		printf("NA\n");
	}

}

int main(){

	dp = new double**[13];

	for(int i = 0; i < 13; i++){
		dp[i] = new double*[12];
		for(int k = 0; k < 12; k++){
			dp[i][k] = new double[4096];
		}
	}


	char buf[300];
	int index;
	char ch;

	while(true){
		index = 0;
		ch = getchar();

		if(ch == '\n' || ch == '\0' || ch == EOF)break;

		while(ch != '\n' && ch != '\0' && ch != EOF){
			buf[index++] = ch;
			ch = getchar();
		}
		buf[index] = '\0';
		func(buf);
	}

	return 0;
}

Measured memory_bytes: 8244
from collections import deque

S = deque(input())

Q = int(input())

c = False
for i in range(Q):
  *T, = map(str,input().split())
  if len(T) == 1:
    c = not c  
  elif (int(T[1]) == 1 and not c) or (int(T[1]) == 2 and c):
    S.appendleft(T[2])
  else:
    S.append(T[2])

print("".join(S) if not c else "".join(list(reversed(S))))    
    
  

Measured memory_bytes: 8692
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>

namespace {
    template<int n, typename T>
    void mult(const T *__restrict a, const T *__restrict b, T *__restrict res) {
        if (n <= 64) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    res[i + j] += a[i] * b[j];
                }
            }
        } else {
            const int mid = n / 2;
            alignas(64) T btmp[n], E[n] = {};
            auto atmp = btmp + mid;
            for (int i = 0; i < mid; i++) {
                atmp[i] = a[i] + a[i + mid];
                btmp[i] = b[i] + b[i + mid];
            }
            mult<mid>(atmp, btmp, E);
            mult<mid>(a + 0, b + 0, res);
            mult<mid>(a + mid, b + mid, res + n);
            for (int i = 0; i < mid; i++) {
                const auto tmp = res[i + mid];
                res[i + mid] += E[i] - res[i] - res[i + 2 * mid];
                res[i + 2 * mid] += E[i + mid] - tmp - res[i + 3 * mid];
            }
        }
    }
}

using ll = long long;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    const int NMAX = (1 << 11)*49;
    alignas(64) static ll a[NMAX], b[NMAX * 2];
    int n; ll k; std::cin >> n >> k;
    for (int i = 0, val; i < n; i++) {
        std::cin >> val;
        a[val]++;
    }
    mult<NMAX>(a,a,b);
    ll answ(0);
    for (int i = 2 * NMAX - 1; k > 0 && i >= 0; i--) {
        answ += std::min(k, b[i]) * i;
        k -= b[i];
    }
    std::cout << answ << std::endl;
    return 0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }

    vector<vector<char>> red(h, vector<char>(w));
    auto blue = red;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            red[i][j] = blue[i][j] = '.';

            if (i == 0) {
                red[i][j] = '#';
            } else if (i == h - 1) {
                blue[i][j] = '#';
            } else {
                if (j % 2) {
                    red[i][j] = '#';
                } else {
                    blue[i][j] = '#';
                }
            }

            if (a[i][j] == '#') {
                red[i][j] = blue[i][j] = '#';
            }
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << red[i][j];
        }
        cout << endl;
    }
    cout << endl;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << blue[i][j];
        }
        cout << endl;
    }
}

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

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

    long long min, max;
    max = (h % 2 == 1) ? h / 2 + 1 : h / 2;
    min = h / 2;

    long long cnt = 0;
    if (h == 1 || w == 1) {
        cnt = 1;
    } else if (w % 2 == 0) {
        cnt = (max + min) * (w / 2);
    } else {
        cnt = (max + min) * (w / 2) + max;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
int main(int argc, char *argv[]) {
  // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  ll n;
  cin >> n;
  string sol = "";
  ll p = 1;
  int len = 0;
  while (p <= n) {
    n -= p;
    p *= 26;
    len++;
  }

  for (int i = 0; i < len; i++) {
    sol += (char)(n % 26 + 'a');
    n /= 26;
  }

  reverse(ALL(sol));
  cout << sol << endl;
}

Measured memory_bytes: 3636
package main

import (
	"fmt"
	"io"
	"os"
)

const Mod = 1000000007

func main() {
	r := NewScannerSize(os.Stdin, 4096)
	h, w := r.Int(), r.Int()

	grid := make([]string, h)
	for i := 0; i < h; i++ {
		grid[i] = r.Text()
	}

	var dp [1001][1001]int
	dp[0][0] = 1

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] != '.' {
				continue
			}
			if i == 0 && j == 0 {
				dp[i][j] = 1
				continue
			}
			if i == 0 {
				dp[i][j] = dp[i][j-1]
				continue
			}
			if j == 0 {
				dp[i][j] = dp[i-1][j]
				continue
			}

			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % Mod
		}
	}

	fmt.Println(dp[h-1][w-1])
}

// generated by https://github.com/murosan/gollect

type Scanner struct {
	r     io.Reader
	buf   []byte
	delim byte
	size, eof,
	start, end int
}

func NewScannerSize(r io.Reader, size int) *Scanner {
	return &Scanner{
		r:     r,
		buf:   make([]byte, size),
		delim: ' ',
		size:  size, start: size, end: size,
	}
}

func (s *Scanner) Text() string { return string(s.bytes()) }

func (s *Scanner) Int() int { return ParseInt(s.bytes()) }

func (s *Scanner) bytes() []byte { b, _ := s.next(); return b }
func (s *Scanner) next() (b []byte, size int) {
	for n := 0; ; {
		for i := s.end; i < s.size; i++ {
			if s.buf[i] == s.delim || s.buf[i] == '\n' || i == s.eof {
				b, size = s.buf[s.start:i], i-s.start
				s.start, s.end = i+1, i+1
				return
			}
		}
		s.end = s.size
		if n++; n == 2 {
			panic("lack of buffer size")
		}
		s.read()
	}
}
func (s *Scanner) read() {
	copy(s.buf, s.buf[s.start:s.end])
	s.end -= s.start
	s.start = 0
	n, _ := s.r.Read(s.buf[s.end:])
	s.eof = s.end + n
}

func ParseInt(b []byte) (n int) {
	var i int
	if b[0] == '-' {
		i++
	}
	for ; i < len(b); i++ {
		n *= 10
		n += int(b[i] - '0')
	}
	if b[0] == '-' {
		return -n
	}
	return
}


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

int N;
long long A[123456];
long long ans;

int main(){
 
cin>>N;

for(int i=0; i<N; i++) scanf("%lld",&A[i]);

int m=0,j=0;

for(int i=0; i<N; i++){

	if(m==1&&A[i]>0){
		if(i>j+1){
			j=0; m=0;
		}
		else{
		ans++; A[i]--; m=0;
		}
	}
	if(A[i]%2==0){
		ans+=A[i]/2; 
	}else{
		ans+=A[i]/2;  j=i; m=1;
	}
}

cout<<ans<<endl;

return 0;
 
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 998244353;

li pow(li x, li n) {
    if (n == 0) {
        return 1;
    }
    if (n == 1) {
        return x;
    }

    li sq = pow(x, n / 2);
    if (n & 1) {
        return sq * sq % mod * x % mod;
    }
    return sq * sq % mod;
}

li inv(li x) {
    return pow(x, mod - 2);
}

li solve(li n, li a, li b, li k) {
    li g = __gcd(a, b);

    if (k % g != 0) {
        return 0;
    }

    a /= g;
    b /= g;
    k /= g;

    vector<li> facts(n + 1);
    facts[0] = 1;
    for (li i = 1; i <= n; ++i) {
        facts[i] = facts[i-1] * i % mod;
    }

    auto comb = [&](li x, li y) {
        if (y < 0 || y > x || x < 0) {
            return 0LL;
        }
        return facts[x] * inv(facts[y]) % mod * inv(facts[x - y]) % mod;
    };

    li ans = 0;
    for (li p = 0; p <= n; p++) {
        li v = k - p * a;
        if (v % b != 0) {
            continue;
        }
        li q = v / b;
        if (q < 0 || q > n) {
            continue;
        }
        ans += comb(n, p) * comb(n, q) % mod;
        ans %= mod;

    }

    return ans;
}

int main() {
    li n, a, b, k;
    cin >> n >> a >> b >> k;
    cout << solve(n, a, b, k) << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 10;
	x %= mod;
	return x;
}

int main(){
	int n;
	cin >> n;
	hei(int) a(n);
	int ans = 0;
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n - 1) {
		if (a[i] == a[i + 1]) {
			ans++;
			a[i+1] = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	int r , c;
	int arr[101][101]={0,0};
	cin >> r >> c;
	for(int i=0 ; i<r ; i++){
		for(int j=0 ; j<c ; j++){
			cin >> arr[j][i];
		}
	}
	for(int i=0 ; i<r ; i++){
		for(int j=0 ; j<c ; j++){
			arr[c][i]+=arr[j][i];
		}
	}
	for(int i=0 ; i<c ; i++){
		for(int j=0 ; j<r ; j++){
			arr[i][r]+=arr[i][j];
		}
	}
	for(int i=0 ; i<c ; i++){
		arr[c][r]+=arr[i][r];
	}
	for(int i=0 ; i<=r ; i++){
		for(int j=0 ; j<c ; j++){
			cout << arr[j][i] << " " ;
		}
		cout << arr[c][i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll h, n;
    cin >> h >> n;
    
    vl a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    
    vvl dp(n+1, vl(h+1, INF));  // dp[i+1][j] : i番目の魔法まででjダメージを与えるときの魔力の総和の最小値
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, h+1) {
            chmin(dp[i+1][j], dp[i][j]);
            if(j + a[i] <= h) {
                chmin(dp[i+1][j + a[i]], dp[i+1][j] + b[i]);
            }
            else {
                chmin(dp[i+1][h], dp[i+1][j] + b[i]);
            }
        }
    }
    
    out(dp[n][h]);
    re0;
}

Measured memory_bytes: 78592
k = int(input())
 
even_list = []
odd_list = []
 
is_odd = True
for i in range(1, k + 1):
    if is_odd:
        odd_list.append(i)
    else:
        even_list.append(i)
    is_odd = not is_odd
 
print(int(len(even_list) * len(odd_list)))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;



void solve() {

	
	int H, N;
	cin >> H >> N;
	if (H%N == 0) {
		int A = H / N ;
		cout <<A << endl;
	}
	else {
		int A = H / N + 1;
		cout << A << endl;
	}
	

}


int main() {
	solve();

}

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

using namespace std;

class Edge {
public:
    int source;
    int target;
    int weight;

    Edge(int s = 0, int t = 0, int w = 0) : source(s), target(t), weight(w) {};

    bool operator<(const Edge &e) const
    {
        return weight < e.weight;
    }
};

class DisjointSets {
private:
    vector<int> rank;
    vector<int> parent;

public:
    DisjointSets() {}

    DisjointSets(int size)
    {
        rank.resize(size, 0);
        parent.resize(size, 0);
        for (int i = 0; i < size; i++)
            makeSet(i);
    }

    void makeSet(int x)
    {
        rank[x] = 0;
        parent[x] = x;
    }

    int findSet(int x)
    {
        if (x != parent[x])
            parent[x] = findSet(parent[x]);
        return parent[x];
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int rep1, int rep2)
    {
        if (rank[rep1] < rank[rep2])
            parent[rep1] = rep2;
        else
        {
            parent[rep2] = rep1;
            if (rank[rep1] == rank[rep2])
                rank[rep1]++;
        }
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }
};

class MinimumSpanningTree {
private:
    DisjointSets S;
    vector<Edge> edges;

public:
    MinimumSpanningTree(int vertex_num, int edge_num)
    {
        S = DisjointSets(vertex_num);

        int s, t, w;
        for(int e = 0; e < edge_num; e++)
        {
            cin >> s >> t >> w;
            edges.push_back(Edge(s, t, w));
        }
    }

    void kruscal()
    {
        vector<Edge> K;
        sort(edges.begin(), edges.end());

        for(Edge edge : edges)
        {
            if(!S.same(edge.source, edge.target))
            {
                S.unite(edge.source, edge.target);
                K.push_back(edge);
            }
        }

        int sum = 0;
        for(Edge edge : K)
            sum += edge.weight;
        cout << sum << endl;
    }
};

int main()
{
    int vertex_num, edge_num;
    cin >> vertex_num >> edge_num;
    MinimumSpanningTree mst(vertex_num, edge_num);
    mst.kruscal();
}


Measured memory_bytes: 4576
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		int M; cin >> M;
		if (!M)break;
		vector<pair<int, int>>cards;
		for (int i = 0; i < M; ++i) {

			int a, b; cin >> a >> b;
			cards.emplace_back(a, b);
		}
		vector<vector<int>>dp(M + 1, vector<int>(10000));
		dp[0][0] = 1;
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < 9000; ++j) {
				for (int k = 0; k <= cards[i].second; ++k) {
					int plus = dp[i][j];
					for (int l = 0; l < k; ++l) {
						plus *= cards[i].second-l;
					}
					for (int l = 0; l < k; ++l) {
						plus /= l + 1;
					}
					dp[i + 1][j + k*cards[i].first] +=dp[i][j];
				}
			}
		}
		int G; cin >> G;
		for (int i = 0; i < G; ++i) {
			int n; cin >> n;
			cout << dp[M][n] << endl;
		}
	}
	return 0;
}

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

int main() {
	long n,k=0,l=0;
	cin>>n;
	long p[n];
	for(int i=0;i<n;i++)cin>>p[i];
	for(int i=0;i<n;i++){
		if(p[i]==i+1){
			k++;
			if(i==n-1)l+=(k+1)/2;
		}
		else{
			l+=(k+1)/2;
			k=0;
		}
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main()
{
	int n,l[4]={0};
	char b[3];
	while(scanf("%d,%s",&n,b)!=EOF){
		if(strcmp("A",b)==0){
			l[0]++;
		}else if(strcmp("B",b)==0){
			l[1]++;
		}else if(strcmp("AB",b)==0){
			l[2]++;
		}else{
			l[3]++;
		}
	}
	for(int i=0;i<4;i++){
		printf("%d\n",l[i]);
	}
	return 0;
}

Measured memory_bytes: 2628
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n;
  cin >> n;
  vvi tree(n);
  REP(i,n) {
    int u,k;
    cin >> u >> k;
    REP(j,k) {
      int v;
      cin >> v;
      tree[i].push_back(v-1);
    }
  }
  qi que;
  vi check(n,-1);
  que.push(0);
  check[0]=0;
  while(!que.empty()) {
    int x=que.front();
    int cnt=check[x];
    que.pop();
    for(auto i:tree[x]) {
      if(check[i]!=-1) continue;
      check[i]=cnt+1;
      que.push(i);
    }
  }
  REP(i,n) {
    cout << i+1 << " " << check[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m>>k;

    if(n+m+k>=22)cout<<"bust\n";
    else cout<<"win\n";

    return 0;
}


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

int cntDigits(ll x) {
    return log10(x) + 1;
}

int main() {
    ll n, ans = 1e9;
    cin >> n;
    
    for (ll a = 1; a * a <= n; a++) {
        if (n % a != 0) continue;
        ll b = n / a;
        ll cur = max(cntDigits(a), cntDigits(b));
        ans = min(ans, cur);
    }
    cout << ans << endl;
}

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

struct Combination {
    const lint MAX, MOD;
    vector<lint> fac, finv, inv;

    Combination(lint n, lint mod = 1e9 + 7) : MAX(n + 1), MOD(mod), fac(MAX), finv(MAX), inv(MAX) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for(lint i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    };

    lint perm(int n, int k) {
        if(n < k) {
            return 0;
        }
        if(n < 0 || k < 0) {
            return 0;
        }
        return (fac[n] * finv[n - k]) % MOD;
    }

    lint comb(lint n, lint k) {
        if(n < k)
            return 0;
        if(n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

V<lint> bfs(lint N, lint v0, VV<lint> edge) {

    V<lint> d(N, -1);
    d[v0] = 0;

    deque<lint> q;
    q.emplace_back(v0);

    while(not q.empty()) {
        lint v = q.front();
        q.pop_front();
        for(auto &&nv : edge[v]) {
            if(d[nv] == -1) {
                q.emplace_back(nv);
                d[nv] = d[v] + 1;
            }
        }
    }

    return d;
}

void solve() {
    lint N, K;
    cin >> N >> K;

    VV<lint> edge(N);
    rep(i, N - 1) {
        lint a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].emplace_back(b);
        edge[b].emplace_back(a);
    }

    auto d = bfs(N, 0, edge);

    VV<lint> dag(N);
    rep(i, N) {
        for(auto &&j : edge[i]) {
            if(d[i] < d[j]) {
                dag[i].emplace_back(j);
            }
        }
    }

    deque<lint> q;
    q.emplace_back(0);

    lint ans = K;
    auto comb = Combination(1e5);

    while(not q.empty()) {
        lint v = q.front();
        q.pop_front();

        if(d[v] == 0) {
            ans *= comb.perm(K - 1, dag[v].size());
            ans %= MOD;
        } else {
            ans *= comb.perm(K - 2, dag[v].size());
            ans %= MOD;
        }

        for(auto &&nv : dag[v]) {
            q.emplace_back(nv);
        }
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

Measured memory_bytes: 18228
#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define imax INT_MAX
#define imin INT_MIN
#define f(i,a,b) for(long long i=a;i<b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define tc long long test;cin>>test;while(test--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define up upper_bound
#define lo lower_bound
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long
#define umap unordered_map

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ll x;
    cin>>x;
    if(x==0) cout<<1<<endl;
    else if(x==1) cout<<0<<endl;

    return 0;
}

Measured memory_bytes: 3636
import sys
import math
sys.setrecursionlimit(1000000)


N = int(input())
K = int(input())

from functools import lru_cache

@lru_cache(maxsize=10000)
def f(n,k):
    # print('n:{},k:{}'.format(n,k))
    if k == 0:
        return 1
    if k== 1 and n < 10:
        return n

    keta = len(str(n))
    if keta < k:
        return 0

    h = n // (10 ** (keta-1))
    b = n % (10 ** (keta-1))

    ret = 0
    for i in range(h+1):
        if i==0:
            ret += f(10 ** (keta-1) - 1, k)
        elif 1 <= i < h:
            ret += f(10 ** (keta-1) - 1, k-1)
        else:
            ret += f(b,k-1)
        
    return ret

print(f(N,K))

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using eg = vector<vector<Edge>>;

vi color;
bool dfs(const vvi &graph, int v) {    // cur:現在の色
    for(auto u : graph[v]) {
        if(color[u] != -1) {
            if(color[u] == color[v]) return false;
            continue;
        }
        color[u] = 1 - color[v];
        if(!dfs(graph, u)) return false;
    }
    
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    // 2部グラフか否かを判定する
    int N, M;
    cin >> N >> M;
    vvi graph(N);
    REP(i, M) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        graph[u].push_back(v);
        graph[v].push_back(u);  
    }
 
    color.assign(N, -1);
    color[0] = 0;
    bool isBi = true;
    if(!dfs(graph, 0)) isBi = false;

    ll ans;
    if(!isBi) ans = (ll)N * (N - 1) / 2 - M;
    else {
        sort(color.begin(), color.end());
        ll count = upper_bound(color.begin(), color.end(), 0) - lower_bound(color.begin(), color.end(), 0);
        ans = count * (N - count) - M;
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int max=arr[0];
  long res=0;
  for(int i=1;i<n;i++)
  {
      if(arr[i]>max)
        max=arr[i];
      else
        res+=(max-arr[i]);
  }
  cout<<res;
}

Measured memory_bytes: 4372
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	long long n,i,k,ans;
	cin>>n;k=sqrt(n);ans=1;
	for(i=1;i<=k;i++)
	{
		if(n%i==0)ans=i;
	}
	k=n/ans;i=0;
	while(k)
	{
		i++;
		k/=10;
	}
	cout<<i;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int H, W; cin >> H >> W;
  int cnt = 0;
  char c;
  rep(i,H*W) {
    cin >> c;
    if (c=='#') cnt++;
  }
  if (cnt==H+W-1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 3596
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const double eps=1e-9;
inline ll read(){
	ll x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int main(){
	ll a,b,ans=0;
	a=read();b=read();
	while(a<=b)ans++,a<<=1ll;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
	int n,m;cin >> n>>m; cout<<(n-1)*(m-1);
	return 0;
	// Bye Bye 2019
}

Measured memory_bytes: 256
from collections import Counter
from itertools import permutations

def main():
    N, C = map(int, input().split())
    D = [[int(x) for x in input().split()] for _ in range(C)]

    cnt = [Counter() for _ in range(3)]

    for i in range(N):
        c = [int(x)-1 for x in input().split()]
        for j in range(3):
            cnt[j].update(c[(3-(i+2)+j)%3::3])

    ans = 1000*500*500+5
    for p in permutations(range(C), 3):
        s = 0
        for j in range(3):
            for k, v in cnt[j].items():
                s += D[k][p[j]] * v
        ans = min(ans, s)

    print(ans)

main()

Measured memory_bytes: 3436
n, m = map(int, input().split())
l = [0]*n

for _ in range(m):
    a, s = map(int, input().split())
    s = str(s)
    if n == 1 and (a==1 and s=="0"):
        l[0] = s
    elif (l[a-1] and l[a-1] != s) or (a==1 and s=="0"):
        l = [-1]
        break
    else:
        l[a-1] = s

num = "".join(map(str, l))

if num[0] == "0" and n != 1:
    print("1" + num[1:])
else:
    print(num)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
public class Main {
    static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static String line;
    static  int n,k,T,N,m;
    static StringTokenizer st;
    static Scanner in = new Scanner(System.in);
    static char [] word;
    public static void main(String[] args) throws IOException {
        line=br.readLine();
        for (int i=0;i<line.length();i++){
            if (line.charAt(i)=='A')
                k++;
            if (line.charAt(i)=='B')
                n++;
        }
        pw.println(n>0&&k>0?"Yes":"No");
        pw.flush();

    }
}

Measured memory_bytes: 23636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>
typedef long long ll;

using namespace std;

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

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll x = (a - 1 - (a - 1) % c) / c;
	ll y = (b - b % c) / c;
	ll w = (a - 1 - (a - 1) % d) / d;
	ll z = (b - b % d) / d;
	ll g = gcd(c, d);
	//cout << g << endl;
	ll l = c * d / g;
	ll r = (a - 1 - (a - 1) % l) / l;
	ll s = (b - b % l) / l;
	ll ans = y - x + z - w - (s - r);
	//cout << ans << endl;
	ans = b - a + 1 - ans;
	cout << ans << endl;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(true) {
        c -= b;
        if(c <= 0) {
            cout << "Yes" << endl;
            break;
        }

        a -= d;
        if(a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}

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

using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> a(M);
    vector<int> b(M);
    vector<long long> c(M);
    for (int i=0; i<M; i++)
        cin>>a[i]>>b[i]>>c[i],
        a[i]--, b[i]--;

    long long oo = 0x1000000000000000LL;
    vector<long long> d(N, -oo);
    d[0] = 0LL;
    long long d1, d2;
    for (int i=0; i<2*N; i++)
    {
        for (int j=0; j<M; j++)
            d[b[j]] = max(d[b[j]], d[a[j]] + c[j]);
        if (i==N-1)
            d1 = d[N-1];
        if (i==2*N-1)
            d2 = d[N-1];
    }
    if (d1 == d2)
        cout<<d1<<endl;
    else
        cout<<"inf"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 10000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
int  main()
{
    ll  n,a,b;
    cin>>n>>a>>b;
    if(a>b) swap(a,b);
    ll  d=min(b-1,n-a);
    if((b-a)%2==0) d=min(d,(b-a)/2);
    ll e=a+(b-a)/2;
    ll f=n-b+1+(b-a)/2;
    cout<<min(d,min(e,f))<<endl;

}


Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val Array(n, k) = readLine.trim.split(' ').map(_.toLong)
  val operations = Array.tabulate(n.toInt){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    (a, b)
  }.sortBy(_._1)
  val count = operations.map(_._2.toLong)
  for (i ← count.indices.tail) count(i) += count(i - 1)
  println(operations(lowerBound(count, k))._1)
  def lowerBound(array: Array[Long], target: Long): Int = {
    var left = 0
    var right = array.length
    while(left < right) {
      val mid = (left + right) / 2
      if (array(mid) < target) left = mid + 1
      else right = mid
    }
    right
  }
}

Measured memory_bytes: 72624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

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;
    int n=N/8,m=N%8;
    vector<int> v={2,3,4,6,8,9,10,12};
    rep(i,n){
        rep(j,8){
            cout << v[j]+12*i << ' ';
        }
    }
    rep(i,8){
        v[i]+=12*n;
    }
    if (m==1){
        cout << v[7] << endl;
    }
    else if (m==2){
        cout << v[0] << ' ' << v[2] << endl;
    }
    else if (m==3){
        if (N==3){
            cout << 2 << ' ' << 5 << ' ' << 63 << endl;
        }
        else {
            cout << v[0] << ' ' << v[2] << ' ' << v[3] << endl;
        }
    }
    else if (m==4){
        cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' << v[5] << endl;
    }
    else if (m==5){
        cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' << v[5] << ' ' << v[7] << endl;
    }
    else if (m==6){
        cout << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' << v[4] << ' ' << v[5] << ' ' << v[6] << endl;
    }
    else if (m==7){
        rep(i,m){
            cout << v[i];
            if (i!=m-1){
                cout << ' ';
            }
            else {
                cout << endl;
            }
        }
    }
    else {
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	string S;
	cin>>S;
	int ans = 0;
	for(int i=0;i<S.size();i++){
		if(S[i]=='+')ans++;
		else ans--;
	}
	
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
c(int*a,int*b){return*a-*b;}L[2001],i,j,k,s;main(){for(;~scanf("%d",L+k++););for(qsort(L+1,*L,4,"\x8b\7+\6Ð");i++<*L;)for(j=i;j++<*L;)for(k=j;k++<*L;)s+=L[k]<L[i]+L[j];printf("%d",s);}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll x;cin>>x;
    ll n = to_string(x).size();
    if(n < 3){
        cout << 0 << ednl;
        return 0;
    }
    ll num = x / 100;
  	ll mmod = x % 100;
    if(num*5 >= mmod) cout << 1 << ednl;
    else cout << 0 << ednl;
}


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

using namespace std;

int main(){

	int n;
	long long sum=0;
	while(cin>>n&&n!=0){
		sum=0;
		for(int i = 0; i < n; i++){
			int t;
			cin>>t;
			sum+=t;
		}
		cout<<sum/n<<endl;
	}

	return 0;
}

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

int main(){
  int d; cin >> d;
  if(d == 22){
    printf("%s", "Christmas Eve Eve Eve");
    return 0;
  }else if(d == 23){
    printf("%s", "Christmas Eve Eve");
    return 0;
  }else if(d == 24){
    printf("%s", "Christmas Eve");
    return 0;
  }else if(d == 25){
    printf("%s", "Christmas");
    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[210000];
int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(k<=a)cout<<k;
    else if(k>a&&k<=a+b)cout<<a;
    else cout<<a-min(c,k-a-b);
    
    
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  int n,i,j,a,b,c,d[100010],max=-1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
    for(j=0;j<i;j++){
      b=d[i]*d[j];
      c=b%10;
      for(b/=10;b;b/=10){
	if(b%10-c+1)break;
	c=b%10;
      }
      if(b==0&&max<d[i]*d[j])max=d[i]*d[j];
    }
  }
  printf("%d\n",max);
  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var N = ReadInt();
        var A = ReadLongs();
        Array.Sort(A);

        var nums = new HashSet<long> { A[0] };
        for (var i = 1; i < N; i++)
        {
            var d = A[i] % nums.Min();
            if (d == 1) { Console.WriteLine(1); return; }

            if (d != 0) nums.Add(d);
        }

        var min = nums.Min();
        nums.Remove(min);

        while (nums.Count >= 1)
        {
            var max = nums.Max();
            var r = max % min;

            nums.Remove(max);
            if (r != 0)
            {
                nums.Add(min);
                min = r;
            }

        }

        Console.WriteLine(min);
    }


    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}

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

int main(){
	int n;
	scanf("%d", &n);
	int x = 1;
	while(true) {
		x <<= 1;
		if(x > n) {
			x >>= 1;
			break;
		}
	}
	printf("%d\n", x);
}


Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Mon Mar 23 19:34:20 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, c = nas()

if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n;
	cin >> n;
	int arr[n];
	rep(i,0,n)
		cin >> arr[i];
	sort(arr,arr+n,greater<int> ());
	int j = 1;
	int ans = arr[0];
	rep(i,1,n-1)
	{
		ans+=arr[j];
		i++;
		if(i < n-1)
		ans+=arr[j];
		j++;
	}
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 5208
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
    return 0;
}

Measured memory_bytes: 256
import math

D, G = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(D)]

ans = float("inf")

for bit in range(1 << D):
    count = 0
    sum = 0
    rest = list(range(1, D+1))

    for i in range(D):
        if bit & (1 << i):
            sum += (i + 1) * pc[i][0] * 100 + pc[i][1]
            count += pc[i][0]
            rest.remove(i + 1)

    if sum < G:
        max_num = max(rest)
        n = min(pc[max_num - 1][0], math.ceil((G - sum) / (max_num * 100)))
        count += n
        sum += n * max_num * 100

    if sum >= G:
        ans = min(ans, count)

print(ans)


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

using namespace std;
typedef long long ll;

int main() 
{
	cin.tie(0);
	cin.sync_with_stdio(0); 
	ll q, h, s, d, n; cin >> q >> h >> s >> d >> n;
	ll min1liter = min(q * 4, min(h * 2, s));
	ll min2liter = min(q * 8, min(h * 4, min(s * 2, d)));
	ll ans = (n / 2 * min2liter) + (n % 2)*min1liter;
	cout << ans;
}


Measured memory_bytes: 256