#include <bits/stdc++.h>
using namespace std;
const int N = 505;
long long dp[N][N][2], C[N][N], a[N];
int dir[4][2] = {{0, 0}, {1, -1}, {1, 0}, {0, 1}};
vector<pair<int, int> > L[N][N], U[N][N];
bitset<4> mark;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    int x, y, t, d, e;
    cin >> x >> y >> d >> t >> e, mark = 0;
    for (int j = 0; j < 4; j++) {
      int sum = x + dir[j][0] * d + y + dir[j][1] * d;
      if (sum >= t + j && sum % 4 == (t + j) % 4) mark[j] = 1;
    }
    for (int j = 0; j < 4; j++)
      if (mark[j]) C[x + dir[j][0] * d][y + dir[j][1] * d] += e;
    if (mark[0] == 1 && mark[2] == 1) U[x + d][y].push_back({x, e});
    if (mark[0] == 1 && mark[3] == 1) L[x][y + d].push_back({y, e});
    if (mark[1] == 1 && mark[2] == 1) L[x + d][y].push_back({y - d, e});
  }
  memset(dp, 63, sizeof dp);
  dp[0][0][0] = dp[0][0][1] = C[0][0];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long cost = C[i][j];
      for (pair<int, int> p : U[i][j]) a[p.first] += p.second;
      for (int k = i - 1; k >= 0; k--) {
        cost -= a[k];
        dp[i][j][0] = min(dp[i][j][0], dp[k][j][1] + cost);
        cost += C[k][j];
        for (pair<int, int> p : U[k][j]) a[p.first] += p.second;
      }
      for (int k = 0; k < i; k++) a[k] = 0;
      cost = C[i][j];
      for (pair<int, int> p : L[i][j]) a[p.first] += p.second;
      for (int k = j - 1; k >= 0; k--) {
        cost -= a[k];
        dp[i][j][1] = min(dp[i][j][1], dp[i][k][0] + cost);
        cost += C[i][k];
        for (pair<int, int> p : L[i][k]) a[p.first] += p.second;
      }
      for (int k = 0; k < j; k++) a[k] = 0;
    }
  }
  cout << min(dp[n - 1][m - 1][0], dp[n - 1][m - 1][1]) << "\n";
}
