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>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*\n"
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define long int64_t
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef priority_queue<int, vector<int>, greater<int>> min_pq;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int N = 100001;

int main()
{
	fio;
	int n, k, m;
	cin >> n >> k >> m;
	vector<pii> v;
	for(int i=0; i<n; i++)
	{
		int a;
		cin >> a;
		if(!v.empty() and v.back().ff == a)
			v.back().ss++;
		else
			v.pb(mp(a, 1));
		if(v.back().ss == k)
			v.pop_back();
	}
	int tot = 0;
	for(auto &it : v)
		tot += it.ss;
	if(m == 1)
	{
		cout << tot << endl;
		return 0;
	}
	int sz = v.size(), p = 0, sum = 0;
	while(v[p].ff == v[sz-p-1].ff and v[p].ss + v[sz-p-1].ss == k)
	{
		sum += k;
		p++;
	}
	if(p == sz)
		cout << ((m & 1) ? sz : 0) << endl;
	else if(p == (sz >> 1))
		cout << ((v[p].ss * 1ll * m) % k ? (v[p].ss * 1ll * m) % k + sum : 0) << endl;
	else
	{
		if(v[p].ff == v[sz-p-1].ff and v[p].ss + v[sz-p-1].ss > k)
			sum += k;
		cout << tot * 1ll * m - sum * 1ll * (m-1) << endl;
	}
	return 0;
}