#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 72;
vector<vector<int>> table;
int n, m, k;
int MAX_QTY = 36;
int DP[72][72][36][72];
int solve(int row, int col, int qty, int mod) {
  if (row >= n)
    return (mod == 0) ? 0 : -80 * 80 * 80;
  else if (col >= m)
    return solve(row + 1, 0, 0, mod);
  else if (DP[row][col][qty][mod] != -1)
    return DP[row][col][qty][mod];
  else if (2 * (qty + 1) <= m) {
    int L = table[row][col] +
            solve(row, col + 1, qty + 1, (mod + table[row][col]) % k);
    int R = solve(row, col + 1, qty, mod);
    return DP[row][col][qty][mod] = max(L, R);
  } else
    return DP[row][col][qty][mod] = solve(row, col + 1, qty, mod);
}
void build() {
  for (int a = 0; a < MAX_N; a++)
    for (int b = 0; b < MAX_N; b++)
      for (int c = 0; c < MAX_QTY; c++)
        for (int d = 0; d < MAX_N; d++) DP[a][b][c][d] = -1;
}
int main() {
  build();
  cin >> n >> m >> k;
  table = vector<vector<int>>(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> table[i][j];
  }
  cout << solve(0, 0, 0, 0) << endl;
}
