#include <bits/stdc++.h>
using namespace std;
long long int n, m, k;
long long int v1[71][71];
long long int dp[71][71][35][71];
long long int power(long long int x, long long int n) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = result * x;
    x = x * x;
    n = n / 2;
  }
  return result;
}
long long int fun(long long int row, long long int col, long long int cnt,
                  long long int mod) {
  if (row == n - 1 && (col == m || cnt >= m / 2)) {
    if (mod == 0)
      return 0;
    else
      return -1e8;
  }
  if (col == m || cnt >= m / 2)
    return dp[row][col][cnt][mod] = fun(row + 1, 0, 0, mod);
  if (dp[row][col][cnt][mod] != -1) return dp[row][col][cnt][mod];
  long long int ans = -1e8;
  ans = max(ans, v1[row][col] +
                     fun(row, col + 1, cnt + 1, (mod + v1[row][col] % k) % k));
  ans = max(ans, fun(row, col + 1, cnt, mod));
  return dp[row][col][cnt][mod] = ans;
}
void solve() {
  cin >> n >> m >> k;
  for (long long int i = 0; i <= n - 1; i++)
    for (long long int j = 0; j <= m - 1; j++) cin >> v1[i][j];
  memset(dp, -1, sizeof(dp));
  long long int a1 = fun(0, 0, 0, 0);
  cout << a1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
