#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   int SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   int SIZE(const T &t) {     return t.size();   }   string to_string(const string s, int x1 = 0, int x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(const bool b) { return (b ?  true  :  false ); }   string to_string(const char c) { return string({c}); }   template <size_t N>   string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) {     string t =   ;     for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords);   int l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(const pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1, int x2, C... coords) {     int rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgm() { ; }   template <typename Heads, typename... Tails>   void dbgm(Heads H, Tails... T) {     cout << to_string(H) <<   |  ;     dbgm(T...);   }   const long long INF = 1e9;   struct Dinic {     int nodes, src, dst;     vector<int> dist, q, work;     struct edge {       int to, rev;       long long f, cap;     };     vector<vector<edge>> g;     Dinic(int x) : nodes(x), g(x), dist(x), q(x), work(x) {}     void add_edge(int s, int t, long long cap) {       g[s].push_back((edge){t, ((int)g[t].size()), 0, cap});       g[t].push_back((edge){s, ((int)g[s].size()) - 1, 0, 0});     }     bool dinic_bfs() {       fill(dist.begin(), dist.end(), -1);       dist[src] = 0;       int qt = 0;       q[qt++] = src;       for (int qh = 0; qh < qt; qh++) {         int u = q[qh];         for (int i = 0; i < ((int)g[u].size()); i++) {           edge &e = g[u][i];           int v = g[u][i].to;           if (dist[v] < 0 && e.f < e.cap) dist[v] = dist[u] + 1, q[qt++] = v;         }       }       return dist[dst] >= 0;     }     long long dinic_dfs(int u, long long f) {       if (u == dst) return f;       for (int &i = work[u]; i < ((int)g[u].size()); i++) {         edge &e = g[u][i];         if (e.cap <= e.f) continue;         int v = e.to;         if (dist[v] == dist[u] + 1) {           long long df = dinic_dfs(v, min(f, e.cap - e.f));           if (df > 0) {             e.f += df;             g[v][e.rev].f -= df;             return df;           }         }       }       return 0;     }     long long max_flow(int _src, int _dst) {       src = _src;       dst = _dst;       long long result = 0;       while (dinic_bfs()) {         fill(work.begin(), work.end(), 0);         while (long long delta = dinic_dfs(src, INF)) result += delta;       }       return result;     }   };   long long cost(long long a, long long b) { return a * a - b * b; }   int N;   int n, h, m;   int getPos(int i, int j) {     if (j == 0) return N;     if (j >= h + 1) return N + 1;     return i * (h + 1) + j;   }   int getPos(int i) { return n * (h + 1) + i; }   int main() {     cin >> n >> h >> m;     N = n * (h + 1) + m;     Dinic din(N + 2);     for (int i = 0; i < n; i++) {       int node = i * (h + 1);       for (int j = 0; j < h + 1; j++) {         int left = getPos(i, j);         int right = getPos(i, j + 1);         din.add_edge(left, right, cost(h, j));       }     }     for (int i = 0; i < m; i++) {       int l, r, x, c;       cin >> l >> r >> x >> c;       int node = getPos(i);       din.add_edge(node, N + 1, c);       for (int j = l - 1; j < r; j++) {         din.add_edge(getPos(j, x + 1), node, INF);       }     }     cout << h * h * n - din.max_flow(N, N + 1) <<   n ;     return 0;   }   