Problem Statement

You are give an initial string ss of length nn consisting of only the letters a and b.

You are also given qq queries, in order, each containing two integers ll and rr.

For each query, determine the number of ab subsequences in the substring of ss from ll to rr.

Input Format

Your first line will contain nn and qq. Your next line will contain ss. Your next qq lines will contain two integers each, representing ll and rr for that query.

Output Format

For each each query, you should output one line containing a single integer representing the number of ab subsequences from that query's substring.

Constraints

Subtask 1

  • 1n,q1031 \leq n, q \leq 10^3
  • 0lrn10 \leq l \leq r \leq n - 1

Subtask 2

  • 1n,q1051 \leq n, q \leq 10^5
  • 0lrn10 \leq l \leq r \leq n - 1

Sample Cases

Input 1
10 3
abbabbbaab
1 2
1 5
0 7
Output 1
0
2
8
Input 2
10 3
bbababbaba
0 4
5 9
0 9
Output 2
1
1
8
Input 3
10 1
aaaaabbbbb
0 9
Output 3
25

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.