Problem:
不運なイクタ君は持っていた大事な文字列
T
をウィルスによって異なる文字列
T'
に書き換えられてしまった。そのウィルスが
T
の１文字を異なる文字に書き換えてしまったことがわかっている。すなわち
T
と
T'
はちょうど１文字のみ異なっている。イクタ君は
T
を復元するために、
T
が出現していると思われる文書
S
を用意した。
T
を復元するための下準備として
S
の部分文字列で
T
と一致している可能性があるものの個数を調べたい。
文字列
T'
と文書
S
が与えられる。
S = a
1
a
2
a
3
. . . a
|S|
の長さ
|T'|
の部分文字列
a
k
a
k+1
. . . a
k+|T'|−1
(1 ≤ k ≤ |S| − |T'| + 1)
で
T'
と比較して1文字だけ異なるものの数を求めよ。
Input
入力は以下の形式で与えられる。
S
T'
１行目で
S
が与えられる。
２行目で
T'
が与えられる。
S
,
T'
はそれぞれ大文字、小文字のアルファベットのみからなる。
Constraints
入力中の各変数は以下の制約を満たす。
1 ≤ |S| ≤ 300,000
1 ≤ |T'| ≤ |S|
Output
条件を満たす部分文字列の数を1行に出力せよ。
Sample Input 1
abcbcdbc
abc
Output for the Sample Input 1
2
S
の3番目の文字から始まるcbc,
S
の6番目の文字から始まるdbcが条件を満たす。
Sample Input 2
aaaaaa
aaaaaa
Output for the Sample Input 2
0
完全に一致する文字列は数えてはならない。
Sample Input 3
baaaaaaaa
b
Output for the Sample Input 3
8

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;

using ll =  int;
using ha = pair<ll, ll>;
struct RollingHash {
	static const ll mul0 = 10009, mul1 = 10007;
	static const ll add0 = 1000010007, add1 = 1003333331;
	size_t len;
	//vector<ll> hash_, hash2_;
	vector<ha>hash_;
	//static vector<ll> pmo_, pmo2_;
	static vector<ha>pmo_;
	void init(const vector<ll>& s) {
		len = s.size();
		hash_.resize(len + 1);
		hash_[0] = make_pair(0, 0);

		if (pmo_.empty()) {
			pmo_.push_back(make_pair(1, 1));
		}
		while (pmo_.size() <= len) {
			pmo_.push_back(make_pair(pmo_.back().first*mul0, pmo_.back().second*mul1));
		}
		for (unsigned int i = 0; i < len; ++i) {
			hash_[i + 1] = make_pair((hash_[i].first * mul0 + s[i]), (hash_[i].second*mul1 + s[i]));
		}
		return;
	}
	void init(const string& s) {
		vector<ll>v;
		for (char c : s) {
			v.push_back(c);
		}
		init(v);
	}
	ha hash(const int l, const int r)const { // s[l..r]
		return make_pair(hash_[r + 1].first - hash_[l].first * pmo_[r + 1 - l].first,
			hash_[r + 1].second - hash_[l].second * pmo_[r + 1 - l].second);
	}
	ha  hash()const { // s[all]
		return hash(0, len - 1);
	}

	//hashの結合　
	static ha concat(const ha L, const ha R, const int RLength) { // hash(L+R) 
		return make_pair((R.first + L.first*pmo_[RLength].first), (R.second + L.second*pmo_[RLength].second));
	}

	//indexの位置をfromからtoに変えたもののハッシュを返す。
	ha get_changed_hash(const int index, const ll from, const ll to)const {
		const ha p(hash());
		return make_pair(
			p.first + (to - from) * pmo_[len - index - 1].first,
			p.second + (to - from) * pmo_[len - index - 1].second);
	}
};
vector<ha> RollingHash::pmo_;
int main() { 
	string S, T; cin >> S >> T;
	RollingHash srh, trh;
	srh.init(S);
	trh.init(T);
	vector<ha>thash;
	for (int i = 0; i < T.size(); ++i) {
		char from(T[i]);
		for (char ch = 'a'; ch <= 'z'; ++ch) {
			if (ch == from)continue;
			ha ath = trh.get_changed_hash(i, from, ch);
			thash.emplace_back(ath);
		}
		for (char ch = 'A'; ch <= 'Z'; ++ch) {
			if (ch == from)continue;
			ha ath = trh.get_changed_hash(i, from, ch);
			thash.emplace_back(ath);
		}
	}
	sort(thash.begin(), thash.end());
	int ans = 0;
	for (int i = 0; i <= S.size() - T.size(); ++i) {
		ha shash = srh.hash(i, i + T.size() - 1);
		if (binary_search(thash.begin(), thash.end(), shash))ans++;
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 570
memory_kb: 82348
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    std::vector<long long> hash1, hash2, power1, power2;
    std::vector<long long> hash1_, hash2_, power1_, power2_;

    void rev_init(std::string S) {
        std::reverse(S.begin(), S.end());
        int n = (int)S.size();
        hash1_.assign(n+1, 0);
        hash2_.assign(n+1, 0);
        power1_.assign(n+1, 1);
        power2_.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1_[i+1] = (hash1_[i] * base1 + S[i]) % mod1;
            hash2_[i+1] = (hash2_[i] * base2 + S[i]) % mod2;
            power1_[i+1] = (power1_[i] * base1) % mod1;
            power2_[i+1] = (power2_[i] * base2) % mod2;
        }
    }
 
    // construct
    RollingHash(const std::string &S, int rev = 0) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
        if(rev) rev_init(S);
    }
    
    // get hash of S[left:right)
    inline std::pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    inline std::pair<long long, long long> get_rev(int l, int r) const {
        long long res1 = hash1_[r] - hash1_[l] * power1_[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2_[r] - hash2_[l] * power2_[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // [l, r) is palindrome
    inline bool is_palindrome(int l, int r, int n) const {
        int l_rev = n - r;
        int r_rev = n - l;
        return get(l, r) == get_rev(l_rev, r_rev);
    }
 
    // get lcp of S[a:) and T[b:)
    inline int getLCP(int a, int b) const {
        int len = std::min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = -1, high = len;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;
    int m = t.size();
    s = t + "#" + s;
    RollingHash r(s);
    int lim = s.size();
    int ans = 0;
    for(int i = m + 1; i + m <= lim; i ++) {
        int val = r.getLCP(0, i);
        if(val == m) continue;
        val ++;
        if(val + r.getLCP(val, i + val) == m) ans ++;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 17916
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

namespace Random {
mt19937_64 randgen(chrono::steady_clock::now().time_since_epoch().count());
using u64 = unsigned long long;
u64 get() {
    return randgen();
}
template <typename T> T get(T L) { // [0,L]

    return get() % (L + 1);
}
template <typename T> T get(T L, T R) { // [L,R]

    return get(R - L) + L;
}
}; // namespace Random

/**
 * @brief Random
 */

struct RollingHash {
    using ull = unsigned long long;
    const ull MOD = 0x1fffffffffffffff;
    const ull base;
    vector<ull> hashed, power;

    static constexpr ull mask(ll a) { return (1ULL << a) - 1; }

    inline ull mul(ull a, ull b) const {
        __uint128_t ans = __uint128_t(a) * b;
        ans = (ans >> 61) + (ans & MOD);
        if (ans >= MOD)
            ans -= MOD;
        return ans;
    }

    static inline ull genbase() { return Random::get(ull(0x1fffffffffffffff)); }
    RollingHash() = default;

    RollingHash(const string &s, ull base) : base(base) {
        ll n = s.size();
        hashed.assign(n + 1, 0);
        power.assign(n + 1, 0);
        power[0] = 1;
        for (ll i = 0; i < n; i++) {
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i];
            if (hashed[i + 1] >= MOD)
                hashed[i + 1] -= MOD;
        }
    }

    ull get(ll l, ll r) const {
        ull ret = hashed[r] + MOD - mul(hashed[l], power[r - l]);
        if (ret >= MOD)
            ret -= MOD;
        return ret;
    }

    ull connect(ull h1, ull h2, ll h2len) const {
        ull ret = mul(h1, power[h2len]) + h2;
        if (ret >= MOD)
            ret -= MOD;
        return ret;
    }

    void connect(const string &s) {
        ll n = hashed.size() - 1, m = s.size();
        hashed.resize(n + m + 1);
        power.resize(n + m + 1);
        for (ll i = n; i < n + m; i++) {
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i - n];
            if (hashed[i + 1] >= MOD)
                hashed[i + 1] -= MOD;
        }
    }

    ll LCP(const RollingHash &b, ll l1, ll r1, ll l2, ll r2) {
        ll len = min(r1 - l1, r2 - l2);
        ll low = -1, high = len + 1;
        while (high - low > 1) {
            ll mid = (low + high) / 2;
            if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
                low = mid;
            else
                high = mid;
        }
        return low;
    }
};

/**
 * @brief Rolling Hash
 */

int main() {
    string S;
    string T;
    cin >> S >> T;
    ull base = RollingHash::genbase();
    RollingHash SH(S,base), TH(T,base);
    int N = S.size(), M = T.size();
    int ANS = 0;
    rep(i,0,N) {
        if (i+M > N) break;
        if (SH.get(i,i+M) == TH.get(0,M)) continue;
        int X = SH.LCP(TH,i,i+M,0,M);
        int Y = SH.LCP(TH,i+X+1,i+M,X+1,M);
        if (X+Y+1 == M) ANS++;
    }
    cout << ANS << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 10904
final_rank: 2

code_snippet: #pragma region Macros
#include <bits/stdc++.h>

using namespace std;

using lint = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)             \
    if (bool) {                \
        cout << "Yes" << endl; \
    } else {                   \
        cout << "No" << endl;  \
    }

ostream &operator<<(ostream &dest, __int128_t value) {
    ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char *d = end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(ios_base::badbit);
        }
    }
    return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 != (int)v.size() ? " " : "");
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << " ";
        itr--;
    }
    return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << itr->first << " -> " << itr->second << "\n";
    }
    return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
    cout << a;
    (cout << ... << (cout << ' ', b));
    cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &in : v) is >> in;
    return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
    cin >> first;
    in(rest...);
    return;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

struct RollingHash {
    static const uint64_t mod = (1ull << 61ull) - 1;
    using uint128_t = __uint128_t;
    vector<uint64_t> power;
    const uint64_t base;

    static inline uint64_t add(uint64_t a, uint64_t b) {
        if ((a += b) >= mod) a -= mod;
        return a;
    }

    static inline uint64_t mul(uint64_t a, uint64_t b) {
        uint128_t c = (uint128_t)a * b;
        return add(c >> 61, c & mod);
    }

    static inline uint64_t generate_base() {
        mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
        uniform_int_distribution<uint64_t> rand(1, RollingHash::mod - 1);
        return rand(mt);
    }

    inline void expand(size_t sz) {
        if (power.size() < sz + 1) {
            int pre_sz = (int)power.size();
            power.resize(sz + 1);
            for (int i = pre_sz - 1; i < sz; i++) {
                power[i + 1] = mul(power[i], base);
            }
        }
    }

    explicit RollingHash(uint64_t base = generate_base())
        : base(base), power{1} {}

    vector<uint64_t> build(const string &s) const {
        int sz = s.size();
        vector<uint64_t> hashed(sz + 1);
        for (int i = 0; i < sz; i++) {
            hashed[i + 1] = add(mul(hashed[i], base), s[i]);
        }
        return hashed;
    }

    template <typename T>
    vector<uint64_t> build(const vector<T> &s) const {
        int sz = s.size();
        vector<uint64_t> hashed(sz + 1);
        for (int i = 0; i < sz; i++) {
            hashed[i + 1] = add(mul(hashed[i], base), s[i]);
        }
        return hashed;
    }

    uint64_t query(const vector<uint64_t> &s, int l, int r) {
        expand(r - l);
        return add(s[r], mod - mul(s[l], power[r - l]));
    }

    uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) {
        expand(h2len);
        return add(mul(h1, power[h2len]), h2);
    }

    int lcp(const vector<uint64_t> &a, int l1, int r1,
            const vector<uint64_t> &b, int l2, int r2) {
        int len = min(r1 - l1, r2 - l2);
        int low = 0, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (query(a, l1, l1 + mid) == query(b, l2, l2 + mid))
                low = mid;
            else
                high = mid;
        }
        return low;
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);
    string s, t, rs, rt;
    in(s, t);
    int n = s.size();
    int m = t.size();
    rs = s;
    rt = t;
    reverse(all(rs));
    reverse(all(rt));
    RollingHash roll;
    auto rhs = roll.build(s);
    auto rht = roll.build(t);
    auto rhrs = roll.build(rs);
    auto rhrt = roll.build(rt);
    int res = 0;
    rep(i, n - m + 1) {
        int l = roll.lcp(rhs, i, i + m, rht, 0, m);
        int r = roll.lcp(rhrs, n - m - i, n - i, rhrt, 0, m);
        if (l + r == m - 1) res++;
    }
    out(res);
}
accuracy: 1
time_ms: 60
memory_kb: 12536
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    cout << fixed << setprecision(10);
    string s, t; cin >> s >> t;
    int len = s.size();
    int tsz = t.size();

    const ll PRIME[6] = {
        998244353,
        998244389,
        998244391,
        998244397,
        998244407,
        998244431
    };

    vector<int> cor(len);
    for(int m = 0; m < 3; m++){
        ll base = PRIME[m], mod = PRIME[m + 3];
        vector<ll> powb(len + 10);
        powb[0] = 1;
        for(int i = 0; i < len + 5; i++){
            powb[i + 1] = powb[i] * base % mod;
        }
        vector<ll> sHash(len + 1);
        for(int i = 0; i < len; i++){
            sHash[i + 1] = (sHash[i] * base + (int)s[i]) % mod;
        }
        vector<ll> tHash(tsz + 1);
        for(int i = 0; i < tsz; i++){
            tHash[i + 1] = (tHash[i] * base + (int)t[i]) % mod;
        }
        
        for(int i = 0; i + tsz <= len; i++){
            // ok := correct char length
            int ok = 0, ng = tsz + 1;
            while(abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                ll L = sHash[i + mid] - sHash[i] * powb[mid];
                L = (L % mod + mod) % mod;
                ll R = (tHash[mid]) % mod;
                if(L == R) ok = mid;
                else ng = mid;
            }
            //cout << ng << endl;
            if(ok < tsz - 1){
                ll L = sHash[i + tsz]  - sHash[i + ng] * powb[tsz - ng];
                L = (L % mod + mod) % mod;
                ll R = (tHash[tsz] - tHash[ng] * powb[tsz - ng]);
                R = (R % mod + mod) % mod;
                //cout << "(" << L << " " << R << ")" << endl;
                if(L == R) cor[i]++;
            }
            else if(ok == tsz - 1){
                cor[i]++;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < len; i++){
        if(cor[i] == 3) ans++;
        //cout << cor[i] << " ";
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 330
memory_kb: 10948
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;

int main() {
  //   char c = 'z' - 'a';
  //   cout << int(c) << endl;
  //   5 bit
  string s, t;
  cin >> s >> t;
  bitset<1700000> a, b, v;
  int cur = 1699999;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    char c = s[i] - 'a' + 1;
    for (int j = 4; j >= 0; j--) {
      a[cur] = c & (1 << j);
      cur--;
    }
  }

  cur = 1699999;
  int m = t.size();
  for (int i = 0; i < m; i++) {
    char c = t[i] - 'a' + 1;
    for (int j = 4; j >= 0; j--) {
      b[cur] = c & (1 << j);
      cur--;
    }
  }
  int res = 0;
  for (int i = 0; i < n - m + 1; i++) {
    v = a & b;
    if (v.count() == m - 1) {
      res++;
    }
    b >>= 5;
  }
  cout << res << endl;
}
accuracy: 0.01694915254237288
time_ms: 10
memory_kb: 4196
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef tuple<ll, ll, ll> tt;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pl> vp;
typedef vector<tt> vt;
typedef vector<string> vs;

const ll INF = 1000000010;
const ll INFL = INF * INF;
const double MYPI = acos(-1);
const ld epsilon = 1e-10;

#define ovl(a, b, c, d, e, ...) e
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define DEBUG(...) DEBUG_(#__VA_ARGS__, __VA_ARGS__)
#define REP1(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, l, r) for (int i = (l); i < (r); i++)
#define REP3(i, l, r, d) for (int i = (l); i < (r); i += (d))
#define REP(...) ovl(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define RREP1(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define RREP3(i, l, r, d) for (int i = (r)-1; i >= (l); i -= (d))
#define RREP(...) ovl(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define EACH1(e, a) for (auto &e : a)
#define EACH2(x, y, a) for (auto &[x, y] : a)
#define EACH3(x, y, z, a) for (auto &[x, y, z] : a)
#define EACH(...) ovl(__VA_ARGS__, EACH3, EACH2, EACH1)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
#define sz(x) (ll) x.size()
#define LB(a, x) (lower_bound(ALL(a), x) - a.begin())
#define UB(a, x) (upper_bound(ALL(a), x) - a.begin())
#define FLG(x, i) (((x) >> (i)) & 1)
#define CNTBIT(x) __builtin_popcountll(x)
#define TOPBIT(t) (t == 0 ? -1 : 63 - __builtin_clzll(t))
#define IN(x, a, b) ((a) <= (x) && (x) < (b))
#define int ll

template <class T, class... Ts>
void OUT(const T &a, const Ts &...b) {
    cout << a;
    (cout << ... << (cout << " ", b));
    cout << endl;
}

template <class T>
void DEBUG_(string_view name, const T &a) {
    cout << name << ": " << a << endl;
}

template <class T>
void DEBUG_(string_view name, const vector<T> &a) {
    cout << name << ": ";
    REP(i, sz(a)) cout << a[i] << " ";
    cout << endl;
}

template <class T, class U>
bool chmax(T &x, const U &y) {
    return x < y ? x = y, 1 : 0;
}
template <class T, class U>
bool chmin(T &x, const U &y) {
    return x > y ? x = y, 1 : 0;
}

template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
using maxheap = priority_queue<T>;

const vl dy = {1, 0, -1, 0, 1, -1, -1, 1};
const vl dx = {0, 1, 0, -1, 1, 1, -1, -1};

template <class T = ll>
struct Edge {
    ll from, to;
    T cost;
    ll idx;
    Edge(ll f, ll t, T c = 1, ll i = -1) : from(f), to(t), cost(c), idx(i) {}
    operator int() const { return to; }
};

template <class T = ll>
struct Graph {
    vector<vector<Edge<T>>> g;
    ll es;
    explicit Graph(ll n) : g(n), es(0) {}
    size_t size() const { return sz(g); }
    void add_directed_edge(ll from, ll to, T cost = 1) {
        g[from].eb(from, to, cost, es++);
    }
    void add_edge(ll from, ll to, T cost = 1) {
        g[from].eb(from, to, cost, es);
        g[to].eb(to, from, cost, es++);
    }
    inline vector<Edge<T>> &operator[](const int &k) { return g[k]; }
    inline const vector<Edge<T>> &operator[](const int &k) const { return g[k]; }
};

//-----------------------------------------------------------------------

template <class T>
vector<int> z_algorithm(const vector<T>& s) {
    int n = int(s.size());
    if (n == 0) return {};
    vector<int> z(n);
    z[0] = 0;
    for (int i = 1, j = 0; i < n; i++) {
        int& k = z[i];
        k = (j + z[j] <= i) ? 0 : min(j + z[j] - i, z[i - j]);
        while (i + k < n && s[k] == s[i + k]) k++;
        if (j + z[j] < i + z[i]) j = i;
    }
    z[0] = n;
    return z;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    string _S,_T;
    cin>>_S>>_T;
    int N=_S.size();
    int M=_T.size();

    vl S(ALL(_S));
    vl T(ALL(_T));
    
    vl TS1, TS2;
    REP2(i,1,int(T.size()))TS1.pb(T[i]);
    TS1.pb(-1);
    EACH(c,S)TS1.pb(c);
    REP(i,int(T.size())-1)TS2.pb(T[i]);
    TS2.pb(-1);
    EACH(c,S)TS2.pb(c);

    auto _z1=z_algorithm(TS1);
    vl z1(_z1.begin()+T.size(),_z1.end());
    auto _z2=z_algorithm(TS2);
    vl z2(_z2.begin()+T.size(),_z2.end());

    int ans=0;
    REP(i,N){
        int latter=i+1<int(z1.size())?z1[i+1]:0;
        int center=int(T.size())-1-latter;
        if(S[i]==T[center])continue;
        if(i-center<0)continue;
        if(z2[i-center]==center)ans++;
    }
    
    OUT(ans);

    return 0;
}
accuracy: 0.2542372881355932
time_ms: 10
memory_kb: 26940
final_rank: 16

code_snippet: #include <string.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define REP3(i, l, r, s)                                               \
    for (int i = int(l), rep3_r = int(r), rep3_s = int(s); i < rep3_r; \
         i += rep3_s)
#define REP2(i, l, r) REP3(i, l, r, 1)
#define REP1(i, n) REP2(i, 0, n)
#define rep(...) REP_OVERLOAD(__VA_ARGS__, REP3, REP2, REP1, )(__VA_ARGS__)
#define repin(i, l, r) for (int i = int(l), repin_r = int(r); i <= repin_r; ++i)

#define RREP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define RREP3(i, l, r, s)                                                      \
    for (int i = int(r) - 1, rrep3_l = int(l), rrep3_s = int(s); i >= rrep3_l; \
         i -= rrep3_s)
#define RREP2(i, l, r) RREP3(i, l, r, 1)
#define RREP1(i, n) RREP2(i, 0, n)
#define rrep(...) RREP_OVERLOAD(__VA_ARGS__, RREP3, RREP2, RREP1, )(__VA_ARGS__)
#define rrepin(i, l, r) \
    for (int i = int(r), rrepin_l = int(l); i >= rrepin_l; --i)


#include <algorithm>
#include <cassert>
#include <vector>

namespace rklib {

// a <- max(a, b)
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// a <- min(a, b)
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

// if a < 0: a <- b
// else: a <- min(a, b)
template <class T>
bool chmin_non_negative(T &a, const T &b) {
    if (a < 0 || a > b) {
        a = b;
        return true;
    }
    return false;
}

// floor(num / den)
template <class T>
T div_floor(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num >= 0 ? num / den : (num + 1) / den - 1;
}

// ceil(num / den)
template <class T>
T div_ceil(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num <= 0 ? num / den : (num - 1) / den + 1;
}

namespace internal {

template <class T>
T remainder_count(T r, T b, T m) {
    return r / m * b + std::min(b, r % m);
}

}  // namespace internal

// Number of integer x s.t.
// - x in [l, r)
// - x mod m in [a, b)
template <class T>
T remainder_count(T l, T r, T a, T b, T m) {
    assert(l >= 0);
    assert(m >= 1);

    if (l >= r || a >= b) return 0;
    if (m <= a || b < 0) return 0;
    chmax(a, T(0));
    chmin(b, m);

    auto res = internal::remainder_count(r, b, m);
    if (l >= 1) res -= internal::remainder_count(l, b, m);
    if (a >= 1) res -= internal::remainder_count(r, a, m);
    if (l >= 1 && a >= 1) res += internal::remainder_count(l, a, m);

    return res;
}

}  // namespace rklib


using namespace std;
using namespace rklib;

using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;


#include <string>
#include <vector>

namespace rklib {

struct RollingHash {
   private:
    using ulint = unsigned long long;
    const ulint hash_mod = (1ULL << 61ULL) - 1, hash_base = 1'000'000'007;
    const ulint mask_30bit = (1ULL << 30ULL) - 1,
                mask_31bit = (mask_30bit << 1ULL) + 1;
    const ulint num = hash_mod << 2LL;
    std::vector<ulint> pow_table, hash;
    int n;

    ulint calc_mul31(ulint a, ulint b) {
        ulint au = a >> 31ULL, ad = a & mask_31bit;
        ulint mid = au * b, midu = mid >> 30ULL, midd = mid & mask_30bit;
        return midu + (midd << 31ULL) + ad * b;
    }

    ulint calc_mul61(ulint a, ulint b) {
        ulint au = a >> 31ULL, ad = a & mask_31bit;
        ulint bu = b >> 31ULL, bd = b & mask_31bit;
        ulint mid = au * bd + ad * bu, midu = mid >> 30ULL,
              midd = mid & mask_30bit;
        return 2 * au * bu + midu + (midd << 31ULL) + ad * bd;
    }

    ulint calc_mod(ulint x) {
        x = (x & hash_mod) + (x >> 61ULL);
        if (x > hash_mod) x -= hash_mod;
        return x;
    }

   public:
    RollingHash(std::string &s) {
        n = s.size();
        pow_table.resize(n + 1);
        hash.resize(n + 1);
        pow_table[0] = 1ULL;
        for (int i = 0; i < n; ++i)
            pow_table[i + 1] = calc_mod(calc_mul61(pow_table[i], hash_base));
        hash[0] = 0ULL;
        for (int i = 0; i < n; ++i)
            hash[i + 1] = calc_mod(calc_mul61(hash[i], hash_base) + s[i]);
    }

    ulint slice(int l, int r) {
        return calc_mod(hash[r] + num - calc_mul61(hash[l], pow_table[r - l]));
    }
};

int calc_lcp(RollingHash &rh1, int l1, int r1, RollingHash &rh2, int l2,
             int r2) {
    if (l1 == r1 || l2 == r2) {
        return 0;
    }
    int len = std::min(r1 - l1, r2 - l2);
    if (rh1.slice(l1, l1 + len) == rh2.slice(l2, l2 + len)) {
        return len;
    }

    int low = 0, high = len;
    while (high - low > 1) {
        auto mid = (low + high) / 2;
        if (rh1.slice(l1, l1 + mid) == rh2.slice(l2, l2 + mid)) {
            low = mid;
        } else {
            high = mid;
        }
    }
    return low;
}

}  // namespace rklib


int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    RollingHash rs(s), rt(t);
    int ans = 0;
    for (int i = 0; i + m <= n; ++i) {
        auto lcp = calc_lcp(rs, i, i + m, rt, 0, m);
        if (lcp == m) continue;
        if (rs.slice(i + lcp + 1, i + m) == rt.slice(lcp + 1, m)) {
            ++ans;
        }
    }
    printf("%d\n", ans);
}
accuracy: 1
time_ms: 40
memory_kb: 10916
final_rank: 1

code_snippet: #include<bits/stdc++.h>

using namespace std;

struct RollingHash {
  static const uint64_t mod = (1ull << 61ull) - 1;
  using uint128_t = __uint128_t;
  vector< uint64_t > power;
  const uint64_t base;

  static inline uint64_t add(uint64_t a, uint64_t b) {
    if ((a += b) >= mod) a -= mod;
    return a;
  }

  static inline uint64_t mul(uint64_t a, uint64_t b) {
    uint128_t c = (uint128_t)a * b;
    return add(c >> 61, c & mod);
  }

  static inline uint64_t generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution< uint64_t > rand(1, RollingHash::mod - 1);
    return rand(mt);
  }

  inline void expand(size_t sz) {
    if (power.size() < sz + 1) {
      int pre_sz = (int)power.size();
      power.resize(sz + 1);
      for (int i = pre_sz - 1; i < sz; i++) {
        power[i + 1] = mul(power[i], base);
      }
    }
  }

  explicit RollingHash(uint64_t base = generate_base()) : base(base), power{1} {}

  vector< uint64_t > build(const string &s) const {
    int sz = s.size();
    vector< uint64_t > hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  template< typename T >
  vector< uint64_t > build(const vector< T > &s) const {
    int sz = s.size();
    vector< uint64_t > hashed(sz + 1);
    for (int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  uint64_t query(const vector< uint64_t > &s, int l, int r) {
    expand(r - l);
    return add(s[r], mod - mul(s[l], power[r - l]));
  }

  uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) {
    expand(h2len);
    return add(mul(h1, power[h2len]), h2);
  }

  int lcp(const vector< uint64_t > &a, int l1, int r1, const vector< uint64_t > &b, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = 0, high = len + 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (query(a, l1, l1 + mid) == query(b, l2, l2 + mid)) low = mid;
      else high = mid;
    }
    return low;
  }
};

int func(){
  string s;
  cin >> s;
  string t;
  cin >> t;

  RollingHash rh;
  auto vs = rh.build(s);
  auto vt = rh.build(t);
  reverse(s.begin(),s.end());
  reverse(t.begin(),t.end());
  auto vrs = rh.build(s);
  auto vrt = rh.build(t);

  int res = 0;

  for(int l=0;l<s.size()+1-t.size();++l){
    int r = l + t.size();
    int rl = s.size() - l - t.size();
    int rr = s.size() - l - 1;
    int lmatch = rh.lcp(vs,l,r,vt,0,t.size());
    int rmatch = rh.lcp(vrs,rl,rr,vrt,0,t.size());
    if(lmatch + rmatch + 1 == t.size()){
      ++res;
    }
  }
  return res;
}

int main(){
  cout << func() << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 12304
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll L;
string ST;
string dfs(string S) {
    ll N = S.size();
    ll K = 0;
    string res = "";
    rep(mm, N) {
        if (S[mm] == '(')K++;
        if (S[mm] == ')')K--;
        if (K != 0)continue;
        if (S[mm] <= '9' && S[mm] >= '0') {
            ll d = 0;
            ll k = mm;
            while (S[k] <= '9' && S[k] >= '0') {
                d *= 10;
                d += S[k] - '0';
                k++;
            }
            ll kako = 0;
            string P;
            if (S[k] == '(') {
                for (ll j = k; j < N; j++) {
                    if (S[j] == '(')kako++;
                    if (S[j] == ')') {
                        kako--;
                        if (kako == 0) {
                            P = dfs(S.substr(k + 1, j - k - 1));
                            mm = j;
                            break;
                        }
                    }
                }
            }
            else {
                P = S.substr(k, 1);
                mm = k;
            }
            chmin(d, ll((L - res.size()) / P.size() + 1));
            rep(D, d) {
                res = res + P;
            }
            if (res.size() > L)return res;

        }
        else {
            res.push_back(S[mm]);
        }
    }
    return res;

}

struct rollinghash {
    const ll base = 9971;
    const vector<ll> MoD = { 999999937, 1000000007,32417441 };
    string S;
    vector<ll> hash[3], power[3];
    rollinghash(const string& cs) { init(cs); }

    ll Shash(string T, ll iter) {
        ll n = T.size();
        ll reshash = 0;
        ll respow = 1;
        rep(i, n) {
            reshash = (reshash * base + T[i]) % MoD[iter];
        }
        return reshash;
    }

    void init(const string& cs) {
        S = cs;
        ll n = S.size();
        rep(iter, MoD.size()) {
            hash[iter].assign(n + 1, 0);
            power[iter].assign(n + 1, 1);
            rep(i, n) {
                hash[iter][i + 1] = (hash[iter][i] * base + S[i]) % MoD[iter];
                power[iter][i + 1] = power[iter][i] * base % MoD[iter];
            }
        }
    }



    ll get(int l, int r, int id = 0) const {
        return ((hash[id][r] - (hash[id][l] * power[id][r - l]) % MoD[id]) + MoD[id]) % MoD[id];
    }
    ll getLCP(int a, int b) const {
        int len = min((int)S.size() - a, (int)S.size() - b);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a + mid, 0) != get(b, b + mid, 0)) high = mid;
            else if (get(a, a + mid, 1) != get(b, b + mid, 1)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    string T;
    cin >> S >> T;
    rollinghash s(S);
    map<tuple<ll, ll>, ll> M;
    rep(i, S.size() - T.size() + 1) {
        ll a0 = s.get(i, i + T.size(), 0);
        ll a1 = s.get(i, i + T.size(), 1);
        M[{a0, a1}]++;
    }
    ll an = 0;
    rollinghash t(T);
    ll ht0 = t.get(0, T.size(), 0);
    ll ht1 = t.get(0, T.size(), 1);
    rep(tt, T.size()) {
        for (char a = 'a'; a <= 'z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][T.size()-tt-1];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][T.size() -tt-1];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            if (M.count({ t0,t1 }))an += M[{t0, t1}];
        }

        for (char a = 'A'; a <= 'Z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][T.size() - tt - 1];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][T.size() - tt - 1];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            if (M.count({ t0,t1}))an += M[{t0, t1}];
        }
    }
    cout << an << endl;


}
accuracy: 1
time_ms: 1620
memory_kb: 36124
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll L;
string ST;
string dfs(string S) {
    ll N = S.size();
    ll K = 0;
    string res = "";
    rep(mm, N) {
        if (S[mm] == '(')K++;
        if (S[mm] == ')')K--;
        if (K != 0)continue;
        if (S[mm] <= '9' && S[mm] >= '0') {
            ll d = 0;
            ll k = mm;
            while (S[k] <= '9' && S[k] >= '0') {
                d *= 10;
                d += S[k] - '0';
                k++;
            }
            ll kako = 0;
            string P;
            if (S[k] == '(') {
                for (ll j = k; j < N; j++) {
                    if (S[j] == '(')kako++;
                    if (S[j] == ')') {
                        kako--;
                        if (kako == 0) {
                            P = dfs(S.substr(k + 1, j - k - 1));
                            mm = j;
                            break;
                        }
                    }
                }
            }
            else {
                P = S.substr(k, 1);
                mm = k;
            }
            chmin(d, ll((L - res.size()) / P.size() + 1));
            rep(D, d) {
                res = res + P;
            }
            if (res.size() > L)return res;

        }
        else {
            res.push_back(S[mm]);
        }
    }
    return res;

}

struct rollinghash {
    const ll base = 9971;
    const vector<ll> MoD = { 999999937, 1000000007,32417441 };
    string S;
    vector<ll> hash[3], power[3];
    rollinghash(const string& cs) { init(cs); }

    ll Shash(string T, ll iter) {
        ll n = T.size();
        ll reshash = 0;
        ll respow = 1;
        rep(i, n) {
            reshash = (reshash * base + T[i]) % MoD[iter];
        }
        return reshash;
    }

    void init(const string& cs) {
        S = cs;
        ll n = S.size();
        rep(iter, MoD.size()) {
            hash[iter].assign(n + 1, 0);
            power[iter].assign(n + 1, 1);
            rep(i, n) {
                hash[iter][i + 1] = (hash[iter][i] * base + S[i]) % MoD[iter];
                power[iter][i + 1] = power[iter][i] * base % MoD[iter];
            }
        }
    }



    ll get(int l, int r, int id = 0) const {
        return ((hash[id][r] - (hash[id][l] * power[id][r - l]) % MoD[id]) + MoD[id]) % MoD[id];
    }
    ll getLCP(int a, int b) const {
        int len = min((int)S.size() - a, (int)S.size() - b);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a + mid, 0) != get(b, b + mid, 0)) high = mid;
            else if (get(a, a + mid, 1) != get(b, b + mid, 1)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    string T;
    cin >> S >> T;
    rollinghash s(S);
    map<tuple<ll, ll, ll>, ll> M;
    rep(i, S.size() - T.size() + 1) {
        ll a0 = s.get(i, i + T.size(), 0);
        ll a1 = s.get(i, i + T.size(), 1);
        ll a2 = s.get(i, i + T.size(), 2);
        M[{a0, a1, a2}]++;
    }
    ll an = 0;
    rollinghash t(T);
    ll ht0 = t.get(0, T.size(), 0);
    ll ht1 = t.get(0, T.size(), 1);
    ll ht2 = t.get(0, T.size(), 2);
    rep(tt, T.size()) {
        for (char a = 'a'; a <= 'z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][T.size()-tt-1];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][T.size() -tt-1];
            ll t2 = ht2 + ll(a - T[tt]) * t.power[2][T.size() -tt-1];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            t2 = (t2 % t.MoD[2] + t.MoD[2]) % t.MoD[2];
            if (M.count({ t0,t1,t2 }))an += M[{t0, t1, t2}];
        }

        for (char a = 'A'; a <= 'Z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][T.size() - tt - 1];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][T.size() - tt - 1];
            ll t2 = ht2 + ll(a - T[tt]) * t.power[2][T.size() - tt - 1];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            t2 = (t2 % t.MoD[2] + t.MoD[2]) % t.MoD[2];
            if (M.count({ t0,t1,t2 }))an += M[{t0, t1, t2}];
        }
    }
    cout << an << endl;


}
accuracy: 1
time_ms: 1890
memory_kb: 40580
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll L;
string ST;
string dfs(string S) {
    ll N = S.size();
    ll K = 0;
    string res = "";
    rep(mm, N) {
        if (S[mm] == '(')K++;
        if (S[mm] == ')')K--;
        if (K != 0)continue;
        if (S[mm] <= '9' && S[mm] >= '0') {
            ll d = 0;
            ll k = mm;
            while (S[k] <= '9' && S[k] >= '0') {
                d *= 10;
                d += S[k] - '0';
                k++;
            }
            ll kako = 0;
            string P;
            if (S[k] == '(') {
                for (ll j = k; j < N; j++) {
                    if (S[j] == '(')kako++;
                    if (S[j] == ')') {
                        kako--;
                        if (kako == 0) {
                            P = dfs(S.substr(k + 1, j - k - 1));
                            mm = j;
                            break;
                        }
                    }
                }
            }
            else {
                P = S.substr(k, 1);
                mm = k;
            }
            chmin(d, ll((L - res.size()) / P.size() + 1));
            rep(D, d) {
                res = res + P;
            }
            if (res.size() > L)return res;

        }
        else {
            res.push_back(S[mm]);
        }
    }
    return res;

}

struct rollinghash {
    const ll base = 9971;
    const vector<ll> MoD = { 999999937, 1000000007,32417441 };
    string S;
    vector<ll> hash[3], power[3];
    rollinghash(const string& cs) { init(cs); }

    ll Shash(string T, ll iter) {
        ll n = T.size();
        ll reshash = 0;
        ll respow = 1;
        rep(i, n) {
            reshash = (reshash * base + T[i]) % MoD[iter];
        }
        return reshash;
    }

    void init(const string& cs) {
        S = cs;
        ll n = S.size();
        rep(iter, MoD.size()) {
            hash[iter].assign(n + 1, 0);
            power[iter].assign(n + 1, 1);
            rep(i, n) {
                hash[iter][i + 1] = (hash[iter][i] * base + S[i]) % MoD[iter];
                power[iter][i + 1] = power[iter][i] * base % MoD[iter];
            }
        }
    }



    ll get(int l, int r, int id = 0) const {
        return ((hash[id][r] - (hash[id][l] * power[id][r - l]) % MoD[id]) + MoD[id]) % MoD[id];
    }
    ll getLCP(int a, int b) const {
        int len = min((int)S.size() - a, (int)S.size() - b);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a + mid, 0) != get(b, b + mid, 0)) high = mid;
            else if (get(a, a + mid, 1) != get(b, b + mid, 1)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    string T;
    cin >> S >> T;
    rollinghash s(S);
    map<tuple<ll, ll,ll>, ll> M;
    rep(i, S.size() - T.size() + 1) {
        ll a0 = s.get(i, i + T.size(), 0);
        ll a1 = s.get(i, i + T.size(), 1);
        ll a2 = s.get(i, i + T.size(), 2);
        M[{a0, a1,a2}]++;
    }
    ll an = 0;
    rollinghash t(T);
    ll ht0 = t.get(0, T.size(), 0);
    ll ht1 = t.get(0, T.size(), 1);
    ll ht2 = t.get(0, T.size(), 2);
    rep(tt, T.size()) {
        for (char a = 'a'; a <= 'z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][tt];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][tt];
            ll t2 = ht2 + ll(a - T[tt]) * t.power[2][tt];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            t2 = (t2 % t.MoD[2] + t.MoD[2]) % t.MoD[2];
            if (M.count({ t0,t1,t2 }))an += M[{t0, t1,t2}];
        }

        for (char a = 'A'; a <= 'Z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][tt];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][tt];
            ll t2 = ht2 + ll(a - T[tt]) * t.power[2][tt];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            t2 = (t2 % t.MoD[2] + t.MoD[2]) % t.MoD[2];
            if (M.count({ t0,t1,t2 }))an += M[{t0, t1, t2}];
        }
    }
    cout << an << endl;


}
accuracy: 0.2033898305084746
time_ms: 340
memory_kb: 25108
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll L;
string ST;
string dfs(string S) {
    ll N = S.size();
    ll K = 0;
    string res = "";
    rep(mm, N) {
        if (S[mm] == '(')K++;
        if (S[mm] == ')')K--;
        if (K != 0)continue;
        if (S[mm] <= '9' && S[mm] >= '0') {
            ll d = 0;
            ll k = mm;
            while (S[k] <= '9' && S[k] >= '0') {
                d *= 10;
                d += S[k] - '0';
                k++;
            }
            ll kako = 0;
            string P;
            if (S[k] == '(') {
                for (ll j = k; j < N; j++) {
                    if (S[j] == '(')kako++;
                    if (S[j] == ')') {
                        kako--;
                        if (kako == 0) {
                            P = dfs(S.substr(k + 1, j - k - 1));
                            mm = j;
                            break;
                        }
                    }
                }
            }
            else {
                P = S.substr(k, 1);
                mm = k;
            }
            chmin(d, ll((L - res.size()) / P.size() + 1));
            rep(D, d) {
                res = res + P;
            }
            if (res.size() > L)return res;

        }
        else {
            res.push_back(S[mm]);
        }
    }
    return res;

}

struct rollinghash {
    const ll base = 9973;
    const vector<ll> MoD = { 999999937, 1000000007 };
    string S;
    vector<ll> hash[2], power[2];
    rollinghash(const string& cs) { init(cs); }

    ll Shash(string T, ll iter) {
        ll n = T.size();
        ll reshash = 0;
        ll respow = 1;
        rep(i, n) {
            reshash = (reshash * base + T[i]) % MoD[iter];
        }
        return reshash;
    }

    void init(const string& cs) {
        S = cs;
        ll n = S.size();
        rep(iter, MoD.size()) {
            hash[iter].assign(n + 1, 0);
            power[iter].assign(n + 1, 1);
            rep(i, n) {
                hash[iter][i + 1] = (hash[iter][i] * base + S[i]) % MoD[iter];
                power[iter][i + 1] = power[iter][i] * base % MoD[iter];
            }
        }
    }



    ll get(int l, int r, int id = 0) const {
        return ((hash[id][r] - (hash[id][l] * power[id][r - l]) % MoD[id]) + MoD[id]) % MoD[id];
    }
    ll getLCP(int a, int b) const {
        int len = min((int)S.size() - a, (int)S.size() - b);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a + mid, 0) != get(b, b + mid, 0)) high = mid;
            else if (get(a, a + mid, 1) != get(b, b + mid, 1)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    string T;
    cin >> S >> T;
    rollinghash s(S);
    map<pair<ll, ll>, ll> M;
    rep(i, S.size() - T.size() + 1) {
        ll a0 = s.get(i, i + T.size(), 0);
        ll a1 = s.get(i, i + T.size(), 1);
        M[{a0, a1}]++;
    }
    ll an = 0;
    rollinghash t(T);
    ll ht0 = t.get(0, T.size(), 0);
    ll ht1 = t.get(0, T.size(), 1);
    rep(tt, T.size()) {
        for (char a = 'a'; a <= 'z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][tt];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][tt];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            if (M.count({ t0,t1 }))an += M[{t0, t1}];
        }

        for (char a = 'A'; a <= 'Z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][tt];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[0][tt];
            t0 = (t0 % t.MoD[0] + t.MoD[0]) % t.MoD[0];
            t1 = (t1 % t.MoD[1] + t.MoD[1]) % t.MoD[1];
            if (M.count({ t0,t1 }))an += M[{t0, t1}];
        }
    }
    cout << an << endl;


}
accuracy: 0.2033898305084746
time_ms: 240
memory_kb: 17992
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll L;
string ST;
string dfs(string S) {
    ll N = S.size();
    ll K = 0;
    string res = "";
    rep(mm, N) {
        if (S[mm] == '(')K++;
        if (S[mm] == ')')K--;
        if (K != 0)continue;
        if (S[mm] <= '9' && S[mm] >= '0') {
            ll d = 0;
            ll k = mm;
            while (S[k] <= '9' && S[k] >= '0') {
                d *= 10;
                d += S[k] - '0';
                k++;
            }
            ll kako = 0;
            string P;
            if (S[k] == '(') {
                for (ll j = k; j < N; j++) {
                    if (S[j] == '(')kako++;
                    if (S[j] == ')') {
                        kako--;
                        if (kako == 0) {
                            P = dfs(S.substr(k + 1, j - k - 1));
                            mm = j;
                            break;
                        }
                    }
                }
            }
            else {
                P = S.substr(k, 1);
                mm = k;
            }
            chmin(d, ll((L - res.size()) / P.size() + 1));
            rep(D, d) {
                res = res + P;
            }
            if (res.size() > L)return res;

        }
        else {
            res.push_back(S[mm]);
        }
    }
    return res;

}

struct rollinghash {
    const ll base = 9973;
    const vector<ll> MoD = { 999999937, 1000000007 };
    string S;
    vector<ll> hash[2], power[2];
    rollinghash(const string& cs) { init(cs); }

    ll Shash(string T, ll iter) {
        ll n = T.size();
        ll reshash = 0;
        ll respow = 1;
        rep(i, n) {
            reshash = (reshash * base + T[i]) % MoD[iter];
        }
        return reshash;
    }

    void init(const string& cs) {
        S = cs;
        ll n = S.size();
        rep(iter, MoD.size()) {
            hash[iter].assign(n + 1, 0);
            power[iter].assign(n + 1, 1);
            rep(i, n) {
                hash[iter][i + 1] = (hash[iter][i] * base + S[i]) % MoD[iter];
                power[iter][i + 1] = power[iter][i] * base % MoD[iter];
            }
        }
    }



    ll get(int l, int r, int id = 0) const {
        return ((hash[id][r] - (hash[id][l] * power[id][r - l]) % MoD[id]) + MoD[id]) % MoD[id];
    }
    ll getLCP(int a, int b) const {
        int len = min((int)S.size() - a, (int)S.size() - b);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a + mid, 0) != get(b, b + mid, 0)) high = mid;
            else if (get(a, a + mid, 1) != get(b, b + mid, 1)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    string T;
    cin >> S >> T;
    rollinghash s(S);
    map<pair<ll, ll>, ll> M;
    rep(i, S.size() - T.size() + 1) {
        ll a0 = s.get(i, i + T.size(), 0);
        ll a1 = s.get(i, i + T.size(), 1);
        M[{a0, a1}]++;
    }
    ll an = 0;
    rollinghash t(T);
    ll ht0 = t.get(0, T.size(), 0);
    ll ht1 = t.get(0, T.size(), 1);
    rep(tt, T.size()) {
        for (char a = 'a'; a <= 'z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][tt];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[1][tt];
            if (M.count({ t0,t1 }))an += M[{t0, t1}];
        }

        for (char a = 'A'; a <= 'Z'; a++) {
            if (T[tt] == a)continue;
            ll t0 = ht0 + ll(a - T[tt]) * t.power[0][tt];
            ll t1 = ht1 + ll(a - T[tt]) * t.power[0][tt];
            if (M.count({ t0,t1 }))an += M[{t0, t1}];
        }
    }
    cout << an << endl;


}
accuracy: 0.0847457627118644
time_ms: 40
memory_kb: 17944
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

constexpr int mod1 = 998244353,mod2 = 1000000007;

long long modpow(long long a,long long b,long long m) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= m;
        }
        (a *= a) %= m;
        b /= 2;
    }
    return ans;
}

int calc(char a) {
    if(a >= 'a' && a <= 'z') {
        return a-'a'+1;
    }
    else {
        return a-'A'+27;
    }
}

map<pair<int,int>,int>tmp;

int main() {
    string S,T;
    cin >> S >> T;
    vector<long long>pow1(S.size()+1),pow2(S.size()+1);
    for(int i = 0; i <= S.size(); i++) {
        pow1[i] = modpow(59,i,mod1);
        pow2[i] = modpow(59,i,mod2);
    }
    long long tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < S.size(); i++) {
        tmp1 += pow1[i]*calc(S[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(S[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        if(i >= T.size()) {
            tmp1 += mod1-pow1[i-T.size()]*calc(S[i-T.size()])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i-T.size()]*calc(S[i-T.size()])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        if(i+1 >= T.size()) {
            tmp[{tmp1*modpow(modpow(59,i+1-T.size(),mod1),mod1-2,mod1)%mod1,tmp2*modpow(modpow(59,i+1-T.size(),mod2),mod2-2,mod2)%mod2}]++;
        }
    }
    string base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += modpow(59,i,mod2)*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    int ans = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += mod1-pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += mod2-pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        for(int j = 0; j < base.size(); j++) {
            if(base[j] == T[i]) {
                continue;
            }
            tmp1 += pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
            if(tmp.count({tmp1,tmp2})) {
                ans += tmp[{tmp1,tmp2}];
            }
            tmp1 += mod1-pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 1470
memory_kb: 26068
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

constexpr int mod1 = 998244353,mod2 = 1000000007;

long long modpow(long long a,long long b,long long m) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= m;
        }
        (a *= a) %= m;
        b /= 2;
    }
    return ans;
}

int calc(char a) {
    if(a >= 'a' && a <= 'z') {
        return a-'a'+1;
    }
    else {
        return a-'A'+27;
    }
}

map<pair<int,int>,int>tmp;

int main() {
    string S,T;
    cin >> S >> T;
    vector<long long>pow1(S.size()+1),pow2(S.size()+1);
    for(int i = 0; i <= S.size(); i++) {
        pow1[i] = modpow(59,i,mod1);
        pow2[i] = modpow(59,i,mod2);
    }
    long long tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < S.size(); i++) {
        tmp1 += pow1[i]*calc(S[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(S[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        if(i >= T.size()) {
            tmp1 += mod1-pow1[i-T.size()]*calc(S[i-T.size()])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i-T.size()]*calc(S[i-T.size()])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        if(i+1 >= T.size()) {
            tmp[{tmp1*modpow(modpow(59,i+1-T.size(),mod1),mod1-2,mod1)%mod1,tmp2*modpow(modpow(59,i+1-T.size(),mod2),mod2-2,mod2)%mod2}]++;
        }
    }
    string base = "abcdefghigklmnopqrstuvwxyxzABCDEFGHIGKLMNOPQRSTUVWXYZ";
    tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += modpow(59,i,mod2)*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    int ans = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += mod1-pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += mod2-pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        for(int j = 0; j < base.size(); j++) {
            if(base[j] == T[i]) {
                continue;
            }
            tmp1 += pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
            if(tmp.count({tmp1,tmp2})) {
                ans += tmp[{tmp1,tmp2}];
            }
            tmp1 += mod1-pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    cout << ans << endl;
}
accuracy: 0.3389830508474576
time_ms: 1480
memory_kb: 17620
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

constexpr int mod1 = 998244353,mod2 = 1000000007;

long long modpow(long long a,long long b,long long m) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= m;
        }
        (a *= a) %= m;
        b /= 2;
    }
    return ans;
}

int calc(char a) {
    if(a >= 'a' && a <= 'z') {
        return a-'a'+1;
    }
    else {
        return a-'A'+27;
    }
}

map<pair<int,int>,int>tmp;

int main() {
    string S,T;
    cin >> S >> T;
    vector<long long>pow1(S.size()+1),pow2(S.size()+1);
    for(int i = 0; i <= S.size(); i++) {
        pow1[i] = modpow(55,i,mod1);
        pow2[i] = modpow(55,i,mod2);
    }
    long long tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < S.size(); i++) {
        tmp1 += pow1[i]*calc(S[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(S[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        if(i >= T.size()) {
            tmp1 += mod1-pow1[i-T.size()]*calc(S[i-T.size()])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i-T.size()]*calc(S[i-T.size()])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        if(i+1 >= T.size()) {
            tmp[{tmp1*modpow(modpow(55,i+1-T.size(),mod1),mod1-2,mod1)%mod1,tmp2*modpow(modpow(55,i+1-T.size(),mod2),mod2-2,mod2)%mod2}]++;
        }
    }
    string base = "abcdefghigklmnopqrstuvwxyxzABCDEFGHIGKLMNOPQRSTUVWXYZ";
    tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += modpow(55,i,mod2)*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    int ans = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += mod1-pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += mod2-pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        for(int j = 0; j < base.size(); j++) {
            if(base[j] == T[i]) {
                continue;
            }
            tmp1 += pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
            if(tmp.count({tmp1,tmp2})) {
                ans += tmp[{tmp1,tmp2}];
            }
            tmp1 += mod1-pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    cout << ans << endl;
}
accuracy: 0.3389830508474576
time_ms: 1470
memory_kb: 17532
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

constexpr int mod1 = 998244353,mod2 = 998244853;

long long modpow(long long a,long long b,long long m) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= m;
        }
        (a *= a) %= m;
        b /= 2;
    }
    return ans;
}

int calc(char a) {
    if(a >= 'a' && a <= 'z') {
        return a-'a'+1;
    }
    else {
        return a-'A'+27;
    }
}

map<pair<int,int>,int>tmp;

int main() {
    string S,T;
    cin >> S >> T;
    vector<long long>pow1(S.size()+1),pow2(S.size()+1);
    for(int i = 0; i <= S.size(); i++) {
        pow1[i] = modpow(55,i,mod1);
        pow2[i] = modpow(55,i,mod2);
    }
    long long tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < S.size(); i++) {
        tmp1 += pow1[i]*calc(S[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(S[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        if(i >= T.size()) {
            tmp1 += mod1-pow1[i-T.size()]*calc(S[i-T.size()])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i-T.size()]*calc(S[i-T.size()])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        if(i+1 >= T.size()) {
            tmp[{tmp1*modpow(modpow(55,i+1-T.size(),mod1),mod1-2,mod1)%mod1,tmp2*modpow(modpow(55,i+1-T.size(),mod2),mod2-2,mod2)%mod2}]++;
        }
    }
    string base = "abcdefghigklmnopqrstuvwxyxzABCDEFGHIGKLMNOPQRSTUVWXYZ";
    tmp1 = 0,tmp2 = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += modpow(55,i,mod2)*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    int ans = 0;
    for(int i = 0; i < T.size(); i++) {
        tmp1 += mod1-pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += mod2-pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
        for(int j = 0; j < base.size(); j++) {
            if(base[j] == T[i]) {
                continue;
            }
            tmp1 += pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
            if(tmp.count({tmp1,tmp2})) {
                ans += tmp[{tmp1,tmp2}];
            }
            tmp1 += mod1-pow1[i]*calc(base[j])%mod1;
            if(tmp1 >= mod1) {
                tmp1 -= mod1;
            }
            tmp2 += mod2-pow2[i]*calc(base[j])%mod2;
            if(tmp2 >= mod2) {
                tmp2 -= mod2;
            }
        }
        tmp1 += pow1[i]*calc(T[i])%mod1;
        if(tmp1 >= mod1) {
            tmp1 -= mod1;
        }
        tmp2 += pow2[i]*calc(T[i])%mod2;
        if(tmp2 >= mod2) {
            tmp2 -= mod2;
        }
    }
    cout << ans << endl;
}
accuracy: 0.3389830508474576
time_ms: 1450
memory_kb: 17520
final_rank: 13

code_snippet: #include<bits/stdc++.h> 
using namespace std;
using ll=long long int;
//using Int=__int128;
#define ALL(A) A.begin(),A.end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
template<typename T> constexpr int bitUP(T x,int a){return (x>>a)&1;}
//→　↓　←　↑ 
int dh[4]={0,1,0,-1}, dw[4]={1,0,-1,0};
//右上から時計回り
//int dh[8]={-1,0,1,1,1,0,-1,-1}, dw[8]={1,1,1,0,-1,-1,-1,0};
long double EPS = 1e-6;
long double PI = acos(-1);
const ll INF=(1LL<<62);
const int MAX=(1<<30);
constexpr ll MOD=1000000000+7;
//constexpr ll MOD=998244353;


inline void bin101(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

using Graph=vector<vector<int>>;

template<typename T >
struct edge {
	int to;
	T cost;
	edge()=default;
	edge(int to, T cost) : to(to), cost(cost) {}

};
template<typename T>
using WeightGraph=vector<vector<edge<T>>>;

//要素数n 初期値x
template<typename T>
inline vector<T> vmake(size_t n,T x){
	return vector<T>(n,x);
}

//a,b,c,x data[a][b][c] 初期値x
template<typename... Args>
auto vmake(size_t n,Args... args){
	auto v=vmake(args...);
	return vector<decltype(v)>(n,move(v));
}

vector<int> z_algorithm(const string &s){
    int c=0,N=(int)s.size();
    vector<int> Z(N,0);
    for(int i=1;i<N;i++){
        int l=i-c;
        if(i+Z[l]<c+Z[c]){
            Z[i]=Z[l];
        }else{
            int j=max(0,c+Z[c]-i);
            while(i+j<N && s[j]==s[i+j]) j++;
            Z[i]=j;
            c=i;
        }
    }
    Z[0]=N;
    return Z;
}


void solve(){
    string S,T;
    cin>>S>>T;
    string TS=T+S,rTS=S+T;
    reverse(ALL(rTS));

    auto zTS=z_algorithm(TS);
    auto zrTS=z_algorithm(rTS);

    reverse(ALL(zrTS));
    vector<map<int,int>> v(S.size());

    for(int i=T.size();i<zTS.size();i++){
        int z=zTS[i];
        if(i+z-T.size()<v.size()) v[i+z-T.size()][z]++;
    }
    int ans=0;
    for(int i=0;i<zrTS.size()-T.size();i++){
        int z=zrTS[i];
        if(z>=T.size()) continue;
        if(i-z>=0) ans+=v[i-z][T.size()-1-z];
    }
    cout<<ans<<endl;
}

int main(){
    bin101();
    int T=1;
    //cin>>T;
    while(T--) solve();
}
accuracy: 1
time_ms: 30
memory_kb: 50120
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

// BEGIN CUT
ll modpow(ll x, ll y, ll m) {
    ll a = 1, p = x;
    while (y > 0) {
        if (y % 2 == 0) {
            p = (p * p) % m;
            y /= 2;
        } else {
            a = (a * p) % m;
            y--;
        }
    }
    return a;
}
// END CUT

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ull P[300001];
int idx[256];

int main() {
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < 26; i++) {
        idx['a' + i] = i;
        idx['A' + i] = i + 26;
    }
    int m = T.size();
    ull B = 1e9 + 7;
    P[0] = 1;
    for (int i = 1; i <= m; i++)
        P[i] = P[i - 1] * B;
    vector<ull> hashes;
    ull now = 0;
    for (int i = 0; i < m; i++) {
        now = now * B + idx[S[i]];
    }
    hashes.push_back(now);
    for (int i = m; i < S.size(); i++) {
        now *= B;
        now -= idx[S[i - m]] * P[m];
        now += idx[S[i]];
        hashes.push_back(now);
    }
    sort(ALL(hashes));
    ull H = 0;
    for (int i = 0; i < m; i++) {
        H = H * B + idx[T[i]];
    }
    int ans = 0;
    for (int i = 0; i < m; i++) {
        bool ok = 0;
        for (int j = 0; j < 52; j++) {
            if (j != idx[T[i]]) {
                ll new_hash = H;
                new_hash += (j - idx[T[i]]) * P[m - 1 - i];
                ans += upper_bound(ALL(hashes), new_hash) -
                       lower_bound(ALL(hashes), new_hash);
            }
        }
        if (ok)
            ans++;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 1130
memory_kb: 9032
final_rank: 8