#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int> > a(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  int W = m / 2;
  vector<vector<vector<vector<int> > > > dp(
      n + 1, vector<vector<vector<int> > >(
                 m + 1, vector<vector<int> >(W + 1, vector<int>(k, INT_MIN))));
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      for (int l = 0; l <= W; ++l) {
        for (int rem = 0; rem < k; ++rem) {
          if (i == 0) {
            if (rem == 0) dp[i][j][l][rem] = 0;
            continue;
          } else if (j == 0 || l == 0) {
            dp[i][j][l][rem] = dp[i - 1][m][W][rem];
            continue;
          }
          dp[i][j][l][(rem + a[i - 1][j - 1]) % k] =
              max(dp[i][j][l][(rem + a[i - 1][j - 1]) % k],
                  dp[i][j - 1][l - 1][rem] + a[i - 1][j - 1]);
          dp[i][j][l][rem] = max(dp[i][j][l][rem], dp[i][j - 1][l][rem]);
        }
      }
    }
  }
  cout << dp[n][m][W][0];
  return 0;
}
