- Time limit: 1.00 s
- Memory limit: 512 MB
Given two arrays of integers, find their longest common subsequence.
A subsequence is a sequence of array elements from left to right that can contain gaps. A common subsequence is a subsequence that appears in both arrays.
Input
The first line has two integers and : the sizes of the arrays.
The second line has integers : the contents of the first array.
The third line has integers : the contents of the second array.
Output
First print the length of the longest common subsequence.
After that, print an example of such a sequence. If there are several solutions, you can print any of them.
Constraints
Example
Input:
8 6 3 1 3 2 7 4 8 2 6 5 1 2 3 4
Output:
3 1 2 4