#include // created [2020/03/06] 22:18:37 #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; using uint = unsigned int; using usize = std::size_t; using ll = long long; using ull = unsigned long long; using ld = long double; template using arr = T (&)[n]; template using c_arr = const T (&)[n]; template using max_heap = std::priority_queue; template using min_heap = std::priority_queue, std::greater>; template constexpr T popcount(const T u) { return u ? static_cast(__builtin_popcountll(static_cast(u))) : static_cast(0); } template constexpr T log2p1(const T u) { return u ? static_cast(64 - __builtin_clzll(static_cast(u))) : static_cast(0); } template constexpr T msbp1(const T u) { return log2p1(u); } template constexpr T lsbp1(const T u) { return __builtin_ffsll(u); } template constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast(u); } template constexpr bool ispow2(const T u) { return u and (static_cast(u) & static_cast(u - 1)) == 0; } template constexpr T ceil2(const T u) { return static_cast(1) << clog(u); } template constexpr T floor2(const T u) { return u == 0 ? static_cast(0) : static_cast(1) << (log2p1(u) - 1); } template constexpr bool btest(const T mask, const usize ind) { return static_cast((static_cast(mask) >> ind) & static_cast(1)); } template void bset(T& mask, const usize ind) { mask |= (static_cast(1) << ind); } template void breset(T& mask, const usize ind) { mask &= ~(static_cast(1) << ind); } template void bflip(T& mask, const usize ind) { mask ^= (static_cast(1) << ind); } template void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast(0) : static_cast((static_cast(mask) << (64 - ind)) >> (64 - ind)); } template bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } constexpr unsigned int mod = 1000000007; template constexpr T inf_v = std::numeric_limits::max() / 4; template constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; auto mfp = [](auto&& f) { return [=](auto&&... args) { return f(f, std::forward(args)...); }; }; template T in() { T v; return std::cin >> v, v; } template T in_v(typename std::enable_if<(i == n), c_arr>::type) { return in(); } template auto in_v(typename std::enable_if<(i < n), c_arr>::type& szs) { const usize s = (usize)szs[i]; std::vector(szs))> ans(s); for (usize j = 0; j < s; j++) { ans[j] = in_v(szs); } return ans; } template auto in_v(c_arr szs) { return in_v(szs); } template auto in_t() { return std::tuple...>{in()...}; } struct io_init { io_init() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(20); } void clear() { std::cin.tie(), std::ios::sync_with_stdio(true); } } io_setting; int out() { return 0; } template int out(const T& v) { return std::cout << v, 0; } template int out(const std::vector& v) { for (usize i = 0; i < v.size(); i++) { if (i > 0) { std::cout << ' '; } out(v[i]); } return 0; } template int out(const std::pair& v) { return out(v.first), std::cout << ' ', out(v.second), 0; } template int out(const T& v, const Args... args) { return out(v), std::cout << ' ', out(args...), 0; } template int outln(const Args... args) { return out(args...), std::cout << '\n', 0; } template int outel(const Args... args) { return out(args...), std::cout << std::endl, 0; } # define SHOW(...) static_cast(0) constexpr ull TEN(const usize n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; } template auto make_v(typename std::enable_if<(i == n), c_arr>::type, const T& v = T{}) { return v; } template auto make_v(typename std::enable_if<(i < n), c_arr>::type szs, const T& v = T{}) { const usize s = (usize)szs[i]; return std::vector(szs, v))>(s, make_v(szs, v)); } template auto make_v(c_arr szs, const T& t = T{}) { return make_v(szs, t); } class xoshiro { public: using result_type = uint32_t; static constexpr result_type min() { return std::numeric_limits::min(); } static constexpr result_type max() { return std::numeric_limits::max(); } xoshiro() : xoshiro(std::random_device{}()) {} xoshiro(uint64_t seed) { uint64_t z = 0; for (int i = 0; i < 4; i++) { z = (seed += 0x9e3779b97f4a7c15), z = (z ^ (z >> 33)) * 0x62A9D9ED799705F5, z = (z ^ (z >> 28)) * 0xCB24D0A5C88C35B3, s[i] = static_cast(z >> 32); } } result_type operator()() { const result_type result = rotl(s[1] * 5, 7) * 9, t = s[1] << 9; return s[2] ^= s[0], s[3] ^= s[1], s[1] ^= s[2], s[0] ^= s[3], s[2] ^= t, s[3] = rotl(s[3], 11), result; } void discard(const usize rep) { for (usize i = 0; i < rep; i++) { (*this)(); } } private: result_type s[4]; static result_type rotl(const result_type x, const int k) { return (x << k) | (x >> (32 - k)); } }; class xoshiro_64 { public: using result_type = uint64_t; static constexpr result_type min() { return std::numeric_limits::min(); } static constexpr result_type max() { return std::numeric_limits::max(); } xoshiro_64() : xoshiro_64(std::random_device{}()) {} xoshiro_64(uint64_t seed) { uint64_t z = 0; for (int i = 0; i < 4; i++) { z = (seed += 0x9e3779b97f4a7c15), z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9, z = (z ^ (z >> 27)) * 0x94d049bb133111eb, s[i] = static_cast(z ^ (z >> 31)); } } result_type operator()() { const result_type result = rotl(s[1] * 5, 7) * 9, t = s[1] << 17; return s[2] ^= s[0], s[3] ^= s[1], s[1] ^= s[2], s[0] ^= s[3], s[2] ^= t, s[3] = rotl(s[3], 45), result; } void discard(const usize rep) { for (usize i = 0; i < rep; i++) { (*this)(); } } private: result_type s[4]; static result_type rotl(const result_type x, const int k) { return (x << k) | (x >> (64 - k)); } }; template class rng_base { public: using rng_type = Rng; using result_type = typename rng_type::result_type; static constexpr result_type min() { return rng_type::min(); } static constexpr result_type max() { return rng_type::max(); } rng_base() : rng_base(std::random_device{}()) {} rng_base(const u64 seed) : rng(seed) {} ~rng_base() = default; result_type operator()(const result_type max = std::numeric_limits::max()) { if (max == std::numeric_limits::max()) { return static_cast(rng()); } if (ispow2(max + 1)) { return static_cast(rng() & max); } const result_type mask = static_cast(ceil2(static_cast(max + 1))) - 1; while (true) { const result_type ans = static_cast(rng() & mask); if (ans <= max) { return ans; } } } template Int operator()(const Int min, const Int max) { return min + (Int)(*this)(max - min); } operator bool() { return (bool)(*this)(0, 1); } template std::pair pair(const Int min, const Int max) { return std::pair{*this(min, max), *this(min, max)}; } template std::vector vec(const usize n, const Int min, const Int max) { std::vector v(n); for (usize i = 0; i < n; i++) { v[i] = (*this)(min, max); } return v; } std::vector perm(const usize n) { std::vector ans(n); std::iota(ans.begin(), ans.end(), 0UL); std::shuffle(ans.begin(), ans.end(), rng); return ans; } private: Rng rng; }; using rng_mt = rng_base; using rng_mt64 = rng_base; using rng_xoshiro = rng_base; using rng_xoshiro64 = rng_base; rng_mt g_rng_mt; rng_mt64 g_rng_mt64; rng_xoshiro g_rng_xo; rng_xoshiro64 g_rng_xo64; class fast_rolling_hash { public: template fast_rolling_hash(const InIt first, const InIt last, const u64 base = g_rng_xo64((u64)2, mask61 - 1)) : sz(std::distance(first, last)), pow(sz + 1, 1), h(sz + 1, 0) { for (usize i = 1; i <= sz; i++) { pow[i] = mod(mul(pow[i - 1], base)), h[i] = mod(mul(h[i - 1], base) + *std::next(first, i - 1)); } } u64 operator()(const usize l, const usize r) const { return mod(h[r] + offset - mul(h[l], pow[r - l])); } private: static constexpr u64 mask30 = ((u64)1 << 30) - 1; static constexpr u64 mask31 = ((u64)1 << 31) - 1; static constexpr u64 mask61 = ((u64)1 << 61) - 1; static constexpr u64 offset = mask61 * 7; static constexpr u64 mod(const u64 x) { const u64 y = (x >> 61) + (x & mask61); return y >= mask61 ? y - mask61 : y; } static constexpr u64 mul(const u64 x, const u64 y) { const u64 xh = x >> 31, xl = x & mask31; const u64 yh = y >> 31, yl = y & mask31; const u64 z = xl * yh + xh * yl; const u64 zh = z >> 30, zl = z & mask30; return xh * yh * 2 + zh + (zl << 31) + xl * yl; } const usize sz; std::vector pow, h; }; int main() { constexpr ull B = 271724908108ULL; const auto S = in(); const auto T = in(); const int N = S.size(); const int M = T.size(); if (M == 1) { bool ok = true; for (const char c : S) { if (c == T[0]) { ok = false; } } return outln(ok ? 0 : -1); } const auto shash = fast_rolling_hash(S.begin(), S.end(), B); const auto thash = fast_rolling_hash(T.begin(), T.end(), B); int ans = 0; int p = 0; for (; p + M <= N;) { if (shash(p, p + M) == thash(0, M)) { ans++; p += M - 1; } else { p++; } } outln(ans); return 0; }