406562: GYM102441 D Lis on Circle
Description
There are $$$n$$$ people at the round gaming table. Each of them has a set of cards. Every card contains some number $$$x$$$. Players make turns consecutively, one after another, starting from the player number 1. A player in his turn can either skip his turn (to pass), or put (and leave on the table) a card with a number that is strictly greater than the previously played last number. No more than $$$k$$$ players in a row can pass the turn. All players know the numbers written on the other players cards and always play optimally. Help gamblers to assemble an increasing sequence of maximum length.
InputThe first line contains two numbers $$$n$$$ and $$$k$$$ — the number of players and the maximum possible amount of turn skipping in a row.
The next $$$n$$$ lines contain the description of the cards players have in their hands. The first number in the $$$m_i$$$ is the number of cards the current player has in his hand. The following space separated $$$m_i$$$ numbers represent the written on the cards numbers $$$x$$$.
$$$$$$0 \le \sum m_i \le 10^5$$$$$$ $$$$$$1 \le n \le 10^5$$$$$$ $$$$$$0 \le k < n$$$$$$ $$$$$$0 \le x \le 10^9$$$$$$
OutputIn the first line print the single number — the length of the maximum sequence. In the next lines print two space separated numbers: the player index number and the number written on the card he played. If several solutions exist, output any of them.
ExampleInput3 1 4 1 10 12 20 2 11 21 4 3 5 15 22Output
9 1 1 3 3 1 10 2 11 1 12 3 15 1 20 2 21 3 22