#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  ;
  long long int n, h, q;
  cin >> n >> h >> q;
  vector<long long int> a(n + 1, h);
  while (q--) {
    long long int l, r, x;
    cin >> l >> r >> x;
    for (long long int i = l; i <= r; i++) {
      a[i] = min(a[i], x);
    }
  }
  long long int s = 0;
  for (long long int i = 1; i <= n; i++) {
    s += (a[i] * a[i]);
  }
  cout << s;
  return 0;
}
