#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN = 1e9;
const ll mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> suffix(26, 0);
    ll ans = 0;
    for (int i = n - 2; i >= 0; i--)
    {
        suffix[s[i + 1] - 'A']++;
        if (s[i] == 'A')
        {
            ll cur = 1;
            for (int j = 1; j < 26; j++)
            {
                cur = (cur * suffix[j]) % mod;
            }
            ans += cur;
        }
    }
    cout << ans;
    return 0;
}