logo AlgoBeat OnlineJudge
登录 注册

#212520. [INOI Team Selection 2021] Lisdeque

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Master Oogway has deques, all elements in these deques are different.

Panda wants to be the Dragon Warrior, needs to make most powerful array he can with this deques.

In each turn he can choose a nonempty deque (if there is any) and choose it's front or back and append that value to end of the array, then pop that value from the deque. help him to find most powerful array he can make.

The power of an array is the longest increasing subsequence (LIS) of it.

输入格式

First line of input contains integer , the number of deques Master Oogway has.

In the -th line of next line, there is an integer , the size of -th deque, followed by integers, elements of -th deque.

输出格式

In the first line of output, print the maximum LIS you can make, then print the resulted array, if there is more than one possible answer, you can print any of them.

样例

样例输入 1

3
4 7 2 3 5
3 1 11 9
4 10 4 8 6

样例输出 1

9
1 7 2 3 10 4 5 6 8 9 11

数据范围与提示

constraints

Subtasks

subtask score limits
1 50
2 No extra limits