Greatest Common Increasing Subsequence | 프로그래밍의 벗 PivotOJ
PivotOJ

Greatest Common Increasing Subsequence

시간 제한: 1000ms메모리 제한: 256MB출처: NEERC Northern Subregional 2003BOJ 7476

문제

You are given two sequences of integer numbers. Write a program to determine their common increasing subsequence of maximal possible length.

Sequence S1, S2, ..., Sn of length N is called an increasing subsequence of a sequence A1, A2, ..., AM of length M if there exist 1 ≤ i1 < i2 < ... < iN such that  Sj = Aij for all 1 ≤ j ≤ N, and Sj < Sj+1 for all 1 ≤ j<N.

입력

Each sequence is described with M — its length (1 ≤ M ≤ 500) and M integer numbers Ai (-231 ≤ Ai < 231) — the sequence itself.

출력

On the first line of the output file print L — the length of the greatest common increasing subsequence of both sequences. On the second line print the subsequence itself. If there are several possible answers, output any of them.

예제

예제 1

입력
5
1 4 2 5 -12
4
-12 1 2 4
출력
2
1 4
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.