#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int dp[70][70][70][36];
int a[70][70];
int solve(int x, int y, int c, int r) {
  if (y == m) return solve(x + 1, 0, c, 0);
  if (x == n) return (c % k) == 0 ? 0 : -1e9;
  int &ans = dp[x][y][c][r];
  if (ans != -1) return ans;
  ans = solve(x, y + 1, c, r);
  if (r < m / 2)
    ans = max(ans, solve(x, y + 1, (c + a[x][y]) % k, r + 1) + a[x][y]);
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n >> m >> k;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  cout << solve(0, 0, 0, 0) << "\n";
  return 0;
}
