#include <bits/stdc++.h>
using namespace std;
int arr[51];
int mini(int a, int b) {
  if (a < b) return a;
  return b;
}
int main() {
  int n, maxim, m;
  cin >> n >> maxim >> m;
  for (int i = 1; i <= n; i++) arr[i] = maxim;
  int l, r, x;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> x;
    for (int j = l; j <= r; j++) arr[j] = mini(arr[j], x);
  }
  long long d = 0;
  for (int i = 1; i <= n; i++) d += arr[i] * arr[i];
  cout << d;
  return 0;
}
