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