#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const int N = 71;
int dp[N][N][N][N];
const int INF = -1e9;
void solve() {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++)
        for (int x = 0; x < N; x++) dp[i][j][k][x] = INF;
  dp[0][0][0][0] = 0;
  int n, m, k;
  cin >> n >> m >> k;
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  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;
          int x = j == m - 1 ? i + 1 : i;
          int y = j == m - 1 ? 0 : j + 1;
          if (x != i)
            dp[x][y][0][rem] = max(dp[x][y][0][rem], dp[i][j][cnt][rem]);
          else
            dp[x][y][cnt][rem] = max(dp[x][y][cnt][rem], dp[i][j][cnt][rem]);
          if (cnt + 1 <= m / 2) {
            int nrem = (rem + a[i][j]) % k;
            if (i != x)
              dp[x][y][0][nrem] =
                  max(dp[x][y][0][nrem], dp[i][j][cnt][rem] + a[i][j]);
            else
              dp[x][y][cnt + 1][nrem] =
                  max(dp[x][y][cnt + 1][nrem], dp[i][j][cnt][rem] + a[i][j]);
          }
        }
      }
    }
  }
  cout << max(0, dp[n][0][0][0]) << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T = 1;
  for (int i = 1; i <= T; i++) {
    solve();
  }
}
