#include <bits/stdc++.h>
using namespace std;
int oo = 10000000;
int n, m, k;
int a[71][71];
int dp_[71][71][71][71];
int dp(int row, int col, int remcols, int rem) {
  if (row >= n || remcols < 0) {
    return rem || remcols < 0 ? -oo : 0;
  }
  if (col >= m) return dp(row + 1, 0, m >> 1, rem);
  int& mem = dp_[row][col][remcols][rem];
  if (mem != -1) return mem;
  mem = max(
      max(dp(row, col + 1, remcols, rem),
          a[row][col] + dp(row, col + 1, remcols - 1, (rem + a[row][col]) % k)),
      max(dp(row + 1, 0, m >> 1, rem), rem ? -oo : 0));
  return mem;
}
int main() {
  scanf(" %d %d %d", &n, &m, &k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf(" %d", &a[i][j]);
      for (int x = 0; x <= m; x++)
        for (int z = 0; z <= k; z++) dp_[i][j][x][z] = -1;
    }
  printf("%d\n", dp(0, 0, m / 2, 0));
}
