#include void func (int n, char *s, char t, long long *ans, long long *pow2, long long mod_num) { if (n < 0) { return; } if (s[n] == t) { func(n-1, s, t, ans, pow2, mod_num); } else { char nxt = 'A'; while (nxt == s[n] || nxt == t) { nxt += (char)1; } func(n-1, s, nxt, ans, pow2, mod_num); *ans += pow2[n]; *ans %= mod_num; } return; } int main () { int n = 0; char s[1001] = ""; int res = 0; long long ans = 0LL; long long mod_num = 1000000007LL; long long pow2[1001] = {}; res = scanf("%d", &n); res = scanf("%s", s); pow2[0] = 1LL; for (int i = 0; i < n; i++) { pow2[i+1] = (2LL*pow2[i])%mod_num; } func(n-1, s, 'A', &ans, pow2, mod_num); printf("%lld\n", ans); return 0; }