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
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Candles Counting

Candles Counting

Problem
Submissions
Leaderboard
Discussions
Editorial

Tim is visiting his grandma for two days and is bored due to the lack of the electricity over there. That's why he starts to play with grandma's colorful candle collection.

He aligned the candles from left to right. The th candle from the left has the height and the color , an integer ranged from 1 to a given , the number of colors.

Now he stares at the sequence of candles and wonders, how many strictly increasing ( in height ) colorful subsequences are there? A subsequence is considered as colorful if every of the colors appears at least one times in the subsequence.

As the number of subsequences fulfilling the requirement can be large, print the result modulo .

Input Format

On the first line you will be given and , then lines will follow. On the th line you will be given two integers and .

Constraints

Output Format

Print the number of strictly increasing colorful subsequences modulo .

Sample Input

4 3
1 1
3 2
2 2
4 3

Sample Output

2

Explanation

In the first sample the only two valid subsequences are (1, 2, 4) and (1, 3, 4).

Author

Gary97

Difficulty

Medium

Max Score

85

Submitted By

1385

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature