uses crt;
var n,i,j,t,tong:longint; a:array[1..100000000]of longint; d:text;
function nt(a:longint):boolean;
var i:longint;
begin
i:=2;
while (a>1)and(a mod i<>0) do inc(i);
nt:=i=a;
end;
begin
clrscr;
assign(d,'input.pas');reset(d);
readln(d,n);
for i:=1 to n do
begin
for j:=1 to n do read(d,a[n*(i-1)+j]);
readln(d);
end;
close(d);
assign(d,'output.pas');rewrite(d);
writeln(d,'Cac so nguyen to:');
for i:=1 to n*n do if nt(a[i]) then writeln(d,a[i]);
writeln(d,'Xap sep theo thu tu tang dan:');
for i:=1 to n*n do
for j:=1 to i do
if a[i]<a[j] then
begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end;
for i:=1 to n*n do writeln(d,a[i]);
for i:=1 to n*n do if i mod n=1 then inc(tong,a[i]);
writeln(d,'Tong cua cac gia tri nho nhat tren cac dong: ',tong);
writeln(d,'Vi tri diem cuc tieu cua mang: 1');
close(d);
readln
end.