alexjercan/bugnet huggingface dataset:
Problem D: Lowest Pyramid

You are constructing a triangular pyramid with a sheet of craft paper with grid lines. Its base
and sides are all of triangular shape. You draw the base triangle and the three sides connected
to the base on the paper, cut along the outer six edges, fold the edges of the base, and assemble
them up as a pyramid.

You are given the coordinates of the base's three vertices, and are to determine the coordinates
of the other three. All the vertices must have integral X- and Y-coordinate values between -100 and +100 inclusive. Your goal is to minimize the height of the pyramid satisfying these
conditions. Figure 3 shows some examples.

Figure 3: Some craft paper drawings and side views of the assembled pyramids

Input

The input consists of multiple datasets, each in the following format.

X0 Y0 X1 Y1 X2 Y2

They are all integral numbers between -100 and +100 inclusive. (X0, Y0), (X1, Y1), (X2, Y2) are the coordinates of three vertices of the triangular base in counterclockwise order.

The end of the input is indicated by a line containing six zeros separated by a single space.

Output

For each dataset, answer a single number in a separate line. If you can choose three vertices (Xa, Ya), (Xb, Yb) and (Xc, Yc) whose coordinates are all integral values between -100 and +100 inclusive, and triangles (X0, Y0 )-(X1, Y1)-(Xa, Ya), (X1, Y1)-(X2, Y2)-(Xb, Yb), (X2, Y2)-(X0, Y0)-(Xc, Yc) and (X0, Y0)-(X1, Y1)-(X2, Y2) do not overlap each other (in the XY-plane), and can be assembled as a triangular pyramid of positive (non-zero) height, output the minimum height among such pyramids. Otherwise, output -1.

You may assume that the height is, if positive (non-zero), not less than 0.00001. The output should not contain an error greater than 0.00001.

Sample Input

0 0 1 0 0 1
0 0 5 0 2 5
-100 -100 100 -100 0 100
-72 -72 72 -72 0 72
0 0 0 0 0 0

Output for the Sample Input

2
1.49666
-1
8.52936
Problem F: Slim Span

Given an undirected weighted graph G, you should find one of spanning trees specified as follows.

The graph G is an ordered pair (V, E), where V is a set of vertices {v1, v2, ... , vn} and E is a set of undirected edges {e1, e2, ... , em}. Each edge e ∈ E has its weight w(e).

A spanning tree T is a tree (a connected subgraph without cycles) which connects all the n
vertices with n - 1 edges. The slimness of a spanning tree T is defined as the difference between
the largest weight and the smallest weight among the n - 1 edges of T.

Figure 5: A graph G and the weights of the edges

For example, a graph G in Figure 5(a) has four vertices {v1, v2, v3, v4} and five undirected edges {e1, e2, e3, e4, e5}. The weights of the edges are w(e1) = 3, w(e2) = 5, w(e3) = 6, w(e4) = 6, w(e5) = 7 as shown in Figure 5(b).

Figure 6: Examples of the spanning trees of G

There are several spanning trees for G. Four of them are depicted in Figure 6(a)-(d). The spanning tree Ta in Figure 6(a) has three edges whose weights are 3, 6 and 7. The largest weight
is 7 and the smallest weight is 3 so that the slimness of the tree Ta is 4. The slimnesses of
spanning trees Tb , Tc and Td shown in Figure 6(b), (c) and (d) are 3, 2 and 1, respectively. You
can easily see the slimness of any other spanning tree is greater than or equal to 1, thus the
spanning tree Td in Figure 6(d) is one of the slimmest spanning trees whose slimness is 1.

Your job is to write a program that computes the smallest slimness.

Input

The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset has the following format.

n m
a1 b1 w1
.
.
.
am bm wm

Every input item in a dataset is a non-negative integer. Items in a line are separated by a space.

n is the number of the vertices and m the number of the edges. You can assume 2 ≤ n ≤ 100 and 0 ≤ m ≤ n(n - 1)/2. ak and bk (k = 1, ... , m) are positive integers less than or equal to n, which represent the two vertices vak and vbk connected by the kth edge ek. wk is a positive integer less than or equal to 10000, which indicates the weight of ek . You can assume that the graph G = (V, E) is simple, that is, there are no self-loops (that connect the same vertex) nor parallel edges (that are two or more edges whose both ends are the same two vertices).

Output

For each dataset, if the graph has spanning trees, the smallest slimness among them should be
printed. Otherwise, -1 should be printed. An output should not contain extra characters.

Sample Input

4 5
1 2 3
1 3 5
1 4 6
2 4 6
3 4 7
4 6
1 2 10
1 3 100
1 4 90
2 3 20
2 4 80
3 4 40
2 1
1 2 1
3 0
3 1
1 2 1
3 3
1 2 2
2 3 5
1 3 6
5 10
1 2 110
1 3 120
1 4 130
1 5 120
2 3 110
2 4 120
2 5 130
3 4 120
3 5 110
4 5 120
5 10
1 2 9384
1 3 887
1 4 2778
1 5 6916
2 3 7794
2 4 8336
2 5 5387
3 4 493
3 5 6650
4 5 1422
5 8
1 2 1
2 3 100
3 4 100
4 5 100
1 5 50
2 5 50
3 5 50
4 1 150
0 0

Output for the Sample Input

1
20
0
-1
-1
1
0
1686
50
Problem H: Bug Hunt

In this problem, we consider a simple programming language that has only declarations of one-
dimensional integer arrays and assignment statements. The problem is to find a bug in the given
program.

The syntax of this language is given in BNF as follows:

where <new line> denotes a new line character (LF).

Characters used in a program are alphabetical letters, decimal digits, =, [, ] and new line characters. No other characters appear in a program.

A declaration declares an array and specifies its length. Valid indices of an array of length n are integers between 0 and n - 1, inclusive. Note that the array names are case sensitive, i.e.
array a and array A are different arrays. The initial value of each element in the declared array is undefined.

For example, array a of length 10 and array b of length 5 are declared respectively as follows.

a[10]
b[5]

An expression evaluates to a non-negative integer. A <number> is interpreted as a decimal
integer. An <array_name> [<expression>] evaluates to the value of the <expression> -th element of
the array. An assignment assigns the value denoted by the right hand side to the array element
specified by the left hand side.

Examples of assignments are as follows.

a[0]=3
a[1]=0
a[2]=a[a[1]]
a[a[0]]=a[1]

A program is executed from the first line, line by line. You can assume that an array is declared once and only once before any of its element is assigned or referred to.

Given a program, you are requested to find the following bugs.

An index of an array is invalid.

An array element that has not been assigned before is referred to in an assignment as an index of array or as the value to be assigned.

You can assume that other bugs, such as syntax errors, do not appear. You can also assume
that integers represented by <number>s are between 0 and 231 - 1 (= 2147483647), inclusive.

Input

The input consists of multiple datasets followed by a line which contains only a single '.' (period).
Each dataset consists of a program also followed by a line which contains only a single '.' (period).
A program does not exceed 1000 lines. Any line does not exceed 80 characters excluding a new
line character.

Output

For each program in the input, you should answer the line number of the assignment in which
the first bug appears. The line numbers start with 1 for each program. If the program does not
have a bug, you should answer zero. The output should not contain extra characters such as
spaces.

Sample Input

a[3]
a[0]=a[1]
.
x[1]
x[0]=x[0]
.
a[0]
a[0]=1
.
b[2]
b[0]=2
b[1]=b[b[0]]
b[0]=b[1]
.
g[2]
G[10]
g[0]=0
g[1]=G[0]
.
a[2147483647]
a[0]=1
B[2]
B[a[0]]=2
a[B[a[0]]]=3
a[2147483646]=a[2]
.
.

Output for the Sample Input

2
2
2
3
4
0
Problem I: Most Distant Point from the Sea

The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it
is natural to ask a question: "Where is the most distant point from the sea?" The answer to
this question for Honshu was found in 1996. The most distant point is located in former Usuda
Town, Nagano Prefecture, whose distance from the sea is 114.86 km.

In this problem, you are asked to write a program which, given a map of an island, finds the
most distant point from the sea in the island, and reports its distance from the sea. In order to
simplify the problem, we only consider maps representable by convex polygons.

Input

The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows.

n
x1 y1
.
.
.
xn yn

Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space.

n in the first line is the number of vertices of the polygon, satisfying 3 ≤ n ≤ 100. Subsequent
n lines are the x- and y-coordinates of the n vertices. Line segments (xi, yi) - (xi+1, yi+1) (1 ≤ i ≤ n - 1) and the line segment (xn, yn) - (x1, y1) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive.

You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.

The last dataset is followed by a line containing a single zero.

Output

For each dataset in the input, one line containing the distance of the most distant point from
the sea should be output. An output line should not contain extra characters such as spaces.

The answer should not have an error greater than 0.00001 (10-5 ). You may output any number
of digits after the decimal point, provided that the above accuracy condition is satisfied.

Sample Input

4
0 0
10000 0
10000 10000
0 10000
3
0 0
10000 0
7000 1000
6
0 40
100 20
250 40
250 70
100 90
0 70
3
0 0
10000 10000
5000 5001
0

Output for the Sample Input

5000.000000
494.233641
34.542948
0.353553
Problem J: The Teacher’s Side of Math

One of the tasks students routinely carry out in their mathematics classes is to solve a polynomial equation. It is, given a polynomial, say X2 - 4X + 1, to find its roots (2 ± √3).

If the students’ task is to find the roots of a given polynomial, the teacher’s task is then to find a polynomial that has a given root. Ms. Galsone is an enthusiastic mathematics teacher who is bored with finding solutions of quadratic equations that are as simple as a + b√c. She wanted to make higher-degree equations whose solutions are a little more complicated. As usual in problems in mathematics classes, she wants to maintain all coefficients to be integers and keep the degree of the polynomial as small as possible (provided it has the specified root). Please help her by writing a program that carries out the task of the teacher’s side.

You are given a number t of the form:

t = m√a+n√b

where a and b are distinct prime numbers, and m and n are integers greater than 1.

In this problem, you are asked to find t's minimal polynomial on integers, which is the polynomial F(X) = adXd + ad-1Xd-1 + ... + a1X + a0 satisfying the following conditions.

Coefficients a0, ... , ad are integers and ad > 0.

F(t) = 0.

The degree d is minimum among polynomials satisfying the above two conditions.

F(X) is primitive. That is, coefficients a0, ... , ad have no common divisors greater than one.

For example, the minimal polynomial of √3+ √2 on integers is F(X) = X4 - 10X2 + 1. Verifying F(t) = 0 is as simple as the following (α = 3, β = 2).

F(t) = (α + β)4 - 10(α + β)2 + 1

= (α4 + 4&alpha3β + 6α2β2 + 4αβ3 + β4 ) - 10(α2 + 2αβ + β2) + 1

= 9 + 12αβ + 36 + 8αβ + 4 - 10(3 + 2αβ + 2) + 1

= (9 + 36 + 4 - 50 + 1) + (12 + 8 - 20)αβ

= 0

Verifying that the degree of F(t) is in fact minimum is a bit more difficult. Fortunately, under
the condition given in this problem, which is that a and b are distinct prime numbers and m and n greater than one, the degree of the minimal polynomial is always mn. Moreover, it is
always monic. That is, the coefficient of its highest-order term (ad) is one.

Input

The input consists of multiple datasets, each in the following format.

a m b n

This line represents m√a + n√b. The last dataset is followed by a single line consisting of four zeros. Numbers in a single line are separated by a single space.

Every dataset satisfies the following conditions.

m√a + n√b ≤ 4.

mn ≤ 20.

The coefficients of the answer a0, ... , ad are between (-231 + 1) and (231 - 1), inclusive.

Output

For each dataset, output the coefficients of its minimal polynomial on integers F(X) = adXd + ad-1Xd-1 + ... + a1X + a0, in the following format.

ad ad-1 ... a1 a0

Non-negative integers must be printed without a sign (+ or -). Numbers in a single line must
be separated by a single space and no other characters or extra spaces may appear in the output.

Sample Input

3 2 2 2
3 2 2 3
2 2 3 4
31 4 2 3
3 2 2 7
0 0 0 0

Output for the Sample Input

1 0 -10 0 1
1 0 -9 -4 27 -36 -23
1 0 -8 0 18 0 -104 0 1
1 0 0 -8 -93 0 24 -2976 2883 -32 -3720 -23064 -29775
1 0 -21 0 189 0 -945 -4 2835 -252 -5103 -1260 5103 -756 -2183
Problem A: Grey Area

Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the
world everyday. He is extremely good at sophisticated visualization tools, but yet his favorite is
a simple self-made histogram generator.

Figure 1 is an example of histogram automatically produced by his histogram.

A histogram is a visual display of frequencies of value occurrences as bars. In this example, values
in the interval 0-9 occur five times, those in the interval 10-19 occur three times, and 20-29
and 30-39 once each.

Dr. Grey’s histogram generator is a simple tool. First, the height of the histogram is fixed, that
is, the height of the highest bar is always the same and those of the others are automatically
adjusted proportionately. Second, the widths of bars are also fixed. It can only produce a
histogram of uniform intervals, that is, each interval of a histogram should have the same width
(10 in the above example). Finally, the bar for each interval is painted in a grey color, where
the colors of the leftmost and the rightmost intervals are black and white, respectively, and the
darkness of bars monotonically decreases at the same rate from left to right. For instance, in
Figure 1, the darkness levels of the four bars are 1, 2/3, 1/3, and 0, respectively.

In this problem, you are requested to estimate ink consumption when printing a histogram on paper. The amount of ink necessary to draw a bar is proportional to both its area and darkness.

Input

The input consists of multiple datasets, each of which contains integers and specifies a value
table and intervals for the histogram generator, in the following format.

n w

v1

v2

.

.

vn

n is the total number of value occurrences for the histogram, and each of the n lines following
the first line contains a single value. Note that the same value may possibly occur multiple
times.

w is the interval width. A value v is in the first (i.e. leftmost) interval if 0 ≤ v < w, the second
one if w ≤ v < 2w, and so on. Note that the interval from 0 (inclusive) to w (exclusive) should
be regarded as the leftmost even if no values occur in this interval. The last (i.e. rightmost)
interval is the one that includes the largest value in the dataset.

You may assume the following.

1 ≤ n ≤ 100

10 ≤ w ≤ 50

0 ≤ vi ≤ 100 for 1 ≤ i ≤ n

You can also assume that the maximum value is no less than w. This means that the histogram
has more than one interval.
The end of the input is indicated by a line containing two zeros.

Output

For each dataset, output a line containing the amount of ink consumed in printing the histogram.

One unit of ink is necessary to paint one highest bar black. Assume that 0.01 units of ink per
histogram is consumed for various purposes except for painting bars such as drawing lines and
characters (see Figure 1). For instance, the amount of ink consumed in printing the histogram
in Figure 1 is:

Each output value should be in a decimal fraction and may have an error less than 10-5 .

Sample Input

3 50
100
0
100
3 50
100
100
50
10 10
1
2
3
4
5
16
17
18
29
30
0 0

Output for the Sample Input

0.51
0.26
1.4766666666666667
Problem B: Expected Allowance

Hideyuki is allowed by his father Ujisato some 1000 yen bills every month for his pocket money.
In the first day of every month, the number of bills is decided as follows. Ujisato prepares n
pieces of m-sided dice and declares the cutback k. Hideyuki rolls these dice. The number of
bills given is the sum of the spots of the rolled dice decreased by the cutback. Fortunately to
Hideyuki, Ujisato promises him to give at least one bill, even if the sum of the spots does not
exceed the cutback. Each of the dice has spots of 1 through m inclusive on each side, and the
probability of each side is the same.

In this problem, you are asked to write a program that finds the expected value of the number
of given bills.

For example, when n = 2, m = 6 and k = 3, the probabilities of the number of bills being 1, 2, 3, 4, 5, 6, 7, 8 and 9 are 1/36 + 2/36 + 3/36, 4/36, 5/36, 6/36, 5/36, 4/36, 3/36, 2/36 and 1/36, respectively.

Therefore, the expected value is

(1/36 + 2/36 + 3/36) × 1 + 4/36 × 2 + 5/36 × 3 + 6/36 × 4 + 5/36 × 5 + 4/36 × 6 + 3/36 × 7 + 2/36 × 8 + 1/36 × 9, which is approximately 4.11111111.

Input

The input is a sequence of lines each of which contains three integers n, m and k in this order.
They satisfy the following conditions.

1 ≤ n

2 ≤ m

0 ≤ k < nm

nm × mn < 100000000 (108)

The end of the input is indicated by a line containing three zeros.

Output

The output should be comprised of lines each of which contains a single decimal fraction. It is
the expected number of bills and may have an error less than 10-7 . No other characters should
occur in the output.

Sample Input

2 6 0
2 6 3
3 10 9
13 3 27
1 2008 3
0 0 0

Output for the Sample Input

7.00000000
4.11111111
7.71000000
1.42902599
1001.50298805
Problem E: Spherical Mirrors

A long time ago in a galaxy, far, far away, there were N spheres with various radii.
Spheres were mirrors, that is, they had reflective surfaces . . . .

You are standing at the origin of the galaxy (0, 0, 0), and emit a laser ray to the direction
(u,v, w). The ray travels in a straight line.

When the laser ray from I hits the surface of a sphere at Q, let N be a point outside of the
sphere on the line connecting the sphere center and Q. The reflected ray goes to the direction
towards R that satisfies the following conditions: (1) R is on the plane formed by the three
points I, Q and N , (2) ∠ IQN = ∠ NQR, as shown in Figure 1.

Figure 1: Laser ray reflection

After it is reflected several times, finally it goes beyond our observation. Your mission is to write
a program that identifies the last reflection point.

Input

The input consists of multiple datasets, each in the following format.

N
u v w
x1 y1 z1 r1
.
.
.
xN yN zN rN

The first line of a dataset contains a positive integer N which is the number of spheres. The
next line contains three integers u, v and w separated by single spaces, where (u, v, w) is the
direction of the laser ray initially emitted from the origin.

Each of the following N lines contains four integers separated by single spaces. The i-th line
corresponds to the i-th sphere, and the numbers represent the center position (xi, yi, zi ) and the
radius ri .

N, u, v, w, xi, yi, zi and ri satisfy the following conditions.

1 ≤ N ≤ 100

−100 ≤ u, v, w ≤ 100

−100 ≤ xi, yi, zi ≤ 100

5 ≤ ri ≤ 30

u2 + v2 + w2 > 0

You can assume that the distance between the surfaces of any two spheres is no less than 0.1.
You can also assume that the origin (0, 0, 0) is located outside of any sphere, and is at least 0.1
distant from the surface of any sphere.

The ray is known to be reflected by the sphere surfaces at least once, and at most five times.
You can assume that the angle between the ray and the line connecting the sphere center and
the reflection point, which is known as the angle of reflection (i.e. θ in Figure 1), is less than 85
degrees for each point of reflection.

The last dataset is followed by a line containing a single zero.

Output

For each dataset in the input, you should print the x-, y- and z-coordinates of the last reflection
point separated by single spaces in a line. No output line should contain extra characters.

No coordinate values in the output should have an error greater than 0.01.

Sample Input

3
-20 -20 -24
100 100 100 30
10 8 3 5
-70 -70 -84 5
4
0 47 84
-23 41 42 8
45 -10 14 19
-5 28 47 12
-27 68 34 14
0

Output for the Sample Input

79.0940 79.0940 94.9128
-21.8647 54.9770 34.1761
Problem I: Common Polynomial

Math teacher Mr. Matsudaira is teaching expansion and factoring of polynomials to his students.
Last week he instructed the students to write two polynomials (with a single variable x), and
to report GCM (greatest common measure) of them as a homework, but he found it boring to
check their answers manually. So you are asked to write a program to check the answers.

Hereinafter, only those polynomials with integral coefficients, called integral polynomials, are
considered.

When two integral polynomials A and B are given, an integral polynomial C is a common factor
of A and B if there are some integral polynomials X and Y such that A = CX and B = CY.

GCM of two integral polynomials is a common factor which has the highest degree (for x, here);
you have to write a program which calculates the GCM of two polynomials.

It is known that GCM of given two polynomials is unique when constant multiplication factor is
ignored. That is, when C and D are both GCM of some two polynomials A and B, p × C = q × D
for some nonzero integers p and q.

Input

The input consists of multiple datasets. Each dataset constitutes a pair of input lines, each
representing a polynomial as an expression defined below.

A primary is a variable x, a sequence of digits 0 - 9, or an expression enclosed within ( ... ). Examples:

x, 99, (x+1)

A factor is a primary by itself or a primary followed by an exponent. An exponent consists
of a symbol ^ followed by a sequence of digits 0 - 9. Examples:

x^05, 1^15, (x+1)^3

A term consists of one or more adjoining factors. Examples:

4x, (x+1)(x-2), 3(x+1)^2

An expression is one or more terms connected by either + or -. Additionally, the first
term of an expression may optionally be preceded with a minus sign -. Examples:

-x+1, 3(x+1)^2-x(x-1)^2

Integer constants, exponents, multiplications (adjoining), additions (+) and subtractions/negations
(-) have their ordinary meanings. A sequence of digits is always interpreted as an integer con-
stant. For example, 99 means 99, not 9 × 9.

Any subexpressions of the input, when fully expanded normalized, have coefficients less than
100 and degrees of x less than 10. Digit sequences in exponents represent non-zero values.

All the datasets are designed so that a standard algorithm with 32-bit two’s complement integers
can solve the problem without overflows.

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

Output

For each of the dataset, output GCM polynomial expression in a line, in the format below.

c0x^p0 ± c1x^p1 ... ± cnx^pn

Where ci and pi (i = 0, . . . , n) are positive integers with p0 > p1 > . . . > pn, and the greatest
common divisor of {ci | i = 0, . . . , n} is 1.

Additionally:

When ci is equal to 1, it should be omitted unless corresponding pi is 0,

x^0 should be omitted as a whole, and

x^1 should be written as x.

Sample Input

-(x^3-3x^2+3x-1)
(x-1)^2
x^2+10x+25
x^2+6x+5
x^3+1
x-1
.

Output for the Sample Input

x^2-2x+1
x+5
1