#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll K = 30;
const ll N = 1000005;
const ll M = 1000000007;
int BIT[K][N];
string s;
void updateBIT(ll t, ll i, ll val, ll n)
{
    while (i <= n) {
        BIT[t][i] = BIT[t][i] + val;
        i = i + (i & (-i));
    }
}
ll getSum(ll t, ll i)
{
    ll res = 0;
    while (i > 0) {
        res = (res + BIT[t][i])%M;
        i = i - (i & (-i));
    }
    return res;
}
ll getInvCount(string& s, ll n, ll k)
{
    for (ll i = n - 1; i >= 0; i--) {
        ll x = s[i]-'A'+1;
        updateBIT(1, x, 1, n);
        for (ll l = 1; l < k; l++) {
            updateBIT(l + 1, x, getSum(l, x - 1), n);
        }
    }
    return getSum(k, n);
}
int main()
{
    ll n; cin>>n;
    cin>>s;
    reverse(s.begin(), s.end());
    cout << getInvCount(s, n, 26);
    return 0;
}