#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  for (char& c : s) c = c == ',' ? ' ' : c;
  stringstream ss;
  ss << s;
  vector<string> res;
  for (string z; ss >> z; res.push_back(z))
    ;
  return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
  if (idx > 0) cerr << ", ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, T...);
}
void localTest() {}
const long long N = 71, inf = 1e16;
long long n, m, k, A[N][N], dp[N][N][N][N];
long long doit(long long x, long long y, long long sum, long long cnt) {
  if (x > n) {
    if (!sum) {
      return 0;
    }
    return -inf;
  }
  if (cnt == m / 2 || y > m) {
    return doit(x + 1, 1, sum, 0);
  }
  long long& ret = dp[x][y][sum][cnt];
  if (ret != -1) {
    return ret;
  }
  long long ans = doit(x, y + 1, sum, cnt);
  ans = max(ans, A[x][y] + doit(x, y + 1, (sum + A[x][y]) % k, cnt + 1));
  return ret = ans;
}
int main() {
  localTest();
  memset(dp, -1, sizeof dp);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      cin >> A[i][j];
    }
  }
  cout << doit(1, 1, 0, 0) << "\n";
  return 0;
}
