#C1432. Opposite Substring Verification

    ID: 43956 Type: Default 1000ms 256MiB

Opposite Substring Verification

Opposite Substring Verification

Given two strings \(S\) and \(T\) each of length \(n\) and \(q\) queries, determine for each query whether the specified substrings of \(S\) and \(T\) are opposites. Two substrings \(S[i:j]\) and \(T[i:j]\) (with indices being 1-indexed) are defined as opposites if they are anagrams; that is, they contain the same characters with the same frequencies. Formally, the substrings are opposites if \(\text{Counter}(S[i:j]) = \text{Counter}(T[i:j])\).

inputFormat

The input is provided via standard input and follows the format below:

  1. The first line contains an integer \(n\) representing the length of the strings.
  2. The second line contains the string \(S\).
  3. The third line contains the string \(T\).
  4. The fourth line contains an integer \(q\), the number of queries.
  5. Each of the following \(q\) lines contains two space-separated integers \(i\) and \(j\) (1-indexed) denoting the starting and ending indices of the substrings to be compared.

outputFormat

For each query, output a single line containing either "Yes" if the two substrings are opposites (i.e. anagrams), or "No" if they are not.

## sample
4
abcd
dcba
2
1 4
1 2
Yes

No

</p>