#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const double pi = 3.141592653589793;
long long n, m, k;
long long a[71][71];
long long dp[71][71][71][71];
long long f(long long r, long long c, long long cnt, long long rem) {
  if (cnt < 0) return -1e9;
  if (r == n) return rem == 0 ? 0 : -1e9;
  if (c == m) return f(r + 1, 0, m / 2, rem);
  if (~dp[r][c][cnt][rem]) return dp[r][c][cnt][rem];
  long long ret = f(r, c + 1, cnt, rem);
  ret = max(ret, f(r, c + 1, cnt - 1, (rem + a[r][c]) % k) + a[r][c]);
  return dp[r][c][cnt][rem] = ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));
  long long total = 0;
  cout << f(0, 0, m / 2, 0) << '\n';
  return 0;
}
