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

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<list>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<algorithm>
#include<string>
#include<iomanip>
#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include<unordered_set>
#include<unordered_map>
#include <stack> 
#define boost  std::ios::sync_with_stdio(false)//;cin.tie(0)
#define F first
#define S second
#define tr(container, it)  for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define trr(container, it)  for(__typeof(container.rbegin()) it = container.rbegin(); it != container.rend(); it++)
#define pb push_back
#define in insert
#define mp make_pair
#define fi(var,a,b) for(int var=a;var<=b;var++)
#define fe(var,a,b) for(int var=a;var<b;var++)
#define cin(x) scanf("%d",&x)
#define cout(x) printf("%d",x)
#define newl printf("\n")
#define news printf(" ")
#define inf 20000000000
#define MOD 1000000007
#define endl '\n'
#define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef pair<string,int> psi;
void reverseStr(string &str)
{
    int n = str.length();
 
    // Swap character starting from two
    // corners
    for (int i=0; i<n/2; i++)
       swap(str[i], str[n-i-1]);
}

int n,m,k;
string ggwp(string s)
{
//cout<<"s is"<<s<<endl;
int len=s.size();
vi dp(len);
dp[0]=1;

vi par(len,-1);

int fn=0;

int ans=0;
fe(i,1,len)
{
int pp=fn;
if(pp==-1)
{
dp[i]=1;
fn=i;
par[i]=-1;
continue;
}
if(s[i]==s[pp])
{
dp[i]=1+dp[pp];
if(dp[i]<k)
{par[i]=par[pp];fn=i;}
else
{++ans;par[i]=par[pp];fn=par[pp];}
}
else
{
dp[i]=1;
par[i]=pp;
fn=i;
}

//cout<<i<<" "<<dp[i]<<" "<<par[i]<<" "<<fn<<endl;

}

string zxc;
while(fn!=-1)
{
zxc+=s[fn];
fn=par[fn];
}

reverseStr(zxc);
//cout<<"zxc is "<<zxc<<endl;
//cout<<ans<<endl;
//cout<<len-(k*ans)<<endl;
//cout<<"ans "<<ans<<endl;
return zxc;
}

int cc(string s)
{
set<char> cs;
int len=s.size();
fe(i,0,len)
{
cs.insert(s[i]);
if(cs.size()>1)
return 0;
}
return 1;
}
int findd(string s)
{
//cout<<"s is"<<s<<endl;
int len=s.size();
vi dp(len);
dp[0]=1;

vi par(len,-1);

int fn=0;

int ans=0;
fe(i,1,len)
{
int pp=fn;
if(pp==-1)
{
dp[i]=1;
fn=i;
par[i]=-1;
continue;
}
if(s[i]==s[pp])
{
dp[i]=1+dp[pp];
if(dp[i]<k)
{par[i]=par[pp];fn=i;}
else
{++ans;par[i]=par[pp];fn=par[pp];}
}
else
{
dp[i]=1;
par[i]=pp;
fn=i;
}

//cout<<i<<" "<<dp[i]<<" "<<par[i]<<" "<<fn<<endl;

}
//cout<<ans<<endl;
//cout<<len-(k*ans)<<endl;
//cout<<"ans "<<ans<<endl;
return len-(k*ans);
}
main()
{
cin>>n>>k>>m;
string s;
char x;
fi(i,1,n)
{
cin>>x;
s+=x;
}
s=ggwp(s);
//cout<<cc(s)<<endl;
if(cc(s)==1)
{
cout<<(n*m)%k<<endl;
return 0;
}
if(cc(s)==0&&k>n)
{
cout<<"0"<<endl;
return 0;
}

if(k==1)
cout<<"0"<<endl;
else
{
string gg=s;
int a1=findd(gg);
gg+=s;
int a2=findd(gg);
gg+=s;
int a3=findd(gg);
gg+=s;
int a4=findd(gg);
if(m==1)
cout<<a1<<endl;
if(m==2)
cout<<a2<<endl;
if(m==3)
cout<<a3<<endl;
int diff=(4*n-a4)-(3*n-a3);
//cout<<"diff "<<diff<<endl;
//cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<endl;
if(m>=4)
{
if(a2==0)
{
if(m%2==0)
cout<<"0"<<endl;
else
cout<<a1<<endl;
}
else
cout<<n*m-(diff*(m-1))<<endl;
}
}
}
