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

/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

int n, K, m, a[mxn];
vector<pair<int, int> > v;

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n >> K >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int strt = 1;
    for (int i = 1; i <= n; i++) {
        if (i != n and a[i] == a[i+1]) continue;
        v.push_back({i-strt+1, a[i]});
        strt = i+1;
    }

    int sz = sz(v);
    if (sz == 1) return cout << n*ll(m)%K << '\n', 0;
    if (K >= n) return cout << n << '\n', 0;

    vector<pair<int, int> > o;
    for (int i = 0; i < sz; i++) {
        v[i].first %= K;
        if (v[i].first==0) {
            if (sz(o) and i < sz-1 and o.back().second == v[i+1].second) v[i+1].first += o.back().first, o.pop_back();
        } else {
            o.push_back(v[i]);
        }
    }

    sz = sz(o);
    if (sz == 1) return cout << n*ll(m)%K << '\n', 0;
    ll ans = 0;
    for (auto &i : o) {
        ans += i.first;
    }
    ans *= m;
    if (m == 1) return cout << ans << '\n', 0;

    deque<pair<int, int> > l, r;
    for (auto &i : o) {
        l.push_back(i), r.push_back(i);
    }

    for (int i = 0; i < sz; i++) {
        if (l.back().second!=r.front().second) {
            return cout << ans << '\n', 0;
        }
        if ((l.back().first+r.front().first)%K and !(i>=sz(l)-1 and l.back().first*ll(m)%K==0)) {
            if (i>=sz(l)-1) {
                ll os = l.back().first*ll(m);
                ans -= os;
                ans += os%K;
            }
            else ans -= (l.back().first+r.front().first-(l.back().first+r.front().first)%K)*ll(m-1);
            return cout << ans << '\n', 0;
        }
        ans -= (l.back().first+r.front().first)*ll(m-1);
        l.pop_back(), r.pop_front();
    }

    cout << n*ll(m)%K << '\n';
}