#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n, h, e, x, y, z, sum = 0, min = 87487492;
  cin >> n >> h >> e;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) {
    arr[i] = h;
  }
  for (int i = 0; i < e; i++) {
    cin >> x >> y >> z;
    for (int j = x; j <= y; j++) {
      if (arr[j] > z) {
        arr[j] = z;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sum = sum + (arr[i]) * (arr[i]);
  }
  cout << sum << endl;
}
