#include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
long long ans, n, h, m, l[maxn], r[maxn], x[maxn], hous[maxn];
int main() {
  cin >> n >> h >> m;
  for (register int i = 1; i <= m; ++i) cin >> l[i] >> r[i] >> x[i];
  for (register int i = 1; i <= n; ++i) hous[i] = h;
  for (register int i = 1; i <= m; ++i)
    for (register int j = l[i]; j <= r[i]; ++j) hous[j] = min(hous[j], x[i]);
  for (register int i = 1; i <= n; ++i) ans += (hous[i] * hous[i]);
  return printf("%d", ans) % 1;
}
