#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int inn = 0x80808080;
using namespace std;
const int maxm = 55;
int limit[maxm];
int main() {
  int n, h, m;
  cin >> n >> h >> m;
  memset(limit, inf, sizeof limit);
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    for (int i = l; i <= r; i++) {
      limit[i] = min(limit[i], d);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (limit[i] >= h) {
      ans += h * h;
    } else {
      ans += limit[i] * limit[i];
    }
  }
  printf("%d\n", ans);
  return 0;
}
