local mfl, mce = math.floor, math.ceil local mod = 1000000007 local half = 500000004 local function bmul(x, y) local x1, y1 = mfl(x / 31623), mfl(y / 31623) local x0, y0 = x - x1 * 31623, y - y1 * 31623 return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod end local function badd(x, y) return (x + y) % mod end local ret = 0 local function floorSum(n, m, a, b) local f = f while true do if m <= a then local v = mfl(a / m) ret = badd(ret, bmul(v, bmul(n, bmul(n - 1, half)))) a = a % m end if m <= b then ret = badd(ret, bmul(n, mfl(b / m))) b = b % m end if a == 0 then break end if f then n, m, a, b = a + mfl(a / m), a, m, a % m else local y = mfl((a * n + b) / m) local z = (a * n + b) % m n, m, a, b = y, a, m, z end end end local n, m = io.read("*n", "*n") local a, b = {}, {} for i = 1, n do a[i] = io.read("*n") end for i = 1, m do b[i] = io.read("*n") end for i = 1, n do -- if i % 100 == 0 then -- print(i, os.clock()) -- end for j = 1, m do floorSum(b[j] + 1, b[j], a[i], 0) end end ret = (ret + ret) % mod ret = tostring(ret):gsub("LL", "") print(ret) -- print(os.clock())