mod = 1000000007
def partition(number):
    answer = set()
    answer.add((number, ))
    for x in range(1, number):
        for y in partition(number - x):
            answer.add(tuple(sorted((x, ) + y)))
    return answer
p = lambda n: len(partition(n))

n,m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
print((x[n-1]-x[0])*(y[m-1]-y[0])*p(n-1)*p(m-1) % mod)