#include <bits/stdc++.h>
using namespace std;
long long row[71][71][71][71], pr[71][71], sl[71][71], a[71][71];
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  for (int i = 0; i <= 70; ++i)
    for (int j = 0; j <= 70; ++j)
      for (int z = 0; z <= 70; ++z)
        for (int t = 0; t <= 70; ++t) row[i][j][z][t] = INT_MIN;
  for (int i = 0; i < 71; ++i)
    for (int j = 0; j < 71; ++j) pr[i][j] = INT_MIN, sl[i][j] = INT_MIN;
  for (int i = 1; i <= n; ++i) {
    row[i][0][0][0] = 0;
    for (int j = 1; j <= m; ++j) {
      for (int z = 0; z <= m / 2; ++z) {
        for (int t = 0; t < k; ++t) {
          row[i][j][z][t] = max(row[i][j - 1][z][t], row[i][j][z][t]);
          row[i][j][z + 1][(t + a[i][j]) % k] =
              max(row[i][j][z + 1][(t + a[i][j]) % k],
                  row[i][j - 1][z][t] + a[i][j]);
        }
      }
    }
    for (int t = 0; t <= k; ++t) {
      for (int z = 0; z <= m / 2; ++z) {
        pr[i][t] = max(pr[i][t], row[i][m][z][t]);
      }
    }
  }
  sl[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      for (int z = 0; z < k; ++z) {
        sl[i][(j + z) % k] = max(sl[i][(j + z) % k], sl[i - 1][j] + pr[i][z]);
      }
    }
  }
  cout << sl[n][0];
}
int main() { solve(); }
