#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, m;
  cin >> n >> h >> m;
  int a[n + 1];
  for (int i = 1; i <= n; i++) a[i] = h;
  for (int i = 0; i < m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    for (int j = l; j <= r; j++) {
      a[j] = min(a[j], x);
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum = sum + a[i] * a[i];
  }
  cout << sum;
  return 0;
}
