#include using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, w; if (!(cin >> n >> w)) return 0; vector x(n); for (int i = 0; i < n; ++i) cin >> x[i]; vector y(n); for (int i = 0; i < n; ++i) cin >> y[i]; int max_x = 0; for (int i = 0; i < n; ++i) { max_x = max(max_x, x[i]); } if (w > max_x) { cout << 0 << '\n'; return 0; } vector sum_y(max_x + 1, 0); for (int i = 0; i < n; ++i) { sum_y[x[i]] += y[i]; } long long ans = 0; for (int d = w; d <= max_x; ++d) { long long current_sum = 0; for (int k = d; k <= max_x; k += d) { current_sum += sum_y[k]; } ans = max(ans, current_sum); } cout << ans << '\n'; return 0; }