import sys input = sys.stdin.readline from collections import Counter mod=10**9+7 H,W=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) ANS=0 for i in range(H): for j in range(W): ANS+=min(A[i],B[j]) CA=Counter(A) CB=Counter(B) ANS2=0 S=set(A)|set(B) for s in S: ANS2+=max(CA[s],CB[s])*s print(ANS2%mod) print(ANS%mod)