You are given three positive (i.e. strictly greater than zero) integers x, y and z. Your…
- User
You are given three positive (i.e. strictly greater than zero) integers x, y and z.
Your task is to find positive integers a, b and c such that x = max(a, b), y = max(a, c) and z = max(b, c), or determine that it is impossible to find such a, b and c.
You have to answer t independent test cases. Print required a, b and c in any (arbitrary) order. Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains three integers x, y, and z (1 ≤ x, y, z ≤ 10^9).
Output
For each test case, print the answer:
- "NO" in the only line of the output if a solution doesn't exist;
- or "YES" in the first line and any valid triple of positive integers a, b and c (1 ≤ a, b, c ≤ 10^9) in the second line. You can print a, b and c in any order.
Example
Input
5 3 2 3 100 100 100 50 49 49 10 30 20 1 1000000000 1000000000
Output
YES 3 2 1 YES 100 100 100 NO NO YES 1 1 1000000000
Assistant
We need to find positive integers a, b, c such that:
x = max(a, b) y = max(a, c) z = max(b, c)
Given x, y, z.
We need to determine if such a, b, c exist, and if yes find any.
We can think about constraints. Since max(a,b)=x, max(a,c)=y, max(b,c)=z.
Let’s denote m1=x, m2=y, m3=z.
We need to assign a,b,c >=1.
Observations:
Let M = max(x,y,z). The maximum among a,b,c must equal M? Let's see.
Since x = max(a,b), the maximum of a and b is x, so x >= a,b. Similarly y >= a,c and z >= b,c.
The maximum of all three numbers a,b,c, say Mabc = max(a,b,c). Then we have that Mabc is equal to max of the two numbers involved in at least one equation. Specifically, Mabc = max(a,b) or max(a,c) or max(b,c) depending. Actually Mabc = max(a,b,c) = max( max(a,b), c ) = max(x, c). But also = max( max(a,c), b ) = max(y, b), and = max( max(b,c), a ) = max(z, a). So x, y, z must be at least Mabc? Actually, if Mabc = a, then max(a,b)=a => x = a; max(a,c)=a => y = a; and then z = max(b,c) could be less or equal to a? Since a is max, b,c <= a. Then max(b,c) <= a. But z must be exactly max(b,c). So we have x = a, y = a, and z = max(b,c). So we would have x=y=a and z <= a.
Similarly if Mabc = b, then x = b, z = b, and y = max(a,c) <= b, so y <= b, and x = y? Actually no, x = b, z = b, but y could be less or equal. So we get x=z=b, y <= b.
If Mabc = c, then y = c, z = c, and x = max(a,b) <= c, so x <= c, and y=z=c.
Thus, for existence, it seems that at least two of x,y,z must be equal and they should be the largest? Actually from above, if the max among a,b,c is unique, then the two equations where that variable appears should be equal to that max, and the third equation (involving the other two variables) must be less than or equal to that max, but exactly equal to the max of the other two. So basically, the largest of x,y,z should appear at least twice. For example, if a is the max, then x = a, y = a, so x=y and that common value is >= z. Also z = max(b,c) must be <= a. And we need to find b,c such that max(b,c) = z, and both b <= a, c <= a (since a is max). That's possible as long as z <= a. And also we must have a positive. So we can set a = the common value (x=y). Then choose b and c such that max(b,c)=z and both <= a. For example, set b = z, c = 1? But must ensure max(b,c) = z. So we can set b = z, c = 1 (or c = something <=z) but need max(b,c)=z. So we can set b = z, c = z? But then max(b,c)=z, and both <= a if z <= a. Also need to satisfy x = max(a,b) = max(a,z) = a if a >= z, which holds. y = max(a,c) = max(a,z) = a if a>=z. So works.
But careful: if we set c = z, then y = max(a,c) = max(a,z) = a, okay. And x = max(a,b) = max(a,z) = a, okay. So a = common value, b=z, c=z works. However, check if b and c positive. Yes. But could there be cases where a is max but b or c > a? No, a is max. So constraints.
Now what if the max among a,b,c is not unique? If two or three are equal to M. Then the equations? Let's analyze general conditions.
We have three equations: x = max(a,b), y = max(a,c), z = max(b,c).
We can think in terms of ordering.
Let’s denote the sorted values: Suppose we have a,b,c. The maximum of each pair is given.
Observation: The three numbers x,y,z must satisfy that the maximum of x,y,z appears at least twice. Because consider the maximum M = max(x,y,z). Suppose w.l.o.g. x = M (largest). Since x = max(a,b), we have a or b = M? Actually x = max(a,b) = M, so at least one of a,b is M. Without loss, assume a = M (if not, then b = M; but we can consider symmetry). Then we have a = M. Then y = max(a,c) = max(M,c) = M (since M is max, and c can be ≤ M). So y must be at least M? But y is max(a,c) and a=M, so y = max(M,c) = M if c <= M, or y = c if c > M, but c cannot be > M because M is maximum among x,y,z? Actually we haven't established that M is the maximum of a,b,c; we are considering the case x = M is the largest among x,y,z. But we could have a > M? That would make x = max(a,b) >= a > M, contradiction because x = M. So a cannot be > M. But a could be less than M if b = M. So if x=M and b=M then a <= M. So at least one of a,b = M. So either a=M or b=M.
Case 1: a=M. Then as argued, y = max(a,c) = max(M,c). Since M is max among x,y,z and y is some value (<=M), we must have y <= M. For max(M,c) to be ≤ M, we need c ≤ M. Then y = M if c ≤ M? Actually max(M,c) = M if c <= M. That would force y = M. But y might be less than M? No, max(M,c) is always at least M (since M >= c, the max is M). So if a = M, then y = M exactly. So we must have y = M. Therefore, y must equal M as well. So we deduce that if the maximum M appears as x, then we must have y = M as well, provided we assume a = M. But we could also have b = M. Then consider b = M. Then z = max(b,c) = max(M,c). Similarly, that forces z = M (since max(M,c) >= M, and to have z ≤ M, we need c ≤ M, then z = M). So if b = M, then z = M. So either way, if the maximum M appears in one of x,y,z, then at least two of them must equal M. Because either the variable that is M in the pair (a,b) corresponds to a leading to y=M, or b leading to z=M. But careful: could it be that both a and b are less than M but x=M? No, because max(a,b)=M implies at least one of a,b = M. So exactly one or both equal M. So indeed at least one of a,b = M. If a=M, then y=M. If b=M, then z=M. So in any case, at least two among x,y,z must be M. So the condition is: the maximum of x,y,z must appear at least twice.
Now, is this condition also sufficient? Let's test.
Suppose the maximum M appears exactly twice (or three times). Without loss, assume x = y = M and z ≤ M (or x = z = M and y ≤ M, etc.) Or all three equal M.
We need to construct a,b,c.
Case A: x = y = M, z ≤ M.
From x = max(a,b) = M, y = max(a,c) = M. We want to satisfy z = max(b,c). Since x and y both are M and involve a, it suggests that a = M works (since max(a,b)=M and max(a,c)=M). If we set a = M, then we need to choose b and c such that max(b,c)=z, and also max(M,b)=M => requires b ≤ M, similarly c ≤ M. That's fine. So we can set b = z, c = z (or b = z, c = 1 provided max(b,c)=z, but must ensure c ≤ z? Actually if we set b = z and c = 1, then max(b,c)=max(z,1) = z if z>=1, which holds. And check y = max(a,c) = max(M,1)=M, okay. So many possibilities. However, we also need to ensure that x = max(a,b) = max(M,z) = M (since M >= z). So yes. So a=M, b=z, c=z works. But careful: if we set b = z, c = z, then max(b,c) = z, fine. But note that a, b, c are positive. So this works as long as z ≤ M.
But what if z = M? Then all three equal M. Then a=M, b=M, c=M works.
Case B: x = z = M, y ≤ M. Symmetrically, we can set b = M, a = y? Wait we need to ensure the equations. For x = max(a,b)=M, z = max(b,c)=M. So b should be M? Because max(a,b)=M, if we set b=M, then regardless of a ≤ M, x = M. And z = max(b,c)= max(M,c) = M if c ≤ M. So we can set b = M, then choose a and c such that y = max(a,c) = y (given y ≤ M) and also ensure a ≤ M, c ≤ M. We can set a = y, c = y? But then max(a,c)=y, works. However, need to check x = max(a,b) = max(y, M) = M (since M≥y), okay; z = max(b,c) = max(M, y) = M, okay. So b=M, a=y, c=y works.
But careful: does y have to be equal to max(a,c)? If we set a=y, c=y, then max(a,c)=y indeed. So that works.
Case C: y = z = M, x ≤ M. Then set c = M, and a = x, b = x? Let's test: y = max(a,c) = max(a, M) = M (requires a ≤ M), okay. z = max(b,c) = max(b, M) = M (requires b ≤ M), okay. And x = max(a,b) = max(x, x) = x (since a=b=x, x ≤ M, so max = x). That works if we set a=x, b=x, c=M.
Thus, for any case where the maximum appears at least twice, we can construct a solution.
Now, is it possible that a solution exists when the maximum appears only once? Let's try to find a counterexample or proof. Suppose all three x,y,z are distinct, with maximum M appearing only once. Then we argued that if a,b,c exist, then the maximum among a,b,c must be attained by some variable, say it's a. Then as earlier, we have x = a and y = a, so x = y = M (since a = M). That would imply two of them equal M. Contradiction. If the max is b, then x = b, z = b => x = z = M. If the max is c, then y = c, z = c => y = z = M. So indeed, the maximum among a,b,c must be at least two of the pair max values. Thus, if the maximum among x,y,z appears only once, impossible. So condition is necessary and sufficient.
Now we must also check other constraints: we need positive integers ≤ 1e9. Given inputs up to 1e9, our constructions produce numbers within [1, 1e9] as long as we don't exceed. We need to ensure that our constructed numbers do not exceed 1e9? But the problem allows up to 1e9, and we are using values from input which are ≤ 1e9, so it's fine.
Edge cases: When the maximum appears twice but the third value is less than the maximum, our constructions are valid as described. But what about the case where the maximum appears twice but the third value is greater than the maximum? That cannot happen because maximum is defined as the max of the three, so third value ≤ maximum.
Now, test given examples.
- 3 2 3: max = 3 appears twice (x=3, z=3), y=2 ≤ 3. So case x=z=M=3, y=2. Construction: b=M=3, a=y=2, c=y=2? Wait careful: For x=z=M, we set b=M? Actually according to case B: x = max(a,b)=M, z = max(b,c)=M. So b should be M. Set b = M = 3. Then set a = y = 2? But we also need y = max(a,c) = 2. If we set a = 2 and c = 2, then max(a,c)=2, works. Check x = max(2,3)=3, y = max(2,2)=2, z = max(3,2)=3. Works. Output: 2 3 2? But sample output: 3 2 1. Our construction gives a=2, b=3, c=2 (or order?). The sample says "YES" then "3 2 1". That's also valid: a=3,b=2,c=1 gives: max(a,b)=max(3,2)=3=x, max(a,c)=max(3,1)=3? Wait y=2 given, but that gives 3, not 2. Actually sample says "3 2 1" but we must map to a,b,c. If we output "3 2 1", which order? They said any order. Let's test: suppose a=3, b=2, c=1. Then x = max(a,b)=max(3,2)=3, y = max(a,c)=max(3,1)=3 (but y should be 2). So that doesn't match. Perhaps they output in order a,b,c? Actually the problem statement: "print required a, b and c in any (arbitrary) order." So the triple they printed could be a=3, b=2, c=1 but then y would be max(3,1)=3, not 2. That's not correct. Wait let's re-check sample input:
5 3 2 3 ...
Output: YES 3 2 1
Maybe they printed x,y,z? No. Let's test other possibilities: Could the triple be a=3, b=1, c=2? If we assign a=3,b=1,c=2, then max(a,b)=3, max(a,c)=max(3,2)=3, max(b,c)=max(1,2)=2, not matching 3,2,3. So that gives (3,3,2). Not correct.
Perhaps the output order is a,b,c and they have a=2,b=3,c=1? That yields max(a,b)=3, max(a,c)=max(2,1)=2, max(b,c)=max(3,1)=3 -> (3,2,3). Yes! So a=2, b=3, c=1. That's triple 2 3 1. But they printed "3 2 1". In any order, they could have printed b, a, c or something. For triple (2,3,1) sorted as 3,2,1 is just sorted descending. So they printed numbers in some order but not necessarily a,b,c. So it's fine.
Our construction gave a=2,b=3,c=2. That gives (2,3,2): max(a,b)=3, max(a,c)=max(2,2)=2, max(b,c)=max(3,2)=3 -> (3,2,3). So that also works. So both are valid.
-
100 100 100: all equal. Our construction a=100,b=100,c=100 works.
-
50 49 49: max = 50 appears only once (since 50, 49, 49). So NO. Sample says NO. Good.
-
10 30 20: max = 30 appears only once (10,30,20). So NO. Sample says NO.
-
1 1000000000 1000000000: max = 1e9 appears twice (y=z=1e9, x=1). So YES, and sample output: YES \n 1 1 1000000000. That matches our construction: c=M=1e9, a=x=1, b=x=1? Actually case C: y=z=M, x≤M. Set c=M=1e9, a=x=1, b=x=1. Then max(a,b)=1, max(a,c)=1e9, max(b,c)=1e9. Works. So our construction yields 1 1 1000000000. Good.
Thus, solution: For each test case, compute M = max(x,y,z). Count how many of x,y,z equal M. If count >= 2, then possible. Then output "YES" and construct as per the pattern.
But careful: There might be an edge case when the two equal maxima are not exactly the ones we assume? But we can handle generically.
Construction:
We need to output a,b,c. Let's denote the three numbers: x,y,z.
If x == y == z: then output a=x, b=x, c=x (or any permutation). Works.
Else if x == y (and they are the maximum, i.e., x >= z): then we can set a = x, b = z, c = z (or a=x, b=z, c=1? but better to keep simple). Wait condition: x == y >= z. But need to ensure x is maximum? Since they are equal and at least z. So M = x. Then set a = x, b = z, c = z? Check: x = max(a,b) = max(x,z) = x (since x>=z). y = max(a,c) = max(x,z)=x, but y should be x (equal). That's okay but y becomes x, which is same as given. However, given y is x as well, so it's fine. But check z output: we need z given = max(b,c) = max(z,z) = z. So works. So for x==y, we can output a = x, b = z, c = z. But note: in the example with x=3,y=2,z=3, x != y, so not this case.
Alternatively, if x == z and x >= y: then set b = x, a = y, c = y? Check: x = max(a,b) = max(y, x) = x (since x>=y). y = max(a,c) = max(y,y)=y. z = max(b,c) = max(x,y)=x (but z=x). So works. So output a=y, b=x, c=y? Wait order? The triple we output can be in any order, but we need to specify a,b,c. Let's decide a consistent mapping.
Better: We can unify:
Let M = max(x,y,z). Let the two that equal M be, say, p and q, and the third be r (r ≤ M). Then we need to assign a,b,c.
If the two that are M are x and y, then we set a = M, b = r, c = r? Actually if x and y are M, then from earlier, a=M works, b=r, c=r. Then x = max(a,b)=M, y = max(a,c)=M, z = max(b,c)=r. Works. Output a=M, b=r, c=r.
If the two that are M are x and z, then we set b = M, a = r, c = r. Then x = max(a,b) = max(r, M)=M, y = max(a,c)=max(r,r)=r? But y should be r? In this case the third is y = r. So we need y = max(a,c)=r. With a=r, c=r, max=r, works. So output a=r, b=M, c=r.
If the two that are M are y and z, then set c = M, a = r, b = r. Output a=r, b=r, c=M.
If all three equal M, then any works, say a=M, b=M, c=M.
But wait: In case x and y are M, we set a=M, b=r, c=r. Then y = max(a,c) = M, which is correct because y=M. Good.
Now check example 1: x=3, y=2, z=3. M=3, the two M's are x and z, so case (x,z) are M, third r = y = 2. According to case x and z are M: we set b = M = 3, a = r = 2, c = r = 2. So triple (a,b,c) = (2,3,2). That's valid. Output could be "2 3 2" or in any order. Sample printed "3 2 1" but that's different. Could also be "2 3 2". That is fine.
But note: In the construction above, we used a=r, b=M, c=r. That yields a=2,b=3,c=2. However, check: x = max(a,b)=max(2,3)=3, correct; y = max(a,c)=max(2,2)=2, correct; z = max(b,c)=max(3,2)=3, correct. So yes.
But sample output gave 1,1,1e9 for case 5 which matches our case y and z are M, third r=x=1: set c=M=1e9, a=r=1, b=r=1 -> (1,1,1e9). So matches.
Now we must ensure that all constructed numbers are positive. r is positive because given numbers are >=1. M is positive. So all good.
But is there any scenario where the construction fails because r could be greater than M? No, by definition r ≤ M because M is the maximum.
Now, what about cases where two equal maxima but the third is also equal? That's all equal case, covered.
Thus solution is simple.
But wait, is there any other subtlety? Could there be a solution when the maximum appears at least twice but the construction of a,b,c with the above assignments might violate the condition that a,b,c must be positive integers? Yes they are positive.
Double-check boundary: suppose M appears twice, and the third value r is less than M. Then our construction gives a and/or b and/or c equal to r. That's fine. But what if r = 0? Not possible because all inputs ≥1.
Thus algorithm:
For each test case:
- read x,y,z.
- Find M = max(x,y,z).
- Count how many of x,y,z equal M.
- If count < 2: print "NO".
- Else:
- If x == y == z: print "YES"; print x y z (any order, e.g., x y z).
- Else if x == y and x == M (i.e., x==y>=z): // x and y are M a = x, b = z, c = z. print a,b,c.
- Else if x == z and x >= y: // x and z are M a = y, b = x, c = y.
- Else if y == z and y >= x: // y and z are M a = x, b = x, c = y.
- (We can just determine which two are M) But careful: There could be cases where two are M but also the third equals M? That's covered by all equal case; but we can also treat as any of the above because if all equal, then r = M, and our construction for say x and y are M would set a=M, b=r=M, c=r=M -> (M,M,M) which works. So we don't need separate all equal; our generic handling for two M cases works also when r=M. Let's test: if x=y=z=M, then we could have any pair as the two M. Suppose we pick x and y as M (they are), r=z=M. Then construction: a=M, b=M, c=M. Works. So we can unify.
Thus we can just: find which positions are maximum.
Implementation:
We have variables x,y,z.
Let mx = max(x, max(y,z)).
If (x == mx) + (y == mx) + (z == mx) >= 2: // possible. // we need to output a,b,c. // Determine the third value (the one that is not mx, if any; if all three are mx, then third can be any, say pick one) // Let's assign: // We'll set (a,b,c) accordingly based on which two are mx. // Actually we can assign as per the logic: // if x == mx and y == mx: // a = mx, b = z, c = z // elif x == mx and z == mx: // a = y, b = mx, c = y // elif y == mx and z == mx: // a = x, b = x, c = mx // else: (all three) fall into any, e.g., x == mx and y == mx (since all three, this case will trigger as x==mx and y==mx true, so we'll use that). That's fine. // But careful: if all three equal, then the third value z = mx, so a=mx, b=mx, c=mx. Works. // However, if all three equal, and we use the case x==mx and y==mx, we set a=mx, b=z, c=z -> b=mx, c=mx. Works. // So all good. // Print YES and the triple (a,b,c) in order. Else: print NO
But is there any scenario where the construction fails for case where two are maximum but the third is less, but we use the wrong mapping? Let's test each.
Case: x and y are M, third = z = r. Construction: a=M, b=r, c=r. Check: max(a,b)=max(M,r)=M (x). max(a,c)=max(M,r)=M (y). max(b,c)=max(r,r)=r (z). Works.
Case: x and z are M, third = y = r. Construction: a=r, b=M, c=r. Check: max(a,b)=max(r,M)=M (x). max(a,c)=max(r,r)=r (y). max(b,c)=max(M,r)=M (z). Works.
Case: y and z are M, third = x = r. Construction: a=r, b=r, c=M. Check: max(a,b)=max(r,r)=r (x). max(a,c)=max(r,M)=M (y). max(b,c)=max(r,M)=M (z). Works.
So it's correct.
Now consider a tricky case: maybe there is an alternative solution that works even if maximum appears only once? Let's try to see if there could be a scenario where a,b,c are not positive? For example, x=5, y=4, z=3. Max=5 appears once. Suppose we try to assign a,b,c. If a is max, then x=5, y=5 -> but y=4, contradiction. If b is max, then x=5, z=5 -> but z=3. If c is max, then y=5, z=5 -> but y=4 or z=3. So no. Could there be a case where the max among a,b,c is not unique? For instance, a=b=M, c<M. Then x = max(a,b)=M, y = max(a,c)=M, z = max(b,c)=M. So all three x,y,z would be M. So that would be all equal. So if max appears exactly once in x,y,z, impossible. So condition stands.
One more corner: what if the maximum appears twice but the third value is greater than the maximum? Impossible by definition.
Thus solution is straightforward.
Now, we need to output triple. We need to make sure that we output as three numbers, order arbitrary. We can output our constructed a,b,c in that order, but the problem doesn't require mapping to specific variables? Actually it says "print required a, b and c in any order." So we can print three numbers, and they will be interpreted as the values of a, b, c, but in any order? Wait reading: "print required a, b and c in any (arbitrary) order." That means the three numbers we output can be in any permutation of a,b,c. So we don't have to specify which is which; they just need to be a valid triple. So we can output our triple as e.g., (a,b,c) in some order, but it's simpler to output the numbers in the order we constructed (a,b,c). However, careful: The problem statement says "print required a, b and c in any (arbitrary) order." This is ambiguous: Does it mean that the order of a, b, c in the output does not matter, i.e., we can output them in any order (like a, b, c but we can permute them), or does it mean we can print any triple (maybe not even correspond to a,b,c in the original assignment)? The typical Codeforces problem (I recall this is Codeforces Round # #, maybe problem "Three Integers" or similar) says you can output a, b, c in any order, meaning you can output them as any permutation. So we can output our triple as we compute.
Thus algorithm done.
Now complexity O(t). t up to 2e4.
We must be careful with integer overflow? Not needed.
Now, confirm with more tests.
Test: x=5,y=5,z=1. M=5 appears twice (x,y). Our construction: a=M=5, b=z=1, c=1 -> triple (5,1,1). Check: max(5,1)=5=x, max(5,1)=5=y, max(1,1)=1=z. Works.
Test: x=5,y=1,z=5. Construction: a=y=1? Actually x and z are M: case x&z M => a = y = 1, b = M = 5, c = y = 1 -> (1,5,1). Check: max(1,5)=5=x, max(1,1)=1=y, max(5,1)=5=z. Works.
Test: x=1,y=5,z=5. Construction: a=x=1, b=x=1, c=M=5 -> (1,1,5). Check: max(1,1)=1=x, max(1,5)=5=y, max(1,5)=5=z. Works.
Test: x=100,y=100,z=100 => (100,100,100). Works.
Test: x=100,y=99,z=99. M=100 appears once (only x). So NO.
But is there any scenario where x=100,y=100,z=50, but our construction yields a=100,b=50,c=50. That's fine.
Now, what about very large numbers, e.g., x=1e9, y=1e9, z=1e9-1? Works.
Now, confirm that the constructed numbers are within [1,1e9], yes.
Thus we can implement.
But wait: There is a nuance: In our construction for case x and y are M, we set a = M, b = z, c = z. This gives a = M, b = z, c = z. But what if z = 0? Not possible. If z = 1, fine.
But is there any scenario where the construction fails because it would violate the condition that a,b,c are positive integers? Positive integer means ≥1. All good.
Now, consider if two are maximum, but the third value is also maximum? That's all equal; our construction gives a=M, b=M, c=M, fine.
Now, is there any possibility that the given numbers are such that the maximum appears twice but the construction leads to a,b,c that are not consistent with the definition? For example, if x and y are M, but we set b=z and c=z. However, we must also ensure that max(a,b) = M. This holds if M >= z, which is true because M is max. Similarly for y. And max(b,c)=z holds because both b and c are z. So okay.
Now, think about potential pitfalls: The problem states that a, b, c must be positive integers. Our construction always uses input values (which are positive) or the max (positive). So all good.
Now, I'm thinking if there could be a case where the maximum appears twice but we have to output a different triple because our constructed triple might not satisfy some hidden constraints? No.
Thus solution is simple.
But wait, the problem says "find positive integers a, b and c such that x = max(a, b), y = max(a, c) and z = max(b, c)". In our construction for case x and y M, we set a = M, b = z, c = z. Then max(a,b) = max(M,z) = M = x. max(a,c) = M = y. max(b,c) = max(z,z) = z. So indeed correct.
Now check if any alternative scenario where we need to ensure a,b,c are distinct? Not required.
Thus answer.
Now let's implement.
Implementation details:
We can read t, loop.
For each test:
Read x, y, z.
Find mx = max(x, max(y, z)).
Count cnt = (x==mx) + (y==mx) + (z==mx).
If cnt < 2: print "NO".
Else: print "YES" if x == mx and y == mx: a = mx b = z c = z elif x == mx and z == mx: a = y b = mx c = y elif y == mx and z == mx: a = x b = x c = mx else: // all three equal, covered by any of above, but just in case: a = mx b = mx c = mx
print a, b, c (as integers)
But note: In the case where all three equal, it will fall into the first if condition if x==mx and y==mx (true), so we'll output (mx, mx, mx) because z=mx. So it's fine.
Alternatively, we can set a, b, c more elegantly.
One might also consider: Find which two are max: if x == mx and y == mx -> a=mx, b=z, c=z; elif x == mx and z == mx -> b=mx, a=y, c=y; elif y == mx and z == mx -> c=mx, a=x, b=x.
But we need to output three numbers; order doesn't matter, but we are outputting a,b,c in that order. That's fine.
Now test with sample.
Case1: 3 2 3 -> mx=3, cnt: x=3,y=2,z=3 => cnt=2. Which condition? x==mx and z==mx => true for elif x==mx and z==mx? Actually x==mx true, z==mx true, but condition in code: first if x==mx and y==mx: false. Then elif x==mx and z==mx: true. So we set a=y=2, b=mx=3, c=y=2. Output: "2 3 2". But sample output printed "3 2 1". Our answer is also valid, but does the judge accept any valid triple? Yes. So it's fine.
Case2: 100 100 100 -> mx=100 cnt=3. Condition first if x==mx and y==mx true, so output a=100, b=z=100, c=z=100 => "100 100 100". Works.
Case3: 50 49 49 -> mx=50 cnt=1 => NO.
Case4: 10 30 20 -> mx=30 cnt=1 => NO.
Case5: 1 1000000000 1000000000 -> mx=1e9, cnt: x=1 not mx, y=mx, z=mx -> cnt=2. Condition y==mx and z==mx true (third elif): a=x=1, b=x=1, c=mx=1e9 -> "1 1 1000000000". Works.
Thus matches sample output except first case, but valid.
Now we must ensure we output "YES" and then the triple on next line. Also note: The output for "YES" should be uppercase, and "NO" similarly.
Edge Cases: t up to 20000, fine.
Potential pitfalls: reading large numbers, using Python ints fine.
Now, before finalizing, consider if there is any alternative solution that might be required if the maximum appears twice but with some subtle condition? For instance, if x=3, y=3, z=2, our construction yields a=3, b=2, c=2. That's fine. But could there be a scenario where the third value is less than the max, but our construction yields b and c = r, but maybe r is not <= max? It is <= max by definition. But what if r is 0? Not allowed.
Now, is there any scenario where the two maxima are not adjacent? All fine.
Thus solution accepted.
Now, but let's also think about a proof for necessity and sufficiency.
We can also consider solving via reasoning about inequalities.
Given x = max(a,b), y = max(a,c), z = max(b,c).
Let’s denote A = a, B = b, C = c.
We have:
x >= a, x >= b, and x equals either a or b. y >= a, y >= c. z >= b, z >= c.
Moreover, at least two of a,b,c are <= the respective max.
We can think: Without loss, sort x,y,z? Actually we can try to assign based on the maximum.
Given the analysis earlier, condition is that max(x,y,z) must appear at least twice.
We could also argue that x, y, z must satisfy that the minimum of the two largest equals the largest? Hmm.
But above is fine.
Now, I'll produce final answer.
Implementation in Python:
def solve(): import sys input = sys.stdin.readline t = int(input().strip()) out_lines = [] for _ in range(t): x, y, z = map(int, input().split()) mx = max(x, y, z) cnt = (x == mx) + (y == mx) + (z == mx) if cnt < 2: out_lines.append("NO") else: # Determine which two are mx if x == mx and y == mx: a = mx b = z c = z elif x == mx and z == mx: a = y b = mx c = y elif y == mx and z == mx: a = x b = x c = mx else: # all three equal, but we can assign any a = mx b = mx c = mx out_lines.append("YES") out_lines.append(f"{a} {b} {c}") sys.stdout.write("\n".join(out_lines))
But careful: In the case all three equal, the first if condition x==mx and y==mx will be true because x==mx and y==mx, so it will go into that branch. That's fine. Actually we might not need else.
Now, but consider case: x=5, y=5, z=5, we will go to first branch, output a=5, b=z=5, c=z=5 => "5 5 5". Good.
Now, test with x=5, y=3, z=5, second branch, a=y=3, b=5, c=y=3 => "3 5 3". Check: x = max(3,5)=5 ok; y = max(3,3)=3 ok; z = max(5,3)=5 ok.
Now, test x=2, y=5, z=5, third branch, a=x=2, b=x=2, c=5 => "2 2 5". Check: x = max(2,2)=2 ok; y = max(2,5)=5 ok; z = max(2,5)=5 ok.
Edge: x=5, y=5, z=2: first branch => a=5, b=2, c=2 => works.
Edge: x=5, y=2, z=5: second branch => a=2, b=5, c=2 => works.
Edge: x=2, y=5, z=5: third branch => a=2, b=2, c=5 => works.
Now, could there be a case where two are max but the third is not less? That is all equal, still works.
Now, check a case where two are max but the two max are not uniquely determined? Eg: x=5, y=5, z=5: any branch works.
Now, what about case where cnt>=2 but the max appears more than twice? Only three numbers, so cnt can be 2 or 3.
Now, verify that the constructed numbers are always positive. Since mx >=1 and other values are >=1, yes.
Now, we should also verify that a,b,c do not exceed 1e9. Input values are up to 1e9, so mx <= 1e9, others also ≤ 1e9. Our assignments are just copying these values, so within bound.
Now, is there any scenario where our assignment might produce a,b,c > 1e9? Not.
Thus solution is correct.
But is there any hidden nuance about "positive integers" meaning strictly greater than zero? Yes, so all good.
Now, we can produce final answer.
We should also note that the problem may require a, b, c up to 10^9, but our construction uses the input values, which are within 10^9, so fine.
Now, we can present solution.
However, we need to make sure that in the output, the order of a,b,c is arbitrary; but we are outputting a,b,c in a specific order. That's acceptable.
Now, I'll produce final answer.
But wait, is there any case where the given condition holds but our construction fails because we set both b and c to the smaller value r, but then maybe max(b,c) = r, but what if r is not equal to the given third value? But r is exactly the third value. For case x and y are max, third is z, so we set b=z, c=z. Then max(b,c)=z, correct. So fine.
Now, one more check: Could there be a case where the two max are x and y, but the third value z is not less than mx? It must be ≤ mx because mx is max. So okay.
Thus solution is correct.
I'll produce final answer.
But we should also note that if the maximum appears twice, we could have alternate constructions like a = mx, b = r, c = 1 (if r>1) but we prefer simple one.
Now, we need to output "YES"/"NO" exactly.
Complexities: O(t).
Now, final answer.
However, there is a known Codeforces problem "1368A? Actually I recall problem "A. Three Pairwise Maximums" from Codeforces Round #1385? Actually it's "A. Three Pairwise Maximums" from Codeforces Round #1385. The solution is exactly this.
Now, done.
I'll write answer in explanation and provide code.
One more thing: The problem says "print required a, b and c in any (arbitrary) order." That means the triple we output can be interpreted as a, b, c but we can output them in any order; but we need to output three numbers. So our output is fine.
Thus final. The problem reduces to a simple necessary and sufficient condition: the largest among the three given numbers must appear at least twice. If it appears only once, no solution exists. Otherwise, we can construct a valid triple as follows:
- Let (M = \max(x, y, z)) and let (r) be the remaining value (the one that is not (M) when exactly two are equal to (M); if all three are equal, (r = M)).
- Depending on which two numbers equal (M):
- If (x = y = M) (or all three equal), set (a = M,\ b = r,\ c = r).
- If (x = z = M), set (a = r,\ b = M,\ c = r).
- If (y = z = M), set (a = r,\ b = r,\ c = M).
These assignments always satisfy the equations.
import sys def solve() -> None: it = iter(sys.stdin.read().strip().split()) t = int(next(it)) out = [] for _ in range(t): x = int(next(it)) y = int(next(it)) z = int(next(it)) mx = max(x, y, z) cnt = (x == mx) + (y == mx) + (z == mx) if cnt < 2: out.append("NO") continue # two or three are equal to mx if x == mx and y == mx: a, b, c = mx, z, z elif x == mx and z == mx: a, b, c = y, mx, y elif y == mx and z == mx: a, b, c = x, x, mx else: # all three equal (should not happen because cnt>=2 covers it) a = b = c = mx out.append("YES") out.append(f"{a} {b} {c}") sys.stdout.write("\n".join(out)) if __name__ == "__main__": solve()