#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int maxn = 71, inf = 1 << 29;
int dp[maxn][maxn];
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> a(n, vector<int>(m));
  for (auto &v : a) {
    for (int &x : v) cin >> x;
  }
  fill_n(*dp, maxn * maxn, -inf);
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    vector<int> sack(maxn * maxn, inf);
    sack[0] = 0;
    for (int j = 0; j < m; j++) {
      for (int l = int((sack).size()) - 1; l >= a[i][j]; l--) {
        sack[l] = min(sack[l], sack[l - a[i][j]] + 1);
      }
    }
    vector<int> mx(k, -inf);
    for (int j = 0; j < maxn * maxn; j++) {
      if (sack[j] <= m / 2) mx[j % k] = j;
    }
    for (int j = 0; j < k; j++) {
      for (int l = 0; l < k; l++) {
        dp[i + 1][(j + l) % k] = max(dp[i + 1][(j + l) % k], dp[i][j] + mx[l]);
      }
    }
  }
  cout << dp[n][0];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int tcs = 1;
  for (int tc = 1; tc <= tcs; tc++) {
    solve();
  }
}
