n = int(input())
a = list(map(int, input().split()))

count  = 0
i = 0
while i < n - 2:
    if a[i] < a[i + 1]:
        count += 1
        i+=1
        if a[i] > a[i + 1]:
            break

    elif a[i] == a[i + 1]:
        i += 1
        if a[i] <= a[i + 1]:
            count += 2
        else:
            i += 1

    elif a[i] > a[i + 1]:
        i += 1

count += 1
print(count)


n=int(input())
x=input().split()
y=[]
z=1
for i in range(n-1):
    if int(x[i+1])>=int(x[i]):
        if i==n-2:
            z=z+1
            y=y+[z]
        else:
            z=z+1
    else:
        y=y+[z]
        z=1
print(x,y,max(y))


n=int(input())
x=input().split()
y=[]
z=1
if n>=2:
    for i in range(1,n):
        if int(x[i])>=int(x[i-1]):
            if i==n-2:
                z=z+1
                y=y+[z]
            else:
                z=z+1
        else:
            y=y+[z]
            z=1
    print(max(y))
else:
    print('1')


n=int(input())
x=input().split()
y=[]
z=1
for i in range(n-1):
    if int(x[i+1])>=int(x[i]):
        if i==n-2:
            z=z+1
            y=y+[z]
        else:
            z=z+1
    else:
        y=y+[z]
        z=1
print(max(y))


n = int(input())
line = [int(x) for x in input().split()]
num = line[0]
length = [1]*n
for i in range(1,n):
    if line[i]>=num:
        length[i] = length[i-1]+1
    num = line[i]
length.sort()
print(length[-1])


n=int(input())
x=input().split()
y=[]
z=1
if n>=2:
    for i in range(n-1):
        if int(x[i+1])>=int(x[i]):
            if i==n-2:
                z=z+1
                y=y+[z]
            else:
                z=z+1
        else:
            y=y+[z]
            z=1
    y.sort()
    print(y[-1])
else:
    print('1')


n=int(input())
x=input().split()
y=[]
z=1
for i in range(n-1):
    if x[i+1]>=x[i]:
        z=z+1
    else:
        y=y+[z]
        z=1
if y==[]:
    print(z)
else:
    print(max(y))


n=int(input())
x=input().split()
y=[]
z=1
if n>=2:
    for i in range(n-1):
        if int(x[i+1])>=int(x[i]):
            if i==n-2:
                z=z+1
                y=y+[z]
            else:
                z=z+1
        else:
            y=y+[z]
            z=1
    print(max(y))
else:
    print('1')


n=int(input())
x=input().split()
y=[]
z=1
for i in range(n-1):
    if x[i+1]>=x[i]:
        if i==n-2:
            z=z+1
            y=y+[z]
        else:
            z=z+1
    else:
        y=y+[z]
        z=1
print(max(y))


n=int(input())
l=list(map(int,input().split()))
minnum=l[0]
L=[0,1]
for i in range(1,n):
    if l[i]>=minnum:
        num=L[i]+1
        L.append(num)
        minnum=l[i]
    else:
        minnum=l[i]
        num=1
        L.append(num)
L.sort()
print(L[-1])


a=int(input())
s=list(map(int,input().split()))
m=0
l=0
for i in range(a):
    l=1
    for j in range(i,a-1):
        if s[j]<=s[j+1]:
            l=l+1
        else:
            break
    if l>m:
        m=l
print(m)


n=int(input())
l=list(map(int,input().split()))
minmun=l[0]
L=[0,1]
for i in range(1,n):
    if l[i]>=minnum:
        num=L[i]+1
        L.append(num)
        minnum=l[i]
    else:
        minnum=l[i]
        num=1
        L.append(num)
L.sort()
print(L[-1])


n=int(input())
l=[int(x) for x in input().split()]
L=[]
k=1
for i in range(n-1):
  if i<(n-2):
    if l[i]<=l[i+1]:
      k=k+1
    else:
      L.append(k)
      k=1
  else:
    if l[i]<=l[i+1]:
      k=k+1
      L.append(k)
    else:
      L.append(k)
      L.append(1)
print(max(L))


n=int(input())
l=[int(x) for x in input().split()]
L=[1]
k=1
for i in range(n-1):
  if i<(n-2):
    if l[i]<=l[i+1]:
      k=k+1
    else:
      L.append(k)
      k=1
  else:
    if l[i]<=l[i+1]:
      k=k+1
      L.append(k)
    else:
      L.append(k)
      L.append(1)
print(max(L))


n=int(input())
l=list(map(int,input().split()))
minmun=l[0]
L=[1，]
for i in range(1,n):
    if l[i]>=minnum:
        num=L[i-1]+1
        L.append(num)
        minnum=l[i]
    else:
        minnum=l[i]
        num=1
        L.append(num)
L.sort()
print(L[-1])


n=int(input())
l=list(map(int,input().split()))
minmun=l[0]
L=[1]
for i in range(1,n):
    if l[i]>=minnum:
        num=L[i-1]+1
        L.append(num)
        minnum=l[i]
    else:
        minnum=l[i]
        num=1
        L.append(num)
L.sort()
print(L[-1])


n=int(input())
a=list(map(int,input().split()))

seq=list()
ctr=1

for i in range(1,n):
	if(a[i]>=a[i-1]):
		ctr+=1
	else:
		seq.append(ctr)
		ctr=1

print(max(seq))


n=int(input())
a=list(map(int,input().split()))

longSeq=0
i=0
while(i<n):
	ctr=1
	for j in range(i,n-1):
		if(a[j]<=a[j+1]):
			ctr+=1
		else:
			i=j
			break
	i+=1

	if(ctr>longSeq):
		longSeq=ctr

print(longSeq)


n=int(input())
a=list(map(int,input().split()))

longSeq=0

for i in range(1,n):
	k=i
	ctr=1
	while(k<n):
		if(a[k-1]<=a[k]):
			ctr+=1
	if(ctr>longSeq):
		longSeq=ctr
print(longSeq)


n=int(input())
a=list(map(int,input().split()))

longSeq=0

for i in range(n):
	ctr=1
	for j in range(i,n-1):
		if(a[j]<=a[j+1]):
			ctr+=1
		else:
			break
	if(ctr>longSeq):
		longSeq=ctr
print(longSeq)


n=int(input())
a=list(map(int,input().split()))

if(a.count(a[0])==n):
	print(n)

else:
	longSeq=0
	i=0
	while(i<n):
		ctr=1
		for j in range(i,n-1):
			if(a[j]<=a[j+1]):
				ctr+=1
			else:
				i=j
				break
		i+=1

		if(ctr>longSeq):
			longSeq=ctr

	print(longSeq)


n=int(input())
a=list(map(int,input().split()))

seq=list()
ctr=1

for i in range(1,n):
	if(a[i]>=a[i-1]):
		ctr+=1
	else:
		seq.append(ctr)
		ctr=1

if(len(seq)>0):
	print(max(seq))


n=int(input())
a=list(map(int,input().split()))

seq=list()
ctr=1

for i in range(1,n):
	if(a[i]>=a[i-1]):
		ctr+=1
	else:
		seq.append(ctr)
		ctr=1

if(ctr>1):
	seq.append(ctr)

if(len(seq)>0):
	print(max(seq))


n=int(input())
a=list(map(int,input().split()))

longSeq=0

for i in range(1,n):
	k=i
	ctr=1
	while(k<n):
		if(a[k-1]<=a[k]):
			ctr+=1
		k+=1
	if(ctr>longSeq):
		longSeq=ctr
print(longSeq)


n=int(input())
a=list(map(int,input().split()))

seq=list()
ctr=1

for i in range(1,n):
	if(a[i]>=a[i-1]):
		ctr+=1
	else:
		seq.append(ctr)
		ctr=1

if(ctr>1):
	seq.append(ctr)

if(len(seq)>0):
	print(max(seq))
else:
	print(1)


n=int(input())
a=list(map(int,input().split()))

longSeq=0
i=0
while(i<n-1):
	ctr=1
	for j in range(i,n-1):
		if(a[j]<=a[j+1]):
			ctr+=1
		else:
			i=j
			break
	i+=1

	if(ctr>longSeq):
		longSeq=ctr

print(longSeq)


n=int(input())
a=list(map(int,input().split()))

longSeq=0

for i in range(1,n):
	k=i
	ctr=0
	while(k<n):
		if(a[k-1]<=a[k]):
			ctr+=1
		k+=1
	if(ctr>longSeq):
		longSeq=ctr
print(longSeq)


a=int(input())
b=list(map(int,input().split()))
c=1
k=[]
for i in range(a-1):
    if(b[i]<=b[i+1]):
        c=c+1
        continue
    else:
        k.append(c)
        c=1
k.append(c)
print(max(k))


a=int(input())
b=list(map(int,input().split()))
c=0
k=[]
for i in range(a-1):
    if(b[i]<=b[i+1]):
        c=c+1
    else:
        k.append(c)
        c=0
if len(k)!=0:
    print(max(k))
else:
    print(c)


a=int(input())
b=list(map(int,input().split()))
c=1
k=[]
for i in range(a-1):
    if(b[i]<=b[i+1]):
        c=c+1
    else:
        k.append(c)
        c=1
if len(k)!=0:
    print(max(k))
else:
    print(c)


a=int(input())
b=list(map(int,input().split()))
c=1
k=[]
for i in range(a-1):
    if(b[i]<=b[i+1]):
        c=c+1
    else:
        k.append(c)
        c=1
print(max(k))


a=int(input())
b=list(map(int,input().split()))
c=0
for i in range(a):
    if(b[i]<=b[i+1]):
        c=c+1
    else:
        c=0
print(c)


a=int(input())
b=list(map(int,input().split()))
c=0
k=[]
for i in range(a):
    if(b[i]<=b[i+1]):
        c=c+1
    else:
        k.append(c)
        c=0
print(max(k))


a=int(input())
b=list(map(int,input().split()))
c=0
for i in range(a-1):
    if(b[i]<=b[i+1]):
        c=c+1
    else:
        c=0
print(c)


a=int(input())
b=list(map(int,input().split()))
c=0
k=[]
for i in range(a):
    if(b[i]<=b[i+1]):
        c=c+1
    else:
        k.append(c)
        c=0
if len(k)!=0:
    print(max(k))
else:
    print(c)


n = int(input())
arr = input().split()
for i in range(n):
    arr[i] = int(arr[i])

max = 0
count = 1

for i in range(n-1):
    if arr[i+1] >= arr[i]:
        count += 1
        # print(count)
        if count>max:max=count
    else:
        count = 1

print(max)


n = int(input())
arr = input().split()
# for i in range(n):
#     arr[i] = int(arr[i])

max = 0
count = 1

for i in range(n-1):
    if arr[i+1] >= arr[i]:
        count += 1
        # print(count)
        if count>max:max=count
    else:
        count = 1

print(max)


n = int(input())
arr = input().split()
for i in range(n):
    arr[i] = int(arr[i])

max = 0
count = 1

for i in range(n-1):
    if arr[i+1] >= arr[i]:
        count += 1
        # print(count)
        if count>max:max=count
    else:
        count = 1
else:
    max = 1
print(max)


n = int(input())
arr = input().split()
for i in range(n):
    arr[i] = int(arr[i])

max = 0
count = 0

for i in range(n-1):
    if arr[i+1] >= arr[i]:
        count += 1
        print(count)
        if count>max:max=count
    else:
        count = 0

print(max+1)int(max)


n = int(input())
arr = input().split()
for i in range(n):
    arr[i] = int(arr[i])

max = 1
count = 1

for i in range(n-1):
    if arr[i+1] >= arr[i]:
        count += 1
        # print(count)
        if count>max:max=count
    else:
        count = 1
print(max)


n = int(input())
arr = input().split()
for i in range(n):
    arr[i] = int(arr[i])

max = 0
count = 1

for i in range(n-1):
    if arr[i+1] >= arr[i]:
        count += 1
        if count>max:max=count
    else:
        count = 1

print(max)


n = int(input())
arr = input().split()
for i in range(n):
    arr[i] = int(arr[i])

max = 0
count = 1

for i in range(n-1):
    if arr[i+1] >= arr[i]:
        count += 1
        print(count)
        if count>max:max=count
    else:
        count = 1

print(max)


n=int(input())
a=[int(i) for i in input().split()]
jieguo=1
zuida=1
for i in range(n-1):
    if a[i+1]>=a[i]:
        jieguo+=1
        zuida=jieguo
    else:
        jieguo=1
        if jieguo>zuida:
            zuida=jieguo

print(zuida)


n=int(input())
a=[int(i) for i in input().split()]
jieguo=0
zuida=0
for i in range(n-1):
    if a[i+1]>=a[i]:
        jieguo+=1
    else:
        if jieguo>zuida:
            zuida=jieguo
            jieguo=0
print(zuida)


n=int(input())
a=[int(i) for i in input().split()]
l=[]
zheciduochang=1
for i in range(n-1):
    if a[i+1]>=a[i]:
        zheciduochang+=1
    else:
        l.append(zheciduochang)
        zheciduochang=1
if l!=[]:
    print(max(l))
else:
    print(zheciduochang)


n=int(input())
a=[int(i) for i in input().split()]
l=[]
zheciduochang=1
for i in range(n-1):
    if a[i+1]>=a[i]:
        zheciduochang+=1
    else:
        l.append(zheciduochang)
        zheciduochang=1
pring(max(zheciduochang))


n=int(input())
a=[int(i) for i in input().split()]
l=[]
zheciduochang=1
for i in range(n-1):
    if a[i+1]>=a[i]:
        zheciduochang+=1
    else:
        l.append(zheciduochang)
        zheciduochang=1
print(max(l))


n=int(input())
a=[int(i) for i in input().split()]
jieguo=1
zuida=1
for i in range(n-1):
    if a[i+1]>=a[i]:
        jieguo=jieguo+1
        if jieguo>zuida:
            zuida=jieguo

    else:

        if jieguo>zuida:
            zuida=jieguo
        jieguo=1
print(zuida)


n=int(input())
a=[int(i) for i in input().split()]
jieguo=1
for i in range(n-1):
    if a[i+1]>=a[i]:
        jieguo+=1
    else:
        print(jieguo)
        exit()
print(jieguo)


input()
l = list(map(int, input().split()))
c = r = 1
for i in range(0, len(l)-1):
    if l[i+1] < l[i]:
        c += 1
        r = max(r, c)
    else:
        c = 1
print(r)


n = int(input())
l = list(map(int, input().split()))
x = l[0]
c = r = 1
for i in range(1, n):
    y = l[i]
    if y >= x:
        c += 1
        r = max(r, c)
    else:
        c = 1
    x = y
print(r)


input()
l = list(map(int, input().split()))
c = r = 1
for i in range(0, len(l)-1):
    y = l[i]
    if l[i+1] >= l[i]:
        c += 1
        r = max(r, c)
    else:
        c = 1
print(r)


n = int(input())
l = list(map(int, input().split()))
x = l[0]
c = r = 1
for i in range(1, n):
    y = l[i]
    if y >= x:
        c += 1
        r = max(r, c)
    else:
        c = 1
print(r)


input()
l = list(map(int, input().split()))
c = r = 1
for i in range(0, len(l) - 1):
    x = l[i + 1] < l[i]
    c = (c + 1) * (1 - x) + x
    r = max(r, c)
print(r)


input()
l = list(map(int, input().split()))
c = r = 1
for i in range(0, len(l)-1):
    if l[i+1] < l[i]:
        c = 1
    else:
        c += 1
        r = max(r, c)
print(r)


input()
l = list(map(int, input().split()))
c = r = 1
for i in range(0, len(l)-1):
    x=l[i+1]<l[i]
    c = (c+1)*(1-x)+x
    r = max(r, c)
print(r)


input()
l = list(map(int, input().split()))
c = r = 1
for i in range(0, len(l)-1):
    y = l[i]
    if l[i+1] < l[i]:
        c = 1
    else:
        c += 1
        r = max(r, c)
print(r)


input()
l=list(map(int,input().split()))
c=r=1
for i in range(0,len(l)-1):
    x=l[i + 1]<l[i]
    c=(c+1)*(1-x)+x
    r=max(r,c)
print(r)


n = int(input())
number = input().split()
x = 1
lis =[]
for i in range(len(number)-1):
              if not number[i] > number[i+1]:
                            x += 1
                            lis.append(str(x))
              if number[i] > number[i+1]:
                            x = 1
print(max(lis))


n = int(input())
number = input().split()
x = 1
lis =[]
for i in range(len(number)-1):
              if not number[i] > number[i+1]:
                            x += 1
                            lis.append(str(x))
              if number[i] > number[i+1]:
                            x = 1
answer = [int(i) for i in lis]
print(max(answer))


n = int(input())
number = int(input().split())
x = 1
lis =[1]
for i in range(len(number)-1):
              if not number[i] > number[i+1]:
                            x += 1
                            lis.append(str(x))
              if number[i] > number[i+1]:
                            x = 1
                            lis.append(str(x))
answer = int(lis)
print(max(answer))


n = int(input())
number = input().split()
numbers =[int(i) for i in number]
x = 1
lis =[1]
for i in range(len(numbers)-1):
              if not numbers[i] > numbers[i+1]:
                            x += 1
                            lis.append(str(x))
              if numbers[i] > numbers[i+1]:
                            x = 1
                            lis.append(str(x))
answer = [int(i) for i in lis]
print(max(answer))


n = int(input())
number = input().split()
x = 0
lis =[]
for i in range(len(number)-1):
              if not number[i] > number[i+1]:
                            x += 1
                            lis.append(str(x))
                            while number[i] > number[i+1]:
                                          x = 0
if not number[-2] > number[-1]:
              x += 1
              lis.append(str(x))
print(max(lis))


n = int(input())
number = input().split()
x = 0
lis =[]
print(len(number))
for i in range(len(number)-1):
              if not number[i] > number[i+1]:
                            x += 1
                            lis.append(str(x))
                            while number[i] > number[i+1]:
                                          x = 0
if not number[-2] > number[-1]:
              x += 1
              lis.append(str(x))
print(lis)
print(max(lis))


n = int(input())
number = input().split()
numbers =[int(i) for i in number]
x = 1
lis =[]
for i in range(len(numbers)-1):
              if not numbers[i] > numbers[i+1]:
                            x += 1
                            lis.append(str(x))
              if numbers[i] > numbers[i+1]:
                            x = 1
                            lis.append(str(x))
answer = [int(i) for i in lis]
print(max(answer))


n=int(input())
x=[int(i) for i in input().split()]
t=1
ans=0

for i in range(n-1):
    if x[i]<=x[i+1]:
        t+=1
        ans=max(ans,t)
    else:
        t=1

if n!=1:
    print(ans)
else:
    print('1')


n=int(input())
x=[int(i) for i in input().split()]
t=0
ans=0

for i in range(n-1):
    if x[i]<=x[i+1]:
        if t==0:
            t=1
        t+=1
        ans=max(ans,t)
    else:
        t=0

if n!=1:
    print(ans)
else:
    print('1')


n=int(input())
x=[int(i) for i in input().split()]
t=1
ans=0

for i in range(n-1):
    if x[i]<=x[i+1]:
        t+=1
        ans=max(ans,t)
    else:
        t=1

if n!=1:
    print(ans)
else:
    print('0')


n=int(input())
x=[int(i) for i in input().split()]
t=1
ans=1

for i in range(n-1):
    if x[i]<=x[i+1]:
        t+=1
        ans=max(ans,t)
    else:
        t=1

print(ans)


n=int(input())
x=[int(i) for i in input().split()]
t=1
ans=1

for i in range(n-1):
    if x[i]<=x[i+1]:
        ans=max(ans,t)
    else:
        t=1

print(ans)


n=int(input())
x=[int(i) for i in input().split()]
t=1
ans=0

for i in range(n-1):
    if x[i]<=x[i+1]:
        t+=1
        ans=max(ans,t)
    else:
        t=1

print(ans)


n=int(input())
x=[int(i) for i in input().split()]
t=1
ans=0

for i in range(n-1):
    if x[i]<=x[i+1]:
        t+=1
        ans=max(ans,t)
    else:
        t=1

if ans!=1:
    print(ans)
else:
    print('0')


a=int(input())
n=0
p=0
b=[int(x) for x in input().split()]
if a!=1:
    for i in range(a):
        if i>=1 and i!=a-1:
           if b[i]>=b[i-1]:
              n+=1
           else:
              if n>p:
                 p=n
                 n=0
              else:
                  n=0
        elif i==a-1:
             if b[i]>=b[i-1]:
                n+=1
             if n>p:
                p=n
    if p==0:
       print('0')
    else:
       print(p+1)
if a==1:
    print('1')


a=int(input())
n=0
p=0
b=[int(x) for x in input().split()]
for i in range(a):
     if i>=1:
         if b[i]>=b[i-1]:
             n+=1
         elif n>p:
             p=n
         else:
             pass
if p==0:
    print(p)
else:
    print(p+1)


a=int(input())
n=0
p=0
b=[int(x) for x in input().split()]
for i in range(a):
     if i>=1:
         if b[i]>b[i-1]:
             n+=1
         elif n>p:
             p=n
         else:
             pass
if p==0:
    print(p)
else:
    print(p+1)


a=int(input())
n=0
p=0
b=[int(x) for x in input().split()]
for i in range(a):
     if i>=1 and i!=a-1:
         if b[i]>=b[i-1]:
             n+=1
         else:
             if n>p:
                p=n
                n=0
             else:
                 n=0
     elif i==a-1:
          if b[i]>=b[i-1]:
             n+=1
          if n>p:
              p=n
if p==0:
    print('0')
else:
    print(p+1)


a=int(input())
n=0
p=0
b=[int(x) for x in input().split()]
for i in range(a):
     if i>=1:
         if b[i]>=b[i-1]:
             n+=1
         elif n>p:
             p=n
             n=0
         else:
             n=0
if p==0:
    print(p)
else:
    print(p+1)


a=int(input())
n=0
p=0
b=[int(x) for x in input().split()]
if a!=1:
    for i in range(a):
        if i>=1 and i!=a-1:
           if b[i]>=b[i-1]:
              n+=1
           else:
              if n>p:
                 p=n
                 n=0
              else:
                  n=0
        elif i==a-1:
             if b[i]>=b[i-1]:
                n+=1
             if n>p:
                p=n
    if p==0:
       print('1')
    else:
       print(p+1)
if a==1:
    print('1')


a=int(input())
n=0
p=0
b=[int(x) for x in input().split()]
for i in range(a):
     if i>=1:
         if b[i]>=b[i-1]:
             n+=1
         else:
             if n>p:
                p=n
                n=0
             else:
                 n=0
if p==0 and n==0:
    print('0')
elif p==0 and n!=0:
    p=n
    print(p+1)
else:
    print(p+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l)):
    try:
        if l[i+1] >= l[i]:
            counter += 1
            ans.append(counter)
        else:
            counter = 0
    except:
        break
print(max(ans)+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l) - 1):
    if l[i+1] >= l[i]:
        counter += 1
        ans.append(counter)
    else:
        counter = 0
if len(l) == 1:
    print(1)
elif len(ans) == 0:
    print(0)
else:
    print(max(ans)+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l) - 1):
    if l[i+1] >= l[i]:
        counter += 1
        ans.append(counter)
    else:
        counter = 0
if len(l) == 1:
    print(1)
else:
    print(max(ans)+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l) - 1):
    if l[i+1] >= l[i]:
        counter += 1
        ans.append(counter)
    else:
        counter = 0

if len(l) == 1:
    print(1)
else:
    print(max(ans)+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l)):
    try:
        if l[i+1] >= l[i]:
            counter += 1
            ans.append(counter)
        else:
            counter = 0
    except:
        continue
print(max(ans)+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l) - 1):
    if l[i+1] >= l[i]:
        counter += 1
        ans.append(counter)
    else:
        counter = 0
if len(l) == 1 or len(ans) == 0:
    print(1)
else:
    print(max(ans)+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l)):
    try:
        if l[i+1] >= l[i]:
            counter += 1
            ans.append(counter)
        else:
            counter = 0
    except:
        continue
if len(l) == 1:
    print(1)
else:
    print(max(ans)+1)


n = int(input())
l = list(map(int, input().split()))
counter = 0
ans = []
for i in range(len(l)):
    try:
        if l[i+1] >= l[i]:
            counter += 1
            ans.append(counter)
        else:
            counter = 0
    except:
        break
if len(l) == 1:
    print(1)
else:
    print(max(ans)+1)


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(len(profits)):
    count=1
    maximum = profits[i]
    for j in range(i,len(profits)):
        if(j!=len(profits)-1):
            if(profits[i]<=profits[j] and profits[j]>=maximum and profits[j] <= profits[j+1]):
                maximum=profits[j]
                count+=1
            else:
                break
        else:
            if(profits[j]>=maximum):
                maximum=profits[j]
    counts.append(count)
print(counts)
print(max(counts))


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(len(profits)):
    count=0
    maximum = profits[i]
    for j in range(i,len(profits)):
        if(profits[i]<=profits[j] and profits[j]>=maximum):
            maximum=profits[j]
            count+=1
    counts.append(count)
print(max(counts)-1)


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(len(profits)):
    count=0
    maximum = profits[i]
    for j in range(i,len(profits)):
        if(profits[i]<=profits[j] and profits[j]>=maximum):
            maximum=profits[j]
            count+=1
    counts.append(count)
print(max(counts))


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(len(profits)):
    count=1
    maximum = profits[i]
    for j in range(i,len(profits)):
        if(j!=len(profits)-1):
            if(profits[i]<=profits[j] and profits[j]>=maximum and profits[j] < profits[j+1]):
                maximum=profits[j]
                count+=1
        else:
            if(profits[j]>=maximum):
                maximum=profits[j]
    counts.append(count)
print(max(counts))


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(len(profits)):
    count=1
    maximum = profits[i]
    for j in range(i,len(profits)):
        if(j!=len(profits)-1):
            if(profits[i]<=profits[j] and profits[j]>=maximum and profits[j] <= profits[j+1]):
                maximum=profits[j]
                count+=1
            else:
                break
        else:
            if(profits[j]>=maximum):
                maximum=profits[j]
    counts.append(count)
print(max(counts))


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(n):
    count=1
    maximum = profits[i]
    for j in range(i,n):
        if(j!=n-1):
            if(profits[i]<=profits[j] and profits[j]>=maximum and profits[j] <= profits[j+1]):
                maximum=profits[j]
                count+=1
            else:
                break
        else:
            if(profits[j]>=maximum):
                maximum=profits[j]
    counts.append(count)
print(max(counts))


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(len(profits)):
    count=1
    maximum = profits[i]
    for j in range(i,len(profits)):
        if(j!=len(profits)-1):
            if(profits[i]<=profits[j] and profits[j]>=maximum and profits[j] <= profits[j+1]):
                maximum=profits[j]
                count+=1
        else:
            if(profits[j]>=maximum):
                maximum=profits[j]
    counts.append(count)
print(max(counts))


n = int(input())
maxCount=1
count=1
profits = list(map(int,input().split(" ")))[:n]
for i in range(n):
    if(i>0):
        if(profits[i]>=profits[i-1]):
            count+=1
            maxCount=max(maxCount,count)
        else:
            count=1
print(maxCount)


n = int(input())
counts=[]
profits = list(map(int,input().split(" ")))[:n]
for i in range(n):
    count=1
    maximum = profits[i]
    for j in range(i,n):
        if(j!=n-1):
            if(profits[j]>=maximum and profits[j] <= profits[j+1]):
                maximum=profits[j]
                count+=1
            else:
                break
        else:
            if(profits[j]>=maximum):
                maximum=profits[j]
    counts.append(count)
print(max(counts))


#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int n,m,rd[505][505],dp[505][505];
int s1[505],s2[505];
void DP()
{
	int mac=0,ans=0,I,J,lu[505],mx;
	for(int i=1;i<=n;i++)
	{
		mx=0;
		for(int j=1;j<=m;j++)
		{
			int tem=dp[i][j]=dp[i-1][j];
			if(mx<tem&&s1[i-1]>s2[j-1])
			{
				mx=tem;
				mac=j;
			}
			if(s1[i-1]==s2[j-1])
			{
				dp[i][j]=mx+1;
				rd[i][j]=mac;
			}
			if(ans<dp[i][j])
			{
				ans=dp[i][j];
				I=i,J=j;
			}
		}
	}
	printf("%d\n",ans);
	int len=ans;
	if(ans>0)
		lu[ans--]=J-1;
	while(ans&&I&&J)
	{
		if(rd[I][J]>0)
		{
			lu[ans--]=rd[I][J]-1;
			J=rd[I][J];
		}
		I--;
	}
	for(int i=1;i<=len;i++)
	{
		printf("%d ",s2[lu[i]]);
	}
	printf("\n");
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&s1[i]);
	scanf("%d",&m);
	for(int i=0;i<m;i++)
		scanf("%d",&s2[i]);
	DP();
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N];
int ans[N];
int main(){
    while(scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));
        memset(f, 0, sizeof(f));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++){
            scanf("%d", &b[i]);
        }
        int mid = 0, mv = 0;
        for(int i = 1; i <= n; i++){
            pre[i] = i;
        }
        for(int i = 1; i <= n; i++){
            int k = 0;
            for(int j = 1; j <= m; j++){
                f[i][j] = f[i - 1][j];
                if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
                if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                    f[i][j] = f[i][k] + 1;
                    pre[j] = k;
                    if(f[i][j] > mv){
                        mv = f[i][j];
                        mid = j;
                    }
                }
            }
        }
        int x = mid;
        int ptr = 0;
        while(pre[x] != x){
            ans[ptr ++] = b[x - 1];
            if(ptr == mv)break;
            x = pre[x];
        }
        printf("%d\n", mv);
        for(int i = mv - 1; i >= 0; i--)
            printf("%d ", ans[i]);
        printf("\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N];
int ans[N];
int main(){
    while(scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));
        memset(f, 0, sizeof(f));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++){
            scanf("%d", &b[i]);
        }
        int mid = 0, mv = 0;
        for(int i = 1; i <= n; i++){
            pre[i] = i;
        }
        for(int i = 1; i <= n; i++){
            int k = 0;
            for(int j = 1; j <= m; j++){
                f[i][j] = f[i - 1][j];
                if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
                if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                    f[i][j] = f[i][k] + 1;
                    pre[j] = k;
                    if(f[i][j] > mv){
                        mv = f[i][j];
                        mid = j;
                    }
                }
            }
        }
        int x = mid;
        int ptr = 0;
        while(pre[x] != x){
            ans[ptr ++] = b[x - 1];
            x = pre[x];
        }
        printf("%d\n", mv);
        for(int i = mv - 1; i >= 0; i--){
            if(i != mv - 1) printf(" ");
            printf("%d", ans[i]);
        }
        printf("\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N][N];
int ans[N];
int main(){
    while(scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));
        memset(f, 0, sizeof(f));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++){
            scanf("%d", &b[i]);
        }
        int mid = 0, mv = 0;
        int nid = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                pre[i][j] = j;
            }
        }
        for(int i = 1; i <= n; i++){
            int k = 0;
            for(int j = 1; j <= m; j++){
                f[i][j] = f[i - 1][j];
                pre[i][j] = pre[i - 1][j];
                if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
                if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                    f[i][j] = f[i][k] + 1;
                    pre[i][j] = k;
                    if(f[i][j] > mv){
                        mv = f[i][j];
                        mid = j;
                        nid = i;
                    }
                }
            }
        }
        int x = mid;
        int y = nid;
        int ptr = 1;
        while(pre[y][x] != x){
            ans[ptr ++] = b[x - 1];
            x = pre[y][x];
        }
        printf("%d\n", mv);
        for(int i = mv; i > 0; i--){
            printf("%d ", ans[i]);
        }
        printf("\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N][N];
int ans[N];
int main(){
    while(scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));
        memset(f, 0, sizeof(f));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++){
            scanf("%d", &b[i]);
        }
        int mid = 0, mv = 0;
        int nid = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                pre[i][j] = j;
            }
        }
        for(int i = 1; i <= n; i++){
            int k = 0;
            for(int j = 1; j <= m; j++){
                f[i][j] = f[i - 1][j];
                pre[i][j] = pre[i - 1][j];
                if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
                if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                    f[i][j] = f[i][k] + 1;
                    pre[i][j] = k;
                    if(f[i][j] > mv){
                        mv = f[i][j];
                        mid = j;
                        nid = i;
                    }
                }
            }
        }
        int x = mid;
        int y = nid;
        int ptr = 1;
        while(pre[y][x] != x){
            ans[ptr ++] = b[x - 1];
            if(ans[ptr - 1] == ans[ptr - 2])ptr--;
            if(ptr > mv)break;
            x = pre[y][x];
        }
        printf("%d\n", mv);
        for(int i = mv; i > 0; i--){
            printf("%d ", ans[i]);
        }
        printf("\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N][N][2];
int ans[N];
int main(){
    while(scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));
        memset(f, 0, sizeof(f));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++){
            scanf("%d", &b[i]);
        }
        int mid = 0, mv = 0;
        int nid = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                pre[i][j][0] = i;
                pre[i][j][1] = j;
            }
        }
        for(int i = 1; i <= n; i++){
            int k = 0;
            for(int j = 1; j <= m; j++){
                f[i][j] = f[i - 1][j];
                pre[i][j][0] = i - 1;
                pre[i][j][1] = j;
                if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
                if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                    f[i][j] = f[i][k] + 1;
                    pre[i][j][1] = k;
                    pre[i][j][0] = i;
                    if(f[i][j] > mv){
                        mv = f[i][j];
                        mid = j;
                        nid = i;
                    }
                }
            }
        }
        int x = mid;
        int y = nid;
        int ptr = 1;
        while(pre[y][x][0] != y || pre[y][x][1] != x){
            ans[ptr ++] = b[x - 1];
            if(ans[ptr - 1] == ans[ptr - 2])ptr--;
            x = pre[y][x][1];
            y = pre[y][x][0];
        }
        printf("%d\n", mv);
        for(int i = mv; i > 0; i--){
            if(i != mv) printf(" ");
            printf("%d", ans[i]);
        }
        printf("\n");
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N][N];
int ans[N];
int main(){
    while(scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));
        memset(f, 0, sizeof(f));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++){
            scanf("%d", &b[i]);
        }
        int mid = 0, mv = 0;
        int nid = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                pre[i][j] = j;
            }
        }
        for(int i = 1; i <= n; i++){
            int k = 0;
            for(int j = 1; j <= m; j++){
                f[i][j] = f[i - 1][j];
                pre[i][j] = pre[i - 1][j];
                if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
                if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                    f[i][j] = f[i][k] + 1;
                    pre[i][j] = k;
                    if(f[i][j] > mv){
                        mv = f[i][j];
                        mid = j;
                        nid = i;
                    }
                }
            }
        }
        int x = mid;
        int y = nid;
        int ptr = 1;
        while(pre[y][x] != x){
            ans[ptr ++] = b[x - 1];
            if(ptr > mv)break;
            x = pre[y][x];
        }
        printf("%d\n", mv);
        for(int i = mv; i > 0; i--){
            printf("%d ", ans[i]);
        }
        printf("\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N][N][2];
int ans[N];
int main(){
    scanf("%d", &n);
    memset(ans, 0, sizeof(ans));
    memset(f, 0, sizeof(f));
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    scanf("%d", &m);
    for(int i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }
    int mid = 0, mv = 0;
    int nid = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            pre[i][j][0] = i;
            pre[i][j][1] = j;
        }
    }
    for(int i = 1; i <= n; i++){
        int k = 0;
        for(int j = 1; j <= m; j++){
            f[i][j] = f[i - 1][j];
            pre[i][j][0] = i - 1;
            pre[i][j][1] = j;
            if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
            if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                f[i][j] = f[i][k] + 1;
                pre[i][j][1] = k;
                pre[i][j][0] = i;
                if(f[i][j] > mv){
                    mv = f[i][j];
                    mid = j;
                    nid = i;
                }
            }
        }
    }
    int x = mid;
    int y = nid;
    int ptr = 1;
    while(pre[y][x][0] != y || pre[y][x][1] != x){
        ans[ptr ++] = b[x - 1];
        if(ans[ptr - 1] == ans[ptr - 2])ptr--;
        x = pre[y][x][1];
        y = pre[y][x][0];
    }
    printf("%d\n", mv);
    for(int i = mv; i > 0; i--){
        if(i != mv) printf(" ");
        printf("%d", ans[i]);
    }
    printf("\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N][N][2];
int ans[N];
int main(){
    scanf("%d", &n);
    memset(ans, 0, sizeof(ans));
    memset(f, 0, sizeof(f));
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    scanf("%d", &m);
    for(int i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }
    int mid = 0, mv = 0;
    int nid = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            pre[i][j][0] = i;
            pre[i][j][1] = j;
        }
    }
    for(int i = 1; i <= n; i++){
        int k = 0;
        for(int j = 1; j <= m; j++){
            f[i][j] = f[i - 1][j];
            pre[i][j][0] = i - 1;
            pre[i][j][1] = j;
            if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
            if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                f[i][j] = f[i][k] + 1;
                pre[i][j][1] = k;
                pre[i][j][0] = i;
                if(f[i][j] > mv){
                    mv = f[i][j];
                    mid = j;
                    nid = i;
                }
            }
        }
    }
    int x = mid;
    int y = nid;
    int ptr = 0;
    while(pre[y][x][0] != y || pre[y][x][1] != x){
        ans[ptr ++] = b[x - 1];
        if(ptr == mv)break;
        x = pre[y][x][1];
        y = pre[y][x][0];
    }
    printf("%d\n", mv);
    for(int i = mv - 1; i >= 0; i--){
        if(i != mv - 1) printf(" ");
        printf("%d", ans[i]);
    }
    printf("\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define INF 1000000007
#define N 505
int n, m;
int a[N], b[N];
int f[N][N];
int pre[N][N];
int ans[N];
int main(){
    while(scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));
        memset(f, 0, sizeof(f));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i++){
            scanf("%d", &b[i]);
        }
        int mid = 0, mv = 0;
        int nid = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                pre[i][j] = j;
            }
        }
        for(int i = 1; i <= n; i++){
            int k = 0;
            for(int j = 1; j <= m; j++){
                f[i][j] = f[i - 1][j];
                pre[i][j] = pre[i - 1][j];
                if(a[i - 1] > b[j - 1] && f[i][k] < f[i][j]) k = j;
                if(a[i - 1] == b[j - 1] && f[i][k] + 1 > f[i][j]){
                    f[i][j] = f[i][k] + 1;
                    pre[i][j] = k;
                    if(f[i][j] > mv){
                        mv = f[i][j];
                        mid = j;
                        nid = i;
                    }
                }
            }
        }
        int x = mid;
        int y = nid;
        int ptr = 1;
        while(pre[y][x] != x){
            ans[ptr ++] = b[x - 1];
            x = pre[y][x];
        }
        printf("%d\n", mv);
        for(int i = ptr - 1; i > 0; i--){
            printf("%d ", ans[i]);
        }
        printf("\n");
    }
    return 0;
}


// Only_love97

using namespace std;
#include<bits/stdc++.h>

#define BG begin()
#define ED end()
#define st first
#define nd second
#define PB push_back
#define PF push_front
#define FOR(i,a,b) for (int i=(a),_b=(b);i<_b;i++)
#define FORE(i,a,b) for (int i=(a),_b=(b);i<=_b;i++)
#define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;i--)
#define ri(n)({\
    int neg=0;\
    n=0;\
    char ch;\
    for(ch=getchar(); ch<'0' || ch>'9'; ch=getchar()) if (ch=='-') neg=1-neg;\
    n=ch-48;\
    for(ch=getchar(); ch>='0' && ch<='9'; ch=getchar()) n=(n<<3)+(n<<1)+ch-48;\
    if (neg) n=-n;\
})

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> II;
const ll INF=1000000000+7;
const double esp=1e-13;
const double pi=3.141592653589;

ll mul(ll x, ll y,ll m)
{
    ll sum=0;
    while (y)
    {
        if (y%2) sum=(sum+x)%m;
        x=x*2%m;
        y/=2;
    }
    return sum;
}

ll power(ll a, ll n, ll m)
{
    ll tmp,c;
    tmp=a%m;
    c=a%m;
    n--;
    while (n)
    {
        if (n%2) tmp=tmp*c%m;
        c=c*c%m;
        n/=2;
    }
    return tmp;
}

ll inv(ll x)
{
    ll y,tmp;
    y=INF-2;
    tmp=1;
    while (y)
    {
        if (y%2) tmp=tmp*x%INF;
        x=x*x%INF;
        y/=2;
    }
    return tmp;
}

int bit(ll x, int y)
{
    return (x>> (y-1)&1);
}

int n,m,a[500+10],b[500+10],ans,f[500+10],f2[500+10],res[500+10],ma,mat,dem,vt,vt2;

int main()
{
 //   freopen("codeforces.inp", "r", stdin);
 //   freopen("codeforces.out", "w", stdout);
    cin >> n;
    FORE(i,1,n) cin >> a[i];
    cin >> m;
    FORE(i,1,m) cin >> b[i];

    ans=0;
    FORE(i,1,n)
    {
        ma=0;
        FORE(j,1,m)
        {
            mat=ma;
            if (b[j]<a[i]) ma=max(ma,f[j]);
            if (a[i]==b[j]) f[j]=max(f[j],mat+1);
            if (ans<f[j])
            {
                ans=f[j];
                FORE(j,1,m) f2[j]=f[j];
            }
        }
    }
    cout << ans << "\n";
    if (ans)
    {
        vt=1;
        FORE(i,1,m)
        if (f2[i]>f2[vt]) vt=i;
        dem=1;
        res[1]=b[vt];
        vt2=vt;
        FORD(i,vt2-1,1)
        if (b[i]<b[vt] && f2[i]+1==f2[vt])
        {
            vt=i;
            res[++dem]=b[i];
        }
        FORD(i,dem,1) cout << res[i] << " ";
    }
}


// Only_love97

using namespace std;
#include<bits/stdc++.h>

#define BG begin()
#define ED end()
#define st first
#define nd second
#define PB push_back
#define PF push_front
#define FOR(i,a,b) for (int i=(a),_b=(b);i<_b;i++)
#define FORE(i,a,b) for (int i=(a),_b=(b);i<=_b;i++)
#define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;i--)
#define ri(n)({\
    int neg=0;\
    n=0;\
    char ch;\
    for(ch=getchar(); ch<'0' || ch>'9'; ch=getchar()) if (ch=='-') neg=1-neg;\
    n=ch-48;\
    for(ch=getchar(); ch>='0' && ch<='9'; ch=getchar()) n=(n<<3)+(n<<1)+ch-48;\
    if (neg) n=-n;\
})

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> II;
const ll INF=1000000000+7;
const double esp=1e-13;
const double pi=3.141592653589;

ll mul(ll x, ll y,ll m)
{
    ll sum=0;
    while (y)
    {
        if (y%2) sum=(sum+x)%m;
        x=x*2%m;
        y/=2;
    }
    return sum;
}

ll power(ll a, ll n, ll m)
{
    ll tmp,c;
    tmp=a%m;
    c=a%m;
    n--;
    while (n)
    {
        if (n%2) tmp=tmp*c%m;
        c=c*c%m;
        n/=2;
    }
    return tmp;
}

ll inv(ll x)
{
    ll y,tmp;
    y=INF-2;
    tmp=1;
    while (y)
    {
        if (y%2) tmp=tmp*x%INF;
        x=x*x%INF;
        y/=2;
    }
    return tmp;
}

int bit(ll x, int y)
{
    return (x>> (y-1)&1);
}

int n,m,a[500+10],b[500+10],ans,f[500+10],f2[500+10],res[500+10],ma,mat,dem,vt,vt2;

int main()
{
 //   freopen("codeforces.inp", "r", stdin);
 //   freopen("codeforces.out", "w", stdout);
    cin >> n;
    FORE(i,1,n) cin >> a[i];
    cin >> m;
    FORE(i,1,m) cin >> b[i];

    ans=0;
    FORE(i,1,n)
    {
        ma=0;
        FORE(j,1,m)
        {
            mat=ma;
            if (b[j]<a[i]) ma=max(ma,f[j]);
            if (a[i]==b[j]) f[j]=max(f[j],mat+1);
            if (ans<f[j])
            {
                ans=f[j];
                FORE(j,1,m) f2[j]=f[j];
            }
        }
    }
    cout << ans << "\n";
    vt=1;
    FORE(i,1,m)
    if (f[i]>f[vt]) vt=i;
    dem=1;
    res[1]=b[vt];
    vt2=vt;
    FORD(i,vt2-1,1)
    if (b[i]<b[vt] && f2[i]+1==f2[vt])
    {
        vt=i;
        res[++dem]=b[i];
    }
    FORD(i,dem,1) cout << res[i] << " ";
}


// Only_love97

using namespace std;
#include<bits/stdc++.h>

#define BG begin()
#define ED end()
#define st first
#define nd second
#define PB push_back
#define PF push_front
#define FOR(i,a,b) for (int i=(a),_b=(b);i<_b;i++)
#define FORE(i,a,b) for (int i=(a),_b=(b);i<=_b;i++)
#define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;i--)
#define ri(n)({\
    int neg=0;\
    n=0;\
    char ch;\
    for(ch=getchar(); ch<'0' || ch>'9'; ch=getchar()) if (ch=='-') neg=1-neg;\
    n=ch-48;\
    for(ch=getchar(); ch>='0' && ch<='9'; ch=getchar()) n=(n<<3)+(n<<1)+ch-48;\
    if (neg) n=-n;\
})

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> II;
const ll INF=1000000000+7;
const double esp=1e-13;
const double pi=3.141592653589;

ll mul(ll x, ll y,ll m)
{
    ll sum=0;
    while (y)
    {
        if (y%2) sum=(sum+x)%m;
        x=x*2%m;
        y/=2;
    }
    return sum;
}

ll power(ll a, ll n, ll m)
{
    ll tmp,c;
    tmp=a%m;
    c=a%m;
    n--;
    while (n)
    {
        if (n%2) tmp=tmp*c%m;
        c=c*c%m;
        n/=2;
    }
    return tmp;
}

ll inv(ll x)
{
    ll y,tmp;
    y=INF-2;
    tmp=1;
    while (y)
    {
        if (y%2) tmp=tmp*x%INF;
        x=x*x%INF;
        y/=2;
    }
    return tmp;
}

int bit(ll x, int y)
{
    return (x>> (y-1)&1);
}

int n,m,a[500+10],b[500+10],ans,f[500+10],f2[500+10],res[500+10],ma,mat,dem,vt,vt2;

int main()
{
 //   freopen("codeforces.inp", "r", stdin);
 //   freopen("codeforces.out", "w", stdout);
    cin >> n;
    FORE(i,1,n) cin >> a[i];
    cin >> m;
    FORE(i,1,m) cin >> b[i];

    ans=0;
    FORE(i,1,n)
    {
        ma=0;
        FORE(j,1,m)
        {
            mat=ma;
            if (b[j]<a[i]) ma=max(ma,f[j]);
            if (a[i]==b[j]) f[j]=max(f[j],mat+1);
            if (ans<f[j])
            {
                ans=f[j];
                FORE(j,1,m) f2[j]=f[j];
            }
        }
    }
    cout << ans << "\n";
    if (ans)
    {
        vt=1;
        FORE(i,1,m)
        if (f2[i]>f2[vt]) vt=i;
        dem=1;
        res[1]=b[vt];
        vt2=vt;
        FORD(i,vt2-1,1)
        if (b[i]<b[vt] && f2[i]+1==f2[vt] && f2[i])
        {
            vt=i;
            res[++dem]=b[i];
        }
        FORD(i,dem,1) cout << res[i] << " ";
    }
}


// Only_love97

using namespace std;
#include<bits/stdc++.h>

#define BG begin()
#define ED end()
#define st first
#define nd second
#define PB push_back
#define PF push_front
#define FOR(i,a,b) for (int i=(a),_b=(b);i<_b;i++)
#define FORE(i,a,b) for (int i=(a),_b=(b);i<=_b;i++)
#define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;i--)
#define ri(n)({\
    int neg=0;\
    n=0;\
    char ch;\
    for(ch=getchar(); ch<'0' || ch>'9'; ch=getchar()) if (ch=='-') neg=1-neg;\
    n=ch-48;\
    for(ch=getchar(); ch>='0' && ch<='9'; ch=getchar()) n=(n<<3)+(n<<1)+ch-48;\
    if (neg) n=-n;\
})

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> II;
const ll INF=1000000000+7;
const double esp=1e-13;
const double pi=3.141592653589;

ll mul(ll x, ll y,ll m)
{
    ll sum=0;
    while (y)
    {
        if (y%2) sum=(sum+x)%m;
        x=x*2%m;
        y/=2;
    }
    return sum;
}

ll power(ll a, ll n, ll m)
{
    ll tmp,c;
    tmp=a%m;
    c=a%m;
    n--;
    while (n)
    {
        if (n%2) tmp=tmp*c%m;
        c=c*c%m;
        n/=2;
    }
    return tmp;
}

ll inv(ll x)
{
    ll y,tmp;
    y=INF-2;
    tmp=1;
    while (y)
    {
        if (y%2) tmp=tmp*x%INF;
        x=x*x%INF;
        y/=2;
    }
    return tmp;
}

int bit(ll x, int y)
{
    return (x>> (y-1)&1);
}

int n,m,a[500+10],b[500+10],ans,f[500+10],f2[500+10],res[500+10],ma,mat,dem,vt,vt2;

int main()
{
 //   freopen("codeforces.inp", "r", stdin);
 //   freopen("codeforces.out", "w", stdout);
    cin >> n;
    FORE(i,1,n) cin >> a[i];
    cin >> m;
    FORE(i,1,m) cin >> b[i];

    ans=0;
    FORE(i,1,n)
    {
        ma=0;
        FORE(j,1,m)
        {
            mat=ma;
            if (b[j]<a[i]) ma=max(ma,f[j]);
            if (a[i]==b[j]) f[j]=max(f[j],mat+1);
            if (ans<f[j])
            {
                ans=f[j];
                FORE(j,1,m) f2[j]=f[j];
            }
        }
    }
    cout << ans << "\n";
    if (ans)
    {
        vt=1;
        FORE(i,1,m)
        if (f[i]>f[vt]) vt=i;
        dem=1;
        res[1]=b[vt];
        vt2=vt;
        FORD(i,vt2-1,1)
        if (b[i]<b[vt] && f2[i]+1==f2[vt])
        {
            vt=i;
            res[++dem]=b[i];
        }
        FORD(i,dem,1) cout << res[i] << " ";
    }
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

const double pi = acos(-1.0);
const double eps = 1E-7;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
#define sqr(x) ((x)*(x))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define ME(a) memset((a), 0, sizeof((a)))
#define MM(a, b) memcpy((a), (b), sizeof((a)))
#define FOR(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define REP(i,a,b) for (int (i) = (a); (i) < (b); ++(i))

const int maxn = 500 + 5;

int a[maxn], b[maxn], n, m, g[maxn], f[maxn][maxn], px[maxn][maxn], py[maxn][maxn], p[maxn];
vector <int> li;

int main()
{
    scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j)
        if (a[i] == b[j]) {
            f[i][j] = 1;
            for (int u = 1; u < j; ++u)
            if (b[j] > b[u]) {
                f[i][j] = max(f[i][j], g[u] + 1);
                py[i][j] = u;
                px[i][j] = p[u];
            }
            if (f[i][j] > g[j]) {
                g[j] = f[i][j];
                p[j] = i;
            }
        }
    }

    int x = -1, y = -1;
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
    if (x == -1 || f[x][y] < f[i][j]) x = i, y = j;

    printf("%d\n", f[x][y]);
    li.clear();
    for (int o = f[x][y]; o--; ) {
        li.PB(a[x]);
        int tx = px[x][y]; y = py[x][y]; x = tx;
    }
    for (int i = SIZE(li) - 1; i >= 0; --i) printf("%d%c", li[i], (i == 0 ? '\n' : ' '));
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

const double pi = acos(-1.0);
const double eps = 1E-7;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
#define sqr(x) ((x)*(x))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define ME(a) memset((a), 0, sizeof((a)))
#define MM(a, b) memcpy((a), (b), sizeof((a)))
#define FOR(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define REP(i,a,b) for (int (i) = (a); (i) < (b); ++(i))

const int maxn = 500 + 5;

int a[maxn], b[maxn], n, m, g[maxn], f[maxn][maxn], px[maxn][maxn], py[maxn][maxn], p[maxn];
vector <int> li;

int main()
{
    scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j)
        if (a[i] == b[j]) {
            f[i][j] = 1;
            for (int u = 1; u < j; ++u)
            if (b[j] > b[u] && g[u] + 1 > f[i][j]) {
                f[i][j] = g[u] + 1;
                py[i][j] = u;
                px[i][j] = p[u];
            }
            if (f[i][j] > g[j]) {
                g[j] = f[i][j];
                p[j] = i;
            }
        }
    }

    int x = -1, y = -1;
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
    if (x == -1 || f[x][y] < f[i][j]) x = i, y = j;

    printf("%d\n", f[x][y]);
    li.clear();
    for (int o = f[x][y]; o--; ) {
        li.PB(b[y]);
        int tx = px[x][y]; y = py[x][y]; x = tx;
    }
    for (int i = SIZE(li) - 1; i >= 0; --i) printf("%d%c", li[i], (i == 0 ? '\n' : ' '));
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

const double pi = acos(-1.0);
const double eps = 1E-7;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
#define sqr(x) ((x)*(x))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define ME(a) memset((a), 0, sizeof((a)))
#define MM(a, b) memcpy((a), (b), sizeof((a)))
#define FOR(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define REP(i,a,b) for (int (i) = (a); (i) < (b); ++(i))

const int maxn = 500 + 5;

int a[maxn], b[maxn], n, m, g[maxn], f[maxn][maxn], px[maxn][maxn], py[maxn][maxn], p[maxn], gg[maxn];
vector <int> li;

int main()
{
    scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);

    memset(gg, -1, sizeof(gg));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j)
        if (a[i] == b[j]) {
            f[i][j] = 1;
            int u = gg[i];
            if (g[u] + 1 > f[i][j]) {
                f[i][j] = g[u] + 1;
                py[i][j] = u;
                px[i][j] = p[u];
            }
            if (f[i][j] > g[j]) {
                g[j] = f[i][j];
                p[j] = i;
            }
        } else if (a[i] > b[j]) {
            if (gg[i] == -1 || g[j] > g[gg[i]]) gg[i] = j;
        }
    }

    int x = -1, y = -1;
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
    if (x == -1 || f[x][y] < f[i][j]) x = i, y = j;

    printf("%d\n", f[x][y]);
    li.clear();
    for (int o = f[x][y]; o--; ) {
        li.PB(b[y]);
        int tx = px[x][y]; y = py[x][y]; x = tx;
    }
    for (int i = SIZE(li) - 1; i >= 0; --i) printf("%d%c", li[i], (i == 0 ? '\n' : ' '));
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

const double pi = acos(-1.0);
const double eps = 1E-7;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
#define sqr(x) ((x)*(x))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define ME(a) memset((a), 0, sizeof((a)))
#define MM(a, b) memcpy((a), (b), sizeof((a)))
#define FOR(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define REP(i,a,b) for (int (i) = (a); (i) < (b); ++(i))

const int maxn = 500 + 5;

int a[maxn], b[maxn], n, m, g[maxn], f[maxn][maxn], px[maxn][maxn], py[maxn][maxn], p[maxn];
vector <int> li;

int main()
{
    scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j)
        if (a[i] == b[j]) {
            f[i][j] = 1;
            for (int u = 1; u < j; ++u)
            if (b[j] > b[u] && g[u]) {
                f[i][j] = max(f[i][j], g[u] + 1);
                py[i][j] = u;
                px[i][j] = p[u];
            }
            if (f[i][j] > g[j]) {
                g[j] = f[i][j];
                p[j] = i;
            }
        }
    }

    int x = -1, y = -1;
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
    if (x == -1 || f[x][y] < f[i][j]) x = i, y = j;

    printf("%d\n", f[x][y]);
    li.clear();
    for (int o = f[x][y]; o--; ) {
        li.PB(b[y]);
        int tx = px[x][y]; y = py[x][y]; x = tx;
    }
    for (int i = SIZE(li) - 1; i >= 0; --i) printf("%d%c", li[i], (i == 0 ? '\n' : ' '));
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

const double pi = acos(-1.0);
const double eps = 1E-7;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
#define sqr(x) ((x)*(x))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define ME(a) memset((a), 0, sizeof((a)))
#define MM(a, b) memcpy((a), (b), sizeof((a)))
#define FOR(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define REP(i,a,b) for (int (i) = (a); (i) < (b); ++(i))

const int maxn = 500 + 5;

int a[maxn], b[maxn], n, m, g[maxn], f[maxn][maxn], px[maxn][maxn], py[maxn][maxn], p[maxn];
vector <int> li;

int main()
{
    scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j)
        if (a[i] == b[j]) {
            f[i][j] = 1;
            for (int u = 1; u < j; ++u)
            if (b[j] > b[u] && g[u] + 1 > f[i][j]) {
                py[i][j] = u;
                px[i][j] = p[u];
            }
            if (f[i][j] > g[j]) {
                g[j] = f[i][j];
                p[j] = i;
            }
        }
    }

    int x = -1, y = -1;
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
    if (x == -1 || f[x][y] < f[i][j]) x = i, y = j;

    printf("%d\n", f[x][y]);
    li.clear();
    for (int o = f[x][y]; o--; ) {
        li.PB(b[y]);
        int tx = px[x][y]; y = py[x][y]; x = tx;
    }
    for (int i = SIZE(li) - 1; i >= 0; --i) printf("%d%c", li[i], (i == 0 ? '\n' : ' '));
    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>

using namespace std;

int N, M;
int A[600], B[600];

int C[1200]; int Cn = 0;
map<int, int> m;

vector<int> v[600];
vector<int> LCIS[600][600];

int lth[600]; int I[600]; int J[600];
int mxn = 0; int mxi, mxj;

int main()
{
    scanf("%d", &N);

    for(int Ni = 0; Ni < N; Ni++)
        scanf("%d", &A[Ni]), C[Cn++] = A[Ni];

    scanf("%d", &M);

    for(int Mi = 0; Mi < M; Mi++)
        scanf("%d", &B[Mi]), C[Cn++] = B[Mi];

    sort(C, C+Cn);

    int _Cn = 0;

    for(int Ci = 0; Ci < Cn; Ci++)
        if( !Ci || C[Ci] != C[Ci-1] )
        {
            m[C[Ci] ] = _Cn;
            C[_Cn++] = C[Ci];
        }

    Cn = _Cn;

    for(int Bi = 0; Bi < M; Bi++)
        v[m[B[Bi] ] ].push_back(Bi);

    for(int Ai = 0; Ai < N; Ai++)
    {
        fill(lth, lth+600, 0);

        int t = m[A[Ai] ];

        for(int Aj = Ai-1; Aj >= 0; Aj--)
        {
            if( A[Aj] >= A[Ai] ) continue;

            int vj = 0;

            int p = m[A[Aj] ];

            for(int vi = 0, vn = v[t].size(); vi < vn; vi++)
            {
                while( vj+1 < v[p].size() && v[p][vj+1] < v[t][vi] ) vj++;
                if( vj >= v[p].size() || v[p][vj] > v[t][vi] ) continue;

                int _p = v[p][vj];
                if( LCIS[Aj][_p].size() > lth[vi] )
                {
                    lth[vi] = LCIS[Aj][_p].size();
                    I[vi] = Aj; J[vi] = _p;
                }
            }

        }

        for(int vi = 0, vn = v[t].size(); vi < vn; vi++)
        {
            if( lth[vi] )
            {
                for(int li = 0, ln = LCIS[I[vi] ][J[vi] ].size(); li < ln; li++)
                    LCIS[Ai][v[t][vi] ].push_back(LCIS[I[vi] ][J[vi] ][li] );
            }

            LCIS[Ai][v[t][vi] ].push_back( A[Ai]);
            if( LCIS[Ai][v[t][vi] ].size() > mxn )
            {
                mxn = LCIS[Ai][v[t][vi] ].size();
                mxi = Ai;
                mxj = v[t][vi];
            }
        }
    }

    printf("%d\n", mxn);

    bool _sp = false;
    for(int li = 0, ln = LCIS[mxi ][mxj ].size(); li < ln; li++)
    {
        if( _sp ) printf(" ");
        _sp = true;

        printf("%d", LCIS[mxi ][mxj ][li ]);
    }

    puts("");
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>

using namespace std;

int N, M;
int A[600], B[600];

int C[600]; int Cn = 0;
map<int, int> m;

vector<int> v[600];
vector<int> LCIS[600][600];

int lth[600]; int I[600]; int J[600];
int mxn = 0; int mxi, mxj;

int main()
{
    scanf("%d", &N);

    for(int Ni = 0; Ni < N; Ni++)
        scanf("%d", &A[Ni]), C[Cn++] = A[Ni];

    scanf("%d", &M);

    for(int Mi = 0; Mi < M; Mi++)
        scanf("%d", &B[Mi]), C[Cn++] = B[Mi];

    sort(C, C+Cn);

    int _Cn = 0;

    for(int Ci = 0; Ci < Cn; Ci++)
        if( !Ci || C[Ci] != C[Ci-1] )
        {
            m[C[Ci] ] = _Cn;
            C[_Cn++] = C[Ci];
        }

    Cn = _Cn;

    for(int Bi = 0; Bi < M; Bi++)
        v[m[B[Bi] ] ].push_back(Bi);

    for(int Ai = 0; Ai < N; Ai++)
    {
        fill(lth, lth+600, 0);

        int t = m[A[Ai] ];

        for(int Aj = Ai-1; Aj >= 0; Aj--)
        {
            if( A[Aj] >= A[Ai] ) continue;

            int vj = 0;

            int p = m[A[Aj] ];

            for(int vi = 0, vn = v[t].size(); vi < vn; vi++)
            {
                while( vj+1 < v[p].size() && v[p][vj+1] < v[t][vi] ) vj++;
                if( vj >= v[p].size() || v[p][vj] > v[t][vi] ) continue;

                int _p = v[p][vj];
                if( LCIS[Aj][_p].size() > lth[vi] )
                {
                    lth[vi] = LCIS[Aj][_p].size();
                    I[vi] = Aj; J[vi] = _p;
                }
            }

        }

        for(int vi = 0, vn = v[t].size(); vi < vn; vi++)
        {
            if( lth[vi] )
            {
                for(int li = 0, ln = LCIS[I[vi] ][J[vi] ].size(); li < ln; li++)
                    LCIS[Ai][v[t][vi] ].push_back(LCIS[I[vi] ][J[vi] ][li] );
            }

            LCIS[Ai][v[t][vi] ].push_back( A[Ai]);
            if( LCIS[Ai][v[t][vi] ].size() > mxn )
            {
                mxn = LCIS[Ai][v[t][vi] ].size();
                mxi = Ai;
                mxj = v[t][vi];
            }
        }
    }

    printf("%d\n", mxn);

    bool _sp = false;
    for(int li = 0, ln = LCIS[mxi ][mxj ].size(); li < ln; li++)
    {
        if( _sp ) printf(" ");
        _sp = true;

        printf("%d", LCIS[mxi ][mxj ][li ]);
    }

    puts("");
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>

using namespace std;

int N, M;
int A[600], B[600];
int C[600]; int Cn = 0;

map<int, int> m;
vector<int> v[600];

vector<int> LCIS[600][600];
int lth[600]; int I[600]; int J[600];
int mxn = 0; int mxi, mxj;

int main()
{
    scanf("%d", &N);

    for(int Ni = 0; Ni < N; Ni++)
        scanf("%d", &A[Ni]), C[Cn++] = A[Ni];

    scanf("%d", &M);

    for(int Mi = 0; Mi < M; Mi++)
        scanf("%d", &B[Mi]), C[Cn++] = B[Mi];

    sort(C, C+Cn);

    int _Cn = 0;

    for(int Ci = 0; Ci < Cn; Ci++)
        if( !Ci || C[Ci] != C[Ci-1] )
        {
            m[C[Ci] ] = _Cn;
            C[_Cn++] = C[Ci];
        }

    Cn = _Cn;

    for(int Bi = 0; Bi < M; Bi++)
        v[m[B[Bi] ] ].push_back(Bi);

    for(int Ai = 0; Ai < N; Ai++)
    {
        fill(lth, lth+600, 0);

        for(int Aj = Ai-1; Aj >= 0; Aj--)
        {
            if( A[Aj] < A[Ai] )
            {
                int vj = 0;
                int p = m[A[Aj] ];

                for(int vi = 0, vn = v[m[A[Ai] ] ].size(); vi < vn; vi++)
                {
                    int t = m[A[Ai] ];

                    while( vj+1 < v[p].size() && v[p][vj+1] < v[t][vi] ) vj++;
                    if( vj >= v[p].size() || v[p][vj] > v[t][vi] ) continue;

                    int a = v[p][vj];
                    if( LCIS[Aj][a].size() > lth[vi] )
                    {
                        lth[vi] = LCIS[Aj][a].size();
                        I[vi] = Aj; J[vi] = a;
                    }
                }
            }
        }

        for(int vi = 0, vn = v[m[A[Ai] ] ].size(); vi < vn; vi++)
        {
            int t = m[A[Ai] ];

            if( lth[vi] )
            {
                for(int li = 0, ln = LCIS[I[vi] ][J[vi] ].size(); li < ln; li++)
                    LCIS[Ai][v[t][vi] ].push_back(LCIS[I[vi] ][J[vi] ][li] );
            }

            LCIS[Ai][v[t][vi] ].push_back( A[Ai]);
            if( LCIS[Ai][v[t][vi] ].size() > mxn )
            {
                mxn = LCIS[Ai][v[t][vi] ].size();
                mxi = Ai;
                mxj = v[t][vi];
            }
        }
    }

    printf("%d\n", mxn);

    bool _sp = false;
    for(int li = 0, ln = LCIS[mxi ][mxj ].size(); li < ln; li++)
    {
        if( _sp ) printf(" ");
        _sp = true;

        printf("%d", LCIS[mxi ][mxj ][li ]);
    }

    puts("");
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>

using namespace std;

int N, M;
int A[600], B[600];

int C[1200]; int Cn = 0;
map<int, int> m;

vector<int> v[1200];
vector<int> LCIS[600][600];

int lth[600]; int I[600]; int J[600];
int mxn = 0; int mxi, mxj;

int main()
{
    scanf("%d", &N);

    for(int Ni = 0; Ni < N; Ni++)
        scanf("%d", &A[Ni]), C[Cn++] = A[Ni];

    scanf("%d", &M);

    for(int Mi = 0; Mi < M; Mi++)
        scanf("%d", &B[Mi]), C[Cn++] = B[Mi];

    sort(C, C+Cn);

    int _Cn = 0;

    for(int Ci = 0; Ci < Cn; Ci++)
        if( !Ci || C[Ci] != C[Ci-1] )
        {
            m[C[Ci] ] = _Cn;
            C[_Cn++] = C[Ci];
        }

    Cn = _Cn;

    for(int Bi = 0; Bi < M; Bi++)
        v[m[B[Bi] ] ].push_back(Bi);

    for(int Ai = 0; Ai < N; Ai++)
    {
        fill(lth, lth+600, 0);

        int t = m[A[Ai] ];

        for(int Aj = Ai-1; Aj >= 0; Aj--)
        {
            if( A[Aj] >= A[Ai] ) continue;

            int vj = 0;

            int p = m[A[Aj] ];

            for(int vi = 0, vn = v[t].size(); vi < vn; vi++)
            {
                while( vj+1 < v[p].size() && v[p][vj+1] < v[t][vi] ) vj++;
                if( vj >= v[p].size() || v[p][vj] > v[t][vi] ) continue;

                int _p = v[p][vj];
                if( LCIS[Aj][_p].size() > lth[vi] )
                {
                    lth[vi] = LCIS[Aj][_p].size();
                    I[vi] = Aj; J[vi] = _p;
                }
            }

        }

        for(int vi = 0, vn = v[t].size(); vi < vn; vi++)
        {
            if( lth[vi] )
            {
                for(int li = 0, ln = LCIS[I[vi] ][J[vi] ].size(); li < ln; li++)
                    LCIS[Ai][v[t][vi] ].push_back(LCIS[I[vi] ][J[vi] ][li] );
            }

            LCIS[Ai][v[t][vi] ].push_back( A[Ai]);
            if( LCIS[Ai][v[t][vi] ].size() > mxn )
            {
                mxn = LCIS[Ai][v[t][vi] ].size();
                mxi = Ai;
                mxj = v[t][vi];
            }
        }
    }

    printf("%d\n", mxn);

    bool _sp = false;
    for(int li = 0, ln = LCIS[mxi ][mxj ].size(); li < ln; li++)
    {
        if( _sp ) printf(" ");
        _sp = true;

        printf("%d", LCIS[mxi ][mxj ][li ]);
    }

    puts("");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int dp[510][510];
int tr[510][510][2];

int main() {
	int a[510], b[510];
	int n; scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	int m; scanf("%d", &m);
	for (int i=1; i<=m; i++)
		scanf("%d", &b[i]);

	memset(dp, 0, sizeof(dp));
	memset(tr, -1, sizeof(tr));
	for (int i=1; i<=n; i++) {
		int tmpMax = 0, tmpPos = -1;
		for (int j=1; j<=m; j++) {
			dp[i][j] = dp[i-1][j];
			tr[i][j][0] = tr[i-1][j][0];
			tr[i][j][1] = tr[i-1][j][1];
			if (b[j] < a[i] && dp[i-1][j] > tmpMax) {
				tmpMax = dp[i-1][j];
				tmpPos = j;
			}
			if (a[i] == b[j]) {
				dp[i][j] = tmpMax + 1;
				tr[i][j][0] = i-1;
				tr[i][j][1] = tmpPos;
			}
		}
	}
	int ans = 0, pos = -1;
	for (int i=1; i<=m; i++)
		if (dp[n][i] > ans) {
			ans = dp[n][i]; pos = i;
		}
	printf("%d\n", ans);
	vector <int> path;
	path.clear();
	while (pos != -1) {
		path.push_back(pos);
		int tmp = pos;
		pos = tr[n][tmp][1];
		n   = tr[n][tmp][0];
	}
	for (int i=path.size()-1; i>=0; i--)
		printf("%d ", b[path[i]]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int dp[510][510];
int tr[510][510][2];

int main() {
	int a[510], b[510];
	int n; scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	int m; scanf("%d", &m);
	for (int i=1; i<=m; i++)
		scanf("%d", &b[i]);

	memset(dp, 0, sizeof(dp));
	memset(tr, -1, sizeof(tr));
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++) {
			if (a[i] != b[j]) {
				dp[i][j] = dp[i-1][j];
				tr[i][j][0] = tr[i-1][j][0];
				tr[i][j][1] = tr[i-1][j][1];
			} else {
				for (int k=1; k<j; k++)
					if (b[k] < b[j] && dp[i-1][k] > dp[i][j]) {
						dp[i][j] = dp[i-1][k];
						tr[i][j][0] = i-1;
						tr[i][j][1] = k;
					}
				dp[i][j] ++;
			}
		}
	int ans = 0, pos = -1;
	for (int i=1; i<=m; i++)
		if (dp[n][i] > ans) {
			ans = dp[n][i]; pos = i;
		}
	printf("%d\n", ans);
	vector <int> path;
	path.clear();
	while (dp[n][pos] != 0) {
		while (a[n] != b[pos]) n --;
		path.push_back(pos);
		int tmp = pos;
		pos = tr[n][tmp][1];
		n   = tr[n][tmp][0];
	}
	for (int i=path.size()-1; i>=0; i--)
		printf("%d ", b[path[i]]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int dp[510][510];
int tr[510][510][2];

int main() {
	int a[510], b[510];
	int n; scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	int m; scanf("%d", &m);
	for (int i=1; i<=m; i++)
		scanf("%d", &b[i]);

	memset(dp, 0, sizeof(dp));
	memset(tr, -1, sizeof(tr));
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++) {
			if (a[i] != b[j]) {
				dp[i][j] = dp[i-1][j];
				tr[i][j][0] = tr[i-1][j][0];
				tr[i][j][1] = tr[i-1][j][1];
			} else {
				for (int k=1; k<j; k++)
					if (b[k] < b[j] && dp[i-1][k] > dp[i][j]) {
						dp[i][j] = dp[i-1][k];
						tr[i][j][0] = i-1;
						tr[i][j][1] = k;
					}
				dp[i][j] ++;
			}
		}
	int ans = 0, pos = -1;
	for (int i=1; i<=m; i++)
		if (dp[n][i] > ans) {
			ans = dp[n][i]; pos = i;
		}
	printf("%d\n", ans);
	vector <int> path;
	path.clear();
	while (dp[n][pos] != 0) {
		path.push_back(pos);
		int tmp = pos;
		pos = tr[n][tmp][1];
		n   = tr[n][tmp][0];
	}
	for (int i=path.size()-1; i>=0; i--)
		printf("%d ", b[path[i]]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int dp[510][510];
int tr[510][510][2];

int main() {
	int a[510], b[510];
	int n; scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	int m; scanf("%d", &m);
	for (int i=1; i<=m; i++)
		scanf("%d", &b[i]);

	memset(dp, 0, sizeof(dp));
	memset(tr, -1, sizeof(tr));
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++) {
			if (a[i] != b[j]) {
				dp[i][j] = dp[i-1][j];
				tr[i][j][0] = tr[i-1][j][0];
				tr[i][j][1] = tr[i-1][j][1];
			} else {
				for (int k=1; k<j; k++)
					if (b[k] < b[j] && dp[i-1][k] > dp[i][j]) {
						dp[i][j] = dp[i-1][k];
						tr[i][j][0] = i-1;
						tr[i][j][1] = k;
					}
				dp[i][j] ++;
			}
		}
	int ans = 0, pos = -1;
	for (int i=1; i<=m; i++)
		if (dp[n][i] > ans) {
			ans = dp[n][i]; pos = i;
		}
	printf("%d\n", ans);
	vector <int> path;
	path.clear();
	while (pos != -1) {
		path.push_back(pos);
		int tmp = pos;
		pos = tr[n][tmp][1];
		n   = tr[n][tmp][0];
	}
	for (int i=path.size()-1; i>=0; i--)
		printf("%d ", b[path[i]]);
	return 0;
}


#include <iostream>

using namespace std;
int v[510],v1[510],d[510],m,poz[510],pred;
int verif (int val, int poz)
{
	for(int i=poz;i<=m;i++)
		if(v1[i]==val)
			return i;
	return -1;
}
int main()
{
    int n,i,j,k,mx,p,mxx=0,a;
    cin>>n;
    for(i=1;i<=n;i++)
		cin>>v[i];
	cin>>m;
	for(i=1;i<=m;i++)
		cin>>v1[i];
	for(i=1;i<=n;i++)
	{
		mx=1;
		p=1;
		for(j=i-1;j>=1;j--)
		{
			if(v[j]<v[i] && d[j]>mx-1 ||  v[j]<v[i] && d[j]==i-1)
			{
				a=verif(v[i],poz[j]);
				if(a!=-1 && d[j]>mx-1 || a!=-1 && a<p && d[j]==mx-1)
				{
					mx=d[j]+1;
					p=a;
				}
			}
		}
		a=verif(v[i],p);
		if(a!=-1)
			d[i]=mx,poz[i]=a;
		else
			d[i]=0,poz[i]=m+1;
		if(d[i]>mxx)
			mxx=d[i];
	}
	pred=m+1;
	mx=mxx;
	cout<<mxx<<'\n';
	for(i=n;i>=1,mxx!=0;i--)
	{
		if(d[i]==mxx && poz[i]<pred)
            v1[mxx]=v[i],mxx--,pred=poz[i];
	}
	for(i=1;i<=mx;i++)
		cout<<v1[i]<<' ';
    return 0;
}


#include <iostream>

using namespace std;
int v[510],v1[510],d[510],m,poz[510];
int verif (int val, int poz)
{
	for(int i=poz+1;i<=m;i++)
		if(v1[i]==val)
			return i;
	return -1;
}
int main()
{
    int n,i,j,k,mx,p,mxx=0,a;
    cin>>n;
    for(i=1;i<=n;i++)
		cin>>v[i];
	cin>>m;
	for(i=1;i<=m;i++)
		cin>>v1[i];
	for(i=1;i<=n;i++)
	{
		mx=1;
		p=1;
		for(j=i-1;j>=1;j--)
		{
			if(v[j]<v[i] && d[j]>mx-1)
			{
				a=verif(v[i],poz[j]);
				if(a!=-1)
				{
					mx=d[j]+1;
					p=a;
				}
			}
		}
		if(verif(v[i],p)!=-1)
			d[i]=mx;
		else
			d[i]=0;
		poz[i]=p;
		if(d[i]>mxx)
			mxx=d[i];
	}
	mx=mxx;
	cout<<mxx<<'\n';
	for(i=n;i>=1,mxx!=0;i--)
	{
		if(d[i]==mxx)
            v1[mxx]=v[i],mxx--;
	}
	for(i=1;i<=mx;i++)
		cout<<v1[i]<<' ';
    return 0;
}


#include <iostream>

using namespace std;
int v[510],v1[510],d[510],m,poz[510];
int verif (int val, int poz)
{
	for(int i=poz;i<=m;i++)
		if(v1[i]==val)
			return i;
	return -1;
}
int main()
{
    int n,i,j,k,mx,p,mxx=0,a;
    cin>>n;
    for(i=1;i<=n;i++)
		cin>>v[i];
	cin>>m;
	for(i=1;i<=m;i++)
		cin>>v1[i];
	for(i=1;i<=n;i++)
	{
		mx=1;
		p=1;
		for(j=i-1;j>=1;j--)
		{
			if(v[j]<v[i] && d[j]>mx-1)
			{
				a=verif(v[i],poz[j]);
				if(a!=-1)
				{
					mx=d[j]+1;
					p=a;
				}
			}
		}
		if(verif(v[i],p)!=-1)
			d[i]=mx;
		else
			d[i]=0;
		poz[i]=p;
		if(d[i]>mxx)
			mxx=d[i];
	}
	mx=mxx;
	cout<<mxx<<'\n';
	for(i=n;i>=1,mxx!=0;i--)
	{
		if(d[i]==mxx)
            v1[mxx]=v[i],mxx--;
	}
	for(i=1;i<=mx;i++)
		cout<<v1[i]<<' ';
    return 0;
}


#include <cstdio>
#include <vector>
using namespace std;

const int
    MAX = 505,
    oo = 1e9;
int n, m, A[MAX], B[MAX], sol, li, lj;
vector <int> S;

struct par {
    int val, last, i, j, flag;

    par() {}

    par(int a, int b, int c) {
        i = a, j = b, flag = c;
    }
} dp[MAX][MAX], P[MAX][MAX];

void path(int i, int j, int flag) {
    if(!i && !j)
        return;

    path(P[i][j].i, P[i][j].j, P[i][j].flag);

    if(P[i][j].flag)
        S.push_back(A[i]);
}

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%d", &A[i]);

    scanf("%d", &m);
    for(int i = 1; i <= m; i++)
        scanf("%d", &B[i]);

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            dp[i][j].val = dp[i][j].last = -oo;

    dp[0][0].last = -oo;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(A[i] == B[j]) {
                if(dp[i - 1][j - 1].val == 1 && A[i] < dp[i - 1][j - 1].last) {
                    dp[i][j].val = 1;
                    dp[i][j].last = A[i];
                    P[i][j] = par(0, 0, 1);
                    continue;
                }

                if(A[i] > dp[i - 1][j - 1].last) {
                    dp[i][j].val = dp[i - 1][j - 1].val + 1;
                    dp[i][j].last = A[i];
                    P[i][j] = par(i - 1, j - 1, 1);
                }

                else if(A[i] == dp[i - 1][j - 1].last) {
                    dp[i][j].val = dp[i - 1][j - 1].val;
                    dp[i][j].last = A[i];
                    P[i][j] = par(i - 1, j - 1, 0);
                }
            }

            else if(A[i] != B[j]) {
                if(dp[i - 1][j].val > dp[i][j - 1].val) {
                    dp[i][j].val = dp[i - 1][j].val;
                    dp[i][j].last = dp[i - 1][j].last;
                    P[i][j] = par(i - 1, j, 0);
                }

                else if(dp[i][j - 1].val > dp[i - 1][j].val) {
                    dp[i][j].val = dp[i][j - 1].val;
                    dp[i][j].last = dp[i][j - 1].last;
                    P[i][j] = par(i, j - 1, 0);
                }

                else {
                    if(dp[i - 1][j].last < dp[i][j - 1].last) {
                        dp[i][j].val = dp[i - 1][j].val;
                        dp[i][j].last = dp[i - 1][j].last;
                        P[i][j] = par(i - 1, j, 0);
                    }

                    else {
                        dp[i][j].val = dp[i][j - 1].val;
                        dp[i][j].last = dp[i][j - 1].last;
                        P[i][j] = par(i, j - 1, 0);
                    }
                }
            }

            if(dp[i][j].val > sol) {
                sol = dp[i][j].val;
                li = i, lj = j;
            }
        }
    }

    path(li, lj, P[li][lj].flag);

    printf("%d\n", S.size());
    for(int i = 0; i < S.size() - 1; i++)
        printf("%d ", S[i]);
    printf("%d\n", S.back());

    return 0;
}


#include <cstdio>
#include <vector>
using namespace std;

const int
    MAX = 505,
    oo = 1e9;
int n, m, A[MAX], B[MAX], sol, li, lj;
vector <int> S;

struct par {
    int val, last, i, j, flag;

    par() {}

    par(int a, int b, int c) {
        i = a, j = b, flag = c;
    }
} dp[MAX][MAX], P[MAX][MAX];

void path(int i, int j, int flag) {
    if(!i && !j)
        return;

    path(P[i][j].i, P[i][j].j, P[i][j].flag);

    if(P[i][j].flag)
        S.push_back(A[i]);
}

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%d", &A[i]);

    scanf("%d", &m);
    for(int i = 1; i <= m; i++)
        scanf("%d", &B[i]);

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            dp[i][j].val = dp[i][j].last = -oo;

    dp[0][0].last = -oo;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(A[i] == B[j]) {
                if(dp[i - 1][j - 1].val == 1 && A[i] < dp[i - 1][j - 1].last) {
                    dp[i][j].val = 1;
                    dp[i][j].last = A[i];
                    P[i][j] = par(0, 0, 1);
                    continue;
                }

                if(A[i] > dp[i - 1][j - 1].last) {
                    dp[i][j].val = dp[i - 1][j - 1].val + 1;
                    dp[i][j].last = A[i];
                    P[i][j] = par(i - 1, j - 1, 1);
                }

                else if(A[i] == dp[i - 1][j - 1].last) {
                    dp[i][j].val = dp[i - 1][j - 1].val;
                    dp[i][j].last = A[i];
                    P[i][j] = par(i - 1, j - 1, 0);
                }
            }

            else if(A[i] != B[j]) {
                if(dp[i - 1][j].val > dp[i][j - 1].val) {
                    dp[i][j].val = dp[i - 1][j].val;
                    dp[i][j].last = dp[i - 1][j].last;
                    P[i][j] = par(i - 1, j, 0);
                }

                else if(dp[i][j - 1].val > dp[i - 1][j].val) {
                    dp[i][j].val = dp[i][j - 1].val;
                    dp[i][j].last = dp[i][j - 1].last;
                    P[i][j] = par(i, j - 1, 0);
                }

                else {
                    if(dp[i - 1][j].last < dp[i][j - 1].last) {
                        dp[i][j].val = dp[i - 1][j].val;
                        dp[i][j].last = dp[i - 1][j].last;
                        P[i][j] = par(i - 1, j, 0);
                    }

                    else {
                        dp[i][j].val = dp[i][j - 1].val;
                        dp[i][j].last = dp[i][j - 1].last;
                        P[i][j] = par(i, j - 1, 0);
                    }
                }
            }

            if(dp[i][j].val > sol) {
                sol = dp[i][j].val;
                li = i, lj = j;
            }
        }
    }

    if(!li && !lj) {
        printf("0\n");
        return 0;
    }

    path(li, lj, P[li][lj].flag);

    printf("%d\n", S.size());
    for(int i = 0; i < S.size() - 1; i++)
        printf("%d ", S[i]);
    printf("%d\n", S.back());

    return 0;
}


/*
Prob: Longest Comun Increasing Subsequence
o Subsecuencia Com'un Incremental M'axima.

Idea: Programaci'on Din'amica. Sea

dp[i][j] la longitud de la subsecuencia com'un incremental
de mayor longitud entre los prefijos A[1..i] y B[1..j].

La solucion estar'ia en dp[N][M].

Recurrencia:

Si A[i] == B[j] hay que calcular el optimo con ese entero al
final de la solucion del subproblema dp[i][j] por lo que
comenzamos con dp[i][j] = 1 y lo iremos mejorando
sucesivamente con subproblemas que ya estar'ian
calculados, estos son dp[x][y] para x < i and y < j.
Por lo q si A[i] == B[j] tenemos:

dp[i][j] = 1 + max(dp[x][y]); con A[x] == B[y] and A[x] < A[i]
para todo x < i and y < j.

El caso anterior ya ve todas las posibilidades de soluciones que
terminan con el elemento A[i], pero tal vez el optimo para el
subproblema dp[i][j] no termina con A[i] por lo que hay
arrastrar el optimo de los casos que estan en los subproblemas
dp[i - 1][j] y dp[i][j - 1]:

dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1]);

Y por 'ultimo si A[i] != B[j] entonces tenemos la recurrencia
de LCS:

dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

O sea, que si A[i] != B[j] solo necesitamos la subsecuencia que
sea de mayor longitud entre las aportadas por los subproblemas
dp[i - 1][j] y dp[i][j - 1].

Adem'as, los casos bases son similares a LCS:

dp[0][j] = 0;
dp[i][0] = 0;

Costo del peor caso: O(N^4) que corre en menos de un
segundo ya que N <= 100 por lo que N^4 <= 10^8.

Para la construcci'on de una LCIS simplemente guardamos
quien nos da el optimo o where are you from.. y luego
se construye recursivamente o iterativamente con un vector.

Para la implementaci'on ser'an usados los mismos nombres
de variables empleados en la explicaci'on previa.

*/

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 101;

int N, M;
int A[MAXN];
int B[MAXN];
int dp[MAXN][MAXN];
pii wayf[MAXN][MAXN];//where are you from..
bool toma[MAXN][MAXN];

void print_lcis(int i, int j){
	pii D = wayf[i][j];

	if ( toma[i][j] && (D.first == 0 || D.second == 0) ){
		cout << A[i];
		return;
	}

	print_lcis(D.first, D.second);

	if ( toma[i][j] )
		cout << " " << A[i];
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("lcis.in", "r", stdin);
	//freopen("lcis.out", "w", stdout);

	cin >> N;// >> M; //longitudes de A y B respectivamente.

	for (int i = 1 ; i <= N ; i++)
		cin >> A[i];

    cin >> M;
	for (int j = 1 ; j <= M ; j++)
		cin >> B[j];

	//los casos bases quedan seteados al ser dp[][] global.

	for (int i = 1 ; i <= N ; i++)
		for (int j = 1 ; j <= M ; j++)
			if ( A[i] == B[j] ){
				dp[i][j] = 1; //se ira mejorando..
			 	toma[i][j] = true; //para saber cuando anadir a la construccion de la sol
				for (int x = 1 ; x < i ; x++)
					for (int y = 1 ; y < j ; y++)
						if ( A[x] == B[y]  &&  A[x] < A[i] )
							if ( dp[i][j] < dp[x][y] + 1 ){
								 dp[i][j] = dp[x][y] + 1;
								 wayf[i][j] = pii(x, y);
							}
				//pero como se explico arriba tal vez el obtimo
				//no necesariamente es terminando con A[i] por lo q:
				if ( dp[i][j] < dp[i - 1][j] ){
					 dp[i][j] = dp[i - 1][j];
					 wayf[i][j] = pii(i - 1, j);
					 toma[i][j] = false;
				}
				if ( dp[i][j] < dp[i][j - 1] ){
					 dp[i][j] = dp[i][j - 1];
					 wayf[i][j] = pii(i, j - 1);
					 toma[i][j] = false;
				}
			}//if( A[i] == B[j] )
			else{
				if ( dp[i - 1][j] > dp[i][j - 1] ){
					 dp[i][j] = dp[i - 1][j];
					 wayf[i][j] = pii(i - 1, j);
				}
				else{
					 dp[i][j] = dp[i][j - 1];
					 wayf[i][j] = pii(i, j - 1);
				}
			}

	int Sol = dp[N][M]; //para depurar comodamente..

	cout << Sol << '\n';

	print_lcis(N, M); //tal vez iterativo sea mas sencillo por el tema
	//de no poner el espacio al final de la linea..

	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int N, M, A[505], B[505], Dp[505][505], Tb[505][505], sol, ff, cf;
typedef pair <int, int> par;
par P[505][505];
bool mark[505][505];

par busc( int fil, int col, int id )
{
 if( Tb[fil][col] < A[id] )
   return par( fil, col );

 return busc( P[fil][col].first, P[fil][col].second, id );
}

void imprimir( int fil, int col, int cant )
{
 if( fil == 0 && col == 0 )
  return;

 imprimir( P[fil][col].first, P[fil][col].second, cant - ( mark[fil][col] == true ) );
 if( mark[fil][col] )
 {
  printf("%d", A[fil]);
  if( cant != sol )
   printf(" ");
 }
}

int main()
{
// freopen("LICS.in","r",stdin);
// freopen("LICS.out","w",stdout);

 scanf("%d", &N);

 for( int i = 1; i <= N; i ++ )
  scanf("%d", &A[i]), Tb[0][i] = -1;

 scanf("%d", &M);

 for( int i = 1; i <= M; i ++ )
  scanf("%d", &B[i]), Tb[i][0] = -1;

 int f, c;
 Tb[0][0] = -1;
 for( int i = 1; i <= N; i ++ )
  for( int j = 1; j <= M; j ++ )
  {
   if( A[i] == B[j] )
   {
    mark[i][j] = true;
    if( A[i] > Tb[i - 1][j - 1] )
    {
     Tb[i][j] = A[i];
     Dp[i][j] = Dp[i - 1][j - 1] + 1;
     P[i][j] = par( i - 1, j - 1 );
    }
    else
    {
     par tmp = busc( P[i - 1][j - 1].first, P[i - 1][j - 1].second, i );
     f = tmp.first, c = tmp.second;
     Tb[i][j] = A[i];
     Dp[i][j] = Dp[f][c] + 1;
     P[i][j] = tmp;
    }
   }
   else
   {
    if( Dp[i][j - 1] == Dp[i - 1][j] )
    {
     if( Tb[i][j - 1] < Tb[i - 1][j] )
     {
      Dp[i][j] = Dp[i][j - 1];
      Tb[i][j] = Tb[i][j - 1];
      P[i][j] = par( i, j - 1 );
     }
     else
     {
      Dp[i][j] = Dp[i - 1][j];
      Tb[i][j] = Tb[i - 1][j];
      P[i][j] = par( i - 1, j );
     }
    }
    else
     if( Dp[i][j - 1] > Dp[i - 1][j] )
     {
      Dp[i][j] = Dp[i][j - 1];
      Tb[i][j] = Tb[i][j - 1];
      P[i][j] = par( i, j - 1 );
     }
     else
     {
      Dp[i][j] = Dp[i - 1][j];
      Tb[i][j] = Tb[i - 1][j];
      P[i][j] = par( i - 1, j );
     }
   }

   if( sol < Dp[i][j] )
   {
    sol = Dp[i][j];
    ff = i;
    cf = j;
   }
  }

 printf("%d", sol);

 if( sol )
  printf("\n");

 imprimir( ff, cf, sol );

 ///fflush(stdin);
 ///fflush(stdout);
        return 0;
}


/*
Prob: Longest Comun Increasing Subsequence
o Subsecuencia Com'un Incremental M'axima.

Idea: Programaci'on Din'amica. Sea

dp[i][j] la longitud de la subsecuencia com'un incremental
de mayor longitud entre los prefijos A[1..i] y B[1..j].

La solucion estar'ia en dp[N][M].

Recurrencia:

Si A[i] == B[j] hay que calcular el optimo con ese entero al
final de la solucion del subproblema dp[i][j] por lo que
comenzamos con dp[i][j] = 1 y lo iremos mejorando
sucesivamente con subproblemas que ya estar'ian
calculados, estos son dp[x][y] para x < i and y < j.
Por lo q si A[i] == B[j] tenemos:

dp[i][j] = 1 + max(dp[x][y]); con A[x] == B[y] and A[x] < A[i]
para todo x < i and y < j.

El caso anterior ya ve todas las posibilidades de soluciones que
terminan con el elemento A[i], pero tal vez el optimo para el
subproblema dp[i][j] no termina con A[i] por lo que hay
arrastrar el optimo de los casos que estan en los subproblemas
dp[i - 1][j] y dp[i][j - 1]:

dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1]);

Y por 'ultimo si A[i] != B[j] entonces tenemos la recurrencia
de LCS:

dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

O sea, que si A[i] != B[j] solo necesitamos la subsecuencia que
sea de mayor longitud entre las aportadas por los subproblemas
dp[i - 1][j] y dp[i][j - 1].

Adem'as, los casos bases son similares a LCS:

dp[0][j] = 0;
dp[i][0] = 0;

Costo del peor caso: O(N^4) que corre en menos de un
segundo ya que N <= 100 por lo que N^4 <= 10^8.

Para la construcci'on de una LCIS simplemente guardamos
quien nos da el optimo o where are you from.. y luego
se construye recursivamente o iterativamente con un vector.

Para la implementaci'on ser'an usados los mismos nombres
de variables empleados en la explicaci'on previa.

*/

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 101;

int N, M;
int A[MAXN];
int B[MAXN];
int dp[MAXN][MAXN];
pii wayf[MAXN][MAXN];//where are you from..
bool toma[MAXN][MAXN];

void print_lcis(int i, int j){
	pii D = wayf[i][j];

	if ( D.first == 0 || D.second == 0 ){
		cout << A[i];
		return;
	}

	print_lcis(D.first, D.second);

	if ( toma[i][j] )
		cout << " " << A[i];
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("lcis.in", "r", stdin);
	//freopen("lcis.out", "w", stdout);

	cin >> N;// >> M; //longitudes de A y B respectivamente.

	for (int i = 1 ; i <= N ; i++)
		cin >> A[i];

    cin >> M;
	for (int j = 1 ; j <= M ; j++)
		cin >> B[j];

	//los casos bases quedan seteados al ser dp[][] global.

	for (int i = 1 ; i <= N ; i++)
		for (int j = 1 ; j <= M ; j++)
			if ( A[i] == B[j] ){
				dp[i][j] = 1; //se ira mejorando..
			 	toma[i][j] = true; //para saber cuando anadir a la construccion de la sol
				for (int x = 1 ; x < i ; x++)
					for (int y = 1 ; y < j ; y++)
						if ( A[x] == B[y]  &&  A[x] < A[i] )
							if ( dp[i][j] < dp[x][y] + 1 ){
								 dp[i][j] = dp[x][y] + 1;
								 wayf[i][j] = pii(x, y);
							}
				//pero como se explico arriba tal vez el obtimo
				//no necesariamente es terminando con A[i] por lo q:
				if ( dp[i][j] < dp[i - 1][j] ){
					 dp[i][j] = dp[i - 1][j];
					 wayf[i][j] = pii(i - 1, j);
					 toma[i][j] = false;
				}
				if ( dp[i][j] < dp[i][j - 1] ){
					 dp[i][j] = dp[i][j - 1];
					 wayf[i][j] = pii(i, j - 1);
					 toma[i][j] = false;
				}
			}//if( A[i] == B[j] )
			else{
				if ( dp[i - 1][j] > dp[i][j - 1] ){
					 dp[i][j] = dp[i - 1][j];
					 wayf[i][j] = pii(i - 1, j);
				}
				else{
					 dp[i][j] = dp[i][j - 1];
					 wayf[i][j] = pii(i, j - 1);
				}
			}

	int Sol = dp[N][M]; //para depurar comodamente..

	cout << Sol << '\n';

    if (Sol > 0)
        print_lcis(N, M); //tal vez iterativo sea mas sencillo por el tema
        //de no poner el espacio al final de la linea..

	return 0;
}


/*
Prob: Longest Comun Increasing Subsequence
o Subsecuencia Com'un Incremental M'axima.

Idea: Programaci'on Din'amica. Sea

dp[i][j] la longitud de la subsecuencia com'un incremental
de mayor longitud entre los prefijos A[1..i] y B[1..j].

La solucion estar'ia en dp[N][M].

Recurrencia:

Si A[i] == B[j] hay que calcular el optimo con ese entero al
final de la solucion del subproblema dp[i][j] por lo que
comenzamos con dp[i][j] = 1 y lo iremos mejorando
sucesivamente con subproblemas que ya estar'ian
calculados, estos son dp[x][y] para x < i and y < j.
Por lo q si A[i] == B[j] tenemos:

dp[i][j] = 1 + max(dp[x][y]); con A[x] == B[y] and A[x] < A[i]
para todo x < i and y < j.

El caso anterior ya ve todas las posibilidades de soluciones que
terminan con el elemento A[i], pero tal vez el optimo para el
subproblema dp[i][j] no termina con A[i] por lo que hay
arrastrar el optimo de los casos que estan en los subproblemas
dp[i - 1][j] y dp[i][j - 1]:

dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1]);

Y por 'ultimo si A[i] != B[j] entonces tenemos la recurrencia
de LCS:

dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

O sea, que si A[i] != B[j] solo necesitamos la subsecuencia que
sea de mayor longitud entre las aportadas por los subproblemas
dp[i - 1][j] y dp[i][j - 1].

Adem'as, los casos bases son similares a LCS:

dp[0][j] = 0;
dp[i][0] = 0;

Costo del peor caso: O(N^4) que corre en menos de un
segundo ya que N <= 100 por lo que N^4 <= 10^8.

Para la construcci'on de una LCIS simplemente guardamos
quien nos da el optimo o where are you from.. y luego
se construye recursivamente o iterativamente con un vector.

Para la implementaci'on ser'an usados los mismos nombres
de variables empleados en la explicaci'on previa.

*/

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 101;

int N, M;
int A[MAXN];
int B[MAXN];
int dp[MAXN][MAXN];
pii wayf[MAXN][MAXN];//where are you from..
bool toma[MAXN][MAXN];

void print_lcis(int i, int j){
	pii D = wayf[i][j];

	if ( D.first == 0 || D.second == 0 ){
		cout << A[i];
		return;
	}

	print_lcis(D.first, D.second);

	if ( toma[i][j] )
		cout << " " << A[i];
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("lcis.in", "r", stdin);
	//freopen("lcis.out", "w", stdout);

	cin >> N;// >> M; //longitudes de A y B respectivamente.

	for (int i = 1 ; i <= N ; i++)
		cin >> A[i];

    cin >> M;
	for (int j = 1 ; j <= M ; j++)
		cin >> B[j];

	//los casos bases quedan seteados al ser dp[][] global.

	for (int i = 1 ; i <= N ; i++)
		for (int j = 1 ; j <= M ; j++)
			if ( A[i] == B[j] ){
				dp[i][j] = 1; //se ira mejorando..
			 	toma[i][j] = true; //para saber cuando anadir a la construccion de la sol
				for (int x = 1 ; x < i ; x++)
					for (int y = 1 ; y < j ; y++)
						if ( A[x] == B[y]  &&  A[x] < A[i] )
							if ( dp[i][j] < dp[x][y] + 1 ){
								 dp[i][j] = dp[x][y] + 1;
								 wayf[i][j] = pii(x, y);
							}
				//pero como se explico arriba tal vez el obtimo
				//no necesariamente es terminando con A[i] por lo q:
				if ( dp[i][j] < dp[i - 1][j] ){
					 dp[i][j] = dp[i - 1][j];
					 wayf[i][j] = pii(i - 1, j);
					 toma[i][j] = false;
				}
				if ( dp[i][j] < dp[i][j - 1] ){
					 dp[i][j] = dp[i][j - 1];
					 wayf[i][j] = pii(i, j - 1);
					 toma[i][j] = false;
				}
			}//if( A[i] == B[j] )
			else{
				if ( dp[i - 1][j] > dp[i][j - 1] ){
					 dp[i][j] = dp[i - 1][j];
					 wayf[i][j] = pii(i - 1, j);
				}
				else{
					 dp[i][j] = dp[i][j - 1];
					 wayf[i][j] = pii(i, j - 1);
				}
			}

	int Sol = dp[N][M]; //para depurar comodamente..

	cout << Sol << '\n';

	print_lcis(N, M); //tal vez iterativo sea mas sencillo por el tema
	//de no poner el espacio al final de la linea..

	return 0;
}