#C553. Count Palindromic Subarrays

    ID: 49189 Type: Default 1000ms 256MiB

Count Palindromic Subarrays

Count Palindromic Subarrays

Given an array of integers, your task is to count the number of contiguous subarrays that form a palindrome. A subarray is considered palindromic if it reads the same forwards and backwards.

For example, in the array [2, 2, 2], every individual element and every subarray consisting of contiguous elements is a palindrome, resulting in a total count of 6.

Note: The subarray is defined as a contiguous segment of the array.

Mathematically, if you denote a subarray from index i to j as \(A[i\ldots j]\), then it is a palindrome if: \[ A[i\ldots j] = A[j\ldots i] \]

inputFormat

The input is given in two lines:

  • The first line contains a single integer \(n\) representing the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output a single integer which is the count of all palindromic subarrays in the array.

## sample
1
1
1