CodeEff/ECCO huggingface dataset:
Problem Name: Problem B: The Last Ant
Problem Description: A straight tunnel without branches is crowded with busy ants coming and going. Some ants walk left to right and others right to left. All ants walk at a constant speed of 1 cm/s. When two ants meet, they try to pass each other. However, some sections of the tunnel are narrow and two ants cannot pass each other. When two ants meet at a narrow section, they turn around and start walking in the opposite directions. When an ant reaches either end of the tunnel, it leaves the tunnel.
The tunnel has an integer length in centimeters. Every narrow section of the tunnel is integer centimeters distant from the both ends. Except for these sections, the tunnel is wide enough for ants to pass each other. All ants start walking at distinct narrow sections. No ants will newly enter the tunnel. Consequently, all the ants in the tunnel will eventually leave it. Your task is to write a program that tells which is the last ant to leave the tunnel and when it will.
Figure B.1 shows the movements of the ants during the first two seconds in a tunnel 6 centimeters long. Initially, three ants, numbered 1, 2, and 3, start walking at narrow sections, 1, 2, and 5 centimeters distant from the left end, respectively. After 0.5 seconds, the ants 1 and 2 meet at a wide section, and they pass each other. Two seconds after the start, the ants 1 and 3 meet at a narrow section, and they turn around.
Figure B.1 corresponds to the first dataset of the sample input.
Figure B.1. Movements of ants
Input
The input consists of one or more datasets. Each dataset is formatted as follows.
n
l
d
1
p
1
d
2
p
2
...
d
n
p
n
The first line of a dataset contains two integers separated by a space.
n
(1 ≤
n
≤ 20) represents the number of ants, and
l
(
n
+ 1 ≤
l
≤ 100) represents the length of the tunnel in centimeters. The following
n
lines describe the initial states of ants. Each of the lines has two items,
d
i
and
p
i
, separated by a space. Ants are given numbers 1 through
n
. The ant numbered
i
has the initial direction
d
i
and the initial position
p
i
. The initial direction
d
i
(1 ≤
i
≤
n
) is
L
(to the
left) or
R
(to the right). The initial position
p
i
(1 ≤
i
≤
n
) is an integer specifying the distance from the left end of the tunnel in centimeters. Ants are listed in the left to right order, that is, 1 ≤
p
1
<
p
2
< ... <
p
n
≤
l
- 1.
The last dataset is followed by a line containing two zeros separated by a space.
Output
For each dataset, output how many seconds it will take before all the ants leave the tunnel, and which of the ants will be the last. The last ant is identified by its number. If two ants will leave at the same time, output the number indicating the ant that will leave through the left end of the tunnel.
Sample Input
3 6
R 1
L 2
L 5
1 10
R 1
2 10
R 5
L 7
2 10
R 3
L 8
2 99
R 1
L 98
4 10
L 1
R 2
L 8
R 9
6 10
R 2
R 3
L 4
R 6
L 7
L 8
0 0
Output for the Sample Input
5 1
9 1
7 1
8 2
98 2
8 2
8 3
Problem A
Decimal Sequences
Problem Description: Hanako learned the conjecture that all the non-negative integers appear in the infinite digit sequence of the decimal representation of $\pi$ = 3.14159265..., the ratio of a circle's circumference to its diameter. After that, whenever she watches a sequence of digits, she tries to count up non-negative integers whose decimal representations appear as its subsequences.
For example, given a sequence "
3 0 1
", she finds representations of five non-negative integers 3, 0, 1, 30 and 301 that appear as its subsequences.
Your job is to write a program that, given a finite sequence of digits, outputs the smallest non-negative integer not appearing in the sequence. In the above example, 0 and 1 appear, but 2 does not. So, 2 should be the answer.
Input
The input consists of a single test case.
$n$
$d_1$ $d_2$ ... $d_n$
$n$ is a positive integer that indicates the number of digits. Each of $d_k$'s $(k = 1, ... ,  n)$ is a digit. There is a space or a newline between $d_k$ and $d_{k+1}$ $(k = 1, ..., n - 1)$.
You can assume that $1 \leq n \leq 1000$.
Output
Print the smallest non-negative integer not appearing in the sequence.
Sample Input 1
3
3 0 1
Sample Output 1
2
Sample Input 2
11
9 8 7 6 5 4 3 2 1 1 0
Sample Output 2
12
Sample Input 3
10
9 0 8 7 6 5 4 3 2 1
Sample Output 3
10
Sample Input 4
100
3 6 7 5 3 5 6 2 9 1 2 7 0 9 3 6 0 6 2
6 1 8 7 9 2 0 2 3 7 5 9 2 2 8 9 7 3 6
1 2 9 3 1 9 4 7 8 4 5 0 3 6 1 0 6 3 2
0 6 1 5 5 4 7 6 5 6 9 3 7 4 5 2 5 4 7
4 4 3 0 7 8 6 8 8 4 3 1 4 9 2 0 6 8 9
2 6 6 4 9
Sample Output 4
11
Sample Input 5
100
7 2 7 5 4 7 4 4 5 8 1 5 7 7 0 5 6 2 0
4 3 4 1 1 0 6 1 6 6 2 1 7 9 2 4 6 9 3
6 2 8 0 5 9 7 6 3 1 4 9 1 9 1 2 6 4 2
9 7 8 3 9 5 5 2 3 3 8 4 0 6 8 2 5 5 0
6 7 1 8 5 1 4 8 1 3 7 3 3 5 3 0 6 0 6
5 3 2 2 2
Sample Output 5
86
Sample Input 6
1
3
Sample Output 6
0
Problem A
Rearranging a Sequence
Problem Description: You are given an ordered sequence of integers, ($1, 2, 3, ..., n$). Then, a number of requests will be given. Each request specifies an integer in the sequence. You need to move the specified integer to the head of the sequence, leaving the order of the rest untouched. Your task is to find the order of the elements in the sequence after following all the requests successively.
Input
The input consists of a single test case of the following form.
$n$ $m$
$e_1$
...
$e_m$
The integer $n$ is the length of the sequence ($1 \leq n \leq 200000$). The integer $m$ is the number of requests ($1 \leq m \leq 100000$). The following $m$ lines are the requests, namely $e_1, ...,  e_m$, one per line. Each request $e_i$ ($1 \leq i \leq m$) is an integer between 1 and $n$, inclusive, designating the element to move. Note that, the integers designate the integers themselves to move, not their positions in the sequence.
Output
Output the sequence after processing all the requests. Its elements are to be output, one per line, in the order in the sequence.
Sample Input 1
5 3
4
2
5
Sample Output 1
5
2
4
1
3
Sample Input 2
10 8
1
4
7
3
4
10
1
3
Sample Output 2
3
1
10
4
7
2
5
6
8
9
In Sample Input 1, the initial sequence is (1, 2, 3, 4, 5). The first request is to move the integer 4 to the head, that is, to change the sequence to (4, 1, 2, 3, 5). The next request to move the integer 2 to the head makes the sequence (2, 4, 1, 3, 5). Finally, 5 is moved to the head, resulting in (5, 2, 4, 1, 3).
Problem Name: Problem B: Grid
Problem Description: Given two coordinates (a1,a2) and (b1,b2) on a two-dimensional grid of size r × c, find the number of shortest paths from the first coordinate to the second coordinate. Moving from one cell to an adjacent cell (one step) costs one unit, and moving from cell (e,c-1) to cell (e,0), or from cell (r-1,f) to cell (0,f), also costs one unit.
Input
The input is given in the following format:
r
c
a
1
a
2
b
1
b
2
The input satisfies the following constraints:
1 ≤
r
,
c
≤ 1,000
0 ≤
a
1
,
b
1
< r
0 ≤
a
2
,
b
2
< c
Output
Output the number of shortest paths from the first coordinate to the second coordinate modulo 100,000,007.
Sample Input 1
4 4 0 0 3 3
Sample Output 1
2
Sample Input 2
4 4 0 0 1 1
Sample Output 2
2
Sample Input 3
2 3 0 0 1 2
Sample Output 3
4
Sample Input 4
500 500 0 0 200 200
Sample Output 4
34807775
Problem Name: Problem C: War
Problem Description: There are two countries, A and B, at war. As a soldier in country A, you are tasked with leading a group of n soldiers to occupy a territory in country B.
The territory of country B is represented by a 2D grid. You start by occupying a single cell on the grid. Each of your soldiers has a health level of h_i. Each soldier can move by consuming 1 unit of health. If you are currently at position (a, b), you can choose to move in any of the four directions: (a+1, b), (a-1, b), (a, b+1), or (a, b-1). Once one or more soldiers pass through a cell, that cell is considered occupied.
Your task is to determine the maximum number of cells you can occupy. Assume that the size of the 2D grid is infinite.
Input
The input is given in the following format:
n
h
1
.
.
.
h
n
The input satisfies the following constraints:
1 ≤
n
≤ 500
1 ≤
h
i
≤ 10,000,000
Output
Print the answer on a single line.
Sample Input 1
2
5
5
Sample Output 1
11
Sample Input 2
10
10
10
10
10
10
10
10
10
10
10
Sample Output 2
93
Sample Input 3
5
1
2
3
4
5
Sample Output 3
15
Problem Name: Problem A: Rental DVD Shop NEO
Problem
Problem Description: I started working part-time at a rental DVD shop "NEO". First, I had to study the pricing system of this shop.
There are three types of rental DVDs: old releases, semi-new releases, and new releases, and the rental fee for one DVD is
a
yen,
b
yen, and
c
yen, respectively.
At the time of payment, you can apply the following set rental multiple times.
Select several DVDs that have not yet been set for rental.
If the number of DVDs selected is
d
or more and the total amount of the selected DVDs exceeds
(number of selected DVDs)
*
e
yen, they can be rented for
(number of selected DVDs)
*
e
yen.
If the number of DVDs selected is less than
d
and the total amount of the selected DVDs exceeds
d
*
e
yen, they can be rented for
d
*
e
yen.
If none of the above applies, the selected DVDs will be rented at the regular price.
Here, I noticed a problem. The set rental is not automatically applied when passed through the register, but is manually applied. This may result in applying set rental that is not optimal (there is room for further cost reduction). This may lead to complaints. I don't like complaint handling, so I decided to create a program to calculate the fee when the set rental is optimally applied.
Input
The input consists of multiple data sets.
Each data set is represented as follows.
The first line contains five integers
a
,
b
,
c
,
d
,
e
separated by spaces.
The second line gives the number of rental DVDs. Three integers
na
,
nb
, and
nc
are given separated by spaces, representing the number of old releases, semi-new releases, and new releases, respectively.
The end of the input is five zeros.
a
b
c
d
e
na
nb
nc
Constraints
The input satisfies the following conditions.
All values in the input are integers.
0 <
a
<
b
<
e
<
c
≤ 1000
0 <
d
≤ 100000
0 ≤
na
,
nb
,
nc
≤ 100000
0 <
na
+
nb
+
nc
The number of data sets is at most 100.
Output
For each data set, output the fee when the set rental is optimally applied on one line.
Sample Input
70 100 340 4 200
1 1 4
70 100 340 4 200
0 1 3
70 100 340 4 200
1 1 2
0 0 0 0 0
Sample Output
970
800
800
Explanation
In the first data set, there are 1 old release, 1 semi-new release, and 4 new releases. Since the set rental requires at least 4 DVDs, it cannot be applied this time. Therefore, the fee is 70+100+340*4=1470 yen.
In the second data set, there are 0 old releases, 1 semi-new release, and 3 new releases. Since the set rental requires at least 4 DVDs, it cannot be applied this time. Therefore, the fee is 100+340*4=1460 yen.
In the third data set, there are 1 old release, 1 semi-new release, and 2 new releases. If you choose all three DVDs, the total fee will be 70+100+340+200*3 = 1210 yen. Therefore, it is optimal to apply the set rental to two new releases. The fee will be 70+100+340*2+200*2 = 950 yen.
Problem Name: Divisor
Problem
Problem Description: Given a natural number N less than or equal to 12, find the smallest natural number whose number of divisors is exactly N.
Input
A single natural number
N
is given on one line.
Constraints
1 ≤
N
≤ 12
Output
Output the smallest natural number whose number of divisors is exactly
N
on one line.
Sample Input 1
1
Sample Output 1
1
Sample Input 2
2
Sample Output 2
2
Sample Input 3
3
Sample Output 3
4
Selection of Participants of an Experiment
Problem Description: Dr. Tsukuba has devised a new method of programming training.
In order to evaluate the effectiveness of this method,
he plans to carry out a control experiment.
Having two students as the participants of the experiment,
one of them will be trained under the conventional method
and the other under his new method.
Comparing the final scores of these two,
he will be able to judge the effectiveness of his method.
It is important to select two students having the closest possible scores,
for making the comparison fair.
He has a list of the scores of all students
who can participate in the experiment.
You are asked to write a program which selects two of them
having the smallest difference in their scores.
Input
The input consists of multiple datasets, each in the following format.
n
a
1
a
2
…
a
n
A dataset consists of two lines.
The number of students
n
is given in the first line.
n
is an integer satisfying 2 ≤
n
≤ 1000.
The second line gives scores of
n
students.
a
i
(1 ≤
i
≤
n
) is the score of the
i
-th student, which is a non-negative integer not greater than 1,000,000.
The end of the input is indicated by a line containing a zero.
The sum of
n
's of all the datasets does not exceed 50,000.
Output
For each dataset, select two students with the smallest difference in their scores,
and output in a line (the absolute value of) the difference.
Sample Input
5
10 10 10 10 10
5
1 5 8 9 11
7
11 34 83 47 59 29 70
0
Output for the Sample Input
0
1
5
Daruma Otoshi
Problem Description: You are playing a variant of a game called "Daruma Otoshi (Dharma Block Striking)".
At the start of a game, several wooden blocks of the same size but with varying weights
are stacked on top of each other, forming a tower.
Another block symbolizing Dharma is placed atop.
You have a wooden hammer with its head thicker than the height of a block,
but not twice that.
You can choose any two adjacent blocks, except Dharma on the top,
differing at most 1 in their weight,
and push both of them out of the stack with a single blow of your hammer.
The blocks above the removed ones then fall straight down,
without collapsing the tower.

You cannot hit a block pair with weight difference of 2 or more,
for that makes too hard to push out blocks while keeping the balance of the tower.
There is no chance in hitting three blocks out at a time,
for that would require superhuman accuracy.
The goal of the game is to remove as many blocks as you can.
Your task is to decide the number of blocks that can be removed
by repeating the blows in an optimal order.
Figure D1. Striking out two blocks at a time
In the above figure, with a stack of four blocks weighing 1, 2, 3, and
1, in this order from the bottom, you can hit middle
two blocks, weighing 2 and 3, out from the stack.  The blocks above will
then fall down, and two blocks weighing 1 and the Dharma block will remain.
You can then push out the remaining pair of weight-1 blocks after that.
Input
The input consists of multiple datasets.
The number of datasets is at most 50.
Each dataset is in the following format.
n
w
1
w
2
…
w
n
n
is the number of blocks, except Dharma on the top.
n
is a positive integer not exceeding 300.
w
i
gives the weight of the
i
-th block counted from the bottom.
w
i
is an integer between 1 and 1000, inclusive.
The end of the input is indicated by a line containing a zero.
Output
For each dataset, output in a line the maximum number of blocks you can remove.
Sample Input
4
1 2 3 4
4
1 2 3 1
5
5 1 2 3 6
14
8 7 1 4 3 5 4 1 6 8 10 4 6 5
5
1 3 5 1 3
0
Output for the Sample Input
4
4
2
12
0
Almost Identical Programs
Problem Description: The programming contest named
Concours de Programmation Comtemporaine Interuniversitaire (CPCI)
has a judging system similar to that of ICPC;
contestants have to submit correct outputs for two different inputs
to be accepted as a correct solution.

Each of the submissions should include the program that generated
the output.  A pair of submissions is judged to be a correct
solution when, in addition to the correctness of the outputs, they
include an identical program.
Many contestants, however, do not stop including a different version
of their programs in their second submissions, after modifying a
single string literal in their programs representing 
the input file name, attempting to process different input.

The organizers of CPCI are exploring the possibility of showing a
special error message for such
close
submissions, 
indicating contestants what's wrong with such submissions.

Your task is to detect such close submissions.
Input
The input consists of at most 100 datasets, each in the following format.
s
1
s
2
Each of
s
1
and
s
2
is
a string written in a line, with the length between 1 and 200, inclusive.
They are the first and the second submitted programs respectively.

A program consists of lowercase letters (
a
,
b
, ...,
z
), uppercase letters (
A
,
B
, ...,
Z
),
digits (
0
,
1
, ...,
9
), double quotes (
"
), and semicolons (
;
).
When double quotes occur in a program, there are always even number of them.
The end of the input is indicated by a line containing one '
.
' (period).
Output
For each dataset, print the judge result in a line.
If the given two programs are identical, print
IDENTICAL
.
If two programs differ with only one corresponding string literal, print
CLOSE
.
Otherwise, print
DIFFERENT
.

A string literal is a possibly empty sequence of characters between an
odd-numbered occurrence of a double quote and the next occurrence of
a double quote.
Sample Input
print"hello";print123
print"hello";print123
read"B1input";solve;output;
read"B2";solve;output;
read"C1";solve;output"C1ans";
read"C2";solve;output"C2ans";
""""""""
"""42"""""
slow"program"
fast"code"
"super"fast"program"
"super"faster"program"
X""
X
I"S""CREAM"
I"CE""CREAM"
11"22"11
1"33"111
.
Output for the Sample Input
IDENTICAL
CLOSE
DIFFERENT
CLOSE
DIFFERENT
DIFFERENT
DIFFERENT
CLOSE
DIFFERENT
Boolean Expression Compressor
Problem Description: You are asked to build a compressor for Boolean expressions
that transforms expressions to the shortest form keeping their meaning.
The grammar of the Boolean expressions has terminals
0
1
a
b
c
d
-
^
*
(
)
, start symbol <E> and the following production rule:
<E>  ::=
0
|
1
|
a
|
b
|
c
|
d
|
-
<E>  |
(
<E>
^
<E>
)
|
(
<E>
*
<E>
)
Letters
a
,
b
,
c
and
d
represent Boolean
variables that have values of either
0
or
1
.
Operators are evaluated as shown in the Table below.
In other words,
-
means negation (NOT),
^
means exclusive disjunction (XOR), and
*
means logical conjunction (AND).
Table: Evaluations of operators
Write a program that calculates the length of the shortest expression that
evaluates equal to the given expression with whatever values of the four variables.
For example,
0
, that is the first expression in the sample input,
cannot be shortened further.
Therefore the shortest length for this expression is 1.
For another example,
(a*(1*b))
, the second in the sample input,
always evaluates equal to
(a*b)
and
(b*a)
,
which are the shortest.   The output for this expression, thus, should be
5
.
Input
The input consists of multiple datasets.
A dataset consists of one line, containing an expression
conforming to the grammar described above.
The length of the expression is less than or equal to 16 characters.
The end of the input is indicated by a line containing one

.
 (period).
The number of datasets in the input is at most 200.
Output
For each dataset, 
output a single line containing an integer which is the length of the
shortest expression that has the same value as the given expression for 
all combinations of values in the variables.
Sample Input
0
(a*(1*b))
(1^a)
(-(-a*-b)*a)
(a^(b^(c^d)))
.
Output for the Sample Input
1
5
2
1
13
Income Inequality
Problem Description: We often compute the average as the first step
in processing statistical data.
Yes, the average is a good tendency measure of data,
but it is not always the best.
In some cases, the average may hinder the understanding
of the data.
For example, consider the national income of a country.
As the term
income inequality
suggests,
a small number of people earn a good portion of the gross national income
in many countries.
In such cases, the average income computes much higher than the
income of the vast majority.
It is not appropriate to regard the average as the income of typical people.
Let us observe the above-mentioned phenomenon in some concrete data.
Incomes of
n
people,
a
1
, ... ,
a
n
, are given.
You are asked to write a program that reports the number of people
whose incomes are less than or equal to the average
(
a
1
+ ... +
a
n
) /
n
.
Input
The input consists of multiple datasets, each in the following format.
n
a
1
a
2
...
a
n
A dataset consists of two lines.
In the first line, the number of people
n
is given.
n
is an integer satisfying 2 ≤
n
≤ 10 000.
In the second line, incomes of
n
people are given.
a
i
(1 ≤
i
≤
n
) is the income
of the
i
-th person.
This value is an integer greater than or equal to 1 and
less than or equal to 100 000.
The end of the input is indicated by a line containing a zero.
The sum of
n
's of all the datasets does not exceed 50 000.
Output
For each dataset, output the number of people whose incomes are
less than or equal to the average.
Sample Input
7
15 15 15 15 15 15 15
4
10 20 30 60
10
1 1 1 1 1 1 1 1 1 100
7
90 90 90 90 90 90 10
7
2 7 1 8 2 8 4
0
Output for the Sample Input
7
3
9
1
4
Problem Name: Amida, the City of Miracle
Problem Description: The mayor of the city of miracle, Amida, is not elected by the usual election process like other cities. This city, which was exhausted by long political struggles and natural disasters, decided to entrust the fate of all candidates to a lottery, called Amida-kuji, in order to choose all candidates fairly and to make the mayor the one born under a lucky star. Later, this lottery became known as Amida-kuji.
The election is conducted as follows: A long vertical line is drawn for each candidate, and several horizontal lines are drawn there. The horizontal lines are drawn so as to connect the midpoints of adjacent vertical lines. "Elected" is written under one of the vertical lines, but it is hidden from the candidates which vertical line is elected. Each candidate selects one vertical line. When all candidates have made their choices, they follow the line from top to bottom. However, when a horizontal line is encountered on the way, they move to the vertical line on the opposite side connected by the horizontal line and continue to follow it downwards. When they reach the bottom of the vertical line, the one who was found to be "elected" there becomes the next mayor.
This method worked well. Under the lucky mayor, there was a peaceful era with little conflict or disaster. However, in recent years, the limitations of this method have become evident due to population growth. As the number of candidates increased, the Amida-kuji became large-scale, and the manual calculation became very time-consuming. Therefore, the city has asked you, a programmer at the city hall, to computerize the Amida-kuji.
Your job is to write a program that will determine which vertical line is reached when the structure of the Amida-kuji and the position of the selected vertical line are given.
The following figure shows the input and output contents given as a sample.
Input
The input consists of multiple datasets. One dataset is given as follows:
n
m
a
Horizontal line 1
Horizontal line 2
Horizontal line 3
...
Horizontal line
m
n
,
m
,
a
are integers that satisfy 2 <=
n
<= 100, 0 <=
m
<= 1000, 1 <=
a
<=
n
, respectively, and represent the number of vertical lines, the number of horizontal lines, and the number of vertical lines to be examined, respectively.
The horizontal line data is given as follows:
h
p
q
h
,
p
, and
q
are integers satisfying 1 <=
h
<= 1000, 1 <=
p
<
q
<=
n
, respectively, and
h
represents the height of the horizontal line, and
p
and
q
represent the numbers of the two vertical lines connected to the horizontal line.
No more than two or more different horizontal lines are attached to the same height of one vertical line.
At the end of the input, there is a line consisting of three zeros separated by spaces.
Output
For each dataset, output the number of the vertical line at the bottom when traced from the top of vertical line a on a separate line.
Sample Input
4 4 1
3 1 2
2 2 3
3 3 4
1 3 4
0 0 0
Output for the Sample Input
4