description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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())) def chk(l, r): if len(r) == 0: print(" ".join(map(str, l))) exit() ll = l.copy() rr = r.copy() if l[-1] % 3 == 0 and l[-1] // 3 in rr: rr.remove(l[-1] // 3) chk(ll + [l[-1] // 3], rr) rr = r.copy() if l[-1] * ...
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 FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMB...
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 = [*map(int, input().split())] def solve(c, r, s, x): sys.setrecursionlimit(sys.getrecursionlimit() + 1) r.remove(x) s.remove(x) c.append(x) if len(r) == 0: print(*c) exit() if x % 3 == 0 and x // 3 in s: solve([*c], [*r], set([*s]), x // ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL 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 Alfa(a): m.append(a) if a % 3 == 0 and a // 3 in z: z.remove(a) Alfa(a // 3) elif a * 2 in z: z.remove(a) Alfa(a * 2) elif len(m) == n: for i in m: print(i, end=" ") p = [] n = int(input()) k = sorted(map(int, input().split())) k = k[::-1] d = []...
FUNC_DEF EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING 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...
import sys input = sys.stdin.readline N = int(input()) S = list(map(int, input().split())) def neighbours(node, s=S): out = [node << 1] if node % 3 == 0: out.append(node // 3) return set(x for x in out if x in s) G = {} for x in S: G[x] = neighbours(x) def hamilton(G, size, pt, path=None)...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR LIST BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR 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...
n = int(input()) a = [int(x) for x in input().split()] b = [] for i in range(n): if a[i] > 100000000: if a[i] * 3 not in a and a[i] // 2 not in a: b.append(a[i]) a.pop(i) break elif a[i] * 3 not in a and a[i] / 2 not in a: b.append(a[i]) a.pop(i) ...
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 FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR 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 main(): n = int(input()) a = list(map(int, input().split(" "))) for item in a: current = item copy = list(a) sequence = [current] copy.remove(current) while copy: divided = current // 3 multiplied = current * 2 if divided in cop...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR 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 = eval(input()) a = input().split() length = n start = 0 for i in a: if int(i) % 2 == 0: if not str(eval(i) * 3) in a and not str(eval(i) // 2) in a: start = eval(i) break elif not str(eval(i) * 3) in a: start = eval(i) break print(start, end=" ") while length: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUN...
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())) g = [([0] * n) for _ in range(n)] for i in range(n): for j in range(n): if a[i] * 2 == a[j]: g[i][j] = 1 if a[j] * 3 == a[i]: g[i][j] = 1 def dfs(u, b): for v in range(n): if g[u][v]: if dfs(v, 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 BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN 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())) result = [] i = 0 def checkeven(a): if a % 2 == 0: return True else: return False def check(a): b = 0 if checkeven(a) is True: if a // 2 in s: b += 1 if a * 2 in s: b += 10 if a * 3 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 LIST ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP 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...
def helper(curr, ans, l, visited, n): if l == n: for i in ans: print(i, end=" ") return True for i in arr: if i not in visited and (i * 3 == curr or i == curr * 2): visited.add(i) if helper(i, ans + [i], l + 1, visited, n): return True ...
FUNC_DEF IF VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING RETURN NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR LIST VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 main(): n = int(input()) a = [int(x) for x in input().split()] b = set(a) for e in a: ans = [e] b = set(a) b.remove(e) cur = e flag = True while flag and len(b): if cur % 3 == 0 and cur // 3 in b: cur = cur // 3 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER 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...
def DFS(n, v): global num, pos, ans pos[v] = True for i in range(n): if num[v][i] != 0 and not pos[i]: if len(ans) == 0: ans += str(spis[v]) + " " + str(spis[i]) + " " else: ans += str(spis[i]) + " " DFS(n, i) n = int(input()) spi...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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...
n = int(input().strip()) nums = list(map(int, input().strip().split())) visited = [0] * n def dfs(i): res = [] flag = True for j in range(n): if not visited[j]: if nums[i] % 3 == 0 and nums[j] == nums[i] // 3 or nums[j] == nums[i] * 2: flag = False visit...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER 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...
I = lambda: list(map(int, input().split())) def ch(n): i = 0 while not n % 2: i += 1 n //= 2 return -n, i (n,) = I() l = I() l.sort(key=ch) print(*l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR 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...
n = int(input()) a = list(map(int, input().split())) g = [[] for i in range(n)] for i in range(n): for j in range(n): if a[i] * 3 == a[j]: g[j].append(i) if a[i] == a[j] * 2: g[j].append(i) s = -1 for i in range(n): if len(g[i]) == 0: s = i break x = a[s] ...
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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSI...
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_power(n, k): p = 0 while n % k == 0: n //= k p += 1 return p n = int(input()) a = [[int(n), get_power(int(n), 3), get_power(int(n), 2)] for n in input().split()] a.sort(key=lambda e: e[2]) a.sort(key=lambda e: e[1], reverse=True) print(" ".join([str(e[0]) for e in a]))
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR 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...
def f(x, base): out = 0 while x % base == 0: x //= base out += 1 return out n = int(input()) L = list(map(lambda i: [-f(int(i), 3), int(i)], input().split())) L.sort() for i, j in L: print(j, end=" ") print()
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR 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...
def main(): n, l = int(input()), [] for a in map(int, input().split()): b = a two = three = 0 while not a % 2: a //= 2 two += 1 while not a % 3: a //= 3 three -= 1 l.append((three, two, b)) print(*[t[2] for t in sorted(l...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR E...
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(n, A): A = list(map(int, A.split())) dct = [[0, 0, 0] for i in range(n)] for i in range(n): tmp = A[i] while True: if tmp % 3 == 0: dct[i][0] += 1 tmp //= 3 elif tmp % 2 == 0: dct[i][1] -= 1 tmp //=...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN 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().split())) count = [] for i in range(n): x = 1 c = 0 while a[i] % x == 0: x *= 3 c += 1 c -= 1 count.append([-c, a[i]]) count.sort() for i in range(n): print(count[i][1], 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FOR 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()) a = list(map(int, input().split(" "))) ar = [] def dfs(n): if n % 3 == 0 and n // 3 in a: ar.append(n // 3) dfs(n // 3) elif n * 2 in a: ar.append(n * 2) dfs(n * 2) for i in range(0, len(a)): dfs(a[i]) if len(ar) == len(a) - 1: ar.insert(0, a[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_DEF IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP 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...
import sys sys.setrecursionlimit(1500) n = int(input()) v = list(map(int, input().strip().split())) visited = set() counter = 0 def solve(curr, seq): seq.append(curr) visited.add(curr) if len(seq) == n: print(" ".join(map(str, seq))) elif len(seq) <= n: if curr * 2 in v and curr * 2 n...
IMPORT EXPR FUNC_CALL VAR NUMBER 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 FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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...
import time n = int(input()) a = [int(i) for i in input().split()] start = time.time() pdt = [] div = [] for i in range(n): pdt.append(a[i] * 2) if a[i] % 3 == 0: div.append(a[i] // 3) else: div.append(0) res = [] for i in range(n): c = 0 for j in range(n): if a[i] != pdt[j]...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL 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()) l = list(map(int, input().split())) m = [] for i in range(n): flag = 1 x = l[i] for j in range(n): if x == 2 * l[j] or x * 3 == l[j]: flag = 0 break else: continue if flag == 1: m.append(x) for i in range(n): for j in range...
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 FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER 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...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = [] o = [[] for i in range(80)] for i in a: temp = int(str(i)) c = 0 while True: if temp % 2 == 0: temp /= 2 c += 1 else: break o[c].append(i) f = [] for i i...
IMPORT ASSIGN VAR 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 ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER 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()) a = list(map(int, input().split())) for i in range(n): b = a.copy() r = [] r.append(b[i]) current = b.pop(i) while b: f = False for j, el in enumerate(b): if current % 3 == 0 and current // 3 == el or current * 2 == el: r.append(el) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_O...
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...
class Graph: def __init__(self, n): self.n = n self.adj = [[] for i in range(n)] def add(self, v, u): self.adj[v].append(u) n = int(input()) g = Graph(n) a = list(map(int, input().split())) for i in range(n): for j in range(n): if a[i] == 2 * a[j] or 3 * a[i] == a[j]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP 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...
print( *sorted( list(map(int, __import__("sys").stdin.read().split("\n")[1].split())), key=lambda x: ( (lambda f, x, y: f(f, x, y))( lambda f, x, y: 0 if x == 0 or x % y != 0 else f(f, x // y, y) + 1, x, 2 ), -(lambda f, x, y: f(f, x, y))( ...
EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING NUMBER FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_O...
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 count(num, k): if num % k != 0: return 0 return 1 + count(num // k, k) n = int(input()) a = [*map(int, input().split())] c = [None] * n for i in range(0, n): c[i] = i a.sort(key=lambda num: (-count(num, 3), num)) print(" ".join(map(str, a)))
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR 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...
tempdict = dict() input() for i in input().split(): i = int(i) tempdict[i] = True key = i ans = str(key) while True: if key % 2 is 0 and tempdict.get(key // 2): key = key // 2 ans = str(key) + " " + ans continue if tempdict.get(key * 3): key = key * 3 ans = str(ke...
ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRI...
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 count3(n): ret = 0 while n % 3 == 0: ret += 1 n = n // 3 return ret v = [[0, 0] for i in range(n)] for i in range(len(a)): v[i][1] = a[i] v[i][0] = -count3(v[i][1]) v.sort() for i in v: print(i[1], end=" ")
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 ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN 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...
mod = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) def dfs(d, sv): d[sv] = True dfsarr.append(sv) for i in d: if d[i] == False and (sv * ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN 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()) a = list(map(int, input().split())) aa = [] for i in range(n): tmp = a[i] p2 = 0 while tmp % 2 == 0: tmp //= 2 p2 += 1 p3 = 0 while tmp % 3 == 0: tmp //= 3 p3 += 1 aa.append((p2 - p3, i)) aa.sort() ans = [] for _, i in aa: ans.append(a[i]) pri...
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 VAR VAR 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 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...
from sys import stdin def solve(el, input): if el not in input: return [] res1 = solve(el * 2, input) res2 = solve(el // 3, input) if el % 3 == 0 else [] res = max([res1, res2], key=len) return [el] + res def threetwo(n, input): for el in input: result = solve(el, input) ...
FUNC_DEF IF VAR VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR RETURN BIN_OP LIST VAR VAR FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIG...
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 = [(int(x), int(x)) for x in input().strip().split()] ans = [] while len(ans) < n: odds = [] evens = [] for x, y in arr: if y % 2 == 1: odds.append((x, y)) else: evens.append((x, y // 2)) ans += [x for x, y in sorted(odds, key=lambda x: x[0], ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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()) sequence = input().split() sequence = [int(x) for x in sequence] div3_array = [0] * n def count3(number, idx, div3_array): count = 0 while number % 3 == 0: number //= 3 count += 1 div3_array[idx] = count for idx, number in enumerate(sequence): count3(number, idx, div...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR 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...
n = int(input()) def f(n): r = 0 while n % 2 == 0: n //= 2 r += 1 while n % 3 == 0: n //= 3 r -= 1 return r print(*sorted(map(int, input().split()), key=f))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR 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 FUNC_CALL VAR VAR FUNC_CALL 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 canTake(nbr, lst, dict): return dict[nbr] != lst.count(nbr) def exists(nbr, dict): return nbr in dict def dfs(nbr, lst, dict, n): if len(lst) == n: return lst possibilities = [] if exists(nbr * 2, dict) and canTake(nbr * 2, lst, dict): possibilities.append(nbr * 2) if nbr...
FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR LIST IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER 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...
n = int(input()) array = [int(i) for i in input().split()] s = set() for i in array: s.add(i) z = [0] * 300 i = 150 j = 151 x = array[0] y = array[0] z[i] = x i -= 1 s.remove(x) while len(s) != 0: if x * 3 in s: z[i] = int(x * 3) s.remove(x * 3) x = x * 3 i -= 1 if x // 2 in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER 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 in_power(a): ans = 0 while a % 3 == 0: a = a // 3 ans += 1 return ans def main(): n = int(input()) numbers = [int(i) for i in input().split()] ans = [""] * n for i in range(n): ans[i] = -in_power(numbers[i]), numbers[i] ans.sort() for i in range(n): ...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR E...
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())) edge = [] for i in arr: flag = 0 if i * 3 in arr: edge.append([i * 3, i]) flag += 1 if i % 2 == 0 and i // 2 in arr: edge.append([i // 2, i]) flag += 1 if flag == 0: edge.append([-1, i]) x = arr.index(...
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 NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST 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()) values = input() values = values.split() factor = [[]] * 101 for i in range(n): number = int(values[i]) factor[i] = [number, 0] temp_number = number while temp_number % 3 == 0: factor[i][1] += 1 temp_number //= 3 maximo = 0 curr_max = -1 str_ans = "" j = 0 while j < n: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN 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())) def prime3_occurences(n): cont = 0 while n % 3 == 0: n = n // 3 cont += 1 return cont tups = [] for el in a: tups.append((prime3_occurences(el), el)) tups = sorted(tups, key=lambda x: (-x[0], x[1])) a = [str(x[1]) for x in tups] ou...
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 ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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...
from sys import stdin, stdout def rearrage_polycarp_backtracking(n: int, sequence): poly = set(sequence) def recurse(start: int, path=[], seen=set()) -> bool: if start not in poly or start in seen: return [] path.append(start) seen.add(start) if len(recurse(2 * sta...
FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF VAR LIST FUNC_CALL VAR IF VAR VAR VAR VAR RETURN LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN 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())) num = {} for i in range(50): num[i] = [] for i in range(n): temp = a[i] cnt = 0 while True: if temp % 3 == 0: cnt += 1 temp //= 3 else: break num[cnt].append(a[i]) ans = [] for i in range(50)[::-...
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 FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER 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...
n = int(input()) a = list(map(int, input().split())) d = dict() minP = 9999 maxP = 0 for x in a: curr = x p = 0 while curr % 3 == 0: curr //= 3 p += 1 minP = min(minP, p) maxP = max(maxP, p) l = d.get(p, []) l.append(x) d[p] = l for key in range(maxP, minP - 1, -1): 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL 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 = list(map(int, input().split())) x = 0 r = [] for i in range(n): ok = True r = [] x = a[i] r.append(x) while ok: ok = False if x % 3 == 0: if x // 3 in a: ok = True x = x // 3 r.append(x) if x * 2...
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER 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 key(d, n): for i in d: if d[i] == n: return i return -1 n = int(input()) l = [int(i) for i in input().split()] d = {} for i in range(n): if l[i] % 3 == 0: d[l[i]] = [l[i] // 3, l[i] * 2] else: d[l[i]] = [l[i] * 2] for i in d: c = 1 for j in d[i]: ...
FUNC_DEF FOR VAR VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER 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 FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR LI...
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 cmp(x): i = 0 while x % 2 == 0: i += 1 x /= 2 return -x, i def main(): n = int(input()) a = list(map(int, input().split())) a.sort(key=cmp) for i in range(len(a)): print(a[i], end=" ") main()
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR 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()) l = list(map(int, input().split())) p = [] for i in range(n): x, c = l[i], 0 while l[i] % 3 == 0: l[i] = l[i] // 3 c += 1 p.append([-c, x]) p.sort() print(" ".join(list(map(lambda o: str(o[1]), 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUN...
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 md(x, d): res = 0 dd = 1 while x % (dd * d) == 0: dd *= d res += 1 return res def cmp(a, b): d3a = md(a, 3) d2a = md(a, 2) d3b = md(b, 3) d2b = md(b, 2) if d3a == d3b: return d2a < d2b return d3a...
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 ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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...
v = lambda p: lambda n: 0 if n % p else 1 + v(p)(n // p) input() print( " ".join( map( str, sorted(reversed(sorted(map(int, input().split()), key=v(3))), key=v(2)) ) ) )
ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL 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())) d = {} for t in l: if t not in d: d[t] = 1 else: d[t] += 1 k = [l[0]] x = l[0] d[x] -= 1 for t in range(100): if x * 2 in d and d[x * 2] > 0: k.append(x * 2) d[x * 2] -= 1 x *= 2 elif x % 3 == 0 and x // 3 in d ...
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 FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP 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...
def test(l, m, ite, Mite, dest): if ite == Mite: return True dest.append(m) if m not in l: dest.pop() return False if m % 3 == 0: if test(l, m // 3, ite + 1, Mite, dest): return True else: return test(l, m * 2, ite + 1, Mite, dest) else...
FUNC_DEF IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR 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...
import sys n = int(sys.stdin.readline()) nums = list(map(int, sys.stdin.readline().split())) edges = {} for i in nums: for j in nums: if i * 2 == j: if i in edges: edges[i].append(j) else: edges[i] = [j] if j * 3 == i: if i in edge...
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 DICT FOR VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LI...
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 fact(x): r = [0, 0, x] while x % 2 == 0: x //= 2 r[0] += 1 while x % 3 == 0: x //= 3 r[1] -= 1 return r input() d = [fact(int(x)) for x in input().split()] d.sort() print(*(x[2] for x in d))
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER 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()) res = list(map(int, input().strip().split(" "))) res = sorted(res, reverse=True) for i in range(len(res)): k = 0 result = [] result.append(res[i]) while len(result) != len(res): if result[k] % 3 == 0 and result[k] // 3 in res: result.append(result[k] // 3) el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP 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 comp(d1, d2): if d1.first > d2.first: return 1 if d1.first < d2.first: return 0 return bool(d1.second > d2.second) n = int(input()) a = [int(x) for x in input().split()] b = [] for x in a: tmp = x c3 = 0 c2 = 0 while x % 3 == 0: x //= 3 c3 += 1 b.app...
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR 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 ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR 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 dfs(v, a, c, t): c[v] = 1 for nb in adj[v]: if not c[nb]: dfs(nb, a, c, t) t.append(v) n, a = int(input()), list(map(int, input().split())) adj = [[] for _ in range(n)] for i in range(n - 1): for j in range(i + 1, n): if a[i] * 2 == a[j] or a[j] * 3 == a[i]: ...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_O...
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(item) for item in input().split()] def solve(start, occ, d): if d == n - 1: return True u = False v = False if start % 3 == 0 and start // 3 in occ and occ[start // 3] != 0: new_occ = dict(occ) new_occ[start // 3] = 0 u = solve(start // 3, new_...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR 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...
from sys import stdin, stdout def dfs(n): global ans ans += [n] if n in twice: dfs(twice[n]) elif n in div3: dfs(div3[n]) for _ in range(1): n = int(stdin.readline()) ans = [] a = list(map(int, stdin.readline().split())) twice = {} div3 = {} s = set(a) ind...
FUNC_DEF VAR LIST VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR 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...
n = int(input()) lst = list(map(int, input().split())) def conv(x): ans = 0 while x % 2 == 0: ans += 1 x = x // 2 return -x, ans lst.sort(key=conv) print(*lst)
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 ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR EXPR 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...
n = int(input()) a = [int(x) for x in input().split()] a.sort() l1 = [-1] * n l2 = [-1] * n for i in range(0, n): t = a[i] t2 = t * 2 j = i + 1 f = False while j < n: if a[j] > t2: break if a[j] == t2 and l2[j] == -1: f = True break j += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE 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 pow3(a): if a % 3 != 0: return 0 return 1 + pow3(a // 3) n = int(input()) a = list(map(int, input().split())) b = [] for i in a: b.append((-pow3(i), i)) b.sort() for i in b: print(i[1], end=" ")
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR 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...
f = int(input()) b = input() c = b.split() d = [] e = 0 for i in range(f): d.append(int(c[i])) for i in range(f): check = 0 for j in range(f): if d[j] == 3 * d[i]: check = 1 if d[i] % 2 == 0 and d[i] == 2 * d[j]: check = 1 if check == 0: e = d[i] print(e, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF BIN_OP...
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()) nums = list(map(int, input().split())) nums.sort() ans = [] for i in range(n): aux = nums[:] a = [nums[i]] j = 0 while a[j] // 3 in aux or a[j] * 2 in aux: b = a[j] // 3 c = a[j] * 2 if c in aux: a.append(c) aux.remove(c) elif a[j]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIG...
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()) lis = list(map(int, input().split())) for j in range(n): ans = [] curr = lis[j] cnt = 0 while cnt < n: ans.append(curr) cnt += 1 if curr * 2 in lis: curr *= 2 elif curr // 3 in lis and curr % 3 == 0: curr = curr // 3 ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER 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...
def F(num, a_res, a): a_new = a[:] a_new.remove(num) a_res.append(num) if num % 3 == 0: if num // 3 in a_new: a_res = F(num // 3, a_res, a_new) if num * 2 in a_new: a_res = F(num * 2, a_res, a_new) return a_res n = int(input()) a = [int(i) for i in input().split()] ...
FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL...
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()) numbers = list(map(int, input().split(" "))) divide_by_three = {} for i in numbers: j = 0 while i % 3**j == 0: j += 1 divide_by_three[i] = j num = [(-v, k) for k, v in divide_by_three.items()] num = sorted(num) print(*[i[1] for i in num])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR 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...
def exp_3(a: int) -> int: ans = 0 while a % 3 == 0: a //= 3 ans += 1 return ans def exp_2(a: int) -> int: ans = 0 while a % 2 == 0: a //= 2 ans += 1 return ans def comp(a: int, b: int) -> bool: if exp_3(a) > exp_3(b): return -1 elif exp_3(a) < ...
FUNC_DEF VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN 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()) inputlist = list(map(int, input().split())) outputlist = [inputlist.pop(0)] while len(inputlist) > 0: for i in range(len(inputlist)): if outputlist[0] * 3 == inputlist[i]: outputlist = [inputlist.pop(i)] + outputlist break elif inputlist[i] * 3 == outputlist[...
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 FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR VAR IF BIN_OP 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...
n = int(input()) lst = [int(x) for x in input().split()] n = len(lst) def sol(lst): res = [] for i in range(n): tempLst = lst.copy() res += [lst[i]] tempLst.remove(lst[i]) for j in range(1, n): for k in range(len(tempLst)): if tempLst[k] == res[len(r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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...
n = int(input()) def calc(x0): v2, v3 = 0, 0 x = int(x0) while x % 3 == 0: v3 += 1 x = x // 3 while x % 2 == 0: v2 += 1 x = x // 2 return tuple([v2, -v3, x0]) a = list(map(calc, input().split())) a = sorted(a) print(" ".join(map(lambda x: str(x[2]), a)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL...
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(d, x): stack = [x] res = 1 while stack: v = stack.pop() a = 0 if v % 3 == 0: e = v // 3 if d.get(e) != None: if d[e] > 0: d[e] -= 1 stack.append(e) res += 1 ...
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NONE IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NO...
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 info(x): copy_x = x cnt3 = 0 cnt2 = 0 while x % 3 == 0: x = x // 3 cnt3 += 1 while x % 2 == 0: x = x // 2 cnt2 -= 1 return cnt3, cnt2, copy_x n = int(input()) a = [int(i) for i in input().split()] new_a = [] for i in a: new_a.append(info(i)) new_a.sort()...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL 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 chooseN(k, arr): arr.append(k) global nexti, during if during[k] == 0: return False during[k] -= 1 if len(nexti[k]) == 0: if max([during[x] for x in during.keys()]) != 0: chooseP(arr[0], list(reversed(arr.copy()))) else: print(" ".join([str(x) for ...
FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN 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...
def canTake(nbr, lst, dict): return dict[nbr] != lst.count(nbr) def exists(nbr, dict): return nbr in dict def dfs(nbr, lst, dict, n): if len(lst) == n: print(*lst) exit(0) possibilities = [] if exists(nbr * 2, dict) and canTake(nbr * 2, lst, dict): possibilities.append(nb...
FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL 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, s, v = int(input()), set(map(int, input().split())), [] for x in s: if (x % 2 or x // 2 not in s) and x * 3 not in s: v.append(x) for i in range(n - 1): if v[-1] % 3 == 0 and v[-1] // 3 in s: v.append(v[-1] // 3) elif v[-1] * 2 in s: v.append(v[-1] * 2) print(" ".join(map(str, v))...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR EXPR FUN...
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(a): b = a c, d = 0, 0 while a % 3 == 0: a = a // 3 c = c + 1 while b % 2 == 0: b = b // 2 d = d + 1 if d == 0: return c + 2 return c + 1 / d n = int(input()) a = list(map(int, input().strip().split())) b = [] for i in range(n): b.append([fun...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NUMBER 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 IF VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUN...
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 t(v: int): count = 0 while v % 3 == 0: count += 1 v //= 3 return count n = int(input()) a = list(map(int, input().split())) ans = [] for i in a: ans.append((-t(i), i)) d = dict() for i in ans: if i[0] in d: d[i[0]].append(i[1]) else: d[i[0]] = [i[1]] for i i...
FUNC_DEF VAR 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 VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF 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...
from sys import stdin, stdout cin = stdin.readline cout = stdout.write n = int(cin()) a = list(map(int, cin().split())) l = [0] * n for i in a: l[0] = i for j in range(n - 1): if l[j] % 3 == 0 and l[j] // 3 in a: l[j + 1] = l[j] // 3 elif l[j] * 2 in a: l[j + 1] = l[j] *...
ASSIGN VAR VAR ASSIGN VAR 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 BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP ...
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())) l.sort() l1 = [] l2 = [] cur = l[0] l1.append(cur) while True: if cur % 3 == 0 and cur // 3 in l: cur //= 3 l1.append(cur) elif cur * 2 in l: cur *= 2 l1.append(cur) else: break cur = l[0] while True: if cur % 2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL 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 func(n, m): m = m.split() m = [int(m[i]) for i in range(len(m))] result = [m[0]] count = 0 countall = 0 m.sort(key=lambda p: (-power(p)[1], power(p)[0])) return " ".join(str(m[i]) for i in range(len(m))) def power(n): double = 0 triple = 0 while n % 2 == 0 or n % 3 == 0: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUN...
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(i) for i in input().split()] k = [l[0]] z = w = l[0] l.remove(w) while True: if w * 2 in l: w = w * 2 k = k + [int(w)] l.remove(w) elif w % 3 == 0 and w // 3 in l: w = w // 3 k = k + [w] l.remove(w) else: break w = z while Tru...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR LIST FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF 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...
def traverse(num, nums, position): copy = nums[:] position = position[:] if num not in copy: return [] else: copy.remove(num) position.append(num) if len(copy) == 0: return position elif num % 3 == 0: a = traverse(num // 3, copy, position) ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR RETU...
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_math_and_sorting_solution(n: int, sequence): def exp(b: int, a: int) -> int: k = 0 while a % b == 0: k += 1 a //= b return k power_of_3 = [(-exp(3, num), num) for num in sequence] power_of_3.sort() re...
FUNC_DEF VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR NUMBER VAR VAR 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_O...
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): x = a[i] cell = [0, 0] if x % 3 == 0: if x // 3 in a: cell[0] = 1 if 2 * x in a: cell[1] = 1 if not cell[0] and not cell[1]: last = x b[x] = cell seq = [last] while n > 1: x = s...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR 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()) a = [int(i) for i in input().split()] after = {} f = -1 for i in range(n): if a[i] % 2 == 0 and a[i] // 2 in a: after[a[i] // 2] = a[i] elif a[i] * 3 in a: after[a[i] * 3] = a[i] else: f = a[i] for i in range(n): print(f, end=" ") if i != n - 1: f = a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP 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...
import sys try: sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") except Exception as es: pass n = int(input()) lst = list(map(int, input().split())) ans = [] for i in range(n): for a in lst: if a * 2 in lst or a % 3 == 0 and a // 3 in lst: continue els...
IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING 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 FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP 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 = map(int, input().split()) b = [] for x in a: y = x cnt = 0 while y % 3 == 0: y //= 3 cnt += 1 b.append([-cnt, x]) b = sorted(b) for x in b: print(x[1], end=" ")
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 WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER 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 possible(arr, x): nums = {} for i in arr: if i not in nums.keys(): nums[i] = 0 nums[i] += 1 ans = [x] while True: if x % 3 == 0 and x // 3 in nums.keys(): x = x // 3 elif 2 * x in nums.keys(): x = 2 * x else: ret...
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST VAR WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN NUMBER EXPR FUNC_CALL 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 vert(n): if n * 2 in a: yield n * 2 if n % 3 == 0 and n // 3 in a: yield n // 3 def dfs(i, arr, b): if len(arr) == n: print(" ".join(map(str, arr))) return for j in vert(i): c = b.copy() c.remove(j) dfs(j, arr + [j], c) n = int(input()) a =...
FUNC_DEF IF BIN_OP VAR NUMBER VAR EXPR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR BIN_OP VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL 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...
from sys import stdin, stdout def main(): n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] d = dict() for v in a: v3 = 0 vc = v while vc % 3 == 0: vc = vc // 3 v3 += 1 temp = d.get(v3, []) temp.append(v) d[...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN 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...
n = int(input()) a = [int(i) for i in input().split()] p = [] for i in range(n): for j in range(i + 1, n): if a[i] == a[j] * 2: p.append([a[i], a[j]]) if a[j] == a[i] * 2: p.append([a[j], a[i]]) if a[i] == a[j] * 3: p.append([a[j], a[i]]) if a[j] =...
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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST 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()) lst = [int(x) for x in input().split()] l = -1 for x in range(n): if lst[x] % 2 == 0: if not lst[x] // 2 in lst and not lst[x] * 3 in lst: l = x break elif not lst[x] * 3 in lst: l = x break if l != -1: x = lst[l] else: x = min(lst) array ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR 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()) arr2 = [] arr = [int(i) for i in input().split()] for s in arr: k = s n3 = 0 n2 = 0 while k % 3 == 0: k = k % 3 + k // 3 n3 += 1 while k % 2 == 0: k = k // 2 + k % 2 n2 += 1 arr2.append((n3, n2, s)) arr2 = sorted(arr2, key=lambda x: -x[0]) b = arr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP ...
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())) L.sort() min = L[0] L1 = [L[0]] while True: if min * 3 in L and min * 3 not in L1: min = min * 3 L1 = [min] + L1 elif min / 2 in L and min / 2 not in L1: min = min // 2 L1 = [min] + L1 else: break min = L[0] while T...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR IF BIN_OP VAR NUMBER 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...
def pow3(x): ans = 0 while x % 3 == 0: x = x // 3 ans += 1 return ans n = int(input()) a = list(map(int, input().split())) for i in range(n): a[i] = [-1 * pow3(a[i]), a[i]] a.sort() for i in range(n): a[i] = a[i][1] print(*a)
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL ...
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(v): used[v] = 1 now.append(v) for i in range(len(graph[v])): if not used[graph[v][i]]: dfs(graph[v][i]) n = int(input()) num = list(map(int, input().split())) graph = [[] for i in range(n)] for i in range(n): for j in range(n): if i != j: if num[j] * 3 =...
FUNC_DEF ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR 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 ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FO...
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 calc_deg3(x): d = 0 while x % 3 == 0: x //= 3 d += 1 return d m = {} for ai in a: d = calc_deg3(ai) if d not in m: m[d] = [] m[d].append(ai) answer = [] for d in sorted(m.keys(), reverse=True): answer.extend...
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 DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN V...