#include <bits/stdc++.h>
using namespace std;
const int maxn = 50 + 5;
int a[maxn];
int main() {
  int n, h, m;
  cin >> n >> h >> m;
  for (int i = 1; i <= n; i++) a[i] = h;
  int l, r, x;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r >> x;
    for (int j = l; j <= r; j++) a[j] = min(x, a[j]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += a[i] * a[i];
  cout << ans << endl;
  return 0;
}
