program r3(input,output);
type T1 = array [1..3,1..3] of longint;
     T2 = array [1..6,1..9] of longint;
var i,j,K,L:integer;
    A,B,C:t1;
    D:t2;
    fa,fb,fc:boolean;
    vih:char;
{----------------------------------------------------------------------------}
procedure vvodmatrix (var x:t1;var f:boolean);
var n,m,z:integer;
    q:char;
    o:boolean;
begin
f:=true;
for n:=1 to 3 do
        begin
        for m:=1 to 3 do
                begin
                x[n,m]:=0;
                o:=true;
                read (q);
                if q='-' then
                        begin
                        o:=false;
                        read (q)
                end;
                while (q<>' ') do
                        begin
                        if (ord(q)<48) or (ord(q)>57) then
                                 begin
                                 f:=false;
                                 break
                                 end;
                        x[n,m]:=10 * x[n,m]+ ord(q) - 48;
                        read (q)
                        end;
                if (not o) and f then x[n,m]:=-x[n,m];
                if not f then break
                end;
        if not f then break
        end;
        writeln ('Inputing is finished');
        writeln
end;
{----------------------------------------------------------------------------}
procedure copymatrix (i,j:integer; X:t1;var D:T2);
var k,l:integer;
        begin
        for k:=j+1 to j+3 do
                for l:=i+1 to i+3 do
                D[k,l]:=X[k-j,l-i]
        end;
{----------------------------------------------------------------------------}
procedure constr(A,B,C:t1;var D:T2);
VAR i,j:integer;N:T1;
        begin
        for i:=1 to 3 do
                for j:=1 to 3 do N[i,j]:=0;
        i:=0;
        j:=0;
        copymatrix (i,j,A,D);
        i:=i+3;
        copymatrix (i,j,B,D);
        i:=i+3;
        copymatrix (i,j,C,D);
        i:=0;
        j:=3;
        copymatrix (i,j,B,D);
        i:=i+3;
        copymatrix (i,j,N,D);
        i:=i+3;
        copymatrix (i,j,A,D);
        end;
{----------------------------------------------------------------------------}
procedure outputmatrixD (M:T2);
var i,J:integer;
        begin
        for j:=1 to 6 do
                BEGIN
                for i:=1 to 9 do write (M[j,i],' ');
                WRITELN
                END
        end;
{----------------------------------------------------------------------------}
begin
repeat
writeln ('Input matrix A:');
writeln ('Koefficienti vvodatsa cherez probel i ih vsego 9');
writeln ('posle 9-ogo koefficienta probel obazatelen!');
writeln ('vse cho vvedeno posle 9-ogo probela ne rassmatrivaetsa');
fa:=true;
vvodmatrix (A,fa);
if fa then begin
        writeln ('Input matrix B:');
        fb:=true;
        readln;
        vvodmatrix (B,fb);
        if fb then begin
                readln;
                writeln ('Input matrix C:');
                fc:=true;
                vvodmatrix (C,fc);
                if fc then
                        begin
                        constr(A,B,C,D);
                        outputmatrixD (D);
                        writeln;
                        writeln ('Outputing is finished');
                        readln
                        end
                else
                        begin
                        writeln('This input is incorrect');
                        writeln('YOU ARE STUPID!');
                        end
                end
        else
                begin
                writeln('This input is incorrect');
                writeln('YOU ARE STUPID!');
                end
        end
else
        begin
        writeln('This input is incorrect');
        writeln('YOU ARE STUPID!');
        end;
readln;
writeln ('Do you want to continue computings? ');
writeln ('0-no, others-yes');
readln (vih)
until vih='0';
writeln ('thank you for using my programm!');
readln
end.
