Saki is cleaning up the data obtained from false minoshiro she has captured. The data consists of all non-negative integer sequences of length equal to $$$N$$$, where each integer is less than $$$M$$$.
For a sequence $$$s$$$ in the data, we write $$$s=[s_0, \cdots, s_{N-1}]$$$ where $$$s_i$$$ is the $$$i$$$-th integer in $$$s$$$.
Let $$$\pi(s)$$$ be the length of the longest proper prefix that is also a proper suffix. i.e. it is the maximum non-negative integer $$$p$$$ with $$$p \lt N$$$ such that $$$s_i = s_{N-(p-i)}$$$ for all integer $$$0 \le i \lt p$$$. Note that the maximum always exist as $$$p=0$$$ satisfies the condition. When Saki cleans up sequence $$$s$$$, she saves $$$\pi(s)^2$$$ amount of effort.
Saki now wants to know the sum of all efforts she will save when she cleans up the entire data. Write a program to find the sum, modulo $$$998\,244\,353$$$.
The input is given in the following format:
| $$$N$$$ | $$$M$$$ |
where $$$N$$$ is the length of a sequence, and $$$M$$$ is the upper bound of the size of an element in a sequence plus one.
The input satisfies the following constraints:
Print a single line containing the sum of all efforts Saki will save when cleaning up the data, modulo $$$998\,244\,353$$$.
1 2
0
5 3
264
Saki would like to install sewage system in two villages $$$A$$$ and $$$B$$$, each containing $$$N$$$ houses numbered from $$$0$$$ to $$$N-1$$$. For each village, the house numbered $$$0$$$ is located at the highest altitude, while the house numbered $$$N-1$$$ is located at the lowest altitude.
Saki will order $$$2$$$ pipes for each of the $$$M$$$ types of pipes, for the total of $$$2M$$$ pipes. Saki will install $$$M$$$ pipes of different types to each village.
Each pipe has a fixed non-negative integer capacity, and connects two different houses of the same village. Two pipes of the same type have the same capacity. Note that some pipe may have zero capacity (such pipes are for cosmetic purposes). It is already determined which pipe connects which houses, but the capacities have not yet been determined.
After installation, the maximum flow of water in each village is defined as the maximum flow from $$$0$$$ to $$$N-1$$$ when the given sewage system is interpreted as an undirected flow network.
As the village $$$B$$$ has a bigger population than $$$A$$$, Saki would like the maximum flow of water of village $$$B$$$ to be strictly greater than that of $$$A$$$. She can ask pipemakers to set the capacity of each type of pipe to any non-negative integer she wants, but she hasn't decided on the values.
Write a program to help Saki determine if it is possible to assign non-negative integer capacity to each pipe so that the maximum flow of water of village $$$B$$$ is strictly greater than that of $$$A$$$, and if possible, show one possible way to assign capacities.
The input is given in the following format:
| $$$N$$$ | $$$M$$$ |
| $$$U_0$$$ | $$$V_0$$$ |
| $$$U_1$$$ | $$$V_1$$$ |
| $$$\vdots$$$ | |
| $$$U_{M-1}$$$ | $$$V_{M-1}$$$ |
| $$$X_0$$$ | $$$Y_0$$$ |
| $$$X_1$$$ | $$$Y_1$$$ |
| $$$\vdots$$$ | |
| $$$X_{M-1}$$$ | $$$Y_{M-1}$$$ |
where $$$N$$$ is the number of houses on each villages, $$$M$$$ is the number of types of pipes, and the pipe of type $$$i$$$ connects $$$U_i$$$ and $$$V_i$$$ on village $$$A$$$, and $$$X_i$$$ and $$$Y_i$$$ on village $$$B$$$.
The input satisfies the following constraints:
Note that the same pair of houses can be connected by multiple pipes.
If there is no assignment of capacities such that the maximum flow of water of the village $$$B$$$ is strictly greater than that of $$$A$$$, print a single line containing $$$-1$$$. Otherwise, the output should be in the following format:
| $$$C_0$$$ | $$$C_1$$$ | $$$\cdots$$$ | $$$C_{M-1}$$$ |
where $$$C_i$$$ is the capacity of the edge of type $$$i$$$.
In such case, the output should satisfy the following constraints:
It can be proved that if a desired assignment of non-negative integer capacities exists, there also exists a desired assignment satisfying the above constraints.
4 30 30 30 30 10 20 3
-1
4 30 10 20 30 30 30 3
1 2 3
The unified class is hosting a cantus tournament where classes A and B advanced to the final. However, during the final match, there was an accident where the cantus of the students are entangled together. Saki is tasked with dealing with this situation as soon as possible.
The students are located in an infinite grid, where the rows and columns are numbered with integers. The cell at the $$$i$$$-th row and $$$j$$$-th column is represented as $$$(i, j)$$$, and it is known that all the students occupy a distinct cell, and their location satisfy $$$0 \le i \lt N$$$ and $$$0 \le j \lt M$$$.
Saki will attempt to separate class A and B students from each other, if possible. In one move, she can pick either class A or B, and order every student in that class to simultaneously move one cell in one of four directions: right, up, left, or down. She cannot perform the move if it would result in a student from class A and a student from class B being in the same cell.
Write a program to help Saki determine if it is possible to separate class A and B. They are considered separated if the smallest euclidean distance between a student from class A and a student from class B is at least $$$10^{9999999999999999999999}$$$.
The input is given in the following format:
| $$$N$$$ | $$$M$$$ |
| $$$S_0$$$ | |
| $$$\vdots$$$ | |
| $$$S_{N-1}$$$ | |
where
The input satisfies the following constraints:
If it is possible to separate them, print a single line containing the string "Yes", otherwise print a single line containing the string "No". You may print each character in either case (lower or upper).
4 5AAAA.ABBBBAAAAB.BBBB
Yes
3 4.AA.AB.A.AA.
No
As the head of the Ethics community, Saki is charged with overseeing the railway construction over $$$N+1$$$ sites, numbered from $$$0$$$ to $$$N$$$. It is known that for some unknown positive integer $$$x$$$, geotechnical engineers figured out the following list of candidate bidirectional paths that railways can be constructed upon.
Saki is planning to pick $$$N$$$ of the candidates and build railways so that all $$$N+1$$$ sites are connected either directly or indirectly. She has countably-infinite many friends, numbered $$$1, 2, 3, \cdots$$$. She asked the friend numbered $$$1$$$ to compute the number of ways to pick such a set of candidates whenever Saki choose the value $$$x$$$. Let the correct answer be $$$f(x)$$$.
To make sure, each friend $$$i$$$ asked the friend $$$i+1$$$ to double-check the computation. However, due to a mistake in their communication, when friend $$$i$$$ received the integer $$$y$$$, he/she passed the value $$$f(y)$$$ to friend $$$i+1$$$ instead of the value $$$y$$$. Therefore, friend 1 computed $$$f(x)$$$, friend 2 computed $$$f(f(x))$$$, the friend 3 computed $$$f(f(f(x)))$$$, and so on.
However, one of Saki's friend Satoru noticed that regardless of the value $$$x$$$ Saki chose, for some fixed prime $$$M$$$, his computation result was always equal to $$$x$$$ modulo $$$M$$$. Satoru now wonders what his friend number would be, which is a positive integer, unless there were some mistakes in one of the computations.
Given $$$N$$$ and $$$M$$$, write a program which determines whether this was possible, and if possible, find the minimum friend number of Satoru, modulo $$$998\,244\,353$$$.
The input is given in the following format:
| $$$N$$$ | $$$M$$$ |
where $$$N+1$$$ is the number of construction sites, and $$$M$$$ is the prime modulus of Satoru.
The input satisfies the following constraints:
If there exists a positive integer $$$K$$$ which could have been the friend number of Satoru, print a single line containing the minimum such $$$K$$$, modulo $$$998\,244\,353$$$. Otherwise, print a single line containing $$$-1$$$.
29 89
30
2 2
-1
This is an output-only problem.
In order to avoid repeating the tragedy that unfolded in her childhood, Saki invented a device which drastically lowers the probability of the Karma Demon appearing!
The earth can be modeled as a sphere with radius $$$1$$$, and Saki is planning to install $$$100\,000$$$ devices on its surface. The effectiveness of the devices is known to be proportional to the number of pairs of devices with Euclidean distance exactly $$$\sqrt2$$$. Here, the Euclidean distance between two people with coordinate $$$(x_0, y_0, z_0)$$$ and $$$(x_1, y_1, z_1)$$$ is $$$\sqrt{(x_0 - x_1)^2 + (y_0 - y_1)^2 + (z_0 - z_1)^2}$$$.
Write a program to install $$$100\,000$$$ devices on distinct locations, such that there exists at least $$$1\,400\,000$$$ pairs of devices with Euclidean distance exactly $$$\sqrt2$$$.
The output should be in the following format:
| $$$N$$$ | ||
| $$$x_0$$$ | $$$y_0$$$ | $$$z_0$$$ |
| $$$x_1$$$ | $$$y_1$$$ | $$$z_1$$$ |
| $$$\vdots$$$ | ||
| $$$x_{N-1}$$$ | $$$y_{N-1}$$$ | $$$z_{N-1}$$$ |
| $$$M$$$ | ||
| $$$i_0$$$ | $$$j_0$$$ | |
| $$$i_1$$$ | $$$j_1$$$ | |
| $$$\vdots$$$ | ||
| $$$i_{M-1}$$$ | $$$j_{M-1}$$$ | |
where $$$N$$$ is the number of devices, $$$x_i, y_i, z_i$$$ are the parameters indicating that the $$$i$$$-th device is located at the coordinate $$$\left( \frac{x_i}{\sqrt{x_i^2 + y_i^2 + z_i^2}}, \frac{y_i}{\sqrt{x_i^2 + y_i^2 + z_i^2}}, \frac{z_i}{\sqrt{x_i^2 + y_i^2 + z_i^2}} \right)$$$ for each integer $$$0 \le i \lt N$$$, $$$M$$$ is the required number of pairs of devices with Euclidean distance exactly $$$\sqrt2$$$, and $$$i_k, j_k$$$ are the indices of the devices of the $$$k$$$-th pair for all integer $$$0 \le k \lt M$$$.
The output should satisfy the following constraints:
3
1 0 0
0 1 0
0 0 1
3
0 1
0 2
1 2
Please note that the sample output above does not satisfy $$$N=100\,000$$$ or $$$M=1\,400\,000$$$, thus it will give Wrong Answer verdict upon submission. It is there only to present the output format.
$$$N$$$ people, numbered from $$$0$$$ to $$$N-1$$$, are taking part in the summer festival in Kamisu 66. Kamisu 66 can be represented as a coordinate plane, where $$$i$$$-th person is located at $$$(X_i, Y_i)$$$.
A set of people is said to be in a ritual formation if there exists exactly one circle for which every person in the set lies on its circumference.
Saki would like to know how many sets of people are in a ritual formation. Write a program to help Saki compute the answer, modulo $$$998\,244\,353$$$.
The input is given in the following format:
| $$$N$$$ | |
| $$$X_0$$$ | $$$Y_0$$$ |
| $$$X_1$$$ | $$$Y_1$$$ |
| $$$\vdots$$$ | |
| $$$X_{N-1}$$$ | $$$Y_{N-1}$$$ |
where $$$N$$$ is the number of people participating in the summer festival, and $$$(X_i, Y_i)$$$ is the position of the $$$i$$$-th person.
The input satisfies the following constraints:
The output should be in the following format:
| $$$R$$$ |
where $$$R$$$ is the number of sets of people in a ritual formation, modulo $$$998\,244\,353$$$.
40 00 11 01 1
5
40 01 02 03 0
0
A cantus user's status is characterized by a complex number where both real and imaginary parts are integers. Let $$$\mathbb{G}$$$ be the set of all such complex numbers.
Let's say $$$x \in \mathbb{G}$$$ divides $$$y \in \mathbb{G}$$$ if there exists $$$k \in \mathbb{G}$$$ with $$$k\cdot x = y$$$.
$$$x, y \in \mathbb{G}$$$ are said to be uncorrelated if $$$1$$$, $$$-1$$$, $$$i$$$, $$$-i$$$ are the only element of $$$\mathbb{G}$$$ dividing both $$$x$$$ and $$$y$$$. Otherwise, $$$x$$$ and $$$y$$$ are said to be correlated.
Saki knows that the probability of a cantus user turning into a karma demon is proportional to a quantity called the isolation index. For a cantus user with status $$$x \ne 0$$$, the isolation index is computed as follows.
Saki wants to compute the sum of the isolation index of all non-zero status $$$a+bi \in \mathbb{G}$$$, $$$a \in \mathbb{Z}$$$, $$$b \in \mathbb{Z}$$$ with $$$a^2+b^2 \le N$$$. Write a program to help Saki find the desired sum.
The input is given in the following format:
| $$$N$$$ |
The input satisfies the following constraints:
Print a single integer, the sum of isolation index over all possible non-zero status $$$a+bi$$$ satisfying $$$a^2+b^2 \le N$$$, modulo $$$998\,244\,353$$$.
1
4
2
8
5
48
100
10400
10000000000
985340907
This is an output-only problem.
Saki has invented a new programming language called Tree++. A program in Tree++ can be represented as a rooted binary tree where each non-leaf node has exactly two children, and has one of the following labels: "add", "sub", "mul", "quo", "rem", "pow". Here, a leaf node of a rooted tree is a node with no child.
A program in Tree++ accepts an integer $$$X$$$, and either outputs an integer, or produces an error according to the following rule.
Satoru does not believe in the power of Tree++, so he challenged Saki to implement a short membership test for the 5 of his favourite numbers: $$$561$$$, $$$1105$$$, $$$1729$$$, $$$2465$$$, and $$$2821$$$. (Note that these are the 5 smallest Carmichael numbers, i.e. the composite numbers $$$x$$$ with $$$a^x=a \mod x$$$ for all integer $$$a$$$) More specifically,
Write a program to help Saki implement the membership test.
The output should be in the following format:
| $$$N$$$ | $$$R$$$ | ||
| $$$L_0$$$ | $$$L_1$$$ | $$$\cdots$$$ | $$$L_{N-1}$$$ |
| $$$U_0$$$ | $$$V_0$$$ | ||
| $$$\vdots$$$ | |||
| $$$U_{N-2}$$$ | $$$V_{N-2}$$$ | ||
where
For an internal node, there are two edges connecting it to its children. The left child is the one connected to the edge appearing earlier in the output, while the right child is the one connected to the edge appearing later in the output.
The output should satisfy the following constraints:
11 0
add sub mul quo rem leaf leaf leaf leaf leaf leaf
0 1
0 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10
Please note that the sample output above does not implement the membership test for Satoru's favourite numbers, thus it will give Wrong Answer verdict upon submission. It is there only to present the output format.
Saki is interested in various ways to encode a tree into a sequence ever since she has invented Tree++, especially the Prüfer sequence.
Given a tree with $$$N$$$ nodes labelled from $$$0$$$ to $$$N-1$$$, the Prüfer sequence of the tree is the sequence obtained by the following process.
Saki is curious about how much waste will be made on a given tree with nodes numbered from $$$0$$$ to $$$N-1$$$, so she will perform the following action for each $$$k=0, \cdots, N-1$$$.
Saki is very busy, so she has asked you for a favor. Write a program to help Saki compute $$$W_k$$$ for each $$$0 \le k \lt N$$$.
The input is given in the following format:
| $$$N$$$ | |
| $$$U_0$$$ | $$$V_0$$$ |
| $$$U_1$$$ | $$$V_1$$$ |
| $$$\vdots$$$ | |
| $$$U_{N-2}$$$ | $$$V_{N-2}$$$ |
where $$$N$$$ is the number of the nodes in the tree, and the $$$i$$$-th edge connects the nodes $$$U_i$$$ and $$$V_i$$$ for all integer $$$0 \le i \lt N-1$$$.
The input satisfies the following constraints:
The output should be in the following format:
| $$$W_0$$$ |
| $$$W_1$$$ |
| $$$\vdots$$$ |
| $$$W_{N-1}$$$ |
where $$$W_k$$$ is the waste of the tree when node $$$u$$$ is labelled with $$$u+k \mod N$$$.
70 30 40 61 42 43 5
6 10 8 9 7 8 11
Saki successfully intercepted the secret communication of queerats, but the information is encrypted.
It is known that, for some unknown primes $$$p$$$ and $$$q$$$ with $$$2^{100} \le p, q \lt 2^{150}$$$ such that $$$2p-1$$$ and $$$2p^2-2p+1$$$ are both primes, queerats uses $$$N = p(2p-1)(2p^2-2p+1)q^2$$$ to encrypt their message.
Whether Saki can decrypt the message or not depends on whether she can recover $$$p$$$ and $$$q$$$. Write a program to help Saki recover $$$p$$$ and $$$q$$$ given $$$N$$$. Your solution will be tested against exactly 50 fixed testcases, including the sample tests.
The input is given in the following format:
| $$$N$$$ |
The input satisfies the following constraints:
The output should be in the following format:
| $$$p$$$ | $$$q$$$ |
It can be proved that $$$p$$$ and $$$q$$$ is uniquely determined under the constraints of this problem.
30958404678287761871650278141363... (truncated because too long)
27519497234739335217702161486538475049927611 3673485247907112592302554948506673
2637606013846171358319274548523376... (truncated because too long)
1770172552826549812180151791951 259145553434053480260418032745896979495962091