kmp
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e6;
int next_1[N];
string str, s;
void next_hh()
{
memset(next_1, 0, sizeof next_1);
int i = 0, j = 1;
next_1[0] = 0;
while (j < s.size())
{
if (s[i] == s[j])
{
next_1[j] = i + 1;
i++, j++;
}
else
{
if (i > 0)
i = next_1[i - 1];
else
next_1[j] = 0, j++;
}
}
}
void kmp()
{
int sum = 0;
int i = 0, j = 0;
next_hh();
for (int i = 0; i < s.size(); i++)
cout << next_1[i] << endl;
while (j < str.size())
{
if (s[i] == str[j])
i++, j++;
else if (i > 0)
i = next_1[i - 1];
else
j++;
if (i == s.size())
sum++;
}
cout << sum << " skjdfs" << endl;
}
int main()
{
cin >> str;
while (1)
{
cin >> s;
kmp();
}
}