We need to analyze the problem: We have N numbers (heights). We have an operation: we can apply a powder to one sugarcane which doubles its height. We can apply the powder multiple times? The problem statement: "He finds a powder which when applied to one of his sugarcanes will double the height of that sugar cane." It doesn't say he can use it multiple times; but likely he can apply it repeatedly. Typically such problems: given the ability to multiply any element by 2 any number of times (or maybe only once?), determine if we can make all numbers equal. Usually it's about scaling up by powers of two. But let's think: He can apply to one sugarcane, doubling its height. There's no mention of limit on number of uses. So presumably we can double any sugarcane any number of times. But is there any cost? The question is: "whether is it possible to make all the sugarcanes of the same height?" So we can choose to apply the powder (operation) any number of times on any canes. However, only operation is doubling. No other operation like reducing or halving. So we can only increase heights, not decrease. Therefore, to make all equal, we need to see if we can multiply each height by some power of two (including 2^0 = 1) so that all become equal to some common target H. That is, for each initial height a_i, there exists a non-negative integer k_i such that a_i * 2^{k_i} = H. So H must be a multiple of each a_i by a power of two. Equivalently, H must be such that after dividing H by a_i, the quotient is a power of two. So the problem reduces to: Is there a number H that can be expressed as a_i * 2^{p_i} for all i, with p_i >= 0 integers.
We can think about dividing all numbers by the largest power of 2 common factor? Another approach: For each a_i, we can keep dividing by 2 while the number is even, to get its "odd part". That is, each number can be written as odd_i * 2^{e_i}. Then after multiplying by additional 2^{k_i}, the final height becomes odd_i * 2^{e_i + k_i}. So the odd part remains unchanged. Therefore, for it to be possible to equalize, all numbers must have the same odd part. Because if we multiply by powers of two, the odd component stays the same. So condition: The reduced odd part (i.e., after removing all factors of 2) for all numbers must be identical. Then we can make them equal by making the total exponent (e_i + k_i) equal for all i, i.e., aligning powers. Since we can increase exponents arbitrarily, we can always make them equal as long as we can increase some to match the maximum exponent among them? Let's see: Suppose all odd parts equal O. Then each number is O * 2^{e_i}. We can multiply by 2^{k_i} to get O * 2^{e_i + k_i}. We want to find a common exponent E such that for each i, there exists k_i >= 0 with e_i + k_i = E. That means E must be >= each e_i, and for each i, k_i = E - e_i >= 0 integer. So we can choose E = max(e_i). Then for those with smaller e_i, we multiply to increase exponent to E. So yes, it's possible. So the necessary and sufficient condition is that after removing all factors of 2, all numbers are equal (i.e., have same odd core). That's typical.
But wait, we need to consider if we can apply powder to any sugarcane only once? The problem statement: "He finds a powder which when applied to one of his sugarcanes will double the height of that sugar cane." It doesn't say he can apply multiple times. But often such puzzles allow repeated application. However, the phrase "one of his sugarcanes will double the height" might imply a single application per sugarcane? Or he can apply it multiple times? Usually it's like a magic powder that doubles the height; he could use it multiple times if he buys more? Not specified. But given typical programming problems (like from HackerEarth or Codeforces "Make Product Equal One" etc), it's about being able to multiply by 2 any number of times. But sometimes it's "you can apply the powder any number of times". But the problem statement doesn't explicitly limit to one use. Let's see sample: Input: 2, 1 and 23. Output: NO. If we can only apply once per sugarcane? Let's test: We have 1 and 23. Could we make them equal with only one application? Options: apply to 1: becomes 2, then compare to 23 (no), apply to 23: becomes 46, compare to 1 (no). Or apply to both? Possibly we can apply to each at most once? That would still not equal. But maybe we can apply multiple times: We could apply to 1 multiple times: 1->2->4->8->16->32->64... never equals 23 because 23 is odd and any power of two times 1 is a power of two, cannot become 23. So it's NO. So sample consistent.
Another test: Suppose N=2, heights 2 and 4. Could we make them equal? 2 can be doubled to 4 (once) -> then both 4 -> YES. If we allow only one application per sugarcane? We can apply to the 2 once to become 4, leaving 4 unchanged -> equal. So YES. If we allow multiple, also YES. So consistent.
But consider heights 3 and 6. Can we make them equal? 3 doubled ->6, then both 6 -> YES. odd parts: 3 and 3 (since 6=3*2, odd part 3) -> same odd part, so YES. Good.
What about 6 and 12? 6 odd part 3, 12 odd part 3? 12=34=32^2, odd part 3, so same -> YES. Works.
Now consider 2 and 6: 2 odd part 1, 6 odd part 3 -> different -> NO. Could we make equal by multiple doubles? 2 can become 2,4,8,16,... all powers of two; 6 can become 6,12,24,48,... multiples of 32^k. To equal, need 2^a = 32^b => 2^{a-b}=3, impossible as 3 not power of two. So NO.
Now consider 1 and 2: odd parts 1 and 1? Actually 1 odd part 1, 2 odd part 1 (since 2=1*2). So condition says YES. Indeed, we can double 1 to 2, then both 2; or double 2 to 4 and double 1 twice? but only increase? But if we double 2 to 4, then 1 can be doubled twice to 4, both 4. So YES.
Thus condition stands.
Now, constraints: N up to 50, heights up to 1e9. Simple.
But we must consider: Could there be scenario where we need to apply powder to multiple canes such that we achieve equal heights, but maybe we need to also consider that we might not be required to apply to all canes; we can leave some unchanged. That's covered.
Thus solution: read N, then list of heights. For each height, compute its value after repeatedly dividing by 2 until odd (i.e., remove all factors of 2). Check if all resulting odd parts are equal. If yes, print "YES", else "NO".
Potential pitfalls: Zero? But heights are between 1 and 1e9 inclusive, so no zero.
Time complexity: O(N * log(max height)).
Now, verify sample: N=2, heights 1,23. 1 odd part 1, 23 odd part 23, not equal => NO. Correct.
Edge Cases: N=1 always YES because single cane can be considered same height trivially (or we can do nothing). Condition holds because all one odd part is same.
Now, any twist? The problem statement: "Now he needs to find out whether is it possible to make all the sugarcanes of the same height." It doesn't mention if he can apply powder any number of times. However, the typical problem (like from CodeChef "Sugarcane" maybe?) is exactly this. I've seen similar problem on Codeforces: "Little Elephant and Function" not exactly. There's a known problem: "Make them equal" using only multiplication by 2. So I'm confident.
But we need to read input format: It says: "First line contains N - the number of sugarcanes.Next N lines contains heights of sugarcanes seperated by space". Hmm, sample input:
2
1 23
So first line is N, second line contains N numbers separated by space. So it's not N lines each with one number, but actually next N lines? Wait: It says "Next N lines contains heights of sugarcanes seperated by space". That phrasing is ambiguous. Sample shows only one line after the first, containing both numbers. But N=2, and they have 1 23 on the next line. So actually it's: after first line, there is one line containing N integers. Possibly it can be multiple lines? The description says "Next N lines contains heights of sugarcanes seperated by space". That could be interpreted as "Next N lines each contain heights separated by space"? But then N=2 would have 2 lines each with some numbers? That doesn't match sample. So likely it's a mis-phrasing: Actually it's "Next line contains N heights separated by space." But to be safe, we should read N, then read the next line (or maybe multiple lines) to get N integers. Since N up to 50, we can simply read all integers from stdin after the first integer. So we can read all remaining tokens as heights, ensure we have exactly N.
I'll implement accordingly: read integer N, then read the rest of the input splitting into ints, possibly from multiple lines, until we have N numbers.
Now, output: exactly "YES" or "NO" (uppercase, without quotes).
Now, confirm condition: odd parts equal. Implementation: define function odd_part(x): while x % 2 == 0: x //= 2; return x.
Then compare.
Let's test with more examples:
N=3: 4,6,8. odd parts: 4 -> 1, 6 -> 3, 8 -> 1 => not all same => NO. Could we equalize? 4 (14) can become powers of 2; 6 (32) can become multiples of 32^k; 8 (18) powers of 2. To get equal: need 12^a = 32^b = 1*2^c => impossible because 3 factor can't be eliminated. So NO.
N=3: 3,6,12. odd parts: all 3 => YES. Max exponent: exponents e: 3=32^0 => e=0; 6=32^1 => e=1; 12=3*2^2 => e=2. Max e=2, we can double 3 twice => 12, double 6 once =>12, 12 unchanged => all 12. So YES.
What about 7,14,21? odd parts: 7,7? 14=72 => odd part 7; 21=21? Actually 21=211, odd part 21 (since 21 is odd, so 21). Not equal => NO.
Now, also consider if the odd parts are same, it's always possible. Good.
Now, is there any scenario where we could make them equal by not only increasing but also decreasing? No, we can't decrease.
Thus answer is correct.
Let's consider if the powder can only be used once per sugarcane? That would change condition. But is that plausible? Usually such problems are clear: "He finds a powder which when applied to one of his sugarcanes will double the height of that sugar cane." It doesn't say he can apply it multiple times, but also doesn't say he cannot. In many real-life situations, you could apply multiple times if you have enough powder. But they didn't specify quantity. Often these problems are about "operations" that can be performed any number of times. However, the phrase "one of his sugarcanes" might indicate each application is to one cane. But it's ambiguous. Let's check typical problem statements. I recall a problem from CodeChef: "Sugarcane Juice Business"? Not sure.
But maybe there is a twist: Since Appu created aversion to Maths, and he wants to know if it's possible. The powder doubles the height when applied to one sugarcane. He might have only one powder? No, it's not mentioned he has only one. He goes to market, finds a powder; he could buy as much as needed presumably. So we can assume unlimited uses.
Thus solution stands.
Implementation details: We'll read input via sys.stdin.read().split().
Pseudo:
import sys
def main():
data = sys.stdin.read().split()
if not data: return
n = int(data[0])
arr = list(map(int, data[1:1+n]))
# But if there are more tokens? We'll just take first n after first.
# In case input has extra lines, but we only need n.
# Also ensure len(arr) >= n; if not, maybe we need to read more lines, but typically fine.
base = None
for h in arr:
v = h
while v % 2 == 0:
v //= 2
if base is None:
base = v
elif base != v:
print("NO")
return
print("YES")
if name == "main":
main()
That's it.
But be careful: For large numbers up to 1e9, while loop dividing by 2 is at most ~30 iterations. So fine.
Thus final answer.
We should also consider if the powder can be applied to a sugarcane multiple times, but maybe he can also choose not to apply it. That's fine.
Edge case: N=0? Not in constraints. N>=1.
Thus code ready.
Now, output: Exactly "YES" or "NO". Use capital letters.
Now, let's ensure correct handling of input: Sample: "2\n1 23\n". data = ['2','1','23']; n=2; arr = ['1','23'] -> map to int -> works.
Okay.
Now, I'll produce final answer.
But before final, let's think if there is any other nuance: The problem might be known as "Equalize" from some contest. The condition we derived is correct.
One more nuance: Could we also apply powder to a sugarcane more than once? Yes.
Another nuance: Could we apply to some sugarcane, and then the other, etc. Yes.
Thus answer.
Now, produce final solution explanation.
I'll include explanation: The operation of doubling does not change the odd part (the number after removing all factors of 2). Therefore, for all numbers to become equal, they must share the same odd part. If they do, we can repeatedly double the ones with smaller exponent of 2 to match the largest exponent, achieving equality. So condition: after dividing each height by the highest power of 2 that divides it, all resulting odd numbers are equal.
Implementation: For each height, while it's even, divide by 2. Compare.
Complexities: O(N log max(A_i)).
That's it.
Now final answer code.
But also, could we do it with bit operations: x & -x to get lowest set bit? Not needed.
Alright.
Proceed to output. ```python
import sys
def odd_part(x: int) -> int:
"""Remove all factors of 2 from x."""
while x % 2 == 0:
x //= 2
return x
def main() -> None:
data = sys.stdin.read().split()
if not data:
return
n = int(data[0])
# Take the next n numbers as heights (allow extra spaces or line breaks)
heights = list(map(int, data[1:1 + n]))
base = None
for h in heights:
reduced = odd_part(h)
if base is None:
base = reduced
elif base != reduced:
print("NO")
return
print("YES")
if name == "main":
main()