alexjercan/bugnet huggingface dataset:
Dock to the Future

You had long wanted a spaceship, and finally you bought a used one yesterday! You have heard that the most
difficult thing on spaceship driving is to stop your ship at the right position in the dock. Of course you are no
exception. After a dozen of failures, you gave up doing all the docking process manually. You began to write a
simple program that helps you to stop a spaceship.

First, you somehow put the spaceship on the straight course to the dock manually. Let the distance to the limit
line be x[m], and the speed against the dock be v[m/s]. Now you turn on the decelerating rocket. Then, your
program will control the rocket to stop the spaceship at the best position.

Your spaceship is equipped with a decelerating rocket with n modes. When the spaceship is in mode-i (0 ≤ i < n),
the deceleration rate is ai[m/s2]. You cannot re-accelerate the spaceship. The accelerating rocket is too powerful
to be used during docking. Also, you cannot turn off-and-on the decelerating rocket, because your spaceship is a
used and old one, once you stopped the rocket, it is less certain whether you can turn it on again. In other words,
the time you turn off the rocket is the time you stop your spaceship at the right position.

After turning on the deceleration rocket, your program can change the mode or stop the rocket at every sec-
ond, starting at the very moment the deceleration began. Given x and v, your program have to make a plan of
deceleration. The purpose and the priority of your program is as follows:

Stop the spaceship exactly at the limit line. If this is possible, print “perfect”.

If it is impossible, then stop the spaceship at the position nearest possible to the limit line, but before the
line. In this case, print “good d”, where d is the distance between the limit line and the stopped position.
Print three digits after the decimal point.

If it is impossible again, decelerate the spaceship to have negative speed, and print “try again”.

If all of these three cases are impossible, then the spaceship cannot avoid overrunning the limit line. In this
case, print “crash”.

Input

The first line of the input consists of a single integer c, the number of test cases.

Each test case begins with a single integer n (1 ≤ n ≤ 10), the number of deceleration modes. The following line
contains n positive integers a0, . . . , an-1 (1 ≤ ai ≤ 100), each denoting the deceleration rate of each mode.

The next line contains a single integer q (1 ≤ q ≤ 20), and then q lines follow. Each of them contains two positive
integers x and v (1 ≤ x, v ≤ 100) defined in the problem statement.

Output

For each pair of x and v, print the result in one line. A blank line should be inserted between the test cases.

Sample Input

1
3
2 4 6
4
10 100
2 3
10 6
7 6

Output for the Sample Input

crash
try again
good 1.000
perfect
Flame of Nucleus

Year 20XX — a nuclear explosion has burned the world. Half the people on the planet have died. Fearful.

One city, fortunately, was not directly damaged by the explosion. This city consists of N domes (numbered 1
through N inclusive) and M bidirectional transportation pipelines connecting the domes. In dome i, Pi citizens
reside currently and there is a nuclear shelter capable of protecting Ki citizens. Also, it takes Di days to travel
from one end to the other end of pipeline i.

It has been turned out that this city will be polluted by nuclear radiation in L days after today. So each citizen
should take refuge in some shelter, possibly traveling through the pipelines. Citizens will be dead if they reach
their shelters in exactly or more than L days.

How many citizens can survive at most in this situation?

Input

The input consists of multiple test cases. Each test case begins with a line consisting of three integers N, M
and L (1 ≤ N ≤ 100, M ≥ 0, 1 ≤ L ≤ 10000). This is followed by M lines describing the configuration of
transportation pipelines connecting the domes. The i-th line contains three integers Ai, Bi and Di (1 ≤ Ai < Bi ≤
N, 1 ≤ Di ≤ 10000), denoting that the i-th pipeline connects dome Ai and Bi. There is at most one pipeline
between any pair of domes. Finally, there come two lines, each consisting of N integers. The first gives P1 , . . .,
PN (0 ≤ Pi ≤ 106) and the second gives K1 , . . ., KN (0 ≤ Ki ≤ 106).

The input is terminated by EOF. All integers in each line are separated by a whitespace.

Output

For each test case, print in a line the maximum number of people who can survive.

Sample Input

1 0 1
51
50
2 1 1
1 2 1
1000 0
0 1000
4 3 5
1 2 4
1 3 1
3 4 2
0 1000 1000 1000
3000 0 0 0

Output for the Sample Input

50
0
3000
Problem A: Dance Dance Revolution

Dance Dance Revolution is one of the most popular arcade games in Japan. The rule of this game is very
simple. A series of four arrow symbols, up, down, left and right, flows downwards on the screen in time
to music. The machine has four panels under your foot, each of which corresponds to one of the four
arrows, and you have to make steps on these panels according to the arrows displayed on the screen. The
more accurate in timing, the higher score you will mark.

Figure 1: Layout of Arrow Panels and Screen

Each series of arrows is commonly called a score. Difficult scores usually have hundreds of arrows, and
newbies will often be scared when seeing those arrows fill up the monitor screen. Conversely, scores
with fewer arrows are considered to be easy ones.

One day, a friend of yours, who is an enthusiast of this game, asked you a favor. What he wanted is an
automated method to see if given scores are natural. A score is considered as natural when there is a
sequence of steps that meets all the following conditions:

left-foot steps and right-foot steps appear in turn;

the same panel is not stepped on any two consecutive arrows;

a player can keep his or her upper body facing forward during a play; and

his or her legs never cross each other.

Your task is to write a program that determines whether scores are natural ones.

Input

The first line of the input contains a positive integer. This indicates the number of data sets.

Each data set consists of a string written in a line. Each string is made of four letters, “U” for up, “D”
for down, “L” for left and “R” for right, and specifies arrows in a score. No string contains more than
100,000 characters.

Output

For each data set, output in a line “Yes” if the score is natural, or “No” otherwise.

Sample Input

3
UU
RDUL
ULDURDULDURDULDURDULDURD

Output for the Sample Input

No
Yes
Yes
Problem B: Compress Files

Your computer is a little old-fashioned. Its CPU is slow, its memory is not enough, and its hard drive is
near to running out of space. It is natural for you to hunger for a new computer, but sadly you are not so
rich. You have to live with the aged computer for a while.

At present, you have a trouble that requires a temporary measure immediately. You downloaded a new
software from the Internet, but failed to install due to the lack of space. For this reason, you have decided
to compress all the existing files into archives and remove all the original uncompressed files, so more
space becomes available in your hard drive.

It is a little complicated task to do this within the limited space of your hard drive. You are planning to
make free space by repeating the following three-step procedure:

Choose a set of files that have not been compressed yet.

Compress the chosen files into one new archive and save it in your hard drive. Note that this step
needs space enough to store both of the original files and the archive in your hard drive.

Remove all the files that have been compressed.

For simplicity, you don’t take into account extraction of any archives, but you would like to reduce the
number of archives as much as possible under this condition. Your task is to write a program to find the
minimum number of archives for each given set of uncompressed files.

Input

The input consists of multiple data sets.

Each data set starts with a line containing two integers n (1 ≤ n ≤ 14) and m (1 ≤ m ≤ 1000), where
n indicates the number of files and m indicates the available space of your hard drive before the task of
compression. This line is followed by n lines, each of which contains two integers bi and ai. bi indicates
the size of the i-th file without compression, and ai indicates the size when compressed. The size of each
archive is the sum of the compressed sizes of its contents. It is guaranteed that bi ≥ ai holds for any
1 ≤ i ≤ n.

A line containing two zeros indicates the end of input.

Output

For each test case, print the minimum number of compressed files in a line. If you cannot compress all
the files in any way, print “Impossible” instead.

Sample Input

6 1
2 1
2 1
2 1
2 1
2 1
5 1
1 1
4 2
0 0

Output for the Sample Input

2
Impossible
Problem C: Save the Energy

You were caught in a magical trap and transferred to a strange field due to its cause. This field is three-
dimensional and has many straight paths of infinite length. With your special ability, you found where
you can exit the field, but moving there is not so easy. You can move along the paths easily without your
energy, but you need to spend your energy when moving outside the paths. One unit of energy is required
per distance unit. As you want to save your energy, you have decided to find the best route to the exit
with the assistance of your computer.

Your task is to write a program that computes the minimum amount of energy required to move between
the given source and destination. The width of each path is small enough to be negligible, and so is your
size.

Input

The input consists of multiple data sets. Each data set has the following format:

N
xs ys zs xt yt zt
x1,1 y1,1 z1,1 x1,2 y1,2 z1,2
.
.
.
xN,1 yN,1 zN,1 xN,2 yN,2 zN,2

N is an integer that indicates the number of the straight paths (2 ≤ N ≤ 100). (xs, ys, zs) and (xt, yt, zt)
denote the coordinates of the source and the destination respectively. (xi,1, yi,1, zi,1) and (xi,2, yi,2, zi,2)
denote the coordinates of the two points that the i-th straight path passes. All coordinates do not exceed 30,000 in their absolute values.

The distance units between two points (xu, yu, zu) and (xv, yv, zv) is given by the Euclidean distance as follows:

It is guaranteed that the source and the destination both lie on paths. Also, each data set contains no
straight paths that are almost but not actually parallel, although may contain some straight paths that are
strictly parallel.

The end of input is indicated by a line with a single zero. This is not part of any data set.

Output

For each data set, print the required energy on a line. Each value may be printed with an arbitrary number
of decimal digits, but should not contain the error greater than 0.001.

Sample Input

2
0 0 0 0 2 0
0 0 1 0 0 -1
2 0 0 0 2 0
3
0 5 0 3 1 4
0 1 0 0 -1 0
1 0 1 -1 0 1
3 1 -1 3 1 1
2
0 0 0 3 0 0
0 0 0 0 1 0
3 0 0 3 1 0
0

Output for the Sample Input

1.414
2.000
3.000
Problem D: Goofy Converter

Nathan O. Davis is a student at the department of integrated systems. He is now taking a class in in-
tegrated curcuits. He is an idiot. One day, he got an assignment as follows: design a logic circuit that
takes a sequence of positive integers as input, and that outputs a sequence of 1-bit integers from which
the original input sequence can be restored uniquely.

Nathan has no idea. So he searched for hints on the Internet, and found several pages that describe the
1-bit DAC. This is a type of digital-analog converter which takes a sequence of positive integers as input,
and outputs a sequence of 1-bit integers.

Seeing how 1-bit DAC works on these pages, Nathan came up with a new idea for the desired converter.
His converter takes a sequence L of positive integers, and a positive integer M aside from the sequence,
and outputs a sequence K of 1-bit integers such that:

He is not so smart, however. It is clear that his converter does not work for some sequences. Your task is
to write a program in order to show the new converter cannot satisfy the requirements of his assignment,
even though it would make Nathan in despair.

Input

The input consists of a series of data sets. Each data set is given in the following format:

N M
L0 L1 . . . LN-1

N is the length of the sequence L. M and L are the input to Nathan’s converter as described above. You
may assume the followings: 1 ≤ N ≤ 1000, 1 ≤ M ≤ 12, and 0 ≤ Lj ≤ M for j = 0, . . . , N - 1.

The input is terminated by N = M = 0.

Output

For each data set, output a binary sequence K of the length (N + M - 1) if there exists a sequence which
holds the equation mentioned above, or “Goofy” (without quotes) otherwise. If more than one sequence
is possible, output any one of them.

Sample Input

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

Output for the Sample Input

1111001
Goofy
Problem E: Black Force

A dam construction project was designed around an area called Black Force. The area is surrounded by
mountains and its rugged terrain is said to be very suitable for constructing a dam.

However, the project is now almost pushed into cancellation by a strong protest campaign started by the
local residents. Your task is to plan out a compromise proposal. In other words, you must find a way to
build a dam with sufficient capacity, without destroying the inhabited area of the residents.

The map of Black Force is given as H × W cells (0 < H, W ≤ 20). Each cell hi, j is a positive integer
representing the height of the place. The dam can be constructed at a connected region surrounded
by higher cells, as long as the region contains neither the outermost cells nor the inhabited area of the
residents. Here, a region is said to be connected if one can go between any pair of cells in the region
by following a sequence of left-, right-, top-, or bottom-adjacent cells without leaving the region. The
constructed dam can store water up to the height of the lowest surrounding cell. The capacity of the dam
is the maximum volume of water it can store. Water of the depth of 1 poured to a single cell has the
volume of 1.

The important thing is that, in the case it is difficult to build a sufficient large dam, it is allowed to
choose (at most) one cell and do groundwork to increase the height of the cell by 1 unit. Unfortunately,
considering the protest campaign, groundwork of larger scale is impossible. Needless to say, you cannot
do the groundwork at the inhabited cell.

Given the map, the required capacity, and the list of cells inhabited, please determine whether it is possible
to construct a dam.

Input

The input consists of multiple data sets. Each data set is given in the following format:

H W C R
h1,1 h1,2 . . . h1,W
...
hH,1 hH,2 . . . hH,W
y1 x1
...
yR xR

H and W is the size of the map. is the required capacity. R (0 < R < H × W) is the number of cells
inhabited. The following H lines represent the map, where each line contains W numbers separated by
space. Then, the R lines containing the coordinates of inhabited cells follow. The line “y x” means that
the cell hy,x is inhabited.

The end of input is indicated by a line “0 0 0 0”. This line should not be processed.

Output

For each data set, print “Yes” if it is possible to construct a dam with capacity equal to or more than C.
Otherwise, print “No”.

Sample Input

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

Output for the Sample Input

Yes
No
No
No
Yes
Problem A: Hit and Blow

Hit and blow is a popular code-breaking game played by two people, one codemaker and one
codebreaker. The objective of this game is that the codebreaker guesses correctly a secret
number the codemaker makes in his or her mind.

The game is played as follows. The codemaker first chooses a secret number that consists of
four different digits, which may contain a leading zero. Next, the codebreaker makes the first
attempt to guess the secret number. The guessed number needs to be legal (i.e. consist of four
different digits). The codemaker then tells the numbers of hits and blows to the codebreaker.
Hits are the matching digits on their right positions, and blows are those on different positions.
For example, if the secret number is 4321 and the guessed is 2401, there is one hit and two blows
where 1 is a hit and 2 and 4 are blows. After being told, the codebreaker makes the second
attempt, then the codemaker tells the numbers of hits and blows, then the codebreaker makes
the third attempt, and so forth. The game ends when the codebreaker gives the correct number.

Your task in this problem is to write a program that determines, given the situation, whether
the codebreaker can logically guess the secret number within the next two attempts. Your
program will be given the four-digit numbers the codebreaker has guessed, and the responses
the codemaker has made to those numbers, and then should make output according to the
following rules:

if only one secret number is possible, print the secret number;

if more than one secret number is possible, but there are one or more critical numbers,
print the smallest one;

otherwise, print “????” (four question symbols).

Here, critical numbers mean those such that, after being given the number of hits and blows for
them on the next attempt, the codebreaker can determine the secret number uniquely.

Input

The input consists of multiple data sets. Each data set is given in the following format:

N
four-digit-number1 n-hits1 n-blows1
...
four-digit-numberN n-hitsN n-blowsN

N is the number of attempts that has been made. four-digit-numberi is the four-digit number
guessed on the i-th attempt, and n-hitsi and n-blowsi are the numbers of hits and blows for that
number, respectively. It is guaranteed that there is at least one possible secret number in each
data set.

The end of input is indicated by a line that contains a zero. This line should not be processed.

Output

For each data set, print a four-digit number or “????” on a line, according to the rules stated
above.

Sample Input

2
1234 3 0
1245 3 0
1
1234 0 0
2
0123 0 4
1230 0 4
0

Output for the Sample Input

1235
????
0132
Problem C: !

You are one of ICPC participants and in charge of developing a library for multiprecision numbers
and radix conversion. You have just finished writing the code, so next you have to test if it
works correctly. You decided to write a simple, well-known factorial function for this purpose:

Your task is to write a program that shows the number of trailing zeros when you compute M!
in base N, given N and M.

Input

The input contains multiple data sets. Each data set is described by one line in the format
below:

N M

where N is a decimal number between 8 and 36 inclusive, and M is given in the string repre-
sentation in base N. Exactly one white space character appears between them.

The string representation of M contains up to 12 characters in base N. In case N is greater
than 10, capital letters A, B, C, ... may appear in the string representation, and they represent
10, 11, 12, ..., respectively.

The input is terminated by a line containing two zeros. You should not process this line.

Output

For each data set, output a line containing a decimal integer, which is equal to the number of
trailing zeros in the string representation of M! in base N.

Sample Input

10 500
16 A
0 0

Output for the Sample Input

124
2
Problem E: Spirograph

Some of you might have seen instruments like the figure below.

Figure 1: Spirograph

There are a fixed circle (indicated by A in the figure) and a smaller interior circle with some
pinholes (indicated by B). By putting a pen point through one of the pinholes and then rolling
the circle B without slipping around the inside of the circle A, we can draw curves as illustrated
below. Such curves are called hypotrochoids.

Figure 2: An Example Hypotrochoid

Your task is to write a program that calculates the length of hypotrochoid, given the radius of
the fixed circle A, the radius of the interior circle B, and the distance between the B’s centroid and the used pinhole.

Input

The input consists of multiple test cases. Each test case is described by a single line in which
three integers P, Q and R appear in this order, where P is the radius of the fixed circle A, Q
is the radius of the interior circle B, and R is the distance between the centroid of the circle B
and the pinhole. You can assume that 0 ≤ R < Q < P ≤ 1000. P, Q, and R are separated by
a single space, while no other spaces appear in the input.

The end of input is indicated by a line with P = Q = R = 0.

Output

For each test case, output the length of the hypotrochoid curve. The error must be within
10-2 (= 0.01).

Sample Input

3 2 1
3 2 0
0 0 0

Output for the Sample Input

13.36
6.28
Problem F: Mysterious Dungeons

The Kingdom of Aqua Canora Mystica is a very affluent and peaceful country, but around the
kingdom, there are many evil monsters that kill people. So the king gave an order to you to kill
the master monster.

You came to the dungeon where the monster lived. The dungeon consists of a grid of square
cells. You explored the dungeon moving up, down, left and right. You finally found, fought
against, and killed the monster.

Now, you are going to get out of the dungeon and return home. However, you found strange
carpets and big rocks are placed in the dungeon, which were not there until you killed the
monster. They are caused by the final magic the monster cast just before its death! Every rock
occupies one whole cell, and you cannot go through that cell. Also, each carpet covers exactly
one cell. Each rock is labeled by an uppercase letter and each carpet by a lowercase. Some of
the rocks and carpets may have the same label.

While going around in the dungeon, you observed the following behaviors. When you enter
into the cell covered by a carpet, all the rocks labeled with the corresponding letter (e.g., the
rocks with ‘A’ for the carpets with ‘a’) disappear. After the disappearance, you can enter the
cells where the rocks disappeared, but if you enter the same carpet cell again or another carpet
cell with the same label, the rocks revive and prevent your entrance again. After the revival,
you have to move on the corresponding carpet cell again in order to have those rocks disappear
again.

Can you exit from the dungeon? If you can, how quickly can you exit? Your task is to write
a program that determines whether you can exit the dungeon, and computes the minimum
required time.

Input

The input consists of some data sets.

Each data set begins with a line containing two integers, W and H (3 ≤ W, H ≤ 30). In each
of the following H lines, there are W characters, describing the map of the dungeon as W × H
grid of square cells. Each character is one of the following:

‘@’ denoting your current position,

‘<’ denoting the exit of the dungeon,

A lowercase letter denoting a cell covered by a carpet with the label of that letter,

An uppercase letter denoting a cell occupied by a rock with the label of that letter,

‘#’ denoting a wall, and

‘.’ denoting an empty cell.

Every dungeon is surrounded by wall cells (‘#’), and has exactly one ‘@’ cell and one ‘<’ cell.
There can be up to eight distinct uppercase labels for the rocks and eight distinct lowercase
labels for the carpets.

You can move to one of adjacent cells (up, down, left, or right) in one second. You cannot move
to wall cells or the rock cells.

A line containing two zeros indicates the end of the input, and should not be processed.

Output

For each data set, output the minimum time required to move from the ‘@’ cell to the ‘<’ cell,
in seconds, in one line. If you cannot exit, output -1.

Sample Input

8 3
########
#<A.@.a#
########
8 3
########
#<AaAa@#
########
8 4
########
#<EeEe@#
#FG.e#.#
########
8 8
########
#mmm@ZZ#
#mAAAbZ#
#mABBBZ#
#mABCCd#
#aABCDD#
#ZZcCD<#
########
0 0

Output for the Sample Input

7
-1
7
27