akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A,B;

int main() {
  INCANT;
  cin >> A >> B;

  string ans = (A+B)%3==0 || A%3==0 || B%3==0 ?"Possible":"Impossible";
  cout << ans << "\n";
  return 0;
}

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

// ABC132A
// https://atcoder.jp/contests/abc131/tasks/abc131_a
void ABC132A() {
	string S;
	cin >> S;

	for (int i = 0; i < S.size() - 1; i++)
	{
		if (S[i] == S[i + 1]) {
			cout << "Bad" << endl;
			return;
		}
	}

	cout << "Good" << endl;
}

int main() {
	ABC132A();

	return 0;
}




Measured memory_bytes: 256
def comb2(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    res=1
    for i in range(r):
        res=res*(n-i)%MOD*pow(i+1, MOD-2, MOD)%MOD
    return res

MOD=10**9+7

N, A, B=map(int, input().split())
ans=pow(2, N, MOD)-comb2(N, A)-comb2(N, B)-1
print(ans%MOD)

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

int main()
{
    long long i,j,k,n,m,p,q,r,t,x,y,z,zz;
    string s;
    cin>>s;
    if(s=="SAT")
    {
        cout<<1<<endl;
    }
    else if(s=="SUN")
    {
        cout<<7<<endl;
    }
    else if(s=="MON")
    {
        cout<<6<<endl;
    }
    else if(s=="TUE")
    {
        cout<<5<<endl;
    }
    else if(s=="WED")
    {
        cout<<4<<endl;
    }
    else if(s=="THU")
    {
        cout<<3<<endl;
    }
    else if(s=="FRI")
    {
        cout<<2<<endl;
    }


}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

signed main()
{
	int A[3];
	cin >> A[0] >> A[1] >> A[2];

	int ans = 0;
	while (true)
	{
		if (A[0] == A[1] && A[1] == A[2]) break;

		for (int i = 0; i < 2; i++)
		{
			int min = INT_MAX;
			int min_j = 0;

			for (int j = 0; j < 3; j++)
			{
				if (min > A[j])
				{
					min = A[j];
					min_j = j;
				}
			}
			A[min_j]++;
		}

		ans++;
	}
	cout << ans << endl;


	//int A[3];
	//int ans = 0;
	//cin >> A[0] >> A[1] >> A[2];
	//int max = MAX(A[0], MAX(A[1], A[2]));
	//for (int i = 0; i < 3; i++)
	//{
	//	int cnt = (max - A[i]) / 2;
	//	A[i] += cnt * 2;
	//	ans += cnt;
	//}

	//while (true)
	//{
	//	if (A[0] == A[1] && A[1] == A[2]) break;

	//	int min = INT_MAX;
	//	int min_i = 0;
	//	for (int i = 0; i < 3; i++)
	//	{

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







Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	string s[3];
	for(int i = 0;i < 3;i++)cin >> s[i];
	cout << s[0][0] << s[1][1] << s[2][2] << endl;
}


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

int main()
{
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for(int i = 0; i <= d; i++){
        int e = i / 10;
        int f = i % 10;
        if(e >= 2 && f >= 2 && e * f <= m) ans++;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll n;
  ll h_max = 0;
  ll res = 0;

  cin >> n;
  for(ll i=0; i<n; i++) {
    ll temp;
    cin >> temp;
    if(h_max <= temp) {
      res++;
      h_max = temp;
    }
  }

  cout << res << endl;

  return 0;
}


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

int main()
{
    int n(0);
    std::cin >> n;
    
    std::vector<int> mons(n+1, 0);
    for(auto& v : mons){
        std::cin >> v;
    }
    
    int n_hit(0);
    int n_mons_0(0);
    int n_mons_1 = mons[0];
    int diff(0);
    long long c(0);
    for(int i=0; i < n; ++i){
        std::cin >> n_hit;
        
        n_mons_0 = n_mons_1;
        n_mons_1 = mons[i+1];
        
        diff = std::min(n_hit, n_mons_0);
        c += diff;
        n_hit -= diff;
        
        diff = std::min(n_hit, n_mons_1);
        c += diff;
        n_mons_1 -= diff;
    }
    
    std::cout << c << std::endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int count = 0;
    while (true)
    {
        bool flag = true;
        for(auto e : a)
        {
            if(e % 2 != 0)
            {
                flag = false;
            }
        }
        if(flag)
        {
            count++;
            for(auto &e : a)
            {
                e /= 2;
            }
        }else{
            break;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const int inf = 1<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

ll N, X[1009], Y[1009], H[1009]; vector<tuple<ll,ll,ll>> vec;

int main () {
  cin >> N;
  tuple<ll,ll,ll> G = make_tuple(-1,-1,-1);

  for (int i = 1; i <= N; i++) {
    cin >> X[i] >> Y[i] >> H[i];
    if (H[i] >= 1) G = make_tuple(X[i],Y[i],H[i]);
  }
  for(int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      ll V = get<2>(G) + abs(get<0>(G)-i) + abs(get<1>(G)-j);
      V = max(V,0LL);
      bool flag = true;
      for (int k = 1; k <= N; k++) {
        ll VV = V - abs(X[k]-i) - abs(Y[k]-j);
        VV = max(VV,0LL);
        if (H[k] != VV) flag = false;
      }
      if(flag == true) vec.push_back(make_tuple(i,j,V));
    }
  }

  if (vec.size() == 1) {
    cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
  }
}

Measured memory_bytes: 256
#define rep(i,n) for (int i = 0; i < (n); ++i)

#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
using namespace std;
//typedef Long long int ll;



int main(void) {
	string S;
	cin >> S;

	string prevstr;
	long long K = 0;
	string nowstr;
	for (int i = 0; i != S.length(); i++) {
		nowstr += S[i];
		if (prevstr != nowstr) {
			prevstr = nowstr;
			nowstr.clear();
			K++;
		}
		else {

		}
	}


	cout << K << endl;

	return 0;
}



Measured memory_bytes: 640
h, w = map(int, input().split())
a = [str(input()) for i in range(h)]

row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True
            
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j], end='')
                
        print()

Measured memory_bytes: 4468
//DFS from 1, find length of path to N
//first half of the nodes on the path belong to fennec
//then another dfs to count the reserve of each
#include <iostream>
#include <vector>

using namespace std;

typedef vector<long long> vi;

vector<vector<long long> > g;
vi d;
long long N;

void dfs(long long n, long long p, long long dp){
	d[n] = dp;
	for(long long x=0; x<g[n].size(); x++){
		if(g[n][x]!=p)
			dfs(g[n][x], n, dp+1);
	}
}

long long dfs_erase(long long n, long long p, long long dp, long long nn){
	if(n==N){
		if(nn+1==dp){
			for(long long x=0; x<g[n].size(); x++)
				if(g[n][x]==p)
					g[n][x] = -1;
		}
		return -d[n];
	}
	for(long long x=0; x<g[n].size(); x++){
		if(g[n][x]!=p){
			if(dfs_erase(g[n][x], n, dp+1, nn)<0){
				if(nn==dp){
					//this is the edge to break
					g[n][x] = p;
				} else if(dp==nn+1){
					//the first edge of snuke
					for(long long y=0; y<g[n].size(); y++)
						if(g[n][x]==p)
							g[n][x] = -1;
				}
				return -d[n];
			}
		}
	}
}

long long ssz(long long n, long long p){
	if(n==-1)
		return 0;
	long long s = 1;
	for(long long x=0; x<g[n].size(); x++){
		if(g[n][x]!=p)
			s += ssz(g[n][x], n);
	}
	return s;
}

int main(){
	cin>>N;
	long long A, B;
	g.assign(N+1, vector<long long>());
	d.assign(N+1, 1e9);
	for(long long n=1; n<N; n++){
		cin>>A>>B;
		g[A].push_back(B);
		g[B].push_back(A);
	}
	dfs(1, -1, 1);
	long long nn = d[N]-2;
	//number of nodes between them
	if(nn%2)
		nn = nn/2+1;
	else
		nn = nn/2;
	nn+=1; //the depth which is the last element to belong to fennec
	dfs_erase(1, -1, 1, nn);
	long long ssz1 = ssz(1, -1);
//	cout << ssz1 << " " << ssz2 << nn << endl;
	if(ssz1*2>N){
		cout << "Fennec" << endl;
	} else {
		cout << "Snuke" << endl;
	}
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n,f = 0;
  cin >> n;
  REP(i,1000) {
    REP(j,1000) {
      if (i*4 + j*7 == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
double x1,y1,x2,y2,x,y,sum,c;
  
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  
  x= x1-x2;
  y= y1-y2;
  
  sum = x*x +y*y;
  
  c= sqrt(sum);
  
  printf("%f\n",c);
  
}


Measured memory_bytes: 2112
def segfunc(x, y): return max(x, y)

class SegmentTree:
    def __init__(self, arr):
        size = len(arr)
        n = 2 ** (size - 1).bit_length()
        self.n = n
        self.node = [0] * (2*n)
        for i in range(size):
            self.node[i+n-1] = arr[i]
        for i in reversed(range(n-2)):
            self.node[i] = segfunc(self.node[2*i+1], self.node[2*i+2])

    def update(self, i, x):
        i += self.n - 1
        self.node[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2])

    def update(self, x, val):
        x += (self.n - 1)
        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2])

    def query(self, a, b):
        res = 0
        l = self.n - 1 + a
        r = self.n - 1 + (b - 1)

        while l <= r:
            if l == r:
                res = segfunc(res, self.node[l])
                break

            if l % 2 == 0:
                res = segfunc(res, self.node[l])
            if r % 2 == 1:
                res = segfunc(res, self.node[r])
            l = l // 2
            r = r // 2 - 1

        return res

N, K = map(int, input().split())
INF = 0
seg = SegmentTree([0] * 300000)
for i in range(N):
    a = int(input())
    tmp = seg.query(max(a - K, 0), min(a + K, 300000) + 1) + 1
    seg.update(a, tmp)
print(seg.query(0, 300000))


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

#define mkp make_pair
typedef pair<int,int> P;
typedef string::const_iterator State;

string S;

P formula(State &begin);
P OrExpr(State &begin);
P AndExpr(State &begin);
P term(State &begin);

P formula(State &begin){
  return OrExpr(begin);
}

P OrExpr(State &begin){
  int resa,resb;
  tie(resa,resb)=AndExpr(begin);

  for(;;){
    if(*begin=='|'){
      begin++;
      int a,b;
      tie(a,b)=AndExpr(begin);
      resb=min(resb,resa+b);
      resa+=a;
    }else{
      break;
    }
  }
  return mkp(resa,resb);
}

P AndExpr(State &begin){
  int resa,resb;
  tie(resa,resb)=term(begin);

  for(;;){
    if(*begin=='&'){
      begin++;
      int a,b;
      tie(a,b)=AndExpr(begin);
      resa=min(resa,resb+a);
      resb+=b;
    }else{
      break;
    }
  }
  return mkp(resa,resb);
}

P term(State &begin){
  int a=0,b=0;
  if(*begin=='('){
    begin++;
    tie(a,b)=OrExpr(begin);
    begin++;
  }else{
    tie(a,b)=mkp(1,1);
    begin++;
  }
  return mkp(a,b);
}

int main(){
  cin>>S;
  State begin=S.begin();

  int a,b;
  tie(a,b)=formula(begin);
  cout<<a<<" "<<b<<endl;

  return 0;
}



Measured memory_bytes: 3332
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;


int main(void){
  int N;
  int max = 0;
  map<string,int> m;
  string s;
  vector<string> v;
  cin >> N;
  for(int i = 0; i < N;i++){
    cin >> s;
    auto f = m.find(s);
    if(f != m.end()){
      m[s]++;
    }
    else{
      m.insert(make_pair(s,0));
    }
  }

  for(auto it = m.begin(); it != m.end(); it++){
    if(max < (*it).second) max = (*it).second;
  }
  for(auto it = m.begin(); it != m.end(); it++){
    if(max == (*it).second) v.push_back((*it).first);
  }
  for(string s : v){
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 26868
N,M=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=sum(a)
f = True
for i in range(M):
    if a[i]<s/(4*M):
        f = False
        break

if f:
    print("Yes")
else:
    print("No")

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

ll floor(ll n){
    return (n+1)/2;
}

int main(){
    ll H, W;    cin >> H >> W;
    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    cout << floor(H)*floor(W) + (W/2)*(H/2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
ll gcd (ll x, ll y) {
    if (x < y) swap(x, y);
    if (y == 0) return x;
    return gcd(x % y, y);
}
ll lcm (ll x, ll y) {
    return x/gcd(x, y)*y;
}

int main(){
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    
    ll l=lcm(n,m);
    
    ll ds=l/n;
    ll dt=l/m;
    
    ll x=lcm(ds,dt);
    ll si=x/ds;
    ll ti=x/dt;
    
    rep(i,0,n/si){
        if(s[i*si]!=t[i*ti]) l=-1;
    }
    
    cout<<l<<endl;
}


Measured memory_bytes: 512
r,c=map(int,input().split())
x=[[0]*(c+1) for i in range(r+1)]
for i in range(r):
    y=list(map(int,input().split()))
    for j in range(c):
        x[i][j]=y[j]
for i in range(r):
    for j in range(c):
        x[i][c]+=x[i][j]
for j in range(c+1):
    for i in range(r):
        x[r][j]+=x[i][j]
for i in range(r+1):
    print(x[i][0],end=" ")
    for j in range(1,c):
        print(x[i][j],end=" ")
    for j in range(c,c+1):
        print(x[i][j],end="")
    print()



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

int main(){
  int N;
  cin>>N;
  std::vector<int> a(N),v(N);
  for(int i=0;i<N;i++)cin>>a[i];
  int k=0;
  for(int i=0;i<N;i++)k+=a[i];
  for(int i=0;i<N;i++)a[i]*=N;
  sort(v.begin(),v.end());
  int r;
  int m=1e9+7;
  int ans=0;
  for(int i=0;i<N;i++){
    if(abs(a[i]-k)<m){ans=i;m=abs(a[i]-k);}
  }
  cout<<ans<<endl;
}


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

int main() {
	int g, h, i, k, m, n, p, q, u, v; 
    ios::sync_with_stdio(false), cin.tie(nullptr);
    for (cin >> n >> q, p = 1; p*p <= n; ++p);
    vector<int> c(n), count(n,0), l(q), r(q), ans(q);
    for (auto &color: c)
    	cin >> color;
    priority_queue<tuple<int,int,int>> s;
    for (m = p-1, i = 0; i < q; ++i)
    	cin >> l[i] >> r[i], s.emplace(--l[i]/m,--r[i]/m,i);
    const auto dec = [](int x, int &k) { if (x == 0) --k; };
    const auto inc = [](int x, int &k) { if (x == 0) ++k; };
    for (++count[c[0]], g = h = 0, k = 1; not s.empty(); ans[i] = k, s.pop()) {
    	for (i = get<2>(s.top()), u = l[i], v = r[i]; h > v; --h)
    		dec(--count[c[h]],k);
    	for (; h < v; ++count[c[h]])
        	inc(count[c[++h]],k);
    	for (; g < u; ++g)
        	dec(--count[c[g]],k);
    	for (; g > u; ++count[c[g]])
        	inc(count[c[--g]],k); }
    for (auto a: ans)
        cout << a << '\n'; }


Measured memory_bytes: 19584
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int A,B,C;
    cin  >> A >> B >> C;
    C -=  min(A-B, C);
    cout << C << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long double a[3000],dp[3000][3000];
long long n;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    long long m=n/2;
    if(n%2==0) m--;
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*a[i];
       // cout<<dp[i][0]<<" ";
        dp[0][i]=1;
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=i;j++)
        {
            dp[j][i]=dp[j-1][i]*(1-a[j]);
         //   cout<<dp[j][i]<<" ";
        }
        //cout<<endl;
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            dp[j][i]=a[j]*dp[j-1][i]+(1-a[j])*dp[j-1][i-1];
        }
    }
    long double ans=0;
    for(int i=0;i<=m;i++)
    {
        ans+=dp[n][i];
    }
    cout<<setprecision(10)<<fixed<<ans<<endl;
    return 0;
}


Measured memory_bytes: 86028
n  = int(input())
a = list(map(int, input().split()))

wallet = 1000
stock = 0

for i in range(len(a)-1):
  if a[i+1] > a[i]:
    new_stock = wallet // a[i]
    stock += new_stock
    wallet -= new_stock * a[i]
  elif a[i+1] < a[i]:
    wallet += stock * a[i]
    stock = 0

wallet += stock * a[n-1]

print(wallet)


Measured memory_bytes: 9188
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();

        for (long a = -118; a <= 119; a++) {
            for (long b = -119; b <= 118; b++) {
                if (((long)Math.pow(a, 5)) - ((long)Math.pow(b, 5)) == x) {
                    System.out.println(a + " " + b);
                    System.exit(0);
                }
            }
        }
    }
}

Measured memory_bytes: 38996
import java.util.Scanner;

import static java.lang.Math.*;

public class Main {
    static final int INF = 2147483647;
    static int[] D;
    static int a_n;
    static int t_n;


    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        a_n = Integer.parseInt(scanner.next());
        int q = Integer.parseInt(scanner.next());

        initRMQ(a_n);



        for(int i = 0; i < q; i++){
            int com = Integer.parseInt(scanner.next());
            int x = Integer.parseInt(scanner.next());
            int y = Integer.parseInt(scanner.next());



            if(com == 0){
                update(x, y);
            }
            if(com == 1){
                int result = findMin(x, y);
                System.out.println(result);
            }


        }


    }

    public static void initRMQ(int a_n){
        t_n = 1;

        while (t_n < a_n){
            t_n *= 2;
        }

        D = new int[2 * t_n - 1];

        for(int i = 0; i < 2 * t_n - 1; i++){
           D[i] = INF;
        }

    }

    public static void update(int k, int a){
        k += t_n - 1;
        D[k] = a;
        while (k > 0){
            k = (k - 1) / 2;
            D[k] = min(D[k * 2 + 1], D[k * 2 + 2]);
        }
    }

    public static int query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return D[k];


        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2 );
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);

    }

    public static int findMin(int a, int b){
        return query(a, b + 1, 0, 0, t_n);
    }
}


Measured memory_bytes: 73720
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r: return self.combination(n, n - r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod


def main():
    mod = 10 ** 9 + 7

    n, k = map(int, input().split())

    cl = Calc(max_value=n, mod=mod)

    m = min(k, n - 1)

    ret = 0
    for i in range(m + 1):
        t = cl.combination(n, i)
        t = t * cl.combination(n - 1, i) % mod
        ret = (ret + t) % mod

    print(ret)


if __name__ == '__main__':
    main()

# 解説放送

# 和がn
# 0はk個以下

# 0の個数を固定して、
# [0,k]個の0について総和を取る

# 0がi箇所
# 1以上がn-i箇所 -> 扱いにくいので、全体から1を引いて0以上にする
# 和がn

# 0以上がn-i箇所
# 和がn-(n-i)=i

# n-i箇所にi個のボールを入れる問題になる
# H(n-i,i)

# n-i-1本の仕切り線とi個のボールの並べ方になる
# choose((n-i-1)+i,i)


Measured memory_bytes: 18804
//ehhhhh...... i hate you......

/* optimizations and other useless stuff*/
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e14
#define ull unsigned long long int
using namespace std;
/* TYPE DEFINITIONS */
typedef     long long int   ll;
typedef     vector<ll>      vi;
typedef     pair<ll,ll>     pi;


/* Basic  Math!!! */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll ncr(int n, int k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
} 

/* MACROS */
#define  all(A)         (A).begin() , (A).end()
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)  
int lenOfLongIncSubArr(int arr[], int n) 
{ 
    int max = 1, len = 1; 
      
    for (int i=1; i<n; i++) 
    { 
        if (arr[i] <=arr[i-1]) 
            len++; 
        else
        { 
            if (max < len)     
                max = len; 
                     
            len = 1;     
        }     
    } 
      
    if (max < len) 
        max = len; 
      
    return max; 
} 
void solve()
{
    int n;
    cin>>n;
    int arr[n];
    forn(i,n)cin>>arr[i];
    cout<<lenOfLongIncSubArr(arr,n)-1<<endl;
}

int main()
{
    FastIO;
    ll c=0;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case "<<++c<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 640
//psudora
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)

int main() 
{ 
	fast;
	string s;
	cin>>s;
	{
		if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes"<<endl;
		else 
		cout<<"No"<<endl;
	}
  
    return 0; 
} 


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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
double distance(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
    string s;
    cin >> s;
    int b = 0;
    int r = 0;
    for (size_t i = 0; i < s.length(); i++)
    {
        if (s[i] == '1')
        {
            b++;
        }
        else
        {
            r++;
        }
        /* code */
    }
    cout << s.length() - abs(b - r) << endl;

    //    cout << 2 * sum / n << endl;
    return 0;
}

Measured memory_bytes: 512
//package cf;
import java.io.*;
import java.util.*;
public class Main {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Integer> adj[]=new ArrayList[n+1];
        for(int i=0;i<=n;i++)
        {
            List<Integer> l1=new ArrayList<>();
            adj[i]=l1;
        }
        for(int i=0;i<m;i++)
        {
            int u=sc.nextInt();
            int v=sc.nextInt();
            adj[u].add(v);
        }

        int dp[]=new int[n+1];
        Arrays.fill(dp,-1);
        int ans=0;
        boolean vis[]=new boolean[n+1];
        for(int i=1;i<=n;i++) {
            if(vis[i]==false)
               ans= Math.max(dfs(adj, i, dp, vis),ans);
        }
        System.out.println(ans);
        // StringBuilder sb=new StringBuilder();
        //   out.write(sb.toString());
        out.flush();
    }

    private static int dfs(List<Integer>[] adj, int i, int[] dp, boolean[] vis) {
        vis[i]=true;
      //  System.out.println(i+" ");

        if(adj[i].size()==0)
        {
            dp[i]=0;
            return 0;
        }
        if(dp[i]!=-1)
            return dp[i];
        int this_path=0;
        for(int v:adj[i])
        {
                this_path=Math.max(1+dfs(adj,v,dp,vis),this_path);
        }
        dp[i]=this_path;
        //System.out.println(Arrays.toString(dp));
        return dp[i];
    }


    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }


}


Measured memory_bytes: 72236
#include<stdio.h>
int main(){
  int a=0,s=0,n,m;
  scanf("%d",&n);
  while(n--){
    scanf("%d",&m);
    if(a<m)a=m;
    s+=m;
  }
  printf("%d\n",s-a/2);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };




int main() {
	int n;
	cin >> n;
	vector<int>H(n);
	rep(i, 0, n)cin >> H[i];

	int ans = 0;
	rep(i, 0, n) {
		int ok = 1;
		rep(j, 0, i) {
			if (H[j] > H[i])ok = 0;
		}
		if (ok) ans++;
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
  ll x[2];
  ll y[2];
  ll ans;
  cin >> x[0] >> x[1] >> y[0] >> y[1];
  ans=x[0]*y[0];
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      ans=max(ans,x[i]*y[j]);
    }
  }
  cout << ans;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
	int h, w;
	char a[111][111];
	int r[111] = {0}, c[111] = {0};
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			scanf("\n%c", &a[i][j]);
			if (a[i][j] == '#'){
				r[i]++;
				c[j]++;
			}
		}
	}
  for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (r[i] > 0 && c[j] > 0){
				printf("%c", a[i][j]);
			}
		}
		if (r[i] > 0){
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
n = int(input())
s = input()
cntW = 0
cntE = s[1:].count("E")
ans = cntE
for i in range(1, n):
  if s[i-1] == "W":
    cntW+=1
  if s[i]=="E":
    cntE-=1
  ans=min(ans, cntE+cntW)
print(ans)

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

using namespace std;

int main() {

	int d;
	cin >> d;

	switch (d) {
		case 25:
			cout << "Christmas" << endl;
			return 0;
		case 24:
			cout << "Christmas Eve" << endl;
			return 0;
		case 23:
			cout << "Christmas Eve Eve" << endl;
			return 0;
		case 22:
			cout << "Christmas Eve Eve Eve" << endl;
			return 0;

	}

}

Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    const ll inf = 1e12;
    vector< vector<ll> > dp(n + 2, vector<ll>(h + h, -1));
    function<ll(int, int)> dfs = [&](int idx, int vlu) {
        if( vlu <= 0 ) return 0LL;
        if( idx == n ) return ((vlu <= 0) ? 0LL : inf);
        ll& ret = dp[idx][vlu];
        if( ~ret ) return ret;

        ret = inf;
        ret = min(ret, b[idx] + dfs(idx + 1, vlu - a[idx]));
        ret = min(ret, b[idx] + dfs(idx, vlu - a[idx]));
        ret = min(ret, dfs(idx + 1, vlu));
        return ret;
    };
    cout << dfs( 0, h ) << "\n";
}


Measured memory_bytes: 162784
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    int r = max(0, a - 2 * b);
    cout << r << "\n";

    return 0;
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
B = list(map(int,input().split()))
A = []
for _ in range(n):
    d = list(map(int,input().split()))
    A.append(d)
ans = 0
sum = 0
for i in range(0,n):
    sum = c
    for j in range(0,m):
        sum += A[i][j]*B[j]
    if sum > 0:
        ans += 1
    else:
        ans += 0

print(ans)


Measured memory_bytes: 3064
# include <iostream>
using namespace std;
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	while(a%b != 0)
	{
		int c = a%b;
		a = b;
		b = c;
	}
	printf("%d\n",b);
	return 0;
} 


Measured memory_bytes: 3204
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n%i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<ll, ll> mp;
    for(int i = 1; i <= n; ++i){
        for(auto p : prime_factor(i)){
            mp[p.first] += p.second;
        }
    }
    mint ans = 1;
    for(auto p : mp){
        ans *= p.second + 1;
    }
    cout << ans.x << endl;
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	int dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++){
		//for(int j=0;j<3;j++){
			dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
			dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
			dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
			
		
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	// your code goes here
	return 0;
}

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

int main() {
	int n;
	int count=0;
	cin>>n;
	bool flag=false;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		if(x==y){
			count++;
		}
		else{
			count=0;
		}
		if(count>=3){
			flag=true;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
		
	}
	
}

Measured memory_bytes: 3632
#include<algorithm>
#include<cmath>
#include<cstdio>
typedef double llf;
const int MN=1e5+4;
const llf INF=1e100,EPS=7e-12,GR=(1+sqrt(5))/2.0;
int N;
llf ans=INF;
struct pnt {
    llf x, y;
    llf ox,oy;
    char c;
}pnts[MN];
static inline void mov(pnt &p,llf dt) {
    switch(p.c) {
        case 'R':
            p.x=p.ox+dt;
            p.y=p.oy;
            break;
        case 'L':
            p.x=p.ox-dt;
            p.y=p.oy;
            break;
        case 'U':
            p.x=p.ox;
            p.y=p.oy+dt;
            break;
        case 'D':
            p.x=p.ox;
            p.y=p.oy-dt;
            break;
    }
}
static inline llf bb() {
    llf mxx=-INF,mxy=-INF,mnx=INF,mny=INF;
    for(int i=0;i<N;++i) {
        mxx=std::max(mxx,pnts[i].x);
        mnx=std::min(mnx,pnts[i].x);
        mxy=std::max(mxy,pnts[i].y);
        mny=std::min(mny,pnts[i].y);
    }
    return (mxx-mnx)*(mxy-mny);
}
int main() {
    scanf("%d",&N);
    for(int i=0;i<N;++i) {
        scanf("%lf %lf %c",&pnts[i].ox,&pnts[i].oy,&pnts[i].c);
    }
    // do GSS
    llf lo=0,hi=1e9,mi1,mi2;
    for(int i=0;i<500;++i) {
        mi1=hi-(hi-lo)/GR;
        mi2=lo+(hi-lo)/GR;
        llf b1,b2;
        for(int i=0;i<N;++i)
            mov(pnts[i],mi1);
        b1=bb();
        for(int i=0;i<N;++i)
            mov(pnts[i],mi2);
        b2=bb();
        if(b1<b2) hi=mi2;
        else lo=mi1;
        ans=std::min(std::min(b1,b2),ans);
    }
    printf("%.9lf\n",ans);
}


Measured memory_bytes: 4096
str = input()
q = int(input())

for i in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == "replace":
        str = str[:a] + line[3] + str[b:]
    elif c == "reverse":
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])


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

int main() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j + i <= n; j++) {
      if (y == 10000*i+5000*j+1000*(n - i - j)) {
        cout << i << " " << j << " "  << n -i -j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " "  << -1 << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;


int main()
{
    int n;
    cin>>n;
    int a=n%10;
    if(a==2||a==4||a==5||a==7||a==9)
    {
        cout<<"hon"<<endl;
    }
    else if(a==0||a==1||a==6||a==8)
    {
        cout<<"pon"<<endl;
    }
    else  if(a==3)
    {
        cout<<"bon"<<endl;
    }
    return 0;
}


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

int main() {
  int k;
  int a,b;
  cin >> k >> a >> b;
  int x;
  x = b / k * k;
  if(x >= a){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }

  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>

using namespace std;

bool simulate(const vector<int> &L, const vector< pair<int, int> > &vp, int T, int M){
	int N = vp.size();
	vector<int> lest(T+1, 0);
	vector<bool> ok(vp.size(), false);
	for(int i=0;i<M;i++) lest[L[i]]++;
	int cnt = N-M;
	for(int i=1;i<T;i++){
		if(cnt == 0) return true;
		if(lest[i]==0) continue;
		for(int j=M;j<N;j++){
			if(ok[j]) continue;
			if(i%vp[j].second <= vp[j].first){
				if(i+L[j] > T) return false;
				cnt--;
				ok[j] = true;
				lest[i]--;
				lest[i+L[j]]++; 
			}
			if(lest[i] == 0) break;
		}
		lest[i+1] += lest[i];
	}
	return cnt == 0;
}

int main(){
	int N, T;
	while(cin >> N >> T, N){
		vector<int> L(N);
		vector< pair<int, int> > vp(N);
		for(int i=0;i<N;i++){
			cin >> L[i] >> vp[i].first >> vp[i].second;
			vp[i].second += vp[i].first;
		}
		for(int i=1;i<=N;i++){
			if(simulate(L, vp, T, i)){
				cout << i << endl; break;
			}
		}
	}
}

Measured memory_bytes: 920
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#include<cstdio>

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


int main() {
	int year, month, day;
	scanf("%d/%d/%d", &year, &month, &day);

	if (month >= 10 && day >= 10) {
		cout << year + 1 << "/" << month << "/" << day << endl;
	}
	else if (month < 10 && day >= 10) {
		cout << year + 1 << "/0" << month << "/" << day << endl;
	}
	else if (month >= 10 && day < 10) {
		cout << year + 1 << "/" << month << "/0" << day << endl;
	}
	else {
		cout << year + 1 << "/0" << month << "/0" << day << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int csum[100001] = {};
    FOR(i, 1, S.size()) {
        if (S[i - 1] == 'A' && S[i] == 'C') csum[i] = csum[i - 1] + 1;
        else csum[i] = csum[i - 1];
    }
    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        if (l - 1 >= 0 && S[l - 1] == 'A' && S[l] == 'C') {
            cout << csum[r] - csum[l - 1] - 1 << endl;
        } else {
            cout << csum[r] - csum[l - 1] << endl;
        }
    }
    return 0;
}

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

int main()
{
	int n[1000], data[1000] = {0}, ans[100];
	int count = 0, count2 = 0, max = 0, max2 = 0;
	while (cin >> n[count]){
		if (n[count] > max)
			max = n[count];
		data[n[count]]++;
		count++;
	}
	for (int i = 0; i <= max; i++) {
		if (data[i] >= max2) {
			max2 = data[i];
		}
	}
	for (int i = 0; i <= max; i++) {
		if (data[i]==max2) {
			ans[count2] = i;
			count2++;
		}
	}
	for (int k = 0; k < count2; k++)
		cout << ans[k] << endl;
	return 0;
}

Measured memory_bytes: 3100
h,w=map(int, input().split())
ch,cw=map(lambda x:int(x)-1,input().split())
dh,dw=map(lambda x:int(x)-1,input().split())
s=[list(input()) for _ in range(h)]

dy=[1, 0, -1, 0]
dx=[0, 1, 0 ,-1]
my=[-2, -2, -2, -2, -2, -1, -1, -1, -1, -1,  0,  0, 0, 0,  1,  1, 1, 1, 1,  2,  2,  2,  2,  2]
mx=[-2, -1,  0,  1,  2, -2, -1,  0,  1,  2, -2, -1, 1, 2, -2, -1, 0, 1, 2, -2, -1,  0,  1,  2]

from collections import deque

d=[[float("inf")]*w for _ in range(h)]
queue=deque()
queue.append((ch, cw))
d[ch][cw]=0

while queue:
    y,x=queue.pop()

    for d_y, d_x in zip(dy, dx):
        new_y=y+d_y
        new_x=x+d_x
        if new_y<0 or h<=new_y or new_x<0 or w<=new_x:
            continue
        if s[new_y][new_x]=='.' and d[new_y][new_x]>d[y][x]:
            d[new_y][new_x]=d[y][x]
            queue.append((new_y, new_x))

    for m_y, m_x in zip(my, mx):
        new_y=y+m_y
        new_x=x+m_x
        if new_y<0 or h<=new_y or new_x<0 or w<=new_x:
            continue
        if s[new_y][new_x]=='.' and d[new_y][new_x]==float("inf"):
            d[new_y][new_x]=d[y][x]+1
            queue.appendleft((new_y, new_x))

print(-1 if d[dh][dw]==float("inf") else d[dh][dw])



Measured memory_bytes: 144648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;
constexpr auto MAX = 100000;

class Edge{
  public:
    int direction, weight;
    Edge(){}
    Edge(int d, int w) : direction(d), weight(w) {}
};

vector<Edge> Graph[MAX];
int n, dist[MAX];
bool visited[MAX];
int cnt;

void bfs(int start_at){
  rep(i, n){
  visited[i] = false;
  dist[i] = INF;
  }
  dist[start_at] = 0;
  visited[start_at] = true;
  queue<int> que;
  que.push(start_at);
  int now_at;
  int next_at; 
  while(!que.empty()){
    now_at = que.front();
    que.pop();
    rep(i, Graph[now_at].size()){
      next_at = Graph[now_at][i].direction;
      if(!visited[next_at]){
        dist[next_at] = dist[now_at] + Graph[now_at][i].weight;
        que.push(next_at);
        visited[next_at] = true;
      }
    }
  }
}

int CulcDiameter(){
  bfs(0);
  int start, maxdist;
  maxdist = 0;
  rep(i,n){
    if(dist[i] == INF) continue;
    if(dist[i] > maxdist){
      start = i;
      maxdist = dist[i];
    }
  }
  bfs(start);
  maxdist = 0;
  rep(i,n){
    if(dist[i] == INF) continue;
    maxdist = max(maxdist, dist[i]);
  }
  cout << maxdist << endl;
}

int main(){
  cin >> n;
  int s , t , w;
  rep(i,n-1){
    cin >> s >> t >> w;
    Graph[s].push_back(Edge(t,w));
    Graph[t].push_back(Edge(s,w));
  }

  CulcDiameter();

  return 0;
}


Measured memory_bytes: 9924
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  int t[n+2], v[n+2];
  t[0] = 0; t[n+1] = 0; v[0] = 0; v[n+1] = 0;
  for (int i=0; i<n; ++i) cin >> t[i+1];
  for (int i=0; i<n; ++i) cin >> v[i+1];
  double ans = 0, speed = 0;
  for (int i=1; i<=n; ++i) {
    for (int j=0; j<t[i]*2; ++j) {
      bool flg = false;
      int ov_time = 0;
      for (int k=i+1; k<=n+1; ++k) {
        if (speed - (t[i]*2-j-1)/2.0-ov_time > v[k]) {flg = true; break;}
        ov_time += t[k];
      }
      if (flg) {
        ans += (speed+speed-0.5)*0.5/2;
        speed -= 0.5;
      } else {
        if ((int)speed == v[i]) ans += speed * 0.5;
        else {
          ans += (speed+speed+0.5)*0.5/2;
          speed += 0.5;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    int T;
    int A;
    cin >> N;
    cin >> T;
    cin >> A;
    int H[1001];
    int B[1001];
    int C[1001];
    for(int i = 0;i < N;++i) cin >> H[i];
    for(int i = 0;i < N;++i){
        int x = 1000*T - H[i]*6;
        B[i] = abs(1000*A - x);
        C[i] = abs(1000*A - x);
        }
    sort(B,B+N);
    for(int i = 0;i < N;++i){
        if(C[i] == B[0]) cout << i+1 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    double a[n],s=0,avg=0;
    for (int i=0;i<n;i++) {
        cin>>a[i];
        s += a[i];
    }
    avg= s/((double)n);
    s = abs(a[0]-avg);
    int ans=0;
    for (int i=1;i<n;i++) {
        if (abs(a[i]-avg)<s) {
            s = abs(a[i]-avg);
            ans = i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256