#include <iostream>

using namespace std;

string s;

void unos(int n){
    for (int i = 0; i < n; i++)
        cin >> s[i];
}

int f(char c, int n){
    int N = 0, P1 = n, P2 = n, g;
    for (int i = 0; i < n; i++){
        int g = 0;
        for (int l = 0; l < i; l++){
            if (c - 1 == s[l]) g = 1;
        }
        if ((s[i] == c) && (i < P1) && ((g == 1) || (c == 'A'))) P1 = i;
        if ((s[i] != c) && (i < P2) && (i > P1)) P2 = i;
        if ((s[i] == c) && (i < P2) && (i >= P1))
            N++;
        }
    if (N == 0) return 1;
    return N;
}

int main()
{
    long long b, u = 1, br;
    b = 1000000007;
    int n;
    cin >> n;
    unos(n);
    for (char c = 'A'; c <= 'Z'; c++){
        br = f(c, n);
        u = u * br;
    }
    cout << u % b;
	return 0;
}