Decrease the Boss Strength

시간 제한1.5초메모리 제한1024 MB

요약
시작값 N을 정확히 0으로 줄이는 주문 사용 순서의 가짓수를 구한다. 주문 i는 a_i를 빼며, N이 2^b_i로 나누어떨어질 때만 쓸 수 있다.
난이도

어려움10점 중 8점

유형
동적 계획법, 비트 연산, 조합론, 수학
정답자
아직 제출이 없습니다

문제

Fulano, an avid gamer, has come across an epic challenge in the online game “Boss Challenge”. The goal is to defeat a powerful boss, whose power is described by a set of ancient runes. These runes represent a giant binary number NN, indicating the total strength of the enemy.

To defeat the boss, Fulano has MM different spells at his disposal, and the goal is to reduce the total strength of the enemy to zero using these spells. The ii-th spell is described with two integers a_ia\_i and b_ib\_i. When used, the ii-th spell reduces the value of NN by a_ia\_i units. This spell can be used as many times as the player wants, as long as two specific conditions are met:

  • The value of a_ia\_i must be less than or equal to the current value of NN.
  • The current value of NN must be divisible by 2b_i2^{b\_i}. In other words, the spell ii can only be used if the last b_ib\_i digits of NN are zeros.

Fulano is fascinated by the game and wants to find out how many different ways he can combine the spells to reduce the binary number NN to exactly zero and thus defeat the boss. Two combinations are considered different if the sequence in which the spells are used is different.

Since the number of possible combinations can be very large, the answer should be given modulo 109+710^9 + 7.

Help Fulano find the answer!

입력

The first line contains a single integer NN (1≤N≤10181 ≤ N ≤ 10^{18}), representing the boss’s power.

The second line contains a single integer MM (1≤M≤1051 ≤ M ≤ 10^5), denoting the number of spells available.

The next MM lines contain the spell descriptions: the ii-th of these lines contains two numbers a_ia\_i (1≤a_i≤1001 ≤ a\_i ≤ 100) and b_ib\_i (0≤b_i≤600 ≤ b\_i ≤ 60).

출력

Print a single integer: the number of different sequences of spell uses (taken modulo 109+710^9 + 7) that reduce the boss’s power from NN to 00.

예제2

  1. 예제 1

    입력
    6 2
    1 0
    2 1
    
    예상 출력
    8
    
  2. 예제 2

    입력
    9 5
    1 0
    1 1
    4 3
    1 1
    8 0
    
    예상 출력
    92