#include <bits/stdc++.h>
using namespace std;
const long long mx = 80;
const int mod = 1e9 + 7;
const int inf = 1e7;
int n, m, k;
int a[mx][mx];
int dp[mx][mx][mx][mx];
int solve(int i, int j, int cnt, int rem) {
  int &ret = dp[i][j][cnt][rem];
  if (i == n && j == m) {
    if (rem == 0) {
      return ret = 0;
    }
    return ret = -1e9;
  }
  if (j == m) {
    return ret = solve(i + 1, 0, m / 2, rem);
  }
  if (ret != -1) {
    return ret;
  }
  ret = solve(i, j + 1, cnt, rem);
  if (cnt) {
    ret = max(ret, solve(i, j + 1, cnt - 1, (rem + a[i][j]) % k) + a[i][j]);
  }
  return ret;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, m / 2, 0);
}
