#include <bits/stdc++.h>
using namespace std;
template <class T, size_t N, size_t... dim>
struct Array {
  using meta_elem = Array<T, dim...>;
  using elem_type = typename meta_elem::type;
  using type = vector<elem_type>;
  static Array::type New() { return Array::type(N, meta_elem::New()); }
  static Array::type New(T fill) {
    return Array::type(N, meta_elem::New(fill));
  }
};
template <class T, size_t N>
struct Array<T, N> {
  using type = vector<T>;
  static vector<T> New() { return vector<T>(N); }
  static vector<T> New(T fill) { return vector<T>(N, fill); }
};
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  auto dp = Array<int, 71, 71, 71, 71>::New(-1e9);
  auto a = Array<int, 70, 70>::New();
  dp[0][0][0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> a[i][j];
      for (int m = 0; m <= min(M / 2, j); ++m) {
        for (int k = 0; k < K; ++k) {
          if (m < M / 2) {
            dp[i][j + 1][m + 1][(k + a[i][j]) % K] =
                max(dp[i][j][m][k] + a[i][j],
                    dp[i][j + 1][m + 1][(k + a[i][j]) % K]);
          }
          dp[i][j + 1][m][k] = max(dp[i][j][m][k], dp[i][j + 1][m][k]);
        }
      }
    }
    for (int k = 0; k < K; ++k) {
      for (int m = 0; m <= M / 2; ++m) {
        dp[i + 1][0][0][k] = max(dp[i + 1][0][0][k], dp[i][M][m][k]);
      }
    }
    dp[i + 1][0][0][0] = max(0, dp[i + 1][0][0][0]);
  }
  cout << dp[N][0][0][0];
  return 0;
}
