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.Vector;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.Stack;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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.nextInt();
      int k = in.nextInt();
      int m = in.nextInt();
      int s[] = in.parseInt1D(n);
      ArrayList<Integer> processed = preProcess(s, k);
      ArrayList<Integer> s1 = new ArrayList<>(processed);
      ArrayList<Integer> s2 = new ArrayList<>(processed);
      if (isAllSame(processed)) {
        out.println((processed.size() * m) % k);
        return;
      }

      countRemaining(s1, s2, m, k);
      if (s2.size() == 0 && s1.size() == 0) {
        if (processed.size() % 2 == 1 && m % 2 == 1) {
          out.println(processed.size());
        } else {
          out.println(0);
        }
      } else {
        int removed = 2 * processed.size() - (s1.size() + s2.size());
        out.println(((long) m * processed.size()) - (removed * ((long) (m - 1))));
      }


    }

    public boolean isAllSame(ArrayList<Integer> al) {
      if (al.size() == 0) return true;
      for (int a : al) {
        if (a != al.get(0)) return false;
      }
      return true;
    }

    public ArrayList<Integer> preProcess(int a[], int k) {

      ArrayList<Node> sb = new ArrayList();
      Stack<Node> stack = new Stack<>();

      for (int i = 0; i < a.length; i++) {
        if (stack.empty()) {
          stack.push(new Node(a[i]));
        } else {
          Node n = stack.peek();
          if (n.value == a[i]) {
            n.count++;
            if (n.count == k) {
              stack.pop();
            }
          } else {
            stack.push(new Node(a[i]));
          }
        }
      }
      while (!stack.isEmpty()) {
        sb.add(stack.pop());
      }
      ArrayList<Integer> al = new ArrayList<>();
      Collections.reverse(sb);
      for (Node n : sb) {
        for (int i = 0; i < n.count; i++) {
          al.add(n.value);
        }
      }
      return al;
    }

    public long countRemaining(ArrayList<Integer> s1, ArrayList<Integer> s2, int m, int k) {
      if (s1.size() == 0) {
        return 0;
      }
      int s1count = 0;
      int charToDelete = s1.get(s1.size() - 1);
      for (int i = s1.size() - 1; i >= 0; i--) {
        if (s1.get(i) == charToDelete) {
          s1count++;
        } else {
          break;
        }
      }
      int s2Count = 0;
      for (int i = 0; i < s2.size(); i++) {
        if (s2.get(i) == charToDelete) {
          s2Count++;
        } else {
          break;
        }
      }

      if (s1count + s2Count < k) {
        return 0; //calc
      } else {
        int rem = (s1count + s2Count) % k;
        for (int i = 0; i < s1count; i++) {
          s1.remove(s1.size() - 1);
        }
        for (int i = 0; i < s2Count; i++) {
          s2.remove(0);
        }
        for (int i = 0; i < rem; i++) {
          s1.add(charToDelete);
        }
        return countRemaining(s1, s2, m, k);
      }


    }

    class Node {
      int value;
      int count = 1;

      Node(int value) {
        this.value = value;
      }

    }

  }

  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 int nextInt() {
      return readInt();
    }

    public int[] parseInt1D(int n) {
      int r[] = new int[n];
      for (int i = 0; i < n; i++) {
        r[i] = nextInt();
      }
      return r;
    }

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

    }

  }
}

