#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int base = 1;
vector<complex<double>> roots = {{0, 0}, {1, 0}};
vector<int> rev = {0, 1};
vector<complex<double>> f;
void ensure_base(int nbase) {
  if (nbase <= base) {
    return;
  }
  rev.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); i++) {
    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
  }
  roots.resize(1 << nbase);
  while (base < nbase) {
    double angle = 2 * PI / (1 << (base + 1));
    for (int i = 1 << (base - 1); i < (1 << base); i++) {
      roots[i << 1] = roots[i];
      double angle_i = angle * (2 * i + 1 - (1 << base));
      roots[(i << 1) + 1] = complex<double>(cos(angle_i), sin(angle_i));
    }
    base++;
  }
}
void fft(vector<complex<double>>& a, int n) {
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; i++) {
    if (i < (rev[i] >> shift)) {
      swap(a[i], a[rev[i] >> shift]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        complex<double> z = a[i + j + k] * roots[j + k];
        a[i + j + k] = a[i + j] - z;
        a[i + j] = a[i + j] + z;
      }
    }
  }
}
vector<long long> multiply(const vector<int>& a, const vector<int>& b) {
  int need = (int)a.size() + (int)b.size() - 1;
  int nbase = 1;
  while ((1 << nbase) < need) {
    nbase++;
  }
  ensure_base(nbase);
  int sz = 1 << nbase;
  if (sz > (int)f.size()) {
    f.resize(sz);
  }
  for (int i = 0; i < sz; i++) {
    int x = (i < (int)a.size() ? a[i] : 0);
    int y = (i < (int)b.size() ? b[i] : 0);
    f[i] = complex<double>(x, y);
  }
  fft(f, sz);
  complex<double> r(0, -0.25 / (sz >> 1));
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    complex<double> z = (f[j] * f[j] - conj(f[i] * f[i])) * r;
    f[j] = (f[i] * f[i] - conj(f[j] * f[j])) * r;
    f[i] = z;
  }
  for (int i = 0; i < (sz >> 1); i++) {
    complex<double> a0 = (f[i] + f[i + (sz >> 1)]) * complex<double>(0.5, 0);
    complex<double> a1 = (f[i] - f[i + (sz >> 1)]) * complex<double>(0.5, 0) *
                         roots[(sz >> 1) + i];
    f[i] = a0 + a1 * complex<double>(0, 1);
  }
  fft(f, sz >> 1);
  vector<long long> res(need);
  for (int i = 0; i < need; i++) {
    res[i] = llround(i % 2 == 0 ? f[i >> 1].real() : f[i >> 1].imag());
  }
  return res;
}
template <long long mod>
struct modular {
  long long value;
  modular(long long x = 0) {
    value = x % mod;
    if (value < 0) value += mod;
  }
  modular& operator+=(const modular& other) {
    if ((value += other.value) >= mod) value -= mod;
    return *this;
  }
  modular& operator-=(const modular& other) {
    if ((value -= other.value) < 0) value += mod;
    return *this;
  }
  modular& operator*=(const modular& other) {
    value = value * other.value % mod;
    return *this;
  }
  modular& operator/=(const modular& other) {
    long long a = 0, b = 1, c = other.value, m = mod;
    while (c != 0) {
      long long t = m / c;
      m -= t * c;
      swap(c, m);
      a -= t * b;
      swap(a, b);
    }
    a %= mod;
    if (a < 0) a += mod;
    value = value * a % mod;
    return *this;
  }
  modular operator+(const modular& rhs) const { return modular(*this) += rhs; }
  modular operator-(const modular& rhs) const { return modular(*this) -= rhs; }
  modular operator*(const modular& rhs) const { return modular(*this) *= rhs; }
  modular operator/(const modular& rhs) const { return modular(*this) /= rhs; }
  modular& operator++() { return *this += 1; }
  modular& operator--() { return *this -= 1; }
  modular operator++(int) {
    modular res(*this);
    *this += 1;
    return res;
  }
  modular operator--(int) {
    modular res(*this);
    *this -= 1;
    return res;
  }
  modular operator-() const { return modular(-value); }
  bool operator==(const modular& rhs) const { return value == rhs.value; }
  bool operator!=(const modular& rhs) const { return value != rhs.value; }
  bool operator<(const modular& rhs) const { return value < rhs.value; }
};
template <long long mod>
string to_string(const modular<mod>& x) {
  return to_string(x.value);
}
template <long long mod>
ostream& operator<<(ostream& stream, const modular<mod>& x) {
  return stream << x.value;
}
template <long long mod>
istream& operator>>(istream& stream, modular<mod>& x) {
  stream >> x.value;
  x.value %= mod;
  if (x.value < 0) x.value += mod;
  return stream;
}
constexpr long long mod = (long long)1e9 + 7;
using mint = modular<mod>;
mint power(mint a, long long n) {
  mint res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= a;
    }
    a *= a;
    n >>= 1;
  }
  return res;
}
vector<mint> fact(1, 1);
vector<mint> finv(1, 1);
mint C(int n, int k) {
  if (n < k || k < 0) {
    return mint(0);
  }
  while ((int)fact.size() < n + 1) {
    fact.emplace_back(fact.back() * (int)fact.size());
    finv.emplace_back(mint(1) / fact.back());
  }
  return fact[n] * finv[k] * finv[n - k];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  int b = 0;
  vector<int> c(k);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] %= k;
    b = (b + a[i]) % k;
    c[b]++;
  }
  vector<int> d(k);
  int e = 0;
  for (int i = 0; i < m; i++) {
    d[e]++;
    e = (e + b) % k;
  }
  auto z = multiply(c, d);
  for (int i = 0; i < k - 1; i++) {
    z[i] += z[i + k];
  }
  z.resize(k);
  ;
  mint ans = 0;
  int g = (int)((1LL * b * m) % k);
  b = 0;
  for (int i = 0; i < n; i++) {
    if (i) {
      z[b]--;
      z[(b + g) % k]++;
    }
    ans += z[b];
    b = (b + a[i]) % k;
  }
  if (g == 0) {
    ans -= n;
  }
  ans *= m;
  if (g == 0) {
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

### Prompt

Please formulate a cpp solution to the following problem:

Denote a cyclic sequence of size n as an array s such that s_n is adjacent to s_1. The segment s[r, l] where l < r is the concatenation of s[r, n] and s[1, l].

You are given an array a consisting of n integers. Define b as the cyclic sequence obtained from concatenating m copies of a. Note that b has size n ⋅ m.

You are given an integer k where k = 1 or k is a prime number. Find the number of different segments in b where the sum of elements in the segment is divisible by k.

Two segments are considered different if the set of indices of the segments are different. For example, when n = 3 and m = 2, the set of indices for segment s[2, 5] is \{2, 3, 4, 5\}, and for segment s[5, 2] is \{5, 6, 1, 2\}. In particular, the segments s[1, 6], s[2,1], …, s[6, 5] are considered as the same segment.

Output the answer modulo 10^9 + 7.

Input

The first line contains three integers n, m, and k (1 ≤ n, m, k ≤ 2 ⋅ 10^5, k = 1 or k is a prime number).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 2 ⋅ 10^5).

Output

Output an integer denoting the number of different segments in b where the sum of elements in the segment is divisible by k, modulo 10^9 + 7.

Examples

Input


5 1 5
1 2 3 4 3


Output


4


Input


5 1 5
1 2 3 4 5


Output


5


Input


5 4 5
1 2 3 4 5


Output


125

Note

In the first example, all valid segments are [1,4], [2, 3], [3, 5], and [4, 2].

In the second example, one of the valid segments is [1, 5].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int base = 1;
vector<complex<double>> roots = {{0, 0}, {1, 0}};
vector<int> rev = {0, 1};
vector<complex<double>> f;
void ensure_base(int nbase) {
  if (nbase <= base) {
    return;
  }
  rev.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); i++) {
    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
  }
  roots.resize(1 << nbase);
  while (base < nbase) {
    double angle = 2 * PI / (1 << (base + 1));
    for (int i = 1 << (base - 1); i < (1 << base); i++) {
      roots[i << 1] = roots[i];
      double angle_i = angle * (2 * i + 1 - (1 << base));
      roots[(i << 1) + 1] = complex<double>(cos(angle_i), sin(angle_i));
    }
    base++;
  }
}
void fft(vector<complex<double>>& a, int n) {
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; i++) {
    if (i < (rev[i] >> shift)) {
      swap(a[i], a[rev[i] >> shift]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        complex<double> z = a[i + j + k] * roots[j + k];
        a[i + j + k] = a[i + j] - z;
        a[i + j] = a[i + j] + z;
      }
    }
  }
}
vector<long long> multiply(const vector<int>& a, const vector<int>& b) {
  int need = (int)a.size() + (int)b.size() - 1;
  int nbase = 1;
  while ((1 << nbase) < need) {
    nbase++;
  }
  ensure_base(nbase);
  int sz = 1 << nbase;
  if (sz > (int)f.size()) {
    f.resize(sz);
  }
  for (int i = 0; i < sz; i++) {
    int x = (i < (int)a.size() ? a[i] : 0);
    int y = (i < (int)b.size() ? b[i] : 0);
    f[i] = complex<double>(x, y);
  }
  fft(f, sz);
  complex<double> r(0, -0.25 / (sz >> 1));
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    complex<double> z = (f[j] * f[j] - conj(f[i] * f[i])) * r;
    f[j] = (f[i] * f[i] - conj(f[j] * f[j])) * r;
    f[i] = z;
  }
  for (int i = 0; i < (sz >> 1); i++) {
    complex<double> a0 = (f[i] + f[i + (sz >> 1)]) * complex<double>(0.5, 0);
    complex<double> a1 = (f[i] - f[i + (sz >> 1)]) * complex<double>(0.5, 0) *
                         roots[(sz >> 1) + i];
    f[i] = a0 + a1 * complex<double>(0, 1);
  }
  fft(f, sz >> 1);
  vector<long long> res(need);
  for (int i = 0; i < need; i++) {
    res[i] = llround(i % 2 == 0 ? f[i >> 1].real() : f[i >> 1].imag());
  }
  return res;
}
template <long long mod>
struct modular {
  long long value;
  modular(long long x = 0) {
    value = x % mod;
    if (value < 0) value += mod;
  }
  modular& operator+=(const modular& other) {
    if ((value += other.value) >= mod) value -= mod;
    return *this;
  }
  modular& operator-=(const modular& other) {
    if ((value -= other.value) < 0) value += mod;
    return *this;
  }
  modular& operator*=(const modular& other) {
    value = value * other.value % mod;
    return *this;
  }
  modular& operator/=(const modular& other) {
    long long a = 0, b = 1, c = other.value, m = mod;
    while (c != 0) {
      long long t = m / c;
      m -= t * c;
      swap(c, m);
      a -= t * b;
      swap(a, b);
    }
    a %= mod;
    if (a < 0) a += mod;
    value = value * a % mod;
    return *this;
  }
  modular operator+(const modular& rhs) const { return modular(*this) += rhs; }
  modular operator-(const modular& rhs) const { return modular(*this) -= rhs; }
  modular operator*(const modular& rhs) const { return modular(*this) *= rhs; }
  modular operator/(const modular& rhs) const { return modular(*this) /= rhs; }
  modular& operator++() { return *this += 1; }
  modular& operator--() { return *this -= 1; }
  modular operator++(int) {
    modular res(*this);
    *this += 1;
    return res;
  }
  modular operator--(int) {
    modular res(*this);
    *this -= 1;
    return res;
  }
  modular operator-() const { return modular(-value); }
  bool operator==(const modular& rhs) const { return value == rhs.value; }
  bool operator!=(const modular& rhs) const { return value != rhs.value; }
  bool operator<(const modular& rhs) const { return value < rhs.value; }
};
template <long long mod>
string to_string(const modular<mod>& x) {
  return to_string(x.value);
}
template <long long mod>
ostream& operator<<(ostream& stream, const modular<mod>& x) {
  return stream << x.value;
}
template <long long mod>
istream& operator>>(istream& stream, modular<mod>& x) {
  stream >> x.value;
  x.value %= mod;
  if (x.value < 0) x.value += mod;
  return stream;
}
constexpr long long mod = (long long)1e9 + 7;
using mint = modular<mod>;
mint power(mint a, long long n) {
  mint res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= a;
    }
    a *= a;
    n >>= 1;
  }
  return res;
}
vector<mint> fact(1, 1);
vector<mint> finv(1, 1);
mint C(int n, int k) {
  if (n < k || k < 0) {
    return mint(0);
  }
  while ((int)fact.size() < n + 1) {
    fact.emplace_back(fact.back() * (int)fact.size());
    finv.emplace_back(mint(1) / fact.back());
  }
  return fact[n] * finv[k] * finv[n - k];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  int b = 0;
  vector<int> c(k);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] %= k;
    b = (b + a[i]) % k;
    c[b]++;
  }
  vector<int> d(k);
  int e = 0;
  for (int i = 0; i < m; i++) {
    d[e]++;
    e = (e + b) % k;
  }
  auto z = multiply(c, d);
  for (int i = 0; i < k - 1; i++) {
    z[i] += z[i + k];
  }
  z.resize(k);
  ;
  mint ans = 0;
  int g = (int)((1LL * b * m) % k);
  b = 0;
  for (int i = 0; i < n; i++) {
    if (i) {
      z[b]--;
      z[(b + g) % k]++;
    }
    ans += z[b];
    b = (b + a[i]) % k;
  }
  if (g == 0) {
    ans -= n;
  }
  ans *= m;
  if (g == 0) {
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

```