{
TASK: KAL
LANG: PASCAL
}
program u51;

const
  maxn = 100;
  maxats = 10000;
  FP = 'KAL.DAT';
  FR = 'KAL.REZ';

type
  TKoord = record
    x, y: integer;
  end;
  TLenta = array [1 .. maxn, 1 .. maxn] of integer;

const
  kryptys: array [1 .. 4] of TKoord = ((x:-1; y:0), (x:1; y:0), (x:0; y:-1), (x:0; y:1));

var
  A, B: integer; //Kaladelæ A reikia perstumti á kaladëlës B vietà
  Ak, Bk, Zk: TKoord; //Kaladëliø koordinatës
  N, M: integer; //lentos iðmatavimai
  lenta: TLenta;
  ats: array [1 .. maxats] of integer;
  atsdydis: integer;

function lentoje(x, y: integer): boolean;
begin
  lentoje := (x >= 1) and (x <= N) and (y >= 1) and (y <= M);
end;

procedure ivesk;
var
  fin: text;
  i, j: integer;
begin
  assign(fin, FP); reset(fin);
  readln(fin, N, M);
  readln(fin, A, B);
  for i := 1 to N do
  begin
    for j := 1 to M do
    begin
      read(fin, lenta[i, j]);
      if lenta[i, j] = A then
      begin
        Ak.x := i; Ak.y := j;
      end;
      if lenta[i, j] = B then
      begin
        Bk.x := i; Bk.y := j;
      end;
      if lenta[i, j] = 0 then
      begin
        Zk.x := i; Zk.y := j;
      end;
    end;
    readln(fin);
  end;
  close(fin);
end;

procedure stumiuKaladele(numeris: integer);
begin
  inc(atsdydis);
  ats[atsdydis] := numeris;
end;
{
procedure outLenta(const lenta: TLenta);
var
  i, j: integer;
begin
  writeln;
  for i := 1 to N do
  begin
    for j := 1 to M do
      write(lenta[i, j], ' ');
    writeln;
  end;
  writeln;
end;
}
function banga(var vaiks: TLenta; Ak, Bk: TKoord): boolean;
//vaiks masyve esantys -1 reiðkia, kad ten negalima eiti
//Ak- ið èia bus leidþiama banga
//Bk- iki èia bus leidþiama banga
var
  i, j, k, i1, j1: integer;
  bRasta: boolean;
  counter: integer;
begin
  bRasta := True;
  if (Ak.x <> Bk.x) or (Ak.y <> Bk.y) then
  begin
    vaiks[Ak.x, Ak.y] := 1;
    bRasta := False;
    counter := 1;
    while not bRasta do
    begin
      inc(counter);
      for i := 1 to N do
        for j := 1 to M do
          if vaiks[i, j] = counter - 1 then
            for k := low(kryptys) to high(kryptys) do
            begin
              i1 := i + kryptys[k].x;
              j1 := j + kryptys[k].y;
              if lentoje(i1, j1) and (vaiks[i1, j1] = 0) then
              begin
                vaiks[i1, j1] := counter;
                if (Bk.x = i1) and (Bk.y = j1) then
                  bRasta := True;
              end;
            end;
    end;
  end;
  banga := bRasta;
end;

procedure sprendimas;
var
  ejimai: TLenta;
  Eiti, tmpK: TKoord;
  ejsk: integer;
  k, tmp: integer;
  nulis, nul: TLenta;
begin
  fillchar(ejimai, sizeof(ejimai), 0);
  banga(ejimai, Bk, Ak);
  while (Ak.x <> Bk.x) or (Ak.y <> Bk.y) do
  begin
    ejsk := -1;
    for k := low(kryptys) to high(kryptys) do
    begin
      tmpK.x := Ak.x + kryptys[k].x;
      tmpK.y := Ak.y + kryptys[k].y;
      if lentoje(tmpK.x, tmpK.y) and
        (ejimai[tmpK.x, tmpK.y] + 1 = ejimai[Ak.x, Ak.y]) then
      begin
        fillchar(nulis, sizeof(nulis), 0);
        nulis[Ak.x, Ak.y] := -1;
        banga(nulis, tmpK, Zk);
        if (ejsk < 0) or (nulis[tmpK.x, tmpK.y] < ejsk) then
        begin
          ejsk := nulis[tmpK.x, tmpK.y];
          Eiti := tmpK;
          nul := nulis;
        end;
      end;
    end;
    if ejsk >= 0 then
    begin
      while (Zk.x <> Eiti.x) or (Zk.y <> Eiti.y) do
      begin
        for k := low(kryptys) to high(kryptys) do
        begin
          tmpK.x := Zk.x + kryptys[k].x;
          tmpK.y := Zk.y + kryptys[k].y;
          if lentoje(tmpK.x, tmpK.y) and (nul[tmpK.x, tmpK.y] + 1 = nul[Zk.x, Zk.y]) then
          begin
            stumiuKaladele(lenta[tmpK.x, tmpK.y]);
            tmp := lenta[tmpK.x, tmpK.y];
            lenta[tmpK.x, tmpK.y] := lenta[Zk.x, Zk.y];
            lenta[Zk.x, Zk.y] := tmp;
            Zk := tmpK;
          end;
        end;
      end;
      stumiuKaladele(A);
      tmpK := Ak; Ak := Zk; Zk := tmpK;
    end else begin
      writeln('Blogai!!!!!!!!!');
      halt;
    end;
  end;
end;

procedure atsakymas;
var
  fout: text;
  i: integer;
begin
  assign(fout, FR); rewrite(fout);
  writeln(fout, atsdydis);
  for i := 1 to atsdydis do
    writeln(fout, ats[i], ' ');;
  writeln(fout);
  close(fout);
end;

begin
  ivesk;
  atsdydis := 0;
  sprendimas;
  atsakymas;
end.
