#include using namespace std; int n, c; int l[55], w[55]; int memo[55][55][55]; int calc(int x, int pp, int p) { if(memo[x][pp][p] != -1) return memo[x][pp][p]; int ret = 0; for(int i = 1; i <= n; i++){ if(pp < p && l[i] > p) continue; if(pp > p && l[i] < p) continue; if(l[i] == p || l[i] == pp) continue; if(x+w[i] > c) continue; ret = max(ret, calc(x+w[i], p, l[i]) + l[i]); } return memo[x][pp][p] = ret; } int main(void) { cin >> n >> c; for(int i = 1; i <= n; i++) cin >> l[i]; for(int i = 1; i <= n; i++) cin >> w[i]; for(int i = 0; i < 55; i++){ for(int j = 0; j < 55; j++){ for(int k = 0; k < 55; k++){ memo[i][j][k] = -1; } } } int ans = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(l[i] == l[j]) continue; ans = max(ans, calc(w[i]+w[j], l[i],l[j]) + l[i]+l[j]); } } cout << ans << endl; return 0; }