#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 110;
int n, m, a, b, c, ans;
struct node{
int x, y, p, q;
bool friend operator <(node u, node v) {
return u.x < v.x;
}
} s[N];
signed main() {
freopen("rout.in", "r", stdin);
freopen("rout.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> a >> b >> c;
for (int i = 1; i <= m; i++) cin >> s[i].x >> s[i].y >> s[i].p >> s[i].q;
sort(s+1, s+1+m);
for (int i = 1; i <= m - 1; i++) ans += (a * (s[i+1].p - s[i].q) * (s[i+1].p - s[i].q) + b * (s[i+1].p - s[i].q) + c);
ans += (a * (s[1].p) * (s[1].p) + b * (s[1].p) + c + s[m].q);
cout << ans;
return 0;
}