 type mas = record
             x,y,c,p:longint;
            end;
 var i,j,k,n,m,p:longint;
  a:array [0..101] of mas;
  b:array [0..101] of longint;
 begin
{  assign (input,'input.txt');
  reset (input);
  assign (output,'output.txt');
  rewrite (output);  }
   read (n,m);

  for i:=1 to m do
   begin
    read (a[i].x,a[i].y,a[i].c);
    a[i].p:=i;
  end;

 for i:=1 to n do
  begin
   p:=20000;
   k:=0;
  for j:=1 to m do
    begin
     if a[j].x<=i then
      begin
      if a[j].y=i then
       if a[j].c<>0 then
        begin
         writeln (-1);
         halt;
        end
         else
        begin
         inc (a[k].c);
         k:=m+1;
         p:=-1;
        end;

      if (a[j].c<>0) and (a[j].y-i-a[j].c<p) then
       begin
        inc (a[k].c);
        k:=a[j].p;
        p:=a[j].y-i-a[j].c;
        dec (a[j].c);
       end;

      end;
    end;

   b[i]:=k;

  end;

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

  end.


Var f:Text;
    n,m,x,y,a,b:longint;

Function min(x,y:Longint):Longint;
Begin
    If x<y then Exit(x)
    else Exit(y);
End;

Procedure xl;
Var t1,t2,kq,tmp:Longint;
Begin
    Assign(f,'');
    Reset(f);
    Readln(f,m,n,x,y,a,b);
    Close(f);
    t1:=x-1;
    t2:=y-1;
    If ((x=1) and (y=1)) or ((x=1) and (y=n)) or ((x=m) and (y=1)) or ((x=m) and (y=n)) then kq:=0
    Else kq:=1000000000;
    If ((x-1>=a) or (m-x>=a)) and ((y-1>=b) or (n-y>=b)) then
     Begin
    If (t1 mod a=0) and (t2 mod b=0) then
     Begin
      t1:=t1 div a;
      t2:=t2 div b;
      If abs(t1-t2) mod 2=0 then
       Begin
        tmp:=min(t1,t2)+(abs(t1-t2));
        If (tmp<kq) then kq:=tmp;
       End;
     End;
    t1:=x-1;
    t2:=n-y;
    If (t1 mod a=0) and (t2 mod b=0) then
     Begin
      t1:=t1 div a;
      t2:=t2 div b;
      If abs(t1-t2) mod 2=0 then
       Begin
        tmp:=min(t1,t2)+(abs(t1-t2));
        If tmp<kq then
          kq:=tmp;
       End;
     End;
    t1:=m-x;
    t2:=y-1;
    If (t1 mod a=0) and (t2 mod b=0) then
     Begin
      t1:=t1 div a;
      t2:=t2 div b;
      If abs(t1-t2) mod 2=0 then
       Begin
        tmp:=min(t1,t2)+(abs(t1-t2));
        If tmp<kq then kq:=tmp;
       End;
     End;
    t1:=m-x;
    t2:=n-y;
    If (t1 mod a=0) and (t2 mod b=0) then
     Begin
      t1:=t1 div a;
      t2:=t2 div b;
      If abs(t1-t2) mod 2=0 then
       Begin
        tmp:=min(t1,t2)+(abs(t1-t2));
        If tmp<kq then kq:=tmp;
       End;
     End;
     End;
    If kq=1000000000 then Writeln('Poor Inna and pony!')
    Else Writeln(kq);
End;

Begin
    xl;
End.


program zadacha221b;
var x,i,k:longint;

function proverka(x,i:longint):integer;
var a:array[1..10] of byte;
    b:array[1..10] of byte;
    j,l:longint;
begin
proverka:=0;
j:=1;
while x>0 do
 begin
 a[j]:=x mod 10;
 x:=x div 10;
 inc(j);
 end;
l:=1;
while i>0 do
 begin
 b[l]:=i mod 10;
 i:=i div 10;
 inc(l);
 end;
for x:=1 to j-1 do
 for i:=1 to l-1 do
  if a[x]=b[i] then
   begin
   proverka:=1;
   exit;
   end;
end;
begin
{assign(input,'input.txt');
 assign(output,'output.txt');
 reset(input); rewrite(output);}
readln(x); k:=0;
for i:=1 to trunc(sqrt(x)) do
 if x mod i=0 then
  begin
  if proverka(x,i)=1 then inc(k);
  if (proverka(x,x div i)=1) and (i<>x div i) then inc(k);
  end;
{i:= x div 2;
if proverka(x,i)=1 then inc(k);
if x>1 then inc(k);}
write(k);
{close(input); close(output);}
end.


VAR N,M,K,t,X,Y,M1:int64;
begin
readln(N,M,K);
if K<N then begin
  writeln(1+K,' 1');
  halt;
end;
K:=K-N;
M1:=M-1;
t:=K div M1;
K:=K mod M1;
X:=N-t;
if X mod 2 = 1 then Y:=M-K
               else Y:=2+K;
writeln(X,' ',Y);
end.


var a:array[1..20000000]of boolean;
    i,j,n:longint;
function reverse(x:longint):longint;
var o:longint;
 begin
  o:=0;
  while (x>0) do
   begin
    o:=o*10+(x mod 10);
    x:=x div 10;
   end;
  reverse:=o;
 end;
begin
 readln(n);
 a[1]:=true;
 for i:=2 to 1000007 do
  begin
   j:=i;
   if (a[i]=true) then continue;
   while (j<=1000007) do
    begin
     inc(j,i);
     a[j]:=true;
    end;
  end;
 i:=0;
 a[1]:=true;
 while (n>0) do
  begin
   inc(i);
   j:=reverse(i);
   if ( (not (a[j])) and (not (a[i])) and (i<>j) ) then dec(n);
  end;
 writeln(i);
end.


const maxn = 105; mo = 1000003;
type matrix = array[0..maxn,0..maxn] of int64;
var c,w,h,ans:int64;
    tmp,a:matrix;
procedure multi(a,b:matrix; var c:matrix);
  var t:matrix;
      i,j,k:longint;
  begin
    fillchar(t,sizeof(t),0);
    for k:=0 to w do
      for i:=0 to w do
        for j:=0 to w do t[i,j]:=(t[i,j]+a[i,k]*b[k,j]) mod mo;
    for i:=0 to w do
      for j:=0 to w do c[i,j]:=t[i,j];
  end;
procedure init();
  var i:longint;
  begin
    readln(c,w,h);
    fillchar(tmp,sizeof(tmp),0);
    for i:=0 to w do tmp[i,i]:=1;
    fillchar(a,sizeof(a),0);
    a[0,0]:=1;
    for i:=1 to w do a[0,i]:=(a[0,i-1]*h) mod mo;
    for i:=1 to w do a[i,i-1]:=1;
  end;
procedure main();
  var i,j,k:longint;
  begin
    i:=c+1;
    while (i<>0) do begin
      if (i mod 2=1) then multi(a,tmp,tmp);
      multi(a,a,a); i:=i div 2;
{      for j:=0 to w do begin
        for k:=0 to w do write(tmp[j,k],' '); writeln;
      end;}
    end;
    writeln(tmp[0,0]);
  end;
begin
  init();
  main();
end.


{$mode delphi}

{ $DEFINE IS_TEST}

{$ifndef IS_TEST}
  uses sysutils;
{$endif}

procedure start;
begin
{$ifdef IS_TEST}
  assign(input, 'input.txt');
  reset(input);
{$endif}
end;

var
  a, b, s, r: integer;
begin
  start;

  read(a, b);

  s := a;

  while a div b <> 0 do begin
    inc(s, a div b);

    a := a div b + (a mod b);
  end;

  writeln(s);
end.


{ Free Pascal }
var step: array [1 .. 50] of qword;
    k: qword;
    n, i: byte;
    c: char;

begin
   k:= 0;

   readln(n);

   step[1]:= 1;
   for i:= 2 to n do
      step[i]:= step[i - 1] * 2;

   for i:= 1 to n do
   begin
      read(c);
      if(c = 'B') then
         k:= k + step[i];
   end;

   writeln(k);
end.


var n,m,k,i,j,x,g,max,s:longint;
a:array[0..1001] of longint;
procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
begin
//assign(input,'sxz.in');reset(input);
//assign(output,'sxz.out');rewrite(output);
readln(n,m,k);
for i:=1 to m do begin read(a[i]);s:=s+a[i];end;
sort(1,m);
for i:=0 to n do
  begin
  x:=k-i*s;g:=(m+1)*i;
  if x<0 then break;
  for j:=1 to m do
    if x>=(n-i)*a[j] then
      begin
      x:=x-(n-i)*a[j];
      g:=g+(n-i);
      end
    else
      begin
      g:=g+x div a[j];
      break;
      end;
  if g>max then max:=g;
  end;
writeln(max);
close(input);close(output);
end.


var
       k,n,w,i,tot:integer;

begin
        readln(k,n,w);
        tot := 0;
        for i := 1 to w do
        begin
                tot := tot + (i*k);
        end;
        if tot>n then
                writeln(tot-n)
        else
                writeln('0');
end.


var m,n,a:real;
begin
read(m,n,a);
If round(m) mod round(a) <> 0
then m:=round(m) div round(a) + 1
else m:=round(m) div round(a);
If  round(n) mod round(a) <> 0
then n:=round(n) div round(a) + 1
else n:=round(n) div round(a);
writeln(n*m:0:0);

end.


{$MODE OBJFPC}
uses
  math;
const
  fi = 'INPUT.INP';
  dx : array[0..1] of Integer = (1, -1);
var
  n, res, m, i, j, k, d : Integer;
  s : String;
  f : array[0..105,0..55,-105..105,0..1] of Boolean;

begin
  //assign(input,fi); reset(input);
  readln(s); m := length(s);
  readln(n);
  f[0,0,0,0] := true;
  for i := 0 to m-1 do
    for j := 0 to n do
      for k := -m to m do
        for d := 0 to 1 do
          if f[i,j,k,d] then
            begin
              if s[i+1] = 'F' then
                begin
                  f[i+1,j,k+dx[d],d] := true;
                  f[i+1,j+1,k,1-d] := true;
                end;
              if s[i+1] = 'T' then
                begin
                  f[i+1,j,k,1-d] := true;
                  f[i+1,j+1,k+dx[d],d] := true;
                end;
            end;
    for j := 0 to n do
      for k := -m to m do
        for d := 0 to 1 do
          if ((n - j) and 1 = 0) and (f[m,j,k,d]) then res := max(res, abs(k));
  writeln(res);
end.


program A877;
var
  s:ansistring;
  i,kq:integer;

begin
  read(s);
  for i:=1 to length(s) do
    begin
      if (i+4 <= length(s)) then
        if copy(s,i,5) = 'Danil' then
         inc(kq);
      if (i+3 <= length(s)) then
        if copy(s,i,4) = 'Olya' then
        inc(kq);
      if (i+4 <= length(s)) then
        if copy(s,i,5) = 'Slava' then
         inc(kq);
      if (i+2 <= length(s)) then
        if copy(s,i,3) = 'Ann' then
         inc(kq);
      if (i+5 <= length(s)) then
        if copy(s,i,6) = 'Nikita' then
         inc(kq);
    end;
  if kq = 1 then
   write('YES')
   else
   write('NO');
end.


var a,b,c,d,i,j,k,l,m,n,rst,x,y:longint; s,way,s1:string; Z:array['A'..'Z'] of byte; ch:char;
T:array[0..3,0..14] of char;

Procedure PrintArray;
var i,j:longint;
begin
for i:=1 to 2 do begin for j:=1 to 13 do write(T[i,j]); writeln; end; writeln;
end;

begin
//assign(input,'d:\input.txt'); reset(input);
//assign(output,'d:\output.txt'); rewrite(output);
readln(way); s:=way;
for i:=1 to 27 do
if Z[s[i]]<>0 then begin rst:=i-Z[s[i]]-1;ch:=s[i]; break;
end else Z[s[i]]:=i;

if rst=0 then begin write('Impossible'); exit; end;

if rst mod 2=0 then
 begin
 a:=rst div 2; b:=Z[ch]+1;
 T[1,13-a]:=ch;
 for i:=13-a+1 to 13 do begin T[1,i]:=s[b]; inc(b); end;
 for i:=13 downto 13-a+1 do begin T[2,i]:=s[b]; inc(b); end;
 s1:=copy(s,1,Z[ch]-1); delete(s,1,Z[ch]+rst); s:=s+s1;
 x:=13-a; y:=2; c:=length(s);
 while c>0 do
  begin
  T[y,x]:=s[c]; c:=c-1;
  if y=1 then inc(x);
  if y=2 then dec(x); if x=0 then begin y:=1; x:=1; end;
  end;
 end;

if rst mod 2=1 then
 begin
 a:=rst div 2; b:=Z[ch]+1;
 T[1,13-a]:=ch;
 for i:=13-a+1 to 13 do begin T[1,i]:=s[b]; inc(b); end;
 for i:=13 downto 13-a do begin T[2,i]:=s[b]; inc(b); end;
 s1:=copy(s,1,Z[ch]-1); delete(s,1,Z[ch]+rst); s:=s+s1;
 x:=13-a-1; y:=2; c:=length(s);
 while c>0 do
  begin
  T[y,x]:=s[c]; c:=c-1;
  if y=1 then inc(x);
  if y=2 then dec(x); if x=0 then begin y:=1; x:=1; end;
  end;
 end;

PrintArray;
end.


var n,k,i,j,c:longint;
    q:boolean;
    a:array [1..20] of longint;
begin
     readln(n,k);
     j:=2;
     c:=0;
     q:=true;
     for i:=1 to k do
     begin
          while (n mod j<>0) and (j<=n) do inc(j);
          if j<=n then
          begin
               inc(c);
               a[c]:=j;
               n:=n div j;
          end
          else q:=false;
     end;
     if c<k then q:=false;
     if n>1 then a[c]:=a[c]*n;
     if q=false then writeln(-1)
     else for i:=1 to k do
     if i<>k then write(a[i],' ') else writeln(a[i]);
     readln;
end.


Var n,m:int64;
Begin
Readln(n,m);
If m=1 then writeln(n-1) else writeln((m-1)*n);
End.


var
  i,s1,s2,n:longint;
  x:char;
begin
  readln(n);
  for i:=1 to n do
  begin
    read(x);
    if x='1' then inc(s1) else inc(s2);
  end;
  if (s1=0) then begin writeln(0);exit;end;
  if s1>=1 then write(1);
  for i:=1 to s2 do write(0);
  writeln;
end.


var
  i, sg, j, xx: integer;
  a, su, b, c, d, e, f: array [1..11] of string;

begin
  for i := 1 to 10 do readln(a[i]);

  sg := 1;

  su[1] := '.XXXX';su[2] := 'X.XXX';su[3] := 'XX.XX';su[4] := 'XXX.X';su[5] := 'XXXX.';

  for i := 1 to 10 do
    for j := 1 to 5 do
      if pos(su[j], a[i]) > 0 then begin
        write('YES');
        exit;
      end;

  for i := 1 to 10 do
  begin
    b[i] := '          ';
    c[i] := '          ';
    d[i] := '          ';
    e[i] := '          ';
    f[i] := '          ';
  end;

  for i := 1 to 10 do
    for j := 1 to 10 do
      b[i][j] := a[j][i];

  for i := 1 to 10 do
    for j := 1 to 5 do
      if pos(su[j], b[i]) > 0 then begin
        write('YES');
        exit;
      end;

  for i := 1 to 10 do
    for j := 1 to 11 - i do
      if (i + j - 1) <= 10 then c[i][j] := a[j][i + j - 1];

  for i := 1 to 10 do
    for j := 1 to 5 do
      if pos(su[j], c[i]) > 0 then begin
        write('YES');
        exit;
      end;

  for i := 1 to 10 do
    for j := 1 to 11 - i do
      if (i + j - 1) <= 10 then d[i][j] := a[j + i - 1][j];

  for i := 1 to 10 do
    for j := 1 to 5 do
      if pos(su[j], d[i]) > 0 then begin
        write('YES');
        exit;
      end;

  for i := 1 to 10 do
    for j := 1 to 11 - i  do
      if (j + i - 1) <= 10 then e[i][j] := a[11- j ][j + i - 1];

  for i := 1 to 10 do
    for j := 1 to 5 do
      if pos(su[j], e[i]) > 0 then begin
        write('YES');
        exit;
      end;

  for i := 1 to 10 do
    for j := 1 to 11 - i do
      if (i + j - 1) <= 10 then f[i][j] := a[11 - (j - 1 + i)][j];

  for i := 1 to 10 do
    for j := 1 to 5 do
      if pos(su[j], f[i]) > 0 then begin
        write('YES');
        exit;
      end;
  writeln ('NO');

end.


var n,i,sum,j,max:longint;
s,c,st:string;
begin
//assign(input,'two.in');reset(input);
//assign(output,'two.out');rewrite(output);
readln(n);readln(s);
for i:=2 to n do
  begin
  c:=s[i-1]+s[i];sum:=0;
  for j:=2 to n do
    if s[j-1]+s[j]=c then inc(sum);
  if sum>max then begin max:=sum;st:=c;end;
  end;
writeln(st);
close(input);close(output);
end.


var
  k,
  a,
  b,
  v,
  n,
  nb,
  nk:integer;

begin
  readln(k,a,b,v);
  n:=0;
  if a mod v = 0 then nk:=a div v else nk:=a div v + 1;
  nb:=b div (k-1);
  if (nk>=nb*(k-1)) and (nk>0) then begin
      n:=nb;
      nk:=nk - nb*k;
    end else if (nk>0) then begin
      if (nk mod k>0) then n:=(nk div k) + 1
      else n:=(nk div k);
      nk:= 0;
    end;
  nb:=b mod (k-1) + 1;
  if (nk<=nb) and (nk>0)then begin
      n:=n+1;
      nk:=0;
    end else if (nk>0) then begin
      n:=n+1;
      nk:=nk-nb;
    end;
  n:=n+nk;
  writeln(n);
end.


var a,b,c, max: LongInt;
begin
  Readln(a,b,c);

  if a>b then max:=a else max:=b;
  if c>=max then max:=c;

  if odd(max) then
  begin
    if (max=c) then Writeln(30+((max+1) div 2)*3 - 1) else
    if (max=b) then Writeln(30+((max+1) div 2)*3 - 2) else
    Writeln(30+((max+1) div 2)*3 - 3);
  end else
  begin
    if (max=c) or (max-1=c) then Writeln(30+((max+1) div 2)*3 - 1) else
    if (max=b) or (max-1=b) then Writeln(30+((max+1) div 2)*3 - 2) else
    Writeln(30+((max+1) div 2)*3 - 3);
  end;
end.


program cdiv2_cf_476;
var
        a,b:int64;
        res,x,y,hn:int64;
begin
        hn:=trunc(1e9+7);
        readln(a,b);
        x:=((b*(b-1)) div 2) mod hn;
        y:=((a*(a+1)) div 2) mod hn;
        y:=(y*b) mod hn;
        y:=(y+a) mod hn;
        res:=(x*y) mod hn;
        writeln(res);
end.


Program bv1;
var
 n : longint;
begin
readln (n);
if (n mod 4 = 0) or ( n mod 7 = 0 )or ( n mod 74 = 0 )
or ( n mod 47 = 0 )or ( n mod 774 = 0 )or ( n mod 474 = 0 )
or ( n mod 447 = 0 ) or ( n mod 477 = 0 )or ( n mod 747 = 0 )
then write ('YES')
else write ('NO');
end.


var
x,a,b,c:int64;
i,j,k:longint;
res,s:int64;
mas:array[1..2010000] of int64;
function f(x:int64):int64;
var
k,y,n,c,d:int64;
begin
if(mas[x]<>-1)
then f:=mas[x]
else begin
  if x = 1 then k:=1
  else k:=2;
  y:=2;
  while y*y < x do begin
    if x mod y = 0 then inc(k,2);
    y:=y+1;
  end;
  if y*y = x then k:=k+1;
mas[x]:=k;
  f:=k;
end;
end;
begin
read(a,b,c); s:=0;
for i:=1 to 2010000 do
mas[i]:=-1;
for i:=1 to a do
for j:=1 to b do
for k:=1 to c do
s:=s+f(i*j*k);
writeln(s mod 1073741824);
end.


Uses Math;
Const
   fin='';
   fon='';
Var
   n,v,e,dem: Longint;
   A,B: array[0..400] of Longint;
   x,y,z: array[0..190000] of Longint;
   cha: array[0..400,0..400] of Longint;
   Adj,mark: array[0..400,0..400] of Boolean;
Procedure Start;
   Begin
      assign(input,fin);
      reset(input);
      assign(output,fon);
      rewrite(output);
   End;
Procedure Solve(s,t,val: Longint);
   Begin
      A[s]:=A[s]-val;
      A[t]:=A[t]+val;
      Inc(dem);
      x[dem]:=s;
      y[dem]:=t;
      z[dem]:=val;
   End;
Procedure Work(s,t,val: Longint);
   Var tmp,tam: Longint;
   Begin
      if s=t then Exit;
      tmp:=cha[s,t];
      tam:=Min(val,A[tmp]);
      Solve(tmp,t,tam);
      Work(s,tmp,val);
      if tam < val then
         Solve(tmp,t,val-tam);
   End;
Procedure Programe;
   Var chay,i,j,u,v: Longint;
   Begin
      fillchar(Adj,sizeof(Adj),False);
      read(n,v,e);
      for i:=1 to n do read(A[i]);
      for i:=1 to n do read(B[i]);
      for i:=1 to e do
      begin
         read(u,v);
         Adj[u,v]:=True;
         Adj[v,u]:=True;
      end;
      mark:=Adj;
      for i:=1 to n do
         for j:=1 to n do
            if Adj[i,j] then cha[i,j]:=i;
      for chay:=1 to n do
         for i:=1 to n do
            for j:=1 to n do
               if not mark[i,j]
               and mark[i,chay]
               and mark[chay,j] then
               begin
                  mark[i,j]:=True;
                  cha[i,j]:=cha[chay,j];
               end;
      dem:=0;
      for i:=1 to n do
         for j:=1 to n do
         begin
            if A[i] >= B[i] then Break;
            if mark[i,j] and (A[j] > B[j]) then
               Work(j,i,Min(A[j]-B[j],B[i]-A[i]));
         end;
      for i:=1 to n do
         if A[i] <> B[i] then
         begin
            writeln('NO');
            Halt;
         end;
      writeln(dem);
      for i:=1 to dem do
         writeln(x[i],' ',y[i],' ',z[i]);
   End;
Procedure Finish;
   Begin
      close(input);
      close(output);
   End;
Begin
   Start;
   Programe;
   Finish;
End.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
n,m,d,k,i,o:integer;
begin
read(n,m);
d:=(n*(n+1))div 2;
m:=m mod d;
i:=1;
while i*(i+1)div 2<=m do
begin
inc(i);
end;
writeln(m-i*(i-1)div 2);
read(i);
end.


var
i,j,k,m,n:longint;
s:ansistring;
begin
    readln(m);
    readln(s);
    for i:=1 to length(s) do
    if (s[i]<>'4')and(s[i]<>'7')then begin n:=1;break; end;
    if n=1 then
    begin
        writeln('NO');
        exit;
    end
    else
    begin
        for i:=1 to m div 2 do
        begin
            val(s[i],n);
            k:=n+k;
        end;
        for i:=m div 2+1 to m do
        begin
            val(s[i],n);
            j:=j+n;
        end;
        if j=k then writeln('YES')
        else writeln('NO');
    end;
end.


var x:longint;
begin
  readln(x);
  case x and 3 of
    0:writeln('1 A');
    1:writeln('0 A');
    2:writeln('1 B');
    3:writeln('2 A');
  end;
end.


program feda;

var s,t:string;
i,j,size:integer;

begin
readln(s);
readln(t);
size:= length(s);

while s[size] = 'z' do begin
s[size] := 'a';
size:=size-1;
end;

s[size]:=succ(s[size]);

if s <> t then writeln(s)
else writeln('No such string');

end.


program Shablon;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;

var
  d : array[0..800000] of int64;
  t, nok, a, b, ans : int64;
  w, i, j, k : integer;

function nod(a, b : int64):int64;
var
  r : int64;
begin
  while b > 0 do begin
    r := a mod b;
    a := b;
    b := r;
  end;
  result := a;
end;

begin
  {$IFNDEF ONLINE_JUDGE}
  reset(input, 'input.txt');
  rewrite(output, 'output.txt');
  {$ENDIF}
  read(a, b, k);
  nok := 1;
  for i := 2 to k do begin
    nok := (i * nok) div (nod(i, nok));
  end;
  d[0] := 0;
  d[1] := 1;
  for i := 1 to 2*nok do begin
    d[i] := maxlongint;
  end;
  if a - b <= nok then begin
    if a mod nok < b mod nok then
      w := nok else
      w := 0;
    d[a mod nok + w] := 0;
    for i := a mod nok + w downto b mod nok do begin
      if i > 0 then
        d[i - 1] := min(d[i - 1], d[i] + 1);
      for j := 2 to k do
        if i mod j <= i then
        d[i - i mod j] := min(d[i - i mod j], d[i] + 1);

    end;
    write(d[b mod nok]);
    halt;
  end;
  for i := 0 to nok - 1 do begin
    d[i + 1] := min(d[i + 1], d[i] + 1);
    for j := 2 to k do begin
      if (i mod j = 0) then
        for w := 1 to j - 1 do
          if i + w < nok then
            d[i + w] := min(d[i + w], d[i] + 1);
    end;
  end;

  t := a div nok - b div nok;
  ans := d[a mod nok] + t + (t - 1) * d[nok - 1];
  d[nok - 1] := 0;
  for i := 0 to nok - 2 do
    d[i] := maxlongint;
  for i := nok - 1 downto 1 do begin
    d[i - 1] := min(d[i - 1], d[i] + 1);
    for j := 2 to k do begin
      if i mod j <= i then
        d[i - i mod j] := min(d[i - i mod j], d[i] + 1);
    end;
  end;
    ans := ans + d[b mod nok];

  write(ans);
end.


var
b,w,i,j:integer;
c:string;
begin
for j:=1 to 8 do
begin
readln(c);
for i:=1 to length(c) do
begin
if(c[i]='Q')then w:=w+9;
if(c[i]='R')then w:=w+5;
if(c[i]='P')then w:=w+1;
if(c[i]='B') or (c[i]='N')then w:=w+3;
if(c[i]='q')then b:=b+9;
if(c[i]='r')then b:=b+5;
if(c[i]='p')then b:=b+1;
if(c[i]='b') or (c[i]='n')then b:=b+3;
end;
end;
if(b>w)then writeln('Black');
if(w>b)then writeln('White');
if(b=w)then writeln('Draw');
end.


var
  n,m:int64;

begin
  read(n,m);
  if (n=1)or(m=1)then begin
    writeln(n+m-1);
    exit;
  end;
  if (n=2)or(m=2)then begin
    n:=(n+m-2);
    if ((n-1)mod 4=0)then writeln(n+1) else writeln(n+((4-(n mod 4))mod 4));
    exit;
  end;
  writeln((n*m+1) div 2);
end.


var i,n:byte;
res:longint;
    s:string;
procedure xuli2(j:byte);
begin
        while (j<=n) do
        begin
                if (s[j]='Q') then inc(res);
                inc(j);
        end;
end;

procedure xuli1(j:byte);
begin
        while (j<=n) do
        begin
                if (s[j]='A') then
                        xuli2(j+1);
                inc(j);
        end;
end;

begin
        readln(S);
        n:=length(S);
        i:=1;
        res:=0;
        while (i<=n) do
                begin
                        if (s[i]='Q') then xuli1(i+1);
                        inc(i);
                end;
        writeln(res);
        readln;
end.


program Codecr;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
s:array[1..12] of string;
k:array[1..1000] of string;
a,i,n,j,l,m,b:longint;
c:string;
begin
s[1]:='January';
s[2]:='February';
s[3]:='March';
s[4]:='April';
s[5]:='May';
s[6]:='June';
s[7]:='July';
s[8]:='August';
s[9]:='September';
s[10]:='October';
s[11]:='November';
s[12]:='December';
readln(c); read(n); j:=0; l:=0;
for i:=1 to 12 do
begin
if(c=s[i]) then l:=i;
end;
for i:=l to l+12 do
begin
if (i<=12) then k[i]:=s[i];
if (i>12) then k[i]:=s[i-12];
end;
for i:=1 to l+12 do
begin
k[i]:=k[i+l-1];
end;
a:=n;
if (n>12) then
for i:=1 to a div 12 do
begin
n:=n-12;
end;

for i:=1 to n+1 do
begin
c:=k[i];
end;
write(c);
end.


const
      rp=1000000007;
type
     martix=array[0..84,0..84] of int64;
var
    k,i,j,m:longint;
    a,b,c:martix;
    n:int64;

function times(a,b:martix;x,y,z:longint):martix;
var
    c:martix;
    i,j,k:longint;
begin
  for i:=1 to x do
    for j:=1 to y do
      begin
        c[i,j]:=0;
        for k:=1 to z do
          c[i,j]:=(c[i,j]+a[i,k]*b[k,j]) mod rp;
      end;
  exit(c);
end;

begin {main}
  readln(n,k);
  for i:=0 to k do
    begin
      c[i,0]:=1;c[i,i]:=1;
      for j:=1 to i-1 do c[i,j]:=c[i-1,j]+c[i-1,j-1];
    end;
  m:=2*(k+1)+1;
  b[1,1]:=1;b[m,1]:=1;
  for i:=0 to k do
    for j:=0 to i do
      begin
        b[j+k+3,i+2]:=c[i,j];b[j+2,i+k+3]:=c[i,j];b[j+k+3,i+k+3]:=c[i,j];
      end;
  a[1,0]:=0;for i:=2 to m do a[1,i]:=1;
  while n<>0 do
    begin
      if n mod 2=1 then a:=times(a,b,1,m,m);
      b:=times(b,b,m,m,m);
      n:=n div 2;
    end;
  writeln(a[1,1]);
end.


uses math;
var x1,x2,y1,y2,n:int64;

begin
  readln(x1,y1,x2,y2);
  n:=abs(x1-x2);
  writeln(((n div 2)+1) * ((abs(y1 - y2) div 2) + 1) + (n div 2) * (abs(y1 - y2) div 2))
  {if n mod 4 = 2
    then
      writeln(((n div 4) - 1) * 3 + ((n div 4) - 1) * 2)
    else
      writeln((n div 4) * 3 + ((n div 4) - 1) * 2);}
end.


var
  p,q,res,count,now,d,num:int64;
Function Snt(gt:int64):boolean;
var iv:Longint;
begin
  if gt<=1 then exit(false);
  for iv:=2 to trunc(sqrt(gt)) do
    if gt mod iv=0 then exit(false);
  exit(true);
end;
Function Pali(x:int64):boolean;
var ee:string;
    i:longint;
begin
  if x=0 then exit(false);
  str(x,ee);
  for i:=1 to length(ee) shr 1 do
  if ee[i]<>ee[length(ee)-i+1] then exit(false);
  exit(true);
end;
begin

  readln(p,q);
  count:=0;
  num:=0;
  now:=0;
  d:=0;
  Res:=-1;
  repeat
    if pali(num) then inc(now);
    if snt(num) then inc(count);
    If q*count<=p*now then res:=num;
    inc(num);

  Until count>44*now;

  If res=-1 then writeln('Palindromic tree is better than splay tree')
  else writeln(res);

end.


var n,m,i,k,l1,l2,l3,p:int32;
a:array[1..1100] of int32;
begin

read(n);
for i:=1 to n do
  read(a[i]);
  l1:=1;
  l2:=1;
for i:=1 to n do
  begin
    if ((l3=0) and (a[i]=3)) or ((l2=0) and (a[i]=2)) or ((l1=0) and (a[i]=1)) then p:=1;
    if a[i]=1 then
      begin
        if l2=0 then
          begin
            l2:=1;
            l3:=0;
          end
          else
          begin
            l3:=1;
            l2:=0;
          end;
      end;
    if a[i]=2 then
    begin
      if l1=0 then
          begin
            l1:=1;
            l3:=0;
          end
          else
          begin
            l3:=1;
            l1:=0;
          end;
    end;
    if a[i]=3 then
    begin
      if l2=0 then
          begin
            l2:=1;
            l1:=0;
          end
          else
          begin
            l1:=1;
            l2:=0;
          end;
    end;

  end;
  if p=1 then write('NO') else write ('YES');
end.


var
     T,S,q,ans:Longint;
begin
     Readln(T,S,q);
     while S<T do
begin
     Inc(ans);
     S:=q*S;
 end;
     Writeln(ans);
 end.


 uses Math;
 var n,a,b,c,l:longint;
begin
 readln(n);
 dec(n);
 readln(a);
 readln(b);
 readln(c);
 l:=0;
 if n>0 then begin
   l:=min(a,b);
 dec(n);
 end;
 inc(l,n*( min( c,min(a,b) ) ));
 writeln(l);
end.


var
     S,S1:String;
     kol,Ans,i,N:Longint;
     A,maxkol,answer:array ['A'..'T'] of Longint;
begin
     Readln(S);
     kol:=1;
     N:=Length(S);
     S:=S+' ';
     for i:=2 to N+1 do
     if S[i]=S[i-1] then Inc(kol)
                    else begin
                              if kol mod 2=0 then begin
                                                       Inc(Ans);
                                                   end;
                              kol:=1;
                            end;
     Writeln(Ans);
 end.


const
   fin='680A.inp';fon='680A.out';
var i,a,s,m:longint;
   d:array[0..10000] of longint;

function max(t,u:longint):longint;
begin
if u<t then exit(t);
exit(u);
end;

function min(t,u:longint):longint;
begin
if u>t then exit(t);
exit(u);
end;

procedure mo;
begin
assign(input,fin);reset(input);
assign(output,fon);rewrite(output);
end;

procedure solve;
begin
s:=0;
for i:=1 to 5 do
   begin
   read(a);
   s:=s+a;
   inc(d[a]);
   if d[a]>1 then
      begin
      m:=max(m,a*min(3,d[a]));
      end;
   end;
writeln(s-m);
end;

begin
//mo;
solve;
end.


{$mode objfpc}
//basic geometry defination
const inf=1e30;
	eps=1e-10;
type	float=extended;
	point=object
			x,y:float;
			function length():float;
			function sqrlen():float;
			function zoom(const l:float):point;
			function vtl():point;
		end;
	line=	object
			a,b:point;
                  function online(const p:point):boolean;
                  function intersect(const s:line):longint;
		end;
	function sgn(const x:float):longint; begin if abs(x)<eps then exit(0); if x>0 then exit(1) else exit(-1); end;
	function fsqrt(const x:float):float; begin if abs(x)<eps then exit(0) else exit(sqrt(x)); end;
	operator +(const a,b:point)c:point; begin c.x:=a.x+b.x; c.y:=a.y+b.y; end;
	operator -(const a,b:point)c:point; begin c.x:=a.x-b.x; c.y:=a.y-b.y; end;
	operator *(const a:point; const b:float)c:point; begin c.x:=a.x*b; c.y:=a.y*b; end;
	operator /(const a:point; const b:float)c:point; begin c.x:=a.x/b; c.y:=a.y/b; end;
	operator *(const a,b:point)c:float; begin c:=a.x*b.y-a.y*b.x; end;
	operator /(const a,b:point)c:float; begin c:=a.x*b.x+a.y*b.y; end;
	function point.length():float; begin exit(fsqrt(x*x+y*y)); end;
	function point.sqrlen():float; begin exit(x*x+y*y); end;
	function point.zoom(const l:float):point; begin exit(self*(l/self.length)); end;
	function point.vtl():point; begin vtl.x:=-y; vtl.y:=x; end;
	operator *(const a,b:line)c:point; var s1,s2:extended;
	begin s1:=(a.b-a.a)*(b.a-a.a); s2:=(a.b-a.a)*(b.b-a.a);
		exit((b.a*s2-b.b*s1)/(s2-s1));
	end;
      function line.online(const p:point):boolean; begin exit((sgn((p-a)*(p-b))=0)and(sgn((p-a)/(p-b))<1)); end;
	function line.intersect(const s:line):longint;
	var d1,d2,d3,d4:longint;
	    f1,f2,f3,f4:boolean;
	begin //0=no 1=proper 2=improper,dot 3=improper,segment
		d1:=sgn((b-a)*(s.a-a));
		d2:=sgn((b-a)*(s.b-a));
		d3:=sgn((s.b-s.a)*(a-s.a));
		d4:=sgn((s.b-s.a)*(b-s.a));
		if (d1 xor d2=-2)and(d3 xor d4=-2) then exit(1);
		f1:=online(s.a);
		f2:=online(s.b);
		f3:=s.online(a);
		f4:=s.online(b);
		if (not f1)and(not f2)and(not f3)and(not f4) then exit(0);
		if (d1=0)and(d2=0)and(d3=0)and(d4=0) then exit(3);
		exit(2);
	end;
var
wall,mirror:line;

function can(p1,p2:point):boolean;
var L1:line;
begin p1:=p2+(p1-p2)*0.99999;
	p2:=p1+(p2-p1)*0.99999;
	L1.a:=p1; L1.b:=p2;
	exit((wall.intersect(L1)=0)and(mirror.intersect(L1) in [0,3]));
end;

procedure lemon();
var p1,p2,p,ref,hit:point;
    L1:line;
begin readln(p1.x,p1.y);
	readln(p2.x,p2.y);
	readln(wall.a.x,wall.a.y,wall.b.x,wall.b.y);
	readln(mirror.a.x,mirror.a.y,mirror.b.x,mirror.b.y);
	if sgn((mirror.b-mirror.a)*(p1-mirror.a))*sgn((mirror.b-mirror.a)*(p2-mirror.a))=1 then
	begin L1.a:=p1; L1.b:=p1+(mirror.a-mirror.b).vtl;
		p:=L1*mirror; ref:=p+p-p1;
		L1.a:=ref; L1.b:=p2; hit:=L1*mirror;
            if mirror.online(hit) then
			if can(hit,p1) and can(hit,p2) then begin writeln('YES'); exit; end;
	end;
	if can(p1,p2) then writeln('YES') else writeln('NO');
end;

begin
{$ifndef ONLINE_JUDGE}
	assign(input,'32E.in');
	reset(input);
{$endif}
lemon();
end.


var m,j,i,k,l,k1,ans,temp,x,y,n:longint;
s,r:string;

procedure rec(s:string);
var c:char;i,q:longint;
temp:int64;
 begin
  val(s,temp);
  if temp>n then exit;
  inc(ans);
  q:=0;
  for i:=1 to 10 do
   if pos(r[i],s)<>0 then inc(q);
  if q=1 then
        begin
         for c:='0' to '9' do
           rec(s+c);
        end else
        begin
         for i:=1 to 10 do
          if pos(r[i],s)<>0 then
           rec(s+r[i]);
        end;
 end;

begin
{assign(input,'input.txt');reset(input);
assign(output,'output.txt');rewrite(output); }
readln(n);
r:='0123456789';
for i:=1 to 9 do
  begin
   x:=i;
   rec(chr(x+48));
  end;
writeln(ans);
end.


var a:array[0..30] of int64;
a1,a2,a3,i:longint;
begin
   read(a1,a2,a3);
   a[0]:=a1;
   a[1]:=a2;
   for i:=2 to a3 do
      a[i]:=a[i-1]+a[i-2];
   writeln(a[a3]);
end.


var a,b:array[1..505000] of longint;
n,i,beg1,beg2,k1,k2,k,aa,bb:longint;

procedure put1(t:longint);
begin
   inc(k1);
   a[k1]:=t;
end;

procedure put2(t:longint);
begin
   inc(k2);
   b[k2]:=t;
end;

procedure give1(var t:longint);
begin
   inc(beg1);
   t:=a[beg1];
end;

procedure give2(var t:longint);
begin
   inc(beg2);
   t:=b[beg2];
end;

begin
readln(n);
read(k1);
for i:=1 to k1 do
   read(a[i]);
read(k2);
for i:=1 to k2 do
   read(b[i]);
while (beg1<>k1) and (beg2<>k2) do
   begin
      inc(k);
      give1(aa);
      give2(bb);
      if aa>bb then begin put1(bb);put1(aa); end
               else begin put2(aa);put2(bb); end;
      if k=500000 then begin writeln(-1); exit; end;
   end;
write(k,' ');
if beg1=k1 then writeln(2)
           else writeln(1);
end.


const   fi='991B.inp'; fo='991B.out';
var     n,res,sum,i:longint;
        a:array[0..101] of longint;
procedure QS(l,r:longint);
var i,j,g,tam: longint;
begin
        i:=l; j:=r; g:=a[(l+r)>>1];
        repeat
          while a[i]<g do inc(i);
          while a[j]>g do dec(j);
          if i<=j then
          begin
            tam:=a[i]; a[i]:=a[j]; a[j]:=tam;
            inc(i); dec(j);
          end;
        until i>j;
        if i<r then QS(i,r);
        if j>l then QS(l,j);
end;
begin
   //     assign(input,fi); reset(input);
     //   assign(output,fo); rewrite(output);
        readln(n);
        for i:=1 to n do begin
          read(a[i]);
          sum:=sum+a[i];
        end;
        QS(1,n);
        res:=1;
        while sum*10<n*45 do
        begin
          sum:=sum+5-a[res];
          inc(res);
        end;
        writeln(res-1);
end.


var i,n,k:longint;
BEGIN
readln(n);
for i:=1 to n do
 begin
 readln(k);
 writeln(k div 2);
 end;
END.


program qwe;
{$APPTYPE CONSOLE}
{$MAXSTACKSIZE $00200000}
{$O-}

uses
  SysUtils,
  Math;

//it is a big shablon. if you see any strange function, never mind

const base = 1000000007;
 eps = 1e-8;
 inf = 1 shl 30;

type
 TArray = array[0..10000010] of integer;
 int53 = int64;
 itneger = integer;
 point = record
  x, y: integer;
 end;

function sqrr(a, b: int64): int64;
var
 dega, res: int64;
begin
 res := 1;
 dega := a;
 while b > 0 do
 begin
  if odd(b) then res := res * dega;
  dega := dega * dega;
  b := b div 2;
  res := res mod base;
  dega := dega mod base;
 end;
 result := res mod base;
end;

function less(x, y: point): boolean;
begin
 if (x.x < y.x) or ((x.x = y.x) and (x.y < y.y)) then result := true else result := false;
end;

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

procedure swap64(var x, y: int64);
var
 z: int64;
begin
 z := x;
 x := y;
 y := z;
end;

procedure swapex(var x, y: extended);
var
 z: extended;
begin
 z := x;
 x := y;
 y := z;
end;

procedure swapp(var x, y: point);
var
 z: point;
begin
 z := x;
 x := y;
 y := z;
end;

procedure panic;
begin
 writeln(-1);
 halt(0);
end;

var
 n, m, k, g: integer;
 ans, v, s: int64;

begin
 {$IFNDEF ONLINE_JUDGE}
 reset(input, 'input.txt');
 rewrite(output, 'output.txt');
 {$ENDIF}
 readln(n, m, g);
 ans := 0;
 if m = 0 then
 begin
  writeln(g xor (n mod 2));
  halt(0);
 end;
 m := m - 1;
 if m = 0 then
 begin
  if g = 0 then ans := (n + 1) div 2 else ans := n div 2;
  if (n + 1) mod 2 = g then inc(ans);
  writeln(ans);
  halt(0);
 end;
 k := (n + g) mod 2;
 if k = 0 then s := 1 else s := m + 1;
 while n >= k do
 begin
  ans := ans + s;
  v := (k + m + 2);
  v := v * (v - 1) mod base;
  s := (s * v) mod base;
  v := k + 2;
  v := v * (k + 1) mod base;
  v := sqrr(v, base - 2);
  s := (s * v) mod base;
  k := k + 2;
 end;
 writeln(ans mod base);
end.


var

x,y,i,Her,Posi,Her_l,val_i,Err,k:integer;
n,val_s:string;
a:array[1..3,1..3] of integer;
Val_val:array[0..4,0..4] of integer;
begin
  for x:= 1 to 3 do
    begin
    Readln (n);
        for y:= 1 to 3 do
          begin
          if y = 3 then
            begin
              val(n,val_i,Err);
              a[x,y]:= val_i;
              Val_val[x,y]:= 1;
            end
            else
            begin
          Her:= length(n);
          Posi:=pos(' ',n);
          Her_l:= Her - Posi;
          Her_l:= Her - Her_l - 1;
          val_s:= Copy(n,1,Her_l);
          val(val_s,val_i,Err);

          Delete(n,1,Her_l+1);
          a[x,y]:= val_i;
           Val_val[x,y]:= 1;
            end;
          end;
    end;
   For x:= 1 to 3 do
    begin
      for y:= 1 to 3 do
        begin
          for k:= 1 to a[x,y] do
            begin
          if ((a[x,y]<>0) or (a[x,y] mod 2 <> 0)) then
          begin
             if Val_val[x,y] = 0 then
              begin
                Val_val[x,y]:= 1;
                  if Val_val[x+1,y] = 0 then
                    begin
                      Val_val[x+1,y]:= 1;
                    end
                    else Val_val[x+1,y]:= 0;
                    if Val_val[x-1,y] = 0 then
                    begin
                      Val_val[x-1,y]:= 1;
                      //1 0 1
                       // 8 8 8
                        //2 0 3
                    end
                    else Val_val[x-1,y]:= 0;

                    if Val_val[x,y+1] = 0 then
                    begin
                      Val_val[x,y+1]:= 1;
                    end
                    else Val_val[x,y+1]:= 0;
                    if Val_val[x,y-1] = 0 then
                    begin
                      Val_val[x,y-1]:= 1;
                    end
                    else Val_val[x,y-1]:= 0;

              end
              else
              begin
              Val_val[x,y]:= 0;
              if Val_val[x+1,y] = 0 then
                    begin
                      Val_val[x+1,y]:= 1;
                    end
                    else Val_val[x+1,y]:= 0;
                    if Val_val[x-1,y] = 0 then
                    begin
                      Val_val[x-1,y]:= 1;
                    end
                    else Val_val[x-1,y]:= 0;

                    if Val_val[x,y+1] = 0 then
                    begin
                      Val_val[x,y+1]:= 1;
                    end
                    else Val_val[x,y+1]:= 0;
                    if Val_val[x,y-1] = 0 then
                    begin
                      Val_val[x,y-1]:= 1;
                    end
                    else Val_val[x,y-1]:= 0;
              end;
          end;

    end;
          end;
        end;

    for x:= 1 to 3 do
      begin
        for y:= 1 to 3 do
          begin
            write (Val_val[x,y]);
          end;
          writeln(' ');
      end;

end.


var
cnk:array[0..123,0..123]of int64;
res,n,t,c,ans:int64;
i,j:longint;
function get(n,c:int64):int64;
var
p,i:longint;
s:string;
begin
  s:='';
  while n>0 do
   begin
     s:=chr(n mod 2+48)+s;
     n:=n div 2;
   end;
  p:=0; res:=0;
  for i:=1 to length(s) do
   begin
      if s[i]='0' then continue;
      res:=res+cnk[length(s)-i,c-p];
      if s[i]='1' then inc(p);
      if p>c then break;
   end;
  if p=c then inc(res);
  get:=res;
end;
 begin
    readln(n,t);
    c:=1;
    for i:=0 to 60 do
     cnk[i,0]:=1;
    for i:=1 to 60 do
     for j:=1 to 60 do
      cnk[i,j]:=(cnk[i-1,j-1]+cnk[i-1,j]) mod 1000000000000000;
    while t mod 2=0 do
     begin
       t:=t div 2;
       inc(c);
     end;
    if t<>1 then
     begin
      writeln(0);
      halt(0);
     end;
    ans:=get(n+1,c);
    if (c=1) then ans:=ans-1;
    writeln(ans);
 end.


var
  a,b,k,i,n: longint;
  p: array[1..55555] of longint;
function ok(a: longint): boolean;
var i: longint;
  begin
    i:=2;
    while int64(i)*(i) <= a do begin
      if a mod i=0 then exit(false);
      inc(i);
    end;
    exit(true);
  end;
function kq(a,n: longint): longint;
var res,i: longint;
  begin
    if (n=0) or (a<p[n]) then exit(0);
    a:=a div p[n];
    res:=a;
    for i:=1 to n-1 do res:=res-kq(a,i);
    exit(res);
  end;
begin
//  assign(input,'aaa.in');reset(input);
//  assign(output,'aaa.out');rewrite(output);
  readln(a,b,k);
  if not ok(k) then begin
    writeln(0);close(output);
    halt;
  end;
  if int64(k)*k > b then begin
    if (a<=k) and (k<=b) then writeln(1)
    else writeln(0);
    close(output);
    halt;
  end;
  for i:=2 to k do
    if ok(i) then
    begin
      inc(n);
      p[n]:=i;
    end;
  writeln(kq(b,n)-kq(a-1,n));
  close(output);
end.


             uses strutils;
           const eps=1e-13;
           besk=2000000000000000000; label 4,1,3,2,44,22;
           type  mas=array[-200000..2600000+1] of int64;
           integer=longint;     zap=record  x,y,z:int64; end;
           zap1=^zap;
           var oldpos,kolvzv,sdvig,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto:longint;
           oldss,smin,ss3,ss,ss1,ss2:string;
           newaans,aans:zap;
           pqqq:zap;
           otal,al1,al2,acc, disk,xxx,yyy,prop,bet,al:extended; fl1,fl2,fl:boolean;
           dr3,dr1,dr2,pt,ott1,ott2:zap;
           pointx,pointy,vel,tt1,tt2,shag,radius,ote,ddl,dl1,dl2:extended;

           x,y,ansx,ansy,ugol,xx,yy:array[-100..500000] of int64;
           det,detx,dety,ii,jj,kk,dl,iii,jjj,aaa,bbb,ccc,bb,aa,ot,p0,t,pos,xmax,xmin,ymax,ymin,newpos,newdl,len,pp3,ans1,ans2,modul,t0,t1,t2,dloch,koldel,mmax,nap,stepen,pq,pp1,pp2,period, dolg,ot1,ot2,oldgr,predsum,pmin,tmin,kool,number,imin,qq,kol,n,m,ttt,numpos,vx,vy,ans,up,down,imax,t3,qq1,qq2,q1,q2,ost,koll,w,dx,dy,time,p3,p4,qqqq,tt,pmax,pmax2,p1,p2,ott,hh,pos0,pos1,pos2,pp,mm,maxot,tmax,nn,n1,q,p:int64; flag1:boolean;
           chisl,znam,zzz,fact,z,stan,a2,invx,invy,summ,place,str,b2,z1,sum1,sum0,d0,d1,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
           ot3,izb, sum,oldmax,newmax,posmax,zapas,razn,oldll,oldrr,ppp,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,cc,dist,ugg,r,ug:int64;
           zan:array[-10..1001,-10..1001] of boolean;
           new,zan2,zan1,prost,marked:array[-10000..11000000] of boolean;
           left,right,newoch,d2,och, num,start,finish,zz,ll,rr,path,lx,a3,b3,predok,a1,b1:array[-200000..955000] of int64;
           dd,koldelit,delit:array[-400..1200,-400..1200] of int64;
           ppole1,ppole2,ppole:array[-100..300,-10..300] of char;
           bufer, str1,str2,stroka:array[-1000..1000000] of char;
           dinam:array[-100000..1000000] of extended;
           cosa,sina,cosb,sinb,rx,ry,px,py,h1,h2,h,l1,l2,otmax,v:int64;
           sss1,sss2,sp,sss:array[-10..110000] of string;
           newpole,pole:array[-1..1100,-1..1100] of char;
           sumstr,sumstolb,nomerpole:array[-1..1100,-1..1100] of longint;
           verch,verzn:array[-10..1100000] of int64;
           ddmax,dd1,dd2,ddinv:array[-2..1100000] of int64;
           zzan:array[-1..1200000] of boolean;
           obmen,ch:char;
           ff,flagg1:boolean;
           newleft,newright,pred,oldx,oldy,numx,numy,xleft,xright,s,znach,newplace,newstr,next,prev,aold:array[-100000..1700002] 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 a2[i]<a2[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];b3[l+step]:=a3[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];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:extended):extended;begin min:=b;if a<b then min:=a;  end;
            function max (a,b:extended):extended; 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:int64;k:int64):int64; var p:int64;    label 4;
              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 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 minus(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;
                minus:=@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;   {(d1<d2)}
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
       p1:=fact[ii];
       p2:=fact[jj];
       p3:=fact[ii-jj];
       t2:=degg(p2,modul-2);
       t3:=degg(p3,modul-2);
       ot:=((p1*t2) mod modul*t3) mod modul;
       bincoef:=ot;
      end;

function sovp:boolean;
var i,j:longint; fl:boolean;
begin
 fl:=true;
 for i:=1 to p do if x[i]<>y[i] then fl:=false;
 sovp:=fl;
end;

        begin
  {  assign (input,'D:\Projects\input.txt');reset(input);
    assign (output,'D:\Projects\output.txt'); rewrite(output);
   }
   read(gr,n);
   if n=1 then begin writeln(gr); goto 1; end;
   modul:=998244353;
   fact[0]:=1; for i:=1 to 600000 do fact[i]:=fact[i-1]*i mod modul;

   for i:=1 to gr shr 1 do
      begin
         p:=gr div i;
        { writeln(bincoef(p-1,n-1));
        } ot:=(ot+bincoef(p-1,n-1)) mod modul;

      end;

    writeln(ot);

   goto 1;

      readln(p);   otal:=1e+10;
    for i:=1 to p do read(x[i],y[i],xx[i],yy[i],z[i]);
    for i:=1 to p do for j:=i+1 to p do
       begin

          if xx[i]*yy[j]=xx[j]*yy[i] then
            begin
              if ((y[j]-y[i])*xx[i]=(x[j]-x[i])*yy[i]) and (xx[i]*(x[j]-x[i])>=0)  then
                begin
                   al:=xx[i]*xx[i]+yy[i]*yy[i];
                   al:=sqrt(al);
                   bet:=xx[i]/al*z[i];
                   al1:=(x[j]-x[i])/bet;
                  { writeln('var 1 t1= ',al1:0:5);
                  } otal:=min(otal,al1);
                end;

                if ((y[i]-y[j])*xx[j]=(x[i]-x[j])*yy[j]) and (xx[j]*(x[i]-x[j])>=0)  then
                begin
                   al:=xx[j]*xx[j]+yy[j]*yy[j];
                   al:=sqrt(al);
                   bet:=xx[j]/al*z[j];
                   al1:=(x[i]-x[j])/bet;
                  { writeln('var 2 t1= ',al1:0:5);
                  } otal:=min(otal,al2);

                end;
         {      writeln('i= ',i,' j= ',j,' ot= ',otal:0:3);
         }   end;

          p1:=yy[i]; p2:=-xx[i]; p3:=-(-x[i]*yy[i]+y[i]*xx[i]);
          pp1:=yy[j]; pp2:=-xx[j]; pp3:=-(-x[j]*yy[j]+y[j]*xx[j]);

         { writeln(p1,' ',p2,' ',p3);
          writeln(pp1,' ',pp2,' ',pp3);
         } det:=p1*pp2-p2*pp1;
          detx:=p3*pp2-p2*pp3;
          dety:=p1*pp3-p3*pp1;

          if det=0 then goto 2;
          pointx:=detx/det;
          pointy:=dety/det;
         { writeln(pointx:0:3,' ',pointy:0:3);
         } al:=xx[i]*xx[i]+yy[i]*yy[i];
          al:=sqrt(al);
          bet:=xx[i]/al*z[i];
          al1:=(pointx-x[i])/bet;
         { writeln('t1= ',al1:0:5);
         } al:=xx[j]*xx[j]+yy[j]*yy[j];
          al:=sqrt(al);
          bet:=xx[j]/al*z[j];
        {  writeln('dx= ',bet:0:4);
        } al2:=(pointx-x[j])/bet;
         { writeln('t2= ',al2:0:5);
         } if (al1>-eps)and(al2>-eps) then bet:=max(al1,al2) else bet:=1e+10;
          otal:=min(otal,bet);
         { writeln('i= ',i,' j= ',j,' ot= ',otal:0:3);
         }

2:
       end;

   if otal<1e+8 then writeln(otal:0:8) else writeln('No show :(');

    1: close (output);
     end.


program cf150b;
const mode=1000000007;
var
  n,m,k,i:longint;
  ans:int64;
begin
  readln(n,m,k);
  if (k=1)or(k>n) then begin
    ans:=1;
    for i:=1 to n do ans:=ans * m mod mode;
    writeln(ans);
    halt;
  end;

  if m=1 then begin
    writeln(1);
    halt;
  end;

  if k=n then begin
    ans:=1;
    for i:=1 to (n+1) shr 1 do
      ans:=ans*m mod mode;
    writeln(ans);
    halt;
  end;

  if not(odd(k)) then begin
    writeln(m mod mode);

  end else begin
    if n=1 then writeln(m) else
    writeln(m*m mod mode);
  end;
end.


program _28E_DravDe_Saves_theWorld;

type vertex=record x,y:extended; inw:boolean; end;
 	 vector=record x,y,z:extended; end;
	 line=record a,b,c:extended; end;

const tiny=1e-9;

var f:array[1..20000]of vertex;
	OA,OB,OC,OW,w,FF:vector;
	lOA,lOB,lFF:line;
	a,itc:vertex;
	ft1,ft2,t1,t2,t3,vdown,k:extended;
	n,i,j,dk,n0:longint;
    find:boolean;

function makeline(v:vector; p:vertex):line;
var t:line;
begin
	t.a:=-v.y;
	t.b:=v.x;
	t.c:=-t.a*p.x-t.b*p.y;
    exit(t);
end;

function hand(b,a:vector):longint;
var t:extended;
begin
	t:=a.x*b.y-a.y*b.x;
	if t>tiny then exit(1);
	if t<-tiny then exit(-1);
	exit(0);
end;

function intersect(l1,l2:line):vertex;
var t:vertex;
begin
	if abs(l1.a*l2.b-l1.b*l2.a)<tiny then begin
		t.x:=1e10;
		exit(t);
	end;
	t.x:=(-l1.c*l2.b+l2.c*l1.b)/(l1.a*l2.b-l2.a*l1.b);
	t.y:=(-l1.c*l2.a+l2.c*l1.a)/(l1.b*l2.a-l2.b*l1.a);
	exit(t);
end;

function doton(i,a,b:vertex):boolean;
begin
    if (a.x-i.x)*(b.x-i.x)<-tiny then exit(true) else exit(false);
end;

function sdv(a,b:vector):boolean;
begin
	if a.x*b.x>0 then exit(true);
	if a.y*b.y>0 then exit(true);
	if a.x*b.x+a.y*b.y=0 then exit(true);
	exit(false);
end;

function qs(a,b:vector):extended;
begin
	if a.x*b.x=0 then exit(a.y/b.y);
	exit(a.x/b.x);
end;

begin
	//assign(input,'28EDravDe.txt');reset(input);
	readln(n);
	for i:=1 to n do readln(f[i].x,f[i].y);
	f[n+1]:=f[1];
	readln(a.x,a.y);
	readln(OA.x,OA.y,OA.z);
	readln(vdown);
	readln(w.x,w.y,w.z);
    k:=OA.z/-w.z;
	OW.x:=w.x*k;
	OW.y:=w.y*k;
	OB.x:=OA.x+OW.x;
	OB.y:=OA.y+OW.y;
    if (OB.x=0)and(OB.y=0) then OB:=OA;
	if (OA.x=0)and(OA.y=0) then OA:=OB;
	if (OA.x=0)and(OA.y=0) then begin writeln('-1 -1');halt; end;
	lOA:=makeline(OA,a);
	lOB:=makeline(OB,a);

	n0:=n+1;
	for i:=1 to n do begin
		FF.x:=f[i].x-f[i+1].x;
		FF.y:=f[i].y-f[i+1].y;
		lFF:=makeline(FF,f[i]);
		itc:=intersect(lOA,lFF);
		if (itc.x<>1e10)and(doton(itc,f[i],f[i+1])) then begin
			inc(n0); f[n0]:=itc;
		end;
		itc:=intersect(lOB,lFF);
		if (itc.x<>1e10)and(doton(itc,f[i],f[i+1])) then begin
			inc(n0); f[n0]:=itc;
		end;
	end;

	if hand(OA,OB)=1 then dk:=1 else dk:=-1;
	for i:=1 to n0 do begin
		OC.x:=f[i].x-a.x; OC.y:=f[i].y-a.y;
		if (dk*hand(OA,OC)>=0)and(dk*hand(OC,OB)>=0) then f[i].inw:=true
        else f[i].inw:=false;
	end;

	ft1:=1e10; ft2:=1e10; find:=false;
	for i:=1 to n0 do if f[i].inw then begin
		OC.x:=f[i].x-a.x; OC.y:=f[i].y-a.y;
        if abs(OA.x*w.y-OA.y*w.x)<tiny then
			if sdv(OA,w) then
				if sdv(OA,OC) then begin t1:=qs(OC,OB); t2:=0; end
					else begin t1:=-1; t2:=-1; end
				else
				if sdv(OA,OC) then begin t1:=qs(OC,OA); t2:=t1*OA.z/(-vdown); end
					else begin t1:=qs(OC,OB); t2:=0; end
        else begin
		    t1:=(OC.x*w.y-OC.y*w.x)/(OA.x*w.y-OA.y*w.x);
		    t3:=(OC.x*OA.y-OC.y*OA.x)/(w.x*OA.y-w.y*OA.x);
	        t2:=(OA.z*t1+w.z*t3)/(-vdown);
        end;
		if (t1<ft1+tiny)and(t1>-tiny) then begin
			ft1:=t1; ft2:=t2;
            find:=true;
		end else if (abs(t1-ft1)<tiny)and(t2>-tiny) then
			if t2<ft2+tiny then ft2:=t2;
	end;
    if find then writeln(ft1:0:8,' ',ft2:0:8) else writeln('-1 -1');
end.


var
 i,j,k,n,m,z:longint;
 f1,f2:array[1..100]of boolean;

procedure check(i:longint);
begin
 if(f1[i])and(not f2[i])then write(1) else
 if(not f1[i])and(f2[i])then write(2) else write(1);
 if i<>k then write(' ') else
 if i=k then writeln;
end;

begin
 readln(k,n,m);
 for i:=1 to n do
 begin
  read(z);
  f1[z]:=true;
 end;
 readln;
 for i:=1 to m do
 begin
  read(z);
  f2[z]:=true;
 end;
 for i:=1 to k do check(i);
end.


const fi='';
      fo='';
var f:text;
a:array[0..1000]of integer;
i,j,s,n:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,n);
        for i:=1 to n do
        read(f,a[i]);

        //1~tron
        //2~tam giac
        //3~vuong
        for i:=1 to n-1 do
        begin
                if a[i]+a[i+1]=3 then
                begin
                        s:=s+3;
                        if a[i]+a[i-1]=4 then dec(s);
                end;
                if a[i]+a[i+1]=4 then s:=s+4;
                if a[i]+a[i+1]=5 then
                begin
                        close(f);

                        assign(f,fo);
                        rewrite(f);
                        write(f,'Infinite');
                        close(f);
                        exit;
                end;
        end;
        close(f);

        assign(f,fo);
        rewrite(f);
        writeln(f,'Finite');
        writeln(f,s);
        close(f);
end.


var n,i:int64;
begin
read(n);
i:=2;
while i<=round(sqrt(n)) do
        begin
        while (n mod sqr(i)=0) do
                begin
                n:=n div i;
                end;
        i:=i+1;
        end;
writeln(n);
end.


var s:ansistring;
n,i,ls,m,t,j:longint;
f:array[0..20000] of longint;ff:boolean;
begin
//assign(input,'mxp.in');reset(input);
//assign(output,'mxp.out');rewrite(output);
readln(s);
readln(n);
for i:=1 to length(s) do
  begin
  if s[i]='?' then begin m:=m+1;f[i]:=0; end else
  if s[i]='*' then begin m:=m+1;f[i]:=0; end else
  f[i]:=1;
  end;

ls:=length(s)-m;t:=1;
if ls>n then
  begin
while t<=length(s) do
  begin
  if (s[t]='?') or (s[t]='*') then
    begin
    f[t-1]:=0;ls:=ls-1;
    if ls=n then break;
    end;
  t:=t+1;
  end;
if ls>n then
  begin
  write('Impossible');
  close(input);close(output);halt;
  end;

    end;
if ls<n then
  begin
    for i:=1 to length(s) do
      if s[i]='*' then
        begin
        f[i-1]:=f[i-1]+n-ls; ff:=true;
        break;
        end;
    if not ff then
      begin
      write('Impossible');
  close(input);close(output);halt;
  end;
 end;
for i:=1 to length(s) do
    for j:=1 to f[i] do
       write(s[i]);
close(input);close(output);
end.


var n:longint;
a:array[0..25] of longint;
procedure       mo;
begin
        assign(input,'test.inp');reset(input);
        assign(output,'test.out');rewrite(output);
end;
procedure       dong;
begin
        close(input);close(output);
end;
procedure       nhap;
var i:longint;
begin
        readln(n);
        for i:=1 to n do
                begin
                read(a[i]);
                end;
end;
procedure       xuli;
var i,j:longint;
tam,dem1:longint;
kt:boolean;
begin
        for j:=1 to 12 do
                begin
                tam:=j;
                dem1:=0;
                kt:=true;
                for i:=1 to n do
                        begin
                        if tam>12 then tam:=1;
                        if tam=2 then
                                begin
                                if a[i]=29 then inc(dem1)
                                else if (a[i]<>28) and (a[i]<>29) then
                                        begin
                                        kt:=false;
                                        break;
                                        end;
                                if dem1>=2 then
                                        begin
                                        kt:=false;
                                        break;
                                        end;
                                end;
                        if (tam=1) or (tam=3) or (tam=5) or (tam=7) or (tam=8) or (tam=10) or (tam=12) then
                                begin
                                if a[i]<>31 then
                                        begin
                                        kt:=false;
                                        break;
                                        end;
                                end;
                        if (tam=4) or (tam=6) or (tam=9) or (tam=11) then
                                begin
                                if a[i]<>30 then
                                        begin
                                        kt:=false;
                                        break;
                                        end;
                                end;
                        inc(tam);
                        end;
                if kt=true then
                        begin
                        writeln('YES');
                        halt;
                        end;
                end;
        writeln('NO');
end;
begin
       // mo;
        nhap;
        xuli;
        //dong;
end.


var a,b,c,v,p:integer;
begin
read(a,b,c);
p:=a*b*c;
if p>v then v:=p;

p:=a+b*c;
if p>v then v:=p;

p:=a*b+c;
if p>v then v:=p;

p:=a+b+c;
if p>v then v:=p;

p:=(a+b)*c;
if p>v then v:=p;

p:=a*(b+c);
if p>v then v:=p;

p:=a*(b*c);
if p>v then v:=p;

p:=(a*b)*c;
if p>v then v:=p;
println(v);
end.


var
  x : string;
  i,t,a,y,j,k,b,g : longint;
begin
  readln(t);
  for i:=1 to t do begin
    readln(x);
    g:=0;
    val(x[1],b,y);
    for j:=1 to length(x) do
      g:=g+j;
      writeln((b-1)*10+g);
  end;
end.


var n:int64;
begin
  readln(n);
  n:=n+1;
  if n mod 2=0 then write(n div 2)
               else if n=1 then write(0)
                           else write(n);
end.


var a: array[1..100] of integer;
ka,k,ma,ke,n,j,i:integer;
begin
readln(n);
for i:=1 to n do
read(a[i]);
for i:=1 to n do
ke:=ke+a[i];
for i:=1 to n do
if a[i]>ma then ma:=a[i];
k:=ma;
while ke>=ka do begin
ka:=0;
for i:=1 to n do
ka:=ka+k-a[i];
k:=k+1;
end;
writeln(k-1);

end.


var n,i,l,r:longint;
          s:string;
begin
        readln(n);
        readln(s);
        for i:=1 to length(s) do
        if s[i] = 'L' then inc(l)
        else inc(r);
        writeln(r--l+1);
        readln;
end.


var
  a,b:int64;
begin
  readln(a,b);
  a:=a+1;
  b:=b-1;
  writeln(a+b+0-0);
end.


var m,p:int64;
    n,i:longint;
    a:array[-100..1000] of longint;
begin
read(n,m);
p:=1; dec(m);
while m>0 do begin
a[p]:=m mod 2;
m:=m div 2;
inc(p);
end;

for i:=1 to n do
if a[n-i]=0 then write(i,' ');
for i:=n downto 1 do
if a[n-i]=1 then write(i,' ');
end.


var
  one, n, k:int64;
begin
one:=1;
  readln(n, k);
  if k=1 then writeln(n)
  else
  begin
    k:=0;
    while n<>0 do
      begin
      inc(k);
      n:=n div 2;
      end;
    writeln(one shl k-1);
  end;
end.


var n,i,j,k,w:longint;
x,y,xx,yy,a,b,c:array[0..5] of longint;
sw:boolean;
procedure build(z:longint);
begin
if z>=5 then
begin
x[c[5]]:=x[c[1]];y[c[5]]:=y[c[1]];
for i:=1 to 4 do
if (xx[c[i]]<>x[c[i+1]]) or (yy[c[i]]<>y[c[i+1]]) then exit;
sw:=true;
end else begin
build(z+1);
w:=x[c[z]];x[c[z]]:=xx[c[z]];xx[c[z]]:=w;
w:=y[c[z]];y[c[z]]:=yy[c[z]];yy[c[z]]:=w;
build(z+1);
w:=x[c[z]];x[c[z]]:=xx[c[z]];xx[c[z]]:=w;
w:=y[c[z]];y[c[z]]:=yy[c[z]];yy[c[z]]:=w;
end;
end;

procedure work(x1,x2,x3,x4:longint);
begin
if ((a[x1]=a[x3]) or (b[x1]<>b[x3]))=false then
if ((a[x2]=a[x4]) or (b[x2]<>b[x4]))=false then
if b[x1]<>b[x2] then begin
c[1]:=x1;c[2]:=x2;c[3]:=x3;c[4]:=x4;
build(1);
end;
end;

begin

sw:=true;
for i:=1 to 4 do
begin
readln(x[i],y[i],xx[i],yy[i]);
if (x[i]=xx[i]) or (y[i]=yy[i]) then
begin
if x[i]=xx[i] then a[i]:=x[i] else begin b[i]:=1;a[i]:=y[i];end;
end else sw:=false;
end;

if sw then begin
sw:=false;
work(1,2,3,4);work(1,3,2,4);work(1,2,4,3);
if sw then begin writeln('YES');halt;end;
end;
writeln('NO');
end.


uses math;
var n,i:longint;
    fc,fg,a:array[-100..100000] of longint;
begin
    assign(input,''); reset(input);
    assign(output,''); rewrite(output);
    readln(n); for i:=1 to n do read(a[i]);
    for i:=1 to n do
    begin
        if a[i]=1 then
        begin
            fc[i]:=max(fg[i-1]+1,fc[i-2]+1);
            fg[i]:=max(fc[i-1],fg[i-1]);
        end;
        if a[i]=2 then
        begin
            fc[i]:=max(fg[i-1],fc[i-1]);
            fg[i]:=max(fc[i-1]+1,fg[i-2]+1);
        end;
        if a[i]=3 then
        begin
            fc[i]:=max(fg[i-1]+1,fc[i-2]+1);
            fg[i]:=max(fc[i-1]+1,fg[i-2]+1);
        end;
        if a[i]=0 then
        begin
            fg[i]:=fg[i-1];
            fc[i]:=fc[i-1];
        end;
    end;
    writeln(n-max(fc[n],fg[n]));
    close(input); close(output);
end.


const b1:array[1..13]of char=('2','3','4','5','6','7','8','9','T','J','Q','K','A');
b2:array[1..4]of char=('C','D','H','S');
var i,k,i1,k1,i2,k2,t,t1,t2,t3,n,m,ii,kk:longint;
a:array[1..20,1..20]of string;
b:array['2'..'Z','C'..'Z']of boolean;
c,c1,c2:char;
h:string;
function kd:longint;
var i,k,kol:longint;
begin
kol:=0;
for i:=1 to n do
 for k:=1 to m do
  if a[i,k]='J1' then
   begin
   inc(kol);
   if kol=2 then
   begin
   i2:=i1;
   k2:=k1;
    i1:=i;
    k1:=k;
  // h:='J1';
   end
    else
     begin
     i1:=i;
     k1:=k;
     h:='J1';
     end;
   end
    else
     if a[i,k]='J2'then
      begin
      inc(kol);
      if kol=2 then
       begin
       i2:=i;
       k2:=k;
       end
        else
         begin
         i1:=i;
         k1:=k;
         h:='J2';
         end;
      end;
  kd:=kol;
end;
function hor(x,y,x1,y1:longint):boolean;
 var i,k,iii,kkk:longint;
 e,e1,e2,e3:boolean;
 begin
 e:=true;
 e1:=e;
 e2:=e;
 e3:=e;
 for i:=x to x+2 do
  for k:=y to y+2 do
   if a[i,k][2]<>a[x,y][2]then
    begin
    e:=false;
    break;
    end;
 for i:=x1 to x1+2 do
  for k:=y1 to y1+2 do
   if a[i,k][2]<>a[x1,y1][2]then
    begin
    e2:=false;
    break;
    end;
 if ord(e)*ord(e2)=1 then
 hor:=true
  else
   begin
    for i:=x to x+2 do
     for k:=y to y+2 do
      for iii:=x to x+2 do
       for kkk:=y to y+2 do
        if not((i=iii)and(k=kkk))then
         if a[i,k][1]=a[iii,kkk][1]then
          begin
          e1:=false;
          break;
          end;
      for i:=x1 to x1+2 do
     for k:=y1 to y1+2 do
      for iii:=x1 to x1+2 do
       for kkk:=y1 to y1+2 do
        if not((i=iii)and(k=kkk))then
         if a[i,k][1]=a[iii,kkk][1]then
          begin
          e3:=false;
          break;
          end;
     if e1 and e3 then
     hor:=true
     else
     hor:=false;
   end;
 end;
begin
Readln(n,m);
for i:=1 to n do
 begin
  for k:=1 to m do
   begin
   Read(c,c1,c2);
   a[i,k]:=c+c1;
   if (c1<>'1')and(c1<>'2')then
   b[c,c1]:=true;
   end;
  readln;
 end;
if kd=0 then
 begin
  for i:=1 to n-2 do
   for k:=1 to m-2 do
    for ii:=1 to n-2 do
     for kk:=1 to m-2 do
      if (ii>=i+3)or(kk>=k+3)then
       if hor(i,k,ii,kk)then
        begin
        writeln('Solution exists.');
        writeln('There are no jokers.');
        writeln('Put the first square to (',i,', ',k,').');
        write('Put the second square to (',ii,', ',kk,').');
        halt;
        end;
 end
 else
  if kd=1 then
   begin
    for t:=1 to 13 do
     for t1:=1 to 4 do
      if not b[b1[t],b2[t1]] then
       begin
       a[i1,k1]:=b1[t]+b2[t1];
  for i:=1 to n-2 do
   for k:=1 to m-2 do
    for ii:=1 to n-2 do
     for kk:=1 to m-2 do
      if (ii>=i+3)or(kk>=k+3)then
       if hor(i,k,ii,kk)then
        begin
        writeln('Solution exists.');
        writeln('Replace ',h,' with ',a[i1,k1],'.');
        writeln('Put the first square to (',i,', ',k,').');
        write('Put the second square to (',ii,', ',kk,').');
        halt;
        end;
       end;
   end
    else
     if kd=2 then
      begin
    for t:=1 to 13 do
    for t1:=1 to 4 do
    for t2:=1 to 13 do
    for t3:=1 to 4 do
      if (not b[b1[t],b2[t1]])and(not b[b1[t2],b2[t3]])and(not((t=t2)and(t1=t3))) then
       begin
       a[i1,k1]:=b1[t]+b2[t1];
       a[i2,k2]:=b1[t2]+b2[t3];
  for i:=1 to n-2 do
   for k:=1 to m-2 do
    for ii:=1 to n-2 do
     for kk:=1 to m-2 do
      if (ii>=i+3)or(kk>=k+3)then
       if hor(i,k,ii,kk)then
        begin
        writeln('Solution exists.');
        writeln('Replace J1 with ',a[i1,k1],' and J2 with ',a[i2,k2],'.');
        writeln('Put the first square to (',i,', ',k,').');
        write('Put the second square to (',ii,', ',kk,').');
        halt;
        end;
       end;
      end;
write('No solution.');
end.


//   Author : Phan Anh Tu
//   anhtu208 - haha
var t , n : longint;
    i : longint;
function lt(x : longint) : int64;
var i : longint;
    tam : int64;
begin
    tam:=1;
    for i:=1 to x do tam:=2*tam;
    lt:=tam;
end;
begin
    readln(t);
    for i:=1 to t do
        begin
            readln(n);
            writeln(lt(n) - 1);
        end;
end.


Var a,b:array[1..5] of longint;
    s:array[1..5] of string;
    i,j,n,k:longint;
    ans:string;
 begin
  for i:=1 to 4 do
   Readln(s[i]);
  for i:=1 to 4 do
   for j:=1 to 4 do
    begin
     if i<>j then
      begin
       if (length(s[i])-2)>=(length(s[j])-2)*2 then inc(a[i]);
       if (length(s[i])-2)*2<=(length(s[j])-2) then inc(b[i]);
      end;
    end;
  for i:=1 to 4 do
   if (a[i]=3) or (b[i]=3) then
    begin
     ans:=chr(i+64);
     inc(k);
    end;
  if k=1 then Write(ans) else Write('C');
 end.


var
  max,i,n,min,minn:longint;
  a:array[0..101] of longint;
begin
  readln(n);
  min:=maxlongint;
  for i:=1 to n do
    begin
      read(a[i]);
      if a[i]<min then min:=a[i];
    end;
  write((min xor a[3])+2);
end.


var
n,m,a,b:longint;
begin
read(n,m);
a:=0;
b:=n;
if n mod 2=0
then
n:=n div 2
else
n:=n div 2 +1;
if b-m>n
then
if m+1<=b
then
a:=m+1
else
a:=m;
if b-m=n
then
a:=m+1;
if b-m<n
then
if m-1>0
then
a:=m-1
else
a:=m;
write(a);
end.


{$MODE OBJFPC}
uses math;
const maxN=200000+1067;base=1000000007;
var    f,sum:array[0..1,-maxN..maxN] of int64;
       a,b,k,t,ss,xx,x:int64;
       i,j,nbn,kk:integer;
       res,nnn,mmm:int64;
begin
       readln(a,b,k,t);
       f[0][a-b]:=1;
       mmm:=a-b+2*k*t;
       nnn:=a-b-2*k*t;
       for j:=a-b to mmm do sum[0][j]:=1;
       for kk:=1 to t do
           begin
                xx:=0;
                ss:=0;
                i:=kk mod 2;
                nbn:=(i+1) mod 2;
                for j:=nnn+2*k downto nnn do
                    begin
                         inc(xx);
                         ss:=(ss+f[nbn][j]*xx) mod base;
                    end;
                for j:=nnn to mmm  do
                    begin
                        f[i][j]:=ss mod base;
                        ss:=(ss-(sum[nbn][j]-sum[nbn][max(j-2*k,nnn)-1]) +
                        (sum[nbn][min(j+2*k+1,mmm)]-sum[nbn][j])) mod base;
                        sum[i][j]:=(sum[i][j-1]+f[i][j]) mod base;
                    end;
           end;
       for j:=1 to mmm do res:=(res+f[t mod 2][j]) mod base;
       if (res<0) then inc(res,base);
       writeln(res)
end.


program Ccodeforces15;
const max=trunc(1e9)+7;
var stk,A:array[1..100005] of longint;
    P:array[2..100005] of boolean;
    m,top,i:longint;
    j,ans,s,mu,x,n:int64;
    fi,fo:text;
//-------------------------
procedure bdprime(x:longint);
var i,d:longint;
begin
        d:=trunc(sqrt(x));
        for i:=1 to top do
        begin
                if stk[i]>d then break;
                if x mod stk[i]=0 then
                begin
                        inc(m);
                        A[m]:=stk[i];
                        While x mod stk[i]=0 do
                        begin
                                x:=x div stk[i];
                        end;
                end;
        end;
if x>1 then
begin
        inc(m);
        A[m]:=x;
end;
end;
//-------------------------
function pow(x,n:int64):int64;
begin
if n=0 then exit(1);
if n mod 2=0 then
begin
        exit((sqr(pow(x,n div 2))) mod max);
end
else
begin
        exit((((sqr(pow(x,n div 2))) mod max)*x) mod max);
end;
end;
//-------------------------
begin
assign(fi,'');reset(fi);
assign(fo,'');rewrite(fo);
readln(fi,x,n);
fillchar(P,sizeof(P),true);
for i:=2 to 100000 do
begin
        if P[i] then
        begin
                inc(top);
                stk[top]:=i;
                j:=i;
                j:=j*j;
                While j<=100005 do
                begin
                        P[j]:=false;
                        inc(j,i);
                end;
        end;
end;
bdprime(x);
ans:=1;
for i:=1 to m do
begin
        mu:=n div A[i];
        While mu>0 do
        begin
                ans:=(ans*pow(A[i],mu)) mod max;
                mu:=mu div A[i];
        end;
end;
Writeln(fo,ans);
close(fo);
end.


uses math;
var
  x1,x2,d,i,j,aa,bb,a,b,c:longint;
begin
  readln(x1,x2,a,b);
  aa:=a;
  bb:=b;
  d:=x2-x1;
  if (a<=0) and (b>=0) then begin
    if x2>x1 then begin
      if x1+b>=x2 then begin
        writeln('FIRST');
        writelN(x2);
      end
      Else writeln('DRAW');
      HALT;
    end
    else begin
      if x1+a<=x2 then begin

        writeln('FIRST');
        writelN(x2);
      end
      else writeln('DRAW');
      halt;
    end;
  end;
  if (a<0) and (b<0) then begin

    c:=a;
    a:=-b;
    b:=-c;
  end;
  if d>0 then begin
    if d mod (a+b) = 0 then begin
      writeln('SECOND');
      halt;
    end
    ELSE BEGIN
      if (d mod (a+b) >=a) and ( d mod (a+b) <=b) then begin
        writeln('FIRST');
        WRITELN(X1+(D MOD (A+B)));
      END
      else begin
        writeln('DRAW');
        HALT;
      end;
    end;
  end;
  if d<0 then begin
    if (d mod (a+b) = 0) and (aa<0) and (bb<0) then begin
      writeln('SECOND');
      halt;
    end
    ELSE BEGIN
      if (abs(d) mod (a+b) >=a) and ( abs(d) mod (a+b) <=b) then begin
        writeln('FIRST');
        WRITELN(X1-(abs(D) MOD (A+B)));
      END
      else begin
        writeln('DRAW');
        HALT;
      end;
    end;
  end;

end.


Var n   :   int64 ;

Procedure Enter ;
    Var i,j,res :   longint ; a,b,tg   :   int64 ;
    Begin
        read(n) ; res := 1 ;
        {while (n > 1) do
            begin
                inc(res) ;
                n := (n+1) div 2 ;
            end ;}

        if (n <= 2) then begin writeln(1) ; exit ; end ;
        a := 1 ; b := 2 ;

        while (b <= n) do
            begin
                inc(res) ;
                tg := b ;
                b := a + b ;
                a := tg ;
            end ;

        writeln(res-1) ;
    End ;

Begin
    //Assign(input,'735C.inp') ; reset(input) ;

    Enter ;

    //Close(input) ;
End.


Program Very;
var s:string;
    i,j,u,n,kol,max:byte;
    e:array[0..210]of byte;

begin
readln(n);
read(s);
e[0]:=0;
j:=0;
for i:=1 to n do
  if s[i]=' ' then
    begin
    inc(j);
    e[j]:=i-1;
    end;
inc(j);
e[j]:=n;
for i:=1 to j do
  begin
  kol:=0;
  for u:=e[i-1]+1 to e[i] do
    if (ord(s[u])>=ord('A')) and (ord(s[u])<=ord('Z')) then
      inc(kol);
  if kol>max then max:=kol;
  end;
writeln(max);
end.


Var n,k,i:longint;
    s1,s2:string[20];
    a1,a2:array[1..10] of longint;
    s:string[2];
Begin
Readln(s1);
Readln(s2);
For i:=1 to (length(s1) div 2) do
 Begin
  s:=copy(s1,i*2-1,2);
  If s='[]' Then a1[i]:=1;
  If s='8<' Then a1[i]:=2;
  If s='()' Then a1[i]:=3;
  k:=i;
 End;
For i:=1 to (length(s2) div 2) do
 Begin
  s:=copy(s2,i*2-1,2);
  If s='[]' Then a2[i]:=1;
  If s='8<' Then a2[i]:=2;
  If s='()' Then a2[i]:=3;
 End;
n:=0;
For i:=1 to k do
 Begin
  If a1[i]=a2[i] Then Continue;
  If a1[i]=1 Then Begin
   If a2[i]=2 Then dec(n);
   If a2[i]=3 Then inc(n);
  End;
  If a1[i]=2 Then Begin
   If a2[i]=1 Then inc(n);
   If a2[i]=3 Then dec(n);
  End;
  If a1[i]=3 Then Begin
   If a2[i]=1 Then dec(n);
   If a2[i]=2 Then inc(n);
  End;
 End;
If n=0 Then Begin Writeln('TIE'); Halt; End;
If n>0 Then Begin Writeln('TEAM 1 WINS'); Halt; End;
Writeln('TEAM 2 WINS');
End.


const
    fi ='';
    fg ='';
var dem,n,i:longint;
    deque:array[0..1000000] of longint;
    f,g:text;
begin
    assign(f,fi);
    reset(f);
    assign(g,fg);
    rewrite(g);
    readln(f,n);
    dem :=1;deque[dem] :=1;
    For i:=2 to n do
    begin
        inc(dem);deque[dem] :=1;
        While (deque[dem] = deque[dem-1]) and (dem <> 1) do
        begin
            inc(deque[dem-1]);
            dec(dem);
        end;
    end;
    For i:=1 to dem do write(g,deque[i],' ');
    close(f);
    close(g);
end.


var
p,n,k,i,j,buf,buf2,s:longint;
a:array[1..100,1..2] of longint;
begin
readln(n,k);
for i:=1 to n do
begin
read(a[i,1]);
a[i,2]:=i;
end;
for i:=1 to n-1 do
for j:=1 to n-1 do
if(a[j,1]>a[j+1,1]) then
begin
buf:=a[j,1];
buf2:=a[j,2];
a[j,1]:=a[j+1,1];
a[j,2]:=a[j+1,2];
a[j+1,1]:=buf;
a[j+1,2]:=buf2;
end;
s:=0;
p:=0;
while(s<=k)and(p<n) do
begin
inc(p);
s:=s+a[p,1];
end;
if(s>k) then
dec(p);
writeln(p);
if(p>0) then
begin
for i:=1 to p-1 do
write(a[i,2],' ');
writeln(a[p,2]);
end;
end.


var n,k,s2,s4,tmp,p1,p2,p4:longint;
begin
//assign(input,'hdyx.in');reset(input);
//assign(output,'hdyx.out');rewrite(output);
read(n,k);
s4:=n;s2:=n*2;
while k>0 do
  begin
  read(tmp);
  p4:=p4+tmp div 4;
  case tmp mod 4 of
    1:inc(p1);
    2:inc(p2);
    3:begin inc(p1);inc(p2);end;
    end;
  k:=k-1;
  end;
if p4<s4 then
  begin
  s4:=s4-p4;
  if p2<s2 then
    begin
    s2:=s2-p2;
    if p1<=2*s4+s2 then writeln('YES') else writeln('NO');
    end
  else
    begin
    p2:=p2-s2;s2:=0;
    if p1<s4 then
      begin
      s2:=s2+p1;s4:=s4-p1;
      if p2<=s4*3 div 2+s2 then writeln('YES') else writeln('NO');
      end
    else
      begin
      s2:=s2+s4;p1:=p1-s4;
      if p2+p1<=s2 then writeln('YES') else writeln('NO');
      end;
    end;
  end
else
  begin
  p4:=p4-s4;
  if p4*2+p2+p1<=s2 then writeln('YES') else writeln('NO');
  end;
close(input);close(output);
end.


var a:array[1..105]of longint;
n,ans,i,j,res:longint;
begin
 read(n);
 ans:=maxlongint;
 for i:=1 to n do
 read(a[i]);
 for i:=1 to n do
 begin
 res:=0;
 for j:=1 to n do
 res:=res+2*a[j]*(abs(i-j) + abs(j-1) + abs(1-i));
 if res<ans then ans:=res;
 end;
 write(ans);
end.


program task_a_57;
var n,x1,y1,x2,y2,d,k:longint;

begin
readln(n,x1,y1,x2,y2);
if ((x1=0) and (x2=n)) or
   ((x1=n) and (x2=0))
   then begin
        d:=n+y1+y2;
        if d>2*n
           then d:=4*n-d;
        end
   else begin
        if ((y1=0) and (y2=n)) or
           ((y1=n) and (y2=0))
           then begin
                d:=n+x1+x2;
                if d>2*n
                   then d:=4*n-d;
                end
           else begin
                if ((x1=0) and (x2=0)) or
                   ((x1=n) and (x2=n))
                   then begin
                        d:=abs(y1-y2);
                        end
                   else begin
                        if ((y1=0) and (y2=0)) or
                           ((y1=n) and (y2=n))
                           then begin
                                d:=abs(x1-x2);
                                end
                           else begin
                                if (x1=0) and (y2=0)
                                   then d:=x2+y1;
                                if (x2=0) and (y1=0)
                                   then d:=x1+y2;
                                if (x1=0) and (y2=n)
                                   then d:=n+x2-y1;
                                if (x2=0) and (y1=n)
                                   then d:=n+x1-y2;
                                if (x1=n) and (y2=n)
                                   then d:=2*n-x2-y1;
                                if (x2=n) and (y1=n)
                                   then d:=2*n-x1-y2;
                                if (x1=n) and (y2=0)
                                   then d:=n-x2+y1;
                                if (x2=n) and (y1=0)
                                   then d:=n-x1+y2;
                                end;
                        end;

                end;
        end;
writeln(d);
end.


var b,s,c,bs,ss,cs,cp,sp,bp,q,p,tp,qw:int64; st:string; i:longint;
procedure beli(x,y,z:int64);
begin
  if x < b then begin inc(bs,b-x); dec(p,bp*(b-x))end;
  if y < s then begin inc(ss,s-y); dec(p,sp*(s-y))end;
  if z < c then begin inc(cs,c-z); dec(p,cp*(c-z))end;
end;
begin
  readln(st);b:=0;s:=0;c:=0;q:=0;
  for i:=1 to length(st)do begin
    case st[i] of
	  'B':inc(b);
	  'S':inc(s);
	  'C':inc(c);
	end;
  end;
  readln(bs,ss,cs);
  readln(bp,sp,cp);
  readln(p);
  if b=0 then bs:=0;
  if c=0 then cs:=0;
  if s=0 then ss:=0;
  while (p >= 0)do begin
    if (bs>=b) and (cs>=c) and (ss>=s) then begin
	  dec(bs,b);dec(cs,c);dec(ss,s);inc(q);
	end;
	tp:=(b*bp)+(s*sp)+(c*cp);
	if (tp < p) and (b-bs=b)and (s-ss=s)and (c-cs=c) then begin
      qw:=p div tp;
      dec(p,tp*qw);
      inc(q,qw);
    end;
	beli(bs,ss,cs);
  end;
  writeln(q);
end.


var
 n,x,d: int64;

begin
 readln(n);
 readln(x);
 d:=n mod 6;

 if d = 0 then
 begin
  if x = 0 then writeln(0) else
  if x = 1 then writeln(1) else
  if x = 2 then writeln(2);
 end else
  if d = 1 then
 begin
  if x = 0 then writeln(1) else
  if x = 1 then writeln(0) else
  if x = 2 then writeln(2);
 end else
 if d = 2 then
 begin
  if x = 0 then writeln(1) else
  if x = 1 then writeln(2) else
  if x = 2 then writeln(0);
 end else
 if d = 3 then
 begin
  if x = 0 then writeln(2) else
  if x = 1 then writeln(1) else
  if x = 2 then writeln(0);
 end else
 if d = 4 then
 begin
  if x = 0 then writeln(2) else
  if x = 1 then writeln(0) else
  if x = 2 then writeln(1);
 end else
 if d = 5 then
 begin
  if x = 0 then writeln(0) else
  if x = 1 then writeln(2) else
  if x = 2 then writeln(1);
 end;
end.


var
        s,a:ansistring;
begin
        readln(s);
        readln(a);
        s:=upcase(s);
        a:=upcase(a);
        if (s>a) then writeln('1')
        else if (s<a) then writeln('-1')
        else if (s=a) then writeln(0);
end.


const
  mo=1000000007;

var
  n,m,k,x,y,i,j,ii:longint;
  ans,tmp:int64;
  fac,inv,g:array[0..1000000] of int64;
  d:array[0..1000,0..1000] of int64;

function cb(x,y:longint):int64;
  begin
    cb:=(fac[x]*inv[y] mod mo)*inv[x-y] mod mo;
  end;

function power(a,b:int64):int64;
  var
    tmp:int64;
  begin
    tmp:=1;
    while b<>0 do
      if b and 1=1 then
        begin
          dec(b);
          tmp:=tmp*a mod mo;
        end else
        begin
          b:=b>>1;
          a:=a*a mod mo;
        end;
    exit(tmp);
  end;

begin
  readln(n,m,k);

  fac[0]:=1; inv[0]:=1;

  ii:=k; if n>k then ii:=n;
  for i:=1 to ii do
    begin
      fac[i]:=fac[i-1]*i mod mo;
      inv[i]:=power(fac[i],mo-2) mod mo;
    end;

  fillchar(d,sizeof(d),0);
  d[0,0]:=1;

  for i:=1 to n do
    for j:=1 to i do
      begin
        d[i,j]:=(d[i-1,j]*j+d[i-1,j-1]*j) mod mo;
      end;

  ans:=0;
  if m=1 then
    begin
      for i:=1 to n do
        ans:=(ans+d[n,i]*cb(k,i) mod mo) mod mo;
      writeln(ans);
      close(input);
      close(output);
      halt;
    end;

  ii:=k; if n<k then ii:=n;

  for y:=0 to ii do
    g[y]:=power(power(y,n),m-2);

  for x:=1 to k do
    if x<=n then
      begin
        for y:=0 to x do
          if x-y<=k-x then
            begin
              if (y=0)and(m>2) then continue;
              tmp:=cb(k,x)*cb(k-x,x-y) mod mo;
              tmp:=tmp*cb(x,y) mod mo;
              tmp:=tmp*d[n,x] mod mo;
              tmp:=tmp*d[n,x] mod mo;
              tmp:=tmp*g[y] mod mo;
              ans:=(ans+ tmp ) mod mo;
            end;
      end;

  writeln(ans);

end.


program problem2;

var	n, i: longInt;
	f: array[ 0..50 ] of int64;
	k: int64;

begin
	f[0] := 1;
	f[1] := 1;
	for i := 2 to 50 do
		f[i] := f[i - 1] + f[i - 2];

	readln( n, k );

	i := 1;
	while ( i <= n ) do
		if ( k <= f[n - i] ) then
		begin
			write( i, ' ' );
			inc( i );
		end
		else
		begin
			dec( k, f[n - i] );

			write( i + 1, ' ', i, ' ' );
			inc( i, 2 );
		end;

	writeln();
end.


uses
  Math;

var
  n, m, i, count, l, r, x, sum, ans: longint;
  k, a, day, d, t: array[1..400000] of longint;

begin
  read(n, m);
  for i := 1 to n do
    a[i] := 0;
  count := 0;
  for i := 1 to n do begin
    read(k[i]);
    count := count + k[i];
  end;
  for i := 1 to count * 2 do
    day[i] := 0;
  for i := 1 to m do
    read(d[i], t[i]);

  l := 1;
  r := count * 2;
  while abs(l-r) > 1 do begin
    x := (l + r) div 2;
    for i := 1 to x do
      day[i] := 0;
    for i := 1 to m do
      if ((a[t[i]] > x) or (a[t[i]] < d[i])) and (d[i] <= x) then
        a[t[i]] := d[i];
    for i := 1 to n do
      if (a[i] <= x) and (a[i] > 0) then
        day[a[i]] := day[a[i]] + k[i];
    sum := 0;
    ans := count;
    for i := 1 to x do begin
      inc(sum);
      ans := ans - min(day[i], sum);
      sum := sum - min(day[i], sum);
    end;
    if ans * 2 <= sum then
      r := x
    else
      l := x;
  end;

  for i := 1 to l do
      day[i] := 0;
    for i := 1 to m do
      if ((a[t[i]] > l) or (a[t[i]] < d[i])) and (d[i] <= l) then
        a[t[i]] := d[i];
    for i := 1 to n do
      if (a[i] <= l) and (a[i] > 0) then
        day[a[i]] := day[a[i]] + k[i];
  sum := 0;
  ans := count;
  for i := 1 to min(l, r) do begin
    inc(sum);
    ans := ans - min(day[i], sum);
    sum := sum - min(day[i], sum);
  end;
  if ans * 2 <= sum then
    write(min(l, r))
  else
    write(max(l, r))
end.


var
  h,m,i,j,k,l,h_len,m_len,h1,h2,m1,m2:longint;
  ans:int64;

function get_len(x:longint):longint;
  begin
    if x=0 then exit(0);
    exit(1+get_len(x div 10));
  end;

function nonzero_len(x:longint):longint;
  begin
    if x=0 then exit(0);
    if x mod 10<>0
      then exit(1+nonzero_len(x div 10))
      else exit(nonzero_len(x div 10));
  end;

function power(a,b:longint):longint;
  var
    tmp:longint;
  begin
    tmp:=1;
    for b:=1 to b do
      tmp:=tmp*a;
    exit(tmp);
  end;

function calc(h1,m1:longint):int64;
  var
    d,a,b,c:longint;
    ans:int64;
  begin
    ans:=0;

    if m_len>=k then
      begin
        if k=1 then
          begin
            ans:=ans+int64(m-1)*h1+m1;
          end
        else
          begin
            a:=power(10,k-1);
            ans:=ans+int64(h1)*( (m-1) div a );
            ans:=ans+m1 div a;
          end;
      end;

    d:=k-nonzero_len(m-1);
    if d<=0 then d:=1;

    if d=1 then
      begin
        ans:=ans+h1;
      end
    else
      begin
        a:=power(10,d-1);
        ans:=ans+h1 div a;
      end;

    exit(ans);

  end;

begin

  readln(h,m,k);

  h_len:=get_len(h);
  m_len:=get_len(m);

  readln(h1,m1,h2,m2);

  if (h1<h2)or(h1=h2)and(m1<=m2)
    then writeln(calc(h2,m2)-calc(h1,m1))
    else begin
           ans:=calc(h-1,m-1)-calc(h1,m1)+calc(h2,m2);
           if nonzero_len(h-1)+nonzero_len(m-1)>=k then
             inc(ans);
           writeln(ans);
         end;

end.


var m:array[1..4] of string;
	i,j:integer;
	f:boolean;

procedure check(s:string);
begin
if not f then
f:= (s='###.') or (s='##.#') or (s='#.##') or (s='.###') or (s='####') or
	(s='...#') or (s='..#.') or (s='.#..') or (s='#...') or (s='....');
end;

begin
for i:=1 to 4 do
	readln(m[i]);

f:=false;
for i:=1 to 3 do
	for j:=1 to 3 do
		check(m[i,j]+m[i,j+1]+m[i+1,j]+m[i+1,j+1]);
if f then writeln('YES') else writeln('NO');
end.


uses math;
const fi='837e.inp';
      fo='837e.out';
var n,m,x,y:int64;
    a,b:array[0..1000000] of int64;
//---------------
procedure doc;
begin
      read(x,y);
end;
//---------------
procedure phantich(x:int64);
var i:longint;
begin
      m:=0;
      for i:=2 to trunc(sqrt(x)) do
            while x mod i=0 do
            begin
                  inc(m);
                  a[m]:=i;
                  x:=x div i;
            end;
      if x>1 then
      begin
            inc(m);
            a[m]:=x;
      end;
end;
//---------------
procedure xuli;
var i,count:longint;
    res,g:int64;
begin
      phantich(x);
      res:=0;
      repeat
            g:=y;
            for i:=1 to m do
            begin
                  g:=min(g,y mod a[i]);
            end;
            res:=res+g;
            y:=y-g;
            count:=0;
            for i:=1 to m do
                  if y mod a[i]=0 then y:=y div a[i]
                  else
                  begin
                        inc(count);
                        b[count]:=a[i];
                  end;
            for i:=1 to count do a[i]:=b[i];
            m:=count;
      until y=0;
      write(res);
end;
//---------------
begin
      doc;
      xuli;
end.


program zad_22;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  string1: string;
  res : integer;
{---------------------------------------------------}
procedure checkstring(str : string; var k : integer);
  var
    ch : char;
    i, k1 : integer;
  begin
    ch := 'a';
    k1 := 0;
    for i := 1 to 26 do begin
      if(pos(ch, str) <> 0) then inc(k1);
      inc(ch);
    end;
    k := k1;
  end;
{--------------------------------------------------}
begin
  readln(string1);
  checkstring(string1, res);
  if(res mod 2 = 0) then
    writeln('CHAT WITH HER!')
  else
    writeln('IGNORE HIM!');
  readln;
end.


var i,j,n: longint;
m1,m2: array [1..5] of longint;
sum: uint64;
b: boolean;

begin
read(n);
for i:=1 to n do
begin
 read(j);
 inc(m1[j])
end;
for i:=1 to n do
begin
 read(j);
 inc(m2[j])
end;
for i:=1 to 5 do
begin
if abs(m1[i]-m2[i]) mod 2=1 then b:=true else inc(sum,abs(m1[i]-m2[i]) div 2);

end;

if b=false then write(sum div 2) else write(-1);
readln;
end.


var     n,k,a,dem,UCLN:longint;
procedure GCD(c,b:longint);
var min,i:longint;
begin
        UCLN:=1;
        if c > b then min:=b
                else min:=c;
        for i:=1 to min do
                if (c mod i=0) and (b mod i =0) then UCLN:=i;
end;
begin
        readln(n,k,a);
        dem:=0;
        if a=0 then dem:=4;
        while (dem <> 3) and (dem <> 4) do
                begin
                        gcd(n,a);
                        a:=a-UCLN;
                        if a=0 then dem:=3;
                        gcd(k,a);
                        a:=a-UCLN;
                        if a=0 then dem:=4;
                end;
        if dem=3 then write('0');
        if dem=4 then write('1');
end.


uses math;
var mp:array[0..105,0..105]of int64;
    n,m,ans:int64;
    i,j:longint;
function gcd(a,b:int64):int64;
begin
  if a mod b=0 then exit(b);exit(gcd(b,a mod b));
end;
procedure floyd;
var i,j,k:longint;
begin
for k:=1 to n do
  for i:=1 to n do
    for j:=1 to n do mp[i,j]:=min(mp[i,j],mp[i,k]+mp[k,j]);

end;

begin
readln(n);
for i:=1 to n do for j:=1 to n do mp[i,j]:=999999999;
for i:=1 to n do begin
  read(m);mp[i,m]:=1;
end;
floyd;
ans:=1;
for i:=1 to n do begin
  if mp[i,i]=999999999 then begin writeln(-1);halt;end;
  if mp[i,i] mod 2=0 then mp[i,i]:=mp[i,i] div 2;
  ans:=(ans*mp[i,i])div gcd(ans,mp[i,i]);
end;
writeln(ans);
end.


const ct:longint=1900000000;cp:longint=10007;
type sz=array[0..401,0..401] of longint;
var
        sum:array[0..201] of longint;
        dp:array[0..201,0..201,0..201] of longint;
        f,y,a:sz;
        s:ansistring;
        ans,len,pl,l,i,j,k,st,en,n:longint;
procedure qm(r:longint);
begin
        if r=1 then exit;
        qm(r shr 1);
        for i:=1 to len do for j:=i to len do begin
                a[i,j]:=0;
                for k:=i to j do begin
                        inc(a[i,j],f[i,k]*f[k,j]);
                        if a[i,j]>=ct then a[i,j]:=a[i,j] mod cp;
                end;
                a[i,j]:=a[i,j] mod cp;
        end;
        for i:=1 to len do for j:=i to len do f[i,j]:=a[i,j];
        if r and 1=1 then begin
                for i:=1 to len do for j:=i to len do a[i,j]:=0;
                for k:=1 to len do for i:=1 to k do if y[i,k]>0 then
                for j:=k to len do begin
                        inc(a[i,j],y[i,k]*f[k,j]);
                        if a[i,j]>=ct then a[i,j]:=a[i,j] mod cp;
                end;
                for i:=1 to len do for j:=i to len do begin
                        if a[i,j]<cp then f[i,j]:=a[i,j] else
                        f[i,j]:=a[i,j] mod cp;
                end;
        end;
end;
begin
        readln(s);l:=length(s);
        readln(n);n:=n+l;
        dp[1,l,0]:=1;
        for j:=1 to l do for k:=l downto j do for i:=0 to l do if dp[j,k,i]<>0
        then begin
                if s[j]<>s[k] then begin
                        inc(dp[j+1,k,i+1],dp[j,k,i]);
                        if dp[j+1,k,i+1]>=cp then dec(dp[j+1,k,i+1],cp);
                        inc(dp[j,k-1,i+1],dp[j,k,i]);
                        if dp[j,k-1,i+1]>=cp then dec(dp[j,k-1,i+1],cp);
                end else begin
                        inc(dp[j+1,k-1,i],dp[j,k,i]);
                        if dp[j+1,k-1,i]>=cp then dec(dp[j+1,k-1,i]);
                end;
        end;
        for i:=1 to l+1 do for j:=i-1 downto 0 do for k:=0 to l-1 do begin
                inc(sum[k],dp[i,j,k]);if sum[k]>=cp then dec(sum[k],cp);
        end;
        pl:=(l+1) shr 1;len:=l+2*pl;
        for i:=1 to l do f[i,i]:=24;
        for i:=l+1 to l+pl do begin
                f[i,i]:=25;f[i,i+pl]:=1;
        end;
        for i:=l+pl+1 to len do f[i,i]:=26;
        for i:=1 to l+pl-1 do f[i,i+1]:=1;
        for i:=1 to len do for j:=i to len do y[i,j]:=f[i,j];
        qm((n+1) shr 1);
        for i:=0 to l-1 do if sum[i]>0 then begin
                st:=l-i+1;en:=l+pl+st shr 1;
                inc(ans,sum[i]*f[st,en]);if ans>=ct then ans:=ans mod cp;
        end;
        if n and 1=1 then begin
                for i:=1 to len do for j:=i to len do f[i,j]:=y[i,j];
                qm((n+1) shr 1-1);
                for i:=0 to l-1 do if (sum[i]>0) and ((l-i) mod 2=0) then begin
                        st:=l-i+1;en:=l+st shr 1;
                        dec(ans,sum[i]*f[st,en]);if ans<0 then begin
                                ans:=ans mod cp;if ans<0 then inc(ans,cp);
                        end;
                end;
        end;
        writeln(ans mod cp);
end.


var
 s:string;
 st:array[1..1000]of longint;
 m,n,k,l,w,a,b,c,stn:int64;
 i,j:longint;
begin
 readln(a,b,c);
 for i:=1 to 81 do
 begin
  k:=1;
  for j:=1 to a do k:=k*i;
  w:=b*k+c;
  str(w,s);
  for j:=1 to length(s) do inc(l,ord(s[j])-48);
  if (l=i)and(w>0)and(w<1000000000) then begin inc(stn); st[stn]:=w; end;
  l:=0;
 end;
 writeln(stn);
 for i:=1 to stn do write(st[i],' ');
end.


const finp='';
      fout='';
var n:byte;
    a:Array[1..100] of byte;
procedure nhap;
var f:text;
    i:byte;
begin
    assign(f,finp);
    reset(f);
    readln(f,n);
    for i:=1 to n do
        read(f,a[i]);
    close(f);
end;
procedure sort;
var i,j,temp:byte;
begin
    for i:=1 to n-1 do
        for j:=i+1 to n do
            if a[i]>a[j] then
                begin
                    temp:=a[i];
                    a[i]:=a[j];
                    a[j]:=temp;
                end;
end;
function tinh:integer;
var i,k,lc,j:byte;
begin
    for i:=1 to a[1] do
        begin
            lc:=1;
            for j:=1 to n do
                if a[j] mod i<>0 then
                    begin
                        lc:=0;
                        break;
                    end;
            if lc=1 then
                k:=i;
        end;
    tinh:=k*n;
end;
procedure xuat;
var f:text;
    kq:integer;
begin
    assign(f,fout);
    rewrite(f);
    sort;
    kq:=tinh;
    write(f,kq);
    close(f);
end;
begin
    nhap;
    xuat;
end.


program tt;
uses math;

var a, b, root: array[ 0..200000 ] of longInt;
    t: array[ 0..8000000 ] of qWord;

procedure qsort( l, r: longInt );
var i, j, t, med: longInt;
begin
    if ( l < r ) then
    begin
        i := l;
        j := r;
        med := a[ b[ l + random(r - l + 1) ] ];
        while ( i <= j ) do
        begin
            while ( a[ b[i] ] < med ) do
                inc( i );

            while ( a[ b[j] ] > med ) do
                dec( j );

            if ( i <= j ) then
            begin
                t := b[i];
                b[i] := b[j];
                b[j] := t;

                inc( i );
                dec( j );
            end;
        end;

        qsort( l, j );
        qsort( i, r );
    end;
end;

function compress( lSon, rSon, mn: longInt ): qWord;
begin
    exit( qWord(200001) * ( qWord(8000000) * qWord(lSon) + qWord(rSon) ) + qWord(mn) );
end;

procedure decompress( mask: qWord; var lSon, rSon, mn: longInt );
begin
    mn := mask mod 200001;
    mask := mask div 200001;
    rSon := mask mod 8000000;
    lSon := mask div 8000000;
end;

function build_tree( prev: longInt ): longInt;
const   tw: longInt = 0;
begin
    inc( tw );
    t[tw] := t[prev];

    exit( tw );
end;

function get( v, l, r: longInt ): longInt;
begin
    if ( l = r ) then
        exit( v );

    exit( t[v] mod 200001 );
end;

function add( v, l, r, ll, rr: longInt ): longInt;
var c, delta, lSon, rSon, mn: longInt;
begin
    if ( l = r ) then
        exit( v + 1 );

    v := build_tree( v );

    if ( ll <= l ) and ( r <= rr ) then
    begin
        inc( t[v], 1 );

        exit( v );
    end;

    decompress( t[v], lSon, rSon, mn );

    c := ( l + r ) div 2;

    delta := mn - min( get( lSon, l, c ), get( rSon, c + 1, r ) );
    if ( ll <= c ) then
        lSon := add( lSon, l, c, ll, rr );

    if ( rr > c ) then
        rSon := add( rSon, c + 1, r, ll, rr );

    mn := min( get( lSon, l, c ), get( rSon, c + 1, r ) ) + delta;

    t[v] := compress( lSon, rSon, mn );

    exit( v );
end;

function query( v, l, r, ll, rr: longInt ): longInt;
var res, c, delta, lSon, rSon, mn: longInt;
begin
    if ( l = r ) then
        exit( v );

    if ( ll <= l ) and ( r <= rr ) then
        exit( t[v] mod 200001 );

    decompress( t[v], lSon, rSon, mn );

    c := ( l + r ) div 2;

    delta := mn - min( get( lSon, l, c ), get( rSon, c + 1, r ) );

    res := 100000000;
    if ( ll <= c ) then
        res := min( res, query( lSon, l, c, ll, rr ) );

    if ( rr > c ) then
        res := min( res, query( rSon, c + 1, r, ll, rr ) );

    exit( delta + res );
end;

var n, m, q, i, j, l, r, x, y, ans: longInt;

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

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

    qsort( 1, n );

    root[0] := 0;
    for i := 1 to n do
    begin
        r := min( b[i], n - m + 1 );
        l := max( 1, b[i] - m + 1 );

        root[i] := add( root[i - 1], 1, n - m + 1, l, r );
    end;

    ans := 0;
    readln( q );
    for i := 1 to q do
    begin
        readln( l, r, x );

        x := x xor ans;

        y := 0;
        for j := 20 downto 0 do
            if ( y + 1 shl j <= n ) and ( a[ b[y + 1 shl j] ] < x ) then
                inc( y, 1 shl j );

        ans := query( root[y], 1, n - m + 1, l, r );

        writeln( ans );
    end;
end.


// yk keep smile its sunnah :)
// codeforces  95 div 2 :

uses strutils, sysutils, math;
const MaxN=maxlongint; inf = 1000000000;
type int = longint;  bool = boolean;

procedure inn;
begin
    assign(input,'a.in'); reset(input);
    assign(output,'a.out'); rewrite(output);
end;

var
    n,m,t,i,j,x,men : int;
    ans : int64;
    c : array[0..100,0..100] of int64;

begin
    //inn;
    read(n,m,t);
    for i:=1 to 31 do begin
        c[i,0]:=1;
        for j:=1 to i do
            c[i,j]:=c[i-1,j-1]+c[i-1,j];
    end;

    for men:=4 to n do
        if (t-men>=1) and (t-men<=m) then
                ans:=ans+c[n+1,men]*c[m+1,t-men];

    write(ans);
    close(output);
end.


var

map : array [-10..10,-10..10] of longint;
i,j : longint;
s :string;

begin

   for i:=1 -4 to 8 do
    for j:=1 -4 to 8 do
     map[i,j]:=100;

   for i:=1 to 4 do
     begin
      readln(s);
       for j:=1 to 4 do
        begin
         if s[j] = '.' then map[i,j]:=0 else
         if s[j] = 'x' then map[i,j]:=1 else
         map[i,j]:=100;
        end;
      end;

   //   writeln(map[2,3],' ',map[3,2],' ',map[4,1]);

      for i:=1 to 4 do
        for j:=1 to 4 do
        begin
         if ((map[i,j]+map[i,j+1]+map[i,j+2]) = 2){ or
          ((map[i,j]+map[i,j+1]+map[i,j+2]) = 3)} then
          begin
           writeln('YES');
          // writeln(i,' ',j,' ',1);
           halt;
          end;

         if ((map[i,j]+map[i+1,j]+map[i+2,j]) = 2){ or
          ((map[i,j]+map[i+1,j]+map[i+2,j]) = 3)} then
          begin
           writeln('YES');
          // writeln(i,' ',j,' ',2);
           halt;
          end;

         if ((map[i,j]+map[i+1,j+1]+map[i+2,j+2]) = 2) {or
          ((map[i,j]+map[i+1,j+1]+map[i+2,j+2]) = 3)} then
          begin
           writeln('YES');
         //  writeln(i,' ',j,' ',3);
           halt;
          end;

         if ((map[i,j]+map[i+1,j-1]+map[i+2,j-2]) = 2) {or
         ((map[i,j]+map[i-1,j-1]+map[i-2,j-2]) = 3)} then
          begin
           writeln('YES');
          // writeln(i,' ',j,' ',4);
           halt;
          end;
         end;

     writeln('NO');
  end.


program cf65a;
var
  n,i,j:longint;
  x:double;
  a,b:longint;
begin
  x:=1;
  for i:=1 to 2 do begin
    read(a,b);
    if (a=0) then begin
      if b<>0 then x:=x+1e50
      else begin
        x:=0;
      end;
    end
    else x:=x*(b/a);
  end;

  if x>1e45 then writeln('Ron')
  else begin
    if x<1e-7 then begin
      writeln('Hermione');
      halt;
    end;

    read(a,b);
    if (a=0) then begin
      if b<>0 then x:=x+1e50
      else begin
        x:=0;
      end;
    end
    else x:=x*(b/a);

    if x>1 then writeln('Ron') else writeln('Hermione');
  end;
end.