Problem: In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: «eye», «pop», «level», «aba», «deed», «racecar», «rotor», «madam». 

Nick started to look carefully for all palindromes in the text that they were reading in the class. For each occurrence of each palindrome in the text he wrote a pair — the position of the beginning and the position of the ending of this occurrence in the text. Nick called each occurrence of each palindrome he found in the text subpalindrome. When he found all the subpalindromes, he decided to find out how many different pairs among these subpalindromes cross. Two subpalindromes cross if they cover common positions in the text. No palindrome can cross itself.

Let's look at the actions, performed by Nick, by the example of text «babb». At first he wrote out all subpalindromes:

• «b» — 1..1 • «bab» — 1..3 • «a» — 2..2 • «b» — 3..3 • «bb» — 3..4 • «b» — 4..4

Then Nick counted the amount of different pairs among these subpalindromes that cross. These pairs were six:

1. 1..1 cross with 1..3 2. 1..3 cross with 2..2 3. 1..3 cross with 3..3 4. 1..3 cross with 3..4 5. 3..3 cross with 3..4 6. 3..4 cross with 4..4

Since it's very exhausting to perform all the described actions manually, Nick asked you to help him and write a program that can find out the amount of different subpalindrome pairs that cross. Two subpalindrome pairs are regarded as different if one of the pairs contains a subpalindrome that the other does not.

Input

The first input line contains integer n (1 ≤ n ≤ 2·106) — length of the text. The following line contains n lower-case Latin letters (from a to z).

Output

In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987.

Examples

Input

4
babb


Output

6


Input

2
aa


Output

2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int mod = 51123987;
const int MAXN = 2e6 + 5;
template <typename T>
inline void read(T& x) {
  x = 0;
  char temp = getchar();
  bool f = false;
  while (!isdigit(temp)) {
    if (temp == '-') f = true;
    temp = getchar();
  }
  while (isdigit(temp)) {
    x = (x << 1) + (x << 3) + temp - '0';
    temp = getchar();
  }
  if (f) x = -x;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
int n;
char str[MAXN];
struct node {
  vector<pair<int, int> > son;
  int len, fail, dep;
  inline int Find(int tar) {
    int res = -1;
    for (register int i = 0; i < son.size(); i++)
      if (son[i].first == tar) {
        res = i;
        break;
      }
    return res;
  }
};
struct PAM {
  node a[MAXN];
  int last, now_len, size, res;
  inline void Init() {
    memset(a, 0, sizeof(a));
    a[1].len = -1, a[0].len = 0;
    a[1].fail = a[0].fail = 1;
    size = 1, last = 0, now_len = 0, res = 0;
  }
  inline int GetFail(int id) {
    while (str[now_len - a[id].len - 1] != str[now_len]) id = a[id].fail;
    return id;
  }
  inline void Insert(int s) {
    ++now_len;
    int pre = GetFail(last), tmp = a[pre].Find(s), now;
    if (tmp == -1)
      now = 0;
    else
      now = a[pre].son[tmp].second;
    if (!now) {
      now = ++size;
      tmp = a[GetFail(a[pre].fail)].Find(s);
      if (tmp == -1)
        a[now].fail = 0;
      else
        a[now].fail = a[GetFail(a[pre].fail)].son[tmp].second;
      a[now].len = a[pre].len + 2, a[now].dep = a[a[now].fail].dep + 1;
      a[pre].son.push_back(make_pair(s, now));
    }
    last = now, res = (res + a[now].dep) % mod;
  }
} tree;
int x[MAXN];
int main() {
  read(n);
  scanf("%s", str + 1);
  tree.Init();
  for (register int i = 1; i <= n; i++) tree.Insert(str[i]), x[i] = tree.res;
  for (register int i = 1; i * 2 <= n; i++) swap(str[i], str[n - i + 1]);
  tree.Init();
  int ans = (1ll * x[n] * (x[n] - 1) / 2) % mod, temp = 0;
  for (register int i = 1; i <= n; i++)
    tree.Insert(str[i]),
        ans = ((ans - 1ll * (tree.res - temp) * x[n - i] % mod) % mod + mod) %
              mod,
        temp = tree.res;
  print(ans), puts("");
  return 0;
}