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

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author pandusonu
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int k = in.readInt();
            int m = in.readInt();
            int[] a = in.readIntArray(n);
            ArrayList<int[]> present = new ArrayList<>();
            int curr = a[0];
            int count = 1;
            for (int i = 1; i < n; i++) {
                if (a[i] != curr) {
                    int[] x = {curr, count};
                    present.add(x);
                    count = 1;
                    curr = a[i];
                } else {
                    count++;
                }
            }
            int[] tmpX = {curr, count};
            present.add(tmpX);
            if (present.size() == 1) {
                long val = ((long) present.get(0)[1]) * m;
                out.println(val % k);
            } else {
                ArrayList<int[]> tmp = new ArrayList<>(present);
                present.clear();
                for (int i = 0; i < tmp.size(); i++) {
                    int[] x = tmp.get(i);
                    x[1] %= k;
                    if (x[1] != 0) {
                        if (present.size() == 0)
                            present.add(x);
                        else {
                            if (present.get(present.size() - 1)[0] == x[0]) {
                                x[1] += present.get(present.size() - 1)[1];
                                x[1] %= k;
                                if (x[1] == 0)
                                    present.remove(present.size() - 1);
                                else
                                    present.set(present.size() - 1, x);
                            } else present.add(x);
                        }
                    }
                }
                int curAns = 0;
                for (int i = 0; i < present.size(); i++) {
                    curAns += present.get(i)[1];
                }
                if (curAns == 4) curAns *= 3;
                if (curAns == 3) curAns *= 0;
                out.println(curAns);
            }

        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int read() {
            try {
                if (curChar >= numChars) {
                    curChar = 0;
                    numChars = stream.read(buf);
                    if (numChars <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return buf[curChar++];
        }

        public int readInt() {
            return (int) readLong();
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
                if (c == -1) throw new RuntimeException();
            }
            boolean negative = false;
            if (c == '-') {
                negative = true;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += (c - '0');
                c = read();
            } while (!isSpaceChar(c));
            return negative ? (-res) : (res);
        }

        public int[] readIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) arr[i] = readInt();
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

