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


def main():
    n, k, m = [int(x) for x in input().split()]
    a = []
    last = ("", 0)
    for ai in input().split():
        if last[0] == ai:
            last = (ai, last[1]+1)
            a[len(a)-1] = last
        else:
            last = (ai, 1)
            a.append(last)

        if last[1] == k:
            del a[len(a)-1]
            last = a[len(a)-1]

    s1 = 0
    while a[0][0] == a[len(a)-1][0]:
        if len(a) == 1:
            s = a[0][1] * m
            print(s1 % k + s % k)
            return

        if a[0][1] + a[len(a)-1][1] == k:
            s1 += k
            del a[len(a)-1]
            del a[0]
        elif a[0][1] + a[len(a)-1][1] > k:
            s1 += a[0][1] + a[len(a)-1][1]
            a[0] = (a[0][0], a[0][1]+a[len(a)-1][1]-k)
            del a[len(a) - 1]
            break

    s = 0
    for ai in a:
        s += ai[1]

    print(s*m + s1)


if __name__ == "__main__":
    main()
