Given a string $$$x$$$ of length $$$n$$$ and a string $$$s$$$ of length $$$m$$$ ($$$n \cdot m \le 25$$$), consisting of lowercase Latin letters, you can apply any number of operations to the string $$$x$$$.
In one operation, you append the current value of $$$x$$$ to the end of the string $$$x$$$. Note that the value of $$$x$$$ will change after this.
For example, if $$$x =$$$"aba", then after applying operations, $$$x$$$ will change as follows: "aba" $$$\rightarrow$$$ "abaaba" $$$\rightarrow$$$ "abaabaabaaba".
After what minimum number of operations $$$s$$$ will appear in $$$x$$$ as a substring? A substring of a string is defined as a contiguous segment of it.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two numbers $$$n$$$ and $$$m$$$ ($$$1 \le n \cdot m \le 25$$$) — the lengths of strings $$$x$$$ and $$$s$$$, respectively.
The second line of each test case contains the string $$$x$$$ of length $$$n$$$.
The third line of each test case contains the string $$$s$$$ of length $$$m$$$.
For each test case, output a single number — the minimum number of operations after which $$$s$$$ will appear in $$$x$$$ as a substring. If this is not possible, output $$$-1$$$.
121 5aaaaaa5 5eforcforce2 5abababa3 5abaababa4 3babbbbb5 1aaaaaa4 2aabbba2 8bkkbkbkbkb12 2fjdgmujlconttf2 2aaaa3 5abbbabba1 19mmmmmmmmmmmmmmmmmmmm
3 1 2 -1 1 0 1 3 1 0 2 5
In the first test case of the example, after $$$2$$$ operations, the string will become "aaaa", and after $$$3$$$ operations, it will become "aaaaaaaa", so the answer is $$$3$$$.
In the second test case of the example, after applying $$$1$$$ operation, the string will become "$$$\text{e}\color{red}{\text{force}}\text{forc}$$$", where the substring is highlighted in red.
In the fourth test case of the example, it can be shown that it is impossible to obtain the desired string as a substring.
Once upon a time, bartender Decim found three threadlets and a pair of scissors.
In one operation, Decim chooses any threadlet and cuts it into two threadlets, whose lengths are positive integers and their sum is equal to the length of the threadlet being cut.
For example, he can cut a threadlet of length $$$5$$$ into threadlets of lengths $$$2$$$ and $$$3$$$, but he cannot cut it into threadlets of lengths $$$2.5$$$ and $$$2.5$$$, or lengths $$$0$$$ and $$$5$$$, or lengths $$$3$$$ and $$$4$$$.
Decim can perform at most three operations. He is allowed to cut the threadlets obtained from previous cuts. Will he be able to make all the threadlets of equal length?
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then follows the description of each test case.
In a single line of each test case, there are three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the lengths of the threadlets.
For each test case, output "YES" if it is possible to make all the threadlets of equal length by performing at most three operations, otherwise output "NO".
You can output "YES" and "NO" in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
151 3 25 5 56 36 127 8 76 3 34 4 1212 6 81000000000 1000000000 10000000003 7 19 9 19 3 62 8 25 3 108 4 82 8 4
YES YES NO NO YES YES NO YES NO NO YES YES NO YES NO
Let's consider some testcases of the first test.
In the first testcase, you can apply following operations:
$$$1, 3, 2 \to 1, 2, 1, 2 \to 1, 1, 1, 1, 2 \to 1, 1, 1, 1, 1, 1$$$.
In the second testcase, you can do nothing, the threadlets are already of equal length.
In the third testcase, it isn't possible to make threadlets of equal length.
Kristina has a matrix of size $$$n$$$ by $$$n$$$, filled with lowercase Latin letters. The value of $$$n$$$ is even.
She wants to change some characters so that her matrix becomes a perfect square. A matrix is called a perfect square if it remains unchanged when rotated $$$90^\circ$$$ clockwise once.
Here is an example of rotating a matrix by $$$90^\circ$$$:
In one operation, Kristina can choose any cell and replace its value with the next character in the alphabet. If the character is equal to "z", its value does not change.
Find the minimum number of operations required to make the matrix a perfect square.
For example, if the $$$4$$$ by $$$4$$$ matrix looks like this:
$$$$$$\matrix{ a & b & b & a \cr b & c & \textbf{b} & b \cr b & c & c & b\cr a & b & b & a \cr }$$$$$$
then it is enough to apply $$$1$$$ operation to the letter b, highlighted in bold.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^2$$$) — the number of test cases.
Then follows the description of each test case.
The first line of each test case contains a single even integer $$$n$$$ ($$$2 \le n \le 10^3$$$) — the number of rows and columns in the matrix.
Then follows $$$n$$$ lines, each containing exactly $$$n$$$ lowercase Latin letters.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.
For each test case, output a single number on a separate line: the minimum number of operations required for Kristina to obtain a perfect square.
54abbabcbbbccbabba2abba6codeforcescodeforcescodeforcescodefo4baaaabbabababaab4bbaaabbaaabaabba
1 2 181 5 9
The first test case is explained in the problem statement.
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. You can perform the following operation on it:
For example, let's consider the array $$$a$$$ = [$$$100, 2, 50, 10, 1$$$] with $$$5$$$ elements. Perform two operations on it:
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases.
Then follows the description of each test case.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of elements in the array $$$a$$$.
The second line of each test case contains exactly $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^6$$$) — the elements of the array $$$a$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.
For each test case, output a single line:
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as a positive answer).
75100 2 50 10 131 1 148 2 4 2430 50 27 20275 4024 432 3 1
YES YES NO YES NO YES NO
The first test case is explained in the problem statement.
Given a sequence of integers $$$a$$$ of length $$$n$$$.
A sequence is called beautiful if it has the form of a series of blocks, each starting with its length, i.e., first comes the length of the block, and then its elements. For example, the sequences [$$$\color{red}{3},\ \color{red}{3},\ \color{red}{4},\ \color{red}{5},\ \color{green}{2},\ \color{green}{6},\ \color{green}{1}$$$] and [$$$\color{red}{1},\ \color{red}{8},\ \color{green}{4},\ \color{green}{5},\ \color{green}{2},\ \color{green}{6},\ \color{green}{1}$$$] are beautiful (different blocks are colored differently), while [$$$1$$$], [$$$1,\ 4,\ 3$$$], [$$$3,\ 2,\ 1$$$] are not.
In one operation, you can remove any element from the sequence. What is the minimum number of operations required to make the given sequence beautiful?
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then follows the descriptions of the test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the sequence $$$a$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — the elements of the sequence $$$a$$$.
It is guaranteed that the sum of the values of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single number — the minimum number of deletions required to make the sequence $$$a$$$ beautiful.
773 3 4 5 2 6 145 6 3 263 4 1 6 7 731 4 351 2 3 4 551 2 3 1 254 5 5 1 5
0 4 1 1 2 1 0
In the first test case of the example, the given sequence is already beautiful, as shown in the statement.
In the second test case of the example, the sequence can only be made beautiful by removing all elements from it.
In the fifth test case of the example, the sequence can be made beautiful by removing the first and last elements. Then the sequence will become [$$$2,\ 3,\ 4$$$].
You have a tree with $$$n$$$ vertices, some of which are marked. A tree is a connected undirected graph without cycles.
Let $$$f_i$$$ denote the maximum distance from vertex $$$i$$$ to any of the marked vertices.
Your task is to find the minimum value of $$$f_i$$$ among all vertices.
For example, in the tree shown in the example, vertices $$$2$$$, $$$6$$$, and $$$7$$$ are marked. Then the array $$$f(i) = [2, 3, 2, 4, 4, 3, 3]$$$. The minimum $$$f_i$$$ is for vertices $$$1$$$ and $$$3$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree and the number of marked vertices, respectively.
The second line of each test case contains $$$k$$$ integers $$$a_i$$$ ($$$1 \le a_i \le n, a_{i-1} \lt a_i$$$) — the indices of the marked vertices.
The next $$$n - 1$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ — the indices of vertices connected by the $$$i$$$-th edge.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the minimum value of $$$f_i$$$ among all vertices.
67 32 6 71 21 32 42 53 63 74 41 2 3 41 22 33 45 111 21 31 41 55 24 51 22 31 44 510 81 2 3 4 5 8 9 102 1010 55 33 11 77 44 98 96 110 91 2 4 5 6 7 8 9 101 33 99 44 1010 66 77 22 55 8
2 2 0 1 4 5
36 131 21 33 43 52 65 31 2 51 21 32 43 57 123 22 66 15 67 64 5
0 2 0
Anya received a string $$$s$$$ of length $$$n$$$ brought from Rome. The string $$$s$$$ consists of lowercase Latin letters and at first glance does not raise any suspicions. An instruction was attached to the string.
Start of the instruction.
A palindrome is a string that reads the same from left to right and right to left. For example, the strings "anna", "aboba", "level" are palindromes, while the strings "gorilla", "banan", "off" are not.
A substring $$$[l \ldots r]$$$ of string $$$s$$$ is a string $$$s_l s_{l+1} \ldots s_{r-1} s_r$$$. For example, the substring $$$[4 \ldots 6]$$$ of the string "generation" is the string "era".
A string is called beautiful if it does not contain a substring of length at least two that is a palindrome. For example, the strings "fox", "abcdef", and "yioy" are beautiful, while the strings "xyxx", "yikjkitrb" are not.
When an integer $$$x$$$ is added to the character $$$s_i$$$, it is replaced $$$x$$$ times with the next character in the alphabet, with "z" being replaced by "a".
When an integer $$$x$$$ is added to the substring $$$[l, r]$$$ of string $$$s$$$, it becomes the string $$$s_1 s_2 \ldots s_{l-1} (s_l + x) (s_{l+1} + x) \ldots (s_{r-1} + x) (s_r + x) s_{r+1} \ldots s_n$$$. For example, when the substring $$$[2, 4]$$$ of the string "abazaba" is added with the number $$$6$$$, the resulting string is "ahgfaba".
End of the instruction.
After reading the instruction, Anya resigned herself to the fact that she has to answer $$$m$$$ queries. The queries can be of two types:
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) - the number of test cases.
The descriptions of the test cases follow.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) - the length of the string $$$s$$$ and the number of queries.
The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of lowercase Latin letters.
The next $$$m$$$ lines contain the queries:
It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases do not exceed $$$2 \cdot 10^5$$$.
For each query of the second type, output "YES" if the substring $$$[l \ldots r]$$$ of string $$$s$$$ is beautiful, otherwise output "NO".
You can output "YES" and "NO" in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive answers).
512 8tedubcyyxopz2 2 51 4 8 22 1 71 3 5 401 9 11 31 10 10 92 4 102 10 1210 4ubnxwwgzjt2 4 102 10 101 6 10 82 7 711 3hntcxfxyhtu1 4 6 12 4 101 4 10 2113 2yxhlmzfhqctir1 5 9 31 8 13 152 3bp1 1 2 151 1 2 181 2 2 1000000000
YES NO NO YES NO YES YES YES
In the first test case of the first test, the following happens: