Var rez,a,b,kol,i,n:longint;
k,z,e,m:array [1..10000]  of longint;
used:array [1..10000] of Boolean;
f:boolean;
procedure dfs1(v,k:longint);
Var i:longint;
begin
  inc(rez);
  if used[v]
  then begin
        f:=True;
        exit;
       end;
  i:=e[v];
  while i<>0 do
  begin
    if (m[i]<>k)and(not f)
    then begin
          dfs1(m[i],v);
         end;
    i:=z[i];
  end;
  if f
  then exit;
  dec(rez);
end;

procedure dfs(v,k:longint);
Var i:longint;
begin
  if used[v]
  then begin
        f:=True;
        exit;
       end;
  used[v]:=true;
  i:=e[v];
  while i<>0 do
  begin
    if (m[i]<>k)and(not f)
    then begin
          dfs(m[i],v);
         end;
    i:=z[i];
  end;
  if f
  then Exit;
  used[v]:=false;
end;
procedure add(i,j:longint);
begin
  inc(kol);
  m[kol]:=j;
  z[kol]:=e[i];
  e[i]:=kol;
end;
begin
 // Assign(input,'input.txt');
//  Assign(output,'output.txt');
  Readln(n);
  kol:=0;
  for i:=1 to n do
  begin
    readln(a,b);
    add(a,b);
    add(b,a);
  end;
  for i:=1 to n do
  begin
    f:=false;
    FillChar(used,SizeOf(used),false);
    dfs(i,i);
    if f
    then Break;
  end;
  for i:=1 to n do
  if used[i]=false
  then begin
        rez:=-1;
        f:=False;
        dfs1(i,i);
        k[i]:=rez;
       end;
  for i:=1 to n do
  write(k[i],' ');
end.

A subway scheme, classic for all Berland cities is represented by a set of n stations connected by n passages, each of which connects exactly two stations and does not pass through any others. Besides, in the classic scheme one can get from any station to any other one along the passages. The passages can be used to move in both directions. Between each pair of stations there is no more than one passage.Berland mathematicians have recently proved a theorem that states that any classic scheme has a ringroad. There can be only one ringroad. In other words, in any classic scheme one can find the only scheme consisting of stations (where any two neighbouring ones are linked by a passage) and this cycle doesn't contain any station more than once.This invention had a powerful social impact as now the stations could be compared according to their distance from the ringroad. For example, a citizen could say "I live in three passages from the ringroad" and another one could reply "you loser, I live in one passage from the ringroad". The Internet soon got filled with applications that promised to count the distance from the station to the ringroad (send a text message to a short number...).The Berland government decided to put an end to these disturbances and start to control the situation. You are requested to write a program that can determine the remoteness from the ringroad for each station by the city subway scheme.

The first line contains an integer n (3≤n≤3000), n is the number of stations (and trains at the same time) in the subway scheme. Then n lines contain descriptions of the trains, one per line. Each line contains a pair of integers xi,yi (1≤xi,yi≤n) and represents the presence of a passage from station xi to station yi. The stations are numbered from 1 to n in an arbitrary order. It is guaranteed that xi≠yi and that no pair of stations contain more than one passage. The passages can be used to travel both ways. It is guaranteed that the given description represents a classic subway scheme.

Print n numbers. Separate the numbers by spaces, the i-th one should be equal to the distance of the i-th station from the ringroad. For the ringroad stations print number 0.

var cycle,used:array [0..3137]of boolean;
    g:array [1..3137,0..3137]of longint;
    path:array[1..3137]of longint;
    x,y,n,i,j:longint;

procedure dfs(i,l:longint);
 var j:longint;
begin
 used[i]:=true;
 for j:=1 to g[i,0] do
  begin
   if (not cycle[g[i,j]])and(not used[g[i,j]])
    then begin path[g[i,j]]:=l+1;dfs(g[i,j],l+1)end;
  end;
end;

procedure testdfs(tek,test,prev:longint);
 var j:longint;
begin
 used[tek]:= true;
 for j:=1 to g[tek,0] do
  begin
   if not used[g[tek,j]]
     then testdfs(g[tek,j],test,tek);
   if (g[tek,j]=test)and(prev<>test)
           then begin Cycle[test]:=true;exit;end;
  end;
end;

begin
 read(n);
 for i:=1 to n do
  begin
   read(x,y);
   inc(g[x,0]);
   g[x,g[x,0]]:=y;
   inc(g[y,0]);
   g[y,g[y,0]]:=x;
  end;

  for i:=1 to n do
   begin
    testdfs(i,i,0);
    for j:=1 to n do
     used[j]:=false;
   end;

 for i:=1 to n do
  if cycle[i]
   then dfs(i,0);
 for i:=1 to n do
  write(path[i],' ');
end.


program solution;

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

uses
  SysUtils,
  Math;

type
  tp = record
    x, y : int64;
  end;
  tl = record
    a, b, c : int64;
  end;

var
  n, m, ans, i, j, z : integer;
  t : tp;
  l : tl;
  a, b : array[0..501] of tp;
  f : array[0..501, 0..501] of integer;

function zn(a : int64) : integer;
begin
  if a < 0 then begin
    result := -1;
    exit;
  end;
  if a = 0 then begin
    result := 0;
    exit;
  end;
  result := 1;
end;

function getline(var a, b : tp) : tl;
begin
  result.a := a.y - b.y;
  result.b := b.x - a.x;
  result.c := a.x * b.y - b.x * a.y;
end;

function dist(var l : tl; var p : tp) : int64;
begin
  result := l.a * p.x + l.b * p.y + l.c;
end;

function more(var a, b : tp) : boolean;
begin
  result := a.x > b.x;
end;

begin
  //assign(input, 'input.txt'); reset(input);
  //assign(output, 'output.txt'); rewrite(output);
  read(n, m);
  for i := 1 to n do
    read(a[i].x, a[i].y);
  for i := 1 to m do
    read(b[i].x, b[i].y);
  for i := 1 to n - 1 do
    for j := n downto i + 1 do
      if more(a[i], a[j]) then begin
        t := a[i];
        a[i] := a[j];
        a[j] := t;
      end;
  for i := 1 to m - 1 do
    for j := m downto i + 1 do
      if more(b[i], b[j]) then begin
        t := b[i];
        b[i] := b[j];
        b[j] := t;
      end;
  for i := 1 to n - 1 do
    for j := i + 1 to n do begin
      l := getline(a[i], a[j]);
      for z := 1 to m do
        if (b[z].x >= a[i].x) and (b[z].x <= a[j].x) and (zn(dist(l, b[z])) = 1) then
          inc(f[i, j]);
    end;
  ans := 0;
  for i := 1 to n - 2 do
    for j := i + 1 to n - 1 do
      for z := j + 1 to n do
        if f[i, j] + f[j, z] - f[i, z] = 0 then
          inc(ans);
  writeln(ans);
end.

Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.

The first line contains two non-negative integer numbers N and M (0≤N≤500, 0≤M≤500) — the number of red and blue points respectively. The following N lines contain two integer numbers each — coordinates of red points. The following M lines contain two integer numbers each — coordinates of blue points. All coordinates do not exceed 10^9 by absolute value.

Output one integer — the number of distinct triangles with vertices in red points which do not contain any blue point inside.

var
 ans,n,m,i,j,k:longint;
 a,b,c:int64;
 x1,y1,x2,y2:array[1..1000]of int64;
 ms:array[1..1000,1..1000]of longint;
begin
 readln(n,m);
 for i:=1 to n do read(x1[i],y1[i]);
 for i:=1 to m do read(x2[i],y2[i]);
 fillchar(ms,sizeof(ms),0);
 for i:=1 to n do for j:=1 to n do if x1[i]<x1[j] then
 begin
  a:=y1[j]-y1[i];
  b:=x1[i]-x1[j];
  c:=-x1[i]*a-y1[i]*b;
  for k:=1 to m do if (x2[k]>x1[i])and(x2[k]<=x1[j])and(a*x2[k]+b*y2[k]+c>0)then inc(ms[i,j]);
  ms[j,i]:=-ms[i,j];
 end;
 ans:=0;
 for i:=1 to n do for j:=i+1 to n do for k:=j+1 to n do
 begin
  if ms[i,j]+ms[j,k]+ms[k,i]=0 then inc(ans);
 end;
 writeln(ans);
end.


program Project1;
{$APPTYPE CONSOLE}
uses  SysUtils;

var Rv,rm, r, n,alfa: Extended;
    f: Boolean;

begin
  { TODO -oUser -cConsole Main : Insert code here }
  f:=False;
  Readln(n,rv,rm);
  alfa:=Pi/n;
  if  Rv>rm then
    if (rm/(rv-rm))<Sin(alfa) then f:=True;
  if  (n=1)and(Rv >=rm) then f:=True
    else
    if  (n=2)and(Rv >= 2*rm) then f:=True
    else
        if  Rv>rm then
          if (rm/(rv-rm))<Sin(alfa) then f:=True;

if  f then Writeln('YES') else Writeln('NO');

end.

Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for n plates.

The first line contains three integers n, R and r (1≤n≤100, 1≤r,R≤1000) — the number of plates, the radius of the table and the plates' radius.

Print "YES" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print "NO".
Remember, that each plate must touch the edge of the table.

The possible arrangement of the plates for the first sample is:

Uses Math,SysUtils;
Type Tm=array[1..300000] of Int64;
Var I,J,N,L,R,Q,P,K,R1:Integer;N1,K1,J1:Extended;F:Boolean;m,d,c:Tm;ma,A,B,T,Z:Int64;S:String;
Begin
    ///reset(input,'Input.txt');
    ///assign(output,'Output.txt');
    readln(N,R,R1);
    J1:=(R-R1)*sin(pi/N)*2;
    If (J1>=R1*2) or ((R>=R1) and(N=1))
    then writeln('YES')
    else writeln('NO');
End.


{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Var
   a1,a2,a3,a4,i:Integer;
   ans:String;
Begin
   Read(a1,a2,a3,a4);
   If a3=a4 Then Begin
      If (a1>=a3) and (a1>=a4) and (a2>=a3) and (a2>=a4) Then Begin
         ans:='';
         If a1>=a3+1 Then Begin
            For i:=1 To a1-a3 Do ans:=ans+'4';
            For i:=1 To a3-1 Do ans:=ans+'7'+'4';
            For i:=1 To a2-a4+1 Do ans:=ans+'7';
            ans:=ans+'4';
         End
         Else If a2>=a4+1 Then Begin
            For i:=1 To a4-1 Do ans:=ans+'7'+'4';
            For i:=1 To a2-a4+1 Do ans:=ans+'7';
            For i:=1 To a1-a3 Do ans:=ans+'4';
         End
         Else ans:='-1';
      End
      Else ans:='-1';
   End
   Else If a3=a4-1 Then Begin
      If (a1>=a3) and (a1>=a4) and (a2>=a4) and (a2>=a3) Then Begin
         ans:='7';
         For i:=1 To a1-a3 Do ans:=ans+'4';
         For i:=1 To a4-2 Do ans:=ans+'7'+'4';
         For i:=1 To a2-a4+1 Do ans:=ans+'7';
         ans:=ans+'4';
      End
      Else ans:='-1';
   End
   Else If a3=a4+1 Then Begin
      If (a1>=a3) and (a1>=a4) and (a2>=a4) and (a2>=a3) Then Begin
         ans:='4';
         For i:=1 To a1-a3 Do ans:=ans+'4';
         For i:=1 To a4 Do ans:=ans+'7'+'4';
         For i:=1 To a2-a4 Do ans:=ans+'7';
      End
      Else ans:='-1';
   End
   Else ans:='-1';
   Write(ans);
End.

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d=747747, then cnt(4)=2, cnt(7)=4, cnt(47)=2, cnt(74)=2. Petya wants the following condition to fulfil simultaneously: cnt(4)=a1, cnt(7)=a2, cnt(47)=a3, cnt(74)=a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.

The single line contains four integers a1, a2, a3 and a4 (1≤a1,a2,a3,a4≤10^6).

On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4)=a1, cnt(7)=a2, cnt(47)=a3, cnt(74)=a4. If such number does not exist, print the single number "-1" (without the quotes).

var a4,a7,a47,a74,q4,q7:longint;
    s,s1,s2:ansistring;
    i:longint;

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

begin
 {assign(input,'input.txt');
 reset(input);   }
 readln(a4,a7,a47,a74);
 if abs(a47-a74)>1 then
  begin
   writeln(-1);
   halt;
  end;
 s:='';
 if a47=a74 then
  begin
   for i:= 1 to a47 do s:=s+'47';
   if a4<>a47 then s:=s+'4' else s:='7'+s;
  end else
 if a47>a74 then
  begin
   for i:= 1 to a47 do s:=s+'47';
  end else
  begin
   for i:= 1 to a47 do s:=s+'47';
   s:='7'+s+'4';
  end;
 q4:=0;
 q7:=0;
 for i:= 1 to length(s) do
  if s[i]='4' then q4:=q4+1 else q7:=q7+1;
 if (q4>a4) or (q7>a7) then
  begin
   writeln(-1);
   halt;
  end;
 s1:='';
 s2:='';
 for i:= 1 to a4-q4 do
  s1:=s1+'4';
 for i:= 1 to a7-q7 do
  s2:=s2+'7';
 for i:= 1 to length(s) do
  if s[i]='4' then
   begin
    s:=copy(s,1,i)+s1+copy(s,i+1,length(s)-i);
    break;
   end;
 for i:=length(s) downto 1 do
  if s[i]='7' then
   begin
    s:=copy(s,1,i)+s2+copy(s,i+1,length(s)-i);
    break;
   end;
  writeln(s);
end.


const
  maxn = 61;
var
  f:array[0..maxn, 0..maxn, 1..4] of int64;
  n,k,i,j,q,w:longint;
begin
{  assign(input, 'input.txt');
  reset(input);
  assign(output, 'output.txt');
  rewrite(output);}
  read(n, k);
  f[1, 1, 1]:=1;
  f[1, 1, 2]:=1;
  f[1, 1, 3]:=1;
  for i:=1 to n do for j:=1 to 2*k do for q:=1 to 4 do for w:=1 to 4 do if q <> w then
  begin
    if odd(j) then
    begin
      if q<w then inc(f[i+1, j, w], f[i, j, q]) else inc(f[i+1, j+1, w], f[i, j, q]);
    end else
    begin
      if q>w then inc(f[i+1, j, w], f[i, j, q]) else inc(f[i+1, j+1, w], f[i, j, q]);
    end;
  end;
  if not odd(k) then w:=2*k+1 else w:=2*k;
  writeln(f[n, w, 4]+f[n, w, 3]+f[n, w, 2]+f[n, w, 1]);
  close(output);
end.

Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with t humps, representing them as polylines in the plane. Each polyline consists of n vertices with coordinates (x1,y1), (x2,y2), ..., (xn,yn). The first vertex has a coordinate x1=1, the second — x2=2, etc. Coordinates yi might be any, but should satisfy the following conditions:  there should be t humps precisely, i.e. such indexes j (2≤j≤n-1), so that yj-1<yj>yj+1,  there should be precisely t-1 such indexes j (2≤j≤n-1), so that yj-1>yj<yj+1,  no segment of a polyline should be parallel to the Ox-axis,  all yi are integers between 1 and 4. For a series of his drawings of camels with t humps Bob wants to buy a notebook, but he doesn't know how many pages he will need. Output the amount of different polylines that can be drawn to represent camels with t humps for a given number n.

The first line contains a pair of integers n and t (3≤n≤20, 1≤t≤10).

Output the required amount of camels with t humps.

In the first sample test sequences of y-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of yi).

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
	n, t,
	i, j, k, l: Integer;
	m: array[-1..11, 0..21, 1..4, 0..1] of Int64;
	cnt: Int64;

begin
	Readln(n, t);
	FillChar(m, sizeof(m), 0);
	cnt := 0;
	for i:=1 to 4 do m[0, 2, i, 0] := i-1;

	for i:=0 to t do
	for j:=3 to n do
	for k:=1 to 4 do
	for l:=1 to 4 do
	begin
		if k>l then m[i,j,k,0] := m[i,j,k,0] + m[i,j-1,l,0] + m[i,j-1,l,1];
		if k<l then m[i,j,k,1] := m[i,j,k,1] + m[i,j-1,l,1] + m[i-1,j-1,l,0];
	end;
	for i:=1 to 4 do Inc(cnt, m[t,n,i,1]);
	Writeln(cnt);

	readln;
end.


program qwe;
{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

type
 TArray = array[1..1000000] of integer;

const
 base = 10000000009;
 p = 239017;

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

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

var
 n, m, x, y: integer;
 i: integer;
 a, b: TArray;
 vsp, ans: int64;

procedure QSort(var a: TArray; l, r: integer);
var
 i, j, x: integer;
begin
 if l >= r then exit;
 i := l;
 j := r;
 x := a[l + random(r - l + 1)];
 repeat
  while a[i] < x do inc(i);
  while a[j] > x do dec(j);
  if i <= j then
  begin
   swap(a[i], a[j]);
   inc(i);
   dec(j);
  end;
 until i > j;
 QSort(a, l, j);
 QSort(a, i, r);
end;

begin
 randomize;
 readln(n, m);
 ans := 0;
 fillchar(a, sizeof(a), 0);
 for i := 1 to m do
 begin
  readln(x, y);
  vsp := sqrr(p, x);
  a[y] := (a[y] + vsp) mod base;
  vsp := sqrr(p, y);
  a[x] := (a[x] + vsp) mod base;
 end;
 for i := 1 to n do
 begin
  vsp := sqrr(p, i);
  b[i] := (a[i] + vsp) mod base;
 end;
 QSort(a, 1, n);
 QSort(b, 1, n);
 i := 1;
 while i <= n do
 begin
  m := 0;
  while (i < n) and (a[i] = a[i + 1]) do
  begin
   inc(i);
   inc(m);
  end;
  vsp := m;
  vsp := vsp * (m + 1);
  vsp := vsp div 2;
  ans := ans + vsp;
  inc(i);
 end;
 i := 1;
 while i <= n do
 begin
  m := 0;
  while (i < n) and (b[i] = b[i + 1]) do
  begin
   inc(i);
   inc(m);
  end;
  vsp := m;
  vsp := vsp * (m + 1);
  vsp := vsp div 2;
  ans := ans + vsp;
  inc(i);
 end;
 writeln(ans);
end.

You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user.The social network contains n registered profiles, numbered from 1 to n. Some pairs there are friends (the "friendship" relationship is mutual, that is, if i is friends with j, then j is also friends with i). Let's say that profiles i and j (i≠j) are doubles, if for any profile k (k≠i, k≠j) one of the two statements is true: either k is friends with i and j, or k isn't friends with either of them. Also, i and j can be friends or not be friends.Your task is to count the number of different unordered pairs (i,j), such that the profiles i and j are doubles. Note that the pairs are unordered, that is, pairs (a,b) and (b,a) are considered identical.

The first line contains two space-separated integers n and m (1≤n≤10^6, 0≤m≤10^6), — the number of profiles and the number of pairs of friends, correspondingly.
Next m lines contains descriptions of pairs of friends in the format "v u", where v and u (1≤v,u≤n,v≠u) are numbers of profiles that are friends with each other. It is guaranteed that each unordered pair of friends occurs no more than once and no profile is friends with itself.

Print the single integer — the number of unordered pairs of profiles that are doubles.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.

In the first and second sample any two profiles are doubles.
In the third sample the doubles are pairs of profiles (1,3) and (2,4).

{$apptype console}
{$R-,S+,I+,Q-}
const
     inf = 'input.txt';
     outf = 'output.txt';
     p = 1303;
var
 n,m,i,j:longint;
 x,tmp,ans,k:int64;
 a,b:array[0..1000010] of longint;
 pow,h:array[0..1000010] of int64;

 procedure sort(l,r:longint);
 var i,j:longint;
  begin
   i:=l;
   j:=r;
   x:=h[l+random(r-l+1)];
   repeat
    while h[i] < x do inc(i);
    while h[j] > x do dec(j);
    if i <= j then
     begin
      tmp:=h[i];
      h[i]:=h[j];
      h[j]:=tmp;
      inc(i);
      dec(j);
     end;
   until i > j;
   if i < r then sort(i,r);
   if j > l then sort(l,j);
  end;

begin
 //reset(input,inf);
 //rewrite(output,outf);
 randomize;
 read(n,m);
 for i:=1 to m do read(a[i],b[i]);
 pow[0]:=1;
 for i:=1 to n do pow[i]:=pow[i-1]*p;
 fillchar(h,sizeof(h),0);
 for i:=1 to m do
  begin
   inc(h[a[i]],pow[b[i]]);
   inc(h[b[i]],pow[a[i]]);
  end;
 ans:=0;
 for i:=1 to m do if h[a[i]]+pow[a[i]] = h[b[i]]+pow[b[i]] then inc(ans);
 sort(1,n);
 i:=1;
 while i <= n do
  begin
   j:=i;
   while (j < n) and (h[j+1] = h[i]) do inc(j);
   k:=j-i+1;
   inc(ans,k*(k-1) div 2);
   i:=j+1;
  end;
 writeln(ans);
end.


var t, d : array[0..5000] of int64;
    k, n, i, j : longint;
    tt, time, ans : int64;
begin
  readln(n, k);
  for i := 1 to n do
    readln(t[i], d[i]);
  d[0] := 0;
  for i := 1 to k do
  begin
    t[n + i] := 186401;
    d[n + i] := 186401;
  end;
  ans := 0;
  for i := 1 to n do
  begin
    tt := 1;
    for j := 1 to i - 1 do
    begin
      time := t[j] - tt;
      if t[j] > 86401 then time := 86401 - tt;
      if time > ans then ans := time;
      if tt < t[j] then tt := t[j];
      tt := tt + d[j];
    end;
    for j := i + k to n do
    begin
      time := t[j] - tt;
      if t[j] > 86401 then time := 86401 - tt;
      if time > ans then ans := time;
      if tt < t[j] then tt := t[j];
      tt := tt + d[j];
    end;
    if i + k > n then
    begin
      time := 86401 - tt;
      if time > ans then ans := time;
    end;
  end;
  if n = 0 then ans := 86400;
  writeln(ans);
end.

Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has n calls planned. For each call we know the moment ti (in seconds since the start of the day) when it is scheduled to start and its duration di (in seconds). All ti are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming.Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second t, and the call continues for d seconds, then Mr. Jackson is busy at seconds t,t+1,...,t+d-1, and he can start a new call at second t+d. Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most k calls. Note that a call which comes while he is busy talking can be ignored as well.What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.

The first input line contains a pair of integers n, k (0≤k≤n≤4000) separated by a space. Following n lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers ti and di, (1≤ti,di≤86400). All ti are distinct, the calls are given in the order of strict increasing ti.
Scheduled times of calls [ti, ti+di-1] can arbitrarily intersect.

Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today.

In the first sample the most convenient way is to ignore the first two calls.
In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:
  first call: from 1-st to 20000-th second,  second call: from 20001-st to 30000-th second,  fourth call: from 30001-st to 40000-th second (the third call is ignored),  fifth call: from 80000-th to 139999-th second. Thus, the longest period of free time is from the 40001-th to the 79999-th second.

program pr1;

{$APPTYPE CONSOLE}

const nn=10001;
 eps=0.000000001;  nnn=200;
 label 1,2,3,4;
var tt,k,i3,i0,i1,i2,pgor,pver,p,step,i,j:longint;
mmin,imin,s,x0,y0,w,vp,vd,f,c,ii,n,ot,modul,p1,p2,besk,l,m,k1,k2,a2,jj:int64;
koef:double;  ch,ch1,ch2:char;
t1,t2,t3:array [-1..1000000 ] of longint;
a,t:array[0..100000] of int64;
tmin:array[-2..6000,-2..5000] of int64;
u:array[0..200000] of boolean;
flag2,flag1,flag:boolean;
verot:double;
ss,namemin:string;
name:array[0..200] of string;
function min (a,b:longint):longint;begin min:=b;if a<b then min:=a;  end;
function max (a,b:longint):longint;begin max:=b;if a>b then max:=a;  end;

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

 function luck(a:longint):boolean;
 var i,j,k:longint;flag:boolean;
 c: array[0..10] of longint;
begin
  flag:=true;  j:=0;
  k:=a;
  while k>0 do begin inc(j); c[j]:=k mod 10; k:= k div 10; {writeln(j,' uu ',k); }  end;
 for i:=1 to j do if (c[i]<>4)and(c[i]<>7) then flag:=false;
 luck:=flag;
end;

{function diam(a,b:mas;n:longint):longint;
var i0,t,i,j,k:longint; kver:mas; sv:mas2;
 begin
   for i:=1 to n do for j:=1 to n-1 do
   if a[j]=i then  begin  inc(kver[i]); sv[i,kver[i]]:=b[j];  end;
 for i:=1 to n do for j:=1 to n-1 do
   if b[j]=i then  begin  inc(kver[i]); sv[i,kver[i]]:=a[j];  end;
 for i:=1 to n do write(kver[i],' ');writeln;  writeln;
 for i:=1 to n do begin  for j:=1 to kver[i] do write(i,'-',sv[i,j],'    ');writeln;  end;

for i0:=1 to 1 do
  begin  for i:=1 to n do sm[i]:=false; for i:=1 to n do dist[i]:=1000;
  sm[i0]:=true; dist[i0]:=0; kol:=1;

  end;

diam:=t;
 end; }

         begin
{assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
}
readln(n,k);
  for i:=1 to n do  begin read (a[i],t[i]) end;
    for i:=1 to n do tmin[i,-1]:=1000000;
    tmin[1,0]:=a[1]+t[1];  tmin[1,1]:=1; tmin[0,0]:=1;
  for i:=2 to n do for j:=0 to i do
    begin   {i- obr zvonki, j - propushennye}
        tmin[i,j]:=min(tmin[i-1,j-1],max(tmin[i-1,j],a[i])+t[i]);

    end;

   {  for i:=0 to n do begin  for j:=0 to n do write(tmin[i,j]:6,' ');writeln;  end;
   } for i:=0 to n do for tt:=0 to k do  {tt propusheno sredi pervyh, k-tt - v hvoste}
      begin
         if i+k-tt+1<=n then
         ot:=max(ot,a[i+k-tt+1]-tmin[i,tt]) else
                      ot:=max(ot,86401-tmin[i,tt]);
              { writeln(i,' ',tt,' ',a[i+k-tt+1]-tmin[i,tt]);}
      end;
     writeln(ot);

   1:
            close(output);
end.


{$R+,Q+,I+}
{$apptype console}
Uses SysUtils,math;
Var
   a,b,p:Array[0..3000000] of Integer;
   n,m,i,l,r,f1,f2,ans,t,r1:Integer;
Begin
   Read(n,m);
   For i:=1 To n Do Read(a[i]);
   For i:=1 To m Do Read(b[i]);
   For i:=1 To m Do p[b[i]]:=i;
   l:=1;
   r:=1;
   f1:=0;
   f2:=0;
   t:=0;
   ans:=0;
   r1:=0;
   While True Do Begin
      If l>n Then Break;
      If r>n Then Begin
         If f1=1 Then Break;
         r:=1;
         f1:=1;
         Continue;
      End;
      If (l>r) and (f1=0) Then Begin
         r:=r+1;
         t:=0;
         f2:=0;
         Continue;
      End;
      If (l=r) and (f1=1) Then Begin
         l:=l+1;
         Continue;
      End;
      If f2=0 Then Begin
         If p[a[r]]=0 Then Begin
            l:=r+1;
            r:=r+1;
            If f1=1 Then Break;
            t:=0;
         End
         Else Begin
            If p[a[r]]<t Then Begin
               If p[a[r]]>p[a[l]] Then Begin
                  l:=l+1;
                  //While (l<=n) and (p[a[r]]>p[a[l]]) Do l:=l+1;
                  If l=r Then t:=0;
                  //r1:=l;
                  //f2:=1;
               End
               Else Begin
                  f2:=1;
                  r1:=r-1;
                  If f1=0 Then ans:=max(ans,r-l+1)
                          Else ans:=max(ans,r+n-l+1);
                  t:=p[a[r]];
                  r:=r+1;
               End;
            End
            Else Begin
               If f1=0 Then ans:=max(ans,r-l+1)
                       Else ans:=max(ans,r+n-l+1);
               t:=p[a[r]];
               r:=r+1;
            End;
         End;
      End
      Else Begin
         If p[a[r]]=0 Then Begin
            l:=r+1;
            r:=r+1;
            If f1=1 Then Break;
            f2:=0;
            t:=0;
         End
         Else Begin
            If p[a[r]]<t Then Begin
               If f1=1 Then Break;
               l:=r;
               f2:=0;
               t:=0;
            End
            Else Begin
               If p[a[r]]>p[a[l]] Then Begin
                  l:=l+1;
                  If l>r1 Then Begin
                     f2:=0;
                     r1:=0;
                  End;
                  If l=r Then t:=0;
               End
               Else Begin
                  If f1=0 Then ans:=max(ans,r-l+1)
                          Else ans:=max(ans,r+n-l+1);
                  t:=p[a[r]];
                  r:=r+1;
               End;
            End;
         End;
      End;
   End;
   Write(ans);
End.

Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hieroglyphs. We know that no hieroglyph occurs twice in either the first or the second circle (but in can occur once in each of them).Polycarpus wants to save these pictures on his laptop, but the problem is, laptops do not allow to write hieroglyphs circles. So Polycarp had to break each circle and write down all of its hieroglyphs in a clockwise order in one line. A line obtained from the first circle will be called a, and the line obtained from the second one will be called b.There are quite many ways to break hieroglyphic circles, so Polycarpus chooses the method, that makes the length of the largest substring of string a, which occurs as a subsequence in string b, maximum.Help Polycarpus — find the maximum possible length of the desired substring (subsequence) if the first and the second circles are broken optimally.The length of string s is the number of characters in it. If we denote the length of string s as |s|, we can write the string as s=s1s2... s|s|.A substring of s is a non-empty string x=s[a... b]=sasa+1... sb (1≤a≤b≤|s|). For example, "code" and "force" are substrings of "codeforces", while "coders" is not. A subsequence of s is a non-empty string y=s[p1p2... p|y|]=sp1sp2... sp|y| (1≤p1<p2<...<p|y|≤|s|). For example, "coders" is a subsequence of "codeforces".

The first line contains two integers la and lb (1≤la,lb≤1000000) — the number of hieroglyphs in the first and second circles, respectively.
Below, due to difficulties with encoding of Berland hieroglyphs, they are given as integers from 1 to 10^6.
The second line contains la integers — the hieroglyphs in the first picture, in the clockwise order, starting with one of them.
The third line contains lb integers — the hieroglyphs in the second picture, in the clockwise order, starting with one of them.
It is guaranteed that the first circle doesn't contain a hieroglyph, which occurs twice. The second circle also has this property.

Print a single number — the maximum length of the common substring and subsequence. If at any way of breaking the circles it does not exist, print 0.

In the first test Polycarpus picks a string that consists of hieroglyphs 5 and 1, and in the second sample — from hieroglyphs 1, 3 and 5.

{$R-,S-,Q-,I-,O+}
const co = 1000000;
var
  n,m,i,j,s,ans: longint;
  a,b,pz,c: array [0..2000010] of longint;
begin
  read(n,m);
  for i:=1 to n do read(a[i]);
  for i:=1 to m do read(b[i]);
  fillchar(pz,sizeof(pz),0);
  for i:=1 to m do pz[b[i]]:=i;
  a[n+1]:=a[1];
  for i:=1 to n do
    if (pz[a[i]] = 0) or (pz[a[i+1]] = 0) then c[i]:=10*co else
    begin
      c[i]:=pz[a[i+1]]-pz[a[i]];
      if c[i] < 0 then inc(c[i],m);
    end;
  ans:=0;
  for i:=1 to n do
    if pz[a[i]] > 0 then ans:=1;
  if ans = 0 then
  begin
    writeln(0);
    halt;
  end;
  for i:=1 to n do c[i+n]:=c[i];
  j:=0; s:=0;
  for i:=1 to n do
  begin
    while (j < n+n) and (s+c[j+1] < m) do
    begin
      inc(j);
      s:=s+c[j];
    end;
    if j-i+2 > ans then ans:=j-i+2;
    s:=s-c[i];
  end;
  if ans > n then ans:=n;
  if ans > m then ans:=m;
  writeln(ans);
end.


{$R+ Q+ I+}
{$APPTYPE CONSOLE}
uses
  SysUtils;
var
   a,b,x,y,l,r,m : int64;
begin
    read(a,b,x,y);
    l := 1;
    r := 2000000000;
    while l + 1 < r do begin
          m := (l + r) div 2;
          if (m*x > a) or (m*y > b) then r := m
          else l := m;
    end;
    if (r*x <= a) and (r*y <= b) then begin
        write(r*x,' ',r*y);
        halt;
    end;
    if (l*x <= a) and (l*y <= b) then begin
        write(l*x,' ',l*y);
        halt;
    end;
    write(0,' ',0);
end.

Reca company makes monitors, the most popular of their models is AB999 with the screen size a×b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x:y became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes x:y, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed.

The first line of the input contains 4 integers — a, b, x and y (1≤a,b,x,y≤2·10^9).

If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;

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

var
	a, b, x, y, aa, bb, ra, rb: Int64;

begin
	Readln(a, b, x, y);
	aa := GetGCD(x, y);
	x := x div aa;
	y := y div aa;
	ra := x * Min(a div x, b div y);
	rb := y * Min(a div x, b div y);

	Writeln(ra, ' ', rb);

end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  node = record
    res, y, x : integer;
  end;

var
  n, m, i, j, top, l, r, minn : integer;
  a : array[1..1100, 1..1100] of char;
  b : array[1..1100, 1..1100] of integer;
  q : array[1..1100000] of node;
  u : node;

function pop : node;
begin
  inc(l);
  result := q[l - 1];
end;

procedure push(res, y, x : integer);
begin
  inc(r);
  q[r].res := res;
  q[r].y := y;
  q[r].x := x;
  b[y][x] := res;
end;

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

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

  l := 1;
  for i := 1 to m do
    if a[n][i] = '#' then
      push(0, n, i);

  while l <= r do begin
    u := pop;
    for i := u.y - 1 downto 1 do begin
      if (a[i][u.x] = '#') and (b[i][u.x] > u.res) then
        push(u.res + 1, i, u.x);
      if (a[i][u.x] = '#') and (b[i][u.x] <= u.res) then
        break;
    end;
    for i := u.y + 1 to n do begin
      if (a[i][u.x] = '#') and (b[i][u.x] > u.res) then
        push(u.res + 1, i, u.x);
      if (a[i][u.x] = '#') and (b[i][u.x] <= u.res) then
        break;
    end;
    for i := u.x - 1 downto 1 do begin
      if (a[u.y][i] = '#') and (b[u.y][i] > u.res) then
        push(u.res + 1, u.y, i);
      if (a[u.y][i] = '#') and (b[u.y][i] <= u.res) then
        break;
    end;
    for i := u.x + 1 to m do begin
      if (a[u.y][i] = '#') and (b[u.y][i] > u.res) then
        push(u.res + 1, u.y, i);
      if (a[u.y][i] = '#') and (b[u.y][i] <= u.res) then
        break;
    end;
  end;

  minn := maxint;
  for i := 1 to m do
    if (b[1][i] < minn) and (a[i][j] = '#') then
      minn := b[1][i];

  if minn <> maxint then
    writeln(minn + 1)
  else
    writeln(-1);

  readln;readln;
end.

"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anybody to be able to enter the chamber. The Dark Lord is going to be busy sucking life out of Ginny.The Chamber of Secrets is an n×m rectangular grid in which some of the cells are columns. A light ray (and a basilisk's gaze) passes through the columns without changing its direction. But with some spell we can make a column magic to reflect the light ray (or the gaze) in all four directions when it receives the ray. This is shown in the figure below.   The left light ray passes through a regular column, and the right ray — through the magic column. The basilisk is located at the right side of the lower right cell of the grid and is looking to the left (in the direction of the lower left cell). According to the legend, anyone who meets a basilisk's gaze directly dies immediately. But if someone meets a basilisk's gaze through a column, this person will get petrified. We know that the door to the Chamber is located on the left side of the upper left corner of the grid and anyone who wants to enter will look in the direction of its movement (in the direction of the upper right cell) from that position.   This figure illustrates the first sample test. Given the dimensions of the chamber and the location of regular columns, Lord Voldemort has asked you to find the minimum number of columns that we need to make magic so that anyone who wants to enter the chamber would be petrified or just declare that it's impossible to secure the chamber.

The first line of the input contains two integer numbers n and m (2≤n,m≤1000). Each of the next n lines contains m characters. Each character is either "." or "#" and represents one cell of the Chamber grid. It's "." if the corresponding cell is empty and "#" if it's a regular column.

Print the minimum number of columns to make magic or -1 if it's impossible to do.

The figure above shows the first sample test. In the first sample we should make both columns magic. The dragon figure represents the basilisk and the binoculars represent the person who will enter the Chamber of secrets. The black star shows the place where the person will be petrified. Yellow lines represent basilisk gaze moving through columns.

var i, j, n, m, l, r: Longint;
    xq, yq, dq: array [1..10000000] of Longint;
    a: array [1..2000, 1..2000] of Char;
    dist: array [1..2000, 1..2000, 1..4] of Longint;
    mark: array [1..2000, 1..2000, 1..4] of Boolean;

function able(x, y, d: Longint): Boolean;
Begin
    if (x >= 1) and (x <= n) and (y >= 1) and (y <= m) and (mark[x, y, d] = false) then
        able := true
    else
        able := false;
End;

function gox(x: Longint): Longint;
Begin
    if x = 2 then
        gox := -1
    else
    if x = 4 then
        gox := 1
    else
        gox := 0;
End;

function goy(x: Longint): Longint;
Begin
    if x = 1 then
        goy := -1
    else
    if x = 3 then
        goy := 1
    else
        goy := 0;
End;

Begin
    readln(n, m);
    for i := 1 to n do begin
        for j := 1 to m do
            read(a[i, j]);
        readln;
    end;
    inc(m);
    l := 1;
    r := 1;
    xq[1] := 1;
    yq[1] := 1;
    dq[1] := 3;
    dist[1, 1, 3] := 0;
    mark[xq[1], yq[1], dq[1]] := true;
    while l <= r do begin
        if a[xq[l], yq[l]] = '#' then
        for i := 1 to 4 do
            if (i <> dq[l]) and (able(xq[l] + gox(i), yq[l] + goy(i), i)) then begin
                inc(r);
                xq[r] := xq[l] + gox(i);
                yq[r] := yq[l] + goy(i);
                dq[r] := i;
                dist[xq[r], yq[r], dq[r]] := dist[xq[l], yq[l], dq[l]] + 1;
                mark[xq[r], yq[r], dq[r]] := true;
            end;

        if able(xq[l] + gox(dq[l]), yq[l] + goy(dq[l]), dq[l]) then begin
            dist[xq[l] + gox(dq[l]), yq[l] + goy(dq[l]), dq[l]] := dist[xq[l], yq[l], dq[l]];
            xq[l] := xq[l] + gox(dq[l]);
            yq[l] := yq[l] + goy(dq[l]);
            mark[xq[l], yq[l], dq[l]] := true;
        end else
            inc(l);
    end;
    if mark[n, m, 3] = false then
        write(-1)
    else
        write(dist[n, m, 3]);
End.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  down, up, a : array[1..100000] of integer;
  i, j, n, topup, topdown : integer;

procedure pushup(u : integer);
begin
  inc(topup);
  up[topup] := u;
end;

procedure pushdown(u : integer);
begin
  inc(topdown);
  down[topdown] := u;
end;

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

  readln(n);
  for i := 1 to n + 1 do begin
    read(a[i]);
    if a[i - 1] < a[i] then
      for j := 1 to a[i] - a[i - 1] do
        pushup(i);
    if a[i - 1] > a[i] then
      for j := 1 to a[i - 1] - a[i] do
        pushdown(i - 1);
  end;

  writeln(topup);

  for i := 1 to topup do
    writeln(up[i], ' ', down[i]);

end.

Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l,r]. In other words, this function does the following: function rangeIncrement(l, r)    for i := l .. r do        a[i] = a[i] + 1Polycarpus knows the state of the array a after a series of function calls. He wants to determine the minimum number of function calls that lead to such state. In addition, he wants to find what function calls are needed in this case. It is guaranteed that the required number of calls does not exceed 10^5.Before calls of function rangeIncrement(l, r) all array elements equal zero.

The first input line contains a single integer n (1≤n≤10^5) — the length of the array a[1... n].
The second line contains its integer space-separated elements, a[1],a[2],...,a[n] (0≤a[i]≤10^5) after some series of function calls rangeIncrement(l, r).
It is guaranteed that at least one element of the array is positive. It is guaranteed that the answer contains no more than 10^5 calls of function rangeIncrement(l, r).

Print on the first line t — the minimum number of calls of function rangeIncrement(l, r), that lead to the array from the input data. It is guaranteed that this number will turn out not more than 10^5.
Then print t lines — the descriptions of function calls, one per line. Each line should contain two integers li,ri (1≤li≤ri≤n) — the arguments of the i-th call rangeIncrement(l, r). Calls can be applied in any order.
If there are multiple solutions, you are allowed to print any of them.

The first sample requires a call for the entire array, and four additional calls:
  one for the segment [2,2] (i.e. the second element of the array),  three for the segment [5,5] (i.e. the fifth element of the array).

uses math;
type mass=array[0..100000] of integer;
     maxx=array[1..100000,1..2] of integer;
var d,kol,q,q1,i1,z1,q2,k,uk,p,n,kolv,res,r,l,j,b,c,e,e1,max1:int64;s:string;i,z:integer;
    m,m1:mass;ch:char;u:boolean;qq,w,o,g,a:int64;min1,a1,b1,c1:extended;
    m2:maxx;
begin
  // assign(input,'input.txt');
  // assign(output,'output.txt');
   readln(n);
   for i:=1 to n do
     read(m[i]);
   a:=0;
   b:=0;
   for i:=1 to n do
      Begin
         while (a>0) and (m[i]<m[m1[a]]) do
            Begin
               for z:=max(m[i],m[m1[a-1]]) to m[m1[a]]-1 do
                  Begin
                     inc(b);
                     m2[b,1]:=m1[a];
                     m2[b,2]:=i-1;
                  end;
               if m[i]>m[m1[a-1]]
               then m[m1[a]]:=m[i]
               else dec(a);
            end;
         if m[i]>m[m1[a]]
         then Begin
                 inc(a);
                 m1[a]:=i;
              end;
      end;
   for i:=a downto 1 do
      Begin
         for z:=m[m1[i-1]] to m[m1[i]]-1 do
            Begin
               inc(b);
               m2[b,1]:=m1[i];
               m2[b,2]:=n;
            end;
      end;
   writeln(b);
   for i:=1 to b do
      writeln(m2[i,1],' ',m2[i,2]);
end.


program Project2;
Var k,i,n,j,j1,w:integer;
s3,s2,s:string;
begin
{  Assign(input,'input.txt');
  Assign(output,'output.txt'); }
  Readln(n);
  k:=0; j:=0;
  for i:=1 to n do
  begin
    Readln(s);
    if (Pos('try',s)<>0)
    then begin
          if k=0
          then inc(j)
          else inc(j1)
         end;
    if Pos('throw',s)<>0
    then begin
         k:=i;
         Delete(s,1,Pos('(',s));
         while s[1]=' ' do
         Delete(s,1,1);
         Delete(s,Pos(')',s),Length(s)-Pos(')',s)+1);
         while s[Length(s)]=' ' do
         Delete(s,Length(s),1);
         s2:=s;
         end;
    if Pos('catch',s)<>0
    then begin
          if (j1<>0)or(k=0)
          then begin
                if j1<>0
                then dec(j1)
                else Dec(j);
               end
          else begin
                Delete(s,1,Pos('(',s));
                while s[1]=' ' do
                Delete(s,1,1);
                w:=Pos(',',s)-1;
                while s[w]=' ' do
                Dec(w);
                s3:=Copy(s,1,w);
                if s3=s2
                then begin
                      Delete(s,1,Pos('"',s));
                      Writeln(Copy(s,1,pos('"',s)-1));
                      Halt;
                     end;
               end;
         end;
  end;
  Writeln('Unhandled Exception');
end.

Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks: The try operator. It opens a new try-catch-block.  The catch(<exception_type>, <message>) operator. It closes the try-catch-block that was started last and haven't yet been closed. This block can be activated only via exception of type <exception_type>. When we activate this block, the screen displays the <message>. If at the given moment there is no open try-catch-block, then we can't use the catch operator.The exceptions can occur in the program in only one case: when we use the throw operator. The throw(<exception_type>) operator creates the exception of the given type.Let's suggest that as a result of using some throw operator the program created an exception of type a. In this case a try-catch-block is activated, such that this block's try operator was described in the program earlier than the used throw operator. Also, this block's catch operator was given an exception type a as a parameter and this block's catch operator is described later that the used throw operator. If there are several such try-catch-blocks, then the system activates the block whose catch operator occurs earlier than others. If no try-catch-block was activated, then the screen displays message "Unhandled Exception".To test the system, Vasya wrote a program that contains only try, catch and throw operators, one line contains no more than one operator, the whole program contains exactly one throw operator.Your task is: given a program in VPL, determine, what message will be displayed on the screen.

The first line contains a single integer: n (1≤n≤10^5) the number of lines in the program. Next n lines contain the program in language VPL. Each line contains no more than one operator. It means that input file can contain empty lines and lines, consisting only of spaces.
The program contains only operators try, catch and throw. It is guaranteed that the program is correct. It means that each started try-catch-block was closed, the catch operators aren't used unless there is an open try-catch-block. The program has exactly one throw operator. The program may have spaces at the beginning of a line, at the end of a line, before and after a bracket, a comma or a quote mark.
The exception type is a nonempty string, that consists only of upper and lower case english letters. The length of the string does not exceed 20 symbols. Message is a nonempty string, that consists only of upper and lower case english letters, digits and spaces. Message is surrounded with quote marks. Quote marks shouldn't be printed. The length of the string does not exceed 20 symbols.
Length of any line in the input file does not exceed 50 symbols.

Print the message the screen will show after the given program is executed.

In the first sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(BE,"BE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so the second block will be activated, because operator catch(AE,"AE somewhere") has exception type AE as parameter and operator catch(BE,"BE in line 3") has exception type BE.
In the second sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(AE,"AE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so both blocks can be activated, but only the first one will be activated, because operator catch(AE,"AE in line 3") is described earlier than catch(AE,"AE somewhere")
In the third sample there is no blocks that can be activated by an exception of type CE.

8
try
    try
        throw ( AE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

8
try
    try
        throw ( AE )
    catch ( AE, "AE in line 3")

    try
    catch(BE, "BE in line 5")
catch(AE,"AE somewhere")

8
try
    try
        throw ( CE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

AE somewhere
AE in line 3
Unhandled Exception

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

var
  n, m, i, j, k, l, r, x, free, z, c: integer;
  a: array[0..100001]of integer;
  s, f, ans: string;
  d: char;
  ok, bf: boolean;

procedure red(sss: string; x: integer);
var
  w, mb: string;
begin
  w := '';
  while (sss[x] <> ' ') and (sss[x] <> '(') and (x <= length(sss)) do begin
    w := w + sss[x];
    inc(x);
  end;
  if w = 'try' then begin
    inc(free);
    a[free] := 1;
  end;
  if w = 'throw' then begin
    inc(free);
    a[free] := 2;
    ok := true;
    f := '';
    while (sss[x] <> ')') do begin
      f := f + sss[x];
      inc(x);
    end;
    while (f[1] = '(') or (f[1] = ' ') do begin
      delete(f, 1, 1);
    end;

    while f[length(f)] = ' ' do
      delete(f, length(f), 1);
  end;

  if w = 'catch' then begin
    inc(r);
    mb := '';

    while (sss[x] <> ',') do begin
      mb := mb + sss[x];
      inc(x);
    end;

    while (mb[1] = '(') or (mb[1] = ' ') do begin
      delete(mb, 1, 1);

    end;
    while mb[length(mb)] = ' ' do
      delete(mb, length(mb), 1);

    z := free;
    bf := false;
    c := 0;
    while (a[z] <> 2) do begin
      if a[z] = 1 then inc(c);
      dec(z);
    end;
    if c = 0 then bf := true;

    if (ok) and (mb = f) and (bf) then begin
      ans := '';
      while (sss[x] <> ')') do begin
        ans := ans + sss[x];
        inc(x);
      end;
      while (ans[1] = ',') or (ans[1] = '"') or (ans[1] = ' ') do
        delete(ans, 1, 1);
      while (ans[length(ans)] = '"') or (ans[length(ans)] = ' ') do
        delete(ans, length(ans), 1);

      write(ans);
      halt(0);
    end;

    if a[free] = 1 then
      dec(free);
  end;
end;

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

  readln(n);

  l := 0;
  r := 0;
  free := 0;
  while not seekeof do begin
    readln(s);

    for j := 1 to length(s) do begin
      if s[j] <> ' ' then begin
        red(s, j);
        break;
      end;
    end;
  end;

  writeln('Unhandled Exception');

end.

[{'input': ['8\r\ntry\r\n    try\r\n        throw ( AE ) \r\n    catch ( BE, "BE in line 3")\r\n\r\n    try\r\n    catch(AE, "AE in line 5") \r\ncatch(AE,"AE somewhere")\r\n'], 'output': ['AE somewhere\r\n']}, {'input': ['8\r\ntry\r\n    try\r\n        throw ( AE ) \r\n    catch ( AE, "AE in line 3")\r\n\r\n    try\r\n    catch(BE, "BE in line 5") \r\ncatch(AE,"AE somewhere")\r\n'], 'output': ['AE in line 3\r\n']}, {'input': ['8\r\ntry\r\n    try\r\n        throw ( CE ) \r\n    catch ( BE, "BE in line 3")\r\n\r\n    try\r\n    catch(AE, "AE in line 5") \r\ncatch(AE,"AE somewhere")\r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['3\r\ntry\r\nthrow(A)\r\ncatch(A, "A cought")\r\n'], 'output': ['A cought\r\n']}, {'input': ['5\r\n try  \r\n try \r\n  catch ( gnAEZNTt,  "i5 tAC8ktUdeX")  \r\n  throw(   gnAEZNTt    ) \r\ncatch  ( gnAEZNTt, "g1cN" )  \r\n'], 'output': ['g1cN\r\n']}, {'input': ['5\r\n try    \r\n catch(UqWpIpGKiMqFnKox ,  "bp9h8dfeNLhk9Wea"  ) \r\nthrow   (   uaBRmgAAQyWTCzaaQMlZ ) \r\n    try    \r\ncatch(  UqWpIpGKiMqFnKox,"0OvVhsVWzDyqwo"  )\r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['5\r\n    throw  (    ouB    )    \r\n  try   \r\ncatch(ouB, "bTJZV" )\r\n try    \r\ncatch(  ouB , "DUniE dDhpiN")  \r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['5\r\ntry    \r\n throw(    egdCZzrKRLBcqDl   )\r\n catch (  egdCZzrKRLBcqDl  ,"o" )\r\n    try    \r\n  catch (egdCZzrKRLBcqDl  , "oM62EJIirV D0"  ) \r\n'], 'output': ['o\r\n']}, {'input': ['10\r\n  \r\n\r\n \r\n\r\nthrow (ProgramException)\r\n \r\n  \r\n\r\n\r\n \r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['21\r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  throw(  qtSMze)   \r\ncatch(LY,"x3 j")\r\ncatch(hgSAFgbMGx,"moByu")\r\ncatch(LmydVQgv,"hbZl")\r\ncatch(oK,"B6OZx qy")\r\ncatch(rrtnRQB,"7VFkQMv")\r\ncatch(CASqQXaz,"d9oci1Kx")\r\ncatch(CTCzsdD,"u")\r\ncatch(xqqMxbEs,"Mdu")\r\ncatch(sOWgTPbRp,"fVH6")\r\ncatch(qtSMze,"ZRnNzz")\r\n'], 'output': ['ZRnNzz\r\n']}, {'input': ['3\r\ntry\r\nthrow ( X )\r\ncatch ( X, "try again")\r\n'], 'output': ['try again\r\n']}, {'input': ['3\r\ntry\r\nthrow ( try )\r\ncatch ( try, "try again")\r\n'], 'output': ['try again\r\n']}, {'input': ['3\r\ntry\r\nthrow(tryC)\r\ncatch(tryC, "bad boy")\r\n'], 'output': ['bad boy\r\n']}, {'input': ['7\r\ntry\r\ncatch(A,"try A")\r\ntry\r\n throw(A)\r\ncatch(A,"try B")\r\ntry\r\ncatch(A,"try C")\r\n'], 'output': ['try B\r\n']}, {'input': ['3\r\ntry\r\n throw(try)\r\ncatch(try,"haha")\r\n'], 'output': ['haha\r\n']}, {'input': ['3\r\ntry\r\n throw(try)\r\ncatch(try,"asd")\r\n'], 'output': ['asd\r\n']}, {'input': ['11\r\ntry\r\n  try\r\n  catch (B, "b")\r\n  \r\n  try\r\n    throw ( U )\r\n  catch (U, "try")\r\n  \r\n  try\r\n  catch (C, "c")\r\ncatch (A, "a")\r\n'], 'output': ['try\r\n']}]


program ProjectA;

{$APPTYPE CONSOLE}
{$A+,B-,D-,E+,F+,G-,I-,L-,N+,R-,Q-,S-,V+,X+}

uses
  SysUtils,
  Math;

const
  inf = 1000000000000000000;
  base = 1000000007;

var
  d: array [1..1000001, 1..2] of integer;
  n, i: integer;

procedure panic(x: integer);
begin
  write(x);
  halt(0);
end;

procedure swap(var qx, qy: integer);
var
  qz: integer;
begin
  qz := qx;
  qx := qy;
  qy := qz;
end;

begin
  {$IFNDEF ONLINE_JUDGE}
  Reset(input, 'input.txt');
  Rewrite(output, 'output.txt');
  {$ENDIF}

  read(n);
  if n = 1 then
    panic(1);
  d[1, 1] := 1;
  d[1, 2] := 0;
  for i := 2 to n do
    if odd(i) then
      begin
        d[i, 1] := (d[i - 1, 2] + d[i - 1, 1] + 1) mod base;
        d[i, 2] := d[i - 1, 2];
      end
    else
      begin
        d[i, 2] := (d[i - 1, 1] + d[i - 1, 2] + 1) mod base;
        d[i, 1] := d[i - 1, 1];
      end;

  write(d[n, 1] + d[n, 2]);

end.

Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebroids and sequence (red; red) is not a zebroid.Now Polycarpus wonders, how many ways there are to pick a zebroid subsequence from this sequence. Help him solve the problem, find the number of ways modulo 1000000007 (10^9+7).

The first line contains a single integer n (1≤n≤10^6) — the number of marbles in Polycarpus's sequence.

Print a single number — the answer to the problem modulo 1000000007 (10^9+7).

Let's consider the first test sample. Let's assume that Polycarpus initially had sequence (red; blue; red), so there are six ways to pick a zebroid:
  pick the first marble;  pick the second marble;  pick the third marble;  pick the first and second marbles;  pick the second and third marbles;  pick the first, second and third marbles. It can be proven that if Polycarpus picks (blue; red; blue) as the initial sequence, the number of ways won't change.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var i,j,n : integer;
white, black: int64;
begin
readln(n);
black := 0;
white := 0;
for i := 1 to n do
  begin
  if i mod 2 = 1 then black := black + white + 1
  else
    white := white + black + 1;
  if black >= (1000*1000*1000+7) then black := black - (1000*1000*1000+7);
  if white >= (1000*1000*1000+7) then white := white - (1000*1000*1000+7);

  end;
black  := black + white;
if black >= (1000*1000*1000+7) then black := black - (1000*1000*1000+7);
writeln(black);
readln;
end.


Var m:array [1..2,1..400000] of LongInt;
z:array [1..400000] of longint;
dp:array [1..200000] of longint;
used:array [1..200000] of Boolean;
min,kol,i,n:longint;
procedure sort(l,r:longint);
Var i,j,k,x,b:longint;
begin
  i:=l; j:=r; k:=(l+r) div 2; x:=m[1,k];
  repeat
    while m[1,i]<x do Inc(i);
    while m[1,j]>x do dec(j);
    if i<=j
    then begin
          b:=m[1,i]; m[1,i]:=m[1,j]; m[1,j]:=b;
          b:=m[2,i]; m[2,i]:=m[2,j]; m[2,j]:=b;
          b:=z[i]; z[i]:=z[j]; z[j]:=b;
          inc(i); Dec(j);
         end;
  until i>j;
  if i<r
  then sort(i,r);
  if j>l
  then sort(l,j);
end;
procedure rec(v:longint);
Var rr,i,l,r,k:longint;
begin
  used[v]:=True;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]>=v
    then r:=k
    else l:=k;
  end;
  rr:=r;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]<=v
    then l:=k
    else r:=k;
  end;
  if m[1,rr]=v
  then begin
        for i:=rr to l do
        if used[m[2,i]]=False
        then begin
              dp[1]:=dp[1]+z[i];
              rec(m[2,i]);
            end;
       end;
end;
procedure probeg(v:longint);
Var rr,i,l,r,k:longint;
begin
  used[v]:=true;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]>=v
    then r:=k
    else l:=k;
  end;
  rr:=r;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]<=v
    then l:=k
    else r:=k;
  end;
  if m[1,rr]=v
  then begin
        for i:=rr to l do
        if used[m[2,i]]=False
        then begin
              if z[i]=0
              then dp[m[2,i]]:=dp[v]+1
              else dp[m[2,i]]:=dp[v]-1;
              probeg(m[2,i]);
            end;

       end;
end;

begin
 // Assign(input,'input.txt');
 // assign(output,'output.txt');
  Readln(n);
  kol:=0;
  for i:=1 to n-1 do
  begin
    Inc(kol);
    read(m[1,kol],m[2,kol]);
    inc(kol);
    m[1,kol]:=m[2,kol-1];
    m[2,kol]:=m[1,kol-1];
    z[kol]:=1;
  end;
  sort(1,kol-1);
  rec(1);
  FillChar(used,SizeOf(used),false);
  probeg(1);
  min:=maxint;
  for i:=1 to n do
  if dp[i]<min
  then min:=dp[i];
  writeln(min);
  for i:=1 to n do
  if dp[i]=min
  then write(i,' ');
end.

The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n-1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city a is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city a to any other city. For that some roads may have to be inversed.Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.

The first input line contains integer n (2≤n≤2·10^5) — the number of cities in Treeland. Next n-1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers si,ti (1≤si,ti≤n; si≠ti) — the numbers of cities, connected by that road. The i-th road is oriented from city si to city ti. You can consider cities in Treeland indexed from 1 to n.

In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.

Var m:array [1..2,1..400000] of LongInt;
z:array [1..400000] of longint;
dp:array [1..200000] of longint;
used:array [1..200000] of Boolean;
min,kol,i,n:longint;
procedure sort(l,r:longint);
Var i,j,k,x,b:longint;
begin
  i:=l; j:=r; k:=(l+r) div 2; x:=m[1,k];
  repeat
    while m[1,i]<x do Inc(i);
    while m[1,j]>x do dec(j);
    if i<=j
    then begin
          b:=m[1,i]; m[1,i]:=m[1,j]; m[1,j]:=b;
          b:=m[2,i]; m[2,i]:=m[2,j]; m[2,j]:=b;
          b:=z[i]; z[i]:=z[j]; z[j]:=b;
          inc(i); Dec(j);
         end;
  until i>j;
  if i<r
  then sort(i,r);
  if j>l
  then sort(l,j);
end;
procedure rec(v:longint);
Var rr,i,l,r,k:longint;
begin
  used[v]:=True;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]>=v
    then r:=k
    else l:=k;
  end;
  rr:=r;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]<=v
    then l:=k
    else r:=k;
  end;
  if m[1,rr]=v
  then begin
        for i:=rr to l do
        if used[m[2,i]]=False
        then begin
              dp[1]:=dp[1]+z[i];
              rec(m[2,i]);
            end;
       end;
end;
procedure probeg(v:longint);
Var rr,i,l,r,k:longint;
begin
  used[v]:=true;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]>=v
    then r:=k
    else l:=k;
  end;
  rr:=r;
  l:=1; r:=kol+1;
  for i:=1 to 20 do
  begin
    k:=(l+r) div 2;
    if m[1,k]<=v
    then l:=k
    else r:=k;
  end;
  if m[1,rr]=v
  then begin
        for i:=rr to l do
        if used[m[2,i]]=False
        then begin
              if z[i]=0
              then dp[m[2,i]]:=dp[v]+1
              else dp[m[2,i]]:=dp[v]-1;
              probeg(m[2,i]);
            end;

       end;
end;

begin
 // Assign(input,'input.txt');
//  assign(output,'output.txt');
  Readln(n);
  kol:=0;
  for i:=1 to n-1 do
  begin
    Inc(kol);
    read(m[1,kol],m[2,kol]);
    inc(kol);
    m[1,kol]:=m[2,kol-1];
    m[2,kol]:=m[1,kol-1];
    z[kol]:=1;
  end;
  sort(1,kol);
  rec(1);
  FillChar(used,SizeOf(used),false);
  probeg(1);
  min:=maxint;
  for i:=1 to n do
  if dp[i]<min
  then min:=dp[i];
  writeln(min);
  for i:=1 to n do
  if dp[i]=min
  then write(i,' ');
end.


program task;

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

uses
  SysUtils;

const
  maxn=1000;
  eps=0.000001;

var n,m,v,i,k,j:integer;

begin
//  reset(input,'a.in');
//  rewrite(output,'a.out');
  read(n,m,v);
  if (m<n-1) or (m>(n-1)*(n-2) div 2 + 1) then begin
    writeln(-1);
    Halt(0);
  end;
  for i:=1 to n do
    if i<>v then writeln(v,' ',i);
  m:=m-(n-1);
  k:=1;
  if v=1 then k:=2;
  for i:=k+1 to n do
    for j:=i+1 to n do
      if (i<>v) and (j<>v) then begin
        if m=0 then Halt(0);
        writeln(i,' ',j);
        dec(m);
      end;
end.

Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index v fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.

The first input line contains 3 space-separated integer numbers n, m, v (3≤n≤10^5,0≤m≤10^5,1≤v≤n), n — amount of servers, m — amount of direct connections, v — index of the server that fails and leads to the failure of the whole system.

If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
	n, m, v, a, b: Int64;
	i, cnt: Integer;

begin
	Readln(n, m, v);
	a := (n-1)*(n-2) div 2 + 1;
	if (m<n-1) or (m>a) then
	begin
		Writeln(-1);
		Exit;
	end;
	cnt := 0;
	for i:=1 to n do
	begin
		if i=v then continue;
		Writeln(i, ' ', v);
		Inc(cnt);
	end;
	if n=v then Dec(n);
	a := 1; b := 1;
	while cnt<m do
	begin
		if b=n-1 then
		begin
			Inc(a);
			b := a + 1;
		end
		else Inc(b);
		if (a<>v) and (b<>v) then
		begin
			Writeln(a, ' ', b);
			Inc(cnt);
		end;
	end;
end.


{$R+,Q+,I+}
{$apptype console}
Uses SysUtils,math;
Var
   a:Array[0..100000] of Int64;
   g:Array[0..2500000] of Int64;
   i,j:Integer;
   x:Array[0..2500000,0..10] of Int64;
   n,l,r,p,ans:Int64;
   s:Real;
Begin
   Read(n);
   For i:=1 To n Do Read(a[i]);
   For i:=1 To 2500000 Do Begin
      For j:=max(1,Round(sqrt(sqrt(i)))-3) To max(1,Round(sqrt(sqrt(i)))-3)+6 Do
         If j*j*j*j>=i Then Break;
      l:=j;
      For j:=Round(sqrt(i))+3 DownTo max(1,Round(sqrt(i))-3) Do
         If j*j<=i Then Break;
      r:=j;
      If l>r Then g[i]:=0
      Else Begin
         For j:=0 To 10 Do
            If x[r,j]-x[l-1,j]=0 Then Begin
               g[i]:=j;
               Break;
         End;
      End;
      For j:=0 To 10 Do
         If g[i]=j Then x[i,j]:=x[i-1,j]+1
                   Else x[i,j]:=x[i-1,j];
   End;
   For i:=1 To n Do Begin
      s:=a[i];
      For j:=max(1,Round(sqrt(sqrt(s)))-3) To max(1,Round(sqrt(sqrt(s)))-3)+6 Do
         If j*j*j*j>=a[i] Then Break;
      l:=j;
      For j:=Round(sqrt(s))+3 DownTo max(1,Round(sqrt(s))-3) Do
         If j*j<=a[i] Then Break;
      r:=j;
      If l>r Then p:=0
      Else Begin
         For j:=0 To 10 Do
            If x[r,j]-x[l-1,j]=0 Then Begin
               p:=j;
               Break;
            End;
      End;
      If a[i]=1 Then p:=0;
      If i=1 Then ans:=p
      Else ans:=ans xor p;
   End;
   If ans<>0 Then Write('Furlo')
             Else Write('Rublo');
End.

Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to:  choose some pile, let's denote the current number of coins in it as x;  choose some integer y (0≤y<x; x^1/4≤y≤x^1/2) and decrease the number of coins in this pile to y. In other words, after the described move the pile will have y coins left. The player who can't make a move, loses. Your task is to find out, who wins in the given game if both Furlo and Rublo play optimally well.

The first line contains integer n (1≤n≤77777) — the number of piles. The next line contains n integers a1,a2,...,an (1≤ai≤777777777777) — the sizes of piles. The numbers are separated by single spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

If both players play optimally well and Furlo wins, print "Furlo", otherwise print "Rublo". Print the answers without the quotes.

var
  r,i,n:longint;
  z:int64;

function res(a:int64):longint;
begin
  if a<4 then res:=0 else
  if a<16 then res:=1 else
  if a<82 then res:=2 else
  if a<6724 then res:=0 else
  if a<50626 then res:=3 else
  if a<2562991876 then res:=1 else
  res:=2;
end;

begin
  readln(n);
  read(z);
  r:=res(z);
  for i:=2 to n do begin
    read(z);
    r:=r xor res(z);
  end;
  if r=0 then writeln('Rublo') else writeln('Furlo');
end.


var
    s,str,t:ansistring;
    p:array['a'..'z'] of boolean;
    bor:array[0..3250000,'a'..'z'] of longint;
    i,j,m,l,x,ans:longint;
    c:char;

procedure add(s:ansistring);
var
    v,k:longint;
begin
    v:=0;
    for k:=1 to length(s) do
        begin
            if bor[v][s[k]] = 0 then
                begin
                    inc(x);
                    bor[v][s[k]]:=x;
                end;
            v:=bor[v][s[k]];
        end;
end;

Begin
    readln(s);
    readln(t);
    for i:=0 to 25 do
        if t[i+1] = '0' then
            p[chr(i + ord('a'))]:=true;
    readln(m);
    for i:=1 to length(s) do
        begin
            j:=i; l:=0; str:='';
            while true do
                begin
                    if (l > m) or (j > length(s)) then  break;
                    if p[s[j]] then inc(l);
                    if l <= m then
                        str:=str+ s[j];
                    if l = m then
                        add(str);
                    inc(j);
                end;
        end;
    writeln(x);
end.

You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.A substring s[l...r] (1≤l≤r≤|s|) of string s=s1s2...s|s| (where |s| is the length of string s) is string slsl+1...sr.The substring s[l...r] is good, if among the letters sl,sl+1,...,sr there are at most k bad ones (look at the sample's explanation to understand it more clear).Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y]≠s[p...q].

The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0≤k≤|s|) — the maximum acceptable number of bad characters in a good substring.

Print a single integer — the number of distinct good substrings of string s.

In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".

program vse_podstroki;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  p = 29;

var
  ans, kol, cur, n, hash: int64;
  i, l, r: integer;
  q, c: char;
  s, k: string;
  h, hs, pr: array[1..3250000] of int64;
  good: array['a'..'z'] of boolean;
  pow : array [1..1500] of int64;

procedure qsort(l, r: integer);
var
  i, j, q, w: int64;
begin
  i := l;
  j := r;
  q := h[l+random(r-l+1)];
  repeat
    while h[i] < q do
      inc(i);
    while h[j] > q do
      dec(j);
    if i <= j then
    begin
      w := h[i];
      h[i] := h[j];
      h[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;

procedure predproc;
var i : integer;
begin
  if  not good[s[1]] then pr[1] := 1;
  hs[1] := ord(s[1]) - ord('a') + 1;
  for  i := 2 to length(s) do
    begin
      hs[i] := hs[i-1] * p + (ord(s[i]) - ord('a') + 1);
      if not good[s[i]] then pr[i] := pr[i - 1] + 1 else
                             pr[i] := pr[i - 1];
    end;

end;

begin
  //reset(input, 'input.txt');
  //rewrite(output, 'output.txt');
  readln(s);
  randomize;

  pow[1] := p;

  for i := 2 to 1500 do
    pow[i] := pow[i - 1] * p;

  for q := 'a' to 'z' do
  begin
    read(c);
    if c = '1' then
      good[q] := true;
  end;
  predproc;
  read(n);
  kol := 1;
  for l := 1 to length(s) do
    for r := l to length(s) do
    begin

      cur :=  pr[r] - pr[l - 1];
      if cur <= n then
        begin
        hash := hs[r] - hs[l - 1]*pow[r-l + 1];
        h[kol] := hash;
        inc(kol);
        //writeln(k,' ', hash);
      end else break;
    end;
  dec(kol);
  if kol = 1 then
    begin
      write(1);
      exit;
    end;

    if kol = 0 then
    begin
      write(0);
      exit;
    end;
  qsort(1, kol);

 ans := 1;

  for i := 2 to kol do
    if h[i] <> h[i - 1] then
      inc(ans);
  //writeln(kol);
  write(ans  );
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  h, r : integer;
begin
  read(r, h);
  if h >= r then begin
      if h mod r > r div 2 then
          write(trunc(h / r * 2 + 2))
      else
          write(trunc(h / r * 2 + 1));
  end
  else
      write(2);
end.

A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h+r from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right). Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius . Help Xenia calculate the maximum number of balloons she can put in her cupboard. You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin.

The single line contains two integers r,h (1≤r,h≤10^7).

Print a single integer — the maximum number of balloons Xenia can put in the cupboard.

var
  Rad,h,k:int64;

begin
  readln(Rad,h);
  k:=h div Rad;

  if (h-k*Rad>=Rad/2)
   then k:=k+1;

  if (sqrt((Rad/2)*(Rad/2)+(h+Rad-k*Rad)*(h+Rad-k*Rad))>=Rad)
   then writeln(k*2+1)
   else writeln(k*2);
end.


Uses math;
Var s:string;
rez,j,a,i,n:longint;
m:array [0..1000] of longint;
begin
//  Assign(Input,'input.txt');
//  Assign(output,'output.txt');
  readln(n);
  readln(s);
  a:=0;
  for i:=1 to n do
  if s[i]='T'
  then inc(a);
  for i:=1 to n do
  begin
    m[i]:=m[i-1];
    if s[i]='H'
    then inc(m[i]);
  end;
  rez:=MaxInt;
  for i:=1 to n do
  begin
    if i-a<1
    then j:=m[i]+m[n]-m[n-(i-a)]
    else j:=m[i]-m[i-a];
    rez:=min(rez,j);
  end;
  writeln(rez);
end.

Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him.

The first line contains number n (2≤n≤1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one.

Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.

In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.

var
  t,h:array[0..10000]of longint;
  s:string;
  n,i,j,h1,t1,res:longint;
function min(a,b:longint):longint;
begin
  if a<=b then
    min:=a
  else
    min:=b;
end;
begin
  readln(n);
  readln(s);
  h1:=0;
  t1:=0;
  for i:=1 to n do
    begin
      if s[i]='H' then  inc(h1);
      if s[i]='T' then  inc(t1);
    end;
  s:=s+s;
  t[0]:=0;
  h[0]:=0;
  n:=n+n;
  for i:=1 to n do
    if s[i]='H' then
      h[i]:=h[i-1]+1
    else
      h[i]:=h[i-1];
  for i:=1 to n do
    if s[i]='T' then
      t[i]:=t[i-1]+1
    else
      t[i]:=t[i-1];
  res:=10000000;
  for i:=1 to n-h1+1 do
    begin
     res:=min(res,h1-(h[i+h1-1]-h[i-1]));
    end;
  for i:=1 to n-t1+1 do
    begin
      res:=min(res,t1-(t[i+t1-1]-t[i-1]));
    end;
  write(res);
end.

[{'input': ['3\r\nHTH\r\n'], 'output': ['0\r\n']}, {'input': ['9\r\nHTHTHTHHT\r\n'], 'output': ['2\r\n']}, {'input': ['2\r\nTH\r\n'], 'output': ['0\r\n']}, {'input': ['4\r\nHTTH\r\n'], 'output': ['0\r\n']}, {'input': ['4\r\nHTHT\r\n'], 'output': ['1\r\n']}, {'input': ['7\r\nTTTHTTT\r\n'], 'output': ['0\r\n']}, {'input': ['8\r\nHHTHHTHH\r\n'], 'output': ['1\r\n']}, {'input': ['13\r\nHTTTHHHTTTTHH\r\n'], 'output': ['3\r\n']}, {'input': ['20\r\nTTHTHTHHTHTTHHTTTHHH\r\n'], 'output': ['4\r\n']}, {'input': ['35\r\nTTTTTTHTTHTTTTTHTTTTTTTTTTTHTHTTTTT\r\n'], 'output': ['3\r\n']}, {'input': ['120\r\nTTTTTTTHTHTHTTTTTHTHTTTTHTTTTTTTTTTTTTTTTTTTTHTTHTTTTHTTHTTTTTTTTTTTTTTTHTTTTTTHTHTTHTTTTTTHTTTTTTTTTHTTHTTTTHTTTHTTTTTH\r\n'], 'output': ['14\r\n']}, {'input': ['19\r\nHHHHHHHHHHHHHTTTHHH\r\n'], 'output': ['0\r\n']}, {'input': ['87\r\nHTHHTTHHHHTHHHHHTTTHHTHHHHTTTTHHHTTHHTHTHTHHTTHTHHTHTHTTHHHTTTTTHTTHHHHHHTHHTHHTHTTHTHH\r\n'], 'output': ['17\r\n']}, {'input': ['178\r\nTHHHTHTTTHTTHTTHHHHHTTTHTTHHTHTTTHTHTTTTTHHHTHTHHHTHHHTTTTTTTTHHHHTTHHTHHHHTHTTTHHHHHHTHHTHTTHTHTTTTTTTTTHHTTHHTHTTHHTHHHHHTTHHTTHHTTHHHTTHHTTTTHTHHHTHTTHTHTTTHHHHTHHTHHHTHTTTTTT\r\n'], 'output': ['40\r\n']}]


program Project2;

{$APPTYPE CONSOLE}
{$R+}
{$Q+}
{$O-}

uses
  SysUtils;

type Tv=record
  l, r, w, c: longint;
end;

var

  list: ARRAY [0..10000] OF tv;
  t, ans: array [0..10000] of longint;
  q, o, z, y, s, l, r, n, i, f, u: longint;

procedure inv(x, k, w: longint);
var p: longint;
begin
    p := list[k].r;
    list[k].r := u+1;
    list[p].l := u+1;
    inc(u);
    if p = 0 then q := u;
    list[u].w := x;
    list[u].l := k;
    list[u].r := p;
    if k > 0 then
      list[u].c := list[list[u].l].c + list[list[u].l].w + l else
    list[u].c := list[list[u].l].c + list[list[u].l].w;
    ans[w] := list[u].c;
    t[w] := u;
end;

procedure dl(x: longint);
begin
  x := t[x];
  list[list[x].l].r := list[x].r;
  list[list[x].r].l := list[x].l;
end;

function serch(x: longint):longint;
var i: longint;
begin
  i := 0;
  if list[i].r = 0 then begin
    result := 0;
    exit;
  end;
  while list[i].r<>0 do begin
    if list[i].c + l + list[i].w  + x + r <=list[list[i].r].c then begin
      result := i;
      exit;
    end;
    inc(i);
  end;

  result := q;
end;

begin
  {reset(input, 'input.txt');
  rewrite(output, 'output.txt');}
  read(s, l, r, n);
  u := 0;
  q := 0;
  for i := 1 to n do begin
    read(y, f);
    if y = 2 then begin
      dl(f);
    end else begin
      inc(o);
      z := serch(f);
      if z = -1 then ans[o] := -1 else
        if list[z].c + f + l > s then begin
          ans[o] := -1;
        end else
          inv(f, z, o);
    end;
  end;
  for i := 1 to o do
    writeln(ans[i]);

end.

Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors of the tasks come from the driving is right side!). Every driver when parking wants to leave for themselves some extra space to move their car freely, that's why a driver is looking for a place where the distance between his car and the one behind his will be no less than b meters and the distance between his car and the one in front of his will be no less than f meters (if there's no car behind then the car can be parked at the parking lot segment edge; the same is true for the case when there're no cars parked in front of the car). Let's introduce an axis of coordinates along the pavement. Let the parking lot begin at point 0 and end at point L. The drivers drive in the direction of the coordinates' increasing and look for the earliest place (with the smallest possible coordinate) where they can park the car. In case there's no such place, the driver drives on searching for his perfect peaceful haven. Sometimes some cars leave the street and free some space for parking. Considering that there never are two moving cars on a street at a time write a program that can use the data on the drivers, entering the street hoping to park there and the drivers leaving it, to model the process and determine a parking lot space for each car.

The first line contains three integers L, b и f (10≤L≤100000,1≤b,f≤100). The second line contains an integer n (1≤n≤100) that indicates the number of requests the program has got. Every request is described on a single line and is given by two numbers. The first number represents the request type. If the request type is equal to 1, then in that case the second number indicates the length of a car (in meters) that enters the street looking for a place to park. And if the request type is equal to 2, then the second number identifies the number of such a request (starting with 1) that the car whose arrival to the parking lot was described by a request with this number, leaves the parking lot. It is guaranteed that that car was parked at the moment the request of the 2 type was made. The lengths of cars are integers from 1 to 1000.

For every request of the 1 type print number -1 on the single line if the corresponding car couldn't find place to park along the street. Otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone.

program Problem_D;

{$APPTYPE CONSOLE}

var g : array[-2000..1000000]of longint;
    h, parked : array[0..1000]of longint;
    n, b, f, l, i, cmd, car, request : longint;

procedure Park(car, request : longint);
var i, j, balance : longint;
begin
   if (car > l)
      then begin
           parked[request] := -1;
           writeln('-1');
           exit;
           end;

   balance := 0;
   for i := 0 to car + f - 1 do
      inc(balance, g[i]);

   i := car + f - 1;
   while (balance <> 0) and (i < l + f - 1) do
      begin
      inc(i);
      balance := balance - g[i - car - b - f] + g[i];
      end;

   if (balance = 0)
      then begin
           for j := i - car - f + 1 to i - f do
              g[j] := request;
           parked[request] := i - car - f + 1;
           writeln(parked[request]);
           end
      else begin
           parked[request] := -1;
           writeln('-1');
           end;
end;

procedure Unpark(request : longint);
var i, car : longint;
begin
   car := h[request];
   i := parked[request];
   for i := i to i + car do
      g[i] := 0;

   parked[request] := -1;
end;

begin
   assign(input, '');
   assign(output, '');
   readln(l, b, f);
   readln(n);

   fillchar(g, sizeof(g), 0);
   for i := 1 to n do
      begin
      read(cmd);

      if (cmd = 1)
         then begin
              read(car);
              h[i] := car;
              Park(car, i);
              end
         else begin
              read(request);
              h[i] := -request;
              Unpark(request);
              end;
      end;
   close(input);
   close(output);
end.


{$APPTYPE CONSOLE}

uses
  SysUtils,math;
var
h,w,l,r,i,x,y : int64;
begin
 readln(h,w);
 if (h < w) then
 begin
  i := h;
  h := w;
  w := i;
 end;
 i := 0;
 x := -1;
 y := 1;
 while (1 shl i <= h) do
 begin
  l := round((1 shl i)*0.8);
  r := round((1 shl i)*1.25);
  if r > extended((1 shl i)*1.25) then dec(r);
  if l <  extended((1 shl i)*0.8) then inc(l);
  r := min(r , w);
  if r < l then begin
   inc(i);
   continue;
  end;
  if (x*y < (1 shl i)*r) then
  begin
   x := 1 shl i;
   y := r;
  end
  else
   if (x*y = (1 shl i)*r) and (1 shl i>x) then
   begin
    x := 1 shl i;
    y := r;
   end;
  inc(i);
 end;
 i := 0;
 while (1 shl i <= w) do
 begin
  l := round((1 shl i)*0.8);
  r := round((1 shl i)*1.25);
  if r > extended((1 shl i)*1.25) then dec(r);
  if l <  extended((1 shl i)*0.8) then inc(l);
  r := min(r , h);
  if r < l then begin
   inc(i);
   continue;
  end;
  if (x*y < (1 shl i)*r) then
  begin
   x := 1 shl i;
   y := r;
  end
  else
   if (x*y = (1 shl i)*r) and (1 shl i>x) then
   begin
    x := 1 shl i;
    y := r;
   end;
  inc(i);
 end;
 writeln(max(y,x),' ',min(x,y));
end.

One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height/width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2^x for some integer x). If those rules don't indicate the size of the cut are clearly, then the way with which the cut part possesses the largest area is chosen. Of course, both sides of the cut area should be integer. If there are several answers to this problem, you should choose the answer with the maximal height.

The first line contains a pair of integers h and w (1≤h,w≤10^9) which are the height and width of the uploaded photo in pixels.

Print two integers which are the height and width of the cut area.

          const eps=1e-14;
          besk=2000000000000000000; label 55,5,4,1,3,2,44,22;
          type
          mas=array[-20000..1140060+1] of int64;
          integer=longint;   zap=record  p1,p2,p3:int64; end;
          zap1=^zap;
          var  kolrazn,ii,jj,tip,ppos1,oldtt,ps,pos1,pos2,pred,color,buk,cur,init,res,oldpos,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto:longint;
          oldss,smin,ss3,ss,ss1,ss2:string;
          newaans,aans:zap;
          ddist,ott,tttt:extended;
          pqqq:zap;
          otal,al1,al2,acc, disk,prop,bet,al:extended; fl1,fl2,fl:boolean;
          dr3,dr1,dr2,pt,ott1,ott2:zap;
          zz,x:array[-1000..2100000] of longint;
          sss1,sss2:array[-10..1200000] of char;
          v3,v1,v2,pointx,pointy,vel,tt0,radius,ote,ddl,dl1,dl2:extended;
          dd,ddpos:array[-2..14,-200..65400] of int64;
          posx,posy,zx,zy,z,kol,xxx,yyy,invfact,y,ansx,ansy,ugol,xx,yy:array[-1000..5150000] of int64;
          numleft,numright,pol,dx,dy:array[-100..1850000] of int64;
          popalx,popaly:array[-10..5000,-1..100] of boolean;
          ttt,delta,p8,p6,time,tt1,tt2,sum,maxdob,left,right,koll,newt,osn,oldot,num,oldt,ll,rr,znmax,p,aa,ot,t11,t01,t10,t00,pold,nap,t4,kk,dl,iii,jjj,aaa,bbb,ccc,bb,p0,t,pos,xmax,xmin,ymax,ymin,newpos,newdl,len,pp3,ans1,ans2,modul,t0,t1,t2,dloch,koldel,mmax,stepen,pq,pp1,pp2,period, dolg,ot1,ot2,oldgr,predsum,pmin,tmin,kool,number,imin,qq,n,m,numpos,vx,vy,down,imax,t3,qq1,qq2,q1,q2,ost,w,p3,p4,pmax,pmax2,p1,p2,hh,pos0,pp,mm,maxot,tmax,nn,n1,q:int64; flag1:boolean;
          b,c,a,zzz,fact,stan,a2,invx,invy,place,str,b2,z1,sum1,sum0,d0,d1,d:mas; flag2,flag:boolean;  pl:longint;
          ans,tt,sdvig,start,finish,kolbl,glub,ot3,izb, oldmax,newmax,posmax,zapas,razn,oldll,oldrr,ppp,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,cc,ugg,r,ug:int64;
          prost,zzan,zann:array[-10..2001001] of boolean;
          zanx,zany,zan,zan1,marked:array[-100..1100000] of boolean;
          dstoim,dnomer:array[-1..1201,-1..1201] of int64;
          ochh,newochh:array[0..1000000] of longint;
          first,last,b1,a1,kolnenul,next1,next0,prev1,prev0,newoch,d2,och,path,lx,a3,b3,predok:array[-20000..1500000] of int64;
          znach:array[-10..5200000,0..4] of int64;
          ddsum,dd1:array[-400..65200,-1..20] of int64;
          polesum,sumgor,pole,newpole:array[-100..1300,-100..2300] of int64;
          ssans,bufer, stroka:array[-1000..1000000] of char;
          cosa,sina,cosb,sinb,rx,ry,px,py,h1,h2,h,l1,l2,otmax,v:int64;
          obmen,ch:char;
          flagg,fflag,ok,flagg1:boolean;
          koled,oldx,oldy,numx,numy,xleft,xright,s,newplace,newstr,next,prev,aold:array[-1000..1200002] of int64;
          function srav(i,j:longint):boolean; label 44;
           begin
             if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
             if a[i]>a[j] then begin  srav:=false; goto 44;   end;
             if a[i]=a[j] then if a1[i]<a1[j] then srav:=true else srav:=false;
             44:
           end;

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

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

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

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

                               function nod(a,b:int64):int64; var p,t:int64;
                               begin
                                 a:=abs(a); b:=abs(b);
                                 if (a>0)and(b>0) then
                                 begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                                 p:=a;
                                 end else if a=0 then p:=b else p:=a;
                                 nod:=p;
                               end;
                               function arccos(tt:extended):extended;
                                begin
                                  if abs(tt)>1-1e-13 then
                                  if tt>0 then  arccos:=0 else arccos:=pi;
                                  if tt=0 then arccos:=pi/2 else
                                  if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
                                  else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);
                                end;
                               function degg(a,k,modul:int64):int64; var p:int64;    label 4;
                                 begin
                                  if k<=0 then degg:=1
                                  else if odd(k) then degg:=(degg(a,k-1,modul)*a) mod modul  else
                                  begin  p:=degg(a,k div 2,modul);  degg:=(p*p) mod modul;    end;
                                 end;

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

                          end;

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

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

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

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

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

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

                        function bincoef1(ii,jj:longint):int64;
                           var t1,t2,t3,p1,p2,p3,ot:int64;
                          begin
                          if ii>=jj then
                          begin
                          p1:=fact[ii];
                          p2:=invfact[jj];
                          p3:=invfact[ii-jj];
                          ot:=((p1*p2) mod modul*p3) mod modul;
                          bincoef1:=ot;
                          end  else bincoef1:=0;
                          end;
           }
    function per(i:longint):string;
    var j:longint; ot:string;
    begin
      ot:='';
      while i>0 do begin j:=i and 1; i:=i shr 1; if j=0 then ot:='0'+ot else ot:='1'+ot;   end;
      per:=ot;
    end;

    procedure pech;
    begin
       for i:=1 to p do write(x[i],' '); writeln('ot= ',ot);
    end;

 begin

  {  assign (input,'D:\Projects\input.txt');reset(input);
    assign (output,'D:\Projects\output.txt'); rewrite(output);
   }
  z[0]:=1;
  for i:=1 to 31 do z[i]:=z[i-1]*2;
    read(aa,bb);
   for i:=0 to 30 do if z[i]<=aa then
     begin
         p2:=trunc(z[i]*5/4+eps);
         p1:=trunc(z[i]*4/5-eps)+1;

       {  writeln(z[i],' gr= ',p1,' ',p2);
       }  rr:=min(p2,bb);
         if rr>=p1 then
           begin pp:=rr*z[i];
                ot:=max(ot,pp);
                if ot=pp then begin  aaa:=z[i]; bbb:=rr;   end;
           end;
     end;

    { writeln(aaa,' ',bbb);

     goto 1;
     }
    for i:=0 to 30 do if z[i]<=bb then
     begin
         p2:=trunc(z[i]*5/4+eps);
         p1:=trunc(z[i]*4/5-eps)+1;

       {  writeln(z[i],' gr= ',p1,' ',p2);
       }  rr:=min(p2,aa);
         if rr>=p1 then
           begin pp:=rr*z[i];
                ot:=max(ot,pp);
                if ot=pp then begin  bbb:=z[i]; aaa:=rr;   end;
           end;
     end;

      writeln(aaa,' ',bbb);

       1: close (output);

 end.