#include <bits/stdc++.h>

using namespace std;
vector<int> poz[26];

int memo[26][1000007];

int solve(int letter, int pointer) {
    if (memo[letter][pointer] != 0) {
        return memo[letter][pointer];
    }
    if (poz[letter][poz[letter].size() - 1] < pointer)
        return -1;
    if (letter == 25) {
        int nextCandidate = upper_bound(poz[letter].begin(), poz[letter].end(), pointer) - poz[letter].begin();
        return poz[letter].size() - nextCandidate;
    }
    int result = 0, sr;
    for (int i = poz[letter].size() - 1; poz[letter][i] > pointer; i--) {
        sr = solve(letter + 1, poz[letter][i]);
        if (sr != -1) {
            if (result + sr > 1000000007) {
                result = (result + sr) % (1000000007);
            }
            else result += sr;
        }
        if (i == 0)
            break;
    }
    memo[letter][pointer] = result;
    return result;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < 26; i++)
        poz[i].reserve(n / 26 + 1);
    for (int i = 0; i < n; i++) {
        poz[s[i] - 'A'].push_back(i);
    }
    cout << solve(0, -1);
    return 0;
}