#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
int n, m, k, len;
int a[100][100];
int dp[75][75][75][75];
int dpcall(int x, int y, int cnt, int md) {
  if (x == n) {
    if (md == 0)
      return 0;
    else
      return -1e8;
  }
  if (y == m) return -1e8;
  int &ret = dp[x][y][cnt][md];
  if (~ret) return ret;
  ret = dpcall(x + 1, 0, 0, md);
  ret = max(ret, dpcall(x, y + 1, cnt, md));
  if (cnt < len) {
    ret = max(ret, a[x][y] + dpcall(x, y + 1, cnt + 1, (a[x][y] + md) % k));
    ret = max(ret, a[x][y] + dpcall(x + 1, 0, 0, (a[x][y] + md) % k));
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  len = m / 2;
  memset((dp), -1, sizeof(dp));
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      cin >> a[i][j];
    }
  }
  cout << dpcall(0, 0, 0, 0) << endl;
  return 0;
}
