#include <bits/stdc++.h>
using namespace std;
const int N = 75;
int n, m, k, arr[N][N], dp[N][N][N / 2][N];
int solve(int i, int j, int left, int mod) {
  if (i == n) {
    if (!mod) return 0;
    return -1e9;
  }
  int &ret = dp[i][j][left][mod];
  if (~ret) return ret;
  int take = -1e9, leave = -1e9;
  if (j + 1 < m) {
    if (left - 1 >= 0) {
      take = solve(i, j + 1, left - 1, (mod + arr[i][j]) % k) + arr[i][j];
      leave = solve(i, j + 1, left, mod);
    } else
      leave = solve(i + 1, 0, m / 2, mod);
  } else {
    if (left - 1 >= 0) {
      take = solve(i + 1, 0, m / 2, (mod + arr[i][j]) % k) + arr[i][j];
      leave = solve(i + 1, 0, m / 2, mod);
    } else
      leave = solve(i + 1, 0, m / 2, mod);
  }
  return ret = max(take, leave);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  cout << solve(0, 0, m / 2, 0) << endl;
  return 0;
}
