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

n, k, m = map(int, input().split())
a = list(map(int, input().split()))

if not (n == 1 and k == m):
	import array
	c = array.array('I', [a[0]])
	d = array.array('I', [1])
	for i in range(1, m*n):
		if c and c[-1] == a[i%n]:
			if d[-1] == k - 1:
				del c[-1]
				del d[-1]
			else:
				d[-1] += 1
		else:
			c.append(a[i%n])
			d.append(1)				
	print(len(c))
else:
	print(0)
