program algebgr; uses dos, crt,printer;
const maxb = 8;                    { S E N D M O R Y }
      von: array[1..maxb] of byte = (1,0,0,0,1,0,0,0);
      bis: array[1..maxb] of byte = (9,9,9,9,9,9,9,9);
      used: array[0..9] of boolean =
            (false,false,false,false,false,false,false,false,false,false);
var b:   array[1..maxb] of longint;
    i: byte;

procedure test(i:integer);
var j,k: byte;
begin
  for j:= von[i] to bis[i] do
    if not used[j] then begin
      b[i]:= j; used[j]:= true;
      if i < maxb then TEST(i+1)
        else begin write(#13);
        for k:= 1 to maxb do write(b[k]:2);
        if ((b[1]*10 + b[2])*10 + b[3])*10 + b[4] +                 {*SEND}
           ((b[5]*10 + b[6])*10 + b[7])*10 + b[2] =                 {*MORE}
           (((b[5]*10 + b[6])*10 + b[3])*10 + b[2])*10 + b[8] then {*MONEY}
             begin write('  OK'); writeln; end;
        end;
      used[b[i]]:= false; end;
end; {test}

begin
test(1);
end.
