description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
ans = set()
def f(ip, op=[]):
if ip < 0:
return
if ip == 0:
ans.add(tuple(sorted(op[:], reverse=True)))
return
for d in range(ip, 0, -1):
if len(op) ==... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF LIST IF VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def memoed(self, n, memo):
if n == 0:
return []
if n == 1:
return [[1]]
if n in memo:
return memo[n]
res = [[n]]
for i in range(n, 0, -1):
for j in self.memoed(n - i, memo):
if i >= j[0]:
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST LIST NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF RETUR... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
output = [[0]]
for i in range(n, 0, -1):
temp = []
for item in output:
j = 1
temp2 = []
while item[0] + j * i <= n:
temp2.append(i)
temp.app... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
count = 0
def UniquePartitions(self, n):
table = [[[1]]] + [None] * (n - 1)
for i in range(1, n):
table[i] = [[i + 1]]
for k in range(i):
table[i].extend([([i - k] + l) for l in table[k] if i - k >= l[0]])
return table[-1] | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST LIST LIST NUMBER BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR LIST LIST BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP LIST BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR NUM... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
ans = []
def printArray(p, n, ans):
res = []
for i in range(0, n):
res.append(p[i])
ans.append(res)
return ans
p = [0] * n
k = 0
p[k] = n
while True:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUM... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def __init__(self):
self.ans = []
def fun(self, arr, i, target):
if not target:
self.ans.append(arr)
return
if i == 0:
return
if i <= target:
self.fun(arr + [i], i, target - i)
self.fun(arr, i - 1, target)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR RETURN VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
res = [[n]]
arr = [(n - i) for i in range(n)]
def helper(res, index, temp, _sum, arr):
if _sum > n or index == n:
return
if sum(temp) == n:
res.append(temp)
return
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_C... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
ans = []
self.dfs(n, 0, [], ans)
return ans
def dfs(self, n, s, path, ans):
if s == n:
ans.append(path)
return
if s > n:
return
for i in range(n, 0, -1):
if len(path) ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER LIST VAR RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR LIST VAR VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def __init__(self):
self.res = []
self.sum1 = None
def solve(self, n, pat, sum1):
if sum1 > self.sum1 or n <= 0:
return
if sum1 == self.sum1:
self.res.append(pat)
return
self.solve(n, pat + [n], sum1 + n)
self.... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NONE FUNC_DEF IF VAR VAR VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR LIST NUMBER RETURN VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
curr = []
a = []
for i in range(n, 0, -1):
a.append(i)
res = []
def backtr(i, su):
if su == n:
res.append(curr.copy())
return
if i >= n or su > n:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL V... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
res = []
array = [(n - i) for i in range(n)]
def helper(arr, target, res, temp, index):
if target == 0:
res.append(temp)
return
if target < 0 or index == n:
return
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR V... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
partitions = [[n]]
copier = [n]
while copier[0] != 1:
remainder = 0
while copier[-1] == 1:
remainder += copier.pop(-1)
copier[-1] -= 1
remainder += 1
while remainder >=... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST VAR ASSIGN VAR LIST VAR WHILE VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def __init__(self):
self.unique_parts = []
def UniquePartitions(self, n):
q = self.partitions(n, n, [])
return self.unique_parts
def partitions(self, curr_num, curr_sum, curr_part):
if curr_sum < 0 or curr_num <= 0:
return -1
curr_part.a... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR LIST RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBE... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def back_track(self, res, nums, i, target, found):
if target < 0:
return
elif target == 0:
res.append(found.copy())
else:
for j in range(i, n, 1):
found.append(nums[j])
self.back_track(res, nums, j, target -... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER A... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def __init__(self):
self.ans = None
def UniquePartitions(self, n):
self.ans = []
self.findAns(n, [], n)
return self.ans
def findAns(self, n, cur_list, mx):
if n == 0:
self.ans.append(cur_list.copy())
return
for v in r... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR RETURN VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | a = []
def getArray(n, z, val):
if n == 0:
a.append(z)
elif val <= 0 or n < 0:
return -1
else:
getArray(n - val, z + [val], val)
getArray(n, z, val - 1)
class Solution:
def UniquePartitions(self, n):
global a
a = []
getArray(n, [], n)
... | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR RETURN VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
r = []
def gorec(n, curr):
if n == 0:
r.append(curr.copy())
return
for i in range(n, 0, -1):
if curr and curr[-1] < i:
continue
curr.append(i)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST RETURN VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
a = []
for j in range(1, n + 1):
a.append(j)
a = a[::-1]
ans = []
def sub(i, s, su):
if s == n:
ans.append(su.copy())
return
if i >= n or s > n:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
def fun(n, arr=[], sum=0, partition=[]):
if sum == n:
arr.append(partition)
return
if sum > n:
return
for i in range(n, 0, -1):
if len(partition) == 0 or parti... | CLASS_DEF FUNC_DEF FUNC_DEF LIST NUMBER LIST IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR LIST VAR RETURN VAR RETURN FUNC_CALL VAR VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
res = []
curr = []
def dfs(n, prev):
nonlocal res, curr
if n == 0:
res.append(curr.copy())
return
for i in range(min(prev, n), 0, -1):
curr.append(i)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, k):
dp = [[[] for j in range(k + 1)] for i in range(k + 1)]
for i in range(k + 1):
dp[0][i] = [[]]
for i in range(1, k + 1):
for j in range(1, k + 1):
for g in dp[i][j - 1]:
dp[i][j].appen... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CAL... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def util(self, a, n, S, s):
global ans
if S == 0:
s = s[:-1]
s = s.split(",")
ans.append(s)
return
if n == 0:
return
if a[n - 1] <= S:
self.util(a, n, S - a[n - 1], s + str(a[n - 1]) + ",")
... | CLASS_DEF FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP VA... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
uparts = self.UniquePartitionsLow(n)
upl = list(uparts)
upl.sort(reverse=True)
return upl
def UniquePartitionsLow(self, n, memo={}):
if 0 == n:
return set()
if n in memo:
return memo[n]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR FUNC_DEF DICT IF NUMBER VAR RETURN FUNC_CALL VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMB... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
def func(ind, tar, li, ds, ans):
if ind == len(li):
if tar == 0:
ans.append(ds.copy())
return
if li[ind] <= tar:
ds.append(li[ind])
func(ind, tar - li[... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER N... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def UniquePartitions(self, n):
dp = {(1): ((1,),)}
def recur(num):
for i in range(2, num + 1):
cur = [[i]]
for j in range(1, i // 2 + 1):
for k in dp[i - j]:
cur.append(sorted(list(k) + [j], rev... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR LIST VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR... |
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers.
Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order.
Example 1:
Input: n = 3
Output: 3 2 1 1 1 1
Exp... | class Solution:
def knapsack(self, n, val, i, arr, res, ans):
if i >= n:
if sum(ans) == n:
j = ans.copy()
j.sort(reverse=True)
res.add(tuple(j))
return
if arr[i] <= val:
self.knapsack(n, val - arr[i], i, arr, res, a... | CLASS_DEF FUNC_DEF IF VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR V... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution:
cache = {}
def isMatch(self, s, p):
if (s, p) in self.cache:
return self.cache[s, p]
if not p:
return not s
if p[-1] == "*":
if self.isMatch(s, p[:-2]):
self.cache[s, p] = True
return True
if... | CLASS_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR RETURN VAR IF VAR NUMBER STRING IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR NU... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution:
def isMatch(self, s, p):
self.mem = {}
self.t = s
self.p = p
return self.match(0, 0)
def match(self, i, j):
if (i, j) not in self.mem:
if j == len(self.p):
res = i == len(self.t)
elif j + 1 < len(self.p) and self.p... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR NUMBER NUMBER FUNC_DEF IF VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR V... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution:
def isMatch(self, s, p):
self.maps = dict()
return self.dfs(s, p)
def dfs(self, s, p):
key = s, p
if key in self.maps:
return self.maps[key]
if not s and not p:
return True
if s and not p:
return False
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING IF VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NU... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution:
def isMatch(self, s, p):
m, n = len(s), len(p)
dp = [([False] * (n + 1)) for _ in range(m + 1)]
dp[0][0] = True
for j in range(2, n + 1):
if p[j - 1] == "*":
dp[0][j] = dp[0][j - 2]
for i in range(1, m + 1):
for j in ra... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER FOR ... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution:
def __init__(self):
self.dp = {}
def isMatch(self, text, pattern):
if not pattern:
return not text
if (text, pattern) in self.dp:
return self.dp[text, pattern]
first_match = bool(text) and pattern[0] in {text[0], "."}
if len(patte... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VA... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution:
def isMatch(self, s, p):
dp = [([False] * (len(p) + 1)) for _ in range(len(s) + 1)]
dp[-1][-1] = True
for i in range(len(s), -1, -1):
for j in range(len(p) - 1, -1, -1):
first_match = i < len(s) and p[j] in {s[i], "."}
if j + 1 < l... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VA... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution(object):
def isMatch(self, string, expr):
self.memo = {(0, 0): True}
self.string = string
self.expr = expr
N = len(string)
M = len(expr)
return self.get(N, M)
def get(self, i, j):
if i < 0 or j < 0:
return False
if (i, ... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF IF VAR NUMB... |
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lo... | class Solution:
def isMatch(self, s, p):
m = {}
def dp(i, j):
print((i, j))
if (i, j) not in m:
if j == len(p):
ans = i == len(s)
else:
first_match = i < len(s) and p[j] in {s[i], "."}
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR F... |
While playing yet another strategy game, Mans has recruited $n$ Swedish heroes, whose powers which can be represented as an array $a$.
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consec... | n = int(input())
a = list(map(int, input().split()))
INF = 10**20
DP = [-INF] * 12
DP[1] = a[0]
DP[5] = -a[0]
for elem in a[1:]:
newDP = []
newDP.append(DP[5] + elem)
newDP.append(DP[3] + elem)
newDP.append(DP[4] + elem)
newDP.append(DP[1] - elem)
newDP.append(DP[2] - elem)
newDP.append(DP[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 NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL... |
While playing yet another strategy game, Mans has recruited $n$ Swedish heroes, whose powers which can be represented as an array $a$.
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consec... | N = int(input())
a, b, c, d, e = float("-inf"), float("-inf"), float("-inf"), 0, 1
for x in map(int, input().split()):
a, b, c, d, e = (
max(c + x, b - x),
max(a + x, c - x),
max(b + x, a - x, d - e * x),
d + e * x,
-e,
)
print([d, b][N > 1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VA... |
While playing yet another strategy game, Mans has recruited $n$ Swedish heroes, whose powers which can be represented as an array $a$.
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consec... | n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
print(a[0])
else:
dp = [dict(), dict()]
dp[0][0, 0, 0] = a[0]
dp[0][1, 0, 1] = -a[0]
for i in range(1, n):
_i = i & 1
dp[_i].clear()
for j in range(3):
dp[_i][j, 0, 0] = dp[1 - _i].get((j, 0, 1), -2... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASS... |
While playing yet another strategy game, Mans has recruited $n$ Swedish heroes, whose powers which can be represented as an array $a$.
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consec... | n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
exit()
inf = 1002003004005006007
dp = [[[-inf, -inf, -inf] for _ in range(2)] for _ in range(n + 1)]
dp[0][0][0] = 0
for i in range(n):
for j in range(2):
for k in range(3):
dp[i + 1][j][(k + 1) % 3] = max(
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR V... |
While playing yet another strategy game, Mans has recruited $n$ Swedish heroes, whose powers which can be represented as an array $a$.
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consec... | from sys import stdin
input = stdin.readline
def solve():
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(max(a[0], -a[0]))
return
NINF = -(10**15)
dp = [[[([NINF] * 2) for i in range(2)] for j in range(3)] for k in range(n)]
dp[0][n % 3][0][1] = a[0]
... | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBE... |
While playing yet another strategy game, Mans has recruited $n$ Swedish heroes, whose powers which can be represented as an array $a$.
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consec... | N, x, y, z, v, w = input(), -9000000000.0, -9000000000.0, -9000000000.0, 0, 1
for A in map(int, input().split()):
x, y, z, v, w = (
max(z + A, y - A),
max(x + A, z - A),
max(y + A, x - A, v - w * A),
v + w * A,
-w,
)
print([v, y][N > "1"]) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_O... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def ans(x):
print(x)
def gcd(a, b):
while b:
a, b = b, a % b
return a
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = list(input())
alphcnt = [0] * 26
for i in s:
alphcnt[ord(i) - 97] += 1
alphcnt.sort(reverse=True)
end = 1
for i in ra... | FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUN... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | PI = 3.141592653589793
INF = float("inf")
MOD = 1000000007
def add(x, y):
return (x + y) % MOD
def sub(x, y):
return (x - y + MOD) % MOD
def mul(x, y):
return x * y % MOD
def gcd(x, y):
if y == 0:
return x
return gcd(y, x % y)
def lcm(x, y):
return x * y // gcd(x, y)
def powe... | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUN... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
l = set()
dic = {}
for i in s:
dic[i] = dic.get(i, 0) + 1
a = dic.values()
ans = 0
for i in range(1, int(k**0.5) + 1):
if k % i == 0:
l.add(i)
l.add(k // i)
for fact in ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FU... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def binary_search(item, start, end, l):
if start > end:
return max(end, 0)
if start > len(l) - 1:
return len(l) - 1
mid = (start + end) // 2
if l[mid] > item:
return binary_search(item, start, mid - 1, l)
elif l[mid] < item:
return binary_search(item, mid + 1, end, l)... | FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DE... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def check(x):
add = 0
for i in range(26):
add += alpha[i] // x
return add
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
for t in range(int(input())):
n, m = map(int, input().split())
alpha = [(0) for i in range(26)]
st = input()
for i in range(n):
... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = list(input().rstrip())
l = []
for i in range(1, int(k**0.5) + 1):
if k % i == 0:
if i <= n:
l.append(i)
if k // i <= n:
l.append... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR ... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | from sys import stdin, stdout
def necklace_assembly(n, k, s):
res = 0
cna = [(0) for i in range(26)]
for i in range(len(s)):
cna[ord(s[i]) - ord("a")] += 1
for i in range(n, 0, -1):
l = k % i
if l == 0:
res = i
break
g = gcd(i, l)
if g !=... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN ... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def good(n, k, letters):
if letters[-1] >= n:
return True
necklace = [-1] * n
letters_copy = letters[:]
i = 25
index = 0
visited = set()
while i >= 0:
indices = set()
while index not in indices:
indices.add(index)
index += k
index %... | FUNC_DEF IF VAR NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN ... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def main():
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input()
d = {}
M = 0
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
M = max(M, d[i])
s = sorted(d.keys(), key=... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CAL... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def HOD(a, b):
while a != 0 and b != 0:
if a > b:
a %= b
else:
b %= a
return a + b
for _ in range(int(input())):
n, k = map(int, input().split())
s = list(input())
d = {}
for i in s:
if i not in d:
d[i] = 1
else:
d... | FUNC_DEF WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR F... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | import sys
inp = [x for x in sys.stdin.read().split()]
ii = 0
ttt = int(inp[ii])
ii += 1
for _ in range(ttt):
n, k, s = int(inp[ii]), int(inp[ii + 1]), inp[ii + 2]
ii += 3
cnt = [0] * 26
for c in s:
cnt[ord(c) - ord("a")] += 1
res = 1
for d in range(1, k + 1):
if k % d == 0:
... | IMPORT ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VA... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | for i in range(int(input())):
n, k = list(map(int, input().split()))
s = input()
a = [0] * 26
for i in s:
a["abcdefghijklmnopqrstuvwxyz".find(i)] += 1
z = 1
a = sorted(a)[::-1]
a0 = list(a)
for i in range(1, n + 1):
b = []
c = [0] * i
d = 0
for j i... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FU... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | t = int(input())
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
for _ in range(t):
n, k = map(int, input().split())
s = input()
occ = [0] * 26
for i in s:
occ[ord(i) - 97] += 1
occ.sort()
occ.reverse()
for l in range(1, n + 1):
cycle = gcd(l, k)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FU... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def make_divisors(n):
lower_divisors, upper_divisors = [], []
i = 1
while i * i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n // i)
i += 1
return lower_divisors + upper_divisors[::-1]
def main():
q = in... | FUNC_DEF ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL ... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | t = int(input())
while t:
n, k = [int(i) for i in input().split()]
s = input()
mem = {i: (0) for i in s}
for c in s:
mem[c] += 1
chars = sorted(list(mem.values()))
for i in range(n, 0, -1):
p = [-1] * i
for j in range(i):
p[j] = (j + k) % i
cycles = []... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR F... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def gcd(a, b):
return gcd(b, a % b) if b else a
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input()
elements = {}
for i in s:
if i in elements.keys():
elements[i] += 1
else:
elements[i] = 1
for i in range(n, 0, -1):
e... | FUNC_DEF RETURN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMB... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
s = input()
dict = {}
ans = 0
for i in range(len(s)):
if dict.get(ord(s[i]) - 97) is None:
dict[ord(s[i]) - 97] = 0
dict[ord(s[i]) - 97] += 1
for i in range(1, k + 1):
if k % i == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR V... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def possible(n, brr, k):
chk = []
visited = [0] * n
for i in range(n):
cnt = 0
if visited[i] == 0:
visited[i] = 1
j = (i + k) % n
cnt += 1
while j != i:
visited[j] = 1
cnt += 1
j = (j + k) % n
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSI... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def solve(N, k, s):
count = [0] * 26
for c in s:
count[ord(c) - 97] += 1
ans = 0
for n in range(1, N + 1):
X = 0
for c in count:
X += c // n
for x in range(X, 0, -1):
if k % x == 0:
ans = max(ans, x * n)
break
re... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR ... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def gcd(n, k):
if n % k == 0:
return k
return gcd(k, n % k)
t = int(input())
for you in range(t):
l = input().split()
n = int(l[0])
k = int(l[1])
s = input()
freq = [(0) for i in range(26)]
for i in s:
freq[ord(i) - 97] += 1
mina = []
for i in range(1, n + 1):
... | FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR NU... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input()
m = [0] * 26
for a in s:
m[ord(a) - ord("a")] += 1
t = max(m)
x = t * k
while True:
b = x // gcd(x, k)
... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | from sys import stdin, stdout
rr = lambda: input().strip()
rri = lambda: int(rr())
rrm = lambda: [int(x) for x in rr().split()]
def sol():
n, k = rrm()
s = input().strip()
fr = [(0) for i in range(26)]
for c in s:
fr[ord(c) - ord("a")] += 1
res = 1
for i in range(1, k + 1):
if... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSI... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
qu = list(0 for i in range(26))
qu.sort()
ans = 0
for m in range(1, n + 1):
qu = list(0 for i in range(26))
for i in s:
qu[ord(i) - ord("a")] += 1
p = list(0 for i in range(m))
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL V... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
def feasible(n, k, beads, lng, maxcnt):
g = gcd(k, lng)
h = lng // g
if g == 1:
return lng <= maxcnt
g0 = 0
for _, c in beads.items():
g0 += c // h
return g <= g0
def solve(n, k, beads):
maxcnt = 0
for _, c in b... | FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR FO... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
t = int(input())
for test in range(0, t):
n, k = input().split()
n = int(n)
k = int(k)
s = input()
dic = {}
b = []
for i in range(0, n):
if s[i] in dic:
b[dic[s[i]]] += 1
else:... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VA... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, input().split())
def find(cnt, k, h):
l = 0
r = 2001
while r - l > 1:
now = 0
c = (l + r) // 2
for j in cnt:
now += j // c
if... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR VA... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | letters = 26
for t in range(int(input())):
n, k = map(int, input().split(" "))
s = input()
counts = [0] * (letters + 1)
for c in s:
counts[ord(c) - ord("a")] += 1
counts.sort(reverse=True)
zeroi = counts.index(0)
if zeroi >= 0:
counts = counts[:zeroi]
ans = 1
for d in... | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def find(cnt, k, h):
l = 0
r = 2001
while r - l > 1:
now = 0
c = (l + r) // 2
for j in cnt:
now += j // c
if now >= h:
l = c
else:
r = c
return l * h
for i in range(int(input())):
n, k = map(int, input().split())
cnt =... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FU... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | t = int(input())
for i in range(t):
[n, k] = list(map(int, input().split()))
s = input()
l = [s.count(a) for a in set(s)]
M = 0
for j in range(1, n + 1):
MM = sum(map(lambda x: x // j, l))
if MM == 0:
continue
while k % MM:
MM -= 1
M = max(M, M... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | from sys import stdin, stdout
input = stdin.readline
for t in range(int(input())):
n, k = map(int, input().split())
s = input().strip()
a = [(0) for i in range(26)]
for i in s:
a[ord(i) - 97] += 1
x = 0
for i in a:
if i == n:
x = i
break
if x != 0:
... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NU... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | def gcd(a, b):
if a < b:
return gcd(b, a)
if b == 0:
return a
return gcd(b, a % b)
for _ in range(int(input())):
n, k = list(map(int, input().split()))
s = input()
if s[0] * n == s:
print(n)
continue
cnt = {}
for c in s:
if c not in cnt:
... | FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN V... |
The store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them.
A necklace is a set of beads connected in a circle.
For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can asse... | T = int(input())
def solve():
[N, K] = list(map(int, input().split()))
count = {}
S = input()
for c in S:
if c not in count:
count[c] = 0
count[c] += 1
def necklace_size(m):
count_ = count.copy()
ans = [None for _ in range(m)]
for i in range(len... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR F... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | rri = lambda: int(input())
rrm = lambda: list(map(int, input().split(" ")))
def solve(N, K, A):
oo = 0
for j in range(n):
if A[j] == 1:
oo += 1
ans = oo
for mod in range(k):
delta = 0
for j in range(mod, n, k):
if A[j] == 1:
delta -= 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | import sys
input = sys.stdin.readline
t = int(input())
out = []
for i in range(t):
n, k = map(int, input().split())
s = list(input())
count = [0]
for j in s:
if j == "1":
count.append(count[-1] + 1)
else:
count.append(count[-1])
ans = count[-1]
dp = []
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBE... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | T = int(input())
for test in range(T):
n, k = list(map(int, input().split()))
a = [[] for _ in range(n)]
s = input()
count = 0
for i in range(n):
if s[i] == "1":
count += 1
ans = (i + 1) % k
a[ans].append(i + 1)
if count == 0:
print(0)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUN... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | INF = int(100000000.0)
for _ in [0] * int(input()):
n, k = map(int, input().split())
a = [0] + [*map(int, input())]
b = [0] * (n + 1)
for i in range(1, n + 1):
b[i] += b[i - 1] + a[i]
r = [INF] * (n + 1)
r[0] = 0
for i in range(1, n + 1):
r[i] = min(r[i], b[i - 1] + (a[i] < 1... | ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER LIST FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | tcs = int(input())
for tc in range(tcs):
n, k = map(int, input().split())
s = input()
total = 0
for i in range(n):
if s[i] == "1":
total += 1
ans = total
for i in range(k):
dif = 0
for j in range(i, n, k):
if s[j] == "1":
dif += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR ... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | import sys
input = sys.stdin.readline
def print(val):
sys.stdout.write(str(val) + "\n")
def prog():
for _ in range(int(input().strip())):
n, k = map(int, input().split())
garland = input().strip()
modi = []
for i in range(k):
summ = [0]
for j in range... | IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | for _ in range(int(input())):
n, k = map(int, input().split())
data = input()
total = 0
splited = [[] for _ in range(k)]
for i in range(n):
splited[i % k].append(ord(data[i]) - ord("0"))
total += ord(data[i]) - ord("0")
result = total
for array in splited:
dp = [0] * ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL V... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
for i in range(t):
n, k = [int(x) for x in input().split()]
s = [int(x) for x in list(input())]
ln = len(s)
mp = ln
for j in range(k):
sm, mn, md = 0, 0, 0
for c in range(j, ln, k):
sm += 2 * s[c] - 1
if sm <= mn:
mn = sm
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR V... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | import sys
input = sys.stdin.readline
t = int(input())
ans = []
for _ in range(t):
n, k = map(int, input().split())
s = list(map(int, list(input().rsplit()[0])))
tot = sum(s)
ret = 1 << 100
for i in range(k):
D = [0] * 3
cnt = 0
for j in range(i, n, k):
cnt += s[... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUN... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
for tt in range(t):
n, k = map(int, input().split())
s = input()
ones = best = 0
for i in range(k):
cnt = 0
for j in range(i, n, k):
if s[j] == "1":
cnt += 1
ones += 1
else:
cnt = max(0, cnt - 1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER B... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
for i in range(t):
n, k = map(int, input().split())
s = input()
pre = [0] * n
if s[0] == "1":
pre[0] = 1
for i in range(1, n):
pre[i] = pre[i - 1]
if s[i] == "1":
pre[i] += 1
dp = [0] * n
dp1 = [0] * n
for i in range(k):
atleas... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR V... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | def max_subarray(s):
best_sum = 0
best_start = best_end = 0
current_sum = 0
for current_end, x in enumerate(s):
x = 1 if x == "1" else -1
if current_sum <= 0:
current_start = current_end
current_sum = x
else:
current_sum += x
if current... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
while t > 0:
t -= 1
n, k = map(int, input().split())
s = input()
cnt, v = [0] * k, [list() for i in range(k)]
ans = 0
for i in range(n):
if s[i] == "1":
cnt[i % k] += 1
ans += 1
v[i % k].append(int(s[i]))
tot = ans
for i in range(k... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR VAR NUMBER VAR NUMBE... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
def solve(N, K, A):
P = [0]
for x in A:
P.append(P[-1] + x)
for _ in range(K + 1):
P.append(P[-1])
ans = sum(A)
if ans > 0:
ans -= 1
INF = float("inf")
dp = [INF] * (N + 1)
for i in range(N - 1, -1, -1):
cost = A[i] ^ 1
dp[i] = b... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NU... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | from sys import stdin, stdout
for _ in range(int(stdin.readline())):
n, k = map(int, stdin.readline().split())
s = input()
if n == 1:
print(0)
continue
c1 = s.count("1")
ma = c1
for i in range(k):
l = 0
for j in range(i, n, k):
if s[j] == "1":
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING ASSIG... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
for _ in range(t):
n, k = map(int, input().split(" "))
s = input()
y = []
for i in s:
y.append(i)
totalones = y.count("1")
i = 0
m = 0
countone = 0
while i < k:
m = 0
for j in range(i, n, k):
if y[j] == "1":
m += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMB... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | for t in range(int(input())):
n, k = map(int, input().split())
s = input()
count_1_l = [0] * n
count_1_r = [0] * n
for i in range(n):
if i == 0:
if s[i] == "1":
count_1_l[i] = 1
else:
count_1_l[i] = count_1_l[i - 1]
if s[i] == "1":
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF ... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
s = list(map(int, list(input().strip())))
dp = [[0, 0] for i in range(n)]
dp[0] = [s[0], 1 - s[0]]
p = [s[0]]
for i in range(1, n):
p.append(p[-1] + s[i])
for i in range(1, n):
... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST VAR NUMBER BIN_OP NUMBER VAR NUMBER... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | T = int(input())
while T != 0:
T -= 1
ans = 10**9
n, k = map(int, input().split())
s = input()
tot = s.count("1")
for i in range(k):
sum = 0
maxn = 0
for j in range(i, n, k):
sum = max(0, sum - 1) if s[j] == "0" else sum + 1
maxn = max(maxn, sum)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR ... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
pre = [(0) for i in range(n)]
steps = [(0) for i in range(n)]
su = 0
for i in range(1, n):
su += int(s[i - 1])
pre[i] = su
sol = steps[n - 1] + pre[n - 1]
for i in range(n - 2, -1, -1):
if ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VA... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
for tt in range(t):
n, k = map(int, input().split())
s = input().strip()
arr = []
for i in range(k + 1):
arr.append([])
tot = 0
for i in range(len(s)):
if s[i] == "1":
tot += 1
for i in range(n):
if s[i] == "1":
arr[i % k].appe... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUM... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
for _ in range(t):
n, k = [int(i) for i in input().split()]
s = input()
all = s.count("1")
s = s.strip("0")
new_len = len(s)
ans = new_len
for i in range(k):
cnt0 = 0
cnt1 = 0
succ = 0
for j in range(i, new_len, k):
if s[j] == "0":... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | ord0 = b"0"[0]
qqq = int(input())
ans = []
for _ in range(qqq):
n, k = [int(x) for x in input().split()]
s = [(c - ord0) for c in input().encode("ascii")]
res = 10**9
tot = sum(s)
for rem in range(k):
c = s[rem:n:k]
m = len(c)
cnt = sum(c)
x0, x1, x2 = 0, 0, 0
... | ASSIGN VAR UNKNOWN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSI... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | from sys import stdin
for _ in range(int(stdin.readline())):
n, k = map(int, stdin.readline().split())
s = stdin.readline()
x = s.count("1")
ans = x
for i in range(k):
arr = [(int(s[i]) ^ 1) - (int(s[i]) ^ 0)]
for j in range(i + k, n, k):
y = int(s[j])
arr.ap... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VA... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | from sys import stdin, stdout
int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STR... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
for _ in range(t):
n, k = list(map(int, input().split(" ")))
s = input()
a = [0] * k
total = 0
for i, ch in enumerate(s):
if ch == "1":
a[i % k] += 1
total += 1
res = n
for start in range(k):
last = -1
b = [0, n, n]
c =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR ... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | t = int(input())
answers = []
for _ in range(t):
n, k = [int(i) for i in input().split()]
s = input()
vals = [(0 if i == "0" else 1) for i in s]
total_on = sum(vals)
ans = n
for j in range(k):
counter = j
sub_arr = []
while counter < n:
sub_arr.append(vals[cou... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VA... |
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one l... | import sys
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
def solve():
n, k = nm()
s = list(map(int, lis... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIG... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.