#include <bits/stdc++.h>
using namespace std;
long long int p = 998244353;
int dp[73][73][73][73];
int arr[80][80];
int n;
int m;
int k;
int solution(int i, int j, int count, int sum) {
  if (i == (n + 1)) {
    return 0;
  }
  if (dp[i][j][count][sum] != (-1)) {
    return dp[i][j][count][sum];
  }
  if (j == (m + 1) || count == 0) {
    return dp[i][j][count][sum] = solution(i + 1, 1, m / 2, sum);
  } else {
    int val = solution(i, j + 1, count - 1, ((sum + arr[i][j]) % k));
    if (val == 0 && (sum + arr[i][j]) % k != 0) {
      dp[i][j][count][sum] = 0;
    } else {
      dp[i][j][count][sum] = val + arr[i][j];
    }
    int val2 = solution(i, j + 1, count, sum);
    dp[i][j][count][sum] = max(dp[i][j][count][sum], val2);
  }
  return dp[i][j][count][sum];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  int x;
  x = 0;
  while (t--) {
    for (int i = 0; i < 73; i++)
      for (int j = 0; j < 73; j++)
        for (int k = 0; k < 73; k++)
          for (int l = 0; l < 73; l++) dp[i][j][k][l] = -1;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> arr[i][j];
      }
    }
    cout << solution(1, 1, (m / 2), 0);
  }
  return 0;
}
