{$mode objfpc}

const           InputFile                       =       'problemA.inp';

var             x , t , a , b , da , db         :       integer;
                i , j , tmp                     :       integer;

procedure Result( s : string );
        begin
                writeln( s );
                halt;
        end;

begin
                readln( x , t , a , b , da , db );
                if ( x = 0 ) then Result( 'YES' );
                if ( a + b < x ) then Result( 'NO' );
                for i := 0 to t - 1 do
                        begin
                                if a - da * i = x then Result( 'YES' );
                                if b - db * i = x then Result( 'YES' );
                        end;
                for i := 0 to t - 1 do
                for j := 0 to t - 1 do
                if ( a - da * i + b - db * j ) = x then
                        begin
                                writeln( 'YES' );
                                exit;
                        end;
                writeln( 'NO' );
end.


var s : string;
var i,n:integer;
var b:boolean;
begin
readln(n);
readln(s);
b := true;

if n > 1 then begin
if (s[1] =s[2]) or (s[s.length] =s[s.Length -1] ) then b := false;
if (b = true) and (n >=2) then
for i := 2 to n-1 do
begin
if (s[i-1] = '1') and (s[i] = '1') or (s[i-1] ='0') and (s[i] ='0') and (s[i+1] ='0')  then b := false;
end; end else if (s ='0') then b := false;

if (b = false) then writeln('No') else writeln('Yes');
end.


{papich v dele skill na predele}
var i, a, b,g,x:int64;
begin
readln(a);
b:=3;
for i:=2 to a do begin
 g:=b;
 b:=(b*2+x*3)mod 1000000007;
 X:=g;
 end;
writeln(g);
end.


var s:string;
i,n,d:integer;
begin
read(s);
n:=0;
d:=101;
for i:=1 to length(s) do
 begin
 if (s[i]= '1')and (i<d) then
 begin
 d:=i;
 end;
 end;
for i:=d to length (s) do
 begin
 if s[i]='0' then
 inc(n);
 end;
if (n>5) and (d<>0) then
 write ('yes')
 else
  write ('no');
end.


 var n,m,c,d,k,p,q,suma:longint;
  begin
   read(c,d);
   read(n,m);
   read(k);
   If m*n<=k then writeln(0) else
   begin
   p:=m*n-k;
   q:=p div n;
   If q*c<d*q*n then suma:=q*c else suma:=d*q*n;
   p:=p-q*n;
   If p=0 then writeln(suma) else
   if p*d<c then writeln(p*d+suma) else writeln(c+suma);
   end;
   end.


var n1,niz:array[0..10] of longint;
    nb:array[0..10] of boolean;
    n0:array[0..10] of string;
    n,k,i,r,max,min,br:longint;
procedure per(x:longint);
var i,j:longint;
begin
  if x=k+1 then
   begin
     min:=maxlongint;
     max:=0;
     for i:=1 to n do
      begin
        br:=0;
        for j:=1 to k do
         br:=br+(ord(n0[i][niz[j]])-ord('0'))*n1[j];
        if br>max then max:=br;
        if br<min then min:=br;
      end;
     if max-min<r then r:=max-min;
     exit;
   end;
  for i:=1 to k do
   if not nb[i] then
    begin
      niz[x]:=i;
      nb[i]:=true;
      per(x+1);
      niz[x]:=0;
      nb[i]:=false;
    end;
end;
begin
  readln(n,k);
  for i:=1 to n do
   readln(n0[i]);
  n1[k]:=1;
  for i:=k-1 downto 1 do
   n1[i]:=n1[i+1]*10;
  r:=maxlongint;
  per(1);
  writeln(r);
end.


var
s:string;
a,kitten,n,k,j,i,t:byte;
c:array[0..11]of byte;
begin
readln(n,k,t);
     for i:=1 to n do begin
       readln(s);
         for j:=1 to k do if s[j]='Y' then
            begin inc(c[j]);if c[j]=t then inc(a);end;
        end;
         write(a);
         end.


Program Main;
  Uses DOS ;
  var F , S : Ansistring ;
      FPos , SPos : LongInt;
      moved : Boolean;
      N : LongInt;

      wasBest : Array [ 1 .. 1000001 ] of LongInt;
  Function Nega ( c : Char ) : Char ;
  begin
    if ( c = 'S' ) then
      exit ( 'N' )
    else if ( c = 'N' ) then
      exit ( 'S' )
    else if ( c = 'W' ) then
      exit ( 'E' )
    else
      exit ( 'W' ) ;
  end;
  Function Free ( i , j : LongInt ) : Boolean;
  begin
    if ( j = 0 ) then
      exit ( true ) ;

    if ( S[j] = nega(F[i] ) ) then
      exit ( false ) ;

    Free := true;
  end;

  Procedure DoIt ( c : Char ) ;
  begin
    if (FPos <= N) and ( F[FPos] = c ) then
      inc ( FPos )
    else if ( FPos <> 1 ) then
      if ( F[FPos-1] = nega(c) ) then
        dec ( FPos);

   if (SPos <= N) and ( S[SPos] = c ) then
      inc ( SPos )
    else if ( SPos <> 1 ) then
      if ( S[SPos-1] = nega(c) ) then
        dec ( SPos )    ;

    if ( FPos > N ) and ( SPos > N ) then
    begin
      writeLn ( 'YES' ) ;
      halt();
    end;
  end;

  var StartTime : Int64;
      i : LongInt;
begin
  readLn ( N ) ;
  N := N - 1 ;
  FPos := 1 ;
  SPos := 1 ;

  readLn ( F ) ;
  readLn ( S ) ;

  StartTime := GetMSCount;
  for I := 1 to N do
    DoIt ( F[FPos] ) ;

  while ( GetMSCount - StartTime < 1900 ) do
  begin
    moved := false;
    if ( Free ( FPos , SPos-1 ) ) then
      DoIt(F[FPos] );
    if ( Free ( FPos-1 , SPos ) ) then
      DoIt(S[SPos] );

    if ( not moved ) then
    begin
      if ( wasBest [ SPos ] = 0 ) or ( wasBest[ Spos] < FPos ) then
      begin
        wasBest [ SPos ] := FPos ;
        DoIt(S[SPos]);
      end
      else
      begin
        DoIt(F[Fpos] ) ;
      end;

    end;
  end;

  writeLn ( 'NO' ) ;

end.


uses math;

const
        maxc=1000000000+69;

type
        re=record
                x,y:longint;
        end;

var
        ii:longint;
        n,l,r,res:int64;
        f,g:array[0..60] of int64;

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

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

function getval(x,y,u,g:int64):int64;
var
        mid,res:int64;
begin
        if x>u then exit(0);
        if y<=u then exit(g);
        mid:=(x+y) div 2;
        res:=getval(x,mid-1,u,g div 2)+getval(mid+1,y,u,g div 2);
        if u>=mid then res:=res+g mod 2;
        exit(res);
end;

procedure xuli;
var
        i:longint;
begin
        readln(n,l,r);
        f[0]:=n;
        if n>1 then
        for i:=1 to 50 do
        begin
                f[i]:=f[i-1] div 2;
                if f[i]=1 then
                begin
                        ii:=i;
                        break;
                end;
        end;

        g[ii]:=1;
        for i:=ii-1 downto 0 do
        begin
                g[i]:=g[i+1]*2+1;
        end;

        res:=getval(1,g[0],r,n)-getval(1,g[0],l-1,n);
        writeln(res);
end;

begin
        //mofile;
        xuli;
        dongfile;
end.


program A133;

{$APPTYPE CONSOLE}

uses
  SysUtils;
const let=['H','9','Q'];
var i,c:integer;
s:string;
begin
  read(s);
  c:=0;
  for i:=1 to length(s) do
     if s[i] in let then begin inc(c); break; end;
  if c<>0 then write('YES')
  else write('NO');
end.


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

Uses SysUtils;
Type tname=Array [1..10] of String;
     tm=Array [1..10] of LongInt;
Var name:tname;
    och,goal,raz,nogoal,aa:tm;
    kol,i:LongInt;
    s,name1,name2,nsop:String;
    k,ii,comm,o1,o2,sop,j:LongInt;
    f:Boolean;
    aoldgoal,aoldnogoal,boldgoal,boldnogoal,bestxmy,bestx,besty,xmy:LongInt;

Function Give (x,y:LongInt):LongInt;
Begin
     If x=y then Begin Result:=1; Exit End;
     If x>y then Begin Result:=3; Exit End;
     If x<y then Begin Result:=0; Exit End;
     Result:=0;
End;

Function Prov:LongInt;
Var i:LongInt;
Begin
     For I:=1 to 4 do
     If (aa[i]=2) and (i<>comm)
     then Begin Result:=i; Exit End;
     Result:=0;
End;

Procedure Sort (l,r:LongInt);
Var i,j,x,y,z,b:LongInt;
    nam,nn:String;
Begin
     i:=l;
     j:=r;
     x:=och[(l+r) div 2];
     y:=raz[(l+r) div 2];
     z:=goal[(l+r) div 2];
     nam:=name[(l+r) div 2];
     Repeat
           While (och[i]>x) or ((och[i]=x) and (raz[i]>y)) or ((och[i]=x) and (raz[i]=y) and (goal[i]>z)) or ((och[i]=x) and (raz[i]=y) and (goal[i]=z) and (name[i]<nam)) do Inc (i);
           While (och[j]<x) or ((och[j]=x) and (raz[j]<y)) or ((och[j]=x) and (raz[j]=y) and (goal[j]<z)) or ((och[j]=x) and (raz[j]=y) and (goal[j]=z) and (name[j]>nam)) do Dec (j);
           If i<=j
           then Begin
                     b:=och[i]; och[i]:=och[j]; och[j]:=b;
                     b:=raz[i]; raz[i]:=raz[j]; raz[j]:=b;
                     b:=goal[i]; goal[i]:=goal[j]; goal[j]:=b;
                     b:=nogoal[i]; nogoal[i]:=nogoal[j]; nogoal[j]:=b;
                     nn:=name[i]; name[i]:=name[j]; name[j]:=nn;
                     Inc (i); Dec (j);
                End;
     Until i>j;
     If i<r then Sort (i,r);
     If j>l then Sort (l,j);
End;

Function FindI:LongInt;
Var i:LongInt;
Begin
     For I:=1 to 4 do
     If name[i]='BERLAND'
     then Begin Result:=i; Exit End;
     Result:=0;
End;

Function FindOn:LongInt;
Var i:LongInt;
Begin
     For I:=1 to 4 do
     If name[i]=nsop
     then Begin Result:=i; Exit End;
     Result:=0;
End;

Begin
     //Assign (input,'input.txt'); ReSet (input);
     //Assign (output,'output.txt'); ReWrite (output);
     kol:=0;
     comm:=0;
     FillChar (aa,sizeof (tm),0);
     For I:=1 to 5 do
     Begin
          Readln (s);
          k:=Pos (' ',s);
          name1:=Copy (s,1,k-1);
          Delete (s,1,k);

          k:=Pos (' ',s);
          name2:=Copy (s,1,k-1);
          Delete (s,1,k);

          o1:=StrToInt (s[1]);
          o2:=StrToInt (s[3]);
          f:=False;
          For Ii:=1 to kol do
          If name[ii]=name1
          then Begin
                    Inc (goal[ii],o1);
                    Inc (och[ii],give (o1,o2));
                    Inc (nogoal[ii],o2);
                    Inc (aa[ii]);
                    f:=True;
                    Break
               End;
         If not f
         then Begin
                   Inc (kol);
                   name[kol]:=name1;
                   goal[kol]:=o1;
                   och[kol]:=give (o1,o2);
                   nogoal[kol]:=o2;
                   Inc (aa[kol]);
                   If name1='BERLAND'
                   then comm:=kol;
              End;

           f:=False;
          For Ii:=1 to kol do
          If name[ii]=name2
          then Begin
                    Inc (goal[ii],o2);
                    Inc (och[ii],give (o2,o1));
                    Inc (nogoal[ii],o1);
                    f:=True;
                    Inc (aa[ii]);
                    Break
               End;
         If not f
         then Begin
                   Inc (kol);
                   name[kol]:=name2;
                   goal[kol]:=o2;
                   och[kol]:=give (o2,o1);
                   nogoal[kol]:=o1;
                   Inc (aa[kol]);
                   If name2='BERLAND'
                   then comm:=kol;
              End;
     End;
     sop:=Prov;
     nsop:=name[sop];
     Inc (och[comm],3);
     f:=False;

     aoldgoal:=goal[comm];
     aoldnogoal:=nogoal[comm];
     boldgoal:=goal[sop];
     boldnogoal:=nogoal[sop];

     bestxmy:=100000;
     bestx:=100000;
     besty:=100000;

     For I:=1 to kol do
     raz[i]:=goal[i]-nogoal[i];

     For I:=1 to 100 do
     Begin
          For J:=0 to i-1 do
          Begin
               Inc (goal[comm],i);
               Inc (nogoal[comm],j);
               raz[comm]:=goal[comm]-nogoal[comm];

               Inc (goal[sop],j);
               Inc (nogoal[sop],i);
               raz[sop]:=goal[sop]-nogoal[sop];

               Sort (1,4);
               If (name[1]='BERLAND') or (name[2]='BERLAND')
               then Begin
                         f:=True;
                         xmy:=i-j;
                         If xmy<bestxmy
                         then Begin bestxmy:=xmy; besty:=j; bestx:=i; End
                         else If (xmy=bestxmy) and (j<besty)
                              then Begin besty:=j; bestx:=i; End;
                    End;
               comm:=FindI;
               sop:=FindOn;

               goal[comm]:=aoldgoal;
               nogoal[comm]:=aoldnogoal;
               goal[sop]:=boldgoal;
               nogoal[sop]:=boldnogoal;
          End;
     End;
     If f
     then Writeln (bestx,':',besty)
     else Writeln ('IMPOSSIBLE');
End.


var a:array [1..1000] of integer;
i,max,j,n,y,m,x,min:integer;

begin
readln(n,m);
max:=-maxint;
for i:=1 to n do
begin
  read(a[i]);
  if a[i]>max then max:=a[i];

end;

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

x:=0;
i:=1;

while x<m do
  if a[i]<a[n] then begin  inc(a[i]); inc(x); end else if i=n then begin i:=1; inc(a[n]); inc(x); end else inc(i);

min:=-maxint;

for i:=1 to n do
  if a[i]>min then min:=a[i];

   writeln(min,' ',max+m);
end.


program ex1;
var
  a,b,s,sta,ll,last,ans,wh:array[0..110000] of longint;
  i,j,k,n,m,e:longint;
  t,s1:ansistring;
  pool:array[0..110000] of record
                            number,next:longint;
                          end;

  procedure swap(x,y:longint);
  var
    t:longint;
  begin
    t:=a[x];a[x]:=a[y];a[y]:=t;
    t:=b[x];b[x]:=b[y];b[y]:=t;
  end;

  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 a[j]>x do dec(j);
      if not(i>j) then
        begin
          swap(i,j);
          inc(i);dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end;

  function find(x:longint):longint;
  var
    l,r:longint;
  begin
    r:=sta[x mod 100007];
    while r<>0 do
      begin
        l:=pool[r].number;
        if l=x then exit(r);
        r:=pool[r].next;
      end;
    exit(0);
  end;

begin
  readln(s1);
  readln(n);
  for i:=1 to n do
    begin
      readln(t);
      for j:=1 to length(t) do
        a[i]:=a[i] or (1 shl (ord(t[j])-97));
      b[i]:=i;
    end;
  sort(1,n);

  k:=0;
  for i:=1 to n do
    begin
    if a[i]>a[i-1] then
      begin
        inc(k);
        pool[k].number:=a[i];
        m:=a[i] mod 100007;
        pool[s[m]].next:=k;
        s[m]:=k;
        if sta[m]=0 then sta[m]:=k;
      end;
    wh[b[i]]:=k;
    end;

  for i:=1 to length(s1) do
    begin
      last[ord(s1[i])-97]:=i;
      for j:=0 to 25 do
        begin
          a[j]:=last[j];
          b[j]:=j;
        end;
      sort(0,25);
      m:=0;
      for j:=25 downto 0 do
       if a[j]=0 then break
       else
         begin
           m:=m or (1 shl b[j]);
           e:=find(m);
           if e>0 then
             if (a[j]>ll[e]+1)or(ll[e]=0) then
               begin
                 ll[e]:=i;
                 inc(ans[e]);
               end
             else ll[e]:=i;
         end;
    end;
  for i:=1 to n do writeln(ans[wh[i]]);
end.


var
    n,k,l,r,mid:int64;

begin {main}
  readln(n,k);
  if n=1 then
    writeln(0)
  else
    if (k+2)*(k-1) div 2-(k-2)<n then
      writeln(-1)
    else
      begin
        l:=2;r:=k;
        repeat
          mid:=(l+r) shr 1;
          if (k+mid)*(k-mid+1) div 2-(k-mid)>=n then l:=mid+1 else r:=mid-1;
        until l>r;
        writeln(k-l+2);
      end;
end.


program z1;
var
  a, n, b, i : longint;
  s, z : string;
begin
  readln(n);
  for i := 1 to n do
    begin
      str(i, z);
      s := s + z;
    end;
  write(s[n]);
end.


Program eee;
Const
  Infile='';
  Outfile='';
  modd=1000000007;
Var
  n,m,i,j,p,q,r:Longint;
  c:Array[0..1100,0..1100] Of Int64;
  f:Array[0..1100,0..1100,0..1,0..1,0..1] Of Int64;
  g:Array[0..1100] Of Int64;
  dq:Int64;
Begin
  Assign(Input,Infile);
  Assign(Output,Outfile);
  Reset(Input);
  Rewrite(Output);
  Readln(n,m);
  c[0,0]:=1;
  For i:=1 To n Do Begin
    c[i,0]:=1;
    For j:=1 To i Do c[i,j]:=(c[i-1,j]+c[i-1,j-1]) Mod modd;
  End;
  f[0,0,1,1,0]:=1;
  For i:=0 To n-1 Do
    For j:=0 To n Do  Begin
      For p:=0 To 1 Do
        For q:=0 To 1 Do
          For r:=0 To 1 Do Begin
            f[i+1,j,q,r,0]:=(f[i+1,j,q,r,0]+f[i,j,p,q,r]) Mod modd;
            f[i+1,j+1,q,r,1]:=(f[i+1,j+1,q,r,1]+f[i,j,p,q,r]) Mod modd;
            If (q=0) Then f[i+1,j+1,1,r,0]:=(f[i,j,p,q,r]+f[i+1,j+1,1,r,0]) Mod modd;
          End;
    End;
  For  i:=0 To n Do g[i]:=(f[n,i,0,0,0]+f[n,i,0,1,0]+f[n,i,1,0,0]+f[n,i,1,1,0]) Mod modd;
  dq:=1;
  For i:=n Downto 0 Do Begin
    g[i]:=(g[i]*dq) Mod modd;
    For j:=n Downto i+1 Do Begin
      g[i]:=(g[i]-g[j]*c[j,i]) Mod modd;
      IF g[i]<0 Then g[i]:=g[i]+modd;
    End;
    dq:=(dq*(n-i+1)) Mod modd;
  End;
  Writeln(g[m]);
  Close(Input);
  Close(Output);
End.


program P8C;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, Math
  { you can add units after this };
var
  xs, ys: Integer;
  i, n: Integer;
  Px, Py: array [0..25] of Integer;
  DP: array [0..16*1024* 1024] of Integer;

function Distance (i, j: Integer): Integer;
begin
  Result:= Sqr (Px [i]- Px [j])+ Sqr (Py [i]- Py [j]);

end;

function Solve (x: Integer): Integer;
var
  Temp: Integer;
  i, j: Integer;

begin
  if x= 0 then
  begin
    DP [x]:= 0;
    Exit (0);

  end;

  if 0<= DP [x] then
    Exit (DP [x]);

  Result:= MaxInt;
  for i:= 0 to n- 1 do
    if (x and (1 shl i))<> 0 then
    begin
      for j:= i+ 1 to n- 1 do
        if (x and (1 shl j))<> 0 then
        begin
          Temp:= Solve ((x xor (1 shl i)) xor (1 shl j));
          Result:= Min (Result, Temp+ Distance (i+ 1, 0)+ Distance (i+ 1, j+ 1)+
            Distance (j+ 1, 0));

        end;

      break;
    end;

  for i:= 0 to n- 1 do
    if (x and (1 shl i))<> 0 then
    begin
      Temp:= Solve (x xor (1 shl i));
      Result:= Min (Result, Temp+ 2* Distance (i+ 1, 0));
      break;

    end;

  DP [x]:= Result;;

end;

procedure PrintPath (x: Integer);
var
  i, j: Integer;
  Temp: Integer;

begin
  if x= 0 then
    Exit;

  for i:= 0 to n- 1 do
    if (x and (1 shl i))<> 0 then
    begin
      for j:= i+ 1 to n- 1 do
        if (x and (1 shl j))<> 0 then
        begin
          Temp:= DP [(x xor (1 shl i)) xor (1 shl j)];
           if DP [x]= Temp+ Distance (i+ 1, 0)+ Distance (i+ 1, j+ 1)+
             Distance (j+ 1, 0) then
           begin
             Write (0, ' ', i+ 1, ' ', j+ 1, ' ');
             PrintPath ((x xor (1 shl i)) xor (1 shl j));
             Exit;

           end;

        end;

      break;
    end;

  for i:= 0 to n- 1 do
    if (x and (1 shl i))<> 0 then
    begin
      Temp:= DP [(x xor (1 shl i))];
      if DP [x]= Temp+ 2* Distance (i+ 1, 0) then
       begin
         PrintPath ((x xor (1 shl i)));
         Write (0, ' ', i+ 1, ' ');
         Exit;

       end;
       break;

    end;

end;

begin

  FillChar (Dp [0], SizeOf (DP), 255);
  ReadLn (Px [0], Py [0]);
  ReadLn (n);
  for i:= 1 to n do
    ReadLn (Px [i], Py [i]);
  WriteLn (Solve ((1 shl n)- 1));
  PrintPath ((1 shl n)- 1);
  WriteLn (' 0');

end.


var
  i,j,k,n,m:longint;
  s1,s2:string;
function day(s:string):longint;
begin
  if s='monday' then
  exit(1);
  if s='tuesday' then
  exit(2);
  if s='wednesday' then
  exit(3);
  if s='thursday' then
  exit(4);
  if s='friday' then
  exit(5);
  if s='saturday' then
  exit(6);
  if s='sunday' then
  exit(7);
end;
begin
    readln(s1);
    readln(s2);
    n:=day(s1);
    m:=day(s2);
    if n=m then writeln('YES')
    else if (m-n=3) or (m-n=2) then write('YES')
    else if(n+3-7=m) or (n+2-7=m) then write('YES')
    else write('NO');
end.


var f1,f2 : text;
    kt : array['A'..'Z'] of boolean;
    dem : array['A'..'Z'] of longint;
    n,k,i:longint;
    s:ansistring;

begin
assign(f1,'');reset(f1);
assign(f2,'');rewrite(f2);
readln(f1,n,k);
readln(f1,s);
for i := 1 to n do
        inc(dem[s[i]]);
//fillchar(kt,sizeof(kt),true);
for i := 1 to n do
        if (k=0) and (kt[s[i]]=false) then
                begin
                writeln(f2,'YES');
                close(f1);
                close(f2);
                halt;
                end
        else begin
             if kt[s[i]] = true then dec(dem[s[i]]);
             if kt[s[i]] = false then
                begin
                dec(k);
                kt[s[i]]:=true;
                dec(dem[s[i]]);
                end;
             if dem[s[i]] = 0 then inc(k);
             end;
write(f2,'NO');
close(f1);
close(f2);
end.


uses math;
var f:array[0..1 shl 20] of extended;
    n,l,r,m,i,j,k,mask:longint;
    x,y,a:array[0..22] of extended;
    next:extended;

function find(Dist,x,y,alpha:extended):extended;
var x2,y2,ansx,ansy,a1,a2,b1,b2,c1,c2,current:extended;
begin
 x2:=dist-x; y2:=-y;
 ansx:=x2*cos(-alpha)+y2*sin(-alpha);
 ansy:=y2*cos(-alpha)-x2*sin(-alpha);
 ansx:=ansx+x;
 ansy:=ansy+y;
 a1:=0;
 b1:=1;
 c1:=0;
 a2:=ansy-y;
 b2:=x-ansx;
 c2:=-a2*x-b2*y;
 if (abs(a1*b2-a2*b1)<1e-9) then find:=round(1e18) else
 begin
  current:=(b1*c2-b2*c1)/(a1*b2-a2*b1);
  if current<dist then current:=round(1e18);
  find:=current;
 end;
end;

begin
// assign(input,'input.txt'); reset(input);
 readln(n,l,r);
 for i:= 1 to n do
  readln(x[i],y[i],a[i]);
  {begin
   x[i]:=i;
   y[i]:=i;
   a[i]:=45;
  end;     }
 for i:= 1 to n do
  a[i]:=a[i]*pi/180;
 for i:= 0 to (1 shl n) - 1 do
  f[i]:=l;
 for i:= 0 to (1 shl n) - 1 do
  for j:= 1 to n do
   if i and (1 shl (j-1)) = 0 then
    begin
     next:=find(f[i],x[j],y[j],a[j]);
     if next>r then next:=r;
     mask:=i or (1 shl (j-1));
     if f[mask]<next then f[mask]:=next;
    end;
  if f[1 shl n - 1]>r then f[1 shl n - 1]:=r;
  writeln(f[1 shl n - 1]-f[0]:0:10);
end.


var a,b,c,c1,k,p :  integer;
Begin
  readln(a,b,c);
  p:=1;
  if a>b then a:=a mod b;
  while k<1000 do
    begin
      k:=k+1;
      c1:=a*10 div b;
      a:=a*10 mod b;
      if c=c1 then begin writeln(k); p:=0; break; end;
    end;
  if p=1 then writeln(-1);

end.


const max=100;
var n,x:integer;
    a:array[0..max] of boolean;
procedure init;
var i,j:integer;
begin
  readln(n,x);
  for i:=1 to n do
    begin
      read(j);
      a[j]:=true;
    end;
end;
procedure trys;
var cout,i:integer;
begin
  cout:=0;
  for i:=0 to x do
    if (a[i]=false) and (i<x) then inc(cout)
    else
      if (i=x) and (a[i]=true) then inc(cout);
 writeln(cout);
end;
begin
  init;
  trys;
  readln
end.


program p1;
var a,b,n,k,i,j:integer;
x:array [1..100] of integer;
y:array[1..100] of integer;
f:boolean;
begin
readln (n,a);
for i:=1 to n do
read (x[i]);

for i:=1 to n do
begin
  for j:=1 to n do
begin

if x[i]<>y[j] then inc(b);
if b=n then f:=true else f:=false;
end;
inc(k);
if f then y[k]:=x[i];
b:=0;
end;
b:=0;
for i:=1 to n do
if y[i] <>0 then inc(b);
k:=0;

if b>=a then begin
writeln ('YES');
for i:=1 to n do
begin
if y[i]<>0 then begin if k>=a then break; write(i,' '); inc(k); end;

end;
end
else
writeln ('NO');
end.


var
a:array[1..10000] of integer;
i,n,k:integer;
begin
read(n);
writeln((n div 2)+1)
end.


var a:array[1..360]of longint;
    i,j,k,l,m,n:longint;
procedure qSort(l,r:longint);
var i,j,w,q:longint;
begin
  i := l; j := r;
  q := a[(l+r) div 2];
  repeat
    while (a[i] < q) do inc(i);
    while (q < a[j]) do dec(j);
    if (i <= j) then
    begin
      w:=a[i]; a[i]:=a[j]; a[j]:=w;
      inc(i); dec(j);
    end;
  until (i > j);
  if (l < j) then qSort(l,j);
  if (i < r) then qSort(i,r);
end;
begin
    m := 360;
    read(n);
    for i := 1 to n do
            read(a[i]);
    for i := 1 to n do
        begin
            k := a[i];
            j := i + 1;
            while k + a[j] <= 180 do
                begin
                    k := k + a[j];
                    inc(j);
                    if j > n then j := 1;
                end;
            if (360 - k)-k < m then m := (360 - k)-k
        end;
    writeln(abs(m));
end.


var mid,n,m,k,t,w,mi,ma,p,o,mis,mas,oo:int64;i:longint;
begin
readln(n,m,k);
t:=0;w:=n;mi:=m-1;ma:=n-m;p:=n-1;o:=1;
while t<w do
  begin
  mid:=(t+w)div 2;
  if mid<=k then
    begin
    t:=mid+1;
    if mid<>k then
      begin
      mis:=mis+1;dec(p);
      end;
    end
  else
    begin
    w:=mid;
    mas:=mas+1;dec(p);
    end;
  end;
for i:=1 to mis do begin oo:=i;o:=o*(mi-oo+1) mod 1000000007;end;
for i:=1 to mas do begin oo:=i;o:=o*(ma-oo+1) mod 1000000007;end;
for i:=1 to p do begin oo:=i;o:=o*oo mod 1000000007;end;
writeln(o);
close(input);close(output);
end.


var n,s,k:int64;
    p,q:boolean;

function leap(x:int64):boolean;
begin
  if (x mod 400=0)or((x mod 4=0)and(x mod 100<>0)) then leap:=true
                                                   else leap:=false;
end;

begin
  readln(n);
  p:=leap(n);
  q:=leap(n+1);
  s:=n+1;
  if q then k:=2
       else k:=1;
  while (k mod 7<>0)or(q<>p) do
    begin
      q:=leap(s+1);
      if q then k:=(k+2) mod 7
           else k:=(k+1) mod 7;
      inc(s);
    end;
  writeln(s);
end.


var a,b,c,d:array[byte] of int32;
    i,j,k,n,r,l:int32;
begin
{assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);}
readln(n,L);
for i:=1 to n do read(a[i]);
for i:=1 to n do read(b[i]);
a[i+1]:=L+a[1];
b[i+1]:=L+b[1];
for i:=1 to n do
  begin
    c[i]:=a[i+1]-a[i];
    d[i]:=b[i+1]-b[i];
  end;
k:=0;
for i:=1 to n do
  begin
    r:=0;
    for j:=1 to n do
      if c[j]=d[(i+j-2) mod n+1] then r:=r+1;
    if r=n then k:=1;
  end;
if k=1 then write('YES') else write('NO');
end.


program pr;
 const size = 100010;

 type
     TConn = record
      d:longint;
      Prev:longint;
     end;

 var N,M, i, a,b, c1,c2:longint;
     Stat:array [1..size] of longint;

     List1,List2:array [1..size] of TConn;
     Head1,Head2:array [1..size] of longint;

     mask1,mask2:array [1..size] of boolean;

     f:text;

procedure add(a,b:longint);
begin
 inc(c1);

 List1[c1].d:=b;
 List1[c1].Prev:=Head1[a];

 Head1[a]:=c1;

 inc(c2);

 List2[c2].d:=a;
 List2[c2].Prev:=Head2[b];

 Head2[b]:=c2;
end;

procedure DFS1(a:longint);
 var i,b:longint;
begin
 mask1[a]:=true;

 i:=Head1[a];
 while (i <> 0) do
 begin
  b:=List1[i].d;

  if NOT(mask1[b]) then
   DFS1(b);

  i:=List1[i].Prev;
 end;
end;

procedure DFS2(a:longint);
 var i,b:longint;
begin
 mask2[a]:=true;

 i:=Head2[a];
 while (i <> 0) do
 begin
  b:=List2[i].d;

  if (Stat[b] <> 1) then
  begin
   if NOT(mask2[b]) then
    DFS2(b);
  end else
  begin
   mask2[b]:=true;
  end;

  i:=List2[i].Prev;
 end;
end;

begin
 assign(f, '');
 reset(f);

 readln(f, N,M);

 for i:=1 to N do
  read(f, Stat[i]);

 c1:=0;
 c2:=0;

 FillDWord(Head1, size, 0);
 FillDWord(Head2, size, 0);

 for i:=1 to M do
 begin
  readln(f, a,b);

  add(a,b);
 end;

 close(f);

 FillChar(mask1, size, false);
 FillChar(mask2, size, false);

 for i:=1 to N do
 begin
  if (Stat[i] = 1) then
   DFS1(i);

  if (Stat[i] = 2) then
   DFS2(i);
 end;

 for i:=1 to N do
  if (mask1[i] and mask2[i]) then
   writeln(1)
  else
   writeln(0);

 {for i:=1 to N do
  write(mask1[i],' ');
 writeln;

 for i:=1 to N do
  write(mask2[i],' ');
 writeln;  }
end.


var
        i,j,k,l,n,m,ans:longint;
        a,b:array[0..13,0..2] of longint;
        bb,bz:boolean;
function min(a,b:longint):longint;
begin
        if a>b then exit(b) else exit(a);
end;
begin
        {assign(input,'open5.in'); reset(input);
        assign(output,'open.out'); rewrite(output);}
        readln(n,m); ans:=100;
        for i:=1 to n do read(a[i,1],a[i,2]); readln;
        for i:=1 to m do read(b[i,1],b[i,2]);
        for i:=1 to n do
        begin
                bb:=false; bz:=false;
                for j:=1 to m do
                begin
                        if (a[i,1]=b[j,1]) and (a[i,2]=b[j,2]) then continue;
                        if (a[i,1]=b[j,1]) and (a[i,2]<>b[j,2]) then bb:=true;
                        if (a[i,1]=b[j,2]) and (a[i,2]<>b[j,1]) then bb:=true;
                        if (a[i,2]=b[j,1]) and (a[i,1]<>b[j,2]) then bz:=true;
                        if (a[i,2]=b[j,2]) and (a[i,1]<>b[j,1]) then bz:=true;
                end;
                if (bb) and (not bz) then
                begin
                        if (ans>0) and (ans<>a[i,1]) and (ans<>100)
                                then ans:=0 else ans:=min(ans,a[i,1]);
                end;
                if (not bb) and (bz) then
                begin
                        if (ans>0) and (ans<>a[i,2]) and (ans<>100)
                                then ans:=0 else ans:=min(ans,a[i,2]);
                end;
                if (bb) and (bz) then ans:=min(ans,-1);
        end;
        for j:=1 to m do
        begin
                bb:=false; bz:=false;
                for i:=1 to n do
                begin
                        if (a[i,1]=b[j,1]) and (a[i,2]=b[j,2]) then continue;
                        if (a[i,1]=b[j,1]) and (a[i,2]<>b[j,2]) then bb:=true;
                        if (a[i,1]=b[j,2]) and (a[i,2]<>b[j,1]) then bz:=true;
                        if (a[i,2]=b[j,1]) and (a[i,1]<>b[j,2]) then bb:=true;
                        if (a[i,2]=b[j,2]) and (a[i,1]<>b[j,1]) then bz:=true;
                end;
                if (bb) and (not bz) then
                begin
                        if (ans>0) and (ans<>b[j,1]) and (ans<>100)
                                then ans:=0 else ans:=min(ans,b[j,1]);
                end;
                if (not bb) and (bz) then
                begin
                        if (ans>0) and (ans<>b[j,2]) and (ans<>100)
                                then ans:=0 else ans:=min(ans,b[j,2]);
                end;
                if (bb) and (bz) then ans:=min(ans,-1);
        end;
        if ans=100 then ans:=-1;
        writeln(ans);
        {close(input);
        close(output);}
end.


program A_535;

var
  s:longint;

procedure ed(x:longint);
begin
  case x of
    1:write('one');
    2:write('two');
    3:write('three');
    4:write('four');
    5:write('five');
    6:write('six');
    7:write('seven');
    8:write('eight');
    9:write('nine');
  end;
end;

procedure des(x:longint);
begin
  case x of
    2:write('twenty');
    3:write('thirty');
    4:write('forty');
    5:write('fifty');
    6:write('sixty');
    7:write('seventy');
    8:write('eighty');
    9:write('ninety');
  end;
end;

begin
  read(s);
  if s=0
    then begin
      write('zero');
      exit;
    end;
  if s div 10 =1
    then begin
      case s mod 10 of
        0:write('ten');
        1:write('eleven');
        2:write('twelve');
        3:write('thirteen');
        5:write('fifteen');
        8:write('eighteen');
        4,6,7,9:
        begin
         ed(s mod 10);
         write('teen');
        end;
      end;
      exit;
    end;
  des(s div 10);
  if (s div 10<>0) and (s mod 10<>0)
    then write('-');
  ed(s mod 10);
end.


program pa;
var
  a:array[1..10001] of longint;
  s,max,temp:string;
procedure judge;
  var
    temp1,temp2:string;
    i:longint;
  begin
    temp1:='';temp2:='';
    for i:=1 to length(s) do
      if a[i]=1 then
        begin
          temp1:=temp1+s[i];
          temp2:=s[i]+temp2;
        end;
    if temp1=temp2 then
      if temp1>max then
        max:=temp1;
  end;
procedure try1(k:longint);
  var
    i:longint;
  begin
    if k>length(s) then begin judge;exit;end;
    for i:=0 to 1 do
      begin
        a[k]:=i;
        try1(k+1);
      end;
  end;
begin
  //assign(input,'a.in');reset(input);
  //assign(output,'a.out');rewrite(output);
  readln(s);
  max:='';temp:='';
  try1(1);
  writeln(max);
  //close(input);
  //close(output);
end.


var st,ss:string;
i,j:longint;
    st1:array[0..9] of string;
begin
 readln(st);
 for i:=0 to 9 do
  readln(St1[i]);
  i:=1;
  while i<80 do
  for j:=0 to 9 do
  begin
   ss:=copy(st,i,10);
   if ss=st1[j] then
    write(j);
   if j=9 then i:=i+10;end;

end.


var a:array[1..100]of integer;
i,n,k,b,e,s,max:integer;
begin
     readln(n,k);
     for i:=1 to n do
         read(a[i]);
     for b:=1 to k do
     begin
         s:=0;
         e:=0;
         for i:=1 to n do
             if (i - b) mod k <> 0 then
                if a[i] = -1 then
                   inc(s)
                else
                    inc(e);
         if abs(e-s) > max then
            max:=abs(e-s);
     end;
     writeln(max);
end.


{$OPTIMIZATION LEVEL2}
{$INLINE ON}

uses math;

const
        maxc=1000000000+69;

type
        re=record
                x,y:longint;
        end;

var
        n,m,d,c,mid:qword;

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

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

begin
        //mofile;
        readln(n,m);
        if m>=n then writeln(n) else
        begin
                d:=1;
                c:=n-m;
                while d<=c do
                begin
                        mid:=(d+c) div 2;
                        if (mid+1)<(((n-m)*2)-1)div mid+1 then d:=mid+1 else c:=mid-1;
                end;
                writeln(m+d);
        end;
        dongfile;
end.


var
  n,
  k,
  j,
  m,
  i:integer;
  a,b:array[1..50] of integer;
begin
  readln(n);
  for i:=1 to n do
    read(a[i]);
  b[1]:=a[n];
  k:=1;
  for i:=n-1 downto 1 do begin
    m:=0;
    for j:=1 to k do begin
      if a[i]=b[j] then m:=1;
    end;
    if m=0 then begin
      inc(k);
      b[k]:=a[i];
    end;
  end;
  writeln(k);
  for i:=k downto 1 do write(b[i],' ');
end.


var j,n,m,i:longint;
Function Proste (x:longint):boolean;
begin
proste:=true;
for j:=2 to x div 2 do
if x mod j=0 then begin
proste:=false;
break
end;
end;
begin
read(n,m);
i:=n+1;
while not proste (i)  do inc(i);
if m=i then write('YES')  else  write('NO')
end.


program aaa;
Var x,k,b,t,n:Int64;
    i:Integer;
Begin
     Readln (k,b,n,t);
     x:=1;
     For I:=1 to n do
     Begin
          x:=x*k+b;
          If x>t
          then Begin Writeln (n-i+1);
                     Halt;
                     End;
     End;
     Writeln (0);
End.


var
        ss,st,pres,pret,ans:array[0..100000+5] of longint;
        i,j,k,n,m,lens,lent,p,a,b,c,d,s0,t0,s1,t1,delta,delta2:longint;
        s,t:ansistring;
        bz:boolean;
function min(a,b:longint):longint;
begin
        if a>b then exit(b);
        exit(a);
end;
begin
       // assign(input,'e.in');
        //reset(input);
        //assign(output,'e.out');
        //rewrite(output);
        readln(s);
        readln(t);
        readln(n);
        lens:=length(s);
        lent:=length(t);
        for i:=1 to lens do
        begin
                ss[i]:=ss[i-1];
                if (s[i]='B') or (s[i]='C') then
                        inc(ss[i]);
                if s[i]='A' then
                        pres[i]:=pres[i-1]+1;
        end;
        for i:=1 to lent do
        begin
                st[i]:=st[i-1];
                if (t[i]='B') or (t[i]='C') then
                        inc(st[i]);
                if t[i]='A' then
                        pret[i]:=pret[i-1]+1;
        end;
        for p:=1 to n do
        begin
                readln(a,b,c,d);
                s0:=min(pres[b],b-a+1);
                t0:=min(pret[d],d-c+1);
                s1:=ss[b]-ss[a-1];
                t1:=st[d]-st[c-1];
                delta:=t1-s1;
                delta2:=s0-t0;
                if (delta<0)or(delta mod 2<>0)or(delta2<0)or (delta2=0)and not (s1<>0)and(delta>0) then
                begin
                        write(0);
                        continue;
                end;
                if (s0-t0=0)or(t1-s1>0)or((s0-t0) mod 3=0) then
                        write(1)
                else write(0);
        end;
        //close(input);
        //close(output);
end.


program aaa;
 var a,s,b,c,i,j,d,m,k,n:longint;{d:int64;s,w,q,z: string;}
 x,y,z: longint;{ p,x1,y1,x,y,t1,t2,v,z:real; {s:array[0..100009]of boolean;  }
   {q:char;w:int64;        {
   label 1;                 } f:boolean;
begin
 {assign(input,'input.txt');reset(input);
 assign(output,'output.txt');rewrite(output); }
 read(a,b);
 c:=a+b;
 x:=0;j:=1;
 while a>0 do
 begin
  i:=a mod 10;
  if i>0 then begin x:=x+j*i;j:=j*10;end;
  a:=a div 10;
 end; y:=0;j:=1;
 while b>0 do
 begin
  i:=b mod 10;
  if i>0 then begin y:=y+j*i;j:=j*10;end;
  b:=b div 10;
 end;
 z:=0;          j:=1;
 while c>0 do
 begin
  i:=c mod 10;
  if i>0 then begin z:=z+j*i;j:=j*10;end;
  c:=c div 10;
 end;
 if x+y=z then write('YES') else write('NO');
{ close(input);close(output);                   }
end.


const
 g1:string='abcdefghijklmnopqrstuvwxyz';
var
 i1:char;
 s1,s2,j,i:longint;
 a,b:ansistring;
 m1,m2:array['a'..'z']of longint;
begin
 readln(a);
 readln(b);
 for i:=1 to length(a) do inc(m1[a[i]]);
 for i:=1 to length(b) do inc(m2[b[i]]);
 for i1:='a'to 'z'do
 begin
  if m2[i1]>m1[i1] then
  begin
   writeln('need tree');
   halt;
  end;
  if m2[i1]<m1[i1] then s1:=1;
 end;
 j:=0;
 for i:=1 to length(b) do
 begin
  inc(j);
  while((j<=length(a))and(b[i]<>a[j]))do inc(j);
 end;
 if((j>length(a))or(b[length(b)]<>a[j]))then s2:=1;
 if (s1=1)and(s2=1)then
 begin
  writeln('both');
  halt;
 end;
 if s1=1 then
 begin
  writeln('automaton');
  halt;
 end;
 if s2=1 then
 begin
  writeln('array');
  halt;
 end;
end.


var a:array[0..300,0..300,0..2]of longint;
    u,f,b,c,d,e,i,j,o:longint;
begin
  read(b,c,d,e);
  a[0,0,1]:=1;
  a[0,0,2]:=1;
  o:=100000000;
  for i:=0to b do
    for j:=0to c do
      for f:=1to 2do
        if f=1then
          for u:=1to d do
            a[i+u,j,2]:=(a[i+u,j,2]+a[i,j,1])mod o
        else
          for u:=1to e do
            a[i,j+u,1]:=(a[i,j+u,1]+a[i,j,2])mod o;
  write((a[b,c,1]+a[b,c,2])mod o)
end.


program canh_toan;
//uses math;
const input='VAO.INP';
      output='RA.OUT';
      maxn=trunc(25e4);
var n,m:qword;
    c:array [0..maxn] of qword;
    f,g:text;
{function nhannp(x,y:qword):qword;
var tg:qword;
begin
if (y=0) then exit(0)
else if (y=1) then exit(x mod m)
else
  begin
    tg:=nhannp(x,y div 2) mod m;
    tg:=nhannp(2,tg) mod m;
    if (y mod 2=1) then tg:=(tg+x) mod m;
    exit(tg mod m);
  end;
end;
function munp(x,y:qword):qword;
var tg:qword;
begin
if (y=0) then exit(1)
else
  begin
    tg:=munp(x,y div 2) mod m;
    tg:=(nhannp(tg,tg)) mod m;
    if (y mod 2=1) then tg:=(nhannp(tg,x)) mod m;
    exit(tg mod m);
  end;
end;}
procedure main();
var i:longint;
    x,y,z,res,ans:int64;
begin
//assign(f,input);reset(f);
//assign(g,output);rewrite(g);
read(n,m);
c[0]:=1;
for i:=1 to n do c[i]:=(c[i-1]*i) mod m;
 res:=0;
for i:=1 to n do
    begin
      {x:=((n-i+1) mod m);
      y:=(c[i] mod m);
      z:=(c[n-i+1] mod m);
      res:=((res mod m)+(x*y*z) mod m) mod m;}
      //res:=(res+((n-i+1)*c[n-i+1])) mod m)*c[i]) mod m;
      res:=(res+((c[n-i+1]*(n-i+1)) mod m)*c[i]) mod m;
      res:=res mod m;
    end;
 ans:=res mod m;
write(ans);
//close(f);
//close(g);
end;
BEGIN
  main();
END.


var
n:longint;
begin
readln(n);
writeln((2*n+1) div 3);
end.


var s,s1,s2,s3:string;
    i,j:integer;
    c:char;
begin
 readln(s);
 s:=s+'WUB';

while pos('WUB',s)>0 do
 begin
  if pos('WUB',s)=1 then
   delete(s,1,3)
  else
   begin
    write(copy(s,1,pos('WUB',s)-1),' ');
    delete(s,1,pos('WUB',s)-1);
   end;
 end;

 readln;
 readln;
 end.


var a: array of integer;
function sum(a : int64):integer;
var ans:integer;
begin
  while (a > 0) do
    begin
      ans := ans + a mod 10;
      a := a div 10;
    end;
  sum := ans;
end;
begin
  var n, first: int64;
  readln(n);
  while (first * 10 + 9 <= n) do
    begin
      first := first * 10 + 9;
    end;
  print(sum(first) + sum(n - first));
end.


var
  n,i,min,max : longint;
  a : array [1..100000] of longint;

  Procedure QSort(l,r : longint);
  var
    i,j,x,y : longint;
  begin
    i:=l; j:=r; x:=a[(l+r) shr 1];
    repeat
      while x>a[i] do inc(i);
      while x<a[j] do dec(j);
      if j<i then break;
      y:=a[i]; a[i]:=a[j]; a[j]:=y;
      inc(i); dec(j);
    until j<i;
    if l<j then QSort(l,j);
    if i<r then QSort(i,r);
  end;

begin
  readln(n);
  for i:=1 to n do read(a[i]);
  QSort(1,n);
  for i:=1 to n-1 do
    if (a[i]*2>a[i+1]) and (a[i]<>a[i+1]) then begin writeln('YES'); exit; end;
  writeln('NO')
end.


program c;
const
  infile='c.in';
  outfile='c.out';
var
  r,h,ans,x:longint;
begin
  {assign(input,infile);
  reset(input);
  assign(output,outfile);
  rewrite(output); }

  readln(r,h);
  x:=h div r;
  h:=h mod r;
  if h<r/2 then ans:=1;
  if (h>=r/2) and (h<r*sqrt(3)/2) then ans:=2;
  if (h>=r*sqrt(3)/2) and (h<r) then ans:=3;
  ans:=ans+x*2;
  writeln(ans);

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


const md = 1000000007;
var
  i,n : longint;
  a,b : int64;

begin
  readln(n);
  a:=20; b:=7;
  for i:=2 to n do
    begin
      a:=(a*27 + 20*b) mod md;
      b:=(b*7) mod md;
    end;
  writeln(a);
end.


      const eps=0.0000000001;  besk=20000000000008;  nn=200000;

   label 1,2,3,4;
    type   { real=double;}  {string=ansistring;}
    mas=array [-10..nn] of longint;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of int64;mass1=^mass;
    var ot,maxzah, period,ppp,modul,v1,v2,kol,t,p,sum,k1,ii,jj,q,pos,z,pmax,imax,p3,p4,l,nm,n,s1,s2,m,s,smin,cen,dl,t2,i1:int64;
    start,h,nap,pp1,pp2,mask1,mask2,mask,newnapy,posi,posj,time,pp,step, k,t1,i,j:longint;
   oldpos,kk,osn, aaa,bbb, bb,ccc,dd:int64;
   zah, per, d1,aa,mm,tt,ll,r,x,y,fact,d,c,aold,b,a:array[-10..300000] of int64;
     al,ar:  array[-10..1200,-10..1200] of int64;
    ver, dda:   array[-10..1200,-10..1200] of extended;
     marked:array[-10..3000030] of boolean;
   zanx,zany:array[-10..200000] of boolean;
    sss, ss1,ss2:string;
    sot:array [-10..1000000] of char;
     zan,fl:array[-10..200000] of boolean;
    ss:string;ch:char;
   ddp, pole :array [-100..200,-100..200] of int64;
    maxpr:array[0..nn] of string;
    st2:array[0..nn] of string;
     p1,p2,v0,s0,t0:extended;
     zv:point;
     newx,newy,xx,yy:array[-1..200000] of int64;

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

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

function degg(p,deg:int64):int64; var pp,q:int64;
 begin if deg=0 then degg:=1 else begin   if odd(deg) then degg:=degg(p,deg-1)*p mod modul else
 begin q:=(degg(p,deg shr 1)) mod modul; degg:=(q*q) mod modul;   end; end;   end;

function good:boolean; var i,j,k:longint; fl:boolean;
 begin
     for i:=1 to n do d1[i]:=d[d[i]];
     fl:=true;
     for i:=1 to n do if d1[i]<>d[i] then fl:=false;
          good:=fl;

 end;

begin
 {   assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
  }
     readln(n); for i:=1 to n do read(a[i]);
    for i:=1 to n do d[i]:=a[i];

    if good then begin write(1); goto 1;  end;
 for step:= 1 to 1000 do
   begin

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

   {  for i:=1 to n do write(d[i],' '); writeln;
   }   if good then begin writeln(step+1); goto 1;  end;

   end;
3:

  for start:=1 to n do
   begin
      for i:=1 to n do zan[i]:=false;
      for i:=1 to n do c[i]:=0;

      q:=0;  pos:=start;
       if a[pos]=pos then begin  period:=0; goto 2;  end;
        repeat
          oldpos:=pos;
          inc(q); pos:=a[pos]; zan[pos]:=true; c[pos]:=q;
          period:=q-c[a[pos]];
       until zan[a[pos]];

 2:
   { writeln(start,' ',period,' ',q) ;
   } per[start]:=period+1;
    zah[start]:=q;

   end;

 {  for i:=1 to n do writeln(i,' ',per[i],' ',zah[i]);
 } for i:=1 to n do   maxzah:=max(maxzah,zah[i]);
     ot:=per[1];
  for i:=1 to n do
    begin
        t:=nod(ot,per[i]);
        ot:=(ot*per[i]) div t;
     {  writeln(i,' ',ot); }
    end;
    p:=ot;
    if ot>=maxzah-ot then begin  write(ot); goto 1; end;
    repeat ot:=ot+p until ot+p>=maxzah;
    writeln(ot);

   1:          close(output);
end.


var q,k,s,x1,x2,t1,t2,p,d:longint;
begin
  readln(s,x1,x2);
  readln(t1,t2);
  readln(p,d);

  q:=abs(x1-x2)*t2;
  if t2 < t1 then begin writeln(q); exit; end;

  if (d = -1) and (p < x1) then begin d:=1; k:=p*t1 + x1*t1; end
    else if (d = 1) and (p > x1) then begin d:=-1; k:=(s-p)*t1 + (s-x1)*t1; end
      else k:=abs(p-x1)*t1;

  if (x1 > x2) and (d = 1) then k:=k + (s-x1)*t1 + (s-x2)*t1
    else if (x1 < x2) and (d = -1) then k:=k + x1*t1 + x2*t1
      else k:=k + abs(x1-x2)*t1;

  if k < q then writeln(k) else writeln(q);

end.


label 1,2,3;
var x,y,x1,y1,i,j,k,o,o1:integer;ch:string;a,a1:char;b2:array[1..100,1..100]of longint;
b:array[1..8]of char:=('a','b','c','d','e','f','g','h');
b1:array[1..8]of longint;begin for i:=1 to 8 do b1[i]:=i;
readln(a,x);readln(a1,x1);x:=9-x;x1:=9-x1;
for i:=1 to 8 do begin if b[i]=a then y:=b1[i];if b[i]=a1 then y1:=b1[i];end;
b2[x,y]:=1;k:=1;o:=1;
3:for i:=1 to 8 do
for j:=1 to 8 do
if b2[i,j]=k then begin
if (j<8)and(b2[i,j+1]=0)then begin b2[i,j+1]:=k+1;inc(o1);end;
if (i<8)and(j<8)and(b2[i+1,j+1]=0)then begin b2[i+1,j+1]:=k+1;inc(o1);end;
if (i<8)and(b2[i+1,j]=0)then begin b2[i+1,j]:=k+1;inc(o1);end;
if (i>1)and(j<8)and(b2[i-1,j+1]=0)then begin b2[i-1,j+1]:=k+1;inc(o1);end;
if (i>1)and(b2[i-1,j]=0)then begin b2[i-1,j]:=k+1;inc(o1);end;
if (i>1)and(j>1)and(b2[i-1,j-1]=0)then begin b2[i-1,j-1]:=k+1;inc(o1);end;
if (j>1)and(b2[i,j-1]=0)then begin b2[i,j-1]:=k+1;inc(o1);end;
if (i<8)and(j>1)and(b2[i+1,j-1]=0)then begin b2[i+1,j-1]:=k+1;inc(o1);end;
dec(o);if o=0 then goto 1;if b2[x1,y1]<>0 then begin writeln(b2[x1,y1]-1);k:=b2[x1,y1];goto 2;end;end;
1:if o1>0 then begin o:=o1;o1:=0;inc(k);goto 3;end;
2:if(k>1)and(x1>1)and(b2[x1-1,y1]=k-1)then begin ch:='D '+ch;dec(k);dec(x1);goto 2;end;
if(k>1)and(y1>1)and(b2[x1,y1-1]=k-1)then begin ch:='R '+ch;dec(k);dec(y1);goto 2;end;
if(k>1)and(x1>1)and(y1>1)and(b2[x1-1,y1-1]=k-1)then begin ch:='RD '+ch;dec(k);dec(x1);dec(y1);goto 2;end;
if(k>1)and(x1>1)and(y1<8)and(b2[x1-1,y1+1]=k-1)then begin ch:='LD '+ch;dec(k);dec(x1);inc(y1);goto 2;end;
if(k>1)and(x1<8)and(b2[x1+1,y1]=k-1)then begin ch:='U '+ch;dec(k);inc(x1);goto 2;end;
if(k>1)and(x1<8)and(y1<8)and(b2[x1+1,y1+1]=k-1)then begin ch:='LU '+ch;dec(k);inc(x1);inc(y1);goto 2;end;
if(k>1)and(y1<8)and(b2[x1,y1+1]=k-1)then begin ch:='L '+ch;dec(k);inc(y1);goto 2;end;
if (k>1)and(x1<8)and(y1>1)and(b2[x1+1,y1-1]=k-1)then begin ch:='RU '+ch;dec(k);inc(x1);dec(y1);goto 2;end;

for i:=1 to length(ch) do
if ch[i]=' ' then writeln else write(ch[i]);
end.
{
Одинокий король остался совсем один на шахматной доске. Несмотря на одиночество, он вовсе не унывает — ведь ему еще надо сделать так много дел государственной важности. Например, ему надо совершить официальный визит в клетку t. Так как король не привык терять попусту время, он хочет добраться от своего местоположения s до клетки t за наименьшее число ходов. Помогите ему это сделать.

Король за один ход может переместиться на любую клетку, которая по стороне или углу граничит с текущей (их в общем случае 8).

Входные данные
В первой строке входных данных заданы шахматные координаты клетки s, а во второй — клетки t.

Шахматные координаты состоят из двух символов, один из которых это строчная буква латинского алфавита (от a до h), а второй — цифра от 1 до 8.

Выходные данные
В первую строку выведите n — минимальное число ходов короля. Далее в n строк выведите сами ходы. Каждый ход описывается одной из восьми строк: L, R, U, D, LU, LD, RU или RD.

L, R, U, D, соответственно, означают ходы влево, вправо, вверх и вниз (согласно рисунку), двухбуквенные обозначения соответствуют диагональным ходам. Если решений несколько, выведите любое.

Примеры
входные данныеСкопировать
a8
h1
выходные данныеСкопировать
7
RD
RD
RD
RD
RD
RD
RD
}


   const eps=0.0000000001;    nn=200000;
   label 1,2;
    type   { real=double;}  {string=ansistring;}
    mas=array [0..nn] of longint;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var t,tt,p,time,pp,jj,gr,qq,z,pmax,imax,p1,p2,p3,p4,l,ot,nm,n,s1,s2,m,s,smin,cen,dl,t2,i1:int64;
    step, k,i,j:longint;
     aa,bb,cc:int64;
     dplus,dminus,d1plus,d1minus,d2plus,d2minus,d1,d2,aold,b,a,x,y:array[-10..200000] of int64;
     dda:array[-10..1200,-10..1200] of int64;
   zan,zany:array[-10..2000000] of boolean;
    sss, ss1,ss2:string;
     fl:array[0..200] of boolean;
    ss:string;ch:char;
    pole :array [-10..2000,-10..2000] of char;
    maxpr:array[0..nn] of string;
    st2:array[0..nn] of string;
     v0,v1,s0,t0:real;
     zv:point;
     newx,newy,xx,yy:array[-1..200000] of int64;

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

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

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

end;
 }

begin
  {  assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
   }
   read(n); for i:=1 to n do read(a[i]);
   for i:=n downto 1 do
     begin
        {d1plus[i]:=a[i]+min(d2plus[i+1],d2minus[i+1]);
        d1minus[i]:=d1minus[i+1];

        d2plus[i]:=a[i]+max(d1plus[i+1],d1minus[i+1]);
        d2minus[i]:=d2minus[i+1];
         }

         dplus[i]:=a[i]+min(dplus[i+1],dminus[i+1]);
         dminus[i]:=max(dplus[i+1],dminus[i+1]);

     end;

     writeln(min(dplus[1],dminus[1]),' ',max(dplus[1],dminus[1]));

   1:          close(output);
end.


var n ,i,j,d,x:integer;
a:array[1..10000]of integer;
begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do for j:=1 to n do if a[i]<a[j] then swap(a[i],a[j]);
x:=a[n];
for i:=n-1 downto 1 do if (a[i]=a[i+1]) or (x mod a[i]<>0) then begin write(x,' ',a[i]); exit end;
end.


program _73F_PlaneOfTanks;

uses math;

const eps=1e-6;
	tiny=1e-8;
	maxn=10050;

var tank:array[1..maxn]of record x,y,a,w:extended;end;
	n,k,i:longint;
	mid,high,low,ll,v,tAB,ax,ay,bx,by:extended;

function dis(ax,ay,bx,by:extended):extended;
begin
	exit(sqrt(sqr(ax-bx)+sqr(ay-by)));
end;

function multi(ax,ay,bx,by:extended):extended;
begin
	exit(ax*by-ay*bx);
end;

function angleto(alpha,tx,ty,x,y:extended):extended;
var theta:extended;
begin
	theta:=arctan2(y-ty,x-tx)-alpha;
	while theta<0 do theta:=theta+2*PI;
	while theta>2*PI do theta:=theta-2*PI;
	if 2*PI-theta<theta then theta:=2*PI-theta;
	exit(theta);
end;

function shadow(tx,ty,alpha:extended):extended;
var lA,lB,lC,lk,AGx,AGy:extended;
begin
	lA:=ay-by;
	lB:=-(ax-bx);
	lC:=-lA*ax-lB*ay;
	lk:=(-lC-lA*tx-lB*ty)/(lA*cos(alpha)+lB*sin(alpha));
	AGx:=tx+lk*cos(alpha)-ax;
	AGy:=ty+lk*sin(alpha)-ay;
	exit(sqrt(sqr(AGx)+sqr(AGy)));
end;

function trisearch(tlow,thigh,tx,ty,alpha,wise,w:extended):boolean;
var tm1,tm2,f1,f2:extended;
begin
	repeat
		tm1:=(2*tlow+thigh)/3;
		tm2:=(tlow+2*thigh)/3;
		f1:=v*tm1-shadow(tx,ty,alpha+wise*tm1*w);
		f2:=v*tm2-shadow(tx,ty,alpha+wise*tm2*w);
		if f1<f2 then thigh:=tm2 else tlow:=tm1;
	until thigh-tlow<eps;
	tm1:=(thigh+tlow)/2;
	f1:=v*tm1-shadow(tx,ty,alpha+wise*tm1*w);
	if f1<0 then exit(true) else exit(false);
end;

function canattack(tx,ty,alpha,w:extended):boolean;
var t1,t2,t3,gx,gy,gll,px,py,lPA,lPB,mii,wise,d:extended;
begin
	if w<tiny then exit(false);
	// Scenario I
	t1:=angleto(alpha,tx,ty,bx,by)/w;
	if t1-tAB<tiny then exit(true);
	// Scenario II
	t2:=angleto(alpha,tx,ty,ax,ay)/w;
    if t2>t1 then exit(false);
	mii:=multi(ax-tx,ay-ty,bx-tx,by-ty);
	if mii>0 then wise:=1 else wise:=-1;
	d:=mii/ll;
	gx:=-(ay-by);
	gy:=ax-bx;
	gll:=sqrt(sqr(gx)+sqr(gy));
	px:=tx+gx*(d/gll);
	py:=ty+gy*(d/gll);
	lPA:=dis(px,py,ax,ay);
	lPB:=dis(px,py,bx,by);
	t3:=angleto(alpha,tx,ty,px,py)/w;
    if t1<t2 then t1:=2*PI/w-t1;
    if t3<t2 then t3:=2*PI/w-t3;
	if abs(lPA+lPB-ll)<tiny then begin
		if trisearch(t2,t3,tx,ty,alpha,wise,w) then exit(true);
		if trisearch(t3,t1,tx,ty,alpha,wise,w) then exit(true);
	end else
		if trisearch(t2,t1,tx,ty,alpha,wise,w) then exit(true);
	exit(false);
end;

function check:boolean;
var i,tot:longint;
begin
	tot:=0; v:=mid;
	tAB:=ll/v;
	for i:=1 to n do
		if canattack(tank[i].x,tank[i].y,tank[i].a,tank[i].w) then
			inc(tot);
	if tot<=k then exit(true) else exit(false);
end;

begin
	//assign(input,'73FPlaneOfTanks.in');reset(input);
	readln(ax,ay,bx,by);
	readln(n);
	for i:=1 to n do readln(tank[i].x,tank[i].y,tank[i].a,tank[i].w);
	readln(k);
	if n<=k then begin
		writeln(0.0:0:6);
		halt;
	end;
	ll:=dis(ax,ay,bx,by);
	low:=0;
	high:=ll*10;
	repeat
		mid:=(high+low)/2;
		if check then high:=mid else low:=mid;
	until high-low<eps;
	writeln(low:0:6);
end.


var q:array [0..10000] of qword; i,j,k:longint; n,a,b,c,min,max:qword;
 begin
  read (n);
  k:=0;
  for i:=1 to round(sqrt(n)) do
   begin
    if n mod i=0 then begin
                       inc (k);
                       q[k]:=i;
                       if i<>n div i then begin inc (k); q[k]:=n div i; end;
                      end;
   end;
  min:=10000000000000000000;
  max:=0;
  for i:=1 to k do
   for j:=1 to k do
    if (q[i]*q[j]<=n) and (n mod (q[i]*q[j])=0) then begin
                                                      a:=q[i]+1;
                                                      b:=q[j]+2;
                                                      c:=n div (q[i]*q[j])+2;
                                                      if a*b*c>max then max:=a*b*c;
                                                      if a*b*c<min then min:=a*b*c;
                                                     end;
  writeln (min-n,' ',max-n);
 end.


{$mode objfpc}
uses math;

const inpf='';
      outf='';
      maxN=round(1e5)+2;

var fi,fo:text;
    x,y:integer;

procedure openfiles;
  begin
    assign(fi,inpf);reset(fi);
    assign(fo,outf);rewrite(fo);
  end;

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

function ok(a,b,c:integer):boolean;
  begin
    if a+b<=c then exit(false);
    if a+c<=b then exit(false);
    if b+c<=a then exit(false);
    exit(true);
  end;

procedure solve;
  var a,b,c:integer;
      dem,res:integer;
  begin
    dem:=0;
    res:=0;
    a:=y;b:=y;c:=y;
    while dem<3 do
      begin
        if (a<=b) and (a<=c) and (a<>x) then
          begin
            a:=min(b+c-1,x);
            inc(res);
            if a=x then inc(dem);
          end;
        if (b<=a) and (b<=c) and (b<>x) then
          begin
            b:=min(a+c-1,x);
            inc(res);
            if b=x then inc(dem);
          end;
        if (c<=b) and (c<=a) and (c<>x) then
          begin
            c:=min(a+b-1,x);
            inc(res);
            if c=x then inc(dem);
          end;
      end;
    writeln(res);
  end;

begin
  openfiles;
  readln(Fi,x,y);
  solve;
  closefiles;
end.


uses
    math;

type
    tr = record
        x,y:longint;
    end;

var
    a,c:array[0..20] of tr;
    i,j,n,m,mask,ans,res,pos:longint;

Begin
    read(n,m);
    for i:=1 to n do
        read(a[i].x,a[i].y);
    ans:=maxlongint;
    for mask:=0 to (1 shl n) - 1 do
        begin
            res:=0; c:=a;
            for j:=1 to n do
                if (mask and (1 shl (j-1))) > 0 then
                    begin
                        inc(res, a[j].y);
                        inc(c[n+1].x);
                    end
                else
                    inc(c[j].x);
            pos:=0;
            for i:=1 to n do
                if (c[i].x > c[n+1].x) or
                   ((c[i].x = c[n+1].x) and (mask and (1 shl (i-1)) = 0)) then
                    inc(pos);
            if pos < m then
                ans:=min(ans, res);
        end;
    if ans = maxlongint then
        writeln(-1)
    else
        writeln(ans);
end.


Uses sysutils, math;
var
i:longint;
n,k,l,p,s,nn,d:int64;
begin
readln(n,k);
l:=1;
for i:=1 to k do
l:=l*10;
if n mod l=0 then write(n)
else begin
nn:=n; p:=0; d:=0;
while nn mod 5=0 do
begin inc(p);
nn:=nn div 5; end;
while nn mod 2=0 do
begin nn:=nn div 2;
inc(d); end;
if min(d,p)<k then
begin
if d<k then
for i:=1 to k-d do
n:=n*2;
if p<k then
for i:=1 to k-p do
n:=n*5;
write(n); end; end; end.


const fi='';
      fo='';
      maxn=110;
var
        a:array[1..maxn] of longint;
        kq,n:longint;
{---------------------}
procedure mo;
begin
        assign(input,fi);
        reset(input);
        assign(output,fo);
        rewrite(output);
end;
{---------------------}
procedure doc;
var
        i:longint;
begin
        readln(n);
        for i:=1 to n do
        read(a[i]);
end;
{---------------------}
procedure xuli;
var
        ok:boolean;
        max,i,imax:longint;
begin
        repeat
                ok:=false;
                max:=0;
                for i:=2 to n do
                if (a[i]>=a[1]) and (a[i]>max) then
                begin
                        ok:=true;
                        max:=a[i];
                        imax:=i;
                end;
                if not ok then break;
                dec(a[imax]);
                inc(a[1]);
                inc(kq);
        until false;
end;
{---------------------}
procedure ghi;
begin
        writeln(kq);
end;
{---------------------}
procedure dong;
begin
        close(input);
        close(output);
end;
{---------------------}
begin
        mo;
        doc;
        xuli;
        ghi;
        dong;
end.


var
        a,b,d,i : longint;
        z : boolean;
begin
        readln(a,b);
        {z := true;
        if a=b then}
        if (a<b) and (2*a<b) then
                d := a
        else if (a>b) and (2*b<a) then
                d := b
        else
                d := (a+b) div 3;
        {else if a<b then
        begin
                while z  do
                begin
                        if ((i mod 2)=0) and (a>0) and (b>=2) then
                        begin
                                a := a-1;
                                b := b-2;
                                d := d+1;
                        end
                        else if ((i mod 2)=1) and (a>=2) and (b>0) then
                        begin
                                a := a-2;
                                b := b-1;
                                d := d+1;
                        end;
                        if ((a<=1) and (b<=1)) or (a=0) or (b=0) then
                                z := false;
                        i := i+1;
                end;
        end
        else if a>b then
        begin
                while z  do
                begin
                        if ((i mod 2)=0) and (b>0) and (a>=2) then
                        begin
                                b := b-1;
                                a := a-2;
                                d := d+1;
                        end
                        else if ((i mod 2)=1) and (b>=2) and (a>0) then
                        begin
                                b := b-2;
                                a := a-1;
                                d := d+1;
                        end;
                        if (a<=1) and (b<=1) then
                                z := false;
                        i := i+1;
                end;
        end;             }
        writeln(d);
        readln
end.


{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

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

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

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

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

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

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

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

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

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

procedure run;
var i,j,k:longint;
  begin
  //init;
  read(q,c);
  if q=c then
    begin
    if q=0 then begin writeln('0'); halt; end else
      begin
      writeln('1');
      writeln(q);
      halt;
      end;
    end;
  i:=1;
  p[0]:=1;
  m:=0;
  for i:=1 to 62 do p[i]:=p[i-1]*2;
  for i:=0 to 61 do qq[i]:=q mod p[i+1] div p[i];
  n:=0;
  for i:=61 downto 0 do if qq[i]=1 then begin inc(n); cc[n]:=p[i]; end;
  kk:=c-q;
  if ((kk<0)or(odd(kk))) then begin writeln('-1'); halt; end;
  kk:=(c-q) div 2;
  n:=1;
  cc[1]:=q; cc[2]:=0; cc[3]:=0;
  for i:=1 to n-1 do
    for j:=i+1 to n do
      begin
      for k:=1 to n do r0[k]:=cc[k];
      inc(r0[i],kk); inc(r0[j],kk);
      fillchar(qq,sizeof(qq),0);
      for k:=1 to n do
        for ll:=0 to 61 do
          inc(qq[ll],r0[k] mod p[ll+1] div p[ll]);
      for k:=0 to 61 do qq[k]:=qq[k] mod 2;
      m:=0;
      for k:=0 to 61 do inc(m,qq[k]*p[k]);
      if m=q then
        begin
        writeln(n);
        for k:=1 to n do write(r0[k],' ');
        halt;
        end;
      end;

  for i:=n+1 to n+1 do
    for j:=1 to n do
      begin
      for k:=1 to n+1 do r0[k]:=cc[k];
      inc(r0[i],kk); inc(r0[j],kk);
      fillchar(qq,sizeof(qq),0);
      for k:=1 to n+1 do
        for ll:=0 to 61 do
          inc(qq[ll],r0[k] mod p[ll+1] div p[ll]);
      for k:=0 to 61 do qq[k]:=qq[k] mod 2;
      m:=0;
      for k:=0 to 61 do inc(m,qq[k]*p[k]);
      if m=q then
        begin
        writeln(n+1);
        for k:=1 to n+1 do write(r0[k],' ');
        halt;
        end;
      end;

  cc[n+1]:=kk;
  cc[n+2]:=kk;

  writeln(n+2);
  for i:=1 to n+2 do write(cc[i],' ');

  //fin;
  end;

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


var
 s: shortstring;
 h: char;
 t,x,g,p: int64;
begin
 readln(s);
 h:=s[length(s)];
 val(copy(s,1,length(s)-1),x);

 if h = 'f' then t:=1 else if h = 'e' then t:=2 else
 if h = 'd' then t:=3 else if h = 'a' then t:=4 else
 if h = 'b' then t:=5 else if h = 'c' then t:=6;

 g:=((x+1) div 2-1) div 2;
 p:=g;
 g:=g*2*6+p+p*3+t;

 if not odd(x) then writeln(g+7) else writeln(g);
end.


{$mode objfpc}
uses math;

var
  size,time,t0,a1,t1,p1,a2,t2,p2,kq,w,o,i:int64;

procedure swap;
var nho:int64;
  begin
    nho:=a1; a1:=a2; a2:=nho;
    nho:=t1; t1:=t2; t2:=nho;
    nho:=p1; p1:=p2; p2:=nho;
  end;

begin               {
  assign(input,'c.inp');
  reset(input);    }
  read(size,time,t0);
  read(a1,t1,p1);
  read(a2,t2,p2);
  if t1 > t2 then swap;
  t1:=t0 - t1;
  t2:=t0 - t2;
  time:=size*t0 - time;
  if time <= 0 then
    begin
      write(0);
      halt;
    end;
  i:=-1;
  kq:=high(int64);
  if t1 >= 0 then
  repeat
    inc(i);
    if a1*i >= size then
      begin
        if size*t1 >= time then kq:=min(kq , i*p1);
        break;
      end;
    if  a1*i*t1 + max(0,max(0,size-a1*i)*t2) < time then continue;
    if (time - a1*i*t1 <= 0) or (t2*a2 <= 0) then o:=0
    else
      begin
        o:=(time - a1*i*t1) div (t2*a2);
        if (time - a1*i*t1) mod (t2*a2) <> 0 then inc(o);
      end;
    w:=i*p1 + o*p2;
    if w = 8393 then writeln(i,' ',a1);
    kq:=min(kq , w);
  until a1*i >= size;
  //writeln(i,' ',a1*i,' ',size);
  if kq = high(int64) then kq:=-1;
  write(kq);
end.


var
    k2, k3, k5, k6: uint64;
    m, s: uint64;

function min(a, b: uint64):uint64;
begin
    if a < b then
        min := a
    else
        min := b;
end;

begin
    readln(k2, k3, k5, k6);
    m := min(k5, k6);
    m := min(k2, m);
    s := m * 256;
    k2 := k2 - m;
    k5 := k5 - m;
    k6 := k6 - m;
    m := min(k3, k2);
    s := s + m * 32;
    write(s);
end.


var n,s,k:int64;
a,b,c:double;
i:integer;
begin
read(n);
k:=5;
s:=1;
for i:=n downto n-k+1 do
  s:=s*i*i div (n-i+1);
write(s);
end.


var a:array[1..26]of longint;
n,i,dop:longint;
kol:int64;

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
  readln(n);
  for i:=1 to n do
    read(a[i]);
  sort(1,n);
  dop:=-1;
  for i:=1 to n do
  begin
    if (a[i]<dop) or (dop=-1)
                     then begin
                       kol:=kol+a[i];
                       dop:=a[i];
                      end
    else begin
           if dop-1<1 then break;
           kol:=kol+dop-1;
           dop:=dop-1;
         end;
  end;
  writeln(kol);
end.


var a:array[1..1000] of boolean;
    i,n,s:longint;
    f:boolean;
begin
  readln(n);s:=1;
  fillchar(a,sizeof(a),false);a[s]:=true;
  for i:=1 to 1000000 do
    begin
      inc(s,i);s:=s mod n;if s=0 then s:=n;a[s]:=true;
    end;
  f:=true;
  for i:=1 to n do f:=f and a[i];
  if f then writeln('YES') else writeln('NO');
end.


uses math;
var k,x,r,l,i,j:longint;
s:ansistring;
n:int64;
 w:char;
procedure go(x,y:longint);
 var e:longint;tmp:char;
  begin
   for e:=x downto y do
    begin
     tmp:=s[e];
     s[e]:=s[e-1];
     s[e-1]:=tmp;
    end;
  end;
begin
read(n,k);
str(n,s);
l:=length(s);
x:=1;
while x<>l do
 begin
  w:=s[x];r:=0;
   for j:=x+1 to min(l,x+k) do
    if s[j]>w then begin r:=j; w:=s[j]; end;
    if w=s[x] then inc(x)
    else
     begin
      k:=k-r+x;
      go(r,x+1);
      inc(x);
     end;
    end;
 for j:=1 to l do
  write(s[j]);
end.


var dp:array [0..13,0..1000] of int64;
    p:array [1..13] of int64;
   q,w,e,r,n:int64;
   i,j,l:longint;
   st,inf:extended;
    begin
     read(n);
     p[1]:=2; p[2]:=3; p[3]:=5; p[4]:=7; p[5]:=11;
     p[6]:=13; p[7]:=17; p[8]:=19; p[9]:=23; p[10]:=29;
     p[11]:=31; p[12]:=37;
     q:=1;
     inf:=round(1e18);
     q:=round(inf);
     for i:=0 to 12 do
      for j:=0 to n do
       dp[i][j]:=round(inf);
     dp[0][1]:=1;
     for i:=1 to 12 do
      begin
       dp[i][1]:=1;
       l:=1;
       for j:=1 to n do
        begin
        st:=1;
       for l:=1 to 63 do
        begin

        st:=st*p[i];
        if (st>inf) then break;
        if (j mod (l+1)) =0 then
          begin
           if (dp[i-1][j div (l+1)]*st<=inf) then
            begin
             if (dp[i-1][j div (l+1)]*st<dp[i][j]) then
              begin
              dp[i][j]:=round(dp[i-1][j div (l+1)]*st);
              end;
            end;
          end;
        end;

      end;
      if (dp[i][n]<q) then q:=dp[i][n];
      end;
     write(q);
    end.


program B;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

const
    month : array [0..1, 1..12] of integer = ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
                                       (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
  maxn = 500;
  infile = 'b.in';
  outfile = 'b.out';
type int = longint;
type ttype = record
    d : int;
    m : int;
    y : int;
  end;
var
  s1, s2 : string;
  k : int;
  date1, date2 : ttype;
function decode(s : string) : ttype;
var
  x : ttype;
begin
  x.d := StrToInt(copy(s, 1, 2));
  delete(s, 1, 3);
  x.m := StrToInt(copy(s, 1, 2));
  delete(s, 1, 3);
  x.y := StrToInt(copy(s, 1, 2));
  decode := x;
end;
procedure swap(var x, y : int);
var
  r : int;
begin
  r := x;
  x := y;
  y := r;
end;

function is_correct(date : ttype) : boolean;
begin
  is_correct := false;
  if (date.y > 0) and (date.y < 100) then begin
    if (date.m > 0) and (date.m < 13) then begin
      if date.y mod 4 = 0 then begin
        if (date.d > 0) and (date.d <= month[1][date.m]) then
          is_correct := true else is_correct := false;
      end else
        if (date.d > 0) and (date.d <= month[0][date.m]) then
          is_correct := true else is_correct := false;
    end;
  end;
end;

function is_date_ok(date : ttype) : boolean;
begin
  is_date_ok := false;
  date.y := date.y + 18;
  if date.y < date2.y then
    result := true else
      if date.y = date2.y then
        if date.m < date2.m then
          result := true else begin
            if date.m = date2.m then
              if date.d <= date2.d then
                result := true;
          end;
end;
procedure is_go(var date : ttype; k : int);
begin
  if k = 1 then
    swap(date.d, date.m);
  if k = 2 then
    swap(date.d, date.y);
  if k = 3 then
    swap(date.m, date.y);
  if k = 4 then
    swap(date.m, date.d);
  if k = 5 then
    swap(date.y, date.d);
  if k = 6 then
    swap(date.y, date.m);

end;

begin

  readln(s1);
  readln(s2);
  date1 := decode(s2);
  date2 := decode(s1);
  k := 0;
  while k <= 6 do begin
    if is_correct(date1) then begin
      if is_date_ok(date1) then begin
        writeln('YES');
        exit;
      end else begin
          inc(k);
          is_go(date1, k);
        end;
    end else begin
      inc(k);
      is_go(date1, k);
    end;
   end;
  writeln('NO');

end.


var
    n,i,x,ans:longint;

begin {main}
  readln(n);
  if n=0 then begin writeln(1);halt;end;
  ans:=2*n;
  for i:=1 to n do
    begin
      x:=trunc(sqrt(int64(n)*int64(n)-int64(i)*int64(i)));
      if int64(i+1)*int64(i+1)+int64(x)*int64(x)>int64(n)*int64(n) then dec(ans);
    end;
  writeln(ans*4);
end.


program test;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  s: string;
  n, k, i, g, t: integer;

begin
  readln(n, k);
  readln(s);
  g := pos('G', s);
  t := pos('T', s);
  if (g > t) then begin
    i := g - k;
    while (i > 0) and (s[i] = '.') do
      dec(i, k);
    if (s[i] = 'T') then
      writeln('YES')
    else
      writeln('NO');
  end
  else begin
    i := g  + k;
    while (i > 0) and (s[i] = '.') do
      inc(i, k);
    if (s[i] = 'T') then
      writeln('YES')
    else
      writeln('NO');
  end;
  readln;
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  buffer: string;
  n: Integer;
  m: array of integer;
  max,focus,radius: integer;
begin
  read (max,focus,radius);
  setLength(m,max);
  for n:=0 to high(m) do m[n] := n+1;
  for n:=0 to high(m) do if m[n] = focus then Break;
  if focus-radius>1 then buffer:='<< ';
  if focus-radius>0 then begin  n:=n-radius end
  else n := 0;
  while m[n] < focus do begin buffer:=buffer+inttostr(m[n])+' '; inc(n) end;
  buffer:=buffer+'('+inttostr(m[n])+')';
  while (m[n] < focus+radius) and (m[n] < max) do
  begin inc(n); buffer:=buffer+' '+inttostr(m[n]); end;
  if m[n] < max then buffer:=buffer+' >>';
  Writeln(buffer);
  Readln;
  Readln;
end.


Program TigaTujuhTigaB;

var
	w,m,k,c : int64;
	i,digit : longint;
	temp : string;

function pangkat(a,b : int64): int64;
var
	temp : real;
begin
	temp := exp(b * ln(a));
	pangkat := trunc(temp);
end;

begin
	readln(w,m,k); c:= 0;
	str(m,temp);
	digit := length(temp);
	for i:=digit to 19 do
	begin
		if((i=digit)and(w div (k*i) <= pangkat(10,i)-m)) then
		begin
			writeln(w div (k*i));
			halt(0);
		end else if ((i=digit) and(w div (k*i)> pangkat(10,i)-m)) then
		begin
			c := (pangkat(10,digit)-m);
			w := w - c*k*digit;
		end else if (w > (pangkat(10,i-1)*9*k*i)) then
		begin
			c := c + pangkat(10,i-1)*9;
			w := w - pangkat(10,i-1)*9*k*i;
		end else if (w <= (pangkat(10,i-1)*9*k*i)) then
		begin
			c := c + w div (i*k);
			writeln(c); halt(0);
		end;
	end;
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  s, result: string;
  n, i: integer;
begin
  n := 1;
  result := 'NO';
  readln(s);
  for i := 2 to length(s) do begin
    if s[i] = s[i - 1] then n := n + 1 else n := 1;
    if n = 7 then begin
      result := 'YES';
      break;
    end;
  end;
  writeln(result);
end.


var n,k,s,i:longint;
begin
 readln(n,k);
 s:=0;
 for i:=1 to n do
 begin
  s:=s+i;
  if i+s-k-n=0 then break;
 end;
 writeln(s-k);
 readln;
end.


var
  s : ansistring;
  i,j,n,m,k : longint;
  c : char;

begin
  for i:=1 to 8 do begin
    readln(s);
    c:='q';
    for j:=1 to 8 do begin
      if s[j] = c then begin writeln('NO'); halt; end;
      c:=s[j];
    end;
  end;
  writeln('YES');
end.


program problem5;
uses math, dos;

type	tEdge =	record
					v, next: longInt;
				end;
		tTree =	record
					n, timer: longInt;
					first, size, depth, inTime, vertex: array[ 1..200000 ] of longInt;
					LCA_RMQ: array[ 1..200000, 0..20 ] of longInt;
					s, sumDown, sumUp: array[ 1..100000 ] of int64;
					e: array[ 1..200000 ] of tEdge;
					insideDistanceSum, maxS: int64;
				end;

var	max2pow: array[ 1..200000 ] of longInt;

procedure qsort( var t: tTree; l, r: longInt );
var	i, j, tmp: longInt;
	med: int64;
begin
	if ( l < r ) then
	begin
		with t do
		begin
			i := l;
			j := r;
			med := s[ vertex[ l + random(r - l + 1) ] ];
			while ( i <= j ) do
			begin
				while ( s[ vertex[i] ] > med ) do
					inc( i );
				while ( s[ vertex[j] ] < med ) do
					dec( j );

				if ( i <= j ) then
				begin
					tmp := vertex[i];
					vertex[i] := vertex[j];
					vertex[j] := tmp;

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

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

procedure readEdges( var t: tTree );
var	i, ee, u, v: longInt;
begin
	with t do
	begin
		fillchar( first, sizeOf(first), 0 );

		ee := 0;
		for i := 2 to n do
		begin
			readln( u, v );

			inc( ee );
			e[ee].v := v;
			e[ee].next := first[u];
			first[u] := ee;

			inc( ee );
			e[ee].v := u;
			e[ee].next := first[v];
			first[v] := ee;
		end;
	end;
end;

procedure DFS( var t: tTree; v, p: longInt );
var	i: longInt;
begin
	with t do
	begin
		size[v] := 1;
		sumDown[v] := 0;

		i := first[v];
		while ( i > 0 ) do
		begin
			if ( e[i].v <> p ) then
			begin
				DFS( t, e[i].v, v );

				inc( size[v], size[ e[i].v ] );
				inc( sumDown[v], sumDown[ e[i].v ] + size[ e[i].v ] );
			end;

			i := e[i].next;
		end;
	end;
end;

procedure DFS2( var t: tTree; v, p: longInt );
var	i: longInt;
begin
	with t do
	begin
		inc( timer );
		vertex[timer] := v;
		inTime[v] := timer;

		if ( p = 0 ) then
		begin
			sumUp[v] := 0;
			depth[v] := 0;
		end
		else
		begin
			sumUp[v] := n - size[v] + sumUp[p] + sumDown[p] - sumDown[v] - size[v];
			depth[v] := depth[p] + 1;
		end;

		i := first[v];
		while ( i > 0 ) do
		begin
			if ( e[i].v <> p ) then
			begin
				DFS2( t, e[i].v, v );

				inc( timer );
				vertex[timer] := v;
			end;

			i := e[i].next;
		end;
	end;
end;

function minVertex( const t: tTree; u, v: longInt ): longInt;
begin
	if ( t.depth[u] < t.depth[v] ) then
		exit( u )
	else
		exit( v );
end;

procedure initLCA( var t: tTree );
var	i, j: longInt;
begin
	with t do
	begin
		max2pow[1] := 0;
		for i := 2 to timer do
		begin
			max2pow[i] := max2pow[i - 1];
			if ( i = 2 shl max2pow[i] ) then
				inc( max2pow[i] );
		end;

		for i := 1 to timer do
			LCA_RMQ[i][0] := vertex[i];

		for j := 0 to 19 do
			for i := 1 to timer - (2 shl j) + 1 do
				LCA_RMQ[i][j + 1] := minVertex( t, LCA_RMQ[i][j], LCA_RMQ[ i + (1 shl j) ][j] );
	end;
end;

function LCA( const t: tTree; u, v: longInt ): longInt;
var	p, l, r: longInt;
begin
	with t do
	begin
		l := min( inTime[u], inTime[v] );
		r := max( inTime[u], inTime[v] );

		p := max2pow[r - l + 1];

		p := minVertex( t, LCA_RMQ[l][p], LCA_RMQ[ r - (1 shl p) + 1 ][p] );
	end;

	exit( p );
end;

function distance( const t: tTree; u, v: longInt ): longInt;
var	w: longInt;
begin
	w := LCA( t, u, v );

	exit( t.depth[u] + t.depth[v] - 2 * t.depth[w] );
end;

procedure preprocess( var t: tTree );
var	i: longInt;
begin
	t.timer := 0;

	DFS( t, 1, 0 );
	DFS2( t, 1, 0 );

	initLCA( t );

	with t do
	begin
		insideDistanceSum := 0;
		maxS := 0;

		for i := 1 to n do
		begin
			s[i] := sumDown[i] + sumUp[i];

			inc( insideDistanceSum, s[i] );
			maxS := max( maxS, s[i] );
		end;

		insideDistanceSum := insideDistanceSum div 2;
	end;
end;

function solveOne( const t: tTree; nn: longInt ): int64;
begin
	exit( t.maxS * nn + t.insideDistanceSum );
end;

function solveTwo( var t: tTree; n1, n2: longInt ): int64;
var	i, j: longInt;
	res, nn, endTime: int64;
begin
	endTime := getMsCount() + 850;

	if ( n1 < n2 ) then
	begin
		i := n1;
		n1 := n2;
		n2 := i;
	end;

	nn := n1 * int64(n2);

	with t do
	begin
		res := 0;

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

		qsort( t, 1, n );

		i := 1;
		while ( i <= n ) and ( getMsCount() < endTime ) do
		begin
			for j := 1 to n do
				res := max( res, nn * distance(t, vertex[i], vertex[j]) + s[ vertex[i] ] * n1 + s[ vertex[j] ] * n2 );

			inc( i );
		end;
	end;

	exit( res + t.insideDistanceSum + t.n * int64(n1 + n2) + 2 * nn );
end;

var	t1, t2, t3: tTree;
	ans: int64;

begin
	readln( t1.n, t2.n, t3.n );

	readEdges( t1 );
	readEdges( t2 );
	readEdges( t3 );

	preprocess( t1 );
	preprocess( t2 );
	preprocess( t3 );

	ans := 0;

	ans := max( ans, solveTwo( t1, t2.n, t3.n ) + solveOne( t2, t1.n + t3.n ) + solveOne( t3, t1.n + t2.n ) );
	ans := max( ans, solveTwo( t2, t1.n, t3.n ) + solveOne( t1, t2.n + t3.n ) + solveOne( t3, t1.n + t2.n ) );
	ans := max( ans, solveTwo( t3, t2.n, t1.n ) + solveOne( t2, t1.n + t3.n ) + solveOne( t1, t3.n + t2.n ) );

	writeln( ans );
end.


{$apptype console}
{$R+,S+,I+,Q+}
const
     inf = 'input.txt';
     outf = 'output.txt';
var
 x,y,z,k,ans,cnt,kx,ky,kz:int64;
begin
 //reset(input,inf);
 //rewrite(output,outf);
 read(x,y,z,k);
 kx:=0; ky:=0; kz:=0;
 cnt:=0;
 while (x > 1) or (y > 1) or (z > 1) do
  begin
   if k = 0 then break;
   inc(cnt);
   if cnt = 4 then cnt:=1;
   if (cnt = 1) and (x > 1) then
    begin
     inc(kx);
     dec(x);
     dec(k);
    end;
   if (cnt = 2) and (y > 1) then
    begin
     inc(ky);
     dec(y);
     dec(k);
    end;
   if (cnt = 3) and (z > 1) then
    begin
     inc(kz);
     dec(z);
     dec(k);
    end;
  end;
 ans:=(kx+1)*(ky+1)*(kz+1);
 writeln(ans);
end.


var a1,a2:longint;
    x:string[10];
    k:char;
    i,code:integer;
begin
    readln(a1,a2);
    str(a2,x);
    for i:=1 to (length(x)div 2) do begin
         k:=x[i];
         x[i]:=x[length(x)-i+1];
         x[length(x)-i+1]:=k;
    end;
    val(x,a2,code);
    writeln(a1+a2);
    readln;
end.


Var n,i: longint;
Begin
{assign(input,'in.txt');
assign(output,'out.txt');
reset(input);
rewrite(output);}
Read(n);
i:=0;
Repeat
 inc(i);
 dec(n,i);
Until n<=0;
If n=0 then write('YES') else write('NO');
end.


var a,m:int64;
    i:longint;
  begin
    read(a,m);
    for i:=1 to 100000 do
     begin
       if a mod m=0 then begin writeln('Yes');halt;end;
       a:=a+(a mod m);
     end;
    writeln('No');
  end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n:integer;
  a,b,c,d,e,f,x:extended;

begin
    readln(n);
    a:=1;
    b:=2;
    c:=3;
    d:=4;
    e:=5;
    f:=6;
    x:=0;
    while x<>1 do
        begin
            if (n>=a)and(n<b) then
                begin
                    writeln('Sheldon');
                    x:=1;
                end;
            if (n>=b)and(n<c) then
                begin
                    writeln('Leonard');
                    x:=1;
                end;
            if (n>=c)and(n<d) then
                begin
                    writeln('Penny');
                    x:=1;
                end;
            if (n>=d)and(n<e) then
                begin
                    writeln('Rajesh');
                    x:=1;
                end;
            if (n>=e)and(n<f) then
                begin
                    writeln('Howard');
                    x:=1;
                end;
            n:=n-trunc(d);
            b:=b*2;
            c:=c*2;
            d:=d*2;
            e:=e*2;
            f:=f*2;
        end;
   readln;
end.


{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
var
  s,it,n,m,k,i,p,xx,yy,j: longint;
  ans: string;
  ch: char;
  a: array [0..11111] of longint;
  ok,oka,okb: boolean;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  read(n,m,k);
  p:=0;
  oka:=False; okb:=False;
  for i:=1 to n do
  begin
    xx:=0; yy:=0;
    ok:=False;
    for j:=1 to m do
    begin
      read(ch);
      while not (ch in ['R','-','G']) do read(ch);
      if ch = 'R' then xx:=j;
      if ch = 'G' then yy:=j;
      if ch = '-' then ok:=True;
    end;
    if not ok then continue;
    if (xx > 0) and (yy > 0) then
    begin
      inc(p);
      a[p]:=abs(xx-yy)-1;
    end;
    if xx > 0 then okb:=True;
    if yy > 0 then oka:=True;
  end;
  if m = 1 then ans:='Second' else
  if not oka then ans:='Second' else
  if not okb then ans:='First' else
  if p = 0 then ans:='Draw' else
  begin
    ans:='Second';
    inc(k);
    for it:=1 to 20 do
    begin
      s:=0;
      for i:=1 to p do
      begin
        s:=s+a[i] mod 2;
        a[i]:=a[i] div 2;
      end;
      if s mod k <> 0 then ans:='First';
    end;
  end;
  writeln(ans);
  close(input);
  close(output);
end.


Const
        fi      ='';//B.INP';
        fo      ='';//B.OUT';

Var
        cnt1,cnt2,x,y   :int64;
        res     :int64;

Procedure nhap;
begin
        assign(input,fi);
        reset(input);
        read(cnt1,cnt2,x,y);
        close(input);
end;

Function ok(g:int64):boolean;
begin
        if g-g div x < cnt1 then exit(false);
        if g-g div y < cnt2 then exit(false);
        if g-g div (x*y) < (cnt1+cnt2) then exit(false);
        exit(true);
end;

Procedure Sol;
var
        d,c,g   :int64;
begin
        d:=1;
        c:=round(1E18);
        while d <= c do
          begin
              g:=(d+c) div 2;
              if ok(g) then
                begin
                    res:=g;
                    c:=g-1;
                end
              else
                d:=g+1;
          end;
end;

Procedure xuat;
begin
        assign(output,fo);
        rewrite(output);
        write(res);
        close(output);
end;

Begin
        nhap;
        Sol;
        xuat;
End.


const MAXN = 503; MD = 998244353;

var
	n,x,i,j,k: Longint;
	ans: int64;
	chose, pw, dp : Array [0..MAXN, 0..MAXN] of int64;
BEGIN
	ReadLn(n, x);
	FillChar(dp, SizeOf(dp), 0);

	for i:=0 to MAXN do pw[i, 0]:= 1;
	for i:=0 to MAXN do for j:=1 to MAXN do pw[i, j]:= (pw[i, j-1] * i) mod MD;

	for i:=0 to MAXN do chose[0, i]:= 1;
	for i:=1 to MAXN do
		for j:=i to MAXN do
			if i = j then chose[i, j]:= 1 else chose[i, j]:= (chose[i, j-1] + chose[i-1, j-1]) mod MD;

	for i:=1 to n do
		for j:=1 to i-1 do
			dp[i, j]:= (pw[j, i] - pw[j-1, i] + MD) mod MD;

	for i:=1 to n do
		for j:=1 to x do
			for k:=0 to n-i do
				if (i+k-1 > 0) and (j+i+k-1 <= x) then
					dp[i+k, j+i+k-1]:= (dp[i+k, j+i+k-1] + (dp[i, j] * chose[i, i+k]) mod MD * pw[i+k-1, k]) mod MD;
	Ans:= 0;
	for i:=1 to x do
		Ans:= (Ans + dp[n, i]) MOD MD;
	WriteLn(Ans);
END.


{$MODE OBJFPC}
program dream_hyojoo;
var
       m:int64;
       f:array[0..200000] of int64;
       i:int64;

function check(x:int64):int64;
var i:integer;  sum:int64;
begin
       sum:=0;
       for i:=2 to 200000 do
           if f[i]>x then break else
           begin
              inc(sum,x div f[i]);
              if sum>m then break
           end;
       exit(sum)
end;

procedure bs(l,r:int64);
var    mid:int64;
begin
       while l<r do
         begin
             if r=l+1 then
                begin
                   if check(l)=m then writeln(l) else
                   if check(r)=m then writeln(r) else writeln(-1);
                   halt
                end;
             mid:=(l+r) div 2;
             if check(mid)<m then l:=mid+1 else
             if check(mid)>=m then r:=mid
         end;
       if check(l)=m then writeln(l) else
             writeln(-1)
end;

begin
       readln(m);
       i:=2;
       while i<=200000 do
          begin
             f[i]:=i*i*i;;
             inc(i)
          end;

       bs(1,10000000000000000);

end.


var a,b,c,d: longint;

begin
read(a,b,c,d);
if a mod c=0 then a:=a div c else a:=a div c+1;
a:=(a-1)*b;
if d<a then write('YES') else write('NO');

readln
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  list=array[1..1000000]of integer;
var
  n,p,i,j,h,l,g,c,e,k1,y,f,m,k,code,a,b,d:Integer;
  s,s1,s2:string;
procedure quicksort(var b:list; left,right:integer);
var
  i,j,temp,p:integer;
begin
  i:=left;
  j:=right;
  p:=b[(left+right)div 2];
  repeat
    while(b[i]<p)do inc(i);
    while(b[j]>p) do dec(j);
    if(i<=j)then begin
      temp:=b[i];
      b[i]:=b[j];
      b[j]:=temp;
      inc(i);
      dec(j);
    end;
  until(i>j);
  if(j>left)then quicksort(b,left,j);
  if(i<right)then quicksort(b,i,right);
end;
begin
  Readln(n);
  i:=n+1;
  while(n<i) do
    begin
      a:=i mod 10;
      b:=i mod 100 div 10;
      c:=i mod 1000 div 100;
      d:=i div 1000;
      if (a<>b)and(a<>c)and(a<>d)and(c<>b)and(d<>b)and(c<>d) then Break;
      Inc(i);
    end;
  Writeln(i);
  Readln;
  Readln;
end.


var p:array[0..1200,0..1200]of extended;
	m,n:longint;
function f(i,j:longint):extended;
var A,B,D,g:extended;
begin
	if i=0 then exit(1/(j+1));
	if j=0 then exit(1);
	if p[i,j]>0 then exit(p[i,j]);
	A:=(j/(j+1))*(1-f(j-1,i)); B:=1/(j+1)+A; D:=1-f(j,i-1);
	g:=(D-1)/(A-1+D-B);
	p[i,j]:=(1-g)+A*g;
	exit(p[i,j]);
end;
begin
	readln(n,m);
	writeln(f(n,m):0:10,' ',1-f(n,m):0:10);
end.


var
n,m,r:longint;
begin
readln(n,m);
if n<m then begin
    r:=n;
    n:=m;
    m:=r;
end;
write(m,' ');
write((n-m)div 2);
end.


var
 n,AKIOI,i,j:longint;
 ans:real;
 m,r:array[1..16]of longint;
begin
 readln(n);
 for i:=1 to n do
  read(m[i]);
 readln;
 for i:=1 to n do
  read(r[i]);
 readln;
 for i:=1 to 720720 do
  for j:=1 to n do
   if i mod m[j]=r[j] then begin
                            AKIOI:=AKIOI+1;
                            break;
                           end;
 ans:=AKIOI/720720;
 writeln(ans:0:6);
end.


var
s,s1,s2:string;
begin
readln(s);
s1:=copy(s,1,pos(' ',s)-1);
s2:=copy(s,pos(' ',s)+1,length(s)-pos(' ',s));
if(s2=s1) then writeln(s1) else writeln(1);
end.


var n,i,l,r:longint;
    x1,y1,x2,y2:longint;
    c,c1,m1,m2:char;
    k:string;
begin

readln(k);

read(c,c1);
if c='6' then x1:=6;
if c='7' then x1:=7;
if c='8' then x1:=8;
if c='9' then x1:=9;
if c='T' then x1:=10;
if c='J' then x1:=11;
if c='Q' then x1:=12;
if c='K' then x1:=13;
if c='A' then x1:=14;
m1:=c1;
read(c1);
read(c,c1);
if c='6' then x2:=6;
if c='7' then x2:=7;
if c='8' then x2:=8;
if c='9' then x2:=9;
if c='T' then x2:=10;
if c='J' then x2:=11;
if c='Q' then x2:=12;
if c='K' then x2:=13;
if c='A' then x2:=14;
m2:=c1;

if (m1=k[1]) and (m2<>k[1]) then writeln('YES')
 else
  begin
    if m1<>m2 then writeln('NO')
     else if x1>x2 then writeln('YES')
      else writeln('NO');

  end;

end.


program contest;
var
    max,v:array[1..100] of longint;
    i,vi,vf,t,d,sum:longint;

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

    readln(vi,vf);
    readln(t,d);
    max[t]:=vf;
    for i:=t-1 downto 2 do
        max[i]:=max[i+1] + d;
    sum:=vi+vf;
    v[1]:=vi;
    for i:=2 to t-1 do
    begin
        v[i]:=min(v[i-1]+d,max[i]);
        sum:=sum +v[i];
    end;
    writeln(sum);

end.


var n, i, b: byte;
    s: string;
begin
        readln(n);
        readln(s);
        b := 1;
        for i := 1 to n do
                if s[i] = '1' then
                        b := b + 1
                else break;
        if b > n then b := n;
        writeln(b);
end.


var
	k, l, m, n, d, j: integer;
	a:array[65..90] of integer;
	flag: boolean = true;
	s, s1: string;

begin

	readln(n);
	readln(s);
	s := UpperCase(s);
	if (n < 26) then
	begin
		writeln('NO');
		exit;
	end;

	for var i := 1 to s.length do
	begin
		a[ord(s[i])] += 1;
	end;

	for var i := 65 to 90 do
	begin
		if (a[i] = 0) then
		begin
			flag := false;
			break;
		end;
	end;

	if (flag) then
		writeln('YES')
	else
		writeln('NO');

end.


program ZAD_C_2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
   klizma,i:integer;
   n:int64;
begin
   readln(n);
   klizma:=0;
   for i:=1 to 1010000 do
      if ((n+i) mod 3 = 0) and (((n+i) div 3) >= trunc((1.0 * (1+i) * i) / 2)) then inc(klizma);
   writeln(klizma);//I love asya
   readln;
end.


var a,b,c,ans:int64;
procedure swap(var a,b:int64);
var c:int64;
begin
     c:=a; a:=b; b:=c;
end;
begin
   readln(a,b,c);
   if a<b then swap(a,b);
   if a<c then swap(a,c);
   if b<c then swap(b,c);
   ans:=a;
   if (b+c) mod 2=0 then  if ans>b then ans:=b;
   if (a+c) mod 2=0 then  if ans>a then ans:=a;
   if (a+b) mod 2=0 then  if ans>a then ans:=a;
   writeln(ans);
end.


{$r-,s-,q-,i-,o+}
type arr=array [0..200] of longint;
var
  ii,n,k,x,i,j,w,ans,kol,H,flag:longint;
  a,b:arr;
  mar:array [0..2000] of boolean;
  key,ke:arr;

  function calc(ln:longint;a,key:arr):longint;
    var i,l,r,j,sz,w:longint; b,ke:arr;
      begin
        if (ln<3) then exit(0);
        i:=1;
        while (i<=ln) do
          begin
            l:=i; r:=i;
            for j:=i+1 to ln do
              if (a[j]=a[j-1]) then inc(r) else break;
            sz:=r-l+1;
            if (sz>=3) then
              begin
                w:=0;
                for j:=1 to l-1 do
                  begin
                    inc(w);
                    b[w]:=a[j];
                    ke[w]:=key[j];
                  end;
                for j:=r+1 to ln do
                  begin
                    inc(w);
                    b[w]:=a[j];
                    ke[w]:=key[j];
                  end;
                for j:=l to r do
                  if (key[j]=ii) then flag:=1;
                exit(sz+calc(w,b,ke));
              end;
            i:=i+sz;
          end;
        exit(0);
      end;

begin
  ans:=0;
  readln(n,k,x);
  for i:=1 to n do read(a[i]);
  for ii:=1 to n do
    begin
      flag:=0;
      fillchar(mar,sizeof(mar),false);
      for j:=1 to n do key[j]:=j;
      w:=0;
      for j:=1 to ii-1 do
        begin
          inc(w);
          b[w]:=a[j];
        end;
      inc(w);
      b[w]:=x;
      for j:=ii to n do
        begin
          inc(w);
          b[w]:=a[j];
        end;
      flag:=0;
      H:=calc(n+1,b,key);
      H:=H-flag;
      if (H>ans) then ans:=H;
    end;
  writeln(ans);
end.


var
  i, j, n, c: longint;
  s: string;
  a: Array[0..100000] of longint;

begin
  read(n);

  for i := 1 to n do read(a[i]);
  for i := 1 to n do
    for j := 1 to n do
      if a[i] < a[j] then begin c := a[i]; a[i] := a[j]; a[j] := c; end;

  c := a[1]; a[1] := a[n]; a[n] := c;

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

end.


var
map:array [1..1000,1..10000] of char;
i,j,n,m,ans:longint;
function check(i,j:longint):longint;
  begin
    if (i-1>0) and (map[i-1,j]='P') then exit(1);
    if (i+1<=n) and (map[i+1,j]='P') then exit(1);
    if (j-1>0) and (map[i,j-1]='P') then exit(1);
    if (j+1<=m) and (map[i,j+1]='P') then exit(1);
    exit(0);
  end;
  begin
    readln(n,m);
    for i:=1 to n do
      begin
        for j:=1 to m do read(map[i,j]);
        readln;
      end;
    for i:=1 to n do
      for j:=1 to m do
        if map[i,j]='W' then inc(ans,check(i,j));
    write(ans);
  end.


var     i,j,n,k,m,l,t,x,p,mi,ma:longint;
begin
 read(n,k);
 if (n<>k) and (k>0) then mi:=1;
 if n div 3>=k then ma:=2*k
 else ma:=n-k;
 write(mi,' ', ma);
end.


const mx:int64=1000000007;
var
  a:array[0..200000]of int64;
  b:array[0..1000]of int64;
  p,n,m,i,j,ans:longint;
begin
  readln(n,m);a[0]:=1;
  for i:=1 to 1000 do begin
    b[i]:=b[i-1]+i;
    if b[i]>n+m then begin
      p:=i-1;break;
    end;
  end;
  for i:=1 to p do
    for j:=n downto 0 do begin
      if (b[i]-j-i<=m)and(j+i<=n) then begin
        inc(a[j+i],a[j]);
        if a[j+i]>=mx then dec(a[j+i],mx);
      end;
      if b[i]-j>m then a[j]:=0;
    end;
  for j:=0 to n do begin
    inc(ans,a[j]);
    if ans>mx then dec(ans,mx);
  end;
  writeln(ans);
end.


var	dem,n,t,i,j,hs:longint;
	a,b:array[1..100,1..100] of longint;
	procedure pour(sl,x,y,z:longint);
	var	t:longint;
		begin
			if a[x,y]=hs then
			begin
				pour(sl div 2,x+1,y,z);
				pour(sl div 2,x+1,y+1,z);
			end
			else
			if a[x,y]+sl>=hs then
			begin
				t:=a[x,y]+sl-hs;
				a[x,y]:=hs;
				b[x,y]:=z;
				pour(t div 2,x+1,y,z);
				pour(t div 2,x+1,y+1,z);
			end
			else inc(a[x,y],sl);
		end;
begin
	readln(n,t);
	hs:=1;
	for i:=1 to n do
		hs:=hs*2;
	fillchar(a,sizeof(a),0);
	for i:=1 to hs-1 do
		pour(hs,1,1,i);
	dem:=0;
	for i:=1 to n do
		for j:=1 to i do
			if b[i,j]<=t then inc(dem);
	writeln(dem);
end.


var
 n,m,i:longint;
 s:string;
begin
 readln(n,m);
 for i:=1 to n do
  begin
   readln(s);
   if (pos('C',s)<>0) or (pos('M',s)<>0) or (pos('Y',s)<>0) then begin
    writeln('#Color'); halt; end;
  end;
 writeln('#Black&White');
end.


Var a,x,k:longint;
Begin
a:=0;
read(x);
while a<x do
begin
If x-100>=0 then begin x:=x-100; Inc(k); end else
If x-20>=0 then begin x:=x-20;inc(k); end else
If x-10>=0 then begin x:=x-10; inc(k); end else
If x-5>=0 then begin x:=x-5; inc(k); end else
If x-1>=0 then begin x:=x-1; inc(k); end;
end;
writeln(k);
readln;
readln
end.


{$mode objfpc}

var
  a:integer;

begin
  read(a);
  if a = 1 then writeln(1,' ',2)
  else writeln((a-1)*2,' ',2);
  writeln(1,' ',2);
end.


var min,i,n,k:longint;
begin
min:=maxlongint;
readln(n,k);
for i:=1 to k-1 do
if (n mod i=0) and ((n div i)*k<min) then min:=(n div i)*k+i;
writeln(min);
end.


uses math;
var
  a,b,c,l,t,k : int64;

  function cl(a,b,l : int64) : int64;
    var
      x : int64;
    begin
      if a < b then exit(0);
      x:=min(a-b,l);
      exit((x+1)*(x+2) div 2);
    end;

begin
  readln(a,b,c,l);
  k:=(l+1)*(l+2)*(l+3) div 6;
  while l >= 0 do begin
    dec(k,cl(a+t,b+c,l)+cl(b+t,c+a,l)+cl(c+t,a+b,l));
    dec(l); inc(t);
  end;
  writeln(k);
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n, i: integer;
  s: string;
  a: array[0..10000] of integer;
  res, k: int64;

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

  readln(s);
  n := length(s);

  for i := 2 to n do begin
    inc(a[ord(s[i])]);
  end;

  res := 1;
  k := 10;

  if (s[1] = '?') then begin
    res := 9;
  end else begin
    if (s[1] >= 'A') and (s[1] <= 'J') then begin
      res := 9;
      k := 9;
    end;
  end;

  for i := ord('A') to ord('J') do begin
    if (a[i] > 0) and (s[1] <> chr(i)) then begin
      res := res * k;
      k := k - 1;
    end;
  end;

  write(res);

  for i := 1 to a[ord('?')] do
    write(0);

end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
	i, a, total, g: Integer;

function	sum(x, mdl: Integer): Integer;
begin
	Result := 0;
	while x>0 do
	begin
		Inc(Result, x mod mdl);
		x := x div mdl;
	end;
end;

function	GetGCD(x, y: Integer): Integer;
begin
	if x mod y = 0 then
	begin
		Result := y;
	end
	else
	begin
		Result := GetGCD(y, x mod y);
	end;
end;

begin
	Readln(a);
	total := 0;
	for i:=2 to a-1 do
	begin
		Inc(total, sum(a, i));
	end;
	g := GetGCD(total, a-2);
	Writeln(total div g, '/', (a-2) div g);

end.


var n, k: int64;
    i:int64;
begin
readln(n ,k);

i:=1;

while (n mod i = i-1) and (i<=100000000) and (i<=k) do inc(i);

if (i>k) or (i>100000000) then writeln('Yes')
	else writeln('No');
end.


        {$APPTYPE CONSOLE}
const nn=3; besk=2000000000000000000;
   nnn=2000000;  eps=1e-11; modul=1000000007;
 type matr=array[1..3,1..3] of extended;
   mat=^matr;
 label 1,2,3,4;

var i1,j1,k,step,kt,god,day,mon,mask,i0,j0,i,j,start,finish:longint;
newdl,dloch,kol,shag,m,t,ii,jj,l,r,p,p3,pos,ll,bb,pp,tt,ot1,ot2,s,kold,n:int64;
cc,q,t1,t2,p4,p1,p2,ot,dist1,vt,zap,ba,by,aa,ay,kk,centr,koef:int64;
flag2,flag1,flag:boolean;
ch1,ch2,ch:char;
str:array[-10..12000] of matr;
prob,ccc1,v,rr,h1,h2,h,r1,r2,aaa,bbb,ccc,hh,po,pt,doltek,dolpred:extended;
next,prev,x1,x2,y1,y2,d,och,newoch,f,x,y,fact,c,b,a,prost:array[-100000..1000000] of int64;
oldzan,oldmarked,zan: array[0..330006] of boolean;
gr:array[-1..1001,-1..1001] of boolean;
agor,aver,ssumgor,ssumver,sgor,sver,udd,dostl,dostr: array[-100..600,-100..600] of int64;
det,ott :double;
dd:matr;
d3,d1,d2,dist,edin:matr;
ss,ss1,ss2:string;
za:array[-10..600,-10..600] of boolean;
marked,dost,newdost:array[-10..700000] of boolean;
ssnew:array[-10..1000000] of char;
pole:array[-10..610,-10..600] of char;
name:array[0..2000] of string;
function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

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

function degg(p,deg:int64):int64; var pp,q:int64;
 begin if deg=0 then degg:=1 else begin   if odd(deg) then degg:=(degg(p,deg-1)*p) mod modul else
 begin q:=(degg(p,deg shr 1)) mod modul; degg:=(q*q) mod modul;   end; end;   end;

function pok(t:int64):int64;
begin if t-bb>=0 then pok:=max((t-bb) div (bb-cc)+1,0) else pok:=0; end;

begin
 { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
  }
   read(n,aa,bb,cc);

   ot:=0;
    p:=pok(n);
    t:=n-(bb-cc)*p;
    if t>0 then
    ot:=p+t div aa else ot:=p;

     ot:=max(ot,n div aa);
    writeln(ot); goto 1;

   if bb<=aa then
     begin
        t:=(n-bb) div (bb-cc);
        if n<bb then begin  writeln(0); goto 1; end;
        writeln(t+1); goto 1;

     end;
    if aa<=(bb-cc) then
     begin
        t:=(n) div (aa);
        writeln(t); goto 1;

     end;

   writeln(max(n div aa,pok(n))); goto 1;

  { for i:=0 to 100 do
    begin
       writeln(i,' ',(n-i*aa) div aa,' + ',pok(n-i*aa),' = ',(n-aa*i)+pok(n-i*aa));

    end;
   }

   1:          close(output);
end.


uses math;
const
	maxN = 100;
	tfi='';
	tfo='';
var
	x,y,z,res,t,i: longint;
begin
	assign(input, tfi); reset(input);
	assign(output, tfo); rewrite(output);
	readln(x,y,z);
	res:=300;
	for i:=1 to maxN do
	begin
		t:=abs(x-i)+abs(y-i)+abs(z-i);
		if t<res then res:=t;
	end;
	writeln(res);
	close(input); close(output);
END.


Const   fi = '';
        fo = '';
        maxN = 22;

Var     f1, f2 :text;
        n, m, t, i, u, v, spt, tmp :longint;
        c :array[0..maxN,0..maxN] of longint;
        free :array[0..maxN] of boolean;
        a :array[0..200002] of longint;

Procedure Gen(man, val :longint);
var woman :longint;
  Begin
        if man = n+1 then
          begin
            inc(spt);
            a[spt] := val;
            exit;
        end;
        for woman:=1 to n do
          if free[woman] and (c[man][woman] <> 0) then
            begin
              free[woman] := false;
              Gen(man+1, val + c[man][woman]);
              free[woman] := true;
            end;
        Gen(man+1, val);
  End;

Procedure Sort(l, r :longint);
var i, j, piv :longint;
  Begin
        if l >= r then exit;
        i := l; j := r;
        piv := a[l + random(r-l+1)];
        repeat
          while a[i] < piv do inc(i);
          while a[j] > piv do dec(j);
          if i <= j then
            begin
              tmp := a[i]; a[i] := a[j]; a[j] := tmp;
              inc(i); dec(j);
            end;
        until i > j;
        Sort(l, j);
        Sort(i, r);
  End;

BEGIN
        assign(f1, fi); reset(f1);
        assign(f2, fo); rewrite(f2);

        readln(f1, n, m, t);
        for i:=1 to m do readln(f1, u, v, c[u][v]);

        fillchar(free, sizeof(free), true);
        Gen(1, 0);
        Sort(1, spt);
        writeln(f2, a[t]);

        close(f1);
        close(f2);
END.