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

#ifndef home
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4a,popcnt,abm,mmx")
#endif  // home
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;

template <class X, class C = less<X>, class Y = __gnu_pbds::null_type>
using ordered_map =
	__gnu_pbds::tree<X, Y, C, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class X, class C = greater<X>>
using heap = __gnu_pbds::priority_queue<X, C, __gnu_pbds::pairing_heap_tag>;
#define all(_x) (_x).begin(), (_x).end()
#define mp make_pair
#define lowb lower_bound
#define upb upper_bound
#define bins binary_search
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define sz(_A) (int)_A.size()
#define re return
#define F(i, l, r) for (int i = l; i < r; ++i)
#define f(i, n) F(i, 0, n)
#define eb emplace_back
typedef unsigned long long ulint;
typedef long long ll;
typedef long double ld;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
const int mod = 1000000007;
typedef unsigned long long ull;
const int inf = INT_MAX;
const lint linf = LLONG_MAX;
template <class X>
inline void getarr(X* a, int n) {
	for (int i = 0; i < n; i++) cin >> a[i];
}

template <class X>
inline void getarr(X* a, int n, int m) {
	for (int i = 0; i < n; i++) getarr(a[i], m);
}

template <class X>
inline void putarr(X* a, int n, char ch = ' ') {
	for (int i = 0; i < n; i++) cout << a[i] << ch;
}

template <class X>
inline void putarr(X* a, int n, int m) {
	for (int i = 0; i < n; i++) {
		putarr(a[i], m, ' ');
		cout << '\n';
	}
}

template <class X>
inline X abs(X a) {
	return a < 0 ? -a : a;
}

template <class X>
inline void mini(X& x, X y) {
	x = min(x, y);
}

template <class X>
inline void maxi(X& x, X y) {
	x = max(x, y);
}

template <class X>
constexpr X bround(X x) {
	return x == 0 ? 1 : bround(x >> 1) << 1;
}

template <class X = int>
X myrand(X l = 0, X r = inf) {
	static mt19937 gen;
	uniform_int_distribution<X> dist(l, r);
	return dist(gen);
}
// #define FAST_ALLOCATOR_MEMORY 1e8
#ifdef FAST_ALLOCATOR_MEMORY
int allocator_pos = 0;
char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
inline void* operator new(size_t n) {
	char* res = allocator_memory + allocator_pos;
	allocator_pos += n;
	assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
	return (void*)res;
}
inline void operator delete(void*)noexcept {}
// inline void * operator new [] ( size_t ) { assert(0); }
// inline void operator delete [] ( void * ) { assert(0); }
#endif
//--------------------------------------------------stdfunc------------------

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	vector<int> q;
	lint n, k, m;
	cin >> n >> k >> m;
	vector<int> a(n);
	f(i, n) cin >> a[i];
	vector<int> ps(n);
	int pos = 0;
	for (int x : a) {
		if (q.empty()) {
			q.push_back(x);
			ps[pos] = 1;
		} else {
			if (q[pos - 1] == x) {
				ps[pos - 1]++;
				pos--;
			} else {
				q.pb(x);
				ps[pos] = 1;
			}
		}
		pos++;
		if (ps[pos - 1] == k) {
			ps[pos - 1] = 0;
			q.pop_back();
			pos--;
		}
	}
	//  f(i, q.size()) { cout << ps[i].fi << ' ' << ps[i].se << endl; }
	ll ans = 0;
	f(i, sz(q)) {
		if (i == (sz(q) - i - 1)) {
			ans += ps[i] * m % k;
			ans %= mod;
			if (ps[i] * m % k == 0) {
				for (int j = i - 1; j >= 0; j--) {
					if (ps[j] + ps[sz(q) - j - 1] != k) {
						ans -= ps[j] + ps[sz(q) - j - 1];
						ans += (ps[j] + ps[sz(q) - j - 1]) % k;
						ans = (ans % mod + mod) % mod;
						break;
					} else {
						ans -= ps[j] + ps[sz(q) - j - 1];
						ans = (ans % mod + mod) % mod;
					}
				}
			}
			break;
		}
		if (i > (sz(q) - i - 1)) break;
		if (q[i] != q[sz(q) - i - 1]) {
			F(j, i, sz(q) - i) ans = (ans + m * ps[j]) % mod;
			break;
		}
		ans += ps[i] + ps[sz(q) - i - 1];
		ans %= mod;
		if (ps[i] + ps[sz(q) - i - 1] != k) {
			ans += (m - 1) * ((ps[i] + ps[sz(q) - i - 1]) % k);
			ans %= mod;
			F(j, i + 1, sz(q) - i - 1) ans = (ans + m * ps[j]) % mod;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}  