#include <bits/stdc++.h>
using namespace std;
string s;
long long n, i, j, k, l, h, m, a[1010], b, c, dd;
char d[55][55];
int main() {
  cin >> n >> h >> m;
  for (i = 1; i <= n; i++) {
    a[i] = h;
  }
  for (i = 1; i <= m; i++) {
    cin >> b >> c >> k;
    for (j = b; j <= c; j++) {
      a[j] = min(a[j], k);
    }
  }
  for (i = 1; i <= n; i++) {
    l += a[i] * a[i];
  }
  cout << l;
}
