program Project2;

{$APPTYPE CONSOLE}
{$R+,Q+}

uses
  SysUtils, Math;

var
  ans, edge : int64;
  x, n, m, k, i, j, u, v, top : integer;
  a : array[1..10, 1..10] of boolean;
  d : array[0..1023, 0..511] of int64;
  st : array[1..2] of integer;

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

  read(n, m, k);
  for i := 1 to m do begin
    read(u, v);
    a[u][v] := true;
    a[v][u] := true;
  end;

  ans := 0;
  for i := 1 to 1 shl n - 1 do begin
    j := i;
    u := 1;
    x := 1;
    top := 0;
    while x <= j do begin
      if x and j <> 0 then begin
        inc(top);
        if top <= 2 then
          st[top] := u;
      end;
      x := x shl 1;
      inc(u);
    end;
    if top = 1 then begin
      j := i and (j - 1);
      continue;
    end else
    if top = 2 then begin
      if a[st[1]][st[2]] then
        d[i][j] := 1;
      if (top = k) and (i = 1 shl n - 1) then
        inc(ans, d[i][j]);
//      writeln(i, ' ', j, ' ', d[i][j]);
      j := i and (j - 1);
    end;
    while j <> 0 do begin
      top := 0;
      x := 1;
      while x <= j do begin
        if x and j <> 0 then
          inc(top);
        x := x shl 1;
      end;
      u := 1;
      x := 1;
      while (x <= j) do begin
        if j and x <> 0 then begin
          for v := 1 to n do
            if (a[u][v]) and (i and (1 shl (v - 1)) <> 0) and (j and (1 shl (v - 1)) = 0) then
              inc(d[i][j], d[i xor (1 shl (u - 1))][j xor (1 shl (u - 1)) or (1 shl (v - 1))] + d[i xor (1 shl (u - 1))][j xor (1 shl (u - 1))]);
        end;
        x := x shl 1;
        inc(u);
      end;
      d[i][j] := d[i][j] div top;
      if (top = k) and (i = 1 shl n - 1) then
        inc(ans, d[i][j]);
//      writeln(i, ' ', j, ' ', d[i][j]);
      j := i and (j - 1);
    end;
  end;

  writeln(ans);

end.

Life in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are n junctions and m two way roads, at which one can get from each junction to any other one. The mayor wants to close some roads so that the number of roads left totaled to n-1 roads and it were still possible to get from each junction to any other one. Besides, the mayor is concerned with the number of dead ends which are the junctions from which only one road goes. There shouldn't be too many or too few junctions. Having discussed the problem, the mayor and his assistants decided that after the roads are closed, the road map should contain exactly k dead ends. Your task is to count the number of different ways of closing the roads at which the following conditions are met:   There are exactly n-1 roads left.  It is possible to get from each junction to any other one.  There are exactly k dead ends on the resulting map. Two ways are considered different if there is a road that is closed in the first way, and is open in the second one.

The first line contains three integers n, m and k (3≤n≤10,n-1≤m≤n·(n-1)/2,2≤k≤n-1) which represent the number of junctions, roads and dead ends correspondingly. Then follow m lines each containing two different integers v1 and v2 (1≤v1,v2≤n,v1≠v2) which represent the number of junctions connected by another road. There can be no more than one road between every pair of junctions. The junctions are numbered with integers from 1 to n. It is guaranteed that it is possible to get from each junction to any other one along the original roads.

Print a single number — the required number of ways.

program Project2;

{$APPTYPE CONSOLE}
{$R+,Q+}

uses
  SysUtils, Math;

var
  ans, edge : int64;
  x, n, m, k, i, j, u, v, top : integer;
  a : array[1..10, 1..10] of boolean;
  d : array[0..1023, 0..1023] of int64;
  st : array[1..2] of integer;

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

  read(n, m, k);
  for i := 1 to m do begin
    read(u, v);
    a[u][v] := true;
    a[v][u] := true;
  end;

  ans := 0;
  for i := 1 to 1 shl n - 1 do begin
    j := i;
    u := 1;
    x := 1;
    top := 0;
    while x <= j do begin
      if x and j <> 0 then begin
        inc(top);
        if top <= 2 then
          st[top] := u;
      end;
      x := x shl 1;
      inc(u);
    end;
    if top = 1 then begin
      j := i and (j - 1);
      continue;
    end else
    if top = 2 then begin
      if a[st[1]][st[2]] then
        d[i][j] := 1;
      if (top = k) and (i = 1 shl n - 1) then
        inc(ans, d[i][j]);
//      writeln(i, ' ', j, ' ', d[i][j]);
      j := i and (j - 1);
    end;
    while j <> 0 do begin
      top := 0;
      x := 1;
      while x <= j do begin
        if x and j <> 0 then
          inc(top);
        x := x shl 1;
      end;
      u := 1;
      x := 1;
      while (x <= j) do begin
        if j and x <> 0 then begin
          for v := 1 to n do
            if (a[u][v]) and (i and (1 shl (v - 1)) <> 0) and (j and (1 shl (v - 1)) = 0) then
              inc(d[i][j], d[i xor (1 shl (u - 1))][j xor (1 shl (u - 1)) or (1 shl (v - 1))] + d[i xor (1 shl (u - 1))][j xor (1 shl (u - 1))]);
        end;
        x := x shl 1;
        inc(u);
      end;
      d[i][j] := d[i][j] div top;
      if (top = k) and (i = 1 shl n - 1) then
        inc(ans, d[i][j]);
//      writeln(i, ' ', j, ' ', d[i][j]);
      j := i and (j - 1);
    end;
  end;

  writeln(ans);

end.


program Project11;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var s,s1,s2:string;
    i,j,k,n:integer;
    d:char;
    a:array[1..5000] of string;
    b:array[1..5000] of string;
    c:array[1..5000] of string;
begin
  { TODO -oUser -cConsole Main : Insert code here }
   readln(n);
    for i:=1 to (n div 2) do
     begin
      readln(a[i]);
      readln(b[i]);
     end;
   readln(d);
    for i:=1 to (n div 2) do
     begin
      s1:=a[i]+d+b[i];
      s2:=a[i]+d+a[i];
       if s1<s2 then
       c[i]:=s1
      else
       c[i]:=s2;
     end;
    for i:=1 to (n div 2) do
     writeln(c[i]);
end.

BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n/2 lines of strictly equal length, each of which contains exactly two names and exactly one separator character between them. The name of every city should be used in the calendar exactly once. For historical reasons the symbol d is used as the separator of words in the calendar. The BerOilGasDiamondBank management wants to show that all its branches are equally important to it, that's why the order of their appearance in the calendar should be following: if we "glue"(concatinate) all the n/2 calendar lines (from top to bottom) to make a single line, then the lexicographically minimal line is obtained. No separator character will be used to separate calendar lines. For example, if the lines are "bertown!berville", "newberville!bera", then the resulting line is "bertown!bervillenewberville!bera". In some sense one has to find the lexicographically minimal calendar, where the comparison of calendars happens line by line.Help BerOilGasDiamondBank and construct the required calendar.

The first line contains an integer n (1≤n≤10^4, n is even) which is the number of branches. Then follow n lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol d (d has an ASCII-code from 33 to 126 inclusively, excluding lowercase Latin letters) which is the separator between words in the calendar lines. It is guaranteed that the calendar is possible to be constructed and all the names are different.

Print n/2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern programming languages.

{$apptype console}
{$R+,S+,I+,Q+}
const
     inf = 'input.txt';
     outf = 'output.txt';
var
 n,i,j,len,cur:longint;
 d:char;
 x,tmp:string;
 s:array[1..10100] of string;
 was:array[1..10100] of boolean;

 procedure sort(l,r:longint);
 var i,j:longint;
  begin
   i:=l;
   j:=r;
   x:=s[(l+r) div 2];
   repeat
    while s[i] < x do inc(i);
    while s[j] > x do dec(j);
    if i <= j then
     begin
      tmp:=s[i];
      s[i]:=s[j];
      s[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);
 readln(n);
 for i:=1 to n do readln(s[i]);
 readln(d);
 len:=0;
 for i:=1 to n do inc(len,length(s[i]));
 len:=2*len div n;
 for i:=1 to n do s[i]:=s[i]+d;
 sort(1,n);
 for i:=1 to n do delete(s[i],length(s[i]),1);
 cur:=1;
 fillchar(was,sizeof(was),false);
 for i:=1 to n div 2 do
  begin
   while was[cur] do inc(cur);
   write(s[cur],d);
   was[cur]:=true;
   for j:=cur+1 to n do if not was[j] then
    if length(s[cur])+length(s[j]) = len then
     begin
      writeln(s[j]);
      was[j]:=true;
      break;
     end;
  end;
end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,math;

var
  f:array[0..50] of int64;
  n:longint;
  i,j:longint;

begin
  read(n);
  f[1]:=6;
  f[2]:=10;
  f[3]:=15;
  f[4]:=12;
  if n = 2 then
    write(-1)
  else
  begin
    for i:=1 to min(4,n) do
      write(f[i],' ');
    for i:=5 to n do
      begin
        f[i]:=f[i-1] + 6;
        write(f[i],' ');
      end;
  end;
end.

Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n.Let us remind you the definition of the greatest common divisor: GCD(a1,...,ak)=d, where d represents such a maximal positive number that each ai (1≤i≤k) is evenly divisible by d. At that, we assume that all ai's are greater than zero.Knowing that Petya is keen on programming, his friends has agreed beforehand that the 1-st friend gives a1 sweets, the 2-nd one gives a2 sweets, ..., the n-th one gives an sweets. At the same time, for any i and j (1≤i,j≤n) they want the GCD(ai,aj) not to be equal to 1. However, they also want the following condition to be satisfied: GCD(a1,a2,...,an)=1. One more: all the ai should be distinct.Help the friends to choose the suitable numbers a1,...,an.

The first line contains an integer n (2≤n≤50).

If there is no answer, print "-1" without quotes. Otherwise print a set of n distinct positive numbers a1,a2,...,an. Each line must contain one number. Each number must consist of not more than 100 digits, and must not contain any leading zeros. If there are several solutions to that problem, print any of them.
Do not forget, please, that all of the following conditions must be true:
 For every i and j (1≤i,j≤n): GCD(ai,aj)≠1 GCD(a1,a2,...,an)=1 For every i and j (1≤i,j≤n,i≠j): ai≠aj Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

uses Math;
type chislo=record
            z:integer;
            m:array [1..1000] of byte;
        end;
Var k,n,kol,i:longint;
m:array [1..100] of longint;
c,rez:chislo;
function proverka(n:LongInt):boolean;
Var i:longint;
begin
  for i:=2 to n-1 do
  if n mod i=0
  then begin proverka:=false; exit; end;
  proverka:=true;
end;
function umn(a,b:chislo):chislo;
Var g,I,j:integer;
res:chislo;
begin
  res.z:=0;
  FillChar(res.m,SizeOf(res.m),0);
  g:=a.z+b.z;
  for i:=1 to b.z do
     begin
     for j:=1 to a.z do
     begin
      res.m[j-1+i]:=res.m[j-1+i]+a.m[j]*b.m[i];
     if res.m[j+i-1]>9
     then begin
          res.m[j+i]:=res.m[i+j]+(res.m[j+i-1] div 10);
          res.m[j+i-1]:=res.m[j+i-1] mod 10;
          end;
     end;
     end;
     for i:=1 to g+1 do
     if res.m[i]>9
     then begin
          res.m[i+1]:=res.m[i+1]+(res.m[i] div 10);
          res.m[i]:=res.m[i] mod 10;
          end;
     i:=g+1;
     repeat
     dec(i);
     until (res.m[i]<>0)or(i=0);
     res.z:=i;
     umn:=res;
end;
procedure Del(a:chislo;n:longint);
Var i,z,e:longint;
kk:array [1..1000] of Byte;
begin
  e:=0;
  for i:=a.z downto 1 do
  begin
    inc(e);
    kk[e]:=(a.m[i+2]*100+a.m[i+1]*10+a.m[i]) div n;
    z:=(a.m[i+2]*100+a.m[i+1]*10+a.m[i]) mod n;
    a.m[i+1]:=z div 10;
    a.m[i]:=z mod 10;
  end;
  i:=1;
  while kk[i]=0 do
  inc(i);
  for i:=i to e do
  write(kk[i]);
  writeln;
end;
begin
//    Assign(input,'input.txt');
//    assign(Output,'output.txt');
    readln(n);
    if n=2
    then begin writeln(-1); halt(0); end;
    kol:=0;
    rez.z:=1;
    rez.m[1]:=1;
    for i:=2 to 1000 do
    begin
      if proverka(i)
      then begin
            inc(kol);
            m[kol]:=i;
            k:=i;
            c.z:=0;
            while k<>0 do
            begin
              Inc(c.z);
              c.m[c.z]:=k mod 10;
              k:=k div 10;
            end;
            rez:=umn(rez,c);
            if kol=n
            then break;
           end;
    end;
    for i:=1 to n do
    Del(rez,m[i]);
end.


program ps;  {$Q+ $R+}

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

function nod(a, b: longint): longint;
begin
    if b = 0 then nod := a else nod := nod(b, a mod b);
end;

function sqrtn(n, r: longint): int64;
var i, j: longint; b: boolean; k: int64;
begin
    i := 1; b := true;
    while b do
    begin
        inc(i);
        k := 1;
        for j := 1 to n do
        if k <= r then
        k := k * i;
        b := k <= r;
    end;
    sqrtn := i - 1;
end;

function st(x, n: longint): int64;
var i, j: longint;
begin
    j := 1;
    for i := 1 to n do
    j := j * x;
    st := j;
end;

begin
    {assign(input, 'input.txt'); reset(input);
    assign(output, 'output.txt'); rewrite(output);}
    read(n, l, r);
    if n < 3 then
    begin
        if n = 1 then write(r - l + 1)
        else write((r - l + 1)*(r - l));
        halt(0);
    end;
    m := sqrtn(n - 1, r);
    k := 0;
    for y := 1 to m do
    for x := y + 1 to m do
    if nod(x, y) = 1 then
    if (r div st(x, n - 1)) - ((l - 1) div st(y, n - 1)) >= 0 then
    k := k + (r div st(x, n - 1)) - ((l - 1) div st(y, n - 1));
    write(k*2);
end.

For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l≤ai≤r and ai≠aj , where a1,a2,...,an is the geometrical progression, 1≤i,j≤n and i≠j.Geometrical progression is a sequence of numbers a1,a2,...,an where each term after first is found by multiplying the previous one by a fixed non-zero number d called the common ratio. Note that in our task d may be non-integer. For example in progression 4,6,9, common ratio is .Two progressions a1,a2,...,an and b1,b2,...,bn are considered different, if there is such i (1≤i≤n) that ai≠bi.

The first and the only line cotains three integers n, l and r (1≤n≤10^7,1≤l≤r≤10^7).

Print the integer K — is the answer to the problem.

These are possible progressions for the first test of examples:
  1;  2;  3;  4;  5;  6;  7;  8;  9;  10. These are possible progressions for the second test of examples:
  6,7;  6,8;  6,9;  7,6;  7,8;  7,9;  8,6;  8,7;  8,9;  9,6;  9,7;  9,8. These are possible progressions for the third test of examples:
  1,2,4;  1,3,9;  2,4,8;  4,2,1;  4,6,9;  8,4,2;  9,3,1;  9,6,4. These are possible progressions for the fourth test of examples:
  4,6,9;  9,6,4.

   const nn=6000000; nnn=2000000;eps=0.00000001;  besk1=200000008;
   label 1,2;
    type   { real=double;}  {string=ansistring;}
    mas=array [-10000..nn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var right,left,t1,t2,kol,pp,t,aa,bb,cc,p1,p2,kolx,kolo,l,ot,nm,n,s1,s2,m,s,imax,smin,cen,dl,i1,p,prost,besk:int64;
    k,step, ii,i,j:longint;
     sss:array[-10..10000] of char;
     sssnew:array[-10..1000] of char;
     zan2,zan1:array[0..1000,0..1000] of boolean;
     x,a,b:array[-10..2000000] of int64;
     masstep,dda,ddb:array[-10..12000,-1..120] of int64;
     ss1,ss2:string;
    ss:string;ch:char;
    maxpr:array[0..nn] of string;
    st2:array[0..nnn] of string;
     vol,h0,h1,v0,v1,s0,t0:extended;
     zv:point;
     xx,yy,y:array[-1..10000000] of int64;
     yot:double;
       flag,flag1:boolean;
    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:int64):int64;begin min:=x;if y<x then min:=y; end;
  function max(x,y:int64):int64;begin max:=x;if y>x then max:=y; end;

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

  function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
  tt:zap; tt1:zap1;
begin
  if a<b then begin r:=a;a:=b;b:=r; 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;
    d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt;
   evkl:=tt1;
end;

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

end;

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

    readln(n,aa,bb);
    if n=1 then
      begin
         writeln(bb-aa+1);
         goto 1;

      end;

    if n=2 then
      begin
         t:=bb-aa;
         writeln(t*(t+1));
         goto 1;

      end;

   for step:=1 to 30 do
     begin

         for i:=1 to 3200 do
          begin
           masstep[i,step]:= degg(i,step);
           if  masstep[i,step]>bb then begin x[step]:=i;break; end;

          end;

     end;

  {   for i:=2 to 30 do
    begin
     for j:=1 to x[i] do write(masstep[i,j],' '); writeln;

    end;
   }
  for i:=1 to 3200 do for j:=i+1 to 3200 do
  if (masstep[i,n-1]>=1)and(masstep[i,n-1]<=bb)
     and(masstep[j,n-1]>=1)and(masstep[j,n-1]<=bb)
   then
  begin
   inc(pp); xx[pp]:=i; yy[pp]:=j;
  end;
 {
  writeln(pp);
   for i:=1 to pp do  writeln(xx[i],' ',yy[i]);

     writeln('----------');

   for i:=1 to pp do  writeln(masstep[xx[i],n-1],' ',masstep[yy[i],n-1]);

     writeln('----------');
  }
   for i:=1 to pp do
     begin
       p1:=masstep[xx[i],n-1];
       p2:=masstep[yy[i],n-1];
       right:=bb div p2;
      { writeln('p1= ',p1,' p2= ',p2);
      } left:=max((aa+p1-1) div p1,1);
       kol:=right-left+1;
       if kol<0 then kol:=0;
     {  for j:=left to right do
      begin
        zan1[p1*j,p2*j]:=true;
        writeln(p1*j,' ',p2*j,' ot= ',ot);
        inc(ot);
      end;
       writeln(p1,' -- ',p2,' left= ',left,' right= ',right,' kol= ',kol);
       writeln;
     } if nod(p1,p2)=1 then  ot:=ot+kol;

     end;

     writeln(ot*2);
     goto 1;
       ot:=0;
    if n=3 then
      begin
          for i:=aa to bb do
          for j:=i+1 to bb do
          for k:=j+1 to bb do if i*k=j*j
           then
            begin
              writeln(i,' ',j,' ',k);
              inc(ot);
              zan2[i,k]:=true;
            end;

          writeln(ot);

      end;

     for i:=0 to 1000 do for j:=0 to 1000 do
     if zan1[i,j]<>zan2[i,j] then writeln('bad ',i,' ',j);

      for i:=0 to 1000 do for j:=0 to 1000 do if zan1[i,j] then
        writeln('zan ', i,' ',j);

    for i:=1 to 40 do
    begin for j:=1 to 40 do if zan1[i,j] then write('+') else write('-'); writeln;  end;
    writeln('*************************');

     for i:=1 to 40 do
    begin for j:=1 to 40 do if zan2[i,j] then write('+') else write('-'); writeln;  end;
    writeln('************************');

   1:          close(output);
end.


{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Const
   cifr=['0'..'9'];
Var
   a,b:Array[0..30,0..30] of Char;
   used,h:Array[0..30,0..30] of Boolean;
   s:Array[0..1000,0..1000] of Boolean;
   used1:Array[0..1000] of Boolean;
   d,d1:Array[0..30,0..30] of Integer;
   q1,q2,mt:Array[0..1000] of Integer;
   i,j,i1,j1,i2,j2,n,t,l,r,x1,y1,x2,x3,ans:Integer;
Function Kuhn(v:Integer):Boolean;
Var i:Integer;
Begin
   If used1[v] Then Begin
      Kuhn:=false;
      Exit;
   End;
   used1[v]:=true;
   For i:=1 To 900 Do
      If (s[v,i]) and ((mt[i]=-1) or (Kuhn(mt[i]))) Then Begin
         mt[i]:=v;
         Kuhn:=true;
         Exit;
      End;
   Kuhn:=false;
End;
Begin
   ReadLn(n,t);
   For i:=1 To n Do Begin
      For j:=1 To n Do Read(a[i,j]);
      ReadLn;
   End;
   ReadLn;
   For i:=1 To n Do Begin
      For j:=1 To n Do Read(b[i,j]);
      ReadLn;
   End;
   x1:=0;
   y1:=0;
   For i:=1 To n Do
      For j:=1 To n Do
         If a[i,j]='Z' Then Begin
            x1:=i;
            y1:=j;
            Break;
         End;
   For i:=1 To n Do
      For j:=1 To n Do d[i,j]:=3000;
   q1[1]:=x1;
   q2[1]:=y1;
   used[x1,y1]:=true;
   d[x1,y1]:=0;
   l:=0;
   r:=1;
   While l<r Do Begin
      l:=l+1;
      For i1:=-1 To 1 Do
         For j1:=-1 To 1 Do
            If abs(i1+j1)=1 Then Begin
               If (q1[l]+i1>0) and (q1[l]+i1<=n) and (q2[l]+j1>0) and (q2[l]+j1<=n) and (a[q1[l]+i1,q2[l]+j1] in cifr) and (not(used[q1[l]+i1,q2[l]+j1])) Then Begin
                  r:=r+1;
                  q1[r]:=q1[l]+i1;
                  q2[r]:=q2[l]+j1;
                  used[q1[r],q2[r]]:=true;
                  d[q1[r],q2[r]]:=d[q1[l],q2[l]]+1;
               End;
            End;
   End;
   For i:=1 To n Do
      For j:=1 To n Do
         If (a[i,j] in cifr) and (a[i,j]<>'0') Then Begin
            For i1:=1 To n Do
               For j1:=1 To n Do used[i1,j1]:=false;
            For i1:=1 To n Do
               For j1:=1 To n Do h[i1,j1]:=false;
            q1[1]:=i;
            q2[1]:=j;
            used[i,j]:=true;
            h[i,j]:=true;
            d1[i,j]:=0;
            l:=0;
            r:=1;
            While l<r Do Begin
               l:=l+1;
               For i1:=-1 To 1 Do
                  For j1:=-1 To 1 Do
                     If abs(i1+j1)=1 Then Begin
                        If (q1[l]+i1>0) and (q1[l]+i1<=n) and (q2[l]+j1>0) and (q2[l]+j1<=n) and (a[q1[l]+i1,q2[l]+j1] in cifr) and (not(used[q1[l]+i1,q2[l]+j1])) and (d1[q1[l],q2[l]]<t) Then Begin
                           If d1[q1[l],q2[l]]>=d[q1[l]+i1,q2[l]+j1] Then Continue;
                           If d1[q1[l],q2[l]]+1=d[q1[l]+i1,q2[l]+j1] Then Begin
                              h[q1[l]+i1,q2[l]+j1]:=true;
                              Continue;
                           End;
                           r:=r+1;
                           q1[r]:=q1[l]+i1;
                           q2[r]:=q2[l]+j1;
                           used[q1[r],q2[r]]:=true;
                           h[q1[r],q2[r]]:=true;
                           d1[q1[r],q2[r]]:=d1[q1[l],q2[l]]+1;
                        End;
                     End;
            End;
            x2:=10*((i-1)*n+j-1)+1;
            For i1:=1 To n Do
               For j1:=1 To n Do
                  If (h[i1,j1]) and (b[i1,j1]<>'0') Then Begin
                     x3:=10*((i1-1)*n+j1-1)+1;
                     For i2:=x2 To x2+strtoint(a[i,j])-1 Do
                        For j2:=x3 To x3+strtoint(b[i1,j1])-1 Do s[i2,j2]:=true;
                  End;
         End;
   For i:=1 To 900 Do mt[i]:=-1;
   ans:=0;
   For i:=1 To 900 Do Begin
      For j:=1 To 900 Do used1[j]:=false;
      If Kuhn(i) Then ans:=ans+1;
   End;
   Write(ans);
End.

They've screwed something up yet again... In one nuclear reactor of a research station an uncontrolled reaction is in progress and explosion which will destroy the whole station will happen soon.The station is represented by a square n×n divided into 1×1 blocks. Each block is either a reactor or a laboratory. There can be several reactors and exactly one of them will explode soon. The reactors can be considered impassable blocks, but one can move through laboratories. Between any two laboratories, which are in adjacent blocks, there is a corridor. Blocks are considered adjacent if they have a common edge.In each laboratory there is some number of scientists and some number of rescue capsules. Once the scientist climbs into a capsule, he is considered to be saved. Each capsule has room for not more than one scientist.The reactor, which is about to explode, is damaged and a toxic coolant trickles from it into the neighboring blocks. The block, which contains the reactor, is considered infected. Every minute the coolant spreads over the laboratories through corridors. If at some moment one of the blocks is infected, then the next minute all the neighboring laboratories also become infected. Once a lab is infected, all the scientists there that are not in rescue capsules die. The coolant does not spread through reactor blocks.There are exactly t minutes to the explosion. Any scientist in a minute can move down the corridor to the next lab, if it is not infected. On any corridor an unlimited number of scientists can simultaneously move in both directions. It is believed that the scientists inside a lab moves without consuming time. Moreover, any scientist could get into the rescue capsule instantly. It is also believed that any scientist at any given moment always has the time to perform their actions (move from the given laboratory into the next one, or climb into the rescue capsule) before the laboratory will be infected.Find the maximum number of scientists who will be able to escape.

The first line contains two integers n and t (2≤n≤10, 1≤t≤60). Each of the next n lines contains n characters. These lines describe the scientists' locations. Then exactly one empty line follows. Each of the next n more lines contains n characters. These lines describe the rescue capsules' locations.
In the description of the scientists' and the rescue capsules' locations the character "Y" stands for a properly functioning reactor, "Z" stands for the malfunctioning reactor. The reactors' positions in both descriptions coincide. There is exactly one malfunctioning reactor on the station. The digits "0" - "9" stand for the laboratories. In the description of the scientists' locations those numbers stand for the number of scientists in the corresponding laboratories. In the rescue capsules' descriptions they stand for the number of such capsules in each laboratory.

Print a single number — the maximum number of scientists who will manage to save themselves.

In the second sample the events could take place as follows:

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

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


{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Var
   p1,c1,r1,p2,c2,r2:Array[-30000..30000] of Integer;
   n,i,j,a,b,m,kol:Integer;
   otv:Array[1..10000] of Integer;
Begin
   Read(n);
   For i:=1 To n Do Begin
      Read(a,b);
      For j:=a-b To a+b Do Begin
         If p1[j]=0 Then Begin
            p1[j]:=i;
            c1[j]:=a;
            r1[j]:=b;
         End
         Else Begin
            p2[j]:=i;
            c2[j]:=a;
            r2[j]:=b;
         End;
      End;
   End;
   Read(m);
   For i:=1 To m Do Begin
      Read(a,b);
      If p1[a]<>0 Then Begin
         If ((a-c1[a])*(a-c1[a])+b*b<=r1[a]*r1[a]) and (otv[p1[a]]=0) Then otv[p1[a]]:=i;
         If (p2[a]<>0) and (b=0) and ((a-c2[a])*(a-c2[a])+b*b<=r2[a]*r2[a]) and (otv[p2[a]]=0) Then otv[p2[a]]:=i;
      End;
   End;
   kol:=0;
   For i:=1 To n Do
      If otv[i]=0 Then kol:=kol+1;
   WriteLn(kol);
   For i:=1 To n Do
      If otv[i]<>0 Then Write(otv[i],' ')
                   Else Write(-1,' ');
End.

Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.Of course, biathlon as any sport, proved very difficult in practice. It takes much time and effort. Workouts, workouts, and workouts, — that's what awaited Valera on his way to great achievements in biathlon.As for the workouts, you all probably know that every professional biathlete should ski fast and shoot precisely at the shooting range. Only in this case you can hope to be successful, because running and shooting are the two main components of biathlon. Valera has been diligent in his ski trainings, which is why he runs really fast, however, his shooting accuracy is nothing to write home about.On a biathlon base where Valera is preparing for the competition, there is a huge rifle range with n targets. Each target have shape of a circle, and the center of each circle is located on the Ox axis. At the last training session Valera made the total of m shots. To make monitoring of his own results easier for him, one rather well-known programmer (of course it is you) was commissioned to write a program that would reveal how many and which targets Valera hit. More specifically, for each target the program must print the number of the first successful shot (in the target), or "-1" if this was not hit. The target is considered hit if the shot is inside the circle or on its boundary. Valera is counting on you and perhaps, thanks to you he will one day win international competitions.

The first line of the input file contains the integer n (1≤n≤10^4), which is the number of targets. The next n lines contain descriptions of the targets. Each target is a circle whose center is located on the Ox axis. Each circle is given by its coordinate of the center x (-2·10^4≤x≤2·10^4) and its radius r (1≤r≤1000). It is guaranteed that no two targets coincide, intersect or are nested into each other, but they can touch each other.
The next line contains integer m (1≤m≤2·10^5), which is the number of shots. Next m lines contain descriptions of the shots, which are points on the plane, given by their coordinates x and y (-2·10^4≤x,y≤2·10^4).
All the numbers in the input are integers.
Targets and shots are numbered starting from one in the order of the input.

Print on the first line a single number, the number of targets hit by Valera. Print on the second line for each of the targets the number of its first hit or "-1" (without quotes) if this number does not exist. Separate numbers with spaces.

{$APPTYPE CONSOLE}

uses
  SysUtils;
var x,r,b,ans:array[1..300011] of integer;
m,n,res,q,w,l,u,mid:int64;
i:integer;
procedure qsort(l,t:integer);
var i,j,e,z:integer;
begin
 i:=l;
 j:=t;
 e:=x[(l+t) div 2];
 while i<=j do
 begin
  while x[i]<e do inc(I);
  while x[j]>e do dec(j);
  if i<=j then
  begin
   z:=x[i];
   x[i]:=x[j];
   x[j]:=z;
   z:=r[i];
   r[i]:=r[j];
   r[j]:=z;
   z:=b[i];
   b[i]:=b[j];
   b[j]:=z;
   inc(I);dec(J);
  end;
 end;
if i<t then qsort(i,t);
if l<j then qsort(l,j);
end;

begin
 readln(n);
 for i:=1 to n do
 begin
  readln(x[i],r[i]);
  b[i]:=i;
 end;
 qsort(1,n);
 for i:=1 to n do
  ans[i]:=-1;
 res:=0;
 readln(m);
 for i:=1 to m do
 begin
  readln(q,w);
  l:=1;
  u:=n;
  while (l<u) do
  begin
   mid:=(l+u) shr 1;
   if (x[mid]+r[mid]<q) then l:=mid+1 else u:=mid;
  end;
  if (x[l]-r[l]>q) or (x[l]+r[l]<q) then continue;
  if (ans[b[l]] = -1) and (sqr(q-x[l])+SQR(w)<=sqr(r[l])) then
  begin
   inc(res);
   ans[b[l]] :=i;
  end;
  if l>1 then begin
   dec(l);
   if (ans[b[l]] = -1) and (sqr(q-x[l])+SQR(w)<=sqr(r[l])) then
  begin
   inc(res);
   ans[b[l]] :=i;
  end;
  inc(l);
 end;
 if l<n then
 begin
  inc(l);
  if (ans[b[l]] = -1) and (sqr(q-x[l])+SQR(w)<=sqr(r[l])) then
  begin
   inc(res);
   ans[b[l]] :=i;
  end;
 end;
end;
 writeln(res);
 for i:=1 to n-1 do
 write(ans[i],' ');
 writeln(ans[n]);
end.


{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  dd: boolean;
  sw,s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  word: array [0..110] of boolean;
  pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(word,sizeof(word),False);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    word[t]:=True;
  end;
  sw[1]:='';
  for i:=2 to n do sw[i]:=sw[pv[i]]+pc[i];
  dd:=True;
  while dd do
  begin
    dd:=False;
    for i:=1 to n do
      if word[i] then
        for j:=1 to n do
          if not word[j] then
            if length(sw[j]) > length(sw[i]) then
              if Copy(sw[j],length(sw[j])-length(sw[i])+1,length(sw[i])) = sw[i] then
              begin
                word[j]:=True;
                dd:=True;
              end;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if word[jj] and (de[jj] >= k+1) then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

"Multidimensional spaces are completely out of style these days, unlike genetics problems" — thought physicist Woll and changed his subject of study to bioinformatics. Analysing results of sequencing he faced the following problem concerning DNA sequences. We will further think of a DNA sequence as an arbitrary string of uppercase letters "A", "C", "G" and "T" (of course, this is a simplified interpretation).Let w be a long DNA sequence and s1,s2,...,sm — collection of short DNA sequences. Let us say that the collection filters w iff w can be covered with the sequences from the collection. Certainly, substrings corresponding to the different positions of the string may intersect or even cover each other. More formally: denote by |w| the length of w, let symbols of w be numbered from 1 to |w|. Then for each position i in w there exist pair of indices l,r (1≤l≤i≤r≤|w|) such that the substring w[l ... r] equals one of the elements s1,s2,...,sm of the collection.Woll wants to calculate the number of DNA sequences of a given length filtered by a given collection, but he doesn't know how to deal with it. Help him! Your task is to find the number of different DNA sequences of length n filtered by the collection {si}.Answer may appear very large, so output it modulo 1000000009.

First line contains two integer numbers n and m (1≤n≤1000,1≤m≤10) — the length of the string and the number of sequences in the collection correspondently.
Next m lines contain the collection sequences si, one per line. Each si is a nonempty string of length not greater than 10. All the strings consist of uppercase letters "A", "C", "G", "T". The collection may contain identical strings.

Output should contain a single integer — the number of strings filtered by the collection modulo 1000000009 (10^9+9).

In the first sample, a string has to be filtered by "A". Clearly, there is only one such string: "AA".
In the second sample, there exist exactly two different strings satisfying the condition (see the pictures below).

{$R+,S+,Q+,I+,O-}
{R-,S-,Q-,I-,O+}
const md = round(1e9+9);
      let: string = 'ACGT';
var
  ans,ii,jj,kk,max,km,nn,m,n,i,j,t,q,k: longint;
  dd: boolean;
  sw,s: array [0..110] of string;
  ss,st: string;
  a: array [0..110,'A'..'Z'] of longint;
  fn: array [0..110,0..110] of longint;
  maxw,pv,de,len: array [0..110] of longint;
  pc: array [0..110] of char;
  f: array [0..1010,0..110,0..11] of longint;
begin
//  assign(input,'in'); reset(input);
//  assign(output,'out'); rewrite(output);
  readln(nn,m);
  fillchar(a,sizeof(a),0);
  fillchar(maxw,sizeof(maxw),0);
  n:=1;
  de[1]:=0;
  for i:=1 to m do
  begin
    readln(s[i]);
    len[i]:=length(s[i]);
    t:=1;
    for j:=1 to len[i] do
    begin
      if a[t,s[i,j]] = 0 then
      begin
        inc(n);
        pv[n]:=t;
        pc[n]:=s[i,j];
        de[n]:=de[t]+1;
        a[t,s[i,j]]:=n;
      end;
      t:=a[t,s[i,j]];
    end;
    maxw[t]:=len[i];
  end;
  sw[1]:='';
  for i:=2 to n do sw[i]:=sw[pv[i]]+pc[i];
  dd:=True;
  while dd do
  begin
    dd:=False;
    for i:=1 to n do
      if maxw[i] > 0 then
        for j:=1 to n do
          if length(sw[j]) > length(sw[i]) then
            if Copy(sw[j],length(sw[j])-length(sw[i])+1,length(sw[i])) = sw[i] then
              if maxw[i] > maxw[j] then
              begin
                maxw[j]:=maxw[i];
                dd:=True;
              end;
  end;
  for i:=1 to n do
    for q:=1 to 4 do
    begin
      st:='';
      t:=i;
      while t > 1 do
      begin
        st:=pc[t]+st;
        t:=pv[t];
      end;
      st:=st+let[q];
      max:=0; km:=1;
      for ii:=2 to n do
      begin
        ss:=''; t:=ii;
        while t > 1 do
        begin
          ss:=pc[t]+ss;
          t:=pv[t];
        end;
        if length(ss) > length(st) then continue;
        if Copy(st,length(st)-length(ss)+1,length(ss)) = ss then
          if length(ss) > max then
          begin
            max:=length(ss);
            km:=ii;
          end;
      end;
      fn[i,q]:=km;
    end;
  fillchar(f,sizeof(f),0);
  f[0,1,0]:=1;
  for i:=0 to nn-1 do
    for j:=1 to n do
      for k:=0 to de[j] do
        if f[i,j,k] > 0 then
          for q:=1 to 4 do
          begin
            ii:=i+1;
            jj:=fn[j,q];
            kk:=k+1;
            if maxw[jj] >= k+1 then kk:=0;
            inc(f[ii,jj,kk],f[i,j,k]);
            if f[ii,jj,kk] >= md then dec(f[ii,jj,kk],md);
          end;
  ans:=0;
  for i:=1 to n do ans:=(ans+f[nn,i,0]) mod md;
  writeln(ans);
  close(input);
  close(output);
end.

[{'input': ['2 1\r\nA\r\n'], 'output': ['1\r\n']}, {'input': ['6 2\r\nCAT\r\nTACT\r\n'], 'output': ['2\r\n']}, {'input': ['8 2\r\nAGCT\r\nAGC\r\n'], 'output': ['1\r\n']}, {'input': ['12 1\r\nACC\r\n'], 'output': ['1\r\n']}, {'input': ['13 1\r\nACC\r\n'], 'output': ['0\r\n']}, {'input': ['20 1\r\nACA\r\n'], 'output': ['49\r\n']}, {'input': ['5 6\r\nCGTTGAA\r\nATTATGAACC\r\nTTA\r\nTCAG\r\nCCGAGG\r\nT\r\n'], 'output': ['6\r\n']}, {'input': ['5 4\r\nA\r\nC\r\nG\r\nT\r\n'], 'output': ['1024\r\n']}, {'input': ['4 5\r\nCTA\r\nA\r\nCA\r\nACAG\r\nACC\r\n'], 'output': ['11\r\n']}, {'input': ['4 5\r\nCTA\r\nA\r\nCA\r\nACC\r\nTCT\r\n'], 'output': ['12\r\n']}, {'input': ['4 4\r\nTCT\r\nCTA\r\nA\r\nCA\r\n'], 'output': ['9\r\n']}, {'input': ['1000 3\r\nAT\r\nTTT\r\nGTA\r\n'], 'output': ['354668080\r\n']}, {'input': ['13 3\r\nTCA\r\nAGTC\r\nGTT\r\n'], 'output': ['94\r\n']}, {'input': ['1000 10\r\nATTTTTTTTT\r\nAGGGGGGGGG\r\nACCCCCCCCC\r\nTGGGGGGGGG\r\nTAAAAAAAAA\r\nTCCCCCCCCC\r\nGCCCCCCCCC\r\nGTTTTTTTTT\r\nCAAAAAAAAA\r\nCGGGGGGGGG\r\n'], 'output': ['824781477\r\n']}, {'input': ['10 10\r\nAGA\r\nAT\r\nTAG\r\nGAG\r\nAT\r\nCAT\r\nTAT\r\nTACT\r\nGAT\r\nCAT\r\n'], 'output': ['1087\r\n']}, {'input': ['10 10\r\nAT\r\nTACT\r\nTAT\r\nTAT\r\nGAG\r\nAT\r\nGAT\r\nCAT\r\nTAG\r\nCAT\r\n'], 'output': ['661\r\n']}, {'input': ['10 10\r\nTAG\r\nACT\r\nCAT\r\nACT\r\nGAT\r\nGAG\r\nACT\r\nAGA\r\nAT\r\nGAG\r\n'], 'output': ['894\r\n']}, {'input': ['10 10\r\nAT\r\nTA\r\nTAT\r\nCAT\r\nGAT\r\nCAT\r\nTAG\r\nTAG\r\nTACT\r\nAT\r\n'], 'output': ['1074\r\n']}, {'input': ['10 10\r\nAT\r\nCAT\r\nTAT\r\nGAG\r\nAT\r\nTAT\r\nGAGA\r\nTACT\r\nAT\r\nGAT\r\n'], 'output': ['282\r\n']}, {'input': ['10 10\r\nACT\r\nAT\r\nTACT\r\nGAGA\r\nCAT\r\nAGA\r\nGAT\r\nTA\r\nAT\r\nTA\r\n'], 'output': ['1860\r\n']}, {'input': ['100 10\r\nTAT\r\nAGA\r\nAGA\r\nTAT\r\nCAT\r\nTAG\r\nAT\r\nCAT\r\nTACT\r\nTA\r\n'], 'output': ['219832230\r\n']}, {'input': ['100 10\r\nTACT\r\nTAT\r\nCAT\r\nTA\r\nTACT\r\nGAGA\r\nGAGA\r\nAGA\r\nTAT\r\nTAT\r\n'], 'output': ['821129594\r\n']}, {'input': ['100 10\r\nTACT\r\nACT\r\nTAT\r\nAGA\r\nTA\r\nTACT\r\nGAGA\r\nAT\r\nTAG\r\nGAG\r\n'], 'output': ['951249461\r\n']}, {'input': ['100 10\r\nGAGA\r\nACT\r\nTAG\r\nGAT\r\nTACT\r\nGAGA\r\nTAT\r\nTAT\r\nTAT\r\nACT\r\n'], 'output': ['918741384\r\n']}, {'input': ['100 10\r\nAGA\r\nTACT\r\nAGA\r\nGAG\r\nTAT\r\nCAT\r\nGAT\r\nTAT\r\nCAT\r\nCAT\r\n'], 'output': ['510782351\r\n']}, {'input': ['1000 10\r\nACT\r\nTAT\r\nTAG\r\nCAT\r\nGAGA\r\nAT\r\nGAGA\r\nTAG\r\nTA\r\nGAG\r\n'], 'output': ['496495637\r\n']}, {'input': ['1000 10\r\nTAG\r\nCAT\r\nAGA\r\nTACT\r\nCAT\r\nACT\r\nGAG\r\nGAT\r\nACT\r\nTAT\r\n'], 'output': ['431753919\r\n']}, {'input': ['1000 10\r\nGAGA\r\nGAGA\r\nGAGA\r\nTA\r\nGAG\r\nGAGA\r\nAGA\r\nTA\r\nTAT\r\nTAT\r\n'], 'output': ['249066354\r\n']}, {'input': ['1000 10\r\nTAT\r\nTAT\r\nCAT\r\nAT\r\nTA\r\nGAGA\r\nTACT\r\nAT\r\nTAT\r\nGAT\r\n'], 'output': ['676775\r\n']}, {'input': ['1000 10\r\nTA\r\nTAG\r\nTA\r\nACT\r\nTAT\r\nCAT\r\nTACT\r\nGAGA\r\nTA\r\nACT\r\n'], 'output': ['326183001\r\n']}, {'input': ['10 5\r\nAGT\r\nGTT\r\nA\r\nCCCC\r\nA\r\n'], 'output': ['234\r\n']}, {'input': ['6 5\r\nGGG\r\nAA\r\nA\r\nAGCT\r\nAGC\r\n'], 'output': ['21\r\n']}, {'input': ['6 7\r\nCGTTGAA\r\nATTATGAACC\r\nTTA\r\nTCAG\r\nCCGAGG\r\nT\r\nT\r\n'], 'output': ['10\r\n']}, {'input': ['9 8\r\nTACTACGCA\r\nA\r\nACAAT\r\nGCCCGA\r\nTA\r\nCATG\r\nTTAAC\r\nCTGG\r\n'], 'output': ['220\r\n']}, {'input': ['6 8\r\nCTAAATTCT\r\nCACACA\r\nGACCC\r\nG\r\nCGTCT\r\nTG\r\nGCAA\r\nAGT\r\n'], 'output': ['38\r\n']}, {'input': ['5 5\r\nATTATGAACC\r\nTTA\r\nTCAG\r\nCCGAGG\r\nT\r\n'], 'output': ['6\r\n']}, {'input': ['1000 5\r\nACGTAC\r\nTACTAG\r\nAGACGT\r\nCGTAGA\r\nGTAGAT\r\n'], 'output': ['168020674\r\n']}, {'input': ['312 7\r\nCCA\r\nCACTGATTTT\r\nTAGATGAAT\r\nG\r\nGATAAAC\r\nCCAACCG\r\nCCCCAGTGG\r\n'], 'output': ['673272460\r\n']}, {'input': ['356 6\r\nGG\r\nCG\r\nACAAT\r\nAAG\r\nGGCTCAC\r\nC\r\n'], 'output': ['109620326\r\n']}, {'input': ['524 1\r\nCCAGCCTG\r\n'], 'output': ['0\r\n']}, {'input': ['86 9\r\nGTTG\r\nCCAGC\r\nGTACTGAG\r\nGACCCACGCA\r\nTGCGGTGCT\r\nA\r\nA\r\nGTGG\r\nCCTATAC\r\n'], 'output': ['139639918\r\n']}, {'input': ['408 8\r\nAAAGGTGGCT\r\nG\r\nG\r\nGGAG\r\nCATACT\r\nCAACACCCGG\r\nCCT\r\nATTACT\r\n'], 'output': ['471214946\r\n']}, {'input': ['859 9\r\nCAAGAAG\r\nGCCGAGTA\r\nAAACTTTGGG\r\nTC\r\nAACGGAG\r\nC\r\nAT\r\nCGAATT\r\nGGTA\r\n'], 'output': ['376160458\r\n']}, {'input': ['787 3\r\nGGGGATTTG\r\nAGAT\r\nCGGTAC\r\n'], 'output': ['646775261\r\n']}, {'input': ['596 2\r\nGCC\r\nCTC\r\n'], 'output': ['141314270\r\n']}, {'input': ['889 8\r\nGGGGATCT\r\nCACTGTT\r\nTGCCA\r\nGCGCTTCAT\r\nTCGCAAGATT\r\nTCG\r\nGTAGCATTTG\r\nTAGGCACAC\r\n'], 'output': ['330530182\r\n']}, {'input': ['388 4\r\nCGCCA\r\nCTAATCA\r\nCAGTTTGC\r\nCTAATG\r\n'], 'output': ['128236388\r\n']}, {'input': ['898 5\r\nAAAGT\r\nCTCAAGT\r\nGTCGGAGAGT\r\nAT\r\nCGGAGGGCAT\r\n'], 'output': ['293748514\r\n']}, {'input': ['881 5\r\nGTAC\r\nTACAAT\r\nAATGTGCTC\r\nGCAAT\r\nCT\r\n'], 'output': ['876433412\r\n']}, {'input': ['135 10\r\nCTTATGAAA\r\nTATGA\r\nAGCTC\r\nG\r\nTTTTCT\r\nAC\r\nTTTGTGA\r\nC\r\nTCATAGCTT\r\nC\r\n'], 'output': ['380808214\r\n']}, {'input': ['985 10\r\nAACACCCCCC\r\nACCAAACAAA\r\nACCCAAAAAC\r\nCAACACCACA\r\nAAAAACACAA\r\nCACCAACCAC\r\nAAAAAAAAAC\r\nCCCCAAAACC\r\nCACCCACCCA\r\nCAACACAACC\r\n'], 'output': ['95876385\r\n']}, {'input': ['952 10\r\nCCACAAACCC\r\nCAAAACCACA\r\nACAACAACCC\r\nAAAAAACCAC\r\nCACAACACAC\r\nCCCCACACCC\r\nCACCAACAAC\r\nACACCAAACA\r\nACCACCAACC\r\nCCCACCACCC\r\n'], 'output': ['581293618\r\n']}, {'input': ['910 10\r\nACACAAAACA\r\nAACACACCAC\r\nCCCCAACCAA\r\nAACACCAACA\r\nCCCCCACCAA\r\nAAACACCCAC\r\nACCCAACAAC\r\nCCCCACAAAC\r\nACCCCAAAAA\r\nACAAACACCC\r\n'], 'output': ['124152999\r\n']}, {'input': ['953 10\r\nACCCCACACA\r\nCAAAAAAAAA\r\nAAACACCAAA\r\nCAAACACAAC\r\nAAAACCCAAC\r\nCCCACAACCC\r\nCAACCAACCC\r\nCACAAACCAC\r\nCCACAAAACA\r\nACACCAAAAA\r\n'], 'output': ['359848089\r\n']}, {'input': ['820 10\r\nACCCCCAACA\r\nAACACACCAC\r\nCACAAACCAA\r\nCCAACACACC\r\nACAAAAAACC\r\nCAAACCAACC\r\nCACCAAACCA\r\nAACACAACCC\r\nACCAACACCA\r\nAACCCCCCCA\r\n'], 'output': ['625282992\r\n']}, {'input': ['801 10\r\nCCCCCCACCA\r\nACACAACAAA\r\nCCCCCCCAAA\r\nCCAAACCCCC\r\nCACAAACAAA\r\nCAAAAACCCC\r\nCCAACACCAA\r\nACAAACCAAA\r\nCAAACCACCA\r\nCAACCACAAC\r\n'], 'output': ['156320838\r\n']}, {'input': ['983 10\r\nCACAAAACAC\r\nCAAACACAAA\r\nCACCCAACAA\r\nACACCAACAC\r\nAACAACCCAC\r\nAACCACCACC\r\nACACACCAAA\r\nACAAAAACAA\r\nACACACCCAA\r\nCCACCCAACA\r\n'], 'output': ['4558945\r\n']}, {'input': ['969 10\r\nCACAACCAAC\r\nCCACCACCCA\r\nAAAACCCCCA\r\nCCCAAACCCA\r\nCCACAACCCA\r\nCCACCACAAC\r\nCACACCCACC\r\nCCACCCCCCC\r\nCAACAACCAA\r\nCACACCAACC\r\n'], 'output': ['611933333\r\n']}, {'input': ['843 10\r\nAACCCCCCCC\r\nCCAAAAAACC\r\nACACACCCCC\r\nCCACCAACCC\r\nCCAACCACCC\r\nCAAACCCAAA\r\nCAACACACCA\r\nCAACCCCACA\r\nAAACCCAACC\r\nCCACCCAACA\r\n'], 'output': ['812395062\r\n']}, {'input': ['905 10\r\nCCAAACCCAA\r\nACACACAAAA\r\nCCACCAACCC\r\nCAACACACAC\r\nCCACCAAAAA\r\nACACCACAAC\r\nCACAAAAAAC\r\nAACACCCCCA\r\nCAACCACCAA\r\nCCCAAAAACA\r\n'], 'output': ['544200998\r\n']}, {'input': ['1000 10\r\nACCCC\r\nACACC\r\nACCC\r\nAACC\r\nACCA\r\nAAAAC\r\nACCA\r\nCACC\r\nAAAA\r\nCACCA\r\n'], 'output': ['924594454\r\n']}, {'input': ['1000 10\r\nCCCCA\r\nCACAA\r\nACCC\r\nCCCAA\r\nCAAC\r\nCCCAA\r\nAAACC\r\nCCCC\r\nACAAA\r\nCCCCC\r\n'], 'output': ['43313937\r\n']}, {'input': ['1000 10\r\nCACA\r\nACCC\r\nCCAA\r\nACCCA\r\nACCCC\r\nACCC\r\nCCCC\r\nCCCA\r\nCCAC\r\nACAAA\r\n'], 'output': ['60965086\r\n']}, {'input': ['1000 10\r\nCACAA\r\nAAAAC\r\nACAAC\r\nACAA\r\nAAACA\r\nCACC\r\nCCCCA\r\nCACCC\r\nCCAA\r\nCAAA\r\n'], 'output': ['230123998\r\n']}, {'input': ['1000 10\r\nCAAA\r\nACCCA\r\nACACA\r\nACAC\r\nCAAA\r\nCAAA\r\nAAAA\r\nCCAAC\r\nAAAAA\r\nCCCA\r\n'], 'output': ['703792925\r\n']}, {'input': ['1000 10\r\nACAC\r\nCCCAA\r\nAACAA\r\nCCCA\r\nACACA\r\nACCA\r\nCAAC\r\nAACC\r\nCCCC\r\nACAC\r\n'], 'output': ['175815825\r\n']}, {'input': ['1000 10\r\nCAAAC\r\nAACC\r\nCAACA\r\nCCAAA\r\nACAC\r\nACAAA\r\nCCCAC\r\nACCC\r\nACCAC\r\nAACC\r\n'], 'output': ['879274869\r\n']}, {'input': ['1000 10\r\nACAC\r\nACAA\r\nACCAA\r\nACCC\r\nAAAA\r\nACCCC\r\nAAAC\r\nCCCAC\r\nCACA\r\nAAAA\r\n'], 'output': ['702626026\r\n']}, {'input': ['1000 10\r\nTTTT\r\nGTTGT\r\nGTGT\r\nGGGGT\r\nGGTG\r\nTGTG\r\nTTTGT\r\nTTTTG\r\nGTGTG\r\nGTTTT\r\n'], 'output': ['703149174\r\n']}, {'input': ['1000 10\r\nTGTG\r\nTGTGG\r\nGTTTG\r\nGTGG\r\nGTTGG\r\nTTGG\r\nGTGTT\r\nGGGT\r\nGTTG\r\nTGTG\r\n'], 'output': ['675696965\r\n']}, {'input': ['1000 5\r\nGTTT\r\nTGTGG\r\nTGTT\r\nGGGG\r\nTGTGG\r\n'], 'output': ['976604240\r\n']}, {'input': ['1000 8\r\nTTGG\r\nGTTT\r\nGGGG\r\nGTTTT\r\nGTGGT\r\nTGTG\r\nGGTG\r\nGGTGG\r\n'], 'output': ['284150940\r\n']}, {'input': ['1000 3\r\nTTGTT\r\nTGTG\r\nGGTG\r\n'], 'output': ['401641816\r\n']}, {'input': ['1000 6\r\nTTGT\r\nTGGTT\r\nGGTT\r\nGGTGG\r\nTGTT\r\nGGGG\r\n'], 'output': ['904765495\r\n']}, {'input': ['1000 5\r\nTGTG\r\nTTTGG\r\nTGGG\r\nTTGGG\r\nGGGT\r\n'], 'output': ['829495151\r\n']}, {'input': ['1000 10\r\nTTATTGACCG\r\nACCACTAGCG\r\nGACCGGGTCC\r\nGTTCACAGAG\r\nCAAACCACCT\r\nTGCCCGCAAC\r\nAGAACCGGGG\r\nACCCCGGTGT\r\nAGACTTGCAT\r\nGAGAGCCCAC\r\n'], 'output': ['303961596\r\n']}, {'input': ['1000 10\r\nGATTCCACAA\r\nTCGCAATGTT\r\nTGATGTCCAA\r\nTCGCTTCTTG\r\nCAGAGACGGA\r\nGGTGCCCTGG\r\nCCAGTCCTTA\r\nTTCCTTATCT\r\nTCACGCACAT\r\nACGACATCTA\r\n'], 'output': ['759680724\r\n']}, {'input': ['1000 10\r\nTATGTTATGT\r\nGTTACATTAA\r\nTCATTGCTAC\r\nGCCTCTGACA\r\nGATATATCCA\r\nTTGGGCTTTA\r\nCTGTCTAGGA\r\nTCAGCAGTTC\r\nCAGCTTTAAA\r\nTCTCATATGG\r\n'], 'output': ['247515990\r\n']}, {'input': ['1000 10\r\nCACAAGTCCG\r\nTCAAATTGTT\r\nATTAAGTACT\r\nCTAAGGCGCC\r\nAGAAGGGTTG\r\nATGGTCCGAA\r\nTTCGCGCGAT\r\nGGGCGCGCCA\r\nAAAACGAGAT\r\nTGAATTCGAC\r\n'], 'output': ['23954923\r\n']}, {'input': ['1000 10\r\nAGTACTTTTA\r\nTAATTGTGAC\r\nCCAAGGCATA\r\nCGCGACTACC\r\nCCGCTGCTTT\r\nGCCCAACGAC\r\nGGCGTAGTGG\r\nGGCCGTCGAC\r\nTCCACGATGT\r\nTAATTTTCAT\r\n'], 'output': ['591782113\r\n']}, {'input': ['1000 10\r\nCAGTAGTGGA\r\nTATCGACTAC\r\nCCACTGCGCT\r\nCCTGCGCTCC\r\nTCGTCTATGG\r\nAGTTAAAGCT\r\nTACGACCTAT\r\nGTAGGTTTAC\r\nCTAAGGATTT\r\nCTCTACAATA\r\n'], 'output': ['819181392\r\n']}, {'input': ['1000 10\r\nCCCAGGAGGC\r\nTGCGAACTGG\r\nAGACATACGG\r\nATCTCTTTTG\r\nGCGGAGTCCT\r\nCTTGTGCCGC\r\nCGTCATCTTC\r\nTATGCACAAA\r\nTACATGGCTA\r\nATATCCAAGG\r\n'], 'output': ['681627776\r\n']}, {'input': ['1000 10\r\nATCCAGTTCG\r\nGCCGACTTAG\r\nATTGAAGATT\r\nGTAAAATCCC\r\nTTTACCGGTA\r\nGGATCCTTAG\r\nCCGAGGAAGC\r\nAAATACAACT\r\nAGGAGGCCTA\r\nCGTTCCGCCA\r\n'], 'output': ['71903271\r\n']}, {'input': ['1000 10\r\nCGCGAGGCGC\r\nGAACCTACTC\r\nGGAAGGCCTC\r\nCGAGTCTTTT\r\nCTAGCAGATT\r\nTCAATTGGCC\r\nGGGTAGGTTA\r\nAGGTGCCGCG\r\nCGAATAATTG\r\nTAACTCATGC\r\n'], 'output': ['57916175\r\n']}, {'input': ['1000 10\r\nCCACGTCTTG\r\nTGTCGTGAAC\r\nCCGGGTACAA\r\nACCCGGGGAA\r\nTTCTGTTACT\r\nCTTGAACGAA\r\nACGTCTACTA\r\nAATGAGATGC\r\nCGCAGACCGC\r\nCTCGGTACTT\r\n'], 'output': ['700310600\r\n']}, {'input': ['724 5\r\nGTCTTT\r\nTGGTGTC\r\nCTGCGGG\r\nTGGGGTC\r\nGGGG\r\n'], 'output': ['88397587\r\n']}, {'input': ['675 10\r\nCTTCGCT\r\nCTCG\r\nTGGGTC\r\nCCGTTT\r\nTCCG\r\nGCG\r\nCCCGCT\r\nCCGTT\r\nTTTGCG\r\nTCGC\r\n'], 'output': ['221693941\r\n']}, {'input': ['891 2\r\nCGTCTG\r\nCGGCCG\r\n'], 'output': ['0\r\n']}, {'input': ['574 3\r\nGCTGG\r\nTCGGTGC\r\nGTG\r\n'], 'output': ['917296112\r\n']}, {'input': ['856 8\r\nGGG\r\nCTG\r\nGCTCCTT\r\nGCTCCTG\r\nCGTTCC\r\nGTGTT\r\nCTG\r\nCGGT\r\n'], 'output': ['266655823\r\n']}, {'input': ['749 4\r\nCGGGTGC\r\nGTTTG\r\nGTGTTGT\r\nGCTC\r\n'], 'output': ['146534805\r\n']}, {'input': ['763 9\r\nCGTTT\r\nGGTC\r\nGTTTCGG\r\nCGCCC\r\nCGGCCGT\r\nCCTCTG\r\nTCC\r\nTTCTC\r\nCCGTGC\r\n'], 'output': ['38493212\r\n']}, {'input': ['995 10\r\nGGGCC\r\nTTCCT\r\nCGGTGT\r\nGGCCC\r\nTTGTGG\r\nTTCG\r\nTTTCGGG\r\nTGC\r\nTTTC\r\nTTT\r\n'], 'output': ['458545678\r\n']}, {'input': ['707 2\r\nGGTTGGC\r\nTCTTTTG\r\n'], 'output': ['536680786\r\n']}, {'input': ['867 4\r\nTCGTT\r\nCTG\r\nCCG\r\nGCGT\r\n'], 'output': ['611141739\r\n']}]


{ uses crt;}
   const nn=500; eps=0.000000000001;  besk=1e+10;
   label 1,2;
    type {longint=int64;}   real=double;
    mas=array [0..nn] of longint;   point=record x,y,z:real;end;
        trip=record mx,my,m:real;end;   trip1=^trip;
    coor=record i,j :longint;end; coor1=^coor;
    mass=array[0..nn] of longint;mass1=^mass;
    var ii,mmin,mn,l1,l2,jj,n,k,p,imin,m,s,r,g,b,i1,j1,h,iimax,p1:longint;
    s1,s2:longint;
     v0,v1,s0,t0,t1,t2:real;  mina:array[0..nn] of point;
     minr :array[0..nn] of real; minaship:array[0..nn,0..10] of point;
     zv:point; ppp,vb,aa,bb,vzv:point; ot,t,rzv:real;
     cc:char;  kol:mas;
     a:array[0..nn,0..nn] of char;

     i,j:longint;
      voz,ub:boolean;
      ss:string;
       flag,flag1:boolean; gvx,gvy,rr:real; sss:array[0..3] of real;
    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:real):real;begin min:=x;if y<x then min:=y; end;
  function max(x,y:longint):longint;begin max:=x;if y>x then max:=y; end;

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

  function tper(a,b,vb:point;rad:real):real;  label 23;
  var i,j,k:longint; sinn,l1,l2,ch,zn,coss,t,t1,r1:real; c:point;

  begin
    c.x:=a.x-b.x; c.y:=a.y-b.y;c.z:=a.z-b.z;
   ch:=c.x*vb.x+ c.y*vb.y+c.z*vb.z;
   l1:=sqrt(c.x*c.x+c.y*c.y+c.z*c.z);l2:=sqrt(vb.x*vb.x+vb.y*vb.y+vb.z*vb.z);
   zn:=l1*l2;
   coss:=ch/zn; if coss<=0 then begin tper:=besk; goto 23;    end;
   {writeln(coss:0:5);}  sinn:=sqrt(1-coss*coss);
   r1:=l1*sinn;  if r1>rad then begin tper:=besk; goto 23;  end;
   t1:=(l1*coss-sqrt(rad*rad-r1*r1))/l2;
   tper:=t1;

23:
  end;

     begin   { clrscr;
     assign(input,'input.txt');        reset (input); }
   {  assign(output,'output.txt');        rewrite (output); }
    readln(zv.x,zv.y,zv.z,vzv.x,vzv.y,vzv.z,rzv);
    read(n);
    for i:=1 to n do
     begin
        read(mina[i].x,mina[i].y,mina[i].z,minr[i],kol[i]);
        for j:=1 to kol[i] do read (minaship[i,j].x,minaship[i,j].y,minaship[i,j].z);

     end;
   {  aa.x:=5;aa.y:=4;bb.x:=-3;bb.y:=4;vb.x:=8;vb.y:=-6;
     t:=tper(aa,bb,vb,5);
     writeln('tt=  ',t:0:7); }  ot:=besk;
   for i:=1 to n do
     begin
        ot:=min(ot,tper(mina[i],zv,vzv,minr[i]+rzv+eps));
       { writeln(i,' ',ot); }
        for j:=1 to kol[i] do
         begin
          ppp.x:=mina[i].x+minaship[i,j].x;
          ppp.z:=mina[i].z+minaship[i,j].z;
          ppp.y:=mina[i].y+minaship[i,j].y;
         { writeln(i,' ',j,' ',tper(ppp,zv,vzv,rzv+eps)) ;
         } ot:=min(ot,tper(ppp,zv,vzv,rzv+eps));
         end;

     end;

  if ot<besk-20000000 then writeln(ot:0:6)else write(-1);

 close (output);

           end.

Once upon a time in the galaxy of far, far away...Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — space mines. Let's describe a space mine's build.Each space mine is shaped like a ball (we'll call it the mine body) of a certain radius r with the center in the point O. Several spikes protrude from the center. Each spike can be represented as a segment, connecting the center of the mine with some point P, such that  (transporting long-spiked mines is problematic), where |OP| is the length of the segment connecting O and P. It is convenient to describe the point P by a vector p such that P=O+p.The Death Star is shaped like a ball with the radius of R (R exceeds any mine's radius). It moves at a constant speed along the v vector at the speed equal to |v|. At the moment the rebels noticed the Star of Death, it was located in the point A.The rebels located n space mines along the Death Star's way. You may regard the mines as being idle. The Death Star does not know about the mines' existence and cannot notice them, which is why it doesn't change the direction of its movement. As soon as the Star of Death touched the mine (its body or one of the spikes), the mine bursts and destroys the Star of Death. A touching is the situation when there is a point in space which belongs both to the mine and to the Death Star. It is considered that Death Star will not be destroyed if it can move infinitely long time without touching the mines.Help the rebels determine whether they will succeed in destroying the Death Star using space mines or not. If they will succeed, determine the moment of time when it will happen (starting from the moment the Death Star was noticed).

The first input data line contains 7 integers Ax,Ay,Az,vx,vy,vz,R. They are the Death Star's initial position, the direction of its movement, and its radius (-10≤vx,vy,vz≤10, |v|>0, 0<R≤100).
The second line contains an integer n, which is the number of mines (1≤n≤100). Then follow n data blocks, the i-th of them describes the i-th mine.
The first line of each block contains 5 integers Oix,Oiy,Oiz,ri,mi, which are the coordinates of the mine centre, the radius of its body and the number of spikes (0<ri<100,0≤mi≤10). Then follow mi lines, describing the spikes of the i-th mine, where the j-th of them describes the i-th spike and contains 3 integers pijx,pijy,pijz — the coordinates of the vector where the given spike is directed ().
The coordinates of the mines' centers and the center of the Death Star are integers, their absolute value does not exceed 10000. It is guaranteed that R>ri for any 1≤i≤n. For any mines i≠j the following inequality if fulfilled: . Initially the Death Star and the mines do not have common points.

If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast.
If the Death Star will not touch a mine, print "-1" (without quotes).
For the answer the absolute or relative error of 10^-6 is acceptable.

{$apptype console}
{$R+,S+,I+,Q+}
const
     inf = 'input.txt';
     outf = 'output.txt';
var
 i,j,n,m:longint;
 ax,ay,az,vx,vy,vz,rz,ox,oy,oz,rm,px,py,pz,a,b,c,d,t,ans:extended;

 procedure check(x,y,z,r:extended);
  begin
   x:=ax-x;
   y:=ay-y;
   z:=az-z;
   c:=x*x+y*y+z*z-r*r;
   a:=vx*vx+vy*vy+vz*vz;
   b:=2*vx*x+2*vy*y+2*vz*z;
   d:=b*b-4*a*c;
   if d < 0 then exit;
   t:=(-b+sqrt(d))/(2*a);
   if t > 0 then
    if t < ans then ans:=t;
   t:=(-b-sqrt(d))/(2*a);
   if t > 0 then
    if t < ans then ans:=t;
  end;

begin
 //reset(input,inf);
 //rewrite(output,outf);
 read(ax,ay,az,vx,vy,vz,rz,n);
 ans:=1e18;
 for i:=1 to n do
  begin
   read(ox,oy,oz,rm,m);
   check(ox,oy,oz,rm+rz);
   for j:=1 to m do
    begin
     read(px,py,pz);
     px:=ox+px;
     py:=oy+py;
     pz:=oz+pz;
     check(px,py,pz,rz);
    end;
  end;
 if ans >= 1e18 then writeln(-1) else writeln(ans:0:10);
end.


import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.text.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.zip.GZIPInputStream;

import javax.imageio.ImageIO;

public class Main {
	public static void main(String args[]) throws IOException {
		Scanner s = new Scanner(System.in);

		String[] cpt = s.nextLine().split(" ");
		int n = Integer.parseInt(cpt[0]);

		String dom = s.nextLine();
		int total = 0;

		char wait = '0';
		int interval = 0;
		for (char c : dom.toCharArray()) {
			if (c == '.') {
				interval++;
			} else if (wait == '0' && c == 'R') {
				total += interval;
				wait = 'L';
				interval = 0;
			} else if (c == 'R') {
				if (wait == '0') {
					total += interval;
				}
				interval = 0;
				wait = 'L';
			} else if (c == 'L') {
				if (wait != '0') {
					total += interval % 2;
					wait = 'R';
				}
				interval = 0;
			}
		}

		if (wait != 'L') {
			total += interval;
		}

		System.out.println(total);
	}
}

Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.  Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to    "L", if the i-th domino has been pushed to the left;  "R", if the i-th domino has been pushed to the right;  ".", if the i-th domino has not been pushed.  It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

NoteThe first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.In the second example case, all pieces fall down since the first piece topples all the other pieces.In the last example case, a single piece has not been pushed in either direction.

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int size = Integer.parseInt(scanner.nextLine());
        String input = scanner.nextLine();

        boolean lastLeft = true;
        int numStanding = 0;
        int counter = 0;

        for (int i = 0; i < input.length(); i++) {
            switch (input.charAt(i)) {
                case 'L':
                    // Special case cause starts with left
                    if (!lastLeft) {
                        numStanding += (counter%2); // Add one if odd
                    }
                    counter = 0;
                    lastLeft = true;
                    break;
                case 'R':
                    numStanding += counter;
                    counter = 0;
                    lastLeft = false;
                    break;
                case '.':
                    counter++;
                    break;
                default:
            }
        }

        if (lastLeft) {
            numStanding += counter;
        }

        System.out.println(numStanding);
    }
}


In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α1 and α2 to the OX axis. Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α1 and α2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.  As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.Your task is to find the maximum number of stars m that the Donkey's chain can contain.Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.

The first line contains an integer n (1≤n≤10^5) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that  and  (0≤a,b,c,d≤10^5; ; ; ). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers xi, yi (1≤xi,yi≤10^5)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.

In a single line print number m — the answer to the problem.

In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.

import sys
readline=sys.stdin.readline
import bisect

def LIS(lst,weakly=False,inf=float('inf'),restoration=False):
    f=bisect.bisect_right if weakly else bisect.bisect_left
    N=len(lst)
    update=[None]*N
    dp=[inf]*N
    for k,x in enumerate(lst):
        i=f(dp,x)
        dp[i]=x
        update[k]=(i,dp[i])
    len_lis=bisect.bisect_left(dp,inf)
    if restoration:
        lis=[None]*len_lis
        len_lis-=1
        for i,x in update[::-1]:
            if i==len_lis:
                lis[len_lis]=x
                len_lis-=1
        return lis
    else:
        return len_lis

N=int(readline())
ab,cd=readline().split()
a,b=map(int,ab.split("/"))
c,d=map(int,cd.split("/"))
points=[]
for _ in range(N):
    x,y=map(int,readline().split())
    x,y=b*y-a*x,c*x-d*y
    if x>=0 and y>=0:
        points.append((x,y))
points.sort(key=lambda tpl:(tpl[0],-tpl[1]))
inf=1<<35
ans=LIS([y for x,y in points],inf=inf)
print(ans)


num = gets.chomp

num_of_four = 0
num_of_seven = 0
ans_num = ""
len = num.length

def get_bigger len
  ans_num = "4"
  append_times = len / 2
  append_times.times { ans_num << "4" }
  append_times.times { ans_num << "7" }
  ans_num << "7"
end

def get_rest(ans_num, len, num_of_four, num_of_seven)
  rest_four = len / 2 - num_of_four
  rest_seven = len / 2 - num_of_seven
  rest_four.times { ans_num << "4" }
  rest_seven.times { ans_num << "7" }
  return ans_num
end

if num[0] > "7" || len % 2 == 1
  ans_num = ans_num << (get_bigger len)

else
  index = len
  for i in 0...len
    if num[i] == "4" #many 4
      num_of_four = num_of_four + 1
      if num_of_four > len / 2
        num_of_four = num_of_four - 1
        index = i
        break
      end

    elsif num[i] == "7" #many 7
      num_of_seven = num_of_seven + 1
      if num_of_seven > len / 2
        num_of_seven = num_of_seven - 1
        index = i
        break
      end

    else
      index = i
      break
    end
  end

  if index == len
    ans_num = num
  elsif num[index] <= "4"
    ans_num = ans_num << num[0...index]
    ans_num = get_rest ans_num, len, num_of_four, num_of_seven

  elsif num[index] < "7"
    ans_num = ans_num << num[0...index]
    ans_num << "7"
    num_of_seven = num_of_seven + 1
    ans_num = get_rest ans_num, len, num_of_four, num_of_seven
  else
    index = index - 1
    while index >= 0
      break if num[index] == "4"
      num_of_seven = num_of_seven - 1
    end
    if index == -1
      ans_num = get_bigger len
    else
      ans_num = ans_num << num[0...index]
      ans_num << "7"
      num_of_four = num_of_four - 1
      num_of_seven = num_of_seven + 1
      ans_num = get_rest ans_num, len, num_of_four, num_of_seven
    end
  end
end

puts ans_num

Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.

Output the least super lucky number that is more than or equal to n.

num = gets.chomp

num_of_four = 0
num_of_seven = 0
ans_num = ""
len = num.length

def get_bigger len
  ans_num = "4"
  append_times = len / 2
  append_times.times { ans_num << "4" }
  append_times.times { ans_num << "7" }
  ans_num << "7"
end

def get_rest(ans_num, len, num_of_four, num_of_seven)
  rest_four = len / 2 - num_of_four
  rest_seven = len / 2 - num_of_seven
  rest_four.times { ans_num << "4" }
  rest_seven.times { ans_num << "7" }
  return ans_num
end

def operation_with_seven(index, num, num_of_four, num_of_seven, len)
  ans_num = ""
  index = index - 1
  while index >= 0
    if num[index] == "4"
      num_of_four = num_of_four - 1
      break if len / 2 - num_of_seven > 0
    else
      num_of_seven = num_of_seven - 1
    end
    index = index - 1
  end
  if index == -1
    ans_num = get_bigger len
  else
    ans_num = ans_num << num[0...index]
    ans_num << "7"
    num_of_seven = num_of_seven + 1
    ans_num = get_rest ans_num, len, num_of_four, num_of_seven
  end
  return ans_num
end

if num[0] > "7" || len % 2 == 1
  ans_num = ans_num << (get_bigger len)

else
  index = len
  for i in 0...len
    if num[i] == "4" #many 4
      num_of_four = num_of_four + 1
      if num_of_four > len / 2
        num_of_four = num_of_four - 1
        index = i
        break
      end

    elsif num[i] == "7" #many 7
      num_of_seven = num_of_seven + 1
      if num_of_seven > len / 2
        num_of_seven = num_of_seven - 1
        index = i
        break
      end

    else
      index = i
      break
    end
  end

  if index == len
    ans_num = num
  elsif num[index] <= "4"
    ans_num = ans_num << num[0...index]
    ans_num = get_rest ans_num, len, num_of_four, num_of_seven

  elsif num[index] < "7"
    if len / 2 - num_of_seven > 0
      ans_num = ans_num << num[0...index]
      ans_num << "7"
      num_of_seven = num_of_seven + 1
      ans_num = get_rest ans_num, len, num_of_four, num_of_seven
    else
      ans_num = operation_with_seven index, num, num_of_four, num_of_seven, len
    end
  else
    ans_num = operation_with_seven index, num, num_of_four, num_of_seven, len
  end
end

puts ans_num