#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N;
    int modulo = 1000000007;
    vector<int> slova[26];
    vector<int> coreSlova[26];
    string natpis;
    bool nem = false;
    cin >> N >> natpis;
    long long result;
    long long core = 1;

    for (int i = 0; i < N; i++) slova[(int)natpis[i]-65].push_back(i);
    for (int i = 24; i >= 0 ; i--){
        if(slova[i + 1].size() == 0){
            nem = true;
            break;
        }
        else while (slova[i].at(slova[i].size()-1) > slova[i+1].at(slova[i + 1].size()-1)) slova[i].pop_back();
        copy(begin(slova), end(slova), begin(coreSlova));
        if(slova[i + 1].size() == 0){
            nem = true;
            break;
        }
        else while (coreSlova[i].at(coreSlova[i].size()-1) > coreSlova[i+1].at(0)) coreSlova[i].pop_back();
    }
    if (nem) cout << 0;
    for (int i = 0; i < 26; i++) {
            if (coreSlova[i].size() != 0) core *= coreSlova[i].size();
            core %= modulo;
    }
    result = core;
    if(!nem) cout << result;
    return 0;
}