DNA Palindrome Markers
In molecular biology, palindromic sequences in DNA are significant because they often represent binding sites for enzymes or markers for genetic analysis. A palindromic DNA sequence reads the same forwards and backwards.
Alice is analyzing a DNA strand (represented as a string of characters) and needs to quickly answer queries about whether certain regions contain palindromic markers.
Given a DNA strand and q queries, each query asks: is the substring from position i to position j (inclusive, 1-indexed) a palindrome?
Input
The first line contains the DNA strand s (1 ≤ |s| ≤ 1000).
The second line contains the number of queries q (1 ≤ q ≤ 100000).
Each of the next q lines contains two integers i and j (1 ≤ i ≤ j ≤ |s|) representing a query range.
Output
For each query, print YES if the substring s[i..j] is a palindrome, or NO otherwise.
Notes
A palindrome reads the same forwards and backwards. For example, "ACA" is a palindrome, but "ACG" is not.
Positions are 1-indexed, so the first character of the strand is at position 1.