#include <bits/stdc++.h>
using namespace std;
int n, h, m, pos[55], l, r, x;
int main() {
  cin >> n >> h >> m;
  for (int i = 1; i <= n; i++) pos[i] = h;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> x;
    for (int j = l; j <= r; j++) pos[j] = min(pos[j], x);
  }
  int result = 0;
  for (int i = 1; i <= n; i++) result += pos[i] * pos[i];
  cout << result << endl;
}
