alexjercan/bugnet huggingface dataset:
Road Improvement

Aizu is a country famous for its rich tourism resources and has N cities, each of which is uniquely identified with a number (0 to N-1). It has a road network consisting of M one-way roads connecting a city to another.

All the roads connecting the cities in Aizu have a row of cherry trees along their routes. For enhancing the cherry-viewing experience, a proposal was made to modify the road network so that a tourist can travel around all the roads. To achieve this target, it was decided to construct several one-way roads, each connecting two cities and abiding by the following rules.

The newly constructed road is for one-way traffic

Starting from any city, a tourist is able to make a roundtrip and return to the city, whereby he/she drives all the roads exhaustively, including the newly constructed ones. Multiple passages of some of the roads are allowed.

You, as a tourism promotion officer, are assigned with the task of writing a program for the road construction project.

Write a program to determine the minimum number of roads to be constructed given the road network information in Aizu.

Input

The input is given in the following format.

N M
s_1 t_1
s_2 t_2
:
s_M t_M

The first line provides the number of cities N (1 ≤ N ≤ 104) and roads M (0 ≤ M ≤ 105). Each of the subsequent M lines provides the numbers assigned to start and destination cities for the i-th road: s_i, t_i (0 ≤ s_i, t_i ≤ N-1) , where s_i ≠ t_i. (no duplicate appearance of a road)

Output

Output the minimum number of roads to be newly constructed.

Sample Input 1

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

Sample Output 1

2

Sample Input 2

6 9
0 2
2 1
1 0
2 3
4 3
4 5
5 4
5 2
3 4

Sample Output 2

0
Charging System for Network

There is a network consisting of N machines (sequentially numbered from 0 to N-1) interconnected through N-1 bidirectional communication cables. Any two machines can perform bidirectional communication through one or more cables. From time to time, machines in the network are renewed. When a new machine is introduced, the cables directly connected to it are also replaced with thicker ones to cope with the increased volume of communication traffic.

The communication fee arising from communication traffic between any two machines is calculated by summing the charges assigned to all the cables routing via the two. A unique charging scheme is employed in this system: if the size of a cable is a multiple of K, then the cable is not charged (free of charge). Other cables are charged according to their sizes.

Based on the given information on the network topology and Q instructions, write a program to execute each instruction.

Increase the sizes of all cables directly connected to the machine x by d.

Report the communication charge between the machines s and t.

Input

The input is given in the following format.

N K
a_1 b_1 c_1
a_2 b_2 c_2
:
a_{N−1} b_{N−1} c_{N−1}
Q
query_1
query_2
:
query_Q

The first line provides the number of machines N (2 ≤ N ≤ 105) and the cable size K (1 ≤ K ≤ 105) (the reference value for determining free of charge cables). Each of subsequent N-1 lines provides the i-th cable information that directly connects two machines a_i and b_i (0 ≤ a_i < b_i ≤ N-1), followed by the cable’s initial size c_i (1 ≤ c_i ≤ 105). For any pair of machines, the number of cables directly connecting them is either one or zero. The next line following them provides the number of instructions Q (1 ≤ Q ≤ 105). Each of the Q lines following it provides the i-th instruction query_i, which is either one of the following two:

add x d

or

send s t

The instruction add x d increase the size of all cables directly connected to machine x (0 ≤ x ≤ N-1) by d (1 ≤ d ≤ 105).

The instruction send s t reports the charge imposed to the communication between the two machines s (0 ≤ s ≤ N-1) and t (0 ≤ t ≤ N-1), where s ≠ t.

At least one send instruction is included in the input information.

Output

For each send command, output the communication charge between s and t.

Sample Input 1

6 3
0 1 1
0 2 1
0 3 1
2 4 1
2 5 1
3
send 1 4
add 2 2
send 1 4

Sample Output 1

3
1
Flag

AHK Education, the educational program section of Aizu Broadcasting Cooperation, broadcasts a children’s workshop program called "Let's Play and Make." Today’s theme is "Make your own flag." A child writes his first initial in the center of their rectangular flag.

Given the flag size and the initial letter to be placed in the center of it, write a program to draw the flag as shown in the figure below.

+-------+
|.......|
|...A...|
|.......|
+-------+

The figure has "A" in the center of a flag with size 9 (horizontal) × 5 (vertical).

Input

The input is given in the following format.

W H c

The input line provides the flag dimensions W (width) and H (height) (3 ≤ W,H ≤ 21), and the initial letter c. Both W and H are odd numbers, and c is a capital letter.

Output

Draw the flag of specified size with the initial in its center using the following characters: "+" for the four corners of the flag, "-" for horizontal lines, "|" for vertical lines, and "." for the background (except for the initial in the center).

Sample Input 1

3 3 B

Sample Output 1

+-+
|B|
+-+

Sample Input 2

11 7 Z

Sample Output 2

+---------+
|.........|
|.........|
|....Z....|
|.........|
|.........|
+---------+
Bange Hills Tower

A project is underway to build a new viewing tower in Bange town called “Bange Hills Tower” whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town.

Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. “view of the entire keep” means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings).

Input

The input is given in the following format.

N t
x_1 h_1
x_2 h_2
:
x_N h_N

The first line provides the number of existing buildings N (1≤N≤1000) and the planned location of the tower t (2≤t≤105) in integers. Each of the subsequent N lines provides the information of the i-th building: location x_i (1 ≤ x_i < t) and height from the ground h_i (1 ≤ h_i ≤ 100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if i ≠ j, then x_i ≠ x_j).

Output

Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed ± 10-3.

Sample Input 1

3 10
6 4
4 2
3 2

Sample Output 1

6.666667
Age Difference

A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again and again, they came to notice that the difference of their ages will hit a maximum value even though the months move on forever.

Given the birthdays for the two, make a program to report the maximum difference between their ages. The age increases by one at the moment the birthday begins. If the birthday coincides with the 29th of February in a leap year, the age increases at the moment the 1st of March arrives in non-leap years.

Input

The input is given in the following format.

y_1 m_1 d_1
y_2 m_2 d_2

The first and second lines provide Hatsumi’s and Taku’s birthdays respectively in year y_i (1 ≤ y_i ≤ 3000), month m_i (1 ≤ m_i ≤ 12), and day d_i (1 ≤ d_i ≤ Dmax) format. Where Dmax is given as follows:

28 when February in a non-leap year

29 when February in a leap-year

30 in April, June, September, and November

31 otherwise.

It is a leap year if the year represented as a four-digit number is divisible by 4. Note, however, that it is a non-leap year if divisible by 100, and a leap year if divisible by 400.

Output

Output the maximum difference between their ages.

Sample Input 1

1999 9 9
2001 11 3

Sample Output 1

3

In this example, the difference of ages between them in 2002 and subsequent years is 3 on the 1st of October, but 2 on the 1st of December.

Sample Input 2

2008 2 29
2015 3 1

Sample Output 2

8

In this example, the difference of ages will become 8 on the 29th of February in and later years than 2016.
Electric Metronome

A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously.

He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from time to time in certain intervals. To explore this interesting phenomenon more fully, he is now trying to shorten the interval of ticking in unison by adjusting some of the metronomes’ interval settings. Note, however, that the metronomes do not allow any shortening of the intervals.

Given the number of metronomes and their preset intervals t_i (sec), write a program to make the tick-in-unison interval shortest by adding a non-negative integer d_i to the current interval setting of the i-th metronome, and report the minimum value of the sum of all d_i.

Input

The input is given in the following format.

N
t_1
t_2
:
t_N

The first line provides the number of metronomes N (1 ≤ N ≤ 105). Each of the subsequent N lines provides the preset ticking interval t_i (1 ≤ t_i ≤ 104) of the i-th metronome.

Output

Output the minimum value.

Sample Input 1

3
3
6
8

Sample Output 1

3

If we have three metronomes each with a ticking interval of 3, 6, and 8 seconds, respectively, simultaneous activation of these will produce a tick in unison every 24 seconds. By extending the interval by 1 second for the first, and 2 seconds for the second metronome, the interval of ticking in unison will be reduced to 8 seconds, which is the shortest possible for the system.

Sample Input 2

2
10
10

Sample Output 2

0

If two metronomes are both set to 10 seconds, then simultaneous activation will produce a tick in unison every 10 seconds, which is the shortest possible for this system.
Three Meals

You are running a restaurant that serves dishes only three times a day. Each of your customer has his/her own separate time zones for eating breakfast, lunch and supper. Thus, your customer enjoys your dish only when he/she visits your restaurant to meet your serving time settings. Your wish is to modify your serving time arrangement so that as many as possible of your customers can enjoy your meals three times a day.

Write a program to enable as many as possible of customers can enjoy your service three times a day, i.e. breakfast, lunch, and supper. A list of customers eating time zones is given, which you cannot change. Settings of your service time are your option. Coincidence between your service time and either edge of customer’s time zone (start or end time) does not hinder you to provide your service.

Input

The input is given in the following format.

N
ast_1 aet_1 hst_1 het_1 bst_1 bet_1
ast_2 aet_2 hst_2 het_2 bst_2 bet_2
:
ast_N aet_N hst_N het_N bst_N bet_N

The first line provides the number of customers N(1≤N≤50). Each of subsequent N lines provides time zone information of i-th customer: start and end time of breakfast zone (ast_i, aet_i), those of lunch zone (hst_i, het_i) and those of supper zone (bst_i, bet_i). The end time must be later in time as the start time. Time zones do not overlap, i.e. hst_i is later in time than aet_i, and so on. Each time settings must not cross 0:00 midnight.

h m

Each time information is given by hour h (0≤h≤23) and minute m(0≤m≤59).

Output

Output the maximum number of customers that can be served all three meals (breakfast, lunch, and supper).

Sample Input 1

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

Sample Output 1

3
Checkered Pattern

You have a cross-section paper with W x H squares, and each of them is painted either in white or black. You want to re-arrange the squares into a neat checkered pattern, in which black and white squares are arranged alternately both in horizontal and vertical directions (the figure shown below is a checkered patter with W = 5 and H = 5). To achieve this goal, you can perform the following two operations as many times you like in an arbitrary sequence: swapping of two arbitrarily chosen columns, and swapping of two arbitrarily chosen rows.

Create a program to determine, starting from the given cross-section paper, if you can re-arrange them into a checkered pattern.

Input

The input is given in the following format.

W H
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W

The first line provides the number of squares in horizontal direction W (2≤W≤1000) and those in vertical direction H(2≤H≤1000). Each of subsequent H lines provides an array of W integers ci,j corresponding to a square of i-th row and j-th column. The color of the square is white if ci,j is 0, and black if it is 1.

Output

Output "yes" if the goal is achievable and "no" otherwise.

Sample Input 1

3 2
1 1 0
0 0 1

Sample Output 1

yes

Sample Input 2

2 2
0 0
1 1

Sample Output 2

no
Paper Fortune

If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written.

Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your dream comes true. Cut up the string into more than one segment and compare their values. The difference between the largest and smallest value will give you the number of years before your wish will be fulfilled. Therefore, the result varies depending on the way you cut up the string. For example, if you are given a string 11121314 and divide it into segments, say, as 1,11,21,3,14, then the difference between the largest and smallest is 21 - 1 = 20. Another division 11,12,13,14 produces 3 (i.e. 14 - 11) years. Any random division produces a game of luck. However, you can search the minimum number of years using a program.

Given a string of numerical characters, write a program to search the minimum years before your wish will be fulfilled.

Input

The input is given in the following format.

n

An integer n is given. Its number of digits is from 2 to 100,000, and each digit ranges from 1 to 9.

Output

Output the minimum number of years before your wish will be fulfilled.

Sample Input 1

11121314

Sample Output 1

3

Sample Input 2

123125129

Sample Output 2

6

Sample Input 3

119138

Sample Output 3

5
Lake Survery

The Onogawa Expedition is planning to conduct a survey of the Aizu nature reserve. The expedition planner wants to take the shortest possible route from the start to end point of the survey, while the expedition has to go around the coast of the Lake of Onogawa en route. The expedition walks along the coast of the lake, but can not wade across the lake.

Based on the base information including the start and end point of the survey and the area of Lake Onogawa as convex polygon data, make a program to find the shortest possible route for the expedition and calculate its distance. Note that the expedition can move along the polygonal lines passing through the nodes, but never enter within the area enclosed by the polygon.

Input

The input is given in the following format.

x_s y_s
x_g y_g
N
x_1 y_1
x_2 y_2
:
x_N y_N

The first line provides the start point of the survey x_s,y_s (0≤x_s,y_s≤104), and the second line provides the end point x_g,y_g (0 ≤ x_g,y_g ≤ 104) all in integers. The third line provides the number of apexes N (3 ≤ N ≤ 100) of the polygon that represents the lake, and each of the subsequent N lines provides the coordinate of the i-th apex x_i,y_i (0 ≤ x_i,y_i ≤ 104) in counter-clockwise order. These data satisfy the following criteria:

Start and end points of the expedition are not within the area enclosed by the polygon nor on boundaries.

Start and end points of the expedition are not identical, i.e., x_s ≠ x_g or y_s ≠ y_g.

No duplicate coordinates are given, i.e., if i ≠ j then x_i ≠ x_r or y_i ≠ y_j.

The area enclosed by the polygon has a positive value.

Any three coordinates that define an area are not aligned on a line.

Output

Output the distance of the shortest possible expedition route. Any number of decimal places can be selected as long as the error does not exceed ± 10-3.

Sample Input 1

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

Sample Output 1

4.472136

Sample Input 2

4 4
0 0
4
1 1
3 1
3 3
1 3

Sample Output 2

6.32455
Lottery Box

A lottery is being held in a corner of the venue of the Aizu festival. Several types of balls are inside the lottery box and each type has its unique integer printed on the surfaces of the balls. An integer T is printed on the lottery box.

In the lottery, you first declare two integers A and B, and draw up to M balls from the box. Let the sum of the integers printed on the balls be S. You can get a wonderful gift if the following two criteria are met: S divided by T gives a remainder greater than or equal to A, and S divided by T gives a quotient (fractional portion dropped) greater than or equal to B.

Write a program to determine if you have any chance of getting the gift given the following information: the number of ball types, ball-type specific integers, the maximum number of balls to be drawn from the box, the integer printed on the lottery box, and two integers declared before drawing. Assume that each ball type has sufficient (≥M) population in the box. Note also that there may be a chance of getting the gift even without drawing any ball.

Input

The input is given in the following format.

N M T
a_1
a_2
:
a_N
Q
A_1 B_1
A_2 B_2
:
A_Q B_Q

The first line provides the number of ball types N(1≤N≤105), the maximum number of balls you can draw from the box M(1≤M≤105), and the integer printed on the box T(1≤T≤1000). Each of the subsequent N lines provides an integer a_i (1≤a_i≤109) printed on the i-th ball type. The next line following these provides the number of declarations Q (1≤Q≤105). Each of the Q lines following this provides a pair of integers A_i (0 ≤ A_i < T), B_i (0 ≤ B_i ≤ 109) that constitute the i-th declaration.

Output

Output a line for each pair of declaration A and B that contains "yes" if there is a chance of getting the gift or "no" otherwise.

Sample Input 1

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

Sample Output 1

yes
no
yes
no
yes
Party

The students in a class in Akabe high-school define the relation “acquaintance” as:

If A and B are friends, then A is acquainted with B.

If A and B are friends and B is acquainted with C, then A is acquainted with C.

They define the relation “companion” as:

Suppose A is acquainted with B, and two classmates who have been friend distance. If A is still acquainted with B, then A and B are companions.

A boy PCK joined the class recently and wishes to hold a party inviting his class fellows. He wishes to invite as many boys and girls as possible to the party and has written up an invitation list. In arranging the list, he placed the following conditions based on the acquaintanceship within the class before he joined.

When T is in the list:

U is listed if he/she is a companion of T.

If U is not a companion of T, U is not listed if he/she and T are friends, or he/she and some of T’s companions are friends.

PCK made the invitation list so that the maximum number of his classmates is included.

Given the number of classmates N and the friendships among them, write a program to estimate the number of boys and girls in the list. All the classmates are identified by an index that ranges from 0 to N-1.

Input

The input is given in the following format.

N M
s_1 t_1
s_2 t_2
:
s_M t_M

The first line provides the number of classmates N (2 ≤ N ≤ 105) and the number of friendships M (1 ≤ M ≤ 2×105). Each of the M subsequent lines provides two of the classmates s_i, t_i (0 ≤ s_i,t_i ≤ N-1) indicating they are friends. No duplicate relationship appears among these lines.

Output

Output the maximum number of classmates PCK invited to the party.

Sample Input 1

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

Sample Output 1

6

Sample Input 2

3 2
0 1
1 2

Sample Output 2

2
Aerial Photos

Hideyo has come by two aerial photos of the same scale and orientation. You can see various types of buildings, but some areas are hidden by clouds. Apparently, they are of the same area, and the area covered by the second photograph falls entirely within the first. However, because they were taken at different time points, different shapes and distribution of clouds obscure identification where the area in the second photograph is located in the first. There may even be more than one area within the first that the second fits equally well.

A set of pixel information is given for each of the photographs. Write a program to extract candidate sub-areas within the first photograph that compare with the second equally well and output the number of the candidates.

Input

The input is given in the following format.

AW AH BW BH
arow1
arow2
:
arowAH
brow1
brow2
:
browBH

The first line provides the number of pixels in the horizontal and the vertical direction AW (1 ≤ AW ≤ 800) and AH (1 ≤ AH ≤ 800) for the first photograph, followed by those for the second BW (1 ≤ BW ≤ 100) and BH (1 ≤ BH ≤ 100) (AW ≥ BW andAH ≥ BH). Each of the subsequent AH lines provides pixel information (arowi) of the i-th row from the top of the first photograph. Each of the BH lines that follows provides pixel information (browi) of the i-th row from the top of the second photograph.

Each of the pixel information arowi and browi is a string of length AW and BW, respectively, consisting of upper/lower-case letters, numeric characters, or "?". Each one character represents a pixel, whereby upper/lower-case letters and numeric characters represent a type of building, and "?" indicates a cloud-covered area.

Output

Output the number of the candidates.

Sample Input 1

5 5 3 3
AF??z
W?p88
???Hk
pU?m?
F???c
F??
p?8
?H?

Sample Output 1

4

Sample Input 2

6 5 4 2
aaaaaa
aaaaaa
aaaaaa
aaaaaa
aaaaaa
aaaa
aaaa

Sample Output 2

12