const e:array[0..9] of char=('R','G','B','Y','W','1','2','3','4','5');
var a:array[0..9] of longint;
f:array['A'..'Z','1'..'5'] of boolean;
i,n,s,t,max:longint;c,c1,c2:char;
function pd(x:longint):boolean;
var i,j,t:longint;
begin
t:=0;fillchar(a,sizeof(a),0);
for i:=0 to 4 do
  for j:=5 to 9 do
    if f[e[i],e[j]] then
      begin
      if (x and (1 shl i)>0) and (x and (1 shl j)=0) then a[i]:=a[i]+1;
      if (x and (1 shl i)=0) and (x and (1 shl j)>0) then a[j]:=a[j]+1;
      if (x and (1 shl i)=0) and (x and (1 shl j)=0) then t:=t+1;
      end;
if t>1 then exit(false);
for i:=0 to 9 do
  if a[i]>1 then
    exit(false);
exit(true);
end;
begin
//assign(input,'hanabi.in');reset(input);
//assign(output,'hanabi.out');rewrite(output);
readln(n);max:=maxlongint;
for i:=1 to n do
  begin
  read(c1,c2);
  f[c1,c2]:=true;
  if i<>n then read(c);
  end;
for i:=0 to 1023 do
  if pd(i) then
    begin
    s:=0;t:=i;
    while t<>0 do
      begin
      s:=s+t mod 2;t:=t div 2;
      end;
    if s<max then max:=s;
    end;
writeln(max);
close(input);close(output);
end.


var

tail,n,i,t,q:longint;
p,x,zhan:array[0..1000000] of longint;

Begin

read(n);

for i:=1 to n do read(p[i]);

read(t);
for i:=1 to t do
begin
read(q);
x[q]:=-p[q];

end;

for i:=n downto 1 do
if (p[i]=zhan[tail])and(x[i]=0)
then begin
     x[i]:=p[i];
     dec(tail);
     end
else begin
     inc(tail);
     zhan[tail]:=p[i];
     x[i]:=-p[i];
     end;

if tail>0
then writeln('NO')
else begin
writeln('YES');
for i:=1 to n-1 do write(x[i],' ');
writeln(x[n]);
     end;
End.


program zzz;

type int = longint;

var s:string; s1:string; max:int; maxs:string; i,k,j:int;
	c:boolean; now:int;

begin
	readln(S);

	maxs:='-1';
	max:=-1;
	for k:=1 to length(s) do
		for j:=1 to length(S)-i+1 do
			begin
				s1:=copy(s,j,k);

				//writeln(s1);

				if s1 = '' then continue;

				c:=false;
				for i:=1 to length(s1) do
					if (s1[i]<>'7') and (s1[i]<>'4') then c:=true;

				if c then continue;

				//writeln(s1);

				now:=0;
				for i:=1 to length(s) do
					if copy(s,i,length(s1)) = s1 then inc(now);

			//	writeln(s1,' ',now,' ',max,' ',maxs);

				if now>max then
					begin
						max:=now;
						maxs:=s1;
					end
				else if now = max then
					if maxs>s1 then begin
						maxs:=s1;
						max:=now;
					end;
			end;

	writeln(maxs);
end.


var n, x, i, kq: longint;
begin
	readln(n, x);
	for i := 1 to n do
		if (x mod i = 0) and (x div i <= n) then
			inc(kq);
	writeln(kq);
end.


var n,m,i,h:longint;

function nod(a,b:longint):longint;
begin
 while (a<>0) and (b<>0) do
  if a>b then a:=a mod b else b:=b mod a;
 nod:=a+b;
end;

function nod2(a,b:longint):longint;
var ans:longint;
begin
if a<b then
 begin
  ans:=a;
  a:=b;
  b:=ans;
 end;
 if b=1 then begin nod2:=a-1; exit; end;
 nod2:=(a-a mod b+b-1) div b + nod2(b,a mod b);
end;

begin
 readln(n);
 m:=n-1;
 for i:= 2 to 1000000 do
  if nod(i,n)=1 then
   begin
    h:=nod2(i,n);
    if h<m then m:=h;
   end;
  writeln(m);
end.


{$MODE OBJFPC}
program onlylove;
var  fi,fo : text;
      n : int64;
procedure enter;
   begin
     {assign(fi,'');
     assing(fo,'');
     reset(fi);
     rewrite(fo); }
     readln(n);
   end;
function ktra(x:int64) : boolean   ;
  var    r : int64;
  begin
    if x = 0 then exit(false);
    while x<> 0 do
      begin
        r := x mod 10 ;
        if (r <> 4) and (r <> 7) then exit(false);
        x := x div 10;
      end;
       exit(true) ;
  end;
function dem(x : int64) : int64;
   var r : int64;
   begin
     result := 0;
       while x <> 0 do
         begin
           r := x mod 10;
           if (r = 4 ) or (r = 7) then inc(result);
           x := x div 10;
         end
   end;
procedure solve;
  begin
    if ktra(dem(n)) then writeln('YES') else writeln('NO');

  end;
procedure inkq;
  begin
    {close(fi);
    close(fo);  }
  end;
begin
  enter;
  solve;
end.


 var
   l, r: integer;

 function foo(l, r: integer): integer;
   function IsCoolNum(N: integer): boolean;
     function Count(c: char; s: string): integer;
     var res: integer;
     begin
       for var i := 1 to s.Length do
         if s[i] = c then res += 1;
       result := res;
     end;
   begin
     var temp := N.ToString;
     for var i := 1 to temp.Length do
       if Count(temp[i], temp) > 1 then
       begin
         result := false;
         exit;
       end;
     result := true;
   end;
 var res: integer := -1;
 begin
   for var i := l to r do
   begin
     if IsCoolNum(i) then
     begin
       res := i;
       break;
     end;
   end;
   result := res;
 end;

 begin
   Readln(l, r);
   Writeln(foo(l, r));
 end.


var n,m,k,a,b:int64;
function horizontal:int64;
  var x,y,t:int64;
  begin
  if k+1<=n then begin x:=n div (k+1); y:=m; end
  else begin x:=1;t:=k-(n-1);y:=m div (t+1); end;
  horizontal:=x*y;
end;
function vertical:int64;
  var x,y,t:int64;
  begin
  if k+1<=m then begin x:=n;y:=m div (k+1); end
  else begin t:=k-(m-1);x:=n div (t+1);y:=1; end;
  vertical:=x*y;
end;
begin
readln(n,m,k);
if (n+m)<(k+2) then begin writeln('-1'); halt; end;
a:=horizontal;
b:=vertical;
if a>b then writeln(a) else writeln(b);
end.


var n,m,i,j,x,y:longint;
    a,l,b,c:array[1..100] of longint;

function tim(x,y:longint):longint;
        begin
        IF x<=y then exit(n-y+x)
        else exit(x-y);
        end;

begin
readln(n,m);
for i:=1 to m do read(l[i]);
for i:=1 to n do c[i]:=i;
for i:=1 to m-1 do
        begin
        IF a[l[i]]<>0 then
                IF a[l[i]]<>tim(l[i+1],l[i]) then
                        begin
                        write(-1);
                        exit;
                        end;
        a[l[i]]:=tim(l[i+1],l[i]);
        end;
for i:=1 to n do inc(b[a[i]]);
x:=0;
for i:=1 to n do
        begin
        IF b[i]>=2 then
                begin
                write(-1);
                exit;
                end;
        IF b[i]=0 then
                begin
                inc(x);
                c[x]:=i;
                end;
        end;
y:=0;
for i:=1 to n do
        IF a[i]=0 then
                begin
                inc(y);
                a[i]:=c[y];
                end;
for i:=1 to n do write(a[i],' ');
end.


var d1,d2,a,k,s,i:int64;

begin read(d1); read(d2);
    if (d2-d1=1) then begin
     write(d1,'99 ',d2,'00'); k:=k+1; end;
    if d2=d1 then begin write(d1, '00 ', d2, '01');  k:=k+1; end;
    if (d2=1) and (d1=9) then begin write(d1,'99 ',d2,'000');  k:=k+1; end;
    if k=0 then write('-1');
end.


var x, y, m, n:Int64;
begin
readln(x, y, m);
if((x >= m) or (y >= m)) then writeln(0)
else begin
    if((x <= 0) and (y <= 0)) then writeln(-1)
    else begin
        if(x < 0) then begin
            n:= abs(x) div y;
            if((abs(x) mod y) > 0) then inc(n, 1);
            x:= x + y * n;
        end else if(y < 0) then begin
            n:= abs(y) div x;
            if((abs(y) mod x) > 0) then inc(n, 1);
            y:= y + x * n;
        end;
        while((x < m) and (y < m)) do begin
            inc(n, 1);
            if(x < y) then x:=x+y
            else y:=x+y;
        end;
        writeln(n);
    end;
end;
end.


                          const eps=1e-10;
                      besk=2002000000000000000; label 1,3,2,44;
                type mas=array[-100..1200000+1] of int64;  int64=longint;
                integer=longint;    zap=record p1,p2,p3:int64; end;
                zap1=^zap;
                var qq,sdvig,start,dl,len,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto,num:longint;
                ss3,ss,ss1,ss2:string;
                qqq:zap;
                kol1,kol2,kart1,kart2,vx,vy,ans,up,down,xmin,xmax,ymin,ymax,imax,t3,qq1,qq2,q1,q2,ost,koll,w,pos,dx,dy,ll,rr,sum,m,finish,time,p3,p4,jj,qqqq,ii,tt,pmax,pmax2,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,n,nn,kk,modul,t0,t1,n1,t2,q,t,p:int64; flag1:boolean;
                  invx,invy,summ,place,kol,str,b2,zz,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
                 zapas,razn,oldll,oldrr,ppp,shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
                  zzan,prost,marked,zan:array[-1000000..1000000] of boolean;
                  left,right,zpl,zmi,path,lx,rx,ly,ry,a2,a3,a4,dd1,dd2,predok,a1,b1,strok:array[-10000..1500000] of int64;
                  ppole:array[-1000000..3000000] of char;
                  stroka:array[-1000..1000000] of char;
                  px,py,h1,h2,h,l1,l2,ot1,otmax,v:extended;
                  ssumitog,profil,zzz:array[-10..2100,-10..2100] of int64;
                  sp,sss:array[-10..2000000] of string;
                  newpole,pole:array[-1..2100,-1..2700] of char;
                  blizpr,dd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..6] of int64;
                  poss:int64;
                  ch:char;
                  ff,flagg1:boolean;
                  numx,numy,xleft,xright,s,znach,z,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-10000..4000002] of int64;
                  ddd:array[-10..5010,-10..5010] of int64;
                 function srav(i,j:longint):boolean; label 44;

                begin
                   if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
                   if a[i]>a[j] then begin  srav:=false; goto 44;   end;
                   if a[i]=a[j] then if a1[i]>a1[j] then srav:=true else srav:=false;

                 44:
                end;

                procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
                begin
                i:=l;j:=m; flag:=true; step:=0;while flag do begin
                if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
                inc(step);inc(i);
                {writeln('step=',step,' i=',i);} end;
                if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
                inc(step);inc(j);end;
                if  ((i>=l+k) or (j>=m+k)) then flag:=false;
                end;
                if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
                if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
                end;
                procedure sort(var c:mas);

                begin

                k:=1; repeat
                l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
                for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
                until (k>=n);

                end;

                function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
                function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;
                function min3(a,b,c:int64):int64;  var ot:int64;
                begin ot:=a; if b<ot then ot:=b; if c<ot then ot:=c;  min3:=ot;  end;

      function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
  tt:zap; tt1:zap1;  fl:boolean;
begin
  fl:=false;
  if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
  x2:=1;x1:=0;y2:=0;y1:=1;
  while b>0 do
    begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
          a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
    end;
    if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
         begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
   evkl:=tt1;
end;

                function phi(a,b:double):double; label 222;var p:double;
                begin
                  if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
                  if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
                  if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
                  if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
                  if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
                  222: phi:=p;
                end;

                function nod(a,b:int64):int64; var p,t:int64;
                begin
                  a:=abs(a); b:=abs(b);
                  if (a>0)and(b>0) then
                   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                    p:=a;
                   end else if a=0 then p:=b else p:=a;
                nod:=p;
                end;

                function nok(a,b:int64):int64;
                begin  nok:=(a*b) div nod(a,b);  end;

                   function degg(a:int64;k:int64):int64; var p:int64;
                begin
                 if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
                   begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

                end;

                function zaprmax(left,right:longint):int64;
            begin
               if left>=right then zaprmax:=y[left] else
                 begin
                    if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
                     begin
                      if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
                      if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

                     end;

                 end;

            end;

                procedure udal(ii:longint);
                begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

                function nomerr(gr:int64):int64;

                var ot,aa,bb,cc:int64; fl:boolean;
                begin
                  aa:=1; bb:=p;  cc:=aa; fl:=false;
                  while abs(aa-bb)>1 do
                    begin
                       cc:=(aa+bb) shr 1;
                     {  writeln('cc=++ ',cc);
                     }  if y[cc]<gr then aa:=cc else bb:=cc;

                    end;
                  { writeln(' cc= ',cc);
                  } cc:=max(cc-3,0);
                   repeat inc(cc) until y[cc]>=gr;
                   if y[cc]=gr then fl:=true else fl:=false;
                   { if fl then nomerr:=a1[cc] else nomerr:=-1000;}
                   nomerr:=cc;
                end;

                function pprost(pp:longint):boolean;
                var i,j,t:longint; tt:extended; fl:boolean;
                begin
                  tt:=pp;
                  tt:=sqrt(tt);
                  fl:=true;
                  for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

                 pprost:=fl;

                end;

                function gl(c:char):boolean;
                begin
                 if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;

                end;

function goodpoint(xx,yy:extended):boolean;
var fl1,fl2,fl3:boolean;
begin
  fl1:=(xx>=x[invx[1]])and(xx<=x[invx[2]])and(yy>=y[invy[1]])and(yy<=y[invy[2]]);
  fl2:=(xx>=x[invx[3]])and(xx<=x[invx[4]])and(yy>=y[invy[3]])and(yy<=y[invy[4]]);
  fl3:=(xx>=x[invx[5]])and(xx<=x[invx[6]])and(yy>=y[invy[5]])and(yy<=y[invy[6]]);
  goodpoint:=fl1 and not fl2 and not fl3;
end;

 begin

    {assign (input,'D:\Projects\input.txt');reset(input);
      assign (output,'D:\Projects\output.txt'); rewrite(output);
     }

      for i:=1 to 6 do read(x[i],y[i]);
      for i:=1 to 6 do begin numx[i]:=i; numy[i]:=i;  end;
      for i:=1 to 6 do for j:=1 to 5 do if x[j]>x[j+1] then
        begin
          t:=x[j]; x[j]:=x[j+1]; x[j+1]:=t;
          t:=numx[j]; numx[j]:=numx[j+1]; numx[j+1]:=t;
       end;

      for i:=1 to 6 do for j:=1 to 5 do if y[j]>y[j+1] then
        begin
          t:=y[j]; y[j]:=y[j+1]; y[j+1]:=t;
          t:=numy[j]; numy[j]:=numy[j+1]; numy[j+1]:=t;
       end;

     for i:=1 to 6 do begin invx[numx[i]]:=i; invy[numy[i]]:=i;  end;

    for i:=1 to 6 do for j:=1 to 6 do
      begin
          for ii:=-1 to 1 do for jj:=-1 to 1 do
            begin
               px:=x[i]+0.5*ii;py:=y[j]+0.5*jj;
               if goodpoint(px,py) then begin writeln('YES'); goto 1;  end;

            end;

      end;
      writeln('NO');

      1: close (output);
    end.


var
	n, c1, c2 : Int64;
	s : AnsiString;

	j, k, a, b, c, d, e, f, val, opt : Int64;
	i, g : Longint;

begin
	Readln(n, c1, c2);
	Readln(s);

	a := 0;
	b := 0;

	for i := 1 to n do begin
		if s[i] = '1'
		then
			inc(a)
		else
			inc(b);
	end;

	opt := -1;

	for g := 1 to a do begin
		c := n div g; // c je manja velicina grupe
		e := n mod g; // e je broj nabudzenih grupa

		d := g - e; // d je broj manjih grupa

		val := d * (c1 + c2 * (c - 1) * (c - 1));
		val := val + e * (c1 + c2 * c * c);

		if (opt = -1) or (val < opt) then
			opt := val;
	end;

	Writeln(opt);
end.


var x,y,z:int64;
begin
readln(x,y,z);
writeln((x*z+x*y+z*y)*4/round(sqrt(x*y*z)):0:0);
end.


var
        n,i,p,minn:longint;
        k1,k2,j,ans,x,y,maxn,x1,x2,z3:int64;
        o,d1,d2:array[1..2,1..2]of int64;
        a:array[1..1000000]of int64;
function max(x,y:int64):int64;
begin
        if x>y then exit(x) else exit(y);
end;
function min(x,y:int64):int64;
begin
        if x<y then exit(x) else exit(y);
end;
procedure qs(x:int64);
var
        i,j,k:longint;
begin
        if x=1 then begin
                d1:=o;
                z3:=3;
                exit;
        end;
        qs(x shr 1);
        z3:=z3*z3 mod p;
        fillchar(d2,sizeof(d2),0);
        for i:=1 to 2 do begin
                for j:=1 to 2 do begin
                        for k:=1 to 2 do begin
                                d2[i,j]:=(d1[i,k]*d1[k,j]+d2[i,j])mod p;
                        end;
                end;
        end;
        d1:=d2;
        if x and 1=1 then begin
        fillchar(d2,sizeof(d2),0);
        for i:=1 to 2 do begin
                for j:=1 to 2 do begin
                        for k:=1 to 2 do begin
                                d2[i,j]:=(d1[i,k]*o[k,j]+d2[i,j])mod p;
                        end;
                end;
        end;
        d1:=d2;
        z3:=z3*3 mod p;
        end;
end;
begin
        maxn:=0;
        ans:=0;
        minn:=maxlongint;
        readln(n,x,y,p);
        for i:=1 to n do begin
                read(j);
                a[i]:=j;
                ans:=ans+j;
                if i=1 then k1:=j;
                if i=n then k2:=j;
                minn:=min(minn,j);
                maxn:=max(maxn,j);
        end;
        if x>0 then begin
        z3:=1;
        o[1,1]:=0; o[1,2]:=1; o[2,1]:=1; o[2,2]:=1;
        qs(x);
        x1:=d1[1,2];
        x2:=d1[2,2];
        if x1<0 then begin
        x1:=x1+p; x2:=x2+p;
        end;
        if x2<x1 then x2:=x2+p;
        maxn:=max(maxn,a[n-1]*x1+a[n]*x2);
        maxn:=maxn mod p;
        o[1,1]:=3; o[1,2]:=0; o[2,1]:=-1; o[2,2]:=1;
        qs(x);
        ans:=ans mod p;
        ans:=(ans*d1[1,1] mod p+(a[1]+a[n])*d1[2,1] mod p)mod p;
        end;
        if y>0 then begin
        o[1,1]:=3; o[1,2]:=0; o[2,1]:=-1; o[2,2]:=1;
        qs(y);
        if z3 and 1=0 then z3:=z3+p;
//        ans:=trunc(z3*(ans-(minn+maxn)/2)+(minn+maxn)/2) mod p;
        ans:=ans*d1[1,1] mod p+(maxn+minn)*d1[2,1] mod p;
        end;
        writeln((ans mod p+p)mod p);
end.


program z_630_j;
var n,q:int64;
begin
readln(n);
q:=n div 2520;
writeln(q);
end.


var n,m,i,p,t,r,l:int64;data:boolean;
function sum(x,y:int64):int64;
begin
if x>=y then
sum:=(x+y)*(x-y+1) div 2
else sum:=0;
end;
function Q(i:int64):BOOLEAN;
VAR X,K,Y:INT64;
BEGIN
x:=i-2;
k:=i;
y:=n-p;
if y=0 then inc(k,0)
else if y<x then inc(k,sum(i-1,i-y))
else inc(k,sum(i-1,2));
if y>x then inc(k,y-x);

y:=p-1;
if y=0 then inc(k,0)
else if y<x then inc(k,sum(i-1,i-y))
else inc(k,sum(i-1,2));
if y>x then inc(k,y-x);
if k>m then Q:=FALSe
else q:=true;
END;
begin
readln(n,m,p);
i:=1;
L:=1;R:=m;
while ( true) do begin
if l>=R then begin
           t:=L;
           if t=1 then writeln(1) else
           if (Q(t+1)=true) then
           writeln(t+1)
           else if (Q(t)=true) then
           writeln(t)
           else writeln(t-1);
           break
           end
           else
t:=(R+L)div 2;
IF not (q(t)) then  r:=t-1
                   else l:=t+1;
end;
end.


{$R+ Q+ I+}
{$apptype console}
uses
    sysutils,math;
var
   s : string;
begin
    read(s);
    s[1] := upcase(s[1]);
    write(s);
end.


var
a,b:longint;
s1,s2,s3,v1,v2,v3:longint;
begin
readln (a,b);
if a=b then
    writeln (0)
else
    begin
        s1:=0; s2:=0; s3:=0;
        v1:=0; v2:=0; v3:=0;
        while a mod 2=0 do
            begin
                inc (s1);
                a:=a div 2;
            end;
        while a mod 3=0 do
            begin
               inc (s2);
               a:=a div 3;
            end;
        while a mod 5=0 do
            begin
                inc (s3);
                a:=a div 5;
            end;
        while b mod 2=0 do
            begin
                inc (v1);
                b:=b div 2;
            end;
        while b mod 3=0 do
            begin
               inc (v2);
               b:=b div 3;
            end;
        while b mod 5=0 do
            begin
                inc (v3);
                b:=b div 5;
            end;
        if a<>b then
            writeln (-1)
        else
            writeln (abs(s1-v1)+abs (s2-v2)+abs (s3-v3));
    end;
end.


program cf119e;
const
  eps=1e-8;
type
  dot=record
    x,y:double;
  end;
  dott=record
    x,y,z:double;
  end;
var
  n,i,hhh,j,m,p1,p2:longint;
  vt,vt2,vv:array[0..1000]of dott;
  tt:dott;
  v:array[0..1000]of dot;
  ot,oo,rt:dot;
  ll:array[0..1000]of double;
  a,b,c,aa,bb,cc,a1,b1,rr,c1,co,si:double;
function dis(a,b:dot):double;
begin
  dis:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
end;

function chaji(a,b,c,d:dot):double;
begin
  chaji:=(b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y);
end;

function jiao_dian(a,b,c,d:dot):dot;
var s1,s2:double;
begin
  s1:=chaji(a,c,a,b);
  s2:=chaji(a,b,a,d);
  jiao_dian.x:=(c.x*s2+d.x*s1)/(s1+s2);
  jiao_dian.y:=(c.y*s2+d.y*s1)/(s1+s2);
end;

procedure make_tri(a,b,c:dot);
var
  aa,bb,cc:double;
  e,d,f,g:dot;
begin
  f.x:=(a.x+b.x)/2;
  f.y:=(a.y+b.y)/2;
  d.x:=f.x-(b.y-a.y);
  d.y:=f.y+(b.x-a.x);

  g.x:=(c.x+b.x)/2;
  g.y:=(c.y+b.y)/2;
  e.x:=g.x-(c.y-b.y);
  e.y:=g.y+(c.x-b.x);

  oo:=jiao_dian(f,d,e,g);
  rr:=dis(oo,a);

end;

procedure zuixiaoyuanfugai;
var
  di:double;
  k,i,j,u:longint;
begin
  oo.x:=0;oo.y:=0;
  rr:=0;
  for i:=1 to n do
    if dis(v[i],oo)>rr+eps then begin
      oo:=v[i];
      rr:=0;
      for j:=1 to i-1 do
        if dis(v[j],oo)>rr+eps then begin
          oo.x:=(v[i].x+v[j].x)/2;
          oo.y:=(v[i].y+v[j].y)/2;
          rr:=dis(oo,v[i]);
          for k:=1 to j-1 do
            if dis(oo,v[k])>rr+eps then begin
              make_tri(v[i],v[j],v[k]);
            end;
        end;
    end;
  writeln(rr:0:18);

end;

procedure work;
var i,j,k:longint;
  d1,dd,d2:double;
begin
  d1:=sqrt(a*a+b*b+c*c);
//  d1:=1;
  for i:=1 to n do begin
    dd:=vt[i].x*a+vt[i].y*b+vt[i].z*c;
    dd:=dd/(sqrt(a*a+b*b+c*c));
    aa:=a*(dd/d1);bb:=b*(dd/d1);cc:=c*(dd/d1);

    vt[i].x:=vt[i].x-aa;
    vt[i].y:=vt[i].y-bb;
    vt[i].z:=vt[i].z-cc;
  end;

//--------------------------------------------

  if (abs(b)<eps)and(abs(c)<eps) then begin
    for i:=1 to n do begin
      v[i].x:=vt[i].y;
      v[i].y:=vt[i].z;
    end;
  end else begin
    d1:=sqrt(c*c+b*b);

    for i:=1 to n do
    if (abs(vt[i].x)<eps)and(abs(vt[i].y)<eps)and(abs(vt[i].z)<eps) then
    begin
      v[i].x:=0;v[i].y:=0;
    end else begin
      dd:=sqrt(sqr(vt[i].x)+sqr(vt[i].y)+sqr(vt[i].z));
      d2:=sqrt(sqr(vt[i].x)+sqr(vt[i].y+c)+sqr(vt[i].z-b));
      co:=(dd*dd+d1*d1-d2*d2)/(2*dd*d1);
      si:=1-co*co;
      if abs(si)<eps then si:=0
      else si:=sqrt(si);
      if vt[i].x<0 then si:=-si;
      v[i].x:=dd*co;
      v[i].y:=dd*si;
    end;
  end;

  zuixiaoyuanfugai;

end;

begin
  randomize;
  readln(n,m);
  for i:=1 to n do begin
    readln(vv[i].x,vv[i].y,vv[i].z);
  end;

  for i:=1 to 2*n do begin
    p1:=random(n)+1;p2:=random(n)+1;
    tt:=vv[p1];vv[p1]:=vv[p2];vv[p2]:=tt;
  end;

  for hhh:=1 to m do begin
  for i:=1 to 2*n do begin
    p1:=random(n)+1;p2:=random(n)+1;
    tt:=vv[p1];vv[p1]:=vv[p2];vv[p2]:=tt;
  end;
    for i:=1 to n do vt[i]:=vv[i];
    readln(a,b,c);
    work;
  end;
end.


program NumA;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a: array[1..26] of boolean;
  b: array[0..100] of integer;
  s: string;
  n,k,i,j: integer;
begin
  n := 0;
  readln(k);
  readln(s);
  for i := 1 to length(s) do
    if not a[ord(s[i])-96] then begin
      inc(n);
      a[ord(s[i])-96] := true;
      b[n] := i;
    end;
  if n < k then writeln('NO')
  else begin
    writeln('YES');
    for j := 1 to k-1 do
      writeln(copy(s,b[j],b[j+1]-b[j]));
    writeln(copy(s,b[k],length(s)-b[k]+1));
  end;
  readln;
end.


uses math;
var
  map:array[0..400000,-1..1,-1..1]of boolean;
  n,m,x,y,dx,dy,t,k:longint;
  ans,kk:qword;
  str:string;
begin
  readln(n,m);
  read(x,y);
  readln(str);
    if str[2]='D' then dx:=1
      else dx:=-1;
    if str[3]='R' then dy:=1
      else dy:=-1;
  repeat
    if (x=1)and(y<m) then t:=y;
    if (x<n)and(y=m) then t:=m+x-1;
    if (x=n)and(y>1) then t:=m+n+y-3;
    if (x>1)and(y=1) then t:=2*m+n+x-4;
    if map[t,dx,dy] then break;
    if not map[t,0,0] then inc(kk);
    if kk=n+m-2 then break;
    map[t,dx,dy]:=true;
    map[t,0,0]:=true;
    k:=maxlongint;
    if dx=1 then k:=min(k,n-x)
      else k:=min(k,x-1);
    if dy=1 then k:=min(k,m-y)
      else k:=min(k,y-1);
    ans:=ans+k;
    x:=x+k*dx;
    y:=y+k*dy;
    if (y*dy=m)or(y*dy=-1) then dy:=dy*(-1);
    if (x*dx=n)or(x*dx=-1) then dx:=dx*(-1);
  until 1=0;
  if kk=n+m-2 then writeln(ans+1)
    else writeln(-1);
end.


var a1,a2,a3,b1,b2,b3,n:int64;
function min(x,y:longint):longint;
begin
  if x<y then exit(x);
  exit(y);
end;
function max(x,y:longint):longint;
begin
  if x>y then exit(x);
  exit(y);
end;
begin
  readln(n);
  readln(a1,a2,a3);
  readln(b1,b2,b3);
  write(max(0,a1-b1-b3)+max(0,a2-b2-b1)+max(0,a3-b3-b2),' ');
  writeln(min(a1,b2)+min(a2,b3)+min(a3,b1));
end.


const
        fi='';
        fo='';
        maxn=2000100;
        maxc=1000000000;
type
        re=record
                x:int64;
                y:longint;
        end;
var
        f:array[1..2,0..maxn] of re;
        a:array[1..30] of longint;
        gt:array[0..20] of int64;
        last:array[1..2] of longint;
        sum,s:int64;
        dem:longint;
        n,k,first,lastt,cs,last1,last2:longint;
        luu:array[1..2,0..maxn] of re;
        res:int64;
{-------------------------}
procedure openfiles;
begin
        assign(input,fi);
        reset(input);
        assign(output,fo);
        rewrite(output);
end;
{------------------------}
procedure closefiles;
begin
        close(input);
        close(output);
end;
{-------------------------}
procedure nhap;
var
        i:longint;
begin
        readln(n,k,s);
        for i:=1 to n do read(a[i]);
end;
{-------------------------}
function min(a,b:longint):longint;
begin
        if a>b then exit(b) else exit(a);
end;
{-------------------------}
function max(a,b:longint):longint;
begin
        if a>b then exit(a) else exit(b);
end;
{-------------------------}
procedure init;
var
        i:longint;
begin
        gt[0]:=1;
        for i:=1 to 19 do gt[i]:=gt[i-1]*i;
end;
{-------------------------}
procedure choose(x:longint);
var
        i:longint;
begin
        for i:=0 to 2 do
        begin
                if i=1 then
                begin
                        sum:=sum+a[first+x];
                        if x=lastt then
                        begin
                                inc(last[cs]);
                                f[cs,last[cs]].x:=sum;
                                f[cs,last[cs]].y:=dem;
                        end
                        else
                        if x< lastt then
                        choose(x+1);
                        sum:=sum-a[first+x];
                end
                else
                if i=2 then
                begin
                        if a[first+x] >= 19 then exit;
                        if (dem>k) or (sum+gt[a[first+x]] >s) then exit;
                        sum:=sum+gt[a[first+x]];
                        dem:=dem+1;
                        if x=lastt then
                        begin
                                inc(last[cs]);
                                f[cs,last[cs]].x:=sum;
                                f[cs,last[cs]].y:=dem;
                        end
                        else
                        if x<lastt then
                        choose(x+1);
                        sum:=sum-gt[a[first+x]];
                        dec(dem);
                end
                else
                if i=0 then
                begin
                        if x=lastt then
                        begin
                                inc(last[cs]);
                                f[cs,last[cs]].x:=sum;
                                f[cs,last[cs]].y:=dem;
                        end
                        else
                        if x<lastt then
                        choose(x+1);
                end;
        end;
end;
{-------------------------}
procedure sort(cs,l,h:longint);
var
        i,j,tg,y:longint;
        x:int64;
        tmp:re;
begin
        i:=l; j:=h;
        tg:=random(h-l+1)+l;
        x:=f[cs,tg].x; y:=f[cs,tg].y;
        repeat
                while (f[cs,i].x<x) or ((f[cs,i].x=x) and (f[cs,i].y<y)) do inc(i);
                while (f[cs,j].x>x) or ((f[cs,j].x=x) and (f[cs,j].y>y)) do dec(j);
                if i<=j then
                begin
                        tmp:=f[cs,i];
                        f[cs,i]:=f[cs,j];
                        f[cs,j]:=tmp;
                        inc(i); dec(j);
                end;
        until i>j;
        if l<j then sort(cs,l,j);
        if i<h then sort(cs,i,h);
end;
{-------------------------}
function search(c:longint;y:int64):longint;
var
        d,mid:longint;
begin
        d:=1;
        while d<=c do
        begin
                mid:=(d+c) div 2;
                if (f[2,mid].x+y<s) then d:=mid+1 else c:=mid-1;
        end;
        exit(d);
end;
{-------------------------}
procedure xuly;
var
        i,d,c,tmp:longint;
begin
        cs:=1; first:=0; lastt:=n div 2;
        sum:=0; dem:=0;
        choose(1);
        sort(1,1,last[1]);
        sum:=0;   dem:=0;
        cs:=2; first:=n div 2; lastt:=n - n div 2;
        choose(1);
        sort(2,1,last[2]);

        c:=last[2];
        for i:=min(last[1],1) to last[1] do
        begin
                while (c>=1) and (f[1,i].x+f[2,c].x >s) do dec(c);
                while (c>=1) and (f[1,i].x+f[2,c].x=s) and (f[1,i].y+f[2,c].y >k) do dec(c);
                begin
                        tmp:=search(c,f[1,i].x);
                        res:=res+max(0,c-tmp+1);
                end;
                if c=0 then break;
        end;
        writeln(res);

end;
{-------------------------}
BEGIN
        openfiles;
        init;
        nhap;
        xuly;
        closefiles;
END.


var
dp:array[ -1000..1000, -1000..1000 ] of longint;
i,j,x,y,d,n,dist,k:longint;
a, b:array[1..1000] of longint;
good:boolean;
begin
 {
assign(input, 'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
  }
readln(x, y, n, d);
//writeln(x,' ', y,' ', n, ' ', d);

for i:=1 to n do
readln(a[i], b[i]);
{
for dist:=d + 1 to 500 do
        for i:=-dist to dist do
                begin
                j:=dist - abs(i);
                dp[i][j]:=1;
                j:=-(dist - abs(i));
                dp[i][j]:=1;
                end;
 }

 for i:=-900 to 900 do
 for j:=-900 to 900 do
 //if (abs(i) + abs(j) > d) then dp[i][j]:=-1 else dp[i][j]:=1;
 if (i * i + j*j > d*d) then dp[i][j]:=1 else dp[i][j]:=0;

 for i:=400 downto -400 do
 for j:=400 downto -400 do
        begin
          good:=false;
           for k:=1 to n do
                        if dp[i + a[k]][j+b[k]] = -1 then good:=true;
                        if (dp[i][j] = 0) then
                if (good) then dp[i][j]:=1
                else dp[i][j]:=-1;
        end;
            //   writeln('d = ',d);
             {
for dist:=400+1 downto 0 do
        for i:=-dist to dist do
                begin
                good:=false;
                j:=dist - abs(i);
                for k:=1 to n do
                        if dp[i + a[k]][j+b[k]] = -1 then good:=true;
                        if (dp[i][j] = 0) then
                if (good) then dp[i][j]:=1
                else dp[i][j]:=-1;

                //  if (i = 0 ) and (j = 0) then writeln('rez = ', dp[0][0]);
                 good:=false;
                j:=-(dist - abs(i));
                for k:=1 to n do
                        if dp[i + a[k]][j+b[k]] = -1 then good:=true;
                if (dp[i][j] = 0) then
                if (good) then dp[i][j]:=1
                else dp[i][j]:=-1;
                 //  if (i = 0 ) and (j = 0) then writeln('rez = ', dp[0][0]);

                end;
              }
             {   for i:=0 to 5 do
                begin
                        for j:=0 to 5 do
                     if (dp[i][j] >= 0) then write(' ', dp[i][j],' ') else   write(dp[i][j],' ');
                writeln;
                end;
                       }
      //   writeln('last = ', dp[21][90]);
  if (dp[x][y] = 1) then write('Anton')
  else write('Dasha');
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n, i: integer;
  a: array[1..100]of integer;
begin
  readln(n);
  for i := 1 to n do
    read(a[i]);
   if(n = 1)then
     if(a[n] = 0)then
       writeln('UP')
     else if(a[n] = 15)then
       writeln('DOWN')
     else begin
       writeln(-1);
       halt(0);
     end
  else if(a[n] > a[n - 1])and(a[n] <> 15)then
    writeln('UP')
  else if(a[n] > a[n - 1])and(a[n] = 15)then
    writeln('DOWN')
  else if(a[n] < a[n - 1])and(a[n] <> 0)then
    writeln('DOWN')
  else
    writeln('UP');
  readln;
  readln;
end.


const oo=1000000007;
var
  p:array[0..2000000]of int64;
  i,j,n:longint;
  ans:int64;

function exgcd(a:int64):longint;
var
  temp:longint;
begin
   if a=1 then exit(1)
  else exit(exgcd((oo div a+1)*a-oo)*(oo div a+1) mod oo);
end;

begin
  readln(n);
  if n=1 then begin writeln(1); exit; end;
  p[1]:=1;
  for  i:=2  to  2*n do
  p[i]:=p[i-1]*i mod oo;
  ans:=p[n*2-1]*exgcd(p[n]) mod oo*exgcd(p[n-1]) mod oo;
  ans:=ans*2-n+oo;
  writeln(ans mod oo);
end.


var n,i,j,k,a,b,c:longint; s,st:string;
m:array[1..1000] of longint;
begin
    //assign(input,'baitap.inp');
    //assign(output,'baitap.out');
    //reset(input);
    //rewrite(output);
    read(a,b);
    while a<=b do begin
        a:=a*3;
        b:=b*2;
        k:=k+1;
    end;
    write(k);
    //close(input);
    //close(output);
end.


var
    a,k,n,o,i:longint;
begin
    o:=0;
    readln(n,k);
    for i:=1 to n do
    begin
        read(a);
        if (a>o) and (k mod a=0) then o:=a;
    end;
    writeln(k div o);
end.


var ok:boolean;
    i,j,k,n:longint;
    a,b:array[0..1001] of longint;

 begin
  read(n);
  for i:=1 to n do
   read(a[i]);

  for i:=1 to n-1 do
   for j:=i+1 to n do
    if (a[i]>a[j]) then begin
                         a[0]:=a[i];
                         a[i]:=a[j];
                         a[j]:=a[0];
                        end;

  for i:=1 to n do
   begin
    ok:=true;
    for j:=1 to k do
     if (b[j]<=a[i]) then begin
                           inc(b[j]);
                           ok:=false;
                           break;
                          end;

    if ok then begin
                inc(k);
                b[k]:=1;
               end;
   end;

  writeln(k);
 end.


Program Startuem;
var a,n,b,ch,i,kol:longint;
    k:array[1..100]of longint;

begin
read(n);
for i:=1 to n do
  begin
  read(ch);
  inc(k[ch]);
  if k[ch]=1 then inc(kol);
  if (ch=a) or (a=0) then
    a:=ch else
    b:=ch;
  end;
if (kol=2) and (k[a]=n div 2) then
  begin
  writeln('YES');
  write(a, ' ', b);
  end else
  write('NO');

end.


uses math;
var
 i:longint;n,m:int64;
 a:array[0..16]of int64;

function dfs(n,k:int64):int64;
var
 t:int64;
begin
 t:=k*(n div a[k]);
 n:=n mod a[k];
 if n=0 then exit(t);
 exit(t+min(k+dfs(a[k]-n,k-1),dfs(n,k-1)));
end;

begin
 readln(n);
 for i:=1 to 16 do a[i]:=a[i-1]*10+1;
 writeln(dfs(n,16));
end.


var a,b,r:word;
begin
  read(a,b,r);
  if(a<2*r)or(b<2*r)then write('Second')
  else write('First')
end.


program monstr;
uses math;
var a,b,c,d,i: longint;
begin
read(b,a);
read(d,c);
if a = c then
begin
write(a);
exit;
end;
for i:=max(a,c) to 1000000 do
begin
if ((i - a) mod b = 0) and ((i - c) mod d = 0) then
begin
write(i);
exit;
end;
end;
write(-1);
end.


USES MATH;

{$COPERATORS ON}

VAR i,j,k,ans : integer;
    a : array [1..4] of integer;

Function f(a,b,c : integer) : shortint;
Begin
    if (a < b+c) and (b < a+c) and (c < a+b) then
    f := 1
    else if (a = b+c) or (b = a+c) or (c = a+b) then
    f := 0
    else
    f := -1
End;

BEGIN
    for i := 1 to 4 do
    read(a[i]);

    ans := -1;
    for i := 1 to 2 do
    for j := i+1 to 3 do
    for k := j+1 to 4 do
    ans := max(ans,f(a[i],a[j],a[k]));

    if ans > 0 then
    writeln('TRIANGLE')
    else if ans = 0 then
    writeln('SEGMENT')
    else
    writeln('IMPOSSIBLE')
END.


program VKCUP_C;

var s:string;
	p:array[1..200]of longint;
	f:array[0..7,0..15,1..105]of int64;
	i,j,k,r,ll:longint;
	ans:int64;

function Trans(a,b:longint):longint;
begin
	case a of
		0: case b of
			0: exit(2);
			1: exit(4);
		end;
		1: case b of
			0: exit(1);
			1: exit(3);
		end;
	end;
end;

function OK(s0,V:longint):boolean;
var V0:longint;
begin
    if (s0=5)or(s0=6)or(s0=7)or(s0=1)or(s0=9) then exit(V = 4);
    if s0=4 then exit(V = 2);
    if s0=13 then exit(V = 3);
    V0:=Trans((s0 shr 2)and 1,(s0 shr 1)and 1);
    if V0=4 then V0:=1;
    exit(V=V0);
end;

begin
	readln(s);
	ll:=length(s);
	ans:=0;
	if ll=3 then begin
		writeln(1);
		halt;
	end;
	s:=s+s[1];
	for i:=1 to ll do p[i]:=trans(ord(s[i])-ord('A'),ord(s[i+1])-ord('A'));

	for i:=0 to 15 do
		if OK(i,p[2]) then f[i shr 1,i,4]:=1;
	for k:=0 to 7 do
		for i:=4 to ll do
			for j:=0 to 15 do
				for r:=0 to 1 do
					if OK(((j and 7)shl 1)+r,p[i-1]) then
						inc(f[k,((j and 7)shl 1)+r,i+1],f[k,j,i]);
	for k:=0 to 7 do
		for j:=0 to 15 do
			if OK(((j and 7)shl 1)+(k shr 2),p[ll-1])
			and OK(((j and 3)shl 2)+(k shr 1),p[ll])
			and OK(((j and 1)shl 3)+k,p[1]) then inc(ans,f[k,j,ll]);
	writeln(ans);
end.


type    arr=array[1..4] of longint;

var     n,i,ans,ansc,x,j:longint;
        b,c:Array[1..10] of longint;
        a:Array[1..10,1..4] of longint;

Function Check(x:longint):boolean;
var     i:longint;
        o:arr;
        flag:array[0..9] of boolean;

Function CheckBulls(q:arr;x:longint):boolean;
var     anso,i:longint;
begin
  anso:=0;
  for i:=1 to 4 do
    if a[x,i]=q[i] then inc(anso);
  if anso=b[x] then checkbulls:=true else checkbulls:=false;
  end;

Function CheckCows(q:arr;x:longint):boolean;
var     anso,i,j:longint;
begin
  anso:=0;
  for i:=1 to 4 do
    for j:=1 to 4 do
      if (i<>j)and(a[x,i]=q[j]) then inc(anso);
  if anso=c[x] then checkcows:=true else checkcows:=false;
  end;

begin
  fillchar(flag,sizeof(flag),false);
  for i:=1 to 4 do begin
    o[i]:=x mod 10;
    if flag[o[i]] then begin
      check:=false;
      exit;
      end;
    flag[o[i]]:=true;
    x:=x div 10;
    end;
  for i:=1 to n do
    if (not CheckBulls(o,i))or(not CheckCows(o,i)) then begin
      check:=false;
      exit;
      end;
  check:=true;
  end;

Begin
  //assign(input,'input.txt');assign(output,'output.txt');
  //reset(input);rewrite(output);
  readln(n);
  ans:=0;
  for i:=1 to n do begin
    readln(x,b[i],c[i]);
    for j:=1 to 4 do begin
      a[i,j]:=x mod 10;
      x:=x div 10;
      end;
    end;
  for i:=123 to 9876 do
    if check(i) then begin
      ansc:=i;
      inc(ans);
      end;

  if ans=1 then begin
   if ansc div 1000=0 then write('0');
   writeln(ansc) end else
    if ans>1 then writeln('Need more data') else writeln('Incorrect data');
  end.


Var a:Array [1..6] of LongInt;
    i,s,x,y,z,x1,y1,z1:LongInt;
Begin
    // ReSet (input,'input.txt');
    // ReWrite (output,'output.txt');
     Readln (x,y,z);
     Readln (x1,y1,z1);
     For I:=1 to 6 do
     Read (a[i]);
     s:=0;
     If z>z1 then Inc (s,a[4])
     else If z<0 then Inc (s,a[3]);
     If x>x1 then Inc (s,a[6])
     else If x<0 then Inc (s,a[5]);
     If y>y1 then Inc (s,a[2])
     else If y<0 then Inc (s,a[1]);
     Writeln (s);
End.


uses math;
const
  tfi = '';//603B.inp';
  tfo = '';//603B.out';
  base = 1000000007;
var
  fi,fo : text;
  n,k,kq,top,count,res,ii : longint;
  num,low,st,d,p : array[0..1000000] of longint;
  free : array[0..1000000] of boolean;
procedure input;
  var i : longint;
  begin
    readln(fi,n,k);
  end;
procedure sang;
  var i,j : longint;
  begin
    for i:=1 to n do
        begin
          j:=i;
          while j<=n-1 do
            begin
              p[j]:=(p[j]+int64(d[i])*i mod base) mod base;
              j:=i+j;
            end;
        end;
  end;
procedure dfs(u : longint);
  var v : longint;
  begin
    inc(count);
    low[u]:=count;num[u]:=count;
    inc(top);st[top]:=u;
    v:=int64(u)*k mod n;
    if not free[v] then
      if num[v]=0 then
        begin
          dfs(v);
          low[u]:=min(low[u],low[v]);
        end
      else low[u]:=min(low[u],num[v]);
    if low[u]=num[u] then
      begin
        kq:=0;
        repeat
          v:=st[top];
          free[v]:=true;
          inc(kq);dec(top);
        until v=u;
        inc(d[kq]);
      end;
  end;
procedure work;
  var i,j,sum : longint;
  begin
    res:=1;
    for i:=0 to n-1 do
      if num[i]=0 then dfs(i);
    sang;
    for i:=1 to n do
      if d[i]>0 then
        for j:=1 to d[i] do
          res:=int64(res)*p[i] mod base;
    writeln(fo,res);
  end;
begin
  assign(fi,tfi);reset(fi);
  assign(fo,tfo);rewrite(fo);
    input;
    if k<>0 then work
    else
      begin
        res:=1;
        for ii:=1 to n-1 do res:=int64(res)*n mod base;
        writeln(fo,res);
      end;
  close(fi);close(fo);
end.


var ans,l1,l2,l3,l4,l5,l6,i:longint;
  begin
    read(l1,l2,l3,l4,l5,l6);
    writeln(sqr(l1+l2+l3)-sqr(l1)-sqr(l3)-sqr(l5));
  end.


var a,b,c,d,i,yn,ym,ans:int64;a1:array[0..2000005]of int64;
function max(x,y:int64):int64;
begin
  if x>y then exit(x) else exit(y);
end;
function min(x,y:int64):int64;
begin
  if x<y then exit(x) else exit(y);
end;
begin
  readln(a,b,c,d);
  a1[b+c+1]:=0;
  i:=b+c;
  while i>=c do
  begin
    yn:=max(i-b,b);
    ym:=max(min(i-a,c),yn-1);
    a1[i]:=a1[i+1]+ym-yn+1;
    if i<=d then ans:=ans+a1[i+1];
    dec(i);
  end;
  writeln(ans);
end.


Program NonSquareEquation;
var
n : int64;
akar, idxbawah, sx, temp, x: int64;
IsFound : boolean;
function SumDigit (n : int64) : int64;
var
 S : string;
 TempInt, hasil : int64;
 k : longint;
 begin
    str(n,S);
    hasil := 0;
    for k := 1 to length(S) do
      begin
        val(S[k],TempInt);
        hasil := hasil + TempInt;
      end;
      SumDigit := hasil;
 end;
begin
readln(n);
akar := trunc(sqrt(n));
if akar < 100 then idxbawah := 1
 else idxbawah := akar - 100;
 IsFound := false;
 while (idxbawah <= akar) do
   begin
      sx := SumDigit(idxbawah);
      temp := idxbawah * idxbawah + sx * idxbawah - n;
      if temp = 0 then
       begin
       x := idxbawah;
       IsFound := true;
       break;
       end;
       inc(idxbawah);
   end;
 if IsFound then
  begin
    writeln(x);
  end else writeln('-1');
end.


Var
    k, n: Int64;

Begin
    Read(n, k);
    Write(min(k - 1, n - k) + (n - 1) + 2*(n - 1) + 3)
End.


const   fi  ='c.INP';
        fo  ='c.OUT';
var     n: longint;
        s,kq: string;
        a: array[0..101] of longint;

procedure main;
var     i,sum,v: longint;
begin
        for i:=1 to n do a[i]:= a[i-1] + ord(s[i])-48;

        while (n>1) and (s[n]='0') do
        begin
                delete(s,n,1);
                n:=n-1;
        end;
        if (n=1) and (a[n]=0) then
        begin
                kq:= 'YES';
                exit;
        end;

        for i:=1 to n do a[i]:= a[i-1] + ord(s[i])-48;

        v:= 0;
        for sum:=0 to a[n]-1 do
        begin
                v:=0;
                for i:=1 to n do
                if a[i]-a[v]=sum then v:= i else
                if a[i]-a[v]>sum then break;
                if v=n then
                begin
                        kq:= 'YES';
                        exit;
                end;
        end;
        kq:= 'NO';
end;

begin
        readln(N);
        read(s);
        main;
        write(kq);
end.


var i:longint;t1,t2,m,h1,a1,x1,y1,h2,a2,x2,y2,x,xx,y,yy:int64;
a,b:array[0..4000000]of int64;
begin
//assign(input,'mkhqw.in');reset(input);
//assign(output,'mkhqw.out');rewrite(output);
readln(m);
readln(h1,a1);
readln(x1,y1);
readln(h2,a2);
readln(x2,y2);
for i:=1 to m*3 do
  begin
  if h1=a1 then
    begin
    inc(t1);
    a[t1]:=i-1;
    end;
  if h2=a2 then
    begin
    inc(t2);
    b[t2]:=i-1;
    end;
  if(h1=a1)and(h2=a2)then
    begin
    write(i-1);
    close(input);close(output);halt;
    end;
  h1:=(h1*x1+y1)mod m;
  h2:=(h2*x2+y2)mod m;
  end;
if(t1<=0)or(t2<=0)then
  begin
  write(-1);
  close(input);close(output);halt;
  end;
if(t1=1)or(t2=1)then
  begin
  write(-1);
  close(input);close(output);halt;
  end;
x:=a[1];y:=b[1];
xx:=a[2]-a[1];yy:=b[2]-b[1];
for i:=1 to m*10 do
  if(x+xx*i-y)mod yy=0 then
    begin
    write(x+xx*i);
    close(input);close(output);halt;
    end;
write(-1);
close(input);close(output);
end.


var n,i,j:longint;
    t:array[1..100] of longint;
 begin
{ assign(input,'input.txt');
 assign(output,'output.txt');
 reset(input);
 rewrite(output); }
 readln(n);
 for i:=1 to n do
  read(t[i]);
 if t[1]>15 then
  begin
   writeln(15);
   halt;
  end;
 if (n=1) then
  begin
   writeln(t[1]+15);
   halt;
  end;
 n:=n+1;
 t[n]:=90;

 for i:=1 to n-1 do
  begin
   if (t[i+1]-t[i])>15 then
    begin
     j:=t[i]+15;
     break;
    end
     else
      j:=90;
  end;
 writeln(j);
{ close(input);
 close(output); }
end.


const fin='';
    fout='';
var f,g:text;
    i,n,k,p:longint;
    s:int64;

function xl(x:int64):int64;
var i,p,y:int64;
begin
    y:=x;
    repeat
        p:=y mod 10;
        x:=x*10+p;
        y:=y div 10;
    until y=0;
    exit(x);
end;

begin
    assign(f,fin);reset(f);
    assign(g,fout);rewrite(g);
    read(f,k,p);
    for i:=1 to k do
    begin
        s:=(s+xl(i) mod p)mod p;
    end;
    write(g,s);
    close(f);
    close(g);
end.


var l,r,x,y,k: int64;
    i: longint;

BEGIN
    read(l,r,x,y,k);
    if r<k then begin writeln('NO'); halt; end;
    for i:=x to y do
      if (l<=k*i) and (k*i <= r) then
        begin writeln('YES'); halt; end;
    writeln('NO');
END.


Var a:array[1..10000] of longint;
i,j,n,m,d,k,g1,g2,z,p,ans,s1,s2:longint;
begin
 read(n);
  for i:=1 to n do
   begin
    read(a[i]);
    s2:=s2+a[i];
   end;
   read(g1,g2);
    for i:=n downto 2 do
     begin
      s2:=s2-a[i];
      s1:=s1+a[i];
      if (s1>=g1)and(s1<=g2)and(s2>=g1)and(s2<=g2) then
                                        begin  WriteLn(i); exit; end;
     end;
   WriteLn(0);
end.


var n,i,j,k:longint;
  b,jc:array[0..4002] of int64;
  p:int64;
  ss:array[0..4002,0..4002] of int64;
function s(ii,jj:longint):int64;
begin
  if ii=jj then exit(1);
  if ss[ii,jj]<>0 then exit(ss[ii,jj]);
  if (ii>=1) and (jj>=1) then ss[ii,jj]:=(s(ii-1,jj-1)+jj*s(ii-1,jj)) mod 1000000007;
  exit(ss[ii,jj]);
end;

begin
  readln(n);
  b[0]:=1;
  for i:=1 to 4002 do
  begin
      b[i]:=1;
      for k:=2 to i do
        b[i]:=b[i]+s(i,k);
      b[i]:=b[i] mod 1000000007;
  end;
  writeln((b[n+1]-b[n]+1000000007) mod 1000000007);
end.


Var a,b,c,a1,b1,c1:array[1..100000] of longint;
    i,j,k,m,l,o,p,n:longint;
    ans:extended;
 Begin
  read(n,m);
  if n+m=2 then write('1.0') else write((1+(n-1)*(m-1)/(n*m-1))/n:0:7);

 End.


var
  n,k,i,j,m,max,ans,c : longint;
  a : array[1..200001] of longint;
  b : array[1..20,1..200001] of longint;
begin
  readln(n,k);
  for i := 1 to n do
  begin
    read(a[i]);
    if (a[i] > max) then
      max := a[i];
    inc(b[1,a[i]]);
    j := 1;
    while (a[i] > 1) do
    begin
      a[i] := a[i] div 2;
      inc(j);
      inc(b[j,a[i]]);
    end;
  end;
  ans := 1000000000;
  for i := 1 to max do
  begin
    m := 0;
    c := 0;
    for j := 1 to 20 do
    begin
      m := m+b[j,i];
      c := c+(b[j,i])*(j-1);
      if (m > k) then
      begin
        c := c-(j-1)*(m-k);
        m := k;
      end;
      if (m = k) then
      begin
        if (ans > c) then
          ans := c;
      end;
    end;
  end;
  writeln(ans);
end.


var b,i,k,l:int64;
begin
read (b);
k:=0;
l:=round(sqrt(b));
for i:=1 to l do begin
if b mod i=0 then inc(k);
end;
k:=k*2;
if l*l=b then k:=k-1;
if b=1 then write ('1') else write (k);
end.


const p=1000000007;
var f:array[0..1000000]of int64;
    x,b,a,n,i:longint;
    aa,bb:char;
    r:int64;
function BinPow(a,n:int64):int64;
var b:int64;
begin
  if n=0
  then BinPow:=1
  else
  if odd (n)
  then BinPow:=((BinPow(a,n-1)mod p)*a) mod p
  else begin
    b:=BinPow(a,n div 2)mod p;
    BinPow:=(b*b)mod p;
    end;
end;
function Good(x:int64):boolean;
var i:longint;
    s:string;
begin
   while x<>0 do
   begin
     if (x mod 10 <>b)and(x mod 10<>a)
     then  begin
            Good:=false;
            exit;
          end;
     x:=x div 10;
   end;
   good:=true;
end;
begin
     //reset(input,'input.txt');
     //rewrite(output,'output.txt');
     Readln(a,b,n);
     f[1]:=1;
     f[0]:=1;
     for i:=2 to n do
     begin
        f[i]:=(f[i-1]*i) mod p;
     end;
     aa:=chr(a+ord('0'));
     bb:=chr(b+ord('0'));
     r:=0;
     for x:=0 to n do
     begin
       if good(x*a+b*(n-x))
       then r:=(r+f[n]*BinPow((f[n - x]*f[x]mod p),p-2)mod p)mod p;
     end;
     writeln(r);
end.


var n,m,kol,ii,tt:longint;
    pp:boolean;
procedure fun1;
begin
 if (n>=2) and (m>=2) then
 begin
  n:=n-2;
  m:=m-2;
  pp:=true;
 end else
 if (n>=1) and (m>=12) then
  begin
   n:=n-1;
   m:=m-12;
   pp:=true;
  end else
 if (m>=22) then
  begin
   m:=m-22;
   pp:=true;
  end else
  pp:=false;
end;

procedure fun2;
var i,j:longint;
begin
 for i:= 22 downto 1 do
  begin
   if (m>=i) and ((220-10*i) mod 100=0) and ((220-10*i) div 100<=n)then
    begin
     m:=m-i;
     n:=n-(220-10*i) div 100;
     pp:=true;
    exit;
  end;
  end;
  pp:=false;
end;

begin

 readln(n,m);
 pp:=true;
 kol:=1;
 while pp do
  begin
   if kol=1 then fun1 else fun2;
   kol:=3-kol;
  end;
  if kol=2 then writeln('Hanako') else
  writeln('Ciel');

end.


program cf_95d_yxr;
const
  mo=1000000007;
var
  n,k,i,x,y,j:longint;
  s:ansistring;
  yxr:int64;
  g,wg:array[0..1001,-1..1001]of int64;
  go:array[0..1001]of int64;
  f:array[0..1001,0..9]of int64;
  sf,sg:array[0..1001]of int64;
procedure make;
var
  i,j:longint;
begin
  g[1,0]:=2;
  g[1,-1]:=8;
  sg[1]:=10;
  sg[0]:=1;
  for i:=0 to k-1 do wg[1,i]:=2;
  for i:=2 to 1001 do begin
    for j:=-1 to k-1 do begin
      if j=-1 then begin
        g[i,j]:=(g[i-1,j]+g[i-1,k-1])*8 mod mo;
      end else
      if j=0 then begin
        g[i,j]:=(sg[i-1]-wg[i-1,k-1])*2 mod mo;
      end else begin
        g[i,j]:=g[i-1,j-1]*8 mod mo;
      end;
      sg[i]:=(sg[i]+g[i,j])mod mo;
      if j=0 then
        wg[i,j]:=g[i,j]
      else if j<>-1 then
        wg[i,j]:=(wg[i,j-1]+g[i,j])mod mo;
    end;
  end;

  for i:=2 to 1001 do begin
    for j:=0 to 9 do begin
      f[i,j]:=sf[i-1];
      if (j=4)or(j=7) then begin
        f[i,j]:=(f[i,j]+wg[i-1,k-1])mod mo;
      end;
      sf[i]:=(sf[i]+f[i,j])mod mo;
    end;
  end;
end;
function don(x,y:longint):int64;
var
  i,j,la,num,pos,t,goo:longint;
  ps:string;
  ans:int64;
begin
  la:=-1;
  ans:=0;
  if s[y]=' ' then dec(y);
  pos:=y-x+1;
  for i:=x to y do begin
    ps:=s[i];
    val(ps,num);
    for j:=0 to num-1 do begin
      ans:=(ans+f[pos,j])mod mo;
    end;
    if la<>-1 then begin
      for j:=0 to num-1 do begin
        if (j=4)or(j=7) then begin
          ans:=ans+sg[pos-1]-wg[pos-1,k-1];
        end else begin
          ans:=ans+wg[pos-1,k+pos-la-1]
        end;
      end;
    end;
    if (num=4)or(num=7) then begin
      if (la<>-1)and(la-pos<=k) then begin
        for j:=i+1 to y do begin
           ps:=s[j];
           val(ps,num);
           dec(pos);
           ans:=ans+num*go[pos-1];
        end;
        if x<>1 then
        ans:=(ans+1)mod mo;
        break;
      end else begin
        la:=pos;
      end;
    end;
    dec(pos);
    if (la<>-1)and(la>pos+k) then la:=-1;
  end;
  if ans<0 then ans:=ans+mo;
  exit(ans);
end;
begin
 { assign(input,'a.in');
  assign(output,'a.out');
  reset(input);
  rewrite(output);  }
  readln(n,k);
  make;
  go[0]:=1;
  for j:=1 to 1001 do begin
     go[j]:=(go[j-1]*10) mod mo;
  end;
  for i:=1 to n do begin
    readln(s);
    for j:=1 to length(s) do begin
      if s[j]=' ' then begin
        yxr:=don(j+1,length(s))-don(1,j-1);
        yxr:=yxr mod mo;
        if yxr<0 then yxr:=yxr+mo;
        writeln(yxr);
        break;
      end;
    end;
  end;
  close(input);
  close(output);
end.


program z1;
var a,b,c,d,i,j,k,l,m,n,ta,tb,hh,mm,t,ans:longint; s,s1:string; Z:array[0..14400] of byte;
begin
//assign(input,'d:\input.txt'); reset(input);
//assign(output,'d:\output.txt'); rewrite(output);
readln(a,ta);
readln(b,tb);
for i:=300 to 1439 do
 begin
 if (i-300) mod b=0 then Z[i]:=1;
 end;
readln(s); s1:=s[1]+s[2]; val(s1,hh,c); s1:=s[4]+s[5]; val(s1,mm,c);
t:=hh*60+mm;
for i:=t-tb+1 to t+ta-1 do ans:=ans+Z[i];
writeln(ans);
end.


var i,k,k1,s,v1,v2,t1,t2:longint;begin readln(s,v1,v2,t1,t2);k:=s*v1+2*t1;k1:=s*v2+t2*2;if k<k1 then write('First');if k>k1 then write('Second');if k=k1 then write('Friendship');end.


var
	n,x,i,j,k:integer;
	s:string;
	arr:array[1..200] of integer;
	num:array[0..19] of integer;
	t:boolean;

function Dec(c:char):integer;
begin
	if (c='0') then
	begin
		Dec:=0;
	end else
	if (c='1') then
	begin
		Dec:=1;
	end else
	if (c='2') then
	begin
		Dec:=2;
	end else
	if (c='3') then
	begin
		Dec:=3;
	end else
	if (c='4') then
	begin
		Dec:=4;
	end else
	if (c='5') then
	begin
		Dec:=5;
	end else
	if (c='6') then
	begin
		Dec:=6;
	end else
	if (c='7') then
	begin
		Dec:=7;
	end else
	if (c='8') then
	begin
		Dec:=8;
	end else
	begin
		Dec:=9;
	end;
end;

begin
	readln(n);
	read(s);
	t:=false;
	for i:=0 to 19 do
	begin
		num[i]:=0;
	end;
	for i:=1 to n do
	begin
		x:=Dec(s[i]);
		num[x]:=num[x]+1;
	end;
	for i:=n+1 to n*2 do
	begin
		x:=Dec(s[i])+10;
		num[x]:=num[x]+1;
	end;
	k:=1;
	for i:=0 to 9 do
	begin
		for j:=1 to num[i] do
		begin
			arr[k]:=i;
			k:=k+1;
		end;
	end;
	for i:=10 to 19 do
	begin
		for j:=1 to num[i] do
		begin
			arr[k]:=i-10;
			k:=k+1;
		end;
	end;
	if (n>1) then
	begin
		if (arr[1]<arr[n+1]) then
		begin
			i:=2;
			while (arr[i]<arr[i+n]) and (i<n) do
			begin
				i:=i+1;
			end;
			if (arr[i]<arr[i+n]) then
			begin
				t:=true;
			end;
		end else
		if (arr[1]>arr[n+1])  then
		begin
			i:=2;
			while (arr[i]>arr[i+n]) and (i<n) do
			begin
				i:=i+1;
			end;
			if (arr[i]>arr[i+n]) then
			begin
				t:=true;
			end;
		end;
	end else
	begin
		if (arr[1]<>arr[2]) then
		begin
			t:=true;
		end;
	end;
	if t then
	begin
		writeln('YES');
	end else
	begin
		writeln('NO');
	end;
end.


program WIN;
var
n,k,c,i,W,p : byte;
begin
p:=255;
W:=0;
readln(n,k);
for i:=1 to N do begin
read(c);
if (i<k)and(c<>0) then W:=w+1;
if (i=k)and(c<>0) then begin P:=c; W:=i;  end
else if c>=p then W:=w+1;
end;
Writeln(W);
end.


var n,m,min,max,max1,min1,i,p,o:longint;
 begin
 read(n,m,min,max);
 max1:=0;
 min1:=102;
  for i:=1 to m do begin
  read(o);
  If o>max1 then max1:=o;
  If o<min1 then min1:=o;
  end;
  If max<max1 then writeln('Incorrect') else
  If min>min1 then writeln('Incorrect') else
  begin
  If max<>max1 then p:=p+1;
  If min<>min1 then p:=p+1;
  If n-m>=p then writeln('Correct') else
  writeln('Incorrect');
  end;
  end.


var s,a,k1,k,h:string;
i,l,pod,j:integer;
begin
readln(s);
a:='CODEFORCES';
if (length(s)<=length(a)) then begin writeln('NO'); halt; end;
k:=copy(s,1,10); if k=a then begin writeln('YES'); halt; end;
k:=copy(s,length(s)-10+1,10); if k=a then begin writeln('YES'); halt; end;
pod:=1;
while (pod<=length(s)-10) do begin
for i:=2 to length(s)-pod do begin
h:=s;
delete(h,i,pod);
if h=a then begin writeln('YES'); halt; end;
end;
pod:=pod+1;
end;
writeln('NO');
end.


program p1;
var st:string; k,n,i:longint;
begin
readln(n);
read(st);
k:=0;
for i:=1 to n-1 do
if (st[i]+st[i+1]='YY')or(st[i]+st[i+1]='CC')or(st[i]+st[i+1]='MM') then  k:=1;
if k<>1 then
if pos('??',st)<>0 then write('YES') else
if (pos('C?C',st)<>0)or(pos('M?M',st)<>0)or(pos('Y?Y',st)<>0) then write('YES') else
if (st[length(st)]='?')or(st[1]='?') then write('YES') else write('NO') else write('NO');
end.


var a,b,c,x,y,z,n,md:int64;
function pow(a,b:int64):int64;
 var x:int64;
  begin
  x:=1;
   while(b>0) do
    begin
     if b and 1=1 then begin x:=(x*a) mod md;   end;
     b:=b shr 1;
     a:=a*a mod md;
    end;
    pow:=x;
  end;
 begin
  read(n);
  md:=1000000007 ;
  a:=pow(2,n);
  b:=pow(2,2*n);
  c:=pow(2,md-2);
  writeln((((a+b) mod md)*c) mod md);
 end.


program element;
var a,b,c:int64;
begin
     readln(a,b,c);
     if (c=0) and (a=b) then writeln('YES')
     else if (c=0) and (a<>b) then writeln('NO')
     else if ((b-a) mod c=0) and ((b-a) div c>=0) then writeln('YES') else writeln('NO');
end.


const   fi='';
        fo='';
var     n,res,max:string;
        f,g:text;
function        div8(n:string):boolean;
var     i:longint;
begin
        val(n,i);
        if i mod 8=0 then exit(true)
        else exit(false);
end;
procedure       readfile;
var     x,i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,n);
        close(f)
end;
procedure       xuli;
var     i,j,k:longint;
begin
        n:='00'+n;
        res:='';
        for i:=length(n) downto 3 do
                begin
                res:=n[i]+res;
                for j:=i-1 downto 2 do
                        begin
                        res:=n[j]+res;
                        for k:=j-1 downto 1 do
                                begin
                                res:=n[k]+res;
                                if div8(res) then
                                        //max:=ss(res,max);
                                        exit;
                                delete(res,1,1);
                                end;
                        delete(res,1,1);
                        end;
                delete(res,1,1);
                end;
end;
procedure       writefile;
begin
        assign(g,fo);
        rewrite(g);
        if res='' then writeln(g,'NO')
        else    begin
                while (res[1]='0') and (length(res)>1) do delete(res,1,1);
                writeln(g,'YES');
                write(g,res);
                end;
        close(g);
end;
begin
        readfile;
        xuli;
        writefile;
end.


       const eps=1e-10;
       besk=4000000000000000000; label 33,55,5,4,1,3,2,44,22;
       type
       mas=array[-500000..1570460+1] of int64;
       integer=longint;   zap=record  p1,p2,p3:int64; end;
       zap1=^zap;
       var p11, p00,t00,t10,t01,t11,p01,p10,koled,start,px,py,posx,posy,cur,init,res,oldpos,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto:longint;
       sss:array[-1..1000000] of string;
       ch1,ch2:char;
       ssans,ss1,ss4,oldss,smin,ss3,ss,ss2:string;
       newaans,aans:zap;
       otr1,otr0,d0,vx,vy,ddist,tttt:extended;
       pqqq:zap;
       gam,al0,otal,al1,al2,acc, disk,prop,bet,al:extended; fl1,fl2,fl:boolean;
       dr3,dr1,dr2,pt,ott1,ott2:zap;
       p1,p2,p3,p4,grnado,sumtail,totalsum,sumodin,kolodin,maxsum,i3,p,tt,sum,pp1,pp2,root,oldans,par,dlkruga,topt,t1,t2,t3,ot,aa,bb,cc,dist,znak,rr,kolmax,kkol,pos,pq,razm,poss,mm,tip,ppos1,oldtt,ps,pos1,pos2,pred,color,buk:int64;
       ddsum,dd,kol,stek,time,zz,x:array[-1000..1110000] of int64;
       stroka,sss1,sss2:array[-10..610000] of string;
       v3,v1,v2,pointx,pointy,vel,tt0,radius,ote,dl1,dl2:extended;
       ddl,dnewr,dnewl,dr,ddpos:array[-10..210,-20..150,0..9] of int64;
       y,xold,yold,xxold,yyold,xmin,xmax,ymin,ymax,xx,str,zx,zy,z,xxx,yyy,invfact,ansx,ansy,ugol,yy:array[-1000000..2110000] of int64;
       ll,ost,shag,napr,dl,ppos,ii,jj,t,ptek,dloch1,oldaa,oldbb,zapas,ott,mnog,ttt,delta,tt1,tt2,koll,newt,osn,oldot,num,oldt,znmax,opld,nap,t4,iii,jjj,aaa,bbb,ccc,p0,newpos,newdl,len,pp3,ans1,ans2,modul,t0,dloch,koldel,mmax,period, dolg,ot1,ot2,oldgr,predsum,pmin,tmin,kool,number,imin,qq,n,m,numpos,down,imax,qq1,qq2,q1,q2,w,pmax,pmax2,pos0,pp,maxot,tmax,nn,n1,q:int64; flag1:boolean;
       olda,b,c,a,zzz,fact,stan,a2,invx,invy,place,b2,sum1,sum0,d:mas; flag2,flag:boolean;  pl:longint;
       dx,dy,gor,ver,i2,j2,ans,sdvig,izb, oldmax,newmax,posmax,razn,ppp,minx,miny,maxx,maxy,jmax,gr,grr,ener,dob,ugg,r,ug:int64;
        polezan:array[-1..1000,-1..1000] of boolean;
       zan1,zan2,prost,zan:array[-1000..2001001] of boolean;
       newzan,zann:array[-1000000..4000000] of boolean;
       zanx,marked:array[-1000000..4100000] of boolean;
       zikl,dlzikl,sumdl,z1,z2,x1,y1,x2,y2,ddnew,d3,d1,right,dmin,dd1,left,dnomer:array[-1111..1100000] of int64;
       nomer,ochh,newochh:array[-1000..4000000] of longint;
       newx,newy,dplus,dminus,och1,b1,a1,first,last,kolnenul,next1,next0,prev1,prev0,newoch,och,lx,a3,b3,predok:array[-20000..1610000] of int64;
       ddd:array[-400..1065200,-1..20] of int64;
        pole,newpole:array[-100..600,-100..600] of char;
       ddold,polessum:array[-100..1300,-100..1300] of int64;

       ssan,bufer:array[-1000..1000000] of char;
       cosa,sina,cosb,sinb,rx,ry,h1,h2,h,l1,l2,otmax,v:int64;
       obmen,ch:char;
       stepen,mat:array[-10..1050001,0..4] of longint;
       flagg,fflag,ok,flagg1:boolean;
       oldx,oldy,numx,numy,xleft,xright,s,newplace,newstr,next,prev,aold:array[-1000..1200002] of int64;

       function srav(i,j:longint):boolean;
     var k,tt:longint;
       begin
          if (a[i]<a[j])or(a[i]=a[j])and(a1[i]<a1[j]) then begin srav:=true;   end else srav:=false;

       end;

      procedure sl (k,l,m:integer);
      begin
        i:=l;j:=m; flag:=true; step:=0;while flag do begin
        if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];b3[l+step]:=a3[i];end;
        inc(step);inc(i);
        end;
        if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];b3[l+step]:=a3[j];end;
        inc(step);inc(j);end;
        if  ((i>=l+k) or (j>=m+k)) then flag:=false;
        end;
        if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j]; b3[l+step]:=a3[j];
        inc(step);inc(j);until (j>=m+k);
        if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];  b3[l+step]:=a3[i];inc(step);inc(i);until (i>=l+k);
      end;

      procedure sort(var c:mas);
      begin
      k:=1; repeat
      l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
      for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i];a3[i]:=b3[i]; end;
      until (k>=n);
      end;

       function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
       function max (a,b:int64):int64; begin max:=b;if a>b then max:=a;  end;
       function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
        tt:zap; tt1:zap1;  fl:boolean;
           begin
               fl:=false;
               if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
               x2:=1;x1:=0;y2:=0;y1:=1;
               while b>0 do
               begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
               a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
               end;
              if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
              begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
              evkl:=tt1;
           end;
          function phi(a,b:double):double; label 222;var p:double;
            begin
               if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
               if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
               if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
               if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
               if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
               222: phi:=p;
            end;

              function nod(a,b:int64):int64; var p,t:int64;
                 begin
                 a:=abs(a); b:=abs(b);
                 if (a>0)and(b>0) then
                 begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                 p:=a;
                 end else if a=0 then p:=b else p:=a;
                 nod:=p;
              end;

             function arccos(tt:extended):extended;
                 begin
                   if abs(tt)>1-1e-13 then
                   if tt>0 then  arccos:=0 else arccos:=pi;
                   if tt=0 then arccos:=pi/2 else
                   if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
                    else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);
                 end;

            function degg(a,k,modul:int64):int64; var p:int64;    label 4;
                  begin
                   if k<=0 then degg:=1
                    else if odd(k) then degg:=(degg(a,k-1,modul)*a) mod modul  else
                    begin  p:=degg(a,k div 2,modul);  degg:=(p*p) mod modul;    end;
                  end;

  {  function zaprmax(left,right:longint):int64;
      begin
       if left>=right then zaprmax:=y[left] else
        begin
         if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
          begin
           if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
           if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);
          end;
        end;
      end;

    function zaprmin(left,right:longint):int64;
      begin
       if left>=right then zaprmin:=z[left] else
        begin
         if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
          begin
           if odd(left) then zaprmin:=min(zaprmin(left+1,right),z[left]);
           if not odd(right) then zaprmin:=min(zaprmin(left,right-1),z[right]);
          end;
        end;
      end;

function zaprsum(left,right:longint):int64;
      begin
       if left>=right then if left=right then zaprsum:=y[left] else zaprsum:=0 else
        begin
         if not odd(left) and odd(right) then zaprsum:=zaprsum(left shr 1,right shr 1) else
          begin
           if odd(left) then zaprsum:=zaprsum(left+1,right)+y[left];
           if not odd(right) then zaprsum:=zaprsum(left,right-1)+y[right];
          end;
        end;
      end;

   }

        procedure udal(ii:longint);
        begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

         function pprost(pp:int64):boolean;
           var i,j,t:longint; tt:extended; fl:boolean;
         begin
            tt:=pp;
            tt:=sqrt(tt);
            fl:=true;
            for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;
            pprost:=fl;
         end;

        function gl(c:char):boolean;
           begin
           if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;
           end;
    {        function slog(d1,d2:zap):zap1;
            var t,tt,p,q:int64; ans:zap;
         begin
            p:=d1.x*d2.y+d1.y*d2.x;
            q:=d1.y*d2.y;
            t:=nod(p,q);
            p:=p div t; q:=q div t;
            ans.x:=p mod modul;ans.y:=q mod modul;
            slog:=@ans;
         end;

        function umn(d1,d2:zap):zap1;
         var t,tt,p,q:int64; ans:zap;
         begin
          p:=d1.x*d2.x;
          q:=d1.y*d2.y;
          t:=nod(p,q);
          p:=p div t; q:=q div t;
          ans.x:=p mod modul;ans.y:=q mod modul;
          umn:=@ans;
         end;

          function sravfr(d1,d2:zap):boolean;
            begin
             if  d1.x*d2.y<d2.x*d1.y then sravfr:=true else sravfr:=false;
            end;
              }
        function bincoef(ii,jj:longint):int64;
            var t1,t2,t3,p1,p2,p3,ot:int64;
         begin
             if ii>=jj then
             begin
               p1:=fact[ii];
               p2:=fact[jj];
               p3:=fact[ii-jj];
               t2:=degg(p2,modul-2,modul);
               t3:=degg(p3,modul-2,modul);
               ot:=((p1*t2) mod modul*t3) mod modul;
               bincoef:=ot;
             end  else bincoef:=0;
          end;

      {      function bincoef1(ii,jj:longint):int64;
             var t1,t2,t3,p1,p2,p3,ot:int64;
       begin
           if ii>=jj then
           begin
           p1:=fact[ii];
           p2:=invfact[jj];
           p3:=invfact[ii-jj];
           ot:=((p1*p2) mod modul*p3) mod modul;
            bincoef1:=ot;
            end  else bincoef1:=0;
       end;
       }

    begin

      { assign (input,'D:\Projects\input.txt');reset(input);
       assign (output,'D:\Projects\output.txt'); rewrite(output);
       }
       readln(p,modul);
       dd[1]:=1;   ddsum[1]:=1;
        for step:=2 to p do
           begin
              p1:=0;p2:=0; p3:=0; p4:=0;
            {  for i:=1 to step-1 do p1:=p1+dd[i];
             }
              al:=step; al:=sqrt(al);
              gr:=trunc(al+eps);

              for i:=2 to gr do
                 begin
                     p3:=(p3+dd[step div i]) mod modul;
                 end;

              for i:=gr-1 downto 1 do
                 begin
                     t1:=step div i; t2:=step div (i+1);
                  {   writeln('step= ',step,' i= ',i,' t1= ',t1,' t2= ',t2);
                  }    p4:=(p4+dd[i]*(t1-t2)) mod modul;
                 end;
                 if gr*(gr+1)<=step then dob:=dd[gr] else dob:=0;
                { writeln('step= ',step,' gr= ',gr);
                } if  gr*(gr+2)=step then begin  dob:=(modul+2*dd[gr]) mod modul;   end;

              p2:=0;
            {  for i:=2 to step do p2:=(p2+dd[step div i]) mod modul;
            }  dd[step]:=(ddsum[step-1]+p3+p4+dob) mod modul;
               { writeln('step= ',step,' p2= ',p2,' p3= ',p3,' p4= ',p4,' dd= ',dd[step],' ',p2,' = ',p3+p4+dob,' dob= ',dob);
                if p2<>p3+p4+dob then begin writeln('probl step= ',step);  writeln('**********************');     end;
               }
              ddsum[step]:=(ddsum[step-1]+dd[step]) mod modul;
           end;

            writeln(dd[p]);

       1:  close (output);

    end.


var
 n,i,j,t,s:longint;
 a:array[0..51] of longint;
begin
 readln(n);
 for i:=1 to n do read(a[i]);
 for i:=1 to n-1 do
  for j:=i+1 to n do
   if a[i]>a[j] then
    begin
     t:=a[i]; a[i]:=a[j]; a[j]:=t;
    end;
 i:=2;
 while i<=n do
  begin
   if a[i]=a[i-1] then
    begin
     for j:=i+1 to n do
      a[j-1]:=a[j];
     dec(n);
    end
   else inc(i);
  end;
 for i:=2 to n do
  if (a[i-1]+1=a[i]) and (a[i]+1=a[i+1]) then
   begin writeln('YES'); halt; end;
 writeln('NO');
end.


var a,b,c,d,e,i:integer;
var s:string;
begin
readln(s);
a:=length(s); b:=1;c:=1;
for i:=2 to a  do begin
if ((s[i]=s[i-1]) and (b=5)) then begin
c:=c+1;b:=0;
end;
if ((s[i]=s[i-1]) and (b<5)) then
b:=b+1;
if s[i]<>s[i-1] then begin c:=c+1;b:=1;
end;
end;
writeln(c);
readln;
end.


Program forces;
uses wincrt;
var n,k,m:integer;
begin
read(n);
read(m);
read(k);
if (n<=k) and (n<=m)
then write('yes')
else write('no');
END.


Type
	TPoint	=	Record
			x,y	:LongInt;
	End;
Var
	A,B,C	:TPoint;

	Function Dis(a,b:TPoint):LongInt;
	Begin Exit((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); End;

	Function Check(u,v,w:TPoint):Boolean;
	Var	s1,s2,s3	:LongInt;
	Begin
		s1:=Dis(u,v); s2:=Dis(u,w); s3:=Dis(v,w);
                If (s1=0) or (s2=0) or (s3=0) Then Exit(False);
		If s1+s2=s3 Then Exit(True);
		If s1+s3=s2 Then Exit(True);
		If s2+s3=s1 Then Exit(True);
		Exit(False);
	End;
Begin
	Readln(A.x,A.y,B.x,B.y,C.x,C.y);
	If Check(A,B,C) Then Writeln('RIGHT')
	Else
	Begin
		Inc(A.x); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Dec(A.x);
		Dec(A.x); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Inc(A.x);
		Inc(A.y); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Dec(A.y);
		Dec(A.y); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Inc(A.y);
		Inc(B.x); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Dec(B.x);
		Dec(B.x); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Inc(B.x);
		Inc(B.y); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Dec(B.y);
		Dec(B.y); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Inc(B.y);
		Inc(C.x); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Dec(C.x);
		Dec(C.x); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Inc(C.x);
		Inc(C.y); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Dec(C.y);
		Dec(C.y); If Check(A,B,C) Then Begin Writeln('ALMOST'); Exit; End; Inc(C.y);
		Writeln('NEITHER');
	End
End.


var
  i, a, b, c, d, k, p: integer;
  mas: array [1..100] of integer;

begin
  readln(a, b, c, d);

  mas[1] := a;
  mas[2] := b;
  mas[3] := c;
  mas[4] := d;

  repeat
    k := 0;
    for i := 1 to 3 do
      if mas[i] < mas[i + 1] then
      begin
        p := mas[i];
        mas[i] := mas[i + 1];
        mas[i + 1] := p;
        k := 1;
      end;

  until k = 0;

  if (mas[1]+mas[4]=mas[2]+mas[3]) or (mas[4]+mas[3]+mas[2]=mas[1]) then
  writeln('YES')
  else
  writeln('NO');

end.


var
 s,s1:string;
 i:longint;
begin
 readln(s);
 for i:=1 to length(s) do
  begin
   s1:=copy(s,i,3);
   if length(s1)<3 then break;
   if (pos('A',s1)<>0) and (pos('B',s1)<>0) and (pos('C',s1)<>0) then
    begin
     writeln('Yes');
     halt;
    end;
  end;
 writeln('No');
end.


program task3;
var n,i,k:longint;
function hex(k:longint):longint;
var a,s:longint;
begin
s:=0;
a:=1;
while k>0 do
      begin
      s:=s+a*(k mod 2);
      a:=a*10;
      k:=k div 2;
      end;
hex:=s;
end;

begin
read(n);
i:=0;
repeat
 i:=i+1;
 k:=hex(i);
until k>n;
writeln(i-1);
end.


var a,x1,x2,ans:integer;
str:string;
begin
read(a);
ans:=a;
if a<0 then begin
x1:=-abs(a div 10);
x2:=a div 100;
str:=(IntToStr(x2)+InttoStr(abs(a) mod 10));
x2:=-abs(Strtoint(str));
ans:=max(x1,x2);
end;
writeln(ans);
end.


var a,b,c:array[0..10000] of longint;
i,j,n,t:longint;
begin
//assign(input,'swht.in');reset(input);
//assign(output,'swht.out');rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do b[i]:=i;
for i:=1 to n-1 do
  for j:=i+1 to n do
    if a[i]<a[j] then
      begin
      t:=a[i];a[i]:=a[j];a[j]:=t;
      t:=b[i];b[i]:=b[j];b[j]:=t;
      end;
for i:=1 to n do c[b[i]]:=a[i mod n+1];
for i:=1 to n do write(c[i],' ');
close(input);close(output);
end.


var
        a:ansistring;
        i,k,x:longint;
begin
        readln(a);
        for i:=1 to length(a) do
        begin
                if a[i]='A' then inc(k);
                if a[i]='1' then inc(k,10)
                else
                begin
                        val(a[i],x);
                        inc(k,x);
                end;
        end;
        writeln(k);
end.//此不是相同代码


uses math;
var
  n,st,m,ans,q,pr : int64;
  lnn,i,_,j,l : longint;
  s,t : ansistring;

begin
  readln(n); lnn:=trunc(ln(n)/ln(10))+1;
  readln(s);
  i:=length(s); st:=1;
  while i > 0 do begin
    q:=1; l:=i; pr:=0;
    for j:=i downto 1 do
      if (int64(ord(s[j])-48)*q+pr < n) and (q <= n) then begin
        pr:=pr+int64(ord(s[j])-48)*q;
        q:=q*10;
        if s[j] <> '0' then l:=j;
      end else break;
    ans:=ans+st*pr;
    i:=l-1;
    st:=st*n;
  end;
  writeln(ans);
end.


uses math;
const
   tfi='';
   tfo='';
   MAXN=500;

var
   fi, fo: text;
   n, k, svlt, sum, res: longint;
   a: array[0..MAXN+5,0..MAXN+5] of char;
   c, t: array[0..MAXN*MAXN+5] of longint;
   f: array[0..MAXN+5,0..MAXN+5] of longint;
   dx: array[1..4] of longint=(-1,0,1,0);
   dy: array[1..4] of longint=(0,1,0,-1);

procedure __;
var
   i, j: longint;
begin
   assign(fi, tfi); reset(fi);
   assign(fo, tfo); rewrite(fo);
   readln(fi, n, k);
   for i:=1 to n do
      begin
         for j:=1 to n do read(fi, a[i, j]);
         readln(fi);
      end;
end;

function inside(x, y: longint): boolean;
begin
   if (x>0) and (y>0) and (x<=n) and (y<=n) then exit(true);
   exit(false);
end;

procedure dfs(x, y: longint);
var
   k, u, v: longint;
begin
   f[x, y] := svlt;
   inc(c[svlt]);
   for k:=1 to 4 do
      begin
         u := x+dx[k];
         v := y+dy[k];
         if (inside(u, v)) and (a[u, v]='.') and (f[u, v]=0) then dfs(u, v);
      end;
end;

procedure tinh(x, y, cnt: longint);
begin
   if (not inside(x, y)) or (a[x, y]<>'.') or (t[f[x, y]]=cnt) then exit;
   t[f[x, y]] := cnt;
   sum := sum+c[f[x, y]];
end;

procedure xuly;
var
   x, y, u, v, cnt: longint;
begin
   for x:=1 to n do
      for y:=1 to n do
         if (a[x, y]='.') and (f[x, y]=0) then
            begin
               inc(svlt);
               dfs(x, y);
            end;
   cnt := 0;
   for y:=1 to n-k+1 do
      begin
         for u:=1 to k do for v:=y to y+k-1 do dec(c[f[u, v]]);
         for x:=1 to n-k+1 do
            begin
               inc(cnt);
               sum := k*k;
               for u:=x to x+k-1 do
                  begin
                     tinh(u, y-1, cnt);
                     tinh(u, y+k, cnt);
                  end;
               for v:=y to y+k-1 do
                  begin
                     tinh(x-1, v, cnt);
                     tinh(x+k, v, cnt);
                  end;
               res := max(res, sum);
               if x+k<=n then // Di chuyen hinh vuong xuong duoi;
                  for v:=y to y+k-1 do
                     begin
                        inc(c[f[x, v]]);  // Hoi phuc lai cai o trong h.vuong truoc
                        dec(c[f[x+k, v]]); // Bo cai o trong h.vuong
                     end;
            end;
         for u:=n downto n-k+1 do //Hoi phuc lai h.vuong sat voi canh ben duoi
            for v := y to y+k-1 do inc(c[f[u, v]]); //Do o tren x+k<=n ...
      end;
   writeln(fo, res);
end;

procedure _;
begin
   close(fi); close(fo);
end;

BEGIN
   __;
   xuly;
   _;
END.


uses math;
var
  i,j,k,n,m:longint;
  a,b:array[0..21]of longint;
  dp:array[0..101,0..101]of longint;
  ans,maxint:int64;
procedure solve;
var i,j,p,q:longint;
begin
   fillchar(dp,sizeof(dp),$5f);
   maxint:=dp[0,0];
   dp[0,0]:=0;
   for i:=0 to n*4-1 do
   begin
     p:=i mod n+1;
     for j:=0 to i+1 do if j<>0 then
     dp[i+1,j]:=min(dp[i,j-1]+a[p],dp[i,j+1]+b[p]) else dp[i+1,j]:=dp[i,j+1]+b[p];
   end;
end;
begin
   readln(n,m);
   for i:=1 to n do read(a[i]);
   for i:=1 to n do read(b[i]);
   solve;
   if m<=3 then writeln(dp[n*m,0]) else
   begin
     ans:=dp[n*4,0];
     ans:=ans+int64(dp[n*4,0]-dp[n*2,0])*int64(m div 2-2);
     writeln(ans);
   end;
end.


var s:string;
a,code,i:integer;
begin
readln(s);
for i:=length(s) downto 1 do
begin
val(s[i],a,code);
case a of
0:writeln('O-|-OOOO');
1:writeln('O-|O-OOO');
2:writeln('O-|OO-OO');
3:writeln('O-|OOO-O');
4:writeln('O-|OOOO-');
5:writeln('-O|-OOOO');
6:writeln('-O|O-OOO');
7:writeln('-O|OO-OO');
8:writeln('-O|OOO-O');
9:writeln('-O|OOOO-');
END;
end;
end.


var
        a:array[1..100] of longint;
        n,i,j,z,res,tmp:longint;
        ok:boolean;

begin
        readln(n);
        res:=0;
        for i:=1 to n do
                read(a[i]);
        for i:=1 to n-1 do
          for j:=i+1 to n do
                begin
                        ok:=true;
                        for z:=i+1 to j do
                                if a[z]<>a[z-1]+1 then
                                       begin
                                        ok:=false;
                                        break;
                                       end;
                        if ok then
                                begin
                                        tmp:=j-i-1;
                                        if ((i=1) and(a[i]=1)) or ((j=n) and (a[j]=1000)) then
                                                inc(tmp);
                                        if res<tmp then res:=tmp;
                                end;

                end;
                write(res);
end.


var
  x: array [1..4] of integer;
  n, a, b, c, z, y, t, k,o: integer;

begin
  read(n, a, b); k := 1;
  for var i2:= 1 to 1 do
  begin
    if n-4*a-2*b>=0 then begin write(1); break; end;
    if (n-2*a-b>=0) or (n-3*a-2*b>=0) or (n-2*(a+b)>=0) or ((n-a-2*b>=0) and (n-3*a>=0)) or (n-4*a-b>=0)or ((n-3*a-b>=0) and (n-a-b>=0)) or ((n-2*a-b>=0) and (n-2*a-b>=0)) or ((n-a-b>=0)and(n-3*a-b>=0)) then begin write(2); break; end;
    if a >= b then
  begin
    if n - a * 4 >= 0 then begin
      z := n - 4 * a;
      inc(c);
      x[c] := z;
    end
    else if n - a * 3 >= 0 then begin
      z := n - 3 * a;
      inc(c, 2);
      inc(x[1], z);
      inc(x[2], n - a);
    end
    else if n - 2 * a >= 0 then begin
      z := n - 2 * a;
      inc(c, 2);
      inc(x[1], z);
      inc(x[2], z);
    end else
    if n - a >= 0 then begin
      z := n - a;
      inc(c, 4);
      inc(x[1], z);
      inc(x[2], z);
      inc(x[3], z);
      inc(x[4], z);
    end;
    for var p := 1 to c - 1 do
      for var j := 1 to c - p do
        if x[j] < x[j + 1] then swap(x[j], x[j + 1]);
    for var i := 1 to c do
    begin
      if x[i] - 2 * b >= 0 then inc(y, 2) else
      if x[i] - b >= 0 then inc(y) else break;
      if y = 2 then break;
    end;
    if y = 0 then
    begin
      if n - 2 * b >= 0 then begin
        inc(c);
        write(c);
      end else begin
        inc(c, 2);
        write(c);
      end;
    end else if y = 1 then write(c + 1);
    if y = 2 then  write(c);
  end else
  begin
    if n - 2 * b >= 0 then begin
      c := 1;
      x[1] := n - 2 * b;
    end else begin
      c := 2;
      x[1] := n - b;
      x[2] := x[1];
    end;
    while (x[k] >= 0) and (k <= 2) do
    begin
      if x[k] - a >= 0 then
      begin
        inc(y);
        x[k] := x[k] - a;
      end else inc(k);
      if y = 4 then break;
    end;
    if (n - a * 4 >= 0) and (y = 0) then begin
      z := n - 4 * a;
      inc(c);
      write(c);
    end
    else if (n - a * 3 >= 0) and (y = 0) then begin
      z := n - 3 * a;
      inc(c, 2);
      inc(x[1], z);
      inc(x[2], n - a);
      write(c);
    end
    else if (n - 2 * a >= 0) and (y = 0) then begin
      z := n - 2 * a;
      inc(c, 2);
      inc(x[1], z);
      inc(x[2], z);
      write(c);
    end else
    if (n - a >= 0) and (y = 0) then begin
      z := n - a;
      inc(c, 4);
      write(c);
    end;//
    if (n - a * 3 >= 0) and (y = 1) then begin
      z := n - 3 * a;
      inc(c);
      write(c);
    end
    else if (n - 2 * a >= 0) and (y = 1) then begin
      z := n - 2 * a;
      inc(c, 2);
      write(c);
    end else
    if (n - a >= 0) and (y = 1) then begin
      inc(c, 3);
      write(c);
    end;//
    if (n - 2 * a >= 0) and (y = 2) then begin
      z := n - 2 * a;
      inc(c);
      write(c)
    end else
    if (n - a >= 0) and (y = 2) then begin
      z := n - a;
      inc(c, 2);
      write(c);
    end;//
    if (n - a >= 0) and (y = 3) then begin
      inc(c);
      write(c);
    end;
    if y = 4 then write(c);
  end;
  end;
end.


program zz;

var m,i,j,ii,k,n,w,sb,s:longint;

function ss(x:longint):boolean;
 var i:longint;
begin
 if (x>2)and(odd(x)) then
 begin
  i:=3;
  while i*i<=x do
  if x mod i>0 then inc(i,2) else break;
  if i*i>x then ss:=true else ss:=false;
 end else ss:=false;
end;
begin
 {assign(input,'input.txt');reset(input);
 assign(output,'output.txt');rewrite(output);}
 read(n,m);
 i:=3;j:=5;
 while i+j<n do
 begin
  if ss(i+j+1) then inc(k);
  i:=j;inc(j,2);
  while not ss(j) do inc(j,2);
 end;
 if k<m then write('NO') else write('YES');

{ close(input);
 close(output);                               }
end.


{$O-}
Uses Math, SysUtils;
type
	int = longint;
	bool = boolean;
const
  inf = maxint;
  ux : array [1..4] of int = (1, 0, -1, 0);
  uy : array [1..4] of int = (0, -1, 0, 1);
var
	mn, res, x, y, len, i, j, ii, jj, k, tt, t, n : int;
	can : array [0..61,0..11,0..11,0..11,0..11] of bool;
	d, a, b : array [0..11,0..11] of int;
	qx, qy, s, q : array [0..301] of int;
	f, p, u, v, next, w : array [0..50001] of int;
  used : array [0..301] of bool;
	was : array [0..11,0..11] of bool;

procedure scanf;
var
	c : char;
begin
	readln(n, t);
	for i := 1 to n do begin
	for j := 1 to n do begin
		read(c);
		a[i][j] := ord(c)-ord('0');
		if (c = 'Y') then a[i][j] := -1 else
		if (c = 'Z') then begin
			a[i][j] := -1;
			qx[1] := i;
			qy[1] := j;
		end;
	end;
		readln;
	end;
  readln;
	for i := 1 to n do begin
	for j := 1 to n do begin
		read(c);
		b[i][j] := ord(c)-ord('0');
		if (c in['Y','Z']) then b[i][j] := -1;
	end;
		readln;
	end;
end;
procedure bfs;
begin
	was[qx[1]][qy[1]] := true;
  for i := 1 to n do
  for j := 1 to n do
    d[i][j] := inf;
  d[qx[1]][qy[1]] := 0;
	i := 1; j := 1;
	while (i <= j) do begin
		for k := 1 to 4 do begin
			x := qx[i] + ux[k];
			y := qy[i] + uy[k];
			if (not was[x][y]) and (a[x][y] <> -1) and (1 <= x) and (x <= n) and (1 <= y) and (y <= n) then begin
				inc(j);
				qx[j] := x;
				qy[j] := y;
				was[x][y] := true;
				d[x][y] := d[qx[i]][qy[i]] + 1;
			end;
		end;
		inc(i);
	end;
end;
procedure precalc;
begin
	for i := 1 to n do
	for j := 1 to n do
    if (a[i][j] <> -1) then
  		can[0][i][j][i][j] := true;
	for tt := 1 to t do
	for i := 1 to n do
	for j := 1 to n do begin
		if (a[i][j] = -1) then continue;
		for ii := 1 to n do
		for jj := 1 to n do begin
    if (tt > d[ii][jj]) or (a[ii][jj] = -1) then continue;
		for k := 1 to 4 do begin
			x := ii + ux[k];
			y := jj + uy[k];
			if (tt-1 < d[x][y]) and (1 <= x) and (x <= n) and (1 <= y) and (y <= n) and (can[tt-1][i][j][x][y]) then begin
				can[tt][i][j][ii][jj] := true;
				break;
			end;
		end;
    end;
	end;
end;
procedure add(x, y, z : int);
begin
	inc(len);
	v[len] := y;
	next[len] := s[x];
	w[len] := z;
	s[x] := len;
end;
procedure findpath(x, y : int);
var
  rev : int;
begin
	while (x <> 0) do begin
		mn := min(mn, w[x]-f[x]);
		x := p[x];
	end;
	while (y <> 0) do begin
		if (y and 1 = 1) then rev := y + 1
		else rev := y - 1;
		f[y] := f[y] + mn;
		f[rev] := f[rev] - mn;
		y := p[y];
	end;
end;
procedure bfsflow;
var
  pos : int;
begin
	i := 1; j := 1;
	fillchar(used, sizeof(used), false);
	q[1] := 0; used[0] := true;
	while (i <= j) do begin
		pos := s[q[i]];
		while (pos <> 0) do begin
			if (not used[v[pos]]) and (w[pos]-f[pos] > 0) then begin
				inc(j);
				q[j] := v[pos];
				used[q[j]] := true;
				u[j] := pos;
				p[pos] := u[i];
				if (q[j] = 2*n*n+1) then begin
					findpath(pos, pos);
					exit;
				end;
			end;
			pos := next[pos];
		end;
		inc(i);
	end;
end;
procedure flow;
begin
	for i := 1 to n do
	for j := 1 to n do begin
    if (a[i][j] > 0) then begin
	  	add(0, (i-1)*n+j, a[i][j]);
  		add((i-1)*n+j, 0, 0);
    end;
    if (b[i][j] > 0) then begin
		  add(n*n+(i-1)*n+j, 2*n*n+1, b[i][j]);
	  	add(2*n*n+1, n*n+i*(n-1)+j, 0);
  	end;
  end;
	for i := 1 to n do
	for j := 1 to n do
	for ii := 1 to n do
	for jj := 1 to n do
	for tt := 0 to t do
		if (can[tt][i][j][ii][jj]) and (b[ii][jj] > 0) and (a[i][j] > 0) then begin
			add((i-1)*n+j, n*n+(ii-1)*n+jj, inf);
			add(n*n+(ii-1)*n+jj, (i-1)*n+j, 0);
      break;
		end;
	res := 0;
	while (true) do begin
		mn := inf;
		bfsflow;
		if (mn = inf) then begin
			write(res);
			halt;
		end;
		res := res + mn;
	end;
end;
begin
//	reset(input, 'a.in'); rewrite(output, 'a.out');
	scanf;
	bfs;
	precalc;
	flow;
end.


uses math;
const
        fi='';
        fo='';
var
        f1,f2:text;
        i,n,a,b,ans:longint;
begin
        assign(f1,fi);  reset(f1);
        assign(f2,fo);  rewrite(f2);
        read(f1,n,a,b);
        ans:=0;
        for i:=1 to n-1 do ans:=max(ans,min(a div i,b div (n-i)));
        write(f2,ans);
        close(f1);      close(f2);
end.


{$APPTYPE CONSOLE}

uses SysUtils, Math;

var i, j, k, x : integer;
    s : int64;
    ans : array[0..1000] of int64;
    answer : array[0..1000] of int64;
    cnt : integer;

procedure print;
var i : integer;
begin
  for i := 1 to cnt do
    write(answer[i], ' ');
  writeln;
end;

begin
  //reset(input, 'text.in');
  //rewrite(output, 'text.out');
  read(s, k);
  if (k > 35) then begin
    cnt := 0;
    while (s > 0) do begin
      for i := 30 downto 0 do begin
        if ((1 shl i) <= s) then begin
          ans[cnt] := int64(1 shl i);
          dec(s, int64(1 shl i));
          inc(cnt);
          break;
        end;
      end;
    end;
    ans[cnt] := 0;
    inc(cnt);
    writeln(cnt);
    for i := 0 to cnt - 1 do
      write(ans[i], ' ');
    writeln;
  end else begin
    for i := 0 to k - 1 do
      ans[i] := 0;
    ans[k] := 1;
    for i := k + 1 to 1000 do
      for j := i - 1 downto i - k do
        inc(ans[i], ans[j]);
    for i := 0 to 1000 do
      answer[i] := 0;
    cnt := 0;
    while (s > 0) do begin
      for i := k - 1 to 1000 do begin
        if (ans[i] > s) then begin
          inc(cnt);
          dec(s, ans[i - 1]);
          answer[cnt] := ans[i - 1];
          break;
        end;
      end;
    end;
    inc(cnt);
    answer[cnt] := 0;
    writeln(cnt);
    print;
    writeln;
  end;
end.


program zzz;
var
  s1,s2:string;
  n,i,k:longint;
begin
  readln(n);
  readln(s1);
  k:=0;
  i:=length(s1)div 2;
  while (copy(s1,1,i)<>copy(s1,i+1,i))and (i>0)do dec(i);
  if(copy(s1,1,i)=copy(s1,i+1,i))and(i<>0) then k:=i+1+length(s1)-i*2
  else
   k:=length(s1);
  writeln(k);
end.


var n,i,x1,x2,x3,x4,tmp,pd,j:longint;
a:array[0..10000] of longint;
begin
readln(n);
for i:=1 to n do
read(a[i]);
pd:=0;
for i:=1 to n-2 do
begin
x1:=a[i];
x2:=a[i+1];
if x1>x2 then
begin
tmp:=x1;
x1:=x2;
x2:=tmp;
end;
for j:=i+1 to n-1 do
begin
x3:=a[j];
x4:=a[j+1];
if x3>x4 then
begin
tmp:=x3;
x3:=x4;
x4:=tmp;
end;
if (x1<x3) and (x3<x2) and (x2<x4) then pd:=1;
if (x3<x1) and (x1<x4) and (x4<x2) then pd:=1;
end;
end;
if pd=1 then write('yes')
        else write('no');
end.


var a,b,c,min:longint;
begin
  read(a,b,c);
  min:=a;
  if (min>b div 2) then min:=b div 2;
  if (min>c div 4) then min:=c div 4;
  write(min*7)
end.


uses math;
type mass=array[0..200] of integer;
     maxx=array[0..200,1..2] of integer;
var m1:mass;max1,res,kol,uk,uk1,k,min1,n,q,sx,g,xv,l,np,p,nl,d,sy,c,a,b:Int64;s,s1,ss:string;j,i,z:Integer;
    ch:Char;m:maxx;
begin
 //  Reset(input,'input.txt');
 //  Rewrite(Output,'output.txt');
   readln(n,k);
   for i:=0 to n-1 do
      if (k-i*2) div (n-i)>=3
      then Begin
             writeln(i);
             halt(0);
           end;
   writeln(n);
end.


var
n:integer;
begin
  read(n);
  if n =3 then begin
    write(1);
  end;
  if n =1 then begin
    write(2);
  end;
   if n=4 then begin
       write(2);
   end;
   if n =2 then begin
       write(3);
   end;
   if n=5 then begin
       write(1);
   end;
end.


program Project3;

{$APPTYPE CONSOLE }

uses
  SysUtils;

var a,b:array[1..1000]of integer;
  i,n,k,j:longint;
begin
  readln(n);        k:=0;
  if n>1 then begin
  k:=n+1;
  for i:=2 to n-1 do begin
  k:=k+((i)*(n-i))+1;
  end;
  end else k:=1;
  writeln(k);
  readln;
  readln;
end.


{$APPTYPE CONSOLE}
{$M 99777216}
{$R-,Q-,O+,S+,H+}
var
  t, q, i, j, st : longint;
  a, b, p, o : int64;
procedure swap(var a, b : int64);
var
  c : int64;
begin
  c := a;
  a := b;
  b := c;
end;
function get(a , b: int64) : longint;
var
  q : extended;
  res : LongInt;
begin
  q := a / b;
  res := 1;
  while q + 1e-15 > b do
    begin
      inc(res);
      q := q / b;
    end;
  get := res;
end;
function rec(a, b : int64) : Boolean;
var
  ok : boolean;
  p, o : int64;
  st, j : longint;
begin
  if (a = 0) or (b = 0) then
    begin
      rec := false;
      exit;
    end;
  ok := rec(b, a mod b);
  if not ok then
    begin
      rec := true;
      exit;
    end;
  if (a div b) Mod (b + 1) and 1 = 0 then
    rec := true
  else
    rec := false;
end;
begin
 // reset(input, 'input.txt');
 // rewrite(output, 'output.txt');
  Readln(t);
  for q := 1 to t do
    begin
      readln(a, b);
      if b > a then
        Swap(a, b);
      if not rec(a, b) then
        writeln('Second')
      else
        writeln('First');
      Continue;
      if (a = 0) or (b = 0) then
        begin
          writeln('Second');
          Continue;
        end;
      i := 1;
      while (a mod b <> 0) do
        begin
          st := get(a, b);
          p := b;
          for j := 2 to st do
            begin
              p := p * b;
            end;
          o := b;
          b := a - p;
          a := o;
          if b > a then
            swap(a, b);
          inc(i);
        end;
      if i and 1 = 0 then
        writeln('Second')
      else
        writeln('First');
    end;
end.


{$apptype console}
Uses SysUtils;
Var
   x:Array[0..500000] of Int64;
   n,m,x1,x2,x3,a,b,c,k,ans,r1:Int64;
   n1:Real;
   i,j:Integer;
procedure qSort(l,r:integer);
var i,j:integer;
    w,q:int64;
begin
  i := l; j := r;
  q := x[random(r-l+1) + l];
  repeat
    while (x[i] < q) do inc(i);
    while (q < x[j]) do dec(j);
    if (i <= j) then
    begin
      w:=x[i]; x[i]:=x[j]; x[j]:=w;
      inc(i); dec(j);
    end;
  until (i > j);
  if (l < j) then qSort(l,j);
  if (i < r) then qSort(i,r);
end;
Begin
   Read(n);
   If n mod 3<>0 Then Begin
      Write(0);
      Halt;
   End;
   n:=n div 3;
   m:=0;
   n1:=n;
   For i:=1 To Round(sqrt(n1+0.0000001)) Do
      If n mod i=0 Then Begin
         m:=m+1;
         x[m]:=i;
         If i<>n div i Then Begin
            m:=m+1;
            x[m]:=n div i;
         End;
      End;
   qSort(1,m);
   ans:=0;
   For i:=1 To m-1 Do Begin
      r1:=n div x[i];
      x1:=x[i];
      For j:=i To m Do Begin
         If (x[i]*x[j]<=0) or (x[i]*x[j]>n) Then Break;
         If ((x[j]-x[i])*x[i]*x[j]<0) or ((x[j]-x[i])*x[i]*x[j]>=n) Then Break;
         If r1 mod x[j]=0 Then Begin
            x2:=x[j];
            x3:=r1 div x[j];
            If (x3<x1) or (x3<x2) Then Continue;
            If (x1+x2-x3) mod 2<>0 Then Continue;
            If (x1-x2+x3) mod 2<>0 Then Continue;
            If (-x1+x2+x3) mod 2<>0 Then Continue;
            a:=(x1+x2-x3) div 2;
            b:=(x1-x2+x3) div 2;
            c:=(-x1+x2+x3) div 2;
            If (a<=0) or (b<=0) or (c<=0) Then Continue;
            k:=1;
            If b<>a Then k:=k+1;
            If (c<>a) and (c<>b) Then k:=k+1;
            If k=1 Then ans:=ans+1
            Else If k=2 Then ans:=ans+3
            Else ans:=ans+6;
         End;
      End;
   End;
   Write(ans);
End.


var
        i,j,l,r,n,t,k,ans,ll,rr,mid:longint;
        bz:array[1..1000000]of boolean;
        zs:array[0..1000000]of longint;
begin
        read(n);
        for i:=2 to n do
        begin
                if(bz[i]=false)then
                begin
                        inc(zs[0]);
                        zs[zs[0]]:=i;
                end;
                for j:=1 to zs[0] do
                begin
                        if(n/zs[j]<i)then break;
                        bz[i*zs[j]]:=true;
                        if(i mod zs[j]=0)then break;
                end;
        end;
        ans:=maxlongint;
        for i:=zs[0] downto 1 do
        begin
                if(n mod zs[i]=0)then
                begin
                        t:=n div zs[i];
                        l:=zs[i]*(t-1)+1;
                        r:=zs[i]*t-1;
                        for j:=l to r do
                        begin
                                for k:=2 to trunc(sqrt(j)) do
                                begin
                                        if(j mod k=0)then
                                        begin
                                                if(bz[k]=false)then
                                                begin
                                                        t:=j div k;
                                                        if(k*(t-1)+1<ans)then
                                                        begin
                                                                ans:=k*(t-1)+1;
                                                        end;
                                                end;
                                                if(bz[j div k]=false)then
                                                begin
                                                        t:=j div (j div k);
                                                        if((j div k)*(t-1)+1<ans)then
                                                        begin
                                                                ans:=(j div k)*(t-1)+1;
                                                        end;
                                                end;
                                        end;
                                end;
                                  //if(ans<>maxlongint)then break;
                        end;
                        break;
                end;
        end;
        if(ans<>maxlongint)then writeln(ans)
        else writeln(n-1);
end.


var w,h,k,i,c: longint;
begin
  read(w,h,k);
  c:=(2*w)+2*(h-2);
  if k<>1 then
  for i:=2 to k do begin
    w:=w-4;
    h:=h-4;
    c:=c+(2*w)+2*(h-2);
  end;
  writeln(c);
  readln;
  readln;
end.


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

function nsd(x,y:int64):int64;
begin
  if x<>0 then nsd:=nsd(y mod x,x) else nsd:=y;
end;

function nsk(x,y:int64):int64;
begin
  nsk:=(x div nsd(x,y)) * y;
end;

begin
  reaD(x,y,a,b);
  k:=nsk(x,y);
  write((b div k) -((a-1) div k) );
end.


program Project2;
{$APPTYPE CONSOLE}
uses
  SysUtils, Math;

var n, r1, r2, d: Integer;
k, eps: extended;

begin
    eps := 1e-7;
    read(n, r1, r2);
    if (n = 1) then begin
        if (r1 >= r2) then
            writeln('YES')
        else
            writeln('NO');
        exit;
    end;
    d := r1 - r2;
    k := sin(pi/n);
    k := k * d;
    if (k + eps > r2) then
        writeln('YES')
    else
        writeln('NO');
    readln;
    readln;
end.


var s1,s2,st:string;
k,n:longint;
sim:char;
begin
  readln(st);
  n:=length(st);
  s1:=st;
  while true do
   begin
    sim:=st[n];
    delete(st,n,1);
    insert(sim,st,1);
    if st=s1 then break
             else k:=k+1;
   end;
  writeln(k+1);
end.


var
m, n, i, k, sum: longint;
id, s:array[0..1234567] of longint;
c: array[0..1234567] of char;
l, was: array [0..1234567] of boolean;
begin
readln(n, m);
for i:=1 to m do readln(c[i], id[i]);
for i:=1 to   n do was[i]:=false;
for i:=1 to n do s[i]:=0;
for i:=1 to m do
begin
  if not was[id[i]] then
begin
  if c[i] = '-' then s[id[i]]:=1;
was[id[i]]:=true;
end;
end;
sum:=0;
for i:=1 to n do sum:=sum+s[i];
for i:=1 to n do l[i]:=true;
for i:=1 to m do
begin
  if c[i]='+' then
begin
if sum <> 0 then l[id[i]]:=false;

end;
sum:=sum-s[id[i]];
s[id[i]]:=1-s[id[i]];
sum:=sum+s[id[i]];
if c[i] = '-' then
begin
if sum <> 0 then l[id[i]]:=False;
end;
end;
for i:=1 to m-1 do
if (c[i] = '-') and( (c[i + 1] <> '+')  or (id[i + 1] <> id[i])) then l[id[i]]:=False;
for i:=2 to m do
if (c[i] = '+') and ((c[i - 1] <> '-') or (id[i - 1] <> id[i])) then l[id[i]]:=false;
k:=0;
for i:=1 to n do k:=k+ord(l[i]);
writeln(k);
for i:=1 to n do
if (l[i]) then write(i,' ');
end.