#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, h, m, counter = 0;
  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 n1, h1, m1;
    cin >> n1 >> h1 >> m1;
    for (int j = n1; j <= h1; ++j) {
      arr[j - 1] = min(arr[j - 1], m1);
    }
  }
  for (int i = 0; i < n; ++i) counter += arr[i] * arr[i];
  cout << counter << "\n";
}
int main() { solve(); }
