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 <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#define debug puts("-----")
#define pi (acos(-1.0))
#define eps (1e-8)
#define inf (1<<30)
using namespace std;

struct csct
{
	int ct;
	int ti;
};

list<csct> tf;
int n,m,k;
__int64 ans=0;
int main(int argc, char const *argv[])
{
	/* code */
	cin>>n>>k>>m;
	int last=0,lt=0;
	int cur;
	int vsize=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&cur);
		if(cur==last)lt++;
		else{
			int vti=lt%k;
			if(last)
			{
				if(vti)
					{
						tf.push_back({last,vti});
						last=cur;
						lt=1;
					}
				else{
					if(tf.size()&&tf.back().ct==cur)
					{
						lt=tf.back().ti+1;
						last=cur;
						tf.pop_back();
					}
					else
					{
						lt=1;
						last=cur;
					}
				}
			}
		}
	}
	int vti=lt%k;
	if(last&&vti)tf.push_back({last,vti});
	for(auto &i:tf)vsize+=i.ti;
	int ptcsize=vsize;
	while(tf.size()>0&&tf.front().ct==tf.back().ct)
	{
		if(tf.size()==1)break;
		if(tf.front().ti+tf.back().ti==k){
			tf.pop_back();
			tf.pop_front();
			ptcsize-=k;
		}
		else{
			if(tf.front().ti+tf.back().ti>k){
				tf.begin()->ti-=(k-tf.back().ti);
				tf.pop_back();
				ptcsize-=k;
			}
			break;
		}
	}
	if(tf.size()==1)
	{
		ans=1LL*tf.front().ti*m%k;
	}
	else if(tf.size()>1)
	{
		ans=1LL*ptcsize*(m-1)+vsize;
		//cout<<ptcsize<<vsize<<endl;
	}
	else if(tf.size()==0)
	{
		ans=vsize*(m&1);
	}
	printf("%lld\n",ans);
	return 0;
}