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>
#define int long long
using namespace std;
const int maxn = 1e5+7;
typedef pair<int,int> P;
int a[maxn];
P ps[maxn];
int top,n,m,num,l,r,rec,rec2;
long long ans,k;
main(){
	cin>>n>>k>>m;
	for(int i = 1;i <= n;++i)scanf("%lld",&a[i]);
	for(int i = 1;i <= n;++i){
		if(!top || ps[top].first != a[i]) ps[++top] = make_pair(a[i],1);
		else ps[top].second = (ps[top].second + 1)%k;
		if(ps[top].second == 0) --top;
	}
	for(int i = 1;i <= top;++i) rec += ps[i].second;
	l = 1,r = top;
	while(l < r && ps[l].first == ps[r].first && (ps[l].second+ps[r].second)%k==0) 
		l++,r--,rec2 += ps[l].second+ps[r].second;
	if(l == r){
		if(ps[l].second*m%k == 0){
			ans -= rec2;
		}
		ans += m*rec-rec2*(m-1)-(ps[l].second*m)+(ps[l].second*m%k);
	}
	else{
		if(ps[l].first == ps[r].first)
			rec2 += (ps[l].second+ps[r].second)/k*k;
		ans = m*rec-rec2*(m-1);
	}
	cout<<ans<<endl;
	return 0;
} 
