You are given an array $$$A$$$ of length $$$N$$$. Count the number of subarrays$$$^\dagger$$$ such that the number of elements divisible by $$$K$$$ is divisible by $$$K$$$.
$$$\dagger$$$ A subarray is obtained by deleting several (possibly zero) elements from the start of the array and several (possibly zero) elements from the end of the array.
The first line of the input consists of two space-separated integers $$$N$$$ and $$$K$$$ ($$$1 \le N \le 10^5$$$, $$$1 \le K \le 10^9$$$) — the number of elements in the array and the integer $$$K$$$ from the problem statement, respectively.
The second line of the input consists of $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \le A_i \le 10^9$$$).
Output one line containing a single integer — the answer to the problem.
7 31 9 3 4 5 6 6
7
2 10000000001 1000000000
1
In the first sample test, the subarrays are:
In the second sample test, there's only one subarray: [$$$1$$$] $$$1000000000$$$. This subarray has $$$0$$$ elements divisible by $$$K = 1000000000$$$, and $$$0$$$ is divisible by $$$1000000000$$$.
There are $$$N$$$ computers; each one is either turned on or off.
The computers are connected to each other by $$$N - 1$$$ cables; the connections form a tree$$$^\dagger$$$.
You can do the following operation:
Determine whether it is possible to make all the computers turned on.
$$$\dagger$$$ A tree is a connected undirected graph with $$$N$$$ nodes and $$$N - 1$$$ edges.
The first line of the input 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$$$ ($$$1 \le N \le 2 \cdot 10^5$$$) — the number of computers.
The second line of each testcase consists of $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$A_i \in \{0, 1\}$$$) — the initial state of each computer. If $$$A_i = 0$$$, then the $$$i$$$-th computer is turned off, and if $$$A_i = 1$$$, then the $$$i$$$-th computer is turned on.
Each of the following $$$N - 1$$$ lines consists of two space-separated integers $$$U$$$ and $$$V$$$ ($$$1 \le U, V \le N$$$, $$$U \neq V$$$) — a cable between the computers $$$U$$$ and $$$V$$$ exists.
It is guaranteed that the sum of $$$N$$$ over all testcases does not exceed $$$2 \cdot 10^5$$$.
Output $$$T$$$ lines, each containing a single string "Yes" (without quotes) if it is possible to make all the computers turned on, or "No" (without quotes) otherwise.
You may print each letter of "Yes" and "No" in any case (for example, "yEs", "yes", "No", "NO" will all be accepted).
350 1 0 1 11 21 33 43 581 1 0 0 0 0 0 12 13 24 35 46 57 68 741 0 0 01 22 33 4
YES NO YES
Given a string $$$S$$$ of length $$$N$$$, find the length of the longest substring$$$^\dagger$$$ $$$R$$$ such that: $$$$$$\sum_{c=\texttt{'a'}}^{\texttt{'z'}} freq[c] \cdot C \ge |R| \cdot max(R)$$$$$$
Where:
$$$\dagger$$$ Substring: obtained by deleting several (possibly zero) characters from the start of the string and several (possibly zero) characters from the end of the string.
The first line of the input contains a single integer $$$N$$$ ($$$1 \le N \le 10^5$$$) — the length of the string $$$S$$$.
The second line of the input contains a string $$$S$$$ of length $$$N$$$, consisting of lowercase English letters.
Output one line containing a single integer — the length of the longest substring that satisfies the condition.
4abcd
1
3bba
2
Given an array $$$A$$$ of length $$$N$$$, and a positive integer $$$K$$$.
Consider the following procedure to determine whether a subarray$$$^\dagger$$$ $$$A[L \dots R]$$$ is considered good or not:
Your task is to count the number of good subarrays in $$$A$$$.
$$$\dagger$$$ A subarray is obtained by deleting several (possibly zero) elements from the start of the array and several (possibly zero) elements from the end of the array.
$$$\ddagger$$$ The maximum subarray sum in an array $$$B$$$ of length $$$M$$$ is equal to the maximum value of $$$B_L + B_{L + 1} + ... + B_R$$$ over all pairs of integers $$$L$$$, $$$R$$$ such that $$$1 \le L \le R \le M$$$.
The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 10$$$) — the number of testcases.
The first line of each testcase contains two space-separated integers $$$N$$$ and $$$K$$$ ($$$1 \le N \le 10^5, 1 \le K \le 10^{9}$$$) — the size of the array and the required maximum subarray sum.
The second line of each testcase contains $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$-10^5 \le A_i \le 10^5$$$).
It's guaranteed that the sum of $$$N$$$ over all testcases doesn't exceed $$$10^5$$$.
Output $$$T$$$ lines, each line containing a single integer — the answer for the corresponding testcase.
33 12 1 23 11 -2 14 21 2 -3 4
1 5 2
Given an array $$$A$$$ consisting of $$$N$$$ positive integers.
A sequence of integers is considered $$$\textbf{good}$$$ if the following condition holds:
Your task is to count the number of different$$$^\ddagger$$$ non-empty good subsequences$$$^\dagger$$$ of $$$A$$$. Since the answer can be very large, print the answer modulo $$$10^9 + 7$$$.
$$$\dagger$$$ A sequence $$$B$$$ is a subsequence of $$$A$$$ if $$$B$$$ can be obtained from $$$A$$$ by deleting several (possibly none or all) elements (not necessarily adjacent).
$$$\ddagger$$$ Two subsequences are considered different if the sets of indexes of their elements in the original sequence are different; that is, the values of the elements are not considered when comparing the subsequences.
The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$) — representing the number of testcases.
The first line of each testcase contains a single integer $$$N$$$ ($$$1 \le N \le 10^6$$$) — representing the number of elements in $$$A$$$.
The second line of each testcase contains $$$N$$$ space-separated integers ($$$1 \le a_i \lt 2^{30}$$$) — representing the elements of the array $$$A$$$.
It's guaranteed that the sum of $$$N$$$ over all test cases doesn't exceed $$$10^6$$$.
For each test case, print a new line containing a single integer representing the number of good subsequences, modulo $$$10^9 + 7$$$.
6121322 321 431 2 7310 3 2
1 0 2 2 4 4
In the annual Syrian Collegiate Programming Contest for Private Universities, there's a running joke among teams: the first problem — affectionately called "The Extreme" — is supposed to be the easiest one in the entire contest.
Before the contest begins, coaches often tease the teams with the same iconic question:
"What'll You Do If You Didn't Solve The Extreme?"
The question is always asked exactly this way — with the same wording, the same capitalization, and yes... even the question mark at the end.
If a participant hears this question and responds with:
"I Guess We'll Never Know"
— they're officially forgiven.
Your task is to write a program that reads the exact question from the input and responds with the standard answer.
A single line containing a string represents the question.
You have to out put the phrase "I Guess We'll Never Know" exactly as it is (no extra spaces and the same cases).
What'll You Do If You Didn't Solve The Extreme?
I Guess We'll Never Know
You are given a string $$$S$$$ of length $$$N$$$ and a set of $$$M$$$ strings $$$\{T_1, T_2, \dots, T_m\}$$$.
You want to select as many non-overlapping substrings$$$^\dagger$$$ of $$$S$$$ as possible such that each selected substring is exactly equal to one of the $$$M$$$ strings.
$$$\dagger$$$ Substring: obtained by deleting several (possibly zero) characters from the start of the string and several (possibly zero) characters from the end of the string.
The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 10^5$$$) — the number of testcases.
The first line of each testcase contains two space-separated integers $$$N$$$ and $$$M$$$ ($$$1 \le N, M \le 10^5$$$).
The second line of each testcase contains the string $$$S$$$ of length $$$N$$$, consisting of lowercase English letters.
Each of the next $$$M$$$ lines contains one string $$$T_i$$$ ($$$1 \le |T_i| \le 20$$$).
It is guaranteed that $$$\sum_{i=1}^{M} |T_i|$$$ over all the testcases does not exceed $$$4 \cdot 10^5$$$.
It is guaranteed that $$$\sum |S|$$$ over all test cases does not exceed $$$ 2 \cdot 10^5$$$.
Output $$$T$$$ lines each containing a single integer — the maximum number of pairwise non-overlapping substrings of $$$S$$$ such that each substring equals one of the $$$M$$$ given strings.
27 2arwhwararw7 1arwhwarar
4 2
There is a directed graph consisting of $$$n$$$ levels. Each level $$$i$$$ contains $$$a_i$$$ nodes arranged in a linear sequence.
Alhelue and Ahdali are playing a game on a graph like this. Initially, a stone is placed at the first node in level $$$1$$$. Each player, on their turn, selects a node neighbor to the current stone position and moves the stone directly to that node.
The goal is to move the stone to the last node in level $$$n$$$. The player who performs this final move wins.
You are given:
Determine which player has a winning strategy assuming both play optimally. The first player always starts.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$), representing the number of test cases.
The first line of each test cases contains an integer $$$n$$$ $$$(1 \le n \le 10^5)$$$.
The second line of each test cases contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^{18})$$$.
It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
Print First if the first player has a winning strategy, or Second if the second player will win assuming optimal play.
234 3 213
First Second
You are given an array $$$A$$$ consisting of $$$N$$$ positive integers, and a positive integer $$$X$$$.
Count the number of pairs of integers $$$(i, j)$$$ ($$$1 \le i \lt j \le N$$$) that satisfy the following:
The first line of the input contains two space-separated integers $$$N$$$ and $$$X$$$ ($$$1 \le N \le 10^6$$$, $$$1 \le X \le 10^6$$$) — the length of the array $$$A$$$ and the value of $$$X$$$, respectively.
The second line of the input consists of $$$N$$$ space-separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \le A_i \le 10^6$$$).
Output one line containing a single integer — the number of pairs $$$(i, j)$$$ such that both $$$A_i + A_j$$$ and $$$A_i \cdot A_j$$$ are divisible by $$$X$$$.
3 22 2 3
1
4 22 4 6 3
3
Given an array $$$A$$$ consisting of $$$N$$$ positive integers where $$$1 \le A_i \le M$$$.
We define the shift operation as the following:
You have to process $$$Q$$$ queries of two types:
Note that you have to answer $$$T$$$ testcases.
The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 10$$$) — representing the number of testcases.
The first line of each testcase contains three integers $$$N, M$$$ and $$$Q$$$ ($$$1 \le N, M, Q \le 10^5$$$) — representing the size of the array, the value of $$$M$$$, and the number of queries.
The second line of each testcase contains $$$n$$$ space separated integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \le A_i \le M$$$) — representing the elements of the array.
Each line of the next $$$Q$$$ lines has one of the following forms:
It's guaranteed that the sum of $$$N$$$, the sum of $$$M$$$, and the sum of $$$Q$$$ over all testcases doesn't exceed $$$10^5$$$.
For each query of the second type, print one line containing a single integer — the value of $$$A_i$$$.
13 4 44 4 312 212 1
1 2
You have to write a program to decide if a student passed an exam or failed it.
A university exam is divided into a practical exam and a theoretical exam.
You should pass the practical exam to be allowed to take the theoretical exam.
The practical exam score is out of $$$40$$$, and the theoretical exam score is out of $$$60$$$. Thus, the total exam score is out of $$$100$$$ points, which is calculated by summing up the scores of the practical and theoretical exams.
You pass the practical exam if you score at least $$$18$$$ out of $$$40$$$, and you pass the full exam if you score at least $$$60$$$ out of $$$100$$$.
The first line of the input contains a single integer $$$P$$$ ($$$0 \le P \le 40$$$) — the student's score in the practical exam.
If the student passes the practical exam, the second line of the input will contain a single integer $$$T$$$ ($$$0 \le T \le 60$$$) — the student's score in the theoretical exam.
Output one line containing a single string which is either "Passed" (without quotes) if the student passed the exam or "Failed" (without quotes) otherwise.
Notice that the string must be either "Passed" (without quotes) or "Failed" (without quotes). Strings such as "passed" or "FAILED", etc. will not be accepted.
3052
Passed
10
Failed
In the first sample test, the student's score in the practical exam was $$$30$$$, which is not less than $$$18$$$. Thus, the student was able to take the theoretical exam. The student's score in the theoretical exam was $$$52$$$; thus, the student's total score is $$$82$$$, and they passed the exam.
In the second sample test, the student didn't pass the practical exam, and thus they were unable to take the theoretical exam, thus failing the exam with a total score of $$$10 + 0 = 0$$$.
Ahdali wants to learn more about math and physics. In his research, he discovered a point in any object called the center of mass. In geometry, one often assumes uniform mass density, in which case the center of mass coincides with the centroid.
Ahdali found this equation for the centroid of a weighted triangle (where all three points have weights): $$$$$$C_x = \frac{a \times x_1 + b \times x_2 + c \times x_3 }{a + b + c}, C_y = \frac{a \times y_1 + b \times y_2 + c \times y_3 }{a + b + c}$$$$$$
where $$$x_i$$$ and $$$y_i$$$ are the coordinates of the $$$i$$$-th point. and $$$a$$$, $$$b$$$, $$$c$$$, are the weights of the first, second and third point. respectively.
Shadi and Taim want to see if Ahdali understood the concept correctly, so they proposed an inverse problem: They will give Ahdali a point and the weights of a triangle (a, b, and c), and Ahdali must find a triangle with these weights and this centroid.
An additional constraint they added is that each of the triangle's sides must be longer than 1.
Whether Ahdali actually completed this task is another tale.
For the time being, you should take a crack at this problem.
Input consists of two lines. First line has three integers $$$a$$$, $$$b$$$, $$$c$$$. ($$$ 1 \le a,b,c \le 1000 $$$). The weights of the first, second, and third point on the triangle, respectively.
Second line has two integers $$$c_x$$$, $$$c_y$$$. ($$$ -1000 \le c_x, c_y \le 1000 $$$). The coordinates of the desired centroid.
Output three lines. Each line has two floating point numbers, representing the three points of the triangle.
All number in the output must be between $$$10^6$$$ and $$$-10^6$$$.
Your answer is considered correct if the square distance between the centroid of your triangle and the desired centroid is less than $$$10^{-9}$$$
1 1 10 0
-0.3333333333 -0.3333333333 0.6666666667 -0.3333333333 -0.3333333333 0.6666666667
Note that the order of the points you output matters. such that the first point has weight $$$a$$$ and the second has weight $$$b$$$. and the third has weight $$$c$$$.
Alice has string $$$s$$$ and Bob has string $$$t$$$, both initially equal to the single-character string "a". There are $$$q$$$ operations. Each operation is one of the following:
After each operation, both players may reorder the characters of their current strings to form the lexicographically smallest possible string. They then compare these two strings:
Both players play optimally at every step. Determine and output the result after each operation.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$), the number of test cases.
Then follow $$$T$$$ test cases. Each test case begins with a line containing a single integer $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$), the number of operations.
Each of the next $$$q$$$ lines has: op x k
where:
It is guaranteed that across all test cases, the total length of all appended strings i.e. $$$\sum |x| $$$ does not exceed $$$4\cdot10^5$$$.
For each operation in each test case, print one line:
231 aa 42 ab 32 aa 411 a 1
Bob Alice Alice Bob
A string $$$p$$$ is lexicographically smaller than a string $$$q$$$ if :