func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = (int)5e5 + 123, inf = 1e9, mod = 1e9 + 7, M = 511;   const long long INF = (long long)1e18;   int n, m, k, x, y, d, t, e;   long long A[M][M], a[2][M][M];   vector<pair<int, int> > ex[M][M], ey[M][M];   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(NULL);     cin >> n >> m >> k;     for (int i = 1; i <= k; ++i) {       cin >> x >> y >> d >> t >> e;       if (x + y >= t && ((x + y) - t) % 4 == 0) {         A[x][y] += e;         if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) {           ex[x + d][y].push_back(make_pair(d, e));         }         if (x + y + d >= t && ((x + y + d) - t) % 4 == 3) {           ey[x][y + d].push_back(make_pair(d, e));         }       }       if (x + d + y - d >= t && ((x + d + y - d) - t) % 4 == 1) {         A[x + d][y - d] += e;         if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) {           ey[x + d][y].push_back(make_pair(d, e));         }       }       if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) {         A[x + d][y] += e;       }       if (x + y + d >= t && ((x + y + d) - t) % 4 == 3) {         A[x][y + d] += e;       }     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) a[0][i][j] = a[1][i][j] = INF;     a[0][0][0] = a[1][0][0] = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         sort(ex[i][j].begin(), ex[i][j].end());         sort(ey[i][j].begin(), ey[i][j].end());       }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         long long cost = a[0][i][j];         for (int k = 1; k + i < n; ++k) {           cost += A[i + k][j];           for (int w = 0; w < (int)ex[i + k][j].size(); ++w) {             if (i + k - ex[i + k][j][w].first >= i)               cost -= ex[i + k][j][w].second;             else               break;           }           a[1][i + k][j] = min(a[1][i + k][j], cost);         }         cost = a[1][i][j];         for (int k = 1; k + j < m; ++k) {           cost += A[i][j + k];           for (int w = 0; w < (int)ey[i][j + k].size(); ++w) {             if (j + k - ey[i][j + k][w].first >= j)               cost -= ey[i][j + k][w].second;             else               break;           }           a[0][i][j + k] = min(a[0][i][j + k], cost);         }       }     cout << min(a[0][n - 1][m - 1], a[1][n - 1][m - 1]);     return 0;   }   