Hide

Problem G
Superyatzy

Languages en sv

Emma loved playing Yatzy when she was younger and recently decided to try playing it again for the first time in many years. However, she quickly realized that it was a bit boring with just five dice, so she changed the rules to include $N$ dice and called the new game Superyatzy. Unsurprisingly, it turned out that it is very difficult to get Yatzy when playing Superyatzy! To fix the problem, Emma started cheating and turning some of the dice to show the value she wanted. However, Emma is a bit paranoid and is scared that someone will notice. Therefore, she decides to only change the value of at most $M$ dice. Is it possible for Emma to get Yatzy if she cheats in this way?

Emma is using normal 6 sided dice, and wants all dice to show the same value - then she has gotten ”Yatzy” and wins the game.

Input

First, a line containing the numbers $N$ ($1 \leq N \leq 10^5$) and $M$ ($0 \leq M \leq N$) is given, where $N$ is the number of dice Emma has, and $M$ is the number of dice Emma can cheat with and turn over. Then follow $N$ lines where the $i$-th line contains a number $t_ i$, where $t_ i$ represents the value of the $i$-th die.

Output

Output ”Ja” if Emma can get Yatzy and ”Nej” otherwise.

Points

Your solution will be tested on different test groups. To score points for a group, you must pass all the test cases in that group.

Group

Point value

Constraints

$1$

$15$

$N = 5, M = 0$

$2$

$20$

$N = 5$

$3$

$10$

At least half the dice show $6$.

$4$

$20$

All dice show either $5$ or $6$.

$5$

$35$

No additional constraints.

Explanation of sample 1:

We receive five dice and can cheat zero times. All dice must be the same for us to achieve Yatzy, but they are not.

Explanation of sample 2:

We receive five dice and can cheat three times. This can be done by changing the second, third, and fourth dice to $2$s. Alternatively, we can change the first, fourth, and fifth dice to $4$s and achieve Yatzy in fours.

Sample Input 1 Sample Output 1
5 0
1
1
1
2
1
Nej
Sample Input 2 Sample Output 2
5 3
2
4
4
3
2
Ja
Sample Input 3 Sample Output 3
10 5
1
6
1
3
2
6
6
3
6
4
Nej

Please log in to submit a solution to this problem

Log in