#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, val, a[70][70];
  cin >> n >> m >> val;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  int ans = 0, k, maxm = 4900, dp[4901];
  int prev[70] = {0}, occ[70], v[70];
  for (int i = 0; i < n; i++) {
    int sum = 0;
    memset(dp, -1, sizeof(dp));
    memset(v, 0, sizeof(v));
    memset(occ, 0, sizeof(occ));
    dp[0] = 0;
    for (int j = 0; j < m; j++) {
      for (int k = maxm; k >= 0; k--) {
        if (dp[k] == -1) continue;
        if (dp[k + a[i][j]] == -1) dp[k + a[i][j]] = dp[k] + 1;
        dp[k + a[i][j]] = min(dp[k] + 1, dp[k + a[i][j]]);
        if (dp[k + a[i][j]] <= m / 2) {
          v[(k + a[i][j]) % val] = max(v[(k + a[i][j]) % val], k + a[i][j]);
        }
      }
    }
    for (int j = 0; j < 70; j++) {
      if (!prev[j] && j != 0) continue;
      for (int k = 0; k < 70; k++) {
        occ[(j + v[k]) % val] = max(prev[j] + v[k], occ[(j + v[k]) % val]);
      }
    }
    for (int j = 0; j < 70; j++) prev[j] = max(occ[j], prev[j]);
  }
  cout << prev[0];
  return 0;
}
