func_code_string: #include <bits/stdc++.h>   using namespace std;   void debug() { cerr <<   n ; }   template <typename H, typename... T>   void debug(H h, T... t) {     cerr << h;     if (sizeof...(t)) cerr <<  ,  ;     debug(t...);   }   const int N = 52, INF = 1e9 + 5, mod = 1e9 + 7;   int dp[N][N][N], opt[N][N][N];   vector<pair<pair<int, int>, pair<int, int> > > V2;   int main() {     int n, m, H;     cin >> n >> H >> m;     for (int i = 0; i < m; i++) {       int l, r, c, h;       cin >> l >> r >> h >> c;       V2.push_back(make_pair(make_pair(l, r), make_pair(h, c)));     }     for (int h = 1; h <= H; h++) {       for (int d = 0; d < n; d++) {         for (int l = 1; l <= n - d; l++) {           int r = l + d;           vector<pair<int, int> > V;           for (auto a : V2) {             if (a.first.first >= l && a.first.second <= r && a.second.first < h) {               V.push_back(make_pair(a.first.first, a.second.second));               V.push_back(make_pair(a.first.second + 1, -a.second.second));             }           }           sort((V).begin(), (V).end());           int wsk = 0, c = 0;           for (int i = l; i <= r; i++) {             while (wsk < V.size() && V[wsk].first == i) {               c += V[wsk++].second;             }             dp[l][r][h] = max(                 dp[l][r][h], opt[l][i - 1][h - 1] + opt[i + 1][r][h] + h * h - c);           }           opt[l][r][h] = dp[l][r][h];           if (opt[l][r][h - 1] > opt[l][r][h]) opt[l][r][h] = opt[l][r][h - 1];         }       }     }     cout << opt[1][n][H];   }   