Олимпиадный тренинг

Задача 28416. Greatest Common Subsequence with Response Recovery


Задача

Темы:
Given two sequences, you want to find and print their greatest common subsequence.
 
Input
The first line of the input contains the number N – the length of the first sequence (1 ≤ N ≤ 1000). The second line contains the members of the first sequence (separated by a space) – integers not exceeding 10000 modulo.
 
The third line contains the number M – the length of the second sequence (1 ≤ M ≤ 1000). The fourth line contains the members of the second sequence (separated by a space) – integers not exceeding 10000 modulo.
 
Output
It is required to display the greatest common subsequence of these sequences, separated by a space.
 
Input Output
3
1 2 3
2 3 1
2 3