akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

int f(int v) {
	int res = 0;
	for (int i = 1; i <= v; ++i) {
		if (v % i == 0) res++;
	}
	return res;
}

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

	int ans = 0;
	for (int i = n; i > 0; --i) {
		if (i % 2 == 1 && f(i) == 8) ans++;
		//cout << i << " " << f(i) << endl;
	}
	cout << ans << endl;
}

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

template<class T> struct dual_segment_tree {
    using F = function<T(T, T)>;
	using value_type = T;
private : 
    int n, hight;
    const F f;
    value_type ie;
    vector<value_type> node;

public : 
    dual_segment_tree (const F &f, const value_type &ie) : f(f), ie(ie) { }

    void resize (int sz) {
        n = 1; hight = 0;
        while (n < sz) { n <<= 1; hight++; }
        node.resize(2 * n);
        fill(node.begin(), node.end(), ie);
    }

	void resize (int _n, const value_type &e) {
		n = 1; hight = 0;
		while (n < _n) { n <<= 1; hight++; }
		node.resize(2 * n);
		fill(node.begin(), node.end(), ie);
		for (int i = n; i < 2 * n; i++) node[i] = e;
	}

	void build (auto l, auto r) {
		resize(r - l);
		for (int i = n; l != r; i++, l++) node[i] = (*l);
	}

	void propagate (int i) {
		if (node[i] == ie) return;
		node[i << 1 | 0] = f(node[i << 1 | 0], node[i]);
		node[i << 1 | 1] = f(node[i << 1 | 1], node[i]);
		node[i] = ie;
	}

	inline void apply (int i) {
		for (int j = hight; j > 0; j--) propagate(i >> j);
	}

    void update (int a, int b, value_type x) {
        apply(a + n); apply(b + n - 1);
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) { node[l] = f(node[l], x); l++; }
            if (r & 1) { r--; node[r] = f(node[r], x); }
        }
    }

    const value_type &operator[] (int i) {
        apply(i + n);
        return node[i + n];
    }

	void swap (dual_segment_tree &s) {
		(this->node).swap(s.node);
	}

};

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int &e : a) cin >> e;
	
	auto f = [](int a, int b) { return (a + b); };
	dual_segment_tree<int> seg(f, 0), buff(f, 0);
	seg.build(a.begin(), a.end());

	for (int _ = 0; _ < k; _++) {
		buff.resize(n);
		for (int i = 0; i < n; i++) {
			int d = seg[i];
			buff.update(max(0, i - d), min(n, i + d + 1), 1);
		}
		bool fin = true;
		for (int i = 0; i < n; i++) {
			fin &= (buff[i] == n);
		}
		seg.swap(buff);
		if (fin) break;
	}
	
	for (int i = 0; i < n; i++) cout << seg[i] << ' ';
	
	return 0;
}

Measured memory_bytes: 8264
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int i;
    int k=0;
    int l=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            k++;
        }
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3==0 || a[i]%5==0)
            {
                l++;
            }
        }
    }
    if(k==l)
    {
        cout<<"APPROVED"<<endl;
    }
    else
        cout<<"DENIED"<<endl;
    return 0;

}


Measured memory_bytes: 256
class BufInput:
  def __init__(self):
    self.save = False
    self.buf = None
  def read(self, save=False):
    if self.save:
      ret = self.buf
    else:
      try:
        ret = input()
      except EOFError as e:
      	ret = None
    self.save = save
    self.buf = ret
    return ret
    
  
bi = BufInput()
while bi.read(True):
  n, k = map(int, bi.read().split())
  s = bi.read().rstrip()

  def findEx(s, f, pos, notfound):
    pos = s.find(f, pos)
    if pos == -1:
      pos = notfound
    return pos

  ans = 0
  left = 0
  right = 0
  while right < n:
      if k > 0:
          right = findEx(s, '01', right, n-1) + 1
          k = k - 1
          right = findEx(s, '10', right, n-1) + 1
          ans = max(ans, right - left)
      else:
          left = findEx(s, '01', left, n-1) + 1
          k = k + 1

  print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0): d(n, -1){}
    int find(int x){
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {return find(x) == find(y);}
    int size(int x){return -d[find(x)];}
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.unite(x, y);
    }
    set<int> st;
    rep(i,n) st.insert(uf.find(i));
    int ans = st.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 10000000
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int t=0;
  while(1){
    int tmp = (60*t+c) % (a+b);
    if(tmp<=a) {
      cout << 60*t+c << endl;
      break;
    }
    t++;
    if(t==INF){
      cout << -1 << endl;
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> pos(26);
  for(int i = 0; i < n; ++i){
  	pos[s[i] - 'a'].insert(i);
  }
  while(q--){
  	int t, i, l, r;
  	char c;
  	cin >> t;
  	if(t == 1){
  		cin >> i >> c;
  		--i;
  		pos[s[i] - 'a'].erase(i);
  		s[i] = c;
  		pos[s[i] - 'a'].insert(i);
  	}
  	else{
  		cin >> l >> r;
  		--l;
  		--r;
  		int ans = 0;
  		for(int i = 0; i < 26; ++i){
  			auto itr = pos[i].lower_bound(l);
  			if(itr != pos[i].end() && *itr <= r)++ans;
  		}
  		cout << ans << endl;
  	}
  }
  return 0;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

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

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 105;
int n;
int arr[N];

int cal(int idx){
	if(idx > 100 || idx < 1){
		return INF;
	}
	int ret = 0;
	lp(i, n){
		ret += (arr[i] - idx) * (arr[i] - idx);
	}
	return ret;
}

int main()
{
	init();
	int ans;
	double sum = 0;
	cin >> n;
	lp(i, n){
		cin >> arr[i];
		sum += (double)arr[i] / (double)n;
	}
	ans = sum;
	cout << min(cal(ans), cal(ans+1));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
    // Here your code !
    int x,y,d,r;
    double z;
    cin>>x>>y;
    d=x/y;
    r=x%y;
    z=double(x)/double(y);
    
    printf("%d %d %.5lf\n", d,r,z);
    return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>
int main(){
    int a,b,c;
    int s=3;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);

    if(a==b && b==c)s=1;
    else{ 
        if(a==b)s--;
        else if(b==c)s--;
        else if(c==a)s--;
    }

    printf("%d",s);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)	
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define double long double
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;
#define MAX (int)(pow(10,6)+ 10)

ll arr[MAX];
ll ans[MAX];

void deal(){
	ll n;
	cin>>n;
	fori(n)
		cin>>arr[i];
	multiset<ll> all;
	all.insert(arr[0]);
	for(ll i = 1; i<n; i++){
		auto it = all.lower_bound(arr[i]);
		if(it != all.begin()){
			--it;
			all.erase(it);
		}
		all.insert(arr[i]);
	}
	cout<<all.size();
}

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

/*

4 6
4 8 7 8
1 2 4
2 1 2 2
1 3 4
2 1 1 8
1 1 3
1 1 4

*/

Measured memory_bytes: 9088
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int const M=100000+10;
char a[M];
int ans=0,naruto,hinata;
int main()
{
	scanf("%s",a);naruto=hinata=0;int len=strlen(a);
	for(int i=0;i<len;i++)
	{
		if(naruto==hinata){
			naruto++;if(a[i]=='p') ans--;
		}
		else {
			hinata++;if(a[i]=='g') ans++; 
		} 
	}
	printf("%d\n",ans);
    return 0;
}

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

typedef long long LL;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;
const int maxn = 400 + 10;
const int mod = 1e9 + 7;

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int H, W, h, w;
int ans[1000][1000];

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0) return puts("No"), 0;

    if(H%h) {
        REP(i, 0, H) {
            REP(j, 0, W) ans[i][j] = (i % h == 0) ? 1000 * (h-1) - 1 : -1000;
        }
    }else {
        REP(i, 0, H) {
            REP(j, 0, W) ans[i][j] = (j % w == 0) ? 1000 * (w-1) - 1 : -1000;
        }
    }

    puts("Yes");
    REP(i, 0, H) 
        REP(j, 0, W) {
            printf("%d%c", ans[i][j], " \n"[j == W-1]);
        }
     
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define INF 9999999;
using namespace std;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
stack<char>Q;
string ss;
char s;
map<char,int>mp; 
int tot=0,num=0,t;
int main()
{
	cin>>ss;
	int i=0;
	int j=ss.size()-1;
	while(i<=j)
	 {
	 	if(ss[i]==ss[j])
	 	 {
	 	 	i++;
	 	 	j--;
	 	 	continue;
		 }
		if(ss[i]=='x')
		 {
		 	i++;
		 	tot++;
		 	continue;
		 }
		if(ss[j]=='x')
		 {
		 	j--;
		 	tot++;
		 	continue;
		 }
		else{
		cout<<"-1\n";
		return 0;
	   }
	 }
	cout<<tot<<'\n';
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

using P = pair<ll, ll>;
#define fi first
#define se second

#define amin(a, b) a = min(a, b)
#define amax(a, b) a = max(a, b)

int main() {
    int n;
    ll t;
    cin >> n >> t;
    P shops[n];
    for (auto &si:shops) {
        cin >> si.fi >> si.se;
        si.fi++; si.se++;
    }
    sort(shops, shops+n);
    vector<ll> rui(1, 0);
    for (auto &si:shops) {
        if (si.fi > 1) break;
        rui.push_back(rui.back() + si.se);
    }
    vector<P> mul(shops+rui.size()-1, shops+n);
    sort(mul.begin(), mul.end(), [](P l, P r) {
        return l.se * (r.fi - 1) < (l.fi - 1) * r.se;
    });
    int m = mul.size();
    ll dp[m+1][30];
    fill(dp[0], dp[m+1], t+2);
    dp[0][0] = 1;
    for (int i=0; i<m; i++) {
        ll a = mul[i].fi, b = mul[i].se;
        for (int j=0; j<30; j++) {
            amin(dp[i+1][j+1], a * dp[i][j] + b);
            amin(dp[i+1][j], dp[i][j]);
        }
    }
    int ans = 0;
    for (int i=0; i<=m; i++) {
        for (int j=0; j<30; j++) {
            int x = partition_point(rui.begin(), rui.end(), [&](ll r) { return r + dp[i][j] - 1 <= t; }) - rui.begin();
            amax(ans, (x > 0 ? j + x - 1 : 0));
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 53376
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long

using namespace std;

const ll N = 2e5 + 5;

vector<ll> v1, v2, v3, v4;

ll get(ll xx)
{
    ll ret = 0;
    for(auto i:v3)
    {
        ll s = 0, e = v2.size() - 1, mid, best = 0;
        while(s <= e)
        {
            mid = (s + e) / 2;
            if(v2[mid] + i >= xx)
            {
                s = best = mid + 1;
            }
            else e = mid - 1;
        }
        ret += best;
    }
    return ret;
}

int main()
{
    int x, y, z, k;
    ll xx;
    scanf("%d%d%d%d", &x, &y, &z, &k);
    for(int i = 0 ; i < x ; i++)
    {
        scanf("%lld", &xx);
        v1.emplace_back(xx);
    }
    for(int i = 0 ; i < y ; i++)
    {
        scanf("%lld", &xx);
        for(auto j:v1) v2.emplace_back(j + xx);
    }
    sort(v2.rbegin(), v2.rend());
    for(int i = 0 ; i < z ; i++)
    {
        scanf("%lld", &xx);
        v3.emplace_back(xx);
    }
    sort(v3.rbegin(), v3.rend());
    ll s = 1, mid, e = 1e18, best = 1;
    while(s <= e)
    {
        mid = s + (e - s) / 2;
        if(get(mid) >= k)
        {
            best = mid;
            s = mid + 1;
        }
        else e = mid - 1;
    }
    for(auto i:v3)
    {
        for(auto j:v2)
        {
            if(j + i < best) break;
            v4.emplace_back(j + i);
        }
    }
    sort(v4.rbegin(), v4.rend());
    for(int i = 0 ; i < k ; i++) printf("%lld\n", v4[i]);
    return 0;
}


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

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

	cin >> n;

	if(n<1000)
	{
		cout << "ABC" << '\n';
	}
	else
	{
		cout << "ABD" << '\n';
	}
	
	return 0;	
}

Measured memory_bytes: 256
#include <set>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

using namespace std;

int main(void) {
	string s;
	int x;
	cin >> s >> x;

	set<string> vec_sub;

	for (int i = 0; i < s.size(); i++) {
		int max_index = min(int(s.size() - i), 5);
		for (int j = 1; j <= max_index; j++) {
			vec_sub.insert(s.substr(i, j));
		}
	}

	set<string>::iterator iter = vec_sub.begin();
	advance(iter, x-1);
	cout << *iter;
}

Measured memory_bytes: 1664
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353
MOD_root = 3
max_ntt = 20


@njit((i8, i8), cache=True)
def mpow(a, n):
    p = 1
    while n:
        if n & 1:
            p = p * a % MOD
        a = a * a % MOD
        n >>= 1
    return p


@njit((i8, i8), cache=True)
def ntt_precompute(N, primitive_root):
    roots = np.empty(1 << N, np.int64)
    iroots = np.empty(1 << N, np.int64)
    roots[0] = iroots[0] = 1
    for n in range(N):
        x = mpow(primitive_root, (MOD - 1) >> n + 2)
        y = mpow(x, MOD - 2)
        for i in range(1 << n):
            roots[(1 << n) | i] = roots[i] * x % MOD
            iroots[(1 << n) | i] = iroots[i] * y % MOD
    return roots, iroots


@njit((i8[:], i8[:], i8[:], numba.b1), cache=True)
def ntt(roots, iroots, A, inverse):
    N = len(A)
    if not inverse:
        m = N >> 1
        while m:
            for k in range(N // m >> 1):
                s = 2 * m * k
                for i in range(s, s + m):
                    x, y = A[i], A[i + m] * roots[k]
                    A[i], A[i + m] = x + y, x - y
            A %= MOD
            m >>= 1
    else:
        m = 1
        while m < N:
            for k in range(N // m >> 1):
                s = 2 * m * k
                for i in range(s, s + m):
                    x, y = A[i], A[i + m]
                    A[i], A[i + m] = x + y, (x - y) * iroots[k]
            A %= MOD
            m <<= 1
        for i in range(N):
            A[i] = A[i] * mpow(N, MOD - 2) % MOD
    return A


def ntt_convolve(roots, iroots, A, B):
    N = len(A) + len(B) - 1
    L = 1
    while 2 * L < N:
        L *= 2
    L *= 2
    A = np.concatenate((A, np.zeros(L - len(A), np.int64)))
    B = np.concatenate((B, np.zeros(L - len(B), np.int64)))
    ntt(roots, iroots, A, False)
    ntt(roots, iroots, B, False)
    A *= B
    A %= MOD
    ntt(roots, iroots, A, True)
    return A[:N]


roots, iroots = ntt_precompute(max_ntt, MOD_root)

readline()
A = np.array(readline().split(), np.int64)
B = np.array(readline().split(), np.int64)

C = ntt_convolve(roots, iroots, A, B)
print(' '.join(map(str, C.tolist())))

Measured memory_bytes: 260136
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (A >= 13)
            System.out.println(B);
        else if (A >= 6)
            System.out.println(B/2);
        else
            System.out.println(0);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h> 
using namespace std;
double f(long long x)
{
	long long sum=0,ans=x;
	while(x)
	{
		sum+=x%10;
		x/=10;
	}
	return 1.0*ans/sum;
}
int main()
{
	long long k,t=0,ans=0,x=1;
	cin>>k;
	while(t<k)
	{
		if(ans/x%10!=9)
		{
			ans+=x;
			cout<<ans<<endl;
			t++;
		}
		else
		{
			if(f(ans+x)>f(ans+10*x))
				x*=10;
			ans+=x;
			cout<<ans<<endl;
			t++;
		}
	}
	return 0;
}

Measured memory_bytes: 3524
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int McxiToInt(std::string s){
  int result=0;
  int last_digit=1;
  for(auto c:s){
    if('2'<=c&&c<='9'){
      last_digit=c-'0';
    }else if(c=='m'){
      result+=last_digit*1000;
      last_digit=1;
    }else if(c=='c'){
      result+=last_digit*100;
      last_digit=1;
    }else if(c=='x'){
      result+=last_digit*10;
      last_digit=1;
    }else if(c=='i'){
      result+=last_digit*1;
      last_digit=1;
    }
  }
  return result;
}

std::string IntToMcxi(int n){
  std::string result;
  int m=0,c=0,x=0,i=0;
  while(n>=1000){
    n-=1000;
    m++;
  }
  if(m>=2){
    result+=(m+'0');
    result+='m';
  }else if(m==1){
    result+='m';
  }
  while(n>=100){
    n-=100;
    c++;
  }
  if(c>=2){
    result+=(c+'0');
    result+='c';
  }else if(c==1){
    result+='c';
  }
  while(n>=10){
    n-=10;
    x++;
  }
  if(x>=2){
    result+=(x+'0');
    result+='x';
  }else if(x==1){
    result+='x';
  }
  while(n>=1){
    n-=1;
    i++;
  }
  if(i>=2){
    result+=(i+'0');
    result+='i';
  }else if(i==1){
    result+='i';
  }
  return  result;
}

std::string Solve(std::string a,std::string b){
  int x=McxiToInt(a),y=McxiToInt(b);
  return IntToMcxi(x+y);
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    std::string a,b;
    cin>>a>>b;
    cout<<Solve(a,b)<<endl;
  }

  return 0;
}



Measured memory_bytes: 3204
def main():
    n, m = map(int, input().split())
    if n%2:
        for i in range(m):
            print(i+1, n-i)
    else:
        for i in range(m):
            if n-2*i-1 > n//2:
                print(i+1, n-i)
            else:
                print(i+1, n-i-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9280
/*
  || Shree Ganeshay Namah ||

     || Jai Shree Ram ||
  || Nabh Sparsham Diptam ||
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define mod 1000000007
#define block 180
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f1 first
#define s1 second
#define pb push_back
// to floor a/b you can do a/b and to ceiling a/b you can do (a+b-1)/b
int jai_shree_ram()
{
    return 1;
}
int shree_ganeshay_namah()
{
    return 1;
}
ll power(ll x,ll y)
{
    ll r=1;
    while(y>0)
    {
        if(y%2!=0)
            r=(r%mod * x%mod)%mod;
        x=(x%mod * x%mod)%mod;
        y=y/2;
    }
    return r;
}
ll ncr(ll n,ll k)
{

    ll c[k+1];
    memset(c,0,sizeof(c));
    c[0]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=min(i,k);j>0;j--)
            c[j]=(c[j]%mod + c[j-1]%mod)%mod;
    }
    return c[k];
}

bool prime[1001];
void sieve()
{
    ll i,j;
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(i=2;i<=sqrt(100);i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=100;j=j+i)
                prime[j]=false;
        }
    }
}
//Start of Matrix Exponentiation Code
void mat_mul(ll F[2][2],ll M[2][2]) {
   ll a = ((F[0][0]%mod * M[0][0]%mod)%mod + (F[0][1]%mod * M[1][0]%mod)%mod)%mod;
   ll b = ((F[0][0]%mod * M[0][1]%mod)%mod + (F[0][1]%mod * M[1][1]%mod)%mod)%mod;
   ll c = ((F[1][0]%mod * M[0][0]%mod)%mod + (F[1][1]%mod * M[1][0]%mod)%mod)%mod;
   ll d = ((F[1][0]%mod * M[0][1]%mod)%mod + (F[1][1]%mod * M[1][1]%mod)%mod)%mod;
   F[0][0] = a;
   F[0][1] = b;
   F[1][0] = c;
   F[1][1] = d;
}
void mpower(ll F[2][2], ll n) {
   if (n == 0 || n == 1)
      return;
   ll M[2][2] = {{1,1},{1,0}};
   mpower(F, n / 2);
   mat_mul(F, F);
   if (n % 2 != 0)
      mat_mul(F, M);
}
ll fib_mat(ll n) {
   ll F[2][2] = {{1,1},{1,0}};
   if (n == 0)
      return 0;
   mpower(F, n - 1);
   return F[0][0]%mod;
}
//End of Matrix Exponentiation
/*
Segment Tree
ll ar[200005];
ll st[800005];
void build(ll si,ll ss,ll se)
{
    if(ss==se)
    {
        st[si]=ar[ss];
        return ;
    }
    ll mid=(ss+se)/2;
    build(2*si,ss,mid);
    build(2*si+1,mid+1,se);
    st[si]=(st[2*si]+st[2*si+1]);
}
ll query(ll si,ll ss,ll se,ll l,ll r)
{

   if(l<=ss && se<=r)
     return st[si];
   if(l>se || r<ss)
    return 0;
   ll mid=(ss+se)/2;
   ll x=query(2*si,ss,mid,l,r);
   ll y=query(2*si+1,mid+1,se,l,r);
   return x+y;
}
void update(ll si,ll ss,ll se,ll qi)
{
    if(ss==se)
    {
        st[si]=ar[ss];
        return;
    }
    ll mid=(ss+se)/2;
    if(qi<=mid)
        update(2*si,ss,mid,qi);
    else
        update(2*si+1,mid+1,se,qi);
    st[si]=st[2*si]+st[2*si+1];
}
*/

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,i,j,f=0,m=0;
	string s;
	cin>>s;
	n=s.size();
	for(i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            f=0;
            for(j=i;j<n;j++)
            {
                if(s[j]=='R')
                    f++;
                else
                    break;
            }
            m=max(m,f);
            i=j-1;
        }
    }
    cout<<m;
	return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
    	var sc = new Scanner();
    	int n = sc.NextInt();
    	
    	double sum = 0;
    	for (int i = 0; i < n; i++)
    	{
    		double x = sc.NextDouble();
    		switch (sc.NextString())
    		{
    			case "JPY":
    			    sum += x;
    			    break;
    			case "BTC":
    			    sum += x * 380000;
    			    break;
   	 	}
    	}
    	Console.WriteLine(sum);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }
        
    public long NextLong()
    {
    	CheckNext();
    	return long.Parse(buf[index++]);
    }
    
    public double NextDouble()
    {
    	CheckNext();
    	return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}

Measured memory_bytes: 11092
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 200010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

ll n;

int a[maxn],cnt;

int main(){
	cin>>n;
	while(n)a[++cnt]=n%10,n/=10;
	int ans=0;
	int t=0;
	RREP(i,cnt,1){
		if(a[i])ans=max(ans,t+a[i]-1+(i-1)*9);
		t+=a[i];
	}
	ans=max(ans,t);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int a, b, c, d, e, f;

//解法
void solve() {

	set<double> water, suger;

	double water_max = 0;
	rep(i, f / b + 1) {
		if (i * 100 * b > f) break;
		rep(j, f / a + 1) {
			int val = (i * 100 * b + j * 100 * a);
			if (val <= f) {
				water.insert(val);
				if (val > water_max) water_max = val;
			}
			else {
				break;
			}
		}
	}

	rep(i, f / d + 1) {
		if (i * d > f) break;
		rep(j, f / c + 1) {
			int val = (i *d + j * c);
			if (val <= f && water_max / 100 * e >= val) {
				suger.insert(val);
			}
			else {
				break;
			}
		}
	}

	int ans_water = a*100, ans_suger = 0;
	double ans_conc = 0;

	for (auto wat : water) {
		for (auto sug : suger) {

			if ((wat + sug) <= f && (wat / 100 * e) >= sug && wat + sug != 0) {

				double conc = ((double)100 * sug / (wat + sug));
				if (ans_conc < conc) {
					ans_conc = conc;
					ans_water = wat;
					ans_suger = sug;
				}

			}

		}
	}

	cout << (ans_water + ans_suger) << " " << ans_suger;

	return;
}

int main() {
	//入力
	cin >> a >> b >> c >> d >> e >> f;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
/// I won't go back on my word, that's my ninja way!
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5 ;
int n ,arr[N] ,m;
int midPre[N] ,midSuf[N] ;
long long preSum[N] ,sufSum[N] ;
int main(){
    scanf("%d",&n);
    m = 1;
    for(int i=1;i<=n;++i){
        scanf("%d",arr+i);
        preSum[i] = arr[i] + preSum[i-1] ;
        while(m+1<i && preSum[m+1]<preSum[i]-preSum[m])++m;
        midPre[i] = m ;
    }
    int m = n ;
    for(int i=n;i>=1;--i){
        sufSum[i] = arr[i] + sufSum[i+1] ;
        while(m-1>i && sufSum[m-1]<sufSum[i]-sufSum[m])--m;
        midSuf[i] = m ;
    }
    long long ans = 1e18 ;
    for(int i=2;i+1<n;++i){
        int midP = midPre[i] ;
        int midS = midSuf[i+1];
        vector<long long> vec ;
        vec.push_back(preSum[midP]);
        vec.push_back(preSum[i]-preSum[midP]);
        vec.push_back(sufSum[midS]);
        vec.push_back(sufSum[i+1]-sufSum[midS]);
        sort(vec.begin(),vec.end());
        ans = min(ans,vec.back() - vec.front());
    }
    printf("%lld",ans);
    return 0 ;
}


Measured memory_bytes: 5760
#include<stdio.h>
#define REP(i,n) for (int i = 0 ; i < (int)n ; i++)
typedef long long ll;

int main(){
    int n,k,d,j,count=0;
    scanf("%d %d",&n,&k);
    int sunuke[n];
    REP(i,n){
        sunuke[i] = 0;
    }
    REP(i,k){
        scanf("%d",&d);
        REP(i,d){
            scanf("%d",&j);
            sunuke[j-1] += 1;
        }
    }
    REP(i,n){
        if(!sunuke[i]){
            count += 1;
        }
    }
    printf("%d\n",count);
}

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

n, w = [int(x) for x in input().split()]
weight = [0 for _ in range(n)]
value = [0 for _ in range(n)]
for i in range(n):
  weight[i], value[i] = [int(x) for x in input().split()]

dp = [[0 for i in range(w+1)] for _ in range(n+1)]

for i in range(n):
  for sum_w in range(w+1):
    if (sum_w - weight[i] >= 0):
      dp[i+1][sum_w] = max(dp[i][sum_w-weight[i]]+value[i], dp[i][sum_w])
    else:
      dp[i+1][sum_w] = dp[i][sum_w]

print(dp[n][w])

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

string s;
int n,m;
int a[3003];
int l[3003],r[3003];
vector<P> ps[2];
ll dp[2][3003];

int main(){
  cin>>n>>m>>s;
  rep(i,n)a[i]=s[i]-'0';
  rep(i,n){
    l[i]=i;
    r[i]=i+1;
  }
  rep(i,m){
    int L,R;
    cin>>L>>R;
    L--; 
    rep(j,n){
      if(L<r[j]&&r[j]<R)r[j]=R;
      if(L<l[j]&&l[j]<R)l[j]=L;
    }
  }
  rep(i,n){
    ps[a[i]].push_back(P(l[i],r[i]));
  }
  ps[0].push_back(P(INF,INF+1));
  ps[1].push_back(P(INF,INF+1));
  sort(all(ps[0])); sort(all(ps[1]));

  m=ps[0].size();
  int crt=0,nxt=1;
  dp[crt][0]=1;
  rep(i,n){
    memset(dp[nxt],0,sizeof(dp[nxt]));
    rep(j,m){
      int k=i-j;
      if(k<0||k>=ps[1].size())continue;
      int l0=ps[0][j].fi,r0=ps[0][j].se;
      int l1=ps[1][k].fi,r1=ps[1][k].se;
      if(r0<=i||r1<=i)continue;
      if(l0<=i){
        (dp[nxt][j+1]+=dp[crt][j])%=mod;
      }
      if(l1<=i){
        (dp[nxt][j]+=dp[crt][j])%=mod;
      }
    }
    swap(crt,nxt);
  }
  cout<<dp[crt][m-1]<<endl;

  return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,c=map(int,input().split())
    STC=[tuple(map(int,input().split())) for _ in range(n)]
    STC.sort(lambda x:(x[2],x[0],x[1]))

    # 同じチャンネルで連続するものは結合しておく
    for i in range(n-1):
        s0,t0,c0=STC[i]
        s1,t1,c1=STC[i+1]
        if(c0!=c1): continue
        if(t0==s1):
            STC[i]=(None,None,None)
            STC[i+1]=(s0,t1,c0)
    # 残りについて、[s-1,t)のimosを行う
    M=100000
    imos=[0]*(M+1)
    for s,t,c in STC:
        if(s is None): continue
        imos[s-1]+=1
        imos[t]-=1
    for i in range(M):
        imos[i+1]+=imos[i]
    print(max(imos))
resolve()

Measured memory_bytes: 66972
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=55;

ll f[2];
int n,p,a[N];

int main(){
	scanf("%d%d",&n,&p);
	f[0]=1;
	rep(i,1,n){
		scanf("%d",a+i);
		ll x=f[0],y=f[1];
		if(a[i]&1){
			f[0]=x+y;
			f[1]=x+y;
		}else{
			f[0]=x+x;
			f[1]=y+y;
		}
	}
	printf("%lld\n",f[p]);
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    int ls = s.size();
    const string k = "keyence";
    bool g = false;
    if (k==s.substr(7,0)){g=true;}
    else if (k==s.substr(7,ls-7)){g=true;}
    else {
        string it;
        for (int i=0;i<7;i++) {
            it = s.substr(0,i+1) + s.substr(ls+i-6,6-i);
            if (it == k) {
                g = true;
                break;
            }
        }
    }
    cout << (g ? "YES" : "NO") << endl;
    return 0;
}

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

int main(){
	int n, a[4][3][10]{};
	cin >> n;
	while(n--){
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		a[--b][--f][--r] += v;
	}
	for(int i = 0; i < 4; i++){
		if(i) cout << string(20, '#') << endl;
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 10; k++) cout << ' ' << a[i][j][k];
			cout << endl;
		}
	}
}

Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#define rep(i,j) FOR(i,0,j)
#define FOR(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int d[2][100][100];
int main(){
	int n,m;
	while(cin>>n>>m,n,m){
		rep(i,101)rep(j,101)rep(k,2)d[k][i][j]=99999999;
		int a,b,c,t;
		rep(i,n){
			cin>>a>>b>>c>>t;
			a--;b--;
			d[0][a][b]=d[0][b][a]=c;
			d[1][a][b]=d[1][b][a]=t;
		}
		rep(k,m)rep(i,m)rep(j,m)rep(l,2)d[l][i][j]=min(d[l][i][j],d[l][i][k]+d[l][k][j]);
		int k,p,q,r;
		cin>>k;
		rep(i,k){
			cin>>p>>q>>r;
			p--;q--;
			cout<<d[r][p][q]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	string A = "", B = "";
	for (int i = 0; i < b; ++i) { A += to_string(a); }
	for (int i = 0; i < a; ++i) { B += to_string(b); }
	cout << min(A, B) << endl;

	return 0;
}


Measured memory_bytes: 256
// wrote this code while finding a series of ants crawling up my legs, not even joking
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>
using namespace std;
using ll = int64_t;
#define rep(i,a,n) for (int i=a;i<(int)(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(int)(a);i--)
template<typename T> ostream& operator<<(ostream& _s, vector<T> _t) {
    rep(i, 0, _t.size()) _s << (i ? " " : "") << _t[i]; return _s;
}
template<typename T> istream& operator>>(istream& _s, vector<T> &_t) {
    rep(i, 0, _t.size()) _s >> _t[i]; return _s;
}
template<typename T, typename U> ostream& operator<<(ostream& _s, pair<T, U> _t) {
    _s << "(" << _t.first << "," << _t.second << ")"; return _s;
}
template<typename T, typename U> istream& operator>>(istream& _s, pair<T, U> &_t) {
    _s >> _t.first >> _t.second; return _s;
}

int main() {
    ios_base::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    unordered_map<ll,ll> occ;
    for (ll i = 2; i * i <= k; i++) {
        while(k%i == 0) {
            occ[i] += 1;
            k /= i;
        }
    }
    if (k > 1) {
        occ[k] += 1;
    }
    ll res = 1;
    for(auto x : occ) {
        ll a = x.second;
        while (a >= n) {
            res *= x.first;
            a -= n;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char ans[1000000];int ty[1000000];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n,A,B,C;cin>>n>>A>>B>>C;
    if(A+B+C!=2)
    {
	for(int i=1;i<=n;++i)
	{
	    string s;cin>>s;
	    if(s=="AB")
	    {
		if(A>B) ans[i]='B',--A,++B; else ans[i]='A',++A,--B;
		if(A<0||B<0) return puts("No"),0;
	    }
	    if(s=="BC")
	    {
		if(B>C) ans[i]='C',--B,++C; else ans[i]='B',++B,--C;
		if(B<0||C<0) return puts("No"),0;
	    }
	    if(s=="AC")
	    {
		if(A>C) ans[i]='C',--A,++C; else ans[i]='A',++A,--C;
		if(A<0||C<0) return puts("No"),0;
	    }
	}
	puts("Yes");
	for(int i=1;i<=n;++i) putchar(ans[i]),puts("");
	return 0;
    }
    for(int i=1;i<=n;++i)
    {
	string s;cin>>s;
	if(s=="AB") ty[i]=0;
	else if(s=="AC") ty[i]=1;
	else ty[i]=2;
    }
    ty[n+1]=-1;
    for(int i=1;i<=n;++i)
	{
	    if(!ty[i])
	    {
		if(A>B) ans[i]='B',--A,++B; else if(A<B) ans[i]='A',++A,--B; else if(ty[i+1]==1) ans[i]='A',++A,--B; else ans[i]='B',--A,++B;
		if(A<0||B<0) return puts("No"),0;
	    }
	    else if(ty[i]==2)
	    {
		if(B>C) ans[i]='C',--B,++C; else if(B<C) ans[i]='B',++B,--C; else if(ty[i+1]==0) ans[i]='B',++B,--C; else ans[i]='C',--B,++C;
		if(B<0||C<0) return puts("No"),0;
	    }
	    else 
	    {
		if(A>C) ans[i]='C',--A,++C; else if(A<C) ans[i]='A',++A,--C; else if(ty[i+1]==0) ans[i]='A',++A,--C; else ans[i]='C',--A,++C;
		if(A<0||C<0) return puts("No"),0;
	    }
	}
	puts("Yes");
	for(int i=1;i<=n;++i) putchar(ans[i]),puts("");
}


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

int main() {
  string s;
  cin >> s;
  bool b = 1, c = 1;
  rep(i, s.size()){
    if(i == 0){
      if(s[i] != 'A'){
        b = 0;
        break;
      }
    }
    else if(c && i > 1 && i < s.size()-1 && s[i] == 'C') c = 0;
    else if(s[i] < 'a'){
      b = 0;
      break;
    }
  }
  if(b && !c) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}

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

//const double EPS = 1e-9;
int n,t;
long double dp[2001][2001];
string str;

void solve(){
  fill(dp[0],dp[2001],0.0);
  dp[0][0] = 1.0;

  for(int i=0;i<t;i++){
    for(int j=0;j<n;j++){
      //if(dp[i][j] < EPS) continue;
      for(int k=1;k<=6;k++){
	dp[i+1][(j+k)%n] += dp[i][j] / 6.0;
      }
    }
  }
  
  double ans = 0.0;
  for(int i=0;i<n;i++){
    double sum = 0.0;
    for(int j=0;j<n;j++){
      if(str[(i+j)%n] == 'R') sum += dp[t][j];
    }
    ans = max(ans,sum);
  }

  printf("%.9f\n",ans);

}

int main(){
  while(cin >> n >> t && (n|t)){
    cin >> str;
    solve();
  }
}

Measured memory_bytes: 63808
fun main(){
    val n = readLine()!!.split(" ")[0].toInt()
    var count = 0
    var flag = 0
    for (i in 0 until n){
        val d = readLine()!!.split(" ").map { it.toInt() }
        if (count >= 3){
            println("Yes")
            flag = 1
            break
        }
        if (d[0] == d[1]){
            count++
            if (count >= 3){
                println("Yes")
                flag = 1
                break
            }
        } else {
            if (count >= 3){
                println("Yes")
                flag = 1
                break
            } else {
                count = 0
            }
        }
    }
    if (flag != 1) println("No")

}


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

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

  vector<int> stick(N);
  int length = 0;
  for (int i = 0;i < N; i++) cin >> stick.at(i);
  sort (stick.begin(),stick.end());
  reverse (stick.begin(),stick.end());
  for (int i = 0; i < K; i++) length += stick.at(i);
  cout << length << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    int K;
    int cnt[30] = {0};
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> K;
        for (int j = 0; j < K; j++)
        {
            cin >> tmp;
            cnt[tmp - 1]++;
        }
        
    }

    int ans = 0;
    for (int i = 0; i < M; i++)
    {
        if (cnt[i] == N)
        {
            ans++;
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 888
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim().split('\n').map(Number);
  for (var i = 0; i < inputs.length; i++) {
  	if(inputs[i]=== 0 ) {
  		break;
  	}
  	console.log('Case '+ (i + 1)+ ': '+inputs[i]);
  }
  
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 20744
class Combination:
    """
    SIZEが10^6程度以下の二項係数を何回も呼び出したいときに使う
    使い方:
    comb = Combination(SIZE, MOD)
    comb(10, 3) => 120
    """

    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.fact, self.inv = self._make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def _make_factorial_list(self, N):
        fact = [1] * (N + 1)
        inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            fact[i] = (fact[i - 1] * i) % MOD
        inv[N] = pow(fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            inv[i - 1] = (inv[i] * i) % MOD
        return fact, inv


S = int(input())
mod = 10 ** 9 + 7
comb = Combination(10000, mod)

if S < 3:
    print(0)
    exit()

ans = 0
cnt = 0
while S >= 3:
    S -= 3
    ans += comb(S + cnt, cnt)
    ans %= mod
    cnt += 1

print(ans)

Measured memory_bytes: 9652
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    A.sort(reverse=True)
    lines = []
    prev = ''
    for ai in A:
        if ai == prev:
            lines.append(ai)
            prev = ''
        else:
            prev = ai

    if len(lines) >= 2:
        print(lines[0] * lines[1])
    else:
        print(0)
  

if __name__ == "__main__":
    main()

Measured memory_bytes: 14636
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const LL MOD = 1e9 + 7;
LL cal(int S, auto &arr, auto &sum) {
    if (~sum[S]) return sum[S];
    sum[S] = 0; int n = arr.size();
    for (int i = 0 ; i < n ; i++)
        for (int j = i + 1 ; j < n ; j++)
            if (((S >> i) & 1) & ((S >> j) & 1))
                sum[S] += arr[i][j];
    return sum[S];
}
LL solve(int S, auto &dp, auto &arr, auto &sum) {
    if (~dp[S]) return dp[S];
    dp[S] = 0;
    for (int s = S ; s ; s = (s - 1) & S)
        dp[S] = max(dp[S], solve(S ^ s, dp, arr, sum) + cal(s, arr, sum));
    return dp[S];
}
void marmot0814() {
    int n; cin >> n;
    vector<vector<LL>> arr(n, vector<LL>(n));
    for (auto &vv : arr)
        for (auto &v : vv)
            cin >> v;
    vector<LL> dp(1 << n, -1); dp[0] = 0;
    vector<LL> sum(1 << n, -1);
    cout << solve((1 << n) - 1, dp, arr, sum) << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}

Measured memory_bytes: 4260
n = int(input())
xl = [[int(i) for i in input().split()] for j in range(n)]

xl_li = []

for i in range(n):
    xl_li.append([xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]])
    
xl_li = sorted(xl_li,key=lambda xl_li:xl_li[1])

tmp = xl_li[0][1]
ans = 1

for i in range(1,n):
    if tmp <= xl_li[i][0]:
        tmp = xl_li[i][1]
        ans += 1
        
print(ans)

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

int m,n;
int a[100];

bool check(int x){
  int b[20];
  int i,j=0;
  for(i=0;i<m;i++)b[i] = x;
  for(i=0;i<n;i++){
    if(b[j]>=a[i])b[j] -= a[i];
    else {
      j++;
      i--;
      if(j==m)break;
    }
  }
  if(i==n)return true;
  return false;
}

int main(){
  int l,r,mid;

  while(1){
    cin >> m >> n;
    if(!m && !n)break;

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

    l = 0;r = 1500000;

    while(l+1<r){
      mid = (l+r)/2;
      if(check(mid))r = mid;
      else l = mid;
    }

    cout << r << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int count=0;
  for(int i=0;i<=A;i++)
  {
    for(int k=0;k<=B;k++)
    {
      for(int j=0;j<=C;j++)
      {
        if(500*i+100*k+50*j==X)
        {
          count++;
        }
      }
    }
  }
  cout<<count<<endl;
}


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

typedef long long ll;
#define endl "\n"

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

    int n,k; cin>>n>>k;
    vector<int> a(n);
    for (int &x: a)
    	cin>>x;
    int ans=0;
    sort(a.begin(), a.end());
    for (int i=0; i<k; ++i){
    	ans+=a[i];
    }
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
from functools import reduce
n,a,b = map(int, input().split(' '));
re = 0;

for x in range(1, n+1):
    digits = list(str(x));
    sum_x  = reduce( lambda a,b: int(a)+int(b), digits, 0)
    if ( a <= sum_x and sum_x <= b ):
        re += x;

print(re);


Measured memory_bytes: 3572