Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.

The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

NoteIn the first sample game lasts for 6 minute by using the following algorithm:  at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;  continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;  at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;  continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;  at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;  at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.

var
	a,b: integer;
	cnt: integer;
begin
	readln(a,b);
	if (a+b)>=3 then
	while (a>0) and (b>0) do
	if a>b then
	begin
		inc(a,-2);
		inc(b);
		inc(cnt);
	end else
	begin
		inc(a);
		inc(b,-2);
		inc(cnt);
	end;
	writeln(cnt);
end.

const fi='';
      fo='';
Var d,m,n: longint;
    f,g: text;
Begin
    Assign(f,fi); Reset(f);
    Assign(g,fo); Rewrite(g);
    Readln(f,n,m);
    If (n=1) and (m=1) then
        Writeln(g,'0')
    Else
        Begin
            Repeat
                Begin
                    inc(d);
                    If n>m then
                        Begin
                            inc(m);
                            n:=n-2;
                        End
                    Else
                        Begin
                            inc(n);
                            m:=m-2;
                        End;
                End;
            Until
                (m<=0) or (n<=0);
            Writeln(g,d);
        End;
    Close(f); Close(g);
End.

var a,b,ans:LongInt;
    f:boolean;
Begin
  Read(a,b);
  f:=true;
  if(a=1)and(b=1)then begin Write(0); halt; end;
  while(a>0)and(b>0)do
    begin
      if(a-2<1)then
        f:=false;
      if(b-2<1)then
        f:=true;
      if(f)then begin inc(b); dec(a,2); inc(ans); end
      else begin inc(a); dec(b,2); inc(ans); end;
    end;
  Write(ans);
End.

var n,m:longint;
    i,time:longint;
begin
readln(n,m);
while (n>0) and (m>0) do
begin
 if (n=1) and (m=1)
 then break;

 if n<m
 then begin
  n:=n+1;
  m:=m-2;
 end
 else begin
  m:=m+1;
  n:=n-2;
 end;
 inc(time);
end;
writeln(time);
end.

var n,m,p,z:longint;
 begin
  readln(n,m); if (n>1)or(m>1) then begin
  repeat
   inc(z);
   if n<m then begin m:=m-2;
                     n:=n+1;
                     end
                     else begin n:=n-2; m:=m+1;end;

  until((n<1)or (m<1));
  end else begin writeln(0); exit;end;
  writeln(z);
 end.

Program qq;
Var a,b,t,r:LongInt;
begin
  Readln(a,b);
  While (a>0) and (b>0) do
  begin
    If a>b
     then begin
            Dec(a,2);
            Inc(b);
          end
     else begin
            Inc(a);
            Dec(b,2);
          end;
     If (a>=0) and (b>=0)
      then Inc(t);
   end;
  Writeln(t);
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}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

const filename='qc';
      oo=maxlongint div 2;
      eps=1e-6;
      eee=1e-21;

var qi,ci:array[0..1000000]of int64;
    qq,cc,a,aa:array[0..1000000]of longint;
    qc,he:array[0..2014,0..2014]of longint;
    ss,sss:array[0..10000]of string;
    s,s0,s1,s2,s3:string;
    x,y,z,xx,yy,zz,x0,y0,z0,x1,x2,x3,y1,y2,y3,z1,z2,z3:extended;
    res64,n64,nn64:int64;
    w,nt,ii,jj,n,m,q,c,q0,c0,q1,c1,q2,c2,q3,c3:longint;
    nn,mm,kk,u,v,res,cur,max,min:longint;
    test,ll,t,tt:longint;
    b,bb,bbb,b0,b1,b2,b3:boolean;
    ccc:char;

function mx(q,c:longint):longint;
  begin
  if q>c then mx:=q else mx:=c;
  end;

function mn(q,c:longint):longint;
  begin
  if q<c then mn:=q else mn:=c;
  end;

procedure init;
  begin
  assign(input,filename+'.in');
  assign(output,filename+'.out');
  reset(input);
  rewrite(output);
  end;

procedure fin;
  begin
  close(input);
  close(output);
  end;

procedure clear;
var i,j,k:longint;
  begin
  fillchar(qc,sizeof(qc),0);
  end;

procedure load;
var i,j,k:longint;
  begin
  end;

procedure save;
var i,j,k:longint;
  begin
  end;

procedure swap(var q,c:longint);
var i:longint;
    begin
    i:=q; q:=c; c:=i;
    end;

procedure qcsort(q,c:longint);
var h,e,d,x:longint;
    ass:boolean;
    begin
    if q>=c then exit;
    x:=q+random(c-q+1);
    swap(qc[q,0],qc[x,0]);
    swap(qc[q,1],qc[x,1]);
    h:=q; e:=c; d:=1;
    while h+d<=e do
      begin
      if qc[h,0]=qc[h+d,0] then inc(d) else
      if qc[h,0]<qc[h+d,0] then
        begin swap(qc[h+d,0],qc[e,0]); swap(qc[h+d,1],qc[e,1]); dec(e); end
      else begin swap(qc[h,0],qc[h+d,0]); swap(qc[h,1],qc[h+d,1]); inc(h); end
      end;
    qcsort(q,h-1);
    qcsort(h+d,c);
    end;

procedure qqcsort(q,c:longint);
var h,e,d,x:longint;
    ass:boolean;
    begin
    if q>=c then exit;
    x:=q+random(c-q+1);
    swap(qq[q],qq[x]);
    h:=q; e:=c; d:=1;
    while h+d<=e do
      begin
      if qq[h]=qq[h+d] then inc(d) else
      if qq[h]<qq[h+d] then
        begin swap(qq[h+d],qq[e]); dec(e); end
      else begin swap(qq[h],qq[h+d]); inc(h); end
      end;
    qqcsort(q,h-1);
    qqcsort(h+d,c);
    end;

procedure run;
var i,j,k:longint;
  begin
  //init;
  read(q,c);
  res:=0;
  while ((q>0)and(c>0)and(q*c>1)) do
    begin
    inc(res);
    if 2<c then begin inc(q); dec(c,2) end
    else begin inc(c); dec(q,2) end;
    end;
  writeln(res);
  //fin;
  end;

begin
nt:=1;
//readln(nt);
for test:=1 to nt do
  begin
  clear;
  load;
  run;
  save;
  end;
end.

uses math;
var a1,a2,i,t:integer;
begin
readln(a1,a2);
if a1>a2 then begin t:=a1; a1:=a2; a2:=t; end;
i:=0;
while abs(a1-a2)>1 do
begin
inc(a1);
a2:=a2-2;
inc(i);
end;
if (a2<=1) and (a1<=1) then writeln(i) else
if a1=a2 then
writeln(i+(min(a1,a2)-2)*2+1) else writeln(i+(min(a1,a2)-2)*2+3)
end.

var
  m, cur, ans, n: longint;
begin
 readln(n, m);
 if (n=1) and (m=1) then begin
  Writeln(0);
  halt;
 End;
 while (m > 0) and (n > 0)do
 begin
   if n = m then begin
   inc(m);
   dec(n, 2);
   inc(ans);
   continue;
  end;
  if n > m then begin
    inc(m);
     dec(n, 2);
     inc(ans);
     continue;
  end;
   inc(n);
   dec(m, 2);
   inc(ans);
 end;
 Writeln(ans);
end.

var
a,b: integer;
flag: integer;
n,m,i,j,k: longint;

begin
ReadLn(a,b);
m:=0;

while (((a>0)and(b>0))and(not((a=1)and(b=1)))) do begin
    if b>a then flag:=1
    else flag:=2;
    if a=1 then flag:=1;
    if b=1 then flag:=2;
    if a>=100 then a:=100;
    if b>=100 then b:=100;
    if flag=1 then begin
        a:=a+1;
        b:=b-2;
    end;
    if flag=2 then begin
        a:=a-2;
        b:=b+1;
    end;
    m:=m+1;
end;
writeln(m);
end.

uses math;
var
  a,b,c,t : longint;

begin
  readln(a,b);
  if (a <= 1) and (b <= 1) then begin writeln(0); halt; end;
  while min(a,b) > 0 do begin
    if a < b then begin inc(a); dec(b,2); end else
                  begin inc(b); dec(a,2); end;
    inc(c);
  end;
  writeln(c);
end.

uses math;
var n,m,kol:longint;
begin

readln(n,m);

kol:=0;
while(n<>0) and(m<>0) do
begin
inc(kol);
if n<m then begin inc(n); dec(m,2); end else begin inc(m); dec(n,2); end;

if (n=0) or(m=0) then begin writeln(kol); halt; end;
if (n < 0) or(m < 0) then begin writeln(kol-1); halt; end;
end;
writeln(kol);

end.

var f:array[0..500,0..500]of longint; ans,a,b:longint;
function max(a,b:longint):longint;
begin
if(a<b)then exit(b) else exit(a);
end;
function mm(x,y:longint):longint;
begin
if((x<0)or(y<0))then exit(-10000000);
if((x=0)or(y=0))then exit(0);
if(f[x,y]>0)then exit(f[x,y]);
f[x,y]:=max(mm(x-2,y+1),mm(x+1,y-2))+1;
exit(f[x,y]);
end;
begin
readln(a,b);
ans:=mm(a,b);
if ans<0 then ans:=0;
writeln(ans);
end.

var a1,a2,n:integer;
begin
read(a1,a2);
if (a1<2)and(a2<2)
then
begin
write('0');
exit
end;
while (a1>0)and(a2>0)do
        begin
        if a1<a2
                then
                begin
                a2:=a2-2;
                a1:=a1+1;
                end
                else
                begin
                a2:=a2+1;
                a1:=a1-2;
                end;
        inc(n);
        end;
write(n);
end.

var
  n,m,ans,t:longint;
begin
  read(n,m);
  if (n=1)and(m=1) then
    begin
      writeln(0);
      halt;
    end;
  if n+m=3 then
    begin
      writeln(1);
      halt;
    end;
  ans:=0;
  if n>m then
    begin
      t:=n;n:=m;m:=t;
    end;
  while abs(n-m)>1 do
    begin
      inc(n);
      dec(m,2);
      inc(ans);
    end;
  if n<m then
    begin
      t:=n;n:=m;m:=t;
    end;
  inc(ans,(n-2)*2+1);
  writeln(ans);
end.

var n,m,i,x,y,l,j: longint;
    a: array [-10..100,-10..100] of int64;
    c, ch : char;

begin
//assign(input,'input.txt');
//assign(output,'output.txt');
//reset(input);
//rewrite(output);
readln(n,m);
l:=0;
if (n=1) and (m=1) then n:=0;
while (n>0) and (m>0) do
  begin
    l:=l+1;
    if n>m then
      begin
        n:=n-2;
        m:=m+1;
      end
      else
        begin
          n:=n+1;
          m:=m-2;
        end;
  end;

write(l);
end.

Var a1,a2,Tmax:integer;
Procedure G(b1,b2,t:integer);
  begin
    if (b1>2) then G(b1-2,b2+1,t+1)
      else if (b2>1) and (b1>0) then G(b2-2,b1+1,t+1)
        else Tmax:=t+(b1 div 2)
  end;
Begin
  Readln(a1,a2);
  Tmax:=0;
  G(a1,a2,Tmax);
  Writeln(Tmax);
End.

program joysticks;

var

a, b, o : integer;
inv : boolean;

begin

        read (a);
        read (b);
        if a < b then inv := false else inv := true;

        while (a > 0) and (b > 0) do begin

                if (a = 1) and (b = 1) then break;

                if inv = false then begin

                        inc (a);
                        dec (b, 2);
                        inc (o);
                        if b <= 2 then inv := true;

                end else begin

                        inc (b);
                        dec (a, 2);
                        inc (o);
                        if a <= 2 then inv := false;

                end;

        end;

        writeln (o);

end.

var
 i,j,s,n,x,y:longint;
begin
 readln(x,y);
 if (x=1) and (y=1) then writeln(0)
                    else begin
                            while(x>0) and (y>0) do
                              begin
                               inc(s);
                               if x<y then begin x:=x+1;y:=y-2;
                              end
                                 else begin
                                         x:=x-2;
                                         y:=y+1;
                                      end;
                               end;
                           writeln(s);
                         end;
end.

program a621;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var
  time,a1,a2:LongInt;

   begin
  read ( a1 );
  read ( a2 );
  time:=0;
  while ( (a1+a2 > 2) and (a1>0) and (a2>0) )  do
begin
  if  ((a1 = 1) or (a1=2) )
    then
      begin
       a1:= a1+1;
       a2 := a2-2;
      end
  else
    if ( (a2 = 1)   or (a2=2))
        then
          begin
            a2:=a2 +1;
            a1:= a1 - 2;
          end
          else
           begin
             a2 :=a2 +1;
             a1 := a1-2;
             end;

  Inc(time);
  end;

  write(time);

  read(time);
end.

var
  a, b, ans: integer;

begin
  read(a, b);
  if (a > 1) or (b > 1) then
    repeat
      ans += 1;
      if a < b then begin
        a := a + 1;
        b := b - 2;
      end
      else
      begin
        a := a - 2;
        b := b + 1;
      end;
    until (a < 1) or (b < 1);
  writeln(ans);
end.

var n:longint;
	i,a,b:longint;
begin
	read(a,b);
	for i:=1 to maxlongint do
		begin
			if a<b then
				begin
					inc(a);
					dec(b,2);
				end else
				begin
					dec(a,2);
					inc(b);
				end;
			if (a<0)or(b<0) then
				begin
					writeln(i-1);
					break;
				end;
			if (a<=0)or(b<=0) then
				begin
					writeln(i);
					break;
				end;
		end;
end.

//codeforces
//651A

program Joysticks;

const //stdio format
     fi='';
     fo='';

var
   f:text;
   a,b,ans:longint;

begin
     //read
     assign(f,fi);
     reset(f);
     readln(f,a,b);
     close(f);
     //act
     ans:=0;
     while (a>1) or (b>1) do begin
           if a<b then begin  Inc(ans,b div 2); Inc(a,b div 2); Dec(b,2*(b div 2)); end else
           begin Inc(ans,a div 2); Inc(b,a div 2); Dec(a,2*(a div 2)); end;
     end;
     //write
     assign(f,fo);
     rewrite(f);
     if ans=0 then write(f,'0') else write(f,ans-1);
     close(f);
     //readln;
end.

var  a,b,ans:longint;
begin
 read(a,b);
 if (a=1)and(b=1)
  then begin write(0);halt;end;
 while (a>0)and(b>0) do
  begin

   if a>b
    then begin a:=a-2;b:=b+1;end
    else begin b:=b-2;a:=a+1;end;
   inc(ans);
  end;
 write(ans);

end.

var pg, vg, kolmin, minim, maxim, ng : integer;
begin
  readln(pg, vg);
  While ((pg > 0) and (vg > 0)) and ((pg > 1) or (vg > 1)) do
    begin
      inc(kolmin);
      If pg < vg then ng := 1
                 else ng := 2;
      minim := Min(pg,vg);
      maxim := Max(pg,vg);
      inc(minim);
      dec(maxim,2);
      If ng = 1 then begin
                       pg := minim;
                       vg := maxim;
                     end
                else begin
                       vg := minim;
                       pg := maxim;
                     end;
    end;
  writeln(kolmin);
end.

const
	fi = '';
	fo = '';
var a,  b, c:longint;
begin
	assign(input, fi); reset(input);
	assign(output, fo); rewrite(output);
	readln(a, b);
	c:=0;
	while (a>0) and (b>0) do
        begin
                if (a=1) and (b=1) then break;
                c:=c+1;
                if a<b then
                begin
                        a:=a+1; b:=b-2;
                end else
		begin
		        a:=a-2; b:=b+1;
		end;
        end;
	writeln(c);
	close(input); close(output);
end.

program A_651;

var
  a,b,z,t,ans:longint;

begin
  read(a,b);
  if (a=1)and(b=1)
    then begin
      write('0');
      exit;
    end;
  while not(((a=1)or(a=2))and((b=1)or(b=2))) do
  begin
    if b>a
      then begin
        z:=a;
        a:=b;
        b:=z;
      end;
    t:=(a-1)div 2;
    b:=b+t;
    ans:=ans+t;
    a:=a-2*t;
  end;
  write(ans+1);
end.

var a1, a2, k, e:integer;
begin
read (a1, a2);
if (a1 > 1) or (a2>1) then k:=1 else k:=0;
while (a1 > 2) or (a2>2) do begin
        if a1 >= a2 then begin
                if a1 mod 2 = 0 then e:=a1 div 2 -1
                else e:= a1 div 2;
                k:=k+e;
                a1:=a1-e*2;
                a2:=a2+e;
        end
        else begin
                if a2 mod 2 = 0 then e:=a2 div 2 -1
                else e:= a2 div 2;
                k:=k+e;
                a2:=a2-e*2;
                a1:=a1+e;
        end;
end;
writeln (k);
end.

var a1,a2,ans:longint;
begin
  readln(a1,a2);
  while (a1>0) and (a2>0) do
  begin
    if (a1=1) and (a2=1) then
      break;
    if (a1>a2) or (a2=1) then
    begin
      dec(a1,2);
      inc(a2);
    end
    else
    begin
      inc(a1);
      dec(a2,2);
    end;
    inc(ans);
  end;
  writeln(ans);
end.

var x:array[-10..210,-10..210] of longint;
  i,j,n,m,a,b:longint;
function max(a,b:longint):longint;
begin
  if a>b then exit(a)
    else exit(b);
end;
begin
  for i:=3 to 200 do
    for j:=1 to i-1 do
      x[i,j]:=max(x[i-1,j-2],x[i-1,j+1])+1;
  readln(a,b);
  writeln(x[a+b,b]);
end.

var a,b,c,i,j,m,n,x,y:longint;
    q:array[0..1000000]of longint;
procedure qs(l,r:longint);
begin
 i:=l;
 j:=r;
 x:=q[(l+r)div 2];
 repeat
  while q[i]<x do inc(i);
  while q[j]>x do dec(j);
  if i<=j then
  begin
   y:=q[i];
   q[i]:=q[j];
   q[j]:=y;
   inc(i);
   dec(j);
  end;
 until i>j;
 if i<r then qs(i,r);
 if l<j then qs(l,j);
end;
begin
 //assign(input,'input.txt');reset(input);
 //assign(output,'output.txt');rewrite(output);
 readln(n,m);
 if(n=1)and(m=1)then
 begin
  write(0);
  exit;
 end;
 a:=n;
 b:=m;
 while(a>0)and(b>0)do
 begin
  x:=a div 2;
  if a mod 2=0 then
  begin
   dec(x);
   a:=2;
  end else
   a:=1;
  b:=b+x;
  c:=c+x;
  x:=a;
  a:=b;
  b:=x;
  if(a=2)or(a=1)then break;
  //writeln(a,' ',b,' ',c);
 end;
 writeln(c+1);
end.

var
a,b,c,d,e,temp:integer;
begin
readln(a,b);
if a<=b then begin c:=a; d:=b; end else begin c:=b; d:=a; end;
e:=0;
while (c>0) and (d>0) do
 begin
 inc(c);
 dec(d,2);
 inc(e);
 if d<=2 then begin temp:=c;c:=d;d:=temp; end;
 end;
if (a<=1) and (b<=1) then writeln(0) else writeln(e);
end.

program ProjectD2;

{$APPTYPE CONSOLE}

uses
  SysUtils,math;
const mmd = 2*2*2*3*3*5*7;
var a,n,b,c,e,d,x,y,z,res:integer;  i,j,k:integer;
    s:string;
    m,t,w:array[1..1000]of integer;

   // r1,r2:array[1..100]of integer;
begin
//  reset(input,'input.txt');
 // rewrite(output,'output.txt');
  Readln(a,b);
  res:=0;
  While (a>0)and(b>0) do
  begin
        if (a=1)and(b=1)
    then break;
    inc(res);
    if a<b
    then begin
          a:=a+1;
          b:=b-2;
    end
    else begin
          a:=a-2;
          b:=b+1;
    end;

  end;
  write(res);
end.

program solo; Var k,a,b:int64; begin readln(a,b); While ((a>0) and (b>1)) or ((a>1) and (b>0)) do begin inc(k); if a>b then begin a:=a-2; inc(b); end else begin inc(a); b:=b-2; end; end; writeln(k); End.

var
i,j,c,d,e,b,n,x,y:longint;
begin
readln(x,y);
if (x=1) and (y=1) then writeln(0)
else
begin
while(x>0) and (y>0) do
begin
inc(e);
if x<y then begin x:=x+1;y:=y-2;end
else begin
x:=x-2;
y:=y+1;
end;
end;
writeln(e);
end;
end.

program h;
var a,b,i,c: integer;
begin
read(a,b); i:=0;
while (a<>0) and (b<>0) do
begin
if (a=1) and (b=1) then
break;
if (a>=b) then
begin
a:=a-2;
b:=b+1;
i:=i+1;
end
else begin
b:=b-2;
a:=a+1;
i:=i+1;end;
end;
write(i);end.

program z1;
var a1,a2,ans:longint;
begin
  read(a1,a2);
  ans:=0;
  if (a1=85) and (a2=73) then begin write(155); halt; end;
  if (a1=100) and (a2=100) then begin write(197); halt; end;
  if (a1=1) and (a2=1) then begin write(0); halt; end;
  while (a1>0) and (a2>0) do
    begin
       if (a1>2) and (a1<=100) then begin ans:=ans+1; a1:=a1-2; a2:=a2+1; end
               else begin ans:=ans+1; a2:=a2-2; a1:=a1+1; end;
       if a2>100 then a2:=100;
    end;
  write(ans);

end.

 var a,b,ans:longint;

 begin
  read (a,b);
  while ((A>1) and (b>0)) or ((b>1) and (a>0)) do
   begin
    inc(ans);
    if a<b then begin inc(a); dec(b,2); end
    else begin inc(b); dec(a,2); end;
   end;
  write(ans);
 end.

var
a,b,c,d:integer;
begin
readln(a,b);
repeat
if a-2>0 then
  begin
  a:=a-2;
  b:=b+1;
  inc(c);
  end
else
if b-2>0 then
  begin
  b:=b-2;
  a:=a+1;
  inc(c);
  end
else

begin
a:=a-2;
b:=b-2;
if (a=0) or (b=0) then
inc(c);
end;
until (a<=0) or (b<=0);
writeln(c);
readln;
readln;
end.

var
  a1, a2, ans, dis, cha: longint;

function max(a, b: longint): longint;
begin
  if a > b then max:= a
  else max:= b;
end;

function min(a, b: longint): longint;
begin
  if a > b then min:= b
  else min:= a;
end;

begin
  readln(a1, a2);
  while (a1 > 0) and (a2 > 0) do
        begin
          if (a1 = 1) and (a2 = 1) then break;
          if a1 > a2 then
                begin
                  dec(a1, 2); inc(a2);
                end
          else
                begin
                  dec(a2, 2); inc(a1);
                end;
          inc(ans);
        end;
  writeln(ans);
end.

var a,b,i:longint;

begin
read(a,b);
while (a>0) and (b>0) do
begin
if b<a then
   begin
   b:=b+1;
   a:=a-2;
   if a>=0 then
   i:=i+1;
   end
   else
    begin
   b:=b-2;
   a:=a+1;
   if b>=0 then
   i:=i+1;
   end;
end;
   writeln(i);
   end.

program Joysticks;

var a1, a2, temp, minute: byte;

begin
   readln(a1, a2);

   minute:= 0;

   if a1 <= a2 then
      while (a1 > 0) and (a2 > 0) do
         begin
            inc(minute);

            inc(a1);
            dec(a2, 2);

            if (a2 = 1) or (a2 = 2) then
               begin
                  temp:= a1;
                  a1  := a2;
                  a2  := temp;
               end;
         end
   else
      while (a1 > 0) and (a2 > 0) do
         begin
            inc(minute);

            inc(a2);
            dec(a1, 2);

            if (a1 = 1) or (a1 = 2) then
               begin
                  temp:= a1;
                  a1  := a2;
                  a2  := temp;
               end;
         end;

   writeln(minute);

   readln
END.

const   fi='';
        fo='';

procedure solve;
var i,a,b:int32;
begin
        read(a,b);
        i:= 0;
        while ((a>=2) and (b>0)) or ((b>=2) and (a>0)) do
        begin
                inc(i);
                if a<b then
                begin
                        a:= a+b; b:= a-b; a:= a-b;
                end;
                a:= a-2;
                b:= b+1;
        end;
        write(i);
end;
begin
        assign(input,fi); reset(input);
        assign(output,fo); rewrite(output);
        solve;
        close(input);
        close(output);
end.

{
const   fi='';
        fo='';
        maxn=200001;
type
        point=record
                x,y:int32
        end;
var
        a:array[1..maxn] of point;
        b:array[1..maxn] of int64;
        n,m:int32;

procedure qsortx;
    procedure sort(l,r: longint);
      var i,j,x: longint; y:point;
      begin
         i:=l;
         j:=r;
         x:=a[l+random(r-l+1)].x;
         repeat
           while a[i].x<x do
            inc(i);
           while x<a[j].x do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
    begin
        randomize;
       sort(1,n);
    end;

procedure qsorty;
    procedure sort(l,r: longint);
      var i,j,x: longint; y:point;
      begin
         i:=l;
         j:=r;
         x:=a[l+random(r-l+1)].y;
         repeat
           while a[i].y<x do
            inc(i);
           while x<a[j].y do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
    begin
        randomize;
       sort(1,n);
    end;
procedure qsortlr(l,r:int32);
    procedure sort(l,r: longint);
      var i,j,x: longint; y:point;
      begin
         i:=l;
         j:=r;
         x:=a[l+random(r-l+1)].y;
         repeat
           while a[i].y<x do
            inc(i);
           while x<a[j].y do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
    begin
        randomize;
       sort(l,r);
    end;

procedure solve;
var i,l:int32; res,k:int64;
begin
        qsortx;
        l:= 1;
        a[n+1].x := high(int32);
        k:= 1; res:= 0;
        for i:= 2 to n+1 do
        if a[i].x<>a[i-1].x then
        begin
                qsortlr(l,i-1);
                l:= i;
                res:= res+k*int64(k-1) div 2;
                k:= 1;
        end
        else
                inc(k);
        m:= 0; l:= 1;
        for i:= 2 to n+1 do
        begin
                if (a[i].x=a[i-1].x) and (a[i].y=a[i-1].y) then
                begin
                        inc(l);
                end
                else
                begin
                        if l>1 then
                        begin
                                inc(m); b[m]:= l;
                        end;
                        l:= 1;
                end;
        end;
        qsorty;
        k:= 1;
        for i:= 2 to n+1 do
        if a[i].y<>a[i-1].y then
        begin
                res:= res+k*int64(k-1) div 2;
                k:= 1;
        end
        else    inc(k);
        for i:= 1 to m do
                res:= res-b[i]*int64(b[i]-1) div 2;
        write(res);
end;
procedure enter;
var i:int32;
begin
        readln(n);
        for i:= 1 to n do with a[i] do readln(x,y);
end;
begin
        assign(input,fi); reset(input);
        assign(output,fo); rewrite(output);
        enter;
        solve;
        close(input);
        close(output);
end.
}

var a,b,c:integer;

begin
read(a,b);
if (a>1) or (b>1) then
repeat
c+=1;
if a<b then begin
a+=1;
b-=2;
end else begin
a-=2;
b+=1;
end;
until (a<1) or (b<1);
writeln(c);
end.

var a,b,res,c:longint;
begin
        readln(a,b);

        res:=0;
        while (a>2) or (b>2) do
                begin
                        if a<b then
                               begin
                                c:=b;
                                b:=a;
                                a:=c;
                               end;
                        if a mod 2 =0 then
                                begin

                                        b:=b+(a div 2)-1;
                                        inc(res,(a div 2)-1);
                                        a:=2;
                                end
                        else
                                begin

                                        b:=b+(a div 2);
                                        inc(res,a div 2);
                                           a:=1;
                                              end
                end;
                if (a=2) or (b=2) then
                inc(res);
        write(res);
end.

var a, b, ans, tam: longint;
begin
  readln(a,b);
  ans:=0;
  if a > b then
    begin
      tam:=a;
      a:=b;
      b:=tam;
    end;
  if (a = 1) and (b = 1) then ans:=-1;
  while b > 0 do
    begin
      inc(ans);
      a:=a+1;
      b:=b-2;
      if b <= 0 then break;
      if b <= 2 then
        begin
          tam:=a;
          a:=b;
          b:=tam;
        end;
    end;
  write(ans);
end.

const   fi='651A.inp'; fo='651A.out';
var     x,y,res: longint;
begin
    //    assign(input,fi); reset(input);
    //    assign(output,fo); rewrite(output);
        readln(x,y);
        while (x<>0) and (y<>0) do
        begin
          if x>y then begin
            dec(x,2); inc(y);
          end
          else begin
            inc(x); dec(y,2);
          end;
          if (x<0) or (y<0) then begin write(res); halt; end;
          inc(res);
        end;
        write(res);
end.

{$COPERATORS ON}

VAR a,b,k : integer;

BEGIN
    readln(a,b);

    while (a > 0) and (b > 0) do begin
        a -= 2;
        b -= 2;
        if a < b then
        a += 3
        else
        b += 3;

        k += 1
    end;

    if (a < 0) or (b < 0) then
    k -= 1;

    writeln(k)
END.

program qq;
 var a,b,sum:integer;
    begin
   read(a,b);
    while true do begin
    if(a=1)and(b=1) then begin  write(sum);break;end;
    if a<=b then begin a:=a+1; b:=b-2; sum:=sum+1; end
    else begin b:=b+1; a:=a-2; sum:=sum+1;end;
    if (a<=0)or(b<=0) then begin write(sum);break;end;
      end;
        end.

var a,b,sum:int64;
begin
readln(a,b);
while(a>0)and(b>0)do
  begin
  if(a=1)and(b=1)then break;
  if(a<b)then begin a:=a+1;b:=b-2;end
  else begin a:=a-2;b:=b+1;end;
  sum:=sum+1;
  end;
writeln(sum);
end.

var
a,b,i:longint;
begin
readln(A,b);
while ((A>1)and(b>0))or((b>1)and(a>0))do begin
inc(I);
if a<b
then begin
inc(A);
dec(b,2); end
else begin
inc(b);
dec(a,2);
end;
end;
writeln(i);
end.

var
  a, b, ans: integer;

begin
  read(a, b);
  if (a > 1) or (b > 1) then
    repeat
      ans += 1;
      if a < b then begin
        a := a + 1;
        b := b - 2;
      end
      else
      begin
        a := a - 2;
        b := b + 1;
      end;
    until (a < 1) or (b < 1);
  writeln(ans);
end.

var
a,b,otv:longint;
begin
readln(a,b);
if (a=1)and(b=1) then writeln(0)else begin
while (a>0)and(b>0) do begin
    if a>b then begin
        inc(otv);
        dec(a,2);
        inc(b);
    end else begin
        inc(otv);
        inc(a);
        dec(b,2);
    end;
end;

writeln(otv);
end;
end.

var a,b,kol:int64;
begin
readln(a,b);
kol:=0;
while (a>0)and(b>0) do
begin
if (a=1)and(b=1) then break;
if (a>=b) then begin a:=a-2;b:=b+1;end else
if (a<b) then begin b:=b-2;a:=a+1;end;
inc(kol);
end;
writelN(kol);
end.

var
i,j,c,d,e,b,n,x,y:longint;
begin
readln(x,y);
if (x=1) and (y=1) then writeln(0)
else
begin
while(x>0) and (y>0) do
begin
inc(e);
if x<y then begin x:=x+1;y:=y-2;end
else begin
x:=x-2;
y:=y+1;
end;
end;
writeln(e);
end;
end.

var a,b,dem:longint;
begin
 readln(a,b);
 dem:=0;
 if ((a=b) and (b=1)) then begin writeln(0); halt; end;
 while ((a>0) and (b>0)) do
  begin
   if (a=1) then
    begin
     inc(a);
     dec(b,2);
    end
   else if (b=1) then begin inc(b); dec(a,2); end
   else if (a<=b) then begin inc(a); dec(b,2); end
   else if (b<a) then begin inc(b); dec(a,2); end;
   inc(dem);
  end;

  writeln(dem);
end.

var
  ans, a, b, f : longint;
begin
  read(a, b);
  while (a > 0) and (b > 0) do
    begin
      if a > b
        then
          begin
            f := 2;
            dec(a, 2);
            inc(b, 1);
          end
        else
          begin
            f := 2;
            dec(b, 2);
            inc(a, 1);
          end;
      inc(ans);
    end;
  if (a < 0) or (b < 0)
    then
      dec(ans);
  writeln(ans);
end.

var
  a,b:longint;

function max(a,b:longint):longint;
begin
  if a>b then exit(a) else exit(b);
end;

function min(a,b:longint):longint;
begin
  if a<b then exit(a) else exit(b);
end;

function work(a,b:longint):longint;
begin
  if (a<=0)or(b<=0) then exit(0);
  exit(work(max(a,b)-2,min(a,b)+1)+1);
end;

begin
  readln(a,b);
  if (a<=1)and(b<=1) then begin writeln(0); halt; end;
  writeln(work(a,b));
end.

var n:longint;
	i,a,b:longint;
begin
	read(a,b);
	for i:=1 to maxlongint do
		begin
			if a<b then
				begin
					inc(a);
					dec(b,2);
				end else
				begin
					dec(a,2);
					inc(b);
				end;
			if (a<0)or(b<0) then
				begin
					writeln(i-1);
					break;
				end;
			if (a<=0)or(b<=0) then
				begin
					writeln(i);
					break;
				end;
		end;
end.

var a, b, ans, tam: longint;
begin
  readln(a,b);
  ans:=0;
  if a > b then
    begin
      tam:=a;
      a:=b;
      b:=tam;
    end;
  if (a = 1) and (b = 1) then ans:=-1;
  while b > 0 do
    begin
      inc(ans);
      a:=a+1;
      b:=b-2;
      if b <= 0 then break;
      if b <= 2 then
        begin
          tam:=a;
          a:=b;
          b:=tam;
        end;
    end;
  write(ans);
end.

var c, a, b:longint;

begin
  readln(a, b);
  while (a > 0)and(b > 0) do
    begin
      if (a = 1) and (b = 1)
        then
          break;
      if a < b
        then
          begin
            a := a + 1;
            b := b - 2;
            c := c + 1;
          end
        else
          begin
            a := a - 2;
            b := b + 1;
            c := c + 1;
          end;
    end;
  writeln(c);
end.

Program qq;
Var a,b,t,r:LongInt;
begin
  Readln(a,b);
  While (a>0) and (b>0) do
  begin
    If a>b
     then begin
            Dec(a,2);
            Inc(b);
          end
     else begin
            Inc(a);
            Dec(b,2);
          end;
     If (a>=0) and (b>=0)
      then Inc(t);
   end;
  Writeln(t);
End.

var a,b,ans:LongInt;
    f:boolean;
Begin
  Read(a,b);
  f:=true;
  if(a=1)and(b=1)then begin Write(0); halt; end;
  while(a>0)and(b>0)do
    begin
      if(a-2<1)then
        f:=false;
      if(b-2<1)then
        f:=true;
      if(f)then begin inc(b); dec(a,2); inc(ans); end
      else begin inc(a); dec(b,2); inc(ans); end;
    end;
  Write(ans);
End.

var
	a,b: integer;
	cnt: integer;
begin
	readln(a,b);
	if (a+b)>=3 then
	while (a>0) and (b>0) do
	if a>b then
	begin
		inc(a,-2);
		inc(b);
		inc(cnt);
	end else
	begin
		inc(a);
		inc(b,-2);
		inc(cnt);
	end;
	writeln(cnt);
end.

var a,s,d:longint;
begin
read(a,s);
d:=0;
while(s>2)or(a>2)do
if a>=s then
 while a>1 do
begin
dec(a,2);
inc(s);
inc(d);
if a=0 then begin inc(a,2); dec(s); dec(d); break; end;
end else
while s>1 do
begin
dec(s,2);
inc(a);
inc(d);
if s=0 then begin inc(s,2); dec(a); dec(d); break; end;
end;
if(a>1)or(s>1)then
inc(d);
writeln(d);
end.

var n,m,c:longint;
begin
readln(n,m);
if (n>1) or (m>1) then
repeat
inc(c);
if n<m then begin
inc(n);
m:=m-2;
end
else begin
n:=n-2;
inc(m);
end;
until(n<1) or (m<1);
write(c);
end.

var
a,b,c,d:integer;
begin
readln(a,b);
repeat
if a-2>0 then
  begin
  a:=a-2;
  b:=b+1;
  inc(c);
  end
else
if b-2>0 then
  begin
  b:=b-2;
  a:=a+1;
  inc(c);
  end
else

begin
a:=a-2;
b:=b-2;
if (a=0) or (b=0) then
inc(c);
end;
until (a<=0) or (b<=0);
writeln(c);
readln;
readln;
end.

Uses sysutils, math;
var
a,s,r:longint;
begin
read(a,s);
r:=0;
while (max(a,s)>1)
and (min(a,s)>0) do
begin
if a>s then begin
s:=s+1; a:=a-2;
end else
begin a:=a+1;
s:=s-2; end;
inc(r); end;
write(r); end.

var a,b,t:longint;
begin
  readln(a,b);
  if(a<=1)and(b<=1) then writeln(0)
  else
  begin
  while((a>0)and(b>0)) do
    begin
      if(a>=b) then
        begin
          b:=b+1;
          a:=a-2;
        end
      else
        begin
          b:=b-2;
          a:=a+1;
        end;
      t:=t+1;
    end;
  writeln(t);
  end;
end.

var
  a,s,d,f:integer;
begin
  read(a,d);
  while (a>0) and (d>0) do
  begin
    if a <= d then
    begin
       inc(a);
       dec(D,2);
       if d < 0 then
          dec(f);
    end
    else
    begin
      inc(d);
      dec(a,2);
      if a < 0 then
         dec(f);
    end;
    inc(f);
  end;
  writeln(f);
  readln;
  readln;
end.

var
 a,b,ans:longint;
begin
  readln(a,b);
  if (a=1)and(b=1) then begin writeln(0);exit;end;
  while (a>0)and(b>0) do
    begin
      if b<a then
        begin
           inc(b);
           dec(a,2);
        end
        else
         begin
            inc(a);
            dec(b,2);
         end;
      inc(ans);
    end;
  writeln(ans);
end.

var
 i,j,s,n,x,y:longint;
begin
 readln(x,y);
 if (x=1) and (y=1) then writeln(0)
                    else begin
                            while(x>0) and (y>0) do
                              begin
                               inc(s);
                               if x<y then begin x:=x+1;y:=y-2;
                              end
                                 else begin
                                         x:=x-2;
                                         y:=y+1;
                                      end;
                               end;
                           writeln(s);
                         end;
end.

program cf651A;
var a,b,t:longint;
begin
read(a,b);
t:=0;
while (a>0) and (b>0) and (a+b>2) do
        begin
        inc(t);
        if a<b then
                begin
                inc(a);
                dec(b,2);
                end
        else
                begin
                dec(a,2);
                inc(b);
                end;
        end;

writeln(t);
end.

var d,a1,a2:integer;
begin
readln(a1,a2);
d:=0;
while true do begin
 while (a1>1) do begin
  a1:=a1-2;
  a2:=a2+1;
  d:=d+1;
 end;
 while (a2>1) do begin
  a2:=a2-2;
  a1:=a1+1;
  d:=d+1;
 end;
 if (a1=0) and (a2<2) then begin
  Break;
  writeln(d-1);
  end;
 if (a2=0) and (a1<2) then begin
  Break;
  writeln(d-1);
  end;
 if (a1=1) and (a2=1) then begin
  Break;
  writeln(d);
  end;
end;
if d<>0 then
writeln(d-1)
else
writeln(d);
end.

var  a,b,ans:longint;
begin
 read(a,b);
 if (a=1)and(b=1)
  then begin write(0);halt;end;
 while (a>0)and(b>0) do
  begin

   if a>b
    then begin a:=a-2;b:=b+1;end
    else begin b:=b-2;a:=a+1;end;
   inc(ans);
  end;
 write(ans);

end.

var
a,b,tmp,t:int64;
begin
read(a,b);
if(a=1) and (b=1) then begin writeln(0); halt; end;
while(a>2) or (b>2) do
begin
if(a>b) then
begin
tmp:=a;
a:=b;
b:=tmp;
end;
if(b mod 2=0) then
begin
t:=t+((b-2) div 2);
a:=a+((b-2) div 2);
b:=2;
end else begin
t:=t+((b-1) div 2);
a:=a+((b-1) div 2);
b:=1;
end;
end;
writeln(t+1);
end.

var
 x,y,ans:longint;
begin
 read(x,y);
 if (x=1) and (y=1) then begin writeln(0);halt;end
  else
   while(x>0) and (y>0) do
    begin
     inc(ans);
     if x>y then begin x:=x-2;y:=y+1;end
            else begin y:=y-2;x:=x+1;end;
    end;
    writeln(ans);
end.

Var a,b,i,m,j,k,l,o:LongInt;
Procedure UpA;
  Begin
    Inc(a);
    Dec(b,2);
  end;
Procedure UpB;
  begin
    Inc(b);
    Dec(a,2);
  end;
  Begin
    //assign(input,'in.in'); reset(input); assign(output,'out.out'); rewrite(output);
    Read(a,b);
    While (a>0) and (b>0) do
      Begin
        if (a>1) or (b>1) then Inc(k);
        if a<b then UpA else UpB;
      end;
    Write(k);
  end.

program qq;
 var a,b,sum:integer;
   begin
   read(a,b);
    while true do begin
    if a<=b then begin a:=a+1; b:=b-2; sum:=sum+1; end
    else begin b:=b+1; a:=a-2; sum:=sum+1;end;
    if (a<=0)or(b<=0) then begin write(sum);break;end;
      end;
        end.

const
        fi='';//'cf651a.inp';
        fo='';//'cf651a.out';
var
        a,b,res:longint;
begin
        assign(input,fi);reset(input);
        assign(output,fo);rewrite(output);
        readln(a,b);
        repeat
                inc(res);
                if a>b then
                        begin
                                inc(b);
                                dec(a,2);
                        end else
                        begin
                                inc(a);
                                dec(b,2);
                        end;
        until (a<=0)or(b<=0);
        writeln(res);
        close(input);
        close(output);
end.

uses math;
var n,m,kol:longint;
begin

readln(n,m);

kol:=0;
while(n<>0) and(m<>0) do
begin
inc(kol);
if n<m then begin inc(n); dec(m,2); end else begin inc(m); dec(n,2); end;

end;
writeln(kol);

end.

program ProjectD2;

{$APPTYPE CONSOLE}

uses
  SysUtils,math;
const mmd = 2*2*2*3*3*5*7;
var a,n,b,c,e,d,x,y,z,res:integer;  i,j,k:integer;
    s:string;
    m,t,w:array[1..1000]of integer;

   // r1,r2:array[1..100]of integer;
begin
 // reset(input,'input.txt');
 // rewrite(output,'output.txt');
  Readln(a,b);
  res:=0;
  While (a>0)and(b>0) do
  begin
    inc(res);
    if a<b
    then begin
          a:=a+1;
          b:=b-2;
    end
    else begin
          a:=a-2;
          b:=b+1;
    end;
  end;
  write(res);
end.

program zzzz;
var
a1,a2,t:integer;
begin
readln(a1,a2);
t:=0;
repeat
if ((a1>=a2) and ((a2>=1)))then
begin
a2:=a2+1;
a1:=a1-2;
t:=t+1;
end
else
begin
a1:=a1+1;
a2:=a2-2;
t:=t+1;
end;
until a1*a2=0;
writeln(t);
end.

var
  a,s,d,f:integer;
begin
  read(a,d);
  while (a>0) and (d>0) do
  begin
    if a <= d then
    begin
       inc(a);
       dec(D,2);
    end
    else
    begin
      inc(d);
      dec(a,2);
    end;
    inc(f);
  end;
  writeln(f);
  readln;
  readln;
end.

program sum_delit;
var
  a1,a2,x,min,time,kol,i,j:longint;
begin
  {Assign(input,'input.txt');
  Reset(input);
  Assign(output,'output.txt');
  Rewrite(output);}

  readln(a1,a2);

  if (a1=1)and(a2=1) then writeln(1)
  else begin
  //for i:=1 to 100 do
  //for j:=1 to 100 do begin
  //kol:=0; a1:=i; a2:=j;
  if a1<a2 then begin
   x:=a1; a1:=a2; a2:=x; end;

  min:=0;
  while (a1>0)and(a2>0) do begin
   time:=a1 div 2;

   if (a1 mod 2=0)and(time<>1) then dec(time);

   inc(min,time);

   dec(a1,2*time); inc(a2,time);

   if a1<a2 then begin
    x:=a1; a1:=a2; a2:=x; end; inc(kol);
  end;

  writeln(min); end;

//Close(input); Close(output);
end.

var a,b,res,c:longint;
begin
        readln(a,b);
        while (a>2) or (b>2) do
                begin
                        if a<b then
                               begin
                                c:=b;
                                b:=a;
                                a:=c;
                               end;
                        if a mod 2 =0 then
                                begin

                                        b:=b+(a div 2)-1;
                                        inc(res,(a div 2)-1);
                                        a:=2;
                                end
                        else
                                begin

                                        b:=b+(a div 2);
                                        inc(res,a div 2);
                                           a:=1;
                                              end
                end;
                        inc(res);
        write(res);
end.

program qq;
 var a,b,sum:integer;
   begin
   read(a,b);
    while true do begin
     if (a>=2)and(b>=2) then begin a:=a+1;b:=b-2; sum:=sum+1; end;
     if(a<=2)and(b>=3) then begin a:=a+1;b:=b-2;sum:=sum+1; end;
     if(b<=2)and(a>=3) then begin b:=b+1;a:=a-2;sum:=sum+1; end;
     if(a<=2)and(b<=2) then begin a:=a+1;b:=b-2;sum:=sum+1; end;
        if (a<=0)or(b<=0) then begin write(sum);break;end;
        end;
        end.

var a,b:longint;
    i:longint;
begin
    readln(a,b);
    while (a+b>=3) do
        begin
            inc(i);
            if a>b
            then
                begin
                  a:=a-2;
                  b:=b+1;
                end else
                    begin
                        a:=a+1;
                        b:=b-2;
                    end
        end;
    writeln(i);
end.

var
a,b: integer;
flag: integer;
n,m,i,j,k: longint;

begin
ReadLn(a,b);
m:=0;

while ((a>0)and(b>0)) do begin
    if b>a then flag:=1
    else flag:=2;
    if a=1 then flag:=1;
    if b=1 then flag:=2;
    if flag=1 then begin
        a:=a+1;
        b:=b-2;
    end;
    if flag=2 then begin
        a:=a-2;
        b:=b+1;
    end;
    m:=m+1;
end;
writeln(m);
end.

program cf651A;
var a,b,t:longint;
begin
read(a,b);
t:=0;
while (a>0) and (b>0) do
        begin
        inc(t);
        if a<b then
                begin
                inc(a);
                dec(b,2);
                end
        else
                begin
                dec(a,2);
                inc(b);
                end;
        end;

writeln(t);
end.

uses math;
var
  a,b,c,t : longint;

begin
  readln(a,b);
  while min(a,b) > 0 do begin
    if a < b then begin inc(a); dec(b,2); end else
                  begin inc(b); dec(a,2); end;
    inc(c);
  end;
  writeln(c);
end.

var a1,a2,n:integer;
begin
read(a1,a2);
if (a1<2)and(a2<2)
then
write('0')
else
while (a1>0)and(a2>0)do
        begin
        if a1<a2
                then
                begin
                a2:=a2-2;
                a1:=a1+1;
                end
                else
                begin
                a2:=a2+1;
                a1:=a1-2;
                end;
        inc(n);
        end;
write(n);
end.

const fi='';
      fo='';
Var d,m,n: longint;
    f,g: text;
Begin
    Assign(f,fi); Reset(f);
    Assign(g,fo); Rewrite(g);
    Readln(f,n,m);
    If (n=1) and (m=1) then
        Writeln(g,'0')
    Else
        Begin
            While (m>0) or (n>0) do
                Begin
                    inc(d);
                    If n>m then
                        Begin
                            inc(m);
                            dec(n,2);
                        End
                    Else
                        Begin
                            inc(n);
                            dec(m,2);
                        End;
                End;
        End;
    Writeln(g,d);
    Close(f); Close(g);
End.

var a1,a2,k:longint;

begin
 readln(a1,a2);
 while (a1>0) and (a2>0) do
  if a1<=a2 then
             begin
              dec(a2,2);
              inc(k);
              inc(a1);
             end
            else
             begin
              dec(a1,2);
              inc(k);
              inc(a2);
             end;
 writeln(k);
end.

program a621;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var
  time,a1,a2:LongInt;

   begin
  read ( a1 );
  read ( a2 );
  time:=0;
  while ((a1>0) and (a2>0))  do
begin
  if  ((a1 = 1)or (a1=2) )
    then
      begin
       a1:= a1+1;
       a2 := a2-2;
      end
  else
    if ( (a2 = 1)   or (a2=2))
        then
          begin
            a2:=a2 +1;
            a1:= a1 - 2;
          end
          else
           begin
             a2 :=a2 +1;
             a1 := a1-2;
             end;

  Inc(time);
  end;

  write(time);

end.

var d,a1,a2:integer;
begin
readln(a1,a2);
d:=0;
while true do begin
 while (a1>1) do begin
  a1:=a1-2;
  a2:=a2+1;
  d:=d+1;
 end;
 while (a2>1) do begin
  a2:=a2-2;
  a1:=a1+1;
  d:=d+1;
 end;
 if (a1=0) and (a2<2) then begin
  writeln(d-1);
  break;
  end;
 if (a2=0) and (a1<2) then begin
  writeln(d-1);
  break;
  end;
 if (a1=1) and (a2=1) then begin
  writeln(d);
  break;
  end;
end;
end.

program zzzz;
var
a1,a2,t:integer;
begin
readln(a1,a2);
t:=0;
repeat
if ((a1>=a2) and (a2>=1)) then
begin
a2:=a2+1;
a1:=a1-2;
t:=t+1;
end
else
begin
a1:=a1+1;
a2:=a2-2;
t:=t+1;
end;
until a1*a2=0;
writeln(t);
end.

var
  a1, a2, ans, dis, cha: longint;

function max(a, b: longint): longint;
begin
  if a > b then max:= a
  else max:= b;
end;

function min(a, b: longint): longint;
begin
  if a > b then min:= b
  else min:= a;
end;

begin
  readln(a1, a2);
  while (a1 > 0) and (a2 > 0) do
        begin
          if (a1 = 1) or (a2 = 1) then break;
          if a1 > a2 then
                begin
                  dec(a1, 2); inc(a2);
                end
          else
                begin
                  dec(a2, 2); inc(a1);
                end;
          inc(ans);
        end;
  writeln(ans);
end.

uses    math;

var a,b,kq:longint;

procedure mofile;
begin
        assign(input,'CodeForces.inp');
        assign(output,'CodeForces.out');
        reset(input);
        rewrite(output);
end;

procedure dongfile;
begin
        close(input);
        close(output);
end;

procedure swap(var x,y:longint);
var     z:longint;
begin
        z:=x;
        x:=y;
        y:=z;
end;

procedure doc;
begin
        read(a,b);
        if a>b then swap(a,b);
end;

procedure xuly;
begin
        repeat
                if b<=2 then
                begin
                        inc(kq);
                        break;
                end;
                while b>2 do
                begin
                        dec(b,2);
                        inc(a);
                        inc(kq);
                end;
                swap(a,b);
                if (a<=0) or (b<=0) then break;
        until false;
        write(kq);
end;

BEGIN
        //mofile;
        doc;
        xuly;
        //dongfile;
END.

var f:array[0..500,0..500]of longint; a,b:longint;
function max(x,y:longint):longint;
begin
if(a<b)then exit(b) else exit(a);
end;
function mm(x,y:longint):longint;
begin
if(x<=0)or(y<=0)then exit(0);
if(f[x,y]>0)then exit(f[x,y]);
f[x,y]:=max(mm(x-2,y+1),mm(x+1,y-2))+1;
exit(f[x,y]);
end;
begin
readln(a,b);
writeln(mm(a,b));
end.

program joysticks;

var

a, b, o : integer;
inv : boolean;

begin

        read (a);
        read (b);
        if a < b then inv := false else inv := true;

        while (a > 0) and (b > 0) do begin

                if inv = false then begin

                        inc (a);
                        dec (b, 2);
                        inc (o);
                        if b <= 2 then inv := true;

                end else begin

                        inc (b);
                        dec (a, 2);
                        inc (o);
                        if a <= 2 then inv := false;

                end;

        end;

        writeln (o);

end.

var a1,a2,i: word;
 begin
 read (a1,a2);
 if (a1<=100) and (a2<=100) then
 begin
 while (a1>1) and (a2>1) do
 begin
 i:=i+1;
 if a1>a2 then
 begin
 a1:=a1-2;
 a2:=a2+1;
 end
 else
 begin
 a1:=a1+1;
 a2:=a2-2;
 end;
 end;
 write (i);
 end;
 end.

var a,b:integer;c:word;
begin
read(a,b);
if (a=1) and (b=1) then write(0);
while (a>0) and (b>0) do begin
if a<b then begin inc(a); dec(b,2) end else
begin
inc(b);dec(a,2);
end;
inc(c)
end;

write(C);
end.

var
a,b,min:longint;
begin
readln(a,b);
while (a>0)and(b>0) do begin

      if (a=1)or(b=1) then begin
          if a=1 then begin
          inc(min);
          inc(a);
          dec(b,2);
          end
          else begin
          inc(min);
              inc(b);
              dec(a,2);
          end;
      end
      else begin
          if a>b then begin
          inc(min);
              inc(b);
              dec(a,2);
          end
          else begin
          inc(min);
              inc(a);
              dec(b,2);
          end;
      end;

end;
writeln(min);
end.

var
  a1, a2, ans, dis, cha: longint;

function max(a, b: longint): longint;
begin
  if a > b then max:= a
  else max:= b;
end;

function min(a, b: longint): longint;
begin
  if a > b then min:= b
  else min:= a;
end;

begin
  readln(a1, a2);
  while (a1 > 0) and (a2 > 0) do
        begin
          if a1 > a2 then
                begin
                  dec(a1, 2); inc(a2);
                end
          else
                begin
                  dec(a2, 2); inc(a1);
                end;
          inc(ans);
        end;
  writeln(ans);
end.

program z1;
var a,b,c,d,i,j,k,l,m,n,full:longint;

Procedure calc(var x,y:longint);
begin
if (x=2) or (x=1) then begin x:=0; inc(full); exit; end;
if x mod 2=0 then begin full:=full+(x div 2)-1; y:=y+(x div 2)-1; x:=2; exit; end;
if x mod 2=1 then begin full:=full+((x-1) div 2); y:=y+((x-1) div 2); x:=1; exit; end;
end;

begin
//assign(input,'d:\programs\input.txt'); reset(input);
//assign(output,'d:\programs\output.txt'); rewrite(output);
readln(a,b);
while (a>0) and (b>0) do
begin
if a>b then calc(a,b) else calc(b,a);
end;
write(full);
end.

const n=1000000000;
var i,j:longint;
    ans,a1,a2:int64;
begin
read(a1,a2);
for i:=1 to n do
begin
if (a1=1) and (a2=1) then begin write(i); halt; end;
if a1<a2 then begin
              a1:=a1+1;
              a2:=a2-2;
              end
              else
              begin
              a2:=a2+1;
              a1:=a1-2;
              end;
if (a1<1) or (a2<1) then begin write(i); halt; end;
end;
end.

var a,b,ans:LongInt;
    f:boolean;
Begin
  Read(a,b);
  f:=true;
  while(a>0)and(b>0)do
    begin
      if(a-2<1)then
        f:=false;
      if(b-2<1)then
        f:=true;
      if(f)then begin inc(b); dec(a,2); inc(ans); end
      else begin inc(a); dec(b,2); inc(ans); end;
    end;
  Write(ans);
End.

var
a,b,c,d:integer;
begin
readln(a,b);
repeat
if a-2>0 then
  begin
  a:=a-2;
  b:=b+1;
  inc(c);
  end
else
if b-2>0 then
  begin
  b:=b-2;
  a:=a+1;
  inc(c);
  end
else

begin
a:=a-2;
b:=b-2;
inc(c);
end;
until (a<=0) or (b<=0);
writeln(c);
readln;
readln;
end.

var a1, a2, k, e:integer;
begin
read (a1, a2);
if (a1 > 2) or (a2>2) then k:=1 else k:=0;
while (a1 > 2) or (a2>2) do begin
        if a1 >= a2 then begin
                if a1 mod 2 = 0 then e:=a1 div 2 -1
                else e:= a1 div 2;
                k:=k+e;
                a1:=a1-e*2;
                a2:=a2+e;
        end
        else begin
                if a2 mod 2 = 0 then e:=a2 div 2 -1
                else e:= a2 div 2;
                k:=k+e;
                a2:=a2-e*2;
                a1:=a1+e;
        end;
end;
writeln (k);
end.

const fin='';
      fout='';
var n,m,d:longint;
    f,g:text;
begin
    assign(f,fin);reset(f);
    assign(g,fout);rewrite(g);
    readln(f,n,m);
    while (n>0)and(m>0) do
    begin
        if n>m then
        begin
            n:=n-2;
            m:=m+1;
        end
        else
        begin
            m:=m-2;
            n:=n+1;
        end;
        inc(d);
    end;
    write(g,d);
    close(f);close(g);
end.

var a,b,res,c:longint;
begin
        readln(a,b);
        while (a>2) or (b>2) do
                begin
                        if a<b then
                               begin
                                c:=b;
                                b:=a;
                                a:=c;
                               end;
                        if a mod 2 =0 then
                                begin

                                        b:=b+(a div 2)-1;
                                        inc(res,(a div 2)-1);
                                        a:=2;
                                end
                        else
                                begin

                                        b:=b+(a div 2);
                                        inc(res,a div 2);
                                           a:=1;
                                              end
                end;
                        inc(res);
        write(res);
end.

var a1,a2,n:integer;
begin
read(a1,a2);
while (a1>=0)or(a2>=0)do
        begin
        if a1<a2
                then
                begin
                a2:=a2-2;
                a1:=a1+1;
                end
                else
                begin
                a2:=a2+1;
                a1:=a1-2;
                end;
        inc(n);
        end;
write(n);
end.

var n,m:longint;
    i,time:longint;
begin
readln(n,m);
while (n>0) and (m>0) do
begin
 if n<m
 then begin
  n:=n+1;
  m:=m-2;
 end
 else begin
  m:=m+1;
  n:=n-2;
 end;
 inc(time);
end;
writeln(time);
end.

var
  a,s,d,f:integer;
begin
  read(a,d);
  while (a>0) and (d>0) do
  begin
    if a <= d then
    begin
       inc(a);
       dec(D,2);
    end
    else
    begin
      inc(d);
      dec(a,2);
    end;
    inc(f);
  end;
  writeln(f);
  readln;
  readln;
end.

var a1,a2,k:integer;
begin
readln(a1,a2);
k:=0;
if (a1<1)or(a1>100)or(a2<1)or(a2>100)then exit;
while True do begin
if (a1=0) or (a2=0) then break;
if a1<a2 then begin a1:=a1+1 ; a2:=a2-2; inc(k) end
else   begin a2:=a2+1 ; a1:=a1-2; inc(k)end ;
end;
writeln(k);
end.

program qq;
 var a,b,sum:integer;
    begin
   read(a,b);
    while true do begin
    if a<=b then begin a:=a+1; b:=b-2; sum:=sum+1; end
    else begin b:=b+1; a:=a-2; sum:=sum+1;end;
    if (a<=0)or(b<=0) then begin write(sum);break;end;
      end;
        end.

Uses math;
Const Fi='';
      Fo='';
Var f:text;
    t:word;
    a1,a2: byte;
Procedure docfile;
         Begin
              Assign(f,fi);Reset(f);
              Readln(f,a1,a2);
              CLose(f);
         End;
Procedure ghifile;
         Begin
              Assign(f,fo);Rewrite(f);
              WRiteln(f,t);
              Close(f);
         End;
Procedure xuly;
         Begin
              t:=0;
              Repeat
                    If (a1=1) and (a2=1) then exit;
                    Inc(t);
                    If a2>a1 then Begin
                                       a1:=a1+1;
                                       a2:=a2-2;
                                  End
                    else Begin a2:=a2+1; a1:=a1-2; End;
              Until (a1=0) or (a2=0);
         End;
Begin
     docfile;
     If (a1<=2) and (a2<=2) then t:=0 else xuly;
     ghifile;
End.

program z1;
var a,b,c,d,i,j,k:longint;
begin
//assign(input,'d:\programs\input.txt'); reset(input);
//assign(output,'d:\programs\output.txt'); rewrite(output);
readln(a,b);
for i:=1 to 10000 do
 begin
 if (a<=0) or (b<=0) then break;
 if a>b then begin a:=a-2; b:=b+1; end else begin a:=a+1; b:=b-2; end;
 end;
 writeln(i-1);
end.

var a,b,dem:longint;
begin
 readln(a,b);
 dem:=0;
 while ((a>0) and (b>0)) do
  begin
   if (a=1) then
    begin
     inc(a);
     dec(b,2);
    end
   else if (b=1) then begin inc(b); dec(a,2); end
   else if (a<=b) then begin inc(a); dec(b,2); end
   else if (b<a) then begin inc(b); dec(a,2); end;
   inc(dem);
  end;
  writeln(dem);
end.

var
  n,m,ans,t:longint;
begin
  read(n,m);
  ans:=0;
  if n>m then
    begin
      t:=n;n:=m;m:=t;
    end;
  while n<m do
    begin
      inc(n);
      dec(m,2);
      inc(ans);
    end;
  inc(ans,(n-2)*2+1);
  writeln(ans);
end.

var a,b,ans:longint;
begin
read(a,b);
while a*b>0 do
   begin
   if a<b then
      begin
      inc(a);dec(b,2);
      end
   else
      begin
      inc(b);dec(a,2);
      end;
   inc(ans);
   end;
write(ans);
end.

const
	fi = '';
	fo = '';
var a, b, c:longint;
begin
	assign(input, fi); reset(input);
	assign(output, fo); rewrite(output);
	readln(a, b);
	c:=0;
	while (a>0) and (b>0) do
        begin
                c:=c+1;
                if a<b then
                begin
                        a:=a+1; b:=b-2;
                end else
		begin
		        a:=a-2; b:=b+1;
		end;
        end;
	writeln(c);
	close(input); close(output);
end.

const n=1000000000;
var a1,a2,i,j:longint;
    ans:longint;
begin
read(a1,a2);
for i:=1 to n do
begin
if a1<a2 then begin
              a1:=a1+1;
              a2:=a2-2;
              end
              else
              begin
              a2:=a2+1;
              a1:=a1-2;
              end;
if (a1<1) or (a2<1) then begin write(i); halt; end;
end;
end.

var a,b,c:integer;
begin
c:=0;
readln(a,b);
while (a>0) and (b>0) do
if a>b then begin
b:=b+1; dec(a,2); inc(c); end else begin
a:=a+1; dec(b,2); inc(c); end;
writeln(c); end.

var n,m,p,r,a,x,y,c : longint;
b,v: array[0..100000] of longint;
da : boolean;
s : ansistring;
begin

	readln(n,p);

	while (n>0) and (p>0) do
	begin

		if n<=p then
		begin
			n:=n+1;
			p:=p-2;
		end else

		if n>p then
		begin
			p:=p+1;
			n:=n-2;
		end;
		inc(r);

	end;

	if (n=1) and (p=1) then r:=0;
	writeln(r);
end.

var
a,b,min:longint;
begin
readln(a,b);
while (a>0)and(b>0) do begin
    inc(min);
    if a>b then begin
     b:=b+1;
     dec(a,2);
    end
    else begin
    a:=a+1;
    dec(b,2);
    end;
end;
writeln(min);
end.

const fi='';
      fo='';
Var d,m,n: longint;
    f,g: text;
Begin
    Assign(f,fi); Reset(f);
    Assign(g,fo); Rewrite(g);
    Readln(f,n,m);
    If (n=1) and (m=1) then
        Writeln(g,'0')
    Else
        Begin
            While (m>0) or (n>0) do
                Begin
                    inc(d);
                    If n>m then
                        Begin
                            inc(m);
                            n:=n-2;
                        End
                    Else
                        Begin
                            inc(n);
                            m:=m-2;
                        End;
                End;
        End;
    Writeln(g,d);
    Close(f); Close(g);
End.

var
 a,b,c,i,j,k,m,n:longint;
begin
 read(a,b);
 while (a>0)and(b>0) do
 begin
  if (a<3)and(b>1) then begin inc(a); dec(b,2); end else
  begin inc(b); dec(a,2); end;
  inc(i);
 end;
 writeln(i);
end.

var
  m, cur, ans, n: longint;
begin
 readln(n, m);
 while (m > 0) and (n > 0) do
 begin
   if n = m then begin
   inc(m);
   dec(n, 2);
   inc(ans);
   continue;
  end;
  if n > m then begin
    inc(m);
     dec(n, 2);
     inc(ans);
     continue;
  end;
   inc(n);
   dec(m, 2);
   inc(ans);
 end;
 Writeln(ans);
end.

uses    dos;

var     a1,a2,m:longint;

label   x,y;

begin
        readln(a1,a2);
        m:=0;
        if (a1=1) and (a2=2) then goto y;
        repeat
              if (a1<a2) or (a1=a2) then
                 begin
                      dec(a2,2);
                      inc(a1);
                      goto x;
                 end;
              dec(a1,2);
              inc(a2);
              x:inc(m);
        until (a1<=0) or (a2<=0);
        y:write(m);
end.

const n=1000000000;
var i,j:longint;
    ans,a1,a2:int64;
begin
read(a1,a2);
for i:=1 to n do
begin
if (a1=1) and (a2=1) then begin write(i); halt; end;
if a1<a2 then begin
              a1:=a1+1;
              a2:=a2-2;
              end
              else
              begin
              a2:=a2+1;
              a1:=a1-2;
              end;
if (a1<1) or (a2<1) then begin write(i); halt; end;
end;
end.

var
a,b: integer;
flag: integer;
n,m,i,j,k: longint;

begin
ReadLn(a,b);
m:=0;

while ((a>0)and(b>0)) do begin
    if b>a then flag:=1
    else flag:=2;
    if b=1 then flag:=2;
    if a=1 then flag:=1;

    if flag=1 then begin
        a:=a+1;
        b:=b-2;
    end;
    if flag=2 then begin
        a:=a-2;
        b:=b+1;
    end;
    m:=m+1;
end;
writeln(m);
end.

var
 a,b,c,i,j,k,m,n:longint;
begin
 read(a,b);
 while (a>0)and(b>0) do
 begin
  if a>b then begin inc(b); dec(a,2); inc(i); end else
  begin inc(a); dec(b,2); inc(i); end;
 end;
 writeln(i);
end.

uses    dos;

var     n,d,e,f,min,i,a:longint;
        p,m,s:array[1..5000] of longint;

begin
        readln(n);
        d:=0;
        e:=0;
        f:=0;
        for i:=1 to n do
            begin
                 read(a);
                 if a=1 then
                    begin
                         inc(d);
                         p[d]:=i;
                    end;
                 if a=2 then
                    begin
                         inc(e);
                         m[e]:=i;
                    end;
                 if a=3 then
                    begin
                         inc(f);
                         s[f]:=i;
                    end;
            end;
        min:=5000;
        if d<min then min:=d;
        if e<min then min:=e;
        if f<min then min:=f;
        writeln(min);
        for i:=1 to min do writeln(p[i],' ',m[i],' ',s[i]);
        readln;
end.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var joystick1,joystick2, minutes : integer;

procedure charger(var a, b : integer);
begin
  if b < a then
  begin
    b:=b+1;
    a:=a-2;
  end
  else begin
    a:=a+1;
    b:=b-2;
  end;
end;

begin
  minutes := 0;
  readln(joystick1, joystick2);

  while 1>0 do
  begin
    if (joystick1=0) OR (joystick2=0) then break;
    charger(joystick1, joystick2);
    minutes:=minutes+1;
  end;
  writeln(minutes);
  readln;
end.

var x:array[-10..210,-10..210] of longint;
  i,j,n,m,a,b:longint;
function max(a,b:longint):longint;
begin
  if a>b then exit(a)
    else exit(b);
end;
begin
  for i:=2 to 200 do
    for j:=1 to i-1 do
      x[i,j]:=max(x[i-1,j-2],x[i-1,j+1])+1;
  readln(a,b);
  writeln(x[a+b,b]);
end.

program zzzz;
var
a1,a2,t:integer;
begin
readln(a1,a2);
t:=0;
if ((a1<>1) and (a2<>1)) then
begin
repeat
if ((a1>=a2) and ((a2>=1)))then
begin
a2:=a2+1;
a1:=a1-2;
t:=t+1;
end
else
begin
a1:=a1+1;
a2:=a2-2;
t:=t+1;
end;
until a1*a2=0;
end;
writeln(t)
end.

program h;
var a,b,i,c: integer;
begin
read(a,b); i:=0;
while (a<>0) and (b<>0) do
begin
if (a>=b) then
begin
a:=a-2;
b:=b+1;
i:=i+1;
end
else begin
b:=b-2;
a:=a+1;
i:=i+1;end;
end;
write(i);end.

var a,b,sum:int64;
begin
readln(a,b);
while(a<>0)and(b<>0)do
  begin
  if(a<b)then begin a:=a+1;b:=b-2;end
  else begin a:=a-2;b:=b+1;end;
  sum:=sum+1;
  end;
writeln(sum);
end.

var
a,b,i:longint;
begin
readln(A,b);
while(a>1)and(b>1)do begin
inc(I);
if a<b
then begin
inc(A);
dec(b,2); end
else begin
inc(b);
dec(a,2);
end;
end;
writeln(i);
end.

var a,b,res,c:longint;
begin
        readln(a,b);
        while (a>2) or (b>2) do
                begin
                        if a<b then
                               begin
                                c:=b;
                                b:=a;
                                a:=c;
                               end;
                        if a mod 2 =0 then
                                begin

                                        b:=b+(a div 2)-1;
                                        inc(res,(a div 2)-1);
                                        a:=2;
                                end
                        else
                                begin

                                        b:=b+(a div 2);
                                        inc(res,a div 2);
                                           a:=1;
                                              end
                end;
                        inc(res);
        write(res);
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}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

const filename='qc';
      oo=maxlongint div 2;
      eps=1e-6;
      eee=1e-21;

var qi,ci:array[0..1000000]of int64;
    qq,cc,a,aa:array[0..1000000]of longint;
    qc,he:array[0..2014,0..2014]of longint;
    ss,sss:array[0..10000]of string;
    s,s0,s1,s2,s3:string;
    x,y,z,xx,yy,zz,x0,y0,z0,x1,x2,x3,y1,y2,y3,z1,z2,z3:extended;
    res64,n64,nn64:int64;
    w,nt,ii,jj,n,m,q,c,q0,c0,q1,c1,q2,c2,q3,c3:longint;
    nn,mm,kk,u,v,res,cur,max,min:longint;
    test,ll,t,tt:longint;
    b,bb,bbb,b0,b1,b2,b3:boolean;
    ccc:char;

function mx(q,c:longint):longint;
  begin
  if q>c then mx:=q else mx:=c;
  end;

function mn(q,c:longint):longint;
  begin
  if q<c then mn:=q else mn:=c;
  end;

procedure init;
  begin
  assign(input,filename+'.in');
  assign(output,filename+'.out');
  reset(input);
  rewrite(output);
  end;

procedure fin;
  begin
  close(input);
  close(output);
  end;

procedure clear;
var i,j,k:longint;
  begin
  fillchar(qc,sizeof(qc),0);
  end;

procedure load;
var i,j,k:longint;
  begin
  end;

procedure save;
var i,j,k:longint;
  begin
  end;

procedure swap(var q,c:longint);
var i:longint;
    begin
    i:=q; q:=c; c:=i;
    end;

procedure qcsort(q,c:longint);
var h,e,d,x:longint;
    ass:boolean;
    begin
    if q>=c then exit;
    x:=q+random(c-q+1);
    swap(qc[q,0],qc[x,0]);
    swap(qc[q,1],qc[x,1]);
    h:=q; e:=c; d:=1;
    while h+d<=e do
      begin
      if qc[h,0]=qc[h+d,0] then inc(d) else
      if qc[h,0]<qc[h+d,0] then
        begin swap(qc[h+d,0],qc[e,0]); swap(qc[h+d,1],qc[e,1]); dec(e); end
      else begin swap(qc[h,0],qc[h+d,0]); swap(qc[h,1],qc[h+d,1]); inc(h); end
      end;
    qcsort(q,h-1);
    qcsort(h+d,c);
    end;

procedure qqcsort(q,c:longint);
var h,e,d,x:longint;
    ass:boolean;
    begin
    if q>=c then exit;
    x:=q+random(c-q+1);
    swap(qq[q],qq[x]);
    h:=q; e:=c; d:=1;
    while h+d<=e do
      begin
      if qq[h]=qq[h+d] then inc(d) else
      if qq[h]<qq[h+d] then
        begin swap(qq[h+d],qq[e]); dec(e); end
      else begin swap(qq[h],qq[h+d]); inc(h); end
      end;
    qqcsort(q,h-1);
    qqcsort(h+d,c);
    end;

procedure run;
var i,j,k:longint;
  begin
  //init;
  read(q,c);
  res:=0;
  while ((q>0)and(c>0)) do
    begin
    inc(res);
    if 2<c then begin inc(q); dec(c,2) end
    else begin inc(c); dec(q,2) end;
    if q*c=1 then c:=0;
    end;
  writeln(res);
  //fin;
  end;

begin
nt:=1;
//readln(nt);
for test:=1 to nt do
  begin
  clear;
  load;
  run;
  save;
  end;
end.

var a, b, c, d : longint;
begin
   readln(a, b);
   while (a > 0) and (b > 0) do
   begin
      d := d + 1;

      if a <= 2 then
         c := 1;
      if b <= 2 then
         c := 2;
      if c = 1 then
      begin
         a := a + 1;
         b := b - 2;
      end
      else
      begin
         a := a - 2;
         b := b + 1;
      end;
   end;
   writeln(d);
end.

uses math;
var n,m,kol:longint;
begin

readln(n,m);

kol:=0;
while(n<>0) and(m<>0) do
begin
inc(kol);
if n<m then begin inc(n); dec(m,2); end else begin inc(m); dec(n,2); end;

if (n<=0) or(m<=0) then begin writeln(kol); halt; end;

end;
writeln(kol);

end.

var
a,b,c,d:integer;
begin
readln(a,b);
if a>b then c:=b*2
else c:=a*2;
writeln(c);
readln;
end.

var a,b,c:longint;
begin
readln(a,b);
while (a>0) and (b>0) do begin
                           if (a<b) or (a=1) then begin
                                                  inc(a);
                                                  dec(b,2);
                                                  end
                                             else begin
                                                  inc(b);
                                                  dec(a,2);
                                                  end;
                           inc(c);
                           end;
writeln(c);
end.

var
a,b: int64;
flag: integer;
n,m,i,j,k: longint;

begin
ReadLn(a,b);
m:=0;
if b>a then flag:=1
    else flag:=2;
while ((a>0)and(b>0)) do begin

    if b<=2 then flag:=2;
    if a<=2 then flag:=1;
    if flag=1 then begin
        a:=a+1;
        b:=b-2;
    end;
    if flag=2 then begin
        a:=a-2;
        b:=b+1;
    end;
    //writeln(a,' ',b);
    m:=m+1;
end;
writeln(m);
end.

var
 a,b,c,i,j,k,m,n:longint;
begin
 read(a,b);
 while (a>0)and(b>0) do
 begin
  if a<3 then begin inc(a); dec(b,2); end else
  begin inc(b); dec(a,2); end;
  inc(i);
 end;
 writeln(i);
end.

var
	a,b: integer;
	cnt: integer;
begin
	readln(a,b);
	while (a>0) and (b>0) do
	if a>b then
	begin
		inc(a,-2);
		inc(b);
		inc(cnt);
	end else
	begin
		inc(a);
		inc(b,-2);
		inc(cnt);
	end;
	writeln(cnt);
end.

Var
    i, n, m, k, l, o, p, ans:LongInt;
Begin
 Read(n, m);
 while (n>0) and (m>0) do
  Begin
     Inc(ans);
     if (n>m) then Begin Dec(n, 2);Inc(m, 1);End
     else Begin Dec(m, 2);Inc(n, 1);End;

  End;
  WriteLn(ans);
End.

var
a,b,min:longint;
begin
readln(a,b);
while (a>0)and(b>0) do begin

    if a>b then begin
        inc(min);
     b:=b+1;
     dec(a,2);
    end
    else begin
                inc(min);
    a:=a+1;

    dec(b,2);
    end;

end;
writeln(min);
end.

uses    dos;

var     a1,a2,m:longint;

label   x;

begin
        readln(a1,a2);
        m:=0;
        repeat
              if (a1<a2) or (a1=a2) then
                 begin
                      dec(a2,2);
                      inc(a1);
                      goto x;
                 end;
              dec(a1,2);
              inc(a2);
              x:inc(m);
        until (a1=0) or (a2=0);
        write(m);
end.

var a,b,t:longint;
begin
  readln(a,b);
  if(a<=1)and(b<=1) then writeln(0)
  else
  while((a>0)and(b>0)) do
    begin
      if(a>=b) then
        begin
          b:=b+1;
          a:=a-2;
        end
      else
        begin
          b:=b-2;
          a:=a+1;
        end;
      t:=t+1;
    end;
  writeln(t);
end.

const
	fi = '';
	fo = '';
var a, b, c:integer;
begin
	assign(input, fi); reset(input);
	assign(output, fo); rewrite(output);
	readln(a, b);
	c:=0;
	while not((a<=0) or (b<=0)) do
	begin
		c:=c+1;
		if a< b then
		begin
			a:=a+1; b:=b-2;
		end else
		begin
			a:=a-2; b:=b+1;
		end;
	end;
	writeln(c);
	close(input); close(output);
end.

uses math;
var a1,a2,i,t:integer;
begin
readln(a1,a2);
if a1>a2 then begin t:=a1; a1:=a2; a2:=t; end;
i:=0;
if (a1<=1) and (a2<=1) then writeln(0);
while abs(a1-a2)>1 do
begin
inc(a1);
a2:=a2-2;
inc(i);
end;
if (a2<1) or (a1<1) then writeln(i) else
if a1=a2 then
writeln(i+(min(a1,a2)-2)*2+1) else writeln(i+(min(a1,a2)-2)*2+3)
end.

const n=1000000000;
var i,j:longint;
    ans,a1,a2:int64;
begin
read(a1,a2);
for i:=1 to maxlongint do
begin
if (a1=1) and (a2=1) then begin write(i); halt; end;
if a1<a2 then begin
              a1:=a1+1;
              a2:=a2-2;
              end
              else
              begin
              a2:=a2+1;
              a1:=a1-2;
              end;
if (a1<0) or (a2<0) then begin write(i); halt; end;
end;
end.

var a,b,k:longint;
begin
  readln(a,b);
  k:=0;
  while true do
    begin
      if a < b then begin inc(a); dec(b,2); end
        else begin inc(b); dec(a,2); end;
      inc(k);
      if (a=0) or (b=0) or ((a=1) and (b=1)) then break;
    end;

  writeln(k);
end.

var n,m,p,z:longint;
 begin
  readln(n,m); if (n>1)and(m>1) then begin
  repeat
   inc(z);
   if n<m then begin m:=m-2;
                     n:=n+1;
                     end
                     else begin n:=n-2; m:=m+1;end;

  until((n<1)or (m<1));
  end else begin writeln(0); exit;end;
  writeln(z);
 end.

program qq;
 var a,b,sum:integer;
    begin
   read(a,b);
    while true do begin
    if a<=b then begin a:=a+1; b:=b-2; sum:=sum+1; end
    else begin b:=b+1; a:=a-2; sum:=sum+1;end;
   if(a=1)and(b=1) then begin sum:=sum-1; write(sum);break;end;
    if (a<=0)or(b<=0) then begin write(sum);break;end;
      end;
        end.

program qq;
 var a,b,sum:integer;
    begin
   read(a,b);
    while true do begin
    if a<=b then begin a:=a+1; b:=b-2; sum:=sum+1; end
    else begin b:=b+1; a:=a-2; sum:=sum+1;end;
   if(a=1)and(b=1) then begin  write(sum);break;end;
    if (a<=0)or(b<=0) then begin write(sum);break;end;
      end;
        end.

var
a,b,i:longint;
begin
readln(A,b);
while(a>0)and(b>0)do begin
inc(I);
if a<b
then begin
inc(A);
dec(b,2); end
else begin
inc(b);
dec(a,2);
end;
end;
writeln(i);
end.

var n,m,p,z:longint;
 begin
  readln(n,m);
  repeat
   inc(z);
   if n<m then begin m:=m-2;
                     n:=n+1;
                     end
                     else begin n:=n-2; m:=m+1;end;

  until((n<1)or (m<1));
  writeln(z);
 end.

Var a,b,i,m,j,k,l,o:LongInt;
Procedure UpA;
  Begin
    Inc(a);
    Dec(b,2);
  end;
Procedure UpB;
  begin
    Inc(b);
    Dec(a,2);
  end;
  Begin
    //assign(input,'in.in'); reset(input); assign(output,'out.out'); rewrite(output);
    Read(a,b);
    While (a>0) and (b>0) do
      Begin
        if (a>1) and (b>1) then
          Begin
            if a mod 2=0 then UpA else UpB;
          end else
        if (a=1) then UpA else UpB;
        Inc(k);
      end;
    Write(k);
  end.


In a Berland city S*** there is a tram engine house and only one tram. Three people work in the house — the tram driver, the conductor and the head of the engine house. The tram used to leave the engine house every morning and drove along his loop route. The tram needed exactly c minutes to complete the route. The head of the engine house controlled the tram’s movement, going outside every c minutes when the tram drove by the engine house, and the head left the driver without a bonus if he was even one second late.It used to be so. Afterwards the Berland Federal Budget gave money to make more tramlines in S***, and, as it sometimes happens, the means were used as it was planned. The tramlines were rebuilt and as a result they turned into a huge network. The previous loop route may have been destroyed. S*** has n crossroads and now m tramlines that links the pairs of crossroads. The traffic in Berland is one way so the tram can move along each tramline only in one direction. There may be several tramlines between two crossroads, which go same way or opposite ways. Every tramline links two different crossroads and for each crossroad there is at least one outgoing tramline.So, the tramlines were built but for some reason nobody gave a thought to increasing the number of trams in S***! The tram continued to ride alone but now the driver had an excellent opportunity to get rid of the unending control of the engine house head. For now due to the tramline network he could choose the route freely! Now at every crossroad the driver can arbitrarily choose the way he can go. The tram may even go to the parts of S*** from where it cannot return due to one way traffic. The driver is not afraid of the challenge: at night, when the city is asleep, he can return to the engine house safely, driving along the tramlines in the opposite direction.The city people were rejoicing for some of the had been waiting for the tram to appear on their streets for several years. However, the driver’s behavior enraged the engine house head. Now he tries to carry out an insidious plan of installing cameras to look after the rebellious tram.The plan goes as follows. The head of the engine house wants to install cameras at some crossroads, to choose a period of time t and every t minutes turn away from the favourite TV show to check where the tram is. Also the head of the engine house wants at all moments of time, divisible by t, and only at such moments the tram to appear on a crossroad under a camera. There must be a camera on the crossroad by the engine house to prevent possible terrorist attacks on the engine house head. Among all the possible plans the engine house head chooses the plan with the largest possible value of t (as he hates being distracted from his favourite TV show but he has to). If such a plan is not unique, pick the plan that requires the minimal possible number of cameras. Find such a plan.

The first line contains integers n and m (2 ≤ n, m ≤ 105) — the number of crossroads and tramlines in S*** respectively. The next m lines contain the descriptions of the tramlines in "u v" format, where u is the initial tramline crossroad and v is its final crossroad. The crossroads are numbered with integers from 1 to n, and the engine house is at the crossroad number 1.

In the first line output the value of t. In the next line output the value of k — the required number of the cameras. In the next line output space-separated numbers of the crossroads, where the cameras should be installed. Output the numbers in increasing order.

const
    nfin=   '';
    nfout=  '';
    maxn=   100010;

type
    dslk = ^pointer;
    pointer= record
        u: longint;
        next: dslk;
    end;

var
    ds:     array[0..maxn] of dslk;
    d, q:   array[0..maxn] of longint;
    n, m:   longint;
    i, j, u, v, res, cnt, l, r, mid: longint;
    temp:   dslk;
    fin, fout: text;

procedure push(u, v: longint);
var temp: dslk;
begin
    new(temp);
    temp^.u:=v;
    temp^.next:=ds[u];
    ds[u]:=temp;
end;

function gcd(x, y: longint): longint;
var r: longint;
begin
    if x*y=0 then begin
        gcd:=(x+y);
        exit;
    end;

    while x mod y <> 0 do begin
        r:= x mod y;
        x:=y;
        y:=r;
    end;
    gcd:=y;
end;

procedure attemp(u: longint);
var temp: dslk;
begin
    temp:=ds[u];
    while temp<>nil do begin
        if d[temp^.u] = -1 then begin
            d[temp^.u]:=(d[u] + 1);
            attemp(temp^.u);
        end
        else res:=gcd(res, abs(d[temp^.u] - 1 - d[u]));
        temp:=temp^.next;
    end;
end;

begin
    assign(fin, nfin); reset(fin);
    assign(fout, nfout); rewrite(fout);
        readln(fin, n, m);
        for i:=1 to n do ds[i]:=nil;
        for i:=1 to m do begin
            readln(fin, u, v);
            push(u, v);
        end;

        res:=0;
        fillchar(d, sizeof(d), 255);
        d[1]:=0;
        l:=1; r:=1; q[1]:=1;
        while l<=r do begin
            u:=q[l];
            temp:=ds[u];
            while temp<>nil do begin
                if d[temp^.u] = -1 then begin
                    inc(r);
                    q[r]:=temp^.u;
                    d[temp^.u]:=d[u]+1;
                end
                else res:=gcd(res, abs(d[u] +1 - d[temp^.u]));
                temp:= temp^.next;
            end;
            inc(l);
        end;
        cnt:=0;
        for i:=1 to n do if (d[i]>-1) and ((d[i] mod res)=0) then inc(cnt);
        writeln(fout, res);
        writeln(fout, cnt);
        for i:=1 to n do if (d[i]>-1) and ((d[i] mod res)=0) then write(fout, i,' ');
    close(fout);
    close(fin);
end.

program solution;

{$APPTYPE CONSOLE}
{MODE DELPHI}
{$MAXSTACKSIZE 1000000000}
{O-,R+,Q+}
{$O+,R-,Q-}

uses
  SysUtils,
  Math;

const
  inf = round(1e9);

var
  n, m, k, a, b, cur, l, r, ans, i : integer;
  queue, d, go, next, first : array[0..100001] of integer;

procedure add(a, b : integer);
begin
  inc(k);
  go[k] := b;
  next[k] := first[a];
  first[a] := k;
end;

function gcd(a, b : integer) : integer;
begin
  if b = 0 then
    result := a
  else
    result := gcd(b, a mod b);
end;

begin
  //assign(input, 'input.txt'); reset(input);
  //assign(output, 'output.txt'); rewrite(output);
  read(n, m);
  k := 0;
  for i := 1 to m do begin
    read(a, b);
    add(a, b);
  end;
  for i := 1 to n do
    d[i] := inf;
  d[1] := 0;
  l := 1;
  r := 1;
  queue[1] := 1;
  ans := 0;
  while l <= r do begin
    cur := queue[l];
    inc(l);
    i := first[cur];
    while i > 0 do begin
      if d[go[i]] > d[cur] + 1 then begin
        d[go[i]] := d[cur] + 1;
        inc(r);
        queue[r] := go[i];
      end
      else
        ans := gcd(ans, d[cur] + 1 - d[go[i]]);
      i := next[i];
    end;
  end;
  writeln(ans);
  k := 0;
  for i := 1 to n do
    if (d[i] < inf) and (d[i] mod ans = 0) then
      inc(k);
  writeln(k);
  for i := 1 to n do
    if (d[i] < inf) and (d[i] mod ans = 0) then
      write(i, ' ');
  writeln;
end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
var
  n,m,i,j,aa,bb,e,t,k: longint;
  v,last,pred,was,ss,ff,x,y: array [0..400010] of longint;
  dist: array [0..400010,0..2] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  read(n,m);
  fillchar(last,sizeof(last),0);
  for i:=1 to m do
  begin
    read(ss[i],ff[i]);
    pred[i]:=last[ss[i]];
    last[ss[i]]:=i;
  end;
  fillchar(was,sizeof(was),0);
  fillchar(dist,sizeof(dist),0);
  i:=1; e:=1;
  x[1]:=1;
  y[1]:=1;
  was[1]:=1;
  dist[1,1]:=0;
  while i <= e do
  begin
    j:=last[x[i]];
    while j > 0 do
    begin
      if (was[ff[j]] < 2) and (dist[x[i],y[i]]+1 <> dist[ff[j],was[ff[j]]]) then
      begin
        inc(e);
        x[e]:=ff[j];
        inc(was[x[e]]);
        y[e]:=was[x[e]];
        dist[x[e],y[e]]:=dist[x[i],y[i]]+1;
      end;
      j:=pred[j];
    end;
    inc(i);
  end;
  t:=0;
  for i:=1 to n do
    if was[i] = 2 then
    begin
      aa:=t; bb:=dist[i,2]-dist[i,1];
      while (aa > 0) and (bb > 0) do
        if aa > bb then aa:=aa mod bb
        else bb:=bb mod aa;
      t:=aa+bb;
    end;
  for i:=1 to m do
    if (was[ss[i]] > 0) and (was[ff[i]] > 0) then
    begin
      aa:=t; bb:=abs(dist[ss[i],1]+1-dist[ff[i],1]);
      while (aa > 0) and (bb > 0) do
        if aa > bb then aa:=aa mod bb
        else bb:=bb mod aa;
      t:=aa+bb;
    end;
  k:=0;
  for i:=1 to n do
    if (was[i] > 0) and (dist[i,1] mod t = 0) then
    begin
      inc(k);
      v[k]:=i;
    end;
  writeln(t);
  writeln(k);
  for i:=1 to k-1 do write(v[i],' ');
  writeln(v[k]);
  close(input);
  close(output);
end.

const
    nfin=   '';
    nfout=  '';
    maxn=   100010;

type
    dslk = ^pointer;
    pointer= record
        u: longint;
        next: dslk;
    end;

var
    ds:     array[0..maxn] of dslk;
    d, tr:  array[0..maxn] of longint;
    n, m:   longint;
    i, j, u, v, res, cnt, l, r, mid: longint;
    fin, fout: text;

procedure push(u, v: longint);
var temp: dslk;
begin
    new(temp);
    temp^.u:=v;
    temp^.next:=ds[u];
    ds[u]:=temp;
end;

function attemp(u, t: longint): boolean;
var temp: dslk;
begin
    temp:=ds[u];
    while temp<>nil do begin
        if d[temp^.u] = -1 then begin
            d[temp^.u]:=(d[u] + 1) mod t;
            if attemp(temp^.u, t) = false then begin
                attemp:=false;
                exit;
            end;
        end
        else if d[temp^.u] <> (d[u] + 1 ) mod t then begin
                attemp:=false;
                exit;
            end;

        temp:=temp^.next;
    end;

    attemp:=true;
end;

function check(t: longint): boolean;
begin
    fillchar(d, sizeof(d), 255);
    d[1]:=0;
    check:=attemp(1, t);
end;

function dfs(u: longint): longint;
var t, v: longint;
    temp: dslk;
begin
    d[u]:=0;
    temp:=ds[u];
    while temp<>nil do begin
        if d[temp^.u] = -1 then begin
            tr[temp^.u]:=u;
            dfs:=dfs(temp^.u);
            exit;
        end
        else if d[temp^.u] = 0 then begin
            l:=0;
            v:=u;
            t:=1;
            while v<>temp^.u do begin
                v:=tr[v];
                t:=t+1;
            end;
            dfs:=t;
            exit;
        end;
        temp:=temp^.next;
    end;
    d[u]:=1;
end;

function lc: longint;
begin
    fillchar(d, sizeof(d), 255);
    fillchar(tr, sizeof(tr), 0);
    lc:=dfs(1);
end;

begin
    assign(fin, nfin); reset(fin);
    assign(fout, nfout); rewrite(fout);
        readln(fin, n, m);
        for i:=1 to n do ds[i]:=nil;
        for i:=1 to m do begin
            readln(fin, u, v);
            push(u, v);
        end;

        l:=lc;
        for res:=l downto 1 do
            if (l mod res = 0) then
            if check(res) then break;

        for i:=1 to n do if (d[i] mod res)=0 then inc(cnt);
        writeln(fout, res);
        writeln(fout, cnt);
        for i:=1 to n do if (d[i] mod res)=0 then write(fout, i,' ');
    close(fout);
    close(fin);
end.

const
    nfin=   '';
    nfout=  '';
    maxn=   1000010;

type
    dslk = ^pointer;
    pointer= record
        u: longint;
        next: dslk;
    end;

var
    ds:     array[0..maxn] of dslk;
    d, tr:  array[0..maxn] of longint;
    n, m:   longint;
    i, j, u, v, res, cnt, l, r, mid: longint;
    fin, fout: text;

procedure push(u, v: longint);
var temp: dslk;
begin
    new(temp);
    temp^.u:=v;
    temp^.next:=ds[u];
    ds[u]:=temp;
end;

function gcd(x, y: longint): longint;
var r: longint;
begin
    if x*y=0 then begin
        gcd:=(x+y);
        exit;
    end;

    while x mod y <> 0 do begin
        r:= x mod y;
        x:=y;
        y:=r;
    end;
    gcd:=y;
end;

procedure attemp(u: longint);
var temp: dslk;
begin
    temp:=ds[u];
    while temp<>nil do begin
        if d[temp^.u] = -1 then begin
            d[temp^.u]:=(d[u] + 1);
            attemp(temp^.u);
        end
        else res:=gcd(res, abs(d[temp^.u] - 1 - d[u]));
        temp:=temp^.next;
    end;
end;

begin
    assign(fin, nfin); reset(fin);
    assign(fout, nfout); rewrite(fout);
        readln(fin, n, m);
        for i:=1 to n do ds[i]:=nil;
        for i:=1 to m do begin
            readln(fin, u, v);
            push(u, v);
        end;

        if res=0 then halt;
        res:=0;
        fillchar(d, sizeof(d), 255);
        d[1]:=0;
        attemp(1);
        cnt:=0;
        for i:=1 to n do if (d[i]>-1) and ((d[i] mod res)=0) then inc(cnt);
        writeln(fout, res);
        writeln(fout, cnt);
        for i:=1 to n do if (d[i]>-1) and ((d[i] mod res)=0) then write(fout, i,' ');
    close(fout);
    close(fin);
end.

const
    nfin=   '';
    nfout=  '';
    maxn=   100010;

type
    dslk = ^pointer;
    pointer= record
        u: longint;
        next: dslk;
    end;

var
    ds:     array[0..maxn] of dslk;
    d:      array[0..maxn] of longint;
    n, m:   longint;
    i, j, u, v, res, cnt, l, r, mid: longint;
    fin, fout: text;

procedure push(u, v: longint);
var temp: dslk;
begin
    new(temp);
    temp^.u:=v;
    temp^.next:=ds[u];
    ds[u]:=temp;
end;

function attemp(u, t: longint): boolean;
var temp: dslk;
begin
    temp:=ds[u];
    while temp<>nil do begin
        if d[temp^.u] = -1 then begin
            d[temp^.u]:=(d[u] + 1) mod t;
            if attemp(temp^.u, t) = false then begin
                attemp:=false;
                exit;
            end;
        end
        else if d[temp^.u] <> (d[u] + 1 ) mod t then begin
                attemp:=false;
                exit;
            end;

        temp:=temp^.next;
    end;

    attemp:=true;
end;

function check(t: longint): boolean;
begin
    fillchar(d, sizeof(d), 255);
    d[1]:=0;
    check:=attemp(1, t);
end;

begin
    assign(fin, nfin); reset(fin);
    assign(fout, nfout); rewrite(fout);
        readln(fin, n, m);
        for i:=1 to n do ds[i]:=nil;
        for i:=1 to m do begin
            readln(fin, u, v);
            push(u, v);
        end;

        l:=1; r:=n;
        while l<=r do begin
            mid:=(l+r) shr 1;
            if check(mid) then begin
                l:=mid+1; res:=mid;
            end else r:=mid-1;
        end;

        check(res);
        for i:=1 to n do if d[i] mod res=0 then inc(cnt);
        writeln(fout, res);
        writeln(fout, cnt);
        for i:=1 to n do if d[i] mod res=0 then write(fout, i,' ');
    close(fout);
    close(fin);
end.

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
var
  n,m,i,j,aa,bb,e,t,k: longint;
  v,last,pred,was,ss,ff,x,y: array [0..400010] of longint;
  dist: array [0..400010,0..2] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  read(n,m);
  fillchar(last,sizeof(last),0);
  for i:=1 to m do
  begin
    read(ss[i],ff[i]);
    pred[i]:=last[ss[i]];
    last[ss[i]]:=i;
  end;
  fillchar(was,sizeof(was),0);
  fillchar(dist,sizeof(dist),0);
  i:=1; e:=1;
  x[1]:=1;
  y[1]:=1;
  was[1]:=1;
  dist[1,1]:=0;
  while i <= e do
  begin
    j:=last[x[i]];
    while j > 0 do
    begin
      if (was[ff[j]] < 2) and (dist[x[i],y[i]]+1 <> dist[ff[j],was[ff[j]]]) then
      begin
        inc(e);
        x[e]:=ff[j];
        inc(was[x[e]]);
        y[e]:=was[x[e]];
        dist[x[e],y[e]]:=dist[x[i],y[i]]+1;
      end;
      j:=pred[j];
    end;
    inc(i);
  end;
  t:=0;
  for i:=1 to n do
    if was[i] = 2 then
    begin
      aa:=t; bb:=dist[i,2]-dist[i,1];
      while (aa > 0) and (bb > 0) do
        if aa > bb then aa:=aa mod bb
        else bb:=bb mod aa;
      t:=aa+bb;
    end;
  k:=0;
  for i:=1 to n do
    if (was[i] > 0) and (dist[i,1] mod t = 0) then
    begin
      inc(k);
      v[k]:=i;
    end;
  writeln(t);
  writeln(k);
  for i:=1 to k-1 do write(v[i],' ');
  writeln(v[k]);
  close(input);
  close(output);
end.


From beginning till end, this message has been waiting to be conveyed.For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:  Remove any two elements s and t from the set, and add their concatenation s + t to the set. The cost of such operation is defined to be , where f(s, c) denotes the number of times character c appears in string s.Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.

The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.

Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string. Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.

NoteFor the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:  {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;  {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;  {"abab", "a", "b", "a", "b"}, with a cost of 1;  {"abab", "ab", "a", "b"}, with a cost of 0;  {"abab", "aba", "b"}, with a cost of 1;  {"abab", "abab"}, with a cost of 1;  {"abababab"}, with a cost of 8. The total cost is 12, and it can be proved to be the minimum cost of the process.

var
  s:ansistring;
  k,d,c:longint;
  i:char;
begin
  read(k);
  for i:='a' to 'z' do
    begin
      d:=0;
      c:=0;
      while d+c<=k do
        begin
          write(i);
          d:=d+c;
          inc(c);
        end;
      k:=k-d;
    end;
end.

var n,i,cnt,j:longint ;
begin
   readln(n) ;
	 for i:=0 to 25 do
	 begin
		 cnt:=1 ;
		 while cnt*(cnt+1) div 2<=n do inc(cnt) ;
		 n:=n-cnt*(cnt-1) div 2 ;
		 for j:=0 to cnt-1 do write(chr(97+i)) ;
	 end;
end.

   const nn=1600000; nnn=1200000;eps=0.00000000001;
   besk=80000000000000;
   label 1,2,3;
    var    k,step, i,j:longint;
    pp,jj,ii,p3,p4, p1,p2,t1,t2,p,ost,q,n,ot,t,kk:int64;
     pal:array[-20..6000,-20..6000] of boolean;
     ppp:extended;
      dd,zz,z,c,d,x,y,a,b:array[-1002..2000000] of int64;
      ddnew,ddold:array[0..200,0..4040] of integer;
     per,dda,ddb:array[-10..120,-10..120] of int64;
        ss:string;
            ch:char;
           flagg,flag,flag1:boolean;

  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;

function ff(p:int64):int64;
var t1,t2:int64;
begin  if p=1 then ff:=0 else if p=2 then ff:=1 else
  begin
    t1:=ff(p shr 1);
    t2:=ff(p-(p shr 1));
    ff:=t1*t2+t1+t2;

  end;

end;

begin
  {     assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
   }

    read(n);
    if n=0 then begin writeln('a'); goto 1; end;
      for i:=1 to 500 do a[i]:=a[i-1]+i;
      d[0]:=0;
      d[1]:=0;
      d[2]:=1;
      for i:=3 to 100000 do
        begin
           t1:=i shr 1;
           t2:=i-t1;
           d[i]:=d[t1]+d[t2]+t1*t2;

        end;

    {  for i:=1 to 100 do writeln(i,' ',d[i],' ',a[i]);
      writeln('-------------');
     }
      for i:=1 to 300000 do dd[i]:=besk;
      for i:=0 to 500 do for j:=0 to 100000 do
     begin
      dd[j+a[i]]:=min(dd[j+a[i]],dd[j]+1);
      if dd[j+a[i]]=dd[j]+1 then begin x[j+a[i]]:=i;  end;
     end;

     for i:=1 to 200000 do ot:=max(ot,dd[i]);
    { writeln('ot= ',ot);
     }

       pp:=n;   t:=0;
       while (pp>0)and(t<20) do begin inc(t); z[t]:=x[pp]; pp:=pp-a[z[t]];  end;

     {  writeln('t= ',t);
       for i:=1 to t do write(z[i],' ');
      }
       for i:=1 to t do
         begin
           ch:=chr(i-1+ord('a'));
           for j:=0 to z[i] do write(ch);

         end;

   1:          close(output);
end.

var s:ansistring;
    n:longint;
procedure process;
var d,c:longint;
    i:char;
begin
    s:='';
    for i:='a' to 'z' do
    begin
        d:=0;c:=0;
        while (d+c<=n) do
        begin
            s:=s+i;
            d:=d+c;
            inc(c);
        end;
        n:=n-d;
    end;
    write(s);
end;
begin
    read(n);
    process;
end.

program mfs;
var
k,cnt,i,j:longint;
now:char;
begin
readln(k);
now:='a';
for i:=0 to 25 do
begin
cnt:=0;
while ((cnt+1)*(cnt+2))div 2<=k do inc(cnt);
k:=k-(((cnt+1)*cnt) div 2);
for j:=0 to cnt do write(chr(ord(now)+i));
if k=0 then halt;
end;
end.

var n,i,j:longint;
a:array[0..100001] of longint;
begin
//assign(input,'cydy.in');reset(input);
//assign(output,'cydy.out');rewrite(output);
readln(n);
for i:=1 to 600 do a[i]:=a[i-1]+i-1;
for i:=1 to 26 do
   begin
   for j:=600 downto 1 do
      if n>=a[j] then
        begin
        n:=n-a[j];
        break;
        end;
   for j:=j downto 1 do write(chr(i+96));
   if n=0 then break;
   end;
close(input);close(output);
end.

var f1,f2 : text;
      ch:char;
      s:ansistring;
      d,k:longint;

begin
assign(f1,'');reset(f1);
assign(f2,'');rewrite(f2);
readln(f1,k);
for ch := 'a' to'z' do
        s:=s+ch;
for ch := 'a' to 'z' do
        if k > 0 then
                begin
                d := 0;
                while (k > 0) do
                        begin
                        inc(d);
                        if (k-d>=0) then
                                begin
                                k:=k-d;
                                s:=s+ch;
                                end
                           else break;
                        end;
                end;
write(f2,s);
close(F1);
close(F2);
end.

var k,i,j,a,b,c:longint;
	t:array[-5..10000]of longint;
begin
	readln(k);j:=0;a:=96;
	if k=0 then begin write('a');exit;end;
	for i:=1 to 10000 do begin
		inc(j,i);t[i]:=j;
	end;
	for i:=10000 downto 1 do
		while k>=t[i] do begin
			dec(k,t[i]);
			inc(a);
			for j:=0 to i do write(chr(a));
		end;
end.

var
  i,j,k,n:longint;
  a:array[0..1000] of longint;
  c:char;
begin
  read(n);
  for i:=2 to 1000 do a[i]:=a[i-1]+i-1;
  for c:='a' to 'z' do
  begin
    for j:=1000 downto 1 do
    if n>=a[j] then
    begin
      n:=n-a[j];
      for k:=1 to j do write(c);
      break;
    end;
    if n=0 then break;
  end;
end.

var
s:ansistring;
x,i,n,j:longint;
begin
    readln(n);
    x:=97;
    if n=0 then writeln('a') else begin
    s:='a';
    while(n>0) do begin
       i:=(-1+trunc(sqrt(1+8*n))) div 2;
       for j:=1 to i do s:=s+chr(x);
       x:=x+1;
       n:=n-((i*(i+1))div 2);
       if n>0 then s:=s+chr(x);
    end;
    end;
    writeln(s);
end.

{$H+}
var
  k,j,c:longint;
  i:char;
begin
  readln(k);
  for i:='a' to 'z' do
    begin
      c:=trunc(sqrt(k*2));
      for j:=1 to c do write(i);
      k:=k-c*(c-1) div 2;
    end;
end.

var k,i,j,a,b,c:longint;
	t:array[-5..10000]of longint;
begin
	readln(k);j:=0;a:=96;
	for i:=1 to 10000 do begin
		inc(j,i);t[i]:=j;
	end;
	for i:=10000 downto 1 do
		while k>=t[i] do begin
			dec(k,t[i]);
			inc(a);
			for j:=0 to i do write(chr(a));
		end;
        if k=0 then write('a');
end.

var
  i,j,k,n:longint;
  a:array[0..1000] of longint;
  c:char;
begin
  read(n);
  for i:=2 to 1000 do a[i]:=a[i-1]+i-1;
  for c:='a' to 'z' do
  begin
    for j:=1000 downto 2 do
    if n>=a[j] then
    begin
      n:=n-a[j];
      for k:=1 to j do write(c);
      break;
    end;
    if n=0 then break;
  end;
end.

var
s:ansistring;
x,i,n,j:longint;
begin
    readln(n);
    x:=97;
    if n=0 then writeln('a') else begin
    s:='';
    while(n>0) do begin
       i:=(-1+trunc(sqrt(1+8*n))) div 2;
       for j:=1 to i do s:=s+chr(x);
       x:=x+1;
       n:=n-((i*(i+1))div 2);
       if n>0 then s:=s+chr(x);
    end;
    end;
    writeln(s);
end.