Homs boasts many wonderful things: a rich history, beautiful places, and a moderate climate. What truly makes Homs special, however, are its people. They are joyful and full of life.
The judges love the people of Homs' sense of humor. So tell the judges a funny joke and make them happy, just as they'll make you happy with accepted answers.
Any non-empty string with size less than 1000 will be accepted
Any non-empty string with size less than 1000 will be accepted
Any non-empty string with size less than 1000 will be accepted
A single string "tell us a joke"
Any non-empty joke with size less than 1000
tell us a joke
Mara gebna gat tekarkar gebna qaletlha Kiri Kiri
You are given an undirected tree on $$$n$$$ vertices, numbered from $$$1$$$ to $$$n$$$. Each vertex $$$v$$$ has an initial color $$$a_v$$$. You perform a uniformly random permutation of the colors $$$\{a_1, a_2, \dots, a_n\}$$$ over the $$$n$$$ vertices (all $$$n!$$$ permutations are considered different from each other).
After shuffling, define $$${ D = max_{\substack{u, \space v \space \in \{1, \space\space 2, \space\space \dots, \space\space \large{n}\} \\ a_u \neq a_v}} \mathrm{dist}(u,v). }$$$
where $$$\mathrm{dist}(u,v)$$$ is the number of edges on the unique simple path between $$$u$$$ and $$$v$$$. In other words, $$$D$$$ is the maximum distance between any two vertices that end up with different colors. If all the vertices are of the same color then $$$D$$$ is equal to $$$0$$$.
Since $$$\mathbb{E}[D]$$$ is a rational number $$$\frac{P}{Q}$$$ (with $$$Q$$$ coprime to $$$10^9 + 7$$$), output the value of $$$P \cdot Q^{-1} \bmod 10^9 + 7$$$, where $$$Q^{-1}$$$ denotes the modular inverse of $$$Q$$$ modulo $$$10^9 + 7$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$), the number of testcases.
Each test case is described by:
It is guaranteed that the sum of $$$n$$$ overall testcases does not exceed $$$5\times 10^5$$$.
For each test case, print a single integer — the expected value of $$$D$$$ after a uniformly random shuffle of the colors, taken modulo $$$10^9+7$$$.
1 8 3 5 1 4 2 5 7 8 2 8 2 4 6 8 7 4 5 1 2 1 3 1
4
Omar borrowed some money from his loyal and rich friend Rajaei. After successful trading, Omar now has $$$m$$$ dollars and an infinite amount of Liras. He wants to repay his debt to Rajaei over $$$n$$$ days.
You are given two arrays:
Find the minimum value $$$y$$$ such that $$$max(c_1,\space c_2, \dots,\space c_n) \le y$$$ and Omar can repay his debt using his dollars and liras.
The first line of the input contains a single positive integer $$$t$$$ $$$(1 \le t \le 10^5)$$$, the number of test cases.
The first line of each test case contains two positive integers $$$n$$$ and $$$m$$$ $$$(1 \le n \le 3 \times 10^5)$$$ $$$(1 \le m \le 10^9)$$$, the number of days and the amount of dollars Omar has.
The second line of each test case contains $$$n$$$ positive integers $$${a_1, \space a_2, \dots, \space a_N}$$$ $$$(1 \le a_i \le 10^9)$$$.
The third line of each test case contains $$$n$$$ positive integers $$${b_1, \space b_2, \dots, \space b_N}$$$ $$$(1 \le b_i \le 10^9)$$$.
It is guaranteed that the sum of $$$n$$$ overall test cases doesn't exceed $$$3 \times 10^5$$$.
For each test case output the minimum value $$$y$$$ such that $$$max(c_1,\space c_2, \dots,\space c_N) \le y$$$ and Omar can repay his debt using his dollars and liras.
16 231 8 2 2 5 107 3 8 2 2 3
4
For two positive integers $$$x$$$ and $$$y$$$, define $$$lud(x,y)$$$ as the smallest positive integer $$$z$$$ that divides $$$x$$$ and doesn't divide $$$y$$$. If there is no such element, then $$$lud(x,y) = -1$$$.
For example:
$$$lud(6,4) = 3$$$
$$$lud(8,10) = 4$$$
$$$lud(10,20) = -1$$$
Given an array $$$a$$$ of size $$$n$$$ and an integer $$$x$$$, for each $$$i$$$ $$$(1 \le i \le n)$$$, find $$$lud(x,a_i)$$$.
The first line contains two integers $$$n$$$ and $$$x$$$ $$$(1 \le n \le 10^6)$$$ $$$(1 \le x \le 10^{12})$$$, the length of the array $$$a$$$ and the integer $$$x$$$ respectively.
The second line contains $$$n$$$ integers $$$(1 \le a_i \le 10^{12})$$$, the elements of the array $$$a$$$.
Print $$$n$$$ integers, the $$$i_{ith}$$$ of which is $$$lud(x,a_i)$$$.
5 306 10 15 35 60
5 3 2 2 -1
Given two strings $$$a$$$ and $$$b$$$, each of length $$$n$$$.
You can make this operation at most once:
Choose two integers $$$l$$$ and $$$r$$$ such that $$$(1 \le l \le r \le n)$$$ and reverse the substring from $$$l$$$ to $$$r$$$ of the string $$$a$$$.
Your task is to tell whether it is possible to make string $$$a$$$ lexicographically smaller than string $$$b$$$.
The first line of the input contains a single positive integer $$$t$$$ $$$(1 \le t \le 10^5)$$$, the number of test cases.
The first line of each test case contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$, the length of strings $$$a$$$ and $$$b$$$.
The second line of each test case contains the string $$$a$$$ of length $$$n$$$.
The third line of each test case contains the string $$$b$$$ of length $$$n$$$.
Strings $$$a$$$ and $$$b$$$ contain only lowercase Latin letters.
It is guaranteed that the sum of $$$n$$$ overall test cases doesn't exceed $$$10^5$$$.
For each test case, print $$$\bf{Yes}$$$ if you can make string $$$a$$$ lexicographically smaller than string $$$b$$$ using at most one operation; otherwise, print $$$\bf{No}$$$.You may print each character in either case, for example $$$\bf{YES}$$$ and $$$\bf{yEs}$$$ will also be accepted.
62zaza3abbabb4abzaaaza3badabd3bbaabd6cbadcaabcdcb
Yes No No No Yes Yes
You are given an array $$$a$$$ of $$$n$$$ non-negative integers.
You need to split its elements into 2 non-empty sets $$$s_1$$$ and $$$s_2$$$, such that each element belongs to exactly one set. The value of the split is defined as the value of the following formula:
$$$$$${|and(s_1) - and(s_2)|}$$$$$$
where $$$and(s_1)$$$, $$$and(s_2)$$$ are the bitwise AND of the elements of the first and the second set in order, and $$$|x|$$$ is the absolute value of $$$x$$$.
You need to output the maximum value of a split.
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^5)$$$ — the number of testcases.
The first line of each testcase contains a single integer $$$n$$$ $$$(2 \le n \le 10^5)$$$ — the length of array $$$a$$$.
The following line contains $$$n$$$ non-negative integers $$$(a_1, \space a_2, \space ..a_n)$$$ $$$(1 \le a_i \le 10^9)$$$ — the elements of the array.
It is guaranteed that the sum of $$$n$$$ overall testcases does not exceed $$$10^5$$$.
For each testcase you need to output the maximum value of a split as described in the problem statement.
1107 6 2 1 8 2 8 1 1 7
8
For a permutation $$$p$$$ of size $$$n$$$, define the array $$$a$$$ of size $$$n - 1$$$ as the difference array,in other words $$$(a_i = p_i - p_{i-1})$$$ for each $$$(1 \lt i \lt = n)$$$.
A permutation $$$p$$$ is $$$\it{Mexy}$$$ if the $$$mex$$$ of the difference array $$$a$$$ is greater than or equal to $$$\lfloor \frac{2n}{3} \rfloor$$$.
The $$$mex$$$ of an array is the smallest $$$\bf{positive}$$$ integer $$$x$$$ that does not exist in the array.
For example: if we have the permutation $$$p = (1,3,2)$$$, then the difference array $$$a = (2,-1)$$$ and the $$$mex$$$ of array $$$a$$$ is 1.
Given an integer $$$n$$$, find any $$$\it{Mexy}$$$ permutation $$$p$$$ of size $$$n$$$.
Note that you don't have to find the permutation with the maximum $$$mex$$$ value of array $$$a$$$, just find any $$$\it{Mexy}$$$ permutation.
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 10^5)$$$, the number of test cases.
Each test case contains a single line with a single positive integer $$$n$$$ $$$(1 \le n \le 10^5)$$$, the size of the permutations $$$p$$$.
It is guaranteed there is at least one $$$\it{Mexy}$$$ permutation of size $$$n$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
For each test case print any $$$\it{Mexy}$$$ permutation of size $$$n$$$.
234
1 2 3 1 3 4 2
You are given a whiteboard with integers from $$$l$$$ to $$$r$$$ written on it, inclusive. Initially, the whiteboard contains the set of integers $$$\{l, l+1, \dots, r\}$$$. You will repeatedly perform the following two operations until the whiteboard is empty:
Your task is to calculate the final total score after the whiteboard becomes empty.
The first line contains an integer $$$T$$$ ($$$1 \le t \le 10^5$$$), the number of testcases. Each of the following $$$t$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 2 \times 10^9$$$).
For each testcase, print a single integer representing the final total score.
21 33 5
5 7
You are given a tree with $$$n$$$ nodes. Each node $$$i$$$ (where $$$1 \le i \le n$$$) has a treasure with value $$$a_i$$$. The edges connecting the nodes are of two types: strong or weak.
You start exploring this tree from node 1. You want to find a walk (a sequence of connected nodes) starting at node 1 that maximizes the total value of treasures collected. The treasure at a node is collected the first time you visit that node. Subsequent visits to the same node do not yield any more treasure value.
The rules for traversing the edges depend on their type:
Your walk can finish at any node in the tree. Determine the maximum possible sum of treasure values you can collect.
NOTE: When you step into the node, you can't skip the treasure you must collect it.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.
Each test case begins with a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of nodes in the tree.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the value of the treasure at each node.
The next $$$n-1$$$ lines describe the edges. Each line contains three integers $$$u, v, s$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$, $$$s \in \{0, 1\}$$$), representing an edge between node $$$u$$$ and node $$$v$$$. If $$$s=0$$$, the edge is weak. If $$$s=1$$$, the edge is strong.
It is guaranteed that the given graph is a tree. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, print a single line containing one integer — the maximum total value of treasures that can be collected starting from node 1.
251 1 1 1 11 2 01 3 11 4 12 5 131 2 31 2 01 3 0
5 4
In Nlogonia city there are $$$n$$$ families,the $$$i_{ith}$$$ family has $$$b_i$$$ boys and $$$g_i$$$ girls.
For two integers $$$l$$$ and $$$r$$$ $$$(1 \le l \le r \le n)$$$ when we consider families in the range $$$[l,r]$$$, if it is possible to arrange all the boys and girls whose families are in the given range in couples, then the range $$$[l,r]$$$ is good.
Note that each boy in the given range can marry any girl from the given range,but he can't marry a girl from his family.
Your task is to count the number of good ranges.
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 3 \times 10^5)$$$, the number of test cases.
The first line of each test case contains an integer $$$n$$$ $$$(1 \le n \le 3 \times 10^5)$$$, the number of families.
The second line of each test case contains $$$n$$$ integers $$$b_i$$$ $$$(1 \le b_i \le 10^9)$$$, the number of boys in each family.
The third line of each test case contains $$$n$$$ integers $$$g_i$$$ $$$(1 \le g_i \le 10^9)$$$, the number of girls in each family.
It is guaranteed that the sum of $$$n$$$ overall test cases doesn't exceed $$$3 \times 10^5$$$.
For each query in each test case print the number of good ranges.
532 2 21 1 441 2 2 52 1 3 443 2 2 13 1 1 352 1 2 3 11 2 1 1 352 3 1 2 33 3 2 3 2
1 2 2 4 1
There are $$$n$$$ kids standing in a line, indexed from $$$1$$$ to $$$n$$$. Each kid $$$i$$$ has a rating $$$r_i$$$. You need to distribute cookies to these kids such that the following conditions are met:
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$), representing the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), representing the number of kids.
The second line contains $$$n$$$ space-separated integers $$$r_1, r_2, \ldots, r_n$$$ ($$$1 \le r_i \le 1000$$$), representing the ratings of the kids.
For each test case, output a single integer: the minimum total number of cookies required to satisfy all conditions.
231 2 333 2 1
6 3
Given an array $$$a$$$ of size n. We call a set of indices $$$b_1, b_2, b_3, ..., b_m$$$ good if it satisfies $$$$$$b_1+1 \lt b_2, \space b_2+1 \lt b_3, \space b_3+1 \lt b_4, \space ...., \space b_{m-1}+1 \lt b_m $$$$$$ and so on. And the score of this good set is: $$$$$$max(a_{b_1}, \space a_{b_2}, \space a_{b_3}, \space ..., \space a_{b_m})$$$$$$ For each integer $$$ i \space (1 \le i \le n)$$$ output the minimum score of a good set of size $$$i$$$ or $$$-1$$$ if there are no good sets.
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^5)$$$, the number of test cases.
Each test case contains two lines: In the first line, there is a single integer $$$n$$$ $$$(1 \le n \le 10^6)$$$, the size of the array. In the second line, there are $$$n$$$ integers $$$a_1, a_2, a_3, ..., a_n (1 \le a_i \le 10^9)$$$, the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^6$$$.
For each test case, output n integers, the minimum score of a good set of size $$$i (1 \le i \le n)$$$ or $$$-1$$$ if there are no good sets.
51524 362 3 7 2 1 581 2 1 2 1 2 1 25100000 1000000 10000000 100000000 1000000000
5 3 -1 1 2 5 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 100000 10000000 1000000000 -1 -1
We say that the diameter of a tree is any longest simple path in that tree, and we measure the length of a path by the number of edges it contains.
You are given a positive integer $$$n$$$. Consider the undirected complete graph on vertices $$$\{1,2,\ldots,n\}$$$. A spanning tree $$$T$$$ is chosen uniformly at random among all spanning trees satisfying that the simple path between vertices $$$1$$$ and $$$n$$$ is a diameter of $$$T$$$. Equivalently, if $$$d(u,v)$$$ denotes the distance (number of edges) between $$$u$$$ and $$$v$$$ in $$$T$$$, then $$$$$$ d(1,n) \;=\; \max_{1 \le x \lt y \le n} d(x,y). $$$$$$
Let $$$$$$ D \;=\; d(1,n) $$$$$$ in the chosen tree. We have $$$$$$ \mathbb{E}[D] \;=\;\frac{P}{Q}, $$$$$$ a rational number, where $$$\mathbb{E}[D]$$$ denotes the expected (average) value of the random variable $$$D$$$ taken over all valid spanning trees $$$T$$$ chosen under the given condition.
You are also given an integer $$$m$$$. Since $$$\mathbb{E}[D]$$$ is a rational number $$$\frac{P}{Q}$$$ (with $$$Q$$$ coprime to $$$m$$$), output the value of $$$P \cdot Q^{-1} \bmod m$$$, where $$$Q^{-1}$$$ denotes the modular inverse of $$$Q$$$ modulo $$$m$$$.
The first line contains two integers:
For each testcase, output in the answer to the problem modulo $$$m$$$ in a separate line.
8 71178730912345678
0 1 2 355893657 305051707 211612447 511987367 529573609