#C9159. Count Palindromic Words in Ranges

    ID: 53221 Type: Default 1000ms 256MiB

Count Palindromic Words in Ranges

Count Palindromic Words in Ranges

Given a list of words and a set of queries, your task is to count the number of palindromic words in each query range. A palindrome is a string that reads the same backwards as forwards. Each query specifies a range using 0-indexed positions.

For each query, you should determine the number of words in the specified range that are palindromes.

The palindrome check can be mathematically expressed as follows: \(\text{is\_palindrome}(s) = (s = s^{R})\), where \(s^{R}\) represents the reverse of string \(s\).

inputFormat

The input is read from standard input (stdin) and has the following format:

n
word1 word2 ... wordN
q
L1 R1
L2 R2
... 
Lq Rq

Where:

  • \(n\) is the number of words.
  • The next line contains \(n\) words separated by spaces.
  • \(q\) is the number of queries.
  • Each of the following \(q\) lines contains two integers \(L\) and \(R\) (0-indexed) specifying the range (inclusive).

outputFormat

For each query, output a single line containing the number of palindromic words in the range defined by indices \(L\) and \(R\) (inclusive). The result should be printed to standard output (stdout).

## sample
5
radar level world deified civic
4
0 2
1 3
2 4
0 4
2

2 2 4

</p>