#include <bits/stdc++.h>
using namespace std;
int n, h, m;
int l, r, x;
int a[60];
int main() {
  int ans = 0;
  scanf("%d%d%d", &n, &h, &m);
  for (int i = 1; i <= n; i++) a[i] = h;
  while (m--) {
    scanf("%d%d%d", &l, &r, &x);
    for (int i = l; i <= r; i++) a[i] = min(a[i], x);
  }
  for (int i = 1; i <= n; i++) {
    ans += a[i] * a[i];
  }
  cout << ans << '\n';
}
