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, ls, lsf = int(input()), list(map(int, input().split(" "))), [] for l in ls: x, f2, f3 = l, 0, 0 while x % 2 == 0: x, f2 = x // 2, f2 + 1 while x % 3 == 0: x, f3 = x // 3, f3 + 1 lsf.append((f2, f3, l)) lsf.sort(key=lambda z: z[1], reverse=True) lsf.sort(key=lambda z: z[0]) print(" ".j...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING LIST FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR 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...
def bakchodi(x): cnt = 0 while x % 3 == 0: x = x // 3 cnt += 1 return cnt n = int(input()) ls = [int(x) for x in input().split()] for j in range(n): for i in range(n - 1): if bakchodi(ls[i]) < bakchodi(ls[i + 1]): ls[i], ls[i + 1] = ls[i + 1], ls[i] elif bak...
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 VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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...
def binary_search(item, arr): left = 0 right = len(arr) - 1 while left < right: mid = (left + right) // 2 if arr[mid] == item: arr.pop(mid) return True elif arr[mid] < item: left = mid + 1 elif arr[mid] > item: right = mid - 1 ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER 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...
n = int(input()) vv = list(map(int, input().split())) arr = [[0, 0] for _ in range(n)] for i in range(n): cur = vv[i] while cur % 2 == 0: cur //= 2 arr[i][0] += 1 while cur % 3 == 0: cur //= 3 arr[i][1] += 1 gr = [[] for _ in range(n)] 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 LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER 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 calc(x): ret = 0 while x % 3 == 0: x //= 3 ret += 1 return ret n = int(input()) a = sorted( [(int(x), calc(int(x))) for x in input().split()], key=lambda x: (-x[1], x[0]) ) for elem in a: print(elem[0], sep=" ")
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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER 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...
n = int(input()) a = list(map(int, input().split())) l = [a[0]] for i in range(1, n): for j in range(i, n): if l[-1] * 2 == a[j]: l += [a[j]] a[i], a[j] = a[j], a[i] break if l[-1] // 3 == a[j] and l[-1] % 3 == 0: l += [a[j]] a[i], a[j] = a...
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 FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER 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()) arr = list(map(int, input().split())) MAX3, X = -1, -1 Min2 = arr[0] for i in range(n): x = arr[i] Min2 = min(Min2, x) while x % 2 == 0: x //= 2 if x == MAX3: X = min(X, arr[i]) if x > MAX3: MAX3 = x X = arr[i] if MAX3 == -1: ANS = [Min2] else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN 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 divided_three_multiply_two(a): res = [] for i in a: if i * 2 in a or i % 3 == 0 and i // 3 in a: res.append(i) for j in res: if j // 3 in a and j % 3 == 0: res.append(j // 3) elif j * 2 in a: res.append(j...
FUNC_DEF 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 FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR 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...
import sys n = int(sys.stdin.readline().rstrip("\n")) ls = list(map(int, sys.stdin.readline().split())) res = [] for i in range(n): for l in ls: if l * 2 in ls or l % 3 == 0 and l // 3 in ls: continue else: res.append(l) ls.remove(l) res = list(map(str, res[::-1]...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING 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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN 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 = int(input()) a = list(map(int, input().split())) g = [[(0) for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if i == j: continue if a[i] == 2 * a[j] or 3 * a[i] == a[j]: g[j][i] = 1 if a[j] == 2 * a[i] or 3 * a[j] == a[i]: g[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 NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR 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 input = lambda: sys.stdin.readline().rstrip("\r\n") def solve(): n = int(input()) a = list(map(int, input().split())) b = a[:] t = [[0, 0] for i in range(n)] for i in range(n): while a[i] % 3 == 0: t[i][0] += 1 a[i] //= 3 while a[i] % 2 == 0: ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER 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())) b = [0] * len(a) def search(a, n, num): for i in a: if i == num: return True return False for i in range(n): b[0] = a[i] check = 0 for j in range(n - 1): if check == 0: if b[j] % 3: if se...
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 FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR 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...
n = int(input()) lst = [int(i) for i in input().split()] pairs = list() for i in range(len(lst)): temp, count = lst[i], 0 while not temp % 3: count += 1 temp //= 3 pairs.append((-count, lst[i])) pairs.sort() print(" ".join(str(pairs[i][1]) for i in range(len(pairs))))
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 FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL 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()) li = list(map(int, input().split())) l = [] for i in range(40): l.append(3**i) a = [[] for i in range(40)] for i in range(n): for j in range(39, -1, -1): if li[i] % l[j] == 0: a[j].append(li[i]) break for i in range(39, -1, -1): if len(a[i]) == 0: con...
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 NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP 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...
I = lambda: int(input()) IL = lambda: list(map(int, input().split())) IF = lambda: list(map(float, input().split())) n = I() A = IL() A.sort(key=lambda x: (x & -x, -x)) print(*A)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP 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 three_pow(a): i = 0 while a % 3 ** (i + 1) == 0: i += 1 return i n = int(input()) A = [int(x) for x in input().split()] A.sort(key=lambda x: (-three_pow(x), x)) print(" ".join(map(str, A)))
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 find(ready, rest, restcount): if restcount == 0: return ready if ready[0] * 3 in rest.keys() and rest[ready[0] * 3] > 0: rest1 = dict(rest) rest1[ready[0] * 3] -= 1 res = find([ready[0] * 3] + ready, rest1, restcount - 1) if res: return res if ready[0]...
FUNC_DEF IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER 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()) a = list(map(int, input().split())) d = {} for i in a: d[i] = 1 ans = {} for i in a: if 2 * i in d: ans[i] = 2 * i if i % 2 == 0 and i // 2 in d: ans[i // 2] = i if 3 * i in d: ans[3 * i] = i if i % 3 == 0 and i // 3 in d: ans[i] = i // 3 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 DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN 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...
n = int(input()) a = list(map(int, input().split())) b = [(0) for i in range(105)] ok = False def dfs(now, ans): global ok global b if ans == n: ok = True b[ans] = now return if now % 3 == 0 and now // 3 in a: dfs(now // 3, ans + 1) if ok: b[ans] = now ...
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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR RETURN IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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...
input() arr = list(map(int, input().split())) def getscale(n): while n % 3 == 0: n //= 3 while n % 2 == 0: n //= 2 return n scale = getscale(arr[0]) def coord(n): x, y = 0, 0 while n % 3 == 0: n //= 3 y += 1 while n % 2 == 0: n //= 2 x += 1 ...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHI...
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 while x % 3 == 0: x //= 3 i -= 1 while x % 2 == 0: x //= 2 i += 1 return i input() a = list(map(int, input().split())) a = sorted(a, key=f) print(*a)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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...
n = int(input()) a = list(map(int, input().split())) pool = set(a) def check(pool, start, path=None): pool.remove(start) if path is None: path = [] if not pool: return path + [start] else: if not start % 3 and start // 3 in pool: return check(pool.copy(), start // 3...
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 NONE EXPR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR LIST IF VAR RETURN BIN_OP VAR LIST VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP 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())) def func(x): b = list(a) r = [] for i in range(n): if x % 3 == 0 and x // 3 in b: x //= 3 b.remove(x) r += [x] if x * 2 in b: x *= 2 b.remove(x) r += [x] return ...
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 FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR LIST VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER 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()) a = [int(a) for a in input().split()] ans = [] if n == 2: if a[1] * 2 == a[0] or a[1] / 3 == a[0]: ans.append(a[1]) ans.append(a[0]) else: ans.append(a[0]) ans.append(a[1]) else: while a: for i in a: if i / 2 not in a and i * 3 not in a: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR 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 def getfirstelement(a): for i in a: if i * 3 in a: continue if i % 2 == 0 and i // 2 in a: continue return i def main(): n = int(input()) a = [int(i) for i in input().split()] x = getfirstelement(a) x = int(x) print(int(x)) n -= ...
IMPORT FUNC_DEF FOR VAR VAR IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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...
o = int(input()) l = list(map(int, input().split())) current = min(l) forwards = [current] step = 1 while True and len(forwards) < o: if current * 2 in l and current * 2 not in forwards: current = current * 2 forwards.append(current) elif current % 3 == 0: n = current // 3 if n 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 ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER 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 three_num(n): result = 0 while n % 3 == 0: n //= 3 result += 1 return result n = int(input()) x = list(map(int, input().split())) y = set(x) first = x[0] max_num = three_num(x[0]) for i in range(1, n): temp = three_num(x[i]) if temp > max_num: max_num = temp fir...
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 FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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()) arr = list(map(int, input().split())) minVal = min(arr) currentVal = minVal index = arr.index(currentVal) answer = [] while True: answer.append(currentVal) arr[index] = -1 if currentVal % 3 == 0 and currentVal // 3 in arr: currentVal = currentVal // 3 elif currentVal * 2 in arr:...
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP 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()) a = [int(x) for x in input().split()] a.sort() ans = [] for i in range(n): t = 0 x = a[i] while x % 3 == 0: t += 1 x = x // 3 ans.append((-t, a[i])) ans.sort() for x in ans: print(x[1], end=" ")
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR 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())) ind = -1 for i in range(n): ta = a.copy() cur = a[i] ta.pop(i) res = [cur] while ta: if ta.count(cur * 2): res.append(cur * 2) ta.pop(ta.index(cur * 2)) cur *= 2 elif cur % 3 == 0 and ta.count(cu...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR WHILE VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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()) b = list(map(int, input().split())) a = dict() for i in range(n): a[b[i]] = 0 start = -1 for i in b: if i * 3 not in a and (i % 2 != 0 or i // 2 not in a) and start == -1: start = i if i * 2 in a: a[i] = i * 2 elif i % 3 == 0 and i // 3 in a.keys(): a[i] = i // 3...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR 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()) a = [int(x) for x in input().split()] p = [-1] * n d = [True] * n for i in range(n): for j in range(n): if a[i] * 2 == a[j] or a[i] == a[j] * 3: p[j] = i d[i] = False r = [d.index(True)] while p[r[-1]] >= 0: r.append(p[r[-1]]) r.reverse() print(*(a[x] for x in r)...
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 NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN 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...
def f(x): global a if len(ans) == n: print(" ".join(map(str, ans))) exit() if x % 3 == 0 and x // 3 in a: ans.append(x // 3) f(x // 3) ans.pop() if x * 2 in a: ans.append(x * 2) f(x * 2) ans.pop() n = int(input()) a = list(map(int, input(...
FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP 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...
n = int(input()) p = input().rstrip().split(" ") q = list(p) for i in range(0, len(p)): T = list(q) x = int(p[i]) l = [] U = 1 K = 0 l.append(x) while K < n - 1: K += 1 if x % 3 == 0: x = x // 3 if str(x) not in T: U = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE 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()) a = [int(i) for i in input().split()] ans = [] ans.append(a[0]) a.remove(a[0]) while len(a) > 0: for i in a: if i == ans[0] * 3 or i == ans[0] // 2 and ans[0] % 2 == 0: ans = [i] + ans a.remove(i) if i == ans[-1] * 2 or i == ans[-1] // 3 and ans[-1] % 3 == 0:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER 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...
n = int(input()) a = list(map(int, input().split())) ans = [] ans.append(a[0]) a.pop(0) while len(a) != 0: for i in range(len(a)): if a[i] * 2 == ans[0] or ans[0] * 3 == a[i]: ans.insert(0, a[i]) a.pop(i) break elif a[i] == ans[len(ans) - 1] * 2 or ans[len(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 EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR EX...
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 check(e, u): if not len(u): return 0 elif e % 3 == 0 and e // 3 in u: t = u.copy() t.remove(e // 3) o = check(e // 3, t) if o == -1: if e * 2 in u: t = u.copy() t.remove(e * 2) o = check(e * 2, t) ...
FUNC_DEF IF FUNC_CALL VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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()) L = list(map(int, input().split())) D = {} D_2 = {} check_final = -1 for i in L: if D.get(i) is None: D[i] = -1 for i in L: check = i % 2 == 0 if check: if D.get(i // 2) is not None: D[i] = i // 2 D_2[i // 2] = i if D.get(3 * i) is not None: ...
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 DICT ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER NONE 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 = [int(i) for i in input().split()] dupa = [] max = 0 for i in a: count = 0 while i % 3 == 0: i //= 3 count += 1 dupa.append([i, count]) if count > max: max = count x3 = [] x2 = [] def sort3(x): return x[0] def sort33(x): return x[1] def sort2(x):...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF RETURN 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 dfs(i, visit, ans0, cnt): if cnt == n: ans = [a[ans0[j]] for j in range(n)] print(*ans) exit() for j in G[i]: if not visit[j]: visit[j] = 1 ans0[cnt] = j dfs(j, visit, ans0, cnt + 1) visit[j] = 0 n = int(input()) a = list(map(...
FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 main(): n = int(input()) ar = list(map(int, input().split())) lookup = {ar[i]: i for i in range(n)} def dfs(idx, ai, p): visited[idx] = True ans[ai] = ar[idx] if ai + 1 == n: return True res = False if ar[idx] % 3 == 0: t = ar[idx] // ...
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 VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR 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()) T = input().split(" ") for i in range(n): T[i] = int(T[i]) for w in range(n): bol = True L = [T[w]] for j in range(n - 1): if 2 * L[j] in T and 2 * L[j] not in L: L.append(2 * L[j]) elif L[j] % 3 == 0 and L[j] // 3 in T and L[j] // 3 not in L: L.a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR VAR 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...
def imprime(arr): for i in range(len(arr)): print(arr[i]["num"], end=" ") print() return def troca(i, j): a0 = a[i] b0 = b2[i] c0 = b3[i] a[i] = a[j] b2[i] = b2[j] b3[i] = b3[j] a[j] = a0 b2[j] = b20 b3[j] = c0 return def pot2(x): j = 0 while x % 2...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR RETURN FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN 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()) a = list(map(int, input().split())) forward = [None] * n backward = [None] * n for i in range(n): for j in range(n): if 3 * a[i] == a[j] or a[i] == 2 * a[j]: backward[i] = j forward[j] = i break head = backward.index(None) while head is not None: prin...
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 NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN 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...
n = int(input()) l = sorted([int(x) for x in input().split()]) m = l[-1] a = [] b = [] def solve_before(l, m, k): if k > m or k not in l or k in b: return False b.append(k) if k % 2 == 0: if not solve_before(l, m, k // 2): solve_before(l, m, k * 3) else: solve_befor...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER 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...
class SeqNum: def __init__(self, number): self.num = number self.two = 0 while number % 2 == 0: self.two += 1 number //= 2 self.three = 0 while number % 3 == 0: self.three += 1 number //= 3 l = int(input()) seq = [SeqNum(int(...
CLASS_DEF FUNC_DEF ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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...
__file__ = 0 def input_(): global __file__ if not __file__: return input() if not hasattr(__file__, "readline"): __file__ = open("input.txt", "r") return __file__.readline() n = int(input_()) arr = list(map(int, input_().split())) def factor_counter(x, factor): count = 0 wh...
ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN FUNC_CALL VAR IF FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING RETURN FUNC_CALL 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 ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR RETURN 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...
num = int(input()) Result = [] List = [] String = input().split(" ") for i in String: List.append(int(i)) for i in List: if i * 2 in List or i % 3 == 0 and i // 3 in List: Result.append(i) for j in Result: if j * 2 in List: Result.append(j * 2) if j % 3 ==...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER 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...
n = int(input()) a = list(map(int, input().split())) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 mi = min(a) arr = [mi] prev = [mi] while True: if 3 * prev[-1] in d and d[3 * prev[-1]] > 0: d[3 * prev[-1]] -= 1 prev.append(3 * prev[-1]) elif prev[-1] & 1 == 0 a...
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 VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR WHILE NUMBER IF BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP NUMBER 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 play(x, remain): if not x in remain: return False else: remain.remove(x) anslist.append(str(x)) if len(remain) == 0: return True if x % 3 == 0: if play(x // 3, remain): return True if play(x * 2, remain): return True anslist.remove(...
FUNC_DEF IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR 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()) l = list(int(x) for x in input().split()) s = set(l) for j in range(len(l)): d = [] i = l[j] while i != -1: d.append(i) if i % 3 == 0 and i // 3 in s: i = l[l.index(i // 3)] elif i * 2 in s: i = l[l.index(i * 2)] else: i = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR 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())) st = set(s) for i in range(n): st1 = st.copy() l = 0 x = s[i] ans = [] while l < n: if x % 3 == 0 and x // 3 in st1: ans.append(x) st1.remove(x) x = x // 3 elif x * 2 in st1: ans.appe...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER 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...
n = int(input()) s = input() a = [int(x) for x in s.strip().split(" ")] d = [] for x in a: d.append(x * 2) if x % 3 == 0: d.append(x // 3) ans = [] head = -1 for i in range(n): if a[i] not in d: head = i break ans.append(a[head]) h = a[head] for i in range(1, n): if h % 3 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR 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()) G = list(map(int, input().split())) M = [[] for i in range(n)] for i in range(len(G)): for j in range(len(G)): if G[i] == G[j] * 3 or G[i] * 2 == G[j]: M[i].append(j) used = [0] * n def FindPath(k, m): if m == len(G): Z.append(R[:]) else: for i in M[k]:...
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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR 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...
def solve(n1): i = 0 while n1 % 2 == 0: i += 1 n1 //= 2 return i n = int(input()) arr = list(map(int, input().split())) for i in range(n): arr[i] = [-solve(arr[i]), arr[i]] arr = sorted(arr)[::-1] for i in arr: print(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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR 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 gcd1(a, b): return a if b == 0 else gcd1(b, a % b) def gcd2(arr): ans = arr[0] for i in arr: ans = gcd1(ans, i) return ans def deg(a): ans = [0, 0] while a % 2 == 0: a //= 2 ans[0] += 1 while a % 3 == 0: a //= 3 ans[1] += 1 return ans def...
FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER 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()) flag = 0 lst = [int(x) for x in input().split()] for i in lst: if i * 2 not in lst and i // 3 not in lst: val = i flag = 1 if flag == 0: val = 4 s = [] s.append(val) top = 0 lst.remove(val) loop = len(lst) while loop != 0: a = s[top] // 2 b = s[top] * 3 if a in lst: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR AS...
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): count = 0 while x % 3 == 0: x = x // 3 count += 1 return count def pow2(x): count = 0 while x % 2 == 0: x = x // 2 count += 1 return count n = int(input()) l = input().split() li = [int(i) for i in l] l = [] for i in li: a = pow3(i) b = po...
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 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 FUNC_CALL VAR ASSIGN 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().split())) go = {} for i in range(n): go[i] = [] def add(fr, to): global go go[fr].append(to) for i1, v1 in enumerate(a): for i2, v2 in enumerate(a): if v1 * 2 == v2: add(i1, i2) elif v1 // 3 == v2 and v1 % 3 == 0: add...
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 LIST FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF 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().strip()) ais = list(map(int, input().strip().split())) def d2d3(x): res = 0 while x % 2 == 0: x //= 2 res += 1 while x % 3 == 0: x //= 3 res -= 1 return res ais.sort(key=d2d3) print(" ".join(map(str, ais)))
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 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 VAR EXPR FUNC_CALL 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...
def dfs(u, a, visited, path): path.append(u) if len(path) == len(a): return True vlist = [u * 2] if u % 3 != 0 else [u * 2, u // 3] for v in vlist: if v in a and v not in visited: visited.add(v) if dfs(v, a, visited, path): return True ...
FUNC_DEF EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER LIST BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR 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...
seq_len = int(input()) seq = [int(i) for i in input().split()] head = -1 def arrange_rec(seq): head = -1 if not seq: return for pot_head in seq: if pot_head * 3 not in seq and pot_head % 2 != 0: head = pot_head elif pot_head * 3 not in seq and pot_head % 2 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR RETURN FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER 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...
n = int(input()) A = [int(x) for x in input().split()] S = set(A) ADJ = {} for elem in A: adjs = [] if elem * 2 in S: adjs.append(elem * 2) if elem % 3 == 0 and elem // 3 in S: adjs.append(elem // 3) ADJ[elem] = adjs def solve(V, L): myL = list(L) myL.append(V) if len(myL) ...
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 ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER AS...
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 proc(x): w = x d2, d3 = 0, 0 while x % 2 == 0: d2 += 1 x //= 2 while x % 3 == 0: d3 += 1 x //= 3 return (d2, -d3), w n = int(input()) a = list(map(lambda x: proc(int(x)), input().split())) a.sort() for i in a: print(i[1], end=" ")
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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...
def dfs(n, dic, a, right, left): dic[n] = 1 for i in a: if dic[i] == 0: if i * 3 == n or n * 2 == i: left.append(i) dfs(i, dic, a, right, left) if n * 3 == i or i * 2 == n: right.append(i) dfs(i, dic, a, right, left)...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR 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 = list(map(int, input().split())) g = [-1] * n for i in range(n): for j in range(n): if a[i] * 2 == a[j]: g[i] = j if a[j] * 3 == a[i]: g[i] = j cur = g.index(-1) result = [cur] while cur in g: cur = g.index(cur) result.append(cur) print(*[a[i] for ...
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 FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR 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...
n = int(input()) a = [int(x) for x in input().split()] for i in range(n): ans = list() ans.append(a[i]) for j in range(n): if i != j: if ans[-1] * 2 in a: ans.append(ans[-1] * 2) elif ans[-1] % 3 == 0: if ans[-1] // 3 in a: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER 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...
input() v = list(map(int, input().split())) def find_last_position(li): li = [] for i in v: if i % 3 == 0 and i // 3 in v: li.append(i) elif i * 2 in v: li.append(i) for i in v: if i not in li: return i def find_path(li): v_new = [] e =...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR 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...
def graph(arr, n): ret = [-1] * n for i in range(n): for j in range(n): if i == j: continue if 2 * arr[i] == arr[j]: ret[i] = arr[j] elif arr[i] == 3 * arr[j]: ret[i] = arr[j] return ret def dfs(graph, arr): re...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL 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...
def array_copy(src): trg = list() for each in src: trg.append(each) return trg def recursion(src, progress, element, left): c = array_copy(src) c.remove(element) left -= 1 if left == 0: out = "" for e in progress: out += "{} ".format(e) print(out...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER 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(" ")] ss = set() for x in a: ss.add(x) yy = dict() ini = None for x in a: if 2 * x in ss: yy[2 * x] = x elif x % 3 == 0 and x // 3 in ss: yy[x // 3] = x else: ini = x ans = [ini] cur = ini while cur in yy.keys(): cur = yy[cu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE FOR VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER 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()) l = list(map(int, input().split())) d = [] for i in l: d.clear() t = l[:] t.remove(i) d.append([[i], t]) for k in range(n - 1): to_del = [] for p in range(len(d)): num = d[p][0][-1] s = d[p][1] in_mod = bool(num % 3 == 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 VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL 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()) a = list(map(int, input().split())) check = set(a) start = 0 for x in a: if x * 3 not in check and (x % 2 == 1 or x // 2 not in check): start = x break ans = [start] cnt = 1 while cnt < n: if start % 3 == 0 and start // 3 in check: ans.append(start // 3) start = ...
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 NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR VAR 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...
import sys input = sys.stdin.readline def func(n): r = 0 while n % 2 == 0: n = n // 2 r += 1 while n % 3 == 0: n //= 3 r -= 1 return r q = int(input()) a = list(map(int, input().split())) print(*sorted(a, key=func))
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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 EXPR 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...
n, a = int(input()) - 1, list(map(int, input().split())) for i in a: if i % 2 == 1: if i * 3 not in a: l = i break elif i * 3 not in a and i // 2 not in a: l = i break t = str(l) while n != 0: if l * 2 in a: l *= 2 t += " " + str(l) elif l ...
ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF 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 p3(n): res = 0 while n % 3 == 0: n //= 3 res += 1 return res def p2(n): res = 0 while n % 2 == 0: n //= 2 res += 1 return res def cmp_to_key(mycmp): class K: def __init__(self, obj, *args): self.obj = obj def __lt__(self,...
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 FUNC_DEF CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER 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...
input() a = [int(s) for s in input().split()] b = [a[0]] while True: k = b[-1] x = k * 2 if x in a: b.append(x) elif k % 3 == 0: x = k // 3 if x in a: b.append(x) else: break else: break while True: k = b[0] x = k * 3 if x i...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER WHILE NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR WHILE 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()) m = list(map(int, input().split(" "))) l = [[(0) for i in range(n)] for i in range(n)] d = dict() for i in range(n): d[m[i]] = i for i in range(n): if m[i] * 2 in m: l[i][d[m[i] * 2]] = 1 if not m[i] % 3 and m[i] // 3 in m: l[i][d[m[i] // 3]] = 1 z = [] for i 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 STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN 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...
n = list(map(int, input().strip().split(" "))) nums = set(map(int, input().strip().split(" "))) seq = [None] def check_nums(num): global nums if num * 3 not in nums: if num % 2 == 0: if num // 2 in nums: return False else: return True els...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NONE FUNC_DEF IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER RE...
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()) x = list(map(int, input().split())) edge = [[] for i in range(n)] for i in range(n): for j in range(n): if x[i] == x[j] * 3 or x[i] * 2 == x[j]: edge[i].append(j) prev = [] def count1(q, i): p = i count2 = 0 while q % p == 0: count2 += 1 p *= 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 VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_DEF 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())) two, three = [], [] for i in a: tmp, three_tmp, two_tmp = i, 0, 0 while tmp % 3 == 0: tmp //= 3 three_tmp += 1 while tmp % 2 == 0: tmp //= 2 two_tmp += 1 two.append(two_tmp) three.append(three_tmp) b = sorted((two[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 VAR LIST LIST FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER 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 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()) numbers = input().split() numbers = [int(x) for x in numbers] numbers.sort() numbers.reverse() temps = [] temp = [] def find_factor(temp, n, numbers): if n % 3 == 0 and n // 3 in numbers: temp.append(n // 3) numbers.remove(n // 3) return find_factor(temp, n // 3, numbers) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST 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 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()) pop = list(map(int, input().split())) lap = [] tam = pop lok = [] for item in pop: lok.append(item) tod = len(pop) for item in lok: lap.append(item) pop.remove(item) for x in range(tod): if item * 2 in pop: lap.append(item * 2) pop.remove(item * 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 LIST ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF 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...
n = int(input()) s = [int(x) for x in input().split()] d = {} for i in range(n): q = s[i] t2 = 0 while q % 2 == 0: q //= 2 t2 += 1 q = s[i] t3 = 0 while q % 3 == 0: q //= 3 t3 += 1 d[t3, -t2] = s[i] w = [i for i in d] w.sort(reverse=1) for i in range(n): p...
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 ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER AS...
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, x, t = int(input()), sorted(list(map(int, input().split()))), [] t.append(x[0]) for j in t: if 2 * j in x: t.append(x.pop(x.index(2 * j))) elif j // 3 in x and j % 3 == 0: t.append(x.pop(x.index(j // 3))) while len(t) < n: if t[0] * 3 in x: t.insert(0, x.pop(x.index(t[0] * 3))) ...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR 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())) for i in a: q = i + 0 for j in range(n - 1): if i * 2 in a: i *= 2 elif i % 3 == 0 and i // 3 in a: i //= 3 else: break else: print(q, end=" ") for j in range(n - 1): ...
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 VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR 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 sys n = int(input()) a = list(map(int, input().split())) queue, ans = 0, "" d1, d2 = {}, {} for i in a: d1[i] = 0 for i in a: for j in a: if j * 3 == i or i * 2 == j: d1[j] += 1 d2[i] = j for k, v in d1.items(): if v == 0: queue = k for i in range(n - 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 VAR NUMBER STRING ASSIGN VAR VAR DICT DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR 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...
def count(num): if num % 3 != 0: return 0 return 1 + count(num // 3) n = int(input()) a = [*map(int, input().split())] b = [None] * n c = [None] * n for i in range(0, n): c[i] = i for i in range(0, n): cnt = count(a[i]) b[i] = cnt c.sort(key=lambda id: (-b[id], a[id])) for i in range(0, n)...
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 LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN 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()) a = list(map(int, input().split())) res = [] while len(a) > 0: el = "" for i in range(len(a)): el = a[i] if len(res) > 0: if el == res[-1] * 2 or res[-1] % 3 == 0 and el == res[-1] // 3: res.append(el) a.remove(el) brea...
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 ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER 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()) p = input().rstrip().split(" ") l = list(p) for i in range(0, len(p)): t = int(p[i]) del l[i] q = [] q.append(t) while 1: if len(l) == 0 or len(q) == n: break elif t % 3 == 0 and str(t // 3) in l: t = t // 3 f = l.index(str(t)) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR 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()) a = list(map(int, input().split())) for i in range(n): start = a[i] ans = [start] f = True for j in range(n - 1): if start * 2 in a: ans.append(start * 2) start *= 2 elif start % 3 == 0 and start // 3 in a: ans.append(start // 3) ...
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 VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMB...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
from sys import stdout n = int(input()) if n % 4 == 2: print("!", -1) exit(0) l = 1 r = l + n // 2 memo = [-1] * (n + 1) def check(i): if memo[i] == -1: print("?", i) stdout.flush() memo[i] = int(input()) return memo[i] while r >= l: a = check(l) b = check(l + n // 2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR V...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
import sys def printans(i): print("! %d" % i, flush=True) sys.exit(0) def fullgetdiff(i, m): print("? %d" % i, flush=True) ai = int(input()) print("? %d" % (i + m), flush=True) aim = int(input()) return ai - aim n = int(input()) if n // 2 % 2: printans(-1) getdiff = lambda i: fullg...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR F...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
import sys got = [10**18] * 100005 def getnum(i): if got[i] == 10**18: print("? %d" % i) sys.stdout.flush() got[i] = int(input()) return got[i] n = int(input()) if n % 4 == 2: print("! -1") else: lo = 1 hi = n // 2 + 1 t1 = getnum(lo) t2 = getnum(hi) lo2 = t1...
IMPORT ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUM...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
from sys import stdout n = int(input()) if n % 4 == 2: print("! -1") exit(0) print("?", 1) stdout.flush() a = int(input()) print("?", 1 + n // 2) stdout.flush() b = int(input()) if a == b: print("!", 1) exit(0) l = 1 r = 1 + n // 2 while l != r: mid = (l + r) // 2 print("?", mid) stdout.flu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CAL...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
n = int(input()) if n % 4 == 2: print("!", "-1") exit() def qry(i): print("?", i + 1, flush=True) a = int(input()) return a def qry2(i): a = qry(i + n // 2) - qry(i) if a == 0: print("!", i + 1) exit() return a a = qry2(0) lb, rb = 1, n // 2 - 1 while lb <= rb: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF ...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
import sys def ask(x): print("? %d" % x) sys.stdout.flush() x = int(input()) return x n = int(input()) t = n // 2 if t & 1: print("! -1") sys.stdout.flush() sys.exit() l = 1 r = n while l < r: mid = l + r >> 1 if ask(mid) >= ask((mid + t - 1) % n + 1): r = mid else: ...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VA...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
import sys def ask(i): print("?", i + 1) sys.stdout.flush() a_i = int(input()) return a_i def answer(i): print("!", i + 1 if i != -1 else -1) sys.exit() def has_intersection(l1, r1, l2, r2): if l1 <= l2 and r2 <= r1: return True if l2 <= l1 and r1 <= r2: return True...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR STRING VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR F...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
class Solver: def solve(self): self.num_people = int(input()) if self.num_people % 4 == 2: return -1 return self.find_zero_pair() def find_zero_pair(self): begin = 1 end = self.num_people // 2 + 1 begin_value = self.func(begin) if begin_value...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL ...
Akash got his money from CodeChef today, so he decided to have dinner outside. He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked. Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *c...
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if len(set(a)) < k: print(-1) else: d = {} for i in range(n): if a[i] not in d: d[a[i]] = b[i] else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DIC...