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

from collections import deque
n,k,m=map(int,input().split())
queue = deque()
A = list(map(int,input().split()))

for j in range(n):
	
	if queue:
		
		per = queue.pop()
		if A[j] == per[0]:
			per[1] +=1
			if per[1] !=k:
				queue.append(per)
		else:
			queue.append(per)
			queue.append([A[j],1])
	else:
		queue.append([A[j],1])
lens = len(queue)
queue = list(queue)
#print(queue)
if lens ==0:
	print(0)
elif m == 1:
	ans =0
	for j in range(lens):
		ans+=queue[j][1]
	print(ans)
elif lens%2==0:
	p = 0
	for j in range(lens//2):
		if queue[j][0] == queue[-(j+1)][0] and queue[j][1] + queue[-(j+1)][1] == k:
			p+=1
	#print(p)
	
	ans = 0
	l=0
	if p != lens//2:
		for j in range(lens-1,lens-1-p,-1):
			ans-=queue[j][1]
			ans-=queue[-(j+1)][1]
		ans*=(m-1)
		for j in range(lens):
			l+=queue[j][1]
		ans+=l*m
	
	print(ans)
	#print(l*m)
else:
	
	#print('huyznaet')
	p = 0
	for j in range(lens//2):
		if queue[j][0] == queue[-(j+1)][0] and queue[j][1] + queue[-(j+1)][1] == k:
			p+=1
	#print(p)
	
	ans = 0
	l=0
	if p != lens//2:
		for j in range(lens-1,lens-1-p,-1):
			ans-=queue[j][1]
			ans-=queue[-(j+1)][1]
		ans*=(m-1)
		for j in range(lens):
			l+=queue[j][1]
		ans+=l*m
	
		print(ans)
		#print(pizda)
	else:
		if(m*queue[lens//2][1])%k==0:
			print(0)
		else:
			l=0
			for j in range(lens):
				l+=queue[j][1]
			l-= queue[lens//2][1]
			l+=(m*queue[lens//2][1])%k
			print(l)
	#print(l*m)