alexjercan/bugnet huggingface dataset:
Problem H: Don't Burst the Balloon

An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom.

You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls nor the needles.

Java Specific: Submitted Java programs may not use "java.awt.geom.Area". You may use it for your debugging purposes.

Figure H.1 shows an example of a box with needles and the corresponding largest spheric balloon. It corresponds to the first dataset of the sample input below.

Figure H.1. The upper shows an example layout and the lower shows the largest spheric balloon that can be placed.

Input

The input is a sequence of datasets. Each dataset is formatted as follows.

n w
x1 y1 h1
:
xn yn hn

The first line of a dataset contains two positive integers, n and w, separated by a space. n represents the number of needles, and w represents the height of the side walls.

The bottom of the box is a 100 × 100 square. The corners of the bottom face are placed at positions (0, 0, 0), (0, 100, 0), (100, 100, 0), and (100, 0, 0).

Each of the n lines following the first line contains three integers, xi, yi, and hi. (xi, yi, 0) and hi represent the base position and the height of the i-th needle. No two needles stand at the same position.

You can assume that 1 ≤ n ≤ 10, 10 ≤ w ≤ 200, 0 < xi < 100, 0 < yi < 100 and 1 ≤ hi ≤ 200. You can ignore the thicknesses of the needles and the walls.

The end of the input is indicated by a line of two zeros. The number of datasets does not exceed 1000.

Output

For each dataset, output a single line containing the maximum radius of a balloon that can touch the bottom of the box without interfering with the side walls or the needles. The output should not contain an error greater than 0.0001.

Sample Input

5 16
70 66 40
38 52 20
40 35 10
70 30 10
20 60 10
1 100
54 75 200
1 10
90 10 1
1 11
54 75 200
3 10
53 60 1
61 38 1
45 48 1
4 10
20 20 10
20 80 10
80 20 10
80 80 10
0 0

Output for the Sample Input

26.00000
39.00000
130.00000
49.49777
85.00000
95.00000
Problem I: Hidden Tree

Consider a binary tree whose leaves are assigned integer weights. Such a tree is called balanced if, for every non-leaf node, the sum of the weights in its left subtree is equal to that in the right subtree. For instance, the tree in the following figure is balanced.

Figure I.1. A balanced tree

A balanced tree is said to be hidden in a sequence A, if the integers obtained by listing the weights of all leaves of the tree from left to right form a subsequence of A. Here, a subsequence is a sequence that can be derived by deleting zero or more elements from the original sequence without changing the order of the remaining elements.

For instance, the balanced tree in the figure above is hidden in the sequence 3 4 1 3 1 2 4 4 6, because 4 1 1 2 4 4 is a subsequence of it.

Now, your task is to find, in a given sequence of integers, the balanced tree with the largest number of leaves hidden in it. In fact, the tree shown in Figure I.1 has the largest number of leaves among the balanced trees hidden in the sequence mentioned above.

Input

The input consists of multiple datasets. Each dataset represents a sequence A of integers in the format

N
A1 A2 . . . AN

where 1 ≤ N ≤ 1000 and 1 ≤ Ai ≤ 500 for 1 ≤ i ≤ N. N is the length of the input sequence, and Ai is the i-th element of the sequence.

The input ends with a line consisting of a single zero. The number of datasets does not exceed 50.

Output

For each dataset, find the balanced tree with the largest number of leaves among those hidden in A, and output, in a line, the number of its leaves.

Sample Input

9
3 4 1 3 1 2 4 4 6
4
3 12 6 3
10
10 9 8 7 6 5 4 3 2 1
11
10 9 8 7 6 5 4 3 2 1 1
8
1 1 1 1 1 1 1 1
0

Output for the Sample Input

6
2
1
5
8
Problem A:
Bit String Reordering

You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required.

The initial bit string is simply represented by a sequence of bits, while the target is specified by a run-length code. The run-length code of a bit string is a sequence of the lengths of maximal consecutive sequences of zeros or ones in the bit string. For example, the run-length code of "011100" is "1 3 2". Note that there are two different bit strings with the same run-length code, one starting with zero and the other starting with one. The target is either of these two.

In Sample Input 1, bit string "100101" should be reordered so that its run-length code is "1 3 2", which means either "100011" or "011100". At least four swaps are required to obtain "011100". On the other hand, only one swap is required to make "100011". Thus, in this example, 1 is the answer.

Input

The input consists of a single test case. The test case is formatted as follows.

$N$ $M$

$b_1$ $b_2$ . . . $b_N$

$p_1$ $p_2$ . . . $p_M$

The first line contains two integers $N$ ($1 \leq N \leq 15$) and $M$ ($1 \leq M \leq N$). The second line
specifies the initial bit string by $N$ integers. Each integer $b_i$ is either 0 or 1. The third line contains the run-length code, consisting of $M$ integers. Integers $p_1$ through $p_M$ represent the lengths of consecutive sequences of zeros or ones in the bit string, from left to right. Here, $1 \leq p_j$ for $1 \leq j \leq M$ and $\sum^{M}_{j=1} p_j = N$ hold. It is guaranteed that the initial bit string can be reordered into a bit string with its run-length code $p_1, . . . , p_M$.

Output

Output the minimum number of swaps required

Sample Input 1

6 3
1 0 0 1 0 1
1 3 2

Sample Output 1

1

Sample Input 2

7 2
1 1 1 0 0 0 0
4 3

Sample Output 2

12

Sample Input 3

15 14
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 2

Sample Output 3

7

Sample Input 4

1 1
0
1

Sample Output 4

0
Problem B:
Miscalculation

Bob is an elementary schoolboy, not so good at mathematics. He found Father's calculator and tried cheating on his homework using it. His homework was calculating given expressions containing multiplications and additions. Multiplications should be done prior to additions, of course, but the calculator evaluates the expression from left to right, neglecting the operator precedence. So his answers may be the result of either of the following two calculation rules.

Doing multiplication before addition

Doing calculation from left to right neglecting the operator precedence

Write a program that tells which of the rules is applied from an expression and his answer.

An expression consists of integers and operators. All the integers have only one digit, from 0 to 9. There are two kinds of operators + and *, which represent addition and multiplication, respectively.

The following is an example expression.

1+2*3+4

Calculating this expression with the multiplication-first rule, the answer is 11, as in Sample Input 1. With the left-to-right rule, however, the answer will be 13 as shown in Sample Input 2.

There may be cases in which both rules lead to the same result and you cannot tell which of the rules is applied. Moreover, Bob sometimes commits miscalculations. When neither rules would result in Bob’s answer, it is clear that he actually did.

Input

The input consists of a single test case specified with two lines. The first line contains the expression to be calculated. The number of characters of the expression is always odd and less than or equal to 17. Each of the odd-numbered characters in the expression is a digit from '0' to '9'. Each of the even-numbered characters is an operator '+' or '*'. The second line contains an integer which ranges from 0 to 999999999, inclusive. This integer represents Bob's answer for the expression given in the first line.

Output

Output one of the following four characters:

M When only the multiplication-first rule results Bob's answer.

L When only the left-to-right rule results Bob's answer.

U When both of the rules result Bob's answer.

I When neither of the rules results Bob's answer.

Sample Input 1

1+2*3+4
11

Sample Output 1

M

Sample Input 2

1+2*3+4
13

Sample Output 2

L

Sample Input 3

3
3

Sample Output 3

U

Sample Input 4

1+2*3+4
9

Sample Output 4

I
Problem C:
Shopping

Your friend will enjoy shopping. She will walk through a mall along a straight street, where $N$ individual shops (numbered from 1 to $N$) are aligned at regular intervals. Each shop has one door and is located at the one side of the street. The distances between the doors of the adjacent shops are the same length, i.e. a unit length. Starting shopping at the entrance of the mall, she visits shops in order to purchase goods. She has to go to the exit of the mall after shopping.

She requires some restrictions on visiting order of shops. Each of the restrictions indicates that she shall visit a shop before visiting another shop. For example, when she wants to buy a nice dress before choosing heels, she shall visit a boutique before visiting a shoe store. When the boutique is farther than the shoe store, she must pass the shoe store before visiting the boutique, and go back to the shoe store after visiting the boutique.

If only the order of the visiting shops satisfies all the restrictions, she can visit other shops in any order she likes.

Write a program to determine the minimum required walking length for her to move from the entrance to the exit.

Assume that the position of the door of the shop numbered $k$ is $k$ units far from the entrance, where the position of the exit is $N + 1$ units far from the entrance.

Input

The input consists of a single test case.

$N$ $m$

$c_1$ $d_1$

.

.

.

$c_m$ $d_m$

The first line contains two integers $N$ and $m$, where $N$ ($1 \leq N \leq 1000$) is the number of shops, and $m$ ($0 \leq m \leq 500$) is the number of restrictions. Each of the next $m$ lines contains two integers $c_i$ and $d_i$ ($1 \leq c_i < d_i \leq N$) indicating the $i$-th restriction on the visiting order, where she must visit the shop numbered $c_i$ after she visits the shop numbered $d_i$ ($i = 1, . . . , m$).

There are no pair of $j$ and $k$ that satisfy $c_j = c_k$ and $d_j = d_k$.

Output

Output the minimum required walking length for her to move from the entrance to the exit. You should omit the length of her walk in the insides of shops.

Sample Input 1

10 3
3 7
8 9
2 5

Sample Output 1

23

Sample Input 2

10 3
8 9
6 7
2 4

Sample Output 2

19

Sample Input 3

10 0

Sample Output 3

11

Sample Input 4

10 6
6 7
4 5
2 5
6 9
3 5
6 8

Sample Output 4

23

Sample Input 5

1000 8
3 4
6 1000
5 1000
7 1000
8 1000
4 1000
9 1000
1 2

Sample Output 5

2997
Problem F:
There is No Alternative

ICPC (Isles of Coral Park City) consist of several beautiful islands.

The citizens requested construction of bridges between islands to resolve inconveniences of using boats between islands, and they demand that all the islands should be reachable from any other islands via one or more bridges.

The city mayor selected a number of pairs of islands, and ordered a building company to estimate the costs to build bridges between the pairs. With this estimate, the mayor has to decide the set of bridges to build, minimizing the total construction cost.

However, it is difficult for him to select the most cost-efficient set of bridges among those connecting all the islands. For example, three sets of bridges connect all the islands for the Sample Input 1. The bridges in each set are expressed by bold edges in Figure F.1.

Figure F.1. Three sets of bridges connecting all the islands for Sample Input 1

As the first step, he decided to build only those bridges which are contained in all the sets of bridges to connect all the islands and minimize the cost. We refer to such bridges as no alternative bridges. In Figure F.2, no alternative bridges are drawn as thick edges for the Sample Input 1, 2 and 3.

Figure F.2. No alternative bridges for Sample Input 1, 2 and 3

Write a program that advises the mayor which bridges are no alternative bridges for the given input.

Input

The input consists of a single test case.

$N$ $M$

$S_1$ $D_1$ $C_1$

.

.

.

$S_M$ $D_M$ $C_M$

The first line contains two positive integers $N$ and $M$. $N$ represents the number of islands and each island is identified by an integer 1 through $N$. $M$ represents the number of the pairs of islands between which a bridge may be built.

Each line of the next $M$ lines contains three integers $S_i$, $D_i$ and $C_i$ ($1 \leq i \leq M$) which represent that it will cost $C_i$ to build the bridge between islands $S_i$ and $D_i$. You may assume $3 \leq N \leq 500$, $N − 1 \leq M \leq min(50000, N(N − 1)/2)$, $1 \leq S_i < D_i \leq N$, and $1 \leq C_i \leq 10000$. No two bridges connect the same pair of two islands, that is, if $i \ne j$ and $S_i = S_j$, then $D_i \ne D_j$ . If all the candidate bridges are built, all the islands are reachable from any other islands via one or more bridges.

Output

Output two integers, which mean the number of no alternative bridges and the sum of their construction cost, separated by a space.

Sample Input 1

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

Sample Output 1

1 3

Sample Input 2

4 4
1 2 3
1 3 5
2 3 3
2 4 3

Sample Output 2

3 9

Sample Input 3

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

Sample Output 3

2 4

Sample Input 4

3 3
1 2 1
2 3 1
1 3 1

Sample Output 4

0 0
Problem G:
Flipping Parentheses

A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following.

A string "()" is balanced.

Concatenation of two balanced strings are balanced.

When a string $s$ is balanced, so is the concatenation of three strings "(", $s$, and ")" in this order.

Note that the condition is stronger than merely the numbers of '(' and ')' are equal. For instance, "())(()" is not balanced.

Your task is to keep a string in a balanced state, under a severe condition in which a cosmic ray may flip the direction of parentheses.

You are initially given a balanced string. Each time the direction of a single parenthesis is flipped, your program is notified the position of the changed character in the string. Then, calculate and output the leftmost position that, if the parenthesis there is flipped, the whole string gets back to the balanced state. After the string is balanced by changing the parenthesis indicated by your program, next cosmic ray flips another parenthesis, and the steps are repeated several times.

Input

The input consists of a single test case formatted as follows.

$N$ $Q$

$s$

$q_1$

.

.

.

$q_Q$

The first line consists of two integers $N$ and $Q$ ($2 \leq N \leq 300000$, $1 \leq Q \leq 150000$). The second line is a string $s$ of balanced parentheses with length $N$. Each of the following $Q$ lines is an integer $q_i$ ($1 \leq q_i \leq N$) that indicates that the direction of the $q_i$-th parenthesis is flipped.

Output

For each event $q_i$, output the position of the leftmost parenthesis you need to flip in order to get back to the balanced state.

Note that each input flipping event $q_i$ is applied to the string after the previous flip $q_{i−1}$ and its fix.

Sample Input 1

6 3
((()))
4
3
1

Sample Output 1

2
2
1

Sample Input 2

20 9
()((((()))))()()()()
15
20
13
5
3
10
3
17
18

Sample Output 2

2
20
8
5
3
2
2
3
18

In the first sample, the initial state is "((()))". The 4th parenthesis is flipped and the string becomes "(((())". Then, to keep the balance you should flip the 2nd parenthesis and get "()(())". The next flip of the 3rd parenthesis is applied to the last state and yields "())())". To rebalance it, you have to change the 2nd parenthesis again yielding "(()())".
Problem H:
Cornering at Poles

You are invited to a robot contest. In the contest, you are given a disc-shaped robot that is placed on a flat field. A set of poles are standing on the ground. The robot can move in all directions, but must avoid the poles. However, the robot can make turns around the poles touching them.

Your mission is to find the shortest path of the robot to reach the given goal position. The length of the path is defined by the moving distance of the center of the robot. Figure H.1 shows the shortest path for a sample layout. In this figure, a red line connecting a pole pair means that the distance between the poles is shorter than the diameter of the robot and the robot cannot go through between them.

Figure H.1. The shortest path for a sample layout

Input

The input consists of a single test case.

$N$ $G_x$ $G_y$

$x_1$ $y_1$

.

.

.

$x_N$ $y_N$

The first line contains three integers. $N$ represents the number of the poles ($1 \leq N \leq 8$). $(G_x, G_y)$ represents the goal position. The robot starts with its center at $(0, 0)$, and the robot accomplishes its task when the center of the robot reaches the position $(G_x, G_y)$. You can assume that the starting and goal positions are not the same.

Each of the following $N$ lines contains two integers. $(x_i, y_i)$ represents the standing position of the $i$-th pole. Each input coordinate of $(G_x, G_y)$ and $(x_i, y_i)$ is between $−1000$ and $1000$, inclusive. The radius of the robot is $100$, and you can ignore the thickness of the poles. No pole is standing within a $100.01$ radius from the starting or goal positions. For the distance $d_{i,j}$ between the $i$-th and $j$-th poles $(i \ne j)$, you can assume $1 \leq d_{i,j} < 199.99$ or $200.01 < d_{i,j}$.

Figure H.1 shows the shortest path for Sample Input 1 below, and Figure H.2 shows the shortest paths for the remaining Sample Inputs.

Figure H.2. The shortest paths for the sample layouts

Output

Output the length of the shortest path to reach the goal. If the robot cannot reach the goal, output 0.0. The output should not contain an error greater than 0.0001.

Sample Input 1

8 900 0
40 100
70 -80
350 30
680 -20
230 230
300 400
530 130
75 -275

Sample Output 1

1210.99416

Sample Input 2

1 0 200
120 0

Sample Output 2

200.0

Sample Input 3

3 110 110
0 110
110 0
200 10

Sample Output 3

476.95048

Sample Input 4

4 0 200
90 90
-90 90
-90 -90
90 -90

Sample Output 4

0.0

Sample Input 5

2 0 -210
20 -105
-5 -105

Sample Output 5

325.81116

Sample Input 6

8 680 -50
80 80
80 -100
480 -120
-80 -110
240 -90
-80 100
-270 100
-420 -20

Sample Output 6

1223.53071
Problem J:
Exhibition

The city government is planning an exhibition and collecting industrial products. There are $n$ candidates of industrial products for the exhibition, and the city government decided to choose $k$ of them. They want to minimize the total price of the $k$ products. However, other criteria such as their sizes and weights should be also taken into account. To address this issue, the city government decided to use the following strategy: The $i$-th product has three parameters, price, size, and weight, denoted by $x_i$, $y_i$, and $z_i$, respectively. Then, the city government chooses $k$ items $i_1, . . . , i_k$ ($1 \leq i_j \leq n$) that minimizes the evaluation measure

\[
e = (\sum^k_{j=1}x_{ij}) (\sum^k_{j=1}y_{ij}) (\sum^k_{j=1}z_{ij}),
\]

which incorporates the prices, the sizes, and the weights of products. If there are two or more choices that minimize $e$, the government chooses one of them uniformly at random.

You are working for the company that makes the product 1. The company has decided to cut the price, reduce the size, and/or reduce the weight of the product so that the city government may choose the product of your company, that is, to make the probability of choosing the product positive. We have three parameters $A$, $B$, and $C$. If we want to reduce the price, size, and weight to $(1 − \alpha)x_1$, $(1 − \beta)y_1$, and $(1 − \gamma)z_1$ ($0 \leq \alpha, \beta, \gamma \leq 1$), respectively, then we have to invest $\alpha A + \beta B + \gamma C$ million yen. We note that the resulting price, size, and weight do not have to be integers. Your task is to compute the minimum investment required to make the city government possibly choose the product of your company. You may assume that employees of all the other companies are too lazy to make such an effort.

Input

The input consists of a single test case with the following format.

$n$ $k$ $A$ $B$ $C$

$x_1$ $y_1$ $z_1$

$x_2$ $y_2$ $z_2$

.

.

.

$x_n$ $y_n$ $z_n$

The first line contains five integers. The integer $n$ ($1 \leq n \leq 50$) is the number of industrial products, and the integer $k$ ($1 \leq k \leq n$) is the number of products that will be chosen by the city government. The integers $A$, $B$, $C$ ($1 \leq A, B, C \leq 100$) are the parameters that determine the cost of changing the price, the size, and the weight, respectively, of the product 1.

Each of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ ($1 \leq x_i, y_i, z_i \leq 100$), which are the price, the size, and the weight, respectively, of the $i$-th product.

Output

Output the minimum cost (in million yen) in order to make the city government possibly choose the product of your company. The output should not contain an absolute error greater than $10^{−4}$.

Sample Input 1

6 5 1 2 3
5 5 5
1 5 5
2 5 4
3 5 3
4 5 2
5 5 1

Sample Output 1

0.631579

Sample Input 2

6 1 1 2 3
10 20 30
1 2 3
2 4 6
3 6 9
4 8 12
5 10 15

Sample Output 2

0.999000