We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Requirement

Requirement

Problem
Submissions
Leaderboard
Discussions
Editorial

There are variables and requirements. Requirements are represented as , meaning that the variable must be less than or equal to the variable.

Your task is to assign non-negative numbers smaller than to each variable and then calculate the number of different assignments satisfying all requirements. Two assignments are different if and only if at least one variable is assigned to a different number in both assignments. Print your answer modulo .

Input Format

The first line contains space-separated integers, and , respectively. Each of the subsequent lines contains space-seperated integers describing the respective and values for an requirement.

Constraints

Output Format

Print your answer modulo .

Sample Input 0

6 7
1 3
0 1
2 4
0 4
2 5
3 4
0 2

Sample Output 0

1000

Explanation 0

There are variables and requirements.

Let the variables be in the array .

Requirements are -

One of the assignments is -

Similarly there are assignments possible.

Result = .

Author

HackerRank

Difficulty

Advanced

Max Score

80

Submitted By

1801

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website