import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def Floor_sum(N,M,A,B): ANS=0 if A>=M: ANS+=N*(N-1)//2*(A//M) A%=M if B>=M: ANS+=(B//M*N)%mod B%=M y_max=(A*N+B)//M x_max_divA=y_max*M-B if y_max==0: return ANS else: return ANS+Floor_sum(y_max,A,M,A*N-x_max_divA) N=int(input()) M=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) ANS=0 mod=10**9+7 for i in range(N): for j in range(M): ANS+=Floor_sum(B[j]+1,B[j],A[i],0) print(ANS*2%mod)