Problem:
Score : 900 points

Problem Statement

There is a string S of length N consisting of characters 0 and 1. You will perform the following operation for each i = 1, 2, ..., m:

Arbitrarily permute the characters within the substring of S starting at the l_i-th character from the left and extending through the r_i-th character.

Here, the sequence l_i is non-decreasing.

How many values are possible for S after the M operations, modulo 1000000007(= 10^9+7)?

Constraints

2≦N≦3000

1≦M≦3000

S consists of characters 0 and 1.

The length of S equals N.

1≦l_i < r_i≦N

l_i ≦ l_{i+1}

Input

The input is given from Standard Input in the following format:

N M
S
l_1 r_1
:
l_M r_M

Output

Print the number of the possible values for S after the M operations, modulo 1000000007.

Sample Input 1

5 2
01001
2 4
3 5

Sample Output 1

6

After the first operation, S can be one of the following three: 01001, 00101 and 00011.

After the second operation, S can be one of the following six: 01100, 01010, 01001, 00011, 00101 and 00110.

Sample Input 2

9 3
110111110
1 4
4 6
6 9

Sample Output 2

26

Sample Input 3

11 6
00101000110
2 4
2 3
4 7
5 6
6 10
10 11

Sample Output 3

143

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        string s = Console.ReadLine();
        int N = int.Parse(str[0]);
        int[] R = new int[N];
        {
            int M = int.Parse(str[1]);
            int l = 0;
            int r = 0;
            for(int i=0;i<M;i++){
                str = Console.ReadLine().Split(' ');
                int a = int.Parse(str[0])-1;
                int b = int.Parse(str[1])-1;
                if(l != a){
                    for(int j=l;j<a;j++){
                        R[j] = r;
                    }
                    l = a;
                }
                r = Math.Max(r,b);
            }
            for(int j=l;j<N;j++){
                R[j] = Math.Max(r,j);
            }
        }
        int[] one = new int[N];
        one[0] = s[0] == '1' ? 1 : 0;
        for(int i=1;i<N;i++){
            one[i] = one[i-1] + (s[i] == '1' ? 1 : 0);
        }
        int C = one[N-1];
        long[,] dp = new long[N,C+1];
        dp[N-1,C] = 1;
        for(int i=C-1;i>=0;i--){
            dp[N-1,i] = 0;
        }
        for(int i=N-2;i>=0;i--){
            for(int j=0;j<C;j++){
                dp[i,j] = (one[R[i]] >= j && (R[i] + 1 - one[R[i]] >= i + 1 - j)) ? (dp[i+1,j] + dp[i+1,j+1]) % Define.mod : 0; 
            }
            dp[i,C] = (one[R[i]] >= C && (R[i] + 1 - one[R[i]] >= i + 1 - C)) ? dp[i+1,C] : 0;
        }
        sb.Append((dp[0,0] + dp[0,1])+"\n");
    }
}
public static class Define{
    public const long mod = 1000000007;
}