#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > arr;
int n, m, k;
int dp[71][71][71][71];
int func(int r, int c, int moves_left, int mod) {
  if (r >= n) {
    if (mod == 0) return 0;
    return INT_MIN;
  }
  if (moves_left <= 0) {
    return func(r + 1, c + 1, m / 2, mod);
  }
  if (r == n - 1 && c == m - 1) {
    if (arr[r][c] % k == mod)
      return arr[r][c];
    else
      return INT_MIN;
  }
  int sum1 = 0, sum2 = 0;
  int temp = 10000 * k + mod;
  temp = temp - arr[r][c];
  int temp_m = temp % k;
  if (c == m - 1 || moves_left == 1) {
    if (dp[r + 1][0][m / 2][temp_m] == -2)
      dp[r + 1][0][m / 2][temp_m] = func(r + 1, 0, m / 2, temp_m);
    sum1 = dp[r + 1][0][m / 2][temp_m];
  } else {
    if (dp[r][c + 1][moves_left - 1][temp_m] == -2)
      dp[r][c + 1][moves_left - 1][temp_m] =
          func(r, c + 1, moves_left - 1, temp_m);
    sum1 = dp[r][c + 1][moves_left - 1][temp_m];
  }
  if (c == m - 1) {
    if (dp[r + 1][0][m / 2][mod] == -2)
      dp[r + 1][0][m / 2][mod] = func(r + 1, 0, m / 2, mod);
    sum2 = dp[r + 1][0][m / 2][mod];
  } else {
    if (dp[r][c + 1][moves_left][mod] == -2)
      dp[r][c + 1][moves_left][mod] = func(r, c + 1, moves_left, mod);
    sum2 = dp[r][c + 1][moves_left][mod];
  }
  if ((sum1) % k != temp_m) sum1 = INT_MIN;
  if (sum2 % k != mod) sum2 = INT_MIN;
  if (sum1 == INT_MIN && arr[r][c] % k == mod) sum1 = 0;
  dp[r][c][moves_left][mod] = max(arr[r][c] + sum1, sum2);
  if (sum1 == INT_MIN && sum2 == INT_MIN) dp[r][c][moves_left][mod] = INT_MIN;
  return dp[r][c][moves_left][mod];
}
signed main() {
  for (int x = 0; x <= 70; x++) {
    for (int y = 0; y <= 70; y++) {
      for (int z = 0; z <= 70; z++) {
        for (int w = 0; w <= 70; w++) {
          dp[x][y][z][w] = -2;
        }
      }
    }
  }
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> k;
  for (int x = 1; x <= n; x++) {
    vector<int> temp;
    for (int y = 1; y <= m; y++) {
      int a;
      cin >> a;
      temp.push_back(a);
    }
    arr.push_back(temp);
  }
  int a = func(0, 0, m / 2, 0);
  if (a == INT_MIN)
    cout << "0\n";
  else
    cout << a << "\n";
}
