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

char literka(long long x) {
	static int n = GetLength();
	if (x % 2) {
		if (x / 2 < n)
			return GetLetter(x / 2);
		return '#';
	}
	return '$';
}


long long wynik = 0;
void dodaj(int x) {
	if (x % 2) wynik += tab[x] / 2 + 1;
	else wynik += tab[x] / 2;
}


int main()
{
	if (MyNodeId() == 0) {
		int n = GetLength();
		tab.resize(2*n);
		int k = 0;
	//	printf("%s\n",slo);
		for (int i=0;i<2*n;)
		{
			while(k < i && literka(i-k-1) == literka(i+k+1)) k++;
			tab[i] = k;
			dodaj(i);
			if ( k == 0 ){
				i++;
				continue;
			}
			for (int j=1;;j++)
			{
				if ( j == k || tab[i-j]+i+j >= i+k )
				{
					k -= j;
					i += j;
					break;
				}
				tab[i+j] = tab[i-j];
				dodaj(i + j);
			}
		}
		printf("%lld\n", wynik);
	}
}