local function floorSum(n, m, a, b) local ans = 0LL while true do if m <= a then ans = ans + ((n - 1LL) * n / 2LL) * (a / m) a = a % m end if m <= b then ans = ans + n * (b / m) b = b % m end local ymax = (a * n + b) / m local xmax = ymax * m - b if ymax == 0 then break end ans = ans + (n - (xmax + a - 1LL) / a) * ymax n, m, a, b = ymax, a, m, (a - xmax % a) % a end return ans end local n, m = io.read("*n", "*n") local a, b = {}, {} for i = 1, n do a[i] = io.read("*n") * 1LL end for i = 1, m do b[i] = io.read("*n") * 1LL end local mod = 1000000007LL local ret = 0LL for i = 1, n do for j = 1, m do local v = floorSum(b[j] + 1, b[j], a[i], 0LL) v = v % mod ret = (ret + v) % mod end end ret = (ret + ret) % mod ret = tostring(ret):gsub("LL", "") print(ret)