N, W = map(int, input().split()) weights, values = [list(map(int, input().split())) for _ in range(2)] weight_to_value_sum = dict().fromkeys(weights, 0) for w, v in zip(weights, values): weight_to_value_sum[w] += v max_weight = max(weights) ans = 0 for g in range(W, max_weight + 1): ans = max( ans, sum(weight_to_value_sum.get(t, 0) for t in range(g, max_weight + 1, g)) ) print(ans)