#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXH = 500;
const int MAXW = 500;
const int MAXGUARD = 500000;
int h, w, nguard;
int gx[MAXGUARD], gy[MAXGUARD], gd[MAXGUARD], gt[MAXGUARD], ge[MAXGUARD];
long long cost[MAXH][MAXW];
vector<pair<int, int>> horsave[MAXH][MAXW];
vector<pair<int, int>> versave[MAXH][MAXW];
long long hordp[MAXW][MAXW], nhordp[MAXW][MAXW];
long long verdp[MAXW][MAXH], nverdp[MAXW][MAXH];
long long chorsave[MAXW], cversave[MAXH];
long long solve() {
  for (int x = (0); x < (h); ++x)
    for (int y = (0); y < (w); ++y) cost[x][y] = 0;
  for (int x = (0); x < (h); ++x)
    for (int y = (0); y < (w); ++y) horsave[x][y].clear();
  for (int x = (0); x < (h); ++x)
    for (int y = (0); y < (w); ++y) versave[x][y].clear();
  for (int i = (0); i < (nguard); ++i) {
    int ax = gx[i], ay = gy[i], at = gt[i];
    int bx = gx[i] + gd[i], by = gy[i] - gd[i], bt = gt[i] + 1;
    int cx = gx[i] + gd[i], cy = gy[i], ct = gt[i] + 2;
    int dx = gx[i], dy = gy[i] + gd[i], dt = gt[i] + 3;
    bool hita = false;
    if ((ax + ay) % 4 == at % 4 && at <= ax + ay) hita = true, at = ax + ay;
    bool hitb = false;
    if ((bx + by) % 4 == bt % 4 && bt <= bx + by) hitb = true, bt = bx + by;
    bool hitc = false;
    if ((cx + cy) % 4 == ct % 4 && ct <= cx + cy) hitc = true, ct = cx + cy;
    bool hitd = false;
    if ((dx + dy) % 4 == dt % 4 && dt <= dx + dy) hitd = true, dt = dx + dy;
    if (hita) cost[ax][ay] += ge[i];
    if (hitb) cost[bx][by] += ge[i];
    if (hitc) {
      cost[cx][cy] += ge[i];
      if (hita) versave[cx][cy].push_back(make_pair(ax, ge[i]));
      if (hitb) horsave[cx][cy].push_back(make_pair(by, ge[i]));
    }
    if (hitd) {
      cost[dx][dy] += ge[i];
      if (hita) horsave[dx][dy].push_back(make_pair(ay, ge[i]));
    }
  }
  for (int x = (0); x < (h); ++x) {
    for (int y = (0); y < (w); ++y) {
      for (int k = (0); k <= (y); ++k) chorsave[k] = 0;
      for (int i = (0); i < (((int)(horsave[x][y]).size())); ++i)
        chorsave[horsave[x][y][i].first] += horsave[x][y][i].second;
      for (int k = y; k > 0; --k) chorsave[k - 1] += chorsave[k];
      for (int k = (0); k <= (x); ++k) cversave[k] = 0;
      for (int i = (0); i < (((int)(versave[x][y]).size())); ++i)
        cversave[versave[x][y][i].first] += versave[x][y][i].second;
      for (int k = x; k > 0; --k) cversave[k - 1] += cversave[k];
      nhordp[y][y] = x == 0 && y == 0 ? cost[x][y] : LLONG_MAX;
      for (int k = (0); k < (x); ++k)
        if (verdp[y][k] != LLONG_MAX)
          nhordp[y][y] =
              min(nhordp[y][y], verdp[y][k] + cost[x][y] - cversave[k]);
      for (int k = (0); k < (y); ++k)
        nhordp[y][k] = nhordp[y - 1][k] == LLONG_MAX
                           ? LLONG_MAX
                           : nhordp[y - 1][k] + cost[x][y] - chorsave[k];
      nverdp[y][x] = x == 0 && y == 0 ? cost[x][y] : LLONG_MAX;
      for (int k = (0); k < (y); ++k)
        if (nhordp[y - 1][k] != LLONG_MAX)
          nverdp[y][x] =
              min(nverdp[y][x], nhordp[y - 1][k] + cost[x][y] - chorsave[k]);
      for (int k = (0); k < (x); ++k)
        nverdp[y][k] = verdp[y][k] == LLONG_MAX
                           ? LLONG_MAX
                           : verdp[y][k] + cost[x][y] - cversave[k];
    }
    for (int y = (0); y < (w); ++y)
      for (int k = (0); k <= (y); ++k) hordp[y][k] = nhordp[y][k];
    for (int y = (0); y < (w); ++y)
      for (int k = (0); k <= (x); ++k) verdp[y][k] = nverdp[y][k];
  }
  long long ret = LLONG_MAX;
  for (int k = (0); k < (w); ++k) ret = min(ret, hordp[w - 1][k]);
  for (int k = (0); k < (h); ++k) ret = min(ret, verdp[w - 1][k]);
  return ret;
}
void run() {
  scanf("%d%d%d", &h, &w, &nguard);
  for (int i = (0); i < (nguard); ++i)
    scanf("%d%d%d%d%d", &gx[i], &gy[i], &gd[i], &gt[i], &ge[i]);
  printf("%lld\n", solve());
}
int main() {
  run();
  return 0;
}
