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 JAVA):

Solution:
/**
 * Codeforces Beta Round 17
 * 
 * @author ProjectYoung
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CF17E {
  private static final int base = 51123987;

  private void solve(InputReader in, PrintWriter out) {
    int s = in.nextInt();
    int[] len = StringAlgo.Manacher(in.next());
    PartialSum start = new PartialSum(new int[s]);
    PartialSum end = new PartialSum(new int[s]);
    for (int i = 0; i < len.length; i++) {
      start.update((i - len[i] + 2) >> 1, (i + 2) >> 1, 1);
      end.update((i + 1) >> 1, (i + len[i] + 1) >> 1, 1);
    }
    long sum = start.query(0, s);
    long total =
        (sum & 1L) == 1 ? ((sum - 1) / 2 % base) * (sum % base) % base : (sum / 2 % base)
            * ((sum - 1) % base) % base;
    long not = 0;
    for (int i = 0; i < s; i++) {
      not += end.query(i) % base * start.query(i + 1, s) % base;
      not %= base;
    }
    out.println((total - not + base) % base);
  }

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new CF17E().solve(in, out);
    out.close();
  }

  static class StringAlgo {
    /**
     * Manacher's algorithm to find the maximal length of a subpalindrome with its center either at
     * position i of the string or between positions i and i + 1 for each possible center.
     * 
     * @param s a non-empty string.
     * @return an array of integers "len". substring((i - len[i] + 2) / 2, (i + len[i] + 1) / 2) is
     *         the longest subpalindrome among all the subpalindromes with the same center.
     */
    public static int[] Manacher(String s) {
      int[] len = new int[s.length() * 2 - 1];
      int id = 0;
      int r = 0;
      for (int i = 0; i < len.length; i++) {
        if (i < id + r && len[2 * id - i] < id + r - i) {
          len[i] = len[2 * id - i];
        } else {
          len[i] = Math.max(id + r - i, 1);
          while (i - len[i] + 1 > 0 && i + len[i] < len.length
              && s.charAt((i + len[i]) / 2) == s.charAt((i - len[i] + 1) / 2)) {
            len[i]++;
          }
          id = i;
          r = len[i];
        }
      }
      return len;
    }
  }

  static class PartialSum {
    private long[] sum;
    private long[] delta;
    private boolean queryMode;

    public PartialSum(int[] num) {
      int n = num.length;
      this.sum = new long[n + 1];
      this.delta = new long[n + 1];
      this.queryMode = true;

      for (int i = 0; i < n; i++) {
        this.sum[i + 1] = this.sum[i] + num[i];
      }
    }

    public void update(int l, int r, long d) {
      delta[l] += d;
      delta[r] -= d;
      queryMode = false;
    }

    public void update(int p, long d) {
      update(p, p + 1, d);
    }

    public long query(int l, int r) {
      if (!queryMode) {
        flip();
      }
      return sum[r] - sum[l];
    }

    public long query(int p) {
      return query(p, p + 1);
    }

    private void flip() {
      long c = 0;
      long s = 0;
      for (int i = 0; i < sum.length; i++) {
        sum[i] += s;
        c += delta[i];
        s += c;
        delta[i] = 0;
      }
      queryMode = true;
    }
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}