#include using namespace std; using mint = atcoder::modint1000000007; int main(){ string s; cin >> s >> s; mint ans; char c = 0, p = 'B' ^ 'C'; while(s.size()){ c ^= 'A' ^ 'B' ^ 'C' ^ p; while(s.size() && s.back() == c)s.pop_back(); if(s.size()){ ans += mint(2).pow(s.size() - 1); p = c; c = s.back(); s.pop_back(); } } cout << ans.val() << '\n'; }