Problem 2: Indraneel's Experiment, (K Narayan Kumar, CMI)

Indraneel's student has given him data from two sets of experments that the student has performed. Indraneel wants to establish a correlation between the two sets of data. Each data set is a sequence of N numbers. The two data sets do not match number for number, but Indraneel believes that this is because data has been shifted due to inexact tuning of the equipment.

For example, consider the following two sequences:

3  8   4  23  9  11  28
2  3  22  26  8  16  12

Indraneel observes that if we consider the subsequences 3,4,23,9 and 2,3,22,8 and examine their successive differences we get 1,19,-14. He considers these to subsequences to be "identical". He would like to find the longest such pair of subsequences so that the successive differences are identical. Your task is to help him do this.

Input format

The first line of the input will contain a single integer N indicating the number of datapoints in each of Indraneel's student's data sets. This is followed by two lines, each containing N integers.

Output format

The output consists of three lines. The first line of output contains a single integer indicating the length of the longest pair of subsequences (one from each sequence) that has identical successive differences. This is followed by two lines each containing the corresponding subsequences. If there is more than one answer, it suffices to print one.

Test Data:

You may assume that 1 ≤ N ≤ 300.


Here is the sample input and output corresponding to the example discussed above.

Sample Input

3 8 4 23 9 11 28  
2 3 22 26 8 16 12 

Sample Output

3 4 23 9
2 3 22 8

CPU Timelimit: 3 seconds
Memory limit: 64M
Grading style: ioi
Register Now