#include <bits/stdc++.h>
using namespace std;
const int MAX = 72;
int dp[MAX][MAX][MAX][MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  static const int INF = 1e6;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int cnt = 0; cnt <= m / 2; ++cnt) {
        for (int rem = 0; rem < k; ++rem) {
          dp[i][j][cnt][rem] = -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; ++cnt) {
        for (int rem = 0; rem < k; ++rem) {
          if (dp[i][j][cnt][rem] == -INF) {
            continue;
          }
          int ni = (j == m - 1 ? i + 1 : i);
          int nj = (j == m - 1 ? 0 : j + 1);
          if (i != ni) {
            dp[ni][nj][0][rem] = max(dp[ni][nj][0][rem], dp[i][j][cnt][rem]);
          } else {
            dp[ni][nj][cnt][rem] =
                max(dp[ni][nj][cnt][rem], dp[i][j][cnt][rem]);
          }
          if (cnt + 1 <= m / 2) {
            int nrem = (rem + a[i][j]) % k;
            if (i != ni) {
              dp[ni][nj][0][nrem] =
                  max(dp[ni][nj][0][nrem], dp[i][j][cnt][rem] + a[i][j]);
            } else {
              dp[ni][nj][cnt + 1][nrem] =
                  max(dp[ni][nj][cnt + 1][nrem], dp[i][j][cnt][rem] + a[i][j]);
            }
          }
        }
      }
    }
  }
  cout << max(dp[n][0][0][0], 0) << '\n';
  return 0;
}
