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

r=lambda:map(int,input().split())
n,k,m=r()
a=list(r())
stck=[]
stck
if k==1:
	print(0)
	exit(0)
if n==1 and m >=k:
	print(m%k)
	exit(0)
for i in range(n):#this is team formation possible in a bus itself
	if len(stck)==0:
		stck.append((a[i],1))
		prevV=a[i]
		prevL=1			
	elif a[i]==prevV:
		prevL+=1
		stck=stck[:len(stck)-prevL+1]
		stck+=[(a[i],prevL)]*prevL
	else:
		stck.append((a[i],1))
		prevV=a[i]
		prevL=1
	if prevL==k:
		stck=stck[:len(stck)-k]
last=[stck[len(stck)-1][0],stck[len(stck)-1][1]]
it=0
ans=0
while True:
	p=0
	r=len(stck)
	for i in range(r//2):
		if stck[i][0]==stck[r-i-1][0] and stck[i][1]+stck[r-i-1][1]==k:
			p+=1
	if p==(r//2) and m%2==0 and p!=0:
		print(0)
		exit(0)
	elif p==(r//2) and m%2 !=0 and p!=0:
		if r%2!=0:
			print(r)
			exit(0)
		else:
			print(0)
			exit(0)
	elif p!=(r//2) and p>0:
		ans+=(m*r-(m-1)*(k*p))
		stck=stck[:r-stck[r-1][1]]
	elif stck[0][1]<len(stck) and  stck[r-1][1]+stck[stck[0][1]][1]==k and stck[r-1][0]==stck[stck[0][1]][0]:
		ans+=k*(m-1)
		stck=stck[:r-stck[r-1][1]]
	elif stck[r-1][1]+last[1]==k and stck[r-1][0]==last[0]:
		print(0)
		exit(0)
	elif p==0:
		break
	it+=1
if it==0:
	print(m*r)
else:
	print(ans)
