Like most of the demanding childs.Pratik don't stop until he gets that.He keep on…
- User
Like most of the demanding childs.Pratik don't stop until he gets that.He keep on repeating the name of that thing again and again. For example if he want a computer,He will keep on repeating "computer" again and again. His dad has decided to answer to his demand as "Yes" or "No" without any delay.Otherwise there would be a lot of repercussions.So, randomly at certain interval,He just answer with "Yes" or "No" by using following rule that he will select two integers a and b, if the element at the position a is same as element at position b in the repeating chant pratik then he will speak "Yes", Otherwise he will say "No". Your work is to find the answer of his dad given the name of the demand that pratik is asking for and the random integer his dad has picked. Input
First line of the input contains a string S, the name of the item he is demanding. Next line contains an integer T, the number of pairs of integer to answer "Yes" or "No". For each next N lines, each line contains two space separated integers ai and bi. Next T lines each contain 2 integers, a and b.
Output
For each query, print "Yes" or "No" as described above
Constraints
1 ≤ |S| ≤ 10^5 1 ≤ Q ≤ 10^5 1 ≤ a,b ≤ 10^18
Example Input: computer 4 3 7 2 10 5 21 11 26
Output:
No Yes Yes No
Explanation
In the first case the character at 3rd position is 'm' and the character at 7th position is 'e' so the answer is "No" In the second case the character at the 2nd position is 'o' and if we repeat the string (like computercomputercomputer...) the character at 10th position is 'o' so the answer is "Yes"
Assistant
We need to read a string S of length n (1 ≤ n ≤ 1e5). There is an integer T (actually Q in constraints but input says "Next T lines each contain 2 integers, a and b") but the input description: "Next T lines each contain 2 integers, a and b." Actually sample input: after S, next line is integer T = 4, then "For each next N lines, each line contains two space separated integers ai and bi." That's contradictory. Let's parse sample: Input:
computer 4 3 7 2 10 5 21 11 26
So indeed after string, line with integer T = 4, then T lines each contain two integers (a and b). So Q = T. So we have Q up to 1e5, and a,b up to 1e18.
We need to answer for each pair (a, b) whether the character in the infinite repetition of S at position a (1-indexed) equals the character at position b.
We can compute the index modulo n, but careful: positions are 1-indexed. So position i corresponds to S[(i-1) % n]. So we compare S[(a-1) % n] and S[(b-1) % n]. Print "Yes" if equal, else "No".
So it's trivial.
But note constraints: a,b up to 1e18, so use long long.
Implementation: read S, compute n = length. Then read T, loop T times, read a, b. compute i = (a-1) % n, j = (b-1) % n, compare S[i] == S[j].
But careful: In Python, modulo with large ints works fine.
Edge cases: n can be 1, S length up to 1e5, Q up to 1e5.
Just output each result.
I think that's it.
But is there any trick? Possibly they might have large T and need fast I/O. In Python, we can use sys.stdin.read to read everything.
Also, note: the problem statement includes "For each next N lines" which might be a mistake. We ignore.
Thus solution.
But wait: there's a nuance: In sample, they output: for 3 7 -> No (computer: positions 3 is 'm', 7 is 'e', not equal). 2 10: 'o' and 10: 10 mod 8 = 2 (since 8 length), position 2 is 'o', so Yes. 5 21: 5-> 'u', 21: 21-1=20 mod8=4 -> 'u'? Actually 'computer': indices: 0:c,1:o,2:m,3:p,4:u,5:t,6:e,7:r. So (5) position 5 -> index 4 -> u. 21: (21-1)=20 mod8=4 -> u -> Yes. 11 26: 11-> index10 mod8=2 -> 'm', 26-> index25 mod8=1 -> 'o'? Wait 25 mod8 =1 -> 'o'? Actually 25%8=1, so char index1='o', not equal so No. Yes matches.
So algorithm correct.
Implementation:
def solve(): import sys data = sys.stdin.read().split() S = data[0] n = len(S) T = int(data[1]) out = [] idx = 2 for _ in range(T): a = int(data[idx]); b = int(data[idx+1]); idx+=2 i = (a-1) % n j = (b-1) % n out.append("Yes" if S[i]==S[j] else "No") sys.stdout.write("\n".join(out))
But note: the input after T may have lines with pairs; but we read sequentially.
Check: data[0] = S, data[1] = T, then next 2*T numbers. That works.
But there is a discrepancy: The problem statement says "For each next N lines, each line contains two space separated integers ai and bi." Possibly they meant T lines. We ignore.
Thus final answer.
I'll produce final solution.
But wait: Constraints: 1 ≤ |S| ≤ 10^5, 1 ≤ Q ≤ 10^5, a,b up to 10^18. So it's fine.
Complexity: O(n+Q).
One may use 0-indexed modulo.
Now produce final answer.
However, we should be careful: In some languages, modulo of negative numbers? Not relevant.
So answer is trivial.
Thus final. ```python
import sys
def solve() -> None: data = sys.stdin.read().split() if not data: return S = data[0] n = len(S) t = int(data[1]) out = [] idx = 2 for _ in range(t): a = int(data[idx]) b = int(data[idx + 1]) idx += 2 # 1‑indexed positions -> 0‑based indices in S i = (a - 1) % n j = (b - 1) % n out.append("Yes" if S[i] == S[j] else "No") sys.stdout.write("\n".join(out))
if name == "main": solve()