import sys input = sys.stdin.readline n, w = map(int, input().split()) xs = list(map(int, input().split())) ys = list(map(int, input().split())) mx = 200000 cnt = [0] * (mx + 1) for x, y in zip(xs, ys): cnt[x] += y best = 0 for g in range(w, mx + 1): cur = 0 for j in range(g, mx + 1, g): cur += cnt[j] if cur > best: best = cur print(best)