alexjercan/bugnet huggingface dataset:
Problem B: Headstrong Student

You are a teacher at a cram school for elementary school pupils.

One day, you showed your students how to calculate division of fraction in a class of mathematics.
Your lesson was kind and fluent, and it seemed everything was going so well - except for one
thing. After some experiences, a student Max got so curious about how precise he could compute
the quotient. He tried many divisions asking you for a help, and finally found a case where
the answer became an infinite fraction. He was fascinated with such a case, so he continued
computing the answer. But it was clear for you the answer was an infinite fraction - no matter
how many digits he computed, he wouldn’t reach the end.

Since you have many other things to tell in today’s class, you can’t leave this as it is. So you
decided to use a computer to calculate the answer in turn of him. Actually you succeeded to
persuade him that he was going into a loop, so it was enough for him to know how long he could
compute before entering a loop.

Your task now is to write a program which computes where the recurring part starts and the
length of the recurring part, for given dividend/divisor pairs. All computation should be done
in decimal numbers. If the specified dividend/divisor pair gives a finite fraction, your program
should treat the length of the recurring part as 0.

Input

The input consists of multiple datasets. Each line of the input describes a dataset. A dataset
consists of two positive integers x and y, which specifies the dividend and the divisor, respectively.
You may assume that 1 ≤ x < y ≤ 1,000,000.

The last dataset is followed by a line containing two zeros. This line is not a part of datasets
and should not be processed.

Output

For each dataset, your program should output a line containing two integers separated by exactly
one blank character.

The former describes the number of digits after the decimal point before the recurring part
starts. And the latter describes the length of the recurring part.

Sample Input

1 3
1 6
3 5
2 200
25 99
0 0

Output for the Sample Input

0 1
1 1
1 0
2 0
0 2
Problem C: Dig or Climb

Benjamin Forest VIII is a king of a country. One of his best friends Nod lives in a village far from
his castle. Nod gets seriously sick and is on the verge of death. Benjamin orders his subordinate
Red to bring good medicine for him as soon as possible. However, there is no road from the
castle to the village. Therefore, Red needs to climb over mountains and across canyons to reach
the village. He has decided to get to the village on the shortest path on a map, that is, he will
move on the straight line between the castle and the village. Then his way can be considered as
polyline with n points (x1, y1) . . . (xn , yn ) as illustlated in the following figure.

Figure 1: An example route from the castle to the village

Here, xi indicates the distance between the castle and the point i, as the crow flies, and yi
indicates the height of the point i. The castle is located on the point (x1 , y1 ), and the village is
located on the point (xn , yn).

Red can walk in speed vw . Also, since he has a skill to cut a tunnel through a mountain
horizontally, he can move inside the mountain in speed vc.

Your job is to write a program to the minimum time to get to the village.

Input

The input is a sequence of datasets. Each dataset is given in the following format:

n
vw vc
x1 y1
...
xn yn

You may assume all the following: n ≤ 1,000, 1 ≤ vw, vc ≤ 10, -10,000 ≤ xi, yi ≤ 10,000, and
xi < xj for all i < j.

The input is terminated in case of n = 0. This is not part of any datasets and thus should not
be processed.

Output

For each dataset, you should print the minimum time required to get to the village in a line.
Each minimum time should be given as a decimal with an arbitrary number of fractional digits
and with an absolute error of at most 10-6 . No extra space or character is allowed.

Sample Input

3
2 1
0 0
50 50
100 0
3
1 1
0 0
50 50
100 0
3
1 2
0 0
50 50
100 0
3
2 1
0 0
100 100
150 50
6
1 2
0 0
50 50
100 0
150 0
200 50
250 0
0

Output for the Sample Input

70.710678
100.000000
50.000000
106.066017
150.000000
Problem D: Rotation Estimation

Mr. Nod is an astrologist and has defined a new constellation. He took two photos of the
constellation to foretell a future of his friend. The constellation consists of n stars. The shape
of the constellation in these photos are the same, but the angle of them are different because
these photos were taken on a different day. He foretells a future by the difference of the angle
of them.

Your job is to write a program to calculate the difference of the angle of two constellation.

Input

The input is a sequence of datasets. Each dataset is given in the following format:

n
x1,1 y1,1
...
x1,n y1,n
x2,1 y2,1
...
x2,n y2,n

The first line of each dataset contains a positive integers n (n ≤ 1,000). The next n lines contain
two real numbers x1,i and y1,i (|x1,i|, |y1,i| ≤ 100), where (x1,i , y1,i) denotes the coordinates of
the i-th star of the constellation in the first photo. The next n lines contain two real numbers
x2,i and y2,i (|x2,i|, |y2,i| ≤ 100), where (x2,i , y2,i ) denotes the coordinates of the i-th star of the
constellation in the second photo.

Note that the ordering of the stars does not matter for the sameness. It is guaranteed that
distance between every pair of stars in each photo is larger than 10-5.

The input is terminated in case of n = 0. This is not part of any datasets and thus should not
be processed.

Output

For each dataset, you should print a non-negative real number which is the difference of the
angle of the constellation in the first photo and in the second photo. The difference should be in radian, and should not be negative. If there are two or more solutions, you should print
the smallest one. The difference may be printed with any number of digits after decimal point,
provided the absolute error does not exceed 10-7. No extra space or character is allowed.

Sample Input

3
0.0 0.0
1.0 1.0
0.0 1.0
3.0 3.0
2.0 2.0
3.0 2.0
0

Output for the Sample Input

3.14159265359
Problem E: Optimal Rest

Music Macro Language (MML) is a language for textual representation of musical scores. Although there are various dialects of MML, all of them provide a set of commands to describe
scores, such as commands for notes, rests, octaves, volumes, and so forth.

In this problem, we focus on rests, i.e. intervals of silence. Each rest command consists of a
command specifier ‘R’ followed by a duration specifier. Each duration specifier is basically one
of the following numbers: ‘1’, ‘2’, ‘4’, ‘8’, ‘16’, ‘32’, and ‘64’, where ‘1’ denotes a whole (1), ‘2’
a half (1/2), ‘4’ a quarter (1/4), ‘8’ an eighth (1/8), and so on. This number is called the base
duration, and optionally followed by one or more dots. The first dot adds the duration by the
half of the base duration. For example, ‘4.’ denotes the duration of ‘4’ (a quarter) plus ‘8’ (an
eighth, i.e. the half of a quarter), or simply 1.5 times as long as ‘4’. In other words, ‘R4.’ is
equivalent to ‘R4R8’. In case with two or more dots, each extra dot extends the duration by the
half of the previous one. Thus ‘4..’ denotes the duration of ‘4’ plus ‘8’ plus ‘16’, ‘4...’ denotes
the duration of ‘4’ plus ‘8’ plus ‘16’ plus ‘32’, and so on. The duration extended by dots cannot
be shorter than ‘64’. For exapmle, neither ‘64.’ nor ‘16...’ will be accepted since both of the
last dots indicate the half of ‘64’ (i.e. the duration of 1/128).

In this problem, you are required to write a program that finds the shortest expressions equivalent
to given sequences of rest commands.

Input

The input consists of multiple datasets. The first line of the input contains the number of
datasets N. Then, N datasets follow, each containing a sequence of valid rest commands in one
line. You may assume that no sequence contains more than 100,000 characters.

Output

For each dataset, your program should output the shortest expression in one line. If there are
multiple expressions of the shortest length, output the lexicographically smallest one.

Sample Input

3
R2R2
R1R2R4R8R16R32R64
R1R4R16

Output for the Sample Input

R1
R1......
R16R1R4
Problem F: Controlled Tournament

National Association of Tennis is planning to hold a tennis competition among professional
players. The competition is going to be a knockout tournament, and you are assigned the task
to make the arrangement of players in the tournament.

You are given the detailed report about all participants of the competition. The report contains
the results of recent matches between all pairs of the participants. Examining the data, you’ve
noticed that it is only up to the opponent whether one player wins or not.

Since one of your special friends are attending the competition, you want him to get the best
prize. So you want to know the possibility where he wins the gold medal. However it is not so
easy to figure out because there are many participants. You have decided to write a program
which calculates the number of possible arrangements of tournament in which your friend wins
the gold medal.

In order to make your trick hidden from everyone, you need to avoid making a factitive tourna-
ment tree. So you have to minimize the height of your tournament tree.

Input

The input consists of multiple datasets. Each dataset has the format as described below.

N M
R11 R12 . . . R1N
R21 R22 . . . R2N
...
RN1 RN2 . . . RNN

N (2 ≤ N ≤ 16) is the number of player, and M (1 ≤ M ≤ N) is your friend’s ID (numbered
from 1). Rij is the result of a match between the i-th player and the j-th player. When i-th
player always wins, Rij = 1. Otherwise, Rij = 0. It is guaranteed that the matrix is consistent:
for all i ≠ j, Rij = 0 if and only if Rji = 1. The diagonal elements Rii are just given for
convenience and are always 0.

The end of input is indicated by a line containing two zeros. This line is not a part of any
datasets and should not be processed.

Output

For each dataset, your program should output in a line the number of possible tournaments in
which your friend wins the first prize.

Sample Input

2 1
0 1
0 0
2 1
0 0
1 0
3 3
0 1 1
0 0 1
0 0 0
3 3
0 1 0
0 0 0
1 1 0
3 1
0 1 0
0 0 0
1 1 0
3 3
0 1 0
0 0 1
1 0 0
6 4
0 0 0 0 0 1
1 0 1 0 1 0
1 0 0 1 1 0
1 1 0 0 1 0
1 0 0 0 0 0
0 1 1 1 1 0
7 2
0 1 0 0 0 1 0
0 0 1 0 1 1 1
1 0 0 1 1 0 0
1 1 0 0 0 1 0
1 0 0 1 0 0 1
0 0 1 0 1 0 0
1 0 1 1 0 1 0
8 6
0 0 0 0 1 0 0 0
1 0 1 1 0 0 0 0
1 0 0 0 1 0 0 0
1 0 1 0 0 1 0 1
0 1 0 1 0 0 1 0
1 1 1 0 1 0 0 1
1 1 1 1 0 1 0 0
1 1 1 0 1 0 1 0
0 0

Output for the Sample Input

1
0
0
3
0
1
11
139
78
Problem I: Cousin's Aunt

Sarah is a girl who likes reading books.

One day, she wondered about the relationship of a family in a mystery novel. The story said,

B is A’s father’s brother’s son, and

C is B’s aunt.

Then she asked herself, “So how many degrees of kinship are there between A and C?”

There are two possible relationships between B and C, that is, C is either B’s father’s sister or
B’s mother’s sister in the story. If C is B’s father’s sister, C is in the third degree of kinship to
A (A’s father’s sister). On the other hand, if C is B’s mother’s sister, C is in the fifth degree of
kinship to A (A’s father’s brother’s wife’s sister).

You are a friend of Sarah’s and good at programming. You can help her by writing a general
program to calculate the maximum and minimum degrees of kinship between A and C under
given relationship.

The relationship of A and C is represented by a sequence of the following basic relations: father,
mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson,
granddaughter, uncle, aunt, nephew, and niece. Here are some descriptions about these relations:

X’s brother is equivalent to X’s father’s or mother’s son not identical to X.

X’s grandfather is equivalent to X’s father’s or mother’s father.

X’s grandson is equivalent to X’s son’s or daughter’s son.

X’s uncle is equivalent to X’s father’s or mother’s brother.

X’s nephew is equivalent to X’s brother’s or sister’s son.

Similar rules apply to sister, grandmother, granddaughter, aunt and niece.

In this problem, you can assume there are none of the following relations in the family: adoptions,
marriages between relatives (i.e. the family tree has no cycles), divorces, remarriages, bigamous
marriages and same-sex marriages.

The degree of kinship is defined as follows:

The distance from X to X’s father, X’s mother, X’s son or X’s daughter is one.

The distance from X to X’s husband or X’s wife is zero.

The degree of kinship between X and Y is equal to the shortest distance from X to Y
deduced from the above rules.

Input

The input contains multiple datasets. The first line consists of a positive integer that indicates
the number of datasets.

Each dataset is given by one line in the following format:

C is A(’s relation)*

Here, relation is one of the following:

father, mother, son, daughter, husband, wife, brother,
sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, niece.

An asterisk denotes zero or more occurance of portion surrounded by the parentheses. The
number of relations in each dataset is at most ten.

Output

For each dataset, print a line containing the maximum and minimum degrees of kinship separated
by exact one space. No extra characters are allowed of the output.

Sample Input

7
C is A’s father’s brother’s son’s aunt
C is A’s mother’s brother’s son’s aunt
C is A’s son’s mother’s mother’s son
C is A’s aunt’s niece’s aunt’s niece
C is A’s father’s son’s brother
C is A’s son’s son’s mother
C is A

Output for the Sample Input

5 3
5 1
2 2
6 0
2 0
1 1
0 0
The Closest Circle

You are given N non-overlapping circles in xy-plane. The radius of each circle varies, but the radius of
the largest circle is not double longer than that of the smallest.

Figure 1: The Sample Input

The distance between two circles C1 and C2 is given by the usual formula

where (xi, yi ) is the coordinates of the center of the circle Ci, and ri is the radius of Ci, for i = 1, 2.

Your task is to write a program that finds the closest pair of circles and print their distance.

Input

The input consists of a series of test cases, followed by a single line only containing a single zero, which
indicates the end of input.

Each test case begins with a line containing an integer N (2 ≤ N ≤ 100000), which indicates the number
of circles in the test case. N lines describing the circles follow. Each of the N lines has three decimal
numbers R, X, and Y. R represents the radius of the circle. X and Y represent the x- and y-coordinates of
the center of the circle, respectively.

Output

For each test case, print the distance between the closest circles. You may print any number of digits
after the decimal point, but the error must not exceed 0.00001.

Sample Input

4
1.0 0.0 0.0
1.5 0.0 3.0
2.0 4.0 0.0
1.0 3.0 4.0
0

Output for the Sample Input

0.5
Problem A: Moduic Squares

Have you ever heard of Moduic Squares? They are like 3 × 3 Magic Squares, but each of them has one
extra cell called a moduic cell. Hence a Moduic Square has the following form.

Figure 1: A Moduic Square

Each of cells labeled from A to J contains one number from 1 to 10, where no two cells contain the same
number. The sums of three numbers in the same rows, in the same columns, and in the diagonals in the
3 × 3 cells must be congruent modulo the number in the moduic cell. Here is an example Moduic Square:

Figure 2: An example Moduic Square

You can easily see that all the sums are congruent to 0 modulo 5.

Now, we can consider interesting puzzles in which we complete Moduic Squares with partially filled cells.
For example, we can complete the following square by filling 4 into the empty cell on the left and 9 on
the right. Alternatively, we can also complete the square by filling 9 on the left and 4 on the right. So
this puzzle has two possible solutions.

Figure 3: A Moduic Square as a puzzle

Your task is to write a program that determines the number of solutions for each given puzzle.

Input

The input contains multiple test cases. Each test case is specified on a single line made of 10 integers
that represent cells A, B, C, D, E, F, G, H, I, and J as shown in the first figure of the problem statement.
Positive integer means that the corresponding cell is already filled with the integer. Zero means that the
corresponding cell is left empty.

The end of input is identified with a line containing ten of -1’s. This is not part of test cases.

Output

For each test case, output a single integer indicating the number of solutions on a line. There may be
cases with no solutions, in which you should output 0 as the number.

Sample Input

3 1 6 8 10 7 0 0 2 5
0 0 0 0 0 0 0 0 0 1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

Output for the Sample Input

2
362880
Problem C: Tetrahedra

Peter P. Pepper is facing a difficulty.

After fierce battles with the Principality of Croode, the Aaronbarc Kingdom, for which he serves, had
the last laugh in the end. Peter had done great service in the war, and the king decided to give him a
big reward. But alas, the mean king gave him a hard question to try his intelligence. Peter is given a
number of sticks, and he is requested to form a tetrahedral vessel with these sticks. Then he will be, said
the king, given as much patas (currency in this kingdom) as the volume of the vessel. In the situation,
he has only to form a frame of a vessel.

Figure 1: An example tetrahedron vessel

The king posed two rules to him in forming a vessel: (1) he need not use all of the given sticks, and (2)
he must not glue two or more sticks together in order to make a longer stick.

Needless to say, he wants to obtain as much patas as possible. Thus he wants to know the maximum
patas he can be given. So he called you, a friend of him, and asked to write a program to solve the
problem.

Input

The input consists of multiple test cases. Each test case is given in a line in the format below:

N a1 a2 . . . aN

where N indicates the number of sticks Peter is given, and ai indicates the length (in centimeters) of
each stick. You may assume 6 ≤ N ≤ 15 and 1 ≤ ai ≤ 100.

The input terminates with the line containing a single zero.

Output

For each test case, print the maximum possible volume (in cubic centimeters) of a tetrahedral vessel
which can be formed with the given sticks. You may print an arbitrary number of digits after the decimal
point, provided that the printed value does not contain an error greater than 10-6.

It is guaranteed that for each test case, at least one tetrahedral vessel can be formed.

Sample Input

7 1 2 2 2 2 2 2
0

Output for the Sample Input

0.942809
Problem D: International Party

Isaac H. Ives is attending an international student party (maybe for girl-hunting). Students there enjoy
talking in groups with excellent foods and drinks. However, since students come to the party from all
over the world, groups may not have a language spoken by all students of the group. In such groups,
some student(s) need to work as interpreters, but intervals caused by interpretation make their talking
less exciting.

Needless to say, students want exciting talks. To have talking exciting as much as possible, Isaac proposed
the following rule: the number of languages used in talking should be as little as possible, and not exceed
five. Many students agreed with his proposal, but it is not easy for them to find languages each student
should speak. So he calls you for help.

Your task is to write a program that shows the minimum set of languages to make talking possible, given
lists of languages each student speaks.

Input

The input consists of a series of data sets.

The first line of each data set contains two integers N (1 ≤ N ≤ 30) and M (2 ≤ M ≤ 20) separated
by a blank, which represent the numbers of languages and students respectively. The following N lines
contain language names, one name per line. The following M lines describe students in the group. The
i-th line consists of an integer Ki that indicates the number of languages the i-th student speaks, and
Ki language names separated by a single space. Each language name consists of up to twenty alphabetic
letters.

A line that contains two zeros indicates the end of input and is not part of a data set.

Output

Print a line that contains the minimum number L of languages to be spoken, followed by L language
names in any order. Each language name should be printed in a separate line. In case two or more sets of
the same size is possible, you may print any one of them. If it is impossible for the group to enjoy talking
with not more than five languages, you should print a single line that contains “Impossible” (without
quotes).

Print an empty line between data sets.

Sample Input

3 4
English
French
Japanese
1 English
2 French English
2 Japanese English
1 Japanese
2 2
English
Japanese
1 English
1 Japanese
6 7
English
Dutch
German
French
Italian
Spanish
1 English
2 English Dutch
2 Dutch German
2 German French
2 French Italian
2 Italian Spanish
1 Spanish
0 0

Output for the Sample Input

2
English
Japanese

Impossible

Impossible
Problem E: Hide-and-seek

Hide-and-seek is a children’s game. Players hide here and there, and one player called it tries to find all
the other players.

Now you played it and found all the players, so it’s turn to hide from it. Since you have got tired of
running around for finding players, you don’t want to play it again. So you are going to hide yourself at
the place as far as possible from it. But where is that?

Your task is to find the place and calculate the maximum possible distance from it to the place to hide.

Input

The input contains a number of test cases.

The first line of each test case contains a positive integer N (N ≤ 1000). The following N lines give
the map where hide-and-seek is played. The map consists of N corridors. Each line contains four real
numbers x1, y1, x2, and y2, where (x1, y1 ) and (x2, y2 ) indicate the two end points of the corridor. All
corridors are straight, and their widths are negligible. After these N lines, there is a line containing two
real numbers sx and sy, indicating the position of it. You can hide at an arbitrary place of any corridor,
and it always walks along corridors. Numbers in the same line are separated by a single space.

It is guaranteed that its starting position (sx, sy) is located on some corridor and linked to all corridors
directly or indirectly.

The end of the input is indicated by a line containing a single zero.

Output

For each test case, output a line containing the distance along the corridors from ‘it”s starting position
to the farthest position. The value may contain an error less than or equal to 0.001. You may print any
number of digits below the decimal point.

Sample Input

2
0 0 3 3
0 4 3 1
1 1
0

Output for the Sample Input

4.243