description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999. A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example...
n = int(input()) mod = 998244353 pow = [0, 10] pre = [0, 10] for i in range(n - 1): pre += [(pre[-1] + pow[-1] * 10) % mod] pow += [pow[-1] * 10 % mod] ans = [10] preans = [10] for i in range(2, n + 1): x = pow[i] * i - preans[-1] - ans[-1] - (pow[i - 1] * (i - 1) - ans[-1]) if x < 0: x += 99824...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR F...
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999. A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example...
def force(n): res = [0] * n for i in range(int(10**n)): s = str(i).zfill(n) it = iter(s) last = next(it) c = 1 for j in it: if j == last: c += 1 else: res[c - 1] += 1 c = 1 last = j ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_...
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999. A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example...
n = int(input()) m = 998244353 a = [] a.append(1) for i in range(1, 200001): a.append(10 * a[i - 1] % m) for i in range(1, n): x = int(2 * 9 * a[n - i - 1] * 10) + (n - i - 1) * 81 * a[n - i - 2] * 10 print(x % m, end=" ") print(10)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR BIN_OP BIN_OP V...
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999. A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example...
from sys import stdin input = stdin.readline n = int(input()) dp = [0, 10, 180] s = 190 for x in range(3, n + 1): dp.append( (x * pow(10, x, 998244353) - (x - 1) * pow(10, x - 1, 998244353) - s) % 998244353 ) s += dp[-1] for x in dp[n:0:-1]: print(x, end=" ")
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER...
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999. A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example...
import sys input = sys.stdin.readline mod = 998244353 n = int(input()) f = [(0) for i in range(n + 1)] d = [] for i in range(n): if i == 0: d.append(10) elif i == 1: d.append(180) else: c = (180 + 81 * (i - 1)) * pow(10, i - 1, mod) % mod d.append(c) print(*d[::-1])
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR N...
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999. A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right. For example...
import sys def main(): import sys input = sys.stdin.readline n = int(input()) mod = 998244353 l = [1] ans = [] for i in range(2 * 10**5): l.append(l[-1] * 10 % mod) for i in range(1, n): ans.append( (10 * 9 * l[n - i - 1] * 2 + 10 * 81 * l[n - i - 2] * (n -...
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP B...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def min_cost(self, nums, i, k, n, dp): if i == n: return 0 if dp[i] != -1: return dp[i] mn = float("inf") sum_ = 0 for j in range(i, n): if sum_ + nums[j] + (j - i) > k: break if j == n - 1: ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [0] * n ans = [0] * n dp[n - 1] = 0 ans[n - 1] = n - 1 for i in range(n - 2, -1, -1): dp[i] = float("Inf") curLen = -1 for j in range(i, n): curLe...
CLASS_DEF FUNC_DEF 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 NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): def solve(i, rem): if i == n: return 0 if dp[i][rem] != -1: return dp[i][rem] if nums[i] > rem: ans = (rem + 1) * (rem + 1) + solve(i + 1, k - nums[i] - 1) else...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [([-1] * (k + 1)) for i in range(n)] def rec(i, rem): if i == n: return 0 if dp[i][rem] != -1: return dp[i][rem] ans = 0 if nums[i] > rem: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_O...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
import sys INT_MAX = sys.maxsize class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [-1] * n dp[n - 1] = 0 for i in range(n - 2, -1, -1): dp[i] = INT_MAX curr_len = -1 for j in range(i, n): curr_len += 1 + nums...
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF V...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [0] * n sum = 0 for ind in range(n - 1, -2, -1): if sum > 0: sum += 1 if ind >= 0: sum += nums[ind] if sum > k: break ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VA...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, arr, k): n = len(arr) def recursion(i, rem): if i == n: return 0 if dp[i][rem] != -1: return dp[i][rem] if arr[i] > rem: notPick = (rem + 1) * (rem + 1) + recursion(i + 1, k ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP V...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
import sys sys.setrecursionlimit(10**7) class Solution: def solveWordWrap(self, arr, k): def solve(i, rem): if i == n: return 0 if dp[i][rem] != -1: return dp[i][rem] ans = sys.maxsize if arr[i] > rem - 1: a...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_O...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [([-1] * (k + 1)) for i in range(n)] def findmincost(i, remk, k, n): if i == n - 1: if remk + 1 + nums[i] <= k: dp[i][remk] = 0 return 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [-1] * n def dfs(i): if dp[i] != -1: return dp[i] mn = float("inf") Sum = 0 for idx in range(i, n): Sum += nums[idx] if Sum <...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): dp = [(-1) for i in range(len(nums) + 1)] def sol(arr, i, n, k): if i >= n - 1: return 0 if dp[i] != -1: return dp[i] res = float("inf") s = 0 for j in rang...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR BIN_O...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): dp = {} def dfs(i, limit): if i >= len(nums): return 0 if (i, limit) in dp: return dp[i, limit] if nums[i] <= limit: take = dfs(i + 1, limit - nums[i] - 1) ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMB...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [([-1] * (k + 1)) for _ in range(n + 1)] def recurse(index, cur_limit): if index == n: return 0 if dp[index][cur_limit] != -1: return dp[index][cur_limit] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
import sys sys.setrecursionlimit(10**7) class Solution: def solveWordWrap(self, arr, k): n = len(arr) def solve(i, rem): if i == n: return 0 if dp[i][rem] != -1: return dp[i][rem] if nums[i] > rem: ans = (rem + ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VA...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
def solver(arr, m, n, i, dct, k): if i == n: return 0 if (i, k) in dct: return dct[i, k] cost = float("INF") if k < arr[i]: cost = k**2 + solver(arr, m, n, i + 1, dct, m - arr[i]) elif k > arr[i]: if k < m: cost = k**2 + solver(arr, m, n, i + 1, dct, m - a...
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUM...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): A = nums n = len(A) dp = [float("inf")] * n dp[-1] = 0 for i in range(n - 2, -1, -1): length = -1 for j in range(i, n): length += A[j] + 1 if length <= k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER AS...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): dp = {} def rec(i, rem, nums, k): if i == len(nums): return 0 if (i, rem) in dp: return dp[i, rem] if nums[i] > rem: ans = (rem + 1) * (rem + 1) + rec(i + 1, k - nu...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR ...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [0] * n ans = [0] * n for i in range(n - 1, -1, -1): currlen = -1 for j in range(i, n): currlen += nums[j] + 1 if currlen > k: break ...
CLASS_DEF FUNC_DEF 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 BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solve(self, i, n, nums, k, dp): if i == n - 1: dp[i] = 0 return 0 if dp[i] != -1: return dp[i] ans = 10**8 count = 0 word = 0 for j in range(i, n): count += nums[j] word += 1 ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CA...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, nums, k): n = len(nums) hmap = {} def solve(ind, curr, nums, k, n): if ind == n: return 0 if (ind, curr) not in hmap: pick = 1000000000.0 if nums[ind] <= curr: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: h = dict() def solve(self, csum, i, k): if i in self.h: return self.h[i] ans = float("inf") for j in range(i, n): a = csum[j] - (csum[i - 1] if i - 1 >= 0 else 0) l = j - i if a + l > k: break an...
CLASS_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
import sys class Solution: def solveWordWrap(self, nums, k): n = len(nums) dp = [0] * n ans = [0] * n dp[n - 1] = 0 ans[n - 1] = n - 1 for i in range(n - 2, -1, -1): currlen = -1 dp[i] = sys.maxsize for j in range(i, n): ...
IMPORT CLASS_DEF FUNC_DEF 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 NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR V...
Given an array nums[] of size n, where nums[i] denotes the number of characters in one word. Let K be the limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line...
class Solution: def solveWordWrap(self, words, k): dp = {} def rec(i, remLength): if i >= len(words): dp[i, remLength] = 0 return 0 if (i, remLength) in dp: return dp[i, remLength] if remLength == k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER AS...
Given an sequence from 1 to N and also given an array arr[] of size N. Basically the array is the permutation of 1 to N which determinds that the element from i^{th} position should move to the j^{th} position. Now the task is to find the minimum number of operations such that each array element is present at its origi...
class Solution: def rearrangeArray(self, n, arr): maxNumber = pow(10, 9) + 7 ansValues = set() for i in range(n): arr[i] -= 1 def computeGCD(x, y): while y: x, y = y, x % y return abs(x) def findWindows(): win...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR...
Given an sequence from 1 to N and also given an array arr[] of size N. Basically the array is the permutation of 1 to N which determinds that the element from i^{th} position should move to the j^{th} position. Now the task is to find the minimum number of operations such that each array element is present at its origi...
class Solution: def rearrangeArray(self, n, arr): maxNumber = pow(10, 9) + 7 ansValues = set() for i in range(n): arr[i] -= 1 def computeGCD(x, y): while y: x, y = y, x % y return abs(x) ans = 1 for i in range(n):...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN...
Given an sequence from 1 to N and also given an array arr[] of size N. Basically the array is the permutation of 1 to N which determinds that the element from i^{th} position should move to the j^{th} position. Now the task is to find the minimum number of operations such that each array element is present at its origi...
class Solution: def rearrangeArray(self, n, arr): maxNumber = pow(10, 9) + 7 ansValues = set() for i in range(n): arr[i] -= 1 def computeGCD(x, y): while y: x, y = y, x % y return abs(x) def findWindows(): win...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR...
Given an sequence from 1 to N and also given an array arr[] of size N. Basically the array is the permutation of 1 to N which determinds that the element from i^{th} position should move to the j^{th} position. Now the task is to find the minimum number of operations such that each array element is present at its origi...
class Solution: def rearrangeArray(self, n, arr): visited = [(False) for i in range(n)] cycles = set() for x in arr: if visited[x - 1] == False: start = x curr = x cycle_len = 0 while True: visit...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR N...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
n = int(input()) dp = [[None for j in range(n)] for i in range(n)] cl = input().split(" ") cl = [int(color) for color in cl] for bias in range(0, n): for l in range(n - bias): r = l + bias loc = float("+inf") if bias == 0: dp[l][r] = 1 elif bias == 1: if cl[l]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
n = int(input()) t = tuple(map(int, input().split())) m = [([1] * n) for i in range(n + 1)] for d in range(2, n + 1): for i in range(n - d + 1): m[d][i] = min(m[x][i] + m[d - x][i + x] for x in range(1, d)) if t[i] == t[i + d - 1]: m[d][i] = min(m[d][i], m[d - 2][i + 1]) print(m[n][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 VAR FUNC_CALL VAR BIN_OP 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 VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VA...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
n = int(input()) seg = n - 1 gemstones = [0] * 501 i = 0 for j in input().split(" "): gemstones[i] = int(j) i += 1 matriz = [([0] * 501) for i in range(501)] for k in range(1, n + 1): ini = 0 fim = k - 1 while fim < n: if k == 1: matriz[ini][fim] = 1 else: mat...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIG...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
INF = int(1000000000.0) n = int(input()) s = list(map(int, input().split())) dp = [[INF for j in range(n)] for i in range(n)] for len in range(n): for i in range(n): j = i + len if j >= n: continue dp[i][j] = min(dp[i][j], 1 + (dp[i + 1][j] if i + 1 <= j else 0)) for k in...
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR V...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
dp = [] def calculate(i, j, colors): if i > j: return 0 if dp[i][j] == -1: if i == j: return 1 dp[i][j] = 10000 dp[i][j] = min(dp[i][j], 1 + calculate(i + 1, j, colors)) if colors[i] == colors[i + 1]: dp[i][j] = min(dp[i][j], 1 + calculate(i + 2,...
ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_C...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
n = int(input()) c = [*map(int, input().split())] inf = n + 1 dp = [[inf for _ in range(n)] for __ in range(n)] def find(l, r): if l > r: return 0 if l == r or l == r - 1 and c[l] == c[r]: dp[l][r] = 1 return 1 if dp[l][r] != inf: return dp[l][r] m = 1 + find(l + 1, 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 VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR V...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
def main(): n, l = int(input()), list(map(int, input().split())) dp = [([0] * n) for _ in range(n + 1)] for le in range(1, n + 1): for lo, hi in zip(range(n), range(le - 1, n)): row, c = dp[lo], l[lo] if le == 1: row[hi] = 1 else: t...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
def main(): n, l = int(input()), list(map(int, input().split())) dp = [([0] * n) for _ in range(n)] for i in range(n): dp[i][i] = 1 for i in range(n - 1, 0, -1): ci, row = l[i - 1], dp[i] for j in range(i, n): tmp = [1 + row[j]] if ci == l[i]: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR V...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
from sys import stdin, stdout for _ in range(1): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) dp = [[(0) for _ in range(n)] for _ in range(n)] for sz in range(n): for i in range(n - sz): j = i + sz if sz == 0: dp[i][j] = 1 ...
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR N...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
dp = [[(-1) for i in range(505)] for j in range(505)] n = int(input()) A = [int(i) for i in input().split()] def do(i, j): if i >= j: dp[i][j] = 1 return 1 if dp[i][j] != -1: return dp[i][j] ans = len(A) if A[i] == A[j]: ans = min(ans, do(i + 1, j - 1)) for x in ran...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN ...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
from sys import stdin n = int(input()) s = list(map(int, stdin.readline().strip().split())) dp = [[(-1) for i in range(501)] for j in range(500)] def sol(i, j): if i > j: return 0 if i == j: return 1 if dp[i][j] != -1: return dp[i][j] x = 502 if s[i] == s[i + 1]: x...
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 NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN...
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ...
n = int(input()) C = list(map(int, input().split())) dp = [([0] * n) for _ in range(n)] for i in range(n): dp[i][i] = 1 for i in range(n - 2, -1, -1): for j in range(i + 1, n): dp[i][j] = 1 + dp[i + 1][j] if C[i] == C[i + 1]: dp[i][j] = min(dp[i][j], 1 + (dp[i + 2][j] if i + 2 < n el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN V...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
limit = 100005 ans = [[(0) for i in range(0, limit)] for j in range(0, 6)] def solve(): primeFactors = [0] * limit for i in range(2, limit): if primeFactors[i] == 0: for j in range(i, limit, i): primeFactors[j] += 1 for i in range(limit): if primeFactors[i] < 6:...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
prime = [True] * 100001 count = [(0) for i in range(100001)] p = 2 while p < 100001: if prime[p] == True: count[p] += 1 for i in range(p + p, 100001, p): prime[i] = False count[i] += 1 p += 1 k = [([0] * 100001) for i in range(6)] for i in range(2, 100001, 1): if coun...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_C...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
t = int(input()) n = 100000 prime = [(0) for i in range(n + 1)] p = 2 while p <= n: if not prime[p]: for j in range(p, n + 1, p): prime[j] += 1 p += 1 cache = [[(0) for i in range(n + 1)] for j in range(5)] for i in range(1, 6): for j in range(2, n + 1): if prime[j] == i: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
val = 10**5 ans = [0] * (val + 1) for i in range(2, val + 1): if ans[i] == 0: for j in range(i, val + 1, i): ans[j] += 1 k = [[(0) for _ in range(val + 1)] for _ in range(5)] for i in range(2, val + 1): if ans[i] <= 5: k[ans[i] - 1][i] = 1 f = [] for i in range(5): temp = [0] ...
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
def sieve(N): marked = [(0) for i in range(N + 1)] isPrime = [(True) for i in range(N + 1)] for i in range(2, N + 1): if isPrime[i]: marked[i] = 1 j = 2 while i * j <= N: isPrime[i * j] = False marked[i * j] += 1 j +...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
test = int(input()) t1 = [0] t2 = [0] t3 = [0] t4 = [0] t5 = [0] n = 100000 l = n + 1 prime = [(0) for i in range(0, l)] for p in range(2, n): if prime[p] == 0: for i in range(p, l, p): prime[i] += 1 for i in range(1, 100001): s = prime[i] if s == 1: t1.append(t1[i - 1] + 1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
def sieve(n): factors = [(0) for _ in range(n + 1)] for i in range(2, n + 1): if not factors[i]: for j in range(2 * i, n + 1, i): factors[j] += 1 factors[i] = 1 return factors factors = sieve(100005) lookup = [[(0) for _ in range(100005)] for _ in range(6)] ...
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 VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL ...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
def primes(top): a = [0] * (top + 1) for i in range(2, top + 1): if a[i] == 0: for j in range(i, top + 1, i): a[j] += 1 return a def get_counts(a, k): c = 0 counts = [0] * len(a) for i in range(len(a)): if a[i] == k: c += 1 counts...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VA...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
n = 10**5 + 1 prime = [0] * n for i in range(2, n): if prime[i] == 0: for j in range(i, n, i): prime[j] += 1 k_prime = {} for i in range(1, 6): k_prime[i] = [0] * n for j in range(2, n): if prime[j] == i: k_prime[i][j] += 1 k_prime[i][j] += k_prime[i][j - 1] f...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VA...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
size = 100000 sieve = [i for i in range(size + 1)] counts = [0] * (size + 1) for i in range(2, size + 1): if sieve[i] == i: counts[i] = 1 j = i * 2 while j < size + 1: sieve[j] = i counts[j] += 1 j += i dp = [] mem = {} for count in counts: if count in...
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR LIST ASSI...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
P = input J = int E = len D = range B = [None] * 100001 L = [] for A in D(2, E(B)): B[A] = set() for A in D(2, 100001): if E(B[A]) != 0: continue L.append(A) B[A].add(A) for F in D(2, E(B)): G = F * A if G > 100000: break else: while G <= 10000...
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CA...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
sieve, cnt, d = [1] * 100001, [0] * 100001, [[0, 0] for _ in range(6)] sieve[0] = sieve[1] = 0 for i in range(2, 100001): if sieve[i]: cnt[i] += 1 for j in range(i * 2, 100001, i): sieve[j], cnt[j] = 0, cnt[j] + 1 for i in range(1, 6): for j in range(2, 100001): d[i].append(d...
ASSIGN VAR VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER FOR ...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
LIMIT = 100001 prime = [True] * LIMIT count = [0] * LIMIT for i in range(2, LIMIT): if prime[i]: for j in range(i, LIMIT, i): prime[j] = False count[j] += 1 mat = [([0] * LIMIT) for i in range(6)] for i in range(2, LIMIT): for j in range(1, 6): mat[j][i] = mat[j][i - 1] ...
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBE...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
limit = 100001 prime = [(True) for _ in range(limit)] mark = [(0) for _ in range(limit)] for i in range(2, limit): if prime[i]: mark[i] = 1 j: int = 2 while i * j < limit: prime[i * j] = False mark[i * j] += 1 j += 1 table = [[(0) for _ in range(limit)] fo...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FU...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
lim = 100001 def rmain(): dp = [0] * lim ans = [[(0) for _ in range(100001)] for _ in range(6)] for i in range(2, lim): if dp[i] == 0: dp[i] = 1 for j in range(2 * i, lim, i): dp[j] += 1 for i, val in enumerate(dp): for j in range(1, 6): ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUM...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
lim = 100001 dp = [0] * lim for i in range(2, lim): if dp[i] == 0: dp[i] = 1 for j in range(2 * i, lim, i): dp[j] += 1 ans = [([0] * lim) for i in range(6)] for i in range(lim): if dp[i] <= 5: ans[dp[i]][i] += 1 for i in range(6): for j in range(1, lim): ans[i][j]...
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VA...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
max = 10**5 + 1 prime = [(1) for i in range(max)] prime[0], prime[1] = 0, 0 marked = [(0) for i in range(max)] for i in range(2, max): if prime[i]: marked[i] = 1 for j in range(i * 2, max, i): prime[j] = 0 marked[j] += 1 count = [] for k in range(1, 6): temp = [0] * max ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
limit = 10**5 + 1 dp = [(0) for i in range(limit)] for i in range(2, limit): if dp[i] != 0: continue for j in range(i, limit, i): dp[j] += 1 ans = [[(0) for i in range(limit)] for j in range(6)] for i in range(2, limit): if dp[i] <= 5: ans[dp[i]][i] = 1 for i in range(1, 6): for ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
arr = [[i] for i in range(10**5 + 1)] dictionary = {(1): 0, (2): 0, (3): 0, (4): 0, (5): 0} prime_factors_arr = [([0] * 6) for i in range(10**5 + 1)] for i in range(2, 10**5 + 1): pos = i if len(arr[i]) == 1: while pos <= 10**5: arr[pos].append(i) pos += i if len(arr[i]) - 1 ...
ASSIGN VAR LIST VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN ...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
n = 100000 primefactor = [(0) for i in range(n + 1)] i = 2 lst = [] while i <= n: if primefactor[i] == 0: primefactor[i] = i for j in range(i * i, n + 1, i): primefactor[j] = i i += 1 for i in range(2, n + 1): x = i m = {} while x != 1: if primefactor[x] in m: ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR D...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
def PrimeFactorCountSieve(n): pfc = [0] * (n + 1) for i in range(2, n + 1): if pfc[i] == 0: for j in range(i, n + 1, i): pfc[j] += 1 return pfc def CumulativeKPrimeFactorCount(pfc): ckpfc = [[(0) for _ in range(6)] for __ in range(len(pfc))] for a in range(2, le...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CA...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
dp = [0] * 100001 ans = [([0] * 100001) for i in range(6)] for i in range(2, 100001): if dp[i] == 0: for x in range(i, 100001, i): dp[x] += 1 for i in range(1, 6): for j in range(100001): if dp[j] == i: ans[i][j] = 1 for i in range(1, 6): for j in range(1, 100001): ...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR F...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
lim = 10**5 + 1 dp = [0] * lim for i in range(2, lim): if dp[i] == 0: for j in range(i, lim, i): dp[j] += 1 nk = [["X"]] for k in range(1, 5 + 1): l = [0] * lim for j in range(lim): if dp[j] == k: l[j] = l[j - 1] + 1 else: l[j] = l[j - 1] nk.ap...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST LIST STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
n = 10**5 + 2 def Sieve(n): prime, p = [(0) for i in range(n)], 2 for i in range(2, n): if prime[i] == 0: for j in range(p, n, p): prime[j] += 1 p += 1 return prime def array(): a, q, l = [(True) for i in range(6)], [], Sieve(n) for i in range(n): ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER LIST FUNC_CALL VAR VAR FOR VAR F...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
M = 6 U = 100001 dp = [[0] * M] for x in range(1, U): dp += [[0] * M] for y in range(M): dp[x][y] = dp[x - 1][y] p = 2 q = x y = 0 while p * p <= q and y < M: if q % p == 0: q /= p y += 1 while q % p == 0: q /= p p += 1 ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR LIST BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
factors = [(0) for i in range(100001)] p = 2 while p < 100001: if factors[p] == 0: for j in range(p, 100001, p): factors[j] += 1 p += 1 dp = [[(0) for b in range(100001)] for b in range(6)] for i in range(1, 6): for j in range(2, 100001): if factors[j] == i: dp[i][j] ...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
def getCount_1(start, end, dp): for i in range(2, end + 1): if dp[i] == 0: for value in range(i, end + 1, i): dp[value] += 1 return dp testCases = int(input()) result = [] dp = [] for index in range(0, 100001): dp.append(0) dp = getCount_1(2, 100000, dp) precomputeArray...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
def kprime(a): for i in range(2, 100005): if a[i][0] == 0: a[i][0] = 1 for j in range(i + i, 100005, i): a[j][0] += 1 if a[i][0] <= 5: a[i][a[i][0]] = 1 for j in range(1, 6): a[i][j] += a[i - 1][j] def solve(): A = [[(0) f...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
t = int(input()) n = 100000 marked = [0] * (n + 1) primes = [True] * (n + 1) for i in range(2, n + 1): if primes[i]: marked[i] = 1 for j in range(2 * i, n + 1, i): marked[j] += 1 primes[j] = False table = [([0] * (n + 1)) for i in range(6)] for i in range(2, n + 1): for j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
dp = [[(0) for row in range(6)] for col in range(100001)] def sieve(): for i in range(2, 100001): if dp[i][0] == 0: dp[i][0] = 1 for j in range(2 * i, 100001, i): dp[j][0] += 1 if dp[i][0] <= 5: dp[i][dp[i][0]] = 1 for j in range(1, 6): ...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL ...
Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime i...
M = 5 + 1 limit = 10**5 + 1 primes = [(0) for i in range(limit)] for x in range(2, limit): if primes[x] == 0: for y in range(x, limit, x): primes[y] += 1 dp = [[(0) for k in range(M)] for x in range(limit)] for x in range(2, limit): for y in range(1, M): dp[x][y] = dp[x - 1][y] y...
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for _ in range(int(input())): n = int(input()) L = list(map(int, input().split(" "))) inc = [1] * n dec = [1] * n for i in range(n - 2, -1, -1): if L[i] > L[i + 1]: dec[i] = dec[i + 1] + 1 else: inc[i] = inc[i + 1] + 1 res = 0 for i in range(n): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER AS...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) wl = n a = l op = 1 i = 0 for j in range(i + 1, n): if a[j - 1] < a[j]: wl += j - i op = 0 elif -1 * a[j - 1] < a[j] and op == 1: a[j - 1] = a[j - 1] * -1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR AS...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for _ in range(int(input())): n = int(input()) p = list(map(int, input().split())) v = [] v.append(1) for i in range(1, n - 1): if p[i] > p[i - 1] and p[i] > p[i + 1]: v.append(i + 1) v.append(n) ans = 0 c = 0 for i in range(1, len(v)): c = v[i] - v[i - 1]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CA...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for _ in range(int(input())): n = int(input()) p = list(map(int, input().split())) l = [1] * n r = [1] * n for i in range(1, n): if p[i] <= p[i - 1]: l[i] += l[i - 1] for i in range(n - 2, -1, -1): if p[i] < p[i + 1]: r[i] += r[i + 1] ans = 0 for i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
def weirdArr(n, p): left = [1] * n right = [1] * n for i in range(1, n): if p[i] < p[i - 1]: left[i] += left[i - 1] if p[n - i - 1] < p[n - i]: right[n - i - 1] += right[n - i] ans = 0 for i in range(n): ans += left[i] * right[i] return ans t = i...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for T in range(int(input())): n = int(input()) l = list(map(int, input().split())) dec = [0] * n inc = [0] * n dec[n - 1] = n - 1 inc[n - 1] = n - 1 for i in range(n - 2, -1, -1): if l[i] > l[i + 1]: dec[i] = dec[i + 1] inc[i] = i else: inc...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FO...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
ans = [] nq = int(input()) for _ in range(nq): n = int(input()) A = list(map(int, input().split())) i = 0 sol = [] val = 0 for j in range(1, n - 1): if A[j] > A[j - 1] and A[j] > A[j + 1]: val += (j - i + 1) * (j - i + 2) // 2 val += -1 i = j val +...
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER V...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
def soln(n, arr): left = [1] for i in range(1, n): if arr[i - 1] > arr[i]: left.append(left[-1] + 1) else: left.append(1) right = [1] * n for i in range(n - 2, -1, -1): if arr[i + 1] > arr[i]: right[i] = 1 + right[i + 1] res = 0 for i i...
FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VA...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) in1 = [1] dc1 = [1] j = 0 for i in range(n - 2, -1, -1): if l[i] < l[i + 1]: in1.append(in1[j] + 1) else: in1.append(1) j += 1 j = 0 for i in range(n -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBE...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
def sum(n): if n > 2: return (n - 2) * (n - 1) / 2 return 0 a = int(input()) for i in range(a): b = int(input()) array = list(map(int, input().split())) count = b + b - 1 ini = 0 f = 1 while f < len(array) - 1: if array[f + 1] < array[f] > array[f - 1]: coun...
FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 BIN_OP VAR VAR NUMBER ASSIGN V...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for _ in range(int(input())): n = int(input()) li = list(map(int, input().split())) liDiff = [] last = 0 count = 0 for i in li: if i >= last: count += 1 else: liDiff.append(count) count = 1 last = i liDiff.append(count) liNew = ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
import sys from itertools import islice for s in islice(sys.stdin, 2, None, 2): a = [*map(int, s.split())] m = 0 r = len(a) * 2 - 1 for x, y, z in zip(a, a[1:], a[2:]): if x < y > z: m = 0 else: m += 1 r += m print(r)
IMPORT FOR VAR FUNC_CALL VAR VAR NUMBER NONE NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for _ in range(int(input())): n = int(input()) lis = list(map(int, input().split())) ans = 1 i = 0 j = 1 las = None while j < n: if las == None: if lis[j] > lis[j - 1]: las = "inc" ans += 2 else: las = "dec" ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE VAR VAR IF VAR NONE IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING VAR NUMBER ASSIGN...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for t in range(int(input())): N = int(input()) P = list(map(int, input().split())) hill, h = [], [] C = 0 for i in range(1, N - 1): if P[i - 1] < P[i] and P[i] > P[i + 1]: hill.append(i) h.append(0) h.extend(hill) h.append(N - 1) for i in range(len(h) - 1): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_C...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) s = 0 ans = n + 0 f = 0 for i in range(1, n): if f == 2: if a[i] < a[i - 1]: f = i - s ans += f * (f + 1) // 2 - f s = i - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSI...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) ans = 0 inc = [0] * n desc = [0] * n inc[n - 1] = desc[n - 1] = 1 for i in reversed(range(n - 1)): if a[i] < a[i + 1]: inc[i] = inc[i + 1] + 1 else: inc[i] = 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR V...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
def solve(n, arr): if n == 1: return 1 tmp = [] lst = [] res = 0 for i in range(1, n): tmp.append(arr[i] < arr[i - 1]) lst.append([tmp[0], 1]) for i in range(1, len(tmp)): if tmp[i] == lst[len(lst) - 1][0]: lst[len(lst) - 1][1] += 1 else: ...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
def calculate(arr, n): inc = [(1) for i in range(n)] dec = [(1) for i in range(n)] for i in range(n - 2, -1, -1): if arr[i] < arr[i + 1]: inc[i] = inc[i + 1] + 1 else: dec[i] = dec[i + 1] + 1 count = 1 for i in range(n): if inc[i] > 1: coun...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VA...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
t = int(input()) for _ in range(t): tot = 0 n = int(input()) l, r = [1] * n, [1] * n arr = list(map(int, input().split())) for i in range(1, n): if arr[i] < arr[i - 1]: l[i] += l[i - 1] if arr[n - i - 1] < arr[n - i]: r[n - i - 1] += r[n - i] print(sum(l[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR ...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
import sys from itertools import islice for s in islice(sys.stdin, 2, None, 2): a = (*map(int, s.split()),) s = "".join("* "[x < y > z] for x, y, z in zip(a, a[1:], a[2:])) print(2 * len(a) - 1 + sum(l * (l + 1) // 2 for l in map(len, s.split())))
IMPORT FOR VAR FUNC_CALL VAR VAR NUMBER NONE NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING STRING VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMB...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
from sys import stdin input = stdin.readline def solve(N, P): count = 0 hills = [i for i in range(1, N - 1) if P[i - 1] < P[i] > P[i + 1]] hills = [0] + hills + [N - 1] for left, right in zip(hills, hills[1:]): size = right - left + 1 count += size * (size - 1) // 2 return count +...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR B...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
for i in range(int(input())): n = int(input()) array = list(map(int, input().split())) k = 1 ans = 1 array[0] = min(-array[0], array[0]) for j in range(n - 1): if max(array[j + 1], -array[j + 1]) > array[j]: k += 1 if -array[j + 1] > array[j]: arra...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NU...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
def soln(n, arr): streak = 1 res = 0 i = 0 while i < n - 1: if arr[i] < arr[i + 1]: i += 1 streak += 1 else: arr[i] = -arr[i] if i > 0 and arr[i - 1] > 0: if res != 0: res -= 1 res += stre...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR ...
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times: Select any index i (1 ≤ i ≤ |A|) and set A_{i} := -A_{i}. For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted. JJ has a perm...
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) ans = 0 c = 0 prev = 1 curr = 1 for i in range(n - 1): if arr[i] <= arr[i + 1]: prev = curr curr = 1 c += 1 else: prev = curr ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSI...