#include <bits/stdc++.h>
using namespace std;
int N, M, K, a[71][71], f[71][71][71][71];
int dfs(int x, int y, int cnt, int sum) {
  if (f[x][y][cnt][sum] != -0x3fffffff) return f[x][y][cnt][sum];
  if (x == 0) return sum ? -0x3fffffff : 0;
  if (y == 0) return f[x][y][cnt][sum] = dfs(x - 1, M, M / 2, sum);
  if (cnt)
    f[x][y][cnt][sum] =
        a[x][y] + dfs(x, y - 1, cnt - 1, (sum - a[x][y] % K + K) % K);
  return f[x][y][cnt][sum] = max(f[x][y][cnt][sum], dfs(x, y - 1, cnt, sum));
}
int main() {
  cin >> N >> M >> K;
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= M; j++)
      for (int k = 0; k <= M; k++)
        for (int l = 0; l <= K - 1; l++) f[i][j][k][l] = -0x3fffffff;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) cin >> a[i][j];
  int ans = 0;
  for (int i = 0; i <= M / 2; i++) ans = max(ans, dfs(N, M, i, 0));
  cout << ans << endl;
  return 0;
}
