#include <bits/stdc++.h>
using namespace std;
const int nax = 75;
int dp[nax][nax][nax][nax];
int vis[nax][nax][nax][nax];
int grid[nax][nax];
int n, m, k;
int call(int x, int y, int nilam, int sum) {
  if (x >= n || y >= m) {
    if (sum == 0) return 0;
    return INT_MIN;
  }
  if (vis[x][y][nilam][sum] != 0) return dp[x][y][nilam][sum];
  vis[x][y][nilam][sum] = 1;
  int ans = INT_MIN;
  if (nilam + 1 <= m / 2) {
    ans = max(ans,
              grid[x][y] + call(x, y + 1, nilam + 1, (sum + grid[x][y]) % k));
    ans = max(ans, grid[x][y] + call(x + 1, 0, 0, (sum + grid[x][y]) % k));
  }
  ans = max(ans, call(x, y + 1, nilam, sum));
  ans = max(ans, call(x + 1, 0, 0, sum));
  return dp[x][y][nilam][sum] = ans;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  memset(vis, 0, sizeof vis);
  int ans = call(0, 0, 0, 0);
  cout << ans << endl;
}
