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