alexjercan/bugnet huggingface dataset:
When Can We Meet?

The ICPC committee would like to have its meeting as soon as
possible to address every little issue of the next contest.
However, members of the committee are so busy maniacally developing
(possibly useless) programs that it is very difficult to arrange
their schedules for the meeting.
So, in order to settle the meeting date, the chairperson requested every
member to send back a list of convenient dates by E-mail.
Your mission is to help the chairperson, who is now dedicated to other
issues of the contest, by writing a program that
chooses the best date from the submitted lists.
Your program should find the date convenient for the most members.
If there is more than one such day, the earliest is the best.

Input

The input has multiple data sets, each starting with a line
containing the number of committee members and the quorum of the meeting.

N Q

Here, N, meaning the size of the committee, and Q
meaning the quorum, are positive integers. N is less than 50,
and, of course, Q is less than or equal to N.

N lines follow, each describing convenient dates for a
committee
member in the following format.

M Date1
Date2 ... DateM

Here, M means the number of convenient dates for
the member, which is an integer greater than or equal to zero.
The remaining items in the line are his/her dates of convenience,
which are positive integers less than 100, that is, 1 means tomorrow,
2 means the day after tomorrow, and so on.
They are in ascending order without any repetition
and separated by a space character.
Lines have neither leading nor trailing spaces.

A line containing two zeros indicates the end of the input.

Output

For each data set, print a single line containing the date number
convenient for the largest number of committee members.
If there is more than one
such date, print the earliest. However, if no dates are convenient
for more than or equal to the quorum number of members, print 0 instead.

Sample Input

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

Output for the Sample Input

4
5
0
2
Get Many Persimmon Trees

Seiji Hayashi had been a professor of the Nisshinkan Samurai School
in the domain of Aizu for a long time in the 18th century.
In order to reward him for his meritorious career in education,
Katanobu Matsudaira, the lord of the domain of Aizu, had decided to
grant him a rectangular estate within a large field in the Aizu Basin.
Although the size (width and height) of the estate was strictly specified
by the lord, he was allowed to choose any location for the estate
in the field.
Inside the field which had also a rectangular shape,
many Japanese persimmon trees,
whose fruit was one of the famous products of the Aizu region
known as 'Mishirazu Persimmon', were planted.
Since persimmon was Hayashi's favorite fruit, he wanted to have
as many persimmon trees as possible in the estate given by the lord.

For example, in Figure 1, the entire field is a rectangular grid whose
width and height are 10 and 8 respectively. Each asterisk (*)
represents a place of a persimmon tree. If the specified width and
height of the estate are 4 and 3 respectively, the area surrounded by
the solid line contains the most persimmon trees. Similarly, if the
estate's width is 6 and its height is 4, the area surrounded by the
dashed line has the most, and if the estate's width and height are 3
and 4 respectively, the area surrounded by the dotted line contains
the most persimmon trees. Note that the width and height cannot be
swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure
1.

Figure 1: Examples of Rectangular Estates

Your task is to find the estate of a given size (width and height)
that contains the largest number of persimmon trees.

Input

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

N

W H

x1 y1

x2 y2

...

xN yN

S T

N is the number of persimmon trees,
which is a positive integer less than 500.
W and H are the width and the height of the entire field
respectively.
You can assume that both W and H are positive integers
whose values are less than 100.
For each i (1 <= i <= N),
xi and yi are
coordinates of the i-th persimmon tree in the grid.
Note that the origin of each coordinate is 1.
You can assume that 1 <= xi <= W
and 1 <= yi <= H,
and no two trees have the same positions.
But you should not assume that the persimmon trees are sorted in some order
according to their positions.
Lastly, S and T are positive integers of
the width and height respectively of the estate given by the lord.
You can also assume that 1 <= S <= W
and 1 <= T <= H.

The end of the input is indicated by a line that solely contains a zero.

Output

For each data set, you are requested to print one line containing the
maximum possible number of persimmon trees that can be included in an
estate of the given size.

Sample Input

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

Output for the Sample Input

4
3
The Secret Number

Your job is to find out the secret number hidden in a matrix,
each of whose element is a digit ('0'-'9') or a letter
('A'-'Z'). You can see an example matrix in Figure 1.

Figure 1: A Matrix

The secret number and other non-secret ones are coded in a
matrix as sequences of digits in a decimal format. You should
only consider sequences of digits D1
D2 ... Dn such that
Dk+1 (1 <= k < n)
is either right next to or immediately below
Dk in the matrix. The secret you are
seeking is the largest number coded in this manner.

Four coded numbers in the matrix in Figure 1, i.e., 908820,
23140037, 23900037, and 9930, are depicted in Figure 2. As you
may see, in general, two or more coded numbers may share a
common subsequence. In this case, the secret number is
23900037, which is the largest among the set of all coded numbers
in the matrix.

Figure 2: Coded Numbers

In contrast, the sequences illustrated in Figure 3 should be
excluded: 908A2 includes a letter; the fifth digit of 23149930
is above the fourth; the third digit of 90037 is below right of
the second.

Figure 3: Inappropriate Sequences

Write a program to figure out the secret number from a given
matrix.

Input

The input consists of multiple data sets, each data set
representing a matrix. The format of each data set is as
follows.

W H

C11C12 ... C1W

C21C22 ... C2W

...

CH1CH2 ... CHW

In the first line of a data set, two positive integers W
and H are given. W indicates the width (the
number of columns) of the matrix, and H indicates the
height (the number of rows) of the matrix. W+H is less
than or equal to 70.

H lines follow the first line, each of which corresponds
to a row of the matrix in top to bottom order. The i-th
row consists of W characters
Ci1Ci2
... CiW in left to right order. You may
assume that the matrix includes at least one non-zero digit.

Following the last data set, two zeros in a line indicate the
end of the input.

Output

For each data set, print the secret number on a line. Leading zeros
should be suppressed.

Sample Input

7 4
9R2A993
0E314A0
8A900DE
820R037
6 7
JH03HE
ID7722
0DA1AH
30C9G5
99971A
CA7EAI
AHLBEM
20 2
A1234567891234CBDEGH
BDEDF908034265091499
0 0

Output for the Sample Input

23900037
771971
12345908034265091499
Square Carpets

Mr. Frugal bought a new house.
He feels deeply in love with his new house
because it has a comfortable living room
in which he can put himself completely at ease.
He thinks his new house is a really good buy.

But, to his disappointment,
the floor of its living room has some scratches on it.

The floor has a rectangle shape, covered with square panels.
He wants to replace all the scratched panels with flawless panels,
but he cannot afford to do so.
Then, he decides to cover all the scratched panels
with carpets.

The features of the carpets he can use are as follows.

Carpets are square-shaped.
Carpets may overlap each other.
Carpets cannot be folded.
Different sizes of carpets are available.
Lengths of sides of carpets are multiples of that of the panels.

The carpets must cover all the scratched panels,
but must not cover any of the flawless ones.

For example,
if the scratched panels are as shown in Figure 1,
at least 6 carpets are needed.

Figure 1: Example Covering

As carpets cost the same irrespective of their sizes,
Mr. Frugal would like to use as few number of carpets as possible.

Your job is to write a program which tells the minimum number
of the carpets to cover all the scratched panels.

Input

The input consists of multiple data sets.

As in the following, the end of the input is indicated by a line
containing two zeros.

DataSet1

DataSet2

...

DataSetn

0 0

Each data set (DataSeti) represents the
state of a floor. The format of a data set is as follows.

W H

P11 P12 P13 ... P1W

P21 P22 P23 ... P2W

...

PH1 PH2
PH3 ... PHW

The positive integers W and H are the numbers of panels
on the living room
in the x- and y- direction, respectively.
The values of W and H are no more than 10.
The integer Pyx represents the state of the panel.
The value of Pyx means,

0: flawless panel (must not be covered),

1: scratched panel (must be covered).

Output

For each data set,
your program should output a line containing one integer which
represents the minimum number of the carpets to cover
all of the scratched panels.

Sample Input

4 3
0 1 1 1
1 1 1 1
1 1 1 1
8 5
0 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 0 1 1 1 1
0 1 1 1 0 1 1 1
8 8
0 1 1 0 0 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 0 0 1 1 0
10 10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
0 0

Output for the Sample Input

2
6
14
29
Problem A: Hanafuda Shuffle

There are a number of ways to shuffle a deck of cards. Hanafuda
shuffling for Japanese card game 'Hanafuda' is one such example.
The following is how to perform Hanafuda shuffling.

There is a deck of n cards. Starting from the p-th card
from the top of the deck, c cards are pulled out
and put on the top of the deck, as shown in Figure 1.
This operation, called a cutting operation, is repeated.

Write a program that simulates Hanafuda shuffling and answers which
card will be finally placed on the top of the deck.

Figure 1: Cutting operation

Input

The input consists of multiple data sets.
Each data set starts with a line containing two positive integers n
(1 <= n <= 50) and r (1 <= r <= 50); n and
r are the number of cards in the deck and the number of cutting
operations, respectively.

There are r more lines in the data set, each of which
represents a cutting operation. These cutting operations
are performed in the listed order.
Each line contains two positive integers p and c
(p + c <= n + 1).
Starting from the p-th card from the top of the deck, c
cards should be pulled out and put on the top.

The end of the input is indicated by a line which contains two zeros.

Each input line contains exactly two integers separated by a space
character.
There are no other characters in the line.

Output

For each data set in the input, your program
should write the number of the top card after the shuffle.
Assume that at the beginning the cards
are numbered from 1 to n, from the bottom to the top.
Each number should be written in a separate line
without any superfluous characters such as leading or following spaces.

Sample Input

5 2
3 1
3 1
10 3
1 10
10 1
8 3
0 0

Output for the Sample Input

4
4
Problem B: Red and Black

There is a rectangular room, covered with square tiles. Each tile is
colored either red or black. A man is standing on a black tile.
From a tile, he can move to one of four adjacent tiles. But he can't
move on red tiles, he can move only on black tiles.

Write a program to count the number of black tiles which he can reach
by repeating the moves described above.

Input

The input consists of multiple data sets.
A data set starts with a line containing two positive integers W and H;
W and H are the numbers of tiles in the x-
and y- directions, respectively. W and H are
not more than 20.

There are H more lines in the data set, each of which
includes W characters. Each character represents the color of a
tile as follows.

'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)

The end of the input is indicated by a line consisting of two zeros.

Output

For each data set, your program
should output a line which contains the number of
tiles he can reach from the initial tile (including itself).

Sample Input

6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0

Output for the Sample Input

45
59
6
13
Problem C: Unit Fraction Partition

A fraction whose numerator is 1
and whose denominator is a positive integer
is called a unit fraction.
A representation of a positive rational number
p/q
as the sum of finitely many unit fractions is called a partition of
p/q
into unit fractions.
For example,
1/2 + 1/6
is a partition of
2/3
into unit fractions.
The difference in the order of addition is disregarded.
For example, we do not distinguish
1/6 + 1/2
from
1/2 + 1/6.

For given four positive integers
p,
q,
a, and
n,
count the number
of partitions of
p/q
into unit fractions satisfying the following two conditions.

The partition is the sum of at most
n
many unit fractions.

The product of the denominators of the unit fractions in the
partition is less than or equal to
a.

For example, if
(p,q,a,n) = (2,3,120,3),
you should report 4 since

enumerates all of the valid partitions.

Input

The input is a sequence of at most 1000 data sets followed by a terminator.

A data set is a line containing four positive integers
p,
q,
a, and
n
satisfying
p,q <= 800,
a <= 12000
and
n <= 7.
The integers are separated by a space.

The terminator is composed of just one line
which contains four zeros separated by a space.
It is not a part of the input data but a mark for the end of the input.

Output

The output should be composed of lines
each of which contains a single integer.
No other characters should appear in the output.

The output integer corresponding to a data set
p,
q,
a,
n
should be the number of all partitions of
p/q
into at most
n
many unit fractions such that the product of the denominators of the
unit fractions is less than or equal to
a.

Sample Input

2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 3
2 3 12000 7
54 795 12000 7
2 3 300 1
2 1 200 5
2 4 54 2
0 0 0 0

Output for the Sample Input

4
7
6
2
42
1
0
9
3
Problem D: Circle and Points

You are given N points in the xy-plane. You have a
circle of radius one and move it on the xy-plane, so as to
enclose as many of the points as possible. Find how many points can be
simultaneously enclosed at the maximum. A point is considered
enclosed by a circle when it is inside or on the circle.

Fig 1. Circle and Points

Input

The input consists of a series of data sets, followed by a single line
only containing a single character '0', which indicates the end of the
input. Each data set begins with a line containing an integer N,
which indicates the number of points in the data set. It is
followed by N lines describing the coordinates of the
points. Each of the N lines has two decimal fractions X
and Y, describing the x- and y-coordinates of a
point, respectively. They are given with five digits after the decimal
point.

You may assume 1 <= N <= 300, 0.0 <= X <= 10.0, and 0.0
<= Y <= 10.0. No two points are closer than 0.0001. No two
points in a data set are approximately at a distance of 2.0. More
precisely, for any two points in a data set, the distance d
between the two never satisfies 1.9999 <= d <= 2.0001. Finally,
no three points in a data set are simultaneously very close to a
single circle of radius one. More precisely,
let P1, P2, and P3 be any three points in a
data set, and d1, d2, and d3
the distances from an arbitrarily selected point in the xy-plane to each of them
respectively. Then it never simultaneously holds that 0.9999 <=
di <= 1.0001 (i = 1, 2, 3).

Output

For each data set, print a single line containing the maximum number
of points in the data set that can be simultaneously enclosed by a
circle of radius one. No other characters including leading and
trailing spaces should be printed.

Sample Input

3
6.47634 7.69628
5.16828 4.79915
6.69533 6.20378
6
7.15296 4.08328
6.50827 2.69466
5.91219 3.86661
5.29853 4.16097
6.10838 3.46039
6.34060 2.41599
8
7.90650 4.01746
4.10998 4.18354
4.67289 4.01887
6.33885 4.28388
4.98106 3.82728
5.12379 5.16473
7.84664 4.67693
4.02776 3.87990
20
6.65128 5.47490
6.42743 6.26189
6.35864 4.61611
6.59020 4.54228
4.43967 5.70059
4.38226 5.70536
5.50755 6.18163
7.41971 6.13668
6.71936 3.04496
5.61832 4.23857
5.99424 4.29328
5.60961 4.32998
6.82242 5.79683
5.44693 3.82724
6.70906 3.65736
7.89087 5.68000
6.23300 4.59530
5.92401 4.92329
6.24168 3.81389
6.22671 3.62210
0

Output for the Sample Input

2
5
5
11
Problem E: Water Tank

Mr. Denjiro is a science teacher.

Today he has just received a specially ordered water tank that
will certainly be useful for his innovative experiments on water
flow.

Figure 1: The water tank

The size of the tank is 100cm (Width) * 50cm (Height) * 30cm (Depth)
(see Figure 1).

For the experiments, he fits several partition boards inside of
the tank parallel to the sideboards.

The width of each board is equal to the depth of the tank, i.e. 30cm.
The height of each board is less than that of the tank, i.e. 50 cm,
and differs one another.

The boards are so thin that he can neglect the thickness in the experiments.

Figure 2: The front view of the tank

The front view of the tank is shown in Figure 2.

There are several faucets above the tank and he turns them on at
the beginning of his experiment. The tank is initially empty.
Your mission is to write a
computer program to simulate water flow in the tank.

Input

The input consists of multiple data sets.

D is the number of the data sets.

D

DataSet1

DataSet2

...

DataSetD

The format of each data set
(DataSetd , 1 <= d <= D)
is as follows.

N

B1 H1

B2 H2

...

BN HN

M

F1 A1

F2 A2

...

FM AM

L

P1 T1

P2 T2

...

PL TL

Each line in the data set contains one or two integers.

N is the number of the boards he sets in the tank .
Bi and Hi
are the x-position (cm) and the height (cm)
of the i-th board,
where 1 <= i <= N .

Hi s differ from one another. You may assume the
following.

0 < N < 10 ,

0 < B1 < B2 < ... < BN < 100 ,

0 < H1 < 50 ,
0 < H2 < 50 ,
..., 0 < HN < 50.

M is the number of the faucets above the tank .
Fj and Aj are
the x-position (cm) and the amount of water flow (cm3/second)
of the j-th faucet ,
where 1 <= j <= M .

There is no faucet just above any boards .
Namely, none of Fj is equal to Bi .

You may assume the following .

0 < M <10 ,

0 < F1 < F2 < ...
< FM < 100 ,

0 < A1 < 100,
0 < A2 < 100, ...
0 < AM < 100.

L is the number of observation time and location.
Pk is the x-position (cm) of the k-th
observation point.
Tk is the k-th observation time in seconds from the beginning.

None of Pk
is equal to Bi .

You may assume the following .

0 < L < 10 ,

0 < P1 < 100,
0 < P2 < 100, ...,
0 < PL < 100 ,

0 < T1 < 1000000,
0 < T2 < 1000000,
... ,
0 < TL < 1000000.

Output

For each data set,
your program should output L lines each containing
one real number which represents the height (cm) of the water level specified
by the x-position Pk
at the time Tk.

Each answer may not have an error greater than 0.001.
As long as this condition is satisfied,
you may output any number of digits after the decimal point.

After the water tank is filled to the brim,
the water level at any Pk is equal to the
height of the tank, that is, 50 cm.

Sample Input

2
5
15 40
35 20
50 45
70 30
80 10
3
20 3
60 2
65 2
6
40 4100
25 7500
10 18000
90 7000
25 15000
25 22000
5
15 40
35 20
50 45
70 30
80 10
2
60 4
75 1
3
60 6000
75 6000
85 6000

Output for the Sample Input

0.666667
21.4286
36.6667
11.1111
40.0
50.0
30.0
13.3333
13.3333
Problem F: Name the Crossing

The city of Kyoto is well-known for its Chinese plan: streets are
either North-South or East-West. Some streets are numbered, but most
of them have real names.

Crossings are named after the two streets crossing there,
e.g. Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo
street. But there is a problem: which name should come first?
At first the order seems quite arbitrary: one says Kawaramachi-Sanjo
(North-South first) but Shijo-Kawaramachi (East-West first). With some
experience, one realizes that actually there
seems to be an "order" on the streets, for instance in the above
Shijo is "stronger" than Kawaramachi, which in turn is "stronger" than
Sanjo.
One can use this order to deduce the names of other crossings.

You are given as input a list of known crossing names X-Y.
Streets are either North-South or East-West, and only orthogonal streets
may cross.

As your list is very incomplete, you start by completing it using
the following rule:

two streets A and B have equal strength if (1) to (3) are
all true:

they both cross the same third street C in the input

there is no street D such that D-A and B-D appear in the input

there is no street E such that A-E and E-B appear in the input

We use this definition to extend our strength relation:

A is stronger than B, when there is a
sequence A = A1, A2, ..., An = B,
with n at least 2,

where, for any i in 1 .. n-1, either
Ai-Ai+1 is an input crossing or
Ai and Ai+1 have equal strength.

Then you are asked whether some other possible crossing names X-Y are
valid. You should answer affirmatively if you can infer the validity of a
name, negatively if you cannot. Concretely:

YES if you can infer that the two streets are orthogonal, and X
is stronger than Y

NO otherwise

Input

The input is a sequence of data sets, each of the form

N
Crossing1
...
CrossingN
M
Question1
...
QuestionM

Both Crossings and Questions are of the form

X-Y

where X and Y are strings of alphanumerical characters,
of lengths no more than 16. There is no white space, and case matters
for alphabetical characters.

N and M are between 1 and 1000 inclusive, and there are
no more than 200 streets in a data set.

The last data set is followed by a line containing a zero.

Output

The output for each data set should be composed of M+1 lines,
the first one containing the number of streets
in the Crossing part of the input, followed by the answers to
each question, either YES or NO without any spaces.

Sample Input

7
Shijo-Kawaramachi
Karasuma-Imadegawa
Kawaramachi-Imadegawa
Nishioji-Shijo
Karasuma-Gojo
Torimaru-Rokujo
Rokujo-Karasuma
6
Shijo-Karasuma
Imadegawa-Nishioji
Nishioji-Gojo
Shijo-Torimaru
Torimaru-Gojo
Shijo-Kawabata
4
1jo-Midosuji
Midosuji-2jo
2jo-Omotesando
Omotesando-1jo
4
Midosuji-1jo
1jo-Midosuji
Midosuji-Omotesando
1jo-1jo
0

Output for the Sample Input

8
YES
NO
YES
NO
YES
NO
4
YES
YES
NO
NO