#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << p.first << ' ' << p.second << '\n';
  return out;
}
template <class T>
istream& operator>>(istream& in, vector<T>& arr) {
  for (T& i : arr) in >> i;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
  for (const T& i : arr) out << i << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<vector<T>>& arr) {
  for (const vector<T>& i : arr) out << i << ' ' << '\n';
  return out;
}
const long long INF = 1e9;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> a(n + 1, vector<int>(m + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  vector<vector<vector<vector<long long>>>> dp(
      n + 1, vector<vector<vector<long long>>>(
                 m + 1, vector<vector<long long>>(
                            m + 1, vector<long long>(k + 1, -INF))));
  dp[0][0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int cnt = 0; cnt < m / 2 + 1; cnt++) {
        for (int rem = 0; rem < k; rem++) {
          if (dp[i][j][cnt][rem] == -INF) continue;
          bool is_end = false;
          if (j == m - 1) is_end = true;
          if (!is_end)
            dp[i][j + 1][cnt][rem] =
                max(dp[i][j + 1][cnt][rem], dp[i][j][cnt][rem]);
          else
            dp[i + 1][0][0][rem] =
                max(dp[i + 1][0][0][rem], dp[i][j][cnt][rem]);
          if (cnt + 1 <= m / 2) {
            int new_rem = (rem + a[i][j]) % k;
            if (!is_end)
              dp[i][j + 1][cnt + 1][new_rem] = max(
                  dp[i][j + 1][cnt + 1][new_rem], dp[i][j][cnt][rem] + a[i][j]);
            else
              dp[i + 1][0][0][new_rem] =
                  max(dp[i + 1][0][0][new_rem], dp[i][j][cnt][rem] + a[i][j]);
          }
        }
      }
    }
  }
  cout << max(0ll, dp[n][0][0][0]) << '\n';
  return 0;
}
