atcoder#ABC185E. [ABC185E] Sequence Matching
[ABC185E] Sequence Matching
Score : points
Problem Statement
We have an integer sequence of length and an integer sequence of length . Takahashi will make a new sequence by removing some elements (possibly zero or all) from and concatenating the remaining elements. Similarly, he will make another new sequence by removing some elements (possibly zero or all) from and concatenating the remaining elements. Here, he will remove elements so that . ( denotes the length of for a sequence .) Let be the total number of elements removed from and , and be the number of integers such that and . Print the minimium possible value of .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_N$
$B_1 \hspace{7pt} B_2 \hspace{7pt} B_3 \hspace{5pt} \dots \hspace{5pt} B_M$
Output
Print the minimum possible value of .
4 3
1 2 1 3
1 3 1
2
If we make by removing from , and by removing nothing from , will be . Here, there is just one integer such that and : , so will be , and will be , which is the minimum possible value.
4 6
1 3 2 4
1 5 2 6 4 3
3
If we remove nothing from and remove from , we have , and , which is the minimum possible value.
5 5
1 1 1 1 1
2 2 2 2 2
5
It is allowed to remove nothing from both and .