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;
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  int sgn = 1;
  while (c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  x *= sgn;
}
template <typename T>
void out(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) out(x / 10);
  putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 2e6 + 5;
const int mod = 51123987;
char s[N];
int n;
long long sum[N];
struct link {
  int u[N + 5];
  int v[N + 5];
  int next[N + 5];
  int head[N + 5];
  int tot;
  void clear() {
    memset(head, -1, sizeof(head));
    tot = 0;
  }
  void clear(int x) { head[x] = -1; }
  int get(int x, int y) {
    for (int i = head[x]; i != -1; i = next[i]) {
      if (u[i] == y) return v[i];
    }
    return 0;
  }
  void insert(int x, int y, int z) {
    u[tot] = y;
    v[tot] = z;
    next[tot] = head[x];
    head[x] = tot++;
  }
} ch;
struct PAM {
  int fail[N];
  int len[N];
  int num[N];
  int tot;
  int last;
  int cnt[N];
  int tmp[N];
  void init() {
    s[0] = '#';
    last = 0;
    fail[0] = 1;
    len[1] = -1;
    tot = 1;
    ch.clear();
  }
  void add(int i) {
    int j;
    while (s[i - len[last] - 1] != s[i]) last = fail[last];
    if (!ch.get(last, s[i] - 'a')) {
      len[++tot] = len[last] + 2;
      j = fail[last];
      while (s[i - len[j] - 1] != s[i]) j = fail[j];
      fail[tot] = ch.get(j, s[i] - 'a');
      ch.insert(last, s[i] - 'a', tot);
      cnt[tot] = cnt[fail[tot]] + 1;
      tmp[i] = cnt[tot];
    } else
      tmp[i] = cnt[ch.get(last, s[i] - 'a')];
    last = ch.get(last, s[i] - 'a');
    num[last]++;
  }
  long long query_sum() {
    for (int i = tot; i >= 1; i--) num[fail[i]] = (num[fail[i]] + num[i]) % mod;
    long long ans = 0;
    for (int i = 1; i <= tot; i++) {
      ans = ((long long)ans + num[i]) % mod;
    }
    return ans;
  }
  int query(int x) { return tmp[x]; }
} p, q;
int main() {
  read(n);
  scanf("%s", s + 1);
  q.init();
  reverse(s + 1, s + 1 + n);
  for (int i = 1; i <= n; i++) {
    q.add(i);
    sum[i] = (sum[i - 1] + q.query(i)) % mod;
  }
  reverse(sum + 1, sum + 1 + n);
  reverse(s + 1, s + n + 1);
  p.init();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    p.add(i);
    ans = (ans + (long long)p.query(i) * sum[i + 1]) % mod;
  }
  long long res = p.query_sum();
  ans = (((long long)res * (res - 1) / 2 - ans) % mod + mod) % mod;
  cout << ans << endl;
  return 0;
}