use proconio::input; fn main() { input! { n:usize, m:usize, r:[[usize;m];n], } let mut ans = 0; let mut cnts = vec![0; n]; let mut ids_max = vec![vec![]; m]; let mut maxs = vec![0; m]; for i in 0..n { for j in 0..m { if maxs[j] < r[i][j] { while let Some(id) = ids_max[j].pop() { cnts[id] -= 1; if cnts[id] == 0 { ans -= 1; } } ids_max[j].push(i); maxs[j] = r[i][j]; cnts[i] += 1; } if maxs[j] == r[i][j] { ids_max[j].push(i); cnts[i] += 1; } } if cnts[i] > 0 { ans += 1; } println!("{}", ans); } }