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

def readS(): return raw_input()
def readN(): return int(readS())
def readLS(): return raw_input().split()
def readLN(): return [int(x) for x in readLS()]
def matrix(height, width): return [[None for i in xrange(width)] for j in xrange(height)]

n, k, m = readLN()
a = readLN()

def max_sub(a):
	n, s = 1, 0
	maxn, maxs = 0, 0,
	for i in xrange(1, len(a)):
		if a[i] == a[i - 1]:
			n += 1
		else:
			if n >= k:
				return (n, s)
			if n > maxn:
				maxn, maxs = n, s
			n, s = 1, i
	return maxn, maxs

def f(pref, a, am, suf):
	# print pref, a, am, suf

	# stop conditions
	if pref == [] and suf == [] and a == []:
		return 0
	elif a == []:
		return f([], pref + suf, 1, [])
	elif len(a) <= k and pref == [] and suf == []:
		b = [x == a[0] for x in a]
		if all(b):
			return len(a) * am % k
		else:
			return len(a) * am

	# try middle
	mn, ms = max_sub(a)
	if mn >= k:
		return f(pref, a[ms + k : ] + a[ : ms], am, suf)

	# try borders
	if a[0] == a[-1] and am >= 2:
		ml = 1
		while ml < len(a) and a[0] == a[ml]:
			ml += 1
		mr = 1
		while mr < len(a) and a[-1] == a[-(mr + 1)]:
			mr += 1
		if ml + mr >= k:
			ml = min(ml, k)
			mr = k - ml
			return f(pref + a[ : -mr], a[ml : -mr], am - 2, a[ml : ] + suf)

	if pref == [] and suf == []:
		return len(a) * am

	# try left
	if am:
		pref = pref + a
		am -= 1
	mn, ms = max_sub(pref)
	if mn >= k:
		return f(pref[ : mn] + pref[mn + k : ], a, am, suf)

	# try right
	if am:
		suf = a + suf
		am -= 1
	mn, ms = max_sub(suf)
	if mn >= k:
		return f(pref, a, am, suf[ : mn] + suf[mn + k : ])

	return len(pref) + len(a) * am + len(suf)


print f([], a, m, [])
