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

import math
import copy
import sys
# def p(case, res):
# 	print "Case #"+str(case+1)+": "+str(res)

n, k, m = map(int, raw_input().split())
# for i in range(0,n):	
lst = map(int, raw_input().split())
# lst.sort()

if k == 1:
	print 0
	sys.exit()

ttmp = len(set(lst))
if ttmp == 1:
	print (ttmp*m - ((ttmp*m)/k)*k)
	sys.exit()

lcpoy = copy.copy(lst)
l2 = []
stackTop = lst[0]
stack = [stackTop]
currentCount = 1 
for j in lst[1:]:
	# print 'stack: ',stack, ', j =', j, ', st=',stackTop
	if stackTop != None and j == stackTop:
		currentCount += 1
		# print currentCount
		if currentCount == k:
			del stack[-1]
			currentCount = 0
			if len(stack) != 0:
				stackTop = stack[-1]
				currentCount = 0
				while len(stack) != 0 and stack[-1] == stackTop:
					currentCount += 1
					del stack[-1]
				stack.append(stackTop)
			else:
				stackTop = None
	else:
		# print 'stack: ', stack
		# print 'else'
		if stackTop != None and currentCount > 1:
			stack += ([stackTop]*(currentCount-1))
		currentCount = 1
		# print currentCount

		stack.append(j)
		stackTop = j
	# print "fucl"
		

# print lst
lst = stack

ttmp = len(set(lst))
if ttmp == 1:
	print (ttmp*m - ((ttmp*m)/k)*k)
	sys.exit()


# print lst
if len(lst) == 0:
	print 0
	sys.exit()
l0 = len(lst)

lcpoy = copy.copy(lst)
# l2 = []
stackTop = lst[0]
stack = [stackTop]
currentCount = 1
lst = lst + lst 
# print lst
for j in lst[1:]:
	# print 'stack: ',stack, ', j =', j, ', st=',stackTop
	if stackTop != None and j == stackTop:
		currentCount += 1
		# print currentCount
		if currentCount == k:
			del stack[-1]
			currentCount = 0
			if len(stack) != 0:
				stackTop = stack[-1]
				currentCount = 0
				while len(stack) != 0 and stack[-1] == stackTop:
					currentCount += 1
					del stack[-1]
				stack.append(stackTop)
			else:
				stackTop = None
	else:
		# print 'stack: ', stack
		# print 'else'
		if stackTop != None and currentCount > 1:
			stack += ([stackTop]*(currentCount-1))
		currentCount = 1
		# print currentCount

		stack.append(j)
		stackTop = j
	# print "fucl"


lst = stack
# print lst
l1 = len(lst)

if l1 == 0:
	l2 = 0
else:
	# lcpoy = copy.copy(lst)
	# l2 = []
	stackTop = lst[0]
	stack = [stackTop]
	currentCount = 1
	lst = lst + lcpoy 
	for j in lst[1:]:
		# print 'stack: ',stack, ', j =', j, ', st=',stackTop
		if stackTop != None and j == stackTop:
			currentCount += 1
			# print currentCount
			if currentCount == k:
				del stack[-1]
				currentCount = 0
				if len(stack) != 0:
					stackTop = stack[-1]
					currentCount = 0
					while len(stack) != 0 and stack[-1] == stackTop:
						currentCount += 1
						del stack[-1]
					stack.append(stackTop)
				else:
					stackTop = None
		else:
			# print 'stack: ', stack
			# print 'else'
			if stackTop != None and currentCount > 1:
				stack += ([stackTop]*(currentCount-1))
			currentCount = 1
			# print currentCount

			stack.append(j)
			stackTop = j
		# print "fucl"
	# print stack
	l2 = len(stack) - l1
# print l0, l1, l2
# if len(set(lst)) == 1:
# 	print len(lst)*m - ((len(lst)*m)/k)*k
# 	sys.exit()
if m == 1:
	print l0
elif m == 2:
	print l1
else:
	print l1 + l2*(m-2)

