#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M, K;
cin >> N >> M >> K;
vector<vector<int>> a(N, vector<int>(M));
vector<int> total(N, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> a[i][j];
total[i] += a[i][j];
}
}
vector<int> order(N);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int x, int y) {
if (total[x] != total[y]) return total[x] > total[y];
return x < y;
});
long long revealed = 0;
vector<int> minScore(N, 0);
vector<int> hidden(N, M);
vector<vector<int>> sortedScores(N);
for (int i = 0; i < N; i++) {
sortedScores[i] = a[i];
sort(sortedScores[i].rbegin(), sortedScores[i].rend());
}
vector<int> ptr(N, 0);
for (int t = 0; t + 1 < N; t++) {
int x = order[t];
int y = order[t + 1];
while (true) {
int minx = minScore[x];
int maxy = minScore[y] + hidden[y] * K;
if (maxy < minx) break;
bool revealX = false;
if (ptr[x] < M) {
int gainX = sortedScores[x][ptr[x]];
int newMinX = minx + gainX;
if (maxy < newMinX) revealX = true;
}
if (revealX || ptr[y] == M) {
int v = sortedScores[x][ptr[x]++];
minScore[x] += v;
hidden[x]--;
revealed++;
} else {
int v = sortedScores[y][ptr[y]++];
minScore[y] += v;
hidden[y]--;
revealed++;
}
}
}
cout << revealed << "\n";
}