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;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
template <typename T>
void ckmin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
void ckmax(T& a, const T& b) {
  a = max(a, b);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
template <class Arg, class... Args>
void re(Arg& first, Args&... rest) {
  re(first);
  re(rest...);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.first, p.second);
}
template <class T>
void re(vector<T>& a) {
  for (int i = 0; i < (int((a).size())); i++) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = 0; i < (SZ); i++) re(a[i]);
}
}  // namespace __input
using namespace __input;
namespace __output {
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const deque<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& x);
template <class T>
void pr(const T& x) {
  cout << x;
}
template <class Arg, class... Args>
void pr(const Arg& first, const Args&... rest) {
  pr(first);
  pr(rest...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T, bool pretty = true>
void prContain(const T& x) {
  if (pretty) pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? pretty ? ", " : " " : "", a), fst = 0;
  if (pretty) pr("}");
}
template <class T>
void pc(const T& x) {
  prContain<T, false>(x);
  pr("\n");
}
template <class T, size_t SZ>
void pr(const array<T, SZ>& x) {
  prContain(x);
}
template <class T>
void pr(const vector<T>& x) {
  prContain(x);
}
template <class T>
void pr(const deque<T>& x) {
  prContain(x);
}
template <class T>
void pr(const set<T>& x) {
  prContain(x);
}
template <class T1, class T2>
void pr(const map<T1, T2>& x) {
  prContain(x);
}
void ps() { pr("\n"); }
template <class Arg>
void ps(const Arg& first) {
  pr(first);
  ps();
}
template <class Arg, class... Args>
void ps(const Arg& first, const Args&... rest) {
  pr(first, " ");
  ps(rest...);
}
}  // namespace __output
using namespace __output;
namespace __algorithm {
template <typename T>
void dedup(vector<T>& v) {
  sort((v).begin(), (v).end());
  v.erase(unique((v).begin(), (v).end()), v.end());
}
template <typename T>
typename vector<T>::iterator find(vector<T>& v, const T& x) {
  auto it = lower_bound((v).begin(), (v).end(), x);
  return it != v.end() && *it == x ? it : v.end();
}
template <typename T>
size_t index(vector<T>& v, const T& x) {
  auto it = find(v, x);
  assert(it != v.end() && *it == x);
  return it - v.begin();
}
template <typename C, typename T, typename OP>
vector<T> prefixes(const C& v, T id, OP op) {
  vector<T> r(int((v).size()) + 1, id);
  for (int i = 0; i < (int((v).size())); i++) r[i + 1] = op(r[i], v[i]);
  return r;
}
template <typename C, typename T, typename OP>
vector<T> suffixes(const C& v, T id, OP op) {
  vector<T> r(int((v).size()) + 1, id);
  for (int i = (int((v).size())) - 1; i >= 0; i--) r[i] = op(v[i], r[i + 1]);
  return r;
}
}  // namespace __algorithm
using namespace __algorithm;
struct monostate {
  friend istream& operator>>(istream& is,
                             const __attribute__((unused)) monostate& ms) {
    return is;
  }
  friend ostream& operator<<(ostream& os,
                             const __attribute__((unused)) monostate& ms) {
    return os;
  }
} ms;
template <typename W = monostate>
struct wedge {
  int u, v, i;
  W w;
  wedge<W>(int _u = -1, int _v = -1, int _i = -1) : u(_u), v(_v), i(_i) {}
  int operator[](int loc) const { return u ^ v ^ loc; }
  friend void re(wedge& e) {
    re(e.u, e.v, e.w);
    --e.u, --e.v;
  }
  friend void pr(const wedge& e) { pr(e.u, "<-", e.w, "->", e.v); }
};
namespace __io {
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void setIO(string second = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(15);
  if (int((second).size())) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
}  // namespace __io
using namespace __io;
int main() {
  setIO();
  int N, M, K;
  re(N, M, K);
  vvll cost(N, vll(M));
  vector<vector<vector<pair<int, ll>>>> vert(N,
                                             vector<vector<pair<int, ll>>>(M));
  auto horiz = vert;
  for (int k = 0; k < (K); k++) {
    int x, y, d, t, e;
    re(x, y, d, t, e);
    bool c0 = ((x + y - t) % 4 == 0) && (x + y >= t);
    bool c1 = ((x + y - t - 1) % 4 == 0) && (x + y >= t + 1);
    bool c2 = ((x + y + d - t - 2) % 4 == 0) && (x + y + d >= t + 2);
    bool c3 = ((x + y + d - t - 3) % 4 == 0) && (x + y + d >= t + 3);
    if (c0) cost[x][y] += e;
    if (c1) cost[x + d][y - d] += e;
    if (c2) cost[x + d][y] += e;
    if (c3) cost[x][y + d] += e;
    if (c0 && c3) horiz[x][y + d].emplace_back(d, e);
    if (c0 && c2) vert[x + d][y].emplace_back(d, e);
    if (c1 && c2) horiz[x + d][y].emplace_back(d, e);
  }
  auto calc = [](vector<pair<int, ll>>& v) {
    if (v.empty()) return;
    sort((v).begin(), (v).end());
    int i = 0;
    for (int j = (1); j < (int((v).size())); j++) {
      if (v[j].first == v[i].first)
        v[i].second += v[j].second;
      else
        v[++i] = v[j];
    }
    v.resize(i + 1);
    for (int j = (1); j < (int((v).size())); j++)
      v[j].second += v[j - 1].second;
  };
  for (int i = 0; i < (N); i++)
    for (int j = 0; j < (M); j++) calc(vert[i][j]), calc(horiz[i][j]);
  auto add = [&](int x, int y, int k, bool d, int& i) {
    const auto& sv = d ? vert[x][y] : horiz[x][y];
    while (i + 1 < int((sv).size()) && sv[i + 1].first <= k) i++;
    return cost[x][y] - (i != -1 ? sv[i].second : 0ll);
  };
  const ll INF = LLONG_MAX / 2;
  vvll dpv(N, vll(N, INF)), DPV = dpv;
  vvll dph(N, vll(M, INF)), DPH = dph;
  dpv[0][0] = dph[0][0] = cost[0][0];
  for (int diag = (1); diag < (N + M - 1); diag++) {
    for (auto& e : DPV) fill((e).begin(), (e).end(), INF);
    for (auto& e : DPH) fill((e).begin(), (e).end(), INF);
    for (int x = 0; x < (N); x++) {
      int y = diag - 1 - x;
      if (y < 0 || y >= M) continue;
      int p = -1, q = -1;
      for (int k = 0; k < (N); k++)
        if (dpv[x][k] < INF) {
          if (x + 1 < N)
            ckmin(DPV[x + 1][k + 1], dpv[x][k] + add(x + 1, y, k + 1, 1, p));
          if (y + 1 < M) ckmin(DPH[x][1], dpv[x][k] + add(x, y + 1, 1, 0, q));
        }
      p = -1, q = -1;
      for (int k = 0; k < (M); k++)
        if (dph[x][k] < INF) {
          if (x + 1 < N)
            ckmin(DPV[x + 1][1], dph[x][k] + add(x + 1, y, 1, 1, p));
          if (y + 1 < M)
            ckmin(DPH[x][k + 1], dph[x][k] + add(x, y + 1, k + 1, 0, q));
        }
    }
    swap(dpv, DPV);
    swap(dph, DPH);
  }
  ll ans = LLONG_MAX;
  for (int k = 0; k < (N); k++) ckmin(ans, dpv[N - 1][k]);
  for (int k = 0; k < (M); k++) ckmin(ans, dph[N - 1][k]);
  ps(ans);
  return 0;
}
