import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n, m; scan(n, m); auto r = new int[][](n, m); iota(n).each!(i => r[i] = readln.split.to!(int[])); auto risk = new int[](m); auto jogai = new int[][](m, 0); auto stn = new int[](n); int taijo; foreach (i ; 0 .. n) { foreach (j ; 0 .. m) { if (r[i][j] < risk[j]) { stn[i]++; if (stn[i] == m) { taijo++; } } else if (r[i][j] == risk[j]) { jogai[j] ~= i; } else if (r[i][j] > risk[j]) { foreach (jg ; jogai[j]) { stn[jg]++; if (stn[jg] == m) { taijo++; } } jogai[j] = [i]; risk[j] = r[i][j]; } } debug { writeln("taijo:", taijo); writeln(jogai); } writeln(i + 1 - taijo); } } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }