#include <bits/stdc++.h>

using namespace std;

unsigned long long powI(unsigned long long a,unsigned long long b)
{
    unsigned long long res = 1;
    for(int i = 0; i < b; i++)
        res *= a;
    return res;
}

int main()
{
    //cout << powI(3,26)%1000000007<<endl;

    unsigned long long resarr[26];
    for(int i = 0;i<26;i++)
        resarr[i] = 0;

    string s;
    int N;
    cin >> N;
    char startChar = 'Z';
    for(int i = 0; i<N; i++)
    {
        char c;
        cin >> c;
        if(startChar > c)
            startChar = c;
        s += c;
    }
    while(s[0] != startChar) //step 1-erase front
    {
        s.erase(s.begin());
    }
    for(int i = 1;i<s.size();i++) //step 2-erase stray chars
    {
        if(s[i]<s[i-1])
            s.erase(s.begin()+i--);
    }
    for(int i = 0;i<s.size();i++)
    {
        resarr[s[i]-65]++;
    }
    unsigned long long res = 1;
    for(int i = 0;i<26;i++)
    {
        if(resarr[i] != 0)
            res *= resarr[i];
    }

    cout << res % 1000000007;



    return 0;
}