Misha has an array of n integers indexed by integers from 1 to n. Let's define palindrome degree of array a as the number of such index pairs (l, r)(1 ≤ l ≤ r ≤ n), that the elements from the l-th to the r-th one inclusive can be rearranged in such a way that the whole array will be a palindrome. In other words, pair (l, r) should meet the condition that after some rearranging of numbers on positions from l to r, inclusive (it is allowed not to rearrange the numbers at all), for any 1 ≤ i ≤ n following condition holds: a[i] = a[n - i + 1]. 

Your task is to find the palindrome degree of Misha's array.

Input

The first line contains integer n (1 ≤ n ≤ 105).

The second line contains n positive integers a[i] (1 ≤ a[i] ≤ n), separated by spaces — the elements of Misha's array.

Output

In a single line print the answer to the problem.

Examples

Input

3
2 2 2


Output

6


Input

6
3 6 5 3 3 5


Output

0


Input

5
5 5 2 5 2


Output

4

Note

In the first sample test any possible pair (l, r) meets the condition.

In the third sample test following pairs (1, 3), (1, 4), (1, 5), (2, 5) meet the condition.
// package Div2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class Sketch {	
	private static boolean checkPalidrome(int[] A, int start, int end){
		int n = A.length;
		int[] buckets = new int[n];
		int rstart = n-1-end;
		int rend = n-1-start;
		
		int halfn = n/2;
		
		for(int i=start; i<=end; i++)
			buckets[A[i]]++;
		if(halfn > end || halfn < start){
			for(int i=rstart; i<=rend; i++){
				if(--buckets[A[i]] < 0)
					return false;
			}
			for(int i=0; i<n; i++)
				if(buckets[i] > 0)
					return false;
				else 
					buckets[i] = 0;
			
			int a = Math.min(end, rend);
			int b = Math.max(start, rstart);
			for(int i=a+1; i<b; i++){
				if(A[i] != A[n-1-i])
					return false;
			}
			return true;
		}
		else {
			int a, b;
			if(start < rstart){
				a = end+1;
				b = rend;
			}
			else {
				a = rstart;
				b = start-1;
			}
			for(int i=a; i<=b; i++){
				buckets[A[i]]--;
			}
			int cnt = 0;
			for(int i=0; i<n; i++){
				if(buckets[i] < 0)
					return false;
				if(buckets[i]%2 !=0)
					cnt++;
			}
			if(cnt > 1)
				return false;
			else 
				return true;
		}
	}
	
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] A = new int[n];
		
		for(int i=0; i<n; i++)
			A[i] = input.nextInt()-1;
		
		input.close();
		
		int start = 0;
		while(A[start] == A[n-1-start] && start <= n/2){
			start++;
		}
		
		if(start > n/2){
			long N = n;
			System.out.println(N*(N+1)/2);
			return;
		}
				
		int u = start;
		int v = n-1-start;

		if(!checkPalidrome(A, u, v)){
			System.out.println(0);
			return;
		}
		
		int hd = u;
		int tl = v;
		
		while(hd != tl){
			int mid = (hd+tl)/2;
			if(checkPalidrome(A, u, mid)){
				tl = mid;
			}
			else {
				hd = mid+1;
			}
		}
		
		int uu = hd;
		
		hd = u;
		tl = v;
		
		while(hd != tl){
			int mid = (hd+tl+1)/2;
			if(checkPalidrome(A, mid, v)){
				hd = mid;
			}
			else {
				tl = mid-1;
			}
		}
		
		int vv = hd;
		
		int result = (u+1) * (n-uu) + (vv+1) * (n-v) - (u+1) * (n-v);
		System.out.println(result);
	}
}
