akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
	int height,width;
	int i,j;
	
	while(1){
		scanf("%d %d",&height,&width);
		if(height==0 && width==0){
			break;
		}
		for(i=0;i<height;i++){
			for(j=0;j<width;j++){
				if(i==0 | i==height-1){
					printf("#");
				}else if(j==0 || j==width-1){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
t=[]
j=0
def FillZero(str,i)
	while str.size<i
		str="0"+str
	end
	return str
end
loop{
	a,b,c=gets.chomp.split(' ').map(&:to_i)
	if a==-1 and b==-1 and c==-1 then
		break
	end 
	t[j]=2 * 3600 - (a * 3600 + b * 60 + c)
	j+=1
}
j-=1
(0..j).each{|i|
	h=(t[i]/3600).floor
	m=((t[i]-h*3600)/60).floor
	s=t[i]%60
	puts FillZero(h.to_s,2) + ":" + FillZero(m.to_s,2) + ":" + FillZero(s.to_s,2)

	t[i]=3*t[i]
	h=(t[i]/3600).floor
	m=((t[i]-h*3600)/60).floor
	s=t[i]%60
	puts FillZero(h.to_s,2) + ":" + FillZero(m.to_s,2) + ":" + FillZero(s.to_s,2)
}

Measured memory_bytes: 6124
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int s,sh,sm,g,gh,gm,ng[][2]={{0,5},{0,6},{1,6},{2,6}},t[][7]={{0,300,500,600,700,1350,1650},{0,0,350,450,600,1150,1500},{0,0,0,250,400,1000,1350},{0,0,0,0,250,850,1300},{0,0,0,0,0,600,1150},{0,0,0,0,0,0,500}};

int main(){
	while(cin>>s&&s){
		cin>>sh>>sm>>g>>gh>>gm;
		s--;g--;
		if(s>g)swap(s,g);
		int st=sh*60+sm,gt=gh*60+gm;
		int ok=1;
		rep(i,4)if(s==ng[i][0]&&g==ng[i][1])ok=0;
		if(ok&&(1050<=st&&st<=1170||1050<=gt&&gt<=1170))cout<<(t[s][g]/50+1)/2*50<<endl;
		else cout<<t[s][g]<<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  ll n,m;
  cin>>n>>m;

  for(ll i=m/n;i>0;i--){
    if(m%i==0) {
      cout << i << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x+mo_num)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e5+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
int32_t main()
{
    IOS
    cin>>n;
    int key=1;
    int x;
    fun(i) {
        cin >> a[i];
        if(i==1) {
            x = a[i] - 1;
            continue;
        }
        if(a[i]>x)
        {
            x=a[i]-1;
        }else if(a[i]==x){
            continue;
        }else key=0;

    }
    if(key)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
char str[13][4][3];
int num[13][4];
char pro[2];
int main(){
	while(1){
		scanf("%s",pro);
		if(pro[0]=='#')return 0;
		for(int i=0;i<4;i++)
			for(int j=0;j<13;j++)
				scanf("%s",str[j][i]);
		for(int i=0;i<13;i++)
			for(int j=0;j<4;j++){
				if(str[i][j][0]=='A')num[i][j]=14;
				else if(str[i][j][0]=='K')num[i][j]=13;
				else if(str[i][j][0]=='Q')num[i][j]=12;
				else if(str[i][j][0]=='J')num[i][j]=11;
				else if(str[i][j][0]=='T')num[i][j]=10;
				else num[i][j]=str[i][j][0]-'0';
				if(str[i][j][1]==pro[0])num[i][j]+=40;
			}
		int ns=0;
		int ew=0;
		int at=0;
		for(int i=0;i<13;i++){
			char c=str[i][at][1];
			int n=at;
			int p=num[i][at];
			for(int j=1;j<4;j++){
				if((c==str[i][(at+j)%4][1]||num[i][(at+j)%4]>40)){
					if(p<num[i][(at+j)%4]){
						p=num[i][(at+j)%4];
						n=(at+j)%4;
					}
				}
			}
			if(n%2)ew++;
			else ns++;
			at=n;
		}
		if(ew>6)printf("EW %d\n",ew-6);
		else printf("NS %d\n",ns-6);
	}
}

Measured memory_bytes: 964
(n,_),*s=[[*map(int,t.split())]for t in open(0)]
d=[1,-1]+[0]*2*n
for i in range(n):
  d[i]=(d[i-1]+d[i])%998244353
  for l,r in s:
    d[i+l]+=d[i]
    d[i-~r]-=d[i]
print(d[n-1])

Measured memory_bytes: 24528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.size()){
    s[i] = (s[i]-'A'+n)%26+'A';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    int n;
    cin>>n;
    int r=n%1000;
    if(r==0){
        cout<<0<<endl;
        return 0;
    }
    cout<<1000-r<<endl;

    return 0;
}




Measured memory_bytes: 3588
li = []
while True:
    buf = input().split(' ')
    a = int(buf[0])
    op = buf[1]
    b = int(buf[2])
    if op == '?':
        break
    li.append((a, op, b))


for a, op, b in li:
    if op == '+':
        ans = a + b
    elif op == '-':
        ans = a - b
    elif op == '*':
        ans = a * b
    elif op == '/':
        ans = a // b

    print(ans)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    ll A, B, C;
    cin >> A >> B >> C;

    ll ans = 1LL << 62;
    ans = min(ans, (A % 2) * B * C);
    ans = min(ans, (B % 2) * A * C);
    ans = min(ans, (C % 2) * B * A);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,x = list(map(int,input().split()))
a = [0 for i in range(n+1)]
a[0] = 1
su = [0 for i in range(n+1)]
su[0] = 1
for i in range(1,n+1):
    a[i] = a[i-1]*2 + 1
    su[i] = su[i-1]*2 + 3

ans = 0
i = n
jouken = False
while True:
    if i == 0:
        if x ==1:
            ans += 1
        break
    if x==1:
        break
    if x == su[i]:
        ans+=a[i]
        break
    if x == int(su[i]/2) +1:
        ans += a[i-1] +1
        break
    elif x < int(su[i]/2)+1:
        i -= 1
        x -= 1
    elif x > int(su[i]/2)+1:
        i -= 1
        ans += a[i]+1
        x -= su[i]
        x -= 2

print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[200010],k,ans=0;
    ll sum[200010]={};
    cin>>n>>k;
    map<ll,ll> mp;
    rep(i,n){
        cin>>a[i];
        a[i]--;
        sum[i+1]=sum[i]+a[i];
        sum[i+1]+=k;
        sum[i+1]%=k;
    }
    rep(i,min(n+1,k-1)){
        mp[sum[i]]++;
    }
    // rep(i,n+1) cout<<sum[i]<<" ";
    // cout<<endl;
    rep(i,n){
        mp[sum[i]]--;
        if(i+k-1<=n) mp[sum[i+k-1]]++;
        // cout<<i<<" "<<mp[sum[i]]<<endl;
        ans+=mp[sum[i]];
        // cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
K,_=gets.chomp.split(' ').map{|n| n.to_i}

if(K<=500)
	puts K
	for i in 1..K
		puts ([i]*K).join(" ")
	end
else
	puts 500
	arr = Array.new(500){|i| i.to_i + 1}
	arr2 = Array.new(500){|i| i.to_i+1 <= K - 500 ? i.to_i + 1 + 500 : i.to_i + 1}
	rem = K - 500
	for i in 1..500
		if(i%2 == 1)
			puts arr.rotate(i-1).join(" ")
		else
			puts arr2.rotate(i-1).join(" ")
		end
	end
end



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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
	// random_device rnd;
	// mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A*N,B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <stdio.h>
using namespace std;
int main(){
	vector<int> num;
	vector<double> h;
	vector<double> w;
	vector<double> bmi;
	int n;
	double height,weight;
	while(scanf("%d,%lf,%lf",&n,&weight,&height)!=EOF){
		num.push_back(n);
		h.push_back(height);
		w.push_back(weight);
		bmi.push_back(weight/height/height);
	}
	int c=0;
	for(int i=0;i<num.size();i++){
		if(bmi[i]>=25.0){
			c++;
			cout<<num[i]<<endl;
		}
	}
	if(c==0)
		cout<<"該当なし"<<endl;
	return 0;
}

Measured memory_bytes: 1256
#include <stdio.h>

int main(void){

	int money = 100000;
	int i, n;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		money += money * 0.05;
		if(money % 1000 != 0){
			money = (money + 1000) / 1000 * 1000;
		}
	}
	
	printf("%d\n", money);
	
	return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
int main(){
  int m,f,r;
  cin >> m >> f >> r;
  while(m!=-1||f!=-1||r!=-1){
    if(m==-1||f==-1) cout << "F" << endl;
    else if(m+f>=80) cout << "A" << endl;
    else if(m+f>=65) cout << "B" << endl;
    else if(m+f>=50) cout << "C" << endl;
    else if(m+f>=30)
      if(r>=50) cout << "C" << endl;
      else cout << "D" << endl;
    else cout << "F" << endl;

    cin >> m >> f >> r;
  }
  return 0;
}


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

using namespace std;


int main(){

  int n,c[256]={};
  string s;
  cin>>n>>s;

  for(int i=0;i<s.size();i++)
    c[s[i]]++;

  int cc[10]={},ans=0;

  for(int i='a';i<='z';i++)
    cc[c[i]]++;

  for(int i=1;i<=9;i++)
    if(i==1)ans+=cc[i]*2;
    else if(cc[i]>=2)ans+=cc[i]*2+4;
    else if(cc[i]==1)ans+=4;
  cout<<ans-1<<endl;
  return 0;
}

Measured memory_bytes: 3188
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 998244353;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 210
int x[N], y[N];
ll c[N][N];
map<P, bool> used[N];

int comb(int n, int k){
	if(c[n][k]) return c[n][k];
	if(k==n || k==0) return c[n][k] = 1;
	return c[n][k] = (comb(n-1, k-1)+comb(n-1, k))%mod;
}

int main(){
	int n;
	cin>>n;
	ll res = -(1+n+n*(n-1)/2), t = 1;
	int m = n;
	while(m--) (t<<=1)%=mod;
	res += t;
	rep(i, n){
		cin>>x[i]>>y[i];
	}
	rep(i, n) for(int j = i+1; j < n; j++){
		int cnt = 2;
		int xx = x[j]-x[i], yy = y[j]-y[i];
		int g = __gcd(xx, yy);
		xx /= g; yy /= g;
		if(xx<0){
			xx *= -1;
			yy *= -1;
		}
		P p = P(xx, yy);
		if(used[i][p]) continue;
		used[i][p] = used[j][p] = true;
		for(int k = j+1; k < n; k++){
			int xx2 = x[k]-x[i], yy2 = y[k]-y[i];
			int g2 = __gcd(xx2, yy2);
			xx2 /= g2; yy2 /= g2;
			if(xx2<0){
				xx2 *= -1;
				yy2 *= -1;
			}
			P p2 = P(xx2, yy2);
			if(used[k][p2]) continue;
			if(xx==xx2 && yy==yy2){
				used[k][p2] = true;
				cnt++;
			}
		}
		for(int k = 3; k <= cnt; k++){
			(res-=comb(cnt, k))%=mod;
		}
		cerr<<cnt<<endl;
	}
	cout<<(res+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<cstdio>
#include<algorithm>

#define N (1<<17)

using namespace std;

int n, p[N];
int Ans;

int main()
{
	scanf("%d", &n);
	for (int i = 1;i <= n;i++)
	{
		scanf("%d", &p[i]);
	}
	for (int i = 1;i <= n;i++)
	{
		if (i == n&&p[i] == i)
		{
			Ans++;
		}
		else if (p[i] == i)
		{
			i++, Ans++;
		}
	}
	printf("%d\n", Ans);
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<string> code(n);
        int maxlength=0;
        for(int i=0; i<n; i++){
            string tmp,str="";
            cin >> tmp;
            str += tmp[0];
            for(int j=0; j<(int)tmp.length()-1; j++){
                if(tmp[j]=='a' || tmp[j]=='i' || tmp[j]=='u'
                   || tmp[j]=='e' || tmp[j]=='o'){
                    str+=tmp[j+1];
                }
            }
            code[i] = str;
            maxlength = max(maxlength, (int)str.length());
        }

        for(int i=0; i<maxlength; i++){
            set<string> s;
            for(int j=0; j<n; j++){
                if(i>=(int)code[j].length()){
                    s.insert(code[j]);
                }else{
                    s.insert(code[j].substr(0,i+1));
                }
            }
            if((int)s.size()==n){
                cout << i+1 << endl;
                break;
            }else if(i==maxlength-1){
                cout << -1 << endl;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string S, T; cin >> S >> T;
	int j = 2;
	for (int i = 0; i < 3; i++) {
		if (S.at(i) != T.at(j)) {
			cout << "NO" << endl;
			return 0;
		}
		j--;
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 256
import fractions

A, B, C, D = map(int, input().split())

lcm = (C * D)//fractions.gcd(C, D)
area = B - A + 1
Carea = (B // C - (A-1) // C)
Darea = (B // D - (A-1) // D)
CDarea = (B//lcm - (A-1)//lcm)

print(area - (Carea+Darea-CDarea))


Measured memory_bytes: 5472
n,w = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
inf = float("inf")
dp = [inf]*(10**5+1)
dp[0] = 0
mv = 0
for x,v in l:
  mv += v
  for i in range(mv,v-1,-1):
    dp[i] = min(dp[i],dp[i-v]+x)
    
for i in range(mv,-1,-1):
  if dp[i]<=w:
    print(i)
    break

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

int main() {
  int N, K, a=1;
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    if (a<K) {
      a *= 2;
    }
    else {
      a += K;
    }
  }
  cout << a << endl;
}

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

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 10007
#define left lleft
#define right rright
#define INF 2000000000
#define Linf 1000000000000000000LL
#define next nnext

using namespace std;

int N,K,ans;
int a[5002];
bool lcheck[5002][5002],rcheck[5002][5002];

int main(){
	scanf("%d %d",&N,&K);
	for(int i=1; i<=N; i++) scanf("%d",&a[i]);
	lcheck[0][0] = rcheck[N+1][0] = true;
	for(int i=1; i<=N; i++){
		for(int j=0; j<K; j++){
			if(!lcheck[i-1][j]) continue;
			lcheck[i][j] = true;
			if(j+a[i] < K) lcheck[i][j+a[i]] = true;
		}
	}
	for(int i=N; i>=1; i--){
		for(int j=0; j<K; j++){
			if(!rcheck[i+1][j]) continue;
			rcheck[i][j] = true;
			if(j+a[i] < K) rcheck[i][j+a[i]] = true;
		}
	}
	for(int i=1; i<=N; i++){
		int t = K;
		bool flag = false;
		for(int j=0; j<K; j++){
			if(!lcheck[i-1][j]) continue;
			while(1){
				if(t-1 < max(K-a[i]-j,0)) break;
				t--;
				if(t > K-1-j) continue;
				if(rcheck[i+1][t]){
					flag = true;
					break;
				}
			}
			if(flag) break;
		}
		if(!flag) ans++;
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 49152
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

int main() {
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.length()-1]==b[0])
		if(b[b.length()-1]==c[0]){
			print("YES");
			return 0;
		}
	print("NO");

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  char s[20];
  scanf("%s",s);
  int l=strlen(s),ans=l*9+s[0]-57,sum=0;
  for(int i=0;i<l;i++){
    sum+=s[i]-48;
  }
  if(sum!=ans) ans--;
  printf("%d",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int k=1;int x=0;
    char c=getchar();
    while ((c<'0'||c>'9')&&c!='-')c=getchar();
    if(c=='-')
    k=-1,c=getchar();
    while(c>='0'&&c<='9')
    x=x*10+c-'0',c=getchar();
    return k*x;
}
string a;
int main()
{
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d')
			a[i]='b';
        else if(a[i]=='p')
			a[i]='q';
        else if(a[i]=='q')
			a[i]='p';
    }
    if(a==b)
		cout<<"Yes";
    else
		cout<<"No";
}


Measured memory_bytes: 764
#include <iostream>

using ll = long long;

int main()
{
  ll X, K, D;
  std::cin >> X >> K >> D;
  if (X < 0) X = -X;

  ll r = X - K * D;

  if (X / D < K)
  {
    ll q = X / D;
    X -= q * D;
    K -= q;

    if(K % 2 == 1)
    {
      X = D - X;
    }
    
    r = X;
  }

  std::cout << r << std::endl;

  return 0;
}

Measured memory_bytes: 3604
#include "iostream"
using namespace std;

int main()
{
	int h, w;
	

	while(1){
		cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int j = 0; j < h; j++){

			for (int i = 0; i < w; i++){
				cout << '#';
			}
			cout << endl;

		}
		cout << endl;
	}
	return 0;
}




Measured memory_bytes: 3080
//
// Created by 27420 on 2020/8/15.
//
#include<stdio.h>
#include<iostream>
using namespace std;
int judge(int a,int b,int c){
    if((a+b)>c&&(a+c)>b&&(c+b)>a){
        return 0;
    }
    else
    return -1;
}
int main(){
    int n;
    int a[101]={0};
    scanf("%d ",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    if(n<=2){
        printf("0\n");
    }else{
        int flag=0;
        for(int i=1;i<=n;i++){ //&&(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
            for(int j=i+1;j<=n;j++ ){
                for(int k=j+1;k<=n;k++){
                    if(!judge(a[i],a[j],a[k])&&(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])){//理解错了以为ijk也要满足 卡了呜呜呜
                        flag++;
                           // printf("%d %d %d\n",i,j,k);
                        //printf("((%d %d %d\n",a[i],a[j],a[k]);
                    }
                }
            }
        }
            printf("%d\n",flag);
    }
}

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

int main(){
  unsigned long long N,A,B,C,D,ans;
  cin>>N>>A>>B;
 C=N/(A+B);
 D=N%(A+B);
  ans=C*A;
  if(D<=A){
    ans+=D;
  }else{
    ans+=A;
  }
  cout<<ans<<endl;
}
    

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define put(n) cout<<(n)<<endl
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

int main(){
    int N,ans = 0;
    cin>>N;
    map<string,int> S;
    
    FOR(i,0,N){
        string s = "";
        vector<string> c(3);
        cin>>c[0]>>c[1]>>c[2];
        sort(c.begin(),c.end());
        s += c[0];s += c[1];s += c[2];
        S[s]++;
    }

    for(auto itr = S.begin(); itr != S.end(); itr++){
        ans += itr->second -1;
    }
    put(ans);
}


Measured memory_bytes: 3288
#include <iostream>
#include <string>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int bitcnt(int n) {
	int ret = 0;
	while(n > 0) {
		ret += (n & 1);
		n >>= 1;
	}
	return ret;
}

int n;
string s;
int mods[3];
int p2[3][200001];

signed main() {
	int i, j;
	
	cin >> n >> s;
	
	int cnt = 0;
	rep(i, s.length()) {
		if (s[i] == '1') cnt++;
	}

	for (i = 0; i < 3; i++) {
		int bcnt = cnt - 1 + i;
		if (bcnt <= 0) continue;
		p2[i][0] = 1;
		rep(j, n) {
			p2[i][j + 1] = p2[i][j] * 2 % bcnt;
		}
		
		rep(j, n) {
			if (s[j] == '1') {
				mods[i] += p2[i][n - 1 - j];
				mods[i] %= bcnt;
			}
		}
	}
	
	rep(i, s.length()) {
		if (s[i] == '0') {
			int num = (mods[2] + p2[2][n - 1 - i]) % (cnt + 1);
			int ans = 1;
			while (num > 0) {
				int bcnt = bitcnt(num);
				num %= bcnt;
				ans++;
			}
			cout << ans << endl;
		}
		else {
			if (cnt - 1 <= 0) {
				cout << 0 << endl;
			}
			else {
				int num = (mods[0] - p2[0][n - 1 - i] + cnt - 1) % (cnt - 1);
				int ans = 1;
				while (num > 0) {
					int bcnt = bitcnt(num);
					num %= bcnt;
					ans++;
				}
				cout << ans << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define mer(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353
#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

//vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;
vector<char> v;



int main() {
	ll N;
	cin >> N;
	//--N;
	for (char i = 'a'; i <= 'z'; ++i) {
		v.push_back(i);
	}
	int rec;
	rep(i,0, 12) {
		if (N - powl(26, i) >= 0) {
			N -= powl(26, i);
		}
		else {
			rec = i;
			break; 
		}
	}

	//cout << rec << '\n';
	mer(i, rec, -1) {
		ll sho = N / powl(26, i);
		if (i == 0) {
			//cout << i << " " << sho << '\n';
			cout << v[sho];
		}
		else {
			if (sho >= 1) {
				//cout << i << " " << sho << '\n';
				cout << v[sho];
				N -= powl(26, i) * sho;
			}
			else if (i != rec) {
				cout << "a";
			}
		}
	}
	
	cout << '\n';
	
	return 0;
}

Measured memory_bytes: 3708
a = list(input())
b = list(input())
c = list(input())
now_person = a
a_i = 0
b_i = -1
c_i = -1
now_person_i = 0
while True:
    if now_person_i == len(now_person):
      break
    if now_person[now_person_i] == 'a':
        now_person = a
        a_i += 1
        now_person_i = a_i
    elif now_person[now_person_i] == 'b':
        now_person = b
        b_i += 1
        now_person_i = b_i
    elif now_person[now_person_i] == 'c':
        now_person = c
        c_i += 1
        now_person_i = c_i
if now_person == a:
    print("A")
elif now_person == b:
    print("B")
else:
    print("C")

Measured memory_bytes: 38384
N = gets.to_i
H = gets.split.map(&:to_i)
H.push(100000000000000)

$max_score = 0
$next_index = 0

def score(index)
  con_score = 0
  H.each.with_index(index) do |h, i|
    if H[i] >= H[i + 1] then
      con_score += 1
    else
      break
    end
  end
  $next_index = con_score + index + 1
  return con_score
end
  
while $next_index != N do
max_cand = score($next_index)
if $max_score < max_cand then
  $max_score = max_cand
end
end
  
p $max_score

Measured memory_bytes: 12548
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    if(abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    long int a, b, c, d;
    cin >> a >> b >> c >> d;
    long int x, y, z, w;
    x = a * c;
    y = b * d;
    z = a * d;
    w = b * c;
    long int ans;
    ans = max(max(z, w),max(x, y));
    
    cout << ans << endl;

}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

#define MAX_V 2000

struct edge{int to, cap, rev; bool ori;};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
bool reach[2][MAX_V];

void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, G[to].size(), true});
    G[to].push_back((edge){from, 0, G[from].size()-1, false});
}

void bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int i = 0; i < G[v].size(); i++){
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f){
    if(v == t) return f;
    for(int &i = iter[v]; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to, t, min(f,e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0) return flow;
        memset(iter,0, sizeof(iter));
        int f;
        while((f = dfs(s, t, inf)) > 0){
            flow += f;
        }
    }
}

void reachbfs(int s, int ind){
    queue<int> que;
    que.push(s);
    reach[ind][s] = true;
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int i = 0; i < G[v].size(); i++){
            edge &e = G[v][i];
            if(e.cap != ind && !reach[ind][e.to]) {
                reach[ind][e.to] = true;
                que.push(e.to);
            }
        }
    }
}

int n, m, s, t;

void solve() {
    rep(i,MAX_V) G[i].clear();
    s--; t--;
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        add_edge(a, b, 1);
    }
    int f = max_flow(s,t);
    memset(reach, 0, sizeof(reach));
    reachbfs(s, 0);
    reachbfs(t, 1);

    int cnt = 0;
    rep(i,n) {
        rep(j,G[i].size()) {
            if (G[i][j].ori) continue;
            if (reach[0][i] && reach[1][G[i][j].to]) cnt++;
        }
    }
    if (cnt == 0) cout << f << " " << 0 << endl;
    else cout << f+1 << " " << cnt << endl;
}

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
    cout.precision(20);
    cerr << fixed;
    cerr.precision(6);
#ifdef LOCAL
    //freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif  
    while (cin >> n >> m >> s >> t) {
        if (n == 0 && m == 0 && s == 0 && t == 0) break;
        solve();
    }
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int x = 0;
    for (const auto c : s)
    {
        if (c == 'I')
            ++x;
        else
            --x;
        ans = max(x, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ 0099: Surf Smelt Fishing Contest II
// 2017.10.28 bal4u@uu

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

#define QSIZE 110000
#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef struct { int id, key, c; } QUE;
QUE que[QSIZE+3]; int qsize;

void max_heapify(int i)
{
	int l, r, max;
	l = LEFT(i), r = RIGHT(i);
	if (l < qsize &&
		(que[l].key > que[i].key || (que[l].key == que[i].key && que[l].id < que[i].id)))
		max = l;
	else max = i;
	if (r < qsize && (que[r].key > que[max].key ||
			(que[r].key == que[max].key && que[r].id < que[max].id)))
		max = r;
	if (max != i) {
		QUE t = que[i]; que[i] = que[max], que[max] = t;
		max_heapify(max);
	}
}

void deq(void)
{
//	if (qsize == 0) return;
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(void)
{
	int i, max;
	i = qsize++;
	while (i > 0 && (que[max = PARENT(i)].key < que[i].key
		|| (que[max].key == que[i].key && que[max].id > que[i].id))) {
		QUE t = que[i]; que[i] = que[max], que[max] = t;
		i = max;
	}
}

char buf[65], *p;
int getInt()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

#define MAX 1000000
typedef struct { int f, c; } T;
T tbl[MAX + 5];

int main()
{
	int n, q, a, v;

	fgets(p=buf, 64, stdin), n = getInt(), p++, q = getInt();
	qsize = 0;
	while (q--) {
		fgets(p=buf, 64, stdin), a = getInt();
		p++; if (*p == '-') p++, v = -getInt(); else v = getInt();
		tbl[a].f += v, tbl[a].c++;
		que[qsize].id = a, que[qsize].key = tbl[a].f, que[qsize].c = tbl[a].c;
		enq();

		while (1) {
			a = que[0].id;
			if (tbl[a].c == que[0].c) {
				printf("%d %d\n", que[0].id, que[0].key);
				break;
			}
			deq();
		}
	}
	return 0;
}

Measured memory_bytes: 10756
def function(a,b,c,d,e):
	A=[a,b,c,d,e]
	A.sort()
	if A[0]==A[3] or A[1]==A[4]:
		print("four card")
	elif (A[0]==A[1] and A[2]==A[4]) or (A[0]==A[2] and A[3]==A[4]):
		print("full house")
	elif A[0]==A[2] or A[1]==A[3] or A[2]==A[4]:
		print("three card")

	elif (A[0]==A[1] and A[2]==A[3]) or (A[0]==A[1] and A[3]==A[4]) or (A[1]==A[2] and A[3]==A[4]):
		print("two pair")
	elif A[0]==A[1] or A[1]==A[2] or A[2]==A[3] or A[3]==A[4]:
		print("one pair")
	elif A==[1,10,11,12,13]:
		print("straight")
	elif A[0]==A[1]-1==A[2]-2==A[3]-3==A[4]-4:
		print("straight")
	else:
		print("null")

while True:
	try:
		a,b,c,d,e=map(int,input().split(','))
		function(a,b,c,d,e)
	except EOFError:
		break

Measured memory_bytes: 7752
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

int main(void){
  int N; ll K; cin>>N>>K;
  val<ll> A(N),F(N); cin>>A>>F;
  
  sort(begin(A),end(A));
  sort(begin(F),end(F));
  reverse(begin(F),end(F));
  
  auto f=[&](ll x){
    ll k=K;
    rep(i,N){
      ll Q=x/F[i];
      k-=max(A[i]-Q,0ll);
    }
    return k>=0;
  };
  
  ll l=-1,r=1e12,x;
  while(r-l>1){
    x=(l+r)/2;
    if(f(x)) r=x;
    else l=x;
    //cout<<x<<endl;
  }
  cout<<r<<endl;
}












Measured memory_bytes: 3328
#include <iostream>
using namespace std;
#define LL long long

int main()
{
    int x = 0, mx = 0;
    string s;
    int n;
    cin >> n >> s;
    for(int i=0;i<n;i++){
        if(s[i] == 'I') x++;
        else x--;
        mx = max(x, mx);
    }
    cout << mx  << '\n';
    return 0;
}


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

int main(){
	// sengen
	LL n,m,k;
	// nyuryoku
	cin >> n >> m >> k;
	LL a[n+1],b[m+1];
	LL sa[n+1],sb[m+1];
	sa[0] = 0; sb[0] = 0;
	for(int i=0;i<n;i++){
		cin >> a[i+1];
		sa[i+1] = a[i+1] + sa[i];
	}
	for(int i=0;i<m;i++){
		cin >> b[i+1];
		sb[i+1] = b[i+1] + sb[i];
	}
	int ans = 0,kari = 0,end = m;
	for(int i=0;i<=n;i++){
		for(int j=end;j>=0;j--){
			if(sa[i] + sb[j] > k){
				continue;
			}else{
				end = j;
				kari = i + j;
				ans = max(ans,kari);
				break;
			}
		}
	}
	// keisan
	cout << ans;
	// syutsuryoku
}


Measured memory_bytes: 9844
// D - Lunlun Number
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int k = 0, K; cin>>K;
	queue<ll> q;
	for(int i=1; i<=9; ++i) q.push(i);
	while(q.size()){
		ll n = q.front(); q.pop();
		k++;
		if(k >= K){ cout<< n <<endl; return 0; }
		ll n10 = n*10, d = n%10;
		if(d > 0) q.push(n10 + d-1);
		q.push(n10 + d);
		if(d < 9) q.push(n10 + d+1);
	}
}

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

int main()
{
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	long long int ans = 0;
	for(auto i = 0; i <= n; ++i){
		if(i * r > n) break;
		for(auto j = 0; j <= n - r * i; ++j){
			if(i * r + j * g > n) break;
			if((n - r * i - j * g) % b == 0) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	int n, t, m=0;
	int st[10], ar[10];
	string ans[10];
	int anst[10];
	
	scanf(" %d %d", &n, &t);
	for(int i=0; i<n; ++i){
		int a, b, c, d;
		string p, q;
		
		scanf(" %d:%d", &a, &b);
		cin >> p;
		scanf(" %d:%d", &c, &d);
		cin >> q;
		st[i]=a*60+b;
		ar[i]=c*60+d;
		
		//printf("st[%d]=%d, ar[%d]=%d\n", i, st[i], i, ar[i]);
	
		if(i==0) continue;
		else{
			int tt=st[i]-ar[i-1];
			if(tt>=t){
				ans[m]=p;
				anst[m]=tt;
				m++;		
			}
		}
		
	}
	
	printf("%d\n", m);
	for(int i=0; i<m; ++i) cout << ans[i] << " " << anst[i] << endl;
}

Measured memory_bytes: 1276
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

const int SIZE = 111;
const int INF = 0x3f3f3f3f;

int n;
int m;
int dp[SIZE][SIZE];
int g[SIZE][SIZE];

int main() {    
    int a, b, c;
    memset(g, INF, sizeof(g));
    memset(dp, INF, sizeof(dp));
    input(n >> m);
    
    for (int i = 1; i <= n; i++) {
        g[i][i] = dp[i][i] = 0;
    }
    
    for (int i = 0; i < m; i++) {
        input(a >> b >> c);
        g[a][b] = g[b][a] = c;
        dp[a][b] = dp[b][a] = c;
    }
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (g[i][j] >= INF) {
                continue;
            }
            if (dp[i][j] < g[i][j]) {
                ans++;
                // print(i << ' ' << j);
            }
        }
    }
    print(ans / 2);
    return 0;
}
        
        
    


Measured memory_bytes: 888
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N+1), B(N);
    for(int i=0; i<N+1; i++){
        cin >> A[i];
    }
    for(int i=0; i<N; i++){
        cin >> B[i];
    }
    ll ans=0, r, nex;
    for(int i=0; i<N; i++){
        if(A[i]>=B[i]) ans+=B[i];
        else{
            r=B[i]-A[i];
            ans+=A[i];
            nex=min(r, A[i+1]);
            ans+=nex;
            A[i+1]-=nex;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}

#pragma endregion

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

  string s;
  cin >> s;
  stack<char> st;
  int cnt = 0;
  for (auto c : s)
  {
    if (st.empty() || st.top() == c)
    {
      st.push(c);
    }
    else
    {
      st.pop();
      cnt += 2;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	// Code for B - Five Dishes

	A := make([]int, 5)
	var min int = 130
	var number int
	for i := 0; i < 5; i++ {
		fmt.Scanf("%d", &A[i])
		if 0 < A[i]%10 && A[i]%10 < min {
			min = A[i] % 10
			number = i
		}
	}

	var sum int
	for i := 0; i < 5; i++ {
		if i != number && A[i]%10 != 0 {
			sum += 10 * (A[i]/10 + 1)
		} else if i != number && A[i]%10 == 0 {
			sum += 10 * (A[i] / 10)
		}
	}
	fmt.Println(sum + A[number])
}


Measured memory_bytes: 1832
from collections import defaultdict

N ,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())

dic = defaultdict(list)
for i in range(N):
    dic[i%K].append(T[i])
ans = 0
D = []
for t_s in dic.values():
    before = 'z'
    for t in t_s:
        if t == 's':
            if not before == 's':
                ans += R
                before = t
            else:
                before = 'z'
                
        elif t == 'r':
            if not before == 'r':
                ans += P
                before = t
            else:
                before = 'z'
        else:
            if not before == 'p':
                ans += S
                before = t
            else:
                before = 'z'

print(ans)


Measured memory_bytes: 25676
#include <iostream>
#include <math.h>
#include <climits>
using namespace std;
#define int long long

int32_t main()
{
    int n;
    cin >> n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    int dp[n];
    int ans = INT_MAX;
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i] = min(abs(arr[i]-arr[i-2])+dp[i-2] , abs(arr[i]-arr[i-1])+dp[i-1]);
        //cout << dp[i] << " ";
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 4616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int x = in.nextInt();

            out.println(a <= x && x <= a + b ? "YES" : "NO");
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21460