{
TASK:water
LANG:PASCAL
}
{$R-}
const
 maxk=7;
 maxv=200; {200}
 yey=313131; {66613}
var
 t:text;
 i,j,k,l,v,a1,a2,b1,b2,c1,c2,br,s:longint;
 v1,v2,v3:array [0..maxk] of integer;
 u:array [0..maxv,0..maxv,0..maxv] of boolean;
 u2:array [0..yey] of boolean;
 iu:array [0..yey] of integer;

 procedure rec(lev:byte; o1,o2,o3:integer);
 var
  s1:longint;
 begin
 if lev<=k then begin
   v1[lev]:=o1; v2[lev]:=o2; v3[lev]:=o3;
   if not u[o1,o2,o3] then
   if not((o1=1)or(o2=1)or(o3=1)) then
   begin
    if (o1>=0)and(o2>=0)and(o3>=0) then
    begin
     u[o1,o2,o3]:=true;
{     u[o1,o3,o2]:=true;
     u[o2,o1,o3]:=true;
     u[o2,o3,o1]:=true;
     u[o3,o1,o2]:=true;
     u[o3,o2,o1]:=true;}
     s1:=s;
     inc(s,o1*maxv*maxv+o2*maxv+o3);
     s:=s mod yey;

     rec(lev+1,o1+o2,0,o3);
     rec(lev+1,o1+o3,o2,0);
     rec(lev+1,0,o2+o1,o3);
     rec(lev+1,o1,o2+o3,0);
     rec(lev+1,0,o2,o3+o1);
     rec(lev+1,o1,0,o3+o2);

     if o1>=a1 then rec(lev+1,a1,o1-a1+o2,o3);
     if o1>=a2 then rec(lev+1,a2,o1-a2+o2,o3);
     if o1>=a1 then rec(lev+1,a1,o2,o1-a1+o3);
     if o1>=a2 then rec(lev+1,a2,o2,o1-a2+o3);
     if o1>=b1-o2 then rec(lev+1,o1-(b1-o2),b1,o3);
     if o1>=b2-o2 then rec(lev+1,o1-(b2-o2),b2,o3);
     if o1>=c1-o3 then rec(lev+1,o1-(c1-o3),o2,c1);
     if o1>=c2-o3 then rec(lev+1,o1-(c2-o3),o2,c2);

     if o2>=b1 then rec(lev+1,o2-b1+o1,b1,o3);
     if o2>=b2 then rec(lev+1,o2-b2+o1,b2,o3);
     if o2>=b1 then rec(lev+1,o1,b1,o2-b1+o3);
     if o2>=b2 then rec(lev+1,o1,b2,o2-b2+o3);
     if o2>=a1-o1 then rec(lev+1,a1,o2-(a1-o1),o3);
     if o2>=a2-o2 then rec(lev+1,a2,o2-(a2-o1),o3);
     if o2>=c1-o3 then rec(lev+1,o1,o2-(c1-o3),c1);
     if o2>=c2-o3 then rec(lev+1,o1,o2-(c2-o3),c2);

     if o3>=c1 then rec(lev+1,o3-c1+o1,o2,c1);
     if o3>=c2 then rec(lev+1,o3-c2+o1,o2,c2);
     if o3>=c1 then rec(lev+1,o1,o3-c1+o2,c1);
     if o3>=c2 then rec(lev+1,o1,o3-c2+o2,c2);
     if o3>=a1-o1 then rec(lev+1,a1,o2,o3-(a1-o1));
     if o3>=a2-o1 then rec(lev+1,a2,o2,o3-(a2-o1));
     if o3>=b1-o2 then rec(lev+1,o1,b1,o3-(b1-o2));
     if o3>=b2-o2 then rec(lev+1,o1,b2,o3-(b2-o2));

     u[o1,o2,o3]:=false;
{     u[o1,o3,o2]:=false;
     u[o2,o1,o3]:=false;
     u[o2,o3,o1]:=false;
     u[o3,o1,o2]:=false;
     u[o3,o2,o1]:=false;}
     s:=s1;
    end
  end
  else
    begin
     s1:=s;
     inc(s,o1*maxv*maxv+o2*maxv+o3);
     s:=s mod yey;
     iu[s]:=br;
     if (not u2[s])or(iu[s]<br) then
      begin
        inc(br);
        u2[s]:=true;
      end;
     s:=s1;
    end;
  end;
 end;

begin
{  assign(t,'water.in');
  reset (t);  }
  readln ({t,}v,k); inc(k);
  read({t,}a1,a2,b1,b2,c1,c2);
{  close (t);}

  rec(1,v,0,0);

  writeln(br);
end.