#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int mod = 1e9 + 7;
int n, m, T, k;
int f[80][80][80][80], g[80][80];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> g[i][j];
  memset(f, -1, sizeof f);
  f[1][0][0][0] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= m; j++)
      for (int l = 0; l <= m / 2; l++) {
        for (int r = 0; r < k; r++) {
          if (j >= 1) {
            f[i][j][l][r] = max(f[i][j][l][r], f[i][j - 1][l][r]);
            if (f[i][j - 1][l][r] != -1)
              f[i][j][l + 1][(r + g[i][j]) % k] =
                  max(f[i][j][l + 1][(r + g[i][j]) % k],
                      f[i][j - 1][l][r] + g[i][j]);
          }
        }
        for (int r = 0; r < k; r++)
          f[i + 1][0][0][r] = max(f[i + 1][0][0][r], f[i][j][l][r]);
      }
  cout << max(0, f[n + 1][0][0][0]) << endl;
  return 0;
}
