description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes. A pal...
import sys input = sys.stdin.readline s = list(input().rstrip()) n = len(s) l = [0] * n r = [0] * n for i in range(n): j = 0 while 0 <= i - j and i + j < n and s[i - j] == s[i + j]: l[i + j] += 1 r[i - j] += 1 j += 1 j = 1 while 0 <= i - j + 1 and i + j < n and s[i - j + 1] == s...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMB...
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes. A pal...
word = input() n = len(word) dp = [[(0) for i in range(n)] for j in range(n)] for i in range(n): dp[i][i] = 1 for i in range(1, n): for j in range(n - i): if word[j] == word[j + i]: if i - 1 == 0: dp[j][j + i] = 1 elif dp[j + 1][j + i - 1] == 1: dp...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VA...
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes. A pal...
from sys import stdin, stdout a = stdin.readline() n = len(a) - 1 a = list(a)[:n] dp = [[(0) for j in range(n)] for i in range(n)] for i in range(n): dp[i][i] = 1 for l in range(2, n + 1): for i in range(n - l + 1): j = i + l - 1 if j - i == 1 and a[i] == a[j]: dp[i][j] = 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN ...
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes. A pal...
def main(): s = tuple(input()) n = len(s) a, b = [1] * n, [1] * n for i in range(n): for x, y in zip(range(i, -1, -1), range(i + 2, n)): if s[x] != s[y]: break a[y] += 1 b[x] += 1 for x, y in zip(range(i, -1, -1), range(i + 1, n)): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR F...
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes. A pal...
def f(t): m = len(t) flag = True for i in range(m // 2): if t[i] != t[m - 1 - i]: flag = False return flag s = input() n = len(s) l = [0] * n r = [0] * n arr = [(i, i) for i in range(n)] + [ (i, i + 1) for i in range(n - 1) if s[i] == s[i + 1] ] for x, y in arr: while x >= ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR...
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes. A pal...
t = input() n = len(t) if n == 2000 and len(set(t)) == 1: print(667333166500) else: a, b = [0] + [1] * n, [1] * n for i in range(n // 2): x, y = i - 1, i + 1 while x >= 0 and t[x] == t[y]: a[y + 1] += 1 b[x] += 1 x -= 1 y += 1 x, y = i,...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): cache = {} def dfs(N): if N in cache: return cache[N] max_ = N for i in range(N - 2): max_ = max(max_, dfs(i) * (N - i - 1)) cache[N] = max_ return max_ re...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 6: return N dp = [(0) for i in range(N + 1)] for i in range(1, N + 1): dp[i] = i for i in range(7, N + 1): j = i - 3 while j >= 1: curr = dp[j] * (i - j - 1) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR V...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N < 7: return N cnt = [0] * N for i in range(1, 7): cnt[i - 1] = i for i in range(7, N + 1): for b in range(i - 3, 0, -1): curr = (i - b - 1) * cnt[b - 1] if curr > cnt[i...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF ...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): dp = [(0) for i in range(N + 1)] if N <= 6: return N for i in range(7): dp[i] = i for i in range(7, N + 1): max1 = i dp[i] = i for j in range(1, i - 2): if max1 < dp...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def helper(self, N, dp): if N <= 6: return N if dp[N] != -1: return dp[N] max_count = 0 for b in range(N - 3, 0, -1): count = (N - b - 1) * self.helper(b, dp) max_count = max(max_count, count) dp[N] = max_count ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUM...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def findVal(self, n): if n <= 6: return n if n in self.dp: return self.dp[n] maxi = 0 for b in range(n - 3, 0, -1): maxi = max(maxi, (n - b - 1) * self.findVal(b)) self.dp[n] = maxi return maxi def optimalKeys(...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 6: return N screen = [0] * N for n in range(1, 7): screen[n - 1] = n for n in range(7, N + 1): screen[n - 1] = max( 2 * screen[n - 4], max(3 * screen[n - 5], 4 * screen[n - 6]) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMB...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): l = [0] * 256 l[0] = 0 l[1] = 1 l[2] = 2 for i in range(3, N + 1): l[i] = i for j in range(i - 3, 0, -1): l[i] = max(l[i], l[j] + l[j] * (i - (2 + j))) return l[N]
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BI...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 6: return N dp = [(i if i <= 6 else 0) for i in range(N + 1)] for i in range(7, N + 1): c = 2 for j in range(i - 3, 0, -1): if dp[j] * c >= dp[i]: dp[i] = dp[j] * c ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VA...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): dp = [i for i in range(N + 1)] for i in range(1, N + 1): dp[i] = dp[i - 1] + 1 for j in range(3, i): dp[i] = max(dp[i], (i - j) * dp[j - 1]) return dp[N]
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, n): l = [0, 1, 2, 3, 4, 5, 6] for i in range(7, n + 1): m = i c = 2 for j in range(i - 3, 0, -1): x = l[j] * c if x >= m: m = x else: bre...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR V...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): self.state = [-1] * (N + 1) return self.keys(N) def keys(self, N): if N <= 6: return N if self.state[N] != -1: return self.state[N] ans = 0 times = 2 for i in range(N - 3, 0, -1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VA...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): dparr = [i for i in range(N + 1)] for i in range(7, N + 1): k = 2 temp = [] for j in range(i - 3, 0, -1): temp.append(dparr[j] * k) k += 1 dparr[i] = max(temp) return dp...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR NUMBER
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): arr = [0, 1, 2, 3, 4, 5, 6] for i in range(7, N + 1): arr.append(0) c = 2 for j in range(i - 3, 0, -1): if arr[i] <= arr[j] * c: arr[i] = arr[j] * c else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, n): dp = [0] * (n + 1) for i in range(1, n + 1): dp[i] = dp[i - 1] + 1 for j in range(1, i - 2): dp[i] = max(dp[i], dp[j] * (i - j - 1)) return dp[n]
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def __init__(self): self.keys = {} for i in range(1, 76): self.optimalKeys1(i) def optimalKeys1(self, N): if N <= 5: self.keys[N] = N return N else: val = max( self.keys[N - 1] + 1, ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): res = [-1] * N return self.optimal(res, N) def optimal(self, res, n): if n < 7: return n i = n - 3 temp1 = 2 ans = 0 while i >= 0: if res[i] == -1: res[i] = self.optimal(re...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMB...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): dp = [-1] * (N + 1) dp[0] = 0 def findsol(n): if n <= 6: return n if dp[n] != -1: return dp[n] maxe = 0 times = 2 for i in range(n - 3, 0, -1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER AS...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def recur(self, ans, cnt, N, l): if N < 0: return if N == 0: ans[0] = max(ans[0], cnt) return ans self.recur(ans, cnt + l, N - 1, l) l = cnt cnt = cnt + l self.recur(ans, cnt, N - 3, l) def optimalKeys(self, N)...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NU...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): dp = [(0) for i in range(N + 1)] for i in range(1, N + 1): if i <= 6: dp[i] = i else: j = i - 3 temp = 0 while j >= 1: temp = max(temp, dp[j] * (i - ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: dp = [None for i in range(76)] dp[0], dp[1], dp[2], dp[3], dp[4] = 0, 1, 2, 3, 4 for i in range(5, 76): dp[i] = max(2 * dp[i - 3], 3 * dp[i - 4], 4 * dp[i - 5]) def optimalKeys(self, N): return self.dp[N]
CLASS_DEF ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def util(self, n, copied, i, prev, dp): if i <= 0: return 0 if dp[i] != -1: return dp[i] res = self.util(n, False, i - 1, prev + 1, dp) + 1 val = 0 if copied: val += self.util(n, True, i - 1, prev, dp) + prev ans = ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): n = N if N < 7: return N dp = [0] * (n + 1) for i in range(1, 7): dp[i] = i for i in range(7, N + 1): dp[i] = max(2 * dp[i - 3], 3 * dp[i - 4], 4 * dp[i - 5]) return dp[-1]
CLASS_DEF FUNC_DEF ASSIGN VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUM...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 6: return N if N == 11: return 27 dp = [-1] * (N + 1) maxx = 0 x = 2 y = N - 3 for i in range(7): dp[i] = i for i in range(7, N + 1): multiple = 2 ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 6: return N screen = [0] * N for n in range(1, 7): screen[n - 1] = n for n in range(7, N + 1): screen[n - 1] = 0 for b in range(n - 3, 0, -1): curr = (n - b - 1) * scree...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR ...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): dp = [[1, 0, 0, 0, 0]] for i in range(1, N): pre = dp[-1] dp1 = max(pre[:-1]) + 1 dp2 = max(pre[:-1]) dp3 = pre[1] dp4, dp5 = 0, 0 for j in range(i): if (i - j + 1) * dp...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N < 7: return N arr = [(0) for _ in range(N)] for i in range(6): arr[i] = i + 1 for i in range(6, N): for j in range(i - 3, -1, -1): arr[i] = max(arr[i], arr[j] * (i - j - 1)) re...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def maximumA(self, N, map): if N in map: return map[N] if N <= 6: map[N] = N return N maxi = -1 for i in range(2, N): maxi = max(maxi, (N - i) * self.maximumA(i - 1, map)) map[N] = maxi return maxi ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR DICT
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): buf = {} def ops(n): code = "" + str(n) if code in buf: return buf[code] if n == 0: return 0 if n == 1: return 1 if n < 6: return n ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 5: return N dp = [0] * (N + 1) dp[1] = 1 dp[2] = 2 dp[3] = 3 dp[4] = 4 dp[5] = 5 for i in range(6, N + 1): choices = [i] for k in range(2, i - 1): ch...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP ...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): self.arr = [0] * (N + 1) return self.recur(N) def recur(self, N): if N <= 6: return N if self.arr[N]: return self.arr[N] x = 0 for i in range(N, 6 - 1, -1): x = max(x, (N - i + 2) * se...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def find_optimal(self, N, dp): if N <= 6: return N if dp[N] != -1: return dp[N] max_count = 0 for b in range(N - 3, 0, -1): count = (N - b - 1) * self.find_optimal(b, dp) max_count = max(max_count, count) dp[N] ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR A...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 6: return N dp = [-1] * (N + 1) for i in range(7): dp[i] = i for i in range(7, N + 1): multiple = 2 for j in range(i - 3, 0, -1): dp[i] = max(dp[i], dp[j] * multiple) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR N...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N <= 1: return N dp = [0] * (N + 1) dp[1] = 1 for i in range(2, N + 1): dp[i] = dp[i - 1] + 1 for j in range(2, i): dp[i] = max(dp[i], dp[j - 2] * (i - j + 1)) return dp[N]
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, n): if n < 5: return n else: return max(4 * self.optimalKeys(n - 5), 3 * self.optimalKeys(n - 4))
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, n): if n <= 6: return n else: dp = [(0) for i in range(n + 1)] for i in range(7): dp[i] = i for i in range(7, n + 1): for j in range(3, i): dp[i] = max(dp[i], dp...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR...
Imagine you have a special keyboard with the following keys: Key 1: Prints 'A' on screen Key 2: (Ctrl-A): Select screen Key 3: (Ctrl-C): Copy selection to buffer Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed. Find maximum numbers of A's that can be produced by pressing keys...
class Solution: def optimalKeys(self, N): if N < 7: return N return self.support(N) def support(self, N): dp = [0] * (N + 1) for i in range(7): dp[i] = i for i in range(7, N + 1): res = 0 for j in range(i - 3, 1, -1): ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VA...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
for test in range(int(input())): n, m, k1 = map(int, input().split()) g = [0] gt = list(map(int, input().split())) g.extend(gt) pos = [[] for x in range(n + 1)] for i in range(m): u, v, d = map(int, input().split()) pos[u].append([i, d]) pos[v].append([i, d]) dp = [[]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
for _ in range(int(input())): n, m, k = map(int, input().split()) g = list(map(int, input().split())) g.insert(0, 0) lis = [] dp = [] for _ in range(n + 1): lis.append([]) dp.append([]) for i in range(m): u, v, d = map(int, input().split()) lis[u].append([i, d...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CAL...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
def printAns(k, dp): for i in range(k): print(dp[n][i][0], end=" ") print() def solve(n, m, k1, l, dp): dp[0].append((0, 0)) for i in range(1, n + 1): tmp = [] for j in dp[i - 1]: tmp.append(j) cr = 0 mk = 0 opn = set() for j in range...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
INF = 1e18 t = int(input()) for _ in range(t): all_ans = [] n, m, K = list(map(int, input().split())) g = [0] * (n + 1) temp = list(map(int, input().split())) for i in range(0, n): g[i + 1] = temp[i] intervals = [] arr = [[] for _ in range(n + 1)] dp = [[] for _ in range(n + 1)] ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VA...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
from sys import stdin input = stdin.readline def answer(): dp = [[] for i in range(n + 1)] dp[0].append(0) for i in range(1, n + 1): dp[i].extend(dp[i - 1]) for j in range(i, 0, -1): x = 0 for l in range(j, i + 1): for r in range(l, i + 1): ...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
def solve(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) av = [[] for j in range(n + 1)] res = [[] for j in range(n + 1)] for i in range(m): u, v, d = map(int, input().split()) av[u].append((i, d)) av[v].append((i, d)) res[0].append((0, 0)) ...
FUNC_DEF ASSIGN VAR 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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_C...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
t = int(input()) for i in range(t): n, m, k1 = map(int, input().split()) g = list(map(int, input().split())) g.insert(0, 0) arr = [[] for i in range(n + 1)] for i in range(m): u, v, d = map(int, input().split()) arr[u].append([i, d]) arr[v].append([i, d]) dp = [[] for i i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR V...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
def build_temp_cache(G, ind, Dscore, cache, prev_cache, curr_ind): temp_cache = [] for cache_element in cache: temp_cache.append(cache_element) simple_score = 0 mp = {} two_pw = 0 for j in range(curr_ind, 0, -1): simple_score += G[j] two_pw = two_pw ^ 2**j for l i...
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR ...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
for T in range(int(input())): n, m, k = map(int, input().split()) g = list(map(int, input().split())) value = [[(0) for i in range(n + 1)] for j in range(n + 1)] for i in range(m): x, y, val = map(int, input().split()) value[x][y] = val for i in range(n): value[i + 1][i + 1] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CA...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
def readInt(): return int(input()) def readInts(): return [int(x) for x in input().split()] def readString(): return input().rstrip() def readStrings(): return input().split() def print_list(l): print(" ".join(str(x) for x in l)) def readCase(): n, m, k = readInts() bit_scores = re...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL ...
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider $N$ binary variables $x_{1}, x_{2}, \ldots, x_{N}$. For each valid $i$, the $i$-th of these variables can be $x_{i} = 0$ or $x_{i} = 1$; therefore, there are $2^{N}$ possible assignments of values to the variables. ...
t = int(input()) for x in range(t): n, m, k = map(int, input().split()) l = list(map(int, input().split())) tri = [] tri.append(l) for i in range(1, n): tri.append([]) for j in range(n - i): tri[i].append(0) for i in range(m): u, v, d = map(int, input().split(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VA...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given $M$ triplets $(X_{1}, Y_{1}, B_{1}), (X_{2}, Y_{2}, B_{2}), \ldots, (X_{M}, Y_{M}, B_{M})$. Find the number of sequences of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ such that for each valid $i$,...
def getDisjoint(i, v): disjoint = set() q = {i} while len(q) > 0: pnt = q.pop() disjoint.add(pnt) for ppnt, _ in link[pnt]: if ppnt not in disjoint: q.add(ppnt) return disjoint def validate(i): for pnt, dic in link[i]: if v in tlink[pnt] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUM...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given $M$ triplets $(X_{1}, Y_{1}, B_{1}), (X_{2}, Y_{2}, B_{2}), \ldots, (X_{M}, Y_{M}, B_{M})$. Find the number of sequences of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ such that for each valid $i$,...
mod = 1000000007 def istrue(st, p, n, lis, lcm): if lcm[st][st][p] != -1 and lis[st] != lcm[st][st][p]: return 0 for j in range(1, n + 1): if j == st or lcm[st][j][p] == -1: continue if max(lis[st], lis[j]) != lcm[st][j][p]: return 0 return 1 def getans(st...
ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF F...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import combinations, permutations read = lambda: map(int, input().split()) n, m = read() cnt = 0 p1 = 0 x1 = 1 while x1 <= n - 1: x1 *= 7 p1 += 1 p2 = 0 x2 = 1 while x2 <= m - 1: x2 *= 7 p2 += 1 p1, p2 = max(p1, 1), max(p2, 1) Len = p1 + p2 for comb in combinations([0, 1, 2, 3, 4, 5, 6],...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CAL...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations base = 7 digits = [x for x in range(base)] def get_count(n): answer = 1 while n >= base: n = n // base answer += 1 return answer def is_good(tup, n): a = 0 for x in reversed(tup): a *= base a += x if a >= n: return F...
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR ...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations n, m = map(int, input().split()) p1 = 0 while 7**p1 < n: p1 += 1 p2 = 0 while 7**p2 < m: p2 += 1 cnt = 0 p1, p2 = max(p1, 1), max(p2, 1) for perm in permutations(list(range(0, 7)), p1 + p2): a = b = 0 for k in range(p1): a += perm[k] * 7**k for k in range(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER BI...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations as p def f(n, tn): if not n: tn.append(0) return 1 cnt = 0 while n: tn.append(n % 7) n //= 7 cnt += 1 return cnt ans = 0 tn, tm = [], [] n, m = map(int, input().split()) n -= 1 m -= 1 x, y = f(n, tn), f(m, tm) tn, tm = tuple(...
FUNC_DEF IF VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CA...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations n, m = map(int, input().split()) def l(x): r = x == 0 while x: r += 1 x //= 7 return r ans, ln, lm = 0, l(n - 1), l(m - 1) for s in permutations("0123456", ln + lm): s = "".join(s) ans += int(s[:ln], 7) < n and int(s[ln:], 7) < m print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR V...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
import itertools def tobase(n): if n == 0: return 1 l = 0 while n > 0: l += 1 n //= 7 return l def main(): n, m = map(int, input().split()) nlen = tobase(n - 1) mlen = tobase(m - 1) places = nlen + mlen ans = 0 for perm in itertools.permutations("01234...
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import * def f(x): x -= 1 ret = 0 if x == 0: ret = 1 else: while x != 0: ret += 1 x //= 7 return ret def g(d): ret = 0 for v in d: ret = ret * 7 + v return ret n, m = list(map(int, input().split())) a = f(n) b = f(m) if...
FUNC_DEF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations def findPow(num): ans = 1 num = num // 7 while num > 0: num //= 7 ans += 1 return ans a, b = [int(x) for x in input().split(" ")] x = findPow(a - 1) y = findPow(b - 1) ans = 0 if x + y > 7: ans = 0 else: for i in permutations("0123456", x + ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
def D(n): x, r = n - 1, 1 while x >= 7: x //= 7 r += 1 return r def H(n, l): x, r = n, "" if x == 0: r += "0" while x: r += chr(ord("0") + x % 7) x //= 7 r += "0" * (l - len(r)) return r a, b = list(map(int, input().split())) la = D(a) lb = D(b...
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR STRING IF VAR NUMBER VAR STRING WHILE VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUN...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
import itertools def baseN(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"): return ( num == 0 and numerals[0] or baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b] ) def main(): n, m = [int(x) for x in input().split()] n7, m7 = baseN(n - 1, 7), base...
IMPORT FUNC_DEF STRING RETURN VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP FUNC_CALL V...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations def osn(x): ans = [] x7 = "" while x >= 7: ans.append(x % 7) x = x // 7 ans.append(x) ans.reverse() for k in ans: x7 += str(k) return x7 def it(n, m): from itertools import permutations ans = 0 for k in permutations(...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN V...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations def C(l): for i in range(15): if 7**i > l: return max(i, 1) return -1 n, m = map(int, input().split()) n -= 1 m -= 1 n1, n2 = C(n), C(m) if n1 + n2 > 7: print(0) exit() ans = 0 for i in list(permutations(list(range(0, 7)), n1 + n2)): ans1, a...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER VAR VAR RETURN FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR ...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
def get_size(x): val = 7 size = 1 while True: if val - 1 >= x - 1: return size val *= 7 size += 1 def get_num(L): res = 0 for x in L: res = res * 7 + x return res n = None m = None n_size = None m_size = None vis = None record = None def dfs(floo...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FUNC...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
n, m = map(int, input().split()) def go(on1, val1, on2, val2, has): res = 0 if on1 > 0: for i in range(7): if i not in has: if val1 * 7 + i < n: res += go(on1 // 7, val1 * 7 + i, on2, val2, has + [i]) elif on2 > 0: for i in range(7): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR LIST VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations def str_base(number, base): if number < 0: return "-" + str_base(-number, base) d, m = divmod(number, base) if d > 0: return str_base(d, base) + str(m) return str(m) n, m = map(int, input().split()) max_h = str_base(n - 1, 7) max_m = str_base(m - 1,...
FUNC_DEF IF VAR NUMBER RETURN BIN_OP STRING FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_C...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
def sev(n): if n == 0: return 1 m = 0 while n > 0: n //= 7 m += 1 return m def fil(n, m, l, r): d = [] for i in range(r): d += [m % 7] m //= 7 for i in range(l): d += [n % 7] n //= 7 if len(set(d)) != l + r: return 0 r...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN NUMBE...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations def numberToBase(n): if n == 0: return [] return numberToBase(n // 7) + [n % 7] n, m = map(int, input().split()) x, y = numberToBase(n - 1), numberToBase(m - 1) nl, ml = max(1, len(x)), max(1, len(y)) r = 0 for p in permutations("0123456", nl + ml): a, b = "".j...
FUNC_DEF IF VAR NUMBER RETURN LIST RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
BASE = 7 class Solution(object): def __init__(self, m, n): self.max_hour = self.itov(n) self.max_min = self.itov(m) self.used = used = [False] * BASE def itov(self, x): digits = [] if x == 0: digits.append(0) while x > 0: digits.append(...
ASSIGN VAR NUMBER CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF NUMBER NUMBER NUMBER...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
def digits(n): l = [] if n == 0: l.append(0) else: while n > 0: l.append(n % 7) n = n // 7 l.reverse() return l l = input().split() n = int(l[0]) m = int(l[1]) numh = len(digits(n - 1)) numm = len(digits(m - 1)) ans = 0 if numh + numm > 7: ans = 0 el...
FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL ...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
n, m = [int(x) for x in input().split()] x = 7 d1 = 1 while x < n: d1 += 1 x *= 7 x = 7 d2 = 1 while x < m: d2 += 1 x *= 7 if d1 + d2 > 7: print(0) exit() c1 = {} L = [0] * d1 L[0] = -1 for sadas in range(n): L[0] += 1 for j in range(d1): if L[j] == 7: L[j] = 0 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
import itertools def is_valid(p, n): num = int("".join(map(str, p)), 7) return 0 <= num < n def get_sz(x): if x == 1: return 1 t = 1 ans = 0 while t < x: t *= 7 ans += 1 return ans n, m = map(int, input().split()) ans = 0 sz_left, sz_right = get_sz(n), get_sz(m)...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR F...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
import sys h, m = [int(x) for x in input().split()] def convert(dec, min_len): sev = [] if dec == 0: if min_len > 0: return [0] * min_len return [0] while dec: sev.append(int(dec % 7)) dec = int(dec / 7) ret = sev[::-1] if min_len > 0: return [0...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER IF VAR NUMBER RETURN BIN_OP LIST NUMBER VAR RETURN LIST NUMBER WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER RETURN BIN...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
n, m = map(int, input().split()) def GetDigitsNumberIn7System(number): result = 1 x = 7 while True: if number <= x - 1: return result else: result += 1 x *= 7 def fillZeros(s, razryadCount): for i in range(razryadCount - len(s)): s = "0" + ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR VAR NUMBER VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR E...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations as prm from sys import exit def to_base(n, base): ans = [] while n // base > 0: ans.append(n % base) n //= base ans.append(n % base) ans.reverse() return ans def le(l, n, m): prev_eq = True for i in range(len(n)): if l[i] == n[i]...
FUNC_DEF ASSIGN VAR LIST WHILE BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations n, m = map(int, input().split()) p1 = 1 while 7**p1 < n: p1 += 1 p2 = 1 while 7**p2 < m: p2 += 1 cnt = 0 for perm in permutations(list("0123456"), p1 + p2): a = int("".join(perm[:p1]), 7) b = int("".join(perm[p1 : p1 + p2]), 7) if a < n and b < m: cnt += 1...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR NUMBER ASSIGN VAR FUNC_...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations n, m = tuple(map(int, input().split())) def baseN(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"): return ( num == 0 and numerals[0] or baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b] ) def lt_eq(a, b): if len(a) =...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING RETURN VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VA...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations def dfs(x): r = x == 0 while x: r += 1 x //= 7 return r n, m = list(map(int, input().split())) res, ln, lm = 0, dfs(n - 1), dfs(m - 1) for i in permutations("0123456", ln + lm): i = "".join(i) res += int(i[:ln], 7) < n and int(i[ln:], 7) < m pri...
FUNC_DEF ASSIGN VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations def getdigits(x): if x == 0: return 1 digs = 0 while x != 0: x //= 7 digs += 1 return digs n, m = map(int, input().split()) a, b = getdigits(n - 1), getdigits(m - 1) c = a + b if c > 7: print(0) exit(0) combs = permutations(range(7),...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CAL...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
a, b = map(int, input().split()) def getdig(x): if x == 0: return 0, 1 s = "" c = 0 while x > 0: s = str(x % 7) + s c += 1 x //= 7 return int(s), c ass, an = getdig(a - 1) bss, bn = getdig(b - 1) tn = an + bn if tn > 7: print(0) exit() count = 0 sor = [str...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations as p def length_base_7(ele, arr): if not ele: arr.append(0) return 1 length = 0 while ele: arr.append(ele % 7) ele //= 7 length += 1 return length n, m = list(map(int, input().split())) n -= 1 m -= 1 n_base7, m_base7 = [], []...
FUNC_DEF IF VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL V...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
n, m = map(int, input().split()) d = [pow(7, i) for i in range(12)] ans = 0 nn, mm, kn, km = n - 1, m - 1, 0, 0 while nn: kn += 1 nn //= 7 while mm: km += 1 mm //= 7 kn += kn == 0 km += km == 0 nn, mm = [0] * kn, [0] * km def hm(r1, r2, s1, s2): global ans if s1 >= n: return if r1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BI...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations n, m = map(int, input().split()) def S(x): if x == 0: return 1 res = 0 while x > 0: x //= 7 res += 1 return res a, b = S(n - 1), S(m - 1) if a + b > 7: print(0) exit() D = list(range(7)) res = 0 for v in permutations(D, a): x = ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VA...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
n, m = input().split() n = int(n) m = int(m) def digitos(a): b = 7 r = 1 while b < a: b *= 7 r += 1 return r def valido(s): return int(s[:dn], 7) < n and int(s[dn:], 7) < m def solve(s): if len(s) == dn + dm: if valido(s): resp.append(s) for x in "01...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP VAR VAR IF F...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from itertools import permutations as P n, m = list(map(int, input().split())) a = n - 1 b = m - 1 x = 0 y = 0 c = 0 while a: x += 1 a = a // 7 if x == 0: x = 1 while b: y += 1 b = b // 7 if y == 0: y = 1 if x + y > 7 or x + y == 0: print(0) else: r = x + y l = list(P("0123456", r))...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VA...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
BASE = 7 def itov(x): digits = [] if x == 0: digits.append(0) while x > 0: digits.append(x % BASE) x //= BASE digits.reverse() return digits def gen(pos=0, minute=False, smaller=False): max_val = max_minute if minute else max_hour if pos >= len(max_val): i...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER RETURN FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUM...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
s = input() k = int(input()) n = len(s) if k == 0: print(1) return if k == 1: print(n - 1) return st = [0, 0] for i in range(2, 1000): c = 0 for j in range(10): if 1 << j & i: c += 1 st.append(st[c] + 1) nums = [i for i in range(len(st)) if st[i] == k - 1 and i <= n] if l...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
mas = [[] for i in range(1001)] mas[0].append(1) mas[0].append(1) for i in range(1, 1000): mas[i].append(1) for j in range(1, i): mas[i].append((mas[i - 1][j] + mas[i - 1][j - 1]) % (10**9 + 7)) mas[i].append(1) def c(k, n): if k > n: return 0 if k < 0: return 0 global ...
ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
s0 = input() k = int(input()) s1 = s0[::-1] lens1 = len(s1) maxnum = 1005 mod = 1000000007 dp = [([0] * maxnum) for tmpi in range(maxnum)] f = [0] * maxnum c = [([0] * maxnum) for tmpi in range(maxnum)] def cntone(num): tmps = bin(num)[2:] cnt = 0 for i in range(len(tmps)): if tmps[i] == "1": ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUN...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
R = lambda: map(int, input().split()) mod = 10**9 + 7 maxn = 1001 c = [[(0) for j in range(maxn)] for i in range(maxn)] for i in range(maxn): c[i][0] = 1 for i in range(1, maxn): for j in range(i + 1): c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod arr = list(map(int, input())) k = int(input()) if k ==...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VA...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
def count_oper(x): if x == 1: return 0 res = 0 y = x while y > 0: if y % 2 == 1: res += 1 y = y // 2 return count_oper(res) + 1 def solve(s, k): a = [] ones = [] for i in range(len(s)): c = s[i] a.append(int(c == "1")) if c ==...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CA...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
MX = 1030 M = 1000 * 1000 * 1000 + 7 c = [([0] * MX) for i in range(MX)] for i in range(MX): c[i][0] = 1 for i in range(1, MX): for j in range(1, MX): c[i][j] = c[i - 1][j] + c[i - 1][j - 1] c[i][j] %= M num = list(map(int, list(input()))) cnt = int(input()) dp = [0] * MX for i in range(2, MX): ...
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VA...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
from sys import setrecursionlimit def main(): s, k = input(), int(input()) n = len(s) if k < 2: print((1, n - 1)[k]) return tais = [(n - i - 1) for i, c in enumerate(s) if c == "1"] tlen, cache, res = len(tais), {(0, 0): 1}, 0 def c(n, m): if n < m * 2: m =...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR DICT NUMBER NUMBER NUMBER NUMBER FUNC_DEF ...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
class Combi: def __init__(self, N, mod=10**9 + 7): self.power = [(1) for _ in range(N + 1)] self.rev = [(1) for _ in range(N + 1)] self.mod = mod for i in range(2, N + 1): self.power[i] = self.power[i - 1] * i % self.mod self.rev[N] = pow(self.power[N], self.mod ...
CLASS_DEF FUNC_DEF BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ...
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1...
def reduce(n): n = bin(n)[2:] n = list(n) n = list(map(int, n)) return sum(n) def a(n, bits, dp): if bits == 0: return 1 if n == "0" or n == "": return 0 if bits > len(n): return 0 if bits == len(n): if n == "1" * len(n): return 1 els...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR STRING VAR STRING RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR VAR IF VAR BIN_OP STRING FUNC_CALL VAR...