import sys from math import gcd def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,M = I(),I() A,B = LI(),LI() mod = 10**9+7 ans = 0 for i in range(N): a = A[i] for j in range(M): b = B[j] g = gcd(a,b) ans += a*b+a-b+g ans %= mod print(ans)