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

# -*- coding: utf-8 -*-

import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys

"""
created by shhuan at 2017/10/28 16:57

"""

N, K, M = map(int, input().split())

A = [int(x) for x in input().split()]



def group(a, k):
    if not a:
        return []
    if len(a) < k:
        return a

    ans = []
    p = a[0]
    c = 1
    for v in a[1:]:
        if v == p:
            c += 1
            if c == k:
                c = 0
        else:
            ans += [p] * c
            p = v
            c = 1

    ans += [p] * c

    return ans


A = group(A, K)

rem = []

found = True
while A and found:
    found = False

    if len(set(A)) == 1:
        A = [A[0]] * ((len(A)*M) % K)
        M %= K
        break
    else:
        if K > 2*len(A):
            break
    
        i = 2
        a = group(A*i, K)
        if a and len(a) != len(A)*i:
            rem = A * (M%i) + rem
            A = a
            M //= i
            found = True
            break

A = group(A*M+rem, K)

if A:
    print(len(A))
else:
    print(0)



