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