inp = open("traffic.in", "r")

n, k = map(int, inp.readline().split())
nums = list(map(int, inp.readline().split()))

inp = open("traffic.out", "r")

res = int(inp.readline())
ki = list(map(int, inp.readline().split()))

def calc_anger(_cars, answer):
    anger = 0
    for i, cars in enumerate(_cars):
        cnt = cars // answer[i];
        anger -= cnt * cars - answer[i] * cnt * (cnt + 1) // 2
        anger += cnt * cars * cars
        anger += answer[i] * answer[i] * cnt * (cnt + 1) * (2 * cnt + 1) // 6
        anger -= cars * answer[i] * cnt * (cnt + 1)
    return anger // 2

res2 = calc_anger(nums, ki)

assert(res == res2)