#include #include #include #define treshold 1000000000 using namespace std; int v[50010][30]; long long sum[50010]; vector result; int n,m; bool comp(int a, int b){ int element = 1; while(element <= n){ if(v[a][element] > v[b][element]) return false; else if(v[a][element] == v[b][element]) element++; return true; } return true; } long long getDist(int, int); long long minimum = 99999999; int modulo(int); int main() { int i, j, x; cin >> m >> n; for(i = 1; i <= m; i++){ for(j = 1; j <= n; j++){ cin >> x; x+=treshold; v[i][j] = x; } } for(i = 1; i <= m; i++) for(j = i + 1; j <= m; j++){ x = getDist(i,j); sum[i] += x; sum[j] += x; } for(i = 1; i <= m; i++){ if(sum[i] < minimum){ result.clear(); minimum = sum[i]; result.push_back(i); } else if(sum[i] == minimum){ result.push_back(i); } } sort(result.begin(), result.end(), comp); cout << minimum << '\n'; x = result.size(); cout << x << '\n'; for(i = 0; i < x; i++){ for(j = 1; j <= n; j++) cout << v[result[i]][j]-treshold << ' ';//coords of the houses, not indexes cout << '\n'; } return 0; } long long getDist(int a, int b){ long long sum = 0; for(int i = 1; i <= n; i++) sum += modulo(v[a][i]-v[b][i]); return sum; } int modulo(int x){ if(x < 0) return -x; return x; }