Problem: You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.

In each spot, if a house has height a, you will gain a^2 dollars from it.

The city has m zoning restrictions. The i-th restriction says that the tallest house from spots l_i to r_i (inclusive) must be at most x_i.

You would like to build houses to maximize your profit. Determine the maximum profit possible.

Input

The first line contains three integers n, h, and m (1 ≤ n,h,m ≤ 50) — the number of spots, the maximum height, and the number of restrictions.

Each of the next m lines contains three integers l_i, r_i, and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i ≤ h) — left and right limits (inclusive) of the i-th restriction and the maximum possible height in that range.

Output

Print a single integer, the maximum profit you can make.

Examples

Input


3 3 3
1 1 1
2 2 3
3 3 2


Output


14


Input


4 10 2
2 3 8
3 4 7


Output


262

Note

In the first example, there are 3 houses, the maximum height of a house is 3, and there are 3 restrictions. The first restriction says the tallest house between 1 and 1 must be at most 1. The second restriction says the tallest house between 2 and 2 must be at most 3. The third restriction says the tallest house between 3 and 3 must be at most 2.

In this case, it is optimal to build houses with heights [1, 3, 2]. This fits within all the restrictions. The total profit in this case is 1^2 + 3^2 + 2^2 = 14.

In the second example, there are 4 houses, the maximum height of a house is 10, and there are 2 restrictions. The first restriction says the tallest house from 2 to 3 must be at most 8. The second restriction says the tallest house from 3 to 4 must be at most 7.

In this case, it's optimal to build houses with heights [10, 8, 7, 7]. We get a profit of 10^2+8^2+7^2+7^2 = 262. Note that there are two restrictions on house 3 and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house 1, we must still limit its height to be at most 10 (h=10).

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int alf = 26;
const int dig = 10;
const int two = 2;
const int th = 3;
const long long prost = 239;
const long long bt = 31;
const long double eps = 1e-8;
const long long INF = (long long)(1e18 + 239);
const int BIG = (int)(1e9 + 239);
const int MOD = 998244353;
const long long MOD2 = (long long)MOD * (long long)MOD;
mt19937 rnd(239);
const int M = (int)(2e5 + 239);
const int N = (int)(2e3 + 239);
const int L = 20;
const int T = (1 << 18);
const int B = (int)(trunc(sqrt(M)) + 1);
const int X = 55;
struct MaxFlow {
  struct Edge {
    int to;
    long long c, f;
    Edge() { to = c = f = 0; }
    Edge(int to1, long long c1) {
      to = to1;
      c = c1;
      f = 0;
    }
  };
  int n;
  vector<Edge> e;
  vector<vector<int> > v;
  int s, f;
  vector<int> dist, last;
  MaxFlow() {}
  MaxFlow(int nn, int ss, int ff) {
    n = nn;
    dist.resize(n);
    v.resize(n);
    last.resize(n);
    s = ss, f = ff;
  }
  void connect(int a, int b, long long c) {
    int i = e.size();
    e.push_back(Edge(b, c));
    v[a].push_back(i);
    e.push_back(Edge(a, 0));
    v[b].push_back(i + 1);
  }
  long long dfs(int p, long long f0) {
    if (p == f) return f0;
    while (last[p] >= 0) {
      int i = v[p][last[p]];
      if (dist[e[i].to] != dist[p] + 1) {
        last[p]--;
        continue;
      }
      if (e[i].c == e[i].f) {
        last[p]--;
        continue;
      }
      long long res = dfs(e[i].to, min(f0, e[i].c - e[i].f));
      if (res == 0) {
        last[p]--;
        continue;
      }
      e[i].f += res;
      e[i ^ 1].f -= res;
      if (e[i].f == e[i].c) last[p]--;
      return res;
    }
    return 0;
  }
  void phase() {
    for (int i = 0; i < n; i++) dist[i] = BIG;
    dist[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i : v[x])
        if (e[i].c > e[i].f && dist[e[i].to] > dist[x] + 1) {
          dist[e[i].to] = dist[x] + 1;
          q.push(e[i].to);
        }
    }
    if (dist[f] >= BIG) return;
    for (int i = 0; i < n; i++) last[i] = (int)v[i].size() - 1;
    while (dfs(s, INF) != 0)
      ;
    phase();
  }
  void run() { phase(); }
  long long gett() {
    long long ans = 0;
    for (int i : v[s]) ans += e[i].f;
    return ans;
  }
};
int n, h, m, l[X], r[X];
long long x[X], c[X];
int gett(int i, int x) { return (i * h + x + 1); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> h >> m;
  MaxFlow g = MaxFlow(2 + n * h + m, 0, 1 + n * h + m);
  long long ans = (long long)n * (long long)h * (long long)h;
  for (int i = 0; i < n; i++)
    for (int x = 0; x < h; x++) g.connect(0, gett(i, x), 2 * x + 1);
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> x[i] >> c[i];
    l[i]--, r[i]--;
    for (int t = l[i]; t <= r[i]; t++)
      for (int y = x[i]; y < h; y++) g.connect(gett(t, y), n * h + 1 + i, BIG);
    g.connect(n * h + 1 + i, 1 + n * h + m, c[i]);
  }
  g.run();
  ans -= g.gett();
  cout << ans;
  return 0;
}