Say No To Palindrome
Let's call the string beautiful if it does not contain a substring of length at least 2, which is a palindrome. 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 3 letters of the latin alphabet (in lowercase). You are given a string s of length n, each character of the string is one of the first 3 letters of the latin alphabet ( in lowercase). you have to answer m queries - calculate the cost of the substring of the string s from l to r position, inclusive.
1 <= n,m <= 200000 1 <= l,r <= n
The first line contains two integers n and m. the length of string s and the number of queries. The second line contains the string s, it consists of n characters, each character one of the first 3 Latin letters. The following m lines contain two integers l and r (both inclusive).
For each query, print a single integer. the cost of the substring of the string s from l-th to r-th position.
5 4 baacb 1 3 1 5 4 5 2 3
1 2 0 1