var
  a:array[0..128,0..128,0..128] of int64;
  n,q,w,e,temp,x1,x2,y1,y2,z1,z2:longint;

function add(q,w,e,x:longint):longint;
var
  z,c:longint;
begin
  z:=w;
  c:=e;
  while q <= n do
    begin
      while z <= n do
        begin
          while c <= n do
            begin
              inc(a[q,z,c],x);
              c:=c or (c + 1);
            end;
          c:=e;
          z:=z or (z + 1);
        end;
      z:=w;
      q:=q or (q + 1);
    end;
end;

function sum(q,w,e:longint):int64;
var
  t:int64;
begin
  t := 0;
  while q >= 0 do
    begin
      while w >= 0 do
        begin
          while e >= 0 do
            begin
              inc(t,a[q,w,e]);
              e:=(e and (e + 1)) - 1;
            end;
          w:=(w and (w + 1)) - 1;
        end;
      q:=(q and (q + 1)) - 1;
    end;
  sum:=t;
end;

begin
  {assign(input,'stars.in');
  reset(input);
  assign(output,'stars.out');
  rewrite(output);}
  read(n);
  read(q);
  while q<>3 do
    begin
      if q = 2 then
        begin
          temp:=0;
          read(x1,y1,z1,x2,y2,z2);
          inc(temp,+sum(x2 + 0,y2 + 0,z2 + 0));
          inc(temp,-sum(x1 - 1,y2 + 0,z2 + 0));
          inc(temp,-sum(x2 + 0,y1 - 1,z2 + 0));
          inc(temp,-sum(x2 + 0,y2 + 0,z1 - 1));
          inc(temp,+sum(x1 - 1,y1 - 1,z2 + 0));
          inc(temp,+sum(x1 - 1,y2 + 0,z1 - 1));
          inc(temp,+sum(x2 + 0,y1 - 1,z1 - 1));
          inc(temp,-sum(x1 - 1,y1 - 1,z1 - 1));
          writeln(temp);
        end
      else if q = 1 then
        begin
          read(x1,y1,z1,e);
          add(x1,y1,z1,e);
        end;
      read(q);
    end;
end.