2024 China Collegiate Programming Contest (CCPC) Female Onsite (2024年中国大学生程序设计竞赛女生专场)
A. Box
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Little A has a rectangular box with a height of $$$h$$$. He places this box on a table and establishes a three-dimensional Cartesian coordinate system $$$O-xyz$$$, where the table is located at $$$z=z_0$$$.

Due to Little A's obsessive-compulsive disorder, he places the length and width of the box parallel to the $$$x$$$ and $$$y$$$ axes (the length does not necessarily correspond to the $$$x$$$ axis), and the bottom face has a pair of diagonal vertices located at $$$(u_0,v_0,z_0)$$$ and $$$(u_1,v_1,z_0)$$$.

Now Little A has $$$q$$$ queries. For each query, he provides a point $$$(x_i,y_i,z_i)$$$ and wants to know if the point is inside the box (the boundary is also considered inside).

Input

The first line contains six integers $$$z_0,h,u_0,v_0,u_1,v_1$$$ ($$$0\leq z_0,h\leq 10^6$$$, $$$-10^6\leq u_0,v_0,u_1,v_1\leq 10^6$$$).

The second line contains an integer $$$q$$$ ($$$1\leq q\leq 10^3$$$) indicating the number of queries.

The next $$$q$$$ lines each contain three integers $$$x_i,y_i,z_i$$$ ($$$-10^6\leq x_i,y_i,z_i\leq 10^6$$$) representing the $$$i$$$-th query.

Output

Output $$$q$$$ lines. In the $$$i$$$-th line, output a string YES or NO. YES indicates that the queried point is inside the box, while NO indicates that it is not inside the box. The case does not matter, meaning you can output YES, Yes, YeS, yEs and NO, No, nO, etc.

Example
Input
1 1 -1 -1 1 1
3
-1 -1 1
0 0 2
1 2 2
Output
YES
YES
NO

B. Aho-Corasick Automaton
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Little A has many strings, each with a character set of $$$\{1,2,\cdots,m\}$$$. He constructed a Trie for these strings and built an Aho-Corasick automaton from this Trie.

However, due to Little A's negligence, both the original strings and the constructed Aho-Corasick automaton have disappeared. Little A only remembers that the lengths of all original strings do not exceed $$$d$$$, and that the constructed Aho-Corasick automaton has $$$n$$$ vertices and a character set of $$$\{1,2,\cdots,m\}$$$.

Now, Little A wants to know how many different Aho-Corasick automatons could possibly be the one he constructed. Since the answer can be large, you only need to find the result modulo $$$998244353$$$.

The Aho-Corasick automaton is defined as follows:

  1. A Trie $$$T$$$ is a rooted tree without labels, where each edge is labeled with a character. A vertex $$$x$$$ in the Trie cannot have two child vertices $$$y$$$ and $$$z$$$ such that the edges $$$(x, y)$$$ and $$$(x, z)$$$ are labeled with the same character.
  2. Given a Trie $$$T$$$ with root $$$r$$$, for a vertex $$$x$$$, the string represented by $$$x$$$ is the concatenation of the characters on the edges from $$$r$$$ to $$$x$$$. In particular, the string represented by $$$r$$$ is the empty string. It can be proven that no two different vertices represent the same string.
  3. We say that a string $$$S$$$ exists in Trie $$$T$$$ if and only if there exists a vertex $$$x$$$ such that the string represented by $$$x$$$ is $$$S$$$.
  4. Constructing a Trie $$$T$$$ for some strings $$$S_1,S_2,\cdots,S_k$$$ means finding a Trie $$$T$$$ with the minimum number of vertices such that all strings $$$S_i$$$ exist in Trie $$$T$$$. It can be proven that such a Trie is unique when unlabeled.
  5. The fail tree $$$F$$$ of Trie $$$T$$$ is a tree with root $$$r$$$. Define $$$S_x$$$ as the string represented by vertex $$$x$$$. For a non-root vertex $$$x$$$, let $$$U$$$ be the longest proper suffix of $$$S_x$$$ (a proper suffix is one that is not equal to $$$S_x$$$) such that $$$U$$$ exists in $$$T$$$. Then, $$$fail_x$$$ is defined as the vertex such that $$$S_{fail_x} = U$$$. Note that the empty suffix of $$$S_x$$$ always exists in $$$T$$$, so $$$fail_x$$$ always exists. The edge set of $$$F$$$ is $$$\{(x, fail_x) | x \in [1, n], x \neq r\}$$$. It can be proven that these edges form a tree.
  6. Merging Trie $$$T$$$ and its fail tree $$$F$$$ means that the vertex set remains unchanged (the vertex sets of $$$T$$$ and $$$F$$$ are the same), and the edges and the characters on the edges are merged to obtain the graph, which is the Aho-Corasick automaton $$$A$$$ of Trie $$$T$$$. At this point, $$$A$$$ contains both edges labeled with characters and edges without labels.

Two Aho-Corasick automatons are considered the same if and only if they have the same number of vertices and there exist two labeling schemes for the vertices (let's assume they are two permutations of length equal to the number of vertices) such that:

  1. The roots of the two Aho-Corasick automatons are the same.
  2. For any pair of vertices $$$x,y$$$, either there is no edge between $$$x$$$ and $$$y$$$ in both Aho-Corasick automatons, or there is an edge in both and the characters on the edges are the same, or both edges do not have labels.
Input

A single line containing three integers $$$n,m,d$$$ ($$$1\leq n,m,d\leq 100$$$), representing the number of vertices in the Aho-Corasick automaton, the size of the character set, and the upper limit on the lengths of all strings.

Output

A single line containing an integer representing the answer.

Example
Input
3 2 2
Output
5

C. CCPC
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Given a string $$$S$$$ composed of uppercase letters, please rearrange the order of the characters in $$$S$$$ such that the substring CCPC appears as many times as possible as a contiguous substring. You are to determine the maximum possible number of occurrences of CCPC.

Input

A single line containing a string $$$S$$$ composed of uppercase letters $$$(1 \leq |S| \leq 10^6)$$$.

Output

Output a single integer, representing the maximum possible number of occurrences of CCPC.

Example
Input
ABCDCPCPC
Output
1

D. Excellent Splitting
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Little H has a permutation $$$P$$$, and he wants to split $$$P$$$ into sequence $$$A$$$ and sequence $$$B$$$.

Specifically, Little H will take several elements from $$$P$$$ in order and place them into sequence $$$A$$$, while the remaining elements will form another sequence $$$B$$$ in order.

For example, if $$$P = [1,2,3,4,5]$$$, he can split $$$P$$$ into $$$A = [1,3,5], B = [2,4]$$$.

He is very fond of increasing subsequences and decreasing subsequences. Define $$$f(A)$$$ as the length of the longest increasing subsequence of $$$A$$$, and $$$g(B)$$$ as the length of the longest decreasing subsequence of $$$B$$$. You need to tell him the maximum value of $$$f(A) + g(B)$$$.

Input

The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 2\cdot 10^5)$$$, indicating the number of test cases.

For each test case, the first line contains an integer $$$n$$$ $$$(1 \leq n \leq 2 \times 10^5)$$$, representing the length of the permutation $$$P$$$.

The second line contains $$$n$$$ integers $$$P_1,P_2,\ldots ,P_n$$$ $$$(1\leq P_i \leq n)$$$, ensuring that $$$P_i$$$ is a permutation.

The sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.

Output

For each test case, output a single line containing an integer, representing the maximum value of $$$f(A) + g(B)$$$.

Example
Input
3
5
3 5 1 4 2
4
1 2 4 3
5
3 5 2 1 4
Output
4
4
5

E. Centroid Tree
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Given a rooted tree with $$$n$$$ nodes, rooted at $$$1$$$, which satisfies the property $$$p_i \lt i$$$, where $$$p_i$$$ is the parent node of $$$i$$$.

For each node $$$u$$$, for all its children $$$v$$$, we will provide the index of the centroid of the new tree formed by only considering $$$v$$$ and the nodes in the subtree of $$$v$$$, noting that we will not give you the index of $$$v$$$. If a tree has two centroids, we will tell you the one that is deeper in the original tree. Your task is to construct a tree that satisfies the above conditions.

The centroid of a tree: If a certain node is chosen and removed from the tree, the tree will be divided into several subtrees. The number of nodes in each subtree is counted, and the maximum value is recorded. The node for which this maximum value is minimized when considering all nodes in the tree is called the centroid of the entire tree.

Input

The first line contains an integer $$$T$$$ $$$(1 \leq T \leq 10^5)$$$, representing the number of test cases.

For each test case, the first line contains an integer $$$n$$$ $$$(2\leq n \leq 2\cdot 10^5)$$$, representing the number of nodes in the tree.

The next $$$n$$$ lines provide first an integer $$$c_i$$$ $$$(1\leq c_i\leq n)$$$, representing the number of children of node $$$i$$$, followed by $$$c_i$$$ integers $$$p_{i,j}$$$ $$$(1\leq p_{i,j}\leq n)$$$, representing the index of the centroid of the tree formed by the $$$j$$$-th child of $$$i$$$ and the nodes in its subtree.

The sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.

Output

For each test case, output $$$n-1$$$ lines. The $$$i$$$-th line should output two integers $$$u,v$$$ $$$(1\leq u,v \leq n, u\neq v)$$$, representing an edge $$$(u,v)$$$ in the tree.

The test data guarantees a solution. If there are multiple valid solutions, any one of them is acceptable.

Example
Input
2
4
2 3 4
1 3
0
0
3
1 3
1 3
0
Output
2 3
1 2
1 4
2 3
1 2

F. Perfect Square
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Little A has a sequence of positive integers of length $$$n$$$, denoted as $$$a_1, a_2, \cdots, a_n$$$. He wishes to create another sequence of positive integers of length $$$n$$$, denoted as $$$d_1, d_2, \cdots, d_n$$$, such that $$$d_i$$$ is a divisor of $$$a_i$$$.

It is evident that $$$d_1, d_2, \cdots, d_n$$$ are not unique, so Little A hopes that the product of $$$d_1, d_2, \cdots, d_n$$$ is a perfect square $$$x = y^2$$$, where $$$y$$$ is a positive integer.

However, at this point, $$$d_1, d_2, \cdots, d_n$$$ are still not unique. Therefore, Little A wants to know the sum of $$$y$$$, the square root of the product for all possible combinations of $$$d_1, d_2, \cdots, d_n$$$ that yield a perfect square $$$x = y^2$$$, modulo $$$10^9 + 7$$$.

Input

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$) representing the length of the positive integer sequence.

The second line contains $$$n$$$ integers $$$a_1, a_2, \cdots, a_n$$$ ($$$1 \leq a_i \leq 10^6$$$), representing the positive integer sequence.

Output

Output a single line containing an integer representing the answer.

Example
Input
2
4 4
Output
11
Note

Possible cases include $$$1 \times 1 = 1, 1 \times 2 = 2, 1 \times 4 = 4, 2 \times 1 = 2, 2 \times 2 = 4, 2 \times 4 = 8, 4 \times 1 = 4, 4 \times 2 = 8, 4 \times 4 = 16$$$.

Among these, the products that are perfect squares are $$$1 \times 1 = 1, 1 \times 4 = 4, 2 \times 2 = 4, 4 \times 1 = 4, 4 \times 4 = 16$$$.

The answer is equal to $$$\sqrt{1} + \sqrt{4} + \sqrt{4} + \sqrt{4} + \sqrt{16} = 1 + 2 + 2 + 2 + 4 = 11$$$.

G. Increasing Sequence
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Given a non-negative integer sequence $$$a$$$ of length $$$n$$$ and a constant value $$$k$$$.

Determine how many integers $$$x$$$ satisfy $$$x \in [0,k]$$$, such that $$$a_1 \oplus x, a_2 \oplus x, \ldots, a_n \oplus x$$$ forms a non-decreasing sequence.

Here, $$$\oplus$$$ denotes the XOR operation.

Input

The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 2\cdot 10^5)$$$, indicating the number of test cases.

For each test case, the first line contains two integers $$$n,k$$$ $$$(1 \leq n \leq 2\cdot 10^5, 0 \leq k \leq 10^{18})$$$.

The second line contains $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0 \leq a_i \leq 10^{18})$$$.

The sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.

Output

For each test case, output a single line containing an integer representing the count of integers $$$x$$$ that satisfy the conditions.

Example
Input
1
4 17
3 2 5 16
Output
4

H. Square Root
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Little A has a string that only contains the characters 0 and 1 (hereafter referred to as a 01 string). He likes 1 and dislikes 0, so in Little A's eyes, there are only 1s in a 01 string.

Specifically, for a 01 string, Little A sees 0 as a separator that divides the string into several substrings consisting entirely of 1s. For example, for a 01 string 010011101111101, Little A sees four substrings that consist only of 1s: 1, 111, 11111, and 1.

For a 01 string, Little A defines its charm value as the sum of the square roots of the lengths of the separated substrings that consist entirely of 1s. For example, for the string 010011101111101, Little A's charm value is $$$\sqrt{1}+\sqrt{3}+\sqrt{5}+\sqrt{1}=2+\sqrt{3}+\sqrt{5}$$$.

Now, given a 01 string $$$s$$$, Little A hopes you can change some of the 1s in $$$s$$$ to 0s (or leave them unchanged) to maximize the charm value of this 01 string.

Input

A single line containing a string $$$s$$$ that consists only of the characters 0 and 1 ($$$1\leq |s|\leq 10^6$$$).

Output

A single line containing a floating-point number that represents the maximum charm value that can be obtained after the changes. Your answer is considered correct if the relative or absolute error compared to the standard answer does not exceed $$$10^{-9}$$$.

Assuming your answer is $$$a$$$ and the standard answer is $$$b$$$, it is considered correct if $$$\frac{|a-b|}{\max\{b,1\}}\leq 10^{-9}$$$.

Example
Input
1100110111
Output
4.8284271247
Note

Changing the 9th 1 to 0 will yield the maximum charm value of $$$2+2\sqrt{2}$$$.

I. String Duplication
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Little H initially has a string $$$s$$$ composed of lowercase letters.

The charm value of a string is defined as the number of essentially different substrings.

For example, $$$\texttt{aaa}$$$ has only $$$3$$$ essentially different substrings: $$$\texttt{a}, \texttt{aa}, \texttt{aaa}$$$, while $$$\texttt{aabb}$$$ has $$$8$$$ essentially different substrings: $$$\texttt{a}, \texttt{aa}, \texttt{b}, \texttt{bb}, \texttt{ab}, \texttt{aab}, \texttt{abb}, \texttt{aabb}$$$.

He thinks the charm value of the initial string $$$s$$$ is too low, so he duplicates $$$s$$$ $$$m$$$ times and concatenates them together, trying to obtain a string with a higher charm value.

However, after he finished duplicating, he found that he could not accurately calculate its charm value. Please help him calculate the charm value of the duplicated string. Since the answer may be large, you need to output the charm value modulo $$$998244353$$$.

Input

The first line contains two integers $$$n,m$$$ $$$(1 \leq n \leq 3 \times 10^5, 1 \leq m \leq 10^9)$$$, representing the length of the string $$$s$$$ and the number of duplications.

The second line contains a string $$$s$$$ composed of lowercase letters.

Output

Output a single integer, representing the result of the charm value modulo $$$998244353$$$.

Examples
Input
6 2
mantle
Output
57
Input
12 1919810
ifamjlifamjl
Output
138226305
Input
13 935330878
aabbbbababbaa
Output
348310505

J. Sum of Squares of GCDs
time limit per test
4 s
memory limit per test
1024 MB
input
standard input
output
standard output

Little H has two permutations $$$a$$$ and $$$b$$$, both of length $$$n$$$.

There are $$$q$$$ queries, and for each query, he will give you an interval $$$[l,r]$$$ for $$$a$$$ and an interval $$$[L, R]$$$ for $$$b$$$. He wants to know the value of $$$\sum\limits_{i=l}^r \sum\limits_{j=L}^R \gcd^2(a_i,b_j)$$$, but you only need to provide the result modulo $$$2^{32}$$$.

Input

The first line contains a number $$$n$$$ $$$(1\leq n \leq 10^5)$$$, representing the length of $$$a$$$ and $$$b$$$.

The next line contains $$$n$$$ integers, representing the permutation $$$a$$$ $$$(1 \leq a_i \leq n)$$$, ensuring that $$$a_i \neq a_j$$$ for $$$i \neq j$$$.

The following line contains $$$n$$$ integers, representing the permutation $$$b$$$ $$$(1 \leq b_i \leq n)$$$, ensuring that $$$b_i \neq b_j$$$ for $$$i \neq j$$$.

The next line contains a number $$$q$$$ $$$(1\leq q \leq 10^5)$$$, representing the number of queries.

The next $$$q$$$ lines each contain four numbers $$$l,r,L,R$$$ $$$(1 \leq l \leq r \leq n, 1 \leq L \leq R \leq n)$$$, representing the intervals for the $$$i$$$-th query.

Output

Output $$$q$$$ lines, where the $$$i$$$-th line outputs an integer representing the answer to the $$$i$$$-th query.

Example
Input
5
4 1 5 3 2
1 2 3 4 5
5
3 3 2 3
3 4 2 4
3 4 3 4
5 5 1 1
1 1 2 2
Output
2
14
12
1
4

K. Xiao Kai's Dream of Provincial Scholarship
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

In the legendary magical land, there is a mysterious school. Xiao Kai is a student at this school, and recently his class is evaluating for the Excellent Student Scholarship and the Provincial Government Scholarship.

First, for each class, the allocation of Excellent Student Scholarship slots is as follows: Suppose a class has $$$n$$$ students, then at most $$$\lfloor{0.15n}\rfloor$$$ students will receive the first prize scholarship, at most $$$\lfloor{0.25n}\rfloor$$$ students will receive the second prize scholarship, and at most $$$\lfloor{0.35n}\rfloor$$$ students will receive the third prize scholarship. (For example, in a class of 21 students, 3 students will receive the first prize scholarship, 5 students will receive the second prize scholarship, and 7 students will receive the third prize scholarship.)

Each student will have scores in three areas: academic performance, moral education, and physical education, with scores being integers in the range $$$[0,100]$$$. The comprehensive score is the sum of the three scores. When evaluating scholarships, students will first be sorted in descending order by their comprehensive scores. If two students have the same comprehensive score, they will be sorted by their academic performance scores in descending order. If both comprehensive and academic scores are the same, they will be sorted by their names in ascending lexicographical order. The resulting ranking is referred to as the comprehensive ranking. The college will determine the order of scholarship applications based on the comprehensive ranking.

In addition, there is a rule that restricts the level of scholarship that students can apply for: students receiving the first prize scholarship must ensure that their academic performance score is in the top $$$25\%$$$ of the class, students receiving the second prize scholarship must ensure that their academic performance score is in the top $$$45\%$$$, and students receiving the third prize scholarship must ensure that their academic performance score is in the top $$$75\%$$$. (For example, in a class of 21 students, only the top 5 students in academic performance are eligible to receive the first prize scholarship, the top 9 students are eligible for the second prize scholarship, and the top 15 students are eligible for the third prize scholarship. Specially, if two students are tied for fifth place in academic performance, both are eligible to receive the first prize scholarship.)

After the Excellent Student Scholarships for the two semesters are awarded, the college will also evaluate the Provincial Government Scholarship. The college stipulates that there are only $$$m$$$ slots for the Provincial Government Scholarship in Xiao Kai's class. The evaluation method is to first sort by award points (where one first prize scholarship counts as 15 points, one second prize scholarship counts as 10 points, and one third prize scholarship counts as 5 points; for example, if student X receives one first prize scholarship and one second prize scholarship, their award points will be 25 points), then if the award points are the same, sort by the total comprehensive score in descending order, if the total comprehensive scores are the same, sort by the total academic performance score from both semesters in descending order, and if both total comprehensive scores and total academic performance scores are the same, sort by names in ascending lexicographical order.

Unfortunately, Xiao Kai was unable to win the Provincial Government Scholarship, which made him feel down. That night, he had a dream where he met an immortal sitting on a gourd, who could help him fulfill his wish of winning the Provincial Government Scholarship in his dream. The immortal can sell Xiao Kai several cups of drinks, where the first type of drink costs $$$p$$$ gold coins and can increase Xiao Kai's academic performance score in the first semester by 1 point, and the second type of drink costs $$$q$$$ gold coins and can increase Xiao Kai's academic performance score in the second semester by 1 point. (Note that each semester's academic performance score has a maximum limit of 100 points.)

Given that Xiao Kai's name is registered as crazyzhk, he now tells you all the scores of his class for the two semesters, and he wants to ask you how many gold coins he needs at a minimum to drink the purchased beverages and be able to win the Provincial Government Scholarship. If Xiao Kai cannot win the Provincial Government Scholarship no matter what, please output "Surely next time" (without quotes) to encourage him.

What is lexicographical order:

In simple terms, lexicographical order means "the order in which words appear in a dictionary." More accurately, the algorithm to determine the order of two different strings $$$S$$$ and $$$T$$$ composed of lowercase letters is as follows:

Let the $$$i$$$-th character of $$$S$$$ be denoted as $$$S_i$$$.

Define that if $$$S$$$ is lexicographically less than $$$T$$$, we consider $$$S \lt T$$$, and if $$$S$$$ is lexicographically greater than $$$T$$$, we consider $$$S \gt T$$$.

  • Let $$$L$$$ be the length of the shorter string between $$$S$$$ and $$$T$$$. We check $$$S_i$$$ and $$$T_i$$$ for $$$i=1,2,\cdots,L$$$ in order.
  • If there exists an $$$i$$$ such that $$$S_i \neq T_i$$$, let $$$j$$$ be the smallest $$$i$$$ that satisfies this condition. Compare $$$S_j$$$ and $$$T_j$$$. If $$$S_j$$$ is lexicographically less than $$$T_j$$$, then $$$S \lt T$$$. Otherwise, $$$S \gt T$$$. The algorithm ends here.
  • If there is no $$$i$$$ such that $$$S_i \neq T_i$$$, then we compare the lengths of $$$S$$$ and $$$T$$$. If the length of $$$S$$$ is less than that of $$$T$$$, then $$$S \lt T$$$. If the length of $$$S$$$ is greater than that of $$$T$$$, then $$$S \gt T$$$. If the lengths of $$$S$$$ and $$$T$$$ are equal, then $$$S=T$$$. The algorithm ends here.
Input

The first line contains an integer $$$n$$$ $$$(6 \leq n \leq 500)$$$, representing the number of students in Xiao Kai's class.

The next $$$n$$$ lines each consist of a string $$$name_i$$$ (composed only of lowercase letters) and six integers $$$a_{i,1},a_{i,2},a_{i,3},b_{i,1},b_{i,2},b_{i,3}$$$ $$$(0\leq a_{i,j},b_{i,j} \leq 100)$$$, representing the name of the $$$i$$$-th student, their academic performance score, moral education score, physical education score in the first semester, and their academic performance score, moral education score, physical education score in the second semester. It is guaranteed that each person's name is unique, and Xiao Kai's name is crazyzhk.

The next line contains three integers $$$m,p,q$$$ $$$(0 \le m \leq n,0 \leq p,q \leq 100)$$$, representing the number of slots for the Provincial Government Scholarship in Xiao Kai's class, the price of the first type of drink, and the price of the second type of drink.

Output

Output a single integer representing the minimum number of gold coins Xiao Kai needs. If Xiao Kai cannot win the Provincial Government Scholarship under any circumstances, output the string "Surely next time" (without quotes).

Examples
Input
8
easycxk 94 12 77 74 70 55
hardzhk 80 80 95 96 20 60
crazyzhk 40 49 36 50 50 74
mike 50 98 93 36 90 23
amy 50 81 59 53 100 50
tom 50 71 69 53 90 60
john 65 73 41 60 34 69
jyy 12 26 29 29 53 50
2 44 14
Output
1494
Input
7
a 30 61 27 94 20 70
b 64 57 68 8 43 34
c 97 66 94 33 79 42
crazyzhk 59 6 29 55 43 53
e 65 78 61 71 31 2
f 62 25 95 60 52 44
g 60 90 30 62 42 54
2 72 22
Output
858
Input
8
amy 94 12 77 100 70 55
hardzhk 90 80 95 96 20 60
john 90 39 16 70 50 74
mike 100 98 93 90 90 23
easycxk 70 81 59 73 100 50
ydzlhzs 100 85 89 100 90 60
crazyzhk 65 13 11 60 14 19
jyy 92 26 29 69 53 80
2 44 14
Output
Surely next time
Note

In the first test case, the optimal solution is to buy 26 cups of the first type of drink and 25 cups of the second type of drink. After drinking, Xiao Kai's academic performance score in the first semester becomes 66 points, and in the second semester, it becomes 75 points.

The comprehensive ranking and scholarship situation for the first semester is as follows:

Comprehensive RankingNameAcademic ScoreMoral ScorePhysical ScoreComprehensive ScoreScholarship LevelAcademic Ranking
1hardzhk80809525512
2mike50989324135
3amy50815919035
4tom5071691905
5easycxk94127718321
6john6573411794
7crazyzhk66493615123
8jyy122629678

The comprehensive ranking and scholarship situation for the second semester is as follows:

Comprehensive RankingNameAcademic ScoreMoral ScorePhysical ScoreComprehensive ScoreScholarship LevelAcademic Ranking
1amy531005020335
2tom53906020335
3crazyzhk75507419912
4easycxk74705519923
5hardzhk96206017621
6john6034691634
7mike3690231497
8jyy2953501328

The ranking for the Provincial Government Scholarship is as follows:

RankingNameAward PointsTotal Comprehensive ScoreTotal Academic Score
1hardzhk25431176
2crazyzhk25350141
3easycxk20382168
4amy10393103
5tom5393103
6mike539086
7john0342125
8jyy019941

L. Puzzle
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output
$$$2\times 2$$$ and $$$3\times 3$$$ rectangle examples, A, B, C, D represent four basic blocks

Little Y wants to play a type of puzzle that consists of four basic blocks, as shown in the image above. Little Y has $$$A, B, C, D$$$ of these four types of blocks. Now he wants to use as many blocks as possible to form a rectangle (either a rectangle or a square). The question is, what is the maximum number of blocks he can use?

The formed rectangle must satisfy the following conditions:

  1. Any two adjacent basic blocks must form a concave and convex structure;
  2. The four edges of the formed rectangle must not have any protrusions or indentations;
  3. Unlike common puzzle games, the blocks in this game do not have patterns, and blocks of the same type are considered identical.
Input

The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 10^4)$$$, indicating the number of test cases.

For each test case, each line contains four integers $$$A, B, C, D$$$ $$$(0 \leq A, B, C, D \leq 10^3)$$$, representing the number of four types of basic blocks.

Output

Output $$$n$$$ lines, each line containing an integer that indicates the maximum number of given blocks that can be used to form a rectangle. If it is not possible to form a rectangle, please output $$$0$$$.

Example
Input
2
4 0 0 0
4 4 4 4
Output
4
16

M. Covering a Tree
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Given a tree with $$$n$$$ nodes, you can use several line segments of arbitrary lengths to cover all the edges of the tree, with the following requirements:

  1. Each edge must be covered exactly once;
  2. Each line segment must start from a leaf node and end at one of its ancestor nodes.

You can choose any number of line segments such that these segments can cover the entire tree according to the above requirements, but you need to minimize the maximum length of the segments. Your task is to find this minimum value.

Input

The first line contains an integer $$$T$$$ $$$(1 \le T \le 10^5)$$$, representing the number of test cases.

For each test case, the first line contains an integer $$$n$$$ $$$(2 \le n \le 2\cdot 10^5)$$$, representing the total number of nodes in the tree.

The second line contains $$$n-1$$$ integers $$$p_2, p_3, \ldots , p_n$$$ $$$(1 \le p_i \lt i)$$$, where $$$p_i$$$ represents the index of the parent node of node $$$i$$$.

It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, output a single integer on a new line, representing the minimum possible maximum length of the line segments.

Example
Input
2
8
1 2 3 2 5 1 7
8
1 2 3 4 5 6 7
Output
3
7
Note

For the first sample test case, the illustration is as follows. The red, green, and blue segments represent three line segments with lengths of 2, 3, and 2, respectively.