For a positive integer $$$n$$$, define $$$f(n)$$$ to be the number of non-empty substrings of $$$n$$$ that are divisible by $$$3$$$. For example, the string $$$2573$$$ has $$$10$$$ non-empty substrings, three of which represent numbers that are divisible by $$$3$$$, namely $$$3$$$, $$$57$$$, and $$$573$$$. So $$$f(2573) = 3$$$.
The Giraffe thinks that if $$$f(n)$$$ is divisible by $$$3$$$, then we say that $$$n$$$ is a beautiful number.
Define $$$F(d)$$$ to be the number of $$$d$$$ digit numbers that are beautiful.
Find $$$F(d)$$$. Give your answer modulo $$$1\,000\,000\,007$$$.
The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
Each test case consists of a single integer $$$d$$$ ($$$1 \le d \le 10^5$$$).
The sum of $$$d$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
Print the answer.
226
30 290898
This is the easy version of the problem; the only difference between the easy and hard versions is $$$k = 1$$$.
Deep in the heart of the city lies ASZoo, a sprawling wildlife park known for its winding pathways, lush habitats, and the majestic herds of zebras in its savanna exhibit. As the annual Zebra Spotlight Festival approaches, the ASZoo team needs to map out the shortest route from every park corner to the nearest zebra enclosure, so visitors can dash off to see these striped wonders without getting lost.
In this problem, model the park as an undirected, unweighted, simple graph:
Among these locations, exactly $$$K$$$ contain zebra enclosures. For each location $$$i$$$, compute the minimum number of steps needed to reach any zebra enclosure. If $$$i$$$ itself has a zebra enclosure, its distance is $$$0$$$. If $$$i$$$ cannot reach any zebra enclosure, output $$$-1$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains 3 integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$), ($$$1 \le m \le min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2})$$$), ($$$k = 1$$$).
The next $$$m$$$ lines contains two integers, $$$u_i$$$, $$$v_i$$$ ($$$1 \le u, v \le n, u \neq v$$$), denots the edges. The $$${m + 2}^nd$$$ line contains $$$k$$$ integers ($$$ 1 \le a_i \le n$$$) denots the locations that contain zebra enclosures.
The sum of $$$n$$$, and $$$m$$$ doesn't exceed $$$2 \cdot 10^5$$$ over all test cases.
For each test case, print a single line containing the following:
For each location from $$$1$$$ through $$$n$$$, print the minimum number of pathway steps required to reach any zebra enclosure.
15 5 11 22 33 44 55 11
0 1 2 2 1
This is the hard version of the problem; the only difference between the easy and hard versions is $$$k$$$ ($$$1 \le k \le n$$$)
Deep in the heart of the city lies ASZoo, a sprawling wildlife park known for its winding pathways, lush habitats, and the majestic herds of zebras in its savanna exhibit. As the annual Zebra Spotlight Festival approaches, the ASZoo team needs to map out the shortest route from every park corner to the nearest zebra enclosure, so visitors can dash off to see these striped wonders without getting lost.
In this problem, model the park as an undirected, unweighted, simple graph:
Among these locations, exactly $$$K$$$ contain zebra enclosures. For each location $$$i$$$, compute the minimum number of steps needed to reach any zebra enclosure. If $$$i$$$ itself has a zebra enclosure, its distance is $$$0$$$. If $$$i$$$ cannot reach any zebra enclosure, output $$$-1$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains 3 integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$), ($$$1 \le m \le min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2})$$$), ($$$1 \le k \le n$$$).
The next $$$m$$$ lines contains two integers, $$$u_i$$$, $$$v_i$$$ ($$$1 \le u, v \le n, u \neq v$$$), denots the edges. The $$${m + 2}^nd$$$ line contains $$$k$$$ integers ($$$ 1 \le a_i \le n$$$) denots the locations that contain zebra enclosures.
The sum of $$$n$$$, and $$$m$$$ doesn't exceed $$$2 \cdot 10^5$$$ over all test cases.
For each test case, print a single line containing the following:
For each location from $$$1$$$ through $$$n$$$, print the minimum number of pathway steps required to reach any zebra enclosure.
15 5 11 22 33 44 55 11
0 1 2 2 1
There are a lot of animals in ASZoo, and each kind of animal has a family.
There is $$$n$$$ kind of animals, each kind has $$$a_i$$$ family member, count how many animals in the Zoo.
The first line of input consists of a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
The second line of input consists of $$$n$$$ integers $$$a_1, a_2, ... a_n$$$ ($$$1 \le a_i \le 100$$$).
Print the answer.
43 1 2 5
11
16
6
31 1 1
3
This is the easy version of the problem; the difference between the easy and hard versions is that the hard version requires queries.
Kilani the tiger is the greatest competitive programmer not only in ASZoo but also in the world. And he's well known as Az3ar, but at home they call him "keko", and he doesn't like this name.
He found a string with $$$n$$$ characters, and he wants to find the number of subsequences in the string that contain the word "keko" to determine whether people already know his name.
Given a string $$$s$$$ that consists of $$$n$$$ lowercase Latin letters, find how many subsequences are equal to the word "keko"; the answer will be very large. So, print it modulo $$$1\,000\,000\,007$$$.
A subsequence of a string is a string that can be obtained by removing several (possibly zero) characters from the original string.
For example, consider the string "abac", "aa", "ac", "ba" are subsequences of it, but "ca" is not.
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 test case consists of a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).
The second line of each test case consists of a string $$$s$$$ ($$$|s| = n$$$)
The sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
For each testcase, print the answer modulo $$$1\,000\,000\,007$$$..
26kkkeko6kkekoo
3 4
This is the hard version of the problem; the difference between the easy and hard versions is that the hard version requires queries.
Kilani the tiger is the greatest competitive programmer not only in ASZoo but also in the world. And he's well known as Az3ar, but at home they call him "keko", and he doesn't like this name.
He found a string with $$$n$$$ characters, and he wants to find the number of subsequences in the string that contain the word "keko" to determine whether people already know his name.
Given a string $$$s$$$ that consists of $$$n$$$ lowercase Latin letters. And you'll be given $$$q$$$ queries, on each query, find how many subsequences are equal to the word "keko" in the substring in range $$$l$$$, $$$r$$$ ($$$1 \le l \le r \le |s|$$$).
More formally, find the number of subsequences that equals "keko" in the substring $$$s_l, s_{l+1}, s_{l+2}, ..., s_{r-1}, s_3$$$.
The answer will be very large. So, print it modulo $$$1\,000\,000\,007$$$.
A subsequence of a string is a string that can be obtained by removing several (possibly zero) characters from the original string.
For example, consider the string "abac", "aa", "ac", "ba" are subsequences of it, but "ca" is not.
The input contains only one test case.
The first line consists of a single integer $$$n$$$, $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$).
The second line consists of a string $$$s$$$ ($$$|s| = n$$$)
The next $$$q$$$ lines consists of two integer $$$l_i$$$, $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$).
For each query, print the answer modulo $$$1\,000\,000\,007$$$..
6 4kkkeko1 62 63 61 5
3 2 1 0
In the wildlife outside ASZoo, there are living $$$n$$$ cheetahs and $$$m$$$ deers, and as we all know that the deers are the cheetahs' favorite food.
Each cheetah has power equal to $$$a_i$$$ ($$$1 \le i \le n$$$), and each deer has power equal to $$$b_i$$$ ($$$1 \le i \le m$$$).
The cheetah can eat a deer only if the deer's power is strictly less than the cheetah's power.
Each cheetah wants to eat one deer, and each deer can be eaten once. Can you know whether all the cheetahs will have their dinner or not?
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 test case consists of two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$).
The second line of each test case consists of $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 10^9$$$).
The third line of each test case consists of $$$m$$$ integers $$$b_1, b_2, ..., b_n$$$ ($$$1 \le b_i \le 10^9$$$).
The sum of $$$n$$$ and $$$m$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
For each test case, print "YES" if all cheetahs can eat deers, "No" otherwise (case insensitive).
22 33 24 2 14 61 1 1 11 1 1 1 1 1
Yes No
In the wildlife outside ASZoo, there are living $$$n$$$ cheetahs and $$$m$$$ deers, and as we all know that the deers are the cheetahs' favorite food.
Each cheetah has power equal to $$$a_i$$$ ($$$1 \le i \le n$$$), and each deer has power equal to $$$b_i$$$ ($$$1 \le i \le m$$$).
The cheetah can eat a deer only if the deer's power is strictly less than the cheetah's power.
Each cheetah wants to eat one deer, and each deer can be eaten once. Can you know whether all the cheetahs will have their dinner or not? And if they can, what is the index of the deer that each cheetah will eat?
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 test case consists of two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$).
The second line of each test case consists of $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 10^9$$$).
The third line of each test case consists of $$$m$$$ integers $$$b_1, b_2, ..., b_n$$$ ($$$1 \le b_i \le 10^9$$$).
The sum of $$$n$$$ and $$$m$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
For each test case, print "YES" if all cheetahs can eat deers, "No" otherwise (case insensitive). If the answer was "YES", print $$$n$$$ distinct integers $$$index_i$$$ denoting the $$$index$$$ of the deer the $$$i^{th}$$$ cheetah will eat. If there are multiple answers, print any of them.
22 33 24 2 14 61 1 1 11 1 1 1 1 1
Yes 2 3 No
There are two monkeys in ASZoo, the first one's age is $$$n$$$ and the second one is $$$m$$$, print the age of the younger monkey.
The input consists of two integers $$$n$$$, and $$$m$$$ ($$$ 1 \le n, m \le 100$$$).
Print the age of the younger monkey.
3 5
3
7 1
1
Zmeh is a zookeeper at ASZoo. He knows the number of animals in each family, so he wants to challenge you.
Given an array of $$$n$$$ strings $$$s$$$ denoting the kind of each animal in the zoo, and $$$q$$$ queries.
On each query, you'll be given a string $$$t$$$ and you must find the number of animals that are from that family.
The first line of input consists of two integers $$$n$$$, $$$q$$$ ($$$ 1 \le n, q \le 6 \cdot 10^4$$$).
The second line of input consists of $$$n$$$ strings $$$s_1, s_2, ..., s_n$$$ ($$$1 \le |s_i| \le 10$$$).
The next q lines consist of $$$t_i$$$ ($$$1 \le |t_i| \le 10$$$).
For each test case, print the number of animals that are from family $$$t_i$$$.
4 4dog cat dog dogdogcatdoglion
3 1 3 0
There is A huge cage in ASZoo that can contain up to $$$k$$$ animals.
There are $$$n$$$ families of animals, each of which has an infinite family members, and each kind of animal weighs $$$a_i$$$ ($$$1 \le i \le n$$$).
The zookeeper decided to put exactly $$$k$$$ animals in the cage, regardless of the kind or the weight. The zookeeper can put more than one animal of the same family in the cage, and can also discard an entire family and not putting them in the cage.
Find all possible total weights of animals that the zookeeper can put in the cage.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1000$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 1000$$$).
Print the only line with all the possible total weights of stolen products, separated by a space. The numbers should be printed in ascending order.
3 21 2 3
2 3 4 5 6
5 51 1 1 1 1
5
3 33 5 11
9 11 13 15 17 19 21 25 27 33
In ASZoo, the elephant wants to solve an interesting problem.
Given an array $$$a$$$ of length $$$n$$$ and array $$$b$$$ of length $$$m$$$, ($$$b$$$ values are unique).
The elephant wants to do the following operations until no element in $$$a$$$ exists in $$$b$$$.
And he keeps doing the same operation until the condition is met or the array becomes empty.
More formally, in the operation $$$i$$$ where ($$$i \equiv 1 (mod 2)$$$), the elephant deletes the element at the beginning of the array.
And in operation ($$$i \equiv 0 (mod 2)$$$), the elephant deletes the element at the end of the array.
Calculate the minimum number of operations to meet the condition.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case consists of two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$).
The second line of each test case consists of $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 10^6$$$).
The third line of each test case consists of $$$m$$$ integers $$$b_1, b_2, ..., b_n$$$ ($$$1 \le b_i \le 10^6$$$).
The sum of $$$n$$$ and $$$m$$$ doesn't exceed $$$2 \cdot 10^5$$$ over all test cases.
For each test case, print the answer.
25 31 2 3 4 55 7 25 11 2 3 4 57
3 0
Corvus the Crow, ASZoo's resident genius, loves tackling number-theory puzzles.
In this problem, Corvus is given a positive integer $$$n$$$ and must count how many unordered pairs of distinct numbers between $$$1$$$ and $$$n$$$ are coprime, The number could be very large, so print it modulo $$$1 000 000 007$$$.
A pair $$$(i,j)$$$ with $$$1 \le i \lt j \le n$$$ is called coprime if $$$\gcd(i,j) = 1$$$. Compute the total number of such pairs.
The only integer in the input is $$$n$$$, ($$$2 \le n \le 10^{11}$$$).
Print the answer.
100
3044
59
1086
1765
947722