#include #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { cin.tie(nullptr) -> sync_with_stdio(false); int n, w; cin >> n >> w; vector x(n), y(n); rep(i, n) cin >> x[i]; rep(i, n) cin >> y[i]; int m = 0; rep(i, n) m = max(m, x[i]); vector s(m+1); rep(i, n) s[x[i]] += y[i]; ll ans = 0; for (int i = w; i <= m; ++i) { ll now = 0; for (int j = i; j <= m; j += i) now += s[j]; ans = max(ans, now); } cout << ans << '\n'; return 0; }