akhauriyash/Code-Regression huggingface dataset:
// AOJ 2412: Village
// 2017.12.8 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define HASHSIZ 400031
typedef struct { long long t; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;

int insert(int x, int y)
{
	long long t = ((long long)x << 32) | y;
	HASH *p = hash + (int)(t % HASHSIZ);

	while (p->t) {
		if (p->t == t) return 0;
		if (++p == hashend) p = hash;
	}
	p->t = t;
	return 1;
}

int lookup(int x, int y)
{
	long long t = ((long long)x << 32) | y;
	HASH *p = hash + (int)(t % HASHSIZ);

if (x <= 0 || y <= 0) printf("x %d, y %d, t %lld\n", x, y, t);
	while (p->t) {
		if (p->t == t) return 1;
		if (++p == hashend) p = hash;
	}
	return 0;
}

#define BASE 1000010
int ans;
int mv[8][2] = {{-1,0},{0,-1},{1,0},{0,1},{-1,-1},{-1,1},{1,1},{1,-1}};
char buf[30], *p;

int getdbl()
{
	int minus = 0;
	int n = 0;

	if (*p == '-') minus = 1, p++;
	while (*p >= '0') n = (n<<3)+(n<<1) + (*p++ & 0xf);
	if (*p == '.') p++;
	while (*p >= '0') n = (n<<3)+(n<<1) + (*p++ & 0xf);
	p++;
	if (minus) n = -n;
	return n;
}

int main()
{
	int n, r, x0, y0, x, y, i;

	fgets(p=buf, 30, stdin);
	n = atoi(p); while (*p >= '0') p++; p++;
	r = getdbl();
	while (n--) {
		fgets(p=buf, 30, stdin);
#if 0
		x0 = getdbl(), y0 = getdbl();
		if (x0 < 0) x = (x0+1)/r-1; else x = x0/r;
		if (y0 < 0) y = (y0+1)/r-1; else y = y0/r;
#else
		x = BASE+getdbl()/r, y = BASE+getdbl()/r;
#endif
		if (insert(x, y)) {
			for (i = 0; ; i++) {
				if (i == 8) { ans++; break; }
				if (lookup(x+mv[i][0], y+mv[i][1])) break;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4884
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int solve(string s){
    int res = 0;
    vector<vector<int> > dp(2, vector<int>(11, 0));
    for(int i=0; i<(int)s.size(); ++i){
        int k = s[i] - '0';
        dp[i & 1].assign(11, 0);
        for(int j=0; j<11; ++j)dp[i & 1][(10 * j + k) % 11] += dp[~i & 1][j];
        if(k)dp[i & 1][k]++;
        res += dp[i & 1][0];
    }
    return res;
}

int main(){
    for(string in; cin >> in, in != "0";)cout << solve(in) << '\n';
    return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

struct Work {
    ll t, limit;
    Work(ll t = 0, ll limit = 0) : t(t), limit(limit) {}
    bool operator<(const Work& w) const {
        return limit != w.limit ? limit < w.limit : t < w.t;
    }
};

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

    int n;
    cin >> n;

    vector<Work> ws(n);
    rep(i, 0, n) { cin >> ws[i].t >> ws[i].limit; }
    sort(all(ws));

    ll cnt = 0;
    for (Work w : ws) {
        if (cnt + w.t > w.limit) {
            cout << "No" << endl;
            return 0;
        }
        cnt += w.t;
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3456
using System;

class Program {
    static void Main() {
        string[] stdin = Console.ReadLine().Split();
        int a = int.Parse(stdin[0]);
        int b = int.Parse(stdin[1]);
        if(a < b) Console.WriteLine("a < b");
        else if(a > b) Console.WriteLine("a > b");
        else Console.WriteLine("a == b");
    }
}


Measured memory_bytes: 15948
N = int(input())
S = list(input())

ans = 0
for i in range(N):
  S_1 = set(S[:i+1])
  S_2 = set(S[i+1:])
  count = 0
  for s in S_1:
    if s in S_2:
      count += 1
  ans = max(ans, count)

print(ans)

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

typedef long long ll;

int main(){
    int n;
    while(cin >> n, n){
        ll p, sum = 0;
        for(int i = 0; i < n; i++)  cin >> p, sum += p;
        vector<int> j(n-1);
        for(int i = 0; i < n-1; i++)    cin >> j[i];
        sort(j.rbegin(), j.rend());
        ll ans = sum*n;
        for(int i = 0; i < n-1; i++){
            sum += j[i];
            ans = max(ans, sum*(n-i-1));
        }
        cout << ans << endl;
    }
    return 0;
}


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

int	get_pos_h(vector<int> &A, int v, int L, int H) {
	if (v<A.at(L))
		return L;
	if (v>=A.at(H))
		return -1;
	while (true) {
		int M=(H+L)/2;
		if (M==L)
			return H;
		if (v>=A.at(M))
			L=M;
		else
			H=M;
	}
}

int	get_pos_l(vector<int> &A, int v, int L, int H) {
	if (v<=A.at(L))
		return -1;
	if (v>A.at(H))
		return H;
	while (true) {
		int M=(H+L)/2;
		if (M==L)
			return L;
		if (v<=A.at(M))
			H=M;
		else
			L=M;
	}
}

int	main() {
	int N;
	cin >>N;
	vector<int> L(N);
	for (int i=0; i<N; i++)
		cin >>L.at(i);
	sort(L.begin(), L.end());
	long S=0;
	for (int i=0; i<L.size()-2; i++) {
		for (int j=i+1; j<L.size()-1; j++) {
			if (L.at(j)-L.at(i)>=L.back())
				break;
			/*
			for (int k=j+1; k<L.size(); k++) {
				if (L.at(k)<=L.at(j)-L.at(i))
					continue;
				if (L.at(k)>=L.at(i)+L.at(j))
					break;
				S++;
			}
			*/
			int PL=get_pos_h(L, L.at(j)-L.at(i), j+1, L.size()-1);
			if (-1==PL)
				continue;
			int PH=get_pos_l(L, L.at(j)+L.at(i), PL, L.size()-1);
			if (-1==PH)
				continue;
			S += max(0, PH-PL+1);
		}
	}
	cout <<S <<endl;
	return 0;
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
using namespace std;
using ll = long long;
using tiii = tuple<int, int, int>;

class UnionFind
{
    public:
        const int n;
        vector<int> rank;
        vector<int> parent;

        UnionFind(int num): n(num)
        {
            rep(i, 0, n)
            {
                rank.push_back(0);
                parent.push_back(i);
            }
        }

        int root(int x)
        {
            if (parent[x] == x)
                return x;
            else
                return parent[x] = root(parent[x]);
        }

        void unite(int x, int y)
        {
            x = root(x);
            y = root(y);

            if (x == y) return;

            if (rank[x] < rank[y])
                parent[x] = y;
            else if (rank[y] < rank[x])
                parent[y] = x;
            else
            {
                parent[x] = y;
                rank[y]++;
            }
        }

        bool is_same(int x, int y)
        {
            return root(x) == root(y);
        }
};

int main()
{
    int num_v, num_e; 
    cin >> num_v >> num_e;

    UnionFind uf_tree(num_v);

    priority_queue<tiii, vector<tiii>, greater<tiii>> edges;

    rep(i, 0, num_e)
    {
        int s, t, w;
        cin >> s >> t >> w;
        edges.push(make_tuple(w, s, t));
    }

    ll ans = 0;
    while(edges.size() > 0)
    {
        int s, t, w;
        tie(w, s, t) = edges.top();
        edges.pop();

        if (! uf_tree.is_same(s, t))
        {
            ans += w;
            uf_tree.unite(s, t);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4720
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

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

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long K) {
  ll ans = 1;
  REP(i,N){
    int dd = ans*2;
    int add = ans+K;
    ans = min(dd,add);
  }
  cout << (ans) << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N,K;
  cin >> N >> K;
  solve(N, K);
  return 0;
}


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

int main(void)
{
    int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));

    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    int perms = 1 << n;;
    int ans = 12345678;
    bool flag = true;
    for (int p = 0; p < perms; p++)
    {
        vector<int> level(m, 0);
        int cost = 0; flag = true;
        for (int i = 0; i < n; i++)
        {
            if ((p >> i) & 1)
            {
                cost += c[i];
                for (int j = 0; j < m; j++)
                {
                    level[j] += a[i][j];
                }
            }
        }
        for (int j = 0; j < m; j++)
        {
            if (level[j] < x) flag = false;
        }
        if (flag) ans = min(ans, cost);
    }
    if (ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main(){
    string a, b;
    cin >> a >> b;
    if(a.length() >  b.length()) cout << "GREATER" << endl;
    if(a.length() <  b.length()) cout << "LESS" << endl;
    if(a.length() == b.length()){
        if(a >  b) cout << "GREATER" << endl;
        if(a <  b) cout << "LESS" << endl;
        if(a == b) cout << "EQUAL" << endl;
    }
    return 0;
}

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

const int max_N = 1e5 + 21;

int n,m,ans,siz[max_N];

bool f[max_N];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)siz[i]=1;
	f[1]=1;
	while(m--){
		int x,y; scanf("%d%d",&x,&y);
		++siz[y],f[y]|=f[x];
		if(!--siz[x])f[x]=0;
	}
	for(int i=1;i<=n;++i)if(f[i])++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
#ifndef CLion
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/numeric>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define rep(i,s,e) for (int i = s; i < e; ++i)
#define rev(i,s,e) for (int i = s; i > e; --i)
#define mem(a,v) memset(a , v , sizeof a)
//#define mod(x,m) ((x%m + m)%m)
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

void Main(int cse , bool last){
    int n; cin >> n;
    vector<ll> vec(n);
    for ( ll& i : vec ) cin >> i;

    ll ans = 0;
    rep(i,1,n){
        if ( vec[i] < vec[i - 1] ){
            ans += (vec[i - 1] - vec[i]);
            vec[i] = vec[i - 1];
        }
    }
    cout << ans;
}

int main(){
#ifndef CLion
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
#ifdef CLion
    freopen( "in.txt" , "r" , stdin  );
//    freopen( "out.txt", "w" , stdout );
    clock_t st = clock();
#endif

    int t = 1;
//    cin >> t;
    for ( int cse = 1; cse <= t; ++cse ) Main(cse, cse == t);

#ifdef CLion
    clock_t en = clock();
    cout << "\n\nTime: " << fixed << (en - st - 0.0) / CLOCKS_PER_SEC;
#endif
    return 0;
}


Measured memory_bytes: 4692
#include<stdio.h>
#include<string.h>
#define LEN 100005

/*プロセスをあらわす構造体*/
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) {return a < b ? a : b;}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  /*すべてのプロセスをキューに追加する*/

  for(i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;

  /*シミュレーション*/
  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if( u.t > 0 ) enqueue(u);
    else{
      printf("%s %d\n",u.name, elaps);
    }
  }
}



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

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

    int res = 0;

    while (true) {
        bool exist_odd = false;
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;
        }

        if (exist_odd) break;

        for (int j = 0; j < N; ++j) {
            A[j] /= 2;
        }
        ++res;
    }

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


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

int main() {
    string s;
    cin >> s;
    int n=s.size();
    int ans=n;
    for ( int i=1; i<n; i++ ) {
        if ( s[i]!=s[i-1] ) {
            ans=min(ans,max(i,n-i));
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[3];
  for(int i=0;i<3;i++)
    cin>>a[i];
  if(a[1]=='B')
    a[1]='R';
  else
    a[1]='B';
  for(int i=0;i<3;i++)
    cout<<a[i];
  return 0;
}
       

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define REP(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,q,k;
vector<P>edge[100005];
ll cheat[100005];
void dfs(int v,int u,ll sum){
	cheat[v] = sum;
	REP(i,edge[v].size()){
		if(edge[v][i].fi == u) continue;
		dfs(edge[v][i].fi,v,sum+edge[v][i].sc);
	}	
}
int main(){
	cin >> n;
	REP(i,n-1){
		int a,b,c; scanf("%d%d%d",&a,&b,&c);
		edge[a].pb(mp(b,c));
		edge[b].pb(mp(a,c));
	}
	cin >> q >> k;
	dfs(k,-1,0LL);
	REP(i,q){
		int a,b; cin >> a >> b;
		cout << cheat[a]+cheat[b] << endl;
	}
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    string s, t;
    cin >> s >> t;
    for(int i=0; i<s.size(); i++){
        s[i] -= 'a';
    }
    for(int j=0; j<t.size(); j++){
        t[j] -= 'a';
    }
    // last['d'-'a'][i] は i 文字目より真に後に最初に 'd' が出てくる場所
    // 次のループに突入もする、-1 か i 以上かどっちか
    // last[x][0] != -1 <=> s に x がいる
    vector<vector<int>> last(26, vector<int>(s.size(), -1));

    for(int i=0; i<s.size(); i++){
        for(int j=i; j>=0 && last[s[i]][j] == -1; j--){
                last[s[i]][j] = i;
        }
    }
    for(int i=0; i<26; i++){
        if(last[i][s.size()-1] == -1 && last[i][0] != -1){
            last[i][s.size()-1] = s.size() + last[i][0];
            for(int j=s.size()-2; j>= 0 && last[i][j] == -1; j--){
                last[i][j] = last[i][j+1];
            }
        }
    }

    // あるかどうか
    for(int i=0; i<t.size(); i++){
        if(last[t[i]][0] == -1){
            cout << -1 << endl;
            return 0;
        }
    }


    // 最小
    int ans = -1;  // あほ
    for(int i=0; i<t.size(); i++){
        ans += last[t[i]][(ans+1) % s.size()] - ((ans+1) % s.size()) + 1;
    }

    cout << ans + 1 << endl;

    return 0;

}


Measured memory_bytes: 24612
string = [x for x in input()]
q = int(input())

for i in range(q):
    order_list = [x for x in input().split()]
    a = int(order_list[1])
    b = int(order_list[2])
    if order_list[0] == "print":
        print("".join(string[a:b+1]))
    elif order_list[0] == "reverse":
        rev = reversed(string[a:b+1])
        rev_s = list(rev)
        string = string[:a] + rev_s + string[b+1:]
    elif order_list[0] == "replace":
        replace_str = [x for x in order_list[3]]
        string = string[:a] + replace_str + string[b+1:]
    else:
        None


Measured memory_bytes: 5640
candys = STDIN.gets.chomp.split(' ').map(&:to_i)

if candys[0] == candys[1] + candys[2]
  puts 'Yes'
elsif candys[1] == candys[0] + candys[2]
  puts 'Yes'
elsif candys[2] == candys[0] + candys[1]
  puts 'Yes'
else
  puts 'No'
end



Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n,k;
    //freopen("input.txt","r",stdin);
    cin >> n>>k;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=1;i<n;i++){
        int count=0;
        for(int j=max(0,i-k);j<i;j++){
            //cout<<(++count)<<" inloop"<<" "<<i;
            dp[i] = min(dp[i],dp[j]+abs(v[i]-v[j]));
        }
        cout<<endl;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;



int main(){
    int n,a;
    vector<P> vec;
    map<P,int> m;
    int index = 1;
    string s;
    cin>>n;
    while(n--){
        cin>>s;
        cin>>a;
        P p = make_pair(s,a);
        vec.emplace_back(p);
        m.emplace(map<P,int>::value_type(p,index));
        index++;
    }
    sort(vec.begin(),vec.end(),[](P a,P b){return a.second > b.second;});
    P p;
    for(int i=0;i<vec.size();i++){
        p = vec[i];
        int ind = i;
        for(int j=i+1;j<vec.size();j++)
        {
            if(vec[j].first < p.first){
                p = vec[j];
                ind = j;
            }
        }
        for(int k = ind;k > i;k--)
            vec[k] = vec[k-1];
        vec[i] = p;
    }
    for(auto e : vec){
        cout<<m[e]<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
l=[]
l.append(a)
l.append(b)
l.append(c)
l.sort()

if l[0]==l[1]:
    if l[1]==l[2]:
        print("No")
    else:
        print("Yes")
elif l[0]!=l[1]:
    if l[1]==l[2]:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

			String inputLine;
			while ((inputLine = br.readLine()) != null) {

				final String[] inputs = inputLine.split(" ");

				final Integer H = Integer.valueOf(inputs[0]);
				final Integer W = Integer.valueOf(inputs[1]);

				if (H.equals(0) && W.equals(0)) {
					break;
				}

				StringBuilder output = new StringBuilder();

				for(Integer h = 0; h < H; h++) {
					for(Integer w = 0; w < W; w++) {
						if(0 < h && h < H - 1
								&& 0 < w && w < W - 1) {
							output.append(".");
						} else {
							output.append("#");
						}
					}
					output.append("\n");
				}
				System.out.println(output);
			}
		}
	}
}


Measured memory_bytes: 25152
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  multiset<int> A;
  int atmp;
  while (cin >> atmp) {
    A.insert(atmp);
  }

  int nr_of_pairs = 0;

  while (!A.empty()) {
    auto itr_max = --A.end();
    auto max = *itr_max;
    A.erase(itr_max);
    int i;
    for (i = 1; i <= max; i *= 2)
      ;
    if (A.find(i - max) != A.end()) {
      A.erase(A.find(i - max));
      ++nr_of_pairs;
    }
  }

  cout << nr_of_pairs << endl;
  return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d,n;
    cin>>d>>n;
    if(d==0)
    {
        if(n==100)
        {
            cout<<101<<endl;
            return 0;
        }
        cout<<n<<endl;
    }
    else if(d==1)
    {
        if(n==100)
        {
            cout<<10100<<endl;
            return 0;
        }
        cout<<n*100<<endl;
    }
    else if(d==2)
    {
        if(n==100)
        {
            cout<<1010000<<endl;
            return 0;
        }

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


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

int main()
{
    int n;
    cin >> n;
    vector<pair<int,int>> nums(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> nums[i].second >> nums[i].first;
    }
    sort(nums.begin(), nums.end());

    long long int sum = 0;
    bool result = true;
    for(pair<int,int> n: nums)
    {
        sum += n.second;
        if(sum > n.first)
        {
            result = false;
            break;
        }
    }

    cout << (result ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        int n;
        cin >> n;

        vector<int> a(n), c(n, 0);
        for (int i = 1; i < n; i++) {
                cin >> a[i];
                c[a[i] - 1]++;
        }

        rep (i, n) cout << c[i] << endl;

        return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p 1000000007
#define inf 1000000007

struct item{
    ll weight;
    int value;
};

int solve(int n,ll w,vector<item> &v)
{
    int max_value=n*1000;
    ll dp[n+1][max_value+1];
    
    
    for(int j=0;j<=max_value;j++)
    {
        dp[1][j]=inf;
    }
    dp[1][0]=0;
    // it simply means ki we are leaving it that is weight of the selected item is 0..
    dp[1][v[1].value]=v[1].weight;
    // it means ki directly uss item ko le lo aap...
    
    for(int i=2;i<=n;i++)
    {
        for(ll val=0;val<=max_value;val++)
        {
            ll option1=dp[i-1][val]; //simply leave it...
            ll option2=dp[i-1][val-v[i].value]+v[i].weight;
            
            dp[i][val]=min(option1,option2);
        }
    }
    int ans=0;
    for(int val=0;val<=max_value;val++)
    {
        if(dp[n][val]<=w)
        {
            ans=val;
        }
    }
    
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    ll w;
    cin>>w;
    
    vector<item> v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].weight>>v[i].value;
    }
    cout<<solve(n,w,v);
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
 
 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll A, B; cin >> A;
  bool judge = true;
REP(i, A){
  cin >> B;
  if(B%2 == 0){
    if(B%3 != 0&&B%5 != 0){
      judge = false;
      break;
    }
  }
}
if(judge) cout << "APPROVED";
else cout << "DENIED";
}

Measured memory_bytes: 3588
//#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cstdlib>

std::vector<std::string> split(const std::string &s, char delim) {
	std::stringstream ss(s);
	std::string item;
	std::vector<std::string> elems;
	while (std::getline(ss, item, delim)) {
		//std::cout << item << std::endl;
		elems.push_back(item);
	}
	return elems;
}

void swap(int &x,int &y){
	int tmp;
	tmp = x;
	x = y;
	y = tmp;
}

int main(int argc,char *argv[]){
	std::string s;
	std::getline(std::cin,s);
	//std::cout << s << std::endl;
	std::vector<std::string> A = split(s,' ');
	int A1 = atoi(A[0].c_str());
	int A2 = atoi(A[1].c_str());
	int A3 = atoi(A[2].c_str());
	//ascending order (A1>A2>A3)
	if(A1<A2) swap(A1,A2);
	if(A1<A3) swap(A1,A3);
	if(A2<A3) swap(A2,A3);
	std::cout << (A1-A3) << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);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 LOCAL 1
#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


//改造
typedef long long int ll;
using namespace std;


//ここから編集する



int main() {
    unsigned int N;
    cin >> N;
    vector<ll> v(3 * N);
    REP(i, 0, 3 * N) {
        cin >> v[i];
//        scanf("%d",&v[i]);
    }
    vector<ll> max_sum(N + 1);
    vector<ll> min_sum(N + 1);

//    priority_queue<int> max_q;
//    priority_queue<int, vector<int>, greater<int>> min_q;

    priority_queue<ll> min_q;
    priority_queue<ll, vector<ll>, greater<ll>> max_q;

    max_sum[0] = 0;
    REP(i, 0, N) {
        max_sum[0] += v[i];
        max_q.push(v[i]);
//        cout << max_q.top() << endl;
    }
    REP(i, 1, N + 1) {
        max_sum[i] = max_sum[i - 1] + v[N + i - 1];
//        max_q.push(v[i+N]);
        max_q.push(v[i + N - 1]);

        max_sum[i] -= max_q.top();
        max_q.pop();
    }

    min_sum[N] = 0;
    REP(i, 0, N) {
        min_sum[N] += v[2 * N + i];
        min_q.push(v[2 * N + i]);
    }
    for (int i = N - 1; i >= 0; i--) {
        min_sum[i] = min_sum[i + 1] + v[N + i];
        min_q.push(v[N + i]);
        min_sum[i] -= min_q.top();
        min_q.pop();
    }
    ll ret = max_sum[0] - min_sum[0];
    REP(i, 1, N + 1) {
        ret = max(ret, max_sum[i] - min_sum[i]);
    }
    cout << ret << endl;

    return 0;

}


Measured memory_bytes: 6516
a, b, q = gets.split.map(&:to_i)
s = []
t = []
z = []
a.times do
  s << gets.to_i
end
b.times do
  t << gets.to_i
end
q.times do
  z << gets.to_i
end

before_s = -10**100
before_t = -10**100 - 1

x = (s + t + z).sort
after_s = s.shift
after_t = t.shift

ans = {}

x.each do |i|
  if i == after_s || i == before_s
    before_s = after_s
    after_s = s.shift || 10**100
    next
  end

  if i == after_t || i == before_t
    before_t = after_t
    after_t = t.shift || 10**100 + 1
    next
  end

  if after_t > after_s
    d1 = after_t - i
  else
    d1 = after_s - i
  end

  if before_t < before_s
    d2 = i - before_t
  else
    d2 = i - before_s
  end

  if (i - before_s) < (after_t - i)
    d3 = (i - before_s) * 2 + (after_t - i)
  else
    d3 = (after_t - i) * 2 + (i - before_s)
  end

  if (i - before_t) < (after_s - i)
    d4 = (i - before_t) * 2 + (after_s - i)
  else
    d4 = (after_s - i) * 2 + (i - before_t)
  end

  ans[i] = [d1, d2, d3, d4].min
end


z.each do |i|
  puts ans[i]
end

Measured memory_bytes: 16720
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int W, H, N;
	cin >> W >> H >> N;

	struct Rect { int x, y, a; };
	vector<Rect> rect(N);
	for (int i = 0; i < N; i++) cin >> rect[i].x >> rect[i].y >> rect[i].a;

	int up = H, lo = 0, ri = W, le = 0;

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

		switch (rect[i].a) {
		case(1):
			le = max(le, rect[i].x);
			break;
		case(2):
			ri = min(ri, rect[i].x);
			break;
		case(3):
			lo = max(lo, rect[i].y);
			break;
		case(4):
			up = min(up, rect[i].y);
			break;
		}
	}

	if (up - lo < 0 || ri - le < 0) cout << 0;
	else cout << (up - lo) * (ri - le);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, M;

int main() {
	cin >> N >> M;
	if (N == M) {
		puts("Yes");
	}
	else {
		puts("No");
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
//aoj 0547
int MOD=100000;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		int dp[110][110][2]={0};
		dp[1][0][0]=dp[0][1][1]=1;
		rep(i,n)rep(j,m)if(i!=n-1||j!=m-1){
			if(dp[i][j][0]){
				dp[i+1][j][0]=(dp[i+1][j][0]+dp[i][j][0])%MOD;
				dp[i][j+2][1]=(dp[i][j+2][1]+dp[i][j][0])%MOD;
			}
			if(dp[i][j][1]){
				dp[i+2][j][0]=(dp[i+2][j][0]+dp[i][j][1])%MOD;
				dp[i][j+1][1]=(dp[i][j+1][1]+dp[i][j][1])%MOD;
			}
		}
		cout<<(dp[n-1][m-1][0]+dp[n-1][m-1][1]
			+dp[n][m-1][0]+dp[n-1][m][1])%MOD<<endl;
	}
}
//aoj 0596
/*vi visit,d;
vvi G;
void dfs(int a,int b){
	d[a]=b;
	rep(i,G[a].size()){
		int to=G[a][i];
		if(visit[to]==false&&d[to]>b+1){
			visit[a]=true;
			d[to]=b+1;
			dfs(to,b+1);
			visit[a]=false;
		}
	}
}
struct edge{
	int to,cost;
};
int main(){
	int n,m;
	cin>>n>>m;
	vp in(n);
	rep(i,n)cin>>in[i].first>>in[i].second;
	G=vvi(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	vector<vector<edge> > g(n);
	rep(i,n){
		visit=vi(n);
		d=vi(n,inf);
		visit[i]=true;
		dfs(i,0);
		rep(j,n)if(d[j]<=in[i].second)g[i].pb(edge{j,in[i].first});
	}
	d=vi(n,inf);
	d[0]=0;
	priority_queue<pii>q;
	q.push(pii(0,0));
	while(!q.empty()){
		pii p=q.top();
		q.pop();
		int pos=p.second,cost=-p.first;
		if(cost>d[pos])continue;
		rep(i,g[pos].size()){
			edge e=g[pos][i];
			int to=e.to;
			int nowcost=cost+e.cost;
			if(nowcost<d[to]){
				d[to]=nowcost;
				q.push(pii(-d[to],to));
			}
		}
	}
	cout<<d[n-1]<<endl;
}
*/



	

Measured memory_bytes: 1260
#include<bits/stdc++.h>
#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
using namespace std;
typedef long long ll;

int main(){
   string s;
   cin >> s;
   ll ans;
   ans = 15 - s.size();
   REP(i,0,s.size()){
       ans += (s[i] == 'o');
   }
   if(ans >=  8){
       cout << "YES" << endl;
   }else{
       cout << "NO" << endl;
   }
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc160/tasks/abc160_c
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;

void main() {
    int k, n;
    readf("%s %s", &k, &n);
    readln;

    int[] a = readln.split.map!(to!int).array;

    int[] dist;

    for(long i = a.length-1; i > 0; i--)
        dist ~= a[i]-a[i-1];
    dist ~= k-a[$-1]+a[0];

    sort(dist);
    sum(dist[0..$-1]).writeln;
}



Measured memory_bytes: 11704
n,y = map(int,input().split())

ans = 0
for i in range(2001):
    if ans != 0:
        break
    else:
        for j in range(2001-i):
            if (10000*i + 5000*j + 1000*(n-(i + j))) == y and ((n-(i + j)) >=0):       
                print(i,j,n-(i + j))
                ans +=1
            else:
                continue
                
if ans == 0:
    print('-1','-1','-1')

Measured memory_bytes: 3060
import decimal

N, K = map(int, input().split())

p = 1
times = 0
ans = 0

while N * 2 ** times < K:
    times += 1
p = 0.5 ** times

for i in range(N, 0, -1):
    if i * 2 ** times < K:
        times += 1
        p /= 2
    ans += p

print(decimal.Decimal(ans / N))


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

using std::vector;
    
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  std::cin >> n;

  std::string s = std::to_string(n);
  std::string ans = "ABC" + s;

  std::cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	}

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  if (M1==M2) cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
s=[int(s) for s in input()]
s_len = len(s)

ans=0
for pat in range(2**(s_len-1)):
    evalstr=str(s[0])
    pat=format(pat,'0'+str(s_len-1)+'b')
    for i in range(1,s_len):
        if pat[i-1]=="1":
            evalstr+="+"
        evalstr+=str(s[i])
    ans+=eval(evalstr)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
//using namespace std;
const int maxn = 105;

int S[maxn],top;

void initialize() {
    top = 0;
}

bool isEmpty() { return top==0; }

bool isFull() { return top==maxn-1; }

bool push(int x) {
    if (isFull()) return false;
    top++;
    S[top] = x;
    return true;
}

int pop() {
//    if (isEmpty()) return 0;
    top--;
    return S[top+1];
}

int main() {
//	freopen("input.txt","r",stdin);
/////////
    int a,b;
    char s[100];

    while (scanf("%s",&s) != EOF) {
        if (s[0]=='+') {
            b=pop();
            a=pop();
            push(a+b);
        }
        else if (s[0]=='-') {
            b=pop();
            a=pop();
            push(a-b);
        }
        else if (s[0]=='*') {
            b=pop();
            a=pop();
            push(a*b);
        }
        else {
            a=atoi(s);
            push(a);
        }
    }
    printf("%d\n",pop());
 //   if (!isEmpty()) printf("Error\n");
    return 0;
}

Measured memory_bytes: 2748
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) {
		
		//入力
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String work[]=new String[5];
		try {
			work=br.readLine().split("\\s+");
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		int W=Integer.parseInt(work[0]);
		int H=Integer.parseInt(work[1]);
		int x=Integer.parseInt(work[2]);
		int y=Integer.parseInt(work[3]);
		int r=Integer.parseInt(work[4]);
		
		//判定処理
		String judge;
		if((x-r)>=0 && (x+r)<=W){
			if(((y-r)>=0 && (y+r)<=H)) {
				judge="Yes";
			}else {
				judge="No";
			}
		}else {
			judge="No";
		}
		
		//出力
		System.out.println(judge);
	}

}



Measured memory_bytes: 24616
import java.io.PrintWriter;
import java.util.Scanner;


public class Main {

  private static final Scanner in = new Scanner(System.in);
  private static final PrintWriter out = new PrintWriter(System.out);

  private static int[] nextArray(int n) {
    int[] arr = new int[n];
    for (int i = 0; i < n; i++) {
      arr[i] = in.nextInt();
    }
    return arr;
  }

  public static void main(String[] args) {
    int a = in.nextInt();
    solve(a);
    out.flush();
    out.close();
  }

  private static void solve(int a) {
    int res = 0;
    for (int i = 1; i <= a; i++) {
      for (int j = 2; j < 10; j++) {
        if (Math.pow(i, j) <= a) {
          res = (int) Math.max(res, Math.pow(i, j));
        }
      }
    }
    if (res == 0) {
      res = a;
    }
    out.println(res);

  }
  
}

Measured memory_bytes: 21972
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();
        if (u.equals(s)) {
            System.out.println(--a + " " + b);
        } else {
            System.out.println(a + " " + --b);
        }
    }
}


Measured memory_bytes: 22356
N=int(input())
last = input()
wds = set([last])
res = "Yes"
for i in range(N-1):
    wd = input()
    if wd in wds or last[-1]!=wd[0]: 
        res = "No"
        break
    last = wd
    wds.add(wd)
print(res)

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int tarou_point = 0;
		int hanako_point = 0;
		
		for (int i = 0; i < n; i++){
		    String []words = sc.nextLine().split(" ");
		    char tarou[] = words[0].toCharArray();
		    char hanako[] = words[1].toCharArray();
		    int flag = 2;
		    
		    int length = hanako.length;
		    
		    if (tarou.length < hanako.length){
		        length = tarou.length;
		    }
		    
		    for (int l = 0; l < length; l++){
		        if (tarou[l] < hanako[l]){
		            flag = 0;
		            break;
		        }else if(tarou[l] > hanako[l]){
		            flag = 1;
		            break;
		        }
		    }
		    
		    if (flag == 0){
		        hanako_point += 3;
		    }else if(flag == 1){
		        tarou_point += 3;
		    }else{
		        if (tarou.length > hanako.length){
		            tarou_point += 3;
		        }else if (tarou.length < hanako.length){
		            hanako_point += 3;
		        } else{
		            hanako_point += 1;
		            tarou_point  += 1;
		        }
		        
		    }
		}
		
		System.out.println(tarou_point + " " + hanako_point);
	}
}


Measured memory_bytes: 30652
#include <stdio.h>

int main(void){

        int tmp = 0;
        int a,b;
        int sum = 0;

        scanf("%d %d",&a,&b);

        int c[a];

for(int i=0;i<a;i++){
        scanf("%d",&c[i]);
}



for(int i=0;i<a;i++){
        for(int j=0;j<a-1;j++){
                if(c[j]<c[j+1]){
                        tmp = c[j];
                        c[j] = c[j+1];
                        c[j+1] = tmp;
                }
        }
}

for(int i=0;i<b;i++){
        sum += c[i];
}

printf("%d\n",sum);
return 0;
}


Measured memory_bytes: 128
#include <map>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, x, a[100009];
int main() {
	cin >> n >> x;
	for (int i = 0; i < n; i++) cin >> a[i];
	long long ret = max(a[0] - x, 0); a[0] = min(a[0], x);
	for (int i = 1; i < n; i++) {
		if (a[i] > x - a[i - 1]) {
			ret += a[i] - (x - a[i - 1]);
			a[i] = x - a[i - 1];
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n+1, 0);
    REP(i, n){
        for(int j = i; j <= n; j += i)a[j]++;
    }
    ll ans = 0;
    REP(i, n){
        ans += a[i] * i;
    }
    cout << ans << endl;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s;

// < ----------- func eh ---------------- ? //


// <------------- Start of main() -------------------> //

void MAIN() {
	string a,b,c;
	cin>>a>>b>>c;
	ll i=0,j=0,k=0;
	ll turn = 0;

	while(1) {
		if(turn == 0) {
			if(i == a.size()) {
				cout<<"A";
				return;
			}
			else {
				if(a[i] == 'a') turn = 0;
				else if(a[i] == 'b') turn = 1;
				else turn = 2;
				i++;
			}
		}
		else if(turn == 1) {
			if(j == b.size()) {
				cout<<"B";
				return;
			}
			else {
				if(b[j] == 'a') turn = 0;
				else if(b[j] == 'b') turn = 1;
				else turn = 2;
				j++;	
			}
		}
		else {
			if(k == c.size()) {
				cout<<"C";
				return;
			}
			else {
				if(c[k] == 'a') turn = 0;
				else if(c[k] == 'b') turn = 1;
				else turn = 2;
				k++;
			}
		}
	}
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3596
/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>

#define N 100000
#define L 30

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int length(int n) {
	return n == 0 ? 0 : length(n / 2) + 1;
}

int main() {
	static int aa[L + 1][N], kk[L + 1];
	int n, m, h, i;
	long long ans;

	scanf("%d%d", &n, &m);
	while (n--) {
		int a;

		scanf("%d", &a);
		h = length(a);
		aa[h][kk[h]++] = a;
	}
	for (h = L; h > 0 && m > 0; h--)
		if (m >= kk[h]) {
			for (i = 0; i < kk[h]; i++) {
				int a = aa[h][i];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
			m -= kk[h];
			kk[h] = 0;
		} else {
			qsort(aa[h], kk[h], sizeof *aa[h], compare);
			while (m--) {
				int a = aa[h][--kk[h]];

				aa[h - 1][kk[h - 1]++] = a / 2;
			}
		}
	ans = 0;
	for (h = 1; h <= L; h++)
		for (i = 0; i < kk[h]; i++)
			ans += aa[h][i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 8828
import math
a,b,x=map(int,input().split())
height=x/(a*a)

y1=(2*a*height)/b   #これってbを固定した時の高さじゃ
if y1>a:#a*height=(b+y)*a/2<=>y=2height-b
    y1=b-(2*height-b)
    print(math.degrees(math.atan(y1/a)))
else:#a*height=b*y/2なるy<=>y=2*a*height/b
    print(math.degrees(math.atan(b/y1)))

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

typedef long long ll;

const int N = 50;
ll arr[N + 5];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b;
	cin>>a>>b;
	cout<<max(0, a - 2 * b)<<endl;
}

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

using namespace std;

int N,K;

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

    if(N%2)
    {
        if((N/2)+1<K)cout << "NO" <<  endl;

        else cout << "YES" << endl;
    }
    else 
    {
        if((N/2)<K)cout << "NO" <<  endl;

    else cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define rep(i, n) for(int i=0;i<(n);++i)
#define repp(i, a, b) for(int i=(a);i<=(b);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

void solve() {
	string s;cin >> s;
	int n = s.size()+1;
	vi ans(n, -1);
	rep(i,n) {
		if((i == 0 || s[i-1] == '>') && (i == n-1 || s[i] == '<')) {
			ans[i] = 0;
		}
	}
	rep(i, n) if(ans[i] == 0) {
		int k = 1;
		for(int j=i-1;j>=0&&s[j]=='>';j--) {
			ans[j] = max(ans[j], k);
			k++;
		}
		k = 1;
		for(int j=i+1;j<n&&s[j-1]=='<';j++) {
			ans[j] = max(ans[j], k);
			k++;
		}
	}
	ll res = 0;
	rep(i, n) {
		if(ans[i] == -1) {
			cout << "!";
			return;
		}
		res += ans[i];
	}
	cout << res;
}

int main() {
	fastio;
	solve();
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int n;
string s;

int main()
{
    cin >>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='9')
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
N=3*n
d=[[0]*(N+1) for i in range(N+5)]
d[0][0]=1
for i in range(N):
  a,b,c,e,*_=d[i:]
  for j in range(N):
    J=j+1
    b[j]=(b[j]+a[j])%m
    c[J]=(c[J]+a[j]*(i+1))%m
    e[J]=(e[J]+a[j]*(i+1)*(i+2))%m
print(sum(d[N][:n+1])%m)


Measured memory_bytes: 319752
#include<iostream>
using namespace std;
int main(){
  int k,x,a,b;
  scanf("%d %d",&k,&x);
  if(-1000000<x-k+1){
    a=x-k+1;
  }
  else{
    a=-1000000;
  }
  if(1000000>x+k-1){
    b=x+k-1;
  }
  else{
    b=1000000;
  }
  for(int i=a;i<b;i++){
  cout<<i<<" ";
  }
  cout<<b<<endl;
}

Measured memory_bytes: 256