description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
a = int(input()) lister = input().split() lister = [int(i) for i in lister] ans = dict() def findans(n): if n in ans: return ans[n] mod = n % lister[n] ok = True if n + lister[n] >= a and n - lister[n] < 0: ok = False else: for i in range(mod, a, lister[n]): if ...
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 FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR V...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) board = list(map(int, input().split(" "))) index = list(range(0, n)) ascending = [x for _, x in sorted(zip(board, index))] winners = n * [""] for c in reversed(ascending): if board[c] == n: winners[c] = "B" toCheck = c - board[c] while toCheck >= 0: if winners[toCheck] == "B...
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 FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR LIST STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING A...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys input = sys.stdin.readline out = sys.stdout n = int(input()) a = list(map(int, input().split())) pos = [0] * n for i in range(n): a[i] -= 1 pos[a[i]] = i win = ["?"] * n for x in range(n - 1, -1, -1): i = pos[x] win[i] = "B" j = i while True: j -= x + 1 if j < 0: ...
IMPORT 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 FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBE...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = list(map(int, input().split())) ans = [-1] * n loc = {} for i in range(n): loc[a[i]] = i for i in range(n): if a[i] > i and a[i] >= n - i: ans[i] = "B" prev = 0 while ans.count(-1) != prev: prev = ans.count(-1) for i in range(n): if ans[i] == -1: for j in...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER WHILE FUNC_...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = list(map(int, input().split())) p = [0] * (n + 2) m = [0] * (n + 2) for i in range(n): p[a[i]] = i for i in range(n, 0, -1): j = p[i] % i while j < n and m[i] == 0: m[i] = i < a[j] and m[a[j]] == 0 j += i for i in range(n): print("BA"[m[a[i]]], 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys cin = sys.stdin n = int(next(cin)) a = list(map(int, next(cin).split())) n2idx = {a[i]: i for i in range(n)} f = [False] * (n + 1) for i in range(n, 0, -1): idx_lg = n2idx[i] win_flag = False for j in range(idx_lg % i, n, i): if a[j] > i and not f[a[j]]: win_flag = True ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_C...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = list(map(int, input().split())) res = [] dp = [-1] * n def helper(i): if dp[i] != -1: return dp[i] cur = True std = a[i] while i + std < n: if a[i] < a[i + std]: cur = cur and helper(i + std) std += a[i] std = a[i] while i - std >= 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 ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR B...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [int(x) for x in input().split()] h = [-1] * n b = [(a[i], i) for i in range(n)] b.sort(reverse=True) for e in b: num, idx = e flag = True allNeg = True foundLosing = False foundWin = False for i in range(idx % num, n, num): if i == idx: continue ...
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 VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CAL...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) x = list(map(int, input().split())) dp = [0] * n m = [0] * (n + 1) for i in range(n): m[x[i]] = i for i in range(n, 0, -1): for i2 in range(m[i] + i, n, i): if i < x[i2] and dp[i2] == 0: dp[m[i]] = 1 for i2 in range(m[i] - i, -1, -i): if i < x[i2] and dp[i2] == 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VA...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [int(x) for x in input().split()] a_reverse = a.copy() status = [] for i in range(n): a_reverse[a[i] - 1] = i status.append(None) pos = a_reverse[n - 1] status[pos] = False fails = set() fails.add(pos) for i in range(n - 1, 0, -1): i_ = i - 1 pos = a_reverse[i_] for k in range((...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NONE ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL V...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [int(s) for s in input().split()] ans = [None] * n def get(p): if ans[p] is not None: return ans[p] elif a[p] == 1: ans[p] = "A" elif a[p] == n: ans[p] = "B" else: for i in range(p + a[p], n, a[p]): if a[i] > a[p]: if get...
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 NONE VAR FUNC_DEF IF VAR VAR NONE RETURN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR VAR ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR IF ...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
i = m = n = int(input()) a = [*map(int, input().split())] s = [0] * n r = [range(i % a[i], n, a[i]) for i in range(n)] while m: i = (i - 1) % n if s[i] == 0: if all(a[j] <= a[i] or s[j] == "A" for j in r[i]): s[i] = "B" m -= 1 if any(a[j] > a[i] and s[j] == "B" for j in r...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VA...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys n = int(input()) arr = list(map(int, input().split())) if n == 1: print("B") sys.exit() ind = [0] * (n + 1) for i in range(n): ind[arr[i]] = i l = [False] * (n + 1) l[1] = True for i in range(n - 1, 1, -1): f = ind[i] - i trig = False while f >= 0: if arr[f] > i: ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASS...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys input = sys.stdin.readline n = int(input()) arr = [int(x) for x in input().split()] both = [] for i in range(n): both.append([arr[i], i]) both.sort(reverse=True) color = [-1] * n for val, index in both: done = False for i in range(index + val, n, val): if done: break ...
IMPORT ASSIGN 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP V...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [int(x) for x in input().split()] ans = [""] * n b = [0] * n for i in range(n): b[n - a[i]] = i for i in range(len(b)): t = b[i] % (n - i) f = 0 for j in range(t, n, n - i): if ans[j] == "B" and a[j] > n - i: ans[b[i]] = "A" f = 1 break ...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMB...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [*map(int, input().split())] s = [0] * n t = set(range(n)) while t: q = set() for i in t: x = a[i] r = range(i % x, n, x) if all(a[j] <= x or s[j] == "A" for j in r): s[i] = "B" q |= {i} if any(a[j] > x and s[j] == "B" for j in r): ...
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 NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) p = [[a[i], i] for i in range(n)] p.sort(reverse=True) lose = [0] * n for v, x in p: lose[x] = 1 for i in range(1, n): y = x + i * a[x] if y >= n: break if a[y] > a[x] and lose[y]: ...
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 VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR ...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
R = lambda: map(int, input().split()) n = int(input()) a = list(R()) arr = sorted(([x, i] for i, x in enumerate(a)), reverse=True) res = [-1] * n for x, i in arr: res[i] = ( 0 if any(res[j] == 1 for j in range(i + x, n, x) if a[j] > a[i]) or any(res[j] == 1 for j in range(i - x, -1, -x) if a...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) board = list(map(int, input().strip().split())) board.insert(0, 0) hashed = [0] * (n + 1) for i in range(n + 1): hashed[board[i]] = i answer = ["C"] * (n + 1) for i in range(n, 0, -1): flag = 0 k = hashed[i] - board[hashed[i]] while k > 0: if answer[k] == "B": flag =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER FOR VAR FUNC...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) p = [int(x) for x in input().split()] dp = ["B" for _ in range(n)] idx = sorted([[p[i], i] for i in range(n)], reverse=True) idx = [x[1] for x in idx] for i in idx: for j in range(1, n): ind = i + j * p[i] ind1 = i - j * p[i] if ind >= n and ind1 < 0: break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR V...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) arr = [int(x) for x in input().split()] pos = dict() if n == 1: print("B") else: for i in range(n): pos[arr[i]] = i ans = ["Q"] * n ans[pos[1]] = "A" ans[pos[n]] = "B" for i in range(n - 1, 0, -1): flag = 0 p = pos[i] j = 1 while p + j * i...
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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR NUMBER STRING ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
def solve(n, a): ainv = {} for i in range(1, n + 1): ainv[a[i - 1]] = i sol = {} for i in range(n, 0, -1): ai = ainv[i] j = (ai - 1) % i + 1 while j <= n: if j in sol and sol[j] == "B": sol[ai] = "A" break j += i ...
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR STRING VAR VAR ASSIGN VAR V...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys input = sys.stdin.readline def find(x): global dp if len(adj[x]) == 0: dp[x] = False return False else: if dp[x] != -1: return dp[x] ans = False for neighbor in adj[x]: ans |= not find(neighbor) dp[x] = ans return ...
IMPORT ASSIGN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_C...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [int(i) for i in input().split()] indx = [0] * n winners = [""] * n for i, ai in enumerate(a): indx[ai - 1] = i for ai in range(n, 0, -1): i = indx[ai - 1] can_win = False for j in range(i + ai, n, ai): if a[j] > ai and "B" == winners[j]: can_win = True ...
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 STRING VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FO...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) arr = [0] + list(map(int, input().split())) indx = [(0) for i in range(n + 1)] for i in range(1, n + 1): indx[arr[i]] = i ans = [(-1) for i in range(n + 1)] for i in range(n, 0, -1): ind1 = indx[i] - i count_zero, count_one, count_min_one = 0, 0, 0 while ind1 >= 1: if ans[ind1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [*map(int, input().split())] b = [0] * n for i in range(n): b[n - a[i]] = i s = [0] * n for i, j in enumerate(b): i = n - i s[j] = "BA"[any(a[k] > a[j] and s[k] == "B" for k in range(j % i, n, i))] print("".join(s))
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 NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING FUNC_CALL VAR VAR...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) arr = list(map(int, input().strip().split())) dicti = {} for i in range(n): dicti[arr[i]] = i + 1 ans = [(-1) for i in range(n + 1)] if n > 1: ans[dicti[1]] = 1 for i in range(n, 1, -1): for j in range(dicti[i] % i - 1, n, i): if arr[j] > i: if ans[j + 1] == 0: ...
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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NU...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = [int(i) for i in input().split()] s = ["." for _ in range(n)] v = 0 t = set(range(n)) while v < n: for i in range(n): if s[i] != ".": continue r = range(i % a[i], n, a[i]) if all(a[j] <= a[i] or s[j] == "A" for j in r): s[i] = "B" v +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR IF FUNC_C...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) arr = list(map(int, input().split())) memo = [(-1) for i in range(n + 1)] def can_win(idx): if memo[idx] != -1: return memo[idx] res = False delta = arr[idx] nidx = idx + delta while nidx < n: if arr[nidx] > arr[idx] and not can_win(nidx): res = True ...
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 BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR ASSI...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
import sys input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) PLACE = [None] * (n + 1) for i in range(n): PLACE[A[i]] = i al = n WINLIST = [None] * (n + 1) def move(n, al): place = PLACE[n] for i in range(place, -1, -n): if A[i] > n and WINLIST[A[i]] == "B": ...
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 BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR FOR VAR ...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
def f(k): if an[k] != -1: return an[k] z = a[k] ans = "B" for i in range(k, -1, -z): if a[i] > z: if f(i) == "B": ans = "A" for i in range(k, n, z): if a[i] > z: if f(i) == "B": ans = "A" an[k] = ans return ans ...
FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CA...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = list(map(int, input().split())) b = sorted((x, i) for i, x in enumerate(a)) c = ["B"] * n while b: x, i = b.pop() for j in range(i % x, n, x): if a[j] > a[i] and "B" == c[j]: c[i] = "A" break print("".join(c))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR STRING VAR VAR ASS...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n, a = int(input()), list(map(int, input().split())) mem, arr = [""] * (n + 1), [0] * n for i in range(n): arr[a[i] - 1] = i if a[i] == n: mem[i] = "B" for i in arr[n - 2 :: -1]: flag = -1 for j in range(i + a[i], n, a[i]): if mem[j] == "B": flag = j break if ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST STRING BIN_OP VAR NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR STRING FOR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VA...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) arr = [int(x) for x in input().split()] d = {x: i for i, x in enumerate(arr)} ans = ["B"] * len(arr) for x in reversed(range(1, n + 1)): i, k = d[x], 1 while x * k <= n - 1: y1 = i + k * x y2 = i - k * x if y1 <= n - 1: if arr[y1] > x and ans[y1] == "B": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER A...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) line = list(map(int, input().split())) a = [(0) for i in range(n)] ans = [(0) for _ in range(n)] ans[0] = 1 ans[-1] = -1 for i in range(n): a[line[i] - 1] = i for i in range(n - 2, 0, -1): cur = -1 num = i + 1 k = 0 start = a[i] % num while start + num * k < n: temp = st...
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
from sys import stdin input = stdin.readline n = int(input()) a = [int(x) for x in input().split()] b = [0] * (n + 1) for i in range(n): b[a[i]] = i c = [False] * n for i in range(n, 0, -1): j = i w = False while b[i] + j < n and w == False: w = c[b[i] + j] j += i j = i while b[...
ASSIGN VAR VAR 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE...
After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating...
n = int(input()) a = list(map(int, input().split(" "))) if n == 1: print("B") exit() indices = [(0) for i in range(n + 1)] for i in range(1, n + 1): indices[a[i - 1]] = i steps = [(0) for i in range(n + 1)] steps[1] = 1 existing = {} existing[indices[n]] = steps[n] existing[indices[1]] = steps[1] for i in r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
dc = {} def slv(n, prime=2): if n == 1: return 1 global dc for i in range(2, 10000): if i * i > prime: continue if prime % i == 0: return slv(n, prime + 1) if (n, prime) in dc: return dc[n, prime] ans = 10**50 for i in range(2, n + 1): ...
ASSIGN VAR DICT FUNC_DEF NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUM...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
import sys input = sys.stdin.readline n = int(input()) y = [2, 3, 5, 7, 11, 13, 17, 23, 29, 31] def dfs(n, pos): v = [1, 10**18][n > 1] for i in range(2, n + 1): if n % i == 0: v = min(v, y[pos] ** (i - 1) * dfs(n // i, pos + 1)) return v print(dfs(n, 0))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER BIN_OP NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP B...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
INF = 20**18 primes = [] a = [1] * 100 def crivo(): for i in range(2, 100): if a[i]: primes.append(i) for j in range(i + i, 100, i): a[j] = 0 def dp(div, idx): div = int(div) idx = int(idx) if div == 1: return 1 resp = INF for i in rang...
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETUR...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43] def solve(n, pos): ans = 10**18 if n > 1 else 1 for exp in range(2, n + 1): if n % exp == 0: ans = min(ans, p[pos] ** (exp - 1) * solve(n // exp, pos + 1)) return ans inp = int(input()) print(solve(inp, 0))
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_C...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
from itertools import combinations def prime_divisors(n): a = [] i = 2 while i * i <= n: if n % i == 0: a.append(i) n //= i else: i += 1 a.append(n) a.sort(reverse=True) return a n = int(input()) npr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] r...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
n = int(input()) def get_factors(n): result = [] factor = 2 while n != 1: if n % factor == 0: n = n // factor result.append(factor) else: factor += 1 return result factors = get_factors(n) primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] options = lis...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
n = int(input()) pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61] pprr = set(pr) dp = [[(0) for i in range(9)] for j in range(1005)] def it(n, pref): global dp if dp[n][pref] > 0: return dp[n][pref] if n in pprr or pref == 0: dp[n][pref] = 2 ** (n - 1) retu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR ...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
def main(): def f(x, i, aa): if x == 1: return 1 bb = [q for q in aa if not x % q] p = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43)[i] return min(p ** (d - 1) * f(x // d, i + 1, bb) for d in bb) n = int(input()) print(f(n, 0, [d for d in range(2, n + 1) ...
FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN ...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
prime = [0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29] min_value = round(1e18) n = int(input()) def search(value, total_factor, i): global min_value if total_factor == n: min_value = min(value, min_value) return for k in range(1, 65): value *= prime[i] if value > min_value: ...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR IF VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR E...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
def prime(x): for i in range(2, x): if x % i == 0: return False return True def Solve(i, Cnt): if i == len(L): ans = 1 for j in range(9): ans *= P[j] ** Cnt[j] Min[0] = min(Min[0], ans) return for j in range(9): if Cnt[j] == 0: ...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR B...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
def isPrime(i) -> bool: t = 2 while t * t <= i: if i % t == 0: return False t += 1 return i > 1 MAX_ANS = 10**18 d = int(input()) bound = 25 p = [-1] for i in range(100000): if isPrime(i): p.append(i) if len(p) > bound: break dp = [([MAX_ANS + 1]...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CAL...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] def power(a, b): res = 1 while b: if b & 1: res *= a a *= a b >>= 1 return res ans = [] ans.append(1e30) def solve(pos, n, res): if n == 1: ans[0] = min(ans[0], res) for i in range(2, 62): ...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NU...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
p = [2, 3, 5, 7, 11, 13, 17, 23, 29, 31] b = int(input()) N = [([1] * 11) for i in range(b + 1)] for j in range(10): N[1][j] = 1 for i in range(2, b + 1): for j in range(1, 11): m = None for k in range(i): f = i % (k + 1) if f == 0: if j > 1: ...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] dp = [[(-1) for i in range(12)] for i in range(1100)] def solve(divisors, index): if divisors == 1: return 1 if index == 11: return 9999999999999999999999999999 if dp[divisors][index] != -1: return dp[divisors][index] ans = ...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] N = 0 ans = 1000000000000000000 def dfs(i, x, n): global ans if n > N: return if n == N and x < ans: ans = x for j in range(1, 61): if ans <= x * p[i]: return x *= p[i] dfs(i + 1, x, n * (j + 1)) N = int(inp...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR RETURN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
pri = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def deal(x, y): if x == 1: tmp = 1 else: tmp = 10**18 for csx in range(2, x + 1): if 0 == x % csx: tmp = min(tmp, pri[y] ** (csx - 1) * deal(x // csx, y + 1)) return tmp print(deal(int(input()), 0))
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
n = int(input()) p = [] f = [] def prime(x): for i in range(2, x): if x % i == 0: return False return True def factorize(x): i = 2 while i * i <= x: while x % i == 0: f.append(i) x //= i i = i + 1 if x > 1: f.append(x) f.rev...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
n = int(input()) prime = [(1) for i in range(1001)] primes = [] for i in range(2, 1000 + 1): if prime[i] == 1: for j in range(i * i, 1000 + 1, i): prime[j] = 0 primes.append(i) def recurse(n, last): if n == 1: return 1 ans = 10**18 for i in range(2, n + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] n = int(input()) dp = [] for i in range(n + 1): t = [] for j in range(len(p)): t.append(0) dp.append(t) for i in range(10): dp[1][i] = 1 for i in range(2, n + 1): dp[i][0] = p[0] ** (i - 1) for j in range(1, len(p)): dp[i][j] = dp[i][j - 1...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIG...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] dp = [[(10**18) for i in range(15)] for j in range(1006)] inf = 10**18 for pw in range(64): dp[pw + 1][0] = 2**pw for idx in range(1, 13): for i in range(1005): for pw in range(64): if i % (pw + 1) == 0: if dp[i...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR FO...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
n = int(input()) factors = [i for i in range(2, n + 1) if n % i == 0] primes = [] is_composite = [False] * (n + 1) for i in range(2, n + 1): if not is_composite[i]: primes.append(i) for p in primes: j = i * p if j > n: break is_composite[j] = True if i % p == ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN ...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
def fn(n, index, primes): if n == 1: return 1 ans = 10**19 for i in range(2, n + 1): if n % i == 0: ans = min(ans, primes[index] ** (i - 1) * fn(n // i, index + 1, primes)) return ans primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] n = int(input()) print(fn(n, 0, primes))
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMB...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
PRIMOS = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] def solucion(n, prim_i=0, numero=1, divisores=1): if divisores == n: return numero sol = 10**18 primo = PRIMOS[prim_i] for i in range(1, 64): if numero * primo > sol: break if divisores * (i + 1) > n: bre...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF NUMBER NUMBER NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL V...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
n = int(input()) p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] ans = int(1e19) def calc(i, cur, val): global ans if cur == n: ans = min(ans, val) return if cur > n or i > 10: return t = p[i] for j in range(1, 61): if ans >= t * val: calc(i + 1, cur * (j + 1),...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR V...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
inf = 1 << 64 p = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29] ans = inf linf = int(1e18) def dfs(x, n, m): if n == 1: global ans ans = min(ans, m) return l, k = 1, p[x] while l < n and k < linf: if n % (l + 1) == 0: if m * k > linf: break ...
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER N...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
def fact(n): p = {} d = 2 while d * d <= n: while n % d == 0: p[d - 1] = p.get(d - 1, 0) + 1 n //= d d += 1 if n > 1: p[n - 1] = p.get(n - 1, 0) + 1 return p def isPrime(n): if n % 2 == 0: return n == 2 d = 3 while d * d <= n and ...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN VAR FUNC_DEF IF BIN_...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
n = int(input()) g = lambda n: [q for q in range(2, n + 1) if n % q == 0] t = {k: g(k) for k in g(n)} p = [2, 3, 5, 7, 11, 13, 17, 19, 23] def f(i, k): return min(f(i + 1, k // s) * p[i] ** (s - 1) for s in t[k]) if k > 1 else 1 print(f(0, n))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_O...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
def prime_factors(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors num = int(input()) primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41] k = prime_...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBE...
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Output Output the smallest positive integer with exactly n divisors. Examples Input 4 ...
def is_prime(n): i = 2 while i * i <= n: if n % i == 0: return False i += 1 return True m = {} p = [] i = 2 while len(p) < 12: if is_prime(i): p.append(i) i += 1 INF = 10**18 m = {} ans = INF def f(a, b, div): global ans if b >= len(p): return ...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR VAR FUNC_...
A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an integer c such tha...
for _ in range(int(input())): c = input() n, K = map(int, input().split()) e = [[] for i in range(n)] for i in range(n - 1): t1, t2 = map(int, input().split()) t1 -= 1 t2 -= 1 e[t1].append(t2) e[t2].append(t1) bj = [1] * 101 ans = [0] def dfs(x, depth...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR...
A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an integer c such tha...
import sys input = sys.stdin.readline F = [None] * 101 F[0] = 1 for i in range(1, len(F)): F[i] = F[i - 1] * i % int(1000000000.0 + 7) def rec(x, p, g, c, s): c[s] += 1 for v in g[x]: if v != p: rec(v, x, g, c, s + 1) def solve(): input() n, k = map(int, input().split()) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMB...
A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an integer c such tha...
import sys input = sys.stdin.readline t = int(input()) mod = 10**9 + 7 for _ in range(t): tmp = input() n, k = map(int, input().split()) g = [[] for i in range(n)] for __ in range(n - 1): u, v = map(int, input().split()) g[u - 1].append(v - 1) g[v - 1].append(u - 1) f = [1] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR VAR FUNC_CALL VA...
A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an integer c such tha...
md = int(1000000000.0) + 7 N = 110 def add(x, y): x += y if x >= md: x -= md if x < 0: x += md return x def mul(x, y): x *= y x %= md return x depth = [0] * N cnt = [0] g = [[] for _ in range(N)] def Dfs(v, pr): for to in g[v]: if to != pr: dep...
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER VAR VAR RETURN VAR FUNC_DEF VAR VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_O...
A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an integer c such tha...
mod = 1000000007 def min(x, y): if x < y: return x return y def solve(m, x): if m < k: return 0 f = [[(0) for _ in range(k + 1)] for _ in range(m + 1)] f[0][0] = 1 for i in range(1, m + 1): for j in range(0, min(k + 1, i + 1)): if j == 0: f...
ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUM...
A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an integer c such tha...
import sys input = sys.stdin.readline t = int(input()) mod = 10**9 + 7 cnb_max = 1000 kai = [1] * (cnb_max + 1) rkai = [1] * (cnb_max + 1) for i in range(cnb_max): kai[i + 1] = kai[i] * (i + 1) % mod rkai[cnb_max] = pow(kai[cnb_max], mod - 2, mod) for i in range(cnb_max): rkai[cnb_max - 1 - i] = rkai[cnb_max -...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): result = set() if n == 0: result = [""] else: for i in range(1, n + 1): temp1 = {("(" + x + ")") for x in self.generateParenthesis(i - 1)} temp2 = {x for x in self.generateParenthesis(n...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR V...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): ret = [] def backtrack(left=0, right=0, tmp=""): if len(tmp) == 2 * n: ret.append(tmp) return if left < n: backtrack(left + 1, right, tmp + "(") if left > right: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF NUMBER NUMBER STRING IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR STRING EXPR FUNC_CALL VAR RETURN VAR
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): if not n: return [] cache = [["(", 1, n - 1]] for _ in range(2 * n - 1): for _ in range(len(cache)): temp = cache.pop(0) if temp[1]: toAdd = temp.copy() ...
CLASS_DEF FUNC_DEF IF VAR RETURN LIST ASSIGN VAR LIST LIST STRING NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VA...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): if n < 1 or type(n) != int: return [] ret = [] tmp = [] tmp.append({"str": "(", "cnt": 1, "rcnt": 0}) while tmp: cur = tmp.pop() if n == cur["cnt"]: ret.append(cur["str"] + ...
CLASS_DEF FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR RETURN LIST ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR DICT STRING STRING STRING STRING NUMBER NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING BIN_OP STRING BIN_OP VAR VAR STRING IF VAR STRING VAR STRING EXPR...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): if n == 0: return [""] if n == 1: return ["()"] results = [] for i in range(1, 2 * n, 2): first = self.generateParenthesis(int((i - 1) / 2)) second = self.generateParenthesis(int((2 * n...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST STRING IF VAR NUMBER RETURN LIST STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBE...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): def balance(str): lst = list(str) bal = 0 for char in lst: if char == "(": bal += 1 else: bal -= 1 return bal def left(str): ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF ...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def parenthesis(self, n): return "(" * n + ")" * n def generateParenthesis(self, n): if n == 0: return [] elif n == 1: return ["()"] result = [] for i in range(1, n): r1 = self.generateParenthesis(i) r2 = s...
CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN ...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: hashMap = {} outPut = [] def helper(self, n, string, length, opened, openUsed): if length == n * 2: if string not in self.outPut: self.outPut.append(string) return if string in self.hashMap: return else: ...
CLASS_DEF ASSIGN VAR DICT ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR RETURN ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR STRING BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): answers = [] for i in range(0, n + 1): answers.append(Solution.catalanHelper(i, answers)) print((i, answers)) return list(set(answers[n])) @staticmethod def catalanHelper(n, answers): if n == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN LIST STRING IF VAR NUMBER RETURN LIST STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP ...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): if n == 0: return [] left = right = n result = [] self.generate(left, right, result, "") return result def generate(self, left, right, result, string): if left == 0 and right == 0: result....
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR STRING RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR B...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): self.res = [] self.dfs(n, 0, 0, "") return self.res def dfs(self, n, left, right, path): if left > n or right > n: return if n == 0: self.res.append(path) return if left == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER STRING RETURN VAR FUNC_DEF IF VAR VAR VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR ...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): stack = [] s = "" self.dfs(stack, 0, 0, s, n) return stack def dfs(self, stack, first, last, s, n): if last == n: stack.append(s) else: if first < n: self.dfs(stack, first ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR STRING VAR
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): rst = [] cake = "" self.generateRecursion(rst, cake, n, n) return rst def generateRecursion(self, rst, cake, left, right): if right == 0: rst.append(cake) if left > 0: self.generateRecursi...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR STRING BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR STRING VAR BIN_OP VAR NUMBER
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): results = [] def genparen(prefix, opens, closes): if len(prefix) == 2 * n: results.append(prefix) return if opens < n: genparen(prefix + "(", opens + 1, closes) if ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING NUMBER NUMBER RETURN VAR
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): self.mem = {} return self.top_down(n) def merge(self, left, right): comb = [] for i in left: comb += [(i + j) for j in right] return list(set(comb)) def top_down(self, n): if n == 1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN LIST STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUM...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution: def generateParenthesis(self, n): def gen(n, open_par, res, res_set): print(res) if len(res) == 2 * n: res_set.append("".join(res)) return if 2 * n - len(res) > open_par: res.append("(") gen...
CLASS_DEF FUNC_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN IF BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) a = [] for i in range(n): a.append([]) for x in input(): if x == "0": a[i].append(0) else: a[i].append(1) ans = 0 for x1 in range(0, m): for x2 in range(x1, m): for y1 in range(0, n): for y2 in range(y1, n): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VA...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
nm = input().split() n = int(nm[0]) m = int(nm[1]) room = [] for row in range(n): room.append(input()) best = 0 for row in range(n): for col in range(m): if room[row][col] == "1": continue col2 = m row2 = row while row2 < n: col3 = col while co...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR AS...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) a = [list(map(int, input())) for i in range(n)] p = [([0] * (m + 3)) for i in range(n + 3)] for i in range(n): for j in range(m): p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + a[i][j] ans = 0 for i1 in range(n): for j1 in range(m): for i2 in range(i1, n...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
import sys dim_list = sys.stdin.readline().split() n, m = int(dim_list[0]), int(dim_list[1]) T = [[[[(-1) for l in range(m)] for k in range(m)] for j in range(n)] for i in range(n)] for i in range(n): row = sys.stdin.readline() for j in range(m): T[i][i][j][j] = int(row[j]) max_per = 4 for k in range(3...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUN...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) s = "" for i in range(n): s += input() def is_possible(p, q, r): for i in range(p, p + q): for j in range(r): if s[i + j * m] == "1": return False return True ans = 1 for i in range(m * n): max_cols = n - i // m max_rows = m - ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR AS...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
graph = [] def perimeter(x0, y0, x1, y1): return (x1 - x0 + 1) * 2 + (y1 - y0 + 1) * 2 def check(x0, y0, x1, y1): for i in range(x0, x1 + 1): for j in range(y0, y1 + 1): if graph[i][j] == "1": return False return True def solve(n, m, graph): res = 4 for i in...
ASSIGN VAR LIST FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
def func(a, b): for i in range(min(a[0], b[0]), max(a[0], b[0]) + 1): for j in range(min(a[1], b[1]), max(a[1], b[1]) + 1): if matx[i][j] == 1: return False return True n, m = map(int, input().split()) x = [] matx = [[int(X) for X in list(input().strip())] for i in range(n)...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FU...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) mat = [] for i in range(n): mat.append(input()) dp = [ [[[(True) for i in range(m)] for i in range(n)] for i in range(m)] for i in range(n) ] ans = 0 for x1 in range(n): for y1 in range(m): for x2 in range(x1, n): for y2 in range(y1, m): d...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) n, m = n + 1, m + 1 dp = [[(0) for j in range(m)] for i in range(n)] for i in range(1, n): s = input() for j in range(1, m): dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + int(s[j - 1]) mx = 0 for i in range(1, n): for j in range(1, m): for k in ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMB...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = [int(i) for i in input().split()] matriz = [] for i in range(n): matriz.append(input()) ans = 4 for i in range(n): for j in range(m): for k in range(i, n): for l in range(j, m): block = False for x in range(i, k + 1): for y in range(...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) l = [] for i in range(n): l.append(list(map(int, input()))) l1 = [[] for i in range(n)] for i in range(n): for j in range(m): if l[i][j] == 1: l1[i].append(j) ans = 4 for p in range(n): for q in range(m): if l[p][q] == 0: y = n ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) dp = [[(0) for j in range(m)] for i in range(n)] mp = [] for i in range(n): mp.append(input()) for j in range(m): if mp[i][j] == "1": continue if not i or mp[i - 1][j] == "1": dp[i][j] = 1 else: dp[i][j] = dp[i - 1][j] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR V...