alexjercan/bugnet huggingface dataset:
Problem E:
Enclose Points

There are $N$ points and $M$ segments on the $xy$-plane. Each segment connects two of these
points and they don't intersect each other except at the endpoints. You are also given $Q$ points
as queries. Your task is to determine for each query point whether you can make a polygon that
encloses the query point using some of the given segments. Note that the polygon should not
necessarily be convex.

Input

Each input is formatted as follows.

$N$ $M$ $Q$

$x_1$ $y_1$

...

$x_N$ $y_N$

$a_1$ $b_1$

...

$a_M$ $b_M$

$qx_1$ $qy_1$

...

$qx_Q$ $qy_Q$

The first line contains three integers $N$ ($2 \leq N \leq 100,000$), $M$ ($1 \leq M \leq 100,000$), and $Q$
($1 \leq Q \leq 100,000$), which represent the number of points, the number of segments, and the
number of queries, respectively. Each of the following $N$ lines contains two integers $x_i$ and $y_i$
($-100,000 \leq x_i, y_i \leq 100,000$), the coordinates of the $i$-th point. The points are guaranteed to be
distinct, that is, $(x_i, y_i) \ne (x_j, y_j)$ when $i \ne j$. Each of the following $M$ lines contains two integers
$a_i$ and $b_i$ ($1 \leq a_i < b_i \leq N$), which indicate that the $i$-th segment connects the $a_i$-th point and
the $b_i$-th point. Assume that those segments do not intersect each other except at the endpoints.
Each of the following $Q$ lines contains two integers $qx_i$ and $qy_i$ ($-100,000 \leq qx_i, qy_i \leq 100,000$),
the coordinates of the $i$-th query point.

You can assume that, for any pair of query point and segment, the distance between them is at
least $10^{-4}$.

Output

The output should contain $Q$ lines. Print "Yes" on the $i$-th line if there is a polygon that
contains the $i$-th query point. Otherwise print "No" on the $i$-th line.

Sample Input

4 5 3
-10 -10
10 -10
10 10
-10 10
1 2
1 3
1 4
2 3
3 4
-20 0
1 0
20 0

Output for the Sample Input

No
Yes
No

Sample Input

8 8 5
-20 -20
20 -20
20 20
-20 20
-10 -10
10 -10
10 10
-10 10
1 2
1 4
2 3
3 4
5 6
5 8
6 7
7 8
-25 0
-15 0
0 0
15 0
25 0

Output for the Sample Input

No
Yes
Yes
Yes
No

Sample Input

8 8 5
-20 -10
-10 -10
-10 10
-20 10
10 -10
20 -10
20 10
10 10
1 2
2 3
3 4
1 4
5 6
6 7
7 8
5 8
-30 0
-15 0
0 0
15 0
30 0

Output for the Sample Input

No
Yes
No
Yes
No
Problem G:
Surface Area of Cubes

Taro likes a single player game "Surface Area of Cubes".

In this game, he initially has an $A \times B \times C$ rectangular solid formed by $A \times B \times C$ unit cubes
(which are all 1 by 1 by 1 cubes). The center of each unit cube is placed at 3-dimentional
coordinates $(x, y, z)$ where $x$, $y$, $z$ are all integers ($0 \leq x \leq A-1, 0 \leq y \leq B -1, 0 \leq z \leq C - 1$).
Then, $N$ distinct unit cubes are removed from the rectangular solid by the game master. After
the $N$ cubes are removed, he must precisely tell the total surface area of this object in order to
win the game.

Note that the removing operation does not change the positions of the cubes which are not
removed. Also, not only the cubes on the surface of the rectangular solid but also the cubes
at the inside can be removed. Moreover, the object can be divided into multiple parts by the
removal of the cubes. Notice that a player of this game also has to count up the surface areas
which are not accessible from the outside.

Taro knows how many and which cubes were removed but this game is very difficult for him,
so he wants to win this game by cheating! You are Taro's friend, and your job is to make a
program to calculate the total surface area of the object on behalf of Taro when you are given
the size of the rectangular solid and the coordinates of the removed cubes.

Input

The input is formatted as follows.

The first line of a test case contains four integers $A$, $B$, $C$, and $N$ ($1 \leq A, B, C \leq 10^8, 0 \leq N \leq
$ min{$1,000, A \times B \times C - 1$}).

Each of the next $N$ lines contains non-negative integers $x$, $y$, and $z$ which represent the coordinate
of a removed cube. You may assume that these coordinates are distinct.

Output

Output the total surface area of the object from which the $N$ cubes were removed.

Sample Input

2 2 2 1
0 0 0

Output for the Sample Input

24

Sample Input

1 1 5 2
0 0 1
0 0 3

Output for the Sample Input

18

Sample Input

3 3 3 1
1 1 1

Output for the Sample Input

60
Problem H:
Laser Cutter

Ciel is going to do woodworking. Ciel wants to make a cut in a wooden board using a laser
cutter.

To make it simple, we assume that the board is a two-dimensional plane. There are several
segments on the board along which Ciel wants to cut the board. Each segment has a direction
and Ciel must cut those segments along their directions. Those segments are connected when
you ignore the directions, that is, any two points on the segments are directly or indirectly
connected by the segments.

While the laser cutter is powered on, it emits a laser which hits the board at a point and cuts
the board along its trace. The laser initially points to $(x, y)$. Ciel can conduct the following two
operations:

Move the laser cutter with its power on and cut (a part of) a segment along its direction,
or

Move the laser cutter to any position with its power off. Ciel should not necessarily cut
the whole segment at a time; she can start or stop cutting a segment at any point on the
segments.

Ciel likes to be efficient, so she wants to know the shortest route such that the laser cutter cuts
the whole parts of all the segments and then move back to the initial point. Your task is to
write a program that calculates the minimum total moving distance of the laser cutter.

Input

The first line of the input contains an integer $n$ ($1 \leq n \leq 300$), the number of segments. The
next line contains two integers $x$ and $y$ ($-1,000 \leq x, y \leq 1,000$), which is the initial position
$(x, y)$ of the laser. The $i$-th of the following $n$ lines contains four integers $sx_i$, $sy_i$, $tx_i$ and $ty_i$ ($-1,000 \leq sx_i, sy_i, tx_i, ty_i \leq 1,000$), which indicate that they are the end points of the $i$-th
segment, and that the laser cutter can cut the board in the direction from $(sx_i, sy_i)$ to $(tx_i, ty_i)$.
The input satisfies the following conditions: For all $i$ ($1 \leq i \leq n$), $(sx_i, sy_i) \ne (tx_i, ty_i)$. The
initial point $(x, y)$ lies on at least one of the given segments. For all distinct $i, j$ ($1 \leq i, j \leq n$),
the $i$-th segment and the $j$-th segment share at most one point.

Output

Output a line containing the minimum total moving distance the laser cutter needs to travel to
cut all the segments and move back to the initial point. The absolute error or the relative error
should be less than $10^{-6}$.

Sample Input

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

Output for the Sample Input

6.0000000000000000

Sample Input

2
0 1
0 0 0 2
-1 1 1 1

Output for the Sample Input

6.8284271247461900

Sample Input

5
0 0
0 0 1 0
1 1 -1 1
-1 1 -1 -1
-1 -1 1 -1
1 -1 1 1

Output for the Sample Input

10.0000000000000000
Problem I:
Live Programming

A famous Japanese idol group, JAG48, is planning the program for its next live performance.
They have $N$ different songs, $song_1$, $song_2$, ..., and $song_N$. Each song has three integer param-
eters, $t_i$, $p_i$, and $f_i$: $t_i$ denotes the length of $song_i$, $p_i$ denotes the basic satisfaction points the
audience will get when $song_i$ is performed, and $f_i$ denotes the feature value of songi that affects
the audience's satisfaction. During the live performance, JAG48 can perform any number (but
at least one) of the $N$ songs, unless the total length of the chosen songs exceeds the length of
the live performance $T$. They can decide the order of the songs to perform, but they cannot
perform the same song twice or more.

The goal of this live performance is to maximize the total satisfaction points that the audience
will get. In addition to the basic satisfaction points of each song, the difference between the
feature values of the two songs that are performed consecutively affects the total satisfaction
points. If there is no difference, the audience will feel comfortable. However, the larger the
difference will be, the more frustrated the audience will be.

Thus, the total satisfaction points will be calculated as follows:

If $song_x$ is the first song of the live performance, the total satisfaction points just after
$song_x$ is equal to $p_x$.

If $song_x$ is the second or subsequent song of the live performance and is performed just
after $song_y$, $p_x -(f_x -f_y)^2$ is added to the total satisfaction points, because the audience
will get frustrated if $f_x$ and $f_y$ are different.

Help JAG48 find a program with the maximum total satisfaction points.

Input

The input is formatted as follows.

$N$ $T$

$t_1$ $p_1$ $f_1$

: : :

$t_N$ $p_N$ $f_N$

The first line contains two integers $N$ and $T$: the number of the available $song_s$ $N$ ($1 \leq N \leq
4,000$), and the length of the live performance $T$ ($1 \leq T \leq 4,000$).

The following $N$ lines represent the parameters of the songs. The $i$-th line of them contains three
integers, which are the parameters of $song_i$: the length $t_i$ ($1 \leq t_i \leq 4,000$), the basic satisfaction
points $p_i$ ($1 \leq p_i \leq 10^8$), and the feature value $f_i$ ($1 \leq f_i \leq 10^4$).

You can assume that there is at least one song whose length is less than or equal to $T$.

Output

Output the maximum total satisfaction points that the audience can get during the live performance.

Sample Input

2 10
10 200 1
10 100 100

Output for the Sample Input

200

Sample Input

3 15
5 100 1
5 100 2
5 100 4

Output for the Sample Input

295

Sample Input

3 10
5 200 200
5 200 201
5 300 1

Output for the Sample Input

399

Sample Input

3 20
5 100 200
5 100 201
5 300 1

Output for the Sample Input

300

Sample Input

5 61
14 49 7
31 46 4
30 55 5
52 99 1
34 70 3

Output for the Sample Input

103
Problem J:
Black Company

JAG Company is a sweatshop (sweatshop is called "burakku kigyo" in Japanese), and you are
the CEO for the company.

You are planning to determine $N$ employees' salary as low as possible (employees are numbered
from 1 to $N$). Each employee's salary amount must be a positive integer greater than zero. At
that time, you should pay attention to the employees' contribution degree. If the employee $i$'s
contribution degree $c_i$ is greater than the employee $j$'s contribution degree $c_j$ , the employee i
must get higher salary than the employee $j$'s salary. If the condition is not satisfied, employees
may complain about their salary amount.

However, it is not necessarily satisfied in all pairs of the employees, because each employee can
only know his/her close employees' contribution degree and salary amount. Therefore, as long as
the following two conditions are satisfied, employees do not complain to you about their salary
amount.

If the employees $i$ and $j$ are close to each other, $c_i < c_j \Leftrightarrow p_i < p_j$ must be satisfied, where
$p_i$ is the employee $i$'s salary amount.

If the employee $i$ is close to the employees $j$ and $k$, $c_j < c_k \Leftrightarrow p_j < p_k$ must be satisfied.
Write a program that computes the minimum sum of all employees' salary amount such that no
employee complains about their salary.

Input

Each input is formatted as follows:

$N$

$c_1$ ... $c_N$

$M$

$a_1$ $b_1$

...

$a_M$ $b_M$

The first line contains an integer $N$ ($1 \leq N \leq 100,000$), which indicates the number of employees.
The second line contains $N$ integers $c_i$ ($1 \leq c_i \leq 100,000$) representing the contribution degree
of employee $i$.

The third line contains an integer $M$ ($0 \leq M \leq 200,000$), which specifies the number of relationships. Each of the following $M$ lines contains two integers $a_i$ and $b_i$ ($a_i \ne b_i, 1 \leq a_i, b_i \leq N$).
It represents that the employees $a_i$ and $b_i$ are close to each other. There is no more than one
relationship between each pair of the employees.

Output

Print the minimum sum of all employees' salary amounts in a line.

Sample Input

3
1 3 3
2
1 2
1 3

Output for the Sample Input

5

Sample Input

3
1 2 3
2
1 2
1 3

Output for the Sample Input

6

Sample Input

4
1 1 2 2
2
1 2
3 4

Output for the Sample Input

4

Sample Input

5
1 2 5 5 1
6
1 2
4 1
2 3
5 2
4 3
4 5

Output for the Sample Input

10

Sample Input

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

Output for the Sample Input

13
M and A

The CEO of the company named $S$ is planning M&A with another company named $T$. M&A is an abbreviation for "Mergers and Acquisitions". The CEO wants to keep the original company name $S$ through the M&A on the plea that both company names are mixed into a new one.

The CEO insists that the mixed company name after the M&A is produced as follows.

Let $s$ be an arbitrary subsequence of $S$, and $t$ be an arbitrary subsequence of $T$. The new company name must be a string of the same length to $S$ obtained by alternatively lining up the characters in $s$ and $t$. More formally, $s_0 + t_0 + s_1 + t_1 + ...$ or $t_0 + s_0 + t_1 + s_1 + ... $ can be used as the company name after M&A. Here, $s_k$ denotes the $k$-th (0-based) character of string $s$. Please note that the lengths of $s$ and $t$ will be different if the length of $S$ is odd. In this case, the company name after M&A is obtained by $s_0 + t_0 + ... + t_{|S|/2} + s_{|S|/2+1}$ or $t_0 + s_0 + ... + s_{|S|/2} + t_{|S|/2+1}$ ($|S|$ denotes the length of $S$ and "/" denotes integer division).

A subsequence of a string is a string which is obtained by erasing zero or more characters from the original string. For example, the strings "abe", "abcde" and "" (the empty string) are all subsequences of the string "abcde".

You are a programmer employed by the acquiring company. You are assigned a task to write a program that determines whether it is possible to make $S$, which is the original company name, by mixing the two company names.

Input

The input consists of a single test case. The test case consists of two lines.

The first line contains a string $S$ which denotes the name of the company that you belong to. The second line contains a string $T$ which denotes the name of the target company of the planned M&A. The two names $S$ and $T$ are non-empty and of the same length no longer than 1,000 characters, and all the characters used in the names are lowercase English letters.

Output

Print "Yes" in a line if it is possible to make original company name by combining $S$ and $T$. Otherwise, print "No" in a line.

Sample Input 1

acmicpc
tsukuba

Output for the Sample Input 1

No

Sample Input 2

hoge
moen

Output for the Sample Input 2

Yes

Sample Input 3

abcdefg
xacxegx

Output for the Sample Input 3

Yes
Change a Password

Password authentication is used in a lot of facilities. The office of JAG also uses password authentication. A password is required to enter their office. A password is a string of $N$ digits '0'-'9'. This password is changed on a regular basis. Taro, a staff of the security division of JAG, decided to use the following rules to generate a new password from an old one.

The new password consists of the same number $N$ of digits to the original one and each digit appears at most once in the new password. It can have a leading zero. (Note that an old password may contain same digits twice or more.)

The new password maximizes the difference from the old password within constraints described above. (Definition of the difference between two passwords is described below.)

If there are two or more candidates, the one which has the minimum value when it is read as an integer will be selected.

The difference between two passwords is defined by min($|a - b|, 10^N - |a - b|$), where $a$ and $b$ are the integers represented by the two passwords. For example, the difference between "11" and "42" is 31, and the difference between "987" and "012" is 25.

Taro would like to use a computer to calculate a new password correctly, but he is not good at programming. Therefore, he asked you to write a program. Your task is to write a program that generates a new password from an old password.

Input

The input consists of a single test case. The first line of the input contains a string $S$ which denotes the old password. You can assume that the length of $S$ is no less than 1 and no greater than 10. Note that old password $S$ may contain same digits twice or more, and may have leading zeros.

Output

Print the new password in a line.

Sample Input 1

201

Output for the Sample Input 1

701

Sample Input 2

512

Output for the Sample Input 2

012

Sample Input 3

99999

Output for the Sample Input 3

49876

Sample Input 4

765876346

Output for the Sample Input 4

265874931
Delete Files

You are using an operating system named "Jaguntu". Jaguntu provides "Filer", a file manager with a graphical user interface.

When you open a folder with Filer, the name list of files in the folder is displayed on a Filer window. Each filename is displayed within a rectangular region, and this region is called a filename region. Each filename region is aligned to the left side of the Filer window. The height of each filename region is 1, and the width of each filename region is the filename length. For example, when three files "acm.in1", "acm.c~", and "acm.c" are stored in this order in a folder, it looks like Fig. C-1 on the Filer window.

You can delete files by taking the following steps. First, you select a rectangular region with dragging a mouse. This region is called selection region. Next, you press the delete key on your keyboard. A file is deleted if and only if its filename region intersects with the selection region. After the deletion, Filer shifts each filename region to the upside on the Filer window not to leave any top margin on any remaining filename region. For example, if you select a region like Fig. C-2, then the two files "acm.in1" and "acm.c~" are deleted, and the remaining file "acm.c" is displayed on the top of the Filer window as Fig. C-3.

You are opening a folder storing $N$ files with Filer. Since you have almost run out of disk space, you want to delete unnecessary files in the folder. Your task is to write a program that calculates the minimum number of times to perform deletion operation described above.

Input

The input consists of a single test case. The test case is formatted as follows.

$N$

$D_1$ $L_1$

$D_2$ $L_2$

...

$D_N$ $L_N$

The first line contains one integer $N$ ($1 \leq N \leq 1,000$), which is the number of files in a folder. Each of the next $N$ lines contains a character $D_i$ and an integer $L_i$: $D_i$ indicates whether the $i$-th file should be deleted or not, and $L_i$ ($1 \leq L_i \leq 1,000$) is the filename length of the $i$-th file. If $D_i$ is 'y', the $i$-th file should be deleted. Otherwise, $D_i$ is always 'n', and you should not delete the $i$-th file.

Output

Output the minimum number of deletion operations to delete only all the unnecessary files.

Sample Input 1

3
y 7
y 6
n 5

Output for the Sample Input 1

1

Sample Input 2

3
y 7
n 6
y 5

Output for the Sample Input 2

2

Sample Input 3

6
y 4
n 5
y 4
y 6
n 3
y 6

Output for the Sample Input 3

2
Line Gimmick

You are in front of a linear gimmick of a game. It consists of $N$ panels in a row, and each of them displays a right or a left arrow.

You can step in this gimmick from any panel. Once you get on a panel, you are forced to move following the direction of the arrow shown on the panel and the panel will be removed immediately. You keep moving in the same direction until you get on another panel, and if you reach a panel, you turn in (or keep) the direction of the arrow on the panel. The panels you passed are also removed. You repeat this procedure, and when there is no panel in your current direction, you get out of the gimmick.

For example, when the gimmick is the following image and you first get on the 2nd panel from the left, your moves are as follows.

Move right and remove the 2nd panel.

Move left and remove the 3rd panel.

Move right and remove the 1st panel.

Move right and remove the 4th panel.

Move left and remove the 5th panel.

Get out of the gimmick.

You are given a gimmick with $N$ panels. Compute the maximum number of removed panels after you get out of the gimmick.

Input

The input consists of two lines. The first line contains an integer $N$ ($1 \leq N \leq 100,000$) which represents the number of the panels in the gimmick. The second line contains a character string $S$ of length $N$, which consists of '>' or '<'. The $i$-th character of $S$ corresponds to the direction of the arrow on the $i$-th panel from the left. '<' and '>' denote left and right directions respectively.

Output

Output the maximum number of removed panels after you get out of the gimmick.

Sample Input 1

7
>><><<<

Output for the Sample Input 1

7

Sample Input 2

5
>><<<

Output for the Sample Input 2

5

Sample Input 3

6
><<><<

Output for the Sample Input 3

6

Sample Input 4

7
<<><<>>

Output for the Sample Input 4

5
Cube Dividing

Pablo Cubarson is a well-known cubism artist. He is producing a new piece of work using a cuboid which consists of $A \times B \times C$ unit cubes. He plans to make a beautiful shape by removing $N$ units cubes from the cuboid. When he is about to begin the work, he has noticed that by the removal the cuboid may be divided into several parts disconnected to each other. It is against his aesthetics to divide a cuboid. So he wants to know how many parts are created in his plan.

Your task is to calculate the number of connected components in the cuboid after removing the $N$ cubes. Two cubes are connected if they share one face.

Input

The input consists of a single test case. The test case is formatted as follows:

$A$ $B$ $C$ $N$

$X_1$ $Y_1$ $Z_1$

...

$X_N$ $Y_N$ $Z_N$

The first line contains four integers $A$, $B$, $C$ and $N$. $A$, $B$ and $C$ ($1 \leq A,B,C \leq 10^6$) denote the size of the cuboid $-$ the cuboid has an $A$ unit width from left to right and a $B$ unit height from bottom to top, and a $C$ unit depth from front to back. $N$ ($0 \leq N \leq 20,000, N \leq A \times B \times C - 1$) denotes the number of the cubes removed in the Cubarson's plan. Each of the following $N$ lines contains three integers $X_i$ ($0 \leq X_i \leq A-1$), $Y_i$ ($0 \leq Y_i \leq B-1$) and $Z_i$ ($0 \leq Z_i \leq C - 1$). They denote that the cube located at the $X_i$-th position from the left, the $Y_i$-th from the bottom and the $Z_i$-th from the front will be removed in the plan. You may assume the given positions are distinct.

Output

Print the number of the connected components in the cuboid after removing the specified cubes.

Sample Input 1

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

Output for the Sample Input 1

4

Sample Input 2

3 3 3 1
1 1 1

Output for the Sample Input 2

1

Sample Input 3

1 1 3 2
0 0 0
0 0 2

Output for the Sample Input 3

1