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 <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;

const int mx = 200010;

typedef long long ll;

struct info
{
    int a, num;
    info(){}
    info(int _1, int _2)
    {
        a = _1;
        num = _2;
    }
};

vector <info> Ori, Ans;

int n, k, m;

void reduce(vector <info> &X)
{
    vector <info> tmp;
    tmp.clear();
    for(int i = 0; i < X.size(); i++)
        if(tmp.size() == 0 || tmp.back().a != X[i].a) tmp.push_back(X[i]);
        else {
            tmp.back().num = (tmp.back().num + X[i].num) % k;
            if(tmp.back().num == 0) tmp.pop_back();
        }
    X = tmp;
}

ll len(vector <info> &X)
{
    ll ans = 0;
    for(int i = 0; i < X.size(); i++) ans += X[i].num;
    return ans;
}

int main()
{
    scanf("%d%d%d", &n, &k, &m);
    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        Ori.push_back(info(x, 1));
    }
    reduce(Ori);
    if(Ori.size() == 1) {
        printf("%lld\n", (ll) Ori[0].num * m % k);
        return 0;
    }
    ll prelen = len(Ori), sz = Ori.size();
    for(int i = 0; i < sz; i++) Ori.push_back(Ori[i]);
    reduce(Ori);
    if(Ori.size() == 0) {
        if(m % 2 == 1) printf("%lld\n", prelen); else puts("0");
    } else if(Ori.size() == sz) {
        assert(sz % 2 == 1);
        int o = Ori[sz / 2].num, g = __gcd(o, k);
        if((ll) o * m % k == 0) {
            puts("0");
            return 0;
        } else {
            printf("%lld\n", prelen - o + (ll) o * m % k);
            return 0;
        }
    } else {
        ll delt = len(Ori) - prelen;
        printf("%lld\n", delt * (m - 1) + prelen);
    }
    return 0;
}
