There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:
Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.
Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
Constraints
1 \leq N \leq 10^5
1 \leq A_i \leq 10^9
1 \leq K \leq 10^9
All
input values are integers.
Input
Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N
Output
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE; if it is not possible, print IMPOSSIBLE.
Examples
Input
3 7
9 3 4
Output
POSSIBLE
Input
3 5
6 9 3
Output
IMPOSSIBLE
Input
4 11
11 3 7 15
Output
POSSIBLE
Input
5 12
10 2 8 6 4
Output
IMPOSSIBLE
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are given an operation: take out two balls, compute absolute difference, and add a new ball with that value. The balls are not consumed? The operation says: Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. So we remove two balls, but then we return them (the same two) plus a new ball. So net effect: number of balls increases by 1 each operation. But the box initially has N balls, and we can keep adding balls with new numbers. So the set of numbers we can generate expands. We are asked if we can eventually have a ball with integer K.
Interpretation: This is reminiscent of generating numbers via Euclidean algorithm style operations. Taking two numbers a, b, we can add |a-b|. That is like adding the difference. Over repeated operations, we can generate linear combinations? Actually, this operation is similar to the process used to compute the gcd. Starting from a set of numbers, by repeatedly taking differences, we can generate any integer multiple of the gcd of the initial numbers? However, there is nuance: we can only add absolute differences, but we also keep the original numbers; we can combine any pair multiple times.
Consider the set of numbers we have. Initially set S = {A_i}. Operation: pick any x, y in S, and add |x-y| to S. Note that we keep x and y, so S expands. We want to know if K can appear in S.
Observation: The gcd of all numbers in S is invariant? Let's check: Initially, let g = gcd(A_1, ..., A_N). If we take x and y, then |x-y| is divisible by g because both x and y are multiples of g. So any new number is also a multiple of g. So gcd of the set remains g (or could become a divisor? Actually, adding a multiple of g does not change the gcd; gcd of a set of multiples of g is at least g, but could be a larger divisor? Wait, if all numbers are multiples of g, then gcd could be a multiple of g? Actually, if all numbers are multiples of g, then gcd is at least g, but could be a larger common divisor than g? For example, if initial numbers are 2 and 4, g=2. Adding |2-4|=2 still multiple of 2. gcd stays 2. If we had numbers 4 and 6, gcd=2, |4-6|=2, still 2. If we had numbers 6 and 9, gcd=3, |6-9|=3, still 3. Could we ever get a number that introduces a new divisor that reduces the gcd? Suppose initial numbers: 4, 6. gcd=2. Is it possible to get a number that is odd? 4 and 6 are even, difference is even. So all numbers remain even. So gcd remains even, at least 2. So gcd stays exactly the same? Actually, the gcd of the set might be exactly g initially. After adding numbers that are multiples of g, the gcd might still be g because the original numbers contain numbers that have exactly gcd g. But if we later add numbers that are multiples of g but perhaps we could also get numbers that are multiples of a smaller divisor? No, because the operations preserve the property that all numbers are multiples of the initial gcd? Let's think: If we start with numbers that are all multiples of d, then any difference is also a multiple of d. So all numbers remain multiples of d. So the gcd of the set is at least d. The initial set had gcd exactly g. So any d that divides all numbers must divide g. But the set's gcd could become larger than g if we lose numbers? No, we never remove numbers; we keep original numbers. So original numbers with gcd g remain in the set. So the gcd of the whole set cannot become larger than g because the original numbers themselves have gcd exactly g. So the gcd remains exactly g throughout. Therefore, a necessary condition is that g divides K. Because any number generated is a multiple of g. So if K is not divisible by g, impossible.
But is divisibility by g sufficient? Usually in such "difference" games, we can generate all multiples of g that are not larger than max? For example, with numbers a and b, by repeatedly taking differences we can generate the gcd and multiples thereof, but also numbers like? Consider the classic problem: starting with two numbers, you can generate any multiple of their gcd that does not exceed the maximum? Actually, with the operation: you have two numbers, you can replace one with the difference (like Euclidean algorithm), eventually you can get the gcd. But here you keep both and add new numbers. So the set evolves. With two numbers, say a and b (positive). By repeatedly taking differences, we can generate all multiples of g up to max(a,b)? Let's explore.
If we have two numbers a and b, with a>=b>0. Adding |a-b| = a-b. Now we have set {a, b, a-b}. With these, we can generate more differences: e.g., b and a-b, difference = |b - (a-b)| = |2b - a|. So we can generate numbers like (a mod b) essentially. This is like the Euclidean algorithm. Ultimately, we can generate the gcd g. Also, we can generate multiples of g? For instance, from {g, a}? Since a is a multiple of g, difference between a and g gives a-g, etc. Possibly we can generate any multiple of g between 1 and max? But is it always possible to get any multiple of g? Let's test with simple numbers: a=6, b=3. g=3. Initial: {6,3}. Already have 3. Can we get 0? Not needed. Can we get 9? 9 not present. Can we generate 9? Differences: |6-3|=3 already. |6-3|=3, nothing larger. We could also combine 6 and 3 again, same. To get 9, we need sum? No, only differences. So 9 is not obtainable. What about 12? No. So only numbers that are present initially or differences. With {6,3}, we cannot get 9. So not all multiples of 3 are achievable. So condition is more subtle.
But we also can keep adding new balls, so number of balls grows. However, we only care about existence of K in the set.
We need to characterize reachable numbers.
Let's think in terms of linear combinations. The operation adds absolute difference. However, note that if we consider the multiset of numbers mod something? Alternatively, we can think of the set of numbers we can generate as the set of all nonnegative integer combinations? Actually, difference is not linear combination with coefficients, but there is known result: Starting from a set of integers, by repeatedly taking absolute differences, you can generate any integer that is a multiple of the gcd and is at most the maximum initial number? Wait, consider the classic puzzle: You have a set of numbers, you can replace two numbers by their difference. That's a process that preserves the gcd, and you can end up with a set that contains the gcd. But here we are not replacing; we are adding.
But note that if we can add differences, we might be able to generate numbers that are linear combinations with coefficients of alternating signs? For example, starting from a and b, you can generate a-b, then from a and a-b, you can generate b, etc. Not helpful.
Maybe we can simulate generating any integer that is a linear combination with coefficients that are integer multiples? Because differences can be thought of as generating the lattice generated by the numbers under the operation of taking linear combinations with coefficients that sum to zero? Actually, consider we have numbers as values. The operation of adding the absolute difference, but we can ignore absolute because we can always order them to get positive difference? But absolute ensures nonnegative. However, we can also effectively subtract in either direction? Not directly, since difference is absolute, always nonnegative. But we can generate negative numbers? No, all numbers are positive? Initially A_i >=1, and absolute difference of two positive integers is >=0, but could be 0? If two numbers equal, difference is 0. But K>=1, so 0 not needed. So we only deal with positive numbers except possibly 0, but we can ignore.
Now, if we consider the set of all integer linear combinations of the initial numbers? The difference operation might be able to produce any integer that is a multiple of g and not exceeding some bound? Let's search for known results: This problem appears to be from AtCoder (maybe "Box and Ball" or something). I recall a problem: "Snuke's Coloring" no. Perhaps it's from ABC/ARC? I think I've seen a problem: "Box and Ball" with operation take two balls and add absolute difference. The key is that we can generate any multiple of gcd that is <= max(A). Actually, check examples:
Example 1: N=3, A=[9,3,4], K=7. gcd(9,3,4)=1. max=9. 7 is <=9? Yes, 7<=9. Is 7 a multiple of 1? Yes. Output: POSSIBLE. That fits hypothesis that any multiple of gcd up to max is possible? But is 7 <= max? Yes.
Example 2: N=3, A=[6,9,3], K=5. gcd(6,9,3)=3. 5 not divisible by 3 -> IMPOSSIBLE. Indeed output IMPOSSIBLE. So fits necessary condition.
Example 3: N=4, A=[11,3,7,15], K=11. Already present -> POSSIBLE. But also K=11 is multiple of gcd=1, and <=max=15? Yes. But not testing further.
Example 4: N=5, A=[10,2,8,6,4], K=12. Compute gcd: 2, all even. K=12 is divisible by 2. Max=10? Actually max is 10? 10,2,8,6,4 -> max=10. K=12 >10. Output IMPOSSIBLE. So that suggests that if K > max(A), impossible? But is that always? Consider if we could generate a number larger than the maximum initial? The operation takes absolute difference, which is always <= max of the two numbers (since difference <= larger number). So any new number added is at most the larger of the two numbers used. Since we always have the original numbers, the maximum value in the box never increases: because we take two balls, the larger of them is at most current max, and the difference is <= that larger, so the new ball's value <= current max. Actually careful: Suppose we have numbers a and b, with a >= b. Then |a-b| <= a. So the new value is <= a, which is <= the current maximum (since a is one of the numbers, and max among all numbers is at least a). So the maximum value in the set never increases; it can stay the same or possibly decrease if we add a number smaller than the max? But we keep the original balls, so the max remains at least the original maximum. Since we never remove the balls with the max value, the overall maximum of the set is constant (equal to the initial max). So any new number we add is at most that initial max. So we can never get a number larger than max(A). So necessary condition: K <= max(A). Indeed example 4: K=12 >10, impossible. So we have two necessary conditions: (1) K <= max(A), (2) gcd of all A_i divides K.
But are these conditions sufficient? Let's test more cases. For two numbers, say A=[4,6], max=6, gcd=2. K must be <=6 and multiple of 2. Which numbers satisfy? 2,4,6. Can we get 2? Yes, difference 6-4=2 -> possible. 4 is already there. 6 is already there. So yes. What about K=0? not considered. So works.
What about A=[6,9]? max=9, gcd=3. Multiples of 3 <=9: 3,6,9. Can we get 3? 9-6=3 yes. 6 present, 9 present. Works.
What about A=[5,5]? max=5, gcd=5. K multiples of 5 <=5: only 5. Already present. Can we get 5? yes. If we had A=[5,10]? max=10, gcd=5. Multiples: 5,10. 5? 10-5=5, yes. Good.
What about A=[8,12]? max=12, gcd=4. Multiples: 4,8,12. 4 obtainable? 12-8=4. Good.
Now consider three numbers, maybe more complex: A=[6,10,15]? max=15, gcd=1. So any K<=15 should be possible? Let's test K=1,2,...,15. Is it possible to get all numbers? Possibly not. But we need to check if the condition is sufficient. Let's try to see if we can get K=7 from [6,10,15]? gcd=1, max=15. 7<=15. Is it possible? Let's try to simulate: we have 6,10,15. Compute differences: |10-6|=4, add 4. Now set: 6,10,15,4. Then from 10 and 4, diff=6 (already), 15 and 4 diff=11, add 11. Set: 6,10,15,4,11. From 11 and 6 diff=5, add 5. Set now includes 5. From 5 and 4 diff=1, add 1. So we got 1. So from 1 we can generate many numbers? Actually, if we have 1 and any number up to 15, we can generate any number by repeatedly adding differences? Wait, if we have 1 and some number M, can we generate any number up to M? For example, to get 7, we could have 1 and 8 difference 7, but do we have 8? Not yet. But from 1 and 15, we can get 14. Then from 14 and 15, get 1 again, etc. But we can also generate 2: from 1 and 3? Not yet. However, if we have 1 and any number, we can produce all numbers that are multiples? Actually, consider set containing 1 and any other numbers. Since we can take difference repeatedly, we might be able to generate all numbers from 1 up to max? Let's test: start with 1 and 15. Differences: |15-1|=14, add 14. Now we have 1,15,14. Then |14-1|=13, add 13. Then |13-1|=12, etc. So indeed, if we have 1 and any number M, we can generate all numbers from 1 to M (by repeatedly subtracting 1 from M, then from M-1, etc). More formally: from x and y with x<y, you can generate y-x. If you have 1 and n, you can generate n-1, then from n-1 and n you generate 1 again? Actually, with 1 and n, you get n-1. With n-1 and n, you get 1. So you already have 1. With n-1 and 1, you get n-2. Inductively you can get all numbers down to 1. So yes, if you have 1, you can generate any integer from 1 up to max. So for gcd=1, if we can obtain 1, then any K <= max is possible. But is it always possible to obtain 1 when gcd=1? Possibly yes, because we can simulate Euclidean algorithm to get the gcd. However, need to confirm: Starting from a set of numbers with overall gcd=1, can we always generate the gcd (1) by repeated difference operations? I think yes: by repeatedly taking differences we can reduce numbers to their gcd. But here we are not replacing, we are adding. But we can still simulate the Euclidean algorithm: take two numbers a and b, and add |a-b|. By doing so, we can eventually get the remainder when dividing a by b, etc. Since we keep both numbers, we can produce the sequence of remainders from Euclidean algorithm. Ultimately, we can produce the gcd. So if gcd=1, we can produce 1. Therefore, when gcd=1 and K <= max, it's possible.
Now, what if gcd = d > 1? Then we can divide all numbers by d and consider the reduced problem. Let B_i = A_i / d, K' = K / d must be integer. Then operation on original numbers corresponds to operation on reduced numbers scaled by d: because |A_i - A_j| = d * |B_i - B_j|. So if we can generate K' in the reduced set (with numbers B_i), then we can generate K in original set by scaling. So the problem reduces to the case where gcd=1. So the necessary and sufficient condition becomes: K is divisible by g = gcd(A), and K <= max(A) and ??? Actually, from reduced case, we need that K' <= max(B) i.e., K/d <= max(A)/d => K <= max(A). So same condition. And we also need that when gcd=1, any K <= max is possible? Let's verify if any K <= max is always possible when gcd=1. Consider a set where gcd=1 but there is a gap: can we always generate all numbers up to max? We argued that if we can generate 1, then we can generate all numbers up to max. But can we always generate 1? Is it always possible to generate the gcd via difference operations? In the Euclidean algorithm, starting from any set of integers, we can generate their gcd by repeatedly taking differences. But careful: In Euclidean algorithm, we usually need the ability to replace numbers, but here we only add numbers, not replace. However, adding differences is enough because we can add new numbers, and we still have the original numbers. To generate 1, we can mimic the Euclidean algorithm: take two numbers, add their difference; we may need to repeatedly take differences of the new numbers to get smaller remainders. Since we keep all numbers, we can eventually get down to the gcd. Let's consider a generic set. Suppose we have numbers a and b. By repeatedly taking differences, we can generate all remainders from the Euclidean algorithm: e.g., we can generate a mod b (if a >= b) as follows: we have a and b. Compute a-b, we have a, b, a-b. Now we can compute (a-b) - b = a-2b if a-b >= b; but we need to be careful: we can take differences between a-b and b: |(a-b) - b| = |a-2b|. So we can generate numbers like a - kb for various k, as long as we can successively subtract b. But can we generate a mod b? In Euclidean algorithm, we subtract multiples of the smaller number from the larger until we get remainder less than b. The process uses repeated subtraction, which corresponds to taking differences multiple times. But can we simulate repeated subtraction with only the operation of adding absolute differences? Let's see: Starting with a and b (a > b). We want to generate a mod b. We can do: take a and b, get a-b. Now we have a, b, a-b. Then take a-b and b (if a-b >= b), get a-2b. Continue. However, each step adds a new number that is the difference of the previous generated number and b. So after k steps, we can have a - kb, as long as a - (k-1)b >= b to take difference. Eventually, when we get a - kb < b, we have a number r such that 0 <= r < b. That is exactly the remainder. So we can generate r. So yes, we can generate a mod b. Then we can proceed with b and r, generate b mod r, etc. Ultimately we can generate gcd(a,b). So with two numbers, we can generate their gcd. With more than two numbers, we can take two numbers, generate their gcd d1, then consider d1 and another number to generate gcd(d1, A3) which is overall gcd, etc. But careful: To generate gcd of all numbers, we can sequentially: generate gcd of first two, then that gcd with third, etc. But do we have the ability to "use" the generated gcd as a ball? Yes, once we generate the gcd of two numbers (as a ball), it's in the set. Then we can pair it with a third number to generate gcd of that and the third, which equals overall gcd. So indeed we can generate the overall gcd. So if gcd=1, we can generate 1.
Thus for gcd=1, any K <= max is possible. Let's verify with a potential counterexample: Suppose A = [6,10,15] we already got 1. So yes.
What about A = [2,4,6]? gcd=2, max=6. K must be even and <=6. So possible K: 2,4,6. Can we get 2? Yes, from 4 and 6 diff=2. 4 present, 6 present. So ok.
What about A = [6,10,14]? gcd=2, max=14. Even K <=14: 2,4,6,8,10,12,14. Can we get 8? Let's see. Starting with 6,10,14. gcd=2, we can get 2? 10-6=4, 14-10=4, 14-6=8? Actually 14-6=8, so 8 is directly obtained! So yes. 12? 14-? 14-2? but we need 2. Generate 2? gcd 2. 14-2=12, but we need 2 first. Can we get 2? Compute: 10-6=4, 14-10=4, then 6-4=2? Wait 6-4=2 but absolute difference between 6 and 4 is 2 (since we have 6 and 4). So after adding 4 from 10-6, we have 4,6,10,14. Then |6-4|=2 -> add 2. So we have 2. Then |14-2|=12 -> add 12. So 12 obtainable. So all even numbers up to 14 appear possible. So it seems plausible that any multiple of g up to max is reachable.
But is there any scenario where K is a multiple of g and <= max but not reachable? For instance, consider A = [5, 5, 5] (all equal). gcd=5, max=5. K must be 5. Already present. So ok.
Consider A = [6,9] we saw 3 and 6 and 9 are possible. But what about K=0? Not needed.
Consider A = [4,8]? gcd=4, max=8. K=4? Already present or from diff 8-4=4. K=8 present. K=0 no.
What about A = [7, 14]? gcd=7, max=14. K=7? 14-7=7. K=14 present. So ok.
Now consider A = [6,7,9]? gcd=1, max=9. K=8? Is 8 possible? Let's try. We have 6,7,9. Differences: 9-7=2 -> add 2. Set: 6,7,9,2. Then from 7 and 2 -> 5. From 9 and 5 -> 4. From 6 and 4 -> 2 (already). From 7 and 5 -> 2. From 9 and 2 -> 7 (already). From 6 and 2 -> 4. From 9 and 4 -> 5. Hmm can we get 8? Maybe use 9 and 1? Need 1 first. Can we get 1? gcd=1, so we should be able to get 1. Let's try to get 1 via Euclidean: from 6 and 7, difference 1? |7-6|=1! Yes, 7-6=1. So we have 1. Then from 9 and 1 -> 8. So 8 is possible. So yes.
Now consider A = [10, 15, 25]? gcd=5, max=25. K multiples of 5 up to 25: 5,10,15,20,25. Can we get 20? 25-5=20, need 5. Can we get 5? gcd 5: from 15 and 10 diff=5. So yes.
What about more tricky: A = [6, 8, 10]? gcd=2, max=10. Multiples: 2,4,6,8,10. Can we get 2? 8-6=2. So yes. 4? 8-4? But need 4? 10-6=4, so directly 4. So all good.
Thus seems condition is: g | K and K <= max(A). But is there any other hidden condition? Let's consider case where K = 0? Not in constraints.
But wait: In example 4, they gave output IMPOSSIBLE: N=5, A=[10,2,8,6,4], K=12. gcd=2, K=12 divisible by 2. max=10, 12>10, so impossible. That's consistent.
Now consider edge cases: Suppose N=1. Only one ball with value A1. Then operation requires two balls, but we only have one. So we cannot perform any operation. So the only possible K is if K equals A1. So the condition should be: K == A1. But our condition would be: g = A1, must have g | K => K multiple of A1, and K <= max = A1 => K <= A1, so K must be equal to A1 (since positive integer multiple <= A1 implies K = A1). So that works. For N=1, our condition yields that K must be exactly A1.
For N=2, if A1 != A2, we might be able to generate numbers. Condition seems correct.
But is it possible that K could be less than or equal to max and multiple of g but still impossible due to parity or something? Let's think deeply.
The operation essentially allows us to generate any integer combination that lies in the lattice generated by the numbers? More formally, the set of all numbers we can generate is the set of all nonnegative integer linear combinations? Actually, the operation adds the absolute difference. But difference can be thought of as a combination: x - y or y - x. However, we can simulate addition? Not directly because we can't add two numbers. But we can generate numbers like x+y? Possibly through multiple steps? For example, from x and y we have difference d = |x-y|. Can we get sum? Not directly because sum would be larger than max. Since we argued max never increases, we cannot get sum if sum > max. So no.
Given that max never increases, any number we can generate must be ≤ max initial. So K > max => impossible. So condition necessary.
Now, suppose K ≤ max and g divides K. Is it always possible? Let's attempt to construct a counterexample.
We need a set where gcd=1, max=M, but some number less than M cannot be generated. Is there any number that cannot be generated? We argued that if we can generate 1, then any number up to M can be generated by repeatedly subtracting 1 from M or from larger numbers. But to subtract 1 from M, we need 1 and M. But we might not have M? Actually we have max M, so we have the ball with value M. And if we can generate 1, then we can get M-1 via |M-1| = M-1. Then from M-1 and M, we can get 1 again, but we already have M-1. Then from M-1 and 1, we can get M-2, etc. So indeed we can generate all numbers from 1 to M. So the key is: can we always generate the gcd (1)? In the gcd=1 case, we need to be sure we can generate 1. As argued, using Euclidean algorithm we can generate gcd of any two numbers. However, we must ensure that we can use the numbers in the set to compute gcd of the entire set. Since we can only add numbers, but we keep all numbers, we can produce the gcd of two numbers by repeatedly adding differences. But is there any scenario where the Euclidean algorithm gets stuck because we need to subtract multiples, and we might need to do many subtractions? But the process described earlier (repeatedly taking difference with the same smaller number) can generate the remainder. However, each step adds a new number, but we might need to do many steps. That's fine; we can do unlimited operations.
But is there any limitation: In Euclidean algorithm, we usually compute a mod b by subtracting b from a as many times as needed. With the operation, we can only subtract one b at a time by taking difference between current number and b. Starting with a and b, we can compute a-b. Then from a-b and b, we get a-2b. Continue. But to get a-kb, we need to have the number a-(k-1)b and b. Since we keep all intermediate numbers, we can continue. So after k steps, we get a-kb. So yes, we can simulate repeated subtraction.
But there is a nuance: The operation adds absolute difference, which is always nonnegative. However, if a-(k-1)b is less than b, then |(a-(k-1)b) - b| = b - (a-(k-1)b) = kb - a. That is not the remainder we want; it's the complement. That's okay because when the remainder becomes less than b, we might generate both the remainder and its complement. Let's see the process: Suppose a > b. We generate a-b. If a-b >= b, we continue. At some step, we have r = a - qb where 0 <= r < b. At that step, we have number a - (q-1)b, which is >= b? Actually, let's simulate: a=13, b=5. Step1: diff = 8. (13,5,8). Step2: take 8 and 5, diff = 3. (now have 3). Now 3 < 5. That 3 is the remainder. So we got r=3. So Euclidean remainder is generated. Good. So we get r directly when a - (q-1)b >= b? Actually, in step2: we had 8 (which is a-b) and 5, diff = 3. That's because 8-5=3, which corresponds to a-2b. Since 8 >= 5, we get a-2b=3. So indeed we got remainder 3. So the process yields remainder directly without needing to handle the case where number becomes less than b? Wait, we need to be careful: At step2, we used 8 and 5. Since 8 >=5, difference is 8-5=3. So we get a-2b. In general, after q-1 steps, we have a - (q-1)b. At that point, if a-(q-1)b >= b, we take difference with b to get a - qb, which will be the remainder r. So we get r. So indeed we generate r when we still have a number >= b. So the process works.
Thus, we can generate the remainder. So Euclidean algorithm works.
Now, can we generate the gcd of all numbers? Yes. So condition seems sufficient.
But wait, there is a subtlety: In Euclidean algorithm, we need to have the two numbers at each step. After generating remainder r, we might want to continue with b and r to compute next remainder. But we still have b and r as balls. So we can proceed.
Thus, if gcd=1, we can get 1.
Now, if gcd = d > 1, we can divide everything by d. Then in reduced set, we can generate any K' <= max(B) = max(A)/d, since gcd(B)=1. That means we can generate K' if K' <= max(B). Multiplying by d, we get K if K <= max(A). So condition holds.
Thus, answer: POSSIBLE if (K <= max(A)) and (K % gcd(A) == 0). Otherwise IMPOSSIBLE.
But need to check if there is any scenario where K = 0? Not in constraints.
Also need to check if K is exactly 0? Not needed.
Let's test more edge cases:
N=2, A=[1, 10^9], K=10^9-1. gcd=1, max=10^9, so K<=max, yes, should be possible. Indeed we can generate 1 from 1 and 10^9? Actually we already have 1. Then 10^9-1 = |10^9 - 1|, so we can get it directly. So yes.
N=2, A=[2,4], K=2. works.
N=2, A=[3,9], K=6. gcd=3, max=9, 6<=9 and divisible by 3 => possible? 9-3=6, yes.
N=3, A=[5,10,20], K=15. gcd=5, max=20, 15<=20, 15%5=0 => possible? 20-5=15, need 5. Have 5. So yes.
N=3, A=[5,10,20], K=25. 25 > max 20 => impossible.
N=2, A=[6,10], K=2. gcd=2, max=10, 2<=10, divisible by 2 => possible? 10-6=4, then 6-4=2? Actually 6 and 4 diff=2. But need 4 first. 10-6=4 gives 4. Then 6-4=2. So yes.
N=2, A=[6,10], K=8. 8 <=10, 8%2=0 => possible? Can we get 8? 10-? 10-2=8, but need 2. We have 2 eventually as above. So we can get 2, then 10-2=8. So yes.
Now, is it always possible to get any multiple of g up to max? For N=2, yes as we argued.
But what about N=3 where gcd=1 but max is small and we can get 1, then all numbers up to max? Yes.
Thus seems straightforward.
But I recall some AtCoder problem that had this exact solution. It might be from ABC 059 C or something? Actually, I recall a problem: "Snuke's Coloring" no. There's a problem called "Box and Ball" from ABC/ARC? Let me think: There is AtCoder Beginner Contest 118 C? That problem was about health and gcd. Not that. Actually, there is a problem: "Snuke's Coloring" is different.
But I think it's from AtCoder Regular Contest 064? Or maybe from AtCoder Beginner Contest 100 C? Not sure.
Anyway, the solution is simple.
But we must also consider the case where K is exactly 0? Not needed. But constraints say 1 <= K <= 1e9.
So algorithm: compute g = gcd of all A_i. Compute m = max(A_i). If K <= m and K % g == 0, print "POSSIBLE", else "IMPOSSIBLE".
Now, there might be nuance: If K=0, but not considered.
Edge: N=1, A=[5], K=5 => g=5, m=5, K<=5 and divisible => POSSIBLE. If K=10 => K>5 => impossible. If K=3 => not divisible? 3%5 !=0 => impossible. So correct.
Now, is there any scenario where K is exactly 0? Not needed.
Also, note that the operation allows taking out two balls, and they are returned along with a new ball. So number of balls increases, but values never exceed max. So condition seems correct.
But is there any scenario where K is less than or equal to max and divisible by gcd but still impossible because we cannot generate numbers smaller than some threshold? For instance, consider A=[6,10,15] we already got 1. But what if we have A=[6,10,14]? gcd=2, we can get 2. Then all even numbers up to 14 should be reachable. I think yes.
Double-check with A=[4,6,8]? gcd=2, max=8. Even numbers: 2,4,6,8. 2 can be obtained? 6-4=2, yes. So all.
But what about A=[4,8,12]? gcd=4, max=12. Multiples of 4 up to 12: 4,8,12. Already there. But can we get 0? not needed.
Now, consider A=[4,10,14]? gcd=2, max=14. Even numbers: 2,4,6,8,10,12,14. Can we get 6? 10-4=6, yes. 8? 14-6? but need 6 first, then 14-6=8, yes. 12? 14-2=12, need 2. 2? 10-8? need 8? Actually simpler: 4 and 10 diff=6; 10 and 14 diff=4? Actually 14-10=4 already have. But 2? 4-? we have 4 and 6 diff=2, so yes. So all.
Thus seems fine.
But I want to think of a more formal proof.
Let S be the set of numbers in the box. Define d = gcd of all numbers in S. As argued, d remains invariant (since all numbers are multiples of d, and original numbers remain, so gcd stays exactly d). So necessary condition: d divides K.
Now, define M = max(S). M is invariant because we never add a number larger than existing max. So necessary: K <= M.
Now we need to show that if d | K and K <= M, then K can be generated.
We can scale down by d: Let A_i' = A_i / d, K' = K / d, M' = M / d. Then we need to show that if gcd(A_i') = 1 and K' <= M', then K' can be generated.
Thus, it suffices to prove for the case where gcd=1.
Claim: If gcd(A_i) = 1, then any integer t with 1 <= t <= M (max of A_i) can be generated.
Proof: Since gcd=1, we can generate 1. (Because we can compute gcd via Euclidean algorithm). Once we have 1 and M (which is present), we can generate M-1 by taking difference. Then we have M-1 and M, we can generate 1 (already) but also we have M-1. Then using 1 and M-1 we can generate M-2. Inductively we can generate all integers from 1 to M. So any t in [1, M] is reachable. This completes the proof.
Now, the step "generate 1" requires that we can compute gcd of the whole set using allowed operations. Provide constructive method: pick two numbers a and b. Perform Euclidean algorithm to produce gcd(a,b) by repeatedly adding differences. Since we keep all numbers, we can always produce the remainder of a divided by b. The algorithm terminates with the gcd. So we get g1 = gcd(a,b). Then pick another number c. Since we have g1, we can repeat Euclidean algorithm with g1 and c to get gcd(g1,c) = gcd(a,b,c). Continue until we have overall gcd. Since initial overall gcd is 1, the final number we generate is 1.
Thus, condition is sufficient.
Hence solution: compute g = gcd of all A, m = max(A). If K <= m and K % g == 0, output "POSSIBLE", else "IMPOSSIBLE".
Now, we must be careful about cases where K is exactly 0? Not needed.
But is there any scenario where K = 0? The problem says 1 ≤ K, so ignore.
Now implement: N up to 1e5, A_i up to 1e9, K up to 1e9. Compute gcd using Euclidean algorithm in O(N). Compute max simultaneously. Then check conditions.
Edge: if K is 0? Not allowed. But if we consider K=0, can we generate 0? Possibly if we have two equal numbers, difference =0. But not needed.
Double-check with a case: N=2, A=[2,4], K=0? Not in constraints.
One more test: Suppose N=2, A=[3,5]. gcd=1, max=5. K=4 => 4<=5 and divisible by 1 => should be possible. Can we get 4? 5-3=2, then 3-2=1, then 5-1=4. So yes.
Now, need to confirm that we can indeed generate gcd when numbers are large but we are limited by number of operations? Not a concern.
Thus, the solution is trivial.
But wait, we must consider if the operation is "take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written." This means that we do not remove the two balls; we return them plus the new ball. So net increase of one ball each operation. That's consistent.
Now, is there any nuance about the order? We can pick any two balls. So we can generate any difference.
Thus answer is correct.
Now, we should implement.
But before finalizing, let's consider a potential counterexample: Suppose we have numbers [6,10,15] again. gcd=1, max=15. K=14? Should be possible. We already have 15 and 1 -> 14, so yes. K=13? 15 and 2? 2 from? Actually we can get 2 (15-13?) But we can generate 13 from 15 and 2? need 2. But we can get 2: from 6 and 4? Actually need 4. Let's see if we can get 13 directly: from 15 and 2, but we need 2. Alternatively, we can get 1, then 14, then 13 from 14 and 1? But 14 we get from 15 and 1, then 14-1=13? Actually difference between 14 and 1 is 13, yes. So we can: 1, then 15-1=14, then 14-1=13. So yes.
Now K=12: 15-3? need 3. But we have 3? 15-12? Actually we can get 3 from 6 and 3? Wait we have 6 and 3? Initially we have 6,10,15, we don't have 3. But we can get 3: from 6 and 9? don't have 9. But we can get 3 via Euclidean: 15 and 6? 15-6=9, 9-6=3, yes. So we can. So ok.
Now consider A = [6, 9, 12]? gcd=3, max=12. Multiples of 3 up to 12: 3,6,9,12. Can we get 3? 9-6=3. Yes. So all.
Now consider A = [4, 6, 9]? gcd=1, max=9. Can we get 5? 9-4=5? Actually 9-4=5. But we have 4 and 9, difference =5 directly. So yes. Get 7? 9-2=7? need 2. 2 from 6-4=2. So 7. So all good.
Now consider A = [1000000000, 1]? gcd=1, max=10^9. Any K up to 10^9 possible? With 1 and 10^9, we can produce all numbers. Yes.
Now consider A = [10, 30, 50]? gcd=10, max=50. K=20? 20<=50 and multiple of 10 => possible? Need to generate 20. We have 10,30,50. 30-10=20. So yes. K=40? 50-10=40, yes. K=10 present. K=30,50 present. K=0? not needed.
Now consider A = [10, 30]? gcd=10, max=30. K=20 possible. Good.
Now consider A = [8, 12, 16]? gcd=4, max=16. Multiples: 4,8,12,16. 4? 12-8=4. So yes.
All good.
Now, check if there is any case where K is exactly max but not divisible by gcd? But max is a multiple of gcd because all numbers are multiples of gcd. So if K = max, then K % g = 0 automatically? Because max is one of the numbers, and each A_i is multiple of g, so max is multiple of g. So K = max automatically satisfies divisibility. So if K = max, condition reduces to K <= max (true) and divisibility automatically. So always possible if K equals max, which makes sense because it's already there.
Now, consider case where K is less than max and divisible by g but maybe we cannot generate it because we need some intermediate numbers that are not reachable due to parity or something? I want to search for a pathological case where the set contains numbers that are all even except one odd? But if gcd=1, we have both parities? Not necessarily. Example: A = [6,10,15] has both even and odd. But consider A = [6,10,14]? gcd=2, not gcd=1. For gcd=1, we must have at least one odd and even? Actually if all numbers are even, gcd at least 2. So if gcd=1, there must be at least one odd. But could it be that all numbers are odd? Then gcd of odd numbers could be 1, but all numbers odd, then differences of two odds are even. So we could generate even numbers. So parity not an obstacle.
Now, consider A = [6,10,15] we already did. So it's fine.
One more: A = [9,15,21]? gcd=3, not 1. For gcd=1 case, maybe A = [9,25,49]? All odd, gcd=1? 9 and 25 gcd=1, yes. So we have odd numbers. Differences between odds are even, so we get even numbers. Then from even and odd, we get odd, etc. So can generate all.
Thus I'm convinced.
Now, we need to code.
But wait, the problem might have an alternative interpretation: The operation takes out two balls and returns them along with a new ball. It does not say you cannot take out the same ball twice? Probably you take out two distinct balls. Usually "take out two balls" means two distinct balls. But if there is only one ball, you can't. So N>=2 needed to perform operation. But N could be 1. As argued, then only possible K is that one number.
Thus algorithm holds.
Now, we must be careful about integer overflow? Not an issue.
Implementation steps:
Read N, K.
Read list A of length N.
Compute g = 0; for each a in A: g = gcd(g, a). (Use math.gcd or implement Euclidean)
Compute m = max(A).
If K <= m and K % g == 0: print("POSSIBLE") else print("IMPOSSIBLE").
But check: For N=1, m = A[0], g = A[0], K must satisfy K <= A[0] and K % A[0]==0 => K == A[0] (since positive). So correct.
Edge: if K=0? Not in constraints.
Now, think about time complexity: O(N log(max(A))) for gcd.
Now, is there any case where K is 0? If it were, condition would be 0 <= m and 0 % g ==0 always true. So would say POSSIBLE. But can we generate 0? Yes, if we have two equal numbers, difference =0. But if initial set has no equal numbers, we might still generate 0 via differences? Possibly through operations? For example, a and b, difference d. Not zero unless a=b. But we could generate a number and then later generate its difference with itself? But we can't take out the same ball twice? We need two balls; they could be two distinct balls with the same value? If we have multiple balls with same value, we can take two of them to get 0. But if initially all numbers distinct, can we ever get 0? To get 0, we need two balls with the same number. Could we generate a duplicate? Possibly by generating a number that already exists, but that would be the same value, not necessarily distinct balls? Actually, we add a new ball each operation. So we may end up with multiple balls with the same value. For example, from [1,3], we can get 2. Now we have 1,3,2. Not duplicate yet. From 1 and 2 we get 1? Actually |1-2|=1, so we add another 1. So now we have two balls with value 1. Then we can take those two 1's and get 0. So yes, we can generate 0 even if initially all distinct. So if K=0 were allowed, it would be possible whenever gcd condition? Actually, is there any scenario where 0 cannot be generated? Possibly if max is 0? But all A_i >=1, so we have positive numbers. Using the process, we can always generate 1 eventually (if gcd=1), then from 1 and 1 we can get 0. If gcd >1, scaled version: After scaling, we get 1? Actually if gcd = d>1, then after dividing by d, we may not have 1; but in the original numbers, all are multiples of d. Can we generate 0? To get 0, we need two equal numbers. Could we generate two equal numbers? For example, A=[2,4] (gcd=2). Can we generate 0? From 2 and 4 we get 2 (diff=2). Now we have 2,4,2 -> two 2's. Then difference of two 2's is 0. So yes. In general, can we always generate two equal numbers? Possibly yes: take a and b, generate |a-b|. If a and b are not equal, we might eventually get two equal numbers. But if all numbers are multiples of d, we can get two numbers equal to d? By generating d (gcd) as before. Then we have at least one d. But we need two d's. Can we get another d? Yes, after generating d once, we can generate it again perhaps by similar operations, or by taking d and some other number that yields d again? For example, from d and a multiple of d (say 2d), diff = d, so we can produce another d. So we can have multiple d's. Then two d's give 0. So 0 is generatable regardless? Actually, if d>0, then 0 is always generatable? Let's test with A=[2,6]? gcd=2. Generate 4 from 6-2? Actually 6-2=4. Now we have 2,6,4. From 4 and 2 diff=2 -> add another 2. Now we have two 2's. Then 2-2=0. So yes. For A=[3,6]? gcd=3. 6-3=3 -> add another 3. Then two 3's yield 0. So 0 seems always generatable if we can perform at least one operation? But if N=1, we cannot perform any operation, so cannot generate 0. So for N>=2, 0 is probably always generatable? But not needed.
But this is just a side note.
Now, we should double-check with constraints: N up to 1e5, so straightforward.
Thus final answer.
However, one nuance: The operation requires taking out two balls from the box, and then returning them along with a new ball. So the total number of balls increases by 1. It doesn't say that the two balls are removed temporarily but returned, so they remain. So the set of values never loses any original numbers. So our invariant holds.
Now, I'll write solution.
But I recall a AtCoder problem that had a similar condition but also required that K be less than or equal to the maximum and divisible by gcd. But there was a twist: If K is equal to max, it's possible; if K is less than max, need also that K is at least something? Not needed.
I will now search memory: There is a problem "ABC 071 B" no. Actually, there is a problem "AtCoder ABC 118 C - Monsters Battle Royale" which asks: given N numbers, repeatedly replace two numbers with their absolute difference (like reducing set). That problem asks for the minimum possible final number, which is the gcd. That's a different operation: you take two monsters and they fight, both remain? Actually, in that problem, the operation is: choose two monsters, the stronger one's health becomes the absolute difference; you reduce number of monsters? Wait, the problem "Monsters Battle Royale" from ABC 118 C: You have N monsters with health values. You can choose two monsters, they fight, and the health of the stronger becomes the absolute difference; the weaker dies? Actually I recall: In that problem, you repeatedly choose two monsters, and the health of the larger is reduced by the health of the smaller? Or the smaller is removed? Let me recall: "Monsters Battle Royale" is: You have N monsters, you can choose two, and the health of the stronger becomes the absolute difference of their health; the weaker dies (its health becomes 0 or is removed). So the number of monsters decreases. The final remaining monster's health is the gcd. That's different because here we add a ball, not remove. So that problem's answer is gcd. This problem is a variation where we add balls.
Yes, this problem is reminiscent of that but with addition instead of removal. So it's like the opposite: we can generate many numbers.
Thus, I'm confident.
Now, let's ensure that we have not missed any condition when K is less than some minimal value. For instance, if the smallest number in the set is greater than K, could we generate K? According to our condition, if K <= max and divisible by gcd, we can generate it. But suppose all numbers are large, like [100, 102]? gcd=2, max=102. K=2? Should be possible: 102-100=2, so yes. K=4? 102-? 102-2=100? That gives 100, not 4. But we can get 2, then 102-2=100? Actually 102-2=100, not 4. But we can get 4 maybe via 100-? Wait: 100-? We have 100,102,2. From 100 and 2, diff=98; not 4. From 102 and 100, diff=2. To get 4, maybe need 2 and 2? But we have only one 2. Could we generate another 2? Yes, from 102 and 100 again gives another 2? Actually operation doesn't consume balls, so we can generate another 2 by taking 102 and 100 again, adding another ball with value 2. Then we have two 2's. Then difference of two 2's is 0, not 4. To get 4, we could do 102-98? Not there. Or 100-96? Not there. Perhaps we can get 4 via: 100 and 102 gave 2, then from 100 and 2 we got 98, then from 102 and 98 we get 4? 102-98=4. Indeed! Steps: Have 100,102. Add diff=2 (call it ball C). Now have 100,102,2. Take 100 and 2, diff=98, add 98. Now have 100,102,2,98. Take 102 and 98, diff=4, add 4. So yes, we can get 4. So all good.
Now, consider A = [6,10] we already got 2,4,6,8,10.
So seems all multiples of gcd up to max reachable.
But is there a case where K is smaller than the minimum of the set? For instance, A=[7, 21]? gcd=7, max=21. K=7? already present. K=14? 21-7=14. So okay. K=0? not needed.
Now consider A=[9,15]? gcd=3, max=15. K=3? 15-9=6, 9-6=3. So yes.
Now consider A=[6,9,12]? gcd=3, max=12. K=3? 9-6=3. So yes.
Thus, all good.
Now, consider a more exotic set: A = [30, 42, 70]? gcd=2? Let's compute: 30,42 gcd=6, 6 and 70 gcd=2. So g=2, max=70. Even numbers up to 70. Can we get 2? 42-30=12, 30-12=18? Actually maybe simpler: 70-42=28, 42-28=14, 28-14=14? Wait, we can get 2 eventually. Probably yes.
Thus, the condition is sufficient.
Now, what about the possibility that K is exactly 0? Not required.
Therefore, final answer.
Now, let's code in Python.
We'll read input with sys.stdin.read().split().
Pseudo:
import sys
def main():
data = sys.stdin.read().split()
if not data: return
N = int(data[0]); K = int(data[1])
A = list(map(int, data[2:]))
g = 0
for a in A:
import math
g = math.gcd(g, a)
m = max(A)
if K <= m and K % g == 0:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
if name == "main":
main()
That should work.
But we must be careful: math.gcd(0, a) = a, so we can initialize g=0.
Now, just to be thorough, we should also think about the scenario where K = 0? Not needed.
Also, note that K can be equal to max? Already covered.
Thus, answer is correct.
One more nuance: The operation uses absolute difference, which is always non-negative. But we argued that max never increases, but could max decrease if we somehow lose the ball with max value? We never remove balls, so the ball with max value remains. So max stays.
But what if there are multiple balls with max value? That's fine.
Thus, invariants hold.
Now, I'll provide solution.
But let's double-check the proof that any t between 1 and M can be generated when gcd=1. As argued, we can generate 1. Then from 1 and M, we generate M-1. Then we have M-1. Now we have 1 and M-1, we generate M-2. Continue. However, we need to ensure that at each step, we can generate the next smaller number using the numbers we have. Induction: Suppose we have numbers 1 and all numbers from t to M (for some t). Then we can generate t-1 by taking M and (M - (t-1))? Actually, we can use 1 and t to generate t-1? |t-1|? Wait, if we have 1 and t, difference is |t-1| = t-1 (since t>=1). So to generate t-1, we need 1 and t. So if we have all numbers from 1 to M, we can generate any smaller number? But we start with 1 and M, then we get M-1. Now we have 1, M-1, M. To get M-2, we can use 1 and M-1: | (M-1) - 1 | = M-2. So yes. Then we have 1, M-2, M-1, M. To get M-3, use 1 and M-2, etc. So by induction, we generate all down to 1. So any t in [1, M] is eventually generated. So after we have 1, we can generate all numbers <= M.
Now, we need to ensure that we can generate 1. That is the critical part.
Proof of generating 1: Since overall gcd is 1, there exists a sequence of operations to produce 1. One constructive method: Use two numbers at a time. Let current set S. While we don't have 1, pick two numbers a, b from S with a > b. Compute r = a mod b using repeated differences? Actually, we can simulate the Euclidean algorithm by repeatedly generating differences. More precisely, we can generate the remainder of a divided by b: Let a >= b. We can generate a - b, then from that and b generate a - 2b, and so on until we get a - qb < b. This number is the remainder r. So we generate r. Then we have b and r. Now replace (conceptually) the pair with (b, r) but we keep all numbers. Then repeat with b and r (ensuring the larger first). This process will eventually yield gcd(a,b). Since we keep all numbers, we can later use that gcd. And we can combine gcds of pairs to get overall gcd. Since gcd of whole set is 1, after processing all numbers we can get 1.
Implementation-wise, we don't need to actually simulate; we just need to know it's possible. So condition is sufficient.
Thus, answer is as described.
Now, final code.
But before final, think about potential pitfalls: For large N, computing max and gcd is fine. The condition K % g == 0 uses modulo, but if g=0? Not possible because N>=1 and A_i >=1, so g>=1.
Now, what about negative numbers? Not allowed.
Thus, all good.
Now, I'll produce final answer in the required format.
But wait, I recall a similar problem "Snuke's Coloring" is different. However, there is a known AtCoder problem "Box and Ball" where the operation is exactly this. I think the solution indeed is this.
Now, let's consider if there is any scenario where K is less than or equal to max and divisible by gcd, but we cannot generate 1 in the reduced case because the process might need to generate numbers that exceed some bound? But we argued max never increases, so numbers generated are at most max. However, during Euclidean algorithm, intermediate numbers like a - qb may be less than or equal to a, so they are ≤ max. So fine.
Thus, answer is correct.
Now, implement.
But I realize there is a subtlety: In the Euclidean algorithm, we may generate numbers that are larger than the max? No, because a - b <= a, and a is ≤ max. So all generated numbers ≤ max. So it's fine.
Thus, finalize.
Now, I'll output "POSSIBLE" or "IMPOSSIBLE".
One more test: N=2, A=[2,3], K=1. gcd=1, max=3, 1<=3, divisible -> POSSIBLE. Indeed, |3-2|=1. Good.
N=2, A=[2,4], K=1. gcd=2, 1%2 !=0 -> IMPOSSIBLE. Indeed, all numbers remain even, so cannot get odd. So correct.
Now, consider N=2, A=[10,20], K=5. gcd=10, 5%10 !=0 -> IMPOSSIBLE. Because all numbers multiples of 10, can't get 5.
Now, consider N=2, A=[10,20], K=10 -> POSSIBLE.
All consistent.
Now, one more: N=2, A=[100, 101], K=1 -> POSSIBLE, 101-100=1.
Thus, solution stands.
Now, we can write final answer.
But I'm still slightly uneasy: In the process of generating all numbers from 1 to M, we rely on having 1 and M. But what if we cannot generate 1 before we have M? M is present initially, so we have M. So we need to generate 1. That is done via Euclidean algorithm. However, could it be that the Euclidean algorithm requires generating numbers that are not allowed because we might need to generate a number that is larger than M? No, as argued.
But is it guaranteed that we can generate the gcd of the whole set without ever needing to take a difference between two numbers that are not present? We can always pick two numbers from the set. So it's fine.
Thus, all good.
Now, coding.
We'll write Python solution.
We may also consider using functools.reduce for gcd.
Implementation:
import sys, math
def solve():
data = sys.stdin.read().split()
if not data: return
N = int(data[0]); K = int(data[1])
A = list(map(int, data[2:]))
g = 0
for a in A:
g = math.gcd(g, a)
m = max(A)
if K <= m and K % g == 0:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
if name == "main":
solve()
Now, ensure that we handle the case where N=0? Not possible.
Now, is there any possibility that K is exactly 0? Not in constraints.
Thus, final.
I'll produce final answer with explanation.
But wait, let's verify with a random test via mental simulation: A=[12,18,27]. gcd=3? 12,18 gcd=6; 6 and 27 gcd=3. So g=3. max=27. K=9: 9%3=0, 9<=27 -> POSSIBLE. Can we get 9? 27-18=9, yes. K=6: 12-? 18-12=6, yes. K=15: 27-12=15, yes. K=21: 27-6=21? need 6, we have 6. So yes. K=24: 27-3=24? need 3. Can we get 3? 12 and 9? need 9 first, then 12-9=3. So yes. So all multiples of 3 up to 27 are possible. K=3: 12-9=3, etc. So good.
Now, what about A=[2,4,8]? gcd=2, max=8. K=2,4,6,8. 6? 8-2=6, need 2. Yes. So okay.
Thus, condition is sufficient.
Now, I'll produce final answer.
But there is a nuance: The operation returns the two balls along with a new ball. So the numbers we can generate include all numbers that can be expressed as linear combinations with coefficients? Actually, after we have 1 and M, we can generate any number up to M. That's convincing.
Now, I'll present solution.
But maybe there is a scenario where gcd=1 but we cannot generate 1 because all numbers are greater than 1 and the process of generating differences might always produce numbers that are multiples of some other number? No.
Consider A=[6,10,15] we got 1. Consider A=[6,10,14]? gcd=2, not 1.
Consider A=[9,15,21]? gcd=3, not 1.
Consider A=[9,15,20]? gcd=1? 9,15 gcd=3, 3 and 20 gcd=1, so gcd=1. Can we get 1? Let's try: 20-15=5; 15-9=6; 9-5=4; 5-4=1. So yes.
Now, consider A=[100, 105, 140]? gcd? 100,105 gcd=5, 5 and 140 gcd=5, so g=5, not 1.
Now, consider A=[6,10,14,15]? gcd=1? 6,10 gcd=2; 2 and 14 gcd=2; 2 and 15 gcd=1, yes. Can we get 1? Probably.
Thus, it's fine.
Now, one more subtlety: In the Euclidean algorithm, we need to be able to take two numbers that are the current "pair" for the algorithm. But after generating many numbers, we might have many numbers; we can always choose the appropriate ones. So fine.
Thus, final answer.
Now, I'll produce final solution with explanation.
But the problem might be from AtCoder, and they expect this solution.
Now, I'll produce final answer in the required format.
Will write code accordingly.
Potential pitfalls: Input reading: N K on first line, then A list possibly across lines. Using split reads all.
Now, confirm that K can be up to 1e9, and A_i up to 1e9, so product fits in Python int.
Now, done.
Thus, final answer. ```python
import sys
import math
def solve() -> None:
data = sys.stdin.read().split()
if not data:
return
N = int(data[0])
K = int(data[1])
A = list(map(int, data[2:]))
code
# greatest common divisor of all A_i
g = 0
for a in A:
g = math.gcd(g, a)
# maximum value
m = max(A)
if K <= m and K % g == 0:
print("POSSIBLE")
else:
print("IMPOSSIBLE")