#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
    map<ll,ll> mp;
    ll N, MOD;
    cin >> N >> MOD;
    ll sum[N+1];
    sum[0] =0;
    mp[0]++;
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        sum[i+1] = sum[i] + a;
        sum[i+1] %=MOD;
        mp[sum[i+1]]++;
    }
    ll ans =0;
    for(auto itr = mp.begin();itr != mp.end();++itr){
        ll n = itr->second;
        ans += (n*(n-1))/2;
    }
    cout << ans << endl;

    return 0;
}
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << "\n";
#else
#define DEBUG(message)
#endif

const int MOD = 1000 * 1000 * 1000 + 7;

struct Solver {
  void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    vector<int> b(m);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }

    int x = 0;
    for (int i = 0; i + 1 < n; i++) {
      x += 1LL * (a[i + 1] - a[i]) * (i + 1) % MOD * (n - i - 1) % MOD;
      if (x >= MOD) {
        x -= MOD;
      }
    }

    int y = 0;
    for (int i = 0; i + 1 < m; i++) {
      y += 1LL * (b[i + 1] - b[i]) * (i + 1) % MOD * (m - i - 1) % MOD;
      if (y >= MOD) {
        y -= MOD;
      }
    }

    cout << (1LL * x * y) % MOD << "\n";
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    Solver().solve();
  }
  return 0;
}