#include<stdio.h>
int max(int n, int W, int w[n], int v[n], int weight, int i){
if (i == n || weight > W) {
return 0;
}
if(weight + w[i] <= W){
int in = v[i] + max(n, W, w, v, weight + w[i], i + 1);
int ex = max(n, W, w, v, weight, i + 1);
return (in > ex) ? in : ex;
}
else return max(n, W, w, v, weight, i + 1);
}
int main(){
int n, W;
int w[n], v[n];
for(int i = 0; i < n; i++){
scanf("%d %d", &w
[i
], &v
[i
]); }
printf("%d", max
(n
, W
, w
, v
, 0, 0)); }
I2luY2x1ZGU8c3RkaW8uaD4KCmludCBtYXgoaW50IG4sIGludCBXLCBpbnQgd1tuXSwgaW50IHZbbl0sIGludCB3ZWlnaHQsIGludCBpKXsKCQoJaWYgKGkgPT0gbiB8fCB3ZWlnaHQgPiBXKSB7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICAKCWlmKHdlaWdodCArIHdbaV0gPD0gVyl7CgkJaW50IGluID0gdltpXSArIG1heChuLCBXLCB3LCB2LCB3ZWlnaHQgKyB3W2ldLCBpICsgMSk7CgkgICAgaW50IGV4ID0gbWF4KG4sIFcsIHcsIHYsIHdlaWdodCwgaSArIDEpOwoJICAgIHJldHVybiAoaW4gPiBleCkgPyBpbiA6IGV4OwoJfQoJICAgIAoJZWxzZSByZXR1cm4gbWF4KG4sIFcsIHcsIHYsIHdlaWdodCwgaSArIDEpOwp9CgppbnQgbWFpbigpewogICAgaW50IG4sIFc7CiAgICBzY2FuZigiJWQgJWQiLCAmbiwgJlcpOwogICAgaW50IHdbbl0sIHZbbl07CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICBzY2FuZigiJWQgJWQiLCAmd1tpXSwgJnZbaV0pOwogICAgfQogICAgcHJpbnRmKCIlZCIsIG1heChuLCBXLCB3LCB2LCAwLCAwKSk7Cn0=