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:

import java.util.*;
import java.math.*;
import static java.lang.Character.isDigit;
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
    static void debug(Object...os){
        System.err.println(deepToString(os));
    }
    int M = 51123987;
    void run(){
        next();
        String s = next();
        int res = solve(s);
        System.out.println(res);
    }
        
    int solve(String s) {
        StringBuilder b = new StringBuilder();
        for(int i=0;i<s.length();i++) {
            b.append('$');
            b.append(s.charAt(i));
        }
        b.append('$');
        s=null;
        System.gc();
        int[] rad = palindromeRadius(b.toString());
        b=null;
        System.gc();
        long all = 0;
        for(int i=0;i<rad.length;i++) {
            all += (rad[i]+1)/2 % M;
            if(all>=M)all-=M;
        }
        long res = all*(all-1)/2 % M;
        int[] add = new int[rad.length];
        for(int i=0;i<rad.length;i++) {
            int a = (rad[i]+1)/2 % M;
            if(a<=0)continue;
            if((i&1)==1) {// odd
                add[i+2*(a-1)]++;
                add[i-1]--;
            }else {// even
                add[i+2*(a-1)+1]++;
                add[i]--;
            }
        }
        int[] add2=new int[rad.length];
        for(int i=0;i<rad.length;i++) {
            int a = (rad[i]+1)/2 % M;
            if(a<=0)continue;
            if((i&1)==1) {// odd
                add2[i-2*(a-1)]++;
                add2[i+1]--;
            }else {// even
                add2[i-2*(a-1)-1]++;
                add2[i]--;
            }
        }
        rad=null;
        System.gc();
        int[] num=new int[add.length];
        for(int i=add.length-1;i>=0;i--) {
            num[i] = i==add.length-1 ? 0 : num[i+1] + add[i];
            if(num[i]>=M)num[i] -= M;
        }
        add = null;
        System.gc();
        int[] sum=new int[num.length];
        for(int i=1;i<num.length;i+=2) {
            sum[i] = i==1 ? num[i] : sum[i-2] + num[i];
            if(sum[i]>=M)sum[i] -= M;
        }
        num = null;
        System.gc();
        int[] num2=new int[sum.length];
        long sub = 0;
        for(int i=0;i<sum.length;i++) {
            num2[i] = i==0 ? 0 : num2[i-1] + add2[i];
            if(num2[i]>=M)num2[i] -= M;
            
            if((i&1)==1 && i>2) {
                sub = (sub + (long)num2[i] * sum[i-2]) % M;
            }
        }
        res -= sub;
        if(res<0)res += M;
        return (int)res;
    }
    
    public static int[] palindromeRadius(String s) {
        int n=s.length();
        int[] rad=new int[n];
        for(int i=0,j=0;i<n;) {
            while(j<n && i+i-j>=0 && s.charAt(j)==s.charAt(i+i-j))j++;
            rad[i]=j-i-1;
            for(int bi=i++;i<j && rad[bi+bi-i]!=rad[bi]+bi-i;i++) {
                rad[i] = Math.min(rad[bi]+bi-i,rad[bi+bi-i]);
            }
        }
        return rad;
    }
    
    int nextInt(){
        try{
            int c=System.in.read();
            if(c==-1) return c;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return c;
            }
            if(c=='-') return -nextInt();
            int res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }
    
    long nextLong(){
        try{
            int c=System.in.read();
            if(c==-1) return -1;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return -1;
            }
            if(c=='-') return -nextLong();
            long res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }
    
    double nextDouble(){
        return Double.parseDouble(next());
    }
    
    String next(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(Character.isWhitespace(c))
                c=System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }
    
    String nextLine(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(c=='\r'||c=='\n')
                c=System.in.read();
            do{
                res.append((char)c);
                c=System.in.read();
            }while(c!='\r'&&c!='\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }
    public static void main(String[] args){
        new Main().run();
    }
}