#include <bits/stdc++.h>
using namespace std;
int n, m, k, arr[71][71], dp[71][71][71][36];
int solve(int i, int j, int mod, int left) {
  if (i == n - 1 && (j == m || left == 0)) {
    return mod == 0 ? 0 : INT_MIN;
  }
  if (j == m || left == 0) {
    return dp[i][j][mod][left] = solve(i + 1, 0, mod, m / 2);
  }
  if (dp[i][j][mod][left] != -1) {
    return dp[i][j][mod][left];
  }
  int ans = INT_MIN, curr_mod = arr[i][j] % k;
  if (curr_mod < mod) {
    ans = max(ans, arr[i][j] + solve(i, j + 1, mod - curr_mod, left - 1));
  } else if (curr_mod > mod) {
    ans = max(ans, arr[i][j] + solve(i, j + 1, k - (curr_mod - mod), left - 1));
  } else {
    ans = max(ans, arr[i][j] + solve(i, j + 1, 0, left - 1));
  }
  ans = max(ans, solve(i, j + 1, mod, left));
  return dp[i][j][mod][left] = ans;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << max(0, solve(0, 0, 0, m / 2));
  return 0;
}
