#include <bits/stdc++.h>
using namespace std;
int mx_a[55];
bool done[55];
int lim[55][100010];
int main() {
  int n, k, m;
  cin >> n >> k >> m;
  for (auto i = 1; i <= m; i++) {
    int v1, v2, v3;
    cin >> v1 >> v2 >> v3;
    fill(lim[i], lim[i] + n + 1, k);
    lim[i][v1] = v3;
    lim[i][v2 + 1] = -1;
  }
  vector<int> l;
  fill(mx_a, mx_a + m + 1, k);
  fill(done, done + m + 1, 0);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (auto j = 1; j <= m; j++) {
      if (lim[j][i] == -1) {
        done[j] = 1;
        mx_a[j] = k;
      }
      if (!done[j]) mx_a[j] = min(lim[j][i], mx_a[j]);
    }
    int curMin = k;
    for (auto j = 1; j <= m; j++) {
      curMin = min(curMin, mx_a[j]);
    }
    ans += curMin * curMin;
    l.push_back(curMin);
  }
  cout << ans << '\n';
}
