CodeEff/ECCO huggingface dataset:
Problem Name: Pastry Chef
Problem Description: A cake shop has made a lot of Swiss rolls of different sizes. You have been assigned a job of arranging these cakes in a box.
Swiss rolls are very soft, so if another Swiss roll is placed on top of one, the first one will be crushed. Therefore, all Swiss rolls must be arranged so that they touch the bottom of the box, as shown in Figure (a). If you change the arrangement, the required width will also change.
Figure (a)
Figure (b)
Read the radius
r
1
,
r
2
, ...,
r
n
of
n
Swiss rolls and the length of the box, and for each of them, create a program that determines whether they fit well in the box and outputs "OK" if they fit well by designing their order, or "NA" if they cannot be fitted no matter how they are arranged.
The cross section of the Swiss roll is a circle, and the height of the box wall is sufficiently high. However, the radius of the Swiss roll is an integer between 3 and 10. In other words, there is no extreme difference in the radius of the cake, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format.
W
r
1
r
2
...
r
n
First, an integer
W
(1 ≤
W
≤ 1,000) representing the length of the box is given. Then, an integer
r
i
(3 ≤
r
i
≤ 10) representing the radius of each Swiss roll is given separated by a space. The number of cakes
n
is 12 or less.
The number of datasets does not exceed 50.
Output
For each dataset, output "OK" or "NA" on a single line.
Sample Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output for the Sample Input
OK
OK
OK
NA
Problem Name: 7 Puzzle
Problem Description: The 7 Puzzle consists of a frame and eight square cards that fit snugly into it. Each card is labeled with a number from 0 to 7 so they can be distinguished from each other. The frame can hold two rows of four cards.
To begin the game, all of the cards are placed in the frame. Only the card labeled 0 can be moved by swapping its position with one of its adjacent cards. For example, if the frame is in the state shown in Figure (a) and you swap the position of the 0 card with the 7 card to its right, the state of the frame becomes the one shown in Figure (b). Alternatively, if you swap the position of the 0 card with the 2 card below it, as shown in Figure (c), the state of the frame will change to that. Since the 0 card is only adjacent to the 7 and 2 cards in the state shown in Figure (a), no other swaps are allowed.
The goal of the game is to arrange the cards neatly into the state shown in Figure (d). Given the initial state of the cards as input, create a program that outputs the minimum number of moves necessary to arrange the cards neatly. However, it is assumed that it is possible to move from the input state of the cards to the state shown in Figure (d).
The input data consists of eight numbers separated by spaces on a single line. These represent the order of the cards in the initial state. For example, the numerical representation of Figure (a) is 0 7 3 4 2 5 1 6 and that of Figure (c) is 2 7 3 4 0 5 1 6.
Figure (a) Case:
0 7 3 4 2 5 1 6
Figure (b) Case:
7 0 3 4 2 5 1 6
Figure (c) Case:
2 7 3 4 0 5 1 6
Figure (d) Case:
0 1 2 3 4 5 6 7
(Final State)
Input
Multiple puzzles are given in the format above. Please process until the end of the input.
The number of puzzles given is no more than 1,000.
Output
For each puzzle, output on one line the minimum number of moves required to reach the final state.
Sample Input
0 1 2 3 4 5 6 7
1 0 2 3 4 5 6 7
7 6 5 4 3 2 1 0
Output for the Sample Input
0
1
28
Problem Name: League Standings Score Sheet
Problem Description: There are league and tournament games in sports. In soccer leagues, points are awarded for wins, losses, and draws, and rankings are determined by those points. The points awarded for each are as follows: win (3 points), loss (0 points), and draw (1 point).
Create a program that inputs the number of teams and their league record, sorts them in order of good performance (based on the number of points) and outputs the team name and points. In case of a tie in points, output in the order of input.
Input
Multiple data sets will be given. Each data set will be in the following format:
n
name
1
w
1
l
1
d
1
name
2
w
2
l
2
d
2
:
name
n
w
n
l
n
d
n
The number of teams,
n
(
n
≤ 10), is given on the first line. On the following
n
lines, the name
name
i
of team
i
(up to 20 alphabets), the number of wins
w
i
, the number of losses
l
i
, and the number of draws
d
i
(0 ≤
w
i
,
l
i
,
d
i
≤ 9) are given, separated by spaces.
When the number of teams is 0, the input is terminated. The number of data sets will not exceed 50.
Output
For each data set, output a list of the sorted teams. On the
i
-th line, output the name and points of the
i
-th team separated by a comma.
Insert one blank line between data sets.
Sample Input
4
Japan 1 0 2
Egypt 1 2 0
Canada 0 2 1
Spain 2 0 1
3
India 0 2 0
Poland 1 0 1
Italy 1 0 1
0
Output for the Sample Input
Spain,7
Japan,5
Egypt,3
Canada,1

Poland,4
Italy,4
India,0
Problem Name: Hide and Seek
Problem Description: Tarou doesn't like hide-and-seek. He is always found immediately when he hides, and he can't find the other children who are hiding. Feeling sorry for him, his father made him a super high-performance location search system. With this system, he can accurately locate his friends' positions, including his own position. When he becomes "it", he can easily find the children who are hiding.
Tarou came up with the idea of adding a function to the system that determines whether he can be seen by "it". If he can do this, even if "it" says "Are you done?", he can say "Not yet" if he is in a visible position, and "I'm done" if he is in an invisible position. There are cylindrical walls of various sizes in the park where they always play. The walls cannot be seen from outside, and the inside cannot be seen from inside. If you go inside with "it", you can see it unless there is another wall.
Tarou is not good at making software, even though his idea is good. So, as his best friend, you decided to make a software called "Confirmation System for Not Being Seen by 'it'" for him. The information of the walls in the park (the center coordinates (
wx
,
wy
) and radius
r
) and the positions of Tarou and "it" (Tarou's position coordinates (
tx
,
ty
) and "it"'s position coordinates (
sx
,
sy
)) are given as input, and your task is to create a program that determines whether Tarou can be seen by "it" at that position.
Note that if Tarou can be seen by "it", output Danger, and if he cannot be seen, output Safe. It is assumed that if there is a wall on the line connecting "it" and Tarou's position, it cannot be seen, and neither "it" nor Tarou are on the wall.
Input
Multiple datasets are given. Each dataset is given in the following format.
n
wx
1
wy
1
r
1
wx
2
wy
2
r
2
:
wx
n
wy
n
r
n
m
tx
1
ty
1
sx
1
sy
1
tx
2
ty
2
sx
2
sy
2
:
tx
m
ty
m
sx
m
sy
m
The first line contains the number of cylindrical walls
n
(0 ≤
n
≤ 100), followed by
n
lines of the center coordinates of the wall
i
, integers
wx
i
,
wy
i
(0 ≤
wx
i
,
wy
i
≤ 255), and the integer
r
i
(1 ≤
r
i
≤ 255) indicating the radius.
The following line contains the number of position information of Tarou and "it"
m
(m ≤ 100), followed by
m
lines of position information
i
, integers
tx
i
,
ty
i
(0 ≤
tx
i
,
ty
i
≤ 255), and the position coordinates of "it"
sx
i
,
sy
i
(0 ≤
sx
i
,
sy
i
≤ 255).
It is assumed that all walls are cylindrical and are inside the park, and not that only part of the cylindrical walls are in the park.
The end of the input is indicated by n = 0. The number of datasets does not exceed
Problem Name: Doctor's Photomultiplier Tube
Problem Description: Doctor: Peter, I did it.
Peter: Again? What kind of useless invention is it this time?
Doctor: I invented a detector for that elusive axion particle.
Peter: You mean that the researchers, including the European Organization for Nuclear Research (CERN), are vying for the potential discovery of this particle, correct? Is it real?
Doctor: Of course, it's real. I'll omit the detailed explanation, but my special photomultiplier tube with an exceptionally strong built-in magnetic field detects axions by emitting light.
Peter: If we can detect it before anyone else, this could be a Nobel Prize-level research rivaling Dr. Koshiba's neutrino discovery. No longer would the lab be known as the "useless research lab."
Doctor: Indeed. Drawing inspiration from Dr. Koshiba's "Super-Kamiokande," I've named this machine "Tadajaokande" (Freetalker Reminder).
Peter: A somewhat forced play on words, but moving on…
Doctor: That aside, this machine has some quirks. When an axion particle passes through one of the photomultiplier tubes, the adjacent tubes—up, down, left, and right—react due to sensitivity.
Fig. 1
Fig. 2
★
●
●
●
●
●
●
●
★
●
●
●
●
●
●
●
●
●
●
●
●
●
★
●
●
&
Problem Name: Exit Survey
Problem Description: An exit survey was conducted on the amount of money spent at a department store. Create a program that inputs the data on the amount of money spent and calculates and outputs the average amount spent per person. The number of people surveyed is less than or equal to 100,000, and the amount spent per person is less than or equal to 1 million yen.
Input
The input is given in the following format:
n
v
1
v
2
:
v
n
The first line contains the number of people surveyed
n
, and the following
n
lines contain integers
v
i
that represent the amount spent by person
i
.
Output
Output the average amount spent (an integer value, rounded down) on one line.
Sample Input
6
12300
5600
33800
0
26495
52000
Output for the Sample Input
21699
Problem Name: The Short and Long Hands of Clocks
Problem Description: We have received a prank notice from the primitive slow life organization "Akaruida". Akaruida is famous for pranks such as throwing pies in the faces of important people, but recently they have become more radical, using gunpowder to scatter rat fireworks at reception venues, etc. The notice reads as follows:
---The computer steals human time. Not good.
When the short and long hands of the clock meet, Akaruida will do justice.
Slow life is great.
It is difficult to understand because it is awkwardly written, but it seems to mean that they will carry out the prank when the short and long hands of the clock overlap.
To be on guard against this prank, create a program that takes the time as input and outputs "alert" if the short and long hands are close, "safe" if they are far apart, and "warning" for all other cases. Here, "close" refers to when the angle between the short and long hands is 0° or more and less than 30°, and "far apart" refers to when the angle is between 90° and 180° inclusive. The time will be between 00:00 and 11:59.
Input
The input is given in the following format:
n
hh
1
:
mm
1
hh
2
:
mm
2
:
hh
n
:
mm
n
The first line contains the number of times to be judged
n
(1 ≤
n
≤ 10000), and the second and subsequent lines give the time to be judged
i
in the format
hh
i
:
mm
i
.
Output
Output the judgment result of time
i
as "safe", "warning", or "alert" on separate lines in order.
Sample Input
4
02:15
06:01
11:55
10:40
Output for the Sample Input
alert
safe
alert
warning
Problem Name: Bus Routes
Problem Description: There is a bus route as shown in Figure 1. There are 10 stops, each numbered from 0 to 9. The bus turns back at stop 0, but the opposite side is a circular route, and it circulates in the order of 5→6→7→8→9→5 as shown in the figure.
For this bus route, create a program that takes as input the stop where you get on and the stop where you get off, and outputs the numbers of the stops you pass through from getting on to getting off.
However, at stops 1 to 5, you can take either direction of the bus, but it is assumed that you will take the bus that arrives at the destination stop by the shortest route. For example, if you go from stop 4 to stop 2, you will take the bus that goes to the left and pass through the route "4→3→2". Also, once you get on the bus, you will not get off until you reach your destination stop. The same stop cannot be specified as both the boarding and alighting stops.
Input
Multiple datasets are given. The first line contains the number of datasets,
n
(
n
≤ 20 ). For each dataset, the stop number where you get on and the stop number where you get off are given on one line separated by a space.
Output
For each dataset, output the sequence of stop numbers that you pass through on one line separated by spaces.
Sample Input
2
2 4
4 2
Output for the Sample Input
2 3 4
4 3 2
Problem Name: Spiral Pattern
Problem Description: I decided to create a program that displays a "spiral pattern". The "spiral pattern" is as follows:
If the length of one side is
n
, it is displayed as a string of
n
rows and
n
columns.
The pattern is a vortex that rotates clockwise from the lower left corner.
The parts with lines are represented by # (sharp symbol), and the blank parts are represented by " "(half-width space).
Space is placed between lines.
Create a program that outputs the "spiral pattern" with one side of length
n
as input.
Input
The input is given in the following format.
d
n
1
n
2
:
n
d
The first line gives the number of data sets
d
(
d
≤ 20), and the
i
-th line following it gives the length of the spiral pattern
n
i
(1 ≤
n
i
≤ 100) for the
i
-th spiral pattern.
Output
For each data set, output the spiral pattern. Please insert one blank line between the data sets.
Sample Input
2
5
6
Output for the Sample Input
#####
#   #
# # #
# # #
# ###

######
#    #
# ## #
# #  #
# #  #
# ####
Problem Name: Properties of Prime Numbers
Problem Description: There is an interesting property for prime numbers n (such as 11, 19, 23, etc.) that leave a remainder of 3 when divided by 4. When you calculate the remainder of the squares of natural numbers (1, 2, ..., n-1) when divided by n, and arrange them in order, there will be some numbers that are the same, so the number of distinct numbers will be (n-1)/2.
From the set of numbers obtained in this way, there is a special property. Select two different numbers
a
and
b
from the set of obtained numbers and calculate their difference. If the difference is negative, add
n
to it. If the result is greater than (
n
-1)/2, subtract it from
n
.
For example, when
n=11
, the difference between 1 and 9 is
1 - 9 = -8
→
-8 + n = -8 + 11 = 3
. The difference between 9 and 1 is also
9 - 1 = 8
→
n - 8 = 11 - 8 = 3
, so they both have the same value 3. This difference can be easily understood by considering the short arc between two numbers on a circle with 0, 1, ...,
n
-1 written on it (see the figure below).
The "differences" of the numbers obtained in this way are any of 1, 2, ..., (
n
-1)/2, and occur the same number of times.
【Example】 When
n = 11
, it is as follows.
Calculate the remainder when the numbers from 1 to
n
-1 are squared and divided by
n
.
1
2
=    1   →   1
 2
2
=    4   →   4
 3
2
=    9   →   9
 4
2
=   16   →   5
 5
2
=   25   →   3
 6
2
=   36   →   3
 7
2
=   49   →   5
 8
2
=   64   →   9
 9
2
=   81   →   4
10
2
=  100   →   1
Calculate the "difference" between
a
and
b
Calculate the difference between different numbers obtained in 1 for 1, 3, 4, 5, and 9.
If the result is negative, add
n
= 11.
If the result is greater than (
n
-1)/2 = 5, subtract it from
n
= 11.
Count the number of occurrences
Count the number of occurrences of 1, 2, 3, 4, and 5 in the calculation results.
From these calculation results, it can be seen that the number of occurrences of 1, 2, 3, 4, and 5 is 4 times. This property is unique to prime numbers that leave a remainder of 3 when divided by 4, and does not occur in prime numbers that leave a remainder of 1 when divided by 4. To verify this, write a program that takes an odd number
n
less than or equal to 10,000 as input, executes the calculation described in the example (
n
divided by the remainder of the square of the difference), and outputs the number of occurrences of the result.
Input
Multiple datasets are given. Each dataset consists of a single integer
n
(
n
≤ 10000) on a line. The input ends with a line containing only 0.
Output
For each dataset, output the frequency in the following format.
Number of occurrences of the difference of the square of the remainder is 1 (
a, b
).
Number of occurrences of the difference of the square of the remainder is 2 (
a, b
).
   :
   :
Number of occurrences of the difference of the square of the remainder is (
n
-1)/2 (
a, b
).
Sample Input
11
15
0
Output for the Sample Input
4
4
4
4
4
2
2
4
2
4
4
2
Problem Name: Packet Transfer
Problem Description: In the internet, data is divided into packets and transferred to the destination via intermediate devices called routers. Each router determines the next router to transfer based on the destination described in the packet. In addition, to prevent packets from being transferred between routers indefinitely, a value called TTL (Time To Live) is added to the packet. The router subtracts 1 from the TTL of the received packet, and if the result is 0, the packet is discarded, otherwise it is forwarded to the next router.

Therefore, you are asked to create a program to assist in network design. Given the connection information of the network and the information of the transmitted packet, create a program that displays the minimum value of the number of routers passed through until each packet reaches the destination router.

The network consists of multiple routers and cables connecting them, as shown in the figure. However, be aware that each connection (cable) is one-way. The array of numbers identifying the routers directly connected to each router is given as the network connection information. Each router is identified by an integer from 1 to n, if there are multiple routes from the source to the destination router, output the value of the fewer routers to be passed through. If the packet cannot reach the destination, output NA.

For example, consider the case where the source router is 6 and the destination router is 5 in the network shown in the figure below. The shortest route is 6 → 1 → 5, and the number of routers passed through is 3. In this case, TTL is subtracted at routers 6 and 1, so the packet can be reached if the TTL at the time of transmission is 3 or more. There is no packet that will be at the same router as the source and destination.
Input
The input is given in the following format.
n
r
1
k
1
t
11
t
12
...
t
1k
1
r
2
k
2
t
21
t
22
...
t
2k
2
:
r
n
k
n
t
n1
t
n2
...
t
nk
n
p
s
1
d
1
v
1
s
2
d
2
v
2
:
s
p
d
p
v
p
The first line contains the total number of routers
n
(1 ≤
n
≤ 100), and the following
n
lines give the connection information for each router. For the connection information, the number
r
i
of the
i
-th router, the number
k
i
of routers directly connected to the
i
-th router, and the numbers
t
i1
,
t
i2
, ...,
t
ik
i
of the routers that can be sent from the
i
-th router are given.

The following line gives the number of packets
p
(1 ≤
p
≤ 1000), and the following
p
lines give the information of each packet. The information of the packet includes the number of the source router
s
i
, the number of the destination router
d
i
, and the value of TTL
v
i
(0 ≤
v
i
≤ 10000).
Output
For each packet, output the number of routers passed through or NA on one line.
Sample Input
7
1 4 2 5 4 3
2 1 5
3 1 6
4 1 7
5 2 7 6
6 1 1
7 0
6
1 2 2
1 5 3
1 2 1
5 1 3
6 3 3
1 7 4
Output for the Sample Input
2
2
NA
3
3
3
Problem Name: Cards
Problem Description: There is a set of cards with positive integers written on them. Create several stacks of cards and stack them horizontally. From these, select two adjacent stacks of cards and stack the left stack as is on top of the right stack. Repeat this operation until there is only one stack of cards left.
When stacking two stacks of cards, multiply all the numbers written on the top and bottom cards of the two stacks. This product is called the cost of stacking the cards. The cost of stacking all of the stacks of cards together is the sum of all the costs of stacking.
The cost varies depending on the order in which the stacks of cards are stacked. For example, consider the case where there are three stacks of cards. Assume that the numbers written on the top and bottom cards of these stacks of cards are 3 and 5, 2 and 8, and 5 and 4, respectively, in order from left to right. In this case, the cost of stacking the left and middle stacks of cards together is 3 × 5 × 2 × 8 = 240. By stacking them in this way, a stack of cards is created with the top card being 3 and the bottom card being 8.
When this stack is stacked on top of the right stack, the cost becomes 3 × 8 × 5 × 4 = 480. Therefore, the cost of stacking the stacks of cards in this order to create one stack of cards is 240 + 480 = 720. (Fig. 1)
On the other hand, if you stack the middle and right stacks of cards first and then the left stack last, the cost is 2 × 8 × 5 × 4 + 3 × 5 × 2 × 4 = 440. Therefore, stacking them in this order results in a lower cost. (Fig. 2)
Write a program that takes as input the number of stacks of cards and the numbers written on the top and bottom cards of each stack of cards, and outputs the minimum cost required to stack the stacks of cards into one stack. The number of stacks of cards is 100 or less, and the input data will not result in a cost greater than 2
31
-1, regardless of the order in which the cost is calculated.
Input
The input is given in the following format.
n
a
1
b
1
a
2
b
2
:
a
n
b
n
The first line contains the number of stacks of cards
n
(1 ≤
n
≤ 100), and the following
n
lines contain the numbers written on the top
a
i
(1 ≤
a
i
≤ 200) and bottom
b
i
(1 ≤
b
i
≤ 200) cards of the
i
-th stack of cards from left to right.
Output
Output the minimum cost required to stack the stacks of cards into one stack on one line.
Sample Input
3
3 5
2 8
5 4
Output for the Sample Input
440
Problem Name: Fuku-Shima-ken
Problem Description: "Fuku-Shima-ken" is a popular ramen shop where people line up to get in. However, recently, there have been complaints from customers saying, "I can't forgive that there are empty seats in the shop even though the waiting time is long." I want to investigate why such dissatisfaction is arising, but the shop is busy as long as it is open, and I cannot investigate the actual state of the line. However, based on years of experience, I know the intervals and numbers of customers who come, so I decided to analyze the waiting time based on that.
There are 17 seats facing the counter in the shop. The opening time is noon, and customers come as follows:
100 groups from 0 to 99 come.
The
i
th group arrives at the shop
5i
minutes after noon.
The number of people in the
i
th group is 5 if
i
% 5 = 1, and 2 otherwise. (
x
%
y
represents the remainder when
x
is divided by
y
.)
The
i
th group finishes their meal in 17(
i
% 2) + 3(
i
% 3) + 19 minutes after they are seated.
The arrival time, number of people, and meal time of the first 10 groups are as follows:
Group number
0
1
2
3
4
5
6
7
8