#include <stdio.h>
#include <stdlib.h>

#define CHR(c) (c - 'A')
#define MAX 1000000007
#define ISECI(x, y) (((x)%MAX + (y)%MAX)%MAX)

int main() {
    unsigned long long *rez = calloc(26, sizeof *rez);

    int n;
    scanf("%d\n", &n);
    char chr;
    for (int i = 0; i < n; ++i) {
        scanf("%c", &chr);
        if(chr == 'A' ) {
            ++rez[CHR(chr)];
        } else if (rez[CHR(chr) - 1] > 0) {
            rez[CHR(chr)] = ISECI(rez[CHR(chr)], rez[CHR(chr)-1]);
        }
    }

    printf("%lld", rez[CHR('Z')]);

    return 0;
}