akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)

using namespace std;
int main()
{
    int N, M, X=0;
    cin >> N >> M >> X;
    vector<vector<int>> A(N);
    vector<int> C(N);
    REP(i, N)
    {
        cin >> C[i];
        vector<int> m(M);
        REP(j, M)
        {
            cin >> m[j];
        }
        A.insert(A.begin() + i, m);
    }
    int max = pow(2,N);
    vector<int> test(N, 0);
    int ans = -1;
    REP(i, max)
    {
        REP(j, N)
        {
            if (test[j] == 0)
            {
                test[j] = 1;
                break;
            }
            else
            {
                test[j] = 0;
            }
        }
        vector<int> x(M, 0);
        // REP(j,N){
        //     cout << test[j];
        // }
        // cout << endl;
        // REP(j,N){
        // REP(k,M){
        //     cout << x[k] << endl;;
        //     cout << A[j].size() << endl;
        //     cout << A[j][k] << endl;
        // }

        // }
        int cost = 0;
        REP(j, N)
        {
            if (test[j] == 1)
            {
                REP(k,M){
                    x[k] += A[j][k];
                }
                cost += C[j];
            }
        }
        if (all_of(x.begin(), x.end(), [X](int z) { return z>=X; }))
        {
            if (ans == -1 || ans > cost)
                ans = cost;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

bool check(list<char>::iterator it){
    char a[6] = {"mmewe"};
    char b[6] = {"emeww"};
    auto temp = it;
    bool f = true;

    rep(i,5){
        //cout << *it << a[i] << endl;
        if(*it != a[i]) f = false;
        it++;
    }
    if(f) return 1;

    f = true;
    it = temp;
    rep(i,5){
        //cout << *it << b[i] << endl;
        if(*it != b[i]) f = false;
        it++;
    }
    return f;
}

bool mew(list<char>::iterator it){
    char a[6] = {"mew"};

    rep(i,3){
        //cout << *it << a[i] << endl;
        if(*it != a[i]) return 0;
        it++;
    }
    return 1;


}

int main(){
    list<char> ls;
    char c;
    while(cin >> c){
        ls.push_back(c);
    }

    rep(i,600){
        //if(i == 1) break;
        for(auto it = ls.begin(); it != ls.end(); it++){
            if(check(it)){
                it++;
                rep(i,3) it = ls.erase(it);
                it++;
            }

            //for(auto c = ls.begin(); c != ls.end(); c++) cout << *c; cout << endl;
        }
    }

    auto it = ls.begin();
    if(ls.size() == 3 && mew(it)) cout << "Cat" << endl;
    else cout << "Rabbit" << endl;

}

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    long long int ans = 0;
    for( int i = 1; i < N+1; ++i ){
        long long int tmp = 0;
        for( int j = i; j != 0; j/=10 ){
            tmp += j % 10;
            if( B < tmp ) break;
        }
        if( A <= tmp && tmp <= B ) ans += i;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int Nmax = 2005;

bool used[Nmax];
vector<int> ans, v[Nmax];
int i, j, n, a[Nmax];

void Merge(vector<int> &b, vector<int> c, bool ok)
{
    int q = 0, p = 0;
    vector<int> a;

    if(ok) a.push_back(b[0]), p = 1;

    while(p < b.size() && q < c.size())
        if(b[p] > c[q]) a.push_back(b[p++]);
            else a.push_back(c[q++]);

    while(p < b.size()) a.push_back(b[p++]);
    while(q < c.size()) a.push_back(c[q++]);
    b = a;
}

vector<int> dfs(int node)
{
    used[node] = 1;
    vector<int> a;

    a.push_back(node);
    for(auto it : v[node])
        if(!used[it])
            Merge(a, dfs(it), 1);
    return a;
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

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

    sort(a+1, a+n+1);

    for(i=1; i<=n; ++i)
        for(j=i+1; j<=n; ++j)
            if(__gcd(a[i], a[j]) > 1)
                v[i].push_back(j), v[j].push_back(i);

    for(i=1; i<=n; ++i)
        if(!used[i])
            Merge(ans, dfs(i), 0);

    for(i=0; i<n; ++i) cout << a[ans[i]] << ' ';

    return 0;
}


Measured memory_bytes: 17792
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if(n<=k) {
    cout << n*x << endl;
  }
  else {
    cout << k*x+(n-k)*y << endl;
  }
}

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

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  int d = a * 100 + b * 10 + c;
  if (d % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
 
/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1619&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
  
 ================================================================
 */
 
ll n,m;
 
string b[505];
 
// n <= 20 , 25 <= m <= 500
bool ok[501];
 
// 25 <= n <= 500, m <= 20
int bit[501];
int dp[2][1<<22];
 
int solve(){
    int res = 0;
    for(int i = 0; i < n;i++) cin >> b[i];
    if(n <= m){ // n <= 20 , 25 <= m <= 500
        for(int i = 0; i < (1<<n);i++){
            if(res >= __builtin_popcount(i)) continue;
            fill(ok,ok+501,false);
            for(int j = 0; j < n;j++){ // n <= 20
                if(!((i>>j)&1)) continue;
                for(int k = 0; k < m;k++){ // m <= 500
                    if(b[j][k] == '1') ok[k] = !ok[k];
                }
            }
            if(accumulate(ok,ok+m,0)) continue;
            res = max(res,__builtin_popcount(i));
        }
    }else{ // 25 <= n <= 500, m <= 20
        fill(bit,bit+n,0);
        for(int i = 0; i < n;i++){
            for(int j = 0; j < m;j++){
                if(b[i][j] == '1'){
                    bit[i] |= (1<<j);
                }
            }
        }
        for(int i = 0; i < 2;i++) for(int j = 0; j < (1<<m);j++) dp[i][j] = -1;
        dp[0][0] = 0;
        int cur = 0, next = 1;
        for(int i = 0; i < n;i++){
            for(int j = 0; j < (1<<m);j++){
                if(dp[cur][j] == -1) continue;
                dp[next][j] = max(dp[next][j],dp[cur][j]);
                dp[next][j^bit[i]] = max(dp[next][j^bit[i]],dp[cur][j]+1);
                 
                dp[cur][j] = -1;
            }
            swap(cur,next);
        }
        res = dp[cur][0];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> m,n){
        cout << solve() << endl;
    }
    return 0;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

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

    int ans = a*b;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
N,K=map(int, input().split())
p = list(map(int, input().split()))

s=sum(p[0:K])
d=0
e=0
for i in range(N-K):
  d+=p[i+K]-p[i]
  if d>e:
    e=d
s+=e
print((s+1*K)/2)

Measured memory_bytes: 24556
#include <stdio.h>
#include <string.h>

int main (void) {
    int n, m, i, j, tmp = 0, x = 0;
    char s[100][11], t[100][11];

    scanf("%d", &n);
    for (i = 0; i < n; ++i) {
        scanf("%s", s[i]);
    }
    scanf("%d", &m);
    for (i = 0; i < m; ++i) {
        scanf("%s", t[i]);
    }

    for (i = 0; i < n; ++i) {
        tmp = 0;
        for (j = 0; j < n; ++j) {
            if(strcmp(s[i], s[j]) == 0) {
                tmp++;
            }
        }
        for (j = 0; j < m; ++j) {
            if (strcmp(s[i], t[j]) == 0) {
                tmp--;
            }
        }
        if (tmp > x) x = tmp;
    }

    printf("%d\n", x);
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define fi first
#define se second
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define out(t, a) copy(all(a), ostream_iterator<t>(cout, " ")); cout << "\n";
// #define DEBUG
#define int long long

using namespace std;

void set_program() {
	#ifdef DEBUG
		freopen ("test.in", "r", stdin);
		freopen ("test.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pt;

const int INF = 1e9 + 1;
const int MAXN = 3000;
const int LOGN = 20;
const int MOD = 1e7;
const int ALF = 26;

void solve() {
	string s;
	cin >> s;
	string pref = "", suff = "";
	int m;
	cin >> m;
	bool flag = 0;
	for (; m--; ) {
		int type;
		cin >> type;
		if (type == 1) {
			flag ^= 1;
		} else {
			int f;
			string c;
			cin >> f >> c;
			--f;
			if (f ^ flag == 1) {
				suff += c;
			} else {
				pref += c;
			}
		}
	}
	reverse(all(pref));
	string ans = pref + s + suff;
	if (flag) {
		reverse(all(ans));
	}
	cout << ans << "\n";
}

main() {
	set_program();
	int t;
	#ifdef DEBUG
		// cin >> t;
		t = 3;
	#else
		// cin >> t;
		t = 1;
	#endif
	for (; t--; ) {
		solve();
		cout << "\n";
	}
 	return 0;
}

Measured memory_bytes: 1300
while 1:
    n,m=list(map(int,input().split()))
    if n==0 and m==0:break
    l=list(range(1,1+n))
    st=m-1
    while len(l)!=1:
        del l[st]
        st+=(m-1)
        while 1:
            if st>=len(l):
                st=st-len(l)
            if st<len(l):break  
    print(l[0])



Measured memory_bytes: 5592
import sys
input = sys.stdin.readline


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


def main():
    Q = int(input())
    is_prime, table = sieve(100000)
    N = []
    for p in table:
        if is_prime[(p+1)//2 - 1]:
            N.append(p)
    
    for _ in range(Q):
        l, r = map(int, input().split())
        cnt = 0
        for n in N:
            if l<=n and n<=r:
                cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 56132
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, d) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    println!("{}", (n + 2 * d) / (2 * d + 1))
}


Measured memory_bytes: 4352
import numpy

S = input()
isContinue = True

for i in range(0, len(S), 2):
    if isContinue and S[i] not in ['R', 'U', 'D']:
        print('No')
        isContinue = False

for i in range(1, len(S), 2):
    if isContinue and S[i] not in ['L', 'U', 'D']:
        print('No')
        isContinue = False

if isContinue:
    print('Yes')


Measured memory_bytes: 12508
N, K = map(int, input().split())
H = tuple(map(int, input().split()))

table = [0] * N
for i in range(1, N):
    table[i] = min(abs(H[i] - H[j]) + table[j] for j in range(max(0, i - K), i))

print(table[N-1])


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define RLOOP(i, N) for (int i =(int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int k;
  string s;
  cin>>k>>s;
  int len=s.size();
  if(k>=len){
    cout<<s<<endl;
  }else{
    s.erase(k);
    s+='.';
    s+='.';
    s+='.';
    cout<<s<<endl;
  }

}


Measured memory_bytes: 3632
N = int(input())
str_h = list(map(str, input().split()))
h_list = []
for i in range(len(str_h)):
    h_list.append(int(str_h[i]))
count = 0

while h_list.count(0) != len(h_list):
    if h_list.count(0) == 0:
        h_list = list(map(lambda x: x-1, h_list))
        count += 1
    else:
        switch = []
        for i in range(len(h_list)):
            if h_list[i] == 0:
                switch.append(0)
            else:
                switch.append(1)
        if switch[0] == 1:
            j = 0
            while switch[j] == switch[j+1] and j < len(switch)-1:
                j += 1
            h_list[0:j+1] = list(map(lambda x: x-1, h_list[0:j+1]))
            switch[0:j+1] = list(map(lambda x: x-1, switch[0:j+1]))
            count += 1
        for i in range(len(switch)-1):
            if switch[i] == 0 and switch[i+1] == 1:
                count += 1            
        for i in range(len(switch)):
            h_list[i] -= switch[i]
print(count)

Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    };
    a.sort_by_key(|a_i| -a_i);

    let mut ans = 0;
    let mut pq = std::collections::BinaryHeap::new();
    pq.push(a[0]);
    for i in 1..n {
        let a_i = a[i];
        ans += pq.pop().unwrap();
        pq.push(a_i);
        pq.push(a_i);
    }
    println!("{}", ans);
}


Measured memory_bytes: 7836
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    # N = 6
    # A = [-679, -2409, -3258, 3095, -3291, -4462]

    # N = 3
    # A = [3, 5, -1]

    # 始点を追加
    A = [0] + A
    A = A + [0]
    cum_map = dict()

    # for i in range(1, N + 1):
    #     cum_map[(i - 1, i)] = abs(A[i] - A[i - 1])

    cum_map[(0, 0)] = 0
    for k in range(1, N + 1):
        cum_map[(0, k)] = cum_map[(0, k - 1)] + abs(A[k] - A[k - 1])

    for i in range(1, N + 1):
        if i == 1:
            d = abs(A[i + 1] - A[0]) + cum_map[(0, N)] - cum_map[
                (0, i + 1)] + abs(A[N] - A[0])
        elif i == N:
            d = abs(A[N - 1] - A[0]) + cum_map[(0, N - 1)]
        else:
            d = cum_map[(0, i - 1)] + abs(A[N] - A[0]) \
                + abs(A[i + 1] - A[i - 1]) \
                + (cum_map[(0, N)] - cum_map[(0, i + 1)])
        # print("i:", d)
        print(d)

    # print(cum_map)


Measured memory_bytes: 28748
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 10];
map<int,int> mm;
int val[MAXN],A[MAXN],N,tot,ans;
int head[MAXN],sumE,dp[MAXN];
bool vis[MAXN];
int lowbit(int x) {
    return x & (-x);
}
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void Init() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
        read(A[i]);
        val[i] = A[i];
        mm[A[i]]++;
    }
    sort(val + 1,val + N + 1);
    tot = unique(val + 1,val + N + 1) - val - 1;
    for(int i = 1 ; i <= N ; ++i) {
        int a = val[i];
        int k = lower_bound(val + 1,val + tot + 1,a) - val;
        for(int64 t = 1 ; t <= 1073741824 ; t <<= 1) {
            if(t > 2 * a) {
                if(mm[t - a] == 0) continue;
                int h = lower_bound(val + 1,val + tot + 1,t - a) - val;
                add(k,h);
            }
        }
    }

}
void dfs(int u) {
    vis[u] = 1;
    dp[u] = mm[val[u]];
    for(int i = head[u] ; i ; i = E[i].next) {
        int v = E[i].to;
        if(!vis[v]) {
            dfs(v);
            int t = min(dp[u],dp[v]);
            dp[u] -= t;
            dp[v] -= t;
            ans += t;
        }
    }
}
void Solve() {
    for(int i = 1 ; i <= tot ; ++i) {
        if(!vis[i]) dfs(i);
        if(lowbit(val[i]) == val[i]) ans += dp[i] / 2;
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}

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

int main() {
  int S, W;
  cin >> S >> W;
  if (S <= W) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int p[105];
int x,n,t;
int main(){
	cin>>x>>n;
	for(int i=0;i<n;++i)
	{
		cin>>t;
		p[t]=1;
	}
	int min=1005,ans=0;
	for(int i=0;i<=101;++i)
	{
		if((!p[i])&&abs(i-x)<min)
		{
			min=abs(i-x);
			ans=i;
		}
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 3560
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    A,B,C = LMIIS()
    K = II()
    count = 0
    while A >= B:
        B *= 2
        count += 1
    while B >= C:
        C *= 2
        count += 1
    print('Yes' if count <= K else 'No')


    
main()

Measured memory_bytes: 65504
while True:
    H, W = map(int, input().split())
    if H==0 and W==0:
        break
    for x in range(H):
        for y in range(W):
            if (x+y) % 2 == 0:
                print('#', end='')
            elif (x+y) % 2 == 1:
                print('.', end='')
        print()
    print()



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

void Main()
{
    int k, n;
    cin >> k >> n;
    int a[n];
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    int d = a[0] + (k - a[n-1]);
    for(int i=0; i<n-1; ++i){
        int t = a[i+1]-a[i];
        if(d < t){
            d = t;
        }
    }
    
    cout << k - d << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

int n, m;

int main(){

    cin >> n >> m;
    if (n == 1 || m == 1) cout << 1;
    else if (n%2 == 0) cout << (long long)n*m/2;
    else cout << (long long)(n-1)/2*m + (m+1)/2;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

void check(vector<bool> &flag, int index, int &ans)
{
    flag.at(index) = true;
    int cnt = 2;
    for (long long i = 2; i * i <= (index + 1); i++)
    {
        if ((index + 1) % i == 0)
        {
            flag.at(i) = true;
            flag.at((index + 1) / i) = true;
            if (((index + 1) / i) == i)
            {
                cnt++;
            }
            else
            {
                cnt += 2;
            }

            if (cnt > 8)
            {
                break;
            }
        }
    }
    if (cnt == 8)
    {
        ans++;
    }
}

int check_all(int num)
{
    int ans = 0;
    vector<bool> flag(num, false);
    flag.at(0) = true;
    if (num % 2 == 0)
    {
        for (int i = 0; i < num / 2; i++)
        {
            flag.at(2 * i + 1) = true;
        }
    }
    else
    {
        for (int i = 0; i < (num - 1) / 2; i++)
        {
            flag.at(2 * i + 1) = true;
        }
    }
    bool flag_all = false;
    int index = num - 1;
    while (!flag_all)
    {
        if (!flag.at(index))
        {
            check(flag, index, ans);
            index--;
        }
        else
        {
            index--;
            continue;
        }

        int count = 0;
        for (int i = 0; i < num; i++)
        {
            if (flag.at(i) == true)
            {
                count++;
            }
        }
        if (count == num)
        {
            flag_all = true;
        }
    }
    return ans;
}

int main()
{
    int num, ans;
    cin >> num;
    ans = check_all(num);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include "iostream"
#include<stdio.h>
#include<cctype>
#include<string>
using namespace std;

int main()
{
	string a;
	int goukei = 0;
	int b = 0;
	while (1) {
		goukei = 0;
		getline(cin, a);
		if (a[0] == '0')break;
		for (int i = 0; a[i]; i++)
		{
			goukei+=(int)(a[i] - '0');
		}
		cout << goukei << endl;

	}
	return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N, M;
	cin >> N >> M;
	vector<bool> from_one(N, false);
	vector<bool> to_N(N, false);
	for (int i = 0; i < M; i++)
	{
		int A, B;
		cin >> A >> B;
		if (A == 1)
			from_one[B-1] = true;
		if (B == N)
			to_N[A-1] = true;
	}
	bool ans = false;
	for (int i = 0; i < N; i++)
	{
		if (from_one[i] && to_N[i])
			ans = true;
	}
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

char mp[55][55];
int d[55][55];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main(){

	REP(i,55)REP(j,55){
		mp[i][j] = '#';
		d[i][j] = INF;
	}
	d[1][1] = 0;
	ll ans = 0;

	int h,w;cin >> h >> w;
	REP(i,h)REP(j,w){
		cin >> mp[i+1][j+1];
		if(mp[i+1][j+1] == '#')ans++;
	}

	queue<pair<int,int>> q;
	q.push(MP(1,1));

	while(!q.empty()){
		auto now = q.front();q.pop();

		REP(i,4){
			int x = now.SE + dx[i];
			int y = now.FI + dy[i];
			if(mp[y][x] != '#' && d[y][x] > d[now.FI][now.SE] + 1){
				d[y][x] = d[now.FI][now.SE] + 1;
				q.push(MP(y,x));
			}
		}
	}

	SHOW2d(d,h+2,w+2);

	if(d[h][w] == INF){
		cout << -1 << endl;
	}
	else{
		cout << (h*w - ans - d[h][w] - 1) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void solve() {
    int a,b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
}

signed main() {
    solve();
    
    return 0;
}

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

int
main(void)
{
    int n, m, i, j, sum;
    int **arr;
    int *vector;

    scanf("%d %d", &n, &m);
    arr = (int **) malloc(sizeof(int *) * n);
    for (i = 0; i < n; i++)
        arr[i] = (int *) malloc(sizeof(int) * m);
    vector = (int *) malloc(sizeof(int) * m);

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            scanf("%d", *(arr + i) + j);
    for (i = 0; i < m; i++)
        scanf("%d", vector + i);
    
    for (i = 0; i < n; i++) {
        sum = 0;
        for (j = 0; j < m; j++)
            sum += arr[i][j] * vector[j];
        printf("%d\n", sum);
    }
    return 0;
}


Measured memory_bytes: 2104
#include "iostream"
using namespace std;
 
int main(){
 
 int N,K,d,A,ans=0;
  int box[101]={0};
  
  cin >> N >> K ;
  
  for(int i=1;i<=N;i++){
   
    box[i]=1;
    
  }
  
  for(int i=1; i<=K ;i++){
    
    cin >> d;
    
      for(int j=1; j<=d ;j++){
       cin >> A;
        box[A]=0;
      }

  }
  
  for(int i=1;i<=N;i++){
   
    ans+=box[i];
    
  }
  
  cout <<ans;
  
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

ll a[100010];
ll sum[100010];

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for (int i=0; i<=n; i++) cin>>a[i];
	for (int i=n; i>=0; i--){
		sum[i]=sum[i+1]+a[i];
	}
	sum[0]=1;
	for (int i=1; i<=n; i++){
		sum[i]=min((sum[i-1]-a[i-1])*2,sum[i]);
	}
	ll ans=0;
	for (int i=0; i<=n; i++){
//		dd(sum[i]),de(a[i]);
		if (sum[i]-a[i]<0 || (sum[i]!=a[i] && i==n)){
			cout<<-1;
			return 0;
		}
		ans+=sum[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5216
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector> 
using namespace std;
int main()
{
	int a[100],n,b,ans=2000000000;
	for (int i=0;i<100;i++) a[i]=2147483649;
	a[0]=2;a[1]=4;a[2]=8;a[3]=16;a[4]=32;a[5]=64;a[6]=128;a[7]=256;
	a[8]=512;a[9]=1024;a[10]=2048;a[11]=4096;a[12]=8192;a[13]=16384;
	a[14]=32768;a[15]=65536;a[16]=131072;a[17]=262144;a[18]=524288;
	a[19]=1048576;a[20]=2097152;a[21]=4194304;a[22]=8388608;
	a[23]=16777216;a[24]=33554432;a[25]=67108864;a[26]=134217728;
	a[27]=268435456;a[28]=536870912;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>b;int j=0;
		for (;b%a[j]==0;j++)
			if (b%10==1||b%10==3||b%10==5||b%10==7||b%10==9){
				ans=0;
				break;
			}
		ans=min(ans,j);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl;
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void solve1()
{
	int r;
	cin>>r;
	cout<<2*((double)(r))*(3.141592653589793238);
}
int main()
{
	fastio();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	solve1();
	return 0;

	
}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

int main() {
    int x;
    cin>>x;
    if(x<1200)
        cout<<"ABC"<<endl;
    else
        cout<<"ARC"<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DSumOfDivisors solver = new DSumOfDivisors();
        solver.solve(1, in, out);
        out.close();
    }

    static class DSumOfDivisors {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int m = (int) 1e7;
            int[] f = new int[m + 1];
            for (int i = 1; i <= m; i++) {
                for (int j = 1; i * j <= m; j++) {
                    f[i * j]++;
                }
            }
            long res = 0;
            int n = s.nextInt();
            for (int i = 1; i <= n; i++)
                res += (long) i * f[i];
            w.println(res);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

const ll N = (ll)(1e5);
const ll MOD = (ll)(1e9 + 7);

int main()
{
    FIO;
    
    ll a;
    string s;

    cin >> a >> s;

    if(a < 3200)
    {
        cout << "red";
    }
    else
    {
        cout << s;
    }
    


}


Measured memory_bytes: 256
import unittest

import collections


def solve(n, tree):
    cl = [0] * n
    visited = [False]*n
    stack = []
    stack.append((0, 0))
    while stack:
        v, c = stack.pop()
        if visited[v]:
            continue
        cl[v] = c
        visited[v] = True
        for nv, w in tree[v]:
            if visited[nv]:
                continue
            stack.append((nv, (c + w) % 2))

    return '\n'.join([str(c) for c in cl])


def main():
    n = int(input())
    tree = [[] for i in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        tree[v-1].append((u-1, w % 2))
        tree[u-1].append((v-1, w % 2))
    result = solve(n, tree)
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 44660
#include <stdio.h>
#include <ctype.h>

int main(void){
	char ch[1202]={0};
	int i=0,j=0;
	int a[26]={0};
	while(fgets(ch,sizeof(ch),stdin)!=NULL){
		i = 0;
	while(ch[i] != '\0'){
		j = tolower(ch[i]) - 'a';
		if(0<=j && j<=26) a[j]++;
		i++;
	}
	}
	for(i=0;i<26;i++){
	printf("%c : %d\n",i+'a',a[i]);
	}
	return 0;
}

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

using namespace std;
typedef pair<int, int> P;

struct edge {
    int t, c;
    edge(int t, int c): t(t), c(c) {}
};

const int INF = 1e9;
int n, u, k, v, c;
vector<edge> G[10000];
int d[10000];

void dijkstra(int s) {
    fill(d, d + n, INF);
    d[s] = 0;

    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.t] <= d[v] + e.c) continue;
            d[e.t] = d[v] + e.c;
            que.push(P(d[e.t], e.t));
        }
    }
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[u].push_back(edge(v, c));
        }
    }

    dijkstra(0);

    for (int i = 0; i < n; i++)
        cout << i << " " << d[i] << endl;

    return 0;
}


Measured memory_bytes: 7944
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	double a;
	cin >> a;

	int n, m;
	n = a / 1.08;
	m = (a + 0.999) / 1.08;

	if (a / 1.08 - double(n) == 0.0) {
		cout << n;
	}
	else if (n < m) {
		cout << m;
	}
	else {
		cout << ":(";
	}
}



Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())

an = []
for i in range(N):
    an.append(int(input()))

an_sorted = sorted(an, reverse=True)
an_max = an_sorted[0]
an_max_second = an_sorted[1]

for i in range(N):
    if an[i] != an_max:
        print(an_max)
    else:
        print(an_max_second)



Measured memory_bytes: 14112
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	here = 1
	patarrn = []
	dist = [0]*n
	while 1:
		here = a[here-1]
		if dist[here-1]:
			break
		dist[here-1] = 1
		patarrn.append(here-1)
	log.print(here, patarrn)
	b = patarrn.index(here-1)
	if k <= len(patarrn):
		print(patarrn[k-1]+1)
		exit()
	patarrn = patarrn[b:]
	log.print(patarrn, b, patarrn[(k-b) % len(patarrn) - 1])
	print(patarrn[(k-b) % len(patarrn) - 1]+1)


main()

Measured memory_bytes: 109664
#include<bits/stdc++.h>
using namespace std;
int main(){
    int b,m=0,a,tb,n,i;
    cin>>a>>tb;
    b=tb;
    while(tb!=0){
    	tb=tb/10;
    	m++;
	}
	for(i=1;i<=m;i++){
		a=a*10;
	}
	n=a+b;
	for(i=1;i*i<=n;i++){
		if(i*i==n){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool A[4];

int main()
{
  char ch;
  bool f = false;
  int N;
  int cnt = 0;

  cin >> N;

  while(N--)
  {
    cin >> ch;

    if ( ch == 'Y' ) f = true;
  }

  if ( f ) cout << "Four\n";
  else cout << "Three\n";
}


Measured memory_bytes: 256
n, k = map(int, raw_input().split())

"""
T = [0]*n
def f(a, b, c):
  if a==n-1:
    T[c+max(b-1, 0)] += 1
  else:
    for i in range(0, b+1):
      f(a+1, b-i, c+max(i-1, 0))
f(0, n, 0)
ans = sum(T[:k+1])
print ans
print T
"""

"""
[1]
[1, 2]
[1, 6, 3]
[1, 12, 18, 4]
[1, 20, 60, 40, 5]
[1, 30, 150, 200, 75, 6]
[1, 42, 315, 700, 525, 126, 7]
https://oeis.org/A132813
T(n,k) = (k+1)*binomial(n+1,k+1)*binomial(n+1,k)/(n+1), n>=k>=0.
"""

M = 10**9+7

F = [0]*(n+1)
F[0] = 1
for i in range(1, n+1):
  F[i] = F[i-1]*i%M

def C(x, y):
  return F[x]*pow(F[y], M-2, M)*pow(F[x-y], M-2, M)%M

ans = 0
for i in range(min(k+1, n)):
  ans += (i+1)*C(n, i+1)*C(n, i)*pow(n, M-2, M)%M
print ans%M


Measured memory_bytes: 17384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,a;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a;
    if(a%2==0&&a%5!=0&&a%3!=0){
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout<<"APPROVED"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;   
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    double a=0,b=0,c=0,d=0,n,m,k,ans=0;
    string s,s2;
    cin >> n;
    VI p(n);
    rep(i,n){
        cin >> p[i];
    }
    sort(ALL(p));
    for(int i=0;i<n-1;i++){
        d = (p[0] + p[1]) / 2.0;
        p[0] = 10000;
        p[1] = 10000;
        //cout << d <<endl;
        p.push_back(d);
        sort(ALL(p));
    }
    cout << p[0] <<endl;
    return 0;
}


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

using namespace std;

int n, v[102], maxx;

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (maxx < abs(v[i] - v[j]))
        maxx = abs(v[i] - v[j]);
  cout<< maxx;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}


//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let mut m:i64 = read();
    let mut d:Vec<(i64,i64)> = (0..n).map(|_| (read(), read())).collect();

    d.sort();
    let mut ans:i64 = 0;
    for &(a, b) in d.iter() {
        //debug!(a,b,ans,m);
        if m-b >= 0 {
            m -= b;
            ans += a*b;
        } else {
            ans += a*m;
            m = 0;
        }
        if m==0 {break}
    }

    println!("{}", ans);

}


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


typedef long long int ll;

int main(){
  string s,t;
  cin>>s>>t;
  ll i;
  ll flag=0;
  for(i=0;i<s.length();i++){
    if(s[i]!=t[i]){
      flag=1;
      break;
    }
  }
  if(flag){
    cout<<"No";
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3620
function Main(input) {
  var vals = input.trim().split(/\s+/).map(x => parseInt(x));
  var a = vals[0];
  var b = vals[1];
  var k = vals[2];
  
  if (k < a) {
    a -= k;
  } else if (k < a + b) {
    b = b - (k - a);
    a = 0;
  } else {
    a = 0;
    b = 0;
  }
  
  console.log('%d %d', a, b);
};
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    Integer F[][] = new Integer[N][10];
    Integer P[][] = new Integer[N][11];
    for(int i=0; i<N; i++){
      for(int j=0; j<10; j++){
        F[i][j] = sc.nextInt();
      }
    }
    for(int i=0; i<N; i++){
      for(int j=0; j<11; j++){
        P[i][j] = sc.nextInt();
      }
    }
    int ans = -INF;
    for(int i=1; i<(1<<10); i++){
      int tmp = 0;
      for(int k=0; k<N; k++){
        int count = 0;
        for(int j=0; j<10; j++){
          count += F[k][j] & (i>>j & 1);
        }
        tmp += P[k][count];
      }
      ans = Math.max(ans, tmp);
    }
    out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 28344
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define dbg(x) cout << #x"=" << x << endl; 
const int MAX_N = 1e5+100;
char s[MAX_N];
int a[MAX_N];
int cnt[MAX_N];

int main(){ 
   // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    memset(a, 0, sizeof a);
    memset(cnt, 0, sizeof cnt);
    cin >> (s+1);
    int n = strlen((s+1));
    vector<int> v[2];
    for(int i = 1; i <= n; ++i){
        int x = (s[i] == 'R' ? 0 : 1);
        if(x == 0) v[x].push_back(n+1-i);
        else v[x].push_back(i);
    }
    sort(v[0].begin(), v[0].end());
    for(int i = 1; i <= n; ++i){
        int x = (s[i] == 'R' ? 0 : 1);
        int val = i;
        if(x == 1) val = n+1-i;
        a[i] = *upper_bound(v[x^1].begin(), v[x^1].end(), val);
        if(x == 1) a[i] = n+1-a[i];
    }
    for(int i = 1; i <= n; ++i){
        if(abs(a[i]-i)&1){
            if(s[i] == 'R') cnt[a[i]-1]++;
            else cnt[a[i]+1]++;
        } else cnt[a[i]]++;
    }
    for(int i = 1; i <= n; ++i){
        cout << cnt[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1916
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int main(){
  string s, t; cin >> s >> t;
  string ans = "No";
  if(s == t){
    ans = "Yes";
  } else {
    for(int i = 0; i < s.size() -1; i++){
      s += s[0];
      s.erase(s.begin());
      if(s == t){
        ans = "Yes";
      }
    }
  }

  cout << ans << endl;
}


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

int main() {
  int A,B,AB,X,Y;
  cin >> A >> B >> AB >> X >> Y;
  int price=1000000001;
  for(int i=0;i<X+1;i++){
    int ab = (X-i)*2;
    int y = max(Y-ab/2,0);
    int x = i*A+y*B+ab*AB;
    price=min(price,x);
  }
  for(int i=0;i<Y+1;i++){
    int ab = (Y-i)*2;
    int y = max(X-ab/2,0);
    int x = i*B+y*A+ab*AB;
    price=min(price,x);
  }
  cout << price << endl;
}


Measured memory_bytes: 256