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():
    read = lambda: tuple(map(int, input().split()))

    n, k, m = read()

    l = read()

    lk = []
    lv = -1
    for v in l:
        if lv == v: lk[-1][0] += 1
        else: lk += [[1, v]]
        lv = v

    def suka(i1, i2):
        pp1, pp2 = 0, 0
        while i1 <= i2:
            v1, v2 = lk[i1], lk[i2]
            if v1[1] == v2[1]:
                pp1 += v1[0] % k
                if i1 != i2:
                    pp2 += v2[0] % k
            else:
                break
            i1, i2 = i1 + 1, i2 - 1
        return i1, i2, pp1, pp2
    i1, i2, pp1, pp2 = suka(0, len(lk) - 1)

    if len(lk) == 1:
        return lk[0][0] * m % k
    else:
        v = sum([v[0] % k for v in lk[i1:i2+1]]) * m
        if i1-2 != i2: v += pp1 + pp2
        #print("=", v)
        if m % 2 == 1:
            #print("m =", m, lk[i1-1:i2+2])
            v += sum([v[0] % k for v in lk[i1-1:i2+2]])
    #print(lk)
    #print(i1, i2, lk[i1:i2+1], sum([v[0] % k for v in lk[i1:i2+1]]))
    return v
print(main())
