Nour, also known as Khepri, is obsessed with numbers and mathematics. He always manages to find qualitative solutions to such problems. That's why his friend Abdelaleem attempted to challenge him with a problem and dared him to find the expected result within 3 minutes. As Abdelaleem expected, Nour was able to solve it and find the expected result within just one minute (thanks to his typing speed on the keyboard as well).
The problem was that Abdelaleem would give him a number $$$n$$$, and he wanted to count how many positive numbers smaller than or equal to $$$n$$$ consisted of an odd number of digits.
Can you solve this problem in a short time and beat Nour's record (just one minute)?
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The first and the only line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$).
For each test case, output on a single line the number of positive integers less than or equal to $$$n$$$ that consisted of an odd number of digits.
399999999999
9 909 9090909
Given two strings, $$$s$$$ and $$$t$$$, both containing only lowercase letters.
You can perform an operation where you choose two different lowercase letters, $$$c_1$$$ and $$$c_2$$$, and change all occurrences of $$$c_1$$$ to $$$c_2$$$ and vice versa in the string $$$s$$$.
The goal is to determine if it's possible to transform the string $$$s$$$ into the string $$$t$$$ using these operations in less than $$$10^{10}$$$ operations.
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 2*10^{5})$$$.
The second line contains the string $$$t$$$ ($$$1 \leq |t| \leq 2*10^{5})$$$.
it's guaranteed that $$$|s| = |t|$$$.
For each test case, output "YES" in a separate line if you can do the given task, otherwise output "NO".
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as positive answers.
2acdbbadcppcynkuvazrxvcnvxr
YES NO
In the first test:
You can transform acdbb to adcpp, as follows:
Choose $$$b$$$ as $$$c_1$$$ and $$$p$$$ as $$$c_2$$$ — acdbb becomes acdpp.
Then choose $$$c$$$ as $$$c_1$$$ and $$$d$$$ as $$$c_2$$$ — acdpp becomes adcpp.
Then you just need two operations $$$2 \leq 10^{10} $$$
Given two permutations $$$a$$$ and $$$b$$$ of length $$$n$$$. Determine their (LCIS) – the length of their longest common increasing subsequence.
The first line contains integer $$$T$$$ the number of test cases.
For each test case:
The first line of each test case contains the integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots a_n$$$ ($$$1\leq a_i \leq n$$$).
The third line contains $$$n$$$ integers $$$b_1, b_2, \dots b_n$$$ ($$$1\leq b_i \leq n$$$).
For each test case output one line containing the answer.
453 2 1 4 51 2 3 4 585 2 4 3 1 6 7 81 4 2 3 5 7 6 866 5 4 3 2 11 2 3 4 5 652 5 4 3 15 2 4 3 1
3 4 1 2
In the first test, the possible answers are: $$$2, 4, 5$$$, or $$$3, 4, 5$$$
In the second test, one of the possible answers is: $$$2, 3, 6, 8$$$
In the third test, any subsequence with size one can be an answer.
In the third test, one of the possible answers is: $$$2, 4$$$
Abdelaleem was wondering what is the area of the shape that is formed by two right-angle triangles, he knows that the formula for the area of the triangle is half of the triangle base multiplied by the height.
so he asked you to calculate double the area of the given right-angled triangle.
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The first line contains two integers $$$b$$$, and $$$h$$$ ($$$1 \leq b,h \leq 500$$$) – the base and height of the triangle, respectively.
For each test case, output the answer.
24 810 12
32 120
Abdelaleem has an array consisting of an infinite number of all non-zero digits ($$$1, 2, 3, 4, .\dots, 9$$$). Feeling bored (especially in the half hour before the Maghrib prayer during Ramadan), he decided to select any set of digits from the array, calculate their least common multiple (LCM), and then concatenate them together to form a new number. He recorded the value of each new number along with the LCM of the digits used to create it on a piece of paper.
He noticed that there were many numbers he couldn't form because he didn't have the digit zero. So, he decided that before using a number, he could multiply it by $$$10$$$ once and then use it.
For instance, consider the number $$$1910590$$$. Abdelaleem chose the digits $$$1$$$, $$$9$$$, then $$$1$$$ again (multiplied by $$$10$$$), followed by $$$5$$$ and $$$9$$$ (multiplied by $$$10$$$). Concatenating these digits results in $$$1910590$$$ – $$$(1)(9)(10)(5)(90)$$$ , and the LCM of the selected digits is computed as LCM$$$(1,9,10,5,90) = 90$$$.
Since we all know that the half hour before Maghrib in Ramadan lasted for about $$$10$$$ years, he generates all possible numbers that can be generated using the digits he had. After iftar, he challenged his brother Muhammad, who was still in his first year of computer science, asking him, "Can you tell me how many numbers, among all the numbers I've written down on paper, have a value between $$$l$$$ and $$$r$$$, with their LCM equal to $$$k$$$?"
Muhammad, Abdelaleem's brother, thought for a moment until he wrote code to solve this challenge, but Abdelaleem ate a lot and was too lazy to check his brother's code... So, he asked you to calculate the result so he could see if his brother's code was correct or not.
The first and the only line of the input contains three integers $$$l$$$, $$$r$$$, and $$$k$$$ ( $$$1 \leq l,r,k \leq 10^9, l \leq r$$$).
Output one line containing the answer.
12 70 6
9
1 10000 12
350
400 800 2
0
1 1000000000 720
17537385
102 169850 80
1137
In the first test, the numbers that Abdelaleem made are:
$$$16, 23, 26,32,36,61,62,63$$$ and $$$66$$$
Abdelaleem, while working on his problem set, has exhausted all his ideas and couldn't come up with more problems. Consequently, he is seeking help from his friend Salah. However, Salah insists that his problems are typically somewhat difficult and may not suit the community's level. Despite this, Abdelaleem tries to convince him that the community at Shorouk Academy is improving and has some talented individuals. Thus, he challenges Salah that there are people who can solve his problems. Salah, wishing for the improvement of the community's skill level, agrees not to propose a difficult problem and suggests a moderately challenging one instead.
The proposed problem is as follows:
You are given a string $$$s$$$ consisting of lowercase English letters with size $$$n$$$. Additionally, there are some queries on this string:
1. $$$i, c$$$ $$$( 1 \leq i \leq n )$$$ - You are asked to change the $$$i$$$-th character in the string $$$s$$$ to $$$c$$$.
2. $$$l, r$$$ $$$( 1 \leq l \leq r \leq n )$$$ - You are given a range and asked if it is possible to change at most one character within this range to make it a palindrome. If you can achieve this, print "YES"; otherwise, print "NO".
Can you solve this problem, or will it lead to Abdelaleem's frustration and Salah's mockery?
The first line contains integer $$$T$$$ the number of test cases.
For each test case:
The first line of each test case contains the integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$).
The second line contains a string $$$s$$$ with lowercase English letters.
The third line contains $$$q$$$ ($$$1\leq q \leq 10^5$$$).
Then $$$q$$$ lines each line one of two types of queries:
For each test case output for each type $$$2$$$ query "YES" or "NO".
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as positive answers.
110madamrasha72 1 52 4 71 6 a2 6 102 3 61 2 s2 2 8
YES YES YES NO YES
16zvaoqb42 3 62 1 51 3 n2 5 6
NO NO YES
Abdelalem noticed that people don't appreciate the importance of problem-solving skills. They seem to prioritize other things and overlook the significance of these skills. He believed that improving their problem-solving skills would enhance their overall thinking process. That's why he wanted his colleagues to organize a training sessions for the new batch at Shorouk Academy. They would provide them with training starting from the basics of programming to reaching a good level of problem-solving. To motivate people even more, he decided to create a simple system where mentors could award additional points to students during the training. In each session, the instructor would ask a question, and whoever answered correctly would receive a bonus. He would record this information in an Excel sheet. However, some individuals were tampering with the sheet, removing points from some students and adding points to others. Therefore, he decided to change this system and implement something simpler that wouldn't take much time to manage.
The new system would have two options. The first option would show the scoreboard, while the second option would allow instructors to add bonuses to someone. To protect the system, he would implement a password so that no one could tamper with the bonuses. However, upon further thought, he decided to let people attempt to implement the system themselves first. Can you do it? Keep in mind that he would test the system to ensure you've implemented it correctly using $$$q$$$ commands.
First, you will be provided with the number of students in the training followed by the password you're supposed to create for this system. Then, the list contains the names of the students, each on a new line. After that, you will be provided with the number of commands you're supposed to try on your system. Each command should be on a new line and fall into one of two types: scoreboard or bonus. The scoreboard command should print the current scoreboard and the ranking of each student. The bonus command is followed by the student's ID, the bonus they received, and the password. You should adjust the student's points if the password is correct and print "Updated successfully." If the password is incorrect, print "Wrong password please try again."
The first line contains one integer: $$$n$$$ ($$$1 \leq n \leq 100$$$), the number of students in the training, and $$$P$$$, the password for the system.
followed by $$$n$$$ lines, the $$$i$$$-th line containing the name of the student that have $$$id = i$$$ , each consisting of at most $$$100$$$ characters.
The next line contains an integer $$$q$$$ $$$(1 \leq q \leq 100)$$$, the number of commands to execute.
The following $$$q$$$ lines contain the commands. Each command is either:
"scoreboard" or "bonus id s pass", where $$$id$$$ ($$$1 \leq id \leq n$$$) is the student's ID, $$$s$$$ ($$$1 \leq s \leq 100$$$) is the bonus amount, and $$$pass$$$ is the password for the system.
it's guaranteed that the first command is bonus type
For each "scoreboard" command, print the current standings and ranks of each non-zero points student. Each line should display the rank, followed by the student's ID, name, and total points, separated by spaces. Students should be sorted in descending order of points, with ties broken by the student's ID in ascending order.
For each "bonus" command:
- If the password is correct, adjust the student's points according to the bonus amount and print "Updated successfully".
- If the password is incorrect, print "Wrong password please try again".
after each command outputs three dashes, see the sample output.
6 ShACAbdelaleemMohamedMostafaSamyYousefWalidMohamedSaraGamal10bonus 3 12 ShACbonus 1 8 ShACbonus 3 80 ShaCbonus 6 12 ShACscoreboardbonus 5 8 ShACbonus 2 3 ShACscoreboardbonus 1 10 ShACscoreboard
Updated successfully --- Updated successfully --- Wrong password please try again --- Updated successfully --- 1 3 MostafaSamy 12 1 6 SaraGamal 12 2 1 Abdelaleem 8 --- Updated successfully --- Updated successfully --- 1 3 MostafaSamy 12 1 6 SaraGamal 12 2 1 Abdelaleem 8 2 5 WalidMohamed 8 3 2 Mohamed 3 --- Updated successfully --- 1 1 Abdelaleem 18 2 3 MostafaSamy 12 2 6 SaraGamal 12 3 5 WalidMohamed 8 4 2 Mohamed 3 ---
3 DragonEmanGamalNourAbdulMalekZarzur8bonus 3 10 850bonus 1 8 Dragonbonus 2 3 Dragonscoreboardbonus 1 5 Dragonscoreboardbonus 3 50 Dragonscoreboard
Wrong password please try again --- Updated successfully --- Updated successfully --- 1 1 EmanGamal 8 2 2 Nour 3 --- Updated successfully --- 1 1 EmanGamal 13 2 2 Nour 3 --- Updated successfully --- 1 3 AbdulMalekZarzur 50 2 1 EmanGamal 13 3 2 Nour 3 ---
Abdelaleem (aka Yousef) has an array $$$a$$$ consisting of $$$n$$$ integers, which he will give to Yousef (aka Abdelaleem). Yousef's task is to select a subsequence $$$S$$$ of exactly $$$k$$$ elements from this array.
Define the function $$$f(S)$$$ as the difference between the maximum and minimum elements in the subsequence $$$S$$$: $$$f(S) = \text{max}(S) - \text{min}(S)$$$.
What is the expected value of $$$f(S)$$$ over all possible subsequences $$$S$$$ of size $$$k$$$ that Yousef may select?
A subsequence of a sequence $$$a$$$ is a sequence that can be derived from $$$a$$$ by deleting some (or none) of the elements without changing the order of the remaining elements. Formally, given a sequence $$$a$$$ of length $$$n$$$, a subsequence of $$$a$$$ can be represented as $$$a_{i_1}, a_{i_2}, ..., a_{i_k}$$$, where $$$1 \leq i_1 \lt i_2 \lt ... \lt i_k \leq n$$$.
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The first line contains two integers $$$n$$$ and $$$k$$$ $$$( 1 \leq k \leq n \leq 5 * 10^5 )$$$, the size of the array, and the size of subsequences to select, respectively.
The second line contains $$$n$$$ integers $$$ a_1, a_2, \dots, a_n $$$ $$$( -10^9 \leq a_i \leq 10^9 )$$$, the elements of array $$$a$$$.
For each test case, output one line containing the expected value of $$$f(S)$$$ over all possible subsequences $$$S$$$ of size $$$k$$$ that Yousef may select – module $$$(10^9+7)$$$.
Formally, let $$$M = 10^9 +7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not\equiv 0(mod M)$$$. Output the integer equal to $$$p$$$ $$$*$$$ $$$q^{-1} (mod M)$$$ . In other words, output such an integer $$$x$$$ that $$$0 \leq x \lt M$$$ and $$$x*q \equiv p(modM)$$$.
54 24 1 3 13 11 1 16 3-10 -10 10 10 10 -104 44 2 1 33 2-1 0 1
833333341 0 18 3 333333337
Abdelaleem has $$$n$$$ different drinks, each consisting of $$$a_i$$$ liters. He has $$$m$$$ friends coming to visit him on Eid, and he wants each friend to have an equal amount of the same drink, so he cannot serve the same drink in cups of different sizes and he must serve to all friends.
At the same time, he does not want to have a small quantity of juice left in the pitcher (strictly less than $$$k$$$). Therefore, he decided to divide each type of juice among them so that he could either serve the entire quantity to them and nothing remains, or serve them such that a quantity greater than or equal to $$$k$$$ remains. He can choose to not serve them at all.
Can you tell me what is the maximum quantity he can offer for each one of them?
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \leq n \leq 5 \times 10^5$$$)($$$1 \leq m,k \leq 10^9$$$) - the number of different drinks Abdelaleem has, and the number of friends they visit Abdelaleem, and the minimum allowable quantity of remaining liters, respectively.
The second line contains $$$n$$$ integers $$$a_1,a_2,…,a_n$$$ ($$$1 \leq a_i \leq 10^9$$$), the quantity of each drink.
For each test case, the output maximum quantity he can offer for each one of them.
14 6 21 18 10 25
7
In the first testcase :
Abdelaleem will leave the first juice because it cannot be divided in a way that satisfies any of the conditions.
For the second juice, he will give each person $$$3$$$ units (nothing will be left in the bottle).
The third juice will give each person one unit ($$$4$$$ units will remain in the bottle, which is more than the required $$$k=2$$$ units to remain).
The last juice will give each person $$$3$$$ units, leaving $$$7$$$ units in the bottle that cannot be divided altogether or further in a way that leaves more than $$$k=2$$$ units.
Abdelaleem has an integer $$$x$$$, yet he accidentally encounters the digit $$$d$$$. Fortunately, he has the ability to increment $$$x$$$ by one in a single operation ($$$x:= x + 1$$$). Could you assist him in determining the minimum number of operations required to ensure that $$$n$$$ no longer contains the digit $$$d$$$?
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The first line contains two integers $$$x$$$, and $$$d$$$ ($$$0 \leq d \leq 9$$$)($$$1 \leq x \leq 10^9$$$).
For each test case, output on a single line the minimum number of operations required to ensure that $$$n$$$ no longer contains the digit $$$d$$$.
421 58 8100 0484300 3
0 1 11 100
Abdelaleem and AbdulMalekZarzur, were engrossed in a peculiar challenge. Abdelaleem had a binary string $$$s$$$, a sequence of zeros and ones, and he dared AbdulMalekZarzur to find a substring within it that represented a binary representation of a prime number.
With furrowed brows, AbdulMalekZarzur accepted the challenge. He scrutinized the string, searching for patterns that would reveal the elusive primes. But try as he might, the binary sequence seemed to be devoid of any such substring.
Frustrated and disheartened, AbdulMalekZarzur sought advice from his wise friend, Yousef, renowned for his mathematical prowess. He beseeched Yousef for guidance, hoping to unravel the mystery of prime substrings.
But Yousef, in a surprising turn of events, declined to assist, urging AbdulMalekZarzur to embark on his own journey of discovery. Determined to prove himself, AbdulMalek Zarzur resolved to tackle the new challenge, armed with determination and mathematical insight.
As the sun dipped below the horizon, casting long shadows over Binaryville, AbdulMalekZarzur delved deeper into the binary labyrinth, his resolve unshaken. For in the realm of numbers, where mysteries abound, every challenge is an opportunity to uncover the hidden truths that shape our world.
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The first line contains the binary string $$$s$$$ ($$$1 \leq |s| \leq 5\times 10^5$$$).
For each test case, output "YES" in a separate line if AbdulMalekZarzur can find any substring that represented a binary representation of a prime number, otherwise output "NO".
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as positive answers.
31111101101
No Yes Yes
A substring of a binary string is a contiguous sequence of characters (bits) taken from the original binary string. For instance, if the binary string is "1010101", some of its substrings could be "10", "101", "1010", "10101", and so on. Each substring consists of consecutive characters from the original string, maintaining their order.
Abdelaleem has an array $$$a$$$ of $$$n$$$ integers and needs your assistance in finding the minimum positive integer $$$m$$$ such that $$$\text{gcd}(a_i, m) \geq 2$$$ for all $$$a_i$$$ in the array $$$a$$$.
The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 10$$$) – the number of test cases.
For each test case:
The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 5 \times 10^5)$$$ — the number of integers in the array $$$a$$$.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(2 \leq a_i \leq 50)$$$ — the elements of the array $$$a$$$.
For each test case, Output a single integer $$$m$$$ — the minimum positive integer such that $$$\text{gcd}(a_i, m) \geq 2$$$ for all $$$a_i$$$ in the array $$$a$$$.
424 31227 4773 4 6 7 8 9 10
6 2 329 42
Abdelaleem, while preparing for a contest to divide teams in his university, got distracted and forgot to prepare the part responsible for checking whether the code passed all the test cases or not. Can you write this part instead?
We will provide you with the number of test cases in the problem and the number of test cases in which the code succeeded. If the code passed all of them, print "AC"; if it failed at least one of them, print "WA".
The first line contains an integer $$$T$$$ – the number of test cases.
For each test case:
The input consists of two integers $$$n$$$ $$$(1 \leq n \leq 100)$$$ and $$$m$$$ $$$(0 \leq m \leq n)$$$, where $$$n$$$ represents the total number of test cases and $$$m$$$ represents the number of test cases in which the code succeeded.
For each test case, if the code succeeded in all test cases, print "AC". Otherwise, print "WA".
33 33 21 1
AC WA AC