#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int maxn = 500 + 10;
constexpr ll inf = 0x3f3f3f3f3f3f3f3fll;
int n, m;
ll (*dp)[2][maxn][maxn] = {};
ll killed[maxn][maxn];
vector<pair<int, ll>> saves_left[maxn][maxn];
vector<pair<int, ll>> saves_up[maxn][maxn];
ll kill_cost(int i, int j) { return killed[i][j]; }
ll saved_cost_left(int i, int j, int k) {
  while (saves_left[i][j].size() > 1 &&
         saves_left[i][j].rbegin()[1].first <= k) {
    saves_left[i][j].rbegin()[1].second += saves_left[i][j].rbegin()[0].second;
    saves_left[i][j].pop_back();
  }
  return saves_left[i][j].empty() ? 0 : saves_left[i][j].back().second;
}
ll saved_cost_up(int i, int j, int k) {
  while (saves_up[i][j].size() > 1 && saves_up[i][j].rbegin()[1].first <= k) {
    saves_up[i][j].rbegin()[1].second += saves_up[i][j].rbegin()[0].second;
    saves_up[i][j].pop_back();
  }
  return saves_up[i][j].empty() ? 0 : saves_up[i][j].back().second;
}
void add_monster(int i, int j, int d, int t, int e) {
  bool top = (i + j - t + 1024) % 4 == 0 && (t <= i + j),
       left = (i + j - t - 1 + 1024) % 4 == 0 && (t + 1 <= i + j),
       bottom = (i + j + d - t - 2 + 1024) % 4 == 0 && (t + 2 <= i + j + d),
       right = (i + j + d - t - 3 + 1024) % 4 == 0 && (t + 3 <= i + j + d);
  if (top) killed[i][j] += e;
  if (left) killed[i + d][j - d] += e;
  if (bottom) killed[i + d][j] += e;
  if (right) killed[i][j + d] += e;
  if (top && right) saves_left[i][j + d].emplace_back(d, e);
  if (top && bottom) saves_up[i + d][j].emplace_back(d, e);
  if (left && bottom) saves_left[i + d][j].emplace_back(d, e);
}
void finalise_monsters() {
  for (auto& x : saves_up)
    for (auto& y : x) {
      sort(y.rbegin(), y.rend());
      y.emplace_back(0, 0);
    }
  for (auto& x : saves_left)
    for (auto& y : x) {
      sort(y.rbegin(), y.rend());
      y.emplace_back(0, 0);
    }
}
ll calc_dp() {
  memset(dp, 0x3f, 2 * sizeof(*dp));
  for (int i = 0; i < n; ++i) {
    memset(dp[i % 2], 0x3f, sizeof(dp[i % 2]));
    if (i == 0)
      for (int k = 0; k < 1; ++k)
        dp[(0) % 2][0][0][k] = dp[(0) % 2][1][0][k] = kill_cost(0, 0);
    for (int j = (i == 0 ? 1 : 0); j < m; ++j) {
      for (int k = 1; k < maxn; ++k) {
        if (j > 0)
          dp[(i) % 2][1][j][k] = dp[(i) % 2][1][j - 1][k - 1] +
                                 kill_cost(i, j) - saved_cost_left(i, j, k);
        if (i > 0)
          dp[(i) % 2][0][j][k] = dp[(i - 1) % 2][0][j][k - 1] +
                                 kill_cost(i, j) - saved_cost_up(i, j, k);
      }
      for (int k = maxn - 2; k >= 0; --k) {
        for (int x = 0; x < 2; ++x) {
          dp[(i) % 2][x][j][k] =
              min(dp[(i) % 2][x][j][k], dp[(i) % 2][x][j][k + 1]);
        }
      }
      dp[i % 2][0][j][0] = dp[i % 2][1][j][0] =
          min(dp[i % 2][0][j][1], dp[i % 2][1][j][1]);
    }
  }
  return dp[(n - 1) % 2][0][m - 1][0];
}
int main() {
  dp = decltype(dp)(malloc(2 * sizeof(*dp)));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int k;
  cin >> n >> m >> k;
  while (k--) {
    int i, j, d, t, e;
    cin >> i >> j >> d >> t >> e;
    if (e) add_monster(i, j, d, t, e);
  }
  finalise_monsters();
  cout << calc_dp() << endl;
  ;
  return 0;
}
