#include <iostream>
#include <string>
#include <cmath>
#define MAX_N 1000000
unsigned long long res(int n)
{
    const unsigned int M = 1000000007;
    unsigned long long f = 1;
    for (int i = 1; i <= n; i++)
        f=i;
    f = f % M;
    return f;
}
using namespace std;
int main()
{
    int n, i = 1, j = 2, br = 1;
    unsigned long long proizvod = 1;
    const unsigned int M = 1000000007;
    string rec = "";
    char a[MAX_N];
    cin >> n;
    for (i; i <= n; i++)
    {
        cin >> a[i];
        rec += a[i];
    }
    for (j; j <= n; j++)
    {
        if (int(a[j]) == int(a[j - 1]))
            br++;
        else if (int(a[j]) < int(a[j - 1]))
            br=br;
        proizvod *= br;
        br = 1;
    }
    cout << res(proizvod);
    return 0;
}