#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   inline void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   inline void writes(string s) { puts(s.c_str()); }   inline void writeln() { writes(  ); }   inline void writei(int x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline void writell(long long x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   int n, h, m, i, j, dis[3005], cnt, ans, s = 0, t = 3001;   vector<int> e[3005];   struct edg {     int y, z;   } a[1111111];   void add(int x, int y, int z) {     cnt++;     e[x].push_back(cnt * 2 - 2);     e[y].push_back(cnt * 2 - 1);     a[cnt * 2 - 2] = (edg){y, z};     a[cnt * 2 - 1] = (edg){x, 0};   }   int id(int x, int y) { return (x - 1) * h + y; }   bool bfs(int s, int t) {     queue<int> q;     memset((dis), (0x16), (sizeof((dis))));     dis[s] = 0;     q.push(s);     while (!q.empty()) {       int x = q.front();       q.pop();       for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)         if (a[*it].z) {           if (dis[a[*it].y] > dis[x] + 1) {             dis[a[*it].y] = dis[x] + 1;             q.push(a[*it].y);           }         }     }     return dis[t] < dis[t + 1];   }   int dfs(int x, int tt, int flw) {     if (x == tt || !flw) return flw;     int ans = 0;     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {       if (a[*it].z && dis[x] + 1 == dis[a[*it].y]) {         int t = dfs(a[*it].y, tt, min(flw, a[*it].z));         ans += t;         flw -= t;         a[*it].z -= t;         a[(*it) ^ 1].z += t;       }       if (!flw) break;     }     if (flw) dis[x] = -1;     return ans;   }   int dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       ans += dfs(s, t, 0x3bbbbbbb);     }     return ans;   }   int main() {     read(n);     read(h);     read(m);     for (((i)) = (1); ((i)) <= ((n)); ((i))++) {       for (((j)) = (1); ((j)) <= ((h)); ((j))++) {         if (j < h) add(id(i, j + 1), id(i, j), 0x3bbbbbbb);         add(s, id(i, j), j * 2 - 1);         ans += j * 2 - 1;       }     }     for (((i)) = (1); ((i)) <= ((m)); ((i))++) {       int l, r, ys, c;       read(l);       read(r);       read(ys);       read(c);       if (ys < h)         for ((j) = (l); (j) <= (r); (j)++) {           add(id(j, ys + 1), i + 2500, 0x3bbbbbbb);         }       add(i + 2500, t, c);     }     cout << ans - dinic(s, t) << endl;     return 0;   }