malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   int arr[2000005] = {0};   int foo(int n) {     int maxsize = -1, startindex;     int sumleft[n];     int min, max;     int i;     sumleft[0] = ((arr[0] == 0) ? -1 : 1);     min = arr[0];     max = arr[0];     for (i = 1; i < n; i++) {       sumleft[i] = sumleft[i - 1] + ((arr[i] == 0) ? -1 : 1);       if (sumleft[i] < min) min = sumleft[i];       if (sumleft[i] > max) max = sumleft[i];     }     int hash[max - min + 1];     for (i = 0; i < max - min + 1; i++) hash[i] = -1;     for (i = 0; i < n; i++) {       if (sumleft[i] == 0) {         maxsize = i + 1;         startindex = 0;       }       if (hash[sumleft[i] - min] == -1)         hash[sumleft[i] - min] = i;       else {         if ((i - hash[sumleft[i] - min]) > maxsize) {           maxsize = i - hash[sumleft[i] - min];           startindex = hash[sumleft[i] - min] + 1;         }       }     }     if (maxsize == -1) maxsize = 0;     return maxsize;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) arr[i] = 1;     }     cout << foo(n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int pow1(long long int a, long long int b,                      long long int m = 1000000007) {     if (b == 0)       return 1ll;     else if (b == 1)       return a;     else {       long long int x = pow1(a, b / 2, m);       x *= x;       x %= m;       if (b % 2) {         x *= a;         x %= m;       }       return x;     }   }   template <class avgType>   avgType avg(avgType a, avgType b) {     return (a + b) / 2;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());   int randInt() { return rng() % INT_MAX; }   long long int randLL() { return rng64() % LLONG_MAX; }   vector<int> hashmods = {1000000007, 1000000009, 1000000021,                           1000000033, 1000000087, 1000000093};   long long int n, k, a[110000], t;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> n >> k;       int pres = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         pres += (a[i] == k);       }       if (pres == 0) {         cout <<  no n ;         continue;       }       if (n == 1) {         cout <<  yes n ;         continue;       } else if (n == 2 and a[1] >= k and a[2] >= k) {         cout <<  yes n ;         continue;       }       int yes = 0, less = 0, more = 0, presk = 0;       for (int i = 1; i <= n - 2; i++) {         int m = (a[i] >= k) + (a[i + 1] >= k) + (a[i + 2] >= k);         if (m >= 2) {           yes++;         }       }       cout << (yes ?  yes n  :  no n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int a[4][100100];   vector<int> beg[4], en[4];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       bool out = 1;       int n, noob;       cin >> n >> noob;       for (int i = 1; i <= 3; i++) {         for (int j = 1; j <= n; j++) {           char x;           cin >> x;           if (x ==  s )             a[i][j] = 1;           else if (x ==  . )             a[i][j] = 0;           else             a[i][j] = 3;         }       }       for (int i = 1; i <= 3; i++)         for (int j = 1; j <= n; j++) {           if (a[i][j] == 3 && (j == 1 || a[i][j - 1] != 3)) beg[i].push_back(j);           if (a[i][j] == 3 && (j == n || a[i][j + 1] != 3)) en[i].push_back(j);         }       for (int j = 1; j < n; j++) {         for (int i = 1; i <= 3; i++)           if (a[i][j] == 1 && a[i][j + 1] != 3) a[i][j + 1] = 1, a[i][j] = 0;         if (a[2][j + 1] == 1) {           if (a[1][j + 1] == 0) a[1][j + 1] = 1;           if (a[3][j + 1] == 0) a[3][j + 1] = 1;         } else if (a[1][j + 1] == 1 && a[2][j + 1] == 0)           a[2][j + 1] = 1;         else if (a[3][j + 1] == 1 && a[2][j + 1] == 0)           a[2][j + 1] = 1;         for (int i = 1; i <= 3; i++) {           for (int k = 0; k < en[i].size(); k++) {             int e = en[i][k];             a[i][e] = 0;             if (e > 1) a[i][e - 1] = 0;             en[i][k] = max(0, e - 2);           }           for (int k = 0; k < beg[i].size(); k++) {             int b = beg[i][k];             if (b > 1) a[i][b - 1] = 3;             if (b > 2) a[i][b - 2] = 3;             beg[i][k] = max(0, b - 2);           }         }         bool check = 0;         for (int i = 1; i <= 3; i++)           if (a[i][j + 1] == 1) check = 1;         if (check == 0) {           out = 0;         }       }       if (out)         cout <<  YES  << endl;       else         cout <<  NO  << endl;       for (int i = 1; i <= 3; i++) {         beg[i].clear();         en[i].clear();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans[1500], t, i, j, v[1100];     memset(v, 0, sizeof(v));     for (i = 2; i * i <= 1100; i++) {       if (v[i] == 0) {         for (j = i + i; j <= 1100; j += i) v[j] = 1;       }     }     while (scanf( %d , &n) != EOF) {       if (n == 1)         printf( 0 n );       else {         t = 0;         for (j = 2; j <= n; j++) {           if (v[j] == 0) {             for (i = j; i <= n; i *= j) {               ans[t] = i;               t++;             }           }         }         printf( %d n , t);         for (i = 0; i < t - 1; i++) printf( %d  , ans[i]);         printf( %d n , ans[t - 1]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int M = 1000000007;   long long int mod(long long int x) { return (x % M + M) % M; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, t, c, ans = 0, g = 0, cnt = 0;     cin >> n >> t >> c;     long long int arr[n];     for (long long int i = 0; i < n; ++i) {       cin >> arr[i];     }     for (long long int i = 0; i < n; i++) {       g++;       if (arr[i] > t) {         g = 0;       } else {         if (g >= c) ans += 1;       }     }     cout << ans << endl;     cerr << fixed << setprecision(10);     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-11;   const long double pi = acos(-1);   const long long oo = 1 << 30;   const long long loo = 1ll << 62;   const long long mods = 998244353;   const long long MAXN = 200005;   const long long INF = 0x3f3f3f3f;   inline long long read() {     long long f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   long long Ans[1005], num = 0;   long long solve(long long x, long long y) {     if (!y) return x;     Ans[++num] = x / y;     long long t = solve(y, x % y);     return t;   }   signed main() {     long long x = read(), y = read();     if (solve(x, y) != 1) {       puts( Impossible );       return 0;     }     Ans[num]--;     for (long long i = 1; i <= num; i++)       if (Ans[i] > 0) printf( %lld , Ans[i]), putchar(66 - (i & 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, i, j, k, d;     cin >> n >> m;     vector<int> arr(101, 0);     for (i = 0; i < m; i++) {       int no;       cin >> no;       arr[no]++;     }     for (d = m; d >= 1; d--) {       vector<int> cc(arr);       int k = 0;       for (i = 0; i < cc.size(); i++) {         if (cc[i] >= d) {           k += (floor(cc[i] / d));         }       }       if (k >= n) {         cout << d << endl;         return 0;       }     }     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 5002;   constexpr int mod = 1e9 + 7;   string x, y;   int n, m;   int cache[N][N];   int dp(int a, int b) {     if (b == m) return 0;     int &rv = cache[a][b];     if (~rv) return rv;     rv = dp(a, b + 1);     if (x[a] == y[b]) rv += 1 + dp(a + 1, b + 1), rv %= mod;     return rv;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> x >> y;     n = x.size(), m = y.size();     memset(cache, -1, sizeof cache);     dp(0, 0);     int result = 0;     for (int i = 0; i < n; i++) result += dp(i, 0), result %= mod;     cout << result << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct $ {     $() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }   } $;   const int Maxn = 202005;   class BIT {     int *tree, sz;       public:     BIT() {       sz = 202005;       tree = new int[sz + 1];     }     BIT(int N) {       sz = N;       tree = new int[N + 1];     }     ~BIT() { delete[] tree; }     void update(int idx, int Val) {       if (idx < 1 || idx > sz) return;       while (idx <= sz) {         tree[idx] += Val;         idx += idx & -idx;       }     }     int read(int idx) {       int Sum = 0;       while (idx > 0) {         Sum += tree[idx];         idx -= (idx & -idx);       }       return Sum;     }     int rangeSum(int l, int r) {       int Ret = read(r) - read(l - 1);       Ret = max(0, Ret);       return Ret;     }     int readSingle(int idx) {       int sum = tree[idx];       if (idx > 0) {         int z = idx - (idx & -idx);         idx--;         while (idx != z) {           sum -= tree[idx];           idx -= (idx & -idx);         }       }       return sum;     }   };   int T1[Maxn], T2[Maxn];   int main() {     int n, k, a, b, q, type, d, val;     cin >> n >> k >> a >> b >> q;     BIT B1, B2;     while (q--) {       cin >> type;       if (type == 1) {         cin >> d >> val;         if (T1[d] < a) {           int temp = min(val, a - T1[d]);           T1[d] += temp;           B1.update(d, temp);         }         if (T2[d] < b) {           int temp = min(val, b - T2[d]);           T2[d] += temp;           B2.update(d, temp);         }       } else {         cin >> d;         int Ans = 0;         Ans = B2.rangeSum(1, d - 1);         int z = B1.rangeSum(min(d + k, Maxn - 1), Maxn - 1);         Ans += z;         cout << Ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const int MAXN = 65;   const int MAXB = 10;   const int MAXS = (1 << 10) + 7;   int q;   int b;   long long l, r;   int a[MAXN];   long long dp[MAXB + 3][MAXN][MAXS];   void init();   void input();   void inputq();   void work();   long long getans(long long x);   int main() {     init();     input();     work();   }   void init() {     ios::sync_with_stdio(false);     for (int i = 2; i <= MAXB; ++i) {       int ms = (1 << i);       dp[i][0][0] = 1;       for (int j = 1; j < MAXN; ++j) {         for (int k = 0; k < ms; ++k) {           for (int x = 0; x < i; ++x) {             dp[i][j][k ^ (1 << x)] += dp[i][j - 1][k];           }         }       }     }   }   void input() { scanf( %d , &q); }   void inputq() { scanf( %d%I64d%I64d , &b, &l, &r); }   void work() {     for (int i = 0; i < q; ++i) {       inputq();       printf( %I64d n , getans(r) - getans(l - 1));     }   }   long long getans(long long x) {     if (!x) return 0;     int n = 0;     for (long long t = x; t; t /= b) {       a[n++] = t % b;     }     long long ans = 0;     int beg, ns = 0;     for (int i = n - 1; i >= 0; --i) {       beg = (i == n - 1) ? 1 : 0;       for (int j = beg; j < a[i]; ++j) {         ans += dp[b][i][ns ^ (1 << j)];       }       ns ^= (1 << a[i]);     }     if (!ns) ++ans;     for (int i = n - 2; i >= 0; --i) {       for (int j = 1; j < b; ++j) ans += dp[b][i][1 << j];     }     return ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 7;   const int mod = 1e9 + 7;   map<int, int> mp;   int n, x, ma, ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       mp[x]++;     }     for (auto p : mp) {       int x = p.first, y = p.second;       for (int i = 1; i <= 20; i++) {         if ((y >> i) & 1) {           mp[x + i]++;           mp[x] -= (1 << i);         }       }     }     for (auto p : mp) {       int x = p.first, y = p.second;       for (int i = 1; i <= 20; i++) {         if ((y >> i) & 1) {           mp[x + i]++;           mp[x] -= (1 << i);         }       }     }     for (auto p : mp) {       int x = p.first, y = p.second;       ;       if (y != 0) {         ans++;         ma = max(ma, x);       }     }     printf( %d n , ma + 1 - ans);   }
#include<iostream>   #include<cstdio>   #include<fstream>   #include<algorithm>   #include<vector>   #include<map>   #include<set>   #include<queue>   #include<bitset>   #include<cmath>   #include<cstring>   #include<cstdlib>   using namespace std;   typedef long long LL;   typedef double DB;   const int N = 222222;   const int W = 1111111;   int n,m,q,a[N],b[N];   LL sa,sb;   int w=1e6+1,t[W];   LL g[W];   multiset<int> A,B;   multiset<int>::iterator it;   void ad(int x,int y){    int z=x*y;    x++;    while(x<=w){     t[x]+=y;     g[x]+=z;     x+=x&-x;    }   }   void qu(int x,int&y,LL&z){    x++;    while(x){     y+=t[x];     z+=g[x];     x-=x&-x;    }   }   LL ansb(int p){    int o=min(*A.begin(),*B.begin());    if(p<=o)     return sa-(LL)p*n-sb+(LL)p*m;    int x=0;    LL y=0;    qu(p,x,y);    return sa-(LL)o*n-sb+(LL)p*(m-x)+y;   }   LL ansa(int p){    int o=min(*A.begin(),*B.begin());    if(p<=o)     return ansb(p);    return ansb(p)-(p-o);   }   int main()   {    int i,x,y,o;    LL s;    scanf( %d%d%d ,&n,&m,&q);    for(i=1;i<=n;i=i+1){     scanf( %d ,a+i);     sa+=a[i];     A.insert(a[i]);    }    for(i=1;i<=m;i=i+1){     scanf( %d ,b+i);     sb+=b[i];     ad(b[i],1);     B.insert(b[i]);    }    while(q--){     scanf( %d%d ,&i,&x);     if(i<=2){      scanf( %d ,&y);      if(i==1){       A.erase(A.find(a[x]));       sa-=a[x];       A.insert(y);       sa+=y;       a[x]=y;      }      else{       B.erase(B.find(b[x]));       sb-=b[x];       ad(b[x],-1);       B.insert(y);       sb+=y;       ad(y,1);       b[x]=y;      }     }     else{      s=max(ansb(*B.begin()-x),ansb(*B.rbegin()-x));      s=max(s,max(ansa(*A.begin()-x),ansa(*A.rbegin()-x)));      o=min(*A.begin(),*B.begin());      it=A.lower_bound(o+x);      if(it!=A.end())       s=max(s,ansa(*it-x));      if(it!=A.begin()){       it--;       s=max(s,ansa(*it-x));      }      it=A.lower_bound(*B.rbegin()+x);      if(it!=A.end())       s=max(s,ansa(*it-x));      if(it!=A.begin()){       it--;       s=max(s,ansa(*it-x));      }      printf( %lld n ,s);     }    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 200005;   int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};   int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long powb(long long a, long long b) {     long long res = 1;     a;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a;       a = a * a;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void test() {     int n, k;     cin >> n >> k;     vector<int> a(n), b(k), inda(n), vis(n);     set<pair<int, int> > s;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;       inda[a[i]] = i;       s.insert({i, a[i]});     }     for (int i = 0; i < k; i++) {       cin >> b[i];       b[i]--;       vis[b[i]] = 1;     }     long long ans = 1;     for (int i = 0; i < k; i++) {       int idx = inda[b[i]];       auto pos = s.find({idx, a[idx]});       int inc = 0;       if (pos != s.begin()) {         if (vis[(*(prev(pos))).second] == 0) {           inc++;         }       }       if (next(pos) != s.end()) {         if (vis[(*(next(pos))).second] == 0) inc++;       }       (ans *= 1LL * inc) %= mod;       vis[b[i]] = 0;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       test();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e7 + 10;   int n, fac[MAX_N], pri[MAX_N], pri_n, fac_cnt[MAX_N], phi[MAX_N];   long long ans;   void init() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       if (!fac[i]) {         phi[i] = (fac[i] = pri[++pri_n] = i) - 1;         fac_cnt[i] = 1;       }       for (int j = 1; j <= pri_n && pri[j] * i <= n && pri[j] <= fac[i]; j++) {         fac[pri[j] * i] = pri[j];         fac_cnt[pri[j] * i] = fac_cnt[i] + (pri[j] == fac[i] ? 0 : 1);         phi[pri[j] * i] = phi[i] * (pri[j] - (pri[j] == fac[i] ? 0 : 1));       }     }   }   long long get_pair_suc() {     long long suc = 0;     for (int i = 2; i <= n; i++)       if (i * 2 <= n || fac[i] != i) suc++;     return suc * (suc - 1) / 2;   }   long long get_pair_1() {     long long res = 0;     for (int i = 2; i <= n; i++) res += i - 1 - phi[i];     return res;   }   long long get_pair_2() {     static int pref_fac[MAX_N];     int pref_pri = 0;     long long res = 0;     for (int i = 2; i <= n; i++) {       if (fac[i] == i)         pref_pri++;       else         res += phi[i] - (pref_pri - fac_cnt[i]) - 1;     }     for (int i = 2; i <= n; i++) pref_fac[fac[i]]++;     for (int i = 2; i <= n; i++) pref_fac[i] += pref_fac[i - 1];     for (int i = 2; i <= n; i++) {       if (fac[i] != i) continue;       int lim = n / fac[i];       res += pref_fac[lim];       for (int j = i; j <= n; j += i)         if (fac[j] <= lim) res--;     }     for (int i = 2; i <= n; i++)       if (fac_cnt[i] == 2 && fac[i / fac[i]] == i / fac[i]) res--;     return res;   }   void solve() {     long long pair_suc = get_pair_suc();     long long pair_1 = get_pair_1();     long long pair_2 = get_pair_2();     long long pair_3 = pair_suc - pair_1 - pair_2;     long long ans = pair_1 * 1 + pair_2 * 2 + pair_3 * 3;     printf( %lld n , ans);   }   int main() {     init();     solve();   }
#include <bits/stdc++.h>   using namespace std;   struct ASDF {     ASDF& operator,(int& a) {       scanf( %d , &a);       return *this;     }     ASDF& operator,(long int& a) {       scanf( %ld , &a);       return *this;     }     ASDF& operator,(long long int& a) {       scanf( %lld , &a);       return *this;     }     ASDF& operator,(char& c) {       scanf( %c , &c);       return *this;     }     ASDF& operator,(double& d) {       scanf( %lf , &d);       return *this;     }     template <typename T>     ASDF& operator,(T& a) {       cin >> a;       return *this;     }   } asdf;   template <typename T>   ostream& operator<<(ostream& output, vector<T>& v) {     output <<  [  ;     if (int(v.size())) {       output << v[0];     }     for (int i = 1; i < int(v.size()); i++) {       output <<  ,   << v[i];     }     output <<   ] ;     return output;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& output, pair<T1, T2>& p) {     output <<  (   << p.first <<  ,   << p.second <<   ) ;     return output;   }   int main() {     int n, k;     vector<int> v;     cin >> n >> k;     v.resize(n);     for (int i = 0; i < n; i++) cin >> v[i];     long long sum = 0;     for (int i = 0; i < n; i++) {       if (k > 0 && v[i] < 0) {         v[i] = -v[i];         k--;       }     }     if (k & 1) {       sort(v.begin(), v.end());       v[0] = -v[0];     }     for (int i = 0; i < n; i++) sum += v[i];     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long read() {     long long s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * f;   }   long long cnt = 0;   struct trie {     long long ch[26];     long long fail;     long long tail;   } t[10010];   long long f(char c) {     if (c ==  A ) return 0;     if (c ==  C ) return 1;     if (c ==  T )       return 2;     else       return 3;   }   void insert(string s) {     long long l = s.size();     long long nw = 0;     for (long long i = 0, iend = l - 1; i <= iend; ++i) {       if (t[nw].ch[f(s[i])] == 0) {         t[nw].ch[f(s[i])] = ++cnt;       }       nw = t[nw].ch[f(s[i])];     }     t[nw].tail = l;   }   void bfs() {     queue<long long> q;     for (long long i = 0, iend = 25; i <= iend; ++i) {       if (t[0].ch[i]) {         t[t[0].ch[i]].fail = 0;         q.push(t[0].ch[i]);       }     }     while (!q.empty()) {       long long nw = q.front();       q.pop();       for (long long i = 0, iend = 25; i <= iend; ++i) {         if (t[nw].ch[i] != 0) {           t[t[nw].ch[i]].fail = t[t[nw].fail].ch[i];           t[t[nw].ch[i]].tail =               max(t[t[nw].ch[i]].tail, t[t[t[nw].ch[i]].fail].tail);           q.push(t[nw].ch[i]);         } else {           t[nw].ch[i] = t[t[nw].fail].ch[i];         }       }     }   }   const long long inf = 1e16;   long long dp[1010][1010][11];   const long long mod = 1e9 + 9;   signed main() {     n = read(), m = read();     long long l = 0;     for (long long i = 1, iend = m; i <= iend; ++i) {       string s;       cin >> s;       long long ss = s.size();       l = max(l, ss);       insert(s);     }     bfs();     dp[0][0][0] = 1;     for (long long i = 0, iend = n - 1; i <= iend; ++i) {       for (long long j = 0, jend = cnt; j <= jend; ++j) {         long long v;         for (long long k = 0, kend = l; k <= kend; ++k) {           v = dp[i][j][k];           if (v) {             for (long long p = 0, pend = 3; p <= pend; ++p) {               long long nw = t[j].ch[p];               if (t[nw].tail > k)                 (dp[i + 1][nw][0] += v) %= mod;               else if (k < l)                 (dp[i + 1][nw][k + 1] += v) %= mod;             }           }         }       }     }     long long ans = 0;     for (long long i = 0, iend = cnt; i <= iend; ++i) {       (ans += dp[n][i][0]) %= mod;     }     cout << ans;   }