Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2707.   Greatest Common Increasing Subsequence
Time Limit: 5.0 Seconds   Memory Limit: 65536K    Special Judge
Total Runs: 1349   Accepted Runs: 243    Multiple test files
Case Time Limit: 2.0 Seconds

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 < ... < iNM such that Sj = Aij for all 1 ≤ jN, 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 (-231Ai < 231) — the sequence itself.


On the first line of the output 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.

Sample Input

1 4 2 5 -12
-12 1 2 4

Sample Output

1 4

Note: Special judge problem, you may get "Wrong Answer" when output in wrong format.

Source: Northeastern Europe 2003 Northern Subregion
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:G.D.Retop. Developer: SuperHacker, G.D.Retop