#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
struct trans {
  long long x, y, d, t, e;
};
long long n, m, k;
vector<trans> monster;
long long cost[501][501];
vector<pair<long long, long long> > collisonRow[501][501];
vector<pair<long long, long long> > collisonCol[501][501];
long long timetoreach[501][501];
long long dp[2][501][501][2];
long long dx[] = {0, 1, 1, 0};
long long dy[] = {0, -1, 0, 1};
void addcontribution(int x) {
  int hit[4];
  memset(hit, 0, sizeof(hit));
  for (long long kk = 0; kk < (4); ++kk) {
    int xx = monster[x].x + dx[kk] * monster[x].d;
    int yy = monster[x].y + dy[kk] * monster[x].d;
    if (monster[x].t + kk <= timetoreach[xx][yy] &&
        ((monster[x].t + kk) % 4 == (timetoreach[xx][yy]) % 4)) {
      cost[xx][yy] += monster[x].e;
      hit[kk] = 1;
    }
  }
  if (hit[0] && hit[3]) {
    collisonRow[monster[x].x + dx[3] * monster[x].d]
               [monster[x].y + dy[3] * monster[x].d]
                   .emplace_back(monster[x].d + 1, monster[x].e);
  }
  if (hit[1] && hit[2]) {
    collisonRow[monster[x].x + dx[2] * monster[x].d]
               [monster[x].y + dy[2] * monster[x].d]
                   .emplace_back(monster[x].d + 1, monster[x].e);
  }
  if (hit[0] && hit[2]) {
    collisonCol[monster[x].x + dx[2] * monster[x].d]
               [monster[x].y + dy[2] * monster[x].d]
                   .emplace_back(monster[x].d + 1, monster[x].e);
  }
}
void solve() {
  cin >> n >> m >> k;
  for (long long i = 0; i < (n); ++i)
    for (long long j = 0; j < (m); ++j) timetoreach[i][j] = i + j;
  for (long long i = 0; i < (k); ++i) {
    long long x, y, d, t, e;
    cin >> x >> y >> d >> t >> e;
    monster.push_back({x, y, d, t, e});
  }
  for (long long i = 0; i < (k); ++i) {
    addcontribution(i);
  }
  for (long long i = 0; i < (2); ++i)
    for (long long j = 0; j < (m); ++j)
      for (long long len = 0; len < (max(n, m) + 1); ++len)
        for (long long dir = 0; dir < (2); ++dir)
          dp[i][j][len][dir] = MOD * MOD;
  dp[0][0][1][0] = 0;
  dp[0][0][1][1] = 0;
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      for (long long kk = 0; kk < (max(n, m) + 1); ++kk)
        for (long long dd = 0; dd < (2); ++dd) {
          dp[(i + 1) & 1][j][kk][dd] = MOD * MOD;
        }
    }
    for (long long j = 0; j < (m); ++j) {
      sort((collisonRow[i][j]).begin(), (collisonRow[i][j]).end());
      sort((collisonCol[i][j]).begin(), (collisonCol[i][j]).end());
      long long sum[] = {0, 0};
      int ptr[] = {0, 0};
      for (long long len = 1; len <= max(n, m); ++len) {
        for (long long dir = 0; dir < (2); ++dir) {
          if (dir == 0) {
            while (ptr[dir] < collisonRow[i][j].size() &&
                   collisonRow[i][j][ptr[dir]].first <= len) {
              sum[dir] += collisonRow[i][j][ptr[dir]].second;
              ptr[dir]++;
            }
            dp[i & 1][j][len][dir] -= sum[dir];
            (dp[(i + 1) & 1][j][2][1] =
                 min((dp[(i + 1) & 1][j][2][1]),
                     (dp[i & 1][j][len][dir] + cost[i + 1][j])));
            (dp[(i + 1) & 1][j][1][0] =
                 min((dp[(i + 1) & 1][j][1][0]),
                     (dp[i & 1][j][len][dir] + cost[i + 1][j])));
            (dp[i & 1][j + 1][len + 1][0] =
                 min((dp[i & 1][j + 1][len + 1][0]),
                     (dp[i & 1][j][len][dir] + cost[i][j + 1])));
            (dp[i & 1][j + 1][1][1] =
                 min((dp[i & 1][j + 1][1][1]),
                     (dp[i & 1][j][len][dir] + cost[i][j + 1])));
          } else {
            while (ptr[dir] < collisonCol[i][j].size() &&
                   collisonCol[i][j][ptr[dir]].first <= len) {
              sum[dir] += collisonCol[i][j][ptr[dir]].second;
              ptr[dir]++;
            }
            dp[i & 1][j][len][dir] -= sum[dir];
            (dp[(i + 1) & 1][j][len + 1][1] =
                 min((dp[(i + 1) & 1][j][len + 1][1]),
                     (dp[i & 1][j][len][dir] + cost[i + 1][j])));
            (dp[(i + 1) & 1][j][1][0] =
                 min((dp[(i + 1) & 1][j][1][0]),
                     (dp[i & 1][j][len][dir] + cost[i + 1][j])));
            (dp[i & 1][j + 1][2][0] =
                 min((dp[i & 1][j + 1][2][0]),
                     (dp[i & 1][j][len][dir] + cost[i][j + 1])));
            (dp[i & 1][j + 1][1][1] =
                 min((dp[i & 1][j + 1][1][1]),
                     (dp[i & 1][j][len][dir] + cost[i][j + 1])));
          }
        }
      }
    }
  }
  long long ans = MOD * MOD;
  for (long long len = 1; len <= n; ++len) {
    (ans = min((ans), (dp[(n - 1) & 1][m - 1][len][0])));
  }
  for (long long len = 1; len <= m; ++len) {
    (ans = min((ans), (dp[(n - 1) & 1][m - 1][len][0])));
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long _t = 1;
  for (long long i = 1; i <= _t; i++) {
    solve();
  }
}
