#include <bits/stdc++.h>
using namespace std;
const int N = 505, K = 5e5 + 100;
int n, m, k;
int x[K], y[K], d[K], appeartime[K], e[K];
bool ok[4][K];
vector<int> bots[2][N][N];
vector<long long> psum[2][N][N];
int dx[] = {0, 1, 1, 0};
int dy[] = {0, -1, 0, 1};
long long dp[N][N][2], zo[N][N];
int timer;
int taketime[K];
int curptr[2][N][N];
bool cmp(int a, int b) { return d[a] < d[b]; }
int main() {
  scanf("%d", &n), scanf("%d", &m), scanf("%d", &k);
  long long con = 0;
  for (int i = 0; i < k; ++i) {
    scanf("%d", &x[i]), scanf("%d", &y[i]), scanf("%d", &d[i]),
        scanf("%d", &appeartime[i]), scanf("%d", &e[i]);
    if (appeartime[i] == 0 && x[i] == 0 && y[i] == 0) con += e[i];
    for (int z = 0; z < 4; ++z) {
      int ti = x[i] + dx[z] * d[i];
      int tj = y[i] + dy[z] * d[i];
      if (ti + tj >= appeartime[i] + z &&
          (ti + tj - appeartime[i] - z) % 4 == 0) {
        ok[z][i] = 1;
        zo[ti][tj] += e[i];
        if (z == 2 && ok[1][i]) bots[0][ti][tj].push_back(i);
        if (z == 3 && ok[0][i]) bots[0][ti][tj].push_back(i);
        if (z == 2 && ok[0][i]) bots[1][ti][tj].push_back(i);
      }
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      for (int z = 0; z < 2; ++z) {
        sort(bots[z][i][j].begin(), bots[z][i][j].end(), cmp);
        psum[z][i][j].resize(bots[z][i][j].size());
        for (int r = 0; r < bots[z][i][j].size(); r++)
          psum[z][i][j][r] =
              e[bots[z][i][j][r]] + (r ? psum[z][i][j][r - 1] : 0);
        curptr[z][i][j] = -1;
      }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = (i == n - 1 ? m - 2 : m - 1); j >= 0; j--) {
      dp[i][j][0] = 1e18;
      long long sum = 0;
      for (int tj = j + 1; tj < m; tj++) {
        sum += zo[i][tj];
        int jmp = tj - j;
        int& ptr = curptr[0][i][tj];
        while (ptr + 1 < bots[0][i][tj].size() &&
               jmp >= d[bots[0][i][tj][ptr + 1]])
          ptr++;
        if (ptr != -1) sum -= psum[0][i][tj][ptr];
        dp[i][j][0] = min(dp[i][j][0], sum + dp[i][tj][1]);
      }
      dp[i][j][1] = 1e18;
      sum = 0;
      for (int ti = i + 1; ti < n; ti++) {
        sum += zo[ti][j];
        int jmp = ti - i;
        int& ptr = curptr[1][ti][j];
        while (ptr + 1 < bots[1][ti][j].size() &&
               jmp >= d[bots[1][ti][j][ptr + 1]])
          ptr++;
        if (ptr != -1) sum -= psum[1][ti][j][ptr];
        dp[i][j][1] = min(dp[i][j][1], sum + dp[ti][j][0]);
      }
    }
  }
  printf("%lld\n", min(dp[0][0][0], dp[0][0][1]) + con);
}
