akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> q;
  rep(i, N) {
    int ai;
    cin >> ai;
    q.push(ai);
  }

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

  ll ans = 0;
  rep(i, N) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  double b, p;
  cin >> N;
  b = (N + 1) / 2;
  p = b / N;
  
  if (N == 1) {
    cout << 1 << endl;
  }
  
  else if (N % 2 == 0) {
    cout << 0.5 << endl;
  }
  
  else if (N % 2 == 1) {
    cout << p << endl;
  }
}

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

int main(){
  int a, b, c, n;

  cin >> a >> b >> c;

  n = a;
  a = b;
  b = n;

  n = a;
  a = c;
  c = n;

  cout << a << " " << b << " " << c << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N ;
    cin >> N;
    
    vector<ll> ans;
    rep(i, sqrt(N+1) + 1){
        if(i == 0 ) continue;
        if( N % i == 0) {
            ll a = i;
            ll b = N/i;
            
            if(a > 2) ans .pb(a);
            if(b > 2)ans.pb(b);
        }
    }
    rmsame(ans);
    ll ret = 0 ;
    rep(i,ans.size()){
        ll a = ans[i] - 1 ;
        ll b = N/a;
        ll c = N%a;
        if(b==c)ret += a;
    }
    
    cout << ret << endl;
    
    

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

ll A, B, N;


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

    cin >> A >> B >> N;

    long double x = N;
    if (x >= B) x = B - 1;

    ll ans = 0;
    ans = floorl(x * A / B) - A * floorl(x / B);

    cout << ans << endl;
    
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int maxi = -1;
	map<string, int> mp;
	for(int i = 1; i <= n; ++i) {
		string s;
		cin >> s;
		++mp[s];
		maxi = max(maxi, mp[s]);
	}
	map<string, int> :: iterator it = mp.begin();
	vector<string> v;
	while(it != mp.end()) {
		if(it -> second == maxi)
			v.push_back(it-> first);
		++it;
	}
	for(string s : v)
		cout << s << '\n';
}


Measured memory_bytes: 27280
#include<cstdio>
#include<vector>


using namespace std;
using vc=vector<char>;
using vvc=vector<vc>;


void fill(vvc&ans, int ox, int oy, int ax, int ay, int s, int c)
{
	int w=ans[0].size();
	int h=ans.size();

	for(int i=0;i<s;i++)
	{
		int y=oy+ay*i;
		if(y<0 || h<=y) continue;

		for(int j=0;j<s-i;j++)
		{
			int x=ox+ax*j;
			if(x<0 || w<=x) continue;

			ans[y][x]=c;
			x+=ax;
		}
	}
}


void fill_big(vvc&ans, int ox, int oy, int d, int c)
{
	fill(ans, ox-1, oy-1, -1, -1, d/2-1, c);
	fill(ans, ox  , oy-1,  1, -1, d/2-1, c);
	fill(ans, ox-1, oy  , -1,  1, d/2  , c);
	fill(ans, ox  , oy  ,  1,  1, d/2  , c);
}


void solve(vvc&ans, int d)
{
	int h=ans.size();
	int w=ans[0].size();

	if(d%2)
	{
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				ans[y][x]="RG"[(x+y)%2];
			}
		}
		return;
	}

	for(int iy=0;iy<h;iy++)
	{
		int y=iy*d;
		for(int ix=0;ix<w;ix++)
		{
			int x=ix*d;
			fill_big(ans, x    , y    , d, "RG"[(ix+iy)%2]);
			fill_big(ans, x+d/2, y+d/2, d, "BY"[(ix+iy)%2]);
			if(x-d/2-1>w) break;
		}
		if(y-d/2-1>h) break;
	}
}


int main(void)
{
	int h, w, d;

	while(scanf("%d%d%d", &h, &w, &d)==3)
	{
		vvc ans(h);

		for(auto&anse:ans) anse.assign(w, '#');

		solve(ans, d);

		for(int y=0;y<h;y++)
		{
			printf("%.*s\n", w, &ans[y][0]);
		}
	}

	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    rep(i,0,n){
        rep(j,0,m){
            chmax(dp[i+1][j+1],max(dp[i+1][j],dp[i][j+1]));
            if(s[i]==t[j]){
                chmax(dp[i+1][j+1],dp[i][j]+1);
            }
        }
    }
    string res = "";
    while(n > 0 && m > 0){
        if(dp[n][m]==dp[n-1][m]) n--;
        else if(dp[n][m]==dp[n][m-1]) m--;
        else{
            res += s[n-1];
            n--; m--;
        }
    }
    reverse(all(res));
    cout << res << endl;
}

Measured memory_bytes: 35584
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
int n;
string s;
int main()
{
    cin>>s;
    rep(i,s.size())
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	fast();
	string s;
	cin>>s;
	if(s[2]==s[3] and s[4]==s[5])
		cout<<"Yes";
		else
		cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    ll s; cin >> s;
    ll y2 = ((ll) pow(s, 0.5));
    if (y2 * y2 < s) y2++;
    ll x2 = y2 * y2 - s;
    cout << 0 << " " << 0 << " ";
    cout << x2 << " " << y2 << " ";
    cout << y2 << " " << 1 << endl;
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
struct seg{
	LL a, k;
};
struct bug{
	LL a, b, c;
};

bool compa(const bug& x, const bug& y){
	return x.a < y.a; 
}
bool compb(const bug& x, const bug& y){
	return x.b > y.b; 
}


int n1, n2 = 1, n3;
seg seg1[1 << 20];
LL suma, sumk, lim;
LL ans;
vector<bug> ab;

bool segmax(int j){
	if(j > n3)return false;
	if(suma + seg1[j].a <= (sumk + seg1[j].k) * lim){
		suma += seg1[j].a;
		sumk += seg1[j].k;
		return true;
	}

	if(segmax(j * 2)) segmax(j * 2 + 1);

	return false;
}

int main(){

	cin >> n1;
	
	while(n2 < n1) n2 <<= 1;
	n3 = n2 * 2 - 1;
	
	for(int i = 0; i < n1; i++){
		LL tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		ab.push_back(bug{tmp1, tmp2, 0});
	}
	
	sort(ab.begin(), ab.end(), compa);
	for(int i = 0; i < n1; i++){
		ab[i].c = n2 + i; 
	}
	
	sort(ab.begin(), ab.end(), compb);
	for(int i = 0; i < n1; i++){
	
		seg1[ab[i].c].a = ab[i].a;
		seg1[ab[i].c].k = 1;
	
		int j = ab[i].c;
	
		while(j > 0){
			j >>= 1;
			seg1[j].a += ab[i].a;
			seg1[j].k++;
		}
		suma = 0, sumk = 0, lim = ab[i].b;
		segmax(1);
		ans = max(sumk, ans);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  vector<int> v(3);
  for (int i = 0; i < 3; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for (int i = 0; i < 2; i++) {
    sum += v[i + 1] - v[i];
  }
  cout << sum << endl;
}


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

int n, u, v, a[200000], d[200000];
vector<int> adj[200000];

vector<int> lis = {int(-1e9)};

void dfs(int u) {
    bool inserted = (a[u] > lis.back());
    int idx, replaced;
    if (inserted) {
        lis.push_back(a[u]);
    }
    else {
        auto it = lower_bound(lis.begin(), lis.end(), a[u]);
        idx = it - lis.begin();
        replaced = lis[idx];
        lis[idx] = a[u];
    }

    d[u] = lis.size() - 1;

    for (int v : adj[u]) {
        if (!d[v]) dfs(v);
    }
    if (inserted) lis.pop_back();
    else lis[idx] = replaced;
}

int main() {
    scanf("%d", &n);
    for (int i=0;i<n;++i) scanf("%d", &a[i]);
    for (int i=1;i<n;++i) {
        scanf("%d%d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0);
    for (int i=0;i<n;++i)
        printf("%d\n" ,d[i]);
}


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

int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (!vis[i] && !vis[x] && a[x][a[x][0]] == i) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
a,b,c,d,e,f = ma()
la = f//(100*a)
lb = f//(100*b)
tmp = -1
ws = 0
s = 0
for ia in range(la+1):
    for ib in range(lb+1):
        water = ia*a*100 + ib*b*100
        if water>f or water==0:
            continue
        lc = (ia*a + ib*b)*e //c
        ld =(ia*a + ib*b)*e //d
        #print(water)
        #print(la,lb,lc,ld)
        for ic in range(lc+1):
            for id in range(ld+1):


                suger = ic*c + id*d
                if suger >e*(ia*a+ib*b) or suger+water>f:
                    continue
                if tmp <(suger)/(water+suger):
                    tmp = (suger)/(water+suger)
                    ws = water+suger
                    s = suger
print(ws,s)


Measured memory_bytes: 9492
N = int(input())
A = list(map(int, input().split()))
x = 0
y = "Owarunjane-zo"
while True:
    for i in range(len(A)):
        if A[i] % 2 == 0:
            A[i] = A[i] / 2
        else:
            y = "OwaOwaRi"
    if y == "OwaOwaRi":
        break
    else:
        x += 1
print(x)

Measured memory_bytes: 2940
n, a, b = map(int,input().split())
s = input()
p = 0
pb = 0
for i in range(n):
    if s[i] == "a":
        if a+b > p:
            p += 1
            print("Yes")
        else:
            print("No")
    elif s[i] == "b":
        if a+b > p and b > pb:
            p += 1
            pb += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N + 1), B(N);
    for (int i = 0; i < N + 1; i++)
    {
        cin >> A[i];
    }
        
    ll ans = 0;

    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
        if (A[i] == 0)
        {
            if (A[i + 1] >= B[i])
            {
                A[i + 1] -= B[i];
                ans += B[i];
            } else
            {
                ans += A[i + 1];
                A[i + 1] = 0;
                
            }
            continue;
        }
        
        if (A[i] >= B[i])
        {
            A[i] -= B[i];
            ans += B[i];
        } else
        {
            ans += A[i];
            B[i] -= A[i];
            if (A[i + 1] >= B[i])
            {
                A[i + 1] -= B[i];
                ans += B[i];
            } else
            {
                ans += A[i + 1];
                A[i + 1] = 0;
                
            }   
        }  
    }
    cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	while(1) {
		int s;
		scanf(" %d", &s);
		if(s == 0) break;
		rep(i,9) {
			int t;
			scanf(" %d", &t);
			s -= t;
		}
		printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
using vec = vector<vector<int>>;


int main(){
string s;
  int n;
  cin>>n>>s;
  int cnt,ans;
  cnt =0;
  ans =0;
  for(int i=0;i<s.size();i++){
     if(s.at(i)=='A') cnt=1;
     else if(cnt==1 && s.at(i)=='B') cnt =2;
    else if(cnt ==2 && s.at(i)=='C'){
      ans ++;
      cnt=0;
    }
    else cnt =0;
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
int main() {
    int a;
    cin >> a;
    cout << a * (a * a + a + 1);
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N;
  cin>>N;
  vector<ll> a(N+1);
  rep(i,1,N+1)
    cin>>a[i];
  vector<ll> pmax(N+2, -1);
  vector<ll> pmax2(N+2, -1);
  rep(i,1,N+1) {
    pmax[i] = max(pmax[i-1], a[i]);
  }
  for (int i=N; i>=1; i--) {
    pmax2[i] = max(pmax2[i+1], a[i]);
  }

  rep(i,1,N+1) {
    ll x = max(pmax[i-1], pmax2[i+1]);
    cout<<x<<endl;
  }
  return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  
  vector<int> ans(n);

  int up = 0;
  int down = 0;

  
  for(int i = 0; i < n; i++){
    down += vec.at(i);
  }
  
  for(int i = 0; i < n; i++){
    up += vec.at(i);
    down -= vec.at(i);
    ans.at(i) = abs(up - down);
  }
  
  sort(ans.begin(), ans.end());
  
  cout << ans.at(0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
  	cin>>s;
  	int cur=0;
  	for (char c:s){
    	cur+=c-'0';
    }
  	cout<<max(cur,(int)(s[0]-'0'-1+9*(s.size()-1)))<<endl;
  	return 0;
}


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

int main(void){
    int H, W;
    while(true){
        cin >> H >> W;
        if (H == 0 && W == 0){
            break;
        }
        for(int j = 0; j < W; j++){
            cout << '#';
        }
        cout << endl;
        for(int i = 1; i < H-1; i++){
            cout << '#';
            for(int j = 1; j < W-1; j++){
                cout << '.';
            }
            cout << '#' << endl;
        }
        for(int j = 0; j < W; j++){
            cout << '#';
        }
        cout << endl << endl;
    }
}


Measured memory_bytes: 3080
#include <iostream>
#include <fstream>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=1e5+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

ll a[N];

bool ans[N];



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    if(!n){
        cout<<0;
        return 0;
    }
    vector<pll>v;
    for(ll i=0;i<=38;i++){
        a[i]=pow(-2ll,i);
    }
    for(ll i=0;i<(1ll<<20);i++){
        ll s=0;
        for(ll j=0;j<=19;j++){
            if(i&(1ll<<j)){
                s+=a[j];
            }
        }
        v.push_back({s,i});
    }
    v.push_back({INF,1ll});
    sort(all(v));
    for(ll i=0;i<(1ll<<19);i++){
        ll s=0;
        for(ll j=20;j<=38;j++){
            if(i&(1ll<<(j-20ll))){
                s+=a[j];
            }
        }
        pll p=*low_b(all(v),mp(n-s,0ll));
        if(p.x==n-s){
            ll q=p.y+(i<<20);
            string s;
            while(q){
                s+=char(q%2+'0');
                q/=2;
            }
            reverse(all(s));
            for(int i=0;i<s.size();i++){
                cout<<s[i];
            }
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 35044
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((a==5 && b==5 && c==7)||(a==5 && b==7 && c==5)||(a==7 && b==5 && c==5)){

          printf("YES\n");
    }

    else{
          printf("NO\n");
    }
}



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

namespace A
{

    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineInt();
            Console.WriteLine(n*2*Math.PI);
            ReadLine();

        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 18620
#include <bits/stdc++.h>
#include <map>
 
using std::map;
 
const int
	MAXN = 500005,
	MAXLGN = 20;
 
int N, Q;
map< int, int > pos;
int tree[MAXN];
int cant;
struct node {
	int val, L, R, size;
} buff[2 * MAXN * MAXLGN];
 
int build( int lo, int hi ) {
	if ( lo > hi ) return 0;
 
	int idx = ++cant;
	
	int mid = ( lo + hi ) / 2;
	buff[idx] = (node){ mid, build( lo, mid - 1 ), build( mid + 1, hi ), 0 };
	return idx;
}
 
int update( int x, int val, int amount ) {
 
	if ( x == 0 ) return 0;
 
	int idx = ++cant;
	
	int L = buff[x].L;
	int R = buff[x].R;
	if ( val < buff[x].val ) L = update( L, val, amount );
	if ( val > buff[x].val ) R = update( R, val, amount );
	
	buff[idx] = (node){ buff[x].val, L, R, buff[x].size + amount };
 
	return idx;
}
 
int query( int x, int val ) {
	if ( val < buff[x].val )
		return query( buff[x].L, val ) + buff[x].size -	buff[ buff[x].L ].size;
 
	if ( val > buff[x].val )
		return query( buff[x].R, val );
 
	return buff[x].size - buff[ buff[x].L ].size;
}
 
int main() {
 
	scanf( "%d", &N ), scanf( "%d", &Q );
 
	tree[0] = build( 1, N );
	for ( int i = 1; i <= N; i++ ) {
		int x, posx;
		scanf( "%d", &x ); posx = pos[x];
		if ( posx != 0 )
			tree[i] = update( update( tree[i - 1], posx, -1 ), i, +1 );
		else
			tree[i] = update( tree[i - 1], i, +1 );
		pos[x] = i;
	}
 
	while ( Q-- ) {
		int lo, hi;
		scanf( "%d %d", &lo, &hi );
		printf( "%d\n", query( tree[hi], lo ) );
	}
 
	return 0;
}

Measured memory_bytes: 294296
#include<iostream>
#include<vector>
using namespace std;
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  while(true){
    int a,b;
    cin >>a>>b;
    if(cin.eof())return 0;
    int g = gcd(a,b);
    cout << g <<' '<<a/g*b<<endl;
  }
}



Measured memory_bytes: 2996
/*
                                Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
 
#include <bits/stdc++.h>
 
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
 
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
    return result % M;
}
int SieveOfEratosthenes(int m) 
{	int n=200000;
	bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    {   if (prime[p] == true) 
        {   for (int i=p*p; i<=n; i += p) 
            prime[i] = false; 
        } 
    } 
	for(int i=m;i<n;i++)
	{	if(prime[i])
		return i;
	}
} 
signed main()
{   jaldi
	int m;
	cin>>m;
	int x=SieveOfEratosthenes(m);
	cout<<x;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std; 
int main()
{
  int n,a,b,c,d;
  int q[5];
  int p[]={1,-1};
  char w[5];

  cin>>n;
  a=n/1000;
  n%=1000;
  b=n/100;
  n%=100;
  c=n/10;
  n%=10;
  d=n;

  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
	if(a+b*p[i]+c*p[j]+d*p[k]== 7){
	  q[0]=i;
	  q[1]=j;
	  q[2]=k;
	  break;	  
	}
      }
    }
  }

  for(int i=0;i<3;i++){
    if(q[i]==0){
      w[i]='+';
    }else{
      w[i]='-';
    }
  }

  cout<<a<<w[0]<<b<<w[1]<<c<<w[2]<<d<<"=7"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());
        int R = Integer.parseInt(scanner.next());
        int S = Integer.parseInt(scanner.next());
        int P = Integer.parseInt(scanner.next());
        String T = scanner.next();

        long ans = 0;
        Set<Integer> unused = new HashSet<>();
        for (int i = 0; i < N; i++) {
            char c = T.charAt(i);
            if (i < K) {
                if (c == 's')
                    ans += R;
                if (c == 'r')
                    ans += P;
                if (c == 'p')
                    ans += S;
                continue;
            }

            char pc = T.charAt(i - K);
            if (unused.contains(i - K) || c != pc) {
                if (c == 's')
                    ans += R;
                if (c == 'r')
                    ans += P;
                if (c == 'p')
                    ans += S;
                continue;
            }
            unused.add(i);
        }

        System.out.println(ans);
    }

}


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

int main()
{
	
	int n, m, i, s = 0, c = 0, p;
	cin >> n >> m;
	int a[n];
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		s = s + a[i];
	}
	p=ceil(s/(4.0*m));
	for (i = 0; i < n; i++)
	{
		if (a[i] >= p)
			c++;
	}
	if (c >= m)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      cin >> a[i][j];
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int b;
    cin >> b;
    for(vector<vector<int>>::iterator it_v = a.begin(); it_v != a.end(); ++it_v)
      for(vector<int>::iterator it = it_v->begin(); it != it_v->end(); ++it)
        if(b == *it) *it = 0;
  }

  if( ((a[0][0] == 0) && (a[0][1] == 0) && (a[0][2] == 0)) ||
      ((a[1][0] == 0) && (a[1][1] == 0) && (a[1][2] == 0)) ||
      ((a[2][0] == 0) && (a[2][1] == 0) && (a[2][2] == 0)) ||
      ((a[0][0] == 0) && (a[1][0] == 0) && (a[2][0] == 0)) ||
      ((a[0][1] == 0) && (a[1][1] == 0) && (a[2][1] == 0)) ||
      ((a[0][2] == 0) && (a[1][2] == 0) && (a[2][2] == 0)) ||
      ((a[0][0] == 0) && (a[1][1] == 0) && (a[2][2] == 0)) ||
      ((a[0][2] == 0) && (a[1][1] == 0) && (a[2][0] == 0)) )
    cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static long max(long a, long b, long c) {
        return Math.max(a, Math.max(b, c));
    }

    private static long min(long a, long b, long c) {
        return Math.min(a, Math.min(b, c));
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long h = s.nextLong();
        long w = s.nextLong();
        long min = Long.MAX_VALUE;
        for (int i = 1; i < h; i++) {
            long sa = i * w;
            long sbv = ((h - i) / 2) * w;
            long scv = (h - i - (h - i) / 2) * w;
            long sbh = (h - i) * (w / 2);
            long sch = (h - i) * (w - (w / 2));
            min = Math.min(max(sa, sbv, scv) - min(sa, sbv, scv), min);
            min = Math.min(max(sa, sbh, sch) - min(sa, sbh, sch), min);
        }
        for (int i = 1; i < w; i++) {
            long sa = h * i;
            long sbv = h * ((w - i) / 2);
            long scv = h * (w - i - (w - i) / 2);
            long sbh = (h / 2) * (w - i);
            long sch = (h - (h / 2)) * (w - i);
            min = Math.min(max(sa, sbv, scv) - min(sa, sbv, scv), min);
            min = Math.min(max(sa, sbh, sch) - min(sa, sbh, sch), min);
        }
        System.out.println(min);
    }

}


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

#define pb push_back
#define sz(a) ((int)a.size())
#define EACH(i, a) for (auto& i : a)
#define FOR(i, a, b) for (decay<decltype(a)>::type i = (a), i##_n = (b); i < i##_n; i++)
#define ROF(i, a, b) for (decay<decltype(a)>::type i = (a) - 1, i##_n = (b); i >= i##_n; i--)
#define all(vec) (vec).begin(), (vec).end()
#define rev(vec) (vec).rbegin(), (vec).rend()
#define quit(x) do { cout << (x) << "\n"; return; } while (0)

int __tag__ = 0;
#define err(x) "["#x": " << x << "]"
#define debug(x) if (__tag__) cerr << err(x) << "\n"

template <class L, class R>
ostream& operator<< (ostream& out, const pair<L, R> &p) {
  return out << p.first << " " << p.second;
}
template <class T>
ostream& operator<< (ostream& out, const vector<T> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    out << ((it != begin(vec)) ? " " : "") << *it;
  }
  return out;
}

template <class T, class U>
inline bool chkmax(T& a, U b) { return (a < b) ? (a = b, true) : false; }
template <class T, class U>
inline bool chkmin(T& a, U b) { return (a > b) ? (a = b, true) : false; }

template <class T>
inline vector<T> mapping(vector<T> vec) {
  sort(all(vec)), vec.erase(unique(all(vec)), end(vec));
  return vec;
}

template <class T, class U>
inline int mapping(T* st, T* en, U* result) {
  int len = en - st;
  FOR(i, 0, len) result[i] = *(st + i);
  sort(result, result + len);
  return unique(result, result + len) - result;
}

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void solve();
int main(int argc, char **argv) {
  if ((__tag__ = (argc > 1))) {
    assert(freopen(argv[1], "r", stdin));
    cerr.setf(ios_base::fixed), cerr.precision(4);
  }
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int T = 1;
  // cin >> T;
  FOR(Case, 1, T + 1) {
    solve();
  }
  auto times = (clock() * 1.0 / CLOCKS_PER_SEC);
  debug(times);
}

// ***************************************************************************

struct state {
  ll v;
  int x, y, z;
  bool operator< (const state& rhs) const {
    return v < rhs.v;
  }
};

void solve() {
  int X, Y, Z, k; cin >> X >> Y >> Z >> k;
  VL A(X), B(Y), C(Z);
  EACH(x, A) cin >> x;
  EACH(x, B) cin >> x;
  EACH(x, C) cin >> x;

  sort(rev(A)), sort(rev(B)), sort(rev(C));

  VL ans;
  set<tuple<int, int, int>> S;
  priority_queue<state> Q;
  S.insert(make_tuple(0, 0, 0));
  Q.push({ A[0] + B[0] + C[0], 0, 0, 0 });
  while (k--) {
    auto u = Q.top(); Q.pop();
    ans.pb(u.v);
    int x = u.x, y = u.y, z = u.z;
    if (x + 1 < X) {
      ++x;
      if (S.insert(make_tuple(x, y, z)).second) {
        Q.push({ A[x] + B[y] + C[z], x, y, z });
      }
      --x;
    }
    if (y + 1 < Y) {
      ++y;
      if (S.insert(make_tuple(x, y, z)).second) {
        Q.push({ A[x] + B[y] + C[z], x, y, z });
      }
      --y;
    }
    if (z + 1 < Z) {
      ++z;
      if (S.insert(make_tuple(x, y, z)).second) {
        Q.push({ A[x] + B[y] + C[z], x, y, z });
      }
      --z;
    }
  }
  FOR(i, 0, sz(ans)) {
    cout << ans[i] << "\n";
  }
}

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

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> H(N, (K-Q));
    int A[Q];
    for (int i = 0; i < Q; i++) {
        cin >> A[i];
        H[A[i]-1]++;
    }
    for (int j = 0; j < N; j++) {
        if (H[j] <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }

}

Measured memory_bytes: 1408
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define ins insert 
#define mp make_pair
#define fi first
#define se second
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000000000000000
using namespace std;
int main(){
    //double start_time = clock();
    ll n,prev,x,m;
    cin>>n;
    ll a[n][3],dp[n][3]={0};
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for (int i = 0; i < 3; ++i)
    {
        dp[0][i]=a[0][i];
    }
    for (int i = 1; i < n; ++i)
    {
        dp[i][0] = a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    cout<<max3(dp[n-1][0],dp[n-1][1],dp[n-1][2]);
    return 0;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();

        ArrayList<Integer> ans = new ArrayList<>();
        for(int i=1; i<=a; i++) {
            if(a % i == 0) {
                for(int j=1; j<=b; j++) {
                    if(b % j == 0 && i == j) {
                        ans.add(i);
                    }
                }
            }
        }

        Collections.sort(ans, Collections.reverseOrder());
        System.out.println(ans.get(k-1));
    }
}


Measured memory_bytes: 35736
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,t,k,a,b,c;
int main()
{
	scanf("%d%d%d",&t,&a,&b);
	for(int i=1;i<=t;i++)
	{
		scanf("%d%d",&m,&n);
		int kk,ui;
		kk=m/a;
		ui=n/b;
		//printf("%d %d %d\n",kk,ui,k);
		if(kk*ui)
		k++;
	}
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  int ans=0;
  if(s.at(0) == t.at(0)) ans++;
  if(s.at(1) == t.at(1)) ans++;
  if(s.at(2) == t.at(2)) ans++;
  cout << ans << endl;
  return 0;
}


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

/**
 * author @sahil
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        System.out.println(24+(24-n));
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
int a[2501][2501];
int main()
{
    memset(a,0,sizeof(a));
    int k,s;
    scanf("%d%d",&k,&s);
    int sum=0;
    for(int x=0;x<=k;++x)
    {
        for(int y=0;y<=k;++y)
        {
                if(x+y+k>=s&&(x+y<=s))
                    {
                        if(!a[x][y])
                        {
                            a[x][y]=1;
                            sum++;
                        }
                    }
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 24704
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
ll n;
class UnionFind{
    private:
        vector<ll> par;
        vector<ll> siz;
    public:
        UnionFind(ll sz){
            par.resize(sz);
            siz.assign(sz,1LL);
            rep(i,sz) par[i] = i;
        }

        ll find(ll x){
            if (par[x] == x) return x;
            else return par[x] = find(par[x]);
        }

        void unite(ll x,ll y){
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (siz[x] < siz[y]) swap(x,y);
            siz[x] += siz[y];
            par[y] = x;
        }

        bool same(ll x,ll y){
            return find(x) == find(y);
        }

        ll size(ll x){
            return siz[find(x)];
        }

        ll cnt(){
            vector<bool> a(n);
            rep(i,n){
                a[find(i)] = 1;
            }
            ll c = 0;
            rep(i,n){
                if (a[i]) c++;
            }
            return c;
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll m;
    cin >> n >> m;
    UnionFind g(n);
    ll x,y,z;
    rep(i,m){
        cin >> x >> y >> z;
        g.unite(x,y);
    }
    PRINT(g.cnt());
}


Measured memory_bytes: 1920
# coding: utf-8
N, Y = map(int, input().split())
findflag = 0

for man in range(N+1):
    for gosen in range(N+1):
        sen = (Y - 10000 * man - 5000 * gosen) / 1000
        if sen >= 0 and sen <= N and man + gosen + sen == N:
            print("{} {} {}".format(man, gosen, int(sen)))
            findflag = 1
            
        if findflag == 1:
            break
        
    if findflag == 1:
        break

if findflag == 0:
    print("-1 -1 -1")

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

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

ii ma[1 << 18][19];

void Update(ii& a, int x) {
  if (x > a.first) {
    a.second = a.first;
    a.first = x;
  } else if (x > a.second) {
    a.second = x;
  }
}

ii Join(ii a, ii b) {
  //vector<int> v = {a.first, a.second, b.first, b.second};
  //sort(v.begin(), v.end());

  Update(a, b.first);
  Update(a, b.second);

  //assert(a == make_pair(v[3], v[2]));
  return a;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(1 << n);
  for (int i = 0; i < a.size(); ++i) cin >> a[i];

  for (int i = 0; i < (1 << n); ++i) ma[i][0].first = a[i];  

  for (int b = 1; b <= n; ++ b) {
    int r = n - b;
    for (int i = 0; i < (1 << r); ++i) {
      ma[i][b] = Join(ma[i * 2][b - 1], ma[i * 2 + 1][b - 1]);
    }
  }

  for (int b = 0; b < n; ++b) {
    for (int i = 0; i < n; ++i) for (int mask = 0; mask < (1 << n); ++ mask) {
      if (mask & (1 << i)) {
        ma[mask][b] = Join(ma[mask][b], ma[mask ^ (1 << i)][b]);
      }
    }          
  }

  for (int k = 1; k < (1 << n); ++k) {
    ii p = ma[k][0];
    int result = p.first + p.second;
    for (int b = 0; b < n; ++b) {
      int x = k >> b;
      if (x & 1) {
        x--;
        ii p = ma[x][b];
        result = max(result, p.first + p.second);
      }
    }
    cout << result << endl;
  }

  return 0;
}


Measured memory_bytes: 43008
n = int(input())
s = input()

d = {1:'A',2:'B',3:'C',4:'D',5:'E',6:'F',7:'G',8:'H',9:'I',10:'J',11:'K',12:'L',13:'M',14:'N',15:'O',16:'P',17:'Q',18:'R',19:'S',20:'T',21:'U',22:'V',23:'W',24:'X',25:'Y',26:'Z'}

def get(d, val):
    keys = [k for k, v in d.items() if v == val]
    if keys:
        return keys[0]
    return None

ans = ''

for x in s:
    if n + get(d,x) >=27:
        ans = ans + d[n+get(d,x)-26]
    else:
        ans = ans + d[n+get(d,x)]

print(ans)

Measured memory_bytes: 43996
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        char[] s = new char[100000];
        char[] t = new char[100000];
        int n = in.read(s, 0, s.length);
        int m = in.read(t, 0, t.length);

        int[][] c = new int[26][n + 1];

        for (int i = 0; i < n; i++) {
            c[s[i] - 'a'][i] = i;
        }
        for (int i = 0; i < 26; i++) {
            c[i][n] = -1;
            for (int j = n - 1; j >= 0; j--) {
                if (c[i][j] == 0) {
                    c[i][j] = c[i][j + 1];
                }
            }
        }
        c[s[0] - 'a'][0] = 0;

        long ans = 0;
        int j = 0;
        for (int i = 0; i < m; i++) {
            int k = t[i] - 'a';
            if (c[k][0] == -1) {
                ans = -1;
                j = 0;
                break;
            }
            int l = c[k][j];
            if (l == -1) {
                ans += n;
                l = c[k][0];
            }
            j = l + 1;
        }
        ans += j;

        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 46352
n,m = map(int,input().split())
lis = []
for i in range(n):
    info = list(map(int,input().split()))
    lis.append(info)
lis = sorted(lis)
mazai = 0
money = 0
for i in range(n):
    buy = min(lis[i][1], m-mazai)
    money += lis[i][0] * buy
    mazai += buy
    if mazai == m:
        break
print(money)


Measured memory_bytes: 28656