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 std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::copy;
using std::cout;
using std::endl;
using std::fill;
using std::fixed;
using std::greater;
using std::lower_bound;
using std::map;
using std::max;
using std::min;
using std::next_permutation;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse;
using std::rotate;
using std::set;
using std::sort;
using std::string;
using std::swap;
using std::tie;
using std::tuple;
using std::unique;
using std::unordered_map;
using std::unordered_set;
using std::upper_bound;
using std::vector;
int const INF = (int)1e9;
long long const INFL = (long long)1e18;
long double const PI = 3.1415926535897932384626433832795028;
int const MOD = 51123987;
int const N = 2000100;
char s[N];
int stupid(int n) {
  auto const pal = [](int a, int b) {
    for (--b; a < b; ++a, --b) {
      if (s[a] != s[b]) return false;
    }
    return true;
  };
  long long ans = 0;
  for (int a = 0; a < n; ++a) {
    for (int b = a + 1; b <= n; ++b) {
      if (!pal(a, b)) continue;
      for (int c = 0; c < n; ++c) {
        for (int d = c + 1; d <= n; ++d) {
          if (a == c && b == d) continue;
          if (b <= c || d <= a) continue;
          if (!pal(c, d)) continue;
          ++ans;
        }
      }
    }
  }
  ans /= 2;
  return ans % MOD;
}
int a[N + N];
int d[N + N];
int st[N], fn[N];
void solve() {
  int n;
  scanf("%d ", &n);
  gets(s);
  int sz = 0;
  a[sz++] = N;
  for (int i = 0; i < n; ++i) {
    a[sz++] = s[i] - 'a';
    a[sz++] = N;
  }
  int l = 0, r = 0;
  for (int i = 0; i < sz; ++i) {
    int& x = d[i];
    if (i < r) {
      x = min(r - i, d[l + r - i]);
    }
    while (i >= x && i + x < sz && a[i - x] == a[i + x]) {
      ++x;
    }
    if (i + x > r) {
      l = i - x;
      r = i + x;
    }
  }
  long long cnt = 0;
  for (int i = 1; i < sz - 1; ++i) {
    if (i % 2 == 0) {
      int x = i / 2;
      int h = d[i] / 2;
      if (h == 0) continue;
      cnt += h;
      ++st[x - h];
      --st[x];
      ++fn[x];
      --fn[x + h];
    } else {
      int x = i / 2;
      int h = d[i] / 2 - 1;
      cnt += h + 1;
      ++st[x - h];
      --st[x + 1];
      ++fn[x];
      --fn[x + h + 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    st[i] += st[i - 1];
    fn[i] += fn[i - 1];
  }
  cnt %= MOD;
  long long pairs = (long long)cnt * (cnt - 1) / 2;
  long long no = 0;
  long long sums = 0;
  for (int i = n - 1; i >= 0; --i) {
    no += fn[i] * sums % MOD;
    sums += st[i];
    sums %= MOD;
  }
  no %= MOD;
  long long ans = pairs - no + MOD;
  ans %= MOD;
  cout << ans << endl;
}
int main() {
  cout.precision(15);
  cout << fixed;
  cerr.precision(9);
  cerr << fixed;
  srand(1510);
  solve();
}