2026 ICPC Asia Taiwan Online Programming Contest
A. TOPC Crit
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

At the Tournament of Progressive Combos, better known as TOPC, fighters compete to land the legendary TOPC Crit.

Each attack combo produces three damage values: $$$a$$$, $$$b$$$, and $$$c$$$. Three values form an arithmetic progression if the difference between every pair of consecutive values is the same. In other words, they must satisfy $$$$$$ b-a=c-b. $$$$$$ This shared difference is called the common difference.

A combo triggers a TOPC Crit if and only if its three damage values form an arithmetic progression in the given order. When it does, their common difference $$$x$$$ is known as the secret.

Find this value. It is, indeed, the game's top secret.

Input

The only line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$.

  • $$$-10^9 \le a,b,c \le 10^9$$$
Output

If $$$a$$$, $$$b$$$, and $$$c$$$ form an arithmetic progression, output secret $$$x$$$, where $$$x$$$ is the common difference.

Otherwise, output not secret.

Examples
Input
1 4 7
Output
secret 3
Input
1 2 4
Output
not secret
Note

Explanation for Sample 1

The two consecutive differences are both $$$3$$$, so the three integers form an arithmetic progression with common difference $$$3$$$.

Explanation for Sample 2

The consecutive differences are $$$1$$$ and $$$2$$$, so the three integers do not form an arithmetic progression.

B. The Secret of Fats
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Triglycerides are the main components of animal and plant fats, acting as essential substances for energy storage in the human body. Chemically, all triglycerides are formed by combining one glycerol molecule with three fatty acid molecules.

The physical and chemical properties of fats mainly depend on their connected fatty acid chains. Based on the structure of these chains, we can classify fats into two main categories: saturated fat and unsaturated fat.

If we know the total number of carbon (C), hydrogen (H), and oxygen (O) atoms in a triglyceride molecule, we can directly use simple mathematical rules to determine whether it is a saturated or unsaturated fat without needing specialized laboratory instruments.

For a triglyceride completely devoid of carbon-carbon double bonds (i.e., a saturated fat). Derived from the chemical degree of unsaturation formula, the number of carbon atoms ($$$c$$$) and hydrogen atoms ($$$h$$$) of a saturated triglyceride must strictly satisfy the following linear relationship: $$$$$$ h = 2c - 4 $$$$$$ If the number of hydrogen atoms is less than this standard (i.e., $$$h \lt 2c - 4$$$), it indicates the presence of extra carbon-carbon double bonds in the carbon chain, meaning it is an unsaturated fat.

(Note: This problem guarantees that all input test data represents valid triglyceride molecules, and the number of oxygen atoms ($$$o$$$) will always be 6.)

Now, please write a program that reads the C, H, and O atomic counts of several compounds to classify them accordingly.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$. The description of the test cases follows.

The only line of each test case contains three non-negative integers $$$c$$$, $$$h$$$, and $$$o$$$, representing the number of carbon, hydrogen, and oxygen atoms in the compound, respectively.

  • $$$1 \le t \le 10^4$$$
  • $$$6 \le c \le 150$$$
  • $$$8 \le h \le 2\times c - 4$$$, and $$$h$$$ is even.
  • $$$o$$$ is guaranteed to be $$$6$$$, and the data is guaranteed to conform to the chemical rules of a valid triglyceride.
Output

For each test case, output a single line containing the classification result of the compound:

  • If it is a saturated fat, output the string Saturated.
  • If it is an unsaturated fat, output the string Unsaturated.
Example
Input
3
51 98 6
57 104 6
55 102 6
Output
Saturated
Unsaturated
Unsaturated
Note

Explanation for Sample 1

  • Test Case 1: Carbon is 51, hydrogen is 98, and oxygen is 6. It satisfies the saturated fat condition because $$$2\times51-4=98$$$. This compound is Tripalmitin; output Saturated.
  • Test Case 2: Carbon is 57, hydrogen is 104, and oxygen is 6. The saturated upper limit is $$$2\times57-4=110$$$. Because $$$104 \lt 110$$$, this is an unsaturated fat (Triolein, containing 3 double bonds); output Unsaturated.
  • Test Case 3: Carbon is 55, hydrogen is 102, and oxygen is 6. The saturated upper limit is $$$2\times55-4=106$$$. Because $$$102 \lt 106$$$, it contains extra double bonds and is an unsaturated fat; output Unsaturated.

C. Magical Girl and White Rabbits
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Madoka was originally an ordinary student who went to school happily every day. However, one day she was suddenly persuaded to become a magical girl, and thus began her endless battles against enemies to protect the world.

The transportation network of this world is shaped like a complete $$$k$$$-ary tree with $$$l$$$ levels. Her base is located in Central City, which is located at the root node (level $$$1$$$), and all enemies lurk at the leaves (level $$$l$$$). Every non-leaf node has exactly $$$k$$$ children, which are ordered from left to right as its $$$1$$$-st, $$$2$$$-nd, $$$\dots$$$, $$$k$$$-th child, exactly as they are drawn in the picture below. Given $$$k$$$ and $$$l$$$, we can determine the total number of nodes in the tree (denoted $$$S$$$), which is at most $$$10^6$$$. Below is an example transportation network with $$$k = 3$$$ and $$$l = 4$$$, where $$$S=40$$$:

Over time, Madoka has already completed $$$n$$$ enemy extermination missions sequentially. For each mission, she started her journey from Central City.

However, the enemies are not the only threat. There exists a special kind of mysterious "white rabbit" in this world that Madoka finds extremely annoying and difficult to deal with. To conserve her precious magical energy for the actual battles, Madoka actively chooses which enemy to hunt based on the safest route. She evaluates the routes to all leaves and always selects a root-to-leaf path that contains the minimum total number of white rabbits along the way.

Several different paths may share this minimum total, so Madoka fixes her route in the following deterministic way. She walks down from the root one node at a time. Standing at a non-leaf node $$$v$$$, she looks at every child $$$c$$$ of $$$v$$$ that keeps her on a path of the minimum total (that is, the number of white rabbits on the road from $$$v$$$ to $$$c$$$, plus the minimum number of white rabbits on a path from $$$c$$$ down to a leaf of $$$c$$$'s subtree, is as small as possible among all children of $$$v$$$), and she always steps into the leftmost such child, that is, the one with the smallest index among them. She repeats this until she arrives at a leaf.

Unfortunately, these white rabbits have a strange affinity for magical girls and are strongly attracted to Madoka's magical trail. After she completes the $$$i$$$-th mission, her residual magic instantly triggers a rapid multiplication of the creatures. Specifically, on every single road segment that Madoka just traveled across during that mission, the number of white rabbits permanently occupying that road increases by $$$w_i$$$. (Initially, the world was peaceful, and there were $$$0$$$ white rabbits on all roads.)

As the missions pile up, the network becomes increasingly congested with these white rabbits. Madoka needs to know how bad the situation has eventually become. Determine the total number of white rabbits Madoka will inevitably encounter on her chosen path during her NEXT ($$$n+1$$$)-th extermination mission.

Input

The first line contains three integers $$$k$$$, $$$l$$$, and $$$n$$$, representing the branching factor of the tree, the number of levels, and the number of completed missions.

The second line contains $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$, representing the sequence of values by which the white rabbits increase on the traveled road segments after each mission.

  • $$$1 \leq k \leq 10^6$$$
  • $$$2 \leq l \leq 1000$$$
  • $$$1 \leq n \leq 2 \times 10^5$$$
  • $$$1 \leq w_i \leq 10^9$$$
  • The total number of nodes in the tree does not exceed $$$10^6$$$.
Output

Output a single integer representing the total number of white rabbits on the path Madoka will choose during her NEXT ($$$n+1$$$)-th mission.

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

Explanation for Sample 1

The tree has $$$4$$$ leaves, numbered $$$1$$$ to $$$4$$$ from left to right; leaves $$$1$$$ and $$$2$$$ belong to the root's $$$1$$$-st child, leaves $$$3$$$ and $$$4$$$ to its $$$2$$$-nd child. Over the five missions Madoka visited leaves $$$1$$$, $$$3$$$, $$$2$$$, $$$4$$$, $$$1$$$.

The first two missions are the ones that use the tie-breaking rule. In mission $$$1$$$, every road was still empty, so all four routes tied; she went into the left child at the root and again at the next node, reaching leaf $$$1$$$. In mission $$$2$$$, the four routes cost $$$2$$$, $$$1$$$, $$$0$$$, $$$0$$$: at the root the $$$2$$$-nd child was strictly better, and there its two leaves tied at $$$0$$$, so she took the leftmost of them, leaf $$$3$$$. In the remaining three missions, the route with the fewest white rabbits was unique: leaf $$$2$$$ at cost $$$1$$$, then leaf $$$4$$$ at cost $$$2$$$, then leaf $$$1$$$ at cost $$$5$$$.

After these $$$5$$$ missions, the four routes cost $$$15$$$, $$$12$$$, $$$8$$$ and $$$10$$$, respectively. Thus, for her next mission, Madoka takes the path to leaf $$$3$$$ and will inevitably encounter exactly $$$8$$$ white rabbits.

D. Listen to the Music
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Yuki likes listening to music. She has $$$n$$$ favorite songs, numbered from $$$1$$$ to $$$n$$$.

She created two playlists, and each playlist contains each of these $$$n$$$ songs exactly once. In the first playlist, the $$$i$$$-th song is song $$$a_i$$$. In the second playlist, the $$$i$$$-th song is song $$$b_i$$$.

Whenever Yuki wants to listen to music, she chooses one of the two playlists and starts playing it from the first song. She may stop after any song finishes, but she will never stop in the middle of a song. In other words, each time she listens to music, she chooses one of the two playlists and listens to a non-empty prefix of it.

A year has passed, and Yuki's music system reports that song $$$i$$$ was listened to exactly $$$c_i$$$ times in total. However, Yuki suspects that this statistic may be incorrect. Please determine whether there exists some possible listening history such that, for every song $$$i$$$, the total number of times song $$$i$$$ was listened to is exactly $$$c_i$$$. Note that Yuki may not have listened to any music at all last year.

Input

The first line contains a positive integer $$$n$$$, the number of Yuki's favorite songs.

The second line contains $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$, representing the order of the songs in the first playlist.

The third line contains $$$n$$$ positive integers $$$b_1, b_2, \ldots, b_n$$$, representing the order of the songs in the second playlist.

The fourth line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$, where $$$c_i$$$ is the total number of times song $$$i$$$ was listened to.

  • $$$1 \leq n \leq 5000$$$
  • Both $$$a$$$ and $$$b$$$ are permutations of $$$1, 2, \ldots, n$$$.
  • $$$0 \leq c_i \leq 10^9$$$
Output

If there exists a possible listening history such that the number of times each song was listened to matches the reported statistics, output Yes. Otherwise, output No.

Examples
Input
5
2 4 1 3 5
3 1 2 5 4
3 3 2 3 0
Output
Yes
Input
3
1 2 3
2 1 3
0 0 1
Output
No
Note

Explanation for Sample 1

Consider the playlists $$$a = [2, 4, 1, 3, 5]$$$ and $$$b = [3, 1, 2, 5, 4]$$$. Suppose Yuki listens to four prefixes as follows:

  • The first $$$2$$$ songs of the first playlist, so songs $$$2$$$ and $$$4$$$ are listened to once.
  • The first $$$3$$$ songs of the first playlist, so songs $$$2, 4$$$ and $$$1$$$ are listened to once.
  • The first $$$4$$$ songs of the first playlist, so songs $$$2, 4, 1$$$ and $$$3$$$ are listened to once.
  • The first $$$2$$$ songs of the second playlist, so songs $$$3$$$ and $$$1$$$ are listened to once.

Then the total listening counts are exactly $$$[3, 3, 2, 3, 0]$$$, which matches the reported statistics. Hence, the answer is Yes.

E. Elegant Slabstones Rearrangement
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Barbara has a garden, represented as an $$$n \times n$$$ grid. She has bought $$$n^2$$$ slabstones indexed from $$$1$$$ to $$$n^2$$$ and placed them in her garden, so she can enjoy stepping slabstones from one to another every day. The slabstones are arranged in row-major order, that is, the slabstone at cell $$$(i, j)$$$ is indexed $$$(i - 1) \times n + j$$$.

Barbara would like to redesign her garden, so she invited Babara, a famous interior designer. After careful consideration, Barbara suggests that the slabstone at cell $$$(i, j)$$$ should be indexed $$$a_{ij}$$$. They will use the following "elegant" process to rearrange the slabstones:

  1. Color each slabstone either red or blue.
  2. Shift the red slabstones within each row (so they can only move left or right).
  3. Shift the blue slabstones within each column (so they can only move up or down).

However, there is an important restriction: Any two slabstones with the same color should remain non-overlapping during the rearrangement of the slabstones. Note that a red slabstone and a blue slabstone can temporarily overlap (but in order to have the desired garden, they should not overlap at the end).

Now Barbara wants to know whether they can rearrange the slabstones as desired.

Input

The first line contains an integer $$$n$$$, representing the size of the garden.

Followed by $$$n$$$ lines, the $$$i$$$-th of which contains $$$n$$$ integers, the $$$j$$$-th integer $$$a_{ij}$$$ represents the index of the slabstone at cell $$$(i, j)$$$ in the desired garden.

  • $$$1 \leq n \leq 100$$$
  • $$$1 \leq a_{ij} \leq n^2$$$
  • All $$$a_{ij}$$$ are distinct.
Output

If the slabstones can be rearranged as desired, output Yes; otherwise output No.

Examples
Input
4
1 2 4 8
6 10 3 7
5 11 15 12
9 14 13 16
Output
Yes
Input
2
1 2
4 3
Output
No
Note

Explanation for Sample 1

Below is the illustration of one possible way to rearrange the slabstones. The blue slabstones in step 2 (and the red slabstones in step 3) are hidden for clarity. The slabstones should be shifted in some order that does not violate the restriction. For example, in step 3, you can shift slabstone $$$9$$$ one cell down then shift slabstone $$$5$$$ one cell down, but not in the opposite order.

F. Escape Route
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

In a tourist archipelago consisting of $$$n$$$ islands, there are $$$m$$$ bidirectional bridges connecting them. The islands are numbered $$$1, 2, \ldots, n$$$. The $$$i$$$-th bridge connects islands $$$u_i$$$ and $$$v_i$$$, and it takes $$$t_i$$$ minutes to cross. Furthermore, each bridge has a height $$$h_i$$$, representing its height above sea level in centimeters.

An unprecedented natural disaster has struck the archipelago, causing the sea level to rise at a rate of $$$1$$$ centimeter per minute. A bridge $$$i$$$ becomes unusable exactly $$$h_i$$$ minutes after the disaster begins. To ensure safety, a vehicle can only cross bridge $$$i$$$ if the entire traversal completes before the bridge is submerged. Specifically, if a vehicle starts crossing bridge $$$i$$$ at time $$$T$$$, it must arrive at the other end by time $$$T + t_i$$$, and this arrival time must satisfy $$$T + t_i \le h_i$$$.

Island $$$1$$$ serves as the evacuation center. Residents on each island are intelligent; they will choose a route that allows them to reach island $$$1$$$ safely before any bridge they cross becomes submerged. If no such path exists, they will remain on their current island to await rescue.

Given this scenario, for each island $$$k$$$ (where $$$k \in \{1, \ldots, n\}$$$), determine if the residents on island $$$k$$$ can safely reach island $$$1$$$.

Input

The first line contains two integers $$$n$$$ and $$$m$$$, representing the number of islands and the number of bridges, respectively.

Followed by $$$m$$$ lines, the $$$i$$$-th of which contains four integers $$$u_i, v_i, t_i, h_i$$$, representing a bridge connecting islands $$$u_i$$$ and $$$v_i$$$ with travel time $$$t_i$$$ and height $$$h_i$$$.

  • $$$1\leq n\leq 10^5$$$
  • $$$1\leq m\leq 3\times 10^5$$$
  • $$$1\leq u_i, v_i \leq n, u_i\neq v_i$$$
  • $$$1\leq t_i \leq h_i \leq 10^9$$$
Output

Output a single string of length $$$n$$$. The $$$i$$$-th character of the string should be '1' if the residents of island $$$i$$$ can safely reach island $$$1$$$, and '0' otherwise.

Examples
Input
3 2
1 3 2 4
2 3 3 5
Output
101
Input
5 6
1 2 4 4
1 4 8 13
2 3 1 3
2 4 3 7
3 5 2 2
4 5 7 8
Output
11110
Note

Explanation for Sample 1

Residents of island $$$1$$$ are already at island $$$1$$$. Residents of island $$$3$$$ can safely cross the first bridge and arrive at island $$$1$$$ at time $$$2$$$. However, residents of island $$$2$$$ must first cross the second bridge to reach island $$$3$$$ at time $$$3$$$; if they then attempt to cross the first bridge, they will get stuck in the middle at time $$$4$$$, exactly when the bridge becomes unusable since $$$h_1=4$$$. Therefore, the residents of island $$$2$$$ cannot safely reach island $$$1$$$.

G. The Graduation Photo Lineup
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Class leader A-Ming is arranging the $$$n$$$ students of his class into a single row to take a graduation photo. The $$$n$$$ students all have distinct heights, and A-Ming holds a roster listing the real height of every student.

The students were already standing in some order. For fun, A-Ming handed each student a slip of paper and asked everyone to look to their right and compute one number: how many of the people standing behind them (i.e. to the right in the row) are shorter than they are? Everyone wrote down their number and handed the slip back. The slips were originally collected in left-to-right order of the row (the first slip belongs to the student standing first, and so on).

Then a sudden gust of wind scattered all the slips on the ground! A-Ming gathered them back up, but their order was completely lost, leaving only an unordered collection of numbers $$$s_1, s_2, \ldots, s_n$$$.

The photographer is about to arrive and everyone has run off to play. A-Ming is left holding only the height roster and the shuffled pile of slips.

Help A-Ming decide: is it possible to reconstruct at least one valid standing order consistent with the numbers on the slips? If so, to make the picture look as harmonious as possible, output the lexicographically smallest height arrangement among all valid orders (placing shorter students as far toward the front as possible). If the numbers cannot fit together at all, output -1.

Input

The first line contains a single integer $$$n$$$, representing the number of students.

The second line contains $$$n$$$ distinct integers $$$h_1, h_2, \ldots, h_n$$$, representing the real heights of the students.

The third line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$, representing the shuffled collection of numbers written on the slips.

  • $$$1 \leq n \leq 2 \times 10^5$$$
  • $$$1 \leq h_i \leq 10^9$$$, and all $$$h_i$$$ are distinct.
  • $$$0 \leq s_i \lt n$$$
Output

If a valid standing order exists, output a single line of $$$n$$$ integers: the lexicographically smallest valid sequence of heights, separated by single spaces.

If no valid standing order exists, output a single line containing -1.

Examples
Input
3
10 20 30
1 0 0
Output
10 30 20
Input
2
170 165
1 1
Output
-1
Input
4
150 160 170 180
0 2 0 0
Output
150 180 160 170
Note

Explanation for Sample 1

The slips form the multiset $$$\{0, 0, 1\}$$$. Two standing orders are consistent with it: heights $$$[10, 30, 20]$$$ (slip values $$$0, 1, 0$$$) and $$$[20, 10, 30]$$$ (slip values $$$1, 0, 0$$$). The first is lexicographically smaller, so the answer is $$$10\ 30\ 20$$$.

Explanation for Sample 2

With two students, the person standing last has nobody to their right, so one slip must read $$$0$$$. Both slips read $$$1$$$, which is impossible, so the answer is $$$-1$$$.

H. Fridgeberg's Challenge
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Fridgeberg is a well-known veteran in the Taiwanese ICPC community. He specializes in counting problems. Since he solves counting problems faster than everyone else, people call him a speed-counter. Today, he has prepared a challenge for you along with the following message.

"Yo, I'm Fridgeberg, and I'm an 18-year-old ICPC speed-counter from Yunlin, Taiwan. Today, I'm challenging you to a counting problem."

The challenge is as follows.

A rooted labelled tree with $$$n$$$ vertices is a tree with vertices labelled $$$1,2,\ldots,n$$$ and one vertex chosen as the root.

Recall that for any two vertices in a tree, there is a unique simple path connecting them. For each vertex $$$v$$$ in a rooted labelled tree, define its subtree as the set of all vertices $$$u$$$ such that $$$v$$$ is on the unique path from the root to $$$u$$$. In particular, a vertex is always in its own subtree. The subtrees of a tree are the collection of all vertices' subtrees.

A rooted labelled tree is $$$k$$$-free if none of its subtrees has exactly $$$k$$$ vertices.

For each $$$k$$$ from $$$2$$$ to $$$n-1$$$, compute the number of different rooted labelled trees with $$$n$$$ vertices that are $$$k$$$-free. Since the numbers can be very large, please compute them modulo $$$998244353$$$.

Two rooted labelled trees are different if at least one of the following holds:

  • The labels of the roots are different.
  • There exists an edge that is present in one tree but not in the other.
Input

The only line contains a single integer $$$n$$$.

  • $$$3\le n\le 2\times 10^5$$$
Output

Output $$$n-2$$$ lines. On the $$$i$$$-th line, output the answer when $$$k=i+1$$$.

Examples
Input
3
Output
3
Input
4
Output
16
28
Input
11
Output
23790225
701354623
477759311
29734262
735403659
26527433
622702793
495236333
962003659
Note

Explanation for Sample 1

There are exactly $$$3$$$ rooted labelled trees that have no subtree with exactly $$$2$$$ vertices.

The following picture illustrates those $$$3$$$ trees. (The root vertices are colored pink, and the other vertices are colored light blue.)

I. Marks
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

There is a circular track with $$$b$$$ equally spaced positions, numbered $$$0, 1, \dots, b-1$$$ clockwise. Adjacent positions are $$$1$$$ unit apart, so the whole circle measures $$$b$$$ units.

A marker starts at position $$$0$$$ and, at every step, advances by a fixed $$$a$$$ positions clockwise (wrapping back to $$$0$$$ after position $$$b-1$$$). It successively stops at $$$$$$p_k = (a \cdot k) \bmod b, \qquad k = 0, 1, \dots, n-1,$$$$$$ leaving a mark at each stop, for a total of $$$n$$$ marks. It is guaranteed that $$$\gcd(a, b) = 1$$$$$$^{\text{∗}}$$$ and $$$n \leq b$$$, so these $$$n$$$ marks are pairwise distinct.

These $$$n$$$ marks divide the circle into $$$n$$$ arcs. The length of an arc is the number of units it spans (every arc length is a positive integer, and the lengths sum to $$$b$$$).

How many distinct arc-length values are there? For each value, what is it, and how many times does it occur?

$$$^{\text{∗}}$$$$$$\gcd(a, b) = c$$$ means that $$$c$$$ is the largest positive integer such that $$$c$$$ divides both $$$a$$$ and $$$b$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$. The description of the test cases follows.

The only line of each test case contains three integers $$$a$$$, $$$b$$$, and $$$n$$$, representing the parameters of this test case.

  • $$$1 \leq t \leq 30$$$
  • $$$1 \leq a \lt b \leq 10^{18}$$$
  • $$$\gcd(a, b) = 1$$$
  • $$$2 \leq n \leq b$$$
Output

For each test case, first output the number of distinct arc-length values, $$$d$$$.

Followed by $$$d$$$ lines, output $$$2$$$ integers $$$s$$$ and $$$c$$$ for each of which, representing that exactly $$$c$$$ arcs have length $$$s$$$.

For each test case, output these lines in increasing order of $$$s$$$.

Example
Input
1
7 12 7
Output
2
1 2
2 5
Note

Explanation for Sample 1

The marks are $$$\{0, 7, 2, 9, 4, 11, 6\}$$$, which, when sorted, are $$$0, 2, 4, 6, 7, 9, 11$$$. The consecutive arc lengths are $$$2, 2, 2, 1, 2, 2, 1$$$, so length $$$1$$$ occurs $$$2$$$ times and length $$$2$$$ occurs $$$5$$$ times.

J. Crystal Combination
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Elaina, a magic teacher, has prepared an exam with $$$t$$$ questions. In each question, given a target magic power $$$x$$$, a student must combine exactly two magic crystals with powers $$$2^{a}$$$ and $$$2^{b}$$$ for some non-negative integers $$$a$$$ and $$$b$$$ (possibly $$$a = b$$$), and report the minimum possible difference between the combined power and $$$x$$$, that is, $$$\left|2^{a} + 2^{b} - x\right|$$$. Please help the students finish the exam.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$. The description of the test cases follows.

The only line of each test case contains one integer $$$x$$$, representing the target magic power.

  • $$$1 \leq t \leq 10^4$$$
  • $$$1 \leq x \leq 10^{18}$$$
Output

For each test case, output one integer: the minimum possible difference between the combined power and $$$x$$$, that is, $$$\left|2^{a} + 2^{b} - x\right|$$$.

Example
Input
3
7
10
1
Output
1
0
1

K. Subwords
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You have a grammar with the start symbol $$$S$$$, a set of variables $$$V$$$, a set of terminal symbols $$$T$$$, and a set of rules $$$P$$$. Every upper-case letter is a variable, so $$$V=\{A,\dots,Z\}$$$, and every lower-case letter is a terminal symbol, so $$$T=\{a,\dots,z\}$$$. A rule is of the form $$$A\to \alpha$$$, where $$$A\in V$$$ is a variable and $$$\alpha$$$ is a string consisting of variables and terminal symbols. The grammar never contains chain rules of the form $$$A\to B$$$, where the right side consists of a single variable. Rules of the form $$$A\to b$$$ are possible, where the right side consists of a single terminal.

A word can be derived by starting with $$$\alpha=S$$$ and then repeatedly choosing some variable $$$X$$$ in $$$\alpha$$$, some rule $$$X\to\beta$$$, and then replacing one $$$X$$$ in $$$\alpha$$$ with $$$\beta$$$. To be precise, if $$$\alpha=\alpha'X\alpha"$$$ and we have a rule $$$X\to\beta$$$, then we can replace $$$\alpha$$$ with $$$\alpha'\beta\alpha"$$$, and we write $$$\alpha\Rightarrow \alpha'\beta\alpha"$$$.

Here is a complete example. The grammar has the rules $$$$$$ S\to SA,\ \ \ S\to b,\ \ \ A\to bS,\ \ \ A\to a. $$$$$$ Then we can derive the word $$$bbb$$$ in four steps: $$$$$$ S\Rightarrow SA\Rightarrow bA\Rightarrow bbS\Rightarrow bbb. $$$$$$

On the other hand, the word $$$aaa$$$ cannot be derived.

Your task is to answer the following question for a grammar $$$G$$$ and a word $$$w$$$ (consisting of terminal symbols):

  • Can you add zero or more terminal symbols at the beginning of $$$w$$$ and zero or more terminal symbols at the end of $$$w$$$ such that the resulting word $$$uwv$$$ can be derived by $$$G$$$?
Input

The first line contains an integer $$$k$$$, representing the number of rules.

Followed by $$$k$$$ lines, each of which contains one rule. A rule is encoded by its left side, followed by ->, and then followed by its right side.

The last line contains the word $$$w$$$, representing the input word of the question.

  • $$$1\leq k\leq 25$$$
  • The left side of every rule is an upper-case letter.
  • The right side of every rule is a string of upper-case and lower-case letters. Moreover, it is either a string of length at least $$$2$$$ or a single lower-case letter.
  • The total length of the right sides of all rules is at most $$$100$$$.
  • The length of $$$w$$$ is at least $$$1$$$ and at most $$$400$$$, and $$$w$$$ consists of lower-case letters.
Output

Output a single line containing Yes or No that answers the question.

Examples
Input
4
S -> SA
S -> b
A -> bS
A -> a
bbb
Output
Yes
Input
2
S -> aSb
S -> ab
ba
Output
No
Input
2
S -> aSa
S -> b
ab
Output
Yes

L. Park of Three
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

The Park of Three is a famous landmark in the Kingdom of Three. It contains $$$n$$$ magical pillars connected by $$$m$$$ magical connections. The pillars are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th connection links pillar $$$u_i$$$ and pillar $$$v_i$$$, and all connections are bidirectional.

Believing that the number three holds protective power against evil forces, the park's architects ensured that every pillar is incident to exactly three connections. Note that a connection may link a pillar to itself. In such cases, the self-loop counts twice toward the number of pillar's incident connections.

Triangles formed by the pillars are the source of their protective power. Historically, these triangles successfully repelled evil forces hundreds of years ago. To assess the network's true resilience, you must determine its structural vulnerability.

Formally, three distinct pillars $$$i, j, k$$$ form a triangle if the connections $$$(i, j)$$$, $$$(j, k)$$$, and $$$(k, i)$$$ all exist. When a pillar is destroyed, all connections incident to it are removed. The strength of the park is defined as the minimum number $$$s$$$ such that destroying $$$s$$$ specific pillars eliminates all triangles. Please determine the strength $$$s$$$ and output the indices of $$$s$$$ pillars such that there will be no triangles after destroying them.

Input

The first line contains an integer $$$n$$$, representing the number of magical pillars in the park.

Followed by $$$m = \frac{3n}{2}$$$ lines, the $$$i$$$-th of which contains two integers $$$u_i$$$ and $$$v_i$$$, representing the endpoints of the $$$i$$$-th magical connection.

  • $$$4 \leq n \leq 2 \times 10^5$$$, and $$$n$$$ is even.
  • $$$1 \leq u_i, v_i \leq n$$$ for all $$$1 \leq i \leq m$$$.
  • The network of magical connections may contain self-loops and multiple connections between the same pair of pillars.
  • Each pillar is incident to exactly $$$3$$$ connections, where each self-loop is counted twice toward this total.
Output

On the first line, output the integer $$$s$$$.

On the second line, output $$$s$$$ distinct integers representing the indices of the pillars to be destroyed. After removing these pillars and all incident connections, no triangles should remain.

If multiple solutions exist, output any of them. The indices may be printed in any order.

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

Explanation for Sample 1

The network of connections is shown in the figure below. There are $$$4$$$ triangles formed by the pillars: $$$(1, 2, 3)$$$, $$$(1, 2, 4)$$$, $$$(1, 3, 4)$$$, and $$$(2, 3, 4)$$$. After destroying pillars $$$1$$$ and $$$2$$$, no triangle remains in the network. Any subset of $$$\{1, 2, 3, 4\}$$$ of size 2 is also a valid solution.