#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template <typename T>
using p = pair<T, T>;
int dp[71][71][36][71];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> mat(n, vector<int>(m));
  for (auto &i : mat)
    for (auto &j : i) cin >> j;
  for (int i = n; i >= 0; --i) {
    for (int j = m; j >= 0; --j) {
      for (int num = m / 2; num >= 0; --num) {
        for (int sum = k - 1; sum >= 0; --sum) {
          int &ans = dp[i][j][num][sum];
          if (i == n) {
            if (sum == 0)
              ans = 0;
            else
              ans = -0x3f3f3f3f;
          } else if (j == m) {
            ans = dp[i + 1][0][0][sum];
          } else if (num == m / 2) {
            ans = dp[i][j + 1][num][sum];
          } else {
            ans = max(dp[i][j + 1][num + 1][(sum + mat[i][j]) % k] + mat[i][j],
                      dp[i][j + 1][num][sum]);
          }
        }
      }
    }
  }
  cout << dp[0][0][0][0] << '\n';
  return 0;
}
