FLLM - PASIJANS

no tags 

Pasijans, patience, or solitaire is the name for a group of single player card games. One new such game, so new it has no name, is played with cards sporting random integers as values. The game starts by shuffling all cards and distributing them in N sequences, not necessarily of equal length. During each turn, the player can remove the first card in any sequence and place it at the end of the “Solution sequence”. The card that was second in the selected sequence now becomes the first and the turn ends. Of course once the card is in the “Solution sequence” it cannot be removed, replaced or altered in any way. So don't even try.

The game ends when all cards are in the “Solution sequence”. The object of the game is to construct the best possible “Solution sequence”. One sequence  is better than the other if for the first cards they differ, lets call them X and Y, the value on the card X is smaller than the value on the card Y. Write a program that finds the best possible “Solution sequence”.

Input

The first line contains one integer N (1 ≤ N ≤ 1000), number of starting sequences. Next N lines contain description of input sequences. Each line starts with an integer L (1 ≤ L ≤ 1000), length of the sequence. It's followed by L integers, smaller than 100.000.000.

Output

One line containing ΣL numbers, the best possible “Solution sequence” obtainable.

Example

Input:
3
1 2
1 100
1 1

Output:
1 2 100

hide comments
Branfili: 2013-02-19 09:55:57

Really??
Brute force gets AC??
Really??

Marin Tomic: 2012-10-02 13:44:19

weak test cases

:D: 2012-03-13 08:22:24

Yes, I agree. You could add COCI to the resource and add tests from their site (2009/10 round 2). Only remember to increase the time limit and rejudge.

For now I recommend checking those tests offline for full problem solving experience :)

Buda IM (retired): 2012-02-19 12:04:46

Resource is again COCI
EDIT : also testcases are very weak. If you used only official tests, please add some of your own, and put some effort in it. Too bad that you can AC this problem with non-optimal algorithm.

Last edit: 2012-02-22 17:18:54

Added by:Azat Taryhchiyev
Date:2012-02-15
Time limit:1s
Source limit:20000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ASM32-GCC MAWK BC C-CLANG NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PAS-GPC PAS-FPC PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:International Sebat Institutions