Milly and Strings
Practice
3.2 (101 votes)
Ready
Approved
Easy Medium
Problem
42% Success 3349 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Milly is playing with some strings. She will take one random string S. She is interested to find such number of integers i[Li , Ri] such that Si = Si+1 = Si+2 . Your task is to help Milly in this problem.

Input

  • First line of the input will contain T (No. of test cases).
  • For each test case, first line will contain a string S.
  • Next line will contain an integer Q (No. of queries) and then next each Q lines will contain two space separated integers Li and Ri .

Output

  • For every query, print the answer in a new line.

Constraints

  • 1 ≤ T ≤ 5
  • 3 ≤| S| ≤ 105
  • 1 ≤ Q ≤ 105<>
  • 1 ≤ Li Ri ≤ |S|-2
  • Here || denotes the length of the string and characters of S ∈ {a, b, c ..., z}

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
11 votes
Tags:
Basic ProgrammingOpenApprovedEasyMathamatics
Points:30
452 votes
Tags:
Modular exponentiationMediumModular arithmeticApprovedMathematics
Points:20
191 votes
Tags:
ApprovedEasyReadySorting