alexjercan/bugnet huggingface dataset:
J - Unfair Game

Problem Statement

Rabbit Hanako and Fox Jiro are great friends going to JAG primary school. Today they decided to play the following game during the lunch break.

This game is played by two players with $N$ heaps of some number of stones. The players alternatively take their turn to play the game. Jiro is a kind gentleman, so he yielded the first turn to Hanako. In each turn, the player must take some stones, satisfying the following conditions:

If the player is Hanako, she must take between $1$ to $A$ stones, inclusive, from a heap.

If the player is Jiro, he must take between $1$ to $B$ stones, inclusive, from a heap.

The winner is the player who takes the last stone. Jiro thinks it is rude to go easy on her because he is a perfect gentleman. Therefore, he does him best. Of course, Hanako also does so.

Jiro is worried that he may lose the game. Being a cadet teacher working at JAG primary school as well as a professional competitive programmer, you should help him by programming. Your task is to write a program calculating the winner, assuming that they both play optimally.

Input

The first line contains three integers $N$, $A$, and $B$. $N$ ($1 \leq N \leq 10^5$) is the number of heaps. $A$ and $B$ ($1 \leq A, B \leq 10^9$) are the maximum numbers of stones that Hanako and Jiro can take in a turn, respectively. Then $N$ lines follow, each of which contains a single integer $S_i$ ($1 \leq S_i \leq 10^9$), representing the number of stones in the $i$-th heap at the beginning of the game.

Output

Output a line with "Hanako" if Hanako wins the game or "Jiro" in the other case.

Sample Input 1

3 5 4
3
6
12

Output for the Sample Input 1

Hanako

Sample Input 2

4 7 8
8
3
14
5

Output for the Sample Input 2

Jiro
Problem A
Balanced Paths

You are given an undirected tree with $n$ nodes. The nodes are numbered 1 through $n$. Each node is labeled with either '(' or ')'. Let $l[u \rightarrow v]$ denote the string obtained by concatenating the labels of the nodes on the simple path from $u$ to $v$. (Note that the simple path between two nodes is uniquely determined on a tree.) A balanced string is defined as follows:

The empty string is balanced.

For any balanced string $s$, the string "(" $s$ ")" is balanced.

For any balanced strings $s$ and $t$, the string $st$ (the concatenation of $s$ and $t$) is balanced.

Any other string is NOT balanced.

Calculate the number of the ordered pairs of the nodes ($u$, $v$) such that $l[u \rightarrow v]$ is balanced.

Input

The input consists of a single test case. The input starts with an integer $n (2 \leq n \leq 10^5)$, which is the number of nodes of the tree. The next line contains a string of length $n$, each character of which is either '(' or ')'. The $x$-th character of the string represents the label of the node $x$ of the tree. Each of the following $n - 1$ lines contains two integers $a_i$ and $b_i$ $(1 \leq a_i, b_i \leq n)$, which represents that the node $a_i$ and the node $b_i$ are connected by an edge. The given graph is guaranteed to be a tree.

Output

Display a line containing the number of the ordered pairs ($u$, $v$) such that $l[u \rightarrow v]$ is balanced.

Sample Input 1

2
()
1 2

Output for the Sample Input 1

1

Sample Input 2

4
(())
1 2
2 3
3 4

Output for the Sample Input 2

2

Sample Input 3

5
()())
1 2
2 3
2 4
1 5

Output for the Sample Input 3

4
Problem B
Card Game Strategy

Alice and Bob are going to play a card game. There are $n$ cards, each having an integer written on it. The game proceeds as follows:

Alice chooses an integer between $a$ and $b$, inclusive. Call this integer $t$. Alice then tells Bob the value of $t$.

Bob chooses $k$ out of the $n$ cards. Compute the sum of the integers written on the $k$ cards Bob chooses. Call this sum $u$.

Alice's objective is to make $|t - u|$ as large as possible and Bob's is to make $|t - u|$ as small as possible.

Prior to the game, both Alice and Bob know the values of $n$, $k$, $a$, and $b$, and also the integers on the cards. Both Alice and Bob will play optimally. In particular, Alice will make a choice, knowing that Bob will surely minimize $|t - u|$ for told $t$. Additionally, assume that Alice prefers to choose smaller $t$ if she has multiple equally good choices.

Your task is to determine the outcome of the game: the value of $t$ Alice will choose and the $k$ cards Bob will choose for that $t$.

Input

The input consists of two lines representing a single test case. The first line contains four integers $n$, $k$, $a$, and $b$ $(1 \leq k \leq n \leq 600, 0 \leq a \leq b \leq 180,000)$. The second line contains $n$ integers $x_1, ..., x_n$ $(0 \leq x_i \leq 300)$, denoting that $x_i$ is written on the $i$-th card.

Output

Display two lines: The first line should contain an integer representing the value of $t$ Alice will choose. The second line should contain k distinct integers between 1 and $n$, inclusive, representing the indices of the cards Bob will choose. If Bob has multiple equally good choices, display any one of them.

Sample Input 1

4 2 58 100
10 10 50 80

Output for the Sample Input 1

75
2 3

Sample Input 2

8 3 1300 1800
2 0 1 5 0 4 1 9

Output for the Sample Input 2

1800
4 6 8
Problem C
Casino

Taro, who owes a debt of $n$ dollars, decides to make money in a casino, where he can double his wager with probability $p$ percent in a single play of a game. Taro is going to play the game repetitively. He can choose the amount of the bet in each play, as long as it is a positive integer in dollars and at most the money in his hand.

Taro possesses $m$ dollars now. Find out the maximum probability and the optimum first bet that he can repay all his debt, that is, to make his possession greater than or equal to his debt.

Input

The input consists of a single test case, which consists of three integers $p$, $m$, and $n$ separated by single
spaces $(0 \leq p \leq 100, 0 < m < n \leq 10^9)$.

Output

Display three lines: The first line should contain the maximum probability that Taro can repay all his debt. This value must have an absolute error at most $10^{-6}$. The second line should contain an integer representing how many optimum first bets are there. Here, a first bet is optimum if the bet is necessary to achieve the maximum probability. If the number of the optimum first bets does not exceed 200, the third line should contain all of them in ascending order and separated by single spaces. Otherwise the third line should contain the 100 smallest bets and the 100 largest bets in ascending order and separated by single spaces.

Sample Input 1

60 2 3

Output for the Sample Input 1

0.789473
1
1

Sample Input 2

25 3 8

Output for the Sample Input 2

0.109375
2
1 3
Problem D
Content Delivery

You are given a computer network with n nodes. This network forms an undirected tree graph. The $i$-th edge connects the $a_i$-th node with the $b_i$-th node and its distance is $c_i$. Every node has different data and the size of the data on the $i$-th node is $s_i$. The network users can deliver any data from any node to any node. Delivery cost is defined as the product of the data size the user deliver and the distance from the source to the destination. Data goes through the shortest path in the delivery. Every node makes cache to reduce the load of this network. In every delivery, delivered data is cached to all nodes which relay the data including the destination node. From the next time of delivery, the data can be delivered from any node with a cache of the data. Thus, delivery cost reduces to the product of the original data size and the distance between the nearest node with a cache and the destination.

Calculate the maximum cost of the $m$ subsequent deliveries on the given network. All the nodes have no cached data at the beginning. Users can choose the source and destination of each delivery arbitrarily.

Input

The input consists of a single test case. The first line contains two integers $n$ $(2 \leq n \leq 2,000)$ and $m$ $(1 \leq m \leq 10^9)$. $n$ and $m$ denote the number of the nodes in the network and the number of the deliveries, respectively. The following $n - 1$ lines describe the network structure. The $i$-th line of them contains three integers $a_i$, $b_i$ $(1 \leq a_i, b_i \leq n)$ and $c_i$ $(1 \leq c_i \leq 10,000)$ in this order, which means the $a_i$-th node and the $b_i$-th node are connected by an edge with the distance $c_i$. The next line contains $n$ integers. The $j$-th integer denotes $s_j$ $(1 \leq s_j \leq 10,000)$, which means the data size of the $j$-th node. The given network is guaranteed to be a tree graph.

Output

Display a line containing the maximum cost of the $m$ subsequent deliveries in the given network.

Sample Input 1

3 2
1 2 1
2 3 2
1 10 100

Output for the Sample Input 1

320

Sample Input 2

2 100
1 2 1
1 1

Output for the Sample Input 2

2
Problem F
ICPC Teams

You are a coach of the International Collegiate Programming Contest (ICPC) club in your university. There are 3N students in the ICPC club and you want to make $N$ teams for the next ICPC. All teams in ICPC consist of 3 members. Every student belongs to exactly one team.

When you form the teams, you should consider several relationships among the students. Some student has an extremely good relationship with other students. If they belong to a same team, their performance will improve surprisingly. The contrary situation also occurs for a student pair with a bad relationship. In short, students with a good relationship must be in the same team, and students with a bad relationship must be in different teams. Since you are a competent coach, you know all $M$ relationships among the students.

Your task is to write a program that calculates the number of possible team assignments. Two assignments are considered different if and only if there exists a pair of students such that in one assignment they are in the same team and in the other they are not.

Input

The input consists of a single test case. The first line contains two integers $N$ $(1 \leq N \leq 10^6)$ and $M$ $(1 \leq M \leq 18)$. The $i$-th line of the following $M$ lines contains three integers $A_i$, $B_i$ $(1 \leq A_i, B_i \leq 3N, A_i \ne B_i)$, and $C_i$ $(C_i \in \{0, 1\})$. $A_i$ and $B_i$ denote indices of the students and $C_i$ denotes the relation type. If $C_i$ is 0, the $A_i$-th student and the $B_i$-th student have a good relation. If $C_i$ is 1, they have a bad relation. You can assume that $\{A_i, B_i\} \ne \{A_j, B_j\}$ if $i \ne j$ for all $1 \leq i, j \leq M$.

Output

Display a line containing the number of the possible team assignments modulo $10^9 + 9$.

Sample Input 1

2 2
1 2 0
3 4 1

Output for the Sample Input 1

2
Problem G
JAG-channel II

JAG (Japan Alumni Group) is a group of $N$ members that devotes themselves to activation of the competitive programming world. The JAG staff members talk every day on the BBS called JAG-channel. There are several threads in JAG-channel and these are kept sorted by the time of their latest posts in descending order.

One night, each of the $N$ members, identified by the first $N$ uppercase letters respectively, created a thread in JAG-channel. The next morning, each of the $N$ members posted in exactly $K$ different threads which had been created last night. Since they think speed is important, they viewed the threads from top to bottom and posted in the thread immediately whenever they came across an interesting thread. Each member viewed the threads in a different period of time, that is, there was no post of other members while he/she was submitting his/her $K$ posts.

Your task is to estimate the order of the members with respect to the periods of time when members posted in the threads. Though you do not know the order of the threads created, you know the order of the posts of each member. Since the threads are always kept sorted, there may be invalid orders of the members such that some members cannot post in the top-to-bottom order of the threads due to the previous posts of other members. Find out the lexicographically smallest valid order of the members.

Input

The input consists of a single test case. The first line contains two integers separated by a space: $N$ $(4 \leq N \leq 16)$ and $K$ $(N - 3 \leq K \leq N - 1)$. Then $N$ lines of strings follow. Each of the $N$ lines consists of exactly $K$ distinct characters. The $j$-th character of the $i$-th line denotes the $j$-th thread in which the
member denoted by the $i$-th uppercase letter posted. Each thread is represented by its creator (e.g. 'B' represents the thread created by member B, the second member).

It is guaranteed that at least one valid order exists.

Output

Display a string that consists of exactly $N$ characters in a line, which denotes the valid order in which the members posted in the threads. The $i$-th character of the output should represent the member who posted in the $i$-th period. In case there are multiple valid orders, output the lexicographically smallest one.

Sample Input 1

7 4
DEFG
FEDA
EFGB
BGEA
AGFD
DABC
CADE

Output for the Sample Input 1

ABCDEFG

Sample Input 2

4 3
CDB
DAC
BAD
ABC

Output for the Sample Input 2

DCBA

Sample Input 3

16 13
NDHPFJIBLMCGK
CMDJKPOLGIHNE
MOLBIEJFPHADN
KPNAOHBLMCGEI
FCMLBHDOANJPK
NHIGLOAPKJDMC
KMLBIPHDEOANJ
IEGCMLBOAPKJD
JNAOEDHBLMCGF
OEDHPFIBLMGKC
GMLBIFPHDNAEO
ENHGOPKJDMCAF
JKPAOBLGEIHNF
HPKFGJEIBLCOM
LBINEJDAGFKPH
FGMOCADJENIBL

Output for the Sample Input 3

PONCAKJGIEDHMFBL
Problem I
Midpoint

One day, you found $L + M + N$ points on a 2D plane, which you named $A_1, ..., A_L, B_1, ...,B_M, C_1,...,C_N$. Note that two or more points of them can be at the same coordinate. These were named after the following properties:

the points $A_1,...,A_L$ were located on a single straight line,

the points $B_1,...,B_M$ were located on a single straight line, and

the points $C_1,...,C_N$ were located on a single straight line.

Now, you are interested in a triplet $(i, j, k)$ such that $C_k$ is the midpoint between $A_i$ and $B_j$. Your task is counting such triplets.

Input

The first line contains three space-separated positive integers $L$, $M$, and $N$ $(1 \leq L, M, N \leq 10^5)$. The next $L$ lines describe $A$. The $i$-th of them contains two space-separated integers representing the $x$-coordinate and the $y$-coordinate of $A_i$. The next $M$ lines describe $B$. The $j$-th of them contains two space-separated integers representing the $x$-coordinate and the $y$-coordinate of $B_j$. The next $N$ lines describe $C$. The $k$-th of them contains two space-separated integers representing the $x$-coordinate and the $y$-coordinate of $C_k$. It is guaranteed that the absolute values of all the coordinates do not exceed $10^5$.

Output

Print the number of the triplets which fulfill the constraint.

Sample Input 1

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

Output for the Sample Input 1

3

Sample Input 2

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

Output for the Sample Input 2

8

Sample Input 3

4 4 4
0 0
3 2
6 4
9 6
7 14
9 10
10 8
13 2
4 2
5 4
6 6
8 10

Output for the Sample Input 3

3
Problem J
New Game AI

Aoba is a beginner programmer who works for a game company. She was appointed to develop a battle strategy for the enemy AI (Artificial Intelligence) in a new game. In this game, each character has two parameters, hit point ($hp$) and defence point ($dp$). No two characters have the same $hp$ and $dp$ at the same time. The player forms a party by selecting one or more characters to battle with the enemy. Aoba decided to develop a strategy in which the AI attacks the weakest character in the party: that is, the AI attacks the character with the minimum hit point in the party (or, if there are several such characters, the character with the minimum defense point among them). She wrote a function selectTarget($v$) that takes an array of characters representing a party and returns a character that her AI will attack.

However, the project manager Ms. Yagami was not satisfied with the behavior of her AI. Ms. Yagami said this AI was not interesting.

Aoba struggled a lot, and eventually she found that it is interesting if she substitutes one of the constant zeros in her program with a constant $C$. The rewritten program is as follows. Note that Character is a type representing a character and has fields $hp$ and $dp$ which represent the hit point and the defense point of the character respectively.

int C = <constant integer>;

Character selectTarget(Character v[]) {
int n = length(v);
int r = 0;
for (int i = 1; i < n; i++) {
if (abs(v[r].hp - v[i].hp) > C) {
if (v[r].hp > v[i].hp) r = i;
} else {
if (v[r].dp > v[i].dp) r = i;
}
}
return v[r];
}

By the way, this function may return different characters according to the order of the characters in $v$, even if $v$ contains the same set of characters. Ms. Yagami wants to know how many characters in a party may become the target of the new AI. Aoba's next task is to write a program that takes a given party $v$ and a constant $C$, and then counts the number of characters that may become the return value of selectTarget($v$) if $v$ is re-ordered.

Input

The input consists of a single test case. The first line contains two integers $N$ $(1 \leq N \leq 50,000)$ and $C$ $(0 \leq C \leq 10^9)$. The first integer $N$ represents the size of $v$. The second integer $C$ represents the constant $C$ in Aoba's program. The i-th line of the following $N$ lines contains two integers $hp_i$ and $dp_i$ $(0 \leq hp_i, dp_i \leq 10^9)$. $hp_i$ represents the hit point of the $i$-th character in $v$, and $dp_i$ represents the defense point of the $i$-th character in $v$. You can assume that $hp_i \ne hp_j$ or $dpi \ne dp_j$ if $i \ne j$ for any $1 \leq i, j \leq N$.

Output

Display the number of characters that may become the return value of selectTarget($v$), if $v$ is shuffled in an arbitrary order.

Sample Input 1

5 3
1 5
3 4
5 3
7 2
9 1

Output for the Sample Input 1

5

Sample Input 2

3 2
1 2
3 1
5 1

Output for the Sample Input 2

2

Sample Input 3

4 1
2 0
0 4
1 1
5 9

Output for the Sample Input 3

3

Sample Input 4

5 9
4 10
12 4
2 14
9 19
7 15

Output for the Sample Input 4

3
Problem K
Runner and Sniper

You are escaping from an enemy for some reason. The enemy is a sniper equipped with a high-tech laser gun, and you will be immediately defeated if you get shot. You are a very good runner, but just wondering how fast you have to run in order not to be shot by the sniper. The situation is as follows:

You and the sniper are on the $xy$-plane whose $x$-axis and $y$-axis are directed to the right and the top, respectively. You can assume that the plane is infinitely large, and that there is no obstacle that blocks the laser or your movement.

The sniper and the laser gun are at $(0, 0)$ and cannot move from the initial location. The sniper can continuously rotate the laser gun by at most $\omega$ degrees per unit time, either clockwise or counterclockwise, and can change the direction of rotation at any time. The laser gun is initially directed $\theta$ degrees counterclockwise from the positive direction of the $x$-axis.

You are initially at ($x$, $y$) on the plane and can move in any direction at speed not more than $v$ (you can arbitrarily determine the value of $v$ since you are a very good runner). You will be shot by the sniper exactly when the laser gun is directed toward your position, that is, you can ignore the time that the laser reaches you from the laser gun. Assume that your body is a point and the laser is a half-line whose end point is (0, 0).

Find the maximum speed $v$ at which you are shot by the sniper in finite time when you and the sniper behave optimally.

Input

The input consists of a single test case. The input contains four integers in a line, $x$, $y$, $\theta$ and $\omega$. The two integers $x$ and $y$ $(0 \leq |x|, |y| \leq 1,000$, ($x$, $y$) $\ne$ (0, 0)) represent your initial position on the $xy$-plane. The integer $\theta$ $(0 \leq \theta < 360)$ represents the initial direction of the laser gun: it is the counterclockwise angle in degrees from the positive direction of the $x$-axis. The integer $\omega$ $(1 \leq \omega \leq 100)$ is the angle which the laser gun can rotate in unit time. You can assume that you are not shot by the sniper at the initial position.

Output

Display a line containing the maximum speed $v$ at which you are shot by the sniper in finite time. The
absolute error or the relative error should be less than $10^{-6}$.

Sample Input 1

100 100 0 1

Output for the Sample Input 1

1.16699564
Problem L
Wall Making Game

The game Wall Making Game, a two-player board game, is all the rage.

This game is played on an $H \times W$ board. Each cell of the board is one of empty, marked, or wall. At the beginning of the game, there is no wall on the board.

In this game, two players alternately move as follows:

A player chooses one of the empty cells (not marked and not wall). If the player can't choose a cell, he loses.

Towards each of the four directions (upper, lower, left, and right) from the chosen cell, the player changes cells (including the chosen cell) to walls until the player first reaches a wall or the outside of the board.

Note that marked cells cannot be chosen in step 1, but they can be changed to walls in step 2.

Fig.1 shows an example of a move in which a player chooses the cell at the third row and the fourth
column.

Fig.1: An example of a move in Wall Making Game.

Your task is to write a program that determines which player wins the game if the two players play optimally from a given initial board.

Input

The first line of the input consists of two integers $H$ and $W$ $(1 \leq H, W \leq 20)$, where $H$ and $W$ are the height and the width of the board respectively. The following $H$ lines represent the initial board. Each of the $H$ lines consists of $W$ characters.

The $j$-th character of the $i$-th line is '.' if the cell at the $j$-th column of the $i$-th row is empty, or 'X' if the cell is marked.

Output

Print "First" (without the quotes) in a line if the first player wins the given game. Otherwise, print "Second" (also without the quotes) in a line.

Sample Input 1

2 2
..
..

Output for the Sample Input 1

Second

Sample Input 2

2 2
X.
..

Output for the Sample Input 2

First

Sample Input 3

4 5
X....
...X.
.....
.....

Output for the Sample Input 3

First
Koto Municipal Subway

Koto市営地下鉄

Koto市は，下図のように，道路が碁盤の目状である有名な街である．
南北に伸びる道と東西に伸びる道は，それぞれ1kmの間隔で並んでいる．
Koto市の最も南西の交差点にあるKoto駅を (0, 0) として，そこから東に x km，北に y km 進んだ位置を (x, y) と記すこととする (0 ≤ x, y である)．

5年後に開かれるオリンピックにより観光客が増大することを見越して，市はKoto駅を始発駅とする新しい地下鉄の路線を建設することを決めた．
現在，Koto駅の次の駅として新しく建設されるShin-Koto駅までのレールを敷く計画を立てている．
レールは，Koto駅からShin-Koto駅に向かってまっすぐ敷く．
従って，Shin-Koto駅の場所を (x, y) としたとき，レールの長さは， √(x2 + y2) である．
レールを敷くための費用は，敷いたレールの長さ分だけ必要になる．
レールの長さが1.5kmのように小数であっても，費用も同じように1.5必要となる．

Shin-Koto駅の場所 (x, y) はまだ決定しておらず，以下の条件を満たす場所にする予定である．

交差点である．つまり， x と y がそれぞれ整数である．
Koto駅から道路に沿って歩いた最短距離が，ちょうど D である．つまり， x + y = D を満たす．

上の2つの条件を満たす中で，市が定めるレールの予算 E とレールの費用とのずれ | √(x2 + y2) - E | が最小となるようにShin-Koto駅の場所を選ぶ．
ここで |A| は， A の絶対値を表す．
あなたの仕事は，上記のようにShin-Koto駅を建設したときの，レールを敷くための費用と予算とのずれを出力するプログラムを作成することである．

Input

入力は，複数のデータセットから構成され，1つの入力に含まれるデータセットの数は100以下である． 各データセットの形式は次の通りである．

D E

D (1 ≤ D ≤ 100)は，Koto駅からShin-Koto駅まで道路に沿って歩いたときの最短距離を表す整数である．
E (1 ≤ E ≤ 100)は，レール建設のための予算を表す整数である．

入力の終わりは，空白で区切られた2つのゼロからなる行によって示される．

Output

各データセットに対して，問題の条件を満たすようにレールを敷いたときの費用と予算とのずれを1行で出力せよ．
答えには 10-3 を越える絶対誤差があってはならない．
各行の終わりに改行を出力しなかった場合や，不必要な文字を出力した場合，誤答と判断されてしまうため，注意すること．

Sample Input

2 1
7 5
7 6
7 7
76 5
8 41
0 0

Output for Sample Input

0.4142135624
0
0.0827625303
0
48.7401153702
33

Hint

1つ目のデータセットでは，下図のように，Koto駅から道路に沿って2km進んだ交差点がShin-Koto駅を建設する場所の候補となる．

各交差点にShin-Koto駅を建設した場合の，レールを敷くための費用と予算1とのずれは次のようになる．

(2, 0) ： | √(22 + 02) - 1 | = 1.0
(1, 1) ： | √(12 + 12) - 1 | = 0.4142135623...
(0, 2) ： | √(02 + 22) - 1 | = 1.0

よって，費用と予算とのずれが最小になるのは， (1, 1) に建設した場合となる．