description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def valid(self, k, n): return k * (k + 1) * (2 * k + 1) // 6 <= n def killinSpree(self, n): lower = 1 upper = n while lower < upper - 1: candidate = (upper + lower) // 2 if self.valid(candidate, n): lower = candidate ...
CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): cnt = -1 start = 0 end = n while start <= end: mid = (start + end) // 2 midSquareSum = int(mid * (mid + 1) * (2 * mid + 1) / 6) if midSquareSum <= n: cnt = mid start = mid +...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETUR...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): start = 0 end = 100000.0 mid = start + (end - start) // 2 ans = 0 while start <= end: condition = mid * (mid + 1) * (2 * mid + 1) // 6 if n >= condition: ans = mid start = mid +...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIG...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): l = 1 h = n while l <= h: m = l + h >> 1 if m * (m + 1) * (2 * m + 1) // 6 == n: return m elif m * (m + 1) * (2 * m + 1) // 6 > n: h = m - 1 else: l = m ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR RETURN VAR IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUM...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def binarysearch(self, l, r, n): if l <= r: mid = (l + r) // 2 s = mid * (mid + 1) * (2 * mid + 1) // 6 if s <= n: return self.binarysearch(mid + 1, r, n) else: return self.binarysearch(l, mid - 1, n) re...
CLASS_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER NUMB...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): start = 1 end = 10**6 res = 0 while start <= end: mid = start + (end - start) // 2 value = mid * (mid + 1) * (2 * mid + 1) // 6 if value == n: res = mid break el...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR N...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
def getSum(n): return n * (n + 1) * (2 * n + 1) / 6 class Solution: def killinSpree(self, n): bot = 1 top = n result = 0 while bot <= top: mid = (bot + top) // 2 s = getSum(mid) if s <= n: result = mid bot = m...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): def squareSum(x): return x * (x + 1) * (2 * x + 1) // 6 low = 1 high = 1000000.0 result = -1 while low <= high: mid = int((low + high) // 2) if squareSum(mid) > n: high = mid - 1 ...
CLASS_DEF FUNC_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR AS...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): low = 1 high = n + 1 while low < high: mid = (low + high + 1) // 2 if n >= mid * (mid + 1) * (2 * mid + 1) // 6: low = mid else: high = mid - 1 return low
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): l, h = 0, n while l <= h: mid = (l + h) // 2 if 2 * mid * mid * mid + 3 * mid * mid + mid <= 6 * n: l = mid + 1 else: h = mid - 1 return l - 1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def Formula(self, n): return n * (n + 1) * (2 * n + 1) // 6 def killinSpree(self, n): l = 1 h = 10000000.0 ans = 0 mid = l + (h - l) // 2 if n == 0: return 0 while l <= h: mid = l + (h - l) // 2 if int(...
CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FU...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): s = 0 ans = 0 i = 1 while n > 0: s = i * (i + 1) * (2 * i + 1) // 6 if n > s: i = 2 * i elif n == s: ans = i break else: low = i ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BI...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): if n == 1: return 1 def findSum(k): return k * (k + 1) * (2 * k + 1) // 6 res = 0 start = 1 end = n while start < end: mid = (start + end) // 2 sm = findSum(mid) i...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN V...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): def vaild(target, n): temp = target * (target + 1) * (2 * target + 1) // 6 return n >= temp start = 1 end = n ans = -1 while start <= end: mid = (start + end) // 2 if vaild(mid, n): ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): hi = int((6 * n) ** (1 / 3)) lo = 1 while lo <= hi: mid = (lo + hi) // 2 res = mid * (mid + 1) * (2 * mid + 1) if res <= 6 * n and (mid + 1) * (mid + 2) * (2 * mid + 3) > 6 * n: return mid ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): l = 0 h = n while l <= h: m = (l + h) // 2 if m * (m + 1) * (2 * m + 1) // 6 > n: h = m - 1 else: l = m + 1 for i in range(m - 2, m + 2): if i * (i + 1) * (2 * i...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): def _solve(x): return x * (x + 1) * (2 * x + 1) // 6 L, R = 0, 20000 while L < R: m = (L + R) // 2 if _solve(m) <= n: L = m + 1 else: R = m return L - 1
CLASS_DEF FUNC_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): i = 1 j = n while i < j: mid = i + j + 1 >> 1 ans = (mid + 1) * (mid * 2 + 1) * mid // 6 if ans > n: j = mid - 1 else: i = mid return i
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): def add(x): return x * (x + 1) * (2 * x + 1) // 6 if n == 0: return 0 low = 1 high = 10000000.0 ans = 0 while low <= high: mid = low + (high - low) // 2 sum = add(mid) ...
CLASS_DEF FUNC_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR A...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
MAX = int(1000000000000.0) dp = [] def compute(): i = 1 while i * i <= MAX: dp.append(i * i) i += 1 def bs(key): l = 0 r = len(dp) - 1 ans = 0 while l <= r: mid = l + (r - l) >> 1 if dp[mid] == key: return mid if dp[mid] < key: ...
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN ...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def ss(self, n): return n * (n + 1) * (2 * n + 1) // 6 def killinSpree(self, n): l, r = 1, n while l != r: mid = (l + r) // 2 if mid == l: return l if self.ss(r) > n else r if self.ss(mid) > n: r = mid ...
CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def sum_n2(self, n): return n * (n + 1) * (2 * n + 1) / 6 def killinSpree(self, P): i = 1 count = 0 l = 1 r = P while l <= r: i = (l + r) // 2 sum = self.sum_n2(i) if P == sum: return i ...
CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP ...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): low = 0 up = n ans = 0 while low <= up: mid = (low + up) // 2 power = mid * (mid + 1) * (2 * mid + 1) if power <= n * 6: low = mid + 1 ans = max(ans, mid) else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER R...
There are Infinite People Standing in a row, indexed from 1. A person having index 'i' has strength of (i*i). You have Strength 'P'. You need to tell what is the maximum number of People You can Kill With your Strength P. You can only Kill a person with strength 'X' if P >= 'X' and after killing him, Your Strength dec...
class Solution: def killinSpree(self, n): low, high = 1, 2**32 - 1 while low <= high: mid = (high + low) // 2 temp = mid * (mid + 1) * (2 * mid + 1) // 6 if temp > n: high = mid - 1 elif temp == n: return mid ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().split())) sa = set(a) def dfs(node, li): if len(li) == n: print(*li) exit(0) if node * 2 in sa: dfs(node * 2, li + [node * 2]) if node % 3 == 0 and node // 3 in sa: dfs(node // 3, li + [node // 3]) for i in range(n): dfs(a[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST BIN_OP VAR NUMBER IF BIN...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def ans(): N = int(input()) A = list(map(int, input().split())) Ans = [] for i in range(N): a = 0 b = 0 c = A[i] while A[i] > 0 and c % 3 == 0: c = c // 3 a += 1 while A[i] > 0 and c % 2 == 0: c = c // 2 b += 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER B...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = input().split() ls = [[] for i in range(50)] for i in range(n): a[i] = int(a[i]) x = a[i] count = 0 while x % 3 == 0: x = x // 3 count += 1 ls[count].append(a[i]) for i in range(50): ls[50 - i - 1].sort() for j in range(len(ls[50 - i - 1])): print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) li = list(map(int, input().split())) g = {} def dfs(e, v, order): if e not in v: v[e] = 1 if e % 3 == 0: if e // 3 in g: order.append(e // 3) dfs(e // 3, v, order) if e * 2 in g: order.append(e * 2) dfs(e ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def to(a): s = 0 while a % 2 == 0 and a != 0: s += 1 a = a // 2 return s def tr(a): s = 0 while a % 3 == 0 and a != 0: s += 1 a = a // 3 return s n = int(input()) a = list(map(int, input().split())) for i in range(n): for j in range(i + 1, n): if t...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) def k(x): twos = 0 while x % 2 == 0: x //= 2 twos += 1 threes = 0 while x % 3 == 0: x //= 3 threes += 1 return twos, -threes A = sorted(map(int, input().split()), key=k) print(" ".join(map(str, A)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CAL...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
from sys import stdin, stdout def rearrage_polycarp(n: int, sequence): polys_seq = set(sequence) ordered_seq = [ num for num in sequence if not (num % 2 == 0 and num // 2 in polys_seq or 3 * num in polys_seq) ] n -= 1 i = 0 while n: if 2 * ordered_seq[i] in poly...
FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASS...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def found_sequence(possible_sequence, lookup): if len(possible_sequence) == n: print(" ".join(list(map(str, possible_sequence)))) return True else: last_element = possible_sequence[-1] if ( last_element % 3 == 0 and last_element // 3 in lookup ...
FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN N...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().split())) b = [[a[i], 0, 0] for i in range(n)] for i in range(n): x = a[i] while x % 2 == 0: x = x // 2 b[i][1] += 1 while x % 3 == 0: x = x // 3 b[i][2] += 1 b.sort(key=lambda x: (x[1], -x[2])) c = [b[i][0] for i in range(n)] print(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUM...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) arr = [] for ai in list(map(int, input().split())): num, cnt = ai, 0 while ai % 3 == 0: ai //= 3 cnt += 1 arr.append([-cnt, num]) arr.sort() print(" ".join(list(map(lambda x: str(x[1]), arr))))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def main(): n, sequence = input(), set(map(int, input().split())) firstElement = nThrees = 0 for element in sequence: value = element for i in range(39): if value % 3: if nThrees < i: firstElement, nThrees = element, i break ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CAL...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def GetCount3(k): count = 0 while k % 3 == 0: k //= 3 count += 1 return count n = input() l = sorted(map(int, input().split()), key=lambda a: (-GetCount3(a), a)) print(*l)
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def buildIt(prevval, a, used, howmanyused): if howmanyused == len(a): return [prevval] for i in range(len(a)): if used[i] == False: if a[i] == prevval * 2: used[i] = True howmanyused += 1 answer = buildIt(a[i], a, used, howmanyused) ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NONE RETURN BIN_OP LIST VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR V...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input("")) arr = list(map(int, input().split())) arr.sort() sol = [] for i in range(n): sol.append([0, arr[i]]) for i in range(n): cnt = 0 while arr[i] % 3 == 0: cnt += 1 arr[i] = arr[i] // 3 sol[i][0] = cnt sol = sorted(sol, key=lambda x: x[0], reverse=True) ans = [] for i in ra...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BI...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().split())) def d3(c): ans = 0 while c % 3 == 0: c //= 3 ans += 1 return ans a = [(d3(i), i) for i in a] a = sorted(a, key=lambda x: (-x[0], x[1])) print(" ".join([str(i[1]) for i in a]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL ST...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
N = int(input()) l = [] w = [] used = 0 res = [] orig = [] l_t = list(map(int, input().split())) for a, b in enumerate(l_t): l.append((b, a)) orig.append((b, a)) while used < N: tmp = [i for i in l if i[0] % 2 != 0] w.append(tmp) used += len(tmp) for i in tmp: l.remove(i) for i in ra...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) arr = list(map(int, input().split())) for i, x in enumerate(arr): hp = 0 while not x % 3**hp: hp += 1 arr[i] = hp, x arr.sort(key=lambda t: (t[0], -t[1]), reverse=True) print(*map(lambda o: o[1], arr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = input().split() ans = [] for i in range(n): a[i] = int(a[i]) a.sort() j = 0 while len(a) > 0: temp = [] i = 0 while i < len(a): if a[i] % 3 != 0: temp.append(a[i] * pow(3, j)) a.remove(a[i]) else: a[i] //= 3 i += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def v3(x): ans = 0 while x % 3 == 0: x //= 3 ans += 1 return ans def v2(x): ans = 0 while x % 2 == 0: x //= 2 return ans n = int(input()) arr = sorted(map(int, input().split())) d = set() mxpow3 = 0 pow3 = 0 mnpow2 = 1000 pow2 = 0 for num in arr: d.add(num) if...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) l = list(map(int, input().split())) def search(partial, current_value, remaining): if not partial: partial = [current_value] if len(remaining) == 0: return partial res = [] new_values = [current_value * 2] if current_value % 3 == 0: new_values.append(curren...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR ASSIGN VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR LIST BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR A...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def three(x): c = 0 while x % 3 == 0: x //= 3 c += 1 return c def two(x): c = 0 while x % 2 == 0: x //= 2 c += 1 return c n = int(input()) a = list(map(int, input().split())) D = [[0, 0, 0] for i in range(n)] for i in range(n): D[i][0] = a[i] D[i][1] =...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NU...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) data = map(int, input().split()) mass = [] for el in data: save = el th_deg = 0 tw_deg = 0 while el % 3 == 0: el //= 3 th_deg += 1 while el % 2 == 0: el //= 2 tw_deg += 1 mass.append((save, tw_deg, th_deg)) def comp(a, b): if a[2] > b[2]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def isThird(x, y): return x == y * 3 def isDouble(x, y): return x == y / 2 def sort(lista): if len(lista) == 0: return [] lista = sorted(lista) result = [] n = len(lista) result.append(lista.pop(0)) p = -1 while len(result) < n: p = (p + 1) % len(lista) if...
FUNC_DEF RETURN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR BIN_OP VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) u = list(map(int, input().split())) ok = False def finl(u, d): for i in range(len(u)): if u[i] == d: return i return -1 def gen(i): global ans if len(ans) == n: for i in ans: print(i, end=" ") exit() p = finl(u, u[i] * 2) if p ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR F...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) s = list(map(int, input().split())) sett = set(s) last = s[0] while True: if last % 3 == 0 and last // 3 in sett: last = last // 3 elif last * 2 in sett: last = last * 2 else: break arr = [last] while True: if last % 2 == 0 and last // 2 in sett: last = l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST V...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = [int(x) for x in input().split()] def fact(x): c2 = 0 c3 = 0 while x % 2 == 0: x = x // 2 c2 = c2 + 1 while x % 3 == 0: x = x // 3 c3 = c3 + 1 return c2, c3, x b = [fact(x) for x in a] b.sort(key=lambda x: (x[0], -x[1])) print(" ".join([str(2*...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER R...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def dfs(p, n): ans.append(a[p]) v[p] = True if len(ans) == n: for i in ans: print(i, end=" ") exit() for j in range(0, n): if v[j] == False and (a[j] * 3 == ans[-1] or 2 * ans[-1] == a[j]): dfs(j, n) else: continue return n = int(...
FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
R = lambda: list(map(int, input().split(" "))) n = int(input()) a = R() answer = [a[0]] while len(answer) < n: for i in range(n): if a[i] * 2 == answer[0] or answer[0] * 3 == a[i]: answer = [a[i]] + answer elif answer[-1] * 2 == a[i] or a[i] * 3 == answer[-1]: answer += [a[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER WHILE FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR V...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
input() d = set(list(map(int, input().strip().split()))) x = min(d) d.remove(x) sol = [x] while d: if x * 2 in d: x = x * 2 sol.append(x) d.remove(x) elif x % 3 == 0 and x // 3 in d: x = x // 3 sol.append(x) d.remove(x) else: break sol2 = [] x = sol[0]...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR WHILE VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) l = list(map(int, input().split())) def fact(n): m = n c, c1 = 0, 0 while n % 2 == 0: n = n // 2 c += 1 while n % 3 == 0: n = n // 3 c1 += 1 return c1, -c, m l1 = [] for i in l: l1.append(fact(i)) l1.sort(reverse=True) for i in range(n): p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) l = [int(x) for x in input().split()] def key(x, r=0): while x % 3 == 0: x //= 3 r -= 1 while x % 2 == 0: x //= 2 r += 1 return r print(*sorted(l, key=key))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def m3(n): cnt = 0 while n % 3 == 0: cnt += 1 n //= 3 return cnt n = int(input()) l = list(map(int, input().split())) a = [] for i in range(n): x = m3(l[i]) a.append((-x, l[i])) a.sort() for i in range(n): print(a[i][1], end=" ")
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def div(a, l): if a % 3 == 0: x = a // 3 else: return False if x in l: return True else: return False def mul(a, l): x = a * 2 if x in l: return True else: return False n = int(input()) l = list(map(int, input().split())) for i in l: p ...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) mas = input().split() s = set() for i, x in enumerate(mas): mas[i] = int(x) s.add(mas[i]) start = -1 for x in mas: if not (x % 2 == 0 and x // 2 in s or x * 3 in s): start = x break i = 1 ans = [start] while i < n: if start * 2 in s: ans.append(start * 2) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUM...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) ls = list(map(int, input().split())) cnt2 = [0] * n cnt3 = [0] * n for i in range(n): temp = ls[i] while temp % 2 == 0: temp = temp // 2 cnt2[i] += 1 temp = ls[i] while temp % 3 == 0: temp = temp // 3 cnt3[i] += 1 for i in range(n): for j in range(n -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE B...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) def foo(p, a): if not a: return [p] for i in a: if not p or p % 3 == 0 and p // 3 == i or p * 2 == i: result = foo(i, a.difference({i})) if result is not None: return ([p] if p else []) + result print(*foo(0, set(map(int, input().split...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR RETURN LIST VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NONE RETURN BIN_OP VAR LIST VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def deg(x): ret = 0 while x % 3 == 0: ret += 1 x //= 3 return ret n = int(input()) a = [int(i) for i in input().split()] res = [] for i in a: res.append([-deg(i), i]) res.sort() for i in res: print(i[1], end=" ") print()
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBE...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) def comp(x): i = 0 tmp = x while tmp % 3 == 0: tmp //= 3 i += 1 n3 = i i = 0 tmp = x while tmp % 2 == 0: tmp //= 2 i += 1 n2 = i return -n3 * 100 + n2 n = int...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
import sys n = int(sys.stdin.readline().strip()) l2 = sys.stdin.readline().strip().split(" ") l = [int(i) for i in l2] dic = {i for i in l} pairing = {} sequence = [] for i in range(n): temp = [[], []] num = l[i] f1 = num * 3 if num % 2 == 0: f2 = num // 2 if f2 in dic: temp...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST LIST ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def tri(a): k = 0 while a % 3 == 0: k += 1 a //= 3 return k n = input() katya = list(map(int, input().split())) l = [(-tri(x), x) for x in katya] p = [x[1] for x in sorted(l)] print(*p)
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def f(x): i = 0 z = x while z % 3 == 0: z //= 3 i += 1 return i n = int(input()) a = list(map(int, input().split())) x = [(-f(a[i]), a[i]) for i in range(n)] x.sort() print(" ".join([str(x[i][1]) for i in range(n)]))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n, l = int(input()), list(map(int, input().split())) for i in l: a, x = [i], l.copy() x.remove(i) while len(a) != n: p, q = a[-1] // 3, a[-1] * 2 if a[-1] % 3 == 0 and p in x: a.append(p) x.remove(p) elif q in x: a.append(q) x.remove(q)...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR EXPR FUNC_CA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) A = [int(x) for x in input().split()] i = 0 B = A.copy() C = [1000000000.0] D = B.copy() while i < 39: while max(D) != 0: C = [(x // 3) for x in D] D = C.copy() i = i + 1 break k = i - 1 R = set(B.copy()) X = [x for x in list(R) if x % 3**k == 0] L = list({}) A = [] whil...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR N...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().split())) b = [0] * n for i in range(n): x = a[i] y = 0 while x % 3 == 0: y += 1 x = x // 3 b[i] = y d = [] maxi = max(b) while maxi > -1: c = [] for i in range(n): if b[i] == maxi: c.append(a[i]) c = sorted(c) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def deg_3(x): deg = 0 while x % 3 == 0: x //= 3 deg += 1 return deg n = int(input()) a = map(int, input().split()) a_deg = sorted([(a_i, deg_3(a_i)) for a_i in a], key=lambda x: (-x[1], x[0])) print(" ".join([str(val) for val, deg in a_deg]))
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def f(x, k): cnt = 0 while x % k == 0: x = x // k cnt += 1 return cnt n = int(input()) a = map(int, input().split()) print(*sorted(a, key=lambda x: [f(x, 2), -f(x, 3)]))
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
import sys data = sys.stdin.readlines() lis = [] for line in data: lis.append(line) n = lis[0].split()[0] n = int(n) seq = list(map(int, lis[1].split())) def e2e3(n): n1 = n bn = bin(n)[2:] e2 = len(bn) - (bn.rfind("1") + 1) e3 = 0 n = n >> e2 while n % 3 == 0: n = n // 3 ...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FU...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
import sys n = int(input()) seq = list(map(int, input().split())) used = [False] * n def A_n_k_pythonic(a, curr, depth=0): if depth == len(a): print(" ".join(map(str, curr))) sys.exit() for i in range(len(a)): if not used[i]: if not curr or curr[-1] == a[i] * 3 or curr[-1]...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF V...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def get(x): a = x cnt = [0] * 2 for d in (2, 3): while x % d == 0: cnt[d - 2] += 1 x //= d return cnt[0], -cnt[1], a (n,) = map(int, input().split()) a = list(map(int, input().split())) values = sorted([get(x) for x in a]) print(*[x[2] for x in values])
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR RETURN VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CAL...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) lista = list(map(int, input().split())) def defe(x): i = 0 while x % 2 == 0: i += 1 x /= 2 return -x, i lista.sort(key=defe) print(" ".join(list(map(str, lista))))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def dfs(value, count, stop): global mySet global collect global check if count == stop: return True if value % 3 == 0: if value // 3 in mySet: count += 1 collect.append(value // 3) check = dfs(value // 3, count, stop) if not check: ...
FUNC_DEF IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR NUMBER IF VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().split())) b = [] for i in range(n): for k in a: if not (k * 2 in a or k // 3 in a and k % 3 == 0): a.remove(k) b.append(k) print(*reversed(b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().strip().split())) l = [] for i in a: k = 0 k = i c = 0 while k % 3 == 0: k = k // 3 c += 1 p = -c l.append([p, i]) l.sort() res = [] for i in l: res.append(i[1]) print(" ".join(map(str, res)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FU...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) arr = list(map(int, input().split())) ans = [arr[0]] front = False for _ in range(n - 1): if not front: if ans[-1] * 2 in arr: ans.append(ans[-1] * 2) elif ans[-1] % 3 == 0 and ans[-1] // 3 in arr: ans.append(ans[-1] // 3) else: front = Tr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR IF BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
x = int(input()) temp_seq = input().split(" ") seq = [int(temp_seq[i]) for i in range(x)] final = [] while len(seq) != 0: if len(final) == 0: final = final + [seq[0]] seq.pop(0) elif final[0] // 2 in seq: final = [final[0] // 2] + final seq.remove(final[0]) elif final[-1] * 2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BI...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def pow3(x): c = 0 while x: c += 1 if x % 3 == 0: x = x // 3 else: x = 0 return -1 * c N = int(input()) s = [(int(x), pow3(int(x))) for x in input().split()] s.sort(key=lambda x: (x[1], x[0])) for i in s: print(i[0], end=" ") print()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def func(num): cnt = 0 while num % 3 == 0: num //= 3 cnt += 1 return cnt n = int(input()) arr = list(map(int, input().split())) d = {} val = [] for i in arr: x = func(i) if x in d: d[x].append(i) else: d[x] = [i] val.append(x) val.sort() val = val[-1::-1...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR V...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
input() numbers = set(map(int, input().split())) result = [] for n in numbers: if n * 2 not in numbers and (n % 3 != 0 or n // 3 not in numbers): result.append(n) numbers.remove(n) break while numbers: if result[0] % 2 == 0: candidate = result[0] // 2 if candidate in numb...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def poly_check(nums): for i in range(len(nums) - 1): if nums[i + 1] // 2 != nums[i] and nums[i + 1] * 3 != nums[i]: return False return True def rec_poly(fr, to): if len(fr) == 0: if poly_check(to): for n in to: print(n, end=" ") first = to[0] ...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR NU...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) arr = list(map(int, input().split())) ans = [arr[0]] stack = [arr[0]] visited = set() while stack: p = stack.pop() visited.add(p) if p * 2 in arr and p * 2 not in visited: ans.append(p * 2) stack.append(p * 2) if p % 3 == 0 and p // 3 in arr and p // 3 not in visited: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) A = list(map(int, input().split())) mul2 = [0] * n div3 = [0] * n for i in range(n): if A[i] * 2 in A: mul2[i] = 1 if A[i] % 3 == 0 and A[i] // 3 in A: div3[i] = 1 index = -1 for i in range(n): if mul2[i] == 0 and div3[i] == 0: index = i break ans = [0] * n v...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
import sys n = int(input()) a = list(map(int, input().split())) def dfs(u): r.append(u) s.remove(u) if len(r) == n: print(*r) exit(0) if u % 3 == 0 and u // 3 in s: dfs(u // 3) if u * 2 in s: dfs(u * 2) for i in range(n): s = set(a) r = [] dfs(a[i])
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VA...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().split())) ok = False a.sort() def search(t): l = 0 r = n - 1 while r - l >= 0: mid = (r + l) // 2 if a[mid] == t: return mid if t < a[mid]: r = mid - 1 if t > a[mid]: l = mid + 1 return -1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR B...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
int(input()) a = list(map(int, input().split())) ra = [a[0]] a.pop(0) while len(a): f = -1 ff = -1 for i in range(len(a)): if a[i] * 2 == ra[0]: f = i ff = 0 break elif ra[-1] * 2 == a[i]: f = i ff = 1 break elif...
EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBE...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = list(map(int, input().split())) ans = [] while len(a) > 0: for k in range(38, -1, -1): subans = [] for x in a[:]: if x % 3**k == 0: subans = subans + [x] a.remove(x) ans = ans + sorted(subans) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR VAR ASS...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) l = [int(e) for e in input().split()] dic = {} for i in l: if i in dic: dic[i] += 1 else: dic[i] = 1 res = [] def dfs(res): temp = res[-1] tempLen = len(res) if temp % 3 == 0: tempDiv = temp // 3 if tempDiv in dic and dic[tempDiv] > 0: r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) s = list(map(int, input().split())) ans = [] for i in s: n = i c2 = c3 = 0 while i % 2 == 0: i //= 2 c2 += 1 while i % 3 == 0: i //= 3 c3 += 1 ans.append([-c3, c2, n]) ans.sort() for i in ans: print(i[2], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FU...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = input() c = {} for x in [int(x) for x in input().split()]: u, t = x, 0 while 0 == u % 3: u //= 3 t += 1 c[t] = c.get(t, []) + [x] for x in sorted(c)[::-1]: for y in sorted(c[x]): print(y, end=" ")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER WHILE NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR LIST LIST VAR FOR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def maxpower(n): if n % 3 != 0: return 0 else: count = 0 while n % 3 == 0: n = n // 3 count += 1 return count def mykey(n): return -1 * maxpower(n), n n = int(input()) L = list(map(int, input().split())) print(*sorted(L, key=mykey))
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_C...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) a = [int(i) for i in input().split(" ")] path = [] for p in range(len(a)): path.append(-1) b = [] for i in range(len(a)): b.append([-1, -1]) for x in range(len(a)): mul_two = a[x] * 2 done = 0 if a[x] % 3 == 0: done = 1 div_thr = a[x] // 3 for y in range(len(a)):...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR A...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) l = [int(x) for x in input().split()] for ele in l: if ele % 2 == 0: if ele // 2 not in l and ele * 3 not in l: start = ele elif ele * 3 not in l: start = ele while True: print(start, end=" ") if start * 2 in l: start *= 2 continue if star...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR WHILE NUMBER EXPR FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR NUMBER IF ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
x = [] vis = None def solve(u): vis[u] = 1 x.append(A[u]) if len(x) == n: return True for v in range(n): if v != u and not vis[v]: if A[v] == 2 * A[u]: if solve(v): return True if A[u] % 3 == 0 and A[v] == A[u] // 3: ...
ASSIGN VAR LIST ASSIGN VAR NONE FUNC_DEF ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
from sys import stdin, stdout cin = stdin.readline cout = stdout.write def test(k): try: val = d[k] return 1 except KeyError as e: return 0 n = int(cin()) d = {i: (1) for i in list(map(int, cin().split()))} l = [0] * n for i in d: l[0] = i for j in range(n - 1): if l...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR RETURN NUMBER VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER I...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) arr = list(map(int, input().split())) arr1 = [] for i in range(n): if arr[i] % 3 == 0: if arr[i] // 3 in arr: arr1.append([arr[i], arr[i] // 3]) if arr[i] * 2 in arr: arr1.append([arr[i], arr[i] * 2]) arr1 = sorted(arr1) ans = [arr1[0][0], arr1[0][1]] x = arr1[0][0] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR ...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
def rec(x, fArr, secArr): fArr.remove(x) secArr.append(x) if 2 * x in fArr: return rec(2 * x, fArr, secArr) elif x % 3 == 0 and x // 3 in fArr: return rec(x // 3, fArr, secArr) elif len(fArr) == 0: return secArr else: return [] n = int(input()) a = list(map(int,...
FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR RETURN FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN...
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: divide the number $x$ by $3$ ($x$ must be divisible by $3$); multiply the number $x$ by $2$. After each operation, Polycarp writes down the result on th...
n = int(input()) arr = list(map(int, input().split())) ans = [] for i in range(n): p3 = 0 t = arr[i] while t % 3 == 0: t = t // 3 p3 += 1 p2 = 0 t = arr[i] while t % 2 == 0: t = t // 2 p2 += 1 ans.append([p3, -p2, arr[i]]) ans.sort(reverse=True) for i in ans: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUM...