CSES Required Substring
// compile: make data
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) _debug_print(#x, x);
#define Debug(x...) _debug_print_format(#x, x);
std::ifstream terminal("/dev/tty");
#define PP cerr<<"\033[1;30mpause...\e[0m",terminal.ignore();
#else
#define debug(x...)
#define Debug(x...)
#define PP
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define VI vector<int>
#define VII vector<vector<int>>
#define VIII vector<vector<vector<int>>>
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define FIND(a, x) ((find(a.begin(),a.end(),(x))!=a.end())?1:0)
#define cmin(x,...) x=min({(x), __VA_ARGS__})
#define cmax(x,...) x=max({(x), __VA_ARGS__})
#define INTMAX (int)(9223372036854775807)
#define INF (int)(1152921504606846976)
#define NaN (int)(0x8b88e1d0595d51d1)
#define double long double
#define int long long
#define uint unsigned int
#define MAXN 200010
#define P 1000000007
#define MOD0 11635419037240549
#define MOD1 10487639585196761
#define MOD2 10671969493879289

namespace math {
    constexpr int safe_mod(int x, int m) {
        x %= m;
        if (x < 0) x += m;
        return x;
    }
    struct barrett {
        uint _m, im;
        explicit barrett(uint m) : _m(m), im((uint)(-1) / m + 1) {}
        uint umod() const { return _m; }
        uint mul(unsigned int a, unsigned int b) const {
            uint z = a;
            z *= b;
            uint x = (uint)(((unsigned __int128)(z)*im) >> 64);
            uint y = x * _m;
            return (uint)(z - y + (z < y ? _m : 0));
        }
    };
    int pow_mod(int x, int n, int m = INF) {
        if (m == 1) return 0;
        barrett bt((uint)(m));
        uint r = 1, y = (uint)(safe_mod(x, m));
        while (n) {
            if (n & 1) r = bt.mul(r, y);
            y = bt.mul(y, y);
            n >>= 1;
        }
        return r;
    }
}

template <char F, int B, int N> struct strhash {
    const int M[10] = {999999937, 999999929, 999999893, 999999883, 999999797, 999999761, 999999757, 999999739, 999999733, 999999677};
    string s;
    int len;
    vector<vector<int>> pw, hs;
    strhash(string S): s(S), len(S.size()) {
        assert(N <= 10);
        pw.assign(len, vector<int>(N));
        fill(pw[0].begin(), pw[0].end(), 1);
        rep(i, 1, len) rep(j, 0, N) pw[i][j] = pw[i-1][j] * B % M[j];
        hs.assign(len+1, vector<int>(N, 0));
        rep(i, 0, len) rep(j, 0, N) hs[i+1][j] = (hs[i][j] * B + s[i] - F) % M[j];
    }
    vector<int> hash(int l, int r) {
        if (!l) return hs[r+1];
        vector<int> res(N);
        rep(i, 0, N) res[i] = (hs[r+1][i] - hs[l][i] * pw[r-l+1][i] % M[i] + M[i]) % M[i];
        return res;
    }
};

// 11813125
int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n; cin >> n;
    string s; cin >> s;
    int m = s.length();

    strhash<'A', 26, 2> hs(s);
    auto getlen = [&](int len, char c) -> int {
        string cur = s.substr(0, len) + c;
        int maxlen = cur.length();
        strhash<'A', 26, 2> hcur(cur);
        while (cur.substr(cur.length() - maxlen, maxlen) != s.substr(0, maxlen)) --maxlen;
        return maxlen;
    };
    vector<vector<int>> nxt(m+1, vector<int>(26, 0));
    rep(i, 0, m+1) rep(c, 0, 26) nxt[i][c] = getlen(i, (char)(c + 'A'));

    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    dp[0][0] = 1;
    rep(i, 0, n) {
        rep(j, 0, min(i+1, m)) {
            rep(c, 0, 26) {
                int len = nxt[j][c];
                dp[i+1][len] += dp[i][j];
                dp[i+1][len] %= P;
            }
        }
    }
    int sum = math::pow_mod(26, n, P), ans = 0;
    rep(i, 0, m) ans = (ans + dp[n][i]) % P;
    ans = (sum - ans + P) % P;
    cout << ans << endl;

    return 0;
}

Comments

  1. 11 months ago
    2025-12-06 2:26:39

    Downloaded the CK999gameapk and it’s smooth sailing! The games run great on my phone. Highly recommend downloading it if you’re on the go. Worth it ck999gameapk

  2. 11 months ago
    2025-12-19 13:41:40

    Billionaire777vn… sounds like a plan! Gotta get those wins up! Hoping this website can deliver. I’m feeling lucky today, let’s do this guys! billionaire777vn

  3. 10 months ago
    2025-12-29 6:09:50

    Downloaded the xs66app. Pretty smooth experience so far! Let’s see if the games are as good as the app! Find it here at their site: xs66app!

  4. 6 months ago
    2026-4-21 11:24:03

    The Yolo betting app is pretty solid. A lot of great functionality and great performance. It’s definitely worth it. Learn more about this site yolo betting app

  5. 6 months ago
    2026-4-21 11:24:18

    Just did the betsul app download. Hoping it gets me some luck! Gonna try my hand at a few football matches tonight. Wish me luck folks. Gotta support with Betsul!

  6. 6 months ago
    2026-4-21 11:24:34

    Anyone know where to download the Betesporte app? I want to give it a try. Hopefully it’s easier than their website! Find the link to their site here: betesporte baixar app

  7. 3 days ago
    2026-10-30 1:03:19

    Super fun experience so far. The community is great and the games are genuinely addictive in a good way. I’m spending a lot of my free time on phphfun999.

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next