This page is still under construction.

Parts of this page are still being built. What you see may change.

Listing Passwords

Time limit3sMemory limit1024 MB

Summary
Count the 0/1 strings of length N that fit the fixed digits and M required palindrome intervals, modulo 1e9+7, or 0 on conflict.
Level

Hard8 of 10

Topics
Union-find, String, Math
Solved
No attempts yet

Problem

Michael is the manager of a barely known office, and his room has a locker that holds the money for the employees. Unfortunately, Michael forgot the locker password, so it is now Dwight's job to help his boss. The password is a sequence of NN digits, each either 0 or 1. Michael remembers the value at some positions but not the whole password. He also remembers MM intervals of the password that are palindromes. He remembers palindromes well, for some reason. An interval is a palindrome if its first and last digits are equal, its second and second-to-last digits are equal, and so on. Dwight wants to know how hard it is to recover the whole password. He can calculate the number of possible passwords that match what Michael remembers. The answer may be very large, so output it modulo 109+710^9 + 7.

Input

The first line contains two integers NN and MM (1≤N≤3×1051 \le N \le 3 \times 10^5, 1≤M≤3×1051 \le M \le 3 \times 10^5). The second line contains a string of NN characters sis_i. If sis_i is 0 or 1, the ii-th digit of the password is that value. If sis_i is ?, Michael does not remember the ii-th digit. Each of the next MM lines contains two integers lil_i and rir_i (1≤li≤ri≤N1 \le l_i \le r_i \le N), meaning the part of the password from position lil_i to position rir_i, inclusive, is a palindrome.

Output

If Michael's memories conflict so that no password satisfies all of them, output 0. Otherwise, output the number of passwords that satisfy all of them, modulo 109+710^9 + 7.

Examples3

  1. Example 1

    Input
    5 2
    1??0?
    1 3
    2 4
    
    Expected output
    2
    
  2. Example 2

    Input
    3 2
    ???
    1 1
    1 3
    
    Expected output
    4
    
  3. Example 3

    Input
    5 2
    1???0
    1 3
    3 5
    
    Expected output
    0