1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

#include "poszukiwania.h"
#include "message.h"


using namespace std;

#define FOR(i,n) for(int i=0;i<n;++i)
#define FORB(i,b,n) for(int i=b;i<n;++i)
#define REV(i,n) for(int i=n;i>=0;--i)
#define FOREACH(T, it, v) for(T::iterator it = v.begin(); it !=v.end(); ++it)

typedef unsigned int u32;
typedef unsigned int uint;
const int INF = (0u - 11) / 2;

typedef long long ll;
typedef set<int> SI;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef set<long long> SL;
typedef map<int, int> MII;



int DEBUG = 1;

#define print(STRING,INT) printf("%s= %d\n", STRING, INT)

#define scan(INT) scanf("%d", &INT)


void log(char* S, int a)
{
	if (DEBUG)
	{
		print(S, a);
	}
}

const int MAX_SHORT = 65536;

const int MEMORY_SECTOR_SIZE = 30000012;

int tab[MEMORY_SECTOR_SIZE + 5];


	int main()
{
	//int nodes = NumberOfNodes();
	int PID = MyNodeId();
	if (PID != 0)
	{
		return 0;
	}
	int m = SignalLength();
	int n = SeqLength();
	if (m > MEMORY_SECTOR_SIZE)
	{
		printf("%d\n", 0);
		return 0;
	}
	tab[0] = -1;
	int t = -1;
	FORB(i, 1, m  + 1)
	{
		t = tab[i - 1];
		while (t >= 0 && SignalAt(t + 1) != SignalAt(i))
		{
			t = tab[t];
		}
		t++;
		tab[i] = t;
	}

	int j = 0;
	int out = 0;
	int i = 0;
	while(i < n - m)
	{
		while (j < m && SignalAt(j + 1) == SeqAt(i + j + 1))
		{
			j++;
		}
		if (j == m)
		{
			out++;
		}
		i = i + j - tab[j];
		j = max(tab[j], 0);
	}

	printf("%d\n", out);
	return 0;
}