#include<stdio.h>
#include<algorithm>
using namespace std;
#define lg 100005
#define inf 0x3f3f3f3f
int n, i, val, ind, cnt[lg], d[lg], poz;
struct ches{
int x, s, d, c;
};
ches v[lg];
inline int cmp(ches a, ches b){
return a.x < b.x;
}
int caut(int val){
int li = 2, ls = n+1, x, gs = -1;
while (li <= ls){
x = (li+ls) / 2;
if (v[x].x >= val){
gs = x;
ls = x-1;
}
else
li = x+1;
}
return gs;
}
int caut2(int val){
int li = 2, ls = n+1, x, gs = -1;
while (li <= ls){
x = (li+ls) / 2;
if (v[x].x <= val){
gs = x;
li = x+1;
}
else
ls = x-1;
}
return gs;
}
void update(int poz, int val){
while (poz <= n+1){
cnt[poz] = min(cnt[poz], val);
poz += (poz^(poz-1)) & poz;
}
}
int find(int poz){
int gs = inf;
while (poz > 0){
gs = min(gs, cnt[poz]);
poz -= (poz^(poz-1)) & poz;
}
return gs;
}
int main()
{
freopen("stalpi.in", "rt", stdin);
freopen("stalpi.out", "wt", stdout);
scanf("%d", &n);
for (i = 2; i <= n+1; i ++)
scanf("%d%d%d%d", &v[i].x, &v[i].c, &v[i].s, &v[i].d);
sort(v+2, v+n+2, cmp);
memset(cnt, 0x3f, sizeof(cnt)); memset(d, 0x3f, sizeof(d));
d[n+1] = cnt[n+1] = 0;
for (i = 2; i <= n+1; i ++){
poz = n+1 - caut(v[i].x - v[i].s)+2;
ind = n+1 - caut2(v[i].x + v[i].d)+1;
val = find(poz) + v[i].c;
//printf("la %d cu %d:\n", i-1, v[i].c);
if (val <= d[ind]){
d[ind] = val;
//printf("costul pentru %d este %d\n", n+1-ind+1-1, val);
update(ind, val);
}
}
printf("%d\n", d[1]);
return 0;
}