#include <bits/stdc++.h>
using namespace std;
const int maxn = 50 + 20;
int k[maxn];
int main() {
  int n, h, m, ans = 0;
  cin >> n >> h >> m;
  for (int i = 0; i < n; i++) k[i] = h;
  while (m--) {
    int l, r, x;
    cin >> l >> r >> x;
    for (int i = l - 1; i < r; i++) {
      k[i] = min(x, k[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (k[i] == h)
      ans += h * h;
    else
      ans += k[i] * k[i];
  }
  cout << ans;
}
