You're given an sequence $$$a$$$ of size $$$n$$$.
Determine if there is a sequence $$$b$$$ that satisfies all the following conditions:
A subsequence of a given sequence is a sequence that can be derived from the given sequence by deleting some or no elements without changing the order of the remaining elements. For example,$$$[1,2]$$$ and $$$[1,1]$$$ are subsequences of $$$[1,2,1]$$$ but $$$[2,2]$$$ and $$$[3]$$$ are not.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot 10^5$$$).
The second line of each testcase contains $$$n$$$ integers $$$a_1,a_2,\ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
If there is a sequence $$$b$$$ that satisfies all the following conditions output YES.Otherwise,output NO.
321 221 164 1 5 4 1 1
YES NO YES
Test Case $$$1$$$:
$$$b=[1]$$$ is one of valid sequence.For index $$$i=1$$$,note $$$c=[a_2,a_2]=[2,2]$$$,then $$$b$$$ is not a subsequence of $$$c$$$.
Test Case $$$2$$$:
For index $$$i=1,2$$$,$$$c=[1,1]$$$ always holds.No matter which subsequence $$$b$$$ of $$$a$$$ you choose, $$$b$$$ must be a subsequence of $$$c$$$.
For two positive integers $$$x,y$$$,define $$$con(x,y)$$$ as the number obtained by connecting the decimal representation of $$$x$$$ with $$$y$$$, where $$$x$$$ is on the left and $$$y$$$ is on the right.For example $$$con(20,23)=2023,con(2,33)=233$$$.
You're given two integers $$$n,k$$$.You can choose an array $$$a$$$ of positive integers of size $$$n$$$,which satisfies $$$\Sigma_{i=1}^{n}a_i=k$$$.
Define the score as the number of prime numbers among all $$$con(a_i, a_j)(1\leq i,j\leq n)$$$.Find the minimum score you can get.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The only line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \le n \le k \le 10^9$$$).
For each test case, output a single integer — the minimum score you can get.
62 32 53 33 73 171 1000000000
1 1 9 2 0 0
Test Case $$$1$$$:
One of the optimal array $$$a$$$ is $$$[1,2]$$$.
For this array,$$$con(a_1,a_1)=11,con(a_1,a_2)=12,con(a_2,a_1)=21,con(a_2,a_2)=22$$$.
There's only one prime.It can be proven that $$$1$$$ reaches the minimum.
Test Case $$$2$$$:
One of the optimal array $$$a$$$ is $$$[2,3]$$$.
For this array,$$$con(a_1,a_1)=22,con(a_1,a_2)=23,con(a_2,a_1)=32,con(a_2,a_2)=33$$$.
There's only one prime.It can be proven that $$$1$$$ reaches the minimum.
Test Case $$$3$$$:
The only array $$$a$$$ you can choose is $$$[1,1,1]$$$.
For this array,$$$con(a_i,a_j)=11$$$ for all $$$1 \le i,j \le n$$$.
There're $$$9$$$ primes.It can be proven that $$$9$$$ reaches the minimum.
You're given an string $$$s$$$ of size $$$n$$$ composed of lowercase letters.
Define $$$f(C)$$$ as the character obtained by shifting the character $$$C$$$ to the left.Formally,$$$f(a)=z,f(b)=a,...,f(z)=y$$$.
You can do the following operation any number of times:
Find the minimum number of operations to make all characters in $$$s$$$ to $$$a$$$.If you can not make all characters in $$$s$$$ to $$$a$$$,output $$$-1$$$ instead.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot 10^5$$$).
The second line of each testcase contains a string $$$s$$$ of size $$$n$$$ composed of lowercase letters.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print a single integer — the minimum number of operations to make all characters in $$$s$$$ to $$$a$$$.If you can not make all characters in $$$s$$$ to $$$a$$$,output $$$-1$$$ instead.
52aa2ab2cc3amo4egzx
0 -1 2 26 29
Test Case $$$1$$$:
All characters in $$$s$$$ are already $$$a$$$ so you don't need to do any operations.
Test Case $$$2$$$:
You can not make all characters in $$$s$$$ to $$$a$$$.
Test Case $$$3$$$:
We use the following scheme: $$$cc\xrightarrow{i=1,j=2} bb\xrightarrow{i=1,j=2} aa$$$.
Test Case $$$4$$$:
We use the following scheme: $$$amo\xrightarrow{i=1,j=2} zlo\xrightarrow{i=1,j=2} yko \xrightarrow{i=1,j=2} ... \xrightarrow{i=1,j=2} oao \xrightarrow{i=1,j=3} nan \xrightarrow{i=1,j=3} mam \xrightarrow{i=1,j=3} ... \xrightarrow{i=1,j=3} aaa$$$.
A snake queue can be formed as an $$$n \cdot n$$$ grid graph.
When someone enter this queue, he is in position $$$(1,1)$$$.
Assume someone is in $$$(i,j)$$$ currently(and $$$(i,j)$$$ is not the endpoint of the queue),one second later:
There're $$$n \cdot n$$$ people.The $$$i_{th}$$$ person has a number $$$a_i$$$ in hi hand.In the $$$j_{th}(1\leq j \leq n^2)$$$ second,the $$$j_{th}$$$ person will enter this queue.
For example,$$$n=3$$$ and $$$a=[11,22,33,44,55,66,77,88,99]$$$,the following images show the status of the snake queue at certain times:
![]() | ![]() | ![]() |
You need to answer the $$$q$$$ queries.The $$$i_{th}$$$ query gives two integers $$$t_i,x_i$$$,which means you need to answer the sum of the numbers of all the people in the $$$x_{th}$$$ column in the $$$t_{th}$$$ second.
The first line of contains two integers $$$n,q$$$ ($$$2 \le n \le 2000$$$,$$$1 \le q \le 10^6$$$).
The second line of contains $$$n \cdot n$$$ integers $$$a_1,a_2,...,a_{n^2}(1 \leq a_i \leq 2000)$$$.
The next $$$q$$$ lines,the $$$i_{th}$$$ line contains two integers $$$t_i,x_i(1 \leq t_i \leq n^2,1 \leq x_i \leq n)$$$,which means you need to answer the sum of the numbers of all the people in the $$$x_{th}$$$ column in the $$$t_{th}$$$ second.
For each query, print a single integer in a new line — the sum of the numbers of all the people in the $$$x_{th}$$$ column in the $$$t_{th}$$$ second.
3 711 22 33 44 55 66 77 88 992 12 35 25 38 18 28 3
22 0 55 55 143 132 121
You're given a permutation $$$p$$$ of size $$$n$$$ and a piece of pseudocode:
sum:=0
for i:=1 to n
sort(1,i) #sort p[1],p[2],...p[i] in ascending order
for j:=1 to n
if(j is odd) sum:=sum+p[j]
else sum:=sum-p[j]
Output the final value of the variable $$$sum$$$.
The first line of input will contain a single integer $$$t(1 \leq t \leq 10^5)$$$, denoting the number of test cases.
Each test case consists of one line of input.
The first line of each test case contains an integer $$$n(1 \leq n \leq 4 \cdot 10^5)$$$.
The second line contains $$$n$$$ integers $$$p_1,p_2,...,p_n(1 \le p_i \le n,p$$$ is a permutation $$$)$$$.
The sum of $$$n$$$ over all will not exceed $$$4 \cdot 10^5$$$.
For each test case,output on a new line — the final value of the variable $$$sum$$$.
422 133 1 241 2 3 487 1 6 4 8 2 5 3
0 6 -8 30
Test Case $$$1$$$:
When $$$i=1,p=[2,1]$$$.The current value of $$$sum=0+2-1=1$$$;
When $$$i=2,p=[1,2]$$$.The current value of $$$sum=1+1-2=0$$$.
Test Case $$$2$$$:
When $$$i=1,p=[3,1,2]$$$.The current value of $$$sum=0+3-1+2=4$$$;
When $$$i=2,p=[1,3,2]$$$.The current value of $$$sum=4+1-3+2=4$$$;
When $$$i=3,p=[1,2,3]$$$.The current value of $$$sum=4+1-2+3=6$$$.
Since you are a good friend of Jaber and Eyad, they are asking for your help to solve this problem.
You are given a graph consisting of $$$n$$$ nodes, which initially has no edges. For each node $$$i$$$, there's a string $$$s_i$$$ of lowercase Latin letters written on it.
You have to process $$$q$$$ queries of two types:
The first line contains one integer number $$$n$$$ ($$$1 \le n \le 2 * 10^5$$$), the number of nodes in the given graph.
The following $$$n$$$ lines, the $$$i_{th}$$$ of them has the string $$$a_i$$$, the string written on the $$$i_{th}$$$ node.
The following line has one integer number $$$q$$$ ($$$1 \le q \le 2 * 10^5$$$), which is the number of queries.
The following $$$q$$$ lines have the queries in the following form:
It is guaranteed that the sum of lengths of $$$s_v$$$ doesn't exceed $$$5 * 10^5$$$, and sum of lengths of the query strings doesn't exceed $$$5 * 10^5$$$.
For each query of the second type, print in a single line the answer to the query.
4 a ab ba ca 7 2 2 abab 1 2 3 2 2 abab 1 1 3 2 2 acac 1 3 4 2 2 acac
2 3 2 3