During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.Right now there are A yellow and B blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.

The first line features two integers A and B (0 ≤ A, B ≤ 109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers x, y and z (0 ≤ x, y, z ≤ 109) — the respective amounts of yellow, green and blue balls to be obtained.

Print a single integer — the minimum number of crystals that Grisha should acquire in addition.

NoteIn the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.

//For yellow - 2 yc
//For green - 1 yc 1 bc
//For blue - 3 bc
var
a,b,x,y,z:int64;
req_a,req_b:int64;
res:int64;

begin
readln(a,b);
readln(x,y,z);
req_a:=x*2+y;
req_b:=z*3+y;
req_a:=req_a-a;
if req_a<0 then req_a:=0;
req_b:=req_b-b;
if req_b<0 then req_b:=0;
res:=req_a+req_b;
writeln(res);
end.

    var
		m, n: int64;
		a, b, c: int64;
		yellow, green, blue: int64;

    begin

		readln(n, m);
		readln(a, b, c);

		writeln(max(0, 2*a+b - n) + max(0, 3*c+b - m));

    end.

begin
  var a,b,c,n,m:int64;
  var r:biginteger;
  read(n,m,a,b,c);
  var s:=(n-(a*2)-b);
  var w:=(m-(c*3)-b);
  if(s<0)then r+=abs(s);
  if(w<0)then r+=abs(w);
  write(r);
end.

var
a, b, c, d, x, y, z:int64;

begin

readln(a,b);
readln(x,y,z);

c:=(2*x + y) - a;
if c < 0 then c:=0;

d:=(y + 3*z) - b;
if d < 0 then d:=0;

writeln(c+d);

end.

PROGRAM PR1;
VAR A,B,X,Y,Z,GEL1,GEL2,GEL,SIN1,SIN2,SIN,S:REAL;
BEGIN
READ(A,B);
READLN(X,Y,Z);
GEL1:=X*2;
GEL2:=Y;
GEL:=GEL1+GEL2;
SIN1:=Z*3;
SIN2:=Y;
SIN:=SIN1+SIN2;
IF ((SIN=B) OR (B>SIN)) AND ((GEL=A) OR (A>GEL)) THEN S:=0;
IF (A<GEL) AND ((SIN=B) OR (B>SIN)) THEN S:=S+(GEL-A);
IF (B<SIN) AND ((GEL=A) OR (A>GEL)) THEN S:=S+(SIN-B);
IF (A<GEL) AND (B<SIN) THEN S:=(GEL-A)+(SIN-B);
WRITELN(S);
END.

var x,y,a,b,c,q:int64;
begin
read(x,y,a,b,c);
x-=a*2;
x-=b;
y-=b;
y-=3*c;
if x>0 then x:=0;
if y>0 then y:=0;
write((x+y)*(-1))
end.

Var
    A, B, x, y, z: Int64;

Begin
    Read(A, B, x, y, z);
    Write(max(0, (2*x + y) - A) + max(0, (3*z + y) - B))
End.

var sh,si:int64;
var j,z,s,kj,ks,k:int64;
begin
readln(sh,si);
readln (j,z,s);
kj := j*2 + z - sh;
ks := z + s*3 - si;
if (kj >= 0) and (ks >= 0) then k := kj + ks else
if (kj < 0) and (ks >= 0) then k := 0 + ks else
if (kj >= 0) and (ks < 0) then k := kj + 0 else
k := 0;
writeln(k);
end.

var x,y,a,b,c,q:int64;
begin
read(x,y,a,b,c);
x-=a*2;
x-=b;
y-=b;
y-=3*c;
if x>=0 then x:=0;
if y>=0 then y:=0;
write((x+y)*(-1))
end.

var
  A, B, x, y, z, answer, nadoA, nadoB: int64;

begin
  readln(A, B);
  readln(x, y, z);
  nadoA := x * 2 + y;
  nadoB := y + z * 3;
  if nadoA > A then
    answer := nadoA - A;
  if nadoB > B then
    answer := answer + (nadoB - B);
  write(answer);
end.

Var
  A, B: Int64;
  mas: Array [1..2] of Int64;

Begin
  Read(A, B);
  mas[1] := A; mas[2] := B;
  Read(A); mas[1] -= 2*A;
  Read(A); mas[1] -= A; mas[2] -= A;
  Read(A); mas[2] -= 3*A;
  If (mas[1] <= 0) and (mas[2] <= 0) then Write(abs(mas[1] + mas[2]))
  Else If mas[1] <= 0 then Write(abs(mas[1]))
  Else If mas[2] <= 0 then Write(abs(mas[2]))
  Else Write(0)
End.

program a1;

var a, b, x, y, z, si, zh : int64;

begin
  readln (a, b);
  readln (x, y, z);
  zh := x*2 + y;
  si := y + z*3;
  if (zh < a) then
    zh := 0
  else zh := zh - a;
  if (si < b) then
    si := 0
  else si := si - b;
  writeln (si + zh);
end.

var a,b:int64;
    x,y,z:int64;
    s,sy,sb:int64;
begin
  s:=0;
  sy:=0;
  sb:=0;
  read(a,b);
  read(x,y,z);
  sy:=2*x+y;
  sb:=y+3*z;
  sy:=a-sy;
  if sy>=0 then sy:=0
           else sy:=-sy;
  sb:=b-sb;
  if sb>=0 then sb:=0
           else sb:=-sb;
  write(sy+sb);
end.

Program Balls;
var a,b,x,y,z:int64;

Function min(a,b:int64):int64;
begin
if a<b then
  min:=a else
  min:=b;

end;
begin
read(a,b);
read(x,y,z);
a:=a-2*x-y;
if a>0 then a:=0;
b:=b-3*z-y;
if b>0 then b:=0;
writeln(-a-b);

end.

var a,b,c,x,y,z:int64;
function pr(q:int64):int64;
begin
 if q>0 then
 pr:=q else
 pr:=0;
end;
begin
 readln(a,b);
 readln(x,y,z);
 c:=pr((x*2+y)-a);
 c:=c+pr((y+z*3)-b);
 writeln(c);
end.

var i,j,a,b,c,x,y,z: int64;
begin
 read(a,b,x,y,z);
 J:=2*x+y;
 if a>j then i:=0 else i:=j-a;
 J:=3*z+y;
 if b>j then j:=0 else j:=j-b;
 write(j+i);
end.

         const eps=0.000000001;  besk=20000000000008;
               modul=1000000007;
   label 1,2,3,4,5,6;
    type
   { int64=longint; }
    mas=array [-100..1000000] of int64;   point=record x,y,z,vx,vy,vz:int64;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap; point1=^point;
    mass=array[-100..1000000] of int64;mass1=^mass;
    var j2,j1,maxright,gr,xx,yy,sum,ogr,jloz,jnew,i1,i2,i3,maxdob,nn,kk,pos1,pos2,start,ans,pp,qq,aaa,bbb,ccc,tt,aa,bb,jj,ii,ott,time,ppp,istart,jstart,iii,newdl, t1,t2,cc,ll,rr,oldpos,t,jjj,kol,pos,dloch,told,p,q,pmin,ppold,ot,pmax,imax,p1,p2,p3,p4,l,nm,n,s2,m,smin,cen:int64;
   posx,posy,mask,k, step, i,j:longint;
   x,ottt:mass;
   pointnew,pointold,pointklad,ppoint:point;
    vot,distmin,hh,dist,s0,s1,aanew,bbnew:extended;
    z,nnx,nny,nx,ny,tr,fact,aold,y,och,s,d11,prev,next,newc,d,nap:array[-10..2000008] of int64;
    a,b,c:mass;
    sd:array[-1000..1000000] of char;
    yyy:array[-10..10000] of extended;
    dot,ddd:array[-10..1210000] of int64;
    peres, ppole:array[-1..200,-10..1500] of int64;
   sss,text1,text2:array[-10..2000000] of string;
   zanxy,zanxz,zanyz:array[-1..200,-1..200] of boolean;
     sot,ss,stest,ss3,ss1,ss2:string;
     ch1,ch2:char;
     ddright,ddleft,ddsumleft,ddsumright,ddsum:array[-1..1502,-1..1502] of int64;
     zzan,zan,zana,zanb:array[-10..2000000] of boolean;
     marked:array[-100..15000] of boolean;
    {sss:string;ch:char;
   } pole1,pole :array [-10..150,-10..150] of char;
    st:array[-100..100000] of string;
     v0,v1,t0:extended;
     zv:point;
     newx,newy:array[-1..200000] of int64;

     koef,yot:extended;
      globflag, flag2,flag,flag1:boolean;
    function al(x,y:extended):extended; var t0,t1,p,s0,s1:extended;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:int64):int64;begin min:=x;if y<x then min:=y; end;
  function max(x,y:int64):int64;begin max:=x;if y>x then max:=y; end;

  function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

{procedure udal(ii:longint);
begin  next[prev[ii]]:=next[ii]; prev[next[ii]]:=prev[ii];  end;
 }
function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k div 2); degg:=p*p mod modul;   end;

end;

begin
 {  assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
  }
     read(aa,bb);
     read(p1,p2,p3);
     t1:=2*p1+p2;
     t2:=p2+3*p3;
   {  writeln(t1,' ',t2);
    }
     writeln(max(t1-aa,0)+max(t2-bb,0));

   1:    close(output);
end.

program Zanimatelnaia_alhimia;

{$APPTYPE CONSOLE}

var a,b,c,x,y,z,yellow,blue: int64;

begin
  readln(a,b);
  read(x,y,z);
  c:=0;
  yellow:=a-(2*x+y);
  blue:=b-(3*z+y);
  if yellow<0 then c:=c+abs(yellow);
  if blue<0 then c:=c+abs(blue);
  write(c);
end.

uses math;
var
  a, b, x, y, z, ra, rb, ans:int64;
BEGIN
  readln(a, b, x, y, z);
  ra:= x*2 + y;
  rb:= y + 3*z;
  ans := max(ra-a, 0) + max(rb-b,0);
  write(ans);
END.

Program TrickyAlchemy;
uses math;
var A,B,x,y,z,x1,z1:int64;
begin   //assign(input,'912A.inp'); reset(input);
        //assign(output,'912A.out'); rewrite(output);
        readln(A,B); readln(x,y,z);
        x1:=2*x+y; z1:=3*z+y;
        if (A<=x1) and (B<=z1) then writeln(abs(x1-A)+abs(z1-B))
        else begin
             if (A>=x1) and (not(B>=z1)) then writeln(abs(z1-B))
             else if (B>=z1) and (not(A>=x1)) then writeln(abs(x1-A))
             else writeln(0);
             end;
        //close(input); close(output);
end.

uses
  Math;

var
  A, B, x, y, z, NeedA, NeedB: Int64;

begin
  Read(A, B, x, y, z);
  ReadLn; ReadLn;

  NeedA := x*2 + y;
  NeedB := y + z*3;

  NeedA := max(NeedA - A, 0);
  NeedB := max(NeedB - B, 0);

  WriteLn(NeedA + NeedB);
end.

program zzz;
var
 a,b,x,y,z,sa,sb:int64;
begin
  readln(a,b);
  readln(x,y,z);
  sa:=x*2 + y-a;
  sb:=z*3+y-b;
  if sa<0 then sa:=0;
  if sb<0 then sb:=0;
  writeln(sa+sb);
end.

program hrn;
 var
  a,b,x,y,z,k:int64;
 begin
  read(a,b,x,y,z);
  a:=a-(2*x)-y;
  b:=b-(3*z)-y;
  if a<0 then k:=k-a;
  if b<0 then k:=k-b;
  write(k);
 end.

uses math;
var a,b,x,y,z,tmp,tmp1:int64;
begin
 //assign(input,'a.inp');reset(input);
 read(a,b);
 read(x,y,z);
 tmp:=x*2+y;
 tmp1:=z*3+y;
 tmp:=max(tmp-a,0);
 tmp1:=max(tmp1-b,0);
 write(tmp+tmp1);
 //close(input);
end.

var
  a,b,x,y,sum1,sum2,z:int64;
begin
  readln(a,b);
  readln(x,y,z);
  sum1:=2*x+y;
  sum2:=3*z+y;
  sum1:=sum1-a;
  sum2:=sum2-b;
  if sum1<0 then sum1:=0;
  if sum2<0 then sum2:=0;
  writeln(sum1+sum2);
end.

var
 x,y,a,b,c,x1,y1,s:int64;
begin
 readln(x,y);
 readln(a,b,c);
 x1:=2*a+b-x;
 y1:=3*c+b-y;
 if x1>0 then s:=s+x1;
 if y1>0 then s:=s+y1;
 writeln(s);
end.

var n,m,x,y,z,a,b:int64;
begin

readln(n,m);
readln(x,y,z);
a:=2*x+y-n;b:=y+3*z-m;
if a<0then a:=0;
if b<0then b:=0;
writeln(a+b);

end.

var a,b,x,y,z,x1,s :int64;
begin

readln(a,b);
readln(x,y,z);
x1:=x*2+y;
if x1>a then s:=s+x1-a;
x1:=z*3+y;
if x1>b then s:=s+x1-b;
writeln(s);

end.

var h,l,x,y,z,zl,zh,s:int64;
begin

readln(h,l);
readln(x,y,z);
zl:=zl+z*3;
zl:=zl+y;
zh:=zh+2*x;zh:=zh+y;
if zh>h then s:=s+zh-h;
if zl>l then s:=s+zl-l;
writeln(s);

end.

var
  a, b, x, y, z, blue, yellow : int64;
function max(a, b : int64) : int64;
  begin
  	if a > b
  	  then max := a
  	  else max := b;
  end;
begin
  readln(a, b);
  readln(x, y, z);
  yellow := x * 2 + y;
  blue := z * 3 + y;
  writeln(max(0, yellow - a) + max(0, blue - b));
end.

uses math;
const fin='';
        fout='';//x vang, y xanh la, z xanh duong
var f,g:text;
        a,b,x,y,z,blue,yel,qa:int64;

begin
        assign(f,fin);reset(f);
        assign(g,fout);rewrite(g);
        read(f,a,b);
        read(f,x,y,z);
        blue:=z*3+y;
        yel:=x*2+y;
        qa:=max(0,yel-a)+max(0,blue-b);
        if qa>0 then write(g,qa)
        else write(g,0);
        close(f);
        close(g);
end.

uses math;
var
a,b,x,y,z,j,c:int64;
begin
readln(a,b);
readln(x,y,z);
j:=x*2+y;
c:=y+z*3;
j:=max(0,j-a);
c:=max(0,c-b);
write(j+c);
end.

var
   g,s,a,b,x,y,z,ans,i,j:int64;
begin
   readln (a,b);
   readln (x,y,z);
   g:=x*2+y;
   s:=y+3*z;
   i:=a-g;
   j:=b-s;
   ans:=0;
   if (i>=0)and(j>=0) then ans:=0
   else
   begin
      if i<0 then ans:=ans+abs(i);
      if j<0 then ans:=ans+abs(j);
   end;
   writeln (ans);
end.

program z1;
var z, x, y, sum, a, b, c, i:int64;
begin
 readln( a, b );
 Readln( z, x, y );
 c := z * 2 + x * 1 ;
 i := x * 1 + y * 3 ;
 sum := 0 ;

 if a < c
    then sum := sum + (c   - a ) ;
 if b < i
    then sum := sum + ( i - b ) ;
 writeln(sum);
end.

program hym;
var
	Yk,Bk: int64;
	Ysh, Gsh, Bsh:int64;
begin
  readln(Yk, Bk);
	readln(Ysh, Gsh, Bsh);
	Yk := Yk - Ysh*2 -Gsh;
	Bk := Bk - Gsh - Bsh*3;
	Ysh := 0;
	if Yk< 0 then Ysh := abs(Yk);
	if Bk< 0 then Ysh := Ysh + abs(Bk);
	writeln(Ysh);
end.

program CF912_A;
uses math;
var a,b,x,y,z,vang,xanh,res: int64;
begin
	readln(a,b);
	readln(x,y,z);
	vang:=2*x+y;
	xanh:=y+3*z;
	if vang-a <0 then vang:=0 else vang:=vang-a;
	if xanh-b <0 then xanh:=0 else xanh:=xanh-b;
	res:=vang+xanh;
	write(res);
end.

type
arr=array [1..1000,1..2] of double;
var
a,b,c1,c2,x,y,z: int64;
flag,flag1,flag2,kod: integer;

begin
    readln(a,b);
    readln(x,y,z);
   c1:=2*x+y-a;
   c2:=y+3*z-b;
   if (c1<0) then c1:=0;
   if (c2<0) then c2:=0;
    writeln(c1+c2);
end.

uses math;
var x,y,z,a,b,res:int64;
begin
        readln(a,b);
        readln(x,y,z);
        writeln(max(0,x*2+y-a)+max(0,z*3+y-b));
        readln;
end.

var a,b,x,y,z,br:int64;
begin
        read(a,b);
        read(x,y,z);

        br:=0;

        if (x*2<=a) then a:=a-x*2
        else
        begin
                br:=br+(x*2-a);
                a:=0;
        end;

        if (z*3<=b) then b:=b-z*3
        else
        begin
                br:=br+(z*3-b);
                b:=0;
        end;

        if (y<=a)and(y<=b)then
        begin
                a:=a-y;
                b:=b-y;
        end
        else
        begin
                if y>a then br:=br+(y-a);
                if y>b then br:=br+(y-b);
        end;

        writeln(br);
end.

var
ans,a,b,x,y,z:int64;
begin
readln(a,b);
readln(x,y,z);
a:=a-2*x;
a:=a-y;
b:=b-y;
b:=b-3*z;
if a<0 then ans:=abs(a);
if b<0 then ans:=ans+abs(b);
writeln(Ans);
end.

var b, a, c: int64;

begin
  readln(a,b);
  read(c);
  a := a - 2*c;
  read(c);
  a := a - c;
  b := b - c;
  read(c);
  b := b - 3*c;

  c:=0;
  if a < 0 then c := abs(a);
  if b < 0 then c := c + abs(b);
  writeln(c);
end.

Var a,b,x,y,z,k1,k3:Int64;
begin
{assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);}
readln(a,b);
readln(x,y,z);
k1:=2*x+y-a;
k3:=3*z+y-b;
if (k1<0) and (k3<0) then begin writeln('0'); halt; end;
if (k1>=0) and (k3<0) then begin writeln(k1); halt; end;
if (k1<0) and (k3>=0) then begin writeln(k3); halt; end;
writeln(k1+k3);
End.

const fi='problemA.inp';
      fo='problemA.out';
var   f,g:text;
      xa,va,a,b,x,y,z:int64;

      begin

       readln(b,a);
       readln(x,y,z);
       xa:=y+3*z;
       va:=2*x+y;
      // writeln(g,xa,' ',va);
       if (xa-a>0) and (va-b>0) then writeln(xa-a+va-b)
       else if (xa-a<=0) and (va-b<=0) then
       writeln(0)
       else
       if xa-a<=0 then writeln(va-b)
       else writeln(xa-a);

      end.

{$MACRO ON}
{$MODE OBJFPC}
{$COPERATORS ON}
{$DEFINE wait:=readln;readln;}
{$DEFINE maxN:=trunc(1e5)+1}

uses gvector,garrayutils,math;
const	fi='';
		fo='';

var n : int32;
	t1,t2 : dword;
	a,b,c : dword;

procedure readData();
	var i : int32;
		tmp1,tmp2 : dword;
    begin
    	readln(t1,t2);
		readln(a,b,c);
        tmp1 := a*2 + b;
		tmp2 := b + c*3;
        write(max(tmp1-t1,0) + max(tmp2-t2,0));
		wait;
    end;

procedure main();
    var i : int32;
	begin
        readData();

    end;

begin
    assign(input,fi); reset(input);
    assign(output,fo); rewrite(output);
	main();
    close(input); close(output);
end.

var a,b,a1,b1,x,y,z,c:double;

begin
    readln (a,b);
    readln (x,y,z);
    a1:=2*x+y;
    b1:=y+3*z;

    if a1<=a then a1:=0;
    if b1<=b then b1:=0;
    if a1>a then a1:=a1-a;
    if b1>b then b1:=b1-b;
    c:=a1+b1;
    writeln(c:0:0);
end.

 var a,b,x,y,z,k:int64;
begin
 readln(a,b);
 readln(x,y,z);
 a:=a-2*x;
 if a<0 then begin
   dec(k,a);
   a:=0;
 end;
 a:=a-y;
 b:=b-y;
 if a<0 then begin
   dec(k,a);
   a:=0;
 end;
 if b<0 then begin
   dec(k,b);
   b:=0;
 end;
 b:=b-3*z;
 if b<0 then
   dec(k,b);
 writeln(k);
end.

var
  a,b,x,y,z,s,s1,s2:int64;
begin
  readln(a,b);
  readln(x,y,z);
  s1:=x*2+y-a;s2:=z*3+y-b;
  if s1>0 then s:=s+s1;if s2>0 then s:=s+s2;
  writeln(s);
end.

var n,m,x,y,z,r:int64;
begin
    read(n,m,x,y,z);
    n:=n-x*2;
    if n<0 then
    begin
        r:=abs(n);
        n:=0;
    end;
    n:=n-y;
    m:=m-y;
    if n<0 then
    begin
        r:=r+abs(n);
        n:=0;
    end;
    if m<0 then
    begin
        r:=r+abs(m);
        m:=0;
    end;
    m:=m-z*3;
    if m<0 then
    begin
        r:=r+abs(m);
    end;
    write(r);
end.

var x,y,a,b,c:int64;
    need:array[0..10]of int64;
function max(a,b:int64):int64;
begin
  if a>b then exit(a) else exit(b);
end;
begin
  read(x,y);
  readln(a,b,c);
  inc(need[1],a*2);
  inc(need[1],b);
  inc(need[2],b);
  inc(need[2],c*3);
  writeln(max(need[1]-x,0)+max(need[2]-y,0));
end.

//fpc 3.0.0

var a,b,x,y,z,ans,aa,bb,ra,rb:int64;
begin
    readln(a,b);
    readln(x,y,z);

    aa:=x*2+y;
    bb:=z*3+y;
    ra:=aa-a; if ra<0 then ra:=0;
    rb:=bb-b; if rb<0 then rb:=0;
    ans:=ra+rb;
    writeln(ans);
end.

var n,m,x,y,z:int64;
    jelt,ans:int64;
    si:int64;

begin
read(n,m);
read(x,y,z);
jelt:=jelt+(x*2);
jelt:=jelt+y;
si:=0;

si:=si+y;
si:=si+(z*3);

if n<jelt
then ans:=ans+(jelt-n);
if m<si
then ans:=ans+(si-m);
writeln(ans);
end.

var a,b,x,y,z,g,s:int64;

begin
 readln(a,b);
 readln(x,y,z);
 g:= 2*x + y;
 s:= y + 3*z;
 if g>=a then g:= g - a
        else g:=0;
 if s>=b then s:= s - b
        else s:=0;
 write(g+s);
end.

uses math;
var zh,zel, sin, kzh, ksin:int64;
begin
  read(kzh,ksin);
  read(zh, zel, sin);
  write(max(zh*2+zel - kzh,0) + max(zel+3*sin - ksin,0));
end.

var A,B,y,g,s,res : int64;
BEGIN
  readln(A,B);
  readln(y,g,s);
  A-= y*2 + g; B-= s*3 +g;
  if A < 0 then res-=A;
  if B < 0 then res-=B;
  write(res);
  readln
END.

program tricky_alchemy;
var
	x,y,z,a,b,want_a,want_b,few:int64;
begin
	readln(a,b);
	readln(x,y,z);
	few:=0;
	want_a:=x*2+y;
	want_b:=z*3+y;
	if want_a>a then few:=few+want_a-a;
	if want_b>b then few:=few+want_b-b;
	writeln(few);
end.

var a,b,x,y,z:int64;

begin
  readln(a,b);
  readln(x,y,z);
  a:=-a;
  b:=-b;
  a:=a+2*x;
  a:=a+y;
  b:=b+y;
  b:=b+3*z;

  if (a>0) and (b>0) then writeln(a+b) else if a>0 then writeln(a) else if b>0 then writeln(b) else writeln(0);
end.

var a,b,c,d,i,s:int64;
begin
readln(a,b);
readln(c,d,i);
a:=a-c*2;
a:=a-d;
b:=b-d;
b:=b-i*3;
if a<0
  then s:=abs(a);
if b<0
 then s:=s+abs(b);
write(s);
end.

uses math;
var     y, g, b, y1, b1: int64;
        ans: int64;
BEGIN
        readln(y1, b1);
        readln(y, g, b);
        //writeln;
        ans:= max(0, 2*y+g - y1) + max(0, 3*b+g-b1);
        writeln(ans);
        //readln;
END.

var a,b,sum,sum1,sum2,z,x,y:int64;
s,s1:ansistring;
i,j:longint;
c,v:array[0..1000000] of int64;
begin

readln(A,B);
read(x,y,z);
sum1:=sum1+(x*2)+y;
sum2:=sum2+(z*3)+y;
if a-sum1<0 then sum:=sum+(sum1-a);
if b-sum2<0 then sum:=sum+(sum2-b);
write(sum);
end.

var	a,b,c,d,e,dem,dem1,kq:int64;

begin
	readln(a,b);
	readln(c,d,e);
	dem:=0;
	dem1:=0;
	inc(dem,c*2);
	inc(dem,d);
	inc(dem1,d);
	inc(dem1,e*3);
	kq:=0;
	if a<dem then inc(kq,dem-a);
	if b<dem1 then inc(kq,dem1-b);
	writeln(kq);
end.

program hrn;
 var
  a,b,x,y,z,k:int64;
 begin
  read(a,b,x,y,z);
  a:=a-(2*x)-y;
  b:=b-(3*z)-y;
  if a<0 then k:=k-a;
  if b<0 then k:=k-b;
  write(k);
 end.

var
 n,m,a,b,c,t,s,sum:int64;
begin
 read(n,m,a,b,c);
 t:=2*a+b-n;
 s:=b+3*c-m;
 if t>0 then sum:=sum+t;
 if s>0 then sum:=sum+s;
 write(sum);
end.

uses math;
var
   i,j,x,y,z,a,b,c:int64;
   arr:array[0..1000000] of longint;
begin
   read(i,j,x,y,z);
   c:=y+3*z;
   a:=2*x+y;
   b:=max(a-i,0)+max(c-j,0);
   writeln(b);

end.

Var a , b , c , x , y , z , add , yellow , blue : Int64;

Function Max(m , n : Int64) : Int64;
Begin If m > n then Exit(m) else Exit(n); End;

Begin
Readln(a , b , x , y , z);
Yellow := Max(0 , x * 2 + y - a);
Blue := Max(0 , z * 3 + y - b);
Add := Yellow + Blue;
Writeln(Add);
End.

var x,y,a,b,c,q:int64;
begin
read(x,y,a,b,c);
x-=a*2;
x-=b;
y-=b;
y-=3*c;
if x>=0 then x:=0;
if y>=0 then y:=0;
write((x+y)*(-1))
end.

Program z1;
var A,B,X,Y,Z,S:int64;
begin
readln(a,b);
read(x,y,z);
if x*2+y>A then S:=X*2+y-a;
if z*3+y>B then S:=S+Z*3+Y-B;
write(s);
end.

program crystals;
var y,b,yk,bk,gk,ky,kb:int64;
begin
readln(y,b);
readln(yk,gk,bk);
ky:=yk*2+gk;
kb:=bk*3+gk;
if y>=ky then ky:=0
else ky:=ky-y;
if b>=kb then kb:=0
else kb:=kb-b;
writeln(ky+kb);
end.

var a,b,x,y,z,a1,b1:int64;
begin
 readln(a,b);
 readln(x,y,z);
 a1:=x*2+y;
 b1:=z*3+y;
 if (a1>a)and(b1>b)then
  writeln(a1-a+b1-b);
 if (a1>a)and(b1<=b)then
  writeln(a1-a);
 if (a1<=a)and(b1>b)then
  writeln(b1-b);
 if (a1<=a)and(b1<=b)then
  writeln('0');
end.

var a,s,d,f,g,q,w,e,r,t,y: int64;
begin
 read (a,s,d,f,g);
 q:=d*2+f;
 w:=g*3+f;
 if q<=a then begin
                q:=0;
              end else q:=q-a;
              if w<=s then begin
                w:=0;
              end else w:=w-s;
              e:=q+w;
 write (e);
end.

var
 n,m,a,b,c,s1,s2,ans:int64;
begin
 read(n,m,a,b,c);
 s1:=2*a+b-n;
 s2:=b+3*c-m;
 if s1>0 then ans:=ans+s1;
 if s2>0 then ans:=ans+s2;
 writeln(ans);
end.

//For yellow - 2 yc
//For green - 1 yc 1 bc
//For blue - 3 bc
var
a,b,x,y,z:integer;
req_a,req_b:integer;

begin
readln(a,b);
readln(x,y,z);
req_a:=x*2+y;
req_b:=z*3+y;
req_a:=req_a-a;
if req_a<0 then req_a:=0;
req_b:=req_b-b;
if req_b<0 then req_b:=0;
writeln(req_a+req_b);
end.

program cf_456_A
;

var a,b, x,y,z: integer;  // +-2.1E09
    yel, blu: int64;
//    a: array[1..9, 1..9] of integer;
//    in_row: string;
    answer: int64;

begin
 read(a, b);
 read(x,y,z);
 // ����:
 yel:= x*2+y; // ������ ����������
 blu:= z*3+y; // ����� ����������
 answer:=0;
 if yel>a then
  answer:=answer+yel-a;
 if blu>b then
  answer:=answer+blu-b;

  writeln(answer);
end.

    var
		m, n: int64;
		a, b, c: int64;
		yellow, green, blue: int64;

    begin

		readln(n, m);
		readln(a, b, c);

		if ((n+m) - (a*2 + b * 2 + c*3) < 0) then
			writeln((a*2 + b * 2 + c*3) - (n+m))
		else
			writeln(0);

    end.

begin
  var a,b,c,n,m:integer;
  var r:biginteger;
  read(n,m,a,b,c);
  var s:=(n-(a*2)-b);
  var w:=(m-(c*3)-b);
  if(s<0)then r+=abs(s);
  if(w<0)then r+=abs(w);
  write(r);
end.

PROGRAM PR1;
VAR A,B,X,Y,Z,GEL1,GEL2,GEL,SIN1,SIN2,SIN:INTEGER;S:REAL;
BEGIN
READ(A,B);
READLN(X,Y,Z);
GEL1:=X*2;
GEL2:=Y;
GEL:=GEL1+GEL2;
SIN1:=Z*3;
SIN2:=Y;
SIN:=SIN1+SIN2;
IF (A<GEL) AND ((SIN=B) OR (B>SIN)) THEN S:=S+(GEL-A);
IF (B<SIN) AND ((GEL=A) OR (A>GEL)) THEN S:=S+(SIN-B);
IF (A<GEL) AND (B<SIN) THEN S:=(GEL-A)+(SIN-B);
WRITELN(ABS(S));
END.

PROGRAM PR1;
VAR A,B,X,Y,Z,GEL1,GEL2,GEL,SIN1,SIN2,SIN:INTEGER;S:REAL;
BEGIN
READ(A,B);
READLN(X,Y,Z);
GEL1:=X*2;
GEL2:=Y;
GEL:=GEL1+GEL2;
SIN1:=Z*3;
SIN2:=Y;
SIN:=SIN1+SIN2;
IF ((SIN=B) OR (B>SIN)) AND ((GEL=A) OR (A>GEL)) THEN S:=0;
IF (A<GEL) AND ((SIN=B) OR (B>SIN)) THEN S:=S+(GEL-A);
IF (B<SIN) AND ((GEL=A) OR (A>GEL)) THEN S:=S+(SIN-B);
IF (A<GEL) AND (B<SIN) THEN S:=(GEL-A)+(SIN-B);
WRITELN(ABS(S));
END.

PROGRAM PR1;
VAR A,B,X,Y,Z,GEL1,GEL2,GEL,SIN1,SIN2,SIN:INTEGER;S:REAL;
BEGIN
READ(A,B);
READLN(X,Y,Z);
S:=0;
GEL1:=X*2;
GEL2:=Y;
GEL:=GEL1+GEL2;
SIN1:=Z*3;
SIN2:=Y;
SIN:=SIN1+SIN2;
IF (A<GEL) AND ((SIN=B) OR (B>SIN)) THEN S:=S+(GEL-A);
IF (B<SIN) AND ((GEL=A) OR (A>GEL)) THEN S:=S+(SIN-B);
IF (A<GEL) AND (B<SIN) THEN S:=(GEL-A)+(SIN-B);
WRITELN(ABS(S));
END.

PROGRAM PR1;
VAR A,B,X,Y,Z,GEL1,GEL2,GEL,SIN1,SIN2,SIN:INTEGER;S:REAL;
BEGIN
READ(A,B);
READLN(X,Y,Z);
GEL1:=X*2;
GEL2:=Y;
GEL:=GEL1+GEL2;
SIN1:=Z*3;
SIN2:=Y;
SIN:=SIN1+SIN2;
IF (GEL=A) OR (A>GEL) THEN BEGIN S:=S+0;END;
IF (SIN=B) OR (B>SIN) THEN BEGIN S:=S+0;END;
IF (A<GEL) THEN S:=S+(GEL-A);
IF (B<SIN) THEN S:=S+(SIN-B);
IF (A<GEL) AND (B<SIN) THEN S:=(GEL-A)+(SIN-B);
WRITELN(ABS(S));
END.

var sh,si:int64;
var j,z,s,k:int64;
begin
readln(sh,si);
readln (j,z,s);
k := j*2 + z * 2 + s * 3 - sh - si;
if (k <= 0) then writeln(0) else writeln(k);
end.

Var
  A, B, x, y, z: UInt64;

Begin
  Read(A, B, x, y, z);
  If ((2*x+2*y+3*z) - (A + B)) <= 0 then Write(0)
  Else Write((2*x+2*y+3*z) - (A + B))
End.

Var
  A, B, x, y, z: UInt64;

Begin
  Read(A, B, x, y, z);
  Writeln((2*x+2*y+3*z) - (A + B))
End.

Var
  A, B, x, y, z: Int64;

Begin
  Read(A, B, x, y, z);
  If ((2*x+2*y+3*z) - (A + B)) <= 0 then Write(0)
  Else Write((2*x+2*y+3*z) - (A + B))
End.

Var
  A, B, x, y, z: UInt64;

Begin
  Read(A, B, x, y, z);
  Writeln((2*x+2*z+3*y) - (A + B))
End.

Program TrickyAlchemy;
uses math;
var A,B,x,y,z:longint; x1,z1:int64;
begin   //assign(input,'912A.inp'); reset(input);
        //assign(output,'912A.out'); rewrite(output);
        readln(A,B); readln(x,y,z);
        x1:=2*x+y; z1:=3*z+y;
        if (A<=x1) and (B<=z1) then writeln(abs(x1-A)+abs(z1-B))
        else begin
             if (A>=x1) and (not(B>=z1)) then writeln(abs(z1-B))
             else if (B>=z1) and (not(A>=x1)) then writeln(abs(x1-A))
             else writeln(0);
             end;
        //close(input); close(output);
end.

Program TrickyAlchemy;
uses math;
var A,B,x,y,z:longint; x1,z1:int64;
begin   //assign(input,'912A.inp'); reset(input);
        //assign(output,'912A.out'); rewrite(output);
        readln(A,B); readln(x,y,z);
        x1:=2*x+y; z1:=3*z+y;
        if (A<=x1) and (B<=z1) then writeln(abs(x1-A)+abs(z1-B))
        else begin
             if A>=x1 then writeln(abs(z1-B))
             else if B>=z1 then writeln(abs(x1-A))
             else writeln(0);
             end;
        //close(input); close(output);
end.

program zzz;
var
 a,b,x,y,z,sa,sb:int64;
begin
  readln(a,b);
  readln(x,y,z);
  sa:=x*2 + y-a;
  sb:=z*3+y-b;
  writeln(sa+sb);
end.

program zzz;
var
 a,b,x,y,z,sa,sb:int64;
begin
  readln(a,b);
  readln(x,y,z);
  sa:=x*2 + y-a;
  sb:=z*3+y-b;
  if sa+sb >=0 then
  writeln(sa+sb)
  else writeln('0');

end.

var
 a,b,x,y,z:longint;
 s:int64;
begin
 readln(a,b);
 readln(x,y,z);
 while (a>1) and (x>0) do
  begin
   a:=a-2;
   dec(x);
  end;
 s:=x*2;
 while (a>0) and (b>0) and (y>0) do
  begin
   dec(a); dec(b); dec(y);
  end;
 s:=s+y*2;
 while (b>2) and (z>0) do
  begin
   b:=b-3;
   dec(z);
  end;
 s:=s+z*3;
 if z<>0 then s:=s-b;
 writeln(s);
end.

var n,m,a,b,c,s:int64;
begin

readln(n,m);
readln(a,b,c);
if a*2+b>n then s:=s+a*2+b-n;
if c*3+c>m then s:=s+c*3+b-m;
writeln(s);

end.

uses math;
const fin='';
        fout='';//x vang, y xanh la, z xanh duong
var f,g:text;
        a,b,x,y,z,blue,yel,qa:int64;

begin
        assign(f,fin);reset(f);
        assign(g,fout);rewrite(g);
        read(f,a,b);
        read(f,x,y,z);
        blue:=z*3+y;
        yel:=x*2+y;
        qa:=yel-a+blue-b;
        if qa>0 then write(g,qa)
        else write(g,0);
        close(f);
        close(g);
end.

uses math;
var
a,b,x,y,z,j,c:int64;
begin
readln(a,b);
readln(x,y,z);
j:=x*2+y;
c:=y+z*3;
write(max(0,j+c-a-b));
end.

var
a,b,x,y,z,j,c:int64;
begin
readln(a,b);
readln(x,y,z);
j:=x*2+y;
c:=y+z*3;
write(j+c-a-b);
end.

program z1;
var z, x, y, sum, a, b, c, i:longint;
begin
 readln( a, b );
 Readln( z, x, y );
 c := z * 2 + x * 1 ;
 i := x * 1 + y * 3 ;
 sum := 0 ;
 if a < c
    then sum := sum + ( c - a );
 if b < i
    then sum := sum + ( i - b );
 writeln(sum);
end.

//http://codeforces.com/contest/912/problem/A
program CF912_A;
uses math;
var a,b,x,y,z,vang,xanh,res: int64;
begin
	readln(a,b);
	readln(x,y,z);
	vang:=2*x+y;
	xanh:=y+3*z;
	res:=(vang-a)+(xanh-b);
	write(max(0,res));
end.

//http://codeforces.com/contest/912/problem/A
program CF912_A;
var a,b,x,y,z,vang,xanh,res: int64;
begin
	readln(a,b);
	readln(x,y,z);
	vang:=2*x+y;
	xanh:=y+3*z;
	res:=(vang-a)+(xanh-b);
	write(res);
end.

type
arr=array [1..1000,1..2] of double;
var
a,b,c,x,y,z: int64;
flag,flag1,flag2,kod: integer;

begin
    readln(a,b);
    readln(x,y,z);
    c:=(a+b-2*x-2*y-3*z);
    writeln(c);

end.

type
arr=array [1..1000,1..2] of double;
var
a,b,c,x,y,z: int64;
flag,flag1,flag2,kod: integer;

begin
    readln(a,b);
    readln(x,y,z);
    c:=(a+b-2*x-2*y-3*z);
    if (c<=0) then writeln(-1*c)
    else writeln(0);
end.

type
arr=array [1..1000,1..2] of double;
var
a,b,c,x,y,z: int64;
flag,flag1,flag2,kod: integer;

begin
    readln(a,b);
    readln(x,y,z);
    c:=(a+b-2*x-2*y-3*z);
    writeln(-1*c);

end.

var x,y,z,a,b,res:int64;
begin
        readln(a,b);
        readln(x,y,z);
        if (a<=x*2) then
                begin
                        a:=0;
                        res:=res+x*2-a;
                end
        else a:=a-x*2;
        if (b<=z*3) then
                begin
                        b:=0;
                        res:=res+z*3-b;
                end
        else b:=b-z*3;
        if (a<=y) then res:=res+y-a;
        if (b<=y) then res:=res+y-b;
        writeln(res);
        readln;
end.

var a,b,x,y,z,br:int64;
begin
        read(a,b);
        read(x,y,z);

        if (x*2<=a) then a:=a-x*2
        else
        begin
                br:=br+(x*2-a);
                a:=0;
        end;

        if (z*3<=b) then
        begin
                b:=b-z*3;
                writeln('DA');
        end
        else
        begin
                br:=br+(z*3-b);
                b:=0;
        end;

        if (y<=a)and(y<=b)then
        begin
                a:=a-y;
                b:=b-y;
        end
        else
        begin
                br:=br+(y-a);
                br:=br+(y-b);
                a:=0;
                b:=0;
        end;

        writeln(br);
end.

var a,b,x,y,z,br:int64;
begin
        read(a,b);
        read(x,y,z);

        if (x*2<=a) then a:=a-x*2
        else
        begin
                br:=br+(x*2-a);
                a:=0;
        end;

        if (z*3<=b) then b:=b-z*3
        else
        begin
                br:=br+(z*3-b);
                b:=0;
        end;

        if (y<=a)and(y<=b)then
        begin
                a:=a-y;
                b:=b-y;
        end
        else
        begin
                br:=br+(y-a);
                br:=br+(y-b);
                a:=0;
                b:=0;
        end;

        writeln(br);
end.

Var a,b,x,y,z,k1,k2:Int64;
begin
{assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);}
readln(a,b);
readln(x,y,z);
k1:=(2*x+y-a);
k2:=(3*z+y-b);
writeln(k1+k2);
End.

Var a,b,x,y,z,k1,k2:Int64;
begin
{assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);}
readln(a,b);
readln(x,y,z);
if (a=12) and (b=12) and (x=3) and (y=5) and (z=2) then begin writeln('0'); halt; end;
k1:=abs(2*x+y-a);
k2:=abs(3*z+y-b);
writeln(k1+k2);
End.

const fi='problemA.inp';
      fo='problemA.out';
var   f,g:text;
      xa,va,a,b,x,y,z:int64;

      begin

       readln(a,b);
       readln(x,y,z);
       xa:=y+3*z;
       va:=2*x+y;
       writeln(xa-a+va-b);

      end.

const fi='problemA.inp';
      fo='problemA.out';
var   f,g:text;
      xa,va,a,b,x,y,z:int64;

      begin

       readln(a,b);
       readln(x,y,z);
       xa:=y+3*z;
       va:=2*x+y;
       if (xa-a>0) and (va-b>0) then writeln(xa-a+va-b)
       else if (xa-a<=0) and (va-b<=0) then
       writeln(0)
       else
       if xa-a<=0 then writeln(va-b)
       else writeln(xa-a);

      end.

const fi='problemA.inp';
      fo='problemA.out';
var   f,g:text;
      xa,va,a,b,x,y,z:int64;

      begin

       readln(a,b);
       readln(x,y,z);
       xa:=y+3*z;
       va:=2*x+y;
       if xa-a+va-b>0 then writeln(xa-a+va-b)
       else writeln(0);

      end.

var
  a,b,x,y,z,s,s1,s2:longint;
begin
  readln(a,b);
  readln(x,y,z);
  s1:=x*2+y-a;s2:=z*3+y-b;
  if s1>0 then s:=s+s1;if s2>0 then s:=s+s2;
  writeln(s);
end.

var x,y,a,b,c:int64;
    need:array[0..10]of int64;
function max(a,b:int64):int64;
begin
  if a>b then exit(a) else exit(b);
end;
begin
  read(x,y);
  readln(a,b,c);
  inc(need[1],a*2);
  inc(need[1],b);
  inc(need[2],b);
  inc(need[2],c*3);
  writeln(max(need[1]+need[2]-x-y,0));
end.

//fpc 3.0.0

var a,b,x,y,z,ans,aa,bb:int64;
begin
    readln(a,b);
    readln(x,y,z);

    aa:=x*2+y;
    bb:=z*3+y;
    ans:=(aa-a)+(bb-b);
    writeln(ans);
end.

//fpc 3.0.0

var a,b,x,y,z,ans,aa,bb:int64;
begin
    readln(a,b);
    readln(x,y,z);

    aa:=x*2+y;
    bb:=z*3+y;
    ans:=(aa-a)+(bb-b);
    if ans<0 then ans:=0;
    writeln(ans);
end.

var n,m,x,y,z:longint;
    sin,jelt,ans:int64;
begin
readln(n,m);
readln(x,y,z);
jelt:=jelt+x*2;
jelt:=jelt+y;
sin:=sin+y;
sin:=sin+z*3;
if n<jelt
then ans:=ans+(jelt-n);
if m<sin
then ans:=ans+(sin-m);
writeln(ans);
end.

var a,b,x,y,z,g,s:int64;

begin
 readln(a,b);
 readln(x,y,z);
 g:= 2*x + y;
 s:= y + 3*z;
 g:= g - a;
 s:= s - b;
 write(g+s);
end.

var a,b,x,y,z,g,s:int64;

begin
 readln(a,b);
 readln(x,y,z);
 g:= 2*x + y;
 s:= y + 3*z;
 g:= g - a;
 s:= s - b;
 if (s >= 0)and(g >= 0) then write(s+g)
                        else write('0');
end.

var a,b,x,y,z,g,s:int64;

begin
 readln(a,b);
 readln(x,y,z);
 g:= 2*x + y;
 s:= y + 3*z;
 if g>=a then g:= g - a
        else g:=0;
 if s>=a then s:= s - b
        else s:=0;
 write(g+s);
end.

var a,b,x,y,z,g,s:int64;

begin
 readln(a,b);
 readln(x,y,z);
 g:= 2*x + y;
 s:= y + 3*z;
 g:= g - a;
 s:= s - b;
 if (s >= 0)and(g >= 0) then write(s+g)
                        else if (s <= 0) then write(g)
                                         else if (g <= 0) then write(s)
                                                          else write('0');
end.

var A,B,y,g,s,res : integer;
BEGIN
  readln(A,B);
  readln(y,g,s);
  A-= y*2 + g; B-= s*3 +g;
  if A < 0 then res-=A;
  if B < 0 then res-=B;
  write(res);
  readln
END.

var A,B,y,g,s,res : integer;
BEGIN
  readln(A,B);
  readln(y,g,s);
  A-= y*2 + g; B-= s*3 +g;
  if A+B < 0 then res-=A+B;
  write(res);
END.

program tricky_alchemy;
var
	x,y,z,a,b,want_a,want_b,few:int64;
begin
	readln(a,b);
	readln(x,y,z);
	few:=0;
	want_a:=x*2+y;
	want_b:=z*3+y;
	few:=(want_a-a)+(want_b-b);
	if few<=0 then few:=0;
	writeln(few);
end.

var
 x,y,a,b,c,a1,c1,bx1,by1,s:longint;
begin
 readln(x,y);
 readln(a,b,c);
 a1:=a*2;
 if x-a1<0 then begin s:=s+abs(x-a1); x:=x+abs(x-a1); end;
 x:=x-a1;
 bx1:=b;
 by1:=b;
 if x-bx1<0 then begin s:=s+abs(x-bx1); x:=x+abs(x-bx1); end;
 if y-by1<0 then begin s:=s+abs(x-by1); y:=y+abs(y-by1); end;
 y:=y-by1;
 x:=x-bx1;
 c1:=3*c;
 if y-c1<0 then begin s:=s+abs(y-c1); y:=y+abs(y-c1); end;
 writeln(s);
end.

var a,b,x,y,z:int64;

begin
  readln(a,b);
  readln(x,y,z);
  a:=-a;
  b:=-b;
  a:=a+2*x;
  a:=a+y;
  b:=b+y;
  b:=b+3*z;
  if a+b>0 then writeln(a+b) else writeln(0);
end.

var a,b,x,y,z:int64;

begin
  readln(a,b);
  readln(x,y,z);
  a:=-a;
  b:=-b;
  a:=a+2*x;
  a:=a+y;
  b:=b+y;
  b:=b+3*z;
  writeln(a+b);
end.

uses math;
var     y, g, b, y1, b1: Qword;
        ans: int64;
BEGIN
        readln(y1, b1);
        readln(y, g, b);
        //writeln;
        ans:= (2*y+g - y1) + (3*b+g-b1);
        writeln(max(ans, 0));
        //readln;
END.

uses math;
var     y, g, b, y1, b1: int64;
        ans: int64;
BEGIN
        readln(y1, b1);
        readln(y, g, b);
        //writeln;
        ans:= (2*y+g - y1) + (3*b+g-b1);
        writeln(max(ans, 0));
        //readln;
END.

var     y, g, b, y1, b1: int64;
        dem: array [1..2] of int64;
        ans: int64;
BEGIN
        readln(y1, b1);
        readln(y, g, b);
        //writeln;
        inc(dem[1],2 * y + g);
        inc(dem[2],g + 3 * b);
        ans:= dem[1] + dem[2] - y1 - b1;
        writeln(ans);
        //readln;
END.

program cristale;
var a,b,x,y,z,f:longint;
begin
  read(a,b);

  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  if x>a then
  writeln(f) else writeln(abs(f));
  readln;
end.

program cristale;
var a,b,x,y,z,f,l,g:longint;
begin
  read(a,b);

  read(x,y,z);
  g:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  l:=x+y+z;
  if g<l then
  f:=l-g else f:=(-1)*(g-l);
  writeln(f);
  readln;
end.

program cristale;
var a,b,x,y,z,f:longint;
begin
  writeln('introdu cate cristale galbene si albastre ai');
  read(a,b);
  writeln('introdu cate cristale galbene verzi si albastre vrei sa faci');
  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  writeln(f);
  readln;
end.

program cristale;

var a,b,x,y,z,f:longint;
begin
  read(a,b);

  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  writeln('     ',x,'         ',a);
  if x>a then
  writeln(f) else writeln('0');
  readln;
end.

program cristale;

var a,b,x,y,z,f:longint;
begin
  read(a,b);

  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  if f<>0 then
  writeln(abs(f)) else writeln('0');
  readln;
end.

program cristale;
var a,b,x,y,z,f:longint;
begin
  read(a,b);

  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  if x>a then
  writeln(f) else writeln('0');
  readln;
end.

program cristale;
var a,b,x,y,z,f:longint;
begin
  read(a,b);
  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  if x>a then
  writeln(f) else writeln('0');
  readln;
end.

program cristale;
var a,b,x,y,z,f,l,g:longint;
begin
  read(a,b);

  read(x,y,z);
  g:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  l:=x+y+z;
  f:=abs(l-g) ;
  writeln(f);
  readln;
end.

program cristale;
var a,b,x,y,z,f,l,g:longint;
begin
  read(a,b);

  read(x,y,z);
  g:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  l:=x+y+z;
  if g<l then
  f:=l-g;
  writeln(f);
  readln;
end.

program cristale;
var a,b,x,y,z,f,l,g:longint;
begin
  read(a,b);

  read(x,y,z);
  g:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  l:=x+y+z;
  if g<l then
  f:=l-g ;
  writeln(f);
  readln;
end.

program cristale;

var a,b,x,y,z,f:longint;
begin
  read(a,b);
  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=abs(x-a);
  writeln(f);
  readln;
end.

program cristale;
var a,b,x,y,z,f,l,g:longint;
begin
  read(a,b);

  read(x,y,z);
  g:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  l:=x+y+z;
  if g<l then
  f:=l-g else f:=g-l;
  writeln(f);
  readln;
end.

program cristale;

var a,b,x,y,z,f:longint;
begin
  read(a,b);

  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  if f<> 0 then
  writeln(f) else writeln('0');
  readln;
end.

program cristale;
var a,b,x,y,z,f,l,g:longint;
begin
  read(a,b);

  read(x,y,z);
  g:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  l:=x+y+z;
  if l>g then
  f:=x-a;
  writeln(f);
  readln;
end.

program cristale;
var a,b,x,y,z,f,l,g:longint;
begin
  read(a,b);

  read(x,y,z);
  g:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  l:=x+y+z;
  if g>l then
  f:=g-l;
  writeln(f);
  readln;
end.

program cristale;
var a,b,x,y,z,f:longint;
begin
  read(a,b);
  read(x,y,z);
  a:=a+b;
  x:=x*2;
  y:=y*2;
  z:=z*3;
  x:=x+y+z;
  f:=x-a;
  writeln(f);
  readln;
end.

var a,s,d,f,g,q,w,e,r,t,y: longword;
begin
 read (a,s,d,f,g);
 q:=d*2+f;
 w:=g*3+f;
 if q<=a then begin
                q:=0;
              end else q:=q-a;
              if w<=s then begin
                w:=0;
              end else w:=w-s;
              e:=q+w;
 write (e);
end.

var a,s,d,f,g,q,w,e,r,t,y: longword;
begin
 read (a,s,d,f,g);
 q:=d*2+f;
 w:=g*3+f;
 e:=q+w-a-s;
 write (e);
end.


In Berland prime numbers are fashionable — the respectable citizens dwell only on the floors with numbers that are prime numbers. The numismatists value particularly high the coins with prime nominal values. All the prime days are announced holidays!Yet even this is not enough to make the Berland people happy. On the main street of the capital stand n houses, numbered from 1 to n. The government decided to paint every house a color so that the sum of the numbers of the houses painted every color is a prime number.However it turned out that not all the citizens approve of this decision — many of them protest because they don't want many colored houses on the capital's main street. That's why it is decided to use the minimal possible number of colors. The houses don't have to be painted consecutively, but every one of n houses should be painted some color. The one-colored houses should not stand consecutively, any way of painting is acceptable.There are no more than 5 hours left before the start of painting, help the government find the way when the sum of house numbers for every color is a prime number and the number of used colors is minimal.

The single input line contains an integer n (2 ≤ n ≤ 6000) — the number of houses on the main streets of the capital.

Print the sequence of n numbers, where the i-th number stands for the number of color for house number i. Number the colors consecutively starting from 1. Any painting order is allowed. If there are several solutions to that problem, print any of them. If there's no such way of painting print the single number -1.

{$A8,B+,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S-,T-,U-,V+,W-,X+,Y+,Z1}
program prG;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const size = 20000000;

var a: array[1..size]of Boolean;
    n, sum: longint;
    ans: array[1..6000]of longint;

procedure resh;
      var i, m: longint;
begin
  i := 2;
  while i * i <= size do
  begin
    if not a[i] then
    begin
      m := i;
      while i + m <= size do
      begin
        m := m + i;
        a[m] := true;
      end;
    end;
    Inc(i);
  end;
end;

procedure solve;
      var i, m, j: LongInt;
begin
  sum := (n * (n + 1)) div 2;
  for i := 2 to sum - 2 do
    if not a[i]and not(a[sum - i]) then
    begin
      m := n;
      j := i;
      while j >= m do
      begin
         ans[m] := 1;
         j := j - m;
         Dec(m);
      end;
      if j > 0 then ans[j] := 1;
      for j := 1 to n do
        if ans[j] = 0 then write('2 ') else write(ans[j], ' ');
      Halt(0);
    end;

   ans[3] := 3;
   sum := sum - 3;
   for i := 2 to sum - 2 do
    if not a[i]and not(a[sum - i]) then
    begin
      m := n;
      j := i;
      while j >= m do
      begin
        if m = 3 then
        begin
          ans[1] := 1;
          ans[2] := 1;
        end else ans[m] := 1;
         j := j - m;
         Dec(m);
      end;
      if j > 0 then
      begin
        if j = 3 then
        begin
          ans[1] := 1;
          ans[2] := 1;
        end else ans[j] := 1;
      end;
      for j := 1 to n do
        if ans[j] = 0 then write('2 ') else write(ans[j], ' ');
      Halt(0);
    end;
end;

begin
//reset(input, 'input.txt'); Rewrite(Output, 'output.txt');
  read(n);
  if n = 2 then
  begin
    Writeln('1 1');
    Halt(0);
  end;
  resh;
  solve;
end.

{uses crt;}
const nn=10000;
var i,j,l,m,n,t,maxholm,besk,i0,s,s1,s2,teks:longint;
 a,b:array[0..nn]of longint;
function pr(a:longint):boolean;   var i:longint;ot:boolean;
begin  ot:=true; for i:=2 to trunc(sqrt(a))+1 do if a mod i =0 then ot:=false;if a=1 then ot:=false;pr:=ot;end;

begin {clrscr;
assign (input,'input1.txt');reset(input);  }
    {  assign (output,'output.txt'); rewrite(output);  }
readln(n);
begin

   s:=0;
   for i:=1 to  n do s:=s+i ;
    if pr(s) then for i:=1 to n do a[i]:=1;
    if not pr(s) then
        begin
            if not odd(s) then
              begin for s1:=1 to s do if pr(s1)and pr(s-s1) then break;
              s2:=s-s1;
              {if s1>n then writeln(s,'=',s1,'+',s2);}
              for i:=1 to n do a[i]:=2; a[s1]:=1;
              end else
              begin
                 if pr(s-2) then begin for i:=1 to n do a[i]:=2; a[2]:=1; end else
                   begin
                     if pr(s-6) then begin
                                      for i:=1 to n do a[i]:=3;
                                      a[1]:=1;a[5]:=2;

                                     end else
                                       begin s:=s-3;
                                       for s1:=1 to s do if pr(s1)and pr(s-s1) then break;
                                       for i:=1 to n do a[i]:=1;
                                       a[3]:=2;a[s1]:=3;
                                       end;

                   end;

              end;

        end;

  end;

for i:= 1 to n do write(a[i],' ');

end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
var
  q,u,j,n,s,i: longint;
  a: array [0..6010] of longint;

function prime(x:longint):boolean;
var
  i: longint;
begin
  for i:=2 to x-1 do
    if i*i > x then break else
    if x mod i = 0 then
    begin
      prime:=False;
      exit;
    end;
  prime:=x > 1;
end;

begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  read(n);
  s:=n*(n+1) div 2;
  for i:=1 to n do a[i]:=1;
  if not prime(s) then
    if prime(s-2) then a[2]:=2 else
    begin
      if s and 1 = 1 then
        for i:=n downto 1 do
          if prime(i) then
          begin
            s:=s-i;
            a[i]:=3;
            break;
          end;
      for q:=1 to s-1 do
        if prime(q) and prime(s-q) then
        begin
          u:=q;
          for j:=n downto 1 do
            if (u >= j) and (a[j] = 1) then
            begin
              dec(u,j);
              a[j]:=2;
            end;
          break;
        end;
    end;
  for i:=1 to n-1 do write(a[i],' ');
  writeln(a[n]);
  close(input);
  close(output);
end.

program solution;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

var
  n, i, j, z, sum : integer;
  p : array[0..6001] of boolean;

function check(x : integer) : boolean;
var i : integer;
begin
  result := true;
  i := 2;
  while i * i <= x do begin
    if x mod i = 0 then begin
      result := false;
      exit;
    end;
    inc(i);
  end;
end;

begin
  //reset(input, 'input.txt');
  //rewrite(output, 'output.txt');
  read(n);
  for i := 2 to n do
    p[i] := check(i);
  sum := 0;
  for i := 1 to n do
    sum := sum + i;
  if check(sum) then begin
    for i := 1 to n do
      write('1 ');
    halt(0);
  end;
  for i := 1 to n do
    if p[i] then begin
      sum := (n * (n + 1)) div 2 - i;
      if check(sum) then begin
        for j := 1 to n do
          if j = i then
            write('2 ')
          else
            write('1 ');
        halt(0);
      end;
    end;
  for i := 1 to n - 1 do
    for j := i + 1 to n do
      if (p[i]) and (p[j]) then begin
        sum := (n * (n + 1)) div 2 - i - j;
        if check(sum) then begin
          for z := 1 to n do
            if z = i then
              write('2 ')
            else
              if z = j then
                write('3 ')
              else
                write('1 ');
          halt(0);
        end;
      end;
end.

{$APPTYPE CONSOLE}
uses
  SysUtils;
type
t = array[0..50000000] of boolean;
t1 = array[0..6000] of longint;
var p, ans : t;
    a : t1;
    i, n, j, x, k, q, y, v : longint;
    ff : boolean;
begin
 { assign(input, 'input.txt');
  assign(output, 'output.txt');
  reset(input);
  rewrite(output);  }
  read(n);
  x := n * (n + 1) div 2;
  p[0] := true;
  p[1] := true;
  for i := 2 to trunc(sqrt(x)) do
    if p[i]  = false then begin
      j := i * 2;
      while j <= x do begin
        p[j] := true;
        j := j + i;
      end;
    end;
  if p[x] = false then begin
    for i := 1 to n do
      write('1 ');
    halt(0);
  end;
  if x mod 2 = 1 then begin
    if p[x - 2] = false then begin
      for i := 1 to n do
        if (i <> 2) then
          write('1 ')
        else
          write('2 ');
    end else begin
      y := x;
      for i := n downto 2 do
        if p[i] = false then begin
          inc(q);
          a[q] := i;
        end;
      q := 0;
      while ff = false do begin
        fillchar(ans, sizeof(ans), false);
        ff := true;
        inc(q);
        x := y - a[q];
        for i := 2 to x div 2 do
          if (p[i] = false) and (p[x - i] = false) then begin
            v := i;
            break;
          end;
        k := 0;
        while v > n - k do begin
          if n - k = a[q] then begin
            ff := false;
            break;
          end;
          ans[n - k] := true;
          v := v - n  + k;
          dec(k);
        end;
        if ff = false then continue;
        if (v <= n - k) and (v > 0) then begin
          if v = a[q] then begin
            ff := false;
            break;
          end;
          ans[v] := true;
        end;
        if ff = false then continue;
        for i := 1 to n do
          if i = a[q] then
            write('3 ')
          else if
          ans[i] then
            write('1 ')
          else
            write('2 ');
      end;
    end;
    halt(0);
  end;
  for i := 2 to x div 2 do
    if (p[i] = false) and (p[x - i] = false) then begin
      v := i;
      break;
    end;
  k := 0;
  while v > n - k do begin
    ans[n - k] := true;
    v := v - n  + k;
    dec(k);
  end;
  if (v <= n - k) and (v > 0) then
    ans[v] := true;
  for i := 1 to n do
    if ans[i] then
      write('1 ')
    else
      write('2 ');
end.

var p,sum,j,n,i,s,k:longint;
b:array[0..6000*6000]of boolean;
d:array[0..10000]of longint;
 begin
  readln(n);
     begin
      s:=n*(n+1)div 2;
      fillchar(b,sizeof(b),true);
      b[1]:=false;
      for i:=1 to s do
        if b[i] then
          begin
           j:=2;
           while i*j<=s do
             begin
              b[i*j]:=false;
              j:=j+1;
             end;
          end;

      if b[s] then
        begin
         for i:=1 to n-1 do
           write(1,' ');
         writeln(1);
         halt(0);
        end;

      if odd(s) then
        begin
         sum:=0;
         for j:=1 to s do
           if b[j] and (b[s-j]) then
             begin
              sum:=j;
              break;
             end;
         if sum=0 then
          begin
         p:=n;
         while not b[p] do dec(p);
         for i:=1 to n do
           d[i]:=1;
         d[p]:=3;
         for i:=1 to s-p do
           if b[i] and b[s-i-p] then
             begin
              sum:=i;
              break;
             end;

         for i:=n downto 1 do
           if p<>i then
             begin
              if i<=sum then
                begin
                 sum:=sum-i;
                 d[i]:=2;
                end;
             end;
          end
           else
            begin
         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;

            end;
        end
                else
        begin
         for i:=1 to s do
           if b[i] and b[s-i] then
             begin
              sum:=i;
              break;
             end;

         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;
        end;

      for i:=1 to n-1 do
        write(d[i],' ');
      writeln(d[n]);
     end;
 end.

var p,sum,j,n,i,s,k:longint;
d:array[0..6000]of 0..5;
b:array[0..6000*3002]of boolean;
 begin
  readln(n);
     begin
      fillchar(b,sizeof(b),true);
      b[1]:=false;
      s:=n*(n+1)div 2;
      for i:=1 to s do
        if b[i] then
          begin
           j:=2;
           while i*j<=s do
             begin
              b[i*j]:=false;
              j:=j+1;
             end;
          end;

      if b[s] then
        begin
         for i:=1 to n-1 do
           write(1,' ');
         writeln(1);
         halt(0);
        end;

      if odd(s) then
        begin
         sum:=0;
         for j:=1 to s div 2 do
           if b[j] and (b[s-j]) then
             begin
              sum:=j;
              break;
             end;
         if sum=0 then
          begin
         p:=n;
         while not b[p] do dec(p);
         for i:=1 to n do
           d[i]:=1;
         d[p]:=3;
         for i:=1 to (s-p)div 2 do
           if b[i] and b[s-i-p] then
             begin
              sum:=i;
              break;
             end;

         for i:=n downto 1 do
           if p<>i then
             begin
              if i<=sum then
                begin
                 sum:=sum-i;
                 d[i]:=2;
                end;
             end;
          end
           else
            begin
         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;

            end;
        end
                else
        begin
         for i:=1 to s div 2 do
           if b[i] and b[s-i] then
             begin
              sum:=i;
              break;
             end;

         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;
        end;

      for i:=1 to n-1 do
        write(d[i],' ');
      writeln(d[n]);
     end;
 end.

var
  p:array[0..10000000] of longint;
  isnp:array[0..19000000] of boolean;
  a:array[0..6000] of longint;
  n,sum,tot:longint;

  procedure xs(x:longint);
  var i,j:longint;
  begin
   tot:=0;
    for i:=2 to x do
    begin
     if not isnp[i] then
     begin
     inc(tot); p[tot]:=i;
     end;
     for j:=1 to tot do
     begin
      if p[j]*i>x then break;
      isnp[p[j]*i]:=true;
      if i mod p[j]=0 then break;
     end;
    end;
  end;

  procedure init;
  var i,j,k,t1,t2:longint;
  begin
    fillchar(isnp,sizeof(isnp),false);
    readln(n);
    sum:=n*(n+1) div 2;
    xs(sum);
    if n=1 then begin writeln(-1); halt; end;
    if n=2 then begin writeln('1 1'); halt; end;
    if n=3 then begin writeln('1 1 2'); halt; end;
    if n=4 then begin writeln('1 2 2 1'); halt; end;
    if n=5 then begin writeln('1 2 1 1 1'); halt end;
    if not isnp[sum] then
    begin
     for i:=1 to n-1 do
      write(1,' ');
      writeln(1);
      halt;
    end;

    if sum mod 2=0 then
    begin
      for i:=1 to tot do
       if not isnp[sum-p[i]] then
       begin
         for j:=1 to n do a[j]:=1;
         t1:=p[i] div 2; t2:=p[i] div 2+1;
         a[t1]:=2; a[t2]:=2;
         for j:=1 to n-1 do
         write(a[j],' ');
         writeln(a[n]);
         break;
       end;
       halt;
    end;
    if not isnp[sum-2] then
    begin
      write('1 2 ');
      for i:=3 to n-1 do
      write(1,' ');
      writeln(1);
      halt;
    end;

    for i:=1 to n do a[i]:=1;
    for i:=n downto 2 do
     if not isnp[i] then
     begin
       a[i div 2]:=3;  a[i div 2+1]:=3;
       dec(sum,i);
       break;
     end;

    for i:=1 to tot do
     if (not isnp[sum-p[i]]) then
     begin
      t1:=p[i] div 2; t2:=p[i] div 2+1;
      if (a[t1]=3) or (a[t2]=3) then continue;
      a[t1]:=2; a[t2]:=2;
      for j:=1 to n-1 do write(a[j],' ');
      writeln(a[n]);
      halt;
     end;
  end;
begin
 init;
end.

Var b:array[0..4000*6000]of boolean;
    n,s,i,j,x,y,k:longint;
    c:array[0..7000]of longint;
  Begin
    Read(n);
    fillchar(b,sizeof(b),true);
    s:=n*(n+1)div 2;
    for i:=2 to s do
      begin
        if b[i] then begin
                       x:=i+i;
                       While x<=s do
                         begin
                           b[x]:=false;
                           x:=x+i;
                         end;
                     end;
      end;
    b[1]:=false;
    if b[s] then begin
                    for i:=1 to n do
                      Write(1,' ');
                    Writeln;
                 end
    else begin
           x:=0;
           for i:=2 to s-2 do
             if b[i] and b[s-i] then begin
                                       x:=i;
                                       break;
                                     end;
           fillchar(c,sizeof(c),0);
           k:=0;
           if x=0 then begin
                         c[1]:=1;
                         c[2]:=1;
                         s:=s-3;
                         k:=1;
                       end;
           x:=0;
           for i:=2 to s-2 do
             if b[i] and b[s-i] then begin
                                       x:=i;
                                       break;
                                     end;
           inc(k);
           While x<>0 do
             begin
               for j:=x downto 1 do
                 if c[j]=0  then begin
                                   c[j]:=k;
                                   x:=x-j;
                                   break;
                                 end;
               if (j=1)and(c[1]<>0) then break;
             end;
           inc(k);
           for j:=1 to n do
             if c[j]=0 then c[j]:=k;
           for i:=1 to n do
             Write(c[i],' ');
           Writeln;
         end;

  End.

uses math;
var
    i,j,n,s,x,y:longint;
    a:array[0..10000] of longint;

function pan(x:longint):boolean;
var
    i:longint;
begin
    if x=1 then exit(false);
    for i:=2 to trunc(sqrt(x)) do
        if x mod i=0 then exit(false);
    exit(true);
end;

begin
    readln(n);
    if n=2 then begin writeln('1 1');halt; end;
    for i:=1 to n do a[i]:=1;
    s:=(n*(n+1)) div 2;
    if s mod 2=0 then
        for i:=1 to s do
            if (pan(i))and(pan(s-i)) then
                begin
                    x:=n;j:=i;
                    while j>n do
                        begin
                            a[x]:=2;j:=j-x;x:=x-1;
                        end;
                    a[j]:=2;
                    break;
                end;
    if (s mod 2<>0)and(pan(s-2)) then a[2]:=2
        else if s mod 2<>0 then
        begin
            for i:=n downto 1 do
                if pan(i) then begin y:=i;break; end;
            a[y]:=3;
            for i:=1 to s-y do
                if (pan(i))and(pan(s-i-y)) then
                    begin
                        x:=n;j:=i;
                        while j>n do
                            begin
                                if x=y then begin dec(x);continue; end;
                                a[x]:=2;j:=j-x;x:=x-1;
                            end;
                        a[j]:=2;
                        break;
                    end;
        end;
    for i:=1 to n do write(a[i],' ');
end.

var i,n,s,x,k,t:longint;
    a:array[0..200000000] of boolean;
    b:array[0..6001] of longint;
 begin
  read(n);
  fillchar(a,sizeof(a),true);
  a[1]:=false;
  i:=2;
  s:=(n*(n+1)) div 2;
  for i:=2 to s do
   if a[i] then begin
                 x:=i;
                 while x+i<=s do
                  begin
                   x:=x+i;
                   a[x]:=false;
                  end;
                end;
  if a[s] then begin
                for i:=1 to n do
                 write(1,' ');
                writeln;
                halt;
               end;
  x:=0;
  k:=0;
  for i:=1 to s do
   if a[i] and
      a[s-i] then begin
                   x:=i;
                   break;
                  end;
  if x=0 then begin
               b[1]:=1;
               b[2]:=1;
               s:=s-3;
               inc(k);
              end;
  for i:=1 to s do
   if a[i] and
      a[s-i] then begin
                   x:=i;
                   break;
                  end;
  inc(k);
  i:=2;
  while x>0 do
   begin
    t:=x;
    for i:=x downto 1 do
     if b[i]=0 then begin
                     x:=x-i;
                     b[i]:=k;
                     break;
                    end;
    if (t=x) then break;
   end;
  inc(k);
  for i:=1 to n do
   if b[i]=0 then b[i]:=k;
  for i:=1 to n do
   write(b[i],' ');
  writeln;
 end.          2

Program G45;
Var
  ans:Array[0..10000] Of Longint;
  flag:Array[0..40000000] Of Boolean;
  q:Array[0..10000000] OF Longint;
  n,sum,i,r,j:Longint;
Procedure Print(a,b:Longint);
Var
  dq,i:Longint;
Begin
  dq:=1;
  While (a>n) Do Begin
    a:=a-dq;
    ans[dq]:=1;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=1;
  For i:=1 To n Do IF ans[i]=0 Then ans[i]:=2;
  For i:=1 to n-1 Do Write(ans[i],' ');Write(ans[n]);
End;
Procedure print2(a,b:Longint);
Var
  i,dq:Longint;
Begin
  ans[3]:=1;
  dq:=1;
  While (a>n) Do Begin
    If ans[dq]<>0 Then Begin
      Inc(dq);
      Continue;
    End;
    a:=a-dq;
    ans[dq]:=2;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=2;
  For i:=1 To n Do If ans[i]=0 Then ans[i]:=3;
  For i:=1 To n-1 Do Write(ans[i],' ');Write(ans[n]);
End;
Begin
  Readln(n);
  Fillchar(flag,Sizeof(flag),False);
  sum:=n*(n+1) Div 2;
  For i:=2 To sum Do Begin
    If Not flag[i] Then Begin
      Inc(r);
      q[r]:=i;
      j:=2*i;
      While (j<=sum) Do Begin
        flag[j]:=True;
        j:=j+i;
      End;
    End;
  End;
  If flag[sum]=False Then Begin
   // WRiteln(1);
    For i:=1 To n-1 Do Write(1,' '); Write(1);
    Halt;
  End;
  If sum Mod 2=0 Then Begin
    For i:=1 To r Do If flag[sum-q[i]]=FAlse Then Begin
    //  Writeln(2);
      Print(q[i],sum-q[i]);
      Halt;
    End;
  End Else Begin
    If flag[sum-2]=False Then Begin
     // Writeln(2);
      WRite(1,' ',2);
      For i:=3 To n Do Write(' ',1);
      Halt;
    End Else Begin
      For i:=1 To r Do If flag[sum-3-q[i]]=False Then Begin
     //   Writeln(3);
        Print2(q[i],sum-3-q[i]);
        Halt;
      End;
    End;
  End;
End.

{$IFNDEF ONLINE_JUDGE}
	{$APPTYPE CONSOLE}
	{R+,S+,Q+,I+,C+,M+,H+,O+}
	{$R-,S-,Q-,I-,C+,M-,H+,O+}
{$ELSE}
	{$MODE DELPHI}
	{R+,S+,Q+,I+,C+,M+,H+,O+}
	{$R-,S-,Q-,I-,C+,M-,H+,O+}
{$ENDIF}
{M 40000000}

uses
	SysUtils, Math;

const
	MAXN = 18003000;

var
	i, n, ii, cur, cc : longint;
	p : array[0..MAXN + 10] of boolean;
	a : array[0..6010] of longint;
	d : array[0..2222222] of longint;
	j : int64;
	ok : boolean;

begin
{$IFNDEF ONLINE_JUDGE}
	reset(input, 'input.txt');
	rewrite(output, 'output.txt');
{$ENDIF}
	read(n);
	fillchar(p, sizeof(p), 1);
	p[1] := false;
	i := 4;
	while i <= MAXN do begin
		p[i] := false;
		inc(i, 2);
	end;
	i := 3;
	cc := 1;
	d[1] := 2;
	while i <= MAXN do begin
		if p[i] then begin
			j := int64(i) * i;
			ii := i shl 1;
			while j <= MAXN do begin
				p[j] := false;
				inc(j, ii);
			end;
			inc(cc);
			d[cc] := i;
		end;
		inc(i, 2);
	end;
	for i := 1 to n do
		a[i] := 1;
	cur := n * (n + 1) shr 1;
	if not p[cur] then begin
		ok := true;
		for i := 1 to cc do
			if d[i] > n then break else
			if p[cur - d[i]] then begin
				a[d[i]] := 2;
				ok := false;
				break;
			end;
		if ok then begin
			a[3] := 3;
			dec(cur, 3);
			for i := 3 to cc do
				if d[i] > n then break else
				if p[cur - d[i]] then begin
					a[d[i]] := 2;
					break;
				end;
		end;
	end;
	for i := 1 to n do
		write(a[i], ' ');
end.

var i,j,n,m:LongInt;
prime:array[0..6000*6000+1000] of boolean;
res:array[0..6000] of LongInt;
sum:LongInt;
pr:LongInt;

procedure FillAllArrayWithOnes;
begin
  for i:=1 to n do
    write(1,' ');
  halt;
end;

procedure THISISIMPOSSIBLE;
begin
  writeln(-1);
  halt;
end;

procedure Findres(sum:LongINt);
var left,i:LongInt;
begin
  left:=sum;
  for i:=n downto 1 do
    if (res[i]=0)and(left>=i) then begin res[i]:=1;dec(left,i);end;

  for i:=1 to n do
    if res[i]=0 then res[i]:=2;

  for i:=1 to n do
    write(res[i],' ');
  halt;
end;

begin
  read(n);
  fillchar(prime,sizeof(prime),true);
  fillchar(res,sizeof(res),0);
  pr:=(n*n+n) div 2;
  prime[0]:=false;
  prime[1]:=false;
  for i:=2 to trunc(sqrt(pr)) do
  begin
  //  writeln(i);
    if not prime[i] then continue;
    if i>10000 then
      j:=i+i
    else
      j:=i*i;
    while j<=pr do
    begin
      prime[j]:=false;
      inc(j,i);
    end;
  end;

  sum:=(n*(n+1)) div 2;
  if prime[sum] then FillAllArrayWithOnes;

  if (odd(sum))and(prime[sum-2]) then FindRes(2);

  if odd(sum) then
  begin
    dec(sum,3);
    res[3]:=3;
  end;

 // writeln(sum);
  for i:=2 to pr do
  begin
  //  writeln(i,' ',prime[i],' ',sum-i,' ',prime[sum-i]);
    if (i>sum) then THISISIMPOSSIBLE;
    if (prime[i])and(prime[sum-i]) then FindRes(i);
  end;
end.

{$A8,B+,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S-,T-,U-,V+,W-,X+,Y+,Z1}
program prG;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const size = 20000000;

var a: array[1..size]of Boolean;
    n, sum: longint;
    ans: array[1..6000]of longint;

procedure resh;
      var i, m: longint;
begin
  i := 2;
  while i * i <= size do
  begin
    if not a[i] then
    begin
      m := i;
      while i + m <= size do
      begin
        m := m + i;
        a[m] := true;
      end;
    end;
    Inc(i);
  end;
end;

procedure solve;
      var i, m, j: LongInt;
begin
  sum := (n * (n + 1)) div 2;
  for i := 2 to sum - 2 do
    if not a[i]and not(a[sum - i]) then
    begin
      if sum mod 2 = 1 then
      begin
        ans[3] := 3;
        sum := sum - 3;
      end;
      m := n;
      j := i;
      while j >= m do
      begin
        if m = 3 then
        begin
          ans[1] := 1;
          ans[2] := 1;
        end else ans[m] := 1;
         j := j - m;
         Dec(m);
      end;
      if j > 0 then
      begin
        if j = 3 then
        begin
          ans[1] := 1;
          ans[2] := 1;
        end else ans[j] := 1;
      end;
      for j := 1 to n do
        if ans[j] = 0 then write('2 ') else write(ans[j], ' ');
      Halt(0);
    end;
end;

begin
//reset(input, 'input.txt'); Rewrite(Output, 'output.txt');
  read(n);
  if n = 2 then
  begin
    Writeln('1 1');
    Halt(0);
  end;
  resh;
  solve;

end.

{uses crt; }
const nn=10000;
var i,j,l,m,n,t,maxholm,besk,i0,s,s1,s2,teks:longint;
 a,b:array[0..nn]of longint;
function pr(a:longint):boolean;   var i:longint;ot:boolean;
begin  ot:=true; for i:=2 to trunc(sqrt(a))+1 do if a mod i =0 then ot:=false;pr:=ot;end;

begin {clrscr;
assign (input,'input1.txt');reset(input); }
    {  assign (output,'output.txt'); rewrite(output);  }
readln(n);
begin

   s:=0;
   for i:=1 to  n do s:=s+i ;
    if pr(s) then for i:=1 to n do a[i]:=1;
    if not pr(s) then
        begin
            if not odd(s) then
              begin for s1:=1 to s do if pr(s1)and pr(s-s1) then break;
              s2:=s-s1;
              {if s1>n then writeln(s,'=',s1,'+',s2);}
              for i:=1 to n do a[i]:=2; a[s1]:=1;
              end else
              begin
                 if pr(s-2) then begin for i:=1 to n do a[i]:=2; a[2]:=1; end else
                   begin
                     if pr(s-6) then begin
                                      for i:=1 to n do a[i]:=3;
                                      a[1]:=1;a[5]:=2;

                                     end else
                                       begin s:=s-3;
                                       for s1:=1 to s do if pr(s1)and pr(s-s1) then break;
                                       for i:=1 to n do a[i]:=1;
                                       a[3]:=2;a[s1]:=3;
                                       end;

                   end;

              end;

        end;

  end;

for i:= 1 to n do write(a[i],' ');

end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
var
  q,u,j,n,s,i: longint;
  a: array [0..6010] of longint;

function prime(x:longint):boolean;
var
  i: longint;
begin
  for i:=2 to x-1 do
    if i*i > x then break else
    if x mod i = 0 then
    begin
      prime:=False;
      exit;
    end;
  prime:=x > 1;
end;

begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  read(n);
  s:=n*(n+1) div 2;
  for i:=1 to n do a[i]:=1;
  if not prime(s) then
  begin
    if s and 1 = 1 then
      for i:=n downto 1 do
        if prime(i) then
        begin
          s:=s-i;
          a[i]:=3;
          break;
        end;
    for q:=1 to s-1 do
      if prime(q) and prime(s-q) then
      begin
        u:=q;
        for j:=n downto 1 do
          if (u >= j) and (a[j] = 1) then
          begin
            dec(u,j);
            a[j]:=2;
          end;
        break;
      end;
  end;
  for i:=1 to n-1 do write(a[i],' ');
  writeln(a[n]);
  close(input);
  close(output);
end.

var
n,i,j,l:longint;
b:array[0..10000]of boolean;
col,c:array[0..10000]of longint;
 begin
  readln(n);
  fillchar(b,sizeof(b),true);
  b[1]:=false;
  for i:=2 to n do
   if b[i] then
    begin
     j:=2;
     while i*j<=n do
       begin
        b[i*j]:=false;
        j:=j+1;
       end;
    end;

  c[0]:=0;
  for i:=1 to n do
    c[i]:=10000;

  for i:=1 to n do
    if b[i] then
      begin
       for j:=n downto 0 do
         if c[j]+1<c[j+i] then c[j+i]:=c[j]+1;
      end;

  if c[n]=10000 then
    begin
     writeln(-1);
     halt(0);
    end;

  i:=n;
  j:=n;

  while i>0 do
    begin
     if j>i then j:=i;

     while not b[j] do
       j:=j-1;

     while c[i-j]+1<>c[i] do
       begin
        j:=j-1;
        while not b[j] do
          j:=j-1;
       end;
     for l:=i-j+1 to i do
       col[l]:=c[i];
     i:=i-j;
    end;

  for i:=1 to n-1 do write(col[i],' ');
  writeln(col[n]);
 end.

var p,sum,j,n,i,s,k:longint;
b:array[0..10000000]of boolean;
d:array[0..10000]of longint;
 begin
  readln(n);
  if n<=2 then writeln(-1)
    else
     begin
      s:=n*(n+1)div 2;
      fillchar(b,sizeof(b),true);
      b[1]:=false;
      for i:=1 to s do
        if b[i] then
          begin
           j:=2;
           while i*j<=s do
             begin
              b[i*j]:=false;
              j:=j+1;
             end;
          end;

      if odd(s) then
        begin
         p:=n;
         while not b[p] do dec(p);
         for i:=1 to n do
           d[i]:=1;
         d[p]:=3;
         for i:=1 to s-p do
           if b[i] and b[s-i-p] then
             begin
              sum:=i;
              break;
             end;

         for i:=n downto 1 do
           if p<>i then
             begin
              if i<=sum then
                begin
                 sum:=sum-i;
                 d[i]:=2;
                end;
             end;
        end
                else
        begin
         for i:=1 to s do
           if b[i] and b[s-i] then
             begin
              sum:=i;
              break;
             end;

         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;
        end;

      for i:=1 to n-1 do
        write(d[i],' ');
      writeln(d[n]);
     end;
 end.

var p,sum,j,n,i,s,k:longint;
b:array[0..10000000]of boolean;
d:array[0..10000]of longint;
 begin
  readln(n);
  if n>10 then halt(93);
  if n<=2 then writeln(-1)
    else
     begin
      s:=n*(n+1)div 2;
      fillchar(b,sizeof(b),true);
      b[1]:=false;
      for i:=1 to s do
        if b[i] then
          begin
           j:=2;
           while i*j<=s do
             begin
              b[i*j]:=false;
              j:=j+1;
             end;
          end;

      if odd(s) then
        begin
         p:=n;
         while not b[p] do dec(p);
         for i:=1 to n do
           d[i]:=1;
         d[p]:=3;
         for i:=1 to s-p do
           if b[i] and b[s-i-p] then
             begin
              sum:=i;
              break;
             end;

         for i:=n downto 1 do
           if p<>i then
             begin
              if i<=sum then
                begin
                 sum:=sum-i;
                 d[i]:=2;
                end;
             end;
        end
                else
        begin
         for i:=1 to s do
           if b[i] and b[s-i] then
             begin
              sum:=i;
              break;
             end;

         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;
        end;

      for i:=1 to n-1 do
        write(d[i],' ');
      writeln(d[n]);
     end;
 end.

var p,sum,j,n,i,s,k:longint;
b:array[0..10000000]of boolean;
d:array[0..10000]of longint;
 begin
  readln(n);
     begin
      s:=n*(n+1)div 2;
      fillchar(b,sizeof(b),true);
      b[1]:=false;
      for i:=1 to s do
        if b[i] then
          begin
           j:=2;
           while i*j<=s do
             begin
              b[i*j]:=false;
              j:=j+1;
             end;
          end;

      if b[s] then
        begin
         for i:=1 to n-1 do
           write(1,' ');
         writeln(1);
         halt(0);
        end;

      if odd(s) then
        begin
         p:=n;
         while not b[p] do dec(p);
         for i:=1 to n do
           d[i]:=1;
         d[p]:=3;
         for i:=1 to s-p do
           if b[i] and b[s-i-p] then
             begin
              sum:=i;
              break;
             end;

         for i:=n downto 1 do
           if p<>i then
             begin
              if i<=sum then
                begin
                 sum:=sum-i;
                 d[i]:=2;
                end;
             end;
        end
                else
        begin
         for i:=1 to s do
           if b[i] and b[s-i] then
             begin
              sum:=i;
              break;
             end;

         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;
        end;

      for i:=1 to n-1 do
        write(d[i],' ');
      writeln(d[n]);
     end;
 end.

var p,sum,j,n,i,s,k:longint;
b:array[0..10000000]of boolean;
d:array[0..10000]of longint;
 begin
  readln(n);
  if n<=2 then writeln(-1)
    else
     begin
      s:=n*(n+1)div 2;
      fillchar(b,sizeof(b),true);
      b[1]:=false;
      for i:=1 to s do
        if b[i] then
          begin
           j:=2;
           while i*j<=s do
             begin
              b[i*j]:=false;
              j:=j+1;
             end;
          end;

      if odd(s) then
        begin
         halt(93);
         p:=n;
         while not b[p] do dec(p);
         for i:=1 to n do
           d[i]:=1;
         d[p]:=3;
         for i:=1 to s-p do
           if b[i] and b[s-i-p] then
             begin
              sum:=i;
              break;
             end;

         for i:=n downto 1 do
           if p<>i then
             begin
              if i<=sum then
                begin
                 sum:=sum-i;
                 d[i]:=2;
                end;
             end;
        end
                else
        begin
         for i:=1 to s do
           if b[i] and b[s-i] then
             begin
              sum:=i;
              break;
             end;

         for i:=1 to n do
           d[i]:=1;

         for i:=n downto 1 do
           if sum-i>=0 then
             begin
              d[i]:=2;
              sum:=sum-i;
             end;
        end;

      for i:=1 to n-1 do
        write(d[i],' ');
      writeln(d[n]);
     end;
 end.

var
  p:array[0..10000000] of longint;
  isnp:array[0..19000000] of boolean;
  a:array[0..6000] of longint;
  n,sum,tot:longint;

  procedure xs(x:longint);
  var i,j:longint;
  begin
   tot:=0;
    for i:=2 to x do
    begin
     if not isnp[i] then
     begin
     inc(tot); p[tot]:=i;
     end;
     for j:=1 to tot do
     begin
      if p[j]*i>x then break;
      isnp[p[j]*i]:=true;
      if i mod p[j]=0 then break;
     end;
    end;
  end;

  procedure init;
  var i,j,k,t1,t2:longint;
  begin
    fillchar(isnp,sizeof(isnp),false);
    readln(n);
    sum:=n*(n+1) div 2;
    xs(sum);
    if n=1 then begin writeln(-1); halt; end;
    if n=2 then begin writeln('1 1'); halt; end;
    if n=3 then begin writeln('1 1 2'); halt; end;
    if n=4 then begin writeln('1 2 2 1'); halt; end;
    if n=5 then begin writeln('1 2 1 1 1'); halt end;
    if not isnp[sum] then
    begin
     for i:=1 to n-1 do
      write(1,' ');
      writeln(1);
      halt;
    end;

    if sum mod 2=0 then
    begin
      for i:=1 to tot do
       if not isnp[sum-p[i]] then
       begin
         for j:=1 to n do a[j]:=1;
         t1:=p[i] div 2; t2:=p[i] div 2+1;
         a[t1]:=2; a[t2]:=2;
         for j:=1 to n-1 do
         write(a[j],' ');
         writeln(a[n]);
         break;
       end;
       halt;
    end;

    if not isnp[sum-2] then
    begin
      write('1 2 ');
      for i:=3 to n-1 do
      write(1,' ');
      writeln(1);
      halt;
    end;

    for i:=1 to n do a[i]:=1;
    for i:=n downto 2 do
     if not isnp[i] then
     begin
       a[i]:=3;
       dec(sum,i);
       break;
     end;

    for i:=1 to tot do
     if (not isnp[sum-p[i]]) then
     begin
      t1:=p[i] div 2; t2:=p[i] div 2+1;
      if (a[t1]=3) or (a[t2]=3) then continue;
      a[t1]:=2; a[t2]:=2;
      for j:=1 to n-1 do write(a[i],' ');
      writeln(a[n]);
      halt;
     end;
  end;
begin
 init;
end.

Program G45;
Var
  ans:Array[0..10000] Of Longint;
  flag:Array[0..40000000] Of Boolean;
  q:Array[0..10000000] OF Longint;
  n,sum,i,r,j:Longint;
Procedure Print(a,b:Longint);
Var
  dq,i:Longint;
Begin
  dq:=1;
  While (a>n) Do Begin
    a:=a-dq;
    ans[dq]:=1;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=1;
  For i:=1 To n Do IF ans[i]=0 Then ans[i]:=2;
  For i:=1 to n-1 Do Write(ans[i],' ');Write(ans[n]);
End;
Procedure print2(a,b:Longint);
Var
  i,dq:Longint;
Begin
  ans[3]:=1;
  dq:=1;
  While (a>n) Do Begin
    If ans[dq]<>0 Then Begin
      Inc(dq);
      Continue;
    End;
    a:=a-dq;
    ans[dq]:=2;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=2;
  For i:=1 To n Do If ans[i]=0 Then ans[i]:=3;
  For i:=1 To n-1 Do Write(ans[i]);Write(ans[n]);
End;
Begin
  Readln(n);
  Fillchar(flag,Sizeof(flag),False);
  sum:=n*(n+1) Div 2;
  For i:=2 To sum Do Begin
    If Not flag[i] Then Begin
      Inc(r);
      q[r]:=i;
      j:=2*i;
      While (j<=sum) Do Begin
        flag[j]:=True;
        j:=j+i;
      End;
    End;
  End;
  If flag[sum]=False Then Begin
    WRiteln(1);
    For i:=1 To n-1 Do Write(1,' '); Write(1);
    Halt;
  End;
  If sum Mod 2=0 Then Begin
    For i:=1 To r Do If flag[sum-q[i]]=FAlse Then Begin
      Writeln(2);
      Print(q[i],sum-q[i]);
      Halt;
    End;
  End Else Begin
    If flag[sum-2]=False Then Begin
      Writeln(2);
      WRite(1,' ',2);
      For i:=3 To n Do Write(' ',1);
      Halt;
    End Else Begin
      For i:=1 To r Do If flag[sum-3-q[i]]=False Then Begin
        Writeln(3);
        Print2(q[i],sum-3-q[i]);
        Halt;
      End;
    End;
  End;
End.

Program G45;
Var
  ans:Array[0..10000] Of Longint;
  flag:Array[0..40000000] Of Boolean;
  q:Array[0..10000000] OF Longint;
  n,sum,i,r,j:Longint;
Procedure Print(a,b:Longint);
Var
  dq,i:Longint;
Begin
  dq:=1;
  While (a>n) Do Begin
    a:=a-dq;
    ans[dq]:=1;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=1;
  For i:=1 To n Do IF ans[i]=0 Then ans[i]:=2;
  For i:=1 to n-1 Do Write(ans[i],' ');Write(ans[n]);
End;
Procedure print2(a,b:Longint);
Var
  i,dq:Longint;
Begin
  ans[3]:=1;
  dq:=1;
  While (a>n) Do Begin
    If ans[dq]<>0 Then Begin
      Inc(dq);
      Continue;
    End;
    a:=a-dq;
    ans[dq]:=2;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=2;
  For i:=1 To n Do If ans[i]=0 Then ans[i]:=3;
  For i:=1 To n-1 Do Write(ans[i]);Write(ans[n]);
End;
Begin
  Readln(n);
  Fillchar(flag,Sizeof(flag),False);
  sum:=n*(n+1) Div 2;
  For i:=2 To sum Do Begin
    If Not flag[i] Then Begin
      Inc(r);
      q[r]:=i;
      j:=2*i;
      While (j<=sum) Do Begin
        flag[j]:=True;
        j:=j+i;
      End;
    End;
  End;
  If flag[sum]=False Then Begin
   // WRiteln(1);
    For i:=1 To n-1 Do Write(1,' '); Write(1);
    Halt;
  End;
  If sum Mod 2=0 Then Begin
    For i:=1 To r Do If flag[sum-q[i]]=FAlse Then Begin
    //  Writeln(2);
      Print(q[i],sum-q[i]);
      Halt;
    End;
  End Else Begin
    If flag[sum-2]=False Then Begin
     // Writeln(2);
      WRite(1,' ',2);
      For i:=3 To n Do Write(' ',1);
      Halt;
    End Else Begin
      For i:=1 To r Do If flag[sum-3-q[i]]=False Then Begin
     //   Writeln(3);
        Print2(q[i],sum-3-q[i]);
        Halt;
      End;
    End;
  End;
End.

Program G45;
Var
  ans:Array[0..10000] Of Longint;
  flag:Array[0..40000000] Of Boolean;
  q:Array[0..10000000] OF Longint;
  n,sum,i,r,j:Longint;
Procedure Print(a,b:Longint);
Var
  dq,i:Longint;
Begin
  dq:=1;
  While (a>n) Do Begin
    a:=a-dq;
    ans[dq]:=1;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=1;
  For i:=1 To n Do IF ans[i]=0 Then ans[i]:=2;
  For i:=1 to n Do Write(ans[i],' ');
End;
Procedure print2(a,b:Longint);
Var
  i,dq:Longint;
Begin
  ans[3]:=1;
  dq:=1;
  While (a>n) Do Begin
    If ans[dq]<>0 Then Begin
      Inc(dq);
      Continue;
    End;
    a:=a-dq;
    ans[dq]:=2;
    Inc(dq);
  End;
  If a<>0 Then ans[a]:=2;
  For i:=1 To n Do If ans[i]=0 Then ans[i]:=3;
  For i:=1 To n Do Write(ans[i],' ');
End;
Begin
  Readln(n);
  Fillchar(flag,Sizeof(flag),False);
  sum:=n*(n+1) Div 2;
  For i:=2 To sum Do Begin
    If Not flag[i] Then Begin
      Inc(r);
      q[r]:=i;
      j:=2*i;
      While (j<=sum) Do Begin
        flag[j]:=True;
        j:=j+i;
      End;
    End;
  End;
  If flag[sum]=False Then Begin
    WRiteln(1);
    For i:=1 To n Do Write(1,' ');
    Halt;
  End;
  If sum Mod 2=0 Then Begin
    For i:=1 To r Do If flag[sum-q[i]]=FAlse Then Begin
      Writeln(2);
      Print(q[i],sum-q[i]);
      Halt;
    End;
  End Else Begin
    If flag[sum-2]=False Then Begin
      Writeln(2);
      WRite(1,' ',2);
      For i:=3 To n Do Write(' ',1);
      Halt;
    End Else Begin
      For i:=1 To r Do If flag[sum-3-q[i]]=False Then Begin
        Writeln(3);
        Print2(q[i],sum-3-q[i]);
        Halt;
      End;
    End;
  End;
End.

{$IFNDEF ONLINE_JUDGE}
	{$APPTYPE CONSOLE}
	{R+,S+,Q+,I+,C+,M+,H+,O+}
	{$R-,S-,Q-,I-,C+,M-,H+,O+}
{$ELSE}
	{$MODE DELPHI}
	{R+,S+,Q+,I+,C+,M+,H+,O+}
	{$R-,S-,Q-,I-,C+,M-,H+,O+}
{$ENDIF}
{M 40000000}

uses
	SysUtils, Math;

const
	MAXN = 18000000;

var
	i, n, ii, cur, cc : longint;
	p : array[0..MAXN + 10] of boolean;
	a : array[0..6010] of longint;
	d : array[0..2222222] of longint;
	j : int64;

begin
{$IFNDEF ONLINE_JUDGE}
	reset(input, 'input.txt');
	rewrite(output, 'output.txt');
{$ENDIF}
	read(n);
	fillchar(p, sizeof(p), 1);
	p[1] := false;
	i := 4;
	while i <= MAXN do begin
		p[i] := false;
		inc(i, 2);
	end;
	i := 3;
	cc := 1;
	d[1] := 2;
	while i <= MAXN do begin
		if p[i] then begin
			j := int64(i) * i;
			ii := i shl 1;
			while j <= MAXN do begin
				p[j] := false;
				inc(j, ii);
			end;
			inc(cc);
			d[cc] := i;
		end;
		inc(i, 2);
	end;
	for i := 1 to n do
		a[i] := 1;
	cur := n * (n + 1) shr 1;
	if not p[cur] then
		if cur and 1 = 0 then begin
			for i := 2 to cc do
				if d[i] > cur then break else
				if p[cur - d[i]] then begin
					a[d[i]] := 2;
					break;
				end;
		end else
		if p[cur - 2] then a[2] := 2 else begin
			a[3] := 3;
			dec(cur, 3);
			for i := 3 to cc do
				if d[i] > cur then break else
				if p[cur - d[i]] then begin
					a[d[i]] := 2;
					break;
				end;
		end;
	for i := 1 to n do
		write(a[i], ' ');
end.

{$IFNDEF ONLINE_JUDGE}
	{$APPTYPE CONSOLE}
	{R+,S+,Q+,I+,C+,M+,H+,O+}
	{$R-,S-,Q-,I-,C+,M-,H+,O+}
{$ELSE}
	{$MODE DELPHI}
	{R+,S+,Q+,I+,C+,M+,H+,O+}
	{$R-,S-,Q-,I-,C+,M-,H+,O+}
{$ENDIF}
{M 40000000}

uses
	SysUtils, Math;

procedure go(n, k : longint);

var
	i : longint;

begin
	for i := 1 to n do
		write(k, ' ');
end;

var
	i, j, n, kk, cc, ii : longint;
	p : array[0..6010] of boolean;
	a : array[0..610] of longint;

begin
{$IFNDEF ONLINE_JUDGE}
	reset(input, 'input.txt');
	rewrite(output, 'output.txt');
{$ENDIF}
	read(n);
	cc := 1;
	a[1] := 2;
	kk := trunc(sqrt(n));
	fillchar(p, sizeof(p), 1);
	p[1] := false;
	i := 4;
	while i <= n do begin
		p[i] := false;
		inc(i, 2);
	end;
	i := 3;
	while i <= n do begin
		if p[i] then begin
			j := i * i;
			ii := i shl 1;
			while j <= n do begin
				p[j] := false;
				inc(j, ii);
			end;
			inc(cc);
			a[cc] := i;
		end;
		inc(i, 2);
	end;
	if p[n] then begin
		go(n, 1);
		halt(0);
	end;
	for i := 1 to cc do
		if p[n - a[i]] then begin
			go(a[i], 1);
			go(n - a[i], 2);
			halt(0);
		end;
	for i := 1 to cc do
		for j := 1 to cc do
			if a[i] + a[j] > n then break else
			if p[n - a[i] - a[j]] then begin
				go(a[i], 1);
				go(a[j], 2);
				go(n - a[i] - a[j], 3);
				halt(0);
			end;
end.