alexjercan/bugnet huggingface dataset:
Problem E: Huge Family

Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious personality and are close each other.

They usually communicate by a phone. Of course, They are all taking a family plan. This family plan is such a thing: when a choose b, and b choose a as a partner, a family plan can be applied between them and then the calling fee per unit time between them discounted to f(a, b), which is cheaper than a default fee. Each person can apply a family plan at most 2 times, but no same pair of persons can apply twice. Now, choosing their partner appropriately, all members of Mr. Dango's family applied twice.

Since there are huge number of people, it is very difficult to send a message to all family members by a phone call. Mr. Dang have decided to make a phone calling network that is named 'clan' using the family plan. Let us present a definition of clan.

Let S be an any subset of all phone calls that family plan is applied. Clan is S such that:

For any two persons (let them be i and j), if i can send a message to j through phone calls that family plan is applied (directly or indirectly), then i can send a message to j through only phone calls in S (directly or indirectly).

Meets condition 1 and a sum of the calling fee per unit time in S is minimized.

Clan allows to send a message efficiently. For example, we suppose that one have sent a message through all calls related to him in the clan. Additionaly we suppose that every people follow a rule, "when he/she receives a message through a call in clan, he/she relays the message all other neibors in respect to clan." Then, we can prove that this message will surely be derivered to every people that is connected by all discounted calls, and that the message will never be derivered two or more times to same person.

By the way, you are given information about application of family plan of Mr. Dango's family. Please write a program that calculates that in how many ways a different clan can be constructed. You should output the answer modulo 10007 because it may be very big.

Input

The input consists of several datasets.

The first line of each dataset contains an integer n, which indicates the number of members in the family.

Next n lines represents information of the i-th member with four integers. The first two integers respectively represent b[0] (the partner of i) and f(i, b[0]) (the calling fee per unit time between i and b[0]). The following two integers represent b[1] and f(i, b[1]) in the same manner.

Input terminates with a dataset where n = 0.

Output

For each dataset, output the number of clan modulo 10007.

Constraints

3 ≤ n ≤ 100,000

Sample Input

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

Output for the Sample Input

1
2
Problem F: Ben Toh

As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes.

A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job.

Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%.

He continue to go to supermaket and try to get the discounted box lunch for n days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.

Input

Input consists of several datasets.

Input for a single dataset is given as a single integer n.

Input terminates with a dataset where n = 0.

Output

For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.

Constraints

1 ≤ n ≤ 100,000

Sample Input

1
2
3
0

Output for the Sample Input

1.00000000
1.50000000
2.12500000
Problem G: Rolling Dice

The north country is conquered by the great shogun-sama (which means
king). Recently many beautiful dice which were made by order of the
great shogun-sama were given to all citizens of the country. All
citizens received the beautiful dice with a tear of delight. Now they
are enthusiastically playing a game with the dice.

The game is played on grid of h * w cells that each of which has a
number, which is designed by the great shogun-sama's noble philosophy.
A player put his die on a starting cell and move it to a destination
cell with rolling the die. After rolling the die once, he takes a
penalty which is multiple of the number written on current cell and
the number printed on a bottom face of the die, because of malicious
conspiracy of an enemy country. Since the great shogun-sama strongly
wishes, it is decided that the beautiful dice are initially put so
that 1 faces top, 2 faces south, and 3 faces east. You will find that
the number initially faces north is 5, as sum of numbers on opposite
faces of a die is always 7. Needless to say, idiots those who move his
die outside the grid are punished immediately.

The great shogun-sama is pleased if some citizens can move the
beautiful dice with the least penalty when a grid and a starting cell
and a destination cell is given. Other citizens should be sent to coal
mine (which may imply labor as slaves). Write a program so that
citizens can deal with the great shogun-sama's expectations.

Input

The first line of each data set has two numbers h and w, which stands
for the number of rows and columns of the grid.

Next h line has w integers, which stands for the number printed on the
grid. Top-left corner corresponds to northwest corner.

Row number and column number of the starting cell are given in the
following line, and those of the destination cell are given in the next
line. Rows and columns are numbered 0 to h-1, 0 to w-1, respectively.

Input terminates when h = w = 0.

Output

For each dataset, output the least penalty.

Constraints

1 ≤ h, w ≤ 10

0 ≤ number assinged to a cell ≤ 9

the start point and the goal point are different.

Sample Input

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

Output for the Sample Input

24
19
17
6
21
Problem H: Winter Bells

The best night ever in the world has come! It's 8 p.m. of December 24th, yes, the night of Cristmas Eve. Santa Clause comes to a silent city with ringing bells. Overtaking north wind, from a sleigh a reindeer pulls she shoot presents to soxes hanged near windows for children.

The sleigh she is on departs from a big christmas tree on the fringe of the city. Miracle power that the christmas tree spread over the sky like a web and form a paths that the sleigh can go on. Since the paths with thicker miracle power is easier to go, these paths can be expressed as undirected weighted graph.

Derivering the present is very strict about time. When it begins dawning the miracle power rapidly weakens and Santa Clause can not continue derivering any more. Her pride as a Santa Clause never excuses such a thing, so she have to finish derivering before dawning.

The sleigh a reindeer pulls departs from christmas tree (which corresponds to 0th node), and go across the city to the opposite fringe (n-1 th node) along the shortest path. Santa Clause create presents from the miracle power and shoot them from the sleigh the reindeer pulls at his full power. If there are two or more shortest paths, the reindeer selects one of all shortest paths with equal probability and go along it.

By the way, in this city there are p children that wish to see Santa Clause and are looking up the starlit sky from their home. Above the i-th child's home there is a cross point of the miracle power that corresponds to c[i]-th node of the graph. The child can see Santa Clause if (and only if) Santa Clause go through the node.

Please find the probability that each child can see Santa Clause.

Input

Input consists of several datasets.

The first line of each dataset contains three integers n, m, p, which means the number of nodes and edges of the graph, and the number of the children. Each node are numbered 0 to n-1.

Following m lines contains information about edges. Each line has three integers. The first two integers means nodes on two endpoints of the edge. The third one is weight of the edge.

Next p lines represent c[i] respectively.

Input terminates when n = m = p = 0.

Output

For each dataset, output p decimal values in same order as input. Write a blank line after that.

You may output any number of digit and may contain an error less than 1.0e-6.

Constraints

3 ≤ n ≤ 100

There are no parallel edges and a edge whose end points are identical.

0 < weight of the edge < 10000

Sample Input

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

Output for the Sample Input

1.00000000

0.50000000
0.50000000
Problem I: Mysterious Onslaught

In 2012, human beings have been exposed to fierce onslaught of unidentified mysterious extra-terrestrial creatures. We have exhaused because of the long war and can't regist against them any longer. Only you, an excellent wizard, can save us. Yes, it's time to stand up!

The enemies are dispatched to the earth with being aligned like an n * n square. Appearently some of them have already lost their fighting capabilities for some unexpected reason. You have invented a highest grade magic spell 'MYON' to defeat them all. An attack of this magic covers any rectangles (which is parallel to axis). Once you cast a spell "myon," then all the enemies which the magic covers will lose their fighting capabilities because of tremendous power of the magic. However, the magic seems to activate enemies' self-repairing circuit. Therefore if any enemy which have already lost its fighting capability is exposed to the magic, the enemy repossesses its fighting capability. You will win the war when all the enemies will lose their fighting capabilities.

Let me show an example. An array of enemies below have dispatched:

1 1 1 1 1
1 0 0 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 1

Here, '0' means an enemy that doesn't possess fighting capability, and '1' means an enemy that possesses.
First, you cast a spell "myon" with covering all the enemies, which results in;

0 0 0 0 0
0 1 1 1 0
0 1 0 1 0
0 1 1 1 0
0 0 0 0 0

Next, cast once again with covering central 3 * 3 enemies.

0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0

Now you can defeat them all by casting a spell covers remaining one. Therefore you can cast "myonmyonmyon," which is the shortest spell for this case.

You are given the information of the array. Please write a program that generates the shortest spell that can defeat them all.

Input

The first line of each test case has an integer n. Following n lines are information of an array of enemies. The format is same as described in the problem statement.

Input terminates when n = 0.
You may assume that one or more enemy have fighting capability.

Output

For each dataset, output the shortest spell.

Constraints

1 ≤ n ≤ 5

Sample Input

5
1 1 1 1 1
1 0 0 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 1
3
1 1 1
1 1 1
1 1 1
5
1 1 1 1 0
1 1 1 1 0
1 0 0 0 1
0 1 1 1 1
0 1 1 1 1
0

Output for the Sample Input

myonmyonmyon
myon
myonmyon
Problem J: No Story

Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer L, how many pairs of positive integers a, b (a ≤ b) such that LCM(a, b) = L are there? Here, LCM(a, b) stands for the least common multiple of a and b.

Input

For each dataset, an integer L is given in a line. Input terminates when L = 0.

Output

For each dataset, output the number of pairs of a and b.

Constraints

1 ≤ L ≤ 1012

Sample Input

12
9
2
0

Output for the Sample Input

8
3
2
Problem A: It's our delight!!

You are a student of University of Aizu.
And you work part-time at a restaurant.

Staffs of the restaurant are well trained to be delighted to provide more delicious products faster.

The speed providing products particularly depends on skill of the staff.
So, the manager of the restaurant want to know how long it takes to provide products.

Though some restaurants employ a system which calculates how long it takes to provide products automatically,
the restaurant where you work employs a system which calculates it manually.

You, a student of University of Aizu, want to write a program to calculate it, and you hope that your program makes the task easier.
You are given the checks in a day.
If the length of time it takes to provide the products of a check is shorter than or equal to 8 minutes, it is "ok" check.
Write a program to output the ratio of "ok" checks to the total in percentage.

Input

The input consists of multiple datasets.
The last dataset is followed by a line containing a single zero.
You don't have to process this data.
The first line of each dataset contains a single integer n.

n (0 < n ≤ 100) is the number of checks.
Each of following n lines gives the details of a check in the following format.

hh:mm MM

hh:mm is the clock time to print the check.
MM is minute of the clock time to provide products.
The clock time is expressed according to the 24 hour clock.

For example, "eleven one PM" is expressed by "23:01".

You can assume that the all of products are provided within fifteen minutes.
The restaurant is open from AM 11:00 to AM 02:00.
After AM 02:00, no check is printed.
Also at AM 02:00, no check is printed.

Output

Your program has to print in the following format for each dataset.

lunch L
dinner D
midnight M

L is ratio of "ok" check printed to the total in lunch time.
D is ratio of "ok" check printed to the total in dinner time.
M is ratio of "ok" check printed to the total in midnight time.
You can truncate digits number after the decimal point of the ratio on the percentage. Lunch, dinner, and midnight times are defined as follows:

Lunch time is 11:00 ~ 14:59.
Dinner time is 18:00 ~ 20:59.
Midnight time is 21:00 ~ 01:59.

If a check is not printed in the three range of time, you don't have to process it.
If no check is in the range of time, you should print "no guest".

Sample input

5
12:57 59
20:12 15
12:19 21
18:52 03
16:09 14
0

Sample output

lunch 100
dinner 50
midnight no guest

Hint

If you want to read three integers in the following format,

integer:integer(space)integer

you can read them by scanf("%d%*c%d%d",&a, &b, &c); in C.
Problem D: The House of Huge Family

Mr. Dango's family has an extremely huge number of members.
Once it had about 100 members, and now it has as many as population of a city.
It is jokingly guessed that the member might fill this planet in the near future.

Mr. Dango's family, the huge family, is getting their new house.
Scale of the house is as large as that of town.

They all had warm and gracious personality and were close each other.
However, in this year the two members of them became to hate each other.
Since the two members had enormous influence in the family, they were split into two groups.

They hope that the two groups don't meet each other in the new house.
Though they are in the same building, they can avoid to meet each other by adjusting passageways.

Now, you have a figure of room layout. Your task is written below.

You have to decide the two groups each room should belong to.
Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group.
All of the rooms need to belong to exactly one group.
And any group has at least one room.

To do the task, you can cancel building passageway.
Because the house is under construction, to cancel causes some cost.
You'll be given the number of rooms and information of passageway.
You have to do the task by the lowest cost.

Please answer the lowest cost.

By characteristics of Mr. Dango's family, they move very slowly.
So all passageways are escalators.
Because of it, the passageways are one-way.

Input

The input consists of multiple datasets.
Each dataset is given in the following format.

n m
X1 Y1 C1
...
Xm Ym Cm

All numbers in each datasets are integers.
The integers in each line are separated by a space.

The first line of each datasets contains two integers.
n is the number of rooms in the house, m is the number of passageways in the house.
Each room is indexed from 0 to n-1.

Each of following m lines gives the details of the passageways in the house.
Each line contains three integers.
The first integer Xi is an index of the room, the starting point of the passageway.
The second integer Yi is an index of the room, the end point of the passageway.
The third integer Ci is the cost to cancel construction of the passageway.
The passageways, they are escalators, are one-way.
The last dataset is followed by a line containing two zeros (separated by a space).

Constraints

2 ≤ n ≤ 100

-10,000 ≤ Ci ≤ 10,000

Y1 ... Ym can't be duplicated integer by each other.

Output

For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers.

Sample input

3 2
0 1 2
1 2 1
2 1
0 1 100
2 1
0 1 0
2 1
0 1 -1
0 0

Sample output

1
100
0
-1
Problem F: Cutting a Chocolate

Turtle Shi-ta and turtle Be-ko decided to divide a chocolate.
The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h).
The chocolate has lines for cutting.
They cut the chocolate only along some of these lines.

The lines are expressed as follows.
There are m points on the line connected between (0,0) and (0,h), and between (w,0) and (w,h).
Each i-th point, ordered by y value (i = 0 then y =0), is connected as cutting line.
These lines do not share any point where 0 < x < w .
They can share points where x = 0 or x = w .
However, (0, li ) = (0,lj ) and (w,ri ) = (w,rj ) implies i = j .
The following figure shows the example of the chocolate.

There are n special almonds, so delicious but high in calories on the chocolate.
Almonds are circle but their radius is too small. You can ignore radius of almonds.
The position of almond is expressed as (x,y) coordinate.

Two turtles are so selfish. Both of them have requirement for cutting.

Shi-ta's requirement is that the piece for her is continuous.
It is possible for her that she cannot get any chocolate.
Assume that the minimum index of the piece is i and the maximum is k .
She must have all pieces between i and k .
For example, chocolate piece 1,2,3 is continuous but 1,3 or 0,2,4 is not continuous.

Be-ko requires that the area of her chocolate is at least S .
She is worry about her weight. So she wants the number of almond on her chocolate is as few as possible.

They doesn't want to make remainder of the chocolate because the chocolate is expensive.

Your task is to compute the minumum number of Beko's almonds if both of their requirment are satisfied.

Input

Input consists of multiple test cases.

Each dataset is given in the following format.

n m w h S
l0 r0
...
lm-1 rm-1
x0 y0
...
xn-1 yn-1

The last line contains five 0s.
n is the number of almonds.
m is the number of lines.
w is the width of the chocolate.
h is the height of the chocolate.
S is the area that Be-ko wants to eat.
Input is integer except xi yi.

Input satisfies following constraints.

1 ≤ n ≤ 30000

1 ≤ m ≤ 30000

1 ≤ w ≤ 200

1 ≤ h ≤ 1000000

0 ≤ S ≤ w*h

If i < j then li ≤ lj and ri ≤ rj and then i -th lines and j -th lines share at most 1 point.
It is assured that lm-1 and rm-1 are h.
xi yi is floating point number with ten digits.
It is assured that they are inside of the chocolate.
It is assured that the distance between points and any lines is at least 0.00001.

Output

You should output the minumum number of almonds for Be-ko.

Sample input

2 3 10 10 50
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 70
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 30
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 40
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 100
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
0 0 0 0 0

Sample output

1
1
0
1
2
Problem G: School of Killifish

Jon is the leader of killifish.
Jon have a problem in these days.
Jon has a plan to built new town in a pond.
Of course new towns should have a school for children. But there are some natural enemies in a pond.
Jon thinks that the place of a school should be the safest place in a pond for children.

Jon has asked by some construction companies to make construction plans and Jon has q construction plans now.
The plan is selected by voting. But for each plan, the safest place for the school should be decided before voting.

A pond is expressed by a 2D grid whose size is r*c.
The grid has r rows and c columns. The coordinate of the top-left cell is (0,0). The coordinate of the bottom-right cell is expressed as (r-1,c-1).
Each cell has an integer which implies a dangerousness.
The lower value implies safer than the higher value.
q plans are given by four integer r1 ,c1 ,r2 and c2 which represent the subgrid.
The top-left corner is (r1,c1) and the bottom-right corner is (r2,c2).

You have the r*c grid and q plans. Your task is to find the safest point for each plan.
You should find the lowest value in the subgrid.

Input

Input consists of multiple datasets.

Each dataset is given in the following format.

r c q
grid0,0 grid0,1 ... grid0,c-1
...
gridr-1,0 ... gridr-1,c-1
r1 c1 r2 c2
...
r1 c1 r2 c2

The first line consists of 3 integers, r ,c , and q .
Next r lines have c integers.
gridi,j means a dangerousness of the grid.
And you can assume 0 ≤ gridi,j ≤ 231-1.
After that, q queries, r1, c1, r2 and c2, are given.

The dataset satisfies following constraints.

r*c ≤ 106

q ≤ 104

For each query, you can assume that r1≤ r2 and c1 ≤ c2 .

If r * c ≤ 250000, q ≤ 100 is assured.
If r * c > 250000, Input consists of only that case.

Output

For each query you should print the lowest value in the subgrid in a line.

Sample input

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

Sample output

1
1
4
2
1
1
6
5