#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int dizi[72][72];
int dp[72][72][72][72];
int f(int x, int y, int cnt, int modd) {
  if (x == n and y == m + 1) {
    if (modd == 0 and cnt <= m / 2) return 0;
    return -999999999;
  }
  if (cnt > m / 2) return -999999999;
  if (y == m + 1) return f(x + 1, 1, 0, modd);
  if (dp[x][y][cnt][modd] != -1) return dp[x][y][cnt][modd];
  int almadim = f(x, y + 1, cnt, modd);
  int aldim = f(x, y + 1, cnt + 1, (modd + dizi[x][y]) % k) + dizi[x][y];
  return dp[x][y][cnt][modd] = max(aldim, almadim);
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> dizi[i][j];
  memset(dp, -1, sizeof dp);
  cout << f(1, 1, 0, 0) << endl;
}
