#include #include #include #define MOD 1000000007 unsigned long long count; char *s; std::list *to; std::map pdca; void Serch(int index) { for(auto i = to[index].begin(); i != to[index].end(); i++) { if((s[index] == 'C') && (s[(*i)] == 'A')) { count++; continue; } if(pdca[s[index]] < pdca[s[(*i)]]) { Serch((*i)); } } } int main() { pdca['P'] = 0; pdca['D'] = 1; pdca['C'] = 2; pdca['A'] = 3; int n, m; std::cin >> n >> m; to = new std::list[n]; s = new char[n + 1]; std::cin >> s; for(int i = 0; i < m; i++) { int n1, n2; std::cin >> n1 >> n2; n1--; n2--; int sub = pdca[s[n1]] - pdca[s[n2]]; if(abs(sub) == 1) { if(sub < 0) to[n1].push_back(n2); else to[n2].push_back(n1); } } int ans = 0; for(int i = 0; i < n; i++) { if(s[i] != 'P') continue; count = 0; Serch(i); count %= MOD; ans += count; ans %= MOD; } std::cout << ans << std::endl; delete[] s; delete[] to; return 0; }