#include <bits/stdc++.h>
using namespace std;
const int N = 72;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
long long a[N][N], f[N][N][N], n, m, k, ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int r = 1; r < N; r++) f[i][j][r] = -INF;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++) {
    for (int r = 0; r < k; r++)
      for (int j = 0; j <= m / 2; j++)
        f[i][0][r] = max(f[i][0][r], f[i - 1][j][r]);
    ans = max(ans, f[i][0][0]);
    for (int x = 1; x <= m; x++) {
      for (int j = m / 2; j >= 1; j--) {
        for (int r = 0; r < k; r++) {
          long long p = (r - a[i][x] + k * INF) % k;
          f[i][j][r] = max(f[i][j][r], f[i][j - 1][p] + a[i][x]);
        }
        ans = max(ans, f[i][j][0]);
      }
    }
  }
  cout << ans << endl;
}
