For a given permutation $$$P$$$ of $$$1,2,\dots,n$$$, denote $$$inv(P)$$$ the number of inversions of the array $$$P_1,P_2,\dots, P_n$$$. For two permutations $$$A$$$ $$$B$$$ of $$$1,2,\dots,n$$$, define $$$ A(B)$$$ the permutation $$$A_{B_1}, A_{B_2},\dots,A_{B_n}$$$. Denote the inverse of permutation $$$P$$$ as $$$P^{-1}$$$, the only permutation such that $$$P(P^{-1})$$$ is the permutation $$$1,2,\dots,n$$$.
You are given two permutations $$$A,B$$$ of $$$1,2,\dots,n$$$. You have to choose a permutation $$$P$$$ of $$$1,2,\dots,n$$$ such that $$$inv(A(P^{-1}))+inv(P(B^{-1}))$$$ is minimized. How many such permutations exist?
The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 20)$$$. 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)$$$.
A single integer containing the number of permutations $$$P$$$.
43 1 2 42 1 4 3
3
63 2 6 1 5 41 2 5 6 4 3
12
111
1
You are a farmer and have a rectangular garden, represented as an $$$1 \times n$$$ grid. You numerated the cells from $$$1$$$ to $$$n$$$, from left to right.
In the $$$i$$$-th cell you determine its potential for growing crops, and it is represented by an integer $$$a_i$$$, which can be negative.
Per law, you have to install exactly $$$k$$$ sprinklers to water your garden. Each sprinkler can water a contiguous set of cells, that is, it will water the $$$x$$$-th cell if $$$x \in [l,r]$$$ for some $$$l \leq r$$$. The value of this sprinkler is $$$\sum_{i=l}^{r} a_i$$$. A sprinkler is said to be useless if the set of cells it waters is contained in the set of cells other sprinkler waters. More formally, if two sprinklers cover cells $$$[L,R]$$$ and $$$[l,r]$$$ and if $$$L \leq l \leq r \leq R$$$, then that means the sprinkler that covers cells in $$$[l,r]$$$ is useless.
The law states that no sprinkler should be useless, but all pair of sprinklers have to water at least one cell in common.
Your total profit will be the sum of the values of all sprinklers. What is the maximum possible value of your total profit?
The first line contains the number of testcases, $$$t$$$ ($$$1 \leq t \leq 10^5$$$).
For each testcase, the first line contains an integer $$$n$$$ $$$(2 \leq n \leq 3 \times 10^5)$$$ and an integer $$$k$$$ $$$(1 \leq k \leq \frac{n+1}{2})$$$, denoting the number of cells in your garden and the number of sprinklers. The second line contains a sequence of $$$n$$$ integers $$$a_1,a_2, \dots ,a_n$$$ $$$(-10^6 \leq a_i \leq 10^6)$$$, denoting the value of the $$$i$$$-th cell.
The sum of $$$n$$$ across all testcases does not exceed $$$3 \cdot 10^5$$$.
For each testcase, output a line containing the maximum possible profit.
26 210 2 -5 9 -3 -106 310 2 -5 9 -3 -10
22 15
29 5-4 -3 -2 -1 0 1 2 3 49 34 3 2 1 0 -1 -2 -3 -4
0 18
Your friend is learning electronics, and he invented a new game he wants you to play.
There is a device with $$$n$$$ lightbulbs, disposed in a row. They are numbered from $$$1$$$ to $$$n$$$. The lightbulb $$$i$$$ has an integer $$$w_i$$$ written on it. Notice that $$$w_i$$$ might be negative. Initially, each lightbulb is on or off. In front of each light, except the first and the last lightbulb there is a button. In each step of the game, you may select a button and press it. If the lightbulb on the back is off, nothing will happen; however, if the lightbulb is on, it will turn off and the two neighboring lightbulbs will become on. There is no limit on the number of times you may press a button. When you decide to quit, your score is initially zero, but your friend will inspect all the lightbulbs, and if the $$$i$$$-th lightbulb is on, then he will add $$$w_i$$$ to the score.
What is the maximum possible score that can be obtained?
The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 2000$$$) corresponding to the number of testcases.
For each testcase, the first line contains an integer $$$n$$$ ($$$3 \leq n \leq 2000$$$), corresponding to the number of lightbulbs. The second line contains a string of size $$$n$$$, containing only the characters '$$$0$$$' or '$$$1$$$'. If the $$$i$$$-th character is $$$0$$$, then it means the $$$i$$$-th lightbulb from the left is off; otherwise, the $$$i$$$-th lightbulb from the left is on. The third line contains $$$n$$$ integers $$$w_1,w_2,\dots,w_n$$$ $$$(-10^9 \leq w_i \leq 10^9)$$$, that indicate the number written on the $$$i$$$-th lightbulb.
It is guaranteed that for all testcases the sum of $$$n$$$ is at most $$$2000$$$.
The output should contain $$$T$$$ lines. The $$$i$$$-th line should contain the maximum possible score obtainable in the $$$i$$$-th testcase.
260011001 -2 3 -4 5 -660011001 -2 -3 4 5 -6
9 8
Paulo has decided to study physics, however, he still does not understand the concept of cross product of two vectors.
The cross product of two vectors in a two-dimensional space, $$$\vec{v}$$$ and $$$\vec{w}$$$, is defined by $$$\vec{v} \times \vec{w} = v_x w_y - v_y w_x$$$
His friend Duarte has decided to help him, and as such, he proposes a game: He picks $$$n$$$ distinct points $$$P_1,P_2,\dots,P_n$$$ in the plane, such that there are not two integers $$$1 \leq a \lt b \leq n$$$ such that the points $$$P_a$$$, $$$O$$$ and $$$P_b$$$ are collinear. In particular, this means that the origin is never picked, and no point appears more than one time. Additionally, all points have integer coordinates and they do not exceed $$$2\times 10^4$$$ in absolute value. Paulo can ask queries by saying two integers $$$a$$$ and $$$b$$$, and Duarte will respond with the cross product of vectors $$$\vec{OP_a}$$$ and $$$\vec{OP_b}$$$, where $$$O$$$ is the origin of the plane.
Paulo can ask at most $$$2n$$$ queries, and his objective is to determine the indexes of the points that are vertices in the convex hull of $$$P_1,P_2,\dots,P_n$$$ (points on the edge of the convex hull do not count). Help Paulo win the game!
The interactor first prints an integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$, the number of testcases.
Each testcase starts with the interactor printing an integer $$$n$$$, denoting the number of points hidden by Duarte $$$(3 \leq n \leq 1000)$$$. You can then start asking queries.
You start your query with a ?. Then, two integers $$$a$$$,$$$b$$$ follow $$$(a \neq b)$$$.
? k a b
When you know the convex hull, you must send a line starting with a ! followed by a space, the size $$$sz$$$ of the convex hull and integers $$$i_1$$$ $$$i_2$$$ $$$\dots$$$ $$$i_{sz}$$$ meaning that the points on the convex hull are $$$P_{i_1},P_{i_2},\dots,P_{i_{sz}}$$$. The order does not matter, but all $$$i_1,i_2,\dots,i_{sz}$$$ should be distinct.
! sz i1 i2 ... isz
It is guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1 3 2 -3 -1
? 2 1 ? 3 2 ? 1 3 ! 3 1 2 3
After many hours of stalking a group of $$$n$$$ people, you notice that each pair of persons has a relationship. Denote $$$R(A,B)$$$ the type of relationship between persons $$$A$$$ and $$$B$$$.
There are exactly $$$10^{18}$$$ types of relationships, numbered $$$1,2,\dots,10^{18}$$$.
It is also known that the relationsip is symetric, that is, $$$R(A,B)=R(B,A)$$$.
The group is called stable if for each three distinct persons $$$A$$$, $$$B$$$ and $$$C$$$, the set $$$\{R(A,B),R(B,C),R(C,A)\}$$$ contains exactly $$$1$$$ or $$$3$$$ distinct numbers.
You know the types of $$$m$$$ relationships. Is it possible that the group is stable?
The first number contains an integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$, denoting the number of testcases.
For each testcase, the first line contains two integers $$$n$$$,$$$m$$$ $$$(2 \leq n,m \leq 10^5)$$$, denoting the number of people in the group and the number of known relationships.
The next $$$m$$$ lines contain three integers $$$a$$$,$$$b$$$,$$$c$$$ $$$(1 \leq a,b \leq n, 1 \leq c \leq m, a \neq b)$$$, indicating that the $$$a$$$-th person and the $$$b$$$-th person have a relationship of type $$$c$$$.
The sum of $$$n+m$$$ on all testcases is at most $$$2 \times 10^5$$$.
It is guaranteed that the unordered pair $$$\{a,b\}$$$ does not appear more than once.
For each testcase, output a single line containing "YES" if there is a possible way other people have relationships so that the group is stable, or "NO" otherwise.
210 31 2 13 4 12 3 210 41 2 13 4 12 3 11 4 2
YES NO
Kevin hates implementation problems, but Paulo thinks they deserve a chance. He recently encountered a situation at home that required him to deal with a problem and he had a lot of fun solving it. This is the chance to show Kevin that implementation can be cool.
Paulo has a special programming language. The language only uses basic instructions and IFs. It follows the following grammar:
Program := Instruction
Program := Instruction
Program
Program := IF ci
Program
ELSE
Program
Instruction := ri += rj
Instruction := ri -= rj
Instruction := ri += V
Instruction := ri -= V
Instruction := ri SWAP rj
In this language:
ci
are global boolean variables initially set to false.ri
are global registers. They are not erased once the program runs, are initially set to 0, $$$(0\leq i \lt 3)$$$.V
are numerical values $$$(0\leq V \lt 10^9+7)$$$.The instructions do the following:
ri += rj
increments the value in register ri with the value in register rj.ri -= rj
decrements the value in register ri with the value in register rj.ri += V
increments the value in register ri with the value V.ri -= V
decrements the value in register ri with the value V.ri SWAP rj
swaps the values of registers ri and rj.In all instructions, all the xi are different from the xj, and sum and subtraction are defined modulo $$$10^9+7$$$.
The program runs as follows:
We run every instruction iteratively, applying the respective transformation. When we find an IF statement, we check the value of the associated boolean variable. If the value stored is true, then we run the program immediately below, otherwise we run the program below the ELSE.
Paulo wrote a program on his computer. Sometimes he looks at the values in the registers. Sometimes he runs the program several times. Sometimes he replaces a boolean variable with another boolean variable. Sometimes he notices a bug and changes an instruction to another instruction. Sometimes a boolean variable changes value (Paulo is careful so that no boolean variables change value while being used by the program).
Paulo has been doing this for a long time and keeps a list of the actions he took.
But tragedy happened; he lost the results of his calculations! He just knows the original code and the list of actions he took.
Help Paulo quickly regain the printed register values.
The first line has two integers, the number of lines of code $$$n$$$ $$$(1 \leq n \leq 5 \cdot 10^4)$$$ and the number of boolean variables $$$C$$$ $$$(1 \leq C \leq 5 \cdot 10^4)$$$.
Then $$$n$$$ lines follow, describing a valid program.
Then a line with a value $$$Q$$$ $$$(1 \leq Q \leq 5 \cdot 10^4)$$$, the number of actions Paulo took. The following $$$Q$$$ lines contain the actions Paulo took in order, and they are one of the following categories:
0
Print the values on the three registers.1 x
Run the current program $$$x$$$ $$$(1 \leq x \leq 10^9)$$$ times.2 l ci
Change the IF in line $$$l$$$ $$$(1 \leq l \leq n)$$$ (it's guaranteed that there's an IF in line $$$l$$$) to use boolean variable ci instead $$$(0 \leq i \lt C)$$$.3 l Instruction
Change the instruction in line $$$l$$$ $$$(1 \leq l \leq n)$$$ (it's guaranteed that there's an instruction in line $$$l$$$) to use the new instruction instead. Instruction is a valid instruction.4 ci
Change the boolean value of boolean variable ci. It's guaranteed ci is not being used by the code at the moment.Print a line with the values inside the registers for every time there's a query of type 0. You should print the values in the registers in order, separated by a space. This means
r0 r1 r2
5 2IF c0r1 += r0r0 SWAP r1ELSEr0 += 12404 c11 102 1 c11 101 101 101 101 101 103 2 r0 SWAP r13 3 r1 -= r03 5 r0 -= 11 62 1 c01 10
0 0 0 1 0 0 1 1 0 2 1 0 3 2 0 5 3 0 8 5 0 13 8 0 0 0 0
2 1r1 += 1r2 -= 121 10000000000
0 1000000000 7
This is an interactive problem.
There has been an invasion of your black cherry field.
Your black cherry field is a $$$1700\times 1700$$$ field and an animal has entered it and has been wreaking havoc. You are sure the animal entered at coordinate $$$(1,1)$$$ and exited at $$$(1700,1700)$$$. You also know that the animal just walked downwards and rightwards.
You want to assess the damage as quickly as possible. Your assessment equipment allows you to query several coordinates of your field and it returns how many of them are damaged.
Find the path the animal took in $$$1200$$$ queries or less.
The interactor prints the size of the grid, $$$n$$$.
You start your query with a ?. Then you send $$$k$$$, the number of coordinates you want to query. Then you send $$$k$$$ distinct coordinates $$$x_i$$$, $$$y_i$$$ ($$$1 \leq x_i,y_i \leq n$$$) where $$$x_i$$$ is the row and $$$y_i$$$ is the column. You must send all these tokens in a line separated by a space, with no trailing white space.
? k x1 y1 ... xk yk
When you know the path, you must send a line starting with a ! followed by a space and a string describing the path. The path starts at coordinate $$$(1,1)$$$ and ends at coordinate $$$(n,n)$$$. If you are currently at coordinate $$$(x,y)$$$, if the next character of the path is 'D', you move to coordinate $$$(x+1,y)$$$; if the next character of the path is 'R' you move to coordinate $$$(x,y+1)$$$.
! DR...DR
The sum of the number of coordinates queried shouldn't exceed $$$5\cdot 10^6$$$. You may not repeat the same coordinate on the same query.
3 2
? 3 2 1 3 1 3 2 ! DRDR
Sample has $$$n=3$$$, but all other testcases will have $$$n=1700$$$
As Duarte wakes up, he notices he is in a huge dungeon where $$$n$$$ obelisks stand in a circle.
Suddenly, a tall and mysterious figure appears in front of him, and he says:
"I am the evil logic wizard, and I kidnapped you for a test. As you can observe, these obelisks are numbered from $$$1$$$ to $$$n$$$ clockwise, where the obelisks $$$i$$$ and $$$i+1$$$ are neighbouring obelisks for $$$1 \leq i \leq n-1$$$, as well as obelisks $$$n$$$ and $$$1$$$. The distance between two obelisks numbered $$$i$$$ and $$$j$$$ is defined as $$$min(|i-j|,n-|i-j|)$$$.
Each obelisk is filled with an unknown number of unique treasures, and each obelisk has between $$$0$$$ and $$$1000$$$ treasures, inclusive.
From obelisk $$$1$$$ I emit a magical signal, which determines for each $$$i$$$ from $$$0$$$ to $$$\lfloor \frac{n}{2} \rfloor$$$ the number of treasures at distance exactly $$$i$$$.
I also emit a magic signal from the center of all obelisks, which determines the number of unordered pairs of treasures (each treasure is unique) at distance exactly $$$i$$$, for each $$$i$$$ from $$$0$$$ to $$$\lfloor \frac{n}{2} \rfloor$$$.
Determine a placement of the treasures that is consistent with my information, or you'll be forever stuck in this dungeon!"
The first line contains an integer $$$n$$$ $$$(2 \leq n \leq 32)$$$, containing the number of obelisks.
The second line contains $$$\lfloor \frac{n}{2} \rfloor+1$$$ integers $$$a_0,a_1,\dots,a_{\lfloor \frac{n}{2} \rfloor}$$$, where $$$a_i$$$ $$$(1 \leq a_i \leq 10^8)$$$ indicates the number of treasures at distance $$$i$$$ from obelisk $$$1$$$.
The second line contains $$$\lfloor \frac{n}{2} \rfloor+1$$$ integers $$$b_0,b_1,\dots,b_{\lfloor \frac{n}{2} \rfloor}$$$, where $$$b_i$$$ $$$(1 \leq b_i \leq 10^8)$$$ indicates the number of unordered pairs of treasures at distance $$$i$$$.
The first line should contain "YES" if there exists an example that fits the given information, or "NO" otherwise.
If the answer is "YES", the second line should contain $$$n$$$ integers $$$x_1,x_2,\dots,x_n$$$ where $$$x_i$$$ indicates the number of treasures in obelisk $$$i$$$.
If there are many solutions, you may output any of them.
63 5 2 310 26 28 14
YES 3 2 1 3 1 3
83 8 13 10 378 173 155 169 91
YES 3 2 6 5 3 5 7 6
63 5 2 410 26 28 14
NO
You are the president of a country with $$$n$$$ cities numbered from $$$1$$$ to $$$n$$$. This year, your country will be the host of a famous race!
Your country is connected with exactly $$$n-1$$$ roads, and each road has a length. It is possible to drive from any city to any other city using these roads.
A track is a sequence $$$a_1,a_2,\dots,a_k$$$ of $$$k \geq 2$$$ cities, such that city $$$a_i$$$ and city $$$a_{i+1}$$$ for $$$1 \leq i \leq k-1$$$ are connected by a road. The length of a track is the sum of lengths of each road in that track.
To organize the race, you must select a set of tracks such that every road is in exactly one track. This means, in particular, that no two tracks share the same road.
However, according to the car sports committee, all tracks must have the same length. However, this year they'll make an exception and consider the proposal based on the difference between the largest and shortest track.
What is the minimum possible difference between the largest and shortest track?
The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 40$$$), denoting the number of cities. The next $$$n$$$ lines contain three integers $$$a_i$$$,$$$b_i$$$,$$$w_i$$$ ($$$1 \leq a, b \leq n$$$, $$$1 \leq w_i \leq 10^9$$$), indicating a road between cities $$$a_i$$$ and $$$b_i$$$ with length $$$w_i$$$.
A single integer, containing the minimum possible difference between the largest and shortest track.
41 2 12 3 23 4 3
0
61 2 122 3 52 4 75 6 96 4 5
2
You have $$$S$$$ solar panels on an $$$n\times n$$$ surface. Each solar panel has a desired quantity of sunlight it needs to receive.
There are currently no clouds above the solar panels surface, but you just received the cloud satellite image for the day, a $$$N\times N$$$ image. The clouds are described as rectilinear non-intersecting polygons whose edges are parallel with the coordinate axis.
The wind is constantly blowing in the $$$(-1,-1)$$$ direction. At each second, the wind pushes the clouds in the said direction.
After each second, if there are no clouds above a solar panel, the amount of sunlight that solar panel receives increments by one, otherwise the quantity stays the same. This repeats forever.
Calculate for each solar panel how many seconds you need to wait to reach the needed quantity of sunlight.
The first line has the size of the surface $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5$$$), the size of the satellite image $$$N$$$ $$$(n \lt N \leq 10^9)$$$ and the number of solar panels $$$S$$$ $$$(1 \leq S \leq 10^5)$$$.
Then $$$S$$$ lines follow, each with the $$$x$$$ and $$$y$$$ of the coordinate of a solar panel $$$(1 \leq x,y \leq 2 \cdot 10^5)$$$ and the needed amount of sunlight $$$q$$$ $$$(1 \leq q \leq 10^9)$$$. The coordinate $$$(x,y)$$$ describes the coordinate of the right uppermost corner of the square the solar panel occupies.
The next line has the number of clouds $$$M$$$ ($$$0 \leq M \leq \lfloor \frac{10^5}{4} \rfloor$$$).
Then for each cloud, we have a line with $$$V$$$, the amount of vertices on the rectilinear polygon ($$$1 \leq V \leq 10^5$$$). Then $$$V$$$ lines follow, each with an $$$x$$$ and $$$y$$$ coordinate describing the vertices of the polygon in clockwise order $$$(n \leq x,y \leq N)$$$.
The sum of $$$V$$$ over all clouds doesn't exceed $$$10^5$$$.
Print a line with how long you need to wait to reach the needed quantity of sunlight, for each solar panel, separated by a space. Print the values in the order given by the input.
3 7 61 3 31 2 22 3 22 2 53 2 53 1 5263 43 65 65 54 54 446 56 67 67 5
4 2 4 5 6 5
200000 1000000000 1200000 200000 100000000014200000 200000200000 10000000001000000000 10000000001000000000 200000
1999800000
You are a coach for $$$n$$$ athletes, numbered $$$1,2,\dots,n$$$, and after two years of training you know their strengths and weaknesses very well.
You notice, however, that some athletes are friends. Furthermore, the friendship is always mutual, that is, if athlete $$$a$$$ is a friend of athlete $$$b$$$, then athlete $$$b$$$ is a friend of athlete $$$a$$$.
There are exactly $$$n-1$$$ friendships, and there is no cycle of friendships, that is, a sequence $$$a_1,a_2,\dots,a_k$$$ of $$$k\geq 3$$$ distinct athletes such that athlete $$$a_i$$$ is a friend of athlete $$$a_{i+1}$$$ for $$$1 \leq i \leq k-1$$$ and athlete $$$a_k$$$ is a friend of athlete $$$a_1$$$.
You, however, do not know their friendships. But you can try and create courses to deduce them. That is, for every permutation $$$p_1,p_2,\dots,p_n$$$ of $$$1,2,\dots,n$$$, since you know each athlete, you can create a course such that it is guaranteed that athlete $$$i$$$ finishes in $$$p_i$$$-th position.
After the athletes finish a course, they compare themselves to their friends. An athlete is happy if it finishes first compared to their friends. You can then know the number of happy athletes, but you do not know which athletes are happy.
Since you do not want to put too much pressure, you can create at most $$$25000$$$ courses.
What are the friendships of the athletes?
The friendships are fixed before any queries are made and do not change.
The interactor first outputs an integer $$$n$$$ $$$(3 \leq n \leq 500)$$$, denoting the number of athletes.
You can then start asking queries.
You start your query with a ?. Then, $$$n$$$ integers follow, which form a permutation of $$$1,2,\dots,n$$$.
? p1 p2 ... pn
When you know the friendships, you must send a line starting with a ! followed by a space, then $$$n-1$$$ pairs of integers $$$(a_i,b_i)$$$ denoting the friendships. No two friendships can be repeated, and no friendship appears more than once (the pairs are unordered).
! a1 b1 a2 b2 ... an-1 bn-1
4 1
? 2 3 1 4 ! 1 2 1 3 1 4
5 2
? 2 3 1 4 5 ! 1 3 2 3 2 5 4 5
Your friend invented a game about guessing a hidden sequence.
There is a sequence $$$a_1,a_2,\dots,a_n$$$ of nonnegative integers that you do not know.
Instead, your friend gives $$$m$$$ clues about the sequence.
The clues have the format $$$l$$$ $$$r$$$ U or $$$l$$$ $$$r$$$ N (where $$$1 \leq l \leq r \leq n$$$), indicating if there is a unique maximum in the sequence $$$a_l,a_{l+1},\dots,a_r$$$ or not, respectively.
More formally, there is a unique maximum in the sequence $$$a_l,a_{l+1},\dots,a_r$$$ if there exists an integer $$$s$$$ such that $$$s \in [l,r]$$$ and $$$a_s \gt a_i$$$ for every $$$i \in [l,r] \setminus \{s\}$$$.
Can you find any sequence that satisfies the requirements, or tell that it is impossible to find such a sequence?
The first line of the input contains an integer $$$t$$$ $$$(1 \leq t \leq 300)$$$, denoting the number of testcases.
For each testcase, the first line contains two integers $$$n$$$ $$$(1 \leq n \leq 300)$$$ and $$$m$$$ $$$(1 \leq m \leq \frac{n(n+1)}{2})$$$ denoting the number of elements in the hidden array and the number of hints, respectively. Then exactly $$$m$$$ lines follow, the $$$i$$$-th of which contains two integers $$$l_i$$$ and $$$r_i$$$ $$$(1 \leq l_i \leq r_i \leq n)$$$ and a character $$$c_i$$$, which can only be "U" or "N".
It is guaranteed that there are no two integers $$$1 \leq i \lt j \leq m$$$ such that $$$l_i=l_j$$$ and $$$r_i=r_j$$$.
It is guaranteed that the sum of $$$n$$$ across all testcases does not exceed $$$300$$$.
For each testcase, you should output one line containing either "YES" if there is an array or "NO" if the hints are contradictory.
If the answer is "YES", additionally you should output $$$n$$$ integers corresponding to an array that satisfies the constraints. Each of these integers must be in the range $$$[1,10^9]$$$
25 41 2 U3 4 U3 5 N4 5 N5 41 2 U3 4 U3 5 N4 5 U
YES 10 9 7 8 8 YES 10 9 8 7 8
45 42 3 U1 3 N2 4 N1 4 U4 51 2 U1 3 U1 4 N2 3 N3 4 U4 51 2 N1 3 U1 4 N2 3 U2 4 N6 81 3 U1 5 U2 3 N2 4 U2 6 N3 4 U3 5 U4 5 U
NO YES 8 7 7 8 YES 7 7 8 8 YES 12 10 10 11 10 11