/* 2次元 参考: https://imoz.jp/algorithms/imos_method.html verify: https://atcoder.jp/contests/abc036/tasks/abc036_c */ #include using namespace std; using ll=long long int; template struct IMOS{ int H,W; bool flag; vector> table; IMOS(int H,int W):H(H),W(W),flag(false){ table.resize(H+1,vector(W+1,0)); } void add(int sh,int sw,int gh,int gw,const T x){ flag=false; table[sh][sw]+=x; table[sh][gw+1]-=x; table[gh+1][sw]-=x; table[gh+1][gw+1]+=x; } void build(){ flag=true; //table[1][0]+=table[0][0]; //table[0][1]+=table[0][0]; /*for(int i=1;i<=H;i++){ for(int j=1;j<=W;j++){ table[i][j]+=table[i][j-1]+table[i-1][j]-table[i-1][j-1]; } }*/ for(int i=0;i<=H;i++){ for(int j=1;j<=W;j++){ table[i][j]+=table[i][j-1]; } } for(int i=1;i<=H;i++){ for(int j=0;j<=W;j++){ table[i][j]+=table[i-1][j]; } } } T query(int h,int w){ assert(flag); return table[h][w]; } }; signed main(){ int N,K; cin>>N>>K; IMOS imos(1501,1501); for(int i=0;i>x>>y>>hp; x+=500;y+=500; imos.add(x,y,x,y,-hp); } for(int i=0;i>x>>y>>w>>h>>d; x+=500;y+=500; imos.add(x,y,x+w,y+h,d); } imos.build(); ll ret=0; for(int i=0;i<=1500;i++){ for(int j=0;j<=1500;j++){ if(imos.query(i,j)<0) ret-=imos.query(i,j); } } cout<