You, the mighty Blackout, are standing in the upper-left (0,0) corner of NxM matrix. You must move either right or down each second. 

There are K transformers jumping around the matrix in the following way. Each transformer starts jumping from position (x,y), at time t, and jumps to the next position each second. The x-axes grows downwards, and y-axes grows to the right. The order of jumping positions is defined as {(x,y),(x+d,y-d),(x+d,y),(x,y+d)}, and is periodic. Before time t transformer is not in the matrix.

You want to arrive to the bottom-right corner (N-1,M-1), while slaying transformers and losing the least possible amount of energy. When you meet the transformer (or more of them) in the matrix field, you must kill them all, and you lose the sum of the energy amounts required to kill each transformer.

After the transformer is killed, he of course stops jumping, falls into the abyss and leaves the matrix world. Output minimum possible amount of energy wasted.

Input

In the first line, integers N,M (1 ≤ N, M ≤ 500), representing size of the matrix, and K (0 ≤ K ≤ 5*10^5) , the number of jumping transformers.

In next K lines, for each transformer, numbers x, y, d (d ≥ 1), t (0 ≤ t ≤ N+M-2), and e (0 ≤ e ≤ 10^9), representing starting coordinates of transformer, jumping positions distance in pattern described above, time when transformer starts jumping, and energy required to kill it.

It is guaranteed that all 4 of jumping points of the transformers are within matrix coordinates

Output

Print single integer, the minimum possible amount of energy wasted, for Blackout to arrive at bottom-right corner.

Example

Input


3 3 5
0 1 1 0 7
1 1 1 0 10
1 1 1 1 2
1 1 1 2 2
0 1 1 2 3


Output


9

Note

If Blackout takes the path from (0, 0) to (2, 0), and then from (2, 0) to (2, 2) he will need to kill the first and third transformer for a total energy cost of 9. There exists no path with less energy value.
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
  return os << "(" << x.first << "," << x.second << ")";
}
vector<int> E[505][505];
long long dp[505][505], W[505][505], wv[505][505], wh[505][505];
vector<pair<int, int>> verts[505][505], hors[505][505];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  vector<int> C(k);
  for (int i = 0; i < k; ++i) {
    int r, c, d, t;
    scanf("%d%d%d%d%d", &r, &c, &d, &t, &C[i]);
    vector<bool> has(4);
    if (r + c >= t && (r + c - t) % 4 == 0) has[0] = true;
    if (r + c >= t && (r + c - t) % 4 == 1) has[1] = true;
    if (r + c + d >= t && (r + c + d - t) % 4 == 2) has[2] = true;
    if (r + c + d >= t && (r + c + d - t) % 4 == 3) has[3] = true;
    int tot = has[0] + has[1] + has[2] + has[3];
    assert(tot <= 2);
    if (!tot) continue;
    if (has[0] && has[2])
      verts[r + d][c].emplace_back(r, C[i]);
    else if (has[0] && has[3])
      hors[r][c + d].emplace_back(c, C[i]);
    else if (has[1] && has[2])
      hors[r + d][c].emplace_back(c - d, C[i]);
    if (has[0]) W[r][c] += C[i];
    if (has[1]) W[r + d][c - d] += C[i];
    if (has[2]) W[r + d][c] += C[i];
    if (has[3]) W[r][c + d] += C[i];
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (!i && !j) continue;
      for (auto& x : hors[i][j]) {
        wh[i][x.first] -= x.second;
      }
      for (auto& x : verts[i][j]) {
        wv[x.first][j] -= x.second;
      }
      long long val = LLONG_MAX;
      long long cost = 0;
      for (int k = j; k >= 0; --k) {
        cost += W[i][k] + wh[i][k];
        if (k < j) val = min(val, dp[i][k] + cost - W[i][k]);
      }
      cost = 0;
      for (int k = i; k >= 0; --k) {
        cost += W[k][j] + wv[k][j];
        if (k < i) val = min(val, dp[k][j] + cost - W[k][j]);
      }
      dp[i][j] = val;
    }
  printf("%lld\n", dp[n - 1][m - 1]);
}
