#include <bits/stdc++.h>
using namespace std;
int const INF = (int)1e9 + 1e3;
long long const INFL = (long long)1e18 + 1e6;
mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
uniform_int_distribution<long long> ll_distr;
long long rnd(long long a, long long b) {
  return ll_distr(tw) % (b - a + 1) + a;
}
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<long long>> here(n, vector<long long>(m));
  vector<vector<vector<pair<int, int>>>> prev_h(
      n, vector<vector<pair<int, int>>>(m)),
      prev_v(n, vector<vector<pair<int, int>>>(m));
  for (int i = 0; i < k; ++i) {
    int x, y, d, t, e;
    cin >> x >> y >> d >> t >> e;
    vector<pair<int, int>> positions = {
        {x, y}, {x + d, y - d}, {x + d, y}, {x, y + d}};
    for (int j = 0; j < 4; ++j) {
      auto [cx, cy] = positions[j];
      if ((t + j) % 4 == (cx + cy) % 4 && t + j <= cx + cy) {
        here[cx][cy] += e;
      }
    }
    if (d % 4 == 1) {
      if ((t + 2) % 4 == (x + d + y) % 4 && t + 1 <= x + d + y - d) {
        prev_h[x + d][y].push_back({d, e});
      }
    } else if (d % 4 == 2) {
      if ((t + 2) % 4 == (x + d + y) % 4 && t <= x + y) {
        prev_v[x + d][y].push_back({d, e});
      }
    } else if (d % 4 == 3) {
      if ((t + 3) % 4 == (x + y + d) % 4 && t <= x + y) {
        prev_h[x][y + d].push_back({d, e});
      }
    }
  }
  vector<vector<vector<vector<long long>>>> dp(
      2, vector<vector<vector<long long>>>(
             2, vector<vector<long long>>(
                    m, vector<long long>(max(n, m) + 1, INFL))));
  dp[0][0][0][0] = 0;
  dp[1][0][0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i == 0 && j == 0) {
        continue;
      }
      if (i > 0) {
        sort(prev_v[i][j].begin(), prev_v[i][j].end());
        long long sum = 0;
        int cnt = 0;
        for (int k = 0; k < i; ++k) {
          while (cnt < ((int)prev_v[i][j].size()) &&
                 prev_v[i][j][cnt].first <= k + 1) {
            sum += prev_v[i][j][cnt++].second;
          }
          long long val = dp[0][1 - i % 2][j][k] + here[i][j] - sum;
          dp[0][i % 2][j][k + 1] = val;
        }
      }
      if (j > 0) {
        sort(prev_h[i][j].begin(), prev_h[i][j].end());
        long long sum = 0;
        int cnt = 0;
        for (int k = 0; k < j; ++k) {
          while (cnt < ((int)prev_h[i][j].size()) &&
                 prev_h[i][j][cnt].first <= k + 1) {
            sum += prev_h[i][j][cnt++].second;
          }
          long long val = dp[1][i % 2][j - 1][k] + here[i][j] - sum;
          dp[1][i % 2][j][k + 1] = val;
        }
      }
      if (j) {
        dp[0][i % 2][j][0] = *min_element(dp[1][i % 2][j].begin() + 1,
                                          dp[1][i % 2][j].begin() + j + 1);
      } else {
        dp[0][i % 2][j][0] = INFL;
      }
      if (i) {
        dp[1][i % 2][j][0] = *min_element(dp[0][i % 2][j].begin() + 1,
                                          dp[0][i % 2][j].begin() + i + 1);
      } else {
        dp[1][i % 2][j][0] = INFL;
      }
    }
  }
  long long ans = INFL;
  ans = min(ans, *min_element(dp[0][(n - 1) % 2][m - 1].begin(),
                              dp[0][(n - 1) % 2][m - 1].begin() + n));
  cout << ans << "\n";
}
int main() {
  cout << setprecision(15) << fixed;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int test_count = 1;
  for (int test = 1; test <= test_count; ++test) {
    solve();
  }
}
