#include using namespace std; struct ct { int a, b, c, d; } ct; bool comp(struct ct x, struct ct y){ return x.c < y.c; } int main() { int n, x, y; scanf("%d%d%d", &n, &x, &y); struct ct foo[n]; for (int i = 0; i < n; i++) { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); foo[i].a = a; foo[i].b = b; foo[i].c = c; foo[i].d = d; } sort(foo, foo+n, comp); int ans = 0; for (int i = 0; i < n; i++) { ans += foo[i].d; } printf("%d", ans); return 0; }