var a:array[1..200]of longint;
f:array[1..200,1..200]of longint;
i,j,k,n,r,m:longint;
begin
read(n);
fillchar(f,sizeof(f),0);
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do if a[i]=a[i+1] then inc(f[i,i+1]);
for r:=2 to n-1 do
for i:=1 to n-r do
begin
j:=i+r;
if a[i]=a[j] then f[i,j]:=f[i+1,j-1]+1;
for k:=i+1 to j-2 do
if f[i,k]+f[k+1,j]>f[i,j] then f[i,j]:=f[i,k]+f[k+1,j];
if f[i,j]<f[i+1,j] then f[i,j]:=f[i+1,j];
if f[i,j]<f[i,j-1] then f[i,j]:=f[i,j-1];
end;
for i:=1 to n do
begin
for j:=1 to n do
write(f[i,j]);
writeln;
end;
end.
f:array[1..200,1..200]of longint;
i,j,k,n,r,m:longint;
begin
read(n);
fillchar(f,sizeof(f),0);
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do if a[i]=a[i+1] then inc(f[i,i+1]);
for r:=2 to n-1 do
for i:=1 to n-r do
begin
j:=i+r;
if a[i]=a[j] then f[i,j]:=f[i+1,j-1]+1;
for k:=i+1 to j-2 do
if f[i,k]+f[k+1,j]>f[i,j] then f[i,j]:=f[i,k]+f[k+1,j];
if f[i,j]<f[i+1,j] then f[i,j]:=f[i+1,j];
if f[i,j]<f[i,j-1] then f[i,j]:=f[i,j-1];
end;
for i:=1 to n do
begin
for j:=1 to n do
write(f[i,j]);
writeln;
end;
end.