akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define oo int(1e9)
#define all(s) s.begin(), s.end()
using namespace std;
typedef unsigned long long ll;
typedef double db;
const ll MOD = (ll)(1e9) + 7;
ll dp[10001][100][2];
int D;
int n;
string K;

ll calc(int id,int sum_digit,int tight,const string& K){
    if (id == K.size()) return (sum_digit == 0);
    if (dp[id][sum_digit][tight] != -1) return dp[id][sum_digit][tight];
    int limit = (tight) ? (K[id] - '0'): 9;
    ll ans = 0;
    for (int dig = 0; dig <= limit; dig ++){
        int newtight = ((K[id] - '0') == dig) ? tight : 0;
        ans = (ans + calc(id + 1,(sum_digit + dig) % D,newtight,K) ) % MOD;
    }
    return dp[id][sum_digit][tight] = ans;
}


int main() {
	cin.tie(0); ios::sync_with_stdio(0); cout.tie(0);
    cin >> K;
    cin.ignore();
    cin >> D;
    memset(dp,-1,sizeof(dp));
    cout << (calc(0,0,1,K) - 1 + MOD) % MOD;
	return 0;
}

Measured memory_bytes: 16896
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;

const int mod = 1000000007;
class mint {
public:
    long long x;
    mint(long long 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(long long t) const {
        if(t == 0) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(t & 1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint& a) { return (*this) *= a.inv();}
    mint operator/(const mint& a) const { mint res(*this); return res /= a;}
};
//istream& operator>>(istream& is, mint& a) { return is >> a.x;}
//ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for(int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if(k < 0 || n < k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    int x, y;
    cin >> x >> y;
    if((x+y) % 3) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x+y) / 3;
    x -= n; y -= n;
    if(x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    combination c(x+y);
    mint ans = c(x+y, x);
    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 13816
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

bool is_month(int m) {
    return (1 <= m) && (m <= 12); 
}

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

    int head = s / 100;
    int tail = s % 100;

    bool is_YYMM = is_month(tail);
    bool is_MMYY = is_month(head);

    if (is_YYMM && is_MMYY) {
        cout << "AMBIGUOUS" << endl;
    } else if (is_YYMM && !is_MMYY) {
        cout << "YYMM" << endl;
    } else if (!is_YYMM && is_MMYY) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N , life;
    cin >> N >> life;
    vector<ll> a, b ;
    ll am = 0;
    rep(i,N){
        ll ai, bi;
        cin >> ai >> bi;
        a.pb(ai); b.pb(bi);
        am = max(am, ai);
    }

    sort(rall(b));
    ll ans = 0;
    rep(i,b.size()){
        if(b[i] < am) break;
        ans ++;
        life -= b[i];
        if(life <= 0){cout << ans << endl; return 0;}
    }
    
    cout << ans + life/am + (bool)(life%am) << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector< vector<int> > VVI;
typedef vector< vector<int> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair

int main(){
  int N;
  cin>>N;
  VI P(N),Q(N);
  rep(i,N) cin>>P[i];
  rep(i,N) cin>>Q[i];
  VI X(N);
  rep(i,N) X[i]=i+1;
  int ans;
  int cnt=0;
  do{
    cnt++;
    int Y=1;
    rep(i,N) Y*=(X[i]==P[i]);
    if(Y) break;
  }while(next_permutation(all(X)));
  rep(i,N) X[i]=i+1;
  do{
    cnt--;
    int Y=1;
    rep(i,N) Y*=(X[i]==Q[i]);
    if(Y) break;
  }while(next_permutation(all(X)));
  cout<<abs(cnt)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b; cin>>a>>b;
    cout<<(a+b+1)/2<<endl;
}

Measured memory_bytes: 3592
import sys
input = lambda: sys.stdin.readline().rstrip()

def floor_sum(n, m, a, b):
    ans = 0
    while 1:
        ans += (n - 1) * n // 2 * (a // m) + n * (b // m)
        a %= m
        b %= m
        y = (a * n + b) // m
        x = b - y * m
        if y == 0: return ans
        ans += (x // a + n) * y
        n, m, a, b = y, a, m, x % a

T = int(input())
for _ in range(T):
    n, m, a, b = map(int, input().split())
    print(floor_sum(n, m, a, b))

Measured memory_bytes: 71012
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(all(d));
    cout << d[n/2]-d[n/2-1] << endl;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


bool bad(vi& a, int k) {
    repC2(i,j,5){
        if (a[j]-a[i] > k) return true;
    }
    return false;
}

int main() {
    vi a(5);
    rep(i,5) cin >> a[i];
    int k;
    cin >> k;
    cout << (bad(a,k) ? ":(":"Yay!") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

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

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;}

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// CHAR_MAX  = 127
// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    int n, k;
    cin >> k >> n;
    vector<int> vec;
    rep(i, n) {
        int x;
        cin >> x;
        vec.push_back(x);
    }

    int diffmax = vec[0] + k - vec[n - 1];
    rep(i, n - 1) {
        int diff = vec[i + 1] - vec[i];
        if (diff > diffmax) {
            diffmax = diff;
        }
    }

    cout << k - diffmax << '\n';


    return 0;
}


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

using namespace std;

const int N = 1e5 + 10;

int flag;
int x,y;
int a,b;

int sum[N];
int main()
{
	cin >> a >> b >> x >> y;
	double x1 = 1.0 * a / 2;
	double y1 = 1.0 * b / 2;
	if((double)(x) == x1 && (double)(y) == y1)
	flag = 1;
	printf("%.6lf", x1 * y1 * 2);
	printf(" %d\n", flag);
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long x; // 1 2 3 6 12
	cin>>x;
	int res = 0;
	int r = 0;
	int i = 0;
	while(r < x){
		r += i++;
	}
	cout<<i - 1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()

int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}

signed main(){
  int n,m;
  cin>>n>>m;
  V<P<int,int>> a(m);
  fo(i,m){
    cin>>a[i].fi>>a[i].se;
  }

  Sort(a);

  if(n==1&&m==0){
    cout<<0<<endl;
    return 0;
  }
  if(n==2&&m==0){
      cout<<10<<endl;
      return 0;
  }
  if(n==3&&m==0){
      cout<<100<<endl;
      return 0;
  }
  if(n==1){
    int d=1;
    fo(i,m){
      if(a[i].fi==1&&a[i].se==0)
        d=d;
      else
        d=0;
    }
    if(d){
      cout<<0<<endl;
      return 0;
    }

  }
  for(int i=1; i<=999; i++){
    if(keta(i)!=n)
      continue;
    string f=to_string(i);
    int c=1;
    fo(k,m){
      if(f[a[k].fi-1]-'0'!=a[k].se){
        c=0;
      }

    }
    if(c){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long long a[2010], c[2010], min[2010]={0}, P=0, r=0, t[2010][2010]={{0}}, x;

int llintcmp(const void *a, const void *b) {
	long long c = *(long long *)a-*(long long *)b;
	if (c>0) return 1;
	else if (c==0) return 0;
	else return -1;
}

int main() {
	int b, i, j, k, N;
	scanf("%d%lld", &N, &x);
	for (i=0;i<N;i++) scanf("%lld", &a[i]);

	c[0] = 0;
	for (i=0;i<N;i++) min[i] = a[i];
	for (i=0;i<N;i++) c[0] += a[i];
	for (k=1;k<N;k++) {
		c[k] = x*k;
		for (i=0;i<N;i++) {
			if (i>=k) b = i-k; else b = N+i-k;
			if (min[i] > a[b]) min[i] = a[b];
		}
		for (i=0;i<N;i++) c[k] += min[i];
	}
	qsort(c, N, sizeof(long long), llintcmp);

	printf("%lld\n", c[0]);
	return 0;
}


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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int BITS = 18;

int main() {
    int N, K, S, T;
    cin >> N >> K >> S >> T;

    if ((S | T) != T) {
        cout << 0 << '\n';
        return 0;
    }

    vector<int> A;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;

        if ((a & S) != S || (a | T) != T)
            continue;

        A.push_back(a);
    }

    N = int(A.size());
    K = min(K, N);

    vector<vector<int64_t>> choose(N + 1, vector<int64_t>(N + 1, 0));

    for (int i = 1; i <= N; i++) {
        choose[i][0] = choose[i][i] = 1;

        for (int j = 1; j < i; j++)
            choose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1];
    }

    vector<int64_t> up_to_K(N + 1, 0);

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= K; j++)
            up_to_K[i] += choose[i][j];

    vector<int> freq(1 << BITS, 0);
    int64_t answer = 0;
    int overall = S ^ T;

    for (int mask = overall; ; mask = (mask - 1) & overall) {
        for (int &a : A)
            freq[a & mask]++;

        int64_t sum = 0;

        for (int &a : A) {
            sum += up_to_K[freq[a & mask]];
            freq[a & mask] = 0;
        }

        answer += (__builtin_popcount(mask) % 2 == 0 ? +1 : -1) * sum;

        if (mask == 0)
            break;
    }

    cout << answer << '\n';
}


Measured memory_bytes: 4332
while 1:
    n = int(input())
    if n == 0:
        break
    f = list(map(str,input().split()))
    cnt = 0
    for i in range(n-1):
        if f[i] == "lu" and f[i+1] == "ru":
            cnt += 1
        elif f[i] == "ru" and f[i+1] == "lu":
            cnt += 1
        elif f[i] == "ld" and f[i+1] == "rd":
            cnt += 1
        elif f[i] == "rd" and f[i+1] == "ld":
            cnt += 1
    print(cnt)



Measured memory_bytes: 5608
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	double x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	cout << fixed << setprecision(8) << sqrt(pow(x2 - x1, 2.0) + pow(y2 - y1, 2.0)) << endl;

	return 0;
}


Measured memory_bytes: 3276
import math

def main():
    while True:
        a, d, n = map(int, input().split())
        if a == 0: break

        print(showprime(a, d, n))

    return

def showprime(a, d, n):
    i = 0
    while True:
        i += isprime(a)
        if i == n: return a
        a += d

def isprime(num):
    if num == 0 or num == 1: return 0
    sq_num = int(math.sqrt(num))

    for i in range(2, sq_num + 1):
        if num % i == 0: return 0

    return 1
main()



Measured memory_bytes: 5668
n = int(input())
l = list(map(int,input().split()))
height_stool = 0

temp = [i for i in l]
for i in range(n-1):
    if l[i] > l[i+1]:
        diff = l[i]-l[i+1]
        height_stool += diff
        l[i+1] += diff
print(height_stool)


Measured memory_bytes: 32388
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void a(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE) {
      a(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}
void dfs(){
  int u;
  for(u=0;u<n;u++) color[u]=WHITE;
  tt=0;

  for(u=0;u<n;u++){
    if(color[u]==WHITE)a(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
  for(j=0;j<k;j++){
    scanf("%d",&v);
    v--;
    M[u][v]=1;
  }
}
dfs();
return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

i64 gcd(i64 a, i64 b) {
  if(b == 0) return a;
  else return gcd(b, a % b);
}

i64 lcm(i64 a, i64 b) {
  return a / gcd(a, b) * b;
}

int main() {
  i64 A, B, C, D;
  cin >> A >> B >> C >> D;
  A--;
  cout << (B - A) - (B / C + B / D - B / lcm(C, D)) + (A / C + A / D - A / lcm(C, D)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int m,d,r=0;
  cin>>m>>d;
  for(int k=1;k<=m;++k)for(int i=22;i<=d;++i)if(i%10*(i/10)==k&&i%10>=2&&i/10>=2)r++;
  cout<<r;
}

Measured memory_bytes: 256
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

x = int(input())
a=list(map(int, primes(100003)))
for i in a:
    if x <= i:
        print(i)
        break

Measured memory_bytes: 40816
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9 +7;
signed main(){
   int n,q,l,r;
   cin>>n>>q;
   string s;
   cin>>s;
   int k[n+1]={},t[n+1]={},y=0;
   k[0]=0;t[0]=0;
   for(int i=1;i<n;i++){
       k[i]=y;
       if(s[i-1]=='A'&&s[i]=='C'){
           y++;
           t[i]=1;
       }
   }
    k[n]=y;
    for(int i=0;i<q;i++){
        cin >>l>>r;
        cout<<k[r]-k[l-1]-t[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    string s;
    cin >> s;

    int res1 = 0, res2 = 0;
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            if(s[i] == '1'){
                res1++;
            }
        }else{
            if(s[i] == '0'){
                res1++;
            }
        }
    }
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            if(s[i] == '0'){
                res2++;
            }
        }else{
            if(s[i] == '1'){
                res2++;
            }
        }
    }

    cout << min(res1, res2) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
#define MAXN 810
#define MAXM 640010
#define INF 1000000000
#define PII pair<int,int>
char s[MAXN][MAXN];
int n,m,K,sx,sy,ans=INF;
int dis[MAXN][MAXN];
int d[]={1,0,-1,0,1};
queue<PII>Q;
void BFS()
{
	int l=0,r=0;
	dis[sx][sy]=K+1;
	Q.push(PII(sx,sy));
	while(!Q.empty())
	{
		PII p=Q.front();Q.pop();
		int nx=p.first,ny=p.second;
		ans=min(ans,min(nx-1,min(ny-1,min(n-nx,m-ny))));
		if(dis[nx][ny]==1) continue;
		for(int i=0;i<4;i++)
		{
			int px=nx+d[i],py=ny+d[i+1];
			if(px==0||py==0||px>n||py>m||s[px][py]=='#'||dis[px][py]!=0) continue;
			dis[px][py]=dis[nx][ny]-1;
			Q.push(PII(px,py));
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++)
			if(s[i][j]=='S')
				sx=i,sy=j;
	}
	if(sx==1||sx==n||sy==1||sy==m)
	{
		printf("0\n");
		return 0;
	}
	BFS();
	ans=(ans+K-1)/K+1;
	printf("%d\n",ans);
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define rep(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) static_cast<int>(x.size())
#define mp make_pair
#define fi first
#define se second

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod(ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T> inline void remin(T& x, const T& y) { x = min(x, y); }
template<typename T> inline void remax(T& x, const T& y) { x = max(x, y); }

template<typename T> ostream& operator<<(ostream &os, const vector<T>& v) {
    os << "{"; string sep; for(const auto& x : v) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename T, size_t size> ostream& operator<<(ostream& os, const array<T, size>& arr) {
    os << "{"; string sep; for(const auto& x : arr) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { 
    return os << '(' << p.first << ", " << p.second << ')'; 
}


int main() {
    buff();
    int h, w;
    cin >> h >> w;
    map<int, int> mapa;
    multiset<int> set;
    for(int i = 0; i < w; ++i) mapa[i] = 0, set.insert(0);
    for(int i = 0; i < h; ++i) {
        int l, r; cin >> l >> r;
        --l;
        // semi-open intervals
        while(1) {
            auto it = mapa.lower_bound(l);
            if(it == mapa.end() || it->first >= r) break;
            int p = it->first;
            int val = it->second;
            mapa.erase(it);
            set.erase(set.find(val));
            if(r < w) {
                int nt = val + (r - p);
                if(!mapa.count(r)) {
                    set.insert(nt);
                    mapa[r] = nt;
                }
                else if (mapa[r] > nt) {
                    set.erase(set.find(mapa[r]));
                    set.insert(nt);
                    mapa[r] = nt;
                }
            }
        }
        if(set.empty()) cout << -1 << '\n';
        else cout << i + 1 + *set.begin() << '\n';
    }
    return 0;
}



Measured memory_bytes: 22384
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int main(){
    long long s;
    cin >> s;
    //double t = (double) s / 2;
    ll a, b;
    a=1e9;
    b=(s+a-1)/a;
    ll c=s%a;
    //s=a*b+c
    if(s<=1e9){
        cout<<0<<" "<<0<<" "<<1<<" "<<0<<" "<<0<<" "<<s<<endl;
    }
    else
    cout<<0<<" "<<0<<" "<<a<<" "<<1<<" "<<b*a-s<<" "<<b<<endl;

return 0;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

fn f(mut x: i64) -> BTreeMap<i64, i64> {
    let mut ms = BTreeMap::new();
    let r = (x as f64).sqrt() as i64 + 1;

    for p in 2..r as i64 {
        let mut m = 0;

        while x >= p && x % p == 0 {
            x /= p;
            m += 1;
        }

        if m > 0 {
            ms.insert(p, m);
        }
    }

    if x > 1 {
        ms.insert(x, 1);
    }

    ms
}

fn main() {
    let (A, B) = read!(i64, i64);
    println!("{}", f(gcd(A, B)).len() + 1)
}


Measured memory_bytes: 4352
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e9+7;


int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=0;
    rep(i,n){
        if(s[i]=='R') ans++;
        else ans--;
    }
    if(ans>0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3536
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    long long n;
    cin >> n;

    long long res = (1LL << 48);
    for (long long i = 1; i <= n / i; i++) {
        if (n % i == 0) {
            res = min(res, i - 1 + n / i - 1);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	int N, K; cin >> N >> K;
	vector<int> A(N);
	rep(i, 0, N) {
		int tmp; cin >> tmp;
		A[tmp - 1]++;
	}
	sort(A.begin(), A.end());

	int ans = 0;
	rep(i, 0, N - K)ans += A[i];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    char n;
    for(int i = 0; i<3;i++){
        scanf("%c", &n);
        if(n == '9'){
            printf("1");
        } else if (n == '1') {
            printf("9");
        } else {
            printf("%c", n);
        }
    }
    return 0;
}


Measured memory_bytes: 128
open System.IO
open System

let n = stdin.ReadLine() |> int
let aArray =[| 
    yield 0
    yield! (stdin.ReadLine().Split() |> Array.map int)|]

let bArray = Array.zeroCreate<int> (n+1)

let multipulesWithoutOwn m = 
    seq{for i in m*2..m.. n -> i} |> Seq.map (fun i ->bArray.[i]) |> List.ofSeq

let f i =
    let result = 
        aArray.[i] ^^^ 
            match multipulesWithoutOwn i with
            | [] ->  0
            | [x] -> x 
            | x -> x |> List.reduce (fun total y -> total ^^^ y) 
    bArray.[i] <- result

do [n.. -1 ..1] |> List.iter f

let ans =
    bArray |> Array.mapi (fun i x -> (i,x)) |> Array.filter (fun (i,x) -> x = 1)

//出力
let sw = new StreamWriter(Console.OpenStandardOutput())
sw.AutoFlush <- false
Console.SetOut(sw)

ans.Length |> stdout.WriteLine
ans |> Array.iter (fun (i,_) -> stdout.WriteLine(string i + " "))

stdout.Flush()

Measured memory_bytes: 48292
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool num = true;
    for(int i = 0; i < a + b; i++){
        if(i != a) num &= (s[i] >= '0' && s[i] <= '9');
        else num &= (s[i] == '-');
    }
    if(num){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

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

const ll mod = 1000000007;
void add(ll &a, ll b) {
    a = (a + b) % mod;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<map<string, ll>> dp(n + 1);
    dp[0]["***"] = 1;
    string s = "AGCT";
    REP (i, 0, n) {
        for (auto a : dp[i]) {
            string ss = a.first;
            if (ss == "AGC" || ss == "ACG" || ss == "GAC") {
                continue;
            }
            REP (j, 0, 4) {
                string nxt = ss + s[j];
                if ((nxt[0] == 'A' && nxt.substr(2) == "GC") || (nxt.substr(0, 2) == "AG" && nxt[3] == 'C')) {
                    continue;
                }
                nxt = nxt.substr(1);
                if (nxt == "AGC" || nxt == "ACG" || nxt == "GAC") {
                    continue;
                }
                add(dp[i + 1][nxt], a.second);
            }
        }
    }

    ll ans = 0;
    for (auto &a : dp[n]) {
        add(ans, a.second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap};

// Main
fn main(){
    input!{
        n: usize,
        t: i32,
        ct: [(i32,i32); n]
    }
    let mut ans = 9999;
    for i in 0..n{
        if ct[i].1 <= t{
            ans = min(ans, ct[i].0);
        }
    }
    if ans==9999{
        println!("{}", "TLE");
    }else{
        println!("{}", ans);
    }
}



Measured memory_bytes: 4352
#include <stdio.h>

int n, A[20];

int saiki( int i, int m )
{ 
   if ( m == 0 )
      return 1;
   if ( i >= n )
      return 0;
   int res = saiki( i + 1, m ) || saiki( i + 1, m - A[ i ] );
   return res;
}

int main()
{
   int q, M, i;

   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) {
      scanf("%d", &A[ i ]);
   }
   scanf("%d", &q);
   for ( i = 0; i < q; i++ ) {
      scanf("%d", &M);
      if ( saiki(0,M) ) {
         printf("yes\n");
      }
      else {
         printf("no\n");
      }
   }
   return 0;
}

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

using namespace std;

map<int,int> m;
int n;
int arr[100005];

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		m[arr[i]]++;
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(m[arr[i]]==-1) continue;
		if(m[arr[i]]<arr[i]) ans+=m[arr[i]];
		else ans+=m[arr[i]]-arr[i];
		m[arr[i]]=-1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void warshallFloyd(vector<vector<int> >& dist)
{
    int n = dist.size();
    for(int k=0; k<n; ++k){
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main()
{
    int h, w;
    cin >> h >> w;

    vector<vector<int> > c(10, vector<int>(10));
    for(int i=0; i<10; ++i){
        for(int j=0; j<10; ++j){
            cin >> c[i][j];
        }
    }
    warshallFloyd(c);

    int ans = 0;
    for(int i=0; i<h*w; ++i){
        int a;
        cin >> a;
        if(a != -1)
            ans += c[a][1];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int main()
{
	long long int N, W;
	cin >> N >> W;
	
	vector<P> v1, v2;
	P p;
	p.first = 0;
	p.second = 0;
	v1.push_back(p);
	v2.push_back(p);
	
	for(int i = 0; i < N / 2; i++){
		long long int v, w;
		cin >> v >> w;
		int sz = v1.size();
		for(int j = 0; j < sz; j++){
			p = v1[j];
			p.first += w;
			p.second += v;
			v1.push_back(p);
		}
	}
	
	for(int i = 0; i < (N + 1) / 2; i++){
		long long int v, w;
		cin >> v >> w;
		int sz = v2.size();
		for(int j = 0; j < sz; j++){
			p = v2[j];
			p.first += w;
			p.second += v;
			v2.push_back(p);
		}
	}
	
	p.first = INF;
	p.second = 0;
	
	v2.push_back(p);
	
	long long int ans = 0;
	int id = 0;
	
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	
	long long int vmax = 0;
	for(int i = v1.size() - 1; i >= 0; i--){
		if(v1[i].first > W){
			continue;
		}
		while(true){
			vmax = max(vmax, v2[id].second);
			if(v1[i].first + v2[id + 1].first > W){
				break;
			}
			id++;
		}
		ans = max(ans, v1[i].second + vmax);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 52208
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N, M;
int K[100001];
int to[200001], ne[200001], he[100001], num[200001];
vector<int> S1[100001], S2[100001];
int dame[100001];

int dfs(int v, int prev) {
	if (dame[v]) {
		if (dame[v] >= 2) {
			ll tmp = dfs(to[dame[v]], dame[v] ^ 1);
			int k = K[v] - num[dame[v]];
			for (int i = k - 1; i < K[v]; i++) {
				S1[v][i] = S1[v][i] * tmp % M;
			}
			S2[v][k - 1] = tmp;
			for (int i = K[v] - 2; i >= 0; i--) {
				S2[v][i] = ((ll)S2[v][i] * S2[v][i + 1]) % M;
			}
			dame[v] = -1;
		}

		ll ret = 1;
		if (prev >= 2) {
			int k = K[v] - num[prev];
			if (k >= 2) ret *= S1[v][k - 2];
			if (k < K[v]) ret *= S2[v][k];
			ret %= M;
		}
		else ret = S1[v].back();

		return ret + 1;
	}
	dame[v] = prev;
	ll ret = 1;
	int k = 0;
	for (int i = he[v]; i; i = ne[i]) {
		int tmp = 1;
		if (i != prev) {
			tmp = dfs(to[i], i ^ 1);
			ret = ret * tmp % M;
		}
		S1[v][k] = ret;
		S2[v][k++] = tmp;
	}
	if (prev == -1) {
		for (int i = k - 2; i >= 0; i--) {
			S2[v][i] = ((ll)S2[v][i] * S2[v][i + 1]) % M;
		}
	}
	return ret + 1;
}

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


	cin >> N >> M;

	int k = 2;
	rep1(i, N - 1) {
		int x, y;
		cin >> x >> y;

		num[k] = K[x]++;
		to[k] = y;
		ne[k] = he[x];
		he[x] = k++;
		num[k] = K[y]++;
		to[k] = x;
		ne[k] = he[y];
		he[y] = k++;
	}
	rep1(i, N) {
		S1[i].resize(K[i]);
		S2[i].resize(K[i]);
	}

	rep1(j, N) {
		co(dfs(j, -1) - 1);
	}


	Would you please return 0;
}

Measured memory_bytes: 21248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll f(ll n, ll m) {
	return (n * n) % m;
}
int main() {
	ll N, X, M; cin >> N >> X >> M;
	ll A, preA, ans = 0;
	ll loopcnt = 0, cnt = 0, sum_loop = 0, rec_A;
	bool visit[100001];
	bool dub = false;
	for(int i = 1; i <= N; i++) {
		if(i == 1) {
			A = X;
			ans += A;
			visit[A] = true;
			cnt++;
			continue;
		}
		preA = A;
		A = f(A, M);
		if(dub) {
			if(A == rec_A) break;
			ans += A; sum_loop += A; loopcnt++; cnt++;
		}
		else {
			if(visit[A]) {
				dub = true; rec_A = A; sum_loop += A; loopcnt++;
			}
			ans += A;
			cnt++;
			visit[A] = true;
		}
	}
	A = preA;
	if(dub) {
		ans += sum_loop * ((N - cnt) / loopcnt);
		ll rem = (N - cnt) % loopcnt;
		for(int i = 0; i < rem; i++) {
			A = f(A, M);
			ans += A;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
void ABC135A()
{
	int A, B;
	cin >> A >> B;
	if ((A + B) % 2 != 0)
	{
		cout << "IMPOSSIBLE" << endl;
		return;
	}
	int c = (A + B) / 2;
	cout << c << endl;
}



int main()
{
	ABC135A();
	return 0;
}

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

l = [0]*100001

for i in a:
  l[i] += 1

for i in range(len(l)-2):
  ans = max(ans,l[i]+l[i+1]+l[i+2])
  
print(ans)
  

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

#define SZ(x) (((int)x.size()))

typedef long long ll;
typedef long double ld;

using namespace std;

int a;
string s;

int main()
{
	cin >> a >> s;
	if (a >= 3200)
		cout << s;
	else
		cout << "red";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long h[100005];
long long dp[100005];

long long solve(int i){
	if(i >= n-1) return 0;
	if(dp[i] != -1) return dp[i];

	dp[i] = 1e17;
	for(int j = 1; j <= k; ++j)
		if(i+j <= n-1)
			dp[i] = min(dp[i], abs(h[i] - h[i+j]) + solve(i+j));
	return dp[i];
}

int main(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i)
		scanf("%lld", &h[i]);
	memset(dp, -1, sizeof dp);
	cout<<solve(0)<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define pb(v) push_back(v)
#define all(s) s.begin(),s.end()
ll MOD=1e9+7;

int main() {
	//code
	
     ios_base::sync_with_stdio(false); 
     cin.tie(NULL);
     
	   int n,s;
	   cin>>n>>s;
	   int ans=0;
	   f(i,0,n+1)
	   {
	   	   f(j,0,n+1)
	   	   {
	   	       int z=s-i-j;
				  if(z>=0 && z<=n)
				  ans++;	   
		   }
	   }
	   cout<<ans<<endl;
    
          return 0;

}



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

int main(void){
    int a,b;
    cin >> a >> b;

    if(a>b) cout << 2*a-1 << endl;
    else if(a<b) cout << 2*b-1 << endl;
    else cout << 2*a << endl;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define eb emplace_back
#define pb pop_back
using namespace std;
typedef long long ll;
const int N = 52;
ll n,m,q;
ll a[N],b[N],c[N],d[N];
ll rec(vector<ll> ls, ll nw){
	if(ls.size() == n){
		ll ret = 0;
		for(ll i=0;i<q;i++){
			if(ls[b[i]-1]-ls[a[i]-1] == c[i]) ret += d[i];
		}
		return ret;
	}
	ll ret = 0;
	for(int i=nw;i<=m;i++){
		vector<ll> lss = ls;
		lss.eb(i);
		ret = max(ret,rec(lss,i));
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> m >> q;
	for(ll i=0;i<q;i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
	vector<ll> t = {};
	cout << rec(t,1) << '\n';
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() {
  int A;
  int B;
  string isPossible = "Possible";
  cin >> A >> B;
  if(A%3 != 0){
    if(B%3 != 0){
      if((A+B)%3 != 0){
        isPossible = "Impossible";
      }
    }
  }
  cout << isPossible << endl;
}

Measured memory_bytes: 256