include<bits/stdc++.h>
using namespace std;
const int maxn=4e6+50;
char s[maxn];
char ss[maxn];
int p[maxn];
long long cnt1[maxn];
long long cnt2[maxn];
const int mod=1e9+7;
void manacher(int len)
{
ss[0]='$';
int t=1;
for (int i=0;i<len;i++){
ss[t++]='#',ss[t++]=s[i];
}
ss[t++]='#',ss[t]='&';
fill(p,p+t+1,1);
int id=1;
int now=1;
for (int i=1;i<t;i++){
if (i>now)now=i,id=i;
p[i]=min(now-i+1,p[2id-i]);
for (int j=p[i]+i,k=i-p[i];ss[j]==ss[k];p[i]++,j++,k--);
if (p[i]+i-1>now)now=p[i]+i-1,id=i;
}
long long ans=0;
for (int i=1;i<t;i++){
int l=i-p[i]+1,r=i+p[i]-1;
l+=(l&1);
r-=(r&1);
if (l<=r){
int t1=(i/2);
int t2=(i+1)/2;
l>>=1,r>>=1;
ans=(ans+(r-t2+1))%mod;
cnt1[t1+1]--;
cnt1[l]++;
cnt2[t2]++;
cnt2[r+1]--;
}
}
ans=ans(ans-1)/2%mod;
for (int i=1;i<=len+2;i++){
cnt1[i]+=cnt1[i-1];
cnt2[i]+=cnt2[i-1];
cnt1[i]%=mod,cnt2[i]%=mod;
}
for (int i=1;i<=len;i++){
cnt2[i]+=cnt2[i-1];
cnt2[i]%=mod;
ans=(ans-1LLcnt2[i]cnt1[i+1])%mod;
}
ans=(ans+mod)%mod;
printf("%lld\n",ans);
}
int main()
{
int n;
scanf("%d",&n);
scanf("%s",s);
manacher(n);
}