CodeEff/ECCO huggingface dataset:
Problem Name: Merry-go-round
Problem Description: You may know the merry-go-round in an amusement park. It is a classic play equipment in which vehicles such as horses and carriages are fixed on a large disc, and the vehicles sway up and down as the disc rotates. At a certain amusement park, the merry-go-round is equipped with eight vehicles in the order shown in Figure 1, including two four-person carriages, two two-person cars, and four single-person horses. And the customers who come to the amusement park are waiting at one of the eight boarding places 0 to 7 shown in Figure 1.
At this amusement park, the merry-go-round always stops at a position where the vehicle fits perfectly into the boarding place. Then, each customer waiting at 0 to 7 is supposed to get on the vehicle that has stopped in front of them. It is not possible to hurry to another boarding place and ride from there. In order to efficiently satisfy customers, the stopping position of the merry-go-round must be adjusted well to minimize the number of customers who cannot ride.
Create a program that reads the number of customers waiting at each of the eight boarding places and outputs the position at which each vehicle should be stopped so that the number of customers who cannot ride is minimized.
Input
The input consists of multiple datasets. Each dataset is given in the following format.
p
0
p
1
p
2
p
3
p
4
p
5
p
6
p
7
An integer
p
i
(0 ≤
p
i
≤ 10,000) representing the number of customers waiting at boarding place 0, 1, ..., 7 is given in a single line separated by spaces.
Output
Let 4 represent a horse-drawn carriage, 2 represent a car, and 1 represent a horse. The vehicles stopped at boarding places 0, 1, ..., 7 are represented by
c
0
,
c
1
, ...,
c
7
. For each dataset, output
c
0
,
c
1
, ...,
c
7
separated by spaces on one line.
If there are multiple ways to stop the vehicle so that the number of customers who cannot ride is minimized, assume
c
0
c
1
c
2
c
3
c
4
c
5
c
6
c
7
is an 8-digit integer
V
, and choose the way that minimizes
V
.
The number of datasets is no more than 100.
Sample Input
2 3 1 4 0 1 0 1 
4 2 3 2 2 2 1 1
Output for the Sample Input
1 4 1 4 1 2 1 2 
4 1 4 1 2 1 2 1
Problem Name: Search Engine
Problem Description: On internet search engines such as Google, web pages from all over the world are automatically collected and classified, creating a huge database. Also, the search keywords entered by users are analyzed to create a query for database search.
In either case, complex processing is performed to achieve efficient search, but the basic first step is always extracting words from the text.
So, let's try to extract words from the text. This time, we will target English text with clear word boundaries as follows:
Target text: English text of 1024 characters or less without line breaks
Separators: Only space, period, and comma characters (all half-width)
Extracted words: Words with 3 to 6 characters (ignore words with 2 or fewer or 7 or more characters)
Input
An English sentence consisting of separator characters and alphanumeric characters is given in one line (all half-width).
Output
Output the extracted words separated by a single space character (half-width) on one line.
Sample Input
Rain, rain, go to Spain.
Output for the Sample Input
Rain rain Spain
Sample Input 2
Win today's preliminary contest and be qualified to visit University of Aizu.
Output for the Sample Input 2
Win and visit Aizu
Problem Name: Patrol
Problem Description: In 1862, during the Bunkyu era, the lord of Aizu was appointed as the Kyoto Shugo-shoku. The Kyoto Shugo-shoku had the important role of protecting Kyoto, which had seen a deterioration in public safety during the late Edo period. The lord and his retainers had to patrol the city in collaboration with the shogunate and other clans. However, when it came time to decide on the patrol route, a famous stubborn retainer made the following request:
This was a serious matter. Even the lord could not ignore the retainer's demands. Depending on the choice of patrol route, it could be said that "the honor of the samurai is at stake."
Therefore, please create a program that determines whether the following three conditions are met based on the input of the starting point, the goal point, and the intersection points, and present it to the lord.
The starting point is represented by 1, the goal point by 2, and the other intersections by integers greater than 3. A road is represented by a pair of intersection numbers that it connects. The number of intersections is assumed to be 100 or less, and it is assumed that there is at least one path from each intersection to the starting point and the goal point.
Input
Multiple datasets are given. Each dataset is in the following format.
a
1
b
1
a
2
b
2
：
：
0
0
Two integers in each line indicate the existence of a road connecting intersection
a
i
and intersection
b
i
. When both
a
i
and
b
i
are 0, it indicates the end of the input of intersection information.
The number of datasets is no more than 50.
Output
For each dataset, output "OK" if the honor of the samurai is maintained (that is, if all three conditions are met), and "NG" otherwise (if any of the three conditions are not met).
Sample Input
1 3
3 4
3 5
3 6
4 6
4 7
4 7
5 6
6 7
5 8
5 8
6 8
6 9
7 9
8 9
9 2
0 0
1 3
3 4
3 4
4 2
0 0
Output for the Sample Input
OK
NG
Problem Name: Square search
Problem Description: There is a n × n grid with n rows and n columns. Some of the squares in the grid have marks on them. Write a program to read the status of each square and output the length of the side of the largest square made up of only unmarked squares.
For example, the following data sets are given for each data set:
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
Each line of the input data represents one row of the grid. In the input data string, the period (.) represents an unmarked square, and the asterisk (*) represents a marked square.
In the above example, the maximum square is shown by 0 in the figure below.
...*....**
..........
**....**..
...00000*.
..*00000..
...00000..
.*.00000..
...00000..
....*..***
.*....*...
Therefore, if you output 5, it will be correct.
If all squares have marks, output 0.
Input
Multiple data sets are given in the above format. The end of the input is indicated by 0 for
n
.
n
is at most 1000. The input data string contains no characters except periods, asterisks, and newlines. There are no more than 50 data sets.
Output
For each data set, output the length of the largest square (an integer) on one line.
Sample Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output for the Sample Input
5
3
Problem Name: Ice fishing tournament
Problem Description: An ice fishing tournament was held at Lake Hikaruhara. The person who caught the most icefish won the tournament.
Create a program that reads a list of participant numbers and the number of fish they caught, and outputs the number and the number of fish caught by the winner. If there are multiple winners, output the one with the smallest participant number.
Input
The input is given in the following format.
n
a
1
v
1
a
2
v
2
:
a
n
v
n
n
(1 ≤
n
≤ 20) is the number of participants,
a
i
represents the participant number. Participant numbers are different integers between 1 and
n
.
v
i
(0 ≤
v
i
≤ 100) is the number of fish caught by participant
a
i
.
Output
Output the participant number and the number of fish caught by the winner on one line separated by a space.
Input Example
6
1 14
2 25
3 42
4 11
5 40
6 37
Output Example
3 42
Problem Name: Sum of Four Integers II
Problem Description: Given a positive integer n less than or equal to 4,000, find the number of combinations of 0-1000 integers a, b, c, d such that:
a + b + c + d = n
Output the number of combinations for each dataset. Multiple datasets will be given, and the input will end when there is no more data.
There will be no more than 50 datasets.
Sample Input
2
3
35
Output for the Sample Input
10
20
8436
Problem Name: Sum of Integers II
Problem Description: Write a program that takes n distinct integers between 0 and 100 and outputs the number of combinations that add up to s. Each of the n integers can be between 0 and 100, and the same number cannot be used in one combination. For example, when n is 3 and s is 6, the number of combinations of three numbers that add up to 6 are:
1 + 2 + 3 = 6
0 + 1 + 5 = 6
0 + 2 + 4 = 6
which is 3 combinations in total.
Input
Multiple data sets are given. For each data set,
n
and
s
are given on one line separated by a single space. (
n
is an integer between 1 and 9, and
s
is an integer between 0 and 1000.) When both
n
and
s
are 0, the input is terminated.
The number of data sets is no more than 50.
Output
For each data set, output the number of combinations of
n
integers that add up to
s
on one line.
Inputs that result in combinations greater than 10
10
will not be given.
Sample Input
3 6
3 1
0 0
Output for the Sample Input
3
0
Problem Name: Maximum Sum Sequence II
Problem Description: Given a matrix of integers
a
1,1
a
1,2
...
a
1,n
a
2,1
a
2,2
...
a
2,n
:
a
n,1
a
n,2
...
a
n, n
Create a program that outputs the maximum value of the sum of consecutive terms (submatrix) in the vertical and horizontal directions.
Input
The input data is given in the following format.
n
a
1,1
a
1,2
...
a
1,n
a
2,1
a
2,2
...
a
2,n
:
a
n,1
a
n,2
...
a
n, n
n
is between 1 and 100, and
a
i,j
is between -10000 and 10000.
Output
Output the maximum value on one line.
Sample Input 1
3
1 -2 3
-4 5 6
7 8 -9
Output for the Sample Input 1
16
In this input, the sum of the terms in the following submatrix is maximum.
-4 5
7 8
Sample Input 2
4
1 3 -9 2
2 7 -1 5
-8 3 2 -1
5 0 -3 1
Output for the Sample Input 2
15
In this input, the sum of the terms in the following submatrix is maximum.
7 -1 5
3 2 -1
Problem Name: Ice Fishing Contest 2
Problem Description: An ice fishing contest was held at Hikarigahara Lake. This time, catch and release is recommended.
Create a program that reads the participant number and the number of fish caught or released for each event in order, and outputs the participant number and the number of fish caught by the participant who has the most fish at hand immediately after each event. If there are multiple participants who have caught the most fish (or if all participants have caught 0 fish), output the one with the smallest participant number.
Input
The input is given in the following format.
n
q
a
1
v
1
a
2
v
2
:
a
q
v
q
n
(1 ≤
n
≤ 1,000,000) represents the number of participants and
q
(1 ≤
q
≤ 100,000) represents the number of events.
a
i
(1 ≤
a
i
≤
n
) and
v
i
(-100 ≤
v
i
≤ 100) indicate that participant
a
i
caught or released
v
i
fish in the i-th event. A positive value of
v
i
indicates a catch, a negative value indicates a release, and 0 is not given.
Output
For each event, output the participant number and the number of fish caught by the participant who has the most fish at hand as one line separated by a space.
Input Example 1
3 5
1 4 
2 5 
1 3
3 6
2 7
Output Example 1
1 4
2 5
1 7
1 7
2 12
Input Example 2
3 5
1 4 
2 5 
2 -3
3 4
1 -1
Output Example 2
1 4
2 5
1 4
1 4
3 4
Problem Name: Sale Result
Problem Description: There is data on sales of your company. Your task is to write a program which identifies good workers.
The program should read a list of data where each item includes the employee ID
i
, the amount of sales
q
and the corresponding unit price
p
. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that
n
< 4000, and each employee has an unique ID. The unit price
p
is less than or equal to 1,000,000 and the amount of sales
q
is less than or equal to 100,000.
Input
The input consists of several datasets. The input ends with a line including a single 0. Each dataset consists of:
n
(the number of data in the list)
i
p
q
i
p
q
:
 :
i
p
q
Output
For each dataset, print a list of employee IDs or a text "NA"
Sample Input
4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
2
1001 100 3
1005 1000 100
2
2013 5000 100
2013 5000 100
0
Output for the Sample Input
1001
1003
NA
2013
Problem Name: Aizu PR
Problem Description: An English booklet has been created for publicizing Aizu to the world.
When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina".
Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000.
Input
The input consists of several datasets. There will be the number of datasets
n
in the first line. There will be
n
lines. A line consisting of english texts will be given for each dataset.
Output
For each dataset, print the converted texts in a line.
Sample Input
3
Hoshino
Hashino
Masayuki Hoshino was the grandson of Ieyasu Tokugawa.
Output for the Sample Input
Hoshina
Hashino
Masayuki Hoshina was the grandson of Ieyasu Tokugawa.
Problem Name: Discounts of Buckwheat
Problem Description: Aizu is famous for its buckwheat. There are many people who make buckwheat noodles by themselves.
One day, you went shopping to buy buckwheat flour. You can visit three shops, A, B and C. The amount in a bag and its unit price for each shop is determined by the follows table. Note that it is discounted when you buy buckwheat flour in several bags.
Shop A
Shop B
Shop C
Amount in a bag
200g
300g
500g
Unit price for a bag (nominal cost)
380 yen
550 yen
850 yen
Discounted units
per 5 bags
per 4 bags
per 3 bags
Discount rate
reduced by 20 %
reduced by 15 %
reduced by 12 %
For example, when you buy 12 bags of flour at shop A, the price is reduced by 20 % for 10 bags, but not for other 2 bags. So, the total amount shall be (380 × 10) × 0.8 + 380 × 2 = 3,800 yen.
Write a program which reads the amount of flour, and prints the lowest cost to buy them. Note that you should buy the flour of exactly the same amount as the given input.
Input
The input consists of multiple datasets. For each dataset, an integer
a
(500 ≤
a
≤ 5000,
a
is divisible by 100) which represents the amount of flour is given in a line.
The input ends with a line including a zero. Your program should not process for the terminal symbol. The number of datasets does not exceed 50.
Output
For each dataset, print an integer which represents the lowest cost.
Sample Input
500
2200
0
Output for the Sample Input
850
3390
Problem Name: Smart Calculator
Problem Description: Your task is to write a program which reads an expression and evaluates it.
The expression consists of numerical values, operators and parentheses, and the ends with '='.
The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
You may assume that there is no division by zero.
All calculation is performed as integers, and after the decimal point should be truncated
Length of the expression will not exceed 100.
-1 &times 10
9
≤ intermediate results of computation ≤ 10
9
Input
The input is a sequence of datasets. The first line contains an integer
n
which represents the number of datasets. There will be
n
lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Sample Input
2
4-2*3=
4*(8+4+3)=
Output for the Sample Input
-2
60
Problem Name: Dr. Cipher
Problem Description: Dr. : ?D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to you shouting incomprehensible things, but today it's not even forming sentences.
Dr. : Look at this.
Peter: What's this?... Oh, there was something like this in the preliminary round's problems. By using the table, the number of characters can be reduced by replacing the characters. They wouldn't use the same problem in both the preliminary and the main round to take it easy, right?
Dr. : The opposite.
Peter: The opposite? I see, so it's a problem of restoring the shortened string from this time. So I need to replace the characters in "?D-C'KOPUA" with the "code" using this table... Done.
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Dr. : Yes. Next is this.
Peter: Yes, there was a table like this. So I just need to replace "code" with "character" by using it in reverse. But at first, "11111" is not on the table, is it?
Dr. : In such cases, try to make it shorter or connect it to the end.
Peter: Then I'll make it shorter... Oh, "111" is there. So the first one is "P", right? Then the remaining one is "11", but there is no exact match for it, so I need to borrow 1 character from "00011" and make it "110".
Dr. : That's right. That means it's "E".
Peter: So the remaining one is "0011", so I'll borrow from the next one and make it "00111" and it's "T"... Done. Can I just throw away the last "0000"?
Dr. : That's right. Next is this.
?D-C'?-C'-LMGZN?FNJKN- WEYN?P'QMRWLPZLKKTPOVRGDI
Dr. : And this.
?P'QNPY?IXX?IXXK.BI -G?R'RPP'RPOVWDMW?SWUVG'-LCMGQ
Dr. : Finally, it's like this.
?P'QMDUEQ GADKOQ ?SWUVG'-LCMG?X?IGX,PUL.?UL.VNQQI
Peter: But it's a hassle. Dr., make your own program next time.
That being said, please create a program to replace the above sentence for Dr.
Input
Multiple datasets are given. For each dataset, one string (up to 200 characters composed of characters included in the table) is given in one line. Process until the end of the input. The number of datasets does not exceed 200.
Output
For each dataset, output the converted string on one line.
Sample Input
?D-C'KOPUA
Output for the Sample Input
PETER POTTER
Problem Name: Milk Shop
Problem Description: Suzuki has opened a mobile shop for freshly squeezed milk in the Aizu region. All the customers who come to buy it that day are already lined up with bottles to take home, and no more customers will come. Each customer orders only once. There is only one faucet on the tank, so they must be sold one by one in order. Therefore, Suzuki wants to minimize the waiting time of the customers who are waiting in line as much as possible.
The number of customers and the time required for each customer to pour the milk are given as input. Create a program that finds the order of orders that minimizes the "total waiting time" of the customers (hereinafter referred to as "total waiting time") on behalf of Suzuki, and outputs the "total waiting time" at that time and ends. However, there are up to 10,000 customers, and the time required per person is less than 60 minutes.
For example, if there are 5 customers and each customer requires 2, 6, 4, 3, and 9 minutes in order, the "total waiting time" will be 37 minutes if they are in the same order. In the following example, the order of the first column is swapped with the second and third customers. In this case, the "total waiting time" is 35 minutes. With the optimal order, it can be done in 31 minutes.
Wait time
1st person 2 min
0 min
2nd person 6 min
2 min
3rd person 4 min
8 min
4th person 3 min
12 min
5th person 9 min
15 min
37 min
← "total waiting time"
Example of swapping the 2nd and 3rd persons
Wait time
1st person 2 min
0 min
2nd person 4 min
2 min
3rd person 6 min
6 min
4th person 3 min
12 min
5th person 9 min
15 min
35 min
← "total waiting time"
Input
Multiple datasets are given. Each dataset is given in the following format.
n
t
1
t
2
:
t
n
The number of customers
n
(
n
≤ 10,000) is given on the first line. The following
n
lines give an integer
t
i
(0 ≤
t
i
≤ 60) representing the time required for the
i
-th customer to order.
The input ends with a line containing only 0. The number of datasets does not exceed 50.
Output
For each dataset, output the "total waiting time" (an integer) on one line.
Sample Input
5
2
6
4
3
9
0
Output for the Sample Input
31
Problem Name: Repeating Decimals
Problem Description: Consider representing the division of two positive integers p and q as a decimal number. (We assume that 0 < p < q < 106.)
The result can be either:
represented accurately with a finite number of digits.
a repeating decimal that repeats a range of digits.
By performing division in the same way as long division, the decimal digits can be found one by one, and:
If the remainder becomes 0 (divides evenly), we have found all the digits and can represent the result exactly.
If a remainder repeats, the decimal repeats as well.
Write a program that takes two integers
p
and
q
as input and outputs the decimal part of
p
/
q
. Note that:
If the result can be represented accurately with a finite number of digits, output only the digits.
If the result is a repeating decimal, output two lines as follows:
The first line should contain the non-repeating part of the decimal.
The second line should contain spaces under the non-repeating part and "^" characters under the repeating part.
The length of the digit string will not exceed 80 characters.
Input
The input consists of multiple data sets. Each data set consists of two integers
p
and
q
, separated by a single space, given in a single line. The number of data sets is no more than 250.
Output
For each data set, output the decimal part of the division. If the decimal representation is non-repeating, output only the digits. If the decimal representation is repeating, output a two-line result with the non-repeating part on the top and "^" characters under the repeating part.
Sample Input
1 12
10000 32768
1 11100
1 459550
Output for the Sample Input
083
  ^
30517578125
00009
  ^^^
00000217604178
  ^^^^^^^^^^^^
Problem Name: Rectangular Search
Problem Description: There is a W × H grid, consisting of H rows and W columns. Some of the squares have marks on them. Write a program that reads the state of the marks on each square, and outputs the area of the largest rectangle that does not include any marked squares.
The input consists of
H
rows, each of which contains a string of
W
characters. For example, you may be given data like the following:
..*....**.
..........
**....***.
....*.....
..*.......
...**.....
.*.*......
..........
..**......
.*..*.....
Each row of input data represents one row of squares. In the input data, a period (.) represents an unmarked square, and an asterisk (*) represents a marked square. The input data contains no characters other than periods, asterisks, and newlines.
In the example above, the largest rectangle, marked with 0's in the diagram below, has an area of 35.
..*....**.
..........
**....***.
....*00000
..*..00000
...**00000
.*.*.00000
.....00000
..**.00000
.*..*00000
If all the squares are marked, output 0.
Input
Multiple data sets are given. Each data set begins with a line containing two integers
H
and
W
separated by a space, followed by a rectangular grid of
H × W
squares.
H
and
W
are less than or equal to 500.
The input ends with a line containing two zeros. There are no more than 20 data sets.
Output
For each data set, output the area of the largest rectangle in a single line.
Sample Input
10 10
...*....**
..........
**....**..
........*.
..*.......
**........
.*........
..........
....*..***
.*....*...
10 10
..*....*..
.*.*...*..
*****..*..
*...*..*..
*...*..*..
..........
****.*...*
..*..*...*
.*...*...*
****..***.
2 3
...
...
0 0
Output for the Sample Input
28
12
6