#include <bits/stdc++.h>
using namespace std;
const long long N = 75;
long long dp[N][N][N][N], a[N][N], n, m, k;
long long rec(long long row, long long col, long long val, long long mod) {
  if (row == n) return dp[row][col][val][mod] = ((mod % k == 0) ? 0 : -2);
  if (col == m) return dp[row][col][val][mod] = rec(row + 1, 0, m / 2, mod);
  if (dp[row][col][val][mod] != -1) return dp[row][col][val][mod];
  long long sum1 = rec(row, col + 1, val, mod);
  long long sum2 =
      (val > 0) ? rec(row, col + 1, val - 1, (mod + a[row][col]) % k) : -2;
  if (sum2 != -2) sum2 += a[row][col];
  return dp[row][col][val][mod] = max({sum1, sum2});
}
void solve() {
  memset(dp, -1, sizeof dp);
  cin >> n >> m >> k;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  long long ans = rec(0, 0, m / 2, 0);
  ans = max(ans, 0ll);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
