#include <bits/stdc++.h>
using namespace std;
int main() {
  long long 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 l, r, x;
    cin >> l >> r >> x;
    for (int p = l; p <= r; p++) {
      if (arr[p - 1] > x) {
        arr[p - 1] = x;
      }
    }
  }
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i] * arr[i];
  }
  cout << sum;
}
