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 = input().strip().split()
n = int(n)
k = int(k)
m = int(m)
a = list(map(int, input().strip().split()))
x = []

if n>1:
  y = []
  for i in range(n+1):
    y.append(1)
  pre = 0
  nex = 1
  z = {}
  tup = {}
  tup[0] =1
  kol =1
  while nex <n:
    if nex not in tup:
      tup[nex] = nex-1
    if a[nex] == a[pre]:
      y[nex] = y[pre] + kol
      kol = kol + 1
    else:
      kol = 1
      pre = nex
    if y[nex] ==k:
      kol = 1
      z[pre- y[pre] +1] = nex
      if tup[pre] <=0 or pre ==0:
        pre = nex +1
        tup[pre] = -1
        nex = nex + 1
      else:
        pre = tup[pre - y[pre] + 1]
        tup[nex + 1] =  pre


    nex = nex + 1
  i = 0
  p =[]
  while i <= n-1:
    if i in z:
      i = z[i] +1
    else:
      p.append(a[i])
      i = i +1
      
  a = p[:]
n = len(a)
kol = 1
for i in range(n):
  if i ==0:
    x.append((a[i],kol))
  else:
    if a[i] == a[i-1]:
      kol +=1
      x.append((a[i],kol))
    else:
      kol = 1
      x.append((a[i],kol))

i = n-1
s = 2 * n
l=0
if len(a) ==0:
  print(0)
else:
  if k>=n:
    for i in range(n):
      if (i>0 and a[i]!=a[i-1]):
        l =1
        break
    if l==1:
      print(n*m)
    else:
      if k <= n*m:
        print((n *m) % k)
      else:
        print(n*m)
  else:
    l=0
    for i in range(n//2):
      if a[i] != a[n - i-1]:
        l = 1
    if l==0:
      print(0)
    else:
      s = 0
      i = n-1
      j = 0
      while i  >= 0:
        tt =0
   
        while(j <n -1 and x[i][0] == x[j][0]):
          tt =1
          j +=1
        if tt ==1 and j !=n-1:
          j -= 1
        cur=x[i][1] + x[j][1]
        if  tt==1 and cur>=k:
          if i !=j:
            s += ((cur //k) * k) * (m-1)
            i = i - (x[i][1] - (cur %k))
            j = j + 1
          else:
            s+=  cur *(m//2)
            i = i - (x[i][1] - (cur %k))
            j = j + 1
  
        else:
          i = -1
          break
      s = n*m-s
      print(s)