← Home
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define MAXN 100100
int a[MAXN];
 
ostringstream out;
int n, k, m;
 
int solve(int l, int r) {
    if(l>r) return 0;
    int sz=r-l+1;
    int ce=0, cb=0;
    int ed=a[r];
    for(int i=l;i<=r;i++) {
        if(a[i]!=ed) break;
        ++cb;
    }
    for(int i=r;i>=l;i--) {
        if(a[i]!=ed) break;
        ++ce;
    }
    if(cb==sz) return (sz*m)%k;
    if((ce+cb)%k) return (ce+cb)%k*(m-1)+(sz-ce-cb)*m+ce+cb;
    int ans=solve(l+cb, r-ce);
    if(ans) ans+=ce+cb;
    return ans;
}
 
int32_t main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> k >> m;
    for(int i=1;i<=n;i++) cin >> a[i];
    stack<pair<int, int>> st;
    st.push({0, 0});
    for(int i=1;i<=n;i++) {
        if(st.top().first!=a[i]) st.push({a[i], 1});
        else {
            st.top().second++;
            if(st.top().second==k) st.pop();
        }
    }
    int lst=0;
    vector<pair<int, int>> vc;
    while(st.top().first) {
        vc.push_back(st.top());
        st.pop();
    }
    reverse(vc.begin(), vc.end());
    for(auto pr : vc) {
        while(pr.second--) a[++lst]=pr.first;
    }
    cout << solve(1, lst) << endl;
    return 0;
}