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