#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int MAXN = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, h, m;
  cin >> n >> h >> m;
  int arr[n + 10];
  for (int i = (1); i < (n + 1); ++i) arr[i] = h;
  int l, r, x;
  for (int i = 0; i < (m); ++i) {
    cin >> l >> r >> x;
    for (int j = (l); j < (r + 1); ++j) arr[j] = min(arr[j], x);
  }
  int ans = 0;
  for (int i = (1); i < (n + 1); ++i) ans += (arr[i] * arr[i]);
  cout << ans << '\n';
  return 0;
}
