#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 100;
const int mod = 998244353;
int n, k, m;
long long dp[510][510][2];
vector<pair<int, int> > g[550][550];
int p[maxn];
vector<pair<int, int> > pp[maxn];
long long dx[550], dy[550];
void solve(int x, int y) {
  long long sum = 0;
  memset(dx, 0, sizeof(dx));
  memset(dy, 0, sizeof(dy));
  for (auto to : g[x][y]) {
    int id = to.first;
    if (to.second == 2) {
      for (auto son : pp[id]) {
        if (son.second == y) {
          dx[son.first] += p[id];
        }
        if (son.first == x) {
          dy[son.second] += p[id];
        }
      }
    }
    if (to.second == 3) {
      for (auto son : pp[id]) {
        if (son.first == x) dy[son.second] += p[id];
      }
    }
    sum += p[id];
  }
  if (x == 0 && y == 0) {
    dp[x][y][0] = dp[x][y][1] = sum;
    return;
  }
  for (int i = x; i >= 0; i--) dx[i] += dx[i + 1];
  for (int i = y; i >= 0; i--) dy[i] += dy[i + 1];
  long long v = 1e16;
  for (int i = 0; i <= x - 1; i++) {
    dp[i][y][1] += sum - dx[i];
    v = min(v, dp[i][y][1]);
  }
  for (int i = 0; i <= y - 1; i++) {
    dp[x][i][0] += sum - dy[i];
    v = min(v, dp[x][i][0]);
  }
  dp[x][y][0] = dp[x][y][1] = v;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &k);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      for (int z = 0; z <= 1; z++) dp[i][j][z] = 1e16;
  for (int i = 1; i <= k; i++) {
    int x, y, d, t, e;
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &d);
    scanf("%d", &t);
    scanf("%d", &e);
    p[i] = e;
    int tim = x + y;
    if (tim >= t && (tim - t) % 4 == 0) {
      g[x][y].push_back(make_pair(i, 0));
      pp[i].push_back(make_pair(x, y));
    }
    if (tim >= t && (tim - t) % 4 == 1) {
      g[x + d][y - d].push_back(make_pair(i, 1));
      pp[i].push_back(make_pair(x + d, y - d));
    }
    tim = x + d + y;
    if (tim >= t && (tim - t) % 4 == 2) {
      g[x + d][y].push_back(make_pair(i, 2));
    }
    if (tim >= t && (tim - t) % 4 == 3) {
      g[x][y + d].push_back(make_pair(i, 3));
    }
  }
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j <= m - 1; j++) {
      solve(i, j);
    }
  }
  printf("%lld\n", dp[n - 1][m - 1][0]);
  return 0;
}
