1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
program cia;

var
  k : byte;
  n : word;
  a : array[1..100000, 1..5] of longint;

  i,j,j1 : longword;

  tmp,tmp1,tmp2 : longint;

begin
  readln(n,k);

  for i:=1 to k do
  begin
    for j:=1 to n-1 do read(a[i,j]);
    readln(a[i,n])
  end;
  if (k mod 2)>0 then
  begin
    j:=(k+1) div 2;
    write(a[j,1]);
    for i:=2 to n do write(' ',a[j,i]);
  end
  else
  begin
    j:=k div 2;
    for i:=1 to n do
    begin
      tmp:=(a[j,i]+a[j+1,i]) div 2; tmp1:=0; tmp2:=0;
      for j1:=1 to k do
        tmp1:=tmp1+abs(a[j1,i]-tmp);
      tmp:=tmp+1;
      for j1:=1 to k do
        tmp2:=tmp2+abs(a[j1,i]-tmp);
      if i>1 then write(' ');
      if tmp2>tmp1 then write(tmp-1)
        else write(tmp)
    end
  end;
  writeln;
end.