#include <bits/stdc++.h>
using namespace std;

#define KRJ 1000000007

long long bukve[26];

int subways(char zeta)
{
    int subw = 0;
    char c;
    while (((c = getchar()) != EOF) && (c - zeta == 1 || c - zeta == 0)) {
        subw++; zeta = c;
        if (!bukve[c - 'A']) bukve[c - 'A'] = 1;
    }

    return subw;
}

int main()
{
    long long n; cin >> n;

    char line = 'A';
    long long w = 1;
    char c;
    while ((c = getchar()) != EOF)
    {
        char c; cin >> c;
        if (c < line) { w = ((w % KRJ) * (subways(c) % KRJ)) % KRJ; continue; }
        bukve[c - 'A']++;
        line = c;
    }

    for (long long i = 0; i < 26; i++) w = ((w % KRJ) * (bukve[i] % KRJ)) % KRJ;
    cout << w;
}