akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, mx = 0;
long long w;
vector< long long > weight( 110 );
vector< int > value( 110 );
long long dp[ 100005 ][ 105 ];

long long solve( int v, int n )
{
	if( v < 0 )
	{
		return 1e15;
	}
	if( n == 0 )
	{
		if( v == 0 )
		{
			return 0;
		}
		else
		{
			return 1e15;
		}
	}
	if( dp[ v ][ n ] != -1 )
	{
		return dp[ v ][ n ];
	}
	dp[ v ][ n ] = min( weight[ n ] + solve( v - value[ n ], n - 1 ), solve( v, n - 1 ) );
	return dp[ v ][ n ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	memset( dp, -1, sizeof( dp ) );
	cin >> n >> w;
	for( int i = 1; i <= n; ++i )
	{
		cin >> weight[ i ] >> value[ i ];
		mx += value[ i ];		
	}
	for( int i = mx; i >= 0; --i )
	{
		if( solve( i, n ) <= w )
		{
			cout << i << "\n";
			return 0;
		}
	}
}

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

using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MAX_N = 1e7 + 1;
int mod = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int resh[MAX_N];
    int ans[n + 1];
    fill(resh, resh + MAX_N, 1);
    for (int i = 2; i < MAX_N; ++i) {
        if (resh[i] != 1)continue;
        for (int j = i * 2; j < MAX_N; j += i) {
            resh[j] = i;
        }
    }
    int ret = 1;
    ans[1] = 1;
    for (int i = 2; i < n + 1; ++i) {
        if (resh[i] == 1) {
            ans[i] = 2;
            ret += 2 * i;
        } else {
            int val = resh[i];
            int x = i;
            int cnt = 0;
            while (x % val == 0) {
                x /= val;
                cnt++;
            }
            ans[i] = ans[i / val] * (cnt + 1) / cnt;
            ret += ans[i] * i;
        }
    }
    cout << ret;
}

Measured memory_bytes: 159808
#include "bits/stdc++.h"
using namespace std;

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

	double total = 0;

	for (int i = 0; i < N; i++) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") {
			total += x;
		}
		else {
			total += x * 380000;
		}

	}
	cout << total << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
x = [-1]*(H*W)
y = [-1]*(H*W)

for i in range(H):
    for j in range(W):
        x[A[i][j]-1] = i
        y[A[i][j]-1] = j

acc = [[0] for _ in range(D)]

for i in range(D):
    now = i
    
    while now+D<H*W:
        cost = abs(x[now]-x[now+D])+abs(y[now]-y[now+D])
        acc[i].append(acc[i][-1]+cost)
        now += D

Q = int(input())

for _ in range(Q):
    L, R = map(int, input().split())
    L -= 1
    R -= 1
    print(acc[L%D][R//D]-acc[L%D][L//D])

Measured memory_bytes: 62956
k, n = map(int, input().split())
a = list(map(int, input().split()))
a2 = []
for i in range(n-1):
    d = int(a[i+1]-a[i])
    a2.append(d)
a2.append(k-a[n-1]+a[0])
ans = k - max(a2)
print(ans)


Measured memory_bytes: 26436
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 500005

ll a[maxn];

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);

    Rep(i, 7) cin >> a[i];
    ll res = a[1];

    ll RR1 = (a[0] / 2 + a[3] / 2 + a[4] / 2) * 2;
    if(a[0] && a[3] && a[4]){
    	a[0]--;
    	a[3]--;
    	a[4]--;
    	RR1 = max(RR1, 3 + (a[0] / 2 + a[3] / 2 + a[4] / 2) * 2);
    }

    res += RR1;
    cout << res << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
const int N = 110, W = 1e5 + 10;

ll n, bag, dp[N][W];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> bag;
	for (int i = 1; i <= n; i++) {
		int w, v;
		cin >> w >> v;
		for (int j = 1; j <= bag; j++)
			dp[i][j] = max({dp[i - 1][j], dp[i][j - 1], (w <= j? v + dp[i - 1][j - w]: 0)});
	}
	cout << dp[n][bag];
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

int n,m,a[1001];
ll k;
bool r[1001][1001]={};
bool count[1001][1001]={};
vector<int> v1[1001],load[1001];
string str;
ll ans=0;
queue<int> que;
set<P> st;
int s=0;
ll hea=0;
bool c=0;
int main() {
	cin>>str>>k;
	if(str.size()==1){
		cout<<k/2<<endl;
		return 0;
	}
	ll h=1;
	for(int i=1;i<str.size();++i){
		if(str[i]!=str[i-1]){
			if(!c){
				hea=h;
				c=1;
			}
			if(h>1){
				ans+=h/2;
			}
			h=0;
		}
		++h;
	}
	if(!c){
		cout<<(str.size()*k)/2<<endl;
		return 0;
	}
	if(str[0]==str[str.size()-1]){
		ans-=hea/2;
		ans*=k;
		ans+=((h+hea)/2)*(k-1);
		ans+=h/2+hea/2;
	}else{
		ans+=h/2;
		ans*=k;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		long a=input.nextLong();
		long b=input.nextLong();
		input.close();
		if((a+b)%2==0)
		{
			System.out.println((a+b)/2);
		}
		else
		{
			System.out.println("IMPOSSIBLE");
		}
		System.exit(0);
	

	}

}


Measured memory_bytes: 27148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<19;
	char *s,*t,buf[l],c;
	char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	template<class IT>void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
	}
}
using io::gc;
using io::gi;
template<class IT>void chkmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>void chkmax(IT &a,IT b){if(a<b)a=b;}

const int N=200005;

int h,w,n,l1,l2,r1,r2,s1,s2;
char s[N],t[N];
int main(){
	scanf("%d%d%d%d%d%s%s",&h,&w,&n,&s1,&s2,s+1,t+1);
	l1=1;r1=h;
	l2=1;r2=w;
	for(int i=n;i;i--){
		switch(t[i]){
			case 'U':{++r1;if(r1>h)r1=h;break;}
			case 'D':{--l1;if(l1<1)l1=1;break;}
			case 'L':{++r2;if(r2>w)r2=w;break;}
			case 'R':{--l2;if(l2<1)l2=1;break;}
		}
		switch(s[i]){
			case 'U':{++l1;if(l1>r1){puts("NO");return 0;}break;}
			case 'D':{--r1;if(l1>r1){puts("NO");return 0;}break;}
			case 'L':{++l2;if(l2>r2){puts("NO");return 0;}break;}
			case 'R':{--r2;if(l2>r2){puts("NO");return 0;}break;}
		}
	}
	if(l1<=s1&&s1<=r1&&l2<=s2&&s2<=r2)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	int sum = 0;
	priority_queue<int, vector<int>, greater<int> > que; 
	FOR(i, n) {
		int s;
		cin >> s;
		sum += s;
		if (s % 10) que.push(s);
	}
	if (sum % 10) cout << sum << endl;
	else {
		if (que.empty()) cout << 0 << endl;
		else cout << sum - que.top() << endl;
	}
	return 0;
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  string s;
  string ans;

  cin >> s;

  REP (i, int(s.size())) {
    if (s.at(i) == '0') ans += "0";
    else if (s.at(i) == '1') ans += "1";
    else if (!ans.empty()) ans.pop_back();
  }

  cout << ans << "\n";
}


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

#define mp make_pair
#define fi first
#define se second

using namespace std;

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

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;

int main(){
	n=readint();
	if((n&(n-1))==0) return printf("No\n"),0;
	printf("Yes\n");
	if(n&1){
		for(int i=2;i<=n;i+=2){
			printf("%d %d\n",i,i+1);
			printf("%d %d\n",i+1,1);
			printf("%d %d\n",1,i+n);
			printf("%d %d\n",i+n,i+n+1);
		}
		printf("%d %d\n",n+3,n+1);
		return 0;
	}
	for(int i=2;i<=n-1;i+=2){
		printf("%d %d\n",i,i+1);
		printf("%d %d\n",i+1,1);
		printf("%d %d\n",1,i+n);
		printf("%d %d\n",i+n,i+n+1);
	}
	printf("%d %d\n",n+3,n+1);
	int tmp=n&(-n);
	printf("%d %d\n",n,tmp^1);
	printf("%d %d\n",(n^tmp)+n,n+n);
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


ll gcd(ll a,ll b){
	return a%b==0?b:gcd(b,a%b);
}
ll lcm(ll a,ll b){
	return a*b/gcd(a,b);
}



int main(){
	vi a(3,0),m(3,0),z(3,0),co(3,1),ans(3,0);
	while(1){
		rep(i,3)cin>>a[i]>>m[i];
		if(a==z&&m==z)break;
		rep(i,3){
			ans[i]=0;
			do{
				co[i]=a[i]*co[i]%m[i];
				ans[i]++;
			}while(co[i]!=1);
		}
		cout<<lcm(lcm(ans[0],ans[1]),ans[2])<<endl;
	}
}

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


int main(){
    long long n;
  	cin >> n;
  	long long b = 0;
  	while((1LL<<b) <= n){
    	++b;
    }
    cout <<((1LL<<b) - 1)<<"\n";
	return 0;
}

//1(4) -> 2(4/2) => 4(4/4)

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int white = scanner.nextInt();
        final int black = scanner.nextInt();

        final char[][] table = new char[100][100];

        int tmpWhite = white - 1;
        for (int i = 0; i < 49; i++) {
            for (int j = 0; j < 100; j++) {
                if (j != 0 && j != 99 && j % 3 == i % 3 && tmpWhite > 0) {
                    table[i][j] = '.';
                    tmpWhite--;
                } else {
                    table[i][j] = '#';
                }
            }
        }

        for (int j = 0; j < 100; j++) {
            table[49][j] = '#';
            table[50][j] = '.';
        }

        int tmpBlack = black - 1;
        for (int i = 51; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                if (j != 0 && j != 99 && j % 3 == i % 3 && tmpBlack > 0) {
                    table[i][j] = '#';
                    tmpBlack--;
                } else {
                    table[i][j] = '.';
                }
            }
        }

        System.out.print(100+" ");
        System.out.println(100);
        for (final char[] chars : table) {
            for (final char c : chars) {
                System.out.print(c);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 26580
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)

left = 0 # できない
right = a[0] # できる
while left+1 < right:
    mid = (left+right) // 2
    cnt = 0
    for i in range(n):
        if a[i]%mid == 0:
            cnt += a[i] // mid - 1
        else:
            cnt += a[i] // mid
        if cnt > k: break
    if cnt > k:
        left = mid
    else:
        right = mid
print(right)

Measured memory_bytes: 93844
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

bool v[107] = {};

int main()
{
    int i,j;

    int N,K;

    scanf("%d %d", &N, &K);
    for( i=1; i<=K; i++)
    {
        int d;
        scanf("%d", &d);
        for( j=1; j<=d; j++)
        {
            int a;
            scanf("%d", &a);
            v[a] = 1;
        }
    }

    int cnt = 0;
    for( i=1; i<=N; i++)
    {
        if( !v[i])
            cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<utility>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<bitset>
using namespace std;

int main(){

    int a;
    cin >> a;

    cout << (a-2)*180 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int tmp[] = new int[4];

		tmp[0] = n / 1000;
		tmp[1] = n % 1000 / 100;
		tmp[2] = n % 1000 % 100 / 10;
		tmp[3] = n % 1000 % 100 % 10;

		int count = 0;
		for (int i = 0; i < 3; i++) {
			if (tmp[i] == tmp[i + 1]) {
				count++;
			}
		}

		if (count >= 2 && tmp[1] == tmp[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define INF 1e9 + 5
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
pair<int, int> get(vector<int>& a, bool even, int skip) {
    int n = a.size();
    unordered_map<int, int> book;
    pair<int, int> res = {0, 0};
    if (even) {
        for (int i = 0; i < n; ++i) {
            if (i & 1 || a[i] == skip) continue;
            if (book.count(a[i]))
                book[a[i]]++;
            else
                book[a[i]] = 1;
            if (res.second < book[a[i]]) {
                res.first = a[i];
                res.second = book[a[i]];
            }
        }
    } else {
        for (int i = 0; i < n; ++i) {
            if (!(i & 1) || a[i] == skip) continue;
            if (book.count(a[i]))
                book[a[i]]++;
            else
                book[a[i]] = 1;
            if (res.second < book[a[i]]) {
                res.first = a[i];
                res.second = book[a[i]];
            }
        }
    }
    return res;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    f(i, n) cin >> a[i];
    int m = n / 2;
    pair<int, int> one = get(a, true, INF);
    pair<int, int> two = get(a, false, one.first);
    pair<int, int> three = get(a, false, INF);
    pair<int, int> four = get(a, true, one.first);
    int ans = min({(m - one.second) + (m - two.second),
                   (m - three.second) + (m - four.second)});
    cout << ans << nl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 5852
#include <iostream>

using namespace std;

int main(){

  int D, G, p[11], c[11];
  cin >> D >> G;
  for (int i = 0; i < D; ++i){
    cin >> p[i] >> c[i];
  }

  int min_num = 1e9;

  for (int i = 0; i < (1 << D); ++i){
    int score = 0, num = 0, rest_max = -1;
    for (int j = 0; j < D; ++j){
      if ((i >> j) & 1){
        score += (j+1) * 100 * p[j] + c[j];
        num += p[j];
      }else{
        rest_max = j;
      }
    }

    if (score < G){
      int s1 = 100 * (rest_max + 1);
      int need = (G - score + s1 - 1) / s1;
      if (need >= p[rest_max]){
        continue;
      }
      num += need;
    }
    if (num < min_num) min_num = num;
  }
  cout << min_num << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        decimal[] abn = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
        var a = abn[0];
        var b = abn[1];
        var n = abn[2];

        decimal ans = 0;
        if (b > n)
        {
            ans = Math.Floor((a * n) / b) - a * Math.Floor(n / b);
        }
        else
        {
            ans = Math.Floor((a * (b - 1) / b)) - a * Math.Floor((b - 1) / b);
        }


        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28312
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin>>N;
    vector<vector<int>> a(N);
    REP(i,N) {
        int h,p;
        cin>>h>>p;
        a[i]={h+p,h,p};
    }
    sort(ALL(a));
    vector<vector<int>> dp(N+1,vector<int>(N+1,INF));
    dp[0][0]=0;
    REP(i,N) {
        REP(j,i+1) {
            if(a[i][1]>=dp[i][j]) {
                chmin(dp[i+1][j+1],dp[i][j]+a[i][2]);
            }
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    int ans=0;
    REP(i,N+1) {
        if(dp[N][i]!=INF) ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 196224
N,K = map(int,input().split())

ans = 0
for i in range(1,N+1):
    cnt = 0
    res = i
    while True:
        if res < K:
            res = res * 2
            cnt += 1
        if res >= K:
            break
    ans += (1/N) * pow(1/2,cnt)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){

    char ch;

    while(1){

        scanf("%c", &ch);

        if(ch == '\n') break;
        if('a' <= ch && ch <= 'z'){
            printf("%c", ch - 32);
        }else if('A' <= ch && ch <= 'Z'){
            printf("%c", ch + 32);
        }else{
            printf("%c", ch);
        }
    }

    printf("\n");

    return 0;

}


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

int B[15], C[]={1, 3, 5, 15, 25, 75};
int se(int i, int key){
    if(i==14){
        if(key<=B[i]) return 1;
        else return 0;
    }
    else{
        int ret=0;
        for(int j=0; j<6; ++j){
            if(B[i]<C[j]) break;
            if(key%C[j]<1) ret += se(i+1, key/C[j]);
        }
        return ret;
    }
}
int main() {
	int N; cin >> N;
	int A[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
	for(int i=0; i<15; ++i){
	    int p=N;
	    B[i]=1;
	    while(p>0){
	        B[i] += p/A[i];
	        p /= A[i];
	    }
	}
	cout << se(0, 75) << endl;
	return 0;
}


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

using namespace std;

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c;
    if(a<=b){
        if(b<=c){
            cout << a+b << endl; 
        }else{
            cout << a+c << endl;;
        }
    }else{
        if(a<=c){
            cout << a+b << endl;;
        }else{
            cout << b+c << endl;;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

#define INF (1e+7)

int main(void) {
    int num;
    cin >> num;
    string str;
    cin >> str;

    vector<vector<int>> cum(num+1, vector<int>(2));

    for(int i = 1; i <= num; i++) {
        bool flag = (str[i-1] == '#');
        for(int k = 0; k < 2; k++) {
            cum[i][k] = cum[i-1][k] + (k == flag);
        }
    }

    int ans = 0;
    for(int pos = 0; pos <= num; pos++) {
        // make ...#####
        debug(".:%d #:%d\n", cum[pos][0],
            cum[num][1] - cum[pos][1]
        );
        ans = max(ans, cum[pos][0] + (cum[num][1] - cum[pos][1]));
    }
    cout << num-ans << endl;
    return 0;
}

Measured memory_bytes: 14492
a, b, k = map(int, input().split())
count = 0
ls = []
for x in range(a, b):
    count += 1
    if count <= k and x not in ls:
        ls.append(x)
    if count > k:
        break
count = 0
for x in range(b, a-1, -1):
    count += 1
    if count <= k and x not in ls:
        ls.append(x)
    if count > k:
        break
ls.sort()
for x in range(len(ls)):
    print(ls[x])

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
// string s;

int main() {
    cin >> n;

    int a = sqrt(1 + 8 * n);
    if (a*a != 1 + 8 * n) {
        std::cout << "No" << '\n';
        return 0;
    }
    std::cout << "Yes" << '\n';
    int k = (1 + a) / 2;
    std::cout << k << '\n';
    int c = 1;
    VVi v(k, Vi(k-1));
    REP(i, k) {
        REP(j, k-1-i) {
            v[i][i+j] = c;
            v[i+j+1][i] = c;
            c++;
        }
    }
    REP(i, k) {
        std::cout << k-1 << ' ';
        REP(j, k-1) {
            std::cout << v[i][j];
            if (j != k-2) std::cout << ' ';
            else std::cout << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
main(){string s,t;cin>>s>>t;map<char,vector<int>> l;for(int i=0;i<s.size();i++)l[s[i]].push_back(i);int h=0,w=0;for(int i=0;i<t.size();i++)if(l.count(t[i])){auto it=lower_bound(l[t[i]].begin(),l[t[i]].end(),w);it==l[t[i]].end()?w=l[t[i]][0]+1,h++:w=*it+1;w-s.size()?:(w=0,h++);}else cout<<-1,exit(0);cout<<h*s.size()+w;}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  map<int, int> mp;
  REP(i,n){
    int a;
    cin >> a;
    if(a%4==0) mp[4]++;
    else if(a%2==0) mp[2]++;
    else mp[1]++;
  }
  if(mp[2]==0){
    cout << (mp[1]<=mp[4]+1 ? "Yes" : "No") << '\n';
  }else{
    cout << (mp[1]<=mp[4] ? "Yes" : "No") << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
from collections import deque

def resolve():
    readline=sys.stdin.readline

    h,w=map(int, readline().rstrip().split())
    ch,cw=map(int, readline().rstrip().split())
    dh,dw=map(int, readline().rstrip().split())
    ch-=1
    cw-=1
    dh-=1
    dw-=1

    mp=[[None for i in range(w)] for j in range(h)]

    for i in range(h):
        ss = readline().rstrip()
        for j in range(w):
            if ss[j]=="#":
                mp[i][j] = -1

    d = deque()
    d2 = deque()

    if mp[ch][cw]==None:
        mp[ch][cw]=0
        d.append((ch,cw))
    while len(d) > 0:
        y,x = d.popleft()
        d2.append((y,x))
        for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
            ny=y+dy
            nx=x+dx
            if 0 <= ny < h and 0 <= nx < w and mp[ny][nx]==None:
                mp[ny][nx]=mp[y][x]
                d.append((ny,nx))
        if len(d)==0:
            while len(d2) > 0:
                y2,x2 = d2.popleft()
                for dy in range(-2,3):
                    for dx in range(-2,3):
                        ny=y2+dy
                        nx=x2+dx
                        if 0 <= ny < h and 0 <= nx < w and mp[ny][nx]==None:
                            mp[ny][nx]=mp[y][x]+1
                            d.append((ny,nx))
    if mp[dh][dw] == None:
        print(-1)
    else:
        print(mp[dh][dw])    
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 103368
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    string s;
    cin>>s;

    if(s=="Sunny"){
        s="Cloudy";
    }
    else if(s=="Cloudy"){
        s="Rainy";
    }
    else if(s=="Rainy"){
        s="Sunny";
    }


    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
#D - Lunlun Number
import sys
sys.setrecursionlimit(10**6+1)
K = int(input())

ans = []
def dfs(A):
    if len(A)>=2:
        A_str = [str(i) for i in A] 
        A_str = ''.join(A_str)
        ans.append(int(A_str))
    if len(A) == 10:
        return
    if len(A) >= 1:
        #前の値が0,9のときは範囲が違う   
        if A[-1] == 9:
            sta = 8
            fin = 9+1
        elif A[-1] == 0:
            sta = 0
            fin = 1+1
        else:
            sta = A[-1] - 1
            fin = A[-1] + 1 + 1
        for v in range(sta,fin):
            A.append(v)
            dfs(A)
            A.pop()
    else:
        for v in range(1,9+1):
            A.append(v)
            dfs(A)
            A.pop()
dfs([])
ans = sorted(ans,reverse = False)
if K<=9:
    print(K)
else:
    print(ans[K-10])

Measured memory_bytes: 18840
#include<cstdio>
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
stack<char>s;
string a;
int main(){
    cin>>a;
    int n=a.size();
    for(int i=0;i<n;i++){
        s.push(a[i]);
    }
    bool ju=1;
    for(int i=0;i<n;i++){
        char top=s.top();
        if(top=='b') top='d';
        else if(top=='d') top='b';
        else if(top=='p') top='q';
        else if(top=='q') top='p';
        if(top==a[i]) {
        	ju=1;
			s.pop();
		}
        else {
        	ju=0;
        	break;
		}
    }
    if(ju==0) printf("No");
    else printf("Yes");
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  int a,b,c,w;
  scanf("%d %d %d",&a,&b,&c);
  if(a>c){
  	w=c;
  	c=a;
  	a=w;
  }
  if(a>b){
  	w=b;
  	b=a;
  	a=w;
  }
  if(b>c){
  	w=c;
  	c=b;
  	b=w;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
inline void solve(void){
  int S,W;
  in(S,W);
  out(W>=S?"unsafe":"safe");
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

    if(n<(a+b)){
        if(n<a){
            cout<<n;
        }
        else{
            cout<<a;
        }
    }else{
        if(n%(a+b)==0){
            cout<<a*(n/(a+b));
        }else{
            ll k = n%(a+b);
            if(k<a){
                cout<<a*(n/(a+b)) + k;
            }else{
                cout<<a*(n/(a+b)) + a;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <algorithm>
#include <vector>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <math.h>
#include <sstream>
using namespace std;
#define lld long long

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a.size() == 0 || b.size() == 0 || c.size() == 0)
		cout << "NO" << endl;
	if (a[(int)a.size() - 1] == b[0] && b[(int)b.size() - 1] == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n,a,cnt=0,sum=0;
      cin>>n;
      while(n--)
      {
            cin>>a;
            if(a%2==0)
            {
                  sum++;
                  if(a%3==0||a%5==0)
                        cnt++;
            }
      }
      if((sum&&cnt==sum)||(sum==0))
            cout<<"APPROVED"<<endl;
      else
            cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1] = R[n2] = SENTINEL;
    int i=0, j=0;
    for(int k=left;k<right;k++){
      cnt++;
      if(L[i]<=R[j]){
        A[k] = L[i++];
      } else {
        A[k] = R[j++];
      }
    }

}

void mergeSort(int A[], int n, int left, int right){
    if(left+1<right){
        int mid = (left + right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main(){
    int A[MAX], n, i;
    cnt=0;
    cin >> n;
    for(i=0;i<n;i++) cin >> A[i];
    mergeSort(A, n, 0, n);
    for(i=0;i<n;i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


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

int main() {
  int K, S;
  cin >> K >> S;
  
  int count=0;
  for(int i=0; i<=K; i++){
    for(int j=0; j<=K; j++){
      if(0<=S-(i+j) && S-(i+j)<=K) count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
const int mod = 1000000007;

struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint COM(ll n, ll k) {
  mint deno = 1;
  mint mole = 1;
  for (ll i = 0; i < k; i++) {
    deno *= n - i;
    mole *= (i + 1);
  }

  mint nCk = deno / mole;
  return nCk;
}

mint RepeatSquaring(mint N, ll P) {
  if (P == 0) return 1;
  if (P % 2 == 0) {
    mint t = RepeatSquaring(N, P / 2);
    return t * t;
  }
  return RepeatSquaring(N, P - 1) * N;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  mint X, Y;
  cin >> X.x >> Y.x;

  if ((2 * X.x - Y.x) % 3 != 0 || (2 * Y.x - X.x) % 3 != 0 || X.x * 2 < Y.x ||
      Y.x * 2 < X.x) {
    cout << 0 << endl;
    return 0;
  }

  mint A, B;
  A.x = (2 * X.x - Y.x) / 3;
  B.x = (2 * Y.x - X.x) / 3;

  mint ans = COM(A.x + B.x, A.x);
  cout << ans.x << endl;
}

Measured memory_bytes: 256
N_Y = list(map(int,input().split()))
N = N_Y[0]
Y = N_Y[1]

Y_divt = Y/1000
abc_list = []
break_flag = 0
for b in range(N+1):
    for a in range(N+1):
        if(9*a+4*b == Y_divt-N)&(N-(a+b) >= 0):
            abc_list.append(a)
            abc_list.append(b)
            abc_list.append(N-(a+b))
            break_flag = 1
            break
            
            
            
if(break_flag == 1):           
    print("{} {} {}".format(abc_list[0],abc_list[1],abc_list[2]))
else:
    print("{} {} {}".format(-1,-1,-1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end(), greater<int>());
    int Alice = 0, Bob = 0;
    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            Alice += a.at(i);
        }else{
            Bob += a.at(i);
        }
    }
    cout << Alice - Bob << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
 
class Main {
    public static void main(String args[]) {
        StringBuilder sb = new StringBuilder();
        Scanner scanner = new Scanner(System.in);
  
        int i = 0;
        while (true) {
            i++;
            int x = scanner.nextInt();
            if(x == 0) {
                break;                                              
            }
            sb.append("Case").append(" ").append(i + ":").append(" ").append(x).append("\n");

        }  
            System.out.print(sb);
            sb.setLength(0);
    }
}

Measured memory_bytes: 43448
N, A, B, C = map(int, input().split())
S = [input() for i in range(N)]
add = []

flag = True

for x in range(len(S)):
    if S[x] == "AB":
        if A == 0 and B == 0:
            flag = False
            break
        if A == 0:
            A += 1
            B -= 1
            add.append("A")
        elif B == 0:
            B += 1
            A -= 1
            add.append("B")
        elif x + 1 < len(S) and A + B + C == 2 and S[x + 1] != "AB":
            if S[x + 1] == "AC":
                A += 1
                B -= 1
                add.append("A")
            else:
                B += 1
                A -= 1
                add.append("B")
        elif A < B:
            A += 1
            B -= 1
            add.append("A")
        else:
            B += 1
            A -= 1
            add.append("B")
    elif S[x] == "AC":
        if A == 0 and C == 0:
            flag = False
            break
        if A == 0:
            A += 1
            C -= 1
            add.append("A")
        elif C == 0:
            C += 1
            A -= 1
            add.append("C")
        elif x + 1 < len(S) and A + B + C == 2 and S[x + 1] != "AC":
            if S[x + 1] == "BC":
                C += 1
                A -= 1
                add.append("C")
            else:
                A += 1
                C -= 1
                add.append("A")
        elif A < C:
            A += 1
            C -= 1
            add.append("A")
        else:
            C += 1
            A -= 1
            add.append("C")
    else:
        if B == 0 and C == 0:
            flag = False
            break
        if B == 0:
            B += 1
            C -= 1
            add.append("B")
        elif C == 0:
            C += 1
            B -= 1
            add.append("C")
        elif x + 1 < len(S) and A + B + C == 2 and S[x + 1] != "BC":
            if S[x + 1] == "AB":
                B += 1
                C -= 1
                add.append("B")
            else:
                C += 1
                B -= 1
                add.append("C")
        elif B < C:
            B += 1
            C -= 1
            add.append("B")
        else:
            C += 1
            B -= 1
            add.append("C")

if flag is True and A >= 0 and B >= 0 and C >= 0:
    print("Yes")
    for y in add:
        print(y)
else:
    print("No")


Measured memory_bytes: 85420
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int num[100001];
bool poss[100001];

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

	int N, M; cin >> N >> M;
	for (int i = 1; i <= N; i++) num[i] = 1;
	poss[1] = true;
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		if (poss[x]) poss[y] = true;
		num[x]--;
		num[y]++;
		if (num[x] == 0) poss[x] = 0;
	}

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

	return 0;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}

bool vector_finder(std::vector<int> vec, int number) { // vector 内にnumberがあるかどうか
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance( vec.begin(), itr );
	if (index != vec.size()) { // 発見できたとき
		return true;
	}
	else { // 発見できなかったとき
		return false;
	}
}

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (500*i + 100*j + 50*k == x) {
					ans++;
				}
			}
		}
	}
	return cout << ans << endl, 0;
}

Measured memory_bytes: 3600