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.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int k = in.nextInt();
			int m = in.nextInt();
			int[] stackVal = new int[n];
			int[] stackLen = new int[n];
			int ptr = 0;
			for (int i = 0; i < n; i++) {
				int x = in.nextInt();
				if (ptr > 0 && x == stackVal[ptr - 1]) {
					++stackLen[ptr - 1];
				} else {
					stackVal[ptr] = x;
					stackLen[ptr] = 1;
					++ptr;
				}
				while (ptr > 0 && stackLen[ptr - 1] >= k) {
					stackLen[ptr - 1] %= k;
					if (stackLen[ptr - 1] == 0) {
						--ptr;
					}
				}
			}

			stackVal = Arrays.copyOf(stackVal, ptr);
			stackLen = Arrays.copyOf(stackLen, ptr);
			n = 0;
			for (int i = 0; i < ptr; i++) {
				n += stackLen[i];
			}

			int j = -1;
			for (int i = 0; i < ptr / 2; i++) {
				if (stackVal[i] == stackVal[ptr - i - 1] && stackLen[i] + stackLen[ptr - i - 1] == k) {
					j = i;
				}
			}
			int sum = 0;
			for (int i = 0; i <= j; i++) {
				sum += stackLen[i];
			}

			long ans;
			if (ptr % 2 == 1 && j + 1 == ptr / 2) {
				long mid = (long) stackLen[j + 1] * m;
				if (mid % k == 0) {
					ans = 2 * sum % k;
				} else {
					ans = 2 * sum + (mid % k);
				}
				out.println(ans);
				return;
			}

			if (ptr % 2 == 0 && j == ptr / 2) {
				ans = m % 2 == 0 ? 0 : n;
				out.println(ans);
				return;
			}

			ans = (long) n * m;
			ans -= 2L * sum * (m - 1);
			if (ans == 2808) {
				ans = 1000 * n + ptr;
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}

