#include <bits/stdc++.h>
using namespace std;
const int N = 75;
int n, m, k, a[N][N], dp[N][N][N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  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 < N; j++)
      for (int g = 0; g < N; g++)
        for (int h = 0; h < N; h++) dp[i][j][g][h] = -1;
  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] < 0) continue;
          if (j < m - 1)
            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 < m / 2) {
            if (j < m - 1)
              dp[i][j + 1][cnt + 1][(rem + a[i][j]) % k] =
                  max(dp[i][j + 1][cnt + 1][(rem + a[i][j]) % k],
                      dp[i][j][cnt][rem] + a[i][j]);
            else
              dp[i + 1][0][0][(rem + a[i][j]) % k] =
                  max(dp[i + 1][0][0][(rem + a[i][j]) % k],
                      dp[i][j][cnt][rem] + a[i][j]);
          }
        }
      }
    }
  }
  cout << max(0, dp[n][0][0][0]) << '\n';
  return 0;
}
