#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int mod = 1e9 + 7;   template <class X>   void print(X a) {     cout << a << endl;     exit(0);   }   long long n, k, m;   vector<pair<long long, long long> > reduce(       vector<pair<long long, long long> >& a) {     vector<pair<long long, long long> > b;     pair<long long, long long> last = {-1, -1};     for (auto& x : a) {       if (last.first == x.first)         b.back().second += x.second;       else         b.push_back(x);       if (b.back().second % k == 0) b.pop_back();       if (!b.empty())         last = b.back();       else         last = {-1, -1};     }     for (auto& x : b) x.second %= k;     return b;   }   int main() {     time_t t1, t2;     t1 = clock();     ios_base::sync_with_stdio(0);     cin >> n >> k >> m;     long long faltu[n + 1];     for (int i = 1; i <= n; i++) cin >> faltu[i];     vector<pair<long long, long long> > a;     int i = 1;     while (i <= n) {       int j = i;       for (j = i; j <= n; j++) {         if (faltu[j] != faltu[i]) break;       }       a.push_back({faltu[i], j - i});       i = j;     }     long long sum = 0;     a = reduce(a);     for (auto& x : a) sum += x.second;     long long total = sum * m;     __f( total , total);     int finish_idx = -1;     for (int i = 0, j = a.size() - 1; i < (int)a.size(); i++, j--) {       if (a[i].first != a[j].first or a[i].second + a[j].second != k) {         finish_idx = i;         break;       }     }     if (finish_idx == -1) {       if (m & 1)         cout << sum << endl;       else         cout << 0 << endl;     } else {       long long to_sub = 0;       long long start_sub = 0, end_sub = 0;       long long left_over = 0;       long long c;       for (int i = 0, j = a.size() - 1; i <= finish_idx; i++, j--) {         if (i == finish_idx and a[i].first != a[j].first)           break;         else if (i == finish_idx and a[i].first == a[j].first and                  a[i].second + a[j].second < k)           break;         else if (i == finish_idx)           left_over = (a[i].second + a[j].second) % k;         to_sub += (a[i].second + a[j].second);         start_sub += a[i].second;         end_sub += a[j].second;       }       to_sub *= m;       long long ans = total - to_sub;       ans += start_sub + end_sub;       ans += left_over * (m - 1);       if ((int)a.size() & 1 and finish_idx == (int)a.size() / 2) {         vector<pair<long long, long long> > new_a;         for (int i = 0; i < (int)a.size(); i++) {           if (i == finish_idx)             new_a.push_back({a[i].first, a[i].second * m});           else             new_a.push_back(a[i]);         }         new_a = reduce(new_a);         ans = 0;         for (auto& x : new_a) {           ans += x.second;         }       }       cout << ans << endl;     }     t2 = clock();     cerr <<  time taken:   << t2 - t1 << endl;     return 0;   }