#include <bits/stdc++.h>
using namespace std;
int n, hmax, m, l, r, h;
long long sum;
const int N = 60;
int arr[N];
int main() {
  cin >> n >> hmax >> m;
  for (int i = 0; i < n; i++) {
    arr[i] = hmax;
  }
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> h;
    l--;
    r--;
    for (l; l <= r; l++) {
      if (arr[l] > h) arr[l] = h;
    }
  }
  for (int i = 0; i < n; i++) {
    sum += (arr[i] * arr[i]);
  }
  cout << sum;
}
