#C5630. Counting Contiguous Palindromic Subsequences
Counting Contiguous Palindromic Subsequences
Counting Contiguous Palindromic Subsequences
You are given a sequence of integers. Your task is to count all contiguous palindromic subsequences (subarrays) in the sequence. A contiguous subsequence is a segment of consecutive elements, and a palindrome is a sequence that reads the same forwards and backwards.
For instance, in the sequence [1, 1], the palindromic subsequences are: [1] (the first element), [1] (the second element), and [1, 1] (the entire sequence). Efficient solutions typically use dynamic programming.
inputFormat
The input is provided via standard input (stdin) with the following format:
- The first line contains a single integer n, representing the length of the sequence.
- The second line contains n space-separated integers representing the sequence.
outputFormat
The output, printed to standard output (stdout), is a single integer: the count of contiguous palindromic subsequences in the given sequence.
## sample1
1
1
</p>