#include <bits/stdc++.h>
using namespace std;
struct mob {
  int l, r, e;
};
long long dp[501][501], sum[501][501], sx[501][501], sy[501][501], dx[501][501],
    dy[501][501];
vector<pair<int, int> > mx[501][501], my[501][501];
bool add(int x, int y, int t, int e) {
  if ((x + y - 2) >= t && t % 4 == (x + y - 2) % 4) {
    sum[x][y] += e;
    return true;
  }
  return false;
}
int main(void) {
  int nx, ny, k;
  scanf("%d%d%d", &nx, &ny, &k);
  for (int i = 1; i <= k; ++i) {
    int x, y, d, t, e;
    scanf("%d%d%d%d%d", &x, &y, &d, &t, &e);
    x++;
    y++;
    if (add(x, y, t, e)) {
      if (d % 4 == 2) my[x + d][y].push_back({d, e});
      if (d % 4 == 3) mx[x][y + d].push_back({d, e});
    }
    if (add(x + d, y - d, t + 1, e)) {
      if (d % 4 == 1) mx[x + d][y].push_back({d, e});
    }
    add(x + d, y, t + 2, e);
    add(x, y + d, t + 3, e);
  }
  for (int i = 1; i <= nx; ++i) {
    for (int j = 1; j <= ny; ++j) {
      sx[i][j] = sum[i][j] + sx[i][j - 1];
      sy[i][j] = sum[i][j] + sy[i - 1][j];
    }
  }
  for (int i = 1; i <= nx; ++i) dp[i][0] = LLONG_MAX;
  for (int j = 1; j <= ny; ++j) dp[0][j] = LLONG_MAX;
  for (int i = 1; i <= nx; ++i) {
    for (int j = 1; j <= ny; ++j) {
      if (i == 1 && j == 1) {
        dp[i][j] = sum[i][j];
        continue;
      } else
        dp[i][j] = LLONG_MAX;
      for (pair<int, int> p : mx[i][j]) dx[i][j - p.first] += p.second;
      for (pair<int, int> p : my[i][j]) dy[i - p.first][j] += p.second;
      long long vx = 0, vy = 0;
      for (int k = 1; k < j; ++k) {
        vx += dx[i][j - k];
        dp[i][j] = min(dp[i][j], dp[i][j - k] + sx[i][j] - sx[i][j - k] - vx);
      }
      for (int k = 1; k < i; ++k) {
        vy += dy[i - k][j];
        dp[i][j] = min(dp[i][j], dp[i - k][j] + sy[i][j] - sy[i - k][j] - vy);
      }
    }
  }
  printf("%lld\n", dp[nx][ny]);
  return 0;
}
