#include #define int long long using namespace std; string inslo[102], slo[102]; int pocz[102], block[102]; int mac[102][102]; bool srt(string &a, string &b) { return a.size() < b.size(); } const int N = 101, mod = 1000000007; struct macierz { int t[102][102]; macierz() {} }; macierz mnoz(macierz a, macierz b) { macierz res; for (int i=0; i= (int)b.size() || a[i] != b[j+i]) { ok=0; break; } } if (ok == 1) return true; } return false; } bool isPref(string &a, string &b, int pr) { if (pr > (int)b.size()) return false; for (int i=0; i> n >> q; slo[0] = "%a"; for (int i=1; i<=q; i++) { int l; cin >> l; //pocz[i] = pocz[i-1] + slo[i-1].size(); cin >> inslo[i]; } sort(inslo+1, inslo+q+1, srt); for (int i=1; i<=q; i++) { for (int j=i+1; j<=q; j++) { if (contains(inslo[i], inslo[j])) block[j] = 1; } } int akt=1; for (int i=1; i<=q; i++) { if (block[i] == 1) continue; slo[akt] = inslo[i]; akt++; } q = akt-1; mac[0][0]=26; for (int i=1; i<=q; i++) { //cout << slo[i] << "\n"; pocz[i] = pocz[i-1] + slo[i-1].size() - 1; if (slo[i].size() == 1) { mac[0][0]--; continue; } //cout << pocz[i] << "\n"; mac[0][pocz[i]]=1; mac[pocz[i]+slo[i].size()-2][0] = -1; } // porownujemy prefikso sufiksy for (int i=1; i<=q; i++) { for (int j=1; j<=q; j++) { for (int pr=1; pr<(int)slo[i].size(); pr++) { if (pr!=1) mac[pocz[i]+pr-2][pocz[i]+pr-1]=1; if (isPref(slo[i], slo[j], pr)) { mac[pocz[j] + slo[j].size() - 2][pocz[i] + pr - 1] = -1; // ??? } } } } cout << (mod+pot(normal(), n).t[0][0])%mod << "\n"; }