AGI (artificial general intelligence) is around the corner, but it still cannot add two integers modulo prime. In this task, you can speed up the AGI revolution by training a one-layer perceptron model with $$$n$$$ neurons for a fixed prime $$$p$$$. This model takes two integers $$$a$$$ and $$$b$$$ as inputs and calculates $$$(a + b) \bmod p$$$. The architecture of the model is:
$$$$$$ ReLU(a_{one-hot}W_{input}+b_{one-hot}W_{input})W_{output}^{T} $$$$$$
where
$$$$$$ ReLU(x) = max(x, 0) $$$$$$
and $$$x_{one-hot}$$$ is a matrix of size $$$1 \times p$$$, which consists of all zeros and a single one in column $$$x$$$.
For example, if $$$p=4$$$, $$$0_{one-hot} = \begin{pmatrix}1 & 0 & 0 & 0\end{pmatrix}$$$, $$$2_{one-hot} = \begin{pmatrix}0 & 0 & 1 & 0\end{pmatrix}$$$.
In other words, you must choose the number of neurons $$$n$$$ and generate two real matrices $$$W_{input}$$$ and $$$W_{output}$$$ of size $$$p \times n$$$.
To add integers $$$a$$$ and $$$b$$$ three steps are executed:
See the example explanation for better understanding.
You need to generate two real matrices $$$W_{input}$$$ and $$$W_{output}$$$ that for all pairs $$$(a, b), 0 \le a, b \lt p$$$, the output produced by the model is correct.
The only line of the input consists of the integer $$$p$$$ ($$$3 \le p \le 100$$$). It is guaranteed that $$$p$$$ is prime.
The first line of the output should contain the integer $$$n$$$ ($$$1 \le n \le 25$$$) — the number of neurons in the model.
In the following $$$p$$$ lines, output matrix $$$W_{input}$$$. Each line should consist of $$$n$$$ real numbers not greater than 1000 by the absolute value.
After that, output matrix $$$W_{output}$$$ in the same format.
3
4 2.5 3.0 -0.5 -3.0 -3.0 0.0 0.5 2.0 -0.5 0.5 -3.0 1.5 1.5 1.0 -2.0 2.5 -3.0 3.0 -1.0 2.0 -0.5 2.5 0.5 2.0
Let's calculate $$$(1+2) \bmod 3$$$. First, we add rows $$$[-3.0, 0.0, 0.5, 2.0]$$$ and $$$[-0.5, 0.5, -3.0, 1.5]$$$ and get $$$[-3.5, 0.5, -2.5, 3.5]$$$. Then, we remove all negative numbers: $$$[0.0, 0.5, 0.0, 3.5]$$$.
Then, we calculate the score for each possible result:
Row 0 has the highest score 9.25, and $$$(1+2) \bmod 3$$$ indeed equal 0.
Sofia is the best wife, and she constantly comes up with new ideas on how to spend time with her husband. Idea $$$i$$$ could be described by a segment $$$[l_i..r_i]$$$. It means Sofia wants to visit some event that starts at day $$$l_i$$$ and ends at day $$$r_i$$$. If she decides to visit an event, she fully commits to it and is there every day from $$$l_i$$$ to $$$r_i$$$ inclusive.
Sofia can't visit more than one event each day. Also, if some event ends on day $$$d$$$ and another event starts on day $$$d$$$, she can only visit one of them.
After each new idea comes to her mind, she wonders what the biggest number of events she could visit.
The first line contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of ideas.
Each of next $$$n$$$ lines contain two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 6 \cdot 10^5$$$) — description of the $$$i$$$-th idea.
For each $$$i$$$ in a range $$$1..n$$$, print one integer — the maximum number of events out of $$$1, 2, ..., i$$$ that Sofia can visit.
5 1 3 3 5 1 2 5 6 4 4
1 1 2 2 3
This is an interactive problem.
There are $$$n$$$ sets numbered $$$1$$$ to $$$n$$$, the $$$i$$$-th of them containing only the integer $$$i$$$. You need to process $$$q$$$ queries. The $$$i$$$-th query (1-indexed) is described by a pair of integers $$$(X_i, Y_i)$$$. It creates a set number $$$n + i$$$, which consists of a union of integers from sets $$$X_i$$$ and $$$Y_i$$$.
Each time you create a new set, you must report the number of different integers in this set. You don't need to report the exact result. If the correct size of the set is $$$A$$$ and you print integer $$$B$$$, it will be accepted if $$$0.5 \cdot A \le B \le 2.0 \cdot A$$$.
Flushing the output could be costly on some Judging Systems, so all queries are split into batches of size 50. Your solution should read the first 50 queries, print the answers for all of them, flush the output, read the second batch of 50 queries, print the answers for them, flush the output, and so on. The last batch could consist of less than 50 queries.
The interactor is not adaptive, which means for each test, the sequence of queries is always the same for all runs.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 50\,000, 1 \le q \le 5 \cdot 10^5$$$) — the initial number of sets and the number of queries.
The next $$$q$$$ lines contain queries. The $$$i$$$-th of them contains two integers $$$X_i$$$ and $$$Y_i$$$ ($$$1 \le X_i, Y_i \lt n + i$$$).
For each query, print one integer in a separate line — your estimate of the size of the created set.
Don't forget to flush output after every 50th query!
4 5 1 2 2 3 5 6 6 7 4 7
2 2 3 3 4
$$$n$$$ points $$$a_1, a_2, ..., a_n$$$ are randomly generated inside a cube of size 1.
You are given a matrix $$$d$$$ with $$$d_{i,j}=d_{j,i}=dist(a_i, a_j)+rand(-0.1..0.1)$$$ and $$$d_{i,i}=0$$$. Here $$$dist(p, q)$$$ is the distance between points $$$\sqrt{(p_x-q_x)^2+(p_y-q_y)^2+(p_z-q_z)^2}$$$ and $$$rand(-0.1..0.1)$$$ is a random shift chosen uniformly from interval $$$[-0.1..0.1]$$$. Shifts for different pairs of points are chosen independently.
You need to construct a list of points $$$b_1, b_2, ..., b_n$$$ such that $$$\forall_{i, j} |dist(b_i, b_j)-d_{i,j}| \le 0.1$$$.
The first line contains one integer $$$n$$$ ($$$1 \le n \le 10$$$) — the number of points.
The next $$$n$$$ lines contain the description of matrix $$$d$$$. The $$$i$$$-th line contains $$$n$$$ real values $$$d_{i,j}$$$ ($$$-0.1 \le d_{i,j} \le \sqrt{3}+0.1$$$). Each value is given with 6 digits after the decimal point.
It is guaranteed that $$$d_{i,i}=0$$$ and $$$d_{i,j}=d_{j,i}$$$.
Print $$$n$$$ lines describing the points. $$$i$$$-th line should contain three real numbers $$$x_i$$$ $$$y_i$$$ $$$z_i$$$ ($$$-10.0 \le x_i, y_i, z_i \le 10.0$$$).
4 0.000000 0.758400 0.557479 0.379026 0.758400 0.000000 0.516608 0.446312 0.557479 0.516608 0.000000 0.554364 0.379026 0.446312 0.554364 0.000000
0.210269 0.581333 0.000000 0.090086 0.000000 0.458722 0.000000 0.498388 0.501723 0.204618 0.204262 0.075724
This problem has $$$30$$$ test cases.
This is an interactive problem.
$$$n - 1$$$ random binary strings $$$s_i$$$ of length 50 are generated. Then, one of the strings is duplicated, and all $$$n$$$ strings are shuffled. You need to find indexes of equal strings.
You can ask at most $$$25\ 000$$$ queries. Each query is a pair $$$(i, j)$$$. The answer to the query is the Hamming distance between $$$s_i$$$ and $$$s_j$$$ — the number of positions where they differ.
It is guaranteed that all strings are picked randomly from the uniform distribution. Also, the list of strings is fixed for each test — interactor is not adaptive.
First, the interactor prints one integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the total number of strings.
Then, you can ask at most $$$25\ 000$$$ queries in the format "i j" ($$$1 \le i, j \le n, i \ne j$$$). Don't forget to flush the output after each query!
For each query, you will receive one integer $$$d$$$ ($$$0 \le d \le 50$$$) — the Hamming distance between $$$s_i$$$ and $$$s_j$$$. After receiving $$$d=0$$$, your program should terminate.
4 21 23 21 0
1 2 2 3 1 4 2 4
Strings in the sample:
You are given a tree consisting of $$$n$$$ nodes. Initially, node $$$i$$$ has the integer $$$i$$$ written on it. You need to process $$$q$$$ queries of two types:
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 10^5$$$) — the number of vertices and queries.
Each of the next $$$n - 1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$) — edges of the tree.
Each of the next $$$q$$$ lines contains queries in the format "+ a v x" ($$$1 \le a, v \le n$$$, $$$1 \le x \le 10^4$$$) or "? a v" ($$$1 \le a, v \le n$$$).
For each query of the second type, print the answer in a separate line.
5 6 1 2 1 3 3 4 3 5 ? 2 5 + 1 4 1 ? 2 5 + 4 5 2 ? 4 5 ? 1 1
5 1 6 2
For a given integer $$$n$$$, you must color each cell of an $$$n \times n$$$ grid into one of $$$C = 10 + \lfloor\frac{n^2}{100}\rfloor$$$ colors. Each specific color could be used at most 150 times.
For each cell $$$(r, c)$$$, the set of colors used in cells $$$(r_i, c_i)$$$ where $$$(r - r_i)^2 + (c - c_i)^2 \le 100$$$, should contain at most 8 different colors.
The only line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the grid size.
Print $$$n$$$ lines with $$$n$$$ integers $$$1 \le a_{r,c} \le C$$$ in each.
3
1 2 3 4 5 6 7 8 8
There is an array $$$a$$$ with $$$a[i] = i$$$ initially. $$$m$$$ operations are performed with this array. During each operation, two random indexes $$$i$$$ and $$$j$$$ are chosen, and elements $$$a[i]$$$ and $$$a[j]$$$ are swapped.
You need to answer $$$q$$$ queries. Each query is array $$$b_1$$$, $$$b_2$$$, ..., $$$b_k$$$. You need to find the first time when $$$b$$$ was a continuous subarray of $$$a$$$.
Indexes in swap operations are guaranteed to be chosen independently from a uniform distribution.
The first line contains three integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$1 \le n, m, q \le 10^5$$$).
Each of the following $$$m$$$ lines contains two integers $$$i$$$ and $$$j$$$ ($$$1 \le i \lt j \le n$$$) — descriptions of swap operations.
The next $$$q$$$ lines contain descriptions of the queries. Each description starts with integer $$$k$$$ ($$$1 \le k \le n$$$) and then $$$k$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_k$$$ ($$$1 \le b_i \le n$$$). It is guaranteed that the sum of all $$$k$$$ doesn't exceed $$$10^5$$$.
For each query described by the array $$$b$$$, you need to print the number of operations performed before $$$b$$$ became a continuous subarray of $$$a$$$. If the initial array $$$a$$$ contained $$$b$$$, print $$$0$$$. It is guaranteed that $$$b$$$ was a subarray of $$$a$$$ at some point.
6 3 5 1 5 3 4 1 6 2 4 1 3 3 1 5 3 3 4 5 4 5 2 4 3 2 6 2
1 3 0 2 3
This is an interactive problem.
You are given $$$1000\$$$$. You play a game consisting of $$$T=1000$$$ rounds.
In each round, the jury randomly picks an integer $$$b$$$ from the range $$$[1..m]$$$, where $$$m$$$ is the amount of money you currently have. Each integer in this range has an equal probability of being chosen. You can either play this round or skip it. If you play in the round, one of the outcomes is selected with equal probability:
If, at some point, you have more than $$$10\,000$$$ dollars, you win. You lose if you have 0$ or the game ended (you played or skipped all $$$T$$$ rounds).
The first line contains one integer $$$T$$$ ($$$T=1000$$$ or $$$T=5$$$) — the number of rounds. It is guaranteed that $$$T=5$$$ is used only in the sample. Your solution is considered correct on the sample if you have a positive amount of money after $$$T$$$ rounds.
Each of the $$$T$$$ rounds starts with a command "ROUND m b", where $$$m$$$ is the amount of money you currently have and $$$b$$$ is a bet chosen by the jury for this round. You should respond with either "PLAY" or "SKIP". Don't forget to flush the output after each response!
If you have more than $$$10\,000$$$ dollars after some round, you will get the word "WIN" instead of the next round. If you lose, you will get the word "LOSE". Your program should terminate immediately after receiving "WIN" or "LOSE".
5 ROUND 1000 43 ROUND 957 433 ROUND 957 525 ROUND 957 125 ROUND 832 685 WIN
PLAY SKIP SKIP PLAY SKIP
This problem has one sample test and $$$50$$$ real test cases. Each real test case has some fixed random seed. Note that your decision to participate or not participate in the round affects how the random number generator is used, so all rounds after that will be different.
The following operation is performed at most 20 times with a square piece of paper of the size $$$1 \times 1$$$. Two points inside the square are picked uniformly at random, and a line is drawn through them.
Later, the paper is cut along all of the lines into $$$n$$$ pieces. Then, pieces are randomly rotated (but not flipped), shifted, and given to you. You need to figure out the initial position of each piece.
The first line contains one integer $$$n$$$ ($$$2 \le n$$$) — the number of pieces. The descriptions of the pieces follow.
Each description starts with an integer $$$m$$$ ($$$3 \le m$$$) — the number of vertices. Each of the following $$$m$$$ lines contains two real numbers $$$x_i$$$ and $$$y_i$$$ ($$$0.0 \le x_i, y_i \le 2.0$$$) given with 12 digits after the decimal point. The vertices are given in a counter-clockwise order.
You need to print pieces in the order given in the input.
For each piece, print the coordinates of the vertices in the order given in the input. Each coordinate must fulfill the condition $$$0.0 \le x_i, y_i \le 1.0$$$.
If there are several possible ways to put pieces inside a $$$1 \times 1$$$ square such that they do not intersect, you can print any of them.
The answer will be considered incorrect if the intersection area of any two polygons is bigger than $$$10^{-6}$$$.
4 4 0.440405375916 0.778474079786 0.000000000000 0.090337001520 0.469097990019 0.000000000000 0.702887505082 0.689470121906 4 0.222810526978 0.000000000000 0.270828246634 0.522212063829 0.000000000000 0.547114887265 0.021480010612 0.069880870008 4 0.000000000000 0.312825941471 0.358219176380 0.000000000000 0.532830100286 0.122181578260 0.088431750275 0.414089758021 4 0.158867722074 0.061734605990 0.973532298476 0.000000000000 0.853551564066 0.712811281737 0.000000000000 0.569141075980
0.277161636 -0.000000000 0.473262431 0.793116645 0.000000000 0.728029248 0.000000000 0.000000000 0.524415047 1.000000000 0.000000000 1.000000000 0.000000000 0.728029248 0.473262431 0.793116645 1.000000000 1.000000000 0.524415047 1.000000000 0.473262431 0.793116645 1.000000000 0.865558433 0.473262431 0.793116645 0.277161636 -0.000000000 1.000000000 -0.000000000 1.000000000 0.865558433
$$$n=10^4$$$ integers $$$a_1, a_2, ..., a_n$$$ are randomly and independently generated from the range $$$[1..10^{12}]$$$.
For each integer, you need to either discard it or put it into one of the sets $$$A$$$, $$$B$$$, or $$$C$$$. The sum of the integers in the set $$$A$$$ should be equal to the sum in the set $$$B$$$ and equal to the sum in the set $$$C$$$.
Each set should contain at least one integer. If there are multiple solutions, you could print any of them. It is guaranteed that the answer always exists for all tests in the system.
The first line contains one integer $$$n$$$ ($$$n = 10^4$$$ or $$$n = 6$$$) — the number of elements in the array.
The second line contains integers $$$a_1, a_2, ..., a_n$$$ ($$$1 \le a_i \le 10^{12}$$$).
All tests except the sample are guaranteed to have $$$n=10^4$$$, and integers $$$a_i$$$ are randomly generated from a uniform distribution.
Print one line consisting of $$$n$$$ characters. For each integer, print "." if you want to discard it. Otherwise, print "A", "B" or "C" to indicate the set to put this integer.
6 4 3 8 1 5 4
ABC.BA
This problem has one sample test and $$$50$$$ real test cases.
You are given a graph of the London Underground with 426 stations and 505 two-way connections between them. You are also given some subset of stations. You need to count the number of ways to add more (possibly zero) stations to this set so that no two stations are directly connected.
Two ways of adding stations are considered different if some station is present in one set and not present in another.
The number of ways could be big, so you need to output it modulo $$$998\,244\,353$$$.
The first line contains one integer $$$m$$$ ($$$m = 505$$$) — the number of connections.
The following $$$m$$$ lines contain two stations each. Each station is a string of alphabetical characters, underscores, or digits.
It is guaranteed that the graph is exactly the same in all tests. It doesn't contain self-loops and duplicate edges.
The following line contains one integer $$$k$$$ ($$$0 \le k \le 426$$$) — the number of stations in the initial set. The following $$$k$$$ lines contain station names in the same format.
Print the number of ways to extend the set modulo $$$998\,244\,353$$$.
505 Baker_Street Regents_Park Charing_Cross Embankment Edgware_Road__Bakerloo_ Marylebone Embankment Waterloo Harlesden Willesden_Junction Harrow_and_Wealdstone Kenton Kensal_Green Queens_Park Kenton South_Kenton ... 2 Baker_Street Liverpool_Street
159589981
You can download the complete sample input at https://pastebin.com/yuMX9tRL.
You can check the official map at https://content.tfl.gov.uk/standard-tube-map.pdf. This link is provided for reference only. It may have some differences compared to the graph in the sample.
Teamwork is critical in programming competitions! Effective communication and solution discussion among team members is key before implementation. Sometimes, team members might choose incorrect solutions and spend excessive time coding them. Other times, someone may suggest a more straightforward and simpler approach.
A team of three members is taking part in the competition. For each team member, you are given the time it takes for them to implement each of the problems. However, they share just one computer, so they could only work on one problem at a time. The contest has a duration of $$$300$$$ minutes. Your task is to compute the maximum number of different problems the team can solve. You can neglect the time required for switching between problems — if the total time required for solving problems doesn't exceed $$$300$$$ minutes, they could do it in time.
Let's look at the sample:
The first line contains one integer $$$n$$$ ($$$1 \le n \le 14$$$) — the number of problems in the contest.
Each of the next $$$n$$$ lines contains the description of the problem $$$name$$$ $$$t_1$$$ $$$t_2$$$ $$$t_3$$$ ($$$-1 \le t_i \le 300$$$) — the problem's name and the number of minutes required for each participant to implement it. The problem name consists of at most $$$30$$$ alphanumeric characters. If $$$t_i$$$ equals $$$-1$$$, this team member could not implement this problem at all.
Print single integer — the maximum number of problems the team could solve during the contest.
13AplusB -1 20 -1TheBestWife 80 90 60Cardinality 40 50 303D 40 -1 70EqualStrings 25 15 20FastTreeQueries 120 -1 40GeoSharding 25 20 30HaveYouSeenThisSubarray 80 90 60InteractiveCasino 50 20 30JigsawPuzzle 40 50 80Knapsack -1 40 200LondonUnderground -1 200 40Meta 5 7 10
10