akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int ans=1;
	string t=s.substr(0, 1), tmp="";
	for(int i=1; i<s.length(); i++){
		tmp+=s[i];
		if(t!=tmp){
			ans++;
			t=tmp;
			tmp="";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 644
#include<iostream>
#include<vector>
#include<algorithm>

int main() {
	int n,m=0;

	std::cin >> n;

	std::vector<int> v(n);

	for (int &x : v) {
		std::cin >> x;
	}

	std::sort(v.begin(), v.end());

	for (int i = 0; i < v.size() - 1; i++) {
		m += v[i];
	}

	std::cout << (m > v[n-1] ? "Yes" : "No") << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);


int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll X = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	//ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S[50],T[50],U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;

	ll all = 0;
	ll niku = 0;
	ll state = 2;
	bool down = true;
	

	//cin >> S;
	
	//vector<pair<int,int>> ch(50);
	
	

	cin >> N;// A >> B;

	
			 A = N / 1000;
			 N %= 1000;
			 B = N / 100;
			 N %= 100;
			 C = N / 10;
			 N %= 10;
			 D = N;

			 if (A == 2)
				 count++;
			 if (B == 2)
				 count++;
			 if (C == 2)
				 count++;
			 if (D == 2)
				 count++;

	cout << count << endl;

	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll bur(ll N,ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



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

char t[2];

int main(){
	scanf("%s", t);
	if(t[0] == 'a' || t[0] == 'e' || t[0] == 'i' || t[0] == 'o' || t[0] == 'u') printf("vowel\n");
	else printf("consonant\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int dp[2][100001];
int n,k;
int p[101];
int recur(int a,int g){
	
	if(dp[g][a]!=-1){
		return dp[g][a];
	}
	for(int i=0;i<n;i++){
		if(p[i]==a){
			if(g==0){
				dp[g][a]=0;
				return 0;
			}else{
				dp[g][a]=1;
				return 1;
			}
		}else{
			if(p[i]<a){
				int l=recur(a-p[i],!g);
				if(g==0){
					if(l==0){
						dp[g][a]=0;
						return dp[g][a];
					}
				}else{
					if(l==1){
						dp[g][a]=1;
						return dp[g][a];
					}
				}
			}
		}
	}
	if(dp[g][a]==-1){
		if(g==0){
			dp[g][a]=1;
		}else{
			dp[g][a]=0;
		}
	}
	return dp[g][a];
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<=k;j++){
			dp[i][j]=-1;
		}
	}
	if(recur(k,0)==0){
	    cout<<"First";
	}else{
	    cout<<"Second";
	}
}

Measured memory_bytes: 7296
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    long long k;
    std::cin >> k;

    std::queue<long long> q;
    for (long long i = 1; i < 10; i++) {
        q.push(i);
    }

    for (int i = 0; i < k - 1; i++) {
        long long t = q.front();
        q.pop();

        if (t % 10 != 0) {
            q.push(t * 10 + t % 10 - 1);
        }

        q.push(t * 10 + t % 10);

        if (t % 10 != 9) {
            q.push(t * 10 + t % 10 + 1);
        }
    }

    std::cout << q.front() << std::endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}

const int maxn = 1e5 + 69;

signed main()
{
//	freopen("TEXT.inp", "r", stdin); freopen("TEXT.out", "w", stdout);
	fastio();

	int n; cin >> n;
	int s = 0;
	vector<int> a(n + 1);
	int l = 1e9, r = 0;
	for (int i = 0; i < n; i++) {
        cin >> a[i];
        l = min(l, a[i]);
        r = max(r, a[i]);
	}

	ll ans = 1e12, tmp = 0;

	for (int i = l; i <= r; i++) {
        tmp = 0;
        for (int j = 0; j < n; j++) {
            tmp += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, tmp);
	}

	cout << ans;

}


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

int N,K;
int zero_point;

int dist(vector<int> &x,int start){
    if(start+K-1<zero_point)return (-1)*x[start];
    else if(start>=zero_point)return x[start+K-1];
    else return min(llabs(x[start]-x[start+K-1])+llabs(x[start]),llabs(x[start]-x[start+K-1])+llabs(x[start+K-1]));
}

signed main(){
    cin>>N>>K;
    vector <int> x(N);
    for(int i=0;i<N;i++)cin>>x[i];
    int ans=LONG_LONG_MAX;
    if(x[0]>=0)ans=x[K-1];
    else if(x[N-1]<0)ans=-1*x[N-K];
    else{
        int tmp;
        zero_point=lower_bound(x.begin(),x.end(),0)-x.begin();
        for(int i=0;i<=N-K;i++){
            tmp=dist(x,i);
            //cout<<"tmp:"<<tmp<<endl;
            ans=min(ans,tmp);
        }

    }
    //cout<<zero_point<<endl;
    cout<<ans<<endl;
	
}


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

int main() {
  int N;
  cin >> N;
  if ((N/1000==(N/100)%10&&(N/100)%10==(N/10)%10) || ((N/100)%10==(N/10)%10&&(N/10)%10==N%10))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n,k=[int(i) for i in input().split()]
arr=[int(i) for i in input().split()]
ans=0
mod=10**9+7
arr.sort() 
c=[0 for i in range(n)]
r=k-1
c[r]=1
def modinv(x,mod):
    return pow(x,mod-2,mod)
for i in range(r+1,n):
    c[i]=((c[i-1]*(i))*modinv(i-r,mod))%mod
pos=0
neg=0
for i in range(n):
    pos+=(arr[-1-i]*c[-1-i])%mod
    neg+=(arr[i]*c[-1-i])%mod
    pos%=mod
    neg%=mod
print((pos-neg)%mod)


Measured memory_bytes: 14416
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N, M)
d = {}
s = set()
for i in range(N):
    d[str(i * (L // N))] = S[i]
    s.add(str(i * (L // N)))

for i in range(M):
    key = str(i * (L // M))
    if key in s:
        if d[key] != T[i]:
            print(-1)
            exit()
print(L)

Measured memory_bytes: 31812
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

//#include <vector>
//#include <set>
//#include <map>
//#include <iostream>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000//10^12

//using namespace std;


int main(void)
{
	//変数の宣言
	int n,a,b,c;
	int l[10];
	int cost;
	int sum[2][500];

	//よく使う変数
	int i,j,k;
	int flag=0;
	int ans=0;
	int cnt=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//int sum=0;



	//データの読み込み


	scanf("%d %d %d %d",&n,&a,&b,&c);
//	scanf_s("%d %d %d %d",&n,&a,&b,&c);

	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
//		scanf_s("%d",&l[i]);
	}


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<(1<<n);i++){
		len=0;
		cost=0;
		for(j=0;j<n;j++){
			if(i&(1<<j)){
				if(len==0){
					len=l[j];
				}else{
					len=len+l[j];
					cost=cost+10;
				}
			}
		}

		sum[0][i]=len;
		sum[1][i]=cost;

	}

	ans=10000;
	for(i=1;i<(1<<n);i++){
		for(j=1;j<(1<<n);j++){
			for(k=1;k<(1<<n);k++){
				if((i&j)==0&&((j&k)==0&&(k&i)==0)){
//					printf("i=%d,j=%d,k=%d,i&j&k=%d\n",i,j,k,i&(j&k));
					temp=abs(a-sum[0][i])+abs(b-sum[0][j])+abs(c-sum[0][k])+sum[1][i]+sum[1][j]+sum[1][k];
					ans=min(ans,temp);
				}
			}
		}
	}

	//	printf("計算部分終了\n");

	//出力

	printf("%d",ans);

	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int num[101];

int main(void)
{
	int i;
	int n;
	int max = 0;
	
	while (scanf("%d", &n) != EOF){
		num[n]++;
		if (max < num[n]){
			max = num[n];
		}
	}
	
	for (i = 0; i <= 100; i++){
		if (num[i] == max){
			printf("%d\n", i);
		}
	}
	
	return 0;
}

Measured memory_bytes: 596
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long 
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
   // cout<<x<<' '<<y<<endl;
    if(y==0)
    return x;
    else
    return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
    if(m%2)
	r=(r*n)%p;
    n=(n*n)%p;
    m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
       return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
	z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	++z[i];
    if (i + z[i] - 1 > r)
	l = i, r = i + z[i] - 1;
    }
    return z;
}
int h,w;
char a[1005][1005];
int dp[1005][1005];
int solve(int i,int j)
{
	if(i==h-1&&j==w-1)
		return 1;
	if(dp[i][j]!=-1)
		return dp[i][j];
	int ans=0;
	if(j+1<w&&a[i][j+1]!='#')
		ans=solve(i,j+1)%mod;
	if(i+1<h&&a[i+1][j]!='#')
		ans=(ans+solve(i+1,j))%mod;
	dp[i][j]=ans;
	return ans;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   cin>>h>>w;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<h;i++)
   {
   	for(int j=0;j<w;j++)
   	{
   		cin>>a[i][j];
   	}
   }
   cout<<solve(0,0)<<endl;
}                       

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

int main(){
  int n;
  float x1,y1,x2,y2,x3,y3,x4,y4;
  cin>>n;
  while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4){
    if(((y2-y1)/(x2-x1))==((y4-y3)/(x4-x3))) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
def checkpalindrome(n):
  s=str(n)
  a=[]
  for i in range(len(s)):
    a.append(s[i])
  a.reverse()
  if ''.join(a)==s:
    return 1
  else:
    return 0
a,b=map(int,input().split())
ans=0
for i in range(a,b+1):
  ans+=checkpalindrome(i)
print(ans)

Measured memory_bytes: 73884
N = input()
A = [int(x) for x in input().split()]


def calc(A):
    for i in range(len(A)):
        if A[i] == 0:
            return False
        if A[i] % 2 == 1:
            return False
        A[i] = A[i] // 2
    return True

cnt = 0
while True:
    if calc(A) == False:
        break
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    string s; cin >> s;
	if(s[s.size()-1] == 's')s += "es";
	else s += "s";
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

int main()
{
	int N;

	cin >> N;

	vector<int> As(N,0);

	int max_n = 0;
	for (int ni = 0; ni < N; ni++) {
		cin >> As[ni];
		max_n = max(max_n, As[ni]);
	}

	sort(As.begin(), As.end());

	int md = max_n / 2;
	auto md_itr = lower_bound(As.begin(), As.end(), md);

	int md_r = *md_itr;
	int md_l = *(md_itr-1);

	int md_ans = md_r;
	if (md - md_l <= md_r - (md + max_n % 2) ) {
		md_ans = md_l;
	}

	cout << max_n << " " << md_ans;
	//printf("%.9f", ans);
	//std::cout << "Yes";

	return 0;
}



Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

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

    int max = -1, max_price[N];

    for (int i = N-1; i >= 0; i--) { 
        if (max < A[i]) max = A[i];
        max_price[i] = max;
    }

    int max_profit = -1, cnt = 0;

    for (int i = 0; i < N-1; i++) {
        int t = max_price[i+1] - A[i];
        if (max_profit < t) {
            max_profit = t;
            cnt = 1;
        } else if (max_profit == t) {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
from heapq import *

X, Y, A, B, C = list(map(int, input().split()))
PQR = [list(map(int, input().split())) for _ in range(3)]

def to_heap(l):
    l = [(-x, x) for x in l]
    heapify(l)
    return l

apples = [to_heap(l + [-1]) for l in PQR]
apple_count = [0, 0, 0]
sum_num = 0
while sum(apple_count) < (X + Y):
    if apple_count[0] == X:
        apples[0] = [(1, -1)]
    if apple_count[1] == Y:
        apples[1] = [(1, -1)]
    max_apple_index = max(range(3), key=lambda x: apples[x][0][1])
    sum_num += apples[max_apple_index][0][1]
    heappop(apples[max_apple_index])
    apple_count[max_apple_index] += 1

print(sum_num)

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

typedef pair< int, int > pii;

const int dx[8] = {0,1,1,1,0,-1,-1,-1}, dy[8] = {-1,-1,0,1,1,1,0,-1};

int H, W, counter[1010][1010];
string grid[1010];

int main() {
	cin >> H >> W;
	for_(i,0,H) cin >> grid[i];
	
	queue< pii > cur_que;
	
	for_(y,0,H) for_(x,0,W) {
		counter[y][x] = -1;
		if (grid[y][x] == '.') continue;
		counter[y][x] = grid[y][x] - '0';
		
		for_(d,0,8) {
			int xx = x + dx[d], yy = y + dy[d];
			if (grid[yy][xx] == '.') --counter[y][x];
		}
		
		if (counter[y][x] <= 0) cur_que.push(pii(x, y));
	}
	
	queue< pii > nxt_que;
	
	int ans = 0;
	
	while (!cur_que.empty()) {
		while (!cur_que.empty()) {
			pii p = cur_que.front(); cur_que.pop();
			int x = p.first, y = p.second;
			assert(grid[y][x] != '.');
			grid[y][x] = '.';
			
			for_(d,0,8) {
				int xx = x + dx[d], yy = y + dy[d];
				if (grid[yy][xx] == '.') continue;
				--counter[yy][xx];
				if (counter[yy][xx] == 0) nxt_que.push(pii(xx, yy));
			}
		}
		
		++ans;
		swap(cur_que, nxt_que);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 6224
# -*- coding: utf-8 -*-
# F
# queueの使い方、累積ダメージの更新の仕方がポイント
# 参考：https://atcoder.jp/contests/abc153/submissions/9750027

'''
3 3 2
1 2
5 4
9 2
'''

from collections import deque

N, D, A = map(int, input().split())
a = sorted(list(map(int, input().split())) for _ in range(N))
D *= 2

bomb_queue = deque()
bomb_dmg = 0
ans = 0

for x, h in a:
    # 過去の爆弾が有効でない座標に達していれば、その爆弾を捨て、累積ダメージからも差し引く
    while bomb_queue and bomb_queue[0][0] < x:
        # deque.popleft : 左側から要素を削除し、値を返す
        bomb_dmg -= bomb_queue.popleft()[1]

    # これまでの累積ダメージを差し引く
    h -= bomb_dmg
    if h > 0:
        # このモンスターを倒すのに必要な回数
        cnt = (h + A - 1) // A
        ans += cnt
        # x + Dまでダメージが与えられる
        # deque.append : 右側に付け加える
        bomb_queue.append((x + D, cnt * A))
        bomb_dmg += cnt * A

print(ans)

Measured memory_bytes: 85080
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <bitset>
#include <cmath>
#define ff first
#define ss second
#define MAXN 300005
#define INF 1000000001000000001LL
#define int long long

using namespace std;

const int mod = 998244353; //1000000007;
int n, i, a;
double ans = 0;

main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base :: sync_with_stdio(false);
    cin.tie();
    cin >> n;

    for(i = 0; i < n; i++)
        cin >> a, ans += 1.0 / a;

    cout << fixed << 1.0/ans;

    return 0;
}







Measured memory_bytes: 256
// https://atcoder.jp/contests/abc169/tasks/abc169_f

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 0
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 3000;
const int S_MAX = 3000;
const int A_I_MAX = 3000;
const int MOD = 998244353;

int N, S;
vector<int> A;

vector<int> dp;

int main() {
  cin >> N >> S;
  A = vector<int>(N);
  REP(i, N) cin >> A[i];

  dp = vector<int>(S + 1, 0);
  dp[0] = 1;

  REP(i, N) {
    for (int j = S; j >= 0; j--) {
      dp[j] = dp[j] * 2 % MOD;
      if (j >= A[i]) dp[j] = (dp[j] + dp[j - A[i]]) % MOD;
    }
    DUMP(dp);
  }

  int ans = dp[S];
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

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

	Int N, M;
	cin >> N >> M;

	vector<Int> k(M);
	vector<Int> p(M);
	vector<vector<Int>> s(M,vector<Int>(N,-1));

	Int temp = 0;
	for (Int i = 0; i < M; i++) {
		cin >> k[i];
		for (Int j = 0; j < k[i]; j++) {
			cin >> temp;
			s[i][j]=temp-1;//スイッチ番号を0-Indexedに変更
		}
	}


	for (Int i = 0; i < M; i++)cin >> p[i];

	vector<Int> mask(M);
	for (Int i = 0; i < M; i++) {
		for (int j = 0; j < k[i]; j++) {
			mask[i] += (1LL << s[i][j]);
		}
	}

	Int ans = 0;
	Int temp2 = 0;
	for (Int i = 0; i < (1LL<<N); i++) {//スイッチの個数分だけbit全探索
		Int flag = 0;//各電球が条件を満たしているなら0
		for (Int j = 0; j < M; j++) {//各電球についてpの条件を満たすかどうか
			temp2 = i & mask[j];
			Int count = 0;
			for (Int k = 0; k < N; k++) {
				if (temp2 & (1LL << k))count++;
			}
			if (count % 2 != p[j]) {
				flag = 1;
				break;
			}
			if (flag)break;
		}

		if (flag == 0)ans++;
	}

	cout << ans;
}

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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int n;
        cin >> n;
        int ans = (n - 2) * 180;
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
package main

import "fmt"

func main() {
	var s string
	week := map[string]int{
		"SUN": 0,
		"MON": 1,
		"TUE": 2,
		"WED": 3,
		"THU": 4,
		"FRI": 5,
		"SAT": 6,
	}
	fmt.Scan(&s)
	fmt.Println(7 - week[s])
}


Measured memory_bytes: 1836
from collections import Counter
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for i in range(n)]

    def getParent(self):
        return [self.find(i) for i in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if (root_x == root_y):
            return
        elif self.rank[root_x] > self.rank[root_y]:
            self.parent[root_y] = root_x

        elif self.rank[root_y] > self.rank[root_x]:
            self.parent[root_x] = root_y

        else:
            self.parent[root_x] = root_y
            self.rank[root_y] += 1

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def memsInGroup(self, x):
        """
        O(N)かかります
        """
        root = self.find(x)
        return [i for i in range(N) if root == self.find(i)]

    def sizeOfGroup(self, x):
        return len(self.memsInGroup(x))


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

friend = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    friend.unite(a-1, b-1)

roots = friend.getParent()
counts = Counter(roots)

ans = max(counts.values())
print(ans)


Measured memory_bytes: 140312
// rust input macro: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
  input!{
    n: i32,
    s: [String; n]
  };
  
  let mut set = std::collections::HashSet::new();
  for si in s.iter() {
    set.insert(si);
  }
  println!("{}", set.len());
}

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

const int mod = 1e9 + 7;

vector<int> mem;
int Pow(int a, int b) {
    //cerr << a << " " << b << endl;
    if (b < 0) return 0;
    if (b == 0) return 1;
    if (mem[b]) return mem[b];

    int ret = 3 * Pow(a, b - 1) % mod;
    mem[b] = ret;
    return ret;
}
signed main() {
    string S;
    cin >> S;

    const int n = S.size();
    mem.resize(n + 1);
    Pow(3, n);

    vector<int> a(n), c(n), l(n), r(n);
    for (int i = 0; i < n; i++) {
        a[i] = a[i - !!i] + (S[i] == 'A');
        l[i] = l[i - !!i] + (S[i] == '?');

        int idx = n - i - 1;
        c[idx] = c[idx + !!i] + (S[idx] == 'C');
        r[idx] = r[idx + !!i] + (S[idx] == '?');
    }

    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if (S[i] != 'B' && S[i] != '?') continue;
        ans += a[i - 1] * c[i + 1] * Pow(3, l[i - 1] + r[i + 1]) % mod; // ABC
        ans += a[i - 1] * r[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 1) % mod; // AB?
        ans += l[i - 1] * c[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 1) % mod; // ?BC
        ans += l[i - 1] * r[i + 1] * Pow(3, l[i - 1] + r[i + 1] - 2) % mod; // AB?
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
            using namespace std;
             
            int main() {
              int N;
              cin >> N;
              
              if (N == 1 || N == 2 || N == 3 || N == 4 || N == 5 || N == 6 || N == 7 || N == 8 || N == 9 || N == 10 || N == 12 || N == 14 || N == 15 || N == 16 || N == 18 || N == 20 || N == 21 || N == 24 || N == 25 || N == 27 || N == 30 || N == 32 || N == 35) {
                cout << "Yes" << endl;
              }
              else if (N == 36 || N == 40  || N == 42 || N == 45  || N == 48  || N == 49  || N == 56  || N == 63  || N == 64  || N == 72  || N == 81) {
                cout << "Yes" << endl;
              }
              else {
                cout << "No" << endl;
              }
            }

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

int a[100010];
int ll[100010], rr[100010];

signed main () {
	int n; scanf("%lld", &n);
	for (int i = 0; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	ll[n] = rr[n] = a[n];
	for (int i = n - 1; i >= 0; i--) {
		ll[i] = (ll[i + 1] + 1) / 2 + a[i];
		rr[i] = rr[i + 1] + a[i];
	}
	int l = 1, r = 1;
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		l = max(l, ll[i]), r = min(r, rr[i]);
		if (l > r || r < a[i]) {
			printf("-1\n");
			return 0;
		}
		ans += r;
		l = l - a[i];
		r = (r - a[i]) * 2;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6104
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  string s;cin>>s;
  int ans = 0;
  rep(i, n-2){
    if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin>>s;
	for(int i=0;i<3;++i)
		cout<<s[i];
	
	
	return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(ld i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    ld x; cin >> x;
    REP(a, -1000, 1000){
        REP(b, -1000, 1000){
            if(a*a*a*a*a - b*b*b*b*b == x){
                cout << a  << " " << b << endl;
                return 0;
            }
        }
    }
}

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

void dfs(const vector<vector<int>> &G, vector<bool> &seen, int v, ll sum, vector<ll> &values)
{
    seen[v] = true;
    values[v] += sum;
    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, seen, next_v, values[v], values);
    }
}

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

    vector<vector<int>> graph(n + 1);
    for (int i = 1; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    vector<ll> values(n + 1, 0);
    vector<bool> seen(n + 1, false);

    for (int i = 0; i < q; ++i)
    {
        int p, x;
        cin >> p >> x;

        values[p] += x;
    }

    dfs(graph, seen, 1, 0, values);

    for (int i = 1; i <= n; ++i)
        cout << values[i] << " ";
    cout << endl;
}

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

int main()
{
	int n;
	cin >> n;
	if (n < 105) {
		cout << 0 << endl;
		return 0;
	}

	int ret = 1;
	for (int i = 107; i <= n; i += 2) {
		int count = 0;
		for (int j = 1; j <= i; j += 2) {
			if (i%j == 0) {
				++count;
			}
		}
		if (count == 8) {
			++ret;
		}
	}

	cout << ret << endl;

	return 0;
}


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

int n, ma, mb, a[50], b[50], c[50], inf = 1e9 + 7, Ma, Mb;
int dp[50][444][444]; //dp[i][j][k] i番目まででj[g],k[g]となる最小費用

int main()
{
    cin >> n >> ma >> mb;
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        Ma = max(a[i], Ma);
        Mb = max(b[i], Mb);
    }
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n * Ma; j++)
        {
            for (int k = 0; k <= n * Mb; k++)
            {
                dp[i][j][k] = inf;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= n * Ma; j++)
        {
            for (int k = 0; k <= n * Mb; k++)
            {
                if (dp[i][j][k] == inf)
                    continue;
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    int ans = inf;
    for (int i = 1; i <= n * Ma; i++)
    {
        for (int j = 1; j <= n * Mb; j++)
        {
            if (i * mb == j * ma)
                ans = min(ans, dp[n][i][j]);
        }
    }
    if (ans == inf)
        ans = -1;
    printf("%d\n", ans);
}

Measured memory_bytes: 32896
#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
int main()
{
    fast;
   ll t=1;
   //std::cin >> t;
   while(t--)
   {
       ll n,i,j=0,m,a,b;
       string s;
       std::cin >> s;
       if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
       cout<<"3\n";
       else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R'))
       cout<<"2\n";
       else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
       cout<<"1\n";
       else
       cout<<"0\n";
   }
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
int main(){
    double floor(double);
    int n;
    long int ans1=0;
    double ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0){
            ans+=i;
        }
    }
    ans1=floor(ans);
    printf("%ld\n",ans1);
}


Measured memory_bytes: 2212
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int b, r, g, c, s, t;
    public static void main(String[] args) {
        while(read()){
            solve();
        }
    }

    static boolean read(){
        b = sc.nextInt();
        r = sc.nextInt();
        g = sc.nextInt();
        c = sc.nextInt();
        s = sc.nextInt();
        t = sc.nextInt();
        if((b|r|g|c|s|t) == 0)return false;
        return true;
    }

    static void solve(){
        System.out.println(100 + b*15 + r*15 + (b*5+r*3)*15 + g*7 + c*2 - (b*5+r*3)*2 - (t-b*5-r*3-s)*3);
    }

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>

int main() {
	std::string s;

	std::cin >> s;

	int lose = std::count(s.begin(), s.end(), 'x');

	if (15 - lose >= 8 ) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cassert>
#include <functional>

template <int K, class T>
struct Trie {
    struct Node {
        std::array<int, K> nxt;
        int id, sz, ch;
        explicit Node() : id(-1), sz(0), ch(0) { nxt.fill(-1); }
    };

    std::vector<Node> nodes;
    std::function<int(T)> enc;
    std::vector<std::vector<int>> travs;

    explicit Trie(T base) {
        nodes.emplace_back();
        enc = [=](T c) { return c - base; };
    }

    explicit Trie(const std::function<int(T)>& enc)
        : enc(enc) { nodes.emplace_back(-1); }

    template <class Container>
    void add(const Container& s, int id) {
        int pos = 0;

        for (T c : s) {
            ++nodes[pos].sz;

            int ci = enc(c);

            int npos = nodes[pos].nxt[ci];
            if (npos == -1) {
                npos = nodes.size();
                nodes[pos].nxt[ci] = npos;
                nodes.emplace_back();

                ++nodes[pos].ch;
            }
            pos = npos;
        }

        ++nodes[pos].sz;
        nodes[pos].id = id;
    }

    int dfs(int pos, std::vector<int>& cs, bool solo) {
        if (nodes[pos].id != -1) travs[nodes[pos].id] = cs;

        int ret = pos;
        for (int c = 0; c < K; ++c) {
            int npos = nodes[pos].nxt[c];
            if (npos == -1) continue;

            // reducible?
            bool red = solo &&
                       (nodes[pos].ch == 1) &&
                       (nodes[pos].id == -1);

            if (!red) cs.push_back(c);
            nodes[pos].nxt[c] = dfs(npos, cs, nodes[pos].ch == 1);
            if (!red) {
                cs.pop_back();
            } else {
                ret = nodes[pos].nxt[c];  // compress
            }
        }
        return ret;
    }

    void compress(int n) {
        travs.resize(n);
        std::vector<int> cs;
        dfs(0, cs, false);
    }

    Node& operator[](int pos) { return nodes[pos]; }
    Node operator[](int pos) const { return nodes[pos]; }
};

void solve() {
    int n;
    std::cin >> n;

    Trie<26, char> trie('a');
    for (int i = 0; i < n; ++i) {
        std::string s;
        std::cin >> s;
        trie.add(s, i);
    }

    trie.compress(n);

    int q;
    std::cin >> q;
    while (q--) {
        int k;
        std::cin >> k;
        --k;

        std::vector<int> cs(26);
        for (auto& c : cs) {
            char d;
            std::cin >> d;
            c = d - 'a';
        }

        int pos = 0, ans = 1;
        for (auto c : trie.travs[k]) {
            if (trie[pos].id != -1) ++ans;

            for (auto d : cs) {
                int npos = trie[pos].nxt[d];
                if (d != c) {
                    if (npos != -1) ans += trie[npos].sz;
                } else {
                    assert(npos != -1);
                    pos = npos;
                    break;
                }
            }
        }

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

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

    solve();

    return 0;
}


Measured memory_bytes: 86232
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,ans,a[100005],b[100005];
int main()
{
    scanf("%d",&n);
    for(i=1;i<=n+1;i++)
    {
        scanf("%d",&a[i]);
    }
    long long ans=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        int d=min(a[i],b[i]);
        ans+=d,b[i]-=d,a[i]-=d;
        d=min(a[i+1],b[i]);
        ans+=d,b[i]-=d,a[i+1]-=d;
    }
    printf("%lld\n",ans);
    return 0;
}

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

bool single(string t){
    int n = t.length();
    char c = t[0];
    for(int i=1; i<n; i++){
        if(t[i] != c) return false;
    }
    return true;
}

int operate(string s, char c){
    if(single(s)) return 0;
    
    int ret = 1;
    string t = "";
    int n = s.length();
    for(int i=0; i<n-1; i++){
        if(s[i]==c || s[i+1]==c){
            t.push_back(c);
        }else{
            t.push_back(s[i]);
        }
    }
    if(single(t)) ret = 1;
    else ret = 1 + operate(t, c);

    return ret;
}

int main(){
    string s;  cin >> s;
    int ans = 1e9;
    for(char c='a'; c<='z'; c++){
        ans = min(ans, operate(s,c));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

if N == 1:
    print(max(inputs[0]))
else:
    # dp[i]には1, 2, 3を選択した時の幸福度の最大値を入れている
    dp = [[0, 0, 0] for _ in range(N)]
    dp[0] = inputs[0]
    for i in range(N):
        dp[i][0] = max(dp[i-1][1] + inputs[i][0], dp[i-1][2] + inputs[i][0])
        dp[i][1] = max(dp[i-1][2] + inputs[i][1], dp[i-1][0] + inputs[i][1])
        dp[i][2] = max(dp[i-1][0] + inputs[i][2], dp[i-1][1] + inputs[i][2])

    print(max(dp[-1]))


Measured memory_bytes: 44108
#include<bits/stdc++.h>
using namespace std;
int N;
int happy[100001][3];
int memo[100001][3];
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%d %d %d",&happy[i][0],&happy[i][1],&happy[i][2]);
		for(int j=0;j<3;j++)	memo[i][j]=0;
	}
	memo[0][0]=happy[0][0];
	memo[0][1]=happy[0][1];
	memo[0][2]=happy[0][2];
	
	for(int i=1;i<N;i++)
	{
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<3;k++)
			{
				if(j==k)	continue;
				memo[i][j]=max(memo[i][j],memo[i-1][k]+happy[i][j]);
			}
		}
	}
	printf("%d\n",max(memo[N-1][0],max(memo[N-1][1],memo[N-1][2])));
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;
int main(){
    ll N,M;
    cin >> N>> M;
    ll hwk;
    hwk =0;
    int A;
    rep(i,M){
        cin >> A;
        hwk += A;
    }
    if(hwk > N) cout << -1;
    else cout << N-hwk;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int H, W;
    cin >> H >> W;
    string s[H];
    rep(i, H) cin >> s[i];
    int A[H-1][W-1];
    fill(A[0], A[H-1], 0);
    rep(i, H-1) rep(j, W-1){
        rep(x, 2) rep(y, 2){
            A[i][j] ^= (s[i+x][j+y] == '.');
        }
    }
    int h[W-1];
    fill(h, h+(W-1), 0);
    int ans = max(H, W);
    rep(i, H-1){
        rep(j, W-1){
            if(A[i][j] == 1) h[j] = 0;
            else h[j]++;
        }
        int l[W-1], r[W-1]; //[l,r]
        stack<int> L, R;
        rep(j, W-1){
            while(!L.empty() && h[L.top()] >= h[j]) L.pop();
            if(L.empty()) l[j] = 0;
            else l[j] = L.top()+1;
            L.push(j);
        }
        rep3(j, W-2, 0){
            while(!R.empty() && h[R.top()] >= h[j]) R.pop();
            if(R.empty()) r[j] = W-2;
            else r[j] = R.top()-1;
            R.push(j);
        }
        rep(j, W-1) chmax(ans, (h[j]+1)*(r[j]-l[j]+2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 26844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 1e9+7;
ll pow25[2000005],pow26[2000005];

void init()
{
	pow25[0] = 1;
	pow26[0] = 1;
	rep(i,2000004)
	{
		pow25[i+1] = pow25[i] * 25 % MOD;
		pow26[i+1] = pow26[i] * 26 % MOD;
	}
}

const int MAX = 2100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
	COMinit();
	init();
	ll K;
	cin >> K;
	string S;
	cin >> S;
	ll s = S.size();
	ll ans = 0;
	rep(i,K+1)
	{
		ans = (ans + (COM(s+i-1,s-1) * (pow25[i] * pow26[K-i] % MOD) % MOD) % MOD) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 85808