#P8020. [ONTAK2015] Badania naukowe

[ONTAK2015] Badania naukowe

Problem Description

Given three digit strings A,B,CA, B, C, find a longest common subsequence of AA and BB such that CC is a substring of this subsequence.

Input Format

The first line contains an integer nn, the length of AA.

The second line contains nn integers, representing the digit string AA.

The third line contains an integer mm, the length of BB.

The fourth line contains mm integers, representing the digit string BB.

The fifth line contains an integer kk, the length of CC.

The sixth line contains kk integers, representing the digit string CC.

Output Format

Output one line with one integer. If there is no solution, output 1-1; otherwise, output the length of the longest common subsequence that satisfies the condition.

7
1 2 2 3 1 1 2
6
1 2 1 3 1 2
2
3 2
4

Hint

For 100%100\% of the testdata, 1n,m3×1031 \leq n, m \leq 3 \times 10^3, 0k3×1030 \leq k \leq 3 \times 10^3.

Translated by ChatGPT 5