March is visiting the beautiful city of Belobog!
The city of Belobog can be modeled through a coordinate system. March is currently at the point $$$(x_1,y_1)$$$ and she would like to get to the point $$$(x_2,y_2)$$$.
Due to technological advancements, most people prefer to teleport instead of walk. March can perform the following operation any number of times:
Is it possible to reach $$$(x_2,y_2)$$$ through any number of operations?
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) – the number of test cases. Descriptions of the test case follows.
The first line of each test case contains four integers $$$x_1,y_1,x_2,y_2$$$ ($$$-10^9 \leq x_1,x_2,y_1,y_2 \leq 10^9$$$).
For each test case, output YES if it is possible, and NO otherwise. The letters may be outputted in uppercase or lowercase.
52 3 2 5-15 20 -31 2424 31 93 770 0 0 01000000000 999999999 -999999999 -1000000000
YES YES NO YES NO
In the first test case, March can reflect across the point $$$(2,4)$$$ to reach $$$(2,5)$$$ immediately.
In the second test case, March can first teleport through the point $$$(-20, 22)$$$ to reach $$$(-25, 24)$$$, then across the point $$$(-28, 24)$$$ to reach $$$(-31, 24)$$$.
In the third test case, we can show that March cannot reach $$$(93,77)$$$ no matter which operations she use.
Note: You may want to use $$$64$$$-bit integers instead of $$$32$$$-bit integers in this task. For example, in Java, you may want to use long instead of int. In C++, you may want to use long long.
Yunli is writing numbers on the blackboard!
She first writes the number $$$1$$$ one time, then the number $$$2$$$ two times, then the number $$$3$$$ three times, and so on.
Then, Yunli gives you an integer $$$x$$$, and she wants you to tell her how many numbers she must write in this fashion until the sum of all numbers is at least $$$x$$$.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) – the number of test cases.
The first line of each test case contains an integer $$$x$$$ ($$$1 \leq x \leq 10^{18}$$$).
Scoring
Partial credits will be given to programs who pass tests with smaller constraints outlined below.
| Group | Points | Constraints |
| 1 | 15 | The sum of $$$x$$$ does not exceed $$$2\cdot 10^5$$$ over all test cases |
| 2 | 30 | $$$x \leq 10^{9}$$$ |
| 3 | 55 | No further constraints |
For each test case, output the answer on a new line.
1012345678910
1 2 2 3 3 4 4 4 5 5
The first six numbers written are $$$1$$$, $$$2$$$, $$$2$$$, $$$3$$$, $$$3$$$, $$$3$$$.
Sampo is hiding inside a tunnel system. The tunnel can be modeled as a tree$$$^{\text{∗}}$$$ with $$$n$$$ nodes and $$$n-1$$$ edges. There is an exit situated at every node with exactly one neighbor.
Sampo wants to decide in which node to hide in. Obviously, he should hide in a node that is the furthest distance away from any exit. Please help Sampo determine which node is the best one to hide in. If there are multiple nodes that are equally as far from an exit, output the node with the least index.
$$$^{\text{∗}}$$$A tree is a connected graph without cycles.
The first line contains an integer $$$t$$$ – the number of test cases ($$$1 \leq t \leq 10^4$$$).
The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$) – the number of nodes in the tree.
The following $$$n-1$$$ lines each contain two integers $$$p$$$ and $$$q$$$ ($$$1 \leq p, q \leq n, p\neq q$$$) – signifying that there is an edge from $$$p$$$ to $$$q$$$ in the tree. It is guaranteed that the given edges form a tree.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
Scoring
Partial credits will be given to programs who pass tests with smaller constraints outlined below.
| Group | Points | Constraints |
| 1 | 40 | The sum of $$$n$$$ does not exceed $$$1500$$$ over all test cases |
| 2 | 60 | No further constraints |
For each test case, output the index of the node furthest away from any exit. If there are multiple nodes that are equally far, output the node with the least index.
431 32 341 22 34 241 22 33 4131 22 33 44 54 62 77 82 96 105 1111 1210 13
3 2 2 4
This is the tree in the first test case. Node $$$3$$$ is distance $$$1$$$ away from exits, while nodes $$$1$$$ and $$$2$$$ are distance $$$0$$$ away from exits.
Note: You may want to use $$$64$$$-bit integers instead of $$$32$$$-bit integers in this task. For example, in Java, you may want to use long instead of int. In C++, you may want to use long long.
Serval has an undirected unweighted connected graph of $$$n$$$ nodes and $$$m$$$ edges.
To help you guess the structure of the graph, Serval tells you the distance from node $$$1$$$ to node $$$i$$$ for each $$$2 \leq i \leq n$$$ (distance from node $$$1$$$ to node $$$i$$$ is the minimum number of edges in any path from $$$1$$$ to $$$i$$$). Additionally, Serval tells you that the number of edges in the graph is minimized. That is, there does not exist a graph that also satisfies the distance requirements with less edges.
Despite this, there can still be a lot of possible graphs! Please count the number of graphs with minimum number of edges that satisfies the distance requirements. Since the answer can be massive, output it modulo $$$998\,244\,353$$$.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) – the number of independent test cases. Descriptions of the test cases follow.
The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot 10^5$$$) – the number of nodes in the graph.
The following line contains $$$n-1$$$ integers $$$d_2,d_3,\ldots,d_n$$$ ($$$1 \leq d_i \leq n-1$$$) – the distances from node $$$1$$$ to each other node.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output the number of graphs modulo $$$998\,244\,353$$$.
52141 2 191 2 1 3 4 3 2 281 2 3 4 5 6 741 3 3
1 2 144 1 0
In the second test case, the two graphs are shown below
Note that we cannot have both edges 2 3 and 4 3 as the graph would have $$$4$$$ edges, while the minimal graph has $$$3$$$ edges.
In the last test case, no graph exists.
Note: You may want to use $$$64$$$-bit integers instead of $$$32$$$-bit integers in this task. For example, in Java, you may want to use long instead of int. In C++, you may want to use long long.
Sushang has a multiset $$$S$$$ containing $$$n$$$ elements and $$$k$$$ empty arrays $$$a_1,a_2,\ldots,a_k$$$. She will repeat the following operation until $$$S$$$ is empty:
After that, Sushang calculates the score of each array as follows: if $$$a_i=[x_1,x_2,\ldots,x_m]$$$, then score$$$(a_i)=\sum_{i=1}^mx_i\cdot i=x_1\cdot1+x_2\cdot2+x_3\cdot3+\ldots+x_m\cdot m$$$. The score of an empty array is $$$0$$$.
Sushang wants to minimize the sum of scores over all arrays.
The value of $$$k$$$ is not yet known, so please find the minimum sum of scores possible for $$$k=1,2,\ldots,n$$$ independently.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) – the number of independent test cases. The description of test cases follow.
The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$) – the number of elements in $$$S$$$.
The second line of each test case contains $$$n$$$ integers $$$S_1,S_2,\ldots,S_n$$$ ($$$1 \leq S_i \leq 10^6$$$) – the numbers in the set $$$S$$$ initially.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
Scoring
Partial credits will be given to programs who pass tests with smaller constraints outlined below.
| Group | Points | Constraints |
| 1 | 50 | The sum of $$$n$$$ does not exceed $$$3000$$$ over all test cases |
| 2 | 50 | No further constraints |
For each test case, output $$$n$$$ numbers on a new line: the answer for $$$k=1,2,\ldots,n$$$.
431 1 131 2 31183 1 4 1 5 9 2 6
6 4 3 10 7 6 1 94 56 44 38 35 33 32 31
In the first test case, when $$$k=3$$$, it is optimal to partition into the arrays $$$[1],[1],[1]$$$. Each array has a score of $$$1$$$.
In the second test case, when $$$k=2$$$, it is optimal to partition into the arrays $$$[3,1]$$$ and $$$[2]$$$. The first array has score $$$3\cdot1+1\cdot2=5$$$ and the second array has score $$$2$$$. The total score is $$$7$$$.
Tingyun gives you an array $$$a$$$ of size $$$n$$$.
Given an integer $$$x$$$, define functions $$$f_0(x),f_1(x),\ldots,f_n(x)$$$ as follows:
In other words, $$$f_n(x) = (\ldots((x \text{ mod } a_1)\text{ mod } a_2)\ldots \text{ mod } a_n)$$$.
Note for positive integers $$$a$$$ and $$$b$$$, $$$a \text{ mod } b$$$ is the unique integer $$$0\leq c \lt b$$$ such that $$$a-c$$$ is divisible by $$$b$$$. For example, $$$5 \text{ mod } 3 = 2$$$.
Tingyun then gives you $$$q$$$ values of $$$x$$$. For each $$$x$$$, please output the value of $$$f_n(x)$$$.
The first line contains an integer $$$t$$$ – the number of test cases ($$$1 \leq t \leq 10^4$$$).
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n,q \leq 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \leq a_i \leq 10^9$$$).
The next $$$q$$$ lines each contain an integer $$$x$$$ ($$$1 \leq x \leq 10^9$$$).
It is guaranteed that neither the sum of $$$n$$$ nor the sum of $$$q$$$ exceeds $$$10^5$$$ over all test cases.
Scoring
Partial credits will be given to programs who pass tests with smaller constraints outlined below.
| Group | Points | Constraints |
| 1 | 20 | $$$q=1$$$ |
| 2 | 40 | $$$a_i, x \leq 50$$$, sum of $$$q\leq 3\cdot 10^4$$$ |
| 3 | 40 | No further constraints |
Output the answer for each $$$x$$$ on a new line.
23 315 13 1121452146255 614182 5527 2319 958 7248192489829128491578172857871267639126471891918273752
0 1 10 516 380 24 486 108 157
Note: You may want to use $$$64$$$-bit integers instead of $$$32$$$-bit integers in this task. For example, in Java, you may want to use long instead of int. In C++, you may want to use long long.
Given an array $$$a$$$ of size $$$m$$$, let $$$f(a)$$$ be the number of numbers $$$1\leq i\leq m$$$ where $$$\min(a_1,a_2,\ldots,a_i)=a_i$$$.
For example, if $$$a=[2,4,3,2,1]$$$, $$$f(a)=3$$$ because $$$a_1=\min(a_1)$$$, $$$a_4=\min(a_1,a_2,a_3,a_4)$$$, and $$$a_5=\min(a_1,a_2,a_3,a_4,a_5)$$$.
Seele gives you two integers $$$n$$$ and $$$k$$$.
There are $$$k^n$$$ length-$$$n$$$ arrays such that each element is a positive integer from $$$1$$$ to $$$k$$$, inclusive. Over all such arrays, Seele asks you to output the sum of $$$f(a)$$$ over all such arrays $$$a$$$.
Since the answer may be huge, output the answer modulo $$$998\,244\,353$$$.
The first test case contains an integer $$$t$$$ – the number of independent test cases ($$$1 \leq t \leq 10^4$$$).
The only line of each test case contains two integers $$$n,k$$$ ($$$1 \leq n \leq 10^9, 1 \leq k \leq 3\cdot 10^5$$$).
It is guaranteed that the sum of $$$k$$$ does not exceed $$$3\cdot 10^5$$$ over all test cases.
Scoring
Partial credits will be given to programs who pass tests with smaller constraints outlined below.
| Group | Points | Constraints |
| 1 | 10 | $$$n\leq 7$$$, the sum of $$$k^n$$$ does not exceed $$$1.5\cdot 10^5$$$ over all test cases. |
| 2 | 15 | $$$k=2$$$, sum of $$$n$$$ does not exceed $$$3000$$$ over all test cases. |
| 3 | 20 | $$$k=2$$$, sum of $$$n$$$ does not exceed $$$3\cdot 10^5$$$ over all test cases. |
| 4 | 25 | The sum of $$$n\cdot k$$$ does not exceed $$$10^6$$$ over all test cases. |
| 5 | 30 | No further constraints |
For each test case, output the answer modulo $$$998\,244\,353$$$.
52 23 23 35 5888 999
7 19 59 8479 667852386
11000000000 300000
732088305
The first examples satisfies subtask $$$4$$$ and the second example satisfies subtask $$$5$$$.
In the first test case of the first example, we need to consider the following four arrays:
The sum over all arrays is $$$7$$$.
You may want to use C++ for this problem if you want full credit.
Bronya has $$$n$$$ cards ($$$n$$$ is even), with the $$$i$$$th card having the number $$$a_i$$$ written on it. Given an integer $$$k$$$, she plays the following game:
Naturally, Bronya wants to maximize her score for any given $$$k$$$.
Bronya has not yet determined what value of $$$k$$$ she will use. Therefore, your task is to find out what her score will be for each value of $$$k$$$ from $$$1$$$ to $$$2\cdot n$$$.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) – the number of independent test cases. The descriptions of test cases follow.
The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$). It is guaranteed that $$$n$$$ is even.
The following line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \leq a_i \leq n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
Scoring
Partial credits will be given to programs who pass tests with smaller constraints outlined below.
| Group | Points | Constraints |
| 1 | 50 | The sum of $$$n$$$ does not exceed $$$5000$$$ over all test cases |
| 2 | 50 | No further constraints. |
Output $$$2\cdot n$$$ lines on a new line: the answer for $$$k=1,2,3,\ldots,2\cdot n$$$.
341 2 3 281 2 3 4 5 6 7 861 1 1 1 1 1
0 0 1 2 1 0 0 0 0 0 1 1 2 2 3 3 4 3 3 2 2 1 1 0 0 3 0 0 0 0 0 0 0 0 0 0
In the first test case, for $$$k=5$$$, Bronya can earn $$$1$$$ point by doing the following: