Var n,m,i,j,k,s,s1:longint; y:array[1..10000,1..10000] of longint; o:array[1..10000] of longint; begin read(n,m); for i:=1 to n do for j:=1 to m do read(y[i,j]); for i:=1 to n do for j:=1 to n do if j<>i then begin for k:=1 to m do if y[i,k]=y[j,k] then inc(s); if s=m then begin if o[i]=0 then begin writeln(i); o[i]:=1; end; if o[j]=0 then begin writeln(j); o[j]:=1; end; end; s:=0; end; end. Для общего случая.
y:array[1..10000,1..10000] of longint;
o:array[1..10000] of longint;
begin
read(n,m);
for i:=1 to n do
for j:=1 to m do
read(y[i,j]);
for i:=1 to n do
for j:=1 to n do
if j<>i then
begin for k:=1 to m do
if y[i,k]=y[j,k] then inc(s);
if s=m then
begin
if o[i]=0 then
begin
writeln(i);
o[i]:=1;
end;
if o[j]=0 then
begin
writeln(j);
o[j]:=1;
end;
end;
s:=0;
end;
end.
Для общего случая.