MOD = 10**9 + 7 n = int(input()) s = input().strip() ans = 0 expected = 'A' for i in range(n, 0, -1): current = s[i-1] if current == expected: continue # Find the other peg which is not current or expected if expected != 'A' and current != 'A': other = 'A' elif expected != 'B' and current != 'B': other = 'B' else: other = 'C' ans += pow(2, i-1, MOD) ans %= MOD expected = other print(ans % MOD)