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

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(auto it=(v).begin(); it!=(v).end(); ++it)
//#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

#if 0
#define DEB printf
#else
#define DEB(...)
#endif

typedef long long ll;
typedef long long LL;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int mod = 1000000007;
const int MAXN = 1000006;

int N,me,n;
ll Manacher(const string &x, bool niep)
{
	int n=x.length(),i=1,j=0,k;
	vi r(n,0);
	while(i<n) {
		while(i+j<=n && i-j>0 && x[i-j-1]==x[i+j+niep]) j++;
		r[i]=j;
		k=1;
		while(i+k<n && r[i-k]!=r[i]-k && k<=j) {
			r[i+k] = min(r[i-k], r[i]-k); 
			k++;
		}
		j=max(0,j-k); i+=k;
	}
	ll ret=0;
	DEB("inst[%d]\n",me);
	tr(it,r)DEB("%d ",*it);DEB("\n");
	tr(it,r)ret+=*it;
	return ret;
}

string W;
int main() {
	N=NumberOfNodes();
	me=MyNodeId();
	n=GetLength();
	string S;
  	S.resize(n);
	fru(i,n)S[i]=GetLetter(i);
	ll ret=0;
	DEB("inst[%d]\n",me);
	if (me == 0) {
		ret+=Manacher(S,0);
		Receive(1);
		ret+=GetLL(1);
		printf("%lld\n",ret+n);
	}
	if (me == 1) {
		ret+=Manacher(S,1);
		PutLL(0,ret);
		Send(0);
	}
	return 0;
}