akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// #define pair pair<ll,ll> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


const ll mod =1e9+7;



int main(){

	ll n;
    cin>>n;
    pair<ll,ll> p[n];
    for(ll i=0;i<n;i++){
        cin>>p[i].first>>p[i].second;
    }

    ll x=p[0].first,y=p[0].second;
    // cout<<x<<" "<<y<<endl;
    for(ll i=1;i<n;i++){
        ll a=p[i].first;
        ll b=p[i].second;
        ll c=a*y-b*x;
        for(ll l=max(x/a,y/b);;l++){
            ll X=l*a-x;
            ll Y=l*b-y;
            if(X>=0 && Y>=0){
                x=a*l;
                y=b*l;
                // cout<<x<<" "<<y<<endl;
                break;
            }
        }
        
    }
    cout<<x+y<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define Max 1000

int main() {
    vector<int> v[Max];
    int q, n;
    cin >> n >> q;
    int num, qst, x;
    for (int i = 0; i < q; i++) {
        cin >> qst >> num;
        if (qst == 0) {
            cin >> x;
            v[num].push_back(x);
        } else if (qst == 1) {
            for (int i = 0; i < v[num].size(); i++) {
                if (i) cout << " ";
                cout << v[num][i];
            }
            cout << endl;
        } else {
            v[num].clear();
        }
    }
    return 0;
}



Measured memory_bytes: 5824
#include<stdio.h>
 
int main(){
  int A,B,C,K,i,sum=0,tmp;
  
  scanf("%d%d%d%d",&A,&B,&C,&K);
  if((K-A) >= 0){
  	sum = 1*A;
    K -= A;
    if((K-B) >= 0){
    	K -= B;
      for(i=0; i<K; i++){
      	sum--;
      }
    }
  }
  else{
  	sum = K;
  }
  printf("%d", sum);
	return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>

int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    long long ans=0;
    for(int i=1;i<n;i++){
        int tmp2=a[i],tmp1=a[i-1];
        if(a[i-1]+a[i]>x){
            if(a[i]<(a[i-1]+a[i]-x)){
                a[i]=0;
            }else{
                a[i]-=(a[i-1]+a[i]-x);
            }
            ans+=(tmp1+tmp2-x);
            }
    }
    printf("%lld",ans);
    return 0;
}


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

using namespace std;

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

    int N;
    cin >> N;

    int x[N], y[N], h[N];
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> h[i];
    }

    for (int X = 0; X <= 100; ++X) {
        bool pass = true;
        for (int Y = 0; Y <= 100; ++Y) {
            int H = 0;
            for (int i = 0; i < N; ++i) {
                if (h[i]) {
                    H = abs(X - x[i]) + abs(Y - y[i]) + h[i];
                    break;
                }
            }
            for (int i = 0; i < N; ++i) {
                if (h[i] == 0) {
                    pass &= H - abs(X - x[i]) - abs(Y - y[i]) <= 0;
                } else {
                    pass &= h[i] == H - abs(X - x[i]) - abs(Y - y[i]);
                }
              	if (!pass) break;
            }
            if (pass) {
                printf("%d %d %d", X, Y, H);
                return 0;
            }
            pass = true;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
# mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m = readInts()
Uni = UnionFind(n)
for i in range(m):
    a,b = map(lambda x:int(x)-1, input().split())
    Uni.union(a,b)
print(Uni.group_count()-1)


Measured memory_bytes: 14180
alphabet = 'abcdefghijklmnopqrstuvwxyz'
def convert(num):
    i, n = 1, 26
    while n < num:
        num -= n
        n *= 26
        i += 1
    num -= 1
    
    res = ''
    while num >= 26:
        res = alphabet[num % 26] + res
        num //= 26
    return '{:{fill}{align}{width}}'.format(alphabet[num % 26] + res, fill='a', align='>', width=i)

print(convert(int(input())))

Measured memory_bytes: 9012
"""
l1,l2,...,lN
N は max8本
A,B,Cの3本の竹にしたい

延長 : 1MP  +1
短縮 : 1MP  -1
合成 : 10MP li + lj
A, B, Cを達成するための最小MP
"""


N,A,B,C = map(int, input().split())
ls = [int(input()) for i in range(N)]

import sys
sys.setrecursionlimit(100000)
"""
Gを作りながら探索するパターン
"""

minMP = 10**9 + 7
def dfs(i,MP,a,b,c):
    global minMP
    # 探索打ち切り条件->計算してしまう
    if i+1  >= N:
        if a>0 and b>0 and c>0:
            cnt = MP + abs(A-a)+abs(B-b)+abs(C-c) - 30 
            minMP = min(cnt,minMP)
        return 0
    l = ls[i+1]
    # 再帰的に探索
    dfs(i+1,MP,a,b,c)   # なんもしない
    dfs(i+1,MP+10,a+l,b,c) # aに
    dfs(i+1,MP+10,a,b+l,c) # bに
    dfs(i+1,MP+10,a,b,c+l) # cに

dfs(-1,0,0,0,0)
print(minMP)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

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

    int x[N];
    int dis = 0;
    for (int i = 0; i < N; i++){
        cin >> x[i];
        int L = x[i];
        int R = K - x[i];
        dis += min(L,R) * 2;
    }
    cout << dis << endl;
}

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;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 1e9;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, s;
  cin >> n >> k >> s;
  vector<int> ans(n, MAX);
  if (s == MAX) {
    rep(i, n)
      ans[i]--;
  }
  rep(i, k) ans[i] = s;
  rep(i, n) {
    if (i) cout << ' ';
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        // write your code
        int n = sc.nextInt();
        long[] as = new long[n];

        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        // dp[n][c][b] := i個目まで見て、2連続で使わないことがc回あり、直前の数を使和ない: b = 0, 使ったb = 1 時の最大値
        long[][][] dp = new long[n + 1][3][2];
        for (long[][] a : dp) for (long[] b : a) Arrays.fill(b, -(1L << 60));
        dp[1][1][0] = 0;
        dp[1][0][1] = as[0];
        for (int i = 1; i < n; i++) {
            dp[i + 1][0][0] = dp[i][0][1];
            dp[i + 1][0][1] = dp[i][0][0] + as[i];
            dp[i + 1][1][0] = Math.max(dp[i][0][0], dp[i][1][1]);
            dp[i + 1][1][1] = dp[i][1][0] + as[i];
            dp[i + 1][2][0] = Math.max(dp[i][1][0], dp[i][2][1]);
            dp[i + 1][2][1] = dp[i][2][0] + as[i];
//            debug(dp[i + 1]);
        }

        long ans = -(1L << 50);
        if (n % 2 == 0) {
            ans = Math.max(dp[n][0][0], dp[n][1][1]);
        } else {
            ans = Math.max(dp[n][2][1], dp[n][1][0]);
//            ans = Math.max(dp[n][1][0], ans);
        }
        out.println(ans);

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 84128
#include <cstdio>

int main()
{
	while(true) {

		int n, a[100];
		int mask[10];
		mask[0] = 1+2+4+8+16+32   ;
		mask[1] =   2+4           ;
		mask[2] = 1+2+  8+16+   64;
		mask[3] = 1+2+4+8+      64;
		mask[4] =   2+4+     32+64;
		mask[5] = 1+  4+8+   32+64;
		mask[6] = 1+  4+8+16+32+64;
		mask[7] = 1+2+4+     32   ;
		mask[8] = 1+2+4+8+16+32+64;
		mask[9] = 1+2+4+8+   32+64;

		scanf("%d", &n);
		if(n == -1)
			break;
		for(int i = 0; i < n; ++i) {
			scanf("%d", a + i);
		}

		int state = 0;
		
		for(int i = 0; i < n; ++i) {

			int sig = state ^ mask[a[i]];
			for(int bit = 6; bit >= 0; --bit)
				printf("%c", sig & (1 << bit) ? '1' : '0');
			printf("\n");
			state = mask[a[i]];
			
		}

	}

	return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> coin(h, vector<int>(w));
    rep(i, h) rep(j, w) cin >> coin[i][j];

    vector<pair<int, int>> start, end;
    rep(i, h) {
        if (i % 2 == 0) {
            rep(j, w) {
                if (coin[i][j] % 2) {
                    if (j == w - 1) {
                        if (i != h - 1) {
                            start.push_back({i, j});
                            end.push_back({i + 1, j});
                            --coin[i][j];
                            ++coin[i + 1][j];
                        }
                    } else {
                        start.push_back({i, j});
                        end.push_back({i, j + 1});
                        --coin[i][j];
                        ++coin[i][j + 1];
                    }
                }
            }
        } else {
            for (int j = w - 1; j >= 0; --j) {
                if (coin[i][j] % 2) {
                    if (j == 0) {
                        if (i != h - 1) {
                            start.push_back({i, j});
                            end.push_back({i + 1, j});
                            --coin[i][j];
                            ++coin[i + 1][j];
                        }
                    } else {
                        start.push_back({i, j});
                        end.push_back({i, j - 1});
                        --coin[i][j];
                        ++coin[i][j - 1];
                    }
                }
            }
        }
    }

    cout << start.size() << endl;
    rep(i, start.size()) {
        cout << start[i].first + 1 << " " << start[i].second + 1 << " "
             << end[i].first + 1 << " " << end[i].second + 1 << "\n";
    }

    return 0;
}

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

const int maxn = 3e5+5, M = 1e9+7;;
int n;
ll a[maxn];

ll modexp(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b&1LL) res = (res*a) % M;
        a = (a*a) % M;
        b >>= 1;
    }
    return res;
}

int cnt[65][2];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j < 60; j++) {
            bool o = a[i] & (1LL<<j);
            ans += (modexp(2,j)*cnt[j][o^1]) % M;
            ans %= M;
        }

        for (int j = 0; j < 60; j++) {
            bool o = a[i] & (1LL<<j);
            cnt[j][o]++;
        }
    }
    ans %= M;
    cout << ans << '\n';
}



Measured memory_bytes: 2560
a = int(input())
b = int(input())

if a == 1 and b == 2:
    print('3')
elif a == 2 and b == 1:
    print('3')
elif a == 3 and b == 1:
    print('2')
elif a == 1 and b == 3:
    print('2')
elif a == 3 and b == 2:
    print('1')
elif a == 2 and b == 3:
    print('1')


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

int main() {
int n,m,k;
cin>>n>>m>>k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			int black=(m-j)*i+(n-i)*j;
			if(k==black){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[4],b[4],hi,bl;
	while(!(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]),scanf("%d%d%d%d",&b[0],&b[1],&b[2],&b[3])==EOF)){
		hi=0;
		bl=0;
		for(int i=0;i<4;i++){
			if(a[i]==b[i]){
				hi++;
			}else if(a[i]==b[0]||a[i]==b[1]||a[i]==b[2]||a[i]==b[3]){
				bl++;
			}
		}
		printf("%d %d\n",hi,bl);
	}
	return 0;
}

Measured memory_bytes: 2680
/*
https://atcoder.jp/contests/dp/tasks/dp_a
*/
#include<bits/stdc++.h>
using namespace std;

int main(){

    int n,k;  cin>>n>>k;
    int height[n];
    int dp[n];

    for(int i=0;i<n;i++){
        cin>>height[i];
        dp[i] = INT_MAX;
    }

    dp[0] = 0;
   // cout<<0<<" ";
    for(int i=1;i<=k && i<n;i++){
        dp[i] = abs(height[i]-height[0]);
   //     cout<<dp[i]<<" ";
    }

    for(int i=k+1;i<n;i++){
        for(int j=i-1;j>=i-k && j>=0;j--){
            dp[i] = min(dp[i], (abs(height[i]-height[j])+dp[j]));
        }
      //  cout<<dp[i]<<" ";
    }
  //  cout<<endl;

    cout<<dp[n-1]<<"\n";

return 0;
}


Measured memory_bytes: 1024
N,K=map(int,input().split())
S={}
for i in range(N):
  a,b=map(int,input().split())
  if a in S:
    S[a]+=b
  else:
    S[a]=b
T=sorted(S.items())
count=0
for i in range(len(T)):
  count+=T[i][1]
  if count>=K:
    print(T[i][0])
    break

Measured memory_bytes: 14564
//http://lightoj.com/volume_showproblem.php?problem=1068

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define LL              long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

const LL MOD=1e9+7;
int k;
string str;
LL dp[10005][105][2];

LL call(int pos,int isSmall,int rem)
{
    if(pos==str.size()) {
        if(rem==0) return 1;
        else return 0;
    }
    if(dp[pos][rem][isSmall]!=-1) return dp[pos][rem][isSmall];
    int last=9;
    if(!isSmall) last=str[pos]-'0';
    LL ret=0;
    for(int i=0;i<last;i++) ret=(ret+call(pos+1,1,(rem+i)%k))%MOD;
    if(!isSmall) ret=(ret+call(pos+1,0,(rem+last)%k))%MOD;
    else ret=(ret+call(pos+1,1,(rem+last)%k))%MOD;
    return dp[pos][rem][isSmall]=ret;
}

int main()
{
    Fast
    cin >> str >> k;
    MEM(dp,-1);
    cout << (call(0,0,0)-1+MOD)%MOD;
}


Measured memory_bytes: 17664
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var input2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine((input1[0] - input2[0]) * (input1[1] - input2[1]));
        }
    }
}


Measured memory_bytes: 13268
#include <cstdio>
using namespace std;
int n;
double arr[3005],k;
void print(){
    for (int y=0;y<4;y++){
        printf("%.12f ",arr[y]);
    }
    printf("\n");
}
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d",&n);
    arr[0]=1;
    for (int x=1;x<3005;x++) arr[x]=0;
    for (int x=0;x<n;x++){
        scanf("%lf",&k);
        for (int y=3003;y>0;y--){
            arr[y]=arr[y]*(1-k)+arr[y-1]*k;
        }
        arr[0]*=1-k;
    }
    double ans=0;
    for (int x=(n+1)>>1;x<=n;x++){
        ans+=arr[x];
    }
    printf("%.12f\n",ans);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	}
}

Measured memory_bytes: 185012
#include<bits/stdc++.h>
using namespace std;
int n;
long long int a,b,num[102030],sum = 0,d;
bool ok(long long int x){
    long long int ans = 0;
    for(int i = 1; i <= n && num[i] > x * b; i++){
        long long int k = (num[i] - x * b - 1) / d + 1;
        ans += k;
    }
    if(ans <= x)
        return true;
    return false;
}
bool cmp(int a, int b){
    return a > b;
}
int main()
{
    cin>>n>>a>>b;
    d = a - b;
    for(int i = 1; i <= n ; i ++){
        scanf("%lld",&num[i]);
    }
    sort(num+1,num+1+n,cmp);
    long long int l = 1, r = num[1] / b + 1000;
    long long int ans;
    while(l <= r){
        int m = (l + r) >> 1;
        if(ok(m))
            r = m ,ans = r;
        else
            l = m + 1;

        if(l == r) break;
        
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int p[N],q[N];
  string P="";
  string Q="";
  for(int i=0;i<N;i++){
      cin >> p[i];
      P+=char(p[i]);
  }
  for(int i=0;i<N;i++){
      cin >> q[i];
      Q+=char(q[i]);
  }

  int X[N];
  int count=1000000;
  for(int i=0;i<N;i++)X[i]=i+1;
  while(true){
    count ++;
    string S = "";
    for(int i=0;i<N;i++) S+=char(X[i]);
    if (S==P||S==Q){
      if (count >= 1000000){
        count = 0;
        if (S==P&&S==Q) break;
      }else {
        break;
      }
    }
    next_permutation(X,X+N);
  }
  cout << count;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n)(for i=0;i<n;++i);
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  int x, y;
  cin >> x >> y;
  int ans = 0;
  for (int i = 0; i <= x; i++) {
    ans = i * 2 + (x - i) * 4;
    //cout << ans << endl;
    if (ans == y) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF (1e10+5)
#define F first
#define S second
#define pb push_back
#define MP make_pair
#define FRL(i,a,n) for(i=a;i<n;i++)
#define FR(i,n) FRL(i,0,n)
#define RFRL(i,n) for(i=n;i>=0;i--)
#define MOD 1000000007
#define fill(a) memset(dp,a,sizeof(dp));

using namespace std;

typedef long long int  ll;

typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector< pair<ll,ll> > vpi;
typedef set<ll> st;
typedef map<ll,ll> mp;
typedef unordered_map<ll,ll> ump;

template< class T>
T minn(T a,T b)
{
	return (a>b)?b:a;
}
template< class T>
T maxx(T a,T b)
{
	return (a>b)?a:b;
}


void FILE_OP()
{
	#ifndef ONLINE_JUDGE
        freopen("inputf.txt", "r", stdin);
        freopen("output2.txt", "w", stdout);
    #endif
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

/*ll frog(ll i,ll c)
{
	if(i>n)
		return 0;
	
	c=c+minn(frog(i+1,abs(v[i-1]-v[i])),frog(i+2,abs(v[i-2]-v[i])));
	return c;

}*/

/*ll findmax(ll i,ll val,ll maxv)
{
	if(val>maxv || i>n)
		return INF;
	
	//cout<<i<<"\n";
	if(dp[val]!=-1)
	{
	//	cout<<i<<"dp\n";
		return dp[val];
	}
	if(val+v[i]>maxv)
	{
	//	cout<<i<<"\n";
		return dp[val]=findmax(i+1,val,maxv);
	}
	//cout<<i<<"\n";
	return dp[val]=minn(findmax(i+1,val,maxv),Wi[i]+findmax(i+1,v[i]+val,maxv));
		
	
}*/


void SOLVE()
{

	
	ll tt,m,i,j,k,a,b,c,d,l,r;
	//cin>>tt;
	tt=1;
	//fill(-1)
	ll n,W;
    ll v[105],Wi[105];
    //ll dp[100010];
	while(tt--)
	{
		cin>>n>>W;
		ll maxv=0;
		for(i=1;i<=n;i++)
		{
			cin>>Wi[i]>>v[i];
			maxv+=v[i];
		}
		vi bp(maxv+2,INF);
		bp[0]=0;
		for(i=1;i<=n;i++)
		{
			for(j=maxv-v[i];j>=0;j--)
			{
				bp[j+v[i]]=minn(bp[j]+Wi[i],bp[j+v[i]]);
			}
		}
		
		for(i=maxv;i>=0;i--)
		{
			if(bp[i]<=W)
			{
				cout<<i<<"\n";
				break;
			}
		}
		
		
		
	}


		
}

int main()
{
	FAST_IO
	//FILE_OP();
	SOLVE();
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x.at(i); }


int main() {

    CIN(int, N);
    CINS(int, V, N);
    CINS(int, C, N);

    int sum = 0;

    for (int i = 0; i < N; i++) {
        if (V[i]>C[i]) {
            sum += (V[i]-C[i]);
        }
    }

    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import sys

x, n = map(int, input().split())
listdame = list(map(int, input().split()))

for i in range(100):
    if (x - i in listdame):
        pass
    else:
        print(x - i)
        sys.exit()

    if (x + i in listdame):
        pass
    else:
        print(x + i)
        sys.exit()


Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        
        int c = a - 1;
        
        int count = 0;
        if (b > 1) {
            count++;
        }
        
        while (a < b) {
            a += c;
            count++;
        }
        
        System.out.println(count);
    }
    
}


Measured memory_bytes: 21972
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import copy

x = ['Front', 'Right', 'Back', 'Left']
y = ['Top', 'Front', 'Bottom', 'Back']
z = ['Top', 'Left', 'Bottom', 'Right']


def turn(dice, direction):
    turned_dice = copy.deepcopy(dice)
    # x?????????
    if direction == 'Right':
        for i in range(4):
            turned_dice[x[i]] = dice[x[(i+1)%4]]
    if direction == 'Left':
        for i in range(4):
            turned_dice[x[i]] = dice[x[(i-1)%4]]

    # y?????????
    if direction == 'North':
        for i in range(4):
            turned_dice[y[i]] = dice[y[(i+1)%4]]
    if direction == 'South':
        for i in range(4):
            turned_dice[y[i]] = dice[y[(i-1)%4]]

    # z?????????
    if direction == 'East':
        for i in range(4):
            turned_dice[z[i]] = dice[z[(i+1)%4]]
    if direction == 'West':
        for i in range(4):
            turned_dice[z[i]] = dice[z[(i-1)%4]]

    return turned_dice

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        dice = {'Top': 1, 'Front': 2, 'Right': 3,
                'Left': 4, 'Back': 5, 'Bottom': 6}

        ret = 1
        for i in range(n):
            dice = turn(dice, input())
            ret += dice['Top']

        print(ret)

Measured memory_bytes: 7348
n = int(input())
x = input().split(" ")
t = int(x[0])
a = int(x[1])
h = list(map(int, input().split(" ")))

dif = []

for i in range(n):
    z = abs(t - h[i] * 0.006 - a)
    dif.append(z)

dif_s = sorted(dif)
# print(dif)
# print(dif_s)
# print(dif_s[n-1])
min = dif_s[0]
print(dif.index(min)+1)


Measured memory_bytes: 3060
import sys
h, w = map(int, sys.stdin.readline().split())
dp = [[0] * w for _ in range(h)]
G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]
for x in range(h):
    dp[x][0] = 1 if G[x][0] == 0 else 0
for y in range(w):
    dp[0][y] = 1 if G[0][y] == 0 else 0
for i in range(1, h):
    for j in range(1, w):
        if(G[i][j] == 0):
            dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
print(max(max(i) for i in dp) ** 2)

Measured memory_bytes: 57872
/*
AOL A0045
*/
#include <stdio.h>
#include <float.h>

main()
{
	long tanka,suuryo;
        long sum;
        long suusum;
        int  cnt;
	int  avesuuryo;

	sum=0;suusum=0;cnt=0;

	while(EOF != scanf("%ld,%ld",&tanka,&suuryo))
	{	
		/* printf("%ld,%ld\n",tanka,suuryo);*/
		suusum += suuryo;
		sum    += suuryo*tanka;
                cnt ++;
	}

	avesuuryo =(int)((double)suusum/cnt+0.5);
	printf("%ld\n",sum);
        printf("%d\n",avesuuryo);

	return(0);

}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str;
		String[] arrStr;
		try {
			// 1 line
			str = br.readLine();
			int[] arr = new int[Integer.parseInt(str)];

			// 2 line
			str = br.readLine();
			arrStr = str.split(" ");

			for(int i=0;i<arrStr.length;i++){
				arr[i] = Integer.parseInt(arrStr[i]);
			}

			int min = Integer.MAX_VALUE;
			int max = Integer.MIN_VALUE;
			long sum = 0;
			for(int num :arr){
				min = min > num ? num : min;
				max = max < num ? num : max;
				sum += num;
			}

			System.out.println(min + " " + max + " " + sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 25560
# ＤＦＳ, パターン列挙_竹'n'本の使用パターン

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

stack = [[0],[1],[2],[-1]] # 初期化_ここでは竹の使用パターン4つを設置
ptns = [] # パターン候補の器_初期化
 
while stack: # stackが空になるまでループ
    tmp = stack.pop() # パターンの候補を pop
    if len(tmp) == n: # 条件に合えば append
        ptns.append(tmp)
    elif len(tmp) < n: # 条件に合わなければ...
        w = tmp + [0] # パターンの候補を作成して...
        x = tmp + [1] # 〃
        y = tmp + [2] # 〃
        z = tmp + [-1]
        stack += [w, x, y, z]  # 積む

#print(ptns) # 竹の使用パターン

ans = 10**9
for i in range(len(ptns)):
    if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]:
        continue
    abc = [0, 0, 0, -30]
    for j in range(n):
        tmp = ptns[i][j]
        if tmp >= 0:
            abc[tmp] += l[j]
            abc[3] += 10
    mp = abc[3]
    mp += abs(abc[0] - a)
    mp += abs(abc[1] - b)
    mp += abs(abc[2] - c)
    ans = min(ans, mp)

print(ans)

'''
# パターン列挙と探索を並行して処理

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

stack = [[0],[1],[2],[-1]]

ans = 10**9
while stack:
    tmp = stack.pop()
    if len(tmp) == n:
        if 0 not in tmp or 1 not in tmp or 2 not in tmp:
            continue
        abc = [0, 0, 0, -30]
        for j in range(n):
            if tmp[j] >= 0:
                abc[tmp[j]] += l[j]
                abc[3] += 10
        mp = abc[3]
        mp += abs(abc[0] - a)
        mp += abs(abc[1] - b)
        mp += abs(abc[2] - c)
        ans = min(ans, mp)

    elif len(tmp) < n:
        w = tmp + [0]
        x = tmp + [1]
        y = tmp + [2]
        z = tmp + [-1]
        stack += [w, x, y, z]

print(ans)
'''

Measured memory_bytes: 12788
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}
int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d) print("Yes");
	else if(abs(a-b)<=d && abs(b-c)<=d) print("Yes");
	else print("No");

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int search(int A[],int n,int key){
  int i = 0;
  A[n] = key;
  while (A[i] != key)i++;
  return i != n;
}
int main(){
  int i,n,A[10000+1],q,key,sum =0;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &key);
    if(search(A,n,key))sum++;
  }
  printf("%d\n",sum);

  return 0;
}
       



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<double> v(n);
	rep(i,n) cin>>v[i];
	sort(all(v));
	double ans = v[0];
	for (int i = 1; i < n; i++){
		ans = (ans+v[i])/2;
	}
	printf("%.12f\n",ans);

	return 0;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	string s;
	cin >> s;
	cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<iostream>
#include<iterator>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define eb(a)    emplace_back(a)
#define pb(a)    push_back(a)
typedef long long ll;
const int maxn=300000+3;
const int minn=505;
const double ep=1e-10;
int gcd(int a,int b)
{
    if(a<b){swap(a,b);}
    return b==0?a:gcd(b,a%b);
}
long long  lcm(int a,int b)
{
    return (ll)a*b/gcd(a,b);
}
int main(){
    int m,n;
    scanf("%d%d",&n,&m);
    char s[maxn],t[maxn];
    scanf("%s%s",s,t);
    ll L=lcm(n,m);
    int a=L/n,b=L/m;
    for(int i=0;i<=min(n/b,m/a);i++)
    {
        if(s[i*b]!=t[i*a]){L=-1;break;}
    }
    printf("%lld\n",L);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int a[maxn];
int main(){
	int n;cin>>n;
	rep(i,1,n){
		char x;cin>>x;
		if(x=='W') a[i]=0;		
		else a[i]=1;
	}	
	int l=1,r=n,cnt=0;
	while(l<r){
		if(a[r]==1){
			while(a[l]==1&&l<r){
				l+=1;
			}
			if(a[l]==0){
				swap(a[l],a[r]);
				++cnt;l++;r--;
			}
			if(l==r) break;
		}else{
			--r;
		}
	}
	cout<<cnt<<endl;
}
/*
5
WWWRW
*/

Measured memory_bytes: 4372
s=str(input())
t=str(input())
lens=len(s)
lent=len(t)
cnt=1000
for i in range(lens-lent+1):
  temp=0
  for j in range(lent):
    if t[j]!=s[i+j]:
      temp+=1
  if temp<cnt:
    cnt=temp
print(cnt)

Measured memory_bytes: 9112
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;


int main()
{
	ll i, j, k, l, m, flag, N, M,K;

	flag = 0;
	char S[11];
	cin >> S;
	vector<ll>ans;
	ll cc;
	REP(i, 0, strlen(S) - 2) {
		cc = 100 * (S[i] - '0') + 10 * (S[i + 1] - '0') + (S[i + 2] - '0');
		ans.push_back(abs(cc-753));
	}
	sort(ans.begin(), ans.end());
	output(ans[0]);
	return 0;
}



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

using namespace std;
struct Point {
	int x, y;
	bool operator==(const Point &p){ return x == p.x && y == p.y; }
};
typedef pair<int, Point> pip;

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

vector<string> field;

int bfs(const Point &from, const Point &to){
	queue<pip> q;
	q.push(pip(0, from));
	field[from.y][from.x] = ' ';
	while(!q.empty()){
		pip p = q.front();
		q.pop();
		if(p.second == to){
			for(int i = 0; i < field.size(); ++i){
				for(int j = 0; j < field[i].size(); ++j){
					if(field[i][j] == ' '){ field[i][j] = '.'; }
				}
			}
			return p.first;
		}
		for(int i = 0; i < 4; ++i){
			Point next = { p.second.x + dx[i], p.second.y + dy[i] };
			if(field[next.y][next.x] == '.'){
				field[next.y][next.x] = ' ';
				q.push(pip(p.first + 1, next));
			}
		}
	}
	for(int i = 0; i < field.size(); ++i){
		for(int j = 0; j < field[i].size(); ++j){
			if(field[i][j] == ' '){ field[i][j] = '.'; }
		}
	}
	return -1;
}

int main(){
	while(true){
		int w, h;
		cin >> w >> h;
		if(w == 0 || h == 0){ break; }
		Point robot;
		vector<Point> targets;
		field.clear();
		field.push_back(string(w + 2, '*'));
		for(int i = 1; i <= h; ++i){
			string line;
			cin >> line;
			field.push_back("*" + line + "*");
			for(int j = 1; j <= w; ++j){
				if(field[i][j] == 'o'){
					field[i][j] = '.';
					robot.x = j; robot.y = i;
				}else if(field[i][j] == '*'){
					field[i][j] = '.';
					Point p = { j, i };
					targets.push_back(p);
				}
			}
		}
		field.push_back(string(w + 2, '*'));
		vector<int> roboDist(targets.size());
		vector< vector<int> > targetsDist(targets.size(), vector<int>(targets.size()));
		bool invalid = false;
		for(int i = 0; i < targets.size(); ++i){
			roboDist[i] = bfs(robot, targets[i]);
			if(roboDist[i] < 0){
				invalid = true;
				break;
			}
			for(int j = i + 1; j < targets.size(); ++j){
				targetsDist[i][j] = targetsDist[j][i] = bfs(targets[i], targets[j]);
			}
		}
		if(invalid){
			cout << "-1" << endl;
			continue;
		}
		vector<int> perm(targets.size());
		for(int i = 0; i < targets.size(); ++i){ perm[i] = i; }
		int answer = INT_MAX;
		do {
			int sum = roboDist[perm[0]];
			for(int i = 1; i < targets.size(); ++i){
				sum += targetsDist[perm[i - 1]][perm[i]];
			}
			answer = min(sum, answer);
		} while(next_permutation(perm.begin(), perm.end()));
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 936
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <chrono>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 998244353
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

int n, w;
pii arr[100];
ll dp[100][100001];
int maxValue = 100000;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d %d", &n, &w);
	for (int i = 0; i < n; i++) scanf("%d %d", &arr[i].first, &arr[i].second);
	for (int i = 0; i < n; i++) for (int j = 0; j <= maxValue; j++) 
		dp[i][j] = INF;
	dp[0][0] = 0;
	dp[0][arr[0].second] = arr[0].first;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= maxValue; j++) dp[i][j] = dp[i - 1][j];
		for (int j = 0; j <= maxValue - arr[i].second; j++) {
			dp[i][j + arr[i].second] = min(dp[i][j + arr[i].second], 
				dp[i - 1][j] + arr[i].first);
		}
	}
	ll ans = -INF;
	for (int i = 0; i <= maxValue; i++) {
		if (dp[n - 1][i] <= w) ans = i;
	}
	cout << ans << endl;
	return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

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

    string S, T;
    std::cin >> S >> T;

    vector<int> s_cnt(27, 0), t_cnt(27, 0);
    REP(i, S.size()) {
        s_cnt[S[i] - 'a']++;
    }
    REP(i, T.size()) {
        t_cnt[T[i] - 'a']++;
    }

    SORT(s_cnt);
    SORT(t_cnt);

    string ans = "Yes";
    REP(i, 27) {
        if(s_cnt[i] != t_cnt[i]) {
            ans = "No";
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 916
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pown(ll fi,ll se){
  ll ans=1;
  rep(i,se){
    ans*=fi;
  }
  return ans;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

ll func(ll now,ll mai,ll uf){
  if(now==0){   return 1;}
  else if(mai==uf){
    //op(1);
    return 1+2*func(now-1,(mai-3)/2,(mai-3)/2);
  }else if(uf>((mai-3)/2+2)){
    //op(2);
    return 1+func(now-1,(mai-3)/2,(mai-3)/2)+func(now-1,((mai-3)/2),uf-(mai-3)/2-2);
  }else if(uf==((mai-3)/2+2)){
    //op(3);
    return 1+func(now-1,(mai-3)/2,(mai-3)/2);
  }else if(uf>1){
    //op(4);
    return func(now-1,(mai-3)/2,uf-1);
  }else {
    //op(5);
    return 0;
  }
}


int main(){
 ll n,x;
 cin>>n>>x;
 ll mai=1;
rep(i,n){
mai*=2;
mai+=3;
}
op(func(n,mai,x));
  return 0;
}

Measured memory_bytes: 256
m,d = gets.chomp.split.map &:to_i

ans = 0
(1..m).each do |month|
  (1..d).each do |day|
    d1 = day % 10
    next if d1 <= 1
    d10 = day / 10
    next if d10 <= 1
    mul = d1 * d10
    next if mul != month
    ans += 1
  end
end

puts ans


Measured memory_bytes: 14340
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define prvsort(v) sort(v.begin(), v.end(), greater<pair<ll, ll>>())
#define ll long long
#define ld long double
#define fixset(val) fixed << setprecision(10) << val 
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define mod 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  string S; cin >> S;
  ll Q, T, F; cin >> Q;
  bool rev = false;
  char C;
  string S1 = "", S2 = "";
  rep(i, 0, Q) {
  	ll T; cin >> T;
    if (T == 1) {
    	if (rev) rev = false;
      	else rev = true;
    } else if (T == 2) {
    	cin >> F >> C;
      	if (F == 1) {
        	if (rev) S2 += C;
          	else S1 += C;
        } else if (F == 2) {
        	if (rev) S1 += C;
          	else S2 += C;
        } 
    }
  }
  if (rev) {
    reverse(S2.begin(), S2.end());
    reverse(S.begin(), S.end());
    cout << S2 << S << S1 << endl;
  } else {
    reverse(S1.begin(), S1.end());
    cout << S1 << S << S2 << endl;
  }
}

Measured memory_bytes: 3912
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    LL K;
    cin >> K;
    int N = 50;
    vector<LL> A(N);

    int m = K % N;
    REP(i, m)A[i] = N-i;
    for(int i=m; i<N; i++){
        A[i] = i-m;
    }

    K -= m;
    K /= N;
    cout << N << endl;
    REP(i, N){
        cout << A[i]+K << (i==N-1 ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    string aa=to_string(a);
    string bb=to_string(b);
    string cc=to_string(c);
    string ans=aa+bb+cc;
    int pp=stoi(ans);
    if(pp%4==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
return 0;
}


Measured memory_bytes: 256
#coding: utf-8

def Is_black(coo):
    a = coo[0]
    b = coo[1]
    if 0 <= a < l[1] and 0 <= b < l[0] and \
    map_list[a][b] == '.':
        return True
    else:
        return False

while True:
    l = map(int, raw_input().split())
    if l == [0, 0]:
        break
    else:
        map_list = []
        for i in range(l[1]):
            row = str(raw_input())
            if '@' in row:
                fp = (i, row.find('@'))
            map_list.append(row)
        stack = [fp]
        arrived = [fp]
        while stack:
            coo = stack.pop()
            coo_a = (coo[0], coo[1] + 1)
            coo_b = (coo[0], coo[1] - 1)
            coo_c = (coo[0] + 1, coo[1])
            coo_d = (coo[0] - 1, coo[1])
            coo_l = [coo_a, coo_b, coo_c, coo_d]
            for c in coo_l:
                if Is_black(c) and c not in arrived:
                    stack.append(c)
                    arrived.append(c)
        print len(arrived)

Measured memory_bytes: 6460
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int gcd(int a, int b){
    return b ? gcd(b, a % b) : a;
}
int main(){
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    vi pref(n);
    int g = a[0];
    for(int i = 0; i < n; i++){
        g = gcd(g, a[i]);
        pref[i] = g;
    }
    vi suff(n);
    g = a[n-1];
    for(int i = n-1; i >= 0; i--){
        g = gcd(g, a[i]);
        suff[i] = g;
    }
    for(int i = 1; i < n-1; i++){
        ans = max(ans, gcd(pref[i-1], suff[i+1]));
    }
    ans = max(ans, suff[1]);
    ans = max(ans, pref[n-2]);
    cout << ans;
}

Measured memory_bytes: 1408
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr ll R=5e5+69, INF=2e9+6969;

ll W,n,sum=0,ans=0;
pair <ll,ll> t[R];
vector <ll> dp(100005,INF);
int main()
{
	scanf("%lld%lld", &n, &W);
	for(int i=0;i<n;++i)
	{
		ll a,b;
		scanf("%lld%lld", &a, &b);
		t[i]=mp(a,b);
		sum+=b;
	}
	//  fill(dp.begin(), dp.end(), INF);
	dp[0]=0;
	
	for(int j=0;j<n;++j){
		for(int i=sum;i>=t[j].se;--i){
			dp[i]=min(dp[i],dp[i-t[j].se]+t[j].fi);
		}
	}
	for(int i=0;i<=sum;++i){
		if(dp[i]<=W){
			ans=max(ans,(ll)i);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define clr cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define _val(x) cerr << #x << " is " << x << "\n";
#define all(container) container.begin(), container.end()
#define rall(container) container.rbegin(), container.rend()
#define pb push_back
#define mp make_pair
#define rep(x, a, b, c) for(ll x = a; x <= b; x += c)
#define rrep(x, a, b, c) for(ll x = a; x >= b; x -= c)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long> > vpll;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+1;
const double eps = 1e-6;

ll epow(ll a, ll b) {
	ll ans = 1;
	while(b) {
		if(1&b) ans *= a;
		b >>= 1;
		a = a*a;
	}
	return ans;
}

void solve() {
	int n; cin >> n;
	cout << epow(n, 3) << "\n";
}	

int main(void){
	// #ifndef ONLINE_JUDGE
	//  	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1; //cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
    int n;
    cin >> n;
    int ans = 0;
    int plus = 0;
    dep(i, n, 1) {
        while(i * (plus + 1) < n) plus++;
        ans += plus;
    }

    cout << ans << endl;
}


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

main(){
  string s,t;
  int f =0;
  cin>>s>>t;
  for(int i= 0;i<s.size();i++){
    //cout<<s.substr(s.size()-i, i)<<s.substr(0,s.size()-i)<<endl;
    if(s.substr(s.size()-i, i) + s.substr(0,s.size()-i) == t){
      f = 1;
      break;
    }
  }
  if(f == 1)cout<< "Yes"<<endl;
  else cout<< "No"<<endl;
  return 0;
}

Measured memory_bytes: 256