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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Deque;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int k = in.readInt();
            int m = in.readInt();
            List<IntIntPair> all = new ArrayList<>(n); //{type, size}
            for (int i = 0; i < n; i++) {
                int type = in.readInt();
                if (!all.isEmpty() && all.get(all.size() - 1).first == type) {
                    if (last(all).second == k - 1) {
                        all.remove(all.size() - 1);
                    } else {
                        all.set(all.size() - 1, IntIntPair.makePair(type, last(all).second + 1));
                    }
                } else {
                    all.add(IntIntPair.makePair(type, 1));
                }
            }

            long size = 0;
            for (IntIntPair p : all) {
                size += p.second;
            }
            size *= m;

            if (all.size() == 1) {
                out.print(size % k);
                return;
            }
            if (m == 1 || size == 0 || all.get(0).first != last(all).first) {
                out.print(size);
                return;
            }
            if ((all.get(0).second + last(all).second) % k != 0) {
                long remove = all.get(0).second + last(all).second;
                remove = remove / k * k;
                size -= (m - 1) * remove;
                out.print(size);
                return;
            }

            Deque<IntIntPair>[] parts = new Deque[3];
            parts[0] = new ArrayDeque<>(all);
            parts[1] = new ArrayDeque<>(all);
            parts[2] = new ArrayDeque<>(all);

            while (true) {
                if (parts[1].size() == 1) {
                    long middle = parts[1].peek().second * (long) m;
                    if (middle % k == 0) {
                        size -= middle;
                        parts[0].pollLast();
                        parts[2].pollFirst();
                        size -= merge(parts[0], parts[2], k);
                        break;
                    } else {
                        size -= middle / k * k;
                        break;
                    }
                }
                if (parts[1].peekFirst().first != parts[1].peekLast().first) {
                    break;
                }
                long curSize = parts[1].peekFirst().second + parts[1].peekLast().second;
                if (curSize % k != 0) {
                    size -= (m - 1) * (curSize / k * k);
                    break;
                } else {
                    parts[1].pollFirst();
                    parts[1].pollLast();
                    size -= (m - 1) * curSize;
                    parts[0].pollLast();
                    parts[2].pollFirst();
                }
            }

            out.print(size);
        }

        int merge(Deque<IntIntPair> q1, Deque<IntIntPair> q2, int k) {
            int result = 0;
            while (!q1.isEmpty()) {
                if (q1.peekLast().first != q2.peekFirst().first) {
                    break;
                }
                int sz = q1.pollLast().second + q2.pollFirst().second;
                result += sz / k * k;
                if (sz % k != 0) {
                    break;
                }
            }
            return result;
        }

        <T> T last(List<T> a) {
            return a.get(a.size() - 1);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(long i) {
            writer.print(i);
        }

    }

    static class IntIntPair implements Comparable<IntIntPair> {
        public final int first;
        public final int second;

        public static IntIntPair makePair(int first, int second) {
            return new IntIntPair(first, second);
        }

        public IntIntPair(int first, int second) {
            this.first = first;
            this.second = second;
        }


        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            IntIntPair pair = (IntIntPair) o;

            return first == pair.first && second == pair.second;
        }


        public int hashCode() {
            int result = first;
            result = 31 * result + second;
            return result;
        }


        public String toString() {
            return "(" + first + "," + second + ")";
        }

        @SuppressWarnings({"unchecked"})
        public int compareTo(IntIntPair o) {
            int value = Integer.compare(first, o.first);
            if (value != 0) {
                return value;
            }
            return Integer.compare(second, o.second);
        }

    }

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

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

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

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

