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