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
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long LL;

int n, k;
int tab[5][100005];
int roz[5][100005];
int result[100005];
long long roznice[5];

void P2 ()
{
	int ile = 0;
	int roznica, wynik;
	for (int i = 0; i < n; ++i)
	{
		roznica = abs(tab[0][i] - tab[1][i]);
		wynik = (tab[0][i] + tab[1][i]) / 2;
		if (roznica & 1)
		{
			ile++;
			if (ile & 1)
			{
				if (abs(tab[0][i] - wynik) < abs(tab[1][i] - wynik)) wynik++;
			}
			else
			{
				if (abs(tab[1][i] - wynik) < abs(tab[0][i] - wynik)) wynik++;
			}
		}
		printf("%d ", wynik);
	}
}

void P3 ()
{
	for (int i = 0; i < n; ++i)
	{
		if (tab[0][i] <= tab[1][i])
		{
			if (tab[1][i] <= tab[2][i]) result[i] = tab[1][i];
			else if (tab[0][i] <= tab[2][i]) result[i] = tab[2][i];
			else result[i] = tab[0][i];
		}
		else
		{
			if (tab[0][i] <= tab[2][i]) result[i] = tab[0][i];
			else if (tab[1][i] <= tab[2][i]) result[i] = tab[2][i];
			else result[i] = tab[1][i];
		}
	}
	for (int j = 0; j < 3; ++j) 
	{	
		for (int i = 0; i < n; ++i)
		{
			roz[j][i] = abs(tab[j][i] - result[i]);
			roznice[j] += (LL)(roz[j][i]);
		}
	}
	int maksik;
	long long dazymy;
	if (roznice[0] <= roznice[1])
	{
		if (roznice[1] <= roznice[2])
		{
			maksik = 2;
			dazymy = (roznice[2] + roznice[1]) / 2;
		}
		else if (roznice[0] <= roznice[2])
		{
			maksik = 1;
			dazymy = (roznice[2] + roznice[1]) / 2;
		}
		else
		{
			maksik = 1;
			dazymy = (roznice[0] + roznice[1]) / 2;
		}
	}
	else
	{
		if (roznice[0] <= roznice[2])
		{
			maksik = 2;
			dazymy = (roznice[0] + roznice[2]) / 2;
		}
		else if (roznice[1] <= roznice[2])
		{
			maksik = 0;
			dazymy = (roznice[2] + roznice[0]) / 2;
		}
		else
		{
			maksik = 0;
			dazymy = (roznice[0] + roznice[1]) / 2;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		if (roznice[maksik] == dazymy) break;
		long long hejo = roznice[maksik] - dazymy;
		if ((LL)(roz[maksik][i]) >= hejo)
		{
			roznice[maksik] -= hejo;
			if (tab[maksik][i] < result[i]) result[i] -= hejo;
			else result[i] += hejo;
		}
		else
		{
			roznice[maksik] -= (LL)(roz[maksik][i]);
			result[i] = tab[maksik][i];
		}
	}
	for (int i = 0; i < n; ++i) printf("%d ", result[i]);
}

void P4 ()
{
	
}

void P5 ()
{
	
}

int main ()
{
	scanf("%d%d",&n,&k);
	for (int i = 0; i < k; ++i) for (int j = 0; j < n; ++j) scanf("%d",&tab[i][j]);
	if (k == 2) P2();
	if (k == 3) P3();
	if (k == 4) P4();
	if (k == 5) P5();
	return 0;
}