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=[]
p=0
for i in input().split():
    x=int(i)
    if x==p:
        a[-1][1]+=1
    else:
        p=x
        a.append([x,1])
b=[]
r=len(a)
c=0
for i in range(r//2):
    c = (a[i][1] + a[r - 1 - i][1]) % k
    if a[i][0]!=a[r-1-i][0] or c:
        if c:
            b.append([a[i][0],c])
        for j in range(i+1,r-i-1):
            b.append(a[j])
            c+=a[j][1]
        break
    b.append(a[i])
    if i==n//2-1:exit(print(0))
print(n+c*(m-1))