Game of Cards

Decide the winner of a turn-based card game where each move trims one of many piles by up to K cards plus the value shown on the new top card.

Medium7Game theoryDynamic programmingNo attempts yetTime limit1sMemory limit256 MB

Problem

Alice and Bob invented a game at the beach this summer. All they need is a deck of numbered cards. They lay every card face up in PP piles and pick a number KK. Then they take turns like this.

  1. The player picks one of the piles.
  2. The player removes 00 to KK cards from the top of that pile, and has to leave at least one card in the pile.
  3. The player then reads the number on the card now at the top and removes that many cards from the top of the same pile.

A player who has no cards left to remove loses, and so does a player who has to remove more cards than the pile holds.

The figure shows a position with two piles and K=1K = 1. The first pile holds one card showing 1, and the second pile holds three cards showing 1, 2 and 1 from the bottom to the top. The player to move has three options.

  1. Pick the first pile and remove 0 cards. The top card shows 1, so 1 more card comes off.
  2. Pick the second pile and remove 0 cards. The top card shows 1, so 1 more card comes off.
  3. Pick the second pile and remove 1 card. The top card now shows 2, so 2 more cards come off.

Bob is very good at this game and wins whenever he has the chance. This time Alice moves first. Decide whether Alice can win.

Input

The first line contains two space separated integers PP and KK, the number of piles and the largest number of cards a player may remove at the start of a turn.

Each of the next PP lines describes one pile. The line starts with an integer NN, the number of cards in that pile, followed by NN space separated integers giving the cards from the bottom to the top.

Output

Print Alice can win. if Alice wins, and Bob will win. otherwise, on a single line.

Constraints

  • 1P1001 \le P \le 100, the number of piles.
  • 1K101 \le K \le 10, the largest number of cards a player may remove at the start of a turn.
  • 1N10001 \le N \le 1000, the size of each pile.
  • 1c101 \le c \le 10, the number on each card.