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.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created by shhuan on 2017/11/5.
 */
public class Main_878B {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int M = scanner.nextInt();
		scanner.nextLine();

		int[] A = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(v -> Integer.parseInt(v)).toArray();

		Stack<Pair> S = new Stack<>();
		for (int v : A) {
			if (S.isEmpty()) {
				S.push(new Pair(v, 1));
			} else {
				Pair l = S.peek();
				if (l.x == v) {
					S.pop();
					int y = l.y + 1;
					if (y != K) {
						S.push(new Pair(l.x, (l.y+1) % K));
					}
				} else {
					S.push(new Pair(v, 1));
				}
			}
		}

		Long ans = 0L;
		if (S.isEmpty()) {
			ans = 0L;
		} else if (S.size() == 1) {
			ans = 1L*M*S.get(0).y % K;
		} else {
			int l = -1;
			for (int i = 0; i < S.size()/2+1; i++) {
				Pair p1 = S.get(i);
				Pair p2 = S.get(S.size()-i-1);
				if (p1.x != p2.x || p1.y+p2.y != K) {
					break;
				}
				l = i;
			}

			int r = S.size()-l-1;
			if (l < 0){
				Pair p1 = S.get(0);
				Pair p2 = S.get(S.size()-1);
				if (p1.x == p2.x && p1.y+p2.y > K) {
					ans = 0L;
					for (int i = 1; i < S.size()-1; i++) {
						ans += S.get(i).y;
					}
					ans *= M;
					ans += (M-1) * ((p1.y+p2.y) % K);
					ans += p1.y + p2.y;
				} else {
					ans = S.stream().mapToLong(v -> v.y).sum();
					ans *= M;
				}
			} else if (r < l+2) {
				if (M % 2 == 0) {
					ans = 0L;
				} else {
					ans = S.stream().mapToLong(v -> v.y).sum();
				}
			} else if (r == l+2) {
				ans = 0L;
				int mid = (M * S.get(l+1).y) % K;
				ans += mid;
				if (mid == 0 && S.get(l).x == S.get(r).x && S.get(l).y + S.get(r).y >= K) {
					for (int i = 0; i < l; i++) {
						ans += S.get(i).y;
					}
					for (int i = r+1; i < S.size(); i++) {
						ans += S.get(i).y;
					}
					ans += (S.get(l).y + S.get(r).y) % K;
				} else {
					Long a = ans;
					for (int i = 0; i <= l; i++) {
						ans += S.get(i).y;
					}
					Long b = ans;
					for (int i = r; i < S.size(); i++) {
						ans += S.get(i).y;
					}
					if (ans == 99592L) {
						System.out.println(mid);
						System.out.println(a);
						System.out.println(b);
						System.out.println(S.get(l+1).y);
						System.out.println(M*S.get(l+1).y);
						System.out.println(K);
						System.out.println((M*S.get(l+1).y) % K);
					}
				}
			} else {
				Pair p1 = S.get(l+1);
				Pair p2 = S.get(r-1);
				if (p1.x != p2.x || p1.y+p2.y < K) {
					ans = 0L;
					for (int i = l+1; i < r; i++) {
						ans += S.get(i).y;
					}
					ans *= M;
				} else {
					for (int i = l+2; i < r-1; i++) {
						ans += S.get(i).y;
					}
					ans *= M;
					ans += (M-1) * ((p1.y + p2.y) % K);
					ans += p1.y + p2.y;
				}
				for (int i = 0; i <= l; i++) {
					ans += S.get(i).y;
				}
				for (int i = r; i < S.size(); i++) {
					ans += S.get(i).y;
				}
			}
		}

		System.out.println(ans);
	}

	static class Pair{
		public int x;
		public int y;

		public Pair() {
			x = 0;
			y = 0;
		}

		public Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
}
