You are given two sequences of numbers named A and B. Your task is to find the longest common increasing subsequence.
In other words, let us assume that A has the length of n and can be shown as A1,A2,...,An. Also, B has the length of m and can be shown as B1,B2,...,Bm.
You are required to find a number l and two sequences of indices named C and D of length l such that the following conditions hold:
Input format
Output format
The output contains three lines:
In the first line, print an integer l that denotes the length of the longest common increasing subsequence.
In the second line, print l integers that represent elements of C (chosen indices of subsequence from A).
In the third line, print l integers that represent elements of D (chosen indices of subsequence from B).
Note
Constraints
1≤n,m≤105
1≤Ai,Bi≤109
As you can see, A1=B1 and A4=B2, A1≤A4 and B1≤B2. So this is a common increasing subsequence. However, this is not the best possible.
Consider the following indices from A and B:
Since following condition hold:
this is also a common increasing subsequence with length 3.