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