Var a:array[1..3,1..3] of integer; t:array[0..2] of boolean; k:array[0..2] of integer; i,j:integer; res:boolean;
begin for i := 1 to 3 do for j := 1 to 3 do read(a[i,j]); for i := 0 to 2 do begin k[i] := 0; t[i] := false; end;
for i := 1 to 3 do for j := 1 to 3 do k[a[i,j]] := k[a[i,j]] + 1;
for i := 1 to 3 do begin if (a[i,1] = a[i,2]) and (a[i,2] = a[i,3]) then t[a[i,1]] := true; if (a[1,i] = a[2,i]) and (a[2,i] = a[3,i]) then t[a[1,i]] := true; end; if (a[1,1] = a[2,2]) and (a[2,2] = a[3,3]) then t[a[2,2]] := true; if (a[3,1] = a[2,2]) and (a[2,2] = a[1,3]) then t[a[2,2]] := true;
res := true;
if (k[1] - k[2] > 1) or (k[1] - k[2] < 0) then res := false;
if t[1] and ( t[2] or (k[1] = k[2]) ) then res := false;
if res then writeln('YES') else writeln('NO') end.
a:array[1..3,1..3] of integer;
t:array[0..2] of boolean;
k:array[0..2] of integer;
i,j:integer;
res:boolean;
begin
for i := 1 to 3 do
for j := 1 to 3 do
read(a[i,j]);
for i := 0 to 2 do
begin
k[i] := 0;
t[i] := false;
end;
for i := 1 to 3 do
for j := 1 to 3 do
k[a[i,j]] := k[a[i,j]] + 1;
for i := 1 to 3 do
begin
if (a[i,1] = a[i,2]) and (a[i,2] = a[i,3]) then
t[a[i,1]] := true;
if (a[1,i] = a[2,i]) and (a[2,i] = a[3,i]) then
t[a[1,i]] := true;
end;
if (a[1,1] = a[2,2]) and (a[2,2] = a[3,3]) then
t[a[2,2]] := true;
if (a[3,1] = a[2,2]) and (a[2,2] = a[1,3]) then
t[a[2,2]] := true;
res := true;
if (k[1] - k[2] > 1) or (k[1] - k[2] < 0) then
res := false;
if t[1] and ( t[2] or (k[1] = k[2]) ) then
res := false;
if res then
writeln('YES')
else
writeln('NO')
end.
===== PascalABC.NET =====
procedure SortShell<T>(a: array of T);
where T: IComparable<T>;
// сортировка по Шеллу
begin
var n := a.Length;
var d := n div 2;
while d > 0 do
begin
var k := True;
while k do
begin
k := False;
for var i := 0 to n - d - 1 do
if a[i].CompareTo(a[i + d]) > 0 then begin
Swap(a[i], a[i + d]);
k := True
end
end;
d := d div 2
end
end;
begin
var a := ArrRandom(10, -20, 20); a.Println;
SortShell(a); a.Println
end.