#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
void solve(bool);
void precalc();
clock_t start;
int main() {
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(20);
  cout << fixed;
  while (t--) {
    solve(true);
  }
  cout.flush();
  return 0;
}
template <typename T>
T binpow(T q, T w, T mod) {
  if (!w) return 1 % mod;
  if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}
template <typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template <typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}
template <typename T>
void make_unique(vector<T>& vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
template <typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}
template <typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}
void precalc() {}
long long k;
struct Piece {
  vector<long long> pref, suf;
  long long len;
};
vector<pair<long long, long long>> get_parts(const vector<long long>& a) {
  vector<pair<long long, long long>> res;
  for (long long i = 0; i < a.size();) {
    long long j = i;
    while (j < a.size() && a[i] == a[j]) {
      ++j;
    }
    res.push_back({a[i], j - i});
    i = j;
  }
  return res;
};
long long MAGIC;
Piece merge(const Piece& q, const Piece& w) {
  if (q.len == 0) {
    return w;
  }
  if (w.len == 0) {
    return q;
  }
  auto vec = q.suf;
  reverse(vec.begin(), vec.end());
  auto q_parts = get_parts(vec);
  auto w_parts = get_parts(w.pref);
  long long decrease_q = 0, decrease_w = 0;
  for (long long i = 0; i < q_parts.size() && i < w_parts.size(); ++i) {
    if (q_parts[i].first == w_parts[i].first &&
        q_parts[i].second + w_parts[i].second >= k) {
      if (q_parts[i].second + w_parts[i].second == k) {
        decrease_q += q_parts[i].second;
        decrease_w += w_parts[i].second;
        continue;
      } else {
        long long take_q = min(q_parts[i].second, k);
        decrease_q += take_q;
        decrease_w += k - take_q;
        break;
      }
    } else {
      break;
    }
  }
  Piece res = {q.pref, w.suf, q.len + w.len - decrease_q - decrease_w};
  long long new_q_len = q.len - decrease_q;
  if (res.pref.size() > new_q_len) {
    res.pref.resize(new_q_len);
  }
  long long new_w_len = w.len - decrease_w;
  if (res.suf.size() > new_w_len) {
    vec.clear();
    for (long long i = (long long)res.suf.size() - new_w_len;
         i < res.suf.size(); ++i) {
      vec.push_back(res.suf[i]);
    }
    vec.swap(res.suf);
  }
  if (res.pref.size() == new_q_len && res.suf.size() == new_w_len) {
    for (long long x : res.suf) {
      res.pref.push_back(x);
    }
    res.suf = res.pref;
  }
  if (res.pref.size() > MAGIC) {
    res.pref.resize(MAGIC);
  }
  if (res.suf.size() > MAGIC) {
    reverse(res.suf.begin(), res.suf.end());
    res.suf.resize(MAGIC);
    reverse(res.suf.begin(), res.suf.end());
  }
  return res;
}
Piece get_power(Piece cur, long long step) {
  if (step == 1) {
    return cur;
  }
  if (step % 2) {
    Piece new_piece = get_power(cur, step - 1);
    return merge(new_piece, cur);
  }
  auto new_piece = get_power(cur, step / 2);
  return merge(new_piece, new_piece);
}
struct Segment {
  long long l;
  long long len;
  long long val;
  bool operator<(const Segment& ot) const { return l < ot.l; }
};
void solve(bool read) {
  long long n, m;
  if (read) {
    cin >> n >> k >> m;
  } else {
    n = 100000;
    k = 4;
    m = 1000000000;
  }
  vector<long long> a(n);
  set<long long> have;
  for (long long i = 0; i < n; ++i) {
    if (read) {
      cin >> a[i];
    } else {
      a[i] = rand() % 2;
    }
    have.insert(a[i]);
  }
  if (have.size() == 1) {
    long long res = n * m % k;
    cout << res << endl;
    return;
  }
  vector<pair<long long, long long>> st;
  for (long long i = 0; i < n; ++i) {
    if (st.empty() || st.back().first != a[i]) {
      st.push_back({a[i], 1});
    } else {
      ++st.back().second;
    }
    if (st.back().second == k) {
      st.pop_back();
    }
  }
  vector<long long> b;
  while (!st.empty()) {
    pair<long long, long long> cur = st.back();
    st.pop_back();
    for (long long i = 0; i < cur.second; ++i) {
      b.push_back(cur.first);
    }
  }
  reverse(b.begin(), b.end());
  a = b;
  n = (long long)a.size();
  MAGIC = 3 * n;
  Piece start = {a, a, n};
  Piece res = get_power(start, m);
  cout << res.len << endl;
}
