10 5 1000000000
1 1 1 2 2 1 2 2 2 2
 5 3 3
1 2 2 1 1
 2 4 1
1 1
 1 1000000000 1000000000
100000
 5 3 2
1 1 2 1 1
 5 2 4
1 2 3 2 1
 1 10 10
1

10000000000
 0
 2
 0
 7
 0
 0

#include <bits/stdc++.h>
using namespace std;
const long long mx = 110010;
struct info {
  long long a, num;
  info() {}
  info(long long _1, long long _2) {
    a = _1;
    num = _2;
  }
};
vector<info> Sta[33], Ans;
long long n, k, m, Fir[100010];
long long Core[33];
void DoCore(vector<info> &X, long long x) {
  if (X.size() > mx * 2 + 5) {
    for (long long i = mx; i <= X.size() - mx - 1; i++) Core[x] += X[i].num;
    for (long long a = mx, b = X.size() - mx; b < X.size(); a++, b++)
      X[a] = X[b];
    X.resize(mx * 2);
  }
}
void reduce(vector<info> &X) {
  vector<info> tmp;
  tmp.clear();
  for (long long i = 0; i < X.size(); i++)
    if (tmp.size() == 0 || tmp.back().a != X[i].a)
      tmp.push_back(X[i]);
    else {
      tmp.back().num = (tmp.back().num + X[i].num) % k;
      if (tmp.back().num == 0) tmp.pop_back();
    }
  X = tmp;
}
int main() {
  scanf("%lld%lld%lld", &n, &k, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &Fir[i]);
  Fir[n + 1] = -1;
  for (long long i = 2, lst = 1; i <= n + 1; i++)
    if (Fir[i] != Fir[i - 1]) {
      Sta[0].push_back(info(Fir[i - 1], i - lst));
      lst = i;
    }
  reduce(Sta[0]);
  DoCore(Sta[0], 0);
  for (long long i = 1; i <= 30; i++) {
    Sta[i].resize(Sta[i - 1].size() * 2);
    for (long long j = 0; j < Sta[i - 1].size(); j++) {
      Sta[i][j] = Sta[i - 1][j];
      Sta[i][j + Sta[i - 1].size()] = Sta[i - 1][j];
    }
    Core[i] = 2 * Core[i - 1];
    reduce(Sta[i]);
    DoCore(Sta[i], i);
  }
  Ans.clear();
  long long anspeo = 0;
  for (long long i = 0; i < 30; i++)
    if ((m >> i) & 1) {
      for (long long j = 0; j < Sta[i].size(); j++) Ans.push_back(Sta[i][j]);
      anspeo += Core[i];
    }
  reduce(Ans);
  for (long long i = 0; i < Ans.size(); i++) anspeo += Ans[i].num;
  printf("%lld\n", anspeo);
  return 0;
}
