OLO's global tournament, ISM, is in full swing and Shizuku is a big fan of GNR which is taking part in the tournament. OLO is a game where two teams of five players play against each other. PENTA KILL is considered an unbelievable achievement in the game, which means one player kills five pairwise distinct opponents in a row. We assume that a player will be resurrected immediately after his death, and the death will not affect the verdict of his PENTA KILL.
Normally, PENTA KILL will be displayed in the game. However, sometimes due to unintended disparity in latency between competing teams, it is not displayed properly in the game. After the game, Shizuku gets a chronological list of kills during the game. She wants to know whether a player has achieved PENTA KILL in this game.
The first line contains an integer $$$n$$$ ($$$1\le n \le 1000$$$), indicating the number of kills in the game.
Each of the following $$$n$$$ lines contains two strings $$$a$$$ and $$$b$$$ consisting of English letters and digital numbers, indicating that the player named $$$a$$$ kills the player named $$$b$$$. The length of each string won't exceed $$$100$$$. It is guaranteed that there are no kills between teammates and there are exactly five players per team.
Output PENTA KILL! if a player has achieved PENTA KILL, or SAD:( otherwise.
10 Bin Guigo Grevthar Bin GALA Grevthar GALA TitaN GALA Guigo GALA Aegis GALA Jojo GALA Grevthar Xiaohu Grevthar GALA Aegis
PENTA KILL!
7 GALA Jojo GALA Jojo Aegis GALA GALA Grevthar GALA Aegis GALA Guigo GALA TitaN
PENTA KILL!
7 GALA Jojo Aegis Ming GALA Grevthar GALA Grevthar GALA Aegis GALA Guigo GALA TitaN
SAD:(
In the second sample, GALA kills Jojo, Grevthar, Aegis, Guigo, and TitaN in a row so he gets PENTA KILL.
In the third sample, GALA kills Grevthar twice after he kills Jojo so he doesn't kill five distinct opponents in a row.
Yukikaze is studying number theory. She wonders whether she can arrange all positive integers between $$$1$$$ and $$$n$$$ ($$$n$$$ is a positive even integer) into several disjoint cycles such that each cycle contains at least three integers, and the sum of any two adjacent integers is a prime number in any cycle.
Prime numbers are integers greater than $$$1$$$ and cannot be exactly divided by any positive integer other than itself and $$$1$$$.
Formally speaking, Yukikaze wants to find $$$k$$$ sequences $$$A_1, A_2, \ldots, A_k$$$ that satisfy the following conditions:
The input contains only one positive even integer $$$n$$$ ($$$2 \leq n \leq 10^4$$$).
Output the number of cycles $$$k$$$ in the first line.
Each of the following $$$k$$$ lines starts with a positive integer $$$l$$$ denoting the number of integers in the cycle, followed by $$$l$$$ integers denoting the integers in the cycle in order. If there are multiple answers, print any. Do NOT print any extra spaces at the end of each line.
If it is impossible to arrange these $$$n$$$ integers, print $$$-1$$$ in a single line.
8
1 8 1 2 3 8 5 6 7 4
18
3 4 1 2 3 4 6 5 6 7 10 9 8 8 11 12 17 14 15 16 13 18
Tom likes playing a video game recently. The rules of this game are as follows. The game is played on an $$$x$$$-axis. There are a total of $$$n+1$$$ pillars in the game, which are arranged in a row from left to right. The pillars are numbered from $$$0$$$ to $$$n$$$. The coordinate of the pillar numbered $$$i$$$ is $$$x=i$$$. There is also an infinite platform in the game in the range of $$$[n+1,+\infty)$$$. Players can win by jumping to any position within this range.
Players start from the pillar numbered $$$0$$$ and can only jump from left to right, i.e. the coordinates must increase. And he can only jump on the pillars or the platform, otherwise, he will fall into the void and fail the game. In addition, his jumping ability is limited, and the distance of each jump does not exceed $$$p$$$.
Except for the pillar numbered $$$0$$$, there will be a treasure chest on each remaining pillar. The treasure chest on the pillar numbered $$$i$$$ will have $$$a_{i} $$$ gold coins. However, there are some trap chests ($$$a_{i} \lt 0$$$) where he will lose $$$|a_{i}|$$$ gold coins.
This game has $$$n$$$ levels. Tom can only jump to the pillars numbered with multiples of $$$i$$$ in the $$$i$$$-th level. Now there are $$$q$$$ queries, each of which contains a number $$$x$$$, asking the maximum number of gold coins Tom can get when he wins at level $$$x$$$. It's possible that Tom opens too many trap chests on the way and gets negative gold coins.
The first line contains three integers $$$n$$$, $$$q$$$, and $$$p$$$ ($$$2\le p\le n\le 10^{6}$$$, $$$1\le q\le 10^{6}$$$), indicating the number of pillars, the number of queries, and the longest jump distance.
The second line contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$|a_{i}|\le 10^{9}$$$), indicating the number of gold coins in the treasure chest on the pillar numbered $$$i$$$.
In the next $$$q$$$ lines, each line contains an integer $$$x$$$ ($$$1\le x\le n$$$), indicating a query of the maximum number of gold coins he can obtain in level $$$x$$$.
Output one integer in a single line for each query, representing the answer. If it is impossible to win, output Noob in a single line.
5 3 4 2 5 -6 -4 3 1 2 3
10 5 -6
10 6 8 5 4 -6 8 -11 5 -6 4 -7 3 1 2 4 6 8 10
29 24 12 5 4 Noob
You are given three integers $$$n$$$, $$$k$$$ and $$$q$$$ along with a sequence $$$a_1,a_2,...,a_n$$$. You have to process $$$q$$$ queries.
For each query, you will be given two integers $$$l$$$, $$$r$$$. Then, you should find a sequence of length $$$2m$$$ that consists of pairwise distinct integers, denoted as $$$b_1,b_2,...,b_{2m}$$$, such that $$$l\leq b_1,b_2,...,b_{2m}\leq r$$$, and for each $$$i\in [1,m]$$$, $$$|b_{2i-1}-b_{2i}|=k$$$. $$$m$$$ is a non-negative integer determined by you. Among all the valid sequences, you should find the maximum value of $$$a_{b_1}+a_{b_2}+...+a_{b_{2m}}$$$, and output it for each query.
The first line contains three integers $$$n$$$, $$$k$$$, $$$q$$$ ($$$1\leq n,q\leq 10^5$$$, $$$1\leq k\leq n$$$).
The second line contains $$$n$$$ integers $$$a_1,a_2,...,a_n$$$ ($$$-10^9\leq a_i\leq10^9$$$), indicating the given sequence.
Each of the following $$$q$$$ lines contains two integers $$$l$$$, $$$r$$$ ($$$1\leq l\leq r\leq n$$$), indicating a query.
For each query, output an integer in a single line indicating the answer.
7 2 5 -1 2 4 -3 6 5 3 1 5 2 6 3 7 1 7 2 4
10 12 12 14 0
Alice and Bob are playing cards. Each of them has been given $$$n$$$ cards with a number on each card. They will play the cards for $$$n$$$ rounds, and in each round, each player will play a card that hasn't been played before. After both Alice and Bob play a card in a round, they will compare the number written on the cards, and the person who plays a card with a larger number will win this round. In the case that the numbers written on two cards are exactly the same, this round will be a draw.
Alice has a very strong competitive heart. She doesn't want to lose in any round. If in any round she discovered that the number on the card played by her is smaller than the one played by Bob, she will cheat several times. Cheating once, she can increase the number written on her card by $$$k$$$, and she will keep cheating in a round until the number on her card is not smaller than the number on Bob's card.
However, cheating is very risky, therefore she wants to minimize the times of cheating. To achieve that, she managed to know the sequence of cards that will be played by Bob, and she can determine the order to play the cards in her hands. Please help her calculate the minimum cheating times.
Formally, we can denote the cards in Alice's hands by $$$a_1,a_2,\ldots,a_n$$$, and denote the sequence of cards that will be played by Bob by $$$b_1,b_2,\ldots,b_n$$$. You should find a permutation of $$$n$$$ denoted by $$$c_1,c_2,\ldots,c_n$$$, such that
$$$$$$ \sum\limits_{i=1}^n\left\lceil \frac{\max(b_i-a_{c_i},0)}k\right\rceil $$$$$$
is minimized. You should output the minimized value and a possible sequence $$$c_1,c_2,\ldots,c_n$$$.
The first line contains two integers $$$n$$$ ($$$1\leq n\leq 10^5$$$) and $$$k$$$ ($$$1\leq k \leq 10^9$$$), indicating the number of cards on each player's hands and the number that can be increased per cheating action.
The second line contains $$$n$$$ integers $$$a_1,a_2,...,a_n$$$ ($$$1\leq a_i\leq 10^9$$$), denoting the cards on Alice's hands.
The third line contains $$$n$$$ integers $$$b_1,b_2,...,b_n$$$ ($$$1\leq b_i\leq 10^9$$$), denoting the sequence of cards played by Bob. Note that Bob will play the cards in the order of the sequence.
You should output two lines.
In the first line, output a single integer indicating the minimum times to cheat.
In the second line, output $$$n$$$ integers $$$c_1,c_2,...,c_n$$$, indicating the order of cards played by Alice to minimize the cheating times. That is, Alice will play a card with the number $$$a_{c_i}$$$ in round $$$i$$$. If there are multiple answers, print any.
4 2 2 7 6 4 3 9 1 8
2 4 2 1 3
Luna is shopping at a magic shop, where $$$n$$$ kinds of items are on sale. The value of the $$$i$$$-th kind of item is $$$v_i$$$, and the weight is $$$w_i$$$. The number of items is infinity. Luna's pocket can carry items with a total weight of no more than $$$k$$$. Each time, Luna can take one item of any kind. She can take at most $$$m$$$ times.
In order to take more items, Luna uses magic so that if the number of items she buys is $$$i$$$, she can carry a total weight of at most $$$i+k$$$. Her happiness of shopping is the product of the value over all the items she buys. If she buys nothing, the happiness is $$$1$$$.
There are many ways to buy items, and she wants to know the sum of happiness of all the possible ways of shopping. Since the number can be very large, just tell her the number modulo $$$998244353$$$.
Two ways of shopping are considered different if the number of times to take items are different or she takes a different kind of item at one time.
The first line of input contains three integers $$$n,m,k$$$ ($$$1\le n,m,k\le 10^5$$$), indicating the number of kinds of items, the maximum number of times to take items, and the capacity of the pocket.
Each of the following $$$n$$$ lines contains two integers $$$v,w$$$ ($$$1\le v \lt 998244353$$$, $$$0\le w\le m+k$$$), indicating the value and weight of the kind of item. It is guaranteed that there exists a kind of item that $$$w=0$$$.
Print a single integer denoting the sum of happiness modulo $$$998244353$$$.
1 1 1 1 0
2
3 2 3 8 2 5 3 2 0
216
7 4 6 8 2 5 3 2 0 4 2 7 5 5 8 11 2
983858
The explanation of example 1:
The explanation of example 2:
Given a full bipartite graph with $$$n$$$ nodes on the left and $$$m$$$ nodes on the right where any node on the left is connected to all nodes on the right. Your task is now to assign values to the nodes such that any integer $$$i \in [1,n+m]$$$ occurs exactly once and that for any cycle, the GCD (Greatest Common Divisor) of the values of all the nodes on the cycle is equal to $$$1$$$.
The GCD of some positive integers is the maximum integer that divides all the integers. For example, $$$\text{GCD}(4,6)=2$$$, $$$\text{GCD}(6,9,15)=3$$$.
The first line contains a single integer $$$T(1\le T \le 100)$$$, indicating the number of test cases.
Each test case contains two integers $$$n,m(1\le n,m \le 10^{5})$$$ in a single line. It is guaranteed that $$$\sum \max(n,m) \le 2\cdot 10^5$$$.
For each test case, if there exists a possible assignment, output YES in a single line. Then output two lines, the first of which indicates the nodes on the left, while the second of which contains the nodes on the right. If there are multiple answers, print any. The integers in each line are separated by spaces, and DO NOT PRINT ANY EXTRA SPACES at the end of each line. If you print the wrong number of elements, you will possibly get a $$$\text{Presentation Error}$$$ verdict.
If there's no possible assignment, output NO in a single line.
23 49 9
YES 1 4 7 6 2 5 3 NO
The following figure shows a correct graph with $$$n=3, m=4$$$.
Ponyville is on its annual math festival! The ponies who are able to overcome this problem would be honored as $$$\text{Super Gray Pony}$$$. Get yourself prepared for the problem and try your best!
In this problem, the $$$i$$$-order Gray Code is defined recursively as $$$a^{(i)}$$$ - an array of binary numbers with $$$2^i$$$ elements numbered from $$$0$$$ to $$$2^i-1$$$. Note that in this problem leading zeros are added to make each element a strictly $$$i$$$-bit binary number. The specific rules are as follows:
For example:
Given $$$S$$$ and $$$k$$$, $$$S_k$$$ is defined as:
$$$$$$ S_k=\underbrace{a^{(n)}[a^{(n)}[\ldots a^{(n)}}_{k \times a^{(n)}}[S]\ldots ]] $$$$$$
Now given $$$S$$$ and $$$k$$$, you need to calculate the exact value of $$$S_k$$$. In this problem, $$$S$$$ is given in the form of an $$$n$$$-bit binary number, possibly with leading zeros.
The first line contains two integers $$$n,k$$$ ($$$1\le n\le 3\times 10^6,1\le k\le 10^9$$$).
The second line contains a binary number $$$S$$$ of length $$$n$$$. The highest bit is on the left and the lowest bit is on the right.
Output $$$S_k$$$ in the form of an $$$n$$$-bit binary number in a single line, with its highest bit on the left and the lowest bit on the right.
3 5 011
010
$$$a^{(3)}=[000, 001, 011, 010, 110, 111, 101, 100]$$$
$$$S_1=a^{(3)}[(011)_2]=a^{(3)}[3]=010$$$
$$$S_2=a^{(3)}[(010)_2]=a^{(3)}[2]=011$$$
$$$S_3=a^{(3)}[(011)_2]=a^{(3)}[3]=010$$$
$$$S_4=a^{(3)}[(010)_2]=a^{(3)}[2]=011$$$
$$$S_5=a^{(3)}[(011)_2]=a^{(3)}[3]=010$$$
Given a string $$$S$$$ of length $$$n$$$ consisting of lowercase English characters. We denote $$$\text{Suffix}_i$$$ as the suffix of $$$S$$$ starting from the $$$i$$$-th character. We define $$$w_{i,j}$$$ as the length of the LCP of $$$\text{Suffix}_i$$$ and $$$\text{Suffix}_j$$$. LCP is the longest common prefix of two strings. For example, the LCP of $$$\texttt{abca}$$$ and $$$\texttt{abd}$$$ is $$$\texttt{ab}$$$.
You should divide the integers from $$$1$$$ to $$$n$$$ into two non-empty complementary sets $$$T_1, T_2$$$. We define the value of this partition as follows.
$$$$$$ \sum\limits_{i\in T_1}\sum\limits_{j\in T_2}w_{i,j} $$$$$$
Please find a partition to minimize the value.
The input contains a string $$$S$$$ of length $$$n$$$ ($$$2\leq n\leq 10^5$$$) in a single line, consisting of only lowercase English letters.
Output a single integer indicating the minimum value.
aa
1
ab
0
A binary tree $$$T$$$ is called super balanced if $$$T$$$ is empty or satisfies the following three conditions at the same time:
Please calculate the number of super balanced trees consisting of $$$n$$$ nodes. Since the answer can be very large, just output the answer modulo $$$2^{64}$$$.
The first line contains a single integer $$$T$$$ ($$$1\le T\le 10^6$$$), indicating the number of test cases.
Each test case contains a single integer $$$n$$$ ($$$0 \le n \lt 2 ^{64}$$$), indicating the number of nodes in the tree.
For each test case, output an integer in a single line indicating the number of super balanced trees consisting of $$$n$$$ nodes.
2 2 3
2 1
Vasily Tadokorov is a stringologist. He thinks a string is fragrant if it can be divided into two parts: nunhehheh as the prefix and a number of (excluding $$$0$$$) a as the suffix. For example, nunhehhehaaaaaa is fragrant, but nunhehheh and nunhehhehoooaaa are not fragrant.
Today Vasily Tadokorov has some strings consisting of lowercase English letters. For each string, he wants to know how many subsequences of this string are fragrant. A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (including $$$0$$$) characters.
The above is a problem of string that Vasily came up with. As we know, a problem usually has several examples for better understanding. However, Vasily gets buried in making some fragrant examples. After 2000 years, he finally makes two perfect examples as follows.
Example 1:
Example 2:
Vasily is not clever enough. He doesn't want to work for another 2000 years, so he asks you for help. He gives you $$$T$$$ tasks, each of which contains an integer $$$n$$$, and you should construct a string consisting of only lowercase English letters that has exactly $$$n$$$ fragrant subsequences.
The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 1000$$$), denoting the number of tasks.
Each of the next $$$T$$$ lines contains an integer $$$n$$$ ($$$0 \leq n \leq 10^9$$$).
For each test case, output one string consisting of only lowercase English letters in a single line indicating the answer. You need to ensure that the sum of the length over all the output strings does not exceed $$$10^6$$$. It can be proved that a solution always exists. If there are multiple solutions, print any.
2 114514 1919810
nunhehhehahaahahahahahahaahaahahahahha nunhehhehhehhahaahahahaahaahahaaaahaa
Our best explorer, Vingying, finds a deep cave that is full of diamonds! Well, he is a very careful man, so he decides to do some research before collecting them.
The diamonds can be divided into three kinds, noted as $$$\text{A,B,C}$$$ for convenience. There are a total of $$$n$$$ diamonds in a row, which can be regarded as a sequence $$$s_1,s_2,\dots,s_n$$$ from left to right. Vingying will perform the operation several times, which consists of the following three steps in order.
For example, $$$s=\text{ABCABC}$$$. We can choose index $$$1$$$ and collect $$$1,3$$$, then $$$s$$$ becomes $$$\text{BABC}$$$ indexed $$$1,2,3,4$$$. But if we choose index $$$4$$$ and collect $$$5$$$, then $$$s$$$ becomes $$$\text{ABCAC}$$$ indexed $$$1,2,3,4,5$$$.
Vingying wants to know the maximum number of operations (not the diamonds) he can do.
The input contains a string consisting of only $$$\text{A,B,C}$$$ representing the sequence of the diamonds. The length of the string won't exceed $$$2\times10^5$$$.
Output a single integer representing the maximum number of operations.
ABCAAABCCC
2
AABCAAABCCC
4