#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const long long int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
const int inf = 1e7;
int n, m, k;
int arr[100][100];
int dp[75][75][40][75];
int solve(int i, int j, int picked, int rem) {
  int &ret = dp[i][j][picked][rem];
  if (~ret) return ret;
  if (j == m) {
    if (i == n) {
      return ret = (rem ? -inf : 0);
    } else {
      return ret = solve(i + 1, 0, 0, rem);
    }
  } else {
    int ans = -inf;
    if (picked < m / 2)
      ans = max(ans,
                arr[i][j] + solve(i, j + 1, picked + 1, (rem + arr[i][j]) % k));
    ans = max(ans, solve(i, j + 1, picked, rem));
    return ret = ans;
  }
}
void cp() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  memset(dp, -1, sizeof(dp));
  int ans = solve(0, 0, 0, 0);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    cp();
  }
  return 0;
}
