#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
long long a[505][505], DP[505][505][2];
int N, M, K;
vector<pair<int, int>> hor[505];
vector<pair<pair<int, int>, int>> pos[505][505], ver[505];
int ok(int first, int second, int t) {
  return (first + second) >= t && (first + second) % 4 == t % 4;
}
int main() {
  scanf("%d %d %d", &N, &M, &K);
  int i, j, k;
  for (i = 1; i <= K; ++i) {
    int first, second, d, t, e;
    scanf("%d %d %d %d %d", &first, &second, &d, &t, &e);
    int top_left = ok(first, second, t);
    int top_right = ok(first, second + d, t + 3);
    int bottom_left = ok(first + d, second - d, t + 1);
    int bottom_right = ok(first + d, second, t + 2);
    if (top_left) a[first][second] += e;
    if (top_right) a[first][second + d] += e;
    if (bottom_left) a[first + d][second - d] += e;
    if (bottom_right) a[first + d][second] += e;
    if (top_left && top_right) {
      hor[first].emplace_back(second + d, e);
      pos[first][second].push_back({{first, second + d}, e});
    }
    if (top_left && bottom_right) {
      a[first + d][second] -= e;
      ver[first].push_back({{first + d, second}, e});
    }
    if (bottom_left && bottom_right) {
      hor[first + d].emplace_back(second, e);
      pos[first + d][second - d].push_back({{first + d, second}, e});
    }
  }
  for (i = 0; i < N; ++i) {
    for (j = 0; j < M; ++j) {
      for (k = 0; k < 2; ++k) {
        DP[i][j][k] = INF;
      }
    }
  }
  for (k = 0; k < 2; ++k) DP[0][0][k] = a[0][0];
  for (i = 0; i < N; ++i) {
    for (pair<int, int>& e : hor[i]) a[i][e.first] -= e.second;
    for (j = 0; j < M; ++j) {
      long long cost = 0;
      for (k = i + 1; k < N; ++k) {
        cost += a[k][j];
        DP[k][j][1] = min(DP[k][j][1], DP[i][j][0] + cost);
      }
      cost = 0;
      for (k = j + 1; k < M; ++k) {
        cost += a[i][k];
        DP[i][k][0] = min(DP[i][k][0], DP[i][j][1] + cost);
      }
      for (pair<pair<int, int>, int>& e : pos[i][j])
        a[e.first.first][e.first.second] += e.second;
    }
    for (pair<pair<int, int>, int>& e : ver[i])
      a[e.first.first][e.first.second] += e.second;
  }
  long long ret = min(DP[N - 1][M - 1][0], DP[N - 1][M - 1][1]);
  printf("%lld\n", ret);
}
