时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
Niuniu has recently learned LCS(Longest Common Subsequence) of two sequences.
Now he wants to know the LCS of four sequences.
Given 4 sequences {a
i}, {b
i}, {c
i}, {d
i}.
Please find the longest common subsequence.
输入描述:
The first line contains one integer, which is n.
The second line contains n integers, which is the sequence {ai}.
The third line contains n integers, which is the sequence {bi}.
The fourth line contains n integers, which is the sequence {ci}.
The fifth line contains n integers, which is the sequence {di}.
1 <= n <= 10000
1 <= ai <= n
Any number appears in {ai} at most 2 times.
1 <= bi <= n
Any number appears in {bi} at most 2 times.
1 <= ci <= n
Any number appears in {ci} at most 2 times.
1 <= di <= n
输出描述:
You should output one integer, which is the length of the LCS.
示例1
输入
复制
5
1 2 1 2 3
1 2 3 1 2
3 1 2 1 2
1 2 1 2 1