#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MAXN 1000010
typedef long long ll;
char arr[MAXN];
ll temp[MAXN];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>arr[i];
        if(arr[i]=='A')temp[i]=1;
    }
    ll res=0;
    for(int k=1;k<26;++k)
    {
        ll s=0;
        for(int i=0;i<n;++i)
        {
            if(arr[i]-'A'==k-1)s=(s+temp[i])%MOD;
            if(arr[i]-'A'==k)
            {
                temp[i]=s;
                if(k==25)res=(res+temp[i])%MOD;
            }

        }
    }
    cout<<res;
    return 0;
}