#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF 1 << 29 #define LL long long int LL const MOD = 1000000007; int main(){ cin.tie(0); ios::sync_with_stdio(false); LL n,m; cin >> n >> m; vector> r(n,vector(m)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> r[i][j]; } } vector> pre(n,vector(m)); vector tmp(n); vector> total(n,vector(m,1)); for(int i = 0; i < m; i++){ pre[0][i] = 1; tmp[i] = r[0][i]; } for(int i = 1; i < n; i++){ for(int j = 0; j < m; j++){ if(tmp[j] == r[i][j]){ pre[i][j] = 2; }else if(tmp[j] < r[i][j]){ pre[i][j] = 1; tmp[j] = r[i][j]; }else{ pre[i][j] = 0; } } } for(int i = 1; i < n; i++){ for(int j = 0; j < m; j++){ if(pre[i][j] == 0){ total[i][j] = total[i-1][j]; }else if(pre[i][j] == 2){ total[i][j] = total[i-1][j] + 1; }else{ total[i][j] = 1; } } } vector> mer1(n,vector(m)); vector> mer2(n,vector(m)); for(int i = 0; i < n; i++){ mer1[i][0] = total[i][0]; mer2[i][0] = pre[i][0]; } for(int k = 1; k < m; k++){ LL c = 1; mer1[0][k] = 1; mer2[0][k] = 1; for(int i = 1; i < n; i++){ if(mer2[i][k-1] == 1 || pre[i][k] == 1){ c = 0; } if(mer2[i][k-1] > 0 && pre[i][k] > 0){ c++; } mer1[i][k] = mer1[i][k-1] + total[i][k] - c; if(pre[i][k] == 0){ if(mer2[i][k-1] == 2){ mer2[i][k] = 2; }else{ mer2[i][k] = 0; } }else if(pre[i][k] == 2){ mer2[i][k] = 2; }else{ if(mer2[i][k-1] == 2){ mer2[i][k] = 2; }else if(mer2[i][k-1] == 0){ mer2[i][k] = 0; }else{ mer2[i][k] = 1; } } } } for(int i = 0; i < n; i++){ cout << mer1[i][m-1] << endl; } return 0; }