1.


/* Problemnr: 111
* Author : Peter Schnitzler
* Sprache : C++
* Status : AC
* Runntime: 0.016s
*/

#include <iostream>

using namespace std;

int main()
{
int size;
cin >> size;

int results[size];
int anwsers[size];
int reverseAnwserKey[size];

for (int count = 0; count < size; ++count)
{
cin >> reverseAnwserKey[count];
}

results[0] = 1;

while (true)
{



for (int count = 0; count < size; ++count)
{
int temp;
cin >> temp;
--temp;

if (cin.eof())
{
break;
}


anwsers[temp] = reverseAnwserKey[count];

results[count] = 1;
}

if (cin.eof())
{
break;
}


int maxResult = 1;


for (int count = 0; count < size; ++count)
{
for (int run = count + 1; run < size; ++run)
{
if (anwsers[count] < anwsers[run])
{
int temp = results[count] + 1;

if (results[run] < temp)
{
results[run] = temp;

if (temp > maxResult)
{
maxResult = temp;
}
}
}
}
}


cout << maxResult << endl;
}
}

2.

/**
* 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];
}