import sys def main() -> None: data = list(map(int, sys.stdin.buffer.read().split())) if not data: return n, w = data[0], data[1] xs = data[2:2 + n] ys = data[2 + n:2 + 2 * n] max_x = max(xs) value_by_weight = [0] * (max_x + 1) for x, y in zip(xs, ys): value_by_weight[x] += y ans = 0 for g in range(w, max_x + 1): total = 0 for multiple in range(g, max_x + 1, g): total += value_by_weight[multiple] if total > ans: ans = total print(ans) if __name__ == "__main__": main()