#include <bits/stdc++.h>
using namespace std;
long long n, m, k, ans;
long long dp[2][510][510][2], a[510][510];
vector<pair<long long, long long> > toSubtr[510][510][2];
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (long long i = 0; i < k; ++i) {
    long long x, y, t, e, d;
    cin >> x >> y >> d >> t >> e;
    bitset<4> ok = 0;
    for (long long j = 0; j < 4; ++j) {
      if (t + j > x + y or (x + y) % 4 != (t + j) % 4) {
        if (j == 0) {
          x += d;
          y -= d;
        } else if (j == 1) {
          y += d;
        } else if (j == 2) {
          x -= d;
          y += d;
        }
        continue;
      }
      ok[j] = 1;
      a[x][y] += e;
      if (ok[0] and j == 2) {
        toSubtr[x][y][0].push_back(make_pair(d, e));
      }
      if (ok[0] and j == 3) {
        toSubtr[x][y][1].push_back(make_pair(d, e));
      }
      if (ok[1] and j == 2) {
        toSubtr[x][y][1].push_back(make_pair(d, e));
      }
      if (j == 0) {
        x += d;
        y -= d;
      } else if (j == 1) {
        y += d;
      } else if (j == 2) {
        x -= d;
        y += d;
      }
    }
  }
  for (long long i = 0; i < 2; ++i) {
    for (long long i1 = 0; i1 < m; ++i1) {
      for (long long i2 = 0; i2 < 510; ++i2) {
        for (long long j = 0; j < 2; ++j) {
          dp[i][i1][i2][j] = 1e18;
        }
      }
    }
  }
  dp[0][0][0][0] = 0;
  for (long long i = 0; i < n; ++i) {
    long long nextIdx, curIdx;
    if (i & 1) {
      nextIdx = 0;
      curIdx = 1;
    } else {
      nextIdx = 1;
      curIdx = 0;
    }
    for (long long j = 0; j < m; ++j) {
      for (long long i1 = 0; i1 < 510; ++i1) {
        for (long long i2 = 0; i2 < 2; ++i2) {
          dp[nextIdx][j][i1][i2] = 1e18;
        }
      }
    }
    for (long long j = 0; j < m; ++j) {
      for (long long st = 0; st < 510; ++st) {
        for (long long dir = 0; dir < 2; ++dir) {
          dp[curIdx][j][st][dir] += a[i][j];
          for (auto x : toSubtr[i][j][dir]) {
            if (x.first <= st) {
              dp[curIdx][j][st][dir] -= x.second;
            }
          }
        }
        if (st < 510 - 1) {
          dp[nextIdx][j][st + 1][0] =
              min(dp[nextIdx][j][st + 1][0], dp[curIdx][j][st][0]);
          if (j < m - 1) {
            dp[curIdx][j + 1][st + 1][1] =
                min(dp[curIdx][j + 1][st + 1][1], dp[curIdx][j][st][1]);
          }
        }
        dp[nextIdx][j][1][0] = min(dp[nextIdx][j][1][0], dp[curIdx][j][st][1]);
        if (j < m - 1) {
          dp[curIdx][j + 1][1][1] =
              min(dp[curIdx][j + 1][1][1], dp[curIdx][j][st][0]);
        }
      }
    }
  }
  ans = 1e18;
  for (long long i = 0; i < 510; ++i) {
    ans = min(ans, dp[(n - 1) & 1][m - 1][i][0]);
    ans = min(ans, dp[(n - 1) & 1][m - 1][i][1]);
  }
  cout << ans << '\n';
}
