1. Erste Version: C,  Evgeni Pavlidis

/**
* ACM programming Contest WS 08/09
* UVa Status: accepted
* Run Time: 0.010
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
#include <stdio.h>

#define MAX 25

int n;
int order[MAX];
int answer[MAX];


int main()
{
scanf("%d\n", &n);
int i,aux;

for(i=1; i <= n; i++)
{
scanf("%d", &aux);
order[aux] = i;
}
scanf("\n");

while(1)
{
int aux;
for(i=1; i <= n; i++)
{
scanf("%d", &aux);
answer[aux] = i;
}
scanf("\n");

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

if(feof(stdin))
return 0;
}

}

int lcs()
{
int common[n+1][n+1];
int r,a;

for(r=0; r <= n; r++)
for(a=0; a <= n; a++)
common[r][a] = 0;

for(r=1; r <= n; r++)
for(a=1; a <= n; a++)
{
if(order[r] == answer[a])
common[r][a] = common[r-1][a-1] + 1;
else
common[r][a] = (common[r][a-1] > common[r-1][a])?
common[r][a-1] : common[r-1][a];
}
return common[n][n];
}