#include <bits/stdc++.h>
using namespace std;
const size_t Z = 72;
const int INF = 1 << 28;
int dp[Z][Z][Z][Z / 2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, k, t, z = 0;
  cin >> n >> m >> k;
  dp[0][m][0][0] = INF;
  for (size_t i = 1; i <= n; ++i) {
    for (int r = 0; r < k; ++r) {
      int& y = dp[i][0][r][0];
      for (int c = 0; c <= m / 2; ++c) {
        y = max(y, dp[i - 1][m][r][c]);
      }
    }
    for (size_t j = 1; j <= m; ++j) {
      cin >> t;
      for (int r = 0; r < k; ++r) {
        for (int c = 0; c <= m / 2; ++c) {
          dp[i][j][(r + t) % k][c] = max(dp[i][j - 1][(r + t) % k][c],
                                         c ? dp[i][j - 1][r][c - 1] + t : 0);
        }
      }
    }
  }
  for (int c = 0; c <= m / 2; ++c) z = max(z, dp[n][m][0][c]);
  cout << z - INF << '\n';
  return 0;
}
