Say No to Palindromes solution codeforces

Say No to Palindromes solution codeforces


Let’s call the string beautiful if it does not contain a substring of length at least 22, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings ababaccabcabcbacb are palindromes, but the strings ababbbaacccb are not.

Let’s define cost of a string as the minimum number of operations so that the string becomes beautiful, if in one operation it is allowed to change any character of the string to one of the first 33 letters of the Latin alphabet (in lowercase).

You are given a string ss of length nn, each character of the string is one of the first 33 letters of the Latin alphabet (in lowercase).

You have to answer mm queries — calculate the cost of the substring of the string ss from lili-th to riri-th position, inclusive.

Input

The first line contains two integers nn and mm (1n,m21051≤n,m≤2⋅105) — the length of the string ss and the number of queries.

The second line contains the string ss, it consists of nn characters, each character one of the first 33 Latin letters.

The following mm lines contain two integers lili and riri (1lirin1≤li≤ri≤n) — parameters of the ii-th query.

Output

For each query, print a single integer — the cost of the substring of the string ss from lili-th to riri-th position, inclusive.

Example

input

Copy
5 4
baacb
1 3
1 5
4 5
2 3

output

Copy
1
2
0
1
Note

Consider the queries of the example test.

  • in the first query, the substring is baa, which can be changed to bac in one operation;
  • in the second query, the substring is baacb, which can be changed to cbacb in two operations;
  • in the third query, the substring is cb, which can be left unchanged;
  • in the fourth query, the substring is aa, which can be changed to ba in one operation.

Leave a Comment