And so the competition has begun!
The team consisting of Aidar, Begimai, and Viktor rushed to read the conditions of all $$$n$$$ problems to find the easiest ones.
The team agreed to read the problems in the following manner:
It is known that
Determine how many problems each team member will read.
The first line contains an integer $$$n$$$ $$$(3 \le n \le 15)$$$ — the number of problems in the competition.
The second line contains an integer $$$s$$$ $$$(1 \lt s \lt n)$$$ — the problem from which Begimai starts reading.
The third line specifies Begimai's reading direction:
In a single line, output three integers $$$a$$$, $$$b$$$, and $$$c$$$ $$$(1 \le a, b, c; a + b + c = n$$$ or $$$a + b + c = n + 1)$$$:
129L
5 5 3
87R
6 1 1
First test example
There are a total of $$$12$$$ problems in the competition.
Begimai started reading from problem $$$9$$$ and began moving towards problem $$$1$$$.
Second test example
There are a total of $$$8$$$ problems in the competition.
Begimai started reading from problem $$$7$$$ and began moving towards problem $$$8$$$.
After the guys submitted their first task, the question arose — which task should be solved next?
Begimai, who had experience in such competitions, suggested looking at the page with the "Results".
This page shows how many tasks each team has solved — and how many attempts the team made on each task:
Begimai explained that additional information about the difficulty of tasks can be extracted from this statistics:
The guys decided to collect a small statistics for each task:
The first line contains two integers $$$n$$$ and $$$p$$$ $$$(1 \le n, p \le 100)$$$ — the number of teams and the number of tasks in the results table.
The $$$i$$$-th of the following $$$n$$$ lines contains information about the results of the $$$i$$$-th team — $$$p$$$ pairs of values $$$R_{i, j}$$$, separated by spaces:
In the $$$j$$$-th of the $$$p$$$ lines, output three integers $$$S_j$$$, $$$T_j$$$, $$$F_j$$$ separated by spaces:
2 3+ 0 + 3 - 5+ 1 - 0 - 12
2 2 1 1 1 3 0 2 17
First test example
In the results table, there are $$$2$$$ teams and $$$3$$$ tasks:
In total, it turns out that
Victor completed the solution for the problem and, without waiting for feedback from the team, submitted it to the system.
Upon refreshing the submission page, Victor saw the unpleasant verdict Wrong Answer.
It was unpleasant for two reasons:
His teammates Aidar and Begimai noticed this.
They observed that Victor's solution used two integer variables $$$A$$$ and $$$B$$$, after which the result of their multiplication $$$C = A \cdot B$$$ was computed.
Moreover, all three variables were declared as $$$32$$$-bit.
Both Aidar and Begimai suspected that the program was experiencing integer overflow — a situation where the value of an integer does not fit into the specified data type.
The team could always rewrite it in Python later — right now they wanted to understand what data types should be used for $$$A$$$, $$$B$$$, and $$$C$$$.
Important Information
The first line contains an integer $$$A$$$ $$$(1 \le A \le 10^{18})$$$ — the value of variable $$$A$$$.
The second line contains an integer $$$B$$$ $$$(1 \le B \le 10^{18})$$$ — the value of variable $$$B$$$.
In the first line, output the integer $$$T_A$$$ — the required number of bits for variable $$$A$$$.
In the second line, output the integer $$$T_B$$$ — the required number of bits for variable $$$B$$$.
In the third line, output the integer $$$T_C$$$ — the required number of bits for variable $$$C$$$.
All three numbers $$$T_A, T_B, T_C$$$ can only take values $$$32$$$, $$$64$$$, or $$$128$$$:
20000100000
32 32 32
1000000300000
64 32 64
30000003000000000000
32 64 64
10000000000000000001000000000000000000
128 64 128
A Minute of Useful Information
First test example
All three numbers fit into a $$$32$$$-bit data type.
Second test example
$$$A$$$ and $$$B$$$ fit into a $$$32$$$-bit data type, but $$$C$$$ fits only into a $$$64$$$-bit one.
It is necessary to make either variable $$$A$$$ or $$$B$$$ $$$64$$$-bit.
Third test example
$$$A$$$ fits into a $$$32$$$-bit data type, but $$$B$$$ and $$$C$$$ fit only into a $$$64$$$-bit one.
Since $$$B$$$ is already $$$64$$$-bit, $$$A$$$ can remain $$$32$$$-bit.
Fourth test example
$$$A$$$ and $$$B$$$ fit into a $$$64$$$-bit data type, but $$$C$$$ fits only into a $$$128$$$-bit one.
It is necessary to make either variable $$$A$$$ or $$$B$$$ $$$128$$$-bit.
Important:
Artistic problem statement
Aidar finally finished writing the solution to the problem — he was confident in its correctness but doubted its efficiency.
Aidar's solution worked as follows: on each of the $$$n$$$ iterations of the loop, it performed $$$q$$$ calculations and added $$$k$$$ integers to the data structure.
Before submitting to the system, Aidar decided to show the final code to his teammates and ask for their opinions:
Based on the available information about Aidar's solution, determine what verdict it will receive.
Fixed values used in the problem
It is known that in the problem Aidar is solving, the limits are set to $$$1$$$ second and $$$256$$$ megabytes.
The first line contains an integer $$$n$$$ $$$(1 \le n \le 10^6)$$$ — the number of iterations of the loop in Aidar's solution.
The second line contains an integer $$$q$$$ $$$(0 \le q \le 10^6)$$$ — the number of calculations performed on each iteration of the loop.
The third line contains an integer $$$k$$$ $$$(0 \le k \le 10^6)$$$ — the number of integers added to the data structure on each iteration of the loop.
The fourth line contains a string $$$L$$$, denoting the programming language used for the solution:
In a single line, output the string $$$V$$$, denoting the expected verdict:
200002000200java
OK
1000000300cpp
ML
100000010000000py
TL
10000002000200java
TL and ML
First test example
Aidar wrote the solution to the problem in Java.
In total, the solution will perform $$$2 \cdot 10^4$$$ iterations, on each of which:
Thus, the solution:
Accordingly, this solution will receive the verdict OK.
Second test example
Aidar wrote the solution to the problem in C++.
In total, the solution will perform $$$10^5$$$ iterations, on each of which:
Thus, the solution
Accordingly, this solution will receive the verdict ML.
Third test example
Aidar wrote the solution to the problem in Python.
In total, the solution will perform $$$10^6$$$ iterations, on each of which:
Thus, the solution
Accordingly, this solution will receive the verdict TL.
Fourth test example
This test is completely analogous to the first test, except for the increased number of loop iterations.
In total, the solution will perform $$$2 \cdot 10^6$$$ iterations, on each of which:
Thus, the solution:
Accordingly, this solution may receive any of the verdicts — it is necessary to output TL and ML.
The championship director Artem is constantly improving the testing system, making it more stable, efficient, and user-friendly.
This time, Artem has upgraded the team sorting system in the results table. To test his modification, Artem decided to run it on the results of one of the previous championships.
However, a problem arose — Artem only has the log of submissions, but he does not have the final ranking of the teams.
Help Artem — based on the available information about the teams' submissions, calculate the final results and their rankings.
Rules for Sorting Teams and Determining Rankings
The first line contains two integers $$$n$$$ and $$$p$$$ $$$(1 \le n \le 10^3; 1 \le p \le 20)$$$ — the number of teams and the number of problems in the competition.
The second line contains an integer $$$q$$$ $$$(1 \le q \le 10^5)$$$ — the number of submission records in the log.
In the $$$j$$$-th of the following $$$q$$$ lines, information about the $$$j$$$-th submission in the system is provided — four integers $$$M_j$$$, $$$ID_j$$$, $$$T_j$$$, and $$$V_j$$$ are given separated by spaces:
It is guaranteed that the submissions in the log are ordered chronologically, i.e., $$$M_j \le M_{j + 1}$$$ for all $$$1 \le j \lt q$$$.
This also means that even if $$$M_j = M_{j + 1}$$$, it should be considered that the $$$j$$$-th submission occurred before the $$$(j + 1)$$$-th.
In the $$$i$$$-th of $$$n$$$ lines, output four integers $$$R_i$$$, $$$ID_i$$$, $$$S_i$$$, $$$X_i$$$ separated by spaces:
5 32315 1 1 030 2 2 030 1 1 143 3 1 043 2 1 165 3 1 080 3 2 087 3 1 199 2 2 199 5 2 0100 1 2 0100 4 1 0130 1 2 0130 5 2 1130 2 3 0135 5 2 0140 5 3 1199 2 3 0200 4 3 0200 1 2 1280 4 2 0290 2 3 0299 2 3 1
1 2 3 521 2 1 2 290 2 5 2 290 4 3 1 127 5 4 0 0
First test example
A total of $$$5$$$ teams participated in the competition, and $$$3$$$ problems were available for solving.
In total:
A few days before the competition, the problem authors Slava and Tolya got into a heated argument.
Slava claimed that the string $$$S$$$ of length $$$n$$$ is the best title for the problem.
Tolya insisted that the best title for the problem is the string $$$T$$$ of length $$$n$$$.
To avoid ruining their friendship over some strings, the guys decided to find a string that would satisfy both of them.
They formulated the following criteria for the string—compromise $$$P$$$:
Help the guys—find the string $$$P$$$ that satisfies the conditions described above.
The first line contains an integer $$$n$$$ $$$(1 \le n \le 5 \cdot 10^4)$$$—the length of the strings $$$S$$$ and $$$T$$$.
The second line contains the string $$$S$$$ $$$(|S| = n)$$$—the best title for the problem according to Slava.
The third line contains the string $$$T$$$ $$$(|T| = n)$$$—the best title for the problem according to Tolya.
It is guaranteed that the strings $$$S$$$ and $$$T$$$ consist only of lowercase Latin alphabet characters.
In a single line, output the string $$$P$$$—the compromise string that satisfies the following conditions:
If there are multiple strings $$$P$$$ that satisfy the conditions—output any.
4axcypbqd
kmmk
7qwertyujhgfdsa
oueieuo
Palindrome—a string that reads the same forwards and backwards.
Examples of palindromes: tenet, abacaba, pqqp, d.
Distance $$$d(A, B)$$$ between strings $$$A$$$ and $$$B$$$ of the same length $$$n$$$ is calculated as $$$\sum{|A_i - B_i|}$$$, where $$$A_i - B_i$$$ is the difference in positions of characters $$$A_i$$$ and $$$B_i$$$ in the Latin alphabet.
First test example
The string $$$S$$$ is axcy.
The string $$$T$$$ is pbqd.
Examples of possible strings $$$P$$$: kmmk, oddo, eeee, and many others.
The total distance $$$d(S, P) + d(T, P)$$$ for $$$P$$$ = kmmk will be:
It can be shown that $$$72$$$ is the minimum possible value for suitable strings $$$P$$$.
In search of inspiration for problems, Slava went to scour the vastness of the internet — and found an interesting riddle.
The riddle took the form $$$A + B = C$$$, where the digits of the numbers $$$A$$$, $$$B$$$, and $$$C$$$ were replaced by letters from the Latin (or other) alphabet.
Moreover, three additional rules applied:
The solution to such riddles is any substitution "letter — digit" that transforms the expression into an identity.
For the given riddle of the described form, you need to:
The first line contains the string $$$SA$$$ $$$(1 \le |SA| \le 3)$$$ — the string corresponding to the number $$$A$$$ in the riddle.
The second line contains the string $$$SB$$$ $$$(1 \le |SB| \le 3)$$$ — the string corresponding to the number $$$B$$$ in the riddle.
The third line contains the string $$$SC$$$ $$$(1 \le |SC| \le 4)$$$ — the string corresponding to the number $$$C$$$ in the riddle.
It is guaranteed that the strings $$$SA$$$, $$$SB$$$, and $$$SC$$$ consist only of uppercase Latin alphabet letters.
In the first line, output an integer $$$R$$$ $$$(0 \le R \le 10^9)$$$ — the number of solutions to this riddle.
If $$$R \gt 0$$$, then in the next three lines output any of the solutions to the riddle:
ABCDEFAAAZ
72 123 987 1110
AAABBBCDC
0
PQSTPV
0
XYX
0
First test example
The riddle ABC + DEF = AAAZ can be solved, for example, as $$$123 + 987 = 1110$$$:
Examples of other possible solutions:
Second test example
The riddle AAA + BBB = CDC has no solutions, as in this case
Third test example
The riddle PQ + ST = PV has no solutions, as in this case the number represented by ST must have a leading zero, which is not allowed.
Fourth test example
The riddle X + Y = X has no solutions, as in this case the number represented by Y must equal zero, which is not allowed.
The competition has ended — and now Artem only needs to check the submissions of the teams for plagiarism.
Artem has a total of $$$n$$$ submissions, and checking the $$$i$$$-th submission will take $$$A_i$$$ quanta of time.
The problem is that the checking cannot take too long — it must be completed in no more than $$$T$$$ quanta of time.
To speed up the process, Artem can parallelize it by allocating $$$d$$$ threads. In this case, the $$$i$$$-th submission will be checked in $$$\lceil\frac{A_i}{d}\rceil$$$ quanta of time (the result of integer division, rounded up).
Help Artem find the minimum number of threads $$$d$$$ such that $$$\sum{\lceil\frac{A_i}{d}\rceil} \le T$$$.
The first line contains two integers $$$n$$$ and $$$T$$$ $$$(1 \le n \le 2 \cdot 10^5; n \le T \le 10^{12})$$$ — the number of available submissions.
The second line contains $$$n$$$ integers $$$A_i$$$ $$$(1 \le A_i \le 10^{12})$$$ — the number of quanta of time required to check the $$$i$$$-th submission.
In a single line, output an integer $$$d$$$ $$$(1 \le d \le 10^{12})$$$ — the minimum number of threads such that $$$\sum{\lceil\frac{A_i}{d}\rceil} \le T$$$.
5 2215 130 120 78 43
20
First test example
For $$$d = 20$$$, the submissions are checked in:
In total, for $$$d = 20$$$, $$$1 + 7 + 6 + 4 + 3 = 21$$$ quanta of time are used.
For $$$d = 19$$$, the submissions are checked in:
In total, for $$$d = 19$$$, $$$1 + 7 + 7 + 5 + 3 = 23$$$ quanta of time are used.
Similarly, it can be shown that for all $$$1 \le d \lt 19$$$, the number of quanta of time is also at least $$$23$$$.
Thus, it follows that for $$$T = 22$$$, the value $$$d = 20$$$ is the minimum possible.