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>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 900100;
int n, m, k, cnt[N], a[N];
void solve(vector < int > &v){
    stack < int > s;
    int c = 0;
    int x = -1;
    for (int i = 0; i < v.size(); i++){
        s.push(v[i]);
        if (x != v[i]){
            c = 0;
            x = v[i];
        }
        if (x == v[i]) c++;
        if (c == k){
            for (int j = 0; j < k; j++) s.pop();
            c = 0;
            if (s.empty()) x = -1; else{
                x = s.top();
                c = 1;
            }
        }
    }
    vector < int > u;
    while(!s.empty()){
        u.pb(s.top());
        s.pop();
    }
    reverse(u.begin(), u.end());
    v = u;
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector < int > v, l, r;
    cin >> n >> k >> m;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        v.pb(a[i]);
        cnt[a[i]]++;
    }
    if (k >= n){
        if (cnt[a[1]] == n){
            cout << n * m % k;
            return 0;
        } else{
            cout << 0;
            return 0;
        }
    }
    solve(v);
    int L = 0;
    int R = (int)v.size() - 1;
    while(k < R - L + 1){
        int c = 0;
        int L0 = L;
        int R0 = R;
        while(v[L] == v[L0] && c < k){
            c++;
            L++;
        }
        while(v[R] == v[L0] && c < k){
            R--;
            c++;
        }
        if (c == k){
            for (int j = L0; j < L; j++) l.pb(v[j]);
            for (int j = R0; j > R; j--) r.pb(v[j]);
            continue;
        }
        c = 0;
        L = L0;
        R = R0;
        while(L < R && v[L] == v[R0] && c < k){
            c++;
            L++;
        }
        while(R >= L && v[R] == v[R0] && c < k){
            R--;
            c++;
        }
        if (c == k){
            for (int j = L0; j < L; j++) l.pb(v[j]);
            for (int j = R0; j > R; j--) r.pb(v[j]);
            continue;
        }
        L = L0;
        R = R0;
        break;
    }
    if (L <= R){
        memset(cnt, 0, sizeof(cnt));
        for (int i = L; i <= R; i++) cnt[v[i]]++;
        if (cnt[v[L]] == R - L + 1){
            int x = (R - L + 1) * m;
            for (int i = 0; i < x % k; i++) l.pb(v[L]);
            reverse(r.begin(), r.end());
            for (auto i: r) l.pb(i);
            solve(l);
            cout << l.size() << endl;
            return 0;
        }
    }
    int x = (R - L + 1) * m;
    vector < int > f;
    for (int i = L; i <= R; i++) f.pb(v[i]);
    if (l.size() + r.size() + 100 * n < x){
        int sz1 = l.size();
        for (int i = 0; i < 50 * n; i++){
            l.pb(f[i % (R - L + 1)]);
        }
        solve(l);
        reverse(f.begin(), f.end());
        int sz2 = r.size();
        for (int i = 0; i < 50 * n; i++){
            r.pb(f[i % (R - L + 1)]);
        }
        solve(r);
        cout << x - 100 * n + l.size() + r.size() << endl;
        return 0;
    }
    for (int i = 0; i < x; i++)
        l.pb(f[i % (R - L + 1)]);
    reverse(r.begin(), r.end());
    for (int i = 0; i < r.size(); i++) l.pb(r[i]);
    solve(l);
    cout << l.size() << endl;
}
