You are given $$$n$$$ points in 4-dimensional space: $$$p_1, ~p_2, ~\ldots, ~p_n$$$, where each point $$$p_i$$$ has coordinates $$$(x_i, ~y_i, ~z_i, ~w_i)$$$.
Your task is to find a point $$$o = (o_x, ~o_y, ~o_z, ~o_w)$$$ in 4-dimensional space such that the maximum distance from $$$o$$$ to any point $$$p_i$$$ is minimized. Formally, you need to minimize the value: $$$$$$ \max_{1 \leq i \leq n} \sqrt{(o_x - x_i)^2 + (o_y - y_i)^2 + (o_z - z_i)^2 + (o_w - w_i)^2} $$$$$$
The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^4)$$$ — the number of points.
The next $$$n$$$ lines each contain four integers $$$x_i, ~y_i, ~z_i, ~w_i$$$ $$$(-10^4 \leq x_i, ~y_i, ~z_i, ~w_i \leq 10^4)$$$ — the coordinates of the $$$i$$$-th point. All given points are unique.
Print four real numbers $$$o_x, ~o_y, ~o_z, ~o_w$$$ — the coordinates of the optimal point.
Your answer will be correct if it has an absolute or relative error of at most $$$10^{-6}$$$.
30 0 0 04 0 0 03 2 0 0
2 0.25 0 0
160 0 0 00 0 0 40 0 4 00 0 4 40 4 0 00 4 0 40 4 4 00 4 4 44 0 0 04 0 0 44 0 4 04 0 4 44 4 0 04 4 0 44 4 4 04 4 4 4
2 2 2 2
Once upon a time in a land of numbers and mysteries, a mathematician named Syra discovered a magical dice. This wasn't an ordinary dice — whenever thrown, it could reveal hidden secrets of the numbers it touched. Syra wanted to test its powers, so she devised a challenge for you, the brave coder.
The magical dice is a regular six-sided die with faces numbered from 1 to 6. If you throw this dice twice, you get two outcomes — let's call them $$$a$$$ and $$$b$$$, each ranging from $$$1$$$ to $$$6$$$. Your mission is to determine whether it's possible that the sum of these two throws, $$$a + b$$$, can be equal to a given integer $$$x$$$.
The input contains a single integer $$$x ~(1 \le x \le 20)$$$ — the target sum of two throws of the dice.
Print "Yes" if it's possible to get a sum of $$$x$$$ by throwing the dice twice, or "No" otherwise.
7
Yes
You are given a set $$$S$$$ of integers, initially containing $$$n$$$ elements. Each element in $$$S$$$ is assigned a unique index from $$$1$$$ to $$$n$$$. You are also given an integer $$$p$$$ (where $$$0 \le p \le n$$$).
You will perform the following sequence of operations until the set $$$S$$$ becomes empty:
The final value of $$$p$$$ after all deletions have been performed is the final score. What will be the expected final score if all operations are performed randomly?
You are given the value of $$$n$$$. For each possible initial value of $$$p$$$ (where $$$0 \le p \le n$$$), determine the expected final score after performing all deletions randomly.
An integer $$$n$$$ ($$$1 \le n \le 10^3$$$), the initial number of elements in the set $$$S$$$.
Print $$$n+1$$$ space-separated floating values, the expected final score after all elements have been deleted for each possible initial value of $$$p$$$ from $$$0$$$ to $$$n$$$.
Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. That is, if your answer is $$$a$$$, and the jury's answer is $$$b$$$, then the solution will be accepted if $$$\frac{|a-b|}{\max(1,|b|)} \le 10^{-6}$$$.
3
-3 -1.3333333333 1.3333333333 3
You are given an array $$$a = [a_1, ~a_2, ~\ldots, ~a_n]$$$ of $$$n$$$ integers.
For each integer $$$k$$$ from $$$1$$$ to $$$n$$$, consider the following operation:
You can perform this operation any number of times (possibly zero).
For each $$$k$$$ independently, determine the maximum possible value of the bitwise AND of all elements in the array after performing any number of such operations. That is, for each $$$k$$$ from $$$1$$$ to $$$n$$$, find the maximum achievable value of $$$(a_1 ~\& ~a_2 ~\& ~\ldots ~\& ~a_n)$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of the test cases follows.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$.
The second line 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 $$$5 \cdot 10^5$$$.
For each test case, print $$$n$$$ space-separated integers in a new line, where the $$$k$$$-th integer represents the maximum bitwise AND achievable for the given $$$k$$$.
2101 2 3 4 5 6 7 8 9 1052 4 3 5 6
15 15 15 15 15 4 0 0 0 0 7 7 3 0 0
You are given an array $$$a = [a_1, a_2, \dots, a_n]$$$ of length $$$n$$$.
An inversion is a pair of indices $$$(i, j)$$$ such that $$$1 \le i \lt j \le n$$$ and $$$a_i \gt a_j$$$. The inversion count of an array is the total number of inversions.
A cyclic shift of the first $$$k$$$ elements to the end of the array transforms $$$[a_1, a_2, \dots, a_k, a_{k+1}, \dots, a_n]$$$ into $$$[a_{k+1}, \dots, a_n, a_1, a_2, \dots, a_k]$$$.
For each $$$k = 1, ~2, ~\ldots, ~n - 1$$$, solve the following problem and print the answer.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The description of the test cases follows.
For each test case, the first line contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, print $$$n - 1$$$ space-separated integers in a new line, where the $$$k$$$-th integer is the answer for $$$k$$$.
242 3 3 154 3 5 3 3
0 2 0 1 1 1 1
You are given an array $$$a_1, ~a_2, ~\ldots, ~a_n$$$ of $$$n$$$ integers. For each element $$$a_i$$$, you can perform the following operation at most once:
Determine if it is possible to transform the array $$$a$$$ into a permutation of integers from 1 to $$$n$$$. A permutation of integers from 1 to $$$n$$$ is a sequence of $$$n$$$ distinct integers, each of which is between 1 and $$$n$$$ inclusive.
The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the size of the array.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — the elements of the array.
Print "Yes" if it is possible to make the array a permutation of integers from 1 to $$$n$$$. Otherwise, print "No".
31 3 7
Yes
21 2
Yes
23 3
Yes
63 5 2 6 5 3
Yes
In the first example, you can unset the first bit of $$$3 = (11)_2$$$ to get $$$2=(10)_2$$$. Then the array becomes $$$[1, 2, 7]$$$. Unset the third bit of $$$7=(111)_2$$$ to get $$$3=(011)_2$$$. We now have a permutation $$$[1, 2, 3]$$$.
In the second example, the array is already a permutation.
In the third example, you can unset the first bit of the first $$$3 = (11)_2$$$ to get $$$2=(10)_2$$$. Then the array becomes $$$[2, 3]$$$. Unset the second bit of the second $$$3=(11)_2$$$ to get $$$1=(01)_2$$$. We now have a permutation $$$[2, 1]$$$.
"SynergyX", a cutting-edge email service, is launching soon! To expedite the process, we need your help designing a registration system prototype.
The system operates as follows:
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), representing the number of operations. The following $$$n$$$ lines each contain an operation in the format: operation username, where operation is either a (add) or d (delete), and username is a non-empty string of length at most 30 consisting of lowercase Latin letters and digits.
For each operation, print the system's response on a separate line. Print OK for successful add operations. Print the suggested username if an add operation encounters a duplicate. Print DELETED for successful delete operations. Print INVALID if a delete operation fails to find the username.
11a abacabaa acabaa abacabaa acabad acabaa acabaa a1111111111d a222222222222222a a222222222222222a a222222222222222a a222222222222222
OK OK abacaba1 acaba1 DELETED OK OK INVALID OK a2222222222222221 a2222222222222222
HR of Synergy plans to set two specific weekend days for employees for the period from a given starting date to an ending date. These weekend days will remain fixed throughout the specified period, and the objective is to maximize the total number of working days, excluding both public holidays and weekend days.
The dates should follow the Gregorian calendar, meaning they should align with the standard calendar system, including leap years. A leap year is defined as any year that:
For example:
In leap years, February has 29 days instead of the usual 28.
A working day is any day that is neither a public holiday nor a designated weekend day. The HR wants to select two specific days of the week that will serve as weekend days. Your task is to help him choose these two days such that the total number of working days is maximized.
The input consists of multiple lines:
For each test case:
Each test case should be processed independently.
The sum of $$$H$$$ over all the test cases will not exceed $$$2000$$$.
All the date ranges are between '01-01-1900' and '31-12-3000', inclusive. The dates are guaranteed to be valid.
For each test case, output a single line containing two space-separated, title-cased days (e.g., "Friday Saturday") representing the weekend maximizing working days. Days are: 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'. If multiple pairs achieve this, output the lexicographically smallest (alphabetical order, comparing the first days, then the second). Note that "Saturday Friday" and "Friday Saturday" are considered different pairs.
For example:
110-10-2024 24-10-2024505-0111-10-202412-1015-10-202405-01-2024
Friday Saturday