#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 105;
int s[maxn][maxn], ans[maxn][maxn];
int dp[55][5005], f[maxn][5005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> s[i][j];
  memset(ans, -1, sizeof ans);
  for (int i = 0; i <= n; i++) ans[i][0] = 0;
  for (int line = 1; line <= n; line++) {
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for (int i = 1; i <= m; i++) {
      for (int j = m / 2; j >= 1; j--) {
        for (int k = i * 70; k >= s[line][i]; k--) {
          if (dp[j - 1][k - s[line][i]]) dp[j][k] = 1;
        }
      }
    }
    for (int i = 0; i <= m / 2; i++)
      for (int j = 0; j <= 4900; j++)
        if (dp[i][j]) ans[line][j % k] = max(ans[line][j % k], j);
  }
  memset(f, -1, sizeof f);
  for (int i = 0; i <= n; i++) f[i][0] = 0;
  for (int i = 0; i < k; i++) f[1][i] = ans[1][i];
  for (int i = 2; i <= n; i++)
    for (int j = 0; j < k; j++)
      for (int l = i * k; l >= j; l--)
        if (f[i - 1][l - j] != -1 && ans[i][j] != -1) {
          f[i][l] = max(f[i][l], f[i - 1][l - j] + ans[i][j]);
        }
  int res = 0;
  for (int i = 0; i <= n; i++) res = max(res, f[n][i * k]);
  cout << res << '\n';
}
