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