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

public class b {

    static int[] arr;
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        
        int n = in.nextInt();
        long k = in.nextInt();
        long m = in.nextLong();
        
        arr = in.nextIntArray(n);
        long ans = 0;
        if (m == 1) {
            // brute force
            ArrayList<Pair> tmp = new ArrayList<>();
            Pair q = null;
            for (int i = 0; i < n; i++) {
                if (q == null || q.v != arr[i]) {
                    q = new Pair(arr[i], 0);
                    tmp.add(q);
                }
                q.count++;
            }
            for (int i = 0; i < tmp.size(); i++) {
                Pair p = tmp.get(i);
                if (i > 0) p.prev = tmp.get(i - 1);
                if (i + 1 < tmp.size()) p.next = tmp.get(i + 1);
            }
            
            {
                Pair cur = tmp.get(0);
                while (true) {
                    if (cur.prev != null && cur.prev.v == cur.v) {
                        cur.prev.count += cur.count;
                        cur.prev.next = cur.next;
                        cur.valid = false;
                        cur = cur.prev;
                        continue;
                    }
                    cur.count %= k;
                    if (cur.count == 0) {
                        cur.valid = false;
                        if (cur.prev != null) cur.prev.next = cur.next;
                        if (cur.next != null) cur.next.prev = cur.prev;
                        if (cur.prev != null) cur = cur.prev;
                        else cur = cur.next;
                    } else {
                        cur = cur.next;
                    }
                    if (cur == null) break;
                }
            }
            for (Pair p : tmp)
                if (p.valid)
                    ans += p.count;
        }
        
        ArrayList<Pair> front = new ArrayList<>();
        ArrayList<Pair> middle = new ArrayList<>();
        ArrayList<Pair> back = new ArrayList<>();

        if (m != 1) {
            ArrayList<Pair> tmp = new ArrayList<>();
            Pair q = null;
            for (int i = 0; i < n; i++) {
                if (q == null || q.v != arr[i]) {
                    q = new Pair(arr[i], 0);
                    tmp.add(q);
                }
                q.count++;
            }
            for (int i = 0; i < tmp.size(); i++) {
                Pair p = tmp.get(i);
                if (i > 0) p.prev = tmp.get(i - 1);
                if (i + 1 < tmp.size()) p.next = tmp.get(i + 1);
            }
            
            {
                Pair cur = tmp.get(0);
                while (true) {
                    if (cur.prev != null && cur.prev.v == cur.v) {
                        cur.prev.count += cur.count;
                        cur.prev.next = cur.next;
                        cur.valid = false;
                        cur = cur.prev;
                        continue;
                    }
                    cur.count %= k;
                    if (cur.count == 0) {
                        cur.valid = false;
                        if (cur.prev != null) cur.prev.next = cur.next;
                        if (cur.next != null) cur.next.prev = cur.prev;
                        if (cur.prev != null) cur = cur.prev;
                        else cur = cur.next;
                    } else {
                        cur = cur.next;
                    }
                    if (cur == null) break;
                }
                for (Pair p : tmp) {
                    if (p.valid) {
                        front.add(p);
                        middle.add(new Pair(p.v, p.count));
                        back.add(new Pair(p.v, p.count));
                    }
                }
            }
            
            for (int i = 0; i < front.size(); i++) {
                Pair p = front.get(i);
                if (i > 0) p.prev = front.get(i - 1);
                if (i + 1 < front.size()) p.next = front.get(i + 1);
            }
            for (int i = 0; i < middle.size(); i++) {
                Pair p = middle.get(i);
                if (i > 0) p.prev = middle.get(i - 1);
                if (i + 1 < middle.size()) p.next = middle.get(i + 1);
            }
            for (int i = 0; i < back.size(); i++) {
                Pair p = back.get(i);
                if (i > 0) p.prev = back.get(i - 1);
                if (i + 1 < back.size()) p.next = back.get(i + 1);
            }
            
            if (front.size() > 0) {
                long middleCount = m - 2;
                int fSize = front.size();
                int mSize = middle.size();
                int bSize = back.size();
                Pair a = front.get(front.size() - 1);
                Pair b = middle.get(0);
                Pair c = middle.get(middle.size() - 1);
                Pair d = back.get(0);
                
                while (true) {
                    if (mSize == 0) break;
                    if (mSize == 1) {
                        break;
                    }
                    // shouldnt happen
                    if (b.v == b.next.v) {
                        b.next.valid = false;
                        b.count += b.next.count;
                        b.next = b.next.next;
                        if (b.next != null) b.next.prev = b;
                        mSize--;
                        if (c == b.next) c = b;
                        continue;
                    }
                    if (c.v == c.prev.v) {
                        c.prev.valid = false;
                        c.count += c.prev.count;
                        c.prev = c.prev.prev;
                        if (c.prev != null) c.prev.next = c;
                        mSize--;
                        if (b == c.prev) b = c;
                        continue;
                    }
                    if (a != null && a.v == b.v) {
                        if (a.count + b.count < k) {
                            break;
                        }
                        long total = a.count + b.count;
                        total %= k;
                        if (total == 0) {
                            a.valid = false;
                            b.valid = false;
                            fSize--;
                            mSize--;
                            a = a.prev;
                            if (a != null) a.next = null;
                            b = b.next;
                            b.prev = null;
                            c.valid = false;
                            c = c.prev;
                            mSize--;
                            if (c != null) c.next = null;
                            d.valid = false;
                            d = d.next;
                            if (d != null) d.prev = null;
                        } else {
                            a.count = total;
                            b.valid = false;
                            b = b.next;
                            b.prev = null;
                            c.count = total;
                            d.valid = false;
                            d = d.next;
                            if (d != null) d.prev = null;
                            mSize--;
                        }
                    } else {
                        break;
                    }
                }
                tmp.clear();
                for (Pair p : front)
                    if (p.valid)
                        tmp.add(p);
                for (Pair p : middle)
                    if (p.valid) {
                        p.count *= middleCount;
                        tmp.add(p);
                    }
                for (Pair p : back)
                    if (p.valid)
                        tmp.add(p);
                if (mSize <= 1) {
                    
                    for (int i = 0; i < tmp.size(); i++) {
                        Pair p = tmp.get(i);
                        if (i > 0) p.prev = tmp.get(i - 1);
                        if (i + 1 < tmp.size()) p.next = tmp.get(i + 1);
                    }
                    Pair cur = tmp.get(0);
                    while (true) {
                        if (cur.prev != null && cur.prev.v == cur.v) {
                            cur.prev.count += cur.count;
                            cur.prev.next = cur.next;
                            cur.valid = false;
                            cur = cur.prev;
                            continue;
                        }
                        cur.count %= k;
                        if (cur.count == 0) {
                            cur.valid = false;
                            if (cur.prev != null) cur.prev.next = cur.next;
                            if (cur.next != null) cur.next.prev = cur.prev;
                            if (cur.prev != null) cur = cur.prev;
                            else cur = cur.next;
                        } else {
                            cur = cur.next;
                        }
                        if (cur == null) break;
                    }
                }
                for (Pair p : tmp)
                    if (p.valid)
                        ans += p.count;
            }
        }
        
        out.println(ans);
        out.close();
    }

    static class Pair {
        int v;
        long count;
        boolean valid = true;
        Pair prev, next;
        public Pair(int vv, long countt) {
            v = vv; count = countt;
        }
    }

    static Random rand = new Random();
    static void sort(int[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            int tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static void sort(long[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            long tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static void sort(double[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            double tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    static long[] eEuclid(long a, long b) {
        if (b == 0) return new long[] { a, 1, 0 };
        long[] ans = eEuclid(b, a % b);
        long temp = ans[1] - ans[2] * (a / b);
        ans[1] = ans[2];  ans[2] = temp;
        return ans;
    }
    static long modInverse(long a, long m) {
        return ((eEuclid(a, m)[1] % m) + m) % m;
    }
    static class DisjointSet {
        int[] s, r;	
	public DisjointSet(int n) {
            s = new int[n]; r = new int[n];
            for (int i = 0; i < n; i++) s[i] = i;
        }	
        public int find(int i) { return s[i] == i ? i : (s[i] = find(s[i])); }
	public void union(int a, int b) {
            if(r[a = find(a)] == r[b = find(b)]) r[a]++;
            if(r[a] >= r[b]) s[b] = a; else s[a] = b;
        }
    }
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream i) {
            br = new BufferedReader(new InputStreamReader(i));
            st = new StringTokenizer("");
        }
        public String next() throws IOException {
            if(st.hasMoreTokens())
                return st.nextToken();
            else
                st = new StringTokenizer(br.readLine());
            return next();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
        public int[] nextOffsetIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt() - 1;
            return arr;
        }
        public int[] nextIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }
        public int[][] nextIntArray(int n, int m) throws IOException {
            int[][] arr = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextInt();
            return arr;
        }
        public long[] nextLongArray(int n) throws IOException {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextLong();
            return arr;
        }
        public long[][] nextLongArray(int n, int m) throws IOException {
            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextLong();
            return arr;
        }
        public double[] nextDoubleArray(int n) throws IOException {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextDouble();
            return arr;
        }
        public double[][] nextDoubleArray(int n, int m) throws IOException {
            double[][] arr = new double[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextDouble();
            return arr;
        }
        public char[][] nextCharArray(int n, int m) throws IOException {
            char[][] arr = new char[n][];
            for (int i = 0; i < n; i++)
                arr[i] = next().toCharArray();
            return arr;
        }
    }
}
