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.*;
import java.util.*;
import java.math.*;

public class main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;
    public static int N, K;
    public static long M;
    public static ArrayList<Integer> indexes;

    public static ArrayList<Integer> rm(int[] A){
        ArrayList<Integer> stack = new ArrayList<Integer>();
        ArrayList<Integer> cnt = new ArrayList<Integer>();
        indexes = new ArrayList<Integer>();
        for(int i = 0; i < A.length; i++){
            indexes.add(i);
            if(stack.size() > 0 && stack.get(stack.size()-1) == A[i]){
                stack.add(A[i]);
                cnt.add(cnt.size() == 0 ? 1 : cnt.get(cnt.size()-1) + 1);
                if(cnt.get(cnt.size()-1) == K){
                    for(int j = 0; j < K; j++){
                        stack.remove(stack.size()-1);
                        cnt.remove(cnt.size()-1);
                    }
                }
            } else{
                stack.add(A[i]);
                cnt.add(1);
            }
        }
        return stack;
    }

    public static void main(String[] args) throws Exception{
        st = new StringTokenizer(br.readLine());
        N = Integer.parseInt(st.nextToken());
        K = Integer.parseInt(st.nextToken());
        M = Long.parseLong(st.nextToken());
        int[] A = new int[N];
        st = new StringTokenizer(br.readLine());
        for(int i  = 0; i < N; i++){
            A[i] = Integer.parseInt(st.nextToken());
        }
        ArrayList<Integer> B = rm(A);
        int[] A2 = new int[B.size()*2];
        for(int i = 0; i < B.size()*2; i++){
            A2[i] = B.get(i%B.size());
        }
        // System.out.println(Arrays.toString(A2));
        ArrayList<Integer> B2 = rm(A2);
        long ans = B2.size() * (N/2);
        boolean f = true;
        for(int i = 1; i < B2.size(); i++){
            if(B2.get(i) != B2.get(i-1)){
                f = false;
                break;
            }
        }
        // System.out.println(B2);
        if(f){
            int k = B2.size() > 0 ? B2.get(0) : -1;
            ans = (B2.size() * ((M / 2))) % K;
            if(M % 2 != 0){
                long cnt = ans;
                ans += B2.size();
                for(int i = 0; i < B2.size(); i++){
                    if(B2.get(i) == k){
                        cnt++;
                        if(cnt == K){
                            ans = B2.size() - i - 1;
                            break;
                        }
                    }
                }
            }
        } else{
            if(M % 2 == 1){
                int[] C = new int[B2.size() + B.size()];
                for(int i = 0; i < B2.size(); i++){
                    C[i] = B2.get(i);
                }
                for(int i = 0; i < B.size(); i++){
                    C[i+B2.size()] = B.get(i);
                }
                ArrayList<Integer> C2 = rm(C);
                                // System.out.println(ans);
                // ans = (ans - B2.size()) + C2.size();
            }
        }
        pw.print(ans + "\n");
        pw.close(); 
        br.close();
    }
}

class Pair{
    public int x, y, k, dir;

    Pair(int _x, int _y, int _k, int dir){
        x = _x;
        y = _y;
        k = _k;
        this.dir = dir;
    }
}
class Point implements Comparable<Point>{
    public double x, y;

    Point(double x, double y){
        this.x = x;
        this.y = y;
    }

    public int compareTo(Point p){
        if(x != p.x) return x < p.x ? -1 : 1;
        else if(y != p.y) return y < p.y ? -1 : 1;
        return 0;
    }
}