Indraneel's student has given him data from two sets of experiments 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 two 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:-----
The first line of the input will contain a single integer $N$ indicating the number of data points in each of Indraneel's student's data sets. This is followed by two lines, each containing $N$ integers.
-----Output:-----
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.
-----Constraints:-----
- $1 \leq N \leq 150$.
- $0 \leq$ Each data point $\leq 1000$
-----Sample Input-----
7
3 8 4 23 9 11 28  
2 3 22 26 8 16 12 
-----Sample Output-----
4
3 4 23 9
2 3 22 8
# cook your dish here
ans = []
mxlen = 0

def lcs(a,b,d,mxlen):
    L = [0]*(n+1)
    for i in range(n+1):
        L[i] = [0]*(n+1)
    #print("#",L,a,b)
    for i in range(1,n+1):
        for j in range(1,n+1):
            if a[i-1] == b[j-1]:
                L[i][j] = L[i-1][j-1] + 1
            else:
                L[i][j] = max(L[i-1][j],L[i][j-1])
    #print(L)
    if L[n][n] > mxlen:
        mxlen = L[n][n]
        i,j = n,n
        t = []
        while i>0 and j>0:
            if a[i-1] == b[j-1]:
                t.insert(0,a[i-1])
                i -= 1
                j -= 1
            elif L[i-1][j] > L[i][j-1]:
                i -= 1
            else:
                j -= 1
        #print(t)
        ans.append({d:t})

try:
    n = int(input())
    a = [int(w) for w in input().split()]
    b = [int(w) for w in input().split()]
    minb = min(b)
    b = [(i-minb-1) for i in b]
    for i in range(-1000,1001):
        bb = b.copy()
        bb = [(j+i) for j in bb]
        lcs(a,bb,i,mxlen)
    ans = sorted(ans, key=lambda i: len(list(i.values())[0]),reverse = True)
    t = ans[0]
    d = list(t.keys())[0]
    t = t[d]
    print(len(t))
    print(*t)
    t = [(i-d+minb+1) for i in t]
    print(*t)
except:
    pass
# cook your dish here
ans = []
mxlen = 0

def lcs(a,b,d,mxlen):
    L = [0]*(n+1)
    for i in range(n+1):
        L[i] = [0]*(n+1)
    #print("#",L,a,b)
    for i in range(1,n+1):
        for j in range(1,n+1):
            if a[i-1] == b[j-1]:
                L[i][j] = L[i-1][j-1] + 1
            else:
                L[i][j] = max(L[i-1][j],L[i][j-1])
    #print(L)
    if L[n][n] > mxlen:
        mxlen = L[n][n]
        i,j = n,n
        t = []
        while i>0 and j>0:
            if a[i-1] == b[j-1]:
                t.insert(0,a[i-1])
                i -= 1
                j -= 1
            elif L[i-1][j] > L[i][j-1]:
                i -= 1
            else:
                j -= 1
        #print(t)
        ans.append({d:t})

try:
    n = int(input())
    a = [int(w) for w in input().split()]
    b = [int(w) for w in input().split()]
    minb = min(b)
    b = [(i-minb-1) for i in b]
    for i in range(-1000,1001):
        bb = b.copy()
        bb = [(j+i) for j in bb]
        lcs(a,bb,i,mxlen)
    ans = sorted(ans, key=lambda i: len(list(i.values())[0]),reverse = True)
    t = ans[0]
    d = list(t.keys())[0]
    t = t[d]
    print(len(t))
    print(*t)
    t = [(i-d+minb+1) for i in t]
    print(*t)
except:
    pass