#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
void printArray(int a[], int n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << endl;
}
void setAllValues(int a[], int n, int value) {
  for (int i = 0; i < n; i++) a[i] = value;
}
int main() {
  int arr[60] = {0};
  int n, h, m;
  memset(arr, 0, sizeof arr);
  cin >> n >> h >> m;
  setAllValues(arr, n + 1, h);
  for (int i = 0; i < m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    for (int j = l; j <= r; j++) arr[j] = min(arr[j], x);
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += arr[i] * arr[i];
  }
  cout << sum;
  return 0;
}
