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
#include <bits/stdc++.h>
#include "palindromy.h"
#include "message.h"
using namespace std;

int nodes;
int mynode;

int n;

long long wyn;

vector <char> s;
vector <int> p;
int x;

int main()
{
	nodes=NumberOfNodes();
	mynode=MyNodeId();
	
	n=GetLength();
	
	if (mynode>1)
		return 0;
	
	s.resize(n+5, 0);
	p.resize(n+5, 0);
	
	s[0]=-1;
	s[n+1]=-2;
	for (int i=1; i<=n; i++)
		s[i]=GetLetter(i-1);
	if (mynode)
	{
		for (int i=1; i<n; i++)
		{
			if (x+p[x]>=i)
				p[i]=min(x+p[x]-i, p[2*x-i]);
			while(s[i-p[i]]==s[i+1+p[i]])
				p[i]++;
			if (i+p[i]>x+p[x])
				x=i;
			wyn+=p[i];
		}
		PutLL(0, wyn);
		Send(0);
		return 0;
	}
	for (int i=1; i<=n; i++)
	{
		if (x+p[x]-1>=i)
			p[i]=min(x+p[x]-i, p[2*x-i]);
		while(s[i-p[i]]==s[i+p[i]])
			p[i]++;
		if (i+p[i]>x+p[x])
			x=i;
		wyn+=p[i];
	}
	Receive(1);
	wyn+=GetLL(1);
	printf("%lld\n", wyn);
	return 0;
}