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
#include<iostream>
//#include<cstdio>
#include "poszukiwania.h"
#include "message.h""

using namespace std;

int n, m, tab[20000010], ans, pref[10000010], i, len;

//int sig[4] = { 0, 1, 2, 3 };
//int seq[7] = { 0, 1, 2, 3, 1, 2, 3 };
//int MyNodeId()
//{
//	return 0;
//}
//int SignalLength()
//{
//	return 3;
//}
//int SignalAt( int x )
//{
//	return sig[x];
//}
//int SeqLength()
//{
//	return 6;
//}
//int SeqAt( int x )
//{
//	return seq[x];
//}
int main()
{
//	ios_base::sync_with_stdio( 0 );
	n = SignalLength();
	len = 0;
	for( int a = 1; a <= n; a++ )tab[++len] = SignalAt( a );
	tab[++len] = -1;
	m = SeqLength();
	for( int a = 1; a <= m; a++ )tab[++len] = SeqAt( a );
	i = 0;
	pref[1] = 0;
	for( int a = 2; a <= len; a++ )
	{
		while( i != 0 && tab[ i + 1 ] != tab[ a ] )i = pref[ i ];
		if( tab[ i + 1 ] == tab[ a ] )i++;
		if( a <= n+1 )pref[ a ] = i;
		if( i == n )ans++;
	}
	if( MyNodeId() == 0 )cout<<ans;
	return 0;
}