#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int n, cnt = 1;
    long long res = 1, formula, kraj;
    char c;
    vector <char> unos;
    vector <char> novi;
    scanf("%d",&n);

    for(int i = 0; i < n+1; i++) {
        scanf("%c",&c);
        unos.push_back(c);
    }
    int max = *min_element(unos.begin(), unos.end());

   for(int i = 0; i < n; i++) {
        if(i == 0) {
           novi.push_back(unos[i]); 
        }
        if(unos[i + 1] >= unos[i] && unos[i + 1] > max) {
            novi.push_back(unos[i + 1]);
            max = unos[i - 1];
        }
    }
    
for(int i = 0; i < n + 1; i++) {
    if(novi[i + 1] == novi[i]) {
        cnt++;
    }
    else {
        res = res * cnt;
        cnt = 1;
    }
}

formula = (pow(10,9) + 7);
kraj = res % formula;
printf("\n%lld",kraj);
return 0;
}