M=505 s=[[0]*M*4for _ in[0]*M*4] f=lambda:map(int,input().split()) n,k=f() E=[f()for _ in[0]*n] for t in[-1]*k: x,y,w,h,d=f() for k in[0,5,9,14]:s[x+k%-3*~w][y+k%-5*~h]+=d*t**k i=j=-M while iM;j+=1-(j>M)*2*M print(sum(max(h-s[x][y],0)for x,y,h in E))