akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
using namespace std;

int a,b,n,x,y;
bool block[20][20];
long long comb[20][20];

int main(){
  while(cin >> a >> b, a){
    memset(block,0,sizeof(block));
    memset(comb,0,sizeof(comb));
    
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> x >> y;
      block[x-1][y-1] = true;
    }

    comb[0][0] = 1;
    for(int i=0;i<a;i++){
      for(int j=0;j<b;j++){
	if(block[i][j])continue;
	if(i)comb[i][j] += comb[i-1][j];
	if(j)comb[i][j] += comb[i][j-1];
      }
    }

    cout << comb[a-1][b-1] << endl;
  }
}

Measured memory_bytes: 1156
import queue
k = int(input())
q = queue.Queue()

for i in range(1,10):
  q.put(i)

c = 0
while not q.empty():
  c += 1
  x = q.get()
  if c == k:
    print(x)
    break
  y = x%10
  if y != 0:
    q.put(10*x+y-1)
  q.put(10*x+y)
  if y != 9:
    q.put(10*x+y+1)

Measured memory_bytes: 12480
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibutan(auto a,auto b);
int kai(int n){
    int ans = 1;
    REP(i,n){
        ans *= 2;
        ans %= max_int;
    }
    return ans;
}

signed main(){
    int n;
    cin >> n;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
    }
    Sort(a);
    if(n%2==1){
        REP(i,n){
            if((i+1)/2*2 != a[i]){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << kai(n/2) << endl;
        return 0;
    }
    else{
        REP(i,n){
            if((i/2)*2+1 != a[i]){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << kai(n/2) << endl;
        return 0;
    }
    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibutan(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    return x-1;
}

Measured memory_bytes: 1024
import heapq
n,m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)  #aは優先度付きキューにいれる

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))

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

int N;

void solve(string S,char add){
    if(S.length()==N){
        cout<<S<<endl;
    }else{
        for(char i='a';i<=add;i++){
            if(i==add)solve(S+i,add+1);
            else solve(S+i,add);
        }
    }
}

int main() {
    cin >> N;
    solve("",'a');
    return 0;
}

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

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

int main() {

    ll N;
    cin >> N;

    vector<ll> H(N);

    for(ll i=0; i<N; i++){
        cin >> H[i];
    }

    ll cnt = 0;
    ll ans = 0;
    for(ll i=0; i<N-1; i++){
        if(H[i] >= H[i+1]){
            cnt++;
        }else{
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
    ans = max(ans,cnt);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
#define DIM 1100

//field
int f[DIM*DIM];
//the count of . around f[i][j]
int m[DIM*DIM];
int count(int h,int w){
	int a[9]={0,1,1,0,-1,-1,1,-1,0},sum=0;
	for(int i =0;i<8;i++){
		if(f[(h+a[i])*DIM+w+a[i+1]]==-1)sum++;
	}
	return sum;
}
void change(int h,int w){
	int a[9]={0,1,1,0,-1,-1,1,-1,0};
	for(int i =0;i<8;i++){
		m[(h+a[i])*DIM+w+a[i+1]]++;
	}
}
void add(int h,int w,vector<int>& v){
	int a[9]={0,1,1,0,-1,-1,1,-1,0};
	for(int i =0;i<8;i++){
		if(m[(h+a[i])*DIM+w+a[i+1]] >= f[(h+a[i])*DIM+w+a[i+1]] && f[(h+a[i])*DIM+w+a[i+1]] >= 0 &&f[(h+a[i])*DIM+w+a[i+1]] <9){
		//	cout<<f[(h+a[i])*DIM+w+a[i+1]]<<endl;
			f[(h+a[i])*DIM+w+a[i+1]] = -10;
			v.push_back((h+a[i])*DIM+w+a[i+1]);
		}
	}
}

int main(){
	int h,w;
	cin>>h>>w;
	vector<int> v;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char t;
			cin>>t;
			if(t=='.')f[i*DIM+j]=-1;
			else f[i*DIM+j]=t-'0';
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			m[i*DIM+j]=count(i,j);
			if(m[i*DIM+j] >= f[i*DIM+j] && f[i*DIM+j] != -1){
				v.push_back(i*DIM+j);
				f[i*DIM+j]=-10;
			}
		}
	}
	int c=1;
	int cnt;
	while(1){
		cnt = v.size();
		/*for(int i = 0;i < cnt;i++){
		  f[v[i]] = e;
		  }*/
		for(int i = 0;i < cnt;i++){
			change(v[i]/DIM,v[i]%DIM);
		}
		for(int i = 0;i < cnt;i++){
			add(v[i]/DIM,v[i]%DIM,v);
		}
		v.erase(v.begin(),v.begin()+cnt);
		if(v.size() == 0){
			break;
		}
		c++;
	}
	cout<<c<<endl;
	return 0;
}

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

const int N=200100;
typedef long long ll;
vector<pair<int,int> >g[N];
int n,res1[N],res2[N],mn,rt;
ll ans;

int dfs(int x,int fa=-1){
	int sz=1,mx=0;
	res1[x]=res2[x]=INT_MAX;
	for(auto i:g[x])if(i.first!=fa){
		int u=dfs(i.first,x);
		sz+=u;mx=max(mx,u);res1[x]=min(res1[x],i.second);
		ans+=min(u,n-u)*2ll*i.second;
	}else res2[x]=i.second;
	mx=max(mx,n-sz);
	if(mx<mn){mn=mx;rt=x;}
	return sz;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;++i){
		int x,y,z;cin>>x>>y>>z;
		g[x].emplace_back(y,z);
		g[y].emplace_back(x,z);
	}
	rt=1;mn=n;
	dfs(1);
	ans-=(mn*2==n?res2[rt]:min(res1[rt],res2[rt]));
	cout<<ans<<'\n';
	return 0;
}


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

using namespace std;

class gfg {
    /* Function to get no of set bits in binary
representation of passed binary no. */
public:
    unsigned int countSetBits(int n)
    {
        unsigned int count = 0;
        while (n) {
            n &= (n - 1);
            count++;
        }
        return count;
    }
}g;

vector<long long >prime;

#define MOD 1000000007
#define primemod 998244353
#define ll long long int
#define maxv(all,A) *max_element(A.begin(),A.end())
#define minv(all,A) *min_element(A.begin(),A.end())
#define sumv(all,A,a) accumulate(A.begin(), A.end(),a)
#define FOR(i,n) for(long long int i=0;i<(n);i++)
#define NFOR(i,n) for(long long int i=n-1;i>=0;i--)
#define asort(all,A) sort((A).begin(),(A).end())
#define dsort(all,A,x) sort((A).begin(),(A).end(),greater<x>())
#define pb(a) push_back((a))
#define mk_pair(x,y,a,b) insert(pair<x,y >(a,b))
#define autv(x) vector<x>::iterator
#define autm(x,y) map<x,y>::iterator
#define auts(x) set<x,greater<x> >::iterator
#define ini_v(n,x,A) FOR(i,n){ x a; cin>>a; A.pb(a) ;}
#define ini_m(n,x,y,b,M) for(ll i=0;i!=n;i++){y a; cin>>a; M.mk_pair(x,y,b+i,a);}
#define IFOR(i,x,y,M) for(autm(x,y) i=M.begin(); i!=M.end();i++)
#define in(a) emplace(A.begin(),a)



void solve()
{
   ll s,w;
  cin>>s>>w;
  if(w>=s)
    cout<<"unsafe";
  else
    cout<<"safe";
}

void template1 ()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   //template1();
     solve();cout<<"\n";
    return 0;
}

















Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int n;
  while(cin >> n, n) {
    int dat[n];
    for(int i=0; i<n; i++) cin >> dat[i];
    sort(dat, dat+n);
    int ave = 0;
    for(int i=1; i<n-1; i++) ave += dat[i];
    ave /= n-2;
    cout << ave << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 100005;


ll n;
pii pos[MAXN];
ll djs[MAXN];

ll fnd(ll x) {
    return x == djs[x] ? x : (djs[x] = fnd(djs[x]));
}

void mrg(ll x,ll y) {
    x = fnd(x), y = fnd(y);
    if (x != y) {
        djs[x] = y;
    }
}

vector<ll> x[MAXN*2], y[MAXN*2];
vector<ll> g[MAXN];
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n;
    REP (i,MAXN) {
        djs[i] = i;
    }


    REP (i,n) {
        cin >> pos[i].X >> pos[i].Y;
        x[pos[i].X + MAXN].eb(i);
        y[pos[i].Y + MAXN].eb(i);
    }

    REP (i,MAXN*2) {
        REP (j,SZ(x[i])-1) {
            mrg(x[i][j],x[i][j+1]);
        }
        REP (j,SZ(y[i])-1) {
            mrg(y[i][j],y[i][j+1]);
        }
    }

    REP (i,n) {
        g[fnd(i)].eb(i);
    }

    ll ans = 0;
    REP (i,n) {
        vector<ll> xv,yv;
        for (auto id : g[i]) {
            xv.eb(pos[id].X);
            yv.eb(pos[id].Y);
        }
        sort(ALL(xv));
        sort(ALL(yv));
        ans += (unique(ALL(xv))-xv.begin()) * (unique(ALL(yv))-yv.begin()) - SZ(g[i]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21132
#include <iostream>
#include <algorithm>
#define N 50000
using namespace std;

int main(){
  bool ip[N];
  int p[N];
  for(int i=0;i<N;i++) ip[i]=true;
  int q=0;
  ip[0]=ip[1]=false;
  for(int i=0;i<N;i++){
    if(ip[i]){
      p[q++]=i;
      for(int j=i*2;j<N;j+=i) ip[j]=false;
    }
  }
  int n,a;
  while(1){
    cin>>n;
    a=0;
    if(n==0) break;
    if(n%2){
      if(binary_search(p,p+q,n-2)) a=1;
    }
    else{
      for(int i=0;p[i]<=n/2;i++){
	if(binary_search(p+i,p+q,n-p[i])) a++;
      }
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
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; }

int main()
{
  ll x;
  cin >> x;

  ll sen = x / 500;
  ll remain = x % 500;

  ll five = remain / 5;

  cout << sen * 1000 + five * 5 << endl;

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

l = []
ans = [0] * m

for i in range(m):
    l.append([int(j) for j in input().split()])
    l[i].append(i)

#[県, 市, 元の順番]
l2 = sorted(l, key=lambda x:(x[0],x[1]))
cnt = 1

for i in range(m):
    
    l2[i][1] = cnt
    
    if i < m -1 and l2[i][0] == l2[i + 1][0]:
        cnt += 1
    else:
        cnt = 1

    ans[l2[i][2]] = '{:06}{:06}'.format(l2[i][0],l2[i][1])

for s in ans:
    print(s)

Measured memory_bytes: 33948
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; long long k; cin >> n >> k;
  vector<long long> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a));
  vector<long long> f(n); REP(i, n) cin >> f[i];
  sort(ALL(f), greater<long long>());
  long long lb = -1, ub = 1000000000000;
  while (ub - lb > 1) {
    long long mid = (lb + ub) / 2;
    long long train = 0;
    REP(i, n) {
      if (a[i] * f[i] > mid) {
        train += a[i] - mid / f[i];
      }
    }
    (train <= k ? ub : lb) = mid;
  }
  cout << ub << '\n';
  return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int N = Integer.parseInt(line);
		long money = 1000;

		line = sc.nextLine();
		String[] lines = line.split(" ");
		int[] A = new int[N+1];
		int min = 201;
		int max = -1;

		for (int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(lines[i]);
		}

		long kabu = 0;
		for (int i = 0; i < N - 1; i++) {
			kabu = 0;
			if (A[i] < A[i + 1]) {
				kabu = money / A[i];
			}
			money = money + (A[i + 1] - A[i]) * kabu;
		}
		System.out.println(money);
	}

}


Measured memory_bytes: 35588
from collections import deque
trush_a, trush_b, limit_time = list(map(int,input().split()))
total = [0, 0]
count = [0, 0]
desks = [deque(),deque()]
result = 0

for i in range(2):

    for j in list(map(int,input().split())):
        temp = total[i] + j 
        if temp <= limit_time:
            total[i] += j
            count[i] += 1
            desks[i].append(j)
        else:
            break

while count[0] > 0 or count[1] > 0:
    if count[0] == count[1]:
        select = total[0] > total[1]
    else:
        select = count[0] < count[1]

    temp = desks[select].popleft()
    result += 1
    limit_time -= temp
    total[select] -= temp
    count[select] -= 1

    while total[not select] > limit_time:
        dim_time = desks[not select].pop()
        total[not select] -= dim_time
        count[not select] -= 1

print(result)


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	priority_queue<LL> pq;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		pq.push(a);
	}
	for (int i = 0; i < m; i++) {
		int t = pq.top();
		pq.pop();
		pq.push(t/2);
	}
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, T;
	cin >> n >> T;

	vector<pll> v;
	vl w;
	FOR(i,0,n) {
		ll a, b;
		cin >> a >> b;
		
		if (a == 0) {
			w.pb(b+1);
		} else {
			v.eb(a+1, a+b+1);
		}
	}

	sort(all(v), [&](pll p, pll q) {
		return (p.xx-1)*q.yy > (q.xx-1)*p.yy;
	});

	const ll K = 35;
	vl dp(K,oo);
	dp[0] = 0;
	
	for (auto p: v) {
		ll a, b;
		tie(a,b) = p;
		
		FORD(k,0,K-1) if (__int128(a)*dp[k] < oo) {
			dp[k+1] = min(dp[k+1], a*dp[k] + b);
		}
	}

	sort(all(w));
	vl sum(sz(w)+1);
	FOR(i,0,sz(w)) sum[i+1] = sum[i] + w[i];
	
	ll res = 0;
	FOR(k,0,K) FOR(i,0,sz(w)+1) {
		if (dp[k]+sum[i] <= T) {
			res = max(res, k+i);
		}
	}
	cout << res << endl;
}



Measured memory_bytes: 6512
import java.util.*;

public class Main {
	static int w;
	static int h;
	static int[][] fi;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			w = sc.nextInt();
			h = sc.nextInt();
			if (w == 0 && h == 0)
				break;
			fi = new int[h][w];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
					fi[i][j] = sc.nextInt();
			int n = 0;
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
					if (fi[i][j] == 1)
						n += loop(j, i);
			System.out.println(n);
		}
		sc.close();
	}

	public static int loop(int x, int y) {
		fi[y][x] = 0;
		int[] dx = { 0, 1, 1, 1, 0, -1, -1, -1 };
		int[] dy = { 1, 1, 0, -1, -1, -1, 0, 1 };
		for (int i = 0; i < 8; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
				if (fi[ny][nx] == 1)
					loop(nx, ny);
			}
		}
		return 1;
	}
}

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

int main() {
  int t, n, k;
  vector<int> x;
  vector<int> inter;
  int min_len;

  cin >> t;
  for(int i = 0; i < t; i++) {
    min_len = 0;
    cin >> n >> k;

    for(int j = 0; j < n; j++) {
      int X;
      cin >> X;
      x.push_back(X);
    }

    for(int j = 1; j < n; j++) {
      int I = x[j] - x[j-1];
      inter.push_back(I);
    }

    sort(inter.begin(), inter.end(), greater<int>());

    for(int j = k-1; j < n-1; j++) {
      min_len += inter[j];
    }

    cout << min_len << endl;

    inter.clear();
    x.clear();
  }
}



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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int a,b,c;
	cin >> a >> b >>c;
	if(a-b ==0)
		cout << c << "\n";
	else if(a-c == 0)
		cout << b << "\n";
	else cout << a << "\n";	
	return 0;
}

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

if sum(a) < sum(b): print(-1)
else:
    cnt = 0
    Abs = []
    s = 0
    for i in range(n):
        if a[i] < b[i]: 
            cnt += 1
            s += b[i]-a[i]
        elif a[i] > b[i]:
            Abs.append(a[i]-b[i])
    Abs.sort(reverse=True)
    s2 = 0
    i = 0
    while s2 < s:
        s2 += Abs[i]
        i += 1
    print(i+cnt)

Measured memory_bytes: 18356
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a;
	vector<pair<int, int> > bc;
	for(int i = 0; i < n; i++){
		int tmpa;
		cin >> tmpa;
		a.push_back(tmpa);
	}
	for(int i = 0; i < m; i++){
		int b, c;
		cin >> b >> c;
		bc.push_back(make_pair(c, b));
	}
	sort(a.begin(), a.end());
	sort(bc.begin(), bc.end(), greater<pair<int, int> >());
	int bc_index = 0;
	for(int i = 0; i < n; i++){
		if(bc_index >= m || bc[bc_index].first < a[i]) break;
		a[i] = bc[bc_index].first;
		bc[bc_index].second--;
		if(bc[bc_index].second == 0) bc_index++;
	}
	cout << accumulate(a.begin(), a.end(), 0LL) << endl;
}

Measured memory_bytes: 1784
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn digit_sum(n: u64) -> u64 {
    let mut tmp = n;
    let mut sum = 0;
    while tmp != 0 {
        sum += tmp % 10;
        tmp /= 10;
    }
    sum
}

fn main() {
    from_line!(n: u64);
    let mut min = 1000000;
    for a in 1..n {
        let b = n - a;
        if min > digit_sum(a) + digit_sum(b) {
            min = digit_sum(a) + digit_sum(b);
        }
    }
    println!("{}", min);
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

struct RL {
    int R = 0, L = 0;
};

void solve(long long N, std::vector<std::string> S){
    rep(i,0,N) {
        vector<int> left;
        rep(j,0,S[i].size()) {
            if (S[i][j] == '(') {
                left.push_back(j);
            } else if (!left.empty() && S[i][j] == ')') {
                S[i][left.back()] = 'o';
                S[i][j] = 'o';
                left.pop_back();
            }
        }
        left.clear();
    }
    vector<RL> rl(N);
    rep(i,0,N) {
        rep(j,0,S[i].size()) {
            if (S[i][j] == ')') {
                assert(rl[i].L == 0);
                rl[i].R++;
            } else if (S[i][j] == '(') {
                rl[i].L++;
            }
        }
    }
    sort(all(rl), [](const auto & a, const auto & b) {
        if ((a.L - a.R >= 0) ^ (b.L - b.R >= 0)) {
            return (a.L - a.R) > (b.L - b.R);
        }
        if (a.L - a.R >= 0) {
            return a.R < b.R;
        } else {
            return a.L > b.L;
        }
    });
    bool isValid = true;
    int current = 0;
    rep(i,0,N) {
        current -= rl[i].R;
        if (current < 0) {
            isValid = false;
            break;
        }
        current += rl[i].L;
    }
    if (current != 0) isValid = false;
    cout << (isValid ? "Yes" : "No") << endl;
}

signed main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    long long N;
    cin >> N;
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


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

int main() {
    long long X; cin >> X;
    long long n = 100;
    for(int i=1; i<=10000; ++i) {
        n += (n / 100);
        if(n >= X) {
            cout << i << '\n';
            return 0;
        }
    }
}

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

int main() {
	int H, W;
	string st[100];
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> st[i];
	}

	for (int i = 0; i < W + 2; i++) {
		cout << "#" << flush;
	}
	cout << endl;

	for (int i = 0; i < H; i++) {
		cout << "#" << st[i] << "#" << endl;
	}
	for (int i = 0; i < W + 2; i++) {
		cout << "#" << flush;
	}
	cout << endl;
	return 0;
}

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

int main(){
    ll H,W,x,y;
    cin >> W >> H >> x >> y;
    if(x*2 == W && y*2 == H){
        printf("%.12f 1\n",(double)H*(double)W/2);
    }else{
        printf("%.12f 0\n",(double)H*(double)W/2);

    }
    
    return 0;
}

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

int main() 
{
    ulong N;
    cin>>N;
    vector<ulong>A(N);
    for (ulong i = 0; i < N; i++)
    {
        cin>>A[i];
    }
    
    ulong ans = 0,fumi=0;
    for(auto&a:A)
    {
        if(fumi<=a)
        {
            fumi=a;
        }
        else
        {
            ans+=(fumi-a);
            a=fumi;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4836
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

#input = sys.stdin.readline
from collections import defaultdict

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())

p = list(map(int, input().split()))
q = copy.deepcopy(p)

p.sort()

diff = 0
for i in range(N):
    diff += p[i] != q[i]

print(("NO", "YES")[diff<=2])


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>

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

using namespace std;

int main () {
    int n;
    cin >> n;
    int no = (n+1) / 2;
    cout << (double)no / n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s[100003];
char a[10];
int main()
{
	scanf("%s",a);
	for(int i=0;i<=2;i++)
		s[a[i]]++;
	if(s['A']!=0&&s['B']!=0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

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

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

/////////////////////////////////////////////////////////

void Main() {
  string S; cin >> S;
  string res = "Yes";
  rep(i, 0, S.size()){
    if(i % 2 == 0){
      //odd
      if(S[i] == 'L') res = "No";
    }
    if(i % 2 == 1){
      //even
      if(S[i] == 'R') res = "No";
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#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(){
  char c;
  cin >> c;
  cout << (char)(c+1) << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;
  
  if(x != NIL) x->parent = y->parent;
  
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  
  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20476
#include<stdio.h>
int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a < b) {
    if (b < c) {
      printf("%d %d %d\n", a, b, c);
    } else if (a < c) {
      printf("%d %d %d\n", a, c, b);
    } else {
      printf("%d %d %d\n", c, a, b);
    }
  } else {
    if (a < c) {
      printf("%d %d %d\n", b, a, c);
    } else if (b < c) {
      printf("%d %d %d\n", b, c, a);
    } else {
      printf("%d %d %d\n", c, b, a);
    }
  }
  return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    bool uns = false;

    if ((a == 5) || (a == 7)) {
        count = a;
        if ((b == 5) || (b == 7)) {
            count += b;
            if ((c == 5) || (c == 7)) {
                count += c;
                if (count == 17){
                    uns = true;
                }
            }
        }
    }
    cout << (uns ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

namespace Tenki_20190901
{
    class Program
    {
        static void Main(string[] args)
        {
            string report = Console.ReadLine();   //予報の天気
            string weather = Console.ReadLine();  //実際の天気
            char[] report_c = report.ToCharArray();
            char[] weather_c = weather.ToCharArray();

            int correct = 0;

            for (int i = 0; i < report_c.Length; i++)
            {
                if (report_c[i] == weather_c[i])
                {
                    correct++;
                }
            }
            Console.WriteLine(correct.ToString());
        }
    }
}


Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] listStr = reader.readLine().split(" ");
    int w = Integer.parseInt(listStr[0]);
    int h = Integer.parseInt(listStr[1]);
    int x = Integer.parseInt(listStr[2]);
    int y = Integer.parseInt(listStr[3]);
    int r = Integer.parseInt(listStr[4]);
 
    if (x + r <= w && y + r <= h && x - r >= 0 && y - r >= 0)
      System.out.println("Yes");
    else
      System.out.println("No");
 
  }
 
}

Measured memory_bytes: 24440
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
#include <string>
#include <cmath>
using namespace std;
#pragma warning (disable: 4996)

long long S, A[1000009]; map<long long, int>M;

int main() {
	cin >> S;
	A[1] = S; M[S] = 1;
	for (int i = 2; i <= 1000000; i++) {
		if (A[i - 1] % 2 == 0) A[i] = A[i - 1] / 2;
		else A[i] = 3LL * A[i - 1] + 1LL;
		if (M[A[i]] == 1) {
			cout << i << endl;
			break;
		}
		M[A[i]] = 1;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		string s;
		while((s = Console.ReadLine()) != null){
			int n = int.Parse(s);

			if(n>36) Console.WriteLine(0);
			else{
				if(n>18) n = 36-n;
				int ans = (n+1)*(n+2)*(n+3)/6;
				if(n>9) ans -= 2*(n-9)*(n-8)*(n-7)/3;
				Console.WriteLine(ans);
			}
		}
	}
}

Measured memory_bytes: 8992
from functools import reduce


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


def graham_scan(points):
    points.sort(key=lambda p: (p.real, p.imag))
    lh = reduce(keep_left, points, [])
    uh = reduce(keep_left, reversed(points), [])
    lh.extend(uh[1:-1])
    return lh


def keep_left(hull, r):
    if hull:
        prev = hull.pop()
        while hull:
            p = hull[-1]
            if cross(prev - p, r - p) >= 0:
                hull.append(prev)
                break
            prev = hull.pop()
        else:
            hull.append(prev)
    if not hull or hull[-1] != r:
        hull.append(r)
    return hull


n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
result = graham_scan(points)
lr = len(result)
print(lr)
s = min(range(lr), key=lambda i: (result[i].imag, result[i].real))
for p in (result[s:] + result[:s]):
    print(int(p.real), int(p.imag))

Measured memory_bytes: 24680
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

// 688ms で AC
void calc(int k, long[] a, long[] b, long[] c) {
    long[] ab;
    foreach (x, y; cartesianProduct(a, b))
        ab ~= x + y;

    ab.sort!"a > b";
    c.sort!"a > b";
    long[] abc;
    foreach (x, y; cartesianProduct(c, ab.take(k)))
        abc ~= x + y;
    abc.sort!"a > b";
    foreach (e; abc.take(k)) writeln(e);
}

// 17ms で AC
void calc2(int K, long[] a, long[] b, long[] c) {
    a.sort!"a > b";
    b.sort!"a > b";
    c.sort!"a > b";

    long[] t;
    for (int i = 0; i < a.length; i++) {
        for (int j = 0; j < b.length; j++) {
            for (int k = 0; k < c.length; k++) {
                if ((i + 1) * (j + 1) * (k + 1) > K) break;
                t ~= a[i] + b[j] + c[k];
            }
        }
    }
    t.sort!"a > b";
    foreach (x; t.take(K)) writeln(x);
}

void calc3(int K, long[] a, long[] b, long[] c) {
    alias D = Tuple!(long, "sum", int, "i", int, "j", int, "k");
    alias MaxHeap = BinaryHeap!(Array!D, "a < b");

    a.sort!"a > b";
    b.sort!"a > b";
    c.sort!"a > b";
    auto pq = new MaxHeap;
    pq.insert(D(a[0] + b[0] + c[0], 0, 0, 0));
    int[Tuple!(int, int, int)] used;
    while (K > 0) {
        auto d = pq.front;
        pq.popFront();
        if (used[tuple(d.i, d.j, d.k)]++) continue;

        writeln(d.sum);
        K--;

        int i = d.i;
        int j = d.j;
        int k = d.k;
        if (i + 1 < a.length)
            pq.insert(D(a[i + 1] + b[j] + c[k], i + 1, j, k));
        if (j + 1 < b.length)
            pq.insert(D(a[i] + b[j + 1] + c[k], i, j + 1, k));
        if (k + 1 < c.length)
            pq.insert(D(a[i] + b[j] + c[k + 1], i, j, k + 1));
    }
}

void main() {
    int x, y, z, k; scan(x, y, z, k);
    auto a = reads!long;
    auto b = reads!long;
    auto c = reads!long;

    calc3(k, a, b, c);
}


Measured memory_bytes: 2812
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = -1;
		int min = 1001;
		for(int i=0; i<n; i++){
			int a = sc.nextInt();
			if(max < a){
				max = a;
			}
			if(a < min){
				min = a;
			}
		}
		
		System.out.println(max-min);
		return;
	}
}

Measured memory_bytes: 20948
N=int(input())
G=[[] for i in range(N)]
for i in range(N-1):
    u,v,w=map(int,input().split())
    u-=1; v-=1; w%=2
    G[u].append([v,w])
    G[v].append([u,w])
col=[-1 for i in range(N)]
col[0]=0

from collections import deque
dq=deque([0])

while len(dq)>0:
    p=dq.popleft()
    for i in range(len(G[p])):
        if col[G[p][i][0]]==-1:
            dq.append(G[p][i][0])
            col[G[p][i][0]]=(col[p]+G[p][i][1])%2
        
for i in col:
    print(i)

Measured memory_bytes: 42220
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll dp[1010][1010] = {};
char c[1010][1010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    rep(i,0,H){
        rep(j,0,W){
            cin >> c[i][j];
        }
    }
    dp[0][0] = 1;
    rep(i,0,H){
        rep(j,0,W){
            if(c[i][j] == '#') continue;
            if(i != 0 && c[i-1][j] == '.'){
                dp[i][j] += dp[i-1][j] % MOD;
            }
            if(j != 0 && c[i][j-1] == '.'){
                dp[i][j] += dp[i][j-1] % MOD;
            }
            dp[i][j] %= MOD;
        }
    }
    print(dp[H-1][W-1]);
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, m, a, b;
  cin >> n >> m;
  map<ll, vecll> mp;
  forll(i, 0, m){
	cin >> a >> b;
	mp[a].push_back(b);
	mp[b].push_back(a);
  }
  forll(i, 0, mp[1].size()){
	if(find(mp[mp[1][i]].begin(), mp[mp[1][i]].end(), n) != mp[mp[1][i]].end()){
	  cout << "POSSIBLE" << endl;
	  return 0;
	}
  }
  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 29928
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
int n,k;
ll ans=1;
int l_neg=-1,l_pos=-1,r_neg=-1,r_pos=-1;
const ll M=1e9+7;
inline bool cmp(ll a, ll b) {
	return abs(a)<abs(b);
}
int calc(vector<ll> a) {
	ll ret=1;
	for(int i = n - k; i < n; i++)
		(ret*=a[i])%=M;
	return ret;
}
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int main() {
	n=read(),k=read();
	vector<ll> a(n,0);
	for (register int i=0;i<n;++i) a[i]=read();
	sort(a.begin(),a.end(),cmp);
	for (register int i=n-k;i<n;++i) {
		(ans*=a[i])%=M;
		if (r_pos==-1&&a[i]>0) r_pos=i;
		if (r_neg==-1&&a[i]<0) r_neg=i;
	}
	for (register int i=n-k-1;~i;--i) {
		if(l_pos==-1&&a[i]>0) l_pos=i;
		if(l_neg==-1&&a[i]<0) l_neg=i;
	}
	if (ans<0&&n>k) {
		if (r_pos==-1) {
			if (l_pos==-1) {
				ans=1;
				for (int i=0;i<k;++i)
					(ans*=a[i])%=M;
			}
			else {
				swap(a[l_pos],a[r_neg]);
				ans=calc(a);
			}
		}
		else {
			if (l_neg==-1) {
				swap(a[l_pos],a[r_neg]);
				ans=calc(a);
			}
			else if (l_pos==-1) {
				swap(a[l_neg],a[r_pos]);
				ans=calc(a);
			}
			else {
				vector<ll> c1=a;
				vector<ll> c2=a;
				swap(c1[l_neg],c1[r_pos]);
				swap(c2[l_pos],c2[r_neg]);
//				ans==v_cmp(c1, c2)==true? calc(c1): calc(c2);
				ans=(abs(a[l_neg]*a[r_neg])>abs(a[l_pos]*a[r_pos]))?calc(c1):calc(c2);
			}
		}
	}
	cout<<(ans%M+M)%M<<endl;
	return 0;
}

Measured memory_bytes: 9308
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

bool isPrime(int x){
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(int i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

int main(void){
  int X;
  cin >> X;
  while (!isPrime(X)) X++;
  cout << X << endl;
  return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

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

		int n = sc.nextInt();
		boolean cards[][] = new boolean[4][13];
		
		for(int i = 0; i < n; i++){
			String s = sc.next();
			
			switch(s.charAt(0)){
			case 'S':cards[0][sc.nextInt()-1] = true; break;
			case 'H':cards[1][sc.nextInt()-1] = true; break;
			case 'C':cards[2][sc.nextInt()-1] = true; break;
			case 'D':cards[3][sc.nextInt()-1] = true; break;
			}
		}
		char[] c = {'S','H','C','D'};
        for (int i=0; i<4; i++) {
            for (int j=0; j<13; j++) {
                if (!cards[i][j]) {
                    System.out.println(c[i]+" "+(j+1));
                }
            }
        }
	}
}


Measured memory_bytes: 26364
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  int H,A,temp,sum=0;
  cin>>H;
  cin>>A;
//   while(H!=0 || i != A){
//      cin>>temp;
//       H-=temp;
      
//       }
  for (int i = 0;i<A;i++){
      cin>>temp;
      sum+=temp;
      }
   (H>sum) ? cout<<"No"<<endl:cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
void show(VEC<VEC<int>> m) {
  REP(i, 0, m.size()) {
    REP(j, 0, m[i].size()) { printf("%5d ", m[i][j]); }
    puts("");
  }
  puts("");
}
VEC<VEC<int>> dist;
const int inf = 1e8;
int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  dist = MATINIT(int, N, N, inf);
  REP(i, 0, N) {
    REP(j, 0, N) { dist[i][j] = abs(j - i); }
  }
  // show(dist);

  dist[X][Y] = 1;
  dist[Y][X] = 1;
  REP(i, 0, N) {
    dist[i][X] = min(dist[i][X], dist[i][Y] + dist[Y][X]);
    dist[X][i] = min(dist[X][i], dist[X][Y] + dist[Y][i]);
    dist[i][Y] = min(dist[i][Y], dist[i][X] + dist[X][Y]);
    dist[Y][i] = min(dist[Y][i], dist[Y][X] + dist[X][i]);
  }
  // show(dist);

  REP(i, 0, N) {
    REP(j, 0, N) {
      dist[i][j] =
          min({dist[i][j], dist[i][X] + dist[X][j], dist[i][Y] + dist[Y][j]});
    }
  }
  // show(dist);

  map<int, int> cnt;
  REP(i, 0, N) {
    REP(j, 0, N) { cnt[dist[i][j]]++; }
  }
  REP(i, 0, N - 1) { cout << cnt[i + 1] / 2 << endl; }

  return 0;
}


Measured memory_bytes: 17024