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()]
#
# N, K, M = 100000, 42, 1000
# A = [random.randint(1, 10) for _ in range(N)]

def merge(a, k):
    if not a:
        return False, []
    if len(a)*2 < k:
        return False, a

    v = a[0]
    i = 0
    while i < len(a) and a[i] == v:
        i += 1
    j = len(a)-1
    while j >= 0 and a[j] == v:
        j -= 1

    if i > j:
        return True, []
    else:
        n = i + len(a) - j - 1
        if n >= k:
            return True, a[:j+1] + [a[0]] * (n-k) + a[i:]

    return False, a

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
        else:
            c %= k
            if c > 0:
                ans += [p] * c
                c = 0
            else:
                for i in range(len(ans)-1, -1, -1):
                    if ans[i] == v:
                        c += 1
                    else:
                        break
                ans = ans[:len(ans)-c]
            c += 1
            p = v
    ans += [p] * (c % k)

    return ans


A = group(A, K)

rem = []

found = True
while M > 1 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

        f, a = merge(A, K)
        if f:
            rem = group(A * (M % 2) + rem, K)
            A = a
            M //= 2
            found = True

if not rem:
    print(len(A) * M)
else:
    if M > 0:
        ans = len(A) * (M-1)
        A = group(A + rem, K)
        ans += len(A)
        print(ans)
    else:
        print(len(group(rem, K)))