/* -*- coding: utf-8 -*- * * 3409.cc: No.3409 How Many Gift Boxes? - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_H = 100000; const int MAX_W = 100000; const int MAX_K = MAX_H + MAX_W; const int MOD = 1000000007; /* typedef */ using ll = long long; template struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; } MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; } explicit operator int() const { return v; } MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator-() const { return MI(MOD - v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; using mi = MI; /* global variables */ int as[MAX_H], bs[MAX_W]; int uas[MAX_K], acs[MAX_K], bcs[MAX_K]; ll ass[MAX_H + 1]; /* subroutines */ /* main */ int main() { int h, w; scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) scanf("%d", as + i); for (int i = 0; i < w; i++) scanf("%d", bs + i); mi minsum = 0, maxsum = 0; // minsum int k = 0; for (int i = 0; i < h; i++) uas[k++] = as[i]; for (int i = 0; i < w; i++) uas[k++] = bs[i]; sort(uas, uas + k); k = unique(uas, uas + k) - uas; for (int i = 0; i < h; i++) { int ai = lower_bound(uas, uas + k, as[i]) - uas; acs[ai]++; } for (int i = 0; i < w; i++) { int bi = lower_bound(uas, uas + k, bs[i]) - uas; bcs[bi]++; } for (int i = 0; i < k; i++) minsum += (ll)uas[i] * max(acs[i], bcs[i]); // maxsum sort(as, as + h); for (int i = 0; i < h; i++) ass[i + 1] = ass[i] + as[i]; for (int i = 0; i < w; i++) { int j = lower_bound(as, as + h, bs[i]) - as; maxsum += ass[j] + (ll)(h - j) * bs[i]; } printf("%d\n%d\n", (int)minsum, (int)maxsum); return 0; }