#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
long long int myRand(long long int R) {
  long long int val = rng() % R;
  assert(val >= 0);
  return val;
}
const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
const int32_t MOD = 1e9 + 7;
using namespace std;
void my_debugger(string second, long long int LINE_NUM) { cerr << '\n'; }
template <typename start, typename... end>
void my_debugger(string second, long long int LINE_NUM, start x, end... y) {
  if (second.back() != ',') {
    second += ',';
    cerr << "LINE(" << LINE_NUM << "): ";
  }
  long long int i = second.find(',');
  cerr << second.substr(0, i) << " = " << x;
  second = second.substr(i + 1);
  if (!second.empty()) cerr << ", ";
  my_debugger(second, LINE_NUM, y...);
}
long long int dp[72][72][72][72];
long long int max1 = 0;
long long int N, M, K;
long long int a[75][75];
long long int solve(long long int r, long long int c, long long int can_take,
                    long long int rem) {
  if (r == 0) {
    if (rem == 0) return 0;
    return -INF64;
  }
  if (c <= 0) return solve(r - 1, M, M / 2, rem);
  if (dp[r][c][can_take][rem] != -1) return dp[r][c][can_take][rem];
  long long int& ans = dp[r][c][can_take][rem];
  ans = -INF64;
  long long int rem1 = (rem - a[r][c]) % K;
  rem1 = (rem1 + K) % K;
  ;
  ;
  ans = max(ans, solve(r, c - 1, can_take, rem));
  ans = max(ans, solve(r - 1, M, M / 2, rem));
  if (can_take > 0)
    ans = max(ans, a[r][c] + solve(r, c - 1, can_take - 1, rem1));
  if (can_take > 0) ans = max(ans, a[r][c] + solve(r - 1, M, M / 2, rem1));
  ;
  ;
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  long long int tests = 1;
  for (long long int ii = 0; ii < (long long int)tests; ii++) {
    cin >> N >> M >> K;
    ;
    ;
    for (long long int i = 1; i < (long long int)N + 1; i++)
      for (long long int j = 1; j < (long long int)M + 1; j++) cin >> a[i][j];
    for (long long int i = 0; i < (long long int)71; i++)
      for (long long int j = 0; j < (long long int)71; j++)
        for (long long int k = 0; k < (long long int)71; k++)
          for (long long int l = 0; l < (long long int)71; l++)
            dp[i][j][k][l] = -1;
    max1 = 0;
    cout << solve(N, M, M / 2, 0) << '\n';
  }
  return 0;
}
