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;
int main() {
  ios::sync_with_stdio(false);
  int N, K, M;
  cin >> N >> K >> M;
  vector<int> A(N);
  for (auto& x : A) cin >> x;
  deque<pair<int, int>> B;
  for (int x : A) {
    if (B.empty() || B.back().first != x)
      B.push_back({x, 1});
    else {
      B.back().second += 1;
      if (B.back().second == K) B.pop_back();
    }
  }
  if (B.size() == 0) {
    cout << 0 << endl;
  } else if (B.size() == 1) {
    long long n = B.back().second;
    n *= M;
    cout << n % K << endl;
  } else if (M == 1) {
    long long n = 0;
    for (auto x : B) n += x.second;
    cout << n << endl;
  } else {
    auto head = B;
    auto body = B;
    auto tail = B;
    while (head.size() > 0 && tail.size() > 0 && body.size() >= 2 &&
           head.back().first == body.front().first) {
      (body.front().second += head.back().second) %= K;
      if (body.front().second == 0) {
        body.pop_front();
        tail.pop_front();
      } else {
        tail.front().second = body.front().second;
      }
      head.pop_back();
      body.pop_back();
    }
    if (body.size() == 1) {
      int k = body.back().first;
      long long n = body.back().second;
      n *= M - 2;
      if (head.size() > 0 && tail.size() > 0 && head.back().first == k &&
          tail.front().first == k) {
        n += head.back().second;
        n += tail.front().second;
        n %= K;
        head.pop_back();
        tail.pop_front();
        body.clear();
        if (n > 0) head.push_back({k, (int)n});
      } else if (head.size() > 0 && head.back().first == k) {
        n += head.back().second;
        n %= K;
        head.pop_back();
        body.clear();
        if (n > 0) head.push_back({k, (int)n});
      } else if (tail.size() > 0 && tail.front().first == k) {
        n += tail.front().second;
        n %= K;
        tail.pop_front();
        body.clear();
        if (n > 0) head.push_back({k, (int)n});
      }
    }
    if (body.size() == 0) {
      while (head.size() > 0 && tail.size() > 0 &&
             head.back().first == tail.front().first) {
        (tail.front().second += head.back().second) %= K;
        if (tail.front().second == 0) {
          tail.pop_front();
        }
        head.pop_back();
      }
    }
    long long r = 0;
    for (auto x : body) r += x.second;
    r *= M - 2;
    for (auto x : head) r += x.second;
    for (auto x : tail) r += x.second;
    cout << r << endl;
  }
}
