链接:https://codeforces.com/group/nhsfFrN6WT/contest/266629/problem/C

JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.

First, he splits the Banh-mi into nn parts, places them on a row and numbers them from 11 through nn. For each part ii, he defines the deliciousness of the part as xi∈{0,1}xi∈{0,1}. JATC's going to eat those parts one by one. At each step, he chooses arbitrary remaining part and eats it. Suppose that part is the ii-th part then his enjoyment of the Banh-mi will increase by xixi and the deliciousness of all the remaining parts will also increase by xixi. The initial enjoyment of JATC is equal to 00.

For example, suppose the deliciousness of 33 parts are [0,1,0][0,1,0]. If JATC eats the second part then his enjoyment will become 11 and the deliciousness of remaining parts will become [1,_,1][1,_,1]. Next, if he eats the first part then his enjoyment will become 22 and the remaining parts will become [_,_,2][_,_,2]. After eating the last part, JATC's enjoyment will become 44.

However, JATC doesn't want to eat all the parts but to save some for later. He gives you qq queries, each of them consisting of two integers lili and riri. For each query, you have to let him know what is the maximum enjoyment he can get if he eats all the parts with indices in the range [li,ri][li,ri] in some order.

All the queries are independent of each other. Since the answer to the query could be very large, print it modulo 109+7109+7.

Input

The first line contains two integers nn and qq (1≤n,q≤1000001≤n,q≤100000).

The second line contains a string of nn characters, each character is either '0' or '1'. The ii-th character defines the deliciousness of the ii-th part.

Each of the following qq lines contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n) — the segment of the corresponding query.

Output

Print qq lines, where ii-th of them contains a single integer — the answer to the ii-th query modulo 109+7109+7.

Examples

input

Copy

4 2
1011
1 4
3 4

output

Copy

14
3

input

Copy

3 2
111
1 2
3 3

output

Copy

3
1

Note

In the first example:

  • For query 11: One of the best ways for JATC to eats those parts is in this order: 11, 44, 33, 22.
  • For query 22: Both 33, 44 and 44, 33 ordering give the same answer.

In the second example, any order of eating parts leads to the same answer.

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,t,k,c,sum,mod=1e9+7,vis=1,q,mx=0,kk=0,y=0;
long long l,r,s[10000001];
char x[1000001];
long long pow_m(long long a, long long b)
{
	long long ans = 1;
	while(b > 0)
	{
		if(b & 1)
		{
			ans = ans * a % mod;
		}
		a = a * a % mod;
		b >>= 1; 
	} 
	return ans;
}
int main()
{
	scanf("%lld %lld\n",&n,&q);
	cin>>x;
	sum=0;
	for(int i=0;i<n;i++)
	{
		if(x[i]=='1')
		sum++;
		s[i+1]=sum;
	}
	for(int i=1;i<=q;i++)
	{
		cin>>l>>r;
		c=s[r]-s[l-1];
		k=r-l+1;
		if(c==0)
		cout<<0<<endl;
		else
		{
			long long ss=pow_m(2,c)-1;
			long long kk=pow_m(2,k-c);
			long long ans=kk*ss;
			ans%=mod;
			cout<<ans<<endl;
		}
	}
	
}