National Taiwan University Class Preliminary 2024
A. Akari
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Akari, also known as Light Up, is a logic puzzle played on a rectangular grid. The player places light bulbs in empty cells until the entire grid is illuminated.

A light bulb lights up its own cell and all cells along the horizontal and vertical directions until its light hits an obstacle or the edge of the grid. No two light bulbs should be illuminated by each other. There are clue cells in the original rules indicating exactly how many bulbs must be placed in adjacent cells. However, determining whether a puzzle is solvable has been proven to be NP-complete.

Directions of the light. (a) The light illuminates all cells in the same row or column. (b) The light is blocked by '#' and no longer lights up the '.' cell.
Invalid placement.

In this problem, a puzzle without clue cells will be provided for each test case. Please find a solution to the puzzle.

Input

The first line of the input contains two integers $$$N$$$ and $$$M$$$ — the number of rows and columns in the puzzle.

The following $$$N$$$ lines contain the description of the puzzle. Each line contains a string of length $$$M$$$, consisting of characters '.' and '#'. The character '.' denotes an empty cell and the character '#' denotes an obstacle that blocks the light.

  • $$$1\leq N, M\leq 2000$$$
Output

Mark the light bulbs you placed with the letter 'L' and output the final configuration in the same format as the given puzzle in the input. If there are multiple solutions, print any of them. It is guaranteed that at least one solution exists for the given input.

Examples
Input
3 3
...
.#.
...
Output
L..
.#L
.L.
Input
4 5
..#..
.###.
..#..
.#.#.
Output
L.#L.
.###L
.L#L.
.#L#.

B. Beautiful Strings
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Let's define that a string $$$s$$$ is considered better than another string $$$t$$$ if and only if both of the following conditions are met:

  • $$$s$$$ is not a prefix of $$$t$$$
  • $$$s$$$ is lexicographically smaller than $$$t$$$

Alice has a string $$$s$$$ of length $$$N$$$. She wants to split the string into $$$K$$$ continuous substrings $$$s[1 : p_1], s[p_1 + 1 : p_2], \dots, s[p_{K - 1} + 1 : p_K]$$$ such that:

  • Define $$$p_0 = 0$$$
  • For every $$$1 \leq i \lt K$$$, the substring $$$s[p_{i - 1} + 1 : p_i]$$$ is better than the substring $$$s[p_i + 1 : N]$$$
  • $$$p_K=N$$$
Input

The first line of input contains a single integer $$$T$$$ denoting the number of test cases.

Each test case consists of a single line containing a lowercase letter string $$$s$$$.

  • $$$1 \leq T \leq 2\times 10^5$$$
  • $$$1 \leq |s| \leq 2\times 10^5$$$
  • The total length of all strings across all test cases will not exceed $$$2\times 10^5$$$ characters.
Output

For each test case, output the maximum possible value of $$$K$$$.

Example
Input
2
abababa
aababaddb
Output
2
4

C. Crystal Mining
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Maggie discovers a large magical crystal deep within the cave. The crystal has a regular hexagonal shape, which is seen as a symbol of balance. In this world, there are $$$999$$$ types of magic particles. When these particles are arranged in a hexagonal pattern, a crystal is formed. However, if a crystal contains more than one type of particle, it is considered impure and may explode if someone attempts to release its power.

Maggie decides to extract a pure crystal, where all the magic particles are of the same type. For each potential center of the new crystal, help Maggie determine the side length of the largest pure crystal that can be extracted.

Side length: 1.Side length: 2.Not a crystal.
Input

The first line of the input contains a single integer $$$N$$$ — the side length of the crystal.

The following $$$2N - 1$$$ lines contain the description of the crystal. Each line contains multiple integers $$$a_{r,c}$$$ — the type of the magic particle at the corresponding position.

  • $$$1\leq N\leq 999$$$
  • $$$1\leq a_{r, c}\leq 999$$$
Output

For each position $$$(r, c)$$$ as the center, output the side length of the largest pure crystal.

Arrange the output in the same format as the given input, and do not output any leading and trailing spaces.

Examples
Input
2
1 1
1 1 1
1 1
Output
1 1
1 2 1
1 1
Input
3
2 1 2
2 1 2 1
2 1 1 1 1
1 1 1 1
1 1 1
Output
1 1 1
1 1 1 1
1 1 1 1 1
1 2 2 1
1 1 1
Input
5
2 8 1 6 2
8 8 8 1 4 1
8 8 8 8 4 9 1
8 8 8 8 8 2 2 3
8 7 7 8 8 8 2 2 999
7 7 7 8 8 8 2 2
7 7 8 8 8 2 2
8 8 8 8 2 2
8 8 8 2 2
Output
1 1 1 1 1
1 1 1 1 1 1
1 2 2 1 1 1 1
1 1 1 2 1 1 1 1
1 1 1 1 2 1 1 1 1
1 2 1 1 2 1 1 1
1 1 1 2 1 1 1
1 1 2 1 1 1
1 1 1 1 1

D. Differencing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a set $$$P$$$ of the smallest $$$n$$$ primes $$$p_1 = 2 \le p_2 = 3\le \cdots \le p_n$$$. Partition the primes into two subsets $$$A$$$ and $$$B$$$ (which can be empty), such that the difference between the sums of two subsets is minimized.

Example

If $$$N = 9$$$, the set $$$P$$$ is $$$\{2, 3, 5, 7, 11, 13, 17, 19, 23\}$$$. The table below demonstrates an optimal solution:

$$$p_1$$$$$$p_2$$$$$$p_3$$$$$$p_4$$$$$$p_5$$$$$$p_6$$$$$$p_7$$$$$$p_8$$$$$$p_9$$$sum
A257171950
B311132350
Input

Each test contains multiple test cases. The first line contains a single integer $$$T$$$ — the number of test cases. The description of the test cases follows.

Each test case contains a single integer $$$N$$$ — $$$P$$$ is the set of the smallest $$$N$$$ prime numbers.

  • $$$1\leq T\leq 4\times 10^5$$$
  • $$$1\leq N\leq 4\times 10^5$$$
  • It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$2 \times 10^6$$$.
Output

For each test case, print a string $$$S$$$ of length $$$N$$$ consisting of characters A and B, representing the optimal partition. If the $$$k$$$-th smallest prime, $$$p_k$$$, belongs to $$$A$$$ in your solution, the $$$k$$$-th character of $$$S$$$ must be A, and it must be B otherwise. If there are multiple such partitions, print any of them.

Example
Input
5
3
4
4
9
10
Output
AAB
ABBA
ABBA
ABAABABBA
BABABABAAB

E. Employees Selection
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

ICPC Company has $$$N$$$ employees, with employee $$$1$$$ being the boss of the company. Each of the employees numbered $$$2$$$ through $$$N$$$ has a direct supervisor $$$s_i$$$, where $$$1 \leq s_i \lt i$$$. For employee $$$i$$$, all employees $$$s_i, s_{s_i}, \ldots, 1$$$ are considered to be supervisors of employee $$$i$$$.

Now, ICPC Company has a major project that requires sending some employees on a business trip. It is known that selecting the $$$i$$$-th employee will bring a profit of $$$p_i$$$ million dollars (if this value is negative, it means sending that employee on the trip will incur a loss).

However, selecting employees for the trip is not as simple as just choosing those with positive profits. Each employee also has a capability value $$$a_i$$$, where all capability values form a permutation of $$$1$$$ to $$$N$$$. For each employee $$$i$$$ sent on the business trip, if any of their supervisors is not sent, employee $$$i$$$ will need to handle that supervisor's tasks. But if there exists an unsent supervisor's capability value is higher than theirs, employee $$$i$$$ will feel pressure and cause a loss of $$$c_i$$$ million dollars, no matter how many unsent supervisors with higher capability value there are.

Additionally, there is another way losses can occur: for every $$$1 \leq i \lt N$$$, if the employee with capability values $$$i+1$$$ is selected for the trip but the employee with capability values $$$i$$$ is not, a further loss of $$$d_i$$$ million dollars will occur.

But wait! Before ICPC Company decides on the personnel to dispatch, they need to quickly inform the client whether they will accept the project. For this reason, ICPC Company has commissioned you, with your algorithmic expertise, to help them evaluate the maximum potential profit they could achieve.

However, ICPC Company knows an obvious upper bound: the total profit cannot exceed $$$T = \sum_{i=1}^{N}\max(p_i, 0)$$$ million dollars. After careful evaluation, ICPC Company has decided that if the maximum profit from this business trip is less than $$$T - 20$$$ million dollars, they will immediately reject the project; otherwise, they will begin planning for the trip.

Can you help ICPC Company determine whether they should take on the project? If they decide to take on the project, please also output the exact maximum profit that ICPC Company can achieve.

Input

The input first contains a positive integer $$$N$$$, representing the number of employees in ICPC Company.

The next line contains $$$N-1$$$ integers $$$s_2, s_3, \ldots, s_N$$$, where $$$s_i$$$ represents the direct supervisor of the $$$i$$$-th employee.

The third line contains $$$N$$$ integers $$$p_1, p_2, \ldots, p_N$$$, representing the profit the $$$i$$$-th employee can bring.

The fourth line contains $$$N$$$ integers $$$a_1, a_2, \ldots, a_N$$$, representing the capability value of the $$$i$$$-th employee.

The fifth line contains $$$N$$$ integers $$$c_1, c_2, \ldots, c_N$$$, representing the loss parameter of the $$$i$$$-th employee.

The sixth line contains $$$N-1$$$ integers $$$d_1, d_2, \ldots, d_{N-1}$$$, representing the loss parameter between the employees with capability values $$$i$$$ and $$$i+1$$$.

  • $$$1 \leq N \leq 5\times 10^4$$$
  • $$$1 \leq s_i \lt i$$$
  • $$$-50\leq p_i \leq 50$$$
  • $$$a_1, a_2, \ldots, a_N$$$ form a permutation of the numbers $$$1$$$ to $$$N$$$.
  • $$$0\leq c_i, d_i \leq 50$$$
Output

If the maximum profit is less than $$$T - 20$$$ million dollars, output Fail! on a single line. Otherwise, output a single integer representing the maximum profit that ICPC Company can achieve under the optimal strategy for selecting employees to send on the business trip.

Examples
Input
4
1 2 2
10 -6 6 2
4 3 2 1
1 1 1 5
1 1 1
Output
13
Input
6
1 2 2 4 4
-3 -10 9 -1 4 7
1 4 3 6 5 2
0 1 8 1 3 1
1 5 0 0 2
Output
9
Input
2
1
-42 21
2 1
0 42
0
Output
Fail!

F. Forever on a Bicycle
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

National Taiwan University's campus is quite large, and as a commuting student, Wiwiho doesn't want to walk 15 minutes to her department after a long commute. Therefore, she decides to use the Ubike facilities scattered around the campus.

However, there's a significant flaw she often overlooks. After successfully borrowing a Ubike from a station, she frequently finds that the stations near her department have no available slots when she arrives, forcing her to cycle to a more distant station and then walk a longer distance to her destination, defeating the purpose.

As a competitive programming contestant, Wiwiho decides to plan an optimal route to reach her department as quickly as possible. She selects $$$N$$$ stations on the NTU campus, numbered from $$$1$$$ to $$$N$$$, and plans $$$M$$$ routes between these stations. Each route is defined by three numbers $$$u_i, v_i, w_i$$$, representing a route between station $$$u_i$$$ and $$$v_i$$$ with a cycling time of $$$w_i$$$, regardless of direction.

Because returning a bike depends on luck, for each station, Wiwiho has estimated parameters $$$p_i, q_i, d_i$$$ through statistical data. Initially, all stations are in an "unknown state". When she arrives at station $$$i$$$ which is in an unknown state, she can try to observe the station and use the following strategy:

  • Whenever Wiwiho observes at station $$$i$$$, there's a probability $$$p_i$$$ that the station has an available slot.
  • If there's an available slot, she can return the bike and walk to her department in $$$d_i$$$ time.
  • If there's no available slot, Wiwiho can choose to cycle away immediately. After this, she will turn that station into a "full state".
  • If there's no available slot but Wiwiho chooses not to cycle away, she can wait an expected $$$q_i$$$ time for a slot to become available, then walk to her department in $$$d_i$$$ time. Note that during this $$$q_i$$$ time, Wiwiho cannot leave the station because returning a bike requires queuing.

Besides, when Wiwiho arrives at station $$$i$$$ which is in a full state, she can still choose not to cycle away, and wait an expected $$$q_i$$$ time for a slot to become available, then walk to her department in $$$d_i$$$ time.

Note that Wiwiho can choose not to observe a station when she passes through it.

To simplify the problem, assume that the probabilities and expected values for each station are independent, meaning stations do not influence each other's parameters.

Can you help Wiwiho find the minimum expected time to successfully return a bike and walk to her department if she borrows a Ubike from station $$$1$$$? Note that although Wiwiho can choose to return the bike at station $$$1$$$, she must follow the aforementioned rules, meaning she only has a probability $$$p_1$$$ of immediately returning the bike there.

Input

The first line contains two integers $$$N, M$$$, representing the number of stations, and the number of routes Wiwiho selected.

The second line contains $$$N$$$ floating-point numbers $$$p_1, p_2, \ldots, p_N$$$, representing the probability of finding an available slot at station $$$i$$$ when Wiwiho arrives.

The third line contains $$$N$$$ floating-point numbers $$$q_1, q_2, \ldots, q_N$$$, representing the expected queuing time at station $$$i$$$ if no slot is available upon arrival.

The fourth line contains $$$N$$$ floating-point numbers $$$d_1, d_2, \ldots, d_N$$$, representing the time required to walk from station $$$i$$$ to her department.

The next $$$M$$$ lines each contain two integers and one floating-point number $$$u_i, v_i, w_i$$$, representing a route connecting station $$$u_i$$$ and station $$$v_i$$$, with a cycling time $$$w_i$$$ between them.

  • $$$1 \leq N \leq 18$$$
  • $$$0 \leq M \leq \frac{N \times (N-1)}{2}$$$
  • $$$0 \leq d_i, w_i, q_i \leq 1000$$$
  • $$$0 \leq p_i \leq 1$$$
  • All floating-point numbers will be given to three decimal places.
  • No two routes connect the same pair of stations.
Output

Output a single floating-point number representing the minimum expected time for Wiwiho to successfully return a bike and walk to her department after borrowing a Ubike from station $$$1$$$.

Your answer will be accepted if the absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a-b|}{\max(1,|b|)}\le 10^{-6}$$$.

Examples
Input
4 4
0.800 0.500 0.200 0.600
3.000 3.000 5.000 2.000
15.000 5.000 1.000 2.000
1 2 3.141
2 3 2.718
1 3 7.654
3 4 1.414
Output
8.78560000000000052012
Input
11 13
0.800 0.800 0.900 0.900 0.400 0.200 0.200 0.200 0.250 0.400 0.400
1.000 2.000 2.000 2.000 3.000 4.000 4.000 4.000 2.000 1.000 1.000
15.000 12.000 11.000 9.000 3.000 0.000 0.000 0.000 2.000 5.000 4.000
1 2 1.000
1 4 2.333
2 3 0.333
3 4 0.666
4 5 2.000
5 6 1.000
5 10 1.666
6 7 0.333
6 8 0.333
6 9 0.666
7 8 0.333
9 10 1.000
9 11 0.666
Output
7.31551200000000090284

G. Graph Problem
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

There is a classic graph theory problem: given an undirected graph, find the largest subset of vertices such that the vertices form a clique. A clique is defined as a subset of vertices such that every two distinct vertices are adjacent in the given graph.

However, constructing the graph is troublesome. Now, for the $$$N$$$ vertices in the graph, we assign to the $$$i$$$-th vertex an interval $$$[l, r]$$$, representing a circular interval $$$[l, r]$$$.

What is a circular interval? Suppose the entire circle has a size of $$$2N$$$, which we can represent as coordinates $$$0$$$ to $$$2N-1$$$. A circular interval $$$[l, r]$$$ covers the coordinates: $$$$$$ \begin{cases} l\sim r & \text{if }l \lt r \\ 0\sim r\ \cup\ l\sim 2N-1 & \text{if } l \gt r \end{cases} $$$$$$

where $$$0\leq l, r \lt 2N, l\neq r$$$.

Given these intervals, we let there be an edge between any two vertices if and only if their intervals overlap at some coordinate.

Find any maximum clique.

Input

The first line of input contains a positive integer $$$N$$$, representing the number of intervals.

The next $$$N$$$ lines each contain two integers $$$l_i, r_i$$$, representing the coordinates of the interval for the $$$i$$$-th vertex. The intervals are numbered from $$$0$$$ to $$$N-1$$$.

  • $$$1\leq N\leq 2000$$$
  • $$$0\leq l_i, r_i \lt 2N$$$
  • It is guaranteed that all given coordinates are distinct.
Output

Output a single integer $$$k$$$ in the first line, representing the size of the maximum clique.

In the second line, output $$$k$$$ integers $$$c_0, c_1, \ldots, c_{k-1}$$$ separated by single spaces, where $$$c_i$$$ represents the index of the intervals included in the maximum clique.

If there are multiple valid solutions, output any one of them.

Examples
Input
3
0 3
2 5
4 1
Output
3
0 1 2
Input
5
0 6
9 1
3 4
5 8
2 7
Output
3
0 3 4

H. HW0.514
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Boluteshih and 2qbingquan are preparing the problems for Homework 0.514. Boluteshih selected $$$N$$$ problems, while 2qbingquan selected $$$M$$$ problems for the homework.

To make it harder to identify which problems were prepared by whom, Boluteshih wrote a Python script to shuffle the order of these problems randomly. As a coincidence, Boluteshih discovered that after shuffling, the problems chosen by 2qbingquan formed a contiguous subarray within the shuffled list.

Just out of curiosity, you are asked to answer the probability that the problems chosen by 2qbingquan just formed $$$k$$$ contiguous subarray within the shuffled list, for each $$$k$$$ from $$$1$$$ to $$$M$$$. All $$$(N + M)!$$$ permutations of the $$$N + M$$$ problems are considered equiprobable during the shuffle.

As usual, you are asked to output the answer modulo $$$998244353$$$ (see output section).

Input

The input only contains one line with two space-separated integers $$$N, M$$$.

  • $$$1 \leq N, M \leq 10^6$$$.
Output

Print $$$M$$$ space-separated integers, where the $$$i$$$-th is the probability of that the problems chosen by 2qbingquan just formed $$$k$$$ contiguous subarray, modulo $$$998244353$$$.

For each $$$k$$$, it can be shown that the probability is in the form of $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are non-negative integers and $$$Q \neq 0, \mathrm{gcd}(P, Q) = 1$$$. By modulo $$$998244353$$$ it means $$$P\cdot Q^{-1} \pmod{998244353}$$$, which should be an integer in $$$[0, 998244353)$$$.

Examples
Input
1 2
Output
665496236 332748118
Input
2 5
Output
855638017 427819009 713031681 0 0
Input
37 9
Output
773088076 617179006 965409427 423633148 606148699 470916699 791168354 947239560 394683150

I. Image Matching
time limit per test
4 s
memory limit per test
1024 megabytes
input
standard input
output
standard output

It's Cody's birthday! This year, instead of giving him a long string or an integer array with special properties, his friends surprised him with an interesting picture. Cody suspects that the image was cropped from a scene in a video he recently watched, but he can't remember the exact timestamp of the frame.

Cody has extracted all the frames in the video by FFmpeg, but he knows little about image matching. You, a helpful coder, decide to handle the task to earn an AC in return. Because the picture is stored in a lossy compression format, it is possible that an exact match cannot be found. The goal is to find a position with the smallest sum of squared difference (SSD) for the best match.

If the size of an image $$$I$$$ is $$$W \times H$$$ and the size of a (smaller) template image $$$T$$$ is $$$N \times M$$$, the SSD value of the position $$$(x, y)$$$ is defined as:

$$$\displaystyle\operatorname{SSD}(x, y)=\sum_{i=0}^{N-1}\sum_{j=0}^{M-1} \left(I(x + i, y + j) - T(i, j)\right)^2$$$
(a) $$$I$$$. (b) $$$T$$$. (c) Image difference. $$$\operatorname{SSD}(1,1) = 3^2 + 6^2 = 45$$$.
Input

The first line of the input contains two integers $$$W$$$ and $$$H$$$ — the width and the height of a frame from the video.

The following $$$H$$$ lines contain the description of the image $$$I$$$. Each line contains $$$W$$$ double-digit hexadecimal numbers — the pixels of the corresponding positions.

The next line of the input contains two integers $$$N$$$ and $$$M$$$ — the width and the height of the cropped image.

The following $$$M$$$ lines contain the description of the image $$$T$$$. Each line contains $$$N$$$ double-digit hexadecimal numbers — the pixels of the corresponding positions.

  • $$$1\leq W\leq 1024$$$
  • $$$1\leq H\leq 768$$$
  • $$$0\leq I(x, y)\leq 255$$$
  • $$$1\leq N\leq W$$$
  • $$$1\leq M\leq H$$$
  • $$$0\leq T(x, y)\leq 255$$$
Output

The best matching position $$$(x, y)$$$ $$$(0 \le x \le W - N,\ 0 \le y \le H - M)$$$.

If there are multiple such positions, print any of them.

Examples
Input
3 2
00 FF 12
AA BB 34
2 1
FF 11
Output
1 0
Input
4 5
89 4E 72 C6
C7 E9 EA 8F
6E B1 FD E4
7C 22 6C D0
93 FB DB E5
3 3
79 C0 51
B9 98 37
BB 64 7F
Output
1 0
Input
4 3
14 59 EF A0
83 3E AE 94
06 AA 0C 87
3 2
3E A8 94
A7 0C 87
Output
1 1

J. Just Do it!
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

There is too much work to be done! The ICPC class now has an overwhelming amount of tasks that need to be handled. Each task requires a team of two people to complete. The ICPC class has $$$N$$$ people, and there are $$$M$$$ pairs of people who can work together (assigning incompatible pairs would cause awkwardness and complicate the tasks). Each pair can handle at most one task.

But if you think that means we can handle $$$M$$$ tasks, you are too naive! Each person also has their own workload limit. It is known that the $$$i$$$-th person is willing to handle at most $$$a_i$$$ tasks. This means that if the number of tasks assigned to the $$$i$$$-th person exceeds $$$a_i$$$, that person will refuse to do any work.

Can you help the ICPC class find the maximum number of task-handling pairs, such that no one exceeds their workload limit?

Input

The first line contains two positive integers $$$N$$$ and $$$M$$$, representing the number of people in the ICPC class and the number of pairs who can work together, respectively.

The second line contains $$$N$$$ integers $$$a_1, a_2, \ldots, a_N$$$, where $$$a_i$$$ represents the maximum number of tasks the $$$i$$$-th person is willing to handle.

The next $$$M$$$ lines each contain two integers $$$u_i$$$ and $$$v_i$$$, representing that the $$$u_i$$$-th person and the $$$v_i$$$-th person can work together. The pairs are numbered from $$$1$$$ to $$$m$$$.

  • $$$1 \leq N \leq 100$$$
  • $$$1 \leq M \leq 150$$$
  • $$$1 \leq a_i \leq M$$$
  • $$$1 \leq u_i \lt v_i \leq N$$$
  • $$$\forall i \lt j, (u_i, v_i) \neq (u_j, v_j)$$$
Output

The first line should output an integer $$$k$$$, representing the maximum number of task-handling pairs.

The second line should output $$$k$$$ integers $$$w_1, w_2, \ldots, w_k$$$ separated by single spaces, representing an optimal set of pairs that handled $$$k$$$ tasks, where $$$w_i$$$ represents the pair numbered $$$w_i$$$ in your optimal solution.

If there are multiple optimal solutions, any of them will be considered correct.

Examples
Input
4 4
2 1 3 4
1 2
1 3
2 3
3 4
Output
3
1 2 4
Input
6 8
2 2 3 2 3 1
1 2
1 3
1 5
3 5
3 4
4 5
4 6
5 6
Output
6
1 2 4 5 6 8

K. King Game
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Alice and Bob are playing a cool new game called "King Game." The King Game consists of a $$$300 \times 300$$$ board and two pieces that can be placed on certain positions on the board. For convenience, we use 2D coordinates $$$(x, y)$$$ to represent the positions where pieces are placed, where $$$1 \leq x, y \leq 300$$$.

The rules of the King Game are as follows:

  • At the start of the game, the two pieces are placed on different positions: $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$.
  • The players take turns to move, and each turn, the player must choose one of the pieces. Suppose the position of the chosen piece is $$$(x, y)$$$, the player can move it to any position $$$(p, q)$$$ such that $$$1\leq p \leq x$$$ and $$$1\leq q \leq y$$$. However, the new position $$$(p, q)$$$ cannot be $$$(x, y)$$$ or coincide with another piece.
  • The player who cannot make a move loses.

Alice and Bob are going to play $$$T$$$ games, and they have already planned the starting coordinates for each game. Can you tell them, for each game, how many winning first moves the "first player" has under the condition that both players play optimally?

Input

The first line contains a positive integer $$$T$$$, representing the number of games.

The next $$$T$$$ lines each contain four integers $$$x_1, y_1, x_2, y_2$$$, representing the starting coordinates of the pieces for one game.

  • $$$1 \leq T \leq 10^5$$$
  • $$$1 \leq x_1, y_1, x_2, y_2 \leq 300$$$
  • It is guaranteed that for each game, $$$x_1 \neq y_1$$$ or $$$x_2 \neq y_2$$$.
Output

For each game, output a single integer on a new line representing the number of winning first moves the first player has.

Example
Input
5
1 2 3 4
3 1 4 2
6 6 2 2
3 2 2 3
1 12 3 9
Output
1
2
2
0
0

L. Ltf's Board Game
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Ltf proposed an interesting board game, which is played on an $$$N \times N$$$ board by two players who take turns placing pieces on the board. The unique rule of the game is that each player, when placing a piece, must ensure that no two pieces are orthogonally adjacent, meaning that no two pieces can share a side. The player who cannot place a piece on their turn loses the game.

Ltf invited Ian to play this game with him, and Ltf will go first. Given the size of the board, determine who will win if both players play optimally.

Input

The input consists of a single line containing a positive integer $$$N$$$, representing the size of the board.

  • $$$1 \leq N \leq 10^5$$$
Output

If Ltf has a winning strategy, output Ltf on a single line; otherwise, output Ian.

Examples
Input
2
Output
Ian
Input
3
Output
Ltf

M. Melting
time limit per test
5 s
memory limit per test
1024 megabytes
input
standard input
output
standard output

It's so hot this summer!

Vasya is walking along the street, which can be viewed as an infinite two-dimensional plane. He is currently at the point $$$S = (s_x, s_y)$$$, while an ice cream truck is stationed at the point $$$T = (t_x, t_y)$$$.

Despite his eagerness to get some ice cream, the intense sunshine makes the journey uncomfortable. Fortunately, there are $$$N$$$ shaded areas created by trees and buildings blocking the sun, providing some cooler spots. For the purpose of this problem, these shaded areas are considered as convex polygons.

Vasya aims to find a path to the ice cream truck that minimizes the distance traveled outside these shaded areas. Please determine the minimum length Vasya needs to walk without shade.

Input

The first line is an integer $$$N$$$, denoting the number of shade areas. Then there will be $$$N$$$ sections, each describing a convex polygon.

The $$$i$$$-th section starts with an integer $$$k_i$$$, which is the number of vertices in the $$$i$$$-th shade. Each of the next $$$k_i$$$ lines will be two space-separated integers $$$x_{ij}, y_{ij}$$$, denoting the coordinate of the vertices of the convex polygon. In total, there will be $$$k_i + 1$$$ lines in the $$$i$$$-th section. The vertices will be given in counterclockwise order.

Finally, there will be two lines, each consists of two space-separated integers, $$$s_x, s_y$$$ and $$$t_x, t_y$$$, denoting the coordinate of the starting point and the goal.

  • $$$1 \leq N \leq 500$$$.
  • $$$k_i \geq 3$$$.
  • $$$\sum _ {i=1} ^ N k_i \leq 10^5$$$.
  • $$$-10^9 \leq x_{ij}, y_{ij}, s_x, s_y, t_x, t_y \leq 10^9$$$.
  • Each shade area is guaranteed to be a strict convex polygon. By strict, it means that no three consecutive vertices lie on the same line and no two points coincide. Also, the vertices will be given in counterclockwise order.
Output

Print the desired minimum length.

Your answer will be accepted if the absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a-b|}{\max(1,|b|)}\le 10^{-6}$$$.

Examples
Input
3
3
10 10
20 10
20 50
3
30 50
90 50
70 60
3
90 10
100 10
90 60
0 0
100 0
Output
34.14213562373095048677
Input
3
4
-80 0
-70 -20
-50 -25
-60 20
5
70 -40
90 40
70 30
60 20
50 -10
3
-80 -20
100 20
0 20
-100 0
100 0
Output
39.40285000290663788153
Note

The exact answer of sample 1 and sample 2 are $$$20 + 10 \sqrt{2}$$$ and $$$20 + \frac{80}{\sqrt{17}}$$$, respectively.

Illustration of sample 1 and sample 2