#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 55;
int n, h, m;
int arr[N];
int main() {
  cin >> n >> h >> m;
  for (int i = 1; i <= n; i++) arr[i] = h;
  while (m--) {
    int l, r, x;
    cin >> l >> r >> x;
    for (int i = l; i <= r; i++) arr[i] = min(arr[i], x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += arr[i] * arr[i];
  cout << ans << endl;
  return 0;
}
