local function floorSum(n, m, a, b) local ans = 0LL while true do if m <= a then local v = a / m ans = ans + v * n * (n - 1LL) / 2LL a = a % m end if m <= b then ans = ans + (b / m) * n b = b % m end if a == 0LL then break end local y = (a * n + b) / m local z = (a * n + b) % m n, m, a, b = y, a, m, z 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) -- print(os.clock())