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