#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
unsigned long long rand(unsigned long long l, unsigned long long r) {
  uniform_int_distribution<unsigned long long> uid(l, r);
  return uid(rng);
}
const long long N = 505;
const long long K = 5e5 + 5;
long long dp[N][N][2], val[N][N], val1[N][N];
long long rowval[N], rowval1[N];
vector<long long> trans[N][N][4];
long long X[K], Y[K], D[K], T[K], E[K];
bitset<K> col[N];
bitset<K> row;
void sc(long long &x) {
  bool neg = false;
  register long long c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  if (neg) x *= -1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, k;
  sc(n), sc(m), sc(k);
  if (n == 1 || m == 1) {
    printf("0");
    return 0;
  }
  for (long long i = 1; i <= k; i++) {
    sc(X[i]), sc(Y[i]), sc(D[i]), sc(T[i]), sc(E[i]);
    X[i]++, Y[i]++;
    if (X[i] + Y[i] - 2 >= T[i]) trans[X[i]][Y[i]][T[i] & 3].push_back(i);
    if (X[i] + Y[i] - 2 >= T[i] + 1)
      trans[X[i] + D[i]][Y[i] - D[i]][(T[i] + 1) & 3].push_back(i);
    if (X[i] + Y[i] + D[i] - 2 >= T[i] + 2)
      trans[X[i] + D[i]][Y[i]][(T[i] + 2) & 3].push_back(i);
    if (X[i] + Y[i] + D[i] - 2 >= T[i] + 3)
      trans[X[i]][Y[i] + D[i]][(T[i] + 3) & 3].push_back(i);
  }
  for (long long i = 1; i <= n; i++) {
    row.reset();
    for (long long j = 1; j <= m; j++) {
      rowval[j] = rowval1[j] = 0;
    }
    for (long long j = 1; j <= m; j++) {
      dp[i][j][0] = dp[i][j][1] = 1e18;
      if (i == 1 && j == 1) {
        dp[i][j][0] = dp[i][j][1] = 0;
        continue;
      }
      long long t = (i + j - 2) & 3;
      for (long long &idx : trans[i][j][t]) {
        if (!row[idx]) {
          row[idx] = 1;
          rowval[j] += E[idx];
        } else {
          rowval[j] += E[idx];
          rowval[j - D[idx]] -= E[idx];
          rowval1[j - D[idx]] += E[idx];
        }
        if (!col[j][idx]) {
          col[j][idx] = 1;
          val[i][j] += E[idx];
        } else {
          val[i][j] += E[idx];
          val[i - D[idx]][j] -= E[idx];
          val1[i - D[idx]][j] += E[idx];
        }
      }
      long long cost = 0;
      for (long long k = j; k >= 2; k--) {
        cost += rowval[k];
        long long cost1 = cost - rowval1[k - 1];
        dp[i][j][0] = min(dp[i][j][0], dp[i][k - 1][1] + cost1);
        t = (t + 3) & 3;
      }
      t = (i + j - 2) & 3;
      cost = 0;
      for (long long k = i; k >= 2; k--) {
        cost += val[k][j];
        long long cost1 = cost - val1[k - 1][j];
        dp[i][j][1] = min(dp[i][j][1], dp[k - 1][j][0] + cost1);
        t = (t + 3) & 3;
      }
    }
  }
  printf("%lld", min(dp[n][m][0], dp[n][m][1]));
  return 0;
}
