program Check;

{$APPTYPE CONSOLE}

uses
  TestLib, SysUtils;

const
  maxn=200;  

var
  rows, cols, outsum, anssum, left_row, left_col, right_row, right_col: integer;
  a: array [1..maxn,1..maxn] of integer;
  i, j, s: integer;

begin
  rows:= inf.ReadLongint; cols:= inf.ReadLongint; inf.NextLine;
  outsum:= ouf.ReadLongint;
  anssum:= ans.ReadLongint;
  ouf.NextLine;
  left_row:= ouf.ReadLongint;
  left_col:= ouf.ReadLongint;
  right_row:= ouf.ReadLongint;
  right_col:= ouf.ReadLongint;

  if not ouf.SeekEof then quit(_PE,'Extra characters in output file.');

  if (left_row<=0) or (left_row>rows) or (left_col<=0) or (left_col>cols) or
     (right_row<=0) or (right_row>rows) or (right_col<=0) or (right_col>cols) or
     (left_col>right_col) or (left_row>right_row)
  then
    quit (_PE, Format('(%d, %d) (%d, %d) is wrong row-column format',[left_row,left_col,right_row,right_col]));

  for i:=1 to rows do begin
    for j:=1 to cols do a[i,j]:= inf.ReadLongint;
    inf.NextLine;
  end;

  s:= 0;
  if left_row<>right_row then
    for i:=left_col to right_col do inc(s,a[left_row,i]+a[right_row,i])
  else
    for i:=left_col to right_col do inc(s,a[left_row,i]);

  if left_col<>right_col then
    for i:=left_row+1 to right_row-1 do inc(s,a[i,left_col]+a[i,right_col])
  else
    for i:=left_row+1 to right_row-1 do inc(s,a[i,left_col]);

  if s<>outsum then
    quit (_WA, Format('Sum of border = %d, but output sum = %d',[s,outsum]));

  if outsum<anssum then
    quit(_WA,Format('Not maximum submatrix (%d instead of %d)',[outsum,anssum]));

  if outsum>anssum then
    quit(_Fail,Format('Better solution found !!! (%d instead of %d)',[outsum,anssum]));

  quit(_OK,Format('Sum = %d',[outsum]));
end.
