description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def backtrack(first, curr):
if tuple(curr) not in tracker:
output.append(curr[:])
tracker[tuple(curr)] = 1
for i in range(first, n):
curr.append(arr[i])
backtrack(i + 1, cu... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER LIST RETURN VA... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, nums, n):
arr = {}
self.subset(arr, [], 0, nums)
temp = arr.keys()
return sorted(temp)
def subset(self, arr, temp, start, nums):
if start == len(nums):
tempo = sorted(temp)
if tuple(tempo) not in arr:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | def solve(arr, i, ans, temp):
if i >= len(arr):
ans.append(sorted(temp))
return
temp.append(arr[i])
solve(arr, i + 1, ans, temp)
temp.pop()
solve(arr, i + 1, ans, temp)
class Solution:
def AllSubsets(self, arr, n):
ans = []
solve(arr, 0, ans, [])
f = {}... | FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER VAR LIST ASSIGN VAR DICT FOR VAR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
res = []
def solve(i, ans):
if i == n:
res.append(ans.copy())
return
ans.append(arr[i])
solve(i + 1, ans)
ans.pop()
solve(i + 1, ans)
arr.sort()
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
ls = {()}
tot = n
temp = sorted(arr)
def sol(subs, k, temp, tot):
if k == tot:
ls.add(tuple(subs.copy()))
return
idx = k + 1
while idx < tot and temp[idx] == temp[k]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
op = []
arr.sort()
n = len(arr)
res = {()}
self.solve(arr, op, 0, n, res)
res = list(res)
res = list(map(list, res))
res.sort()
return res
def solve(self, arr, op, i, n, res):
if i == ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
ans = set()
def fun(ip, op):
if len(ip) == 0:
ans.add(tuple(op))
return
op.append(ip[0])
fun(ip[1:], op)
op.pop()
fun(ip[1:], op)
arr.sort()
fu... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_C... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
res = []
def recur(arr, start, path):
res.append(path.copy())
for i in range(start, len(arr)):
if i > start and arr[i - 1] == arr[i]:
continue
path.append(ar... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER LIST RETURN VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, nums, n):
def backtrack(first=0, curr=[]):
if len(curr) <= len(nums):
output.append(list(curr))
for i in range(first, len(nums)):
if i > first and nums[i] == nums[i - 1]:
continue
... | CLASS_DEF FUNC_DEF FUNC_DEF NUMBER LIST IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LI... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def backtrack(start, end, tmp):
ans.append(tmp[:])
for i in range(start, end):
if i > start and arr[i] == arr[i - 1]:
continue
tmp.append(arr[i])
backtrack(i + 1, end, ... | CLASS_DEF FUNC_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR LIST RETURN VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, array, n):
array.sort()
result = []
def solve(idx, cur):
if idx == len(array):
result.append(cur[:])
return
else:
cur.append(array[idx])
solve(idx + 1, cur)
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NU... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def solve(self, s, ou, res):
if len(s) == 0:
res.add(tuple(ou))
return
ou1 = ou[:]
ou2 = ou[:]
ou2.append(s[0])
s = s[1:]
self.solve(s, ou1, res)
self.solve(s, ou2, res)
def AllSubsets(self, arr, n):
ou = [... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL V... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
ans = {()}
arr.sort()
def subset(arr, index, n, temp):
if index >= n:
ans.add(tuple(temp.copy()))
return
else:
temp.append(arr[index])
subset(arr, index + 1... | CLASS_DEF FUNC_DEF ASSIGN VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN EXPR FUNC_CALL VAR VAR NUMBER VAR LIST ASSIGN ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr = sorted(arr)
res = []
def solve(i, subset):
if i >= len(arr):
res.append(subset)
return
sub1 = subset[:]
subset.append(arr[i])
solve(i + 1, subset)
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, array, n):
array.sort()
self.result = list()
i = 0
temps = list()
self.solve(i, temps, array, n)
return self.result
def solve(self, i, temps, array, n):
self.result.append(temps)
flag = None
for i in r... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR VAR IF VAR NONE VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr = sorted(arr)
def util(currentList, resultSet, currentIndex):
resultSet.add(tuple(currentList))
if currentIndex < len(arr):
resultSet = util(currentList, resultSet, currentIndex + 1)
nextList ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN FUNC_CALL... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
if not arr:
return
res = []
arr.sort()
self.dfs(arr, 0, res, [])
return res
def dfs(self, arr, index, res, path):
res.append(path)
if index == len(arr):
return
for i in range(i... | CLASS_DEF FUNC_DEF IF VAR RETURN ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR LIST RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP V... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def solve(self, inp, out, res):
if len(inp) == 0:
res.add(tuple(out))
return
out2 = out.copy()
out2.append(inp[0])
inp = inp[1:]
self.solve(inp, out, res)
self.solve(inp, out2, res)
def AllSubsets(self, arr, n):
su... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VA... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def f(i, n, arr, l, ans):
if i == n:
ans.add(tuple(l))
return
f(i + 1, n, arr, l, ans)
f(i + 1, n, arr, l + [arr[i]], ans)
return
arr = sorted(arr)
ans = set()
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR LIST VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR VAR LIST VAR RETURN ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
curSet, subsets = [], []
self.helper(0, arr, n, curSet, subsets)
subsets.sort()
return subsets
def helper(self, i, arr, n, curSet, subsets):
if i >= n:
subsets.append(curSet.copy())
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR WHILE BIN_OP VAR NUMBER VA... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def sol(arr, idx, n, result, ans):
if idx == n:
ans.append(sorted(result))
return
sol(arr, idx + 1, n, result, ans)
result.append(arr[idx])
sol(arr, idx + 1, n, result, ans)
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR RETURN ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
s = {()}
arr.sort()
def fun(i, arr, l):
if i == len(arr):
s.add(tuple(l.copy()))
return
l.append(arr[i])
fun(i + 1, arr, l)
l.pop()
fun(i + 1, arr, l)
... | CLASS_DEF FUNC_DEF ASSIGN VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR LIST ASSIGN VAR F... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def subset(self, arr, i, curr, ans):
if i == len(arr):
ans.append(curr)
return
self.subset(arr, i + 1, curr + arr[i], ans)
self.subset(arr, i + 1, curr, ans)
def AllSubsets(self, arr, n):
arr.sort()
a = ""
for i in arr:
... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def solve(self, arr, out, i, ans):
if i >= len(arr):
ans.add(tuple(out.copy()))
return
ele = arr[i]
out.append(ele)
self.solve(arr, out, i + 1, ans)
out.pop()
self.solve(arr, out, i + 1, ans)
def AllSubsets(self, arr, n):
... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR ASSIGN VAR NUMBER EXPR F... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
res = [tuple()]
for i in arr:
temp = [tuple()]
for j in res:
temp.append(j)
temp.append(j + (i,))
res = temp
res = set(res)
res = list(res)
re... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR FOR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
res = []
dp = {}
def recurse(arr1, k1):
key = arr1[:]
key.sort()
if tuple(key) in dp:
return
res.append(key)
dp[tuple(key)] = 1
if k1 >= len(arr):
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VA... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, nums, n):
def find(cur, nums):
result.append(cur)
for i in range(len(nums)):
if not i or nums[i] != nums[i - 1]:
find(cur + [nums[i]], nums[i + 1 :])
nums.sort()
result = []
find([], n... | CLASS_DEF FUNC_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST VAR RETURN VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
ans = []
ans_set = set()
ans.append(())
idx = 0
cur_subset = []
self.allSubsetsUtil(arr, n, idx, cur_subset, ans, ans_set)
ans.sort()
return ans
def allSubsetsUtil(self, arr, n, idx, cur_subset, ans, ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def backtrack(start=0, cur=[]):
result.append(cur)
if start >= len(arr):
return
for i in range(start, len(arr)):
if i > start and arr[i - 1] == arr[i]:
continue
... | CLASS_DEF FUNC_DEF FUNC_DEF NUMBER LIST EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | def rec(arr, res, i, ans):
if i == len(arr):
ans.add(tuple(res))
return
rec(arr, res, i + 1, ans)
res.append(arr[i])
rec(arr, res, i + 1, ans)
res.pop()
class Solution:
def AllSubsets(self, arr, n):
arr.sort()
ans = set()
rec(arr, [], 0, ans)
l ... | FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST NUMBER ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
res = set()
def solve(arr, i, q):
if i >= len(arr):
q.sort()
q = tuple(q)
res.add(q)
return
solve(arr, i + 1, q[:])
q.append(arr[i])
solve(a... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER V... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, a, n):
a.sort()
l, d = [], {}
def backtrack(i, b, f):
if i == n:
if f:
if not d.get(tuple(b), False):
l.append(b[:])
d[tuple(b)] = True
retur... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST DICT FUNC_DEF IF VAR VAR IF VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN IF VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
b = []
m = {}
def rec(i, l):
if i == n:
e = tuple(l)
if e not in m:
m[e] = 1
b.append(e)
return
rec(i + 1, l[:])
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR NUMBER LIST EXPR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def dfs(s):
nonlocal temp
if s == []:
return
for i in range(len(s)):
temp += s[i]
if temp not in res:
res.add(temp)
dfs(s[i + 1 :])
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR LIST RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def solve(ip, op, res):
if len(ip) == 0:
op = tuple(op)
res.add(op)
return
op1 = op[:]
op2 = op[:]
op2.append(ip[0])
ip.remove(ip[0])
solve(... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CAL... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
res = []
m = {}
arr.sort()
def backtrack(ind, curr):
if ind == len(arr):
l = tuple(curr)
if l not in m:
m[l] = 1
res.append(l)
return
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT EXPR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def func(arr, li, res, n, ind, ss):
if ind == n:
tt = tuple(li)
if tt not in ss:
res.append(li.copy())
ss.add(tt)
return
li.append(arr[ind])
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
res = []
subset = []
arr.sort()
def helper(i):
if i >= n:
res.append(subset[:])
return
subset.append(arr[i])
helper(i + 1)
while i + 1 < n and arr[i] == arr... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_C... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def solve(self, arr, n, idx, output, ans):
if idx == n:
ans.append(output)
return
self.solve(arr, n, idx + 1, output, ans)
self.solve(arr, n, idx + 1, output + [arr[idx]], ans)
def AllSubsets(self, arr, n):
arr.sort()
ans = []
... | CLASS_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR E... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
dic = {}
def subs(idx, arr, lst, tmp):
if idx >= len(arr):
if str(tmp) not in dic:
lst.append(tmp[:])
dic[str(tmp)] = 1
return
tmp.append(arr[idx])
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR LIST ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def util(self, arr, n, res, ans):
if n == 0:
res.add(tuple(sorted(ans.copy())))
return
self.util(arr, n - 1, res, ans + [arr[n - 1]])
self.util(arr, n - 1, res, ans)
def AllSubsets(self, arr, n):
res = set()
self.util(arr, n, res,... | CLASS_DEF FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR LIST ASSIGN VAR FUNC_C... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
res = []
arr.sort()
self.rec(arr, 0, [], res)
return res
def rec(self, arr, indx, cur_arr, res):
res.append(cur_arr[:])
last_num = -1
for i in range(indx, len(arr)):
if last_num == arr[i]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER LIST VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL V... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
def dfs(ind, path):
if ind == n:
res.add(path)
return
dfs(ind + 1, path + (arr[ind],))
dfs(ind + 1, path)
res = set()
x = tuple()
arr.sort()
dfs(0, x)
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | def subse(arr, ind, ans, res, n):
if ind >= n:
res.add(tuple(ans))
return
subse(arr, ind + 1, ans.copy(), res, n)
ans.append(arr[ind])
subse(arr, ind + 1, ans.copy(), res, n)
class Solution:
def AllSubsets(self, arr, n):
ans = []
res = set()
arr.sort()
... | FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR N... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
dic = {}
arr.sort()
self.solve(arr, (), dic)
return sorted(dic.keys())
def solve(self, ip, op, dic):
if len(ip) == 0:
if op not in dic:
dic[op] = 1
return
else:
op1... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def subsetsHelper(self, arr, i, n, cur, res):
if i >= n:
res.append(cur[:])
return
curInd = i + 1
while curInd < n and arr[curInd] == arr[i]:
curInd += 1
count = curInd - i
for j in range(0, count + 1):
for k in... | CLASS_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
subsets = []
subsets.append([])
start, end = 0, 0
for i in range(n):
start = 0
if i > 0 and arr[i] == arr[i - 1]:
start = end + 1
end = len(subsets) - 1
f... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VA... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, A, n):
ans = set()
def rec(tem, A, ind, n):
if ind == n:
ans.add(tuple(sorted(tem)))
return
tem.append(A[ind])
rec(tem, A, ind + 1, n)
tem.pop(-1)
rec(tem, A, ind + 1, n... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR NUMBER FUNC_CALL VA... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | from itertools import chain, combinations
def powerset(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))
class Solution:
def AllSubsets(self, arr, n):
return sorted(set(powerset(sorted(arr)))) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr = sorted(arr)
ans = []
def solve(arr, n, idx, curr, ans):
if idx >= n:
ans.append(curr[:])
return
curr.append(arr[idx])
solve(arr, n, idx + 1, curr, ans)
curr.p... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
subsets = []
self.util(arr, 0, n, "", subsets)
subsets.sort()
res = []
for i, s in enumerate(subsets):
if i == 0:
res.append([])
elif i > 0 and subsets[i] != subsets[i - ... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER VAR STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def solve(self, index, nums, op, res):
if index >= len(nums):
res.add(tuple(op))
return
op.append(nums[index])
self.solve(index + 1, nums, op, res)
op.pop()
self.solve(index + 1, nums, op, res)
return
def AllSubsets(self, ... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CA... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr = sorted(arr)
def getSubset(index, temp, result):
result.append(list(temp))
if index == len(arr):
return
for i in range(index, len(arr)):
if i != index and arr[i] == arr[i - 1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
res = []
V = set()
def bt(path, i):
if tuple(path) not in V:
res.append(list(path))
V.add(tuple(path))
for j in range(i, n):
path.append(arr[j])
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL V... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def rec(self, arr, n, i, sets, curr_set):
sets.add(tuple(curr_set.copy()))
for j in range(i, n):
curr_set.append(arr[j])
self.rec(arr, n, j + 1, sets, curr_set)
curr_set.pop()
def AllSubsets(self, arr, n):
arr.sort()
sets = se... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ... |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | class Solution:
def AllSubsets(self, arr, n):
arr.sort()
res = []
def solve(idx, ans):
res.append(ans.copy())
prev = -1
for i in range(idx, n):
if arr[i] != prev:
ans.append(arr[i])
solve(i + 1, ans... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER LIST RETURN VAR |
Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.
Note: Each subset should be sorted.
Example 1:
Input: N = 3, arr[] = {2,1,2}
Output:(),(1),(1 2),(1 2 2),(2),(2 2)
Explanation:
All possible subsets = (),(2),(1),(1,2),(2),(2,2),(2,1),(2,1,2)
Afte... | def solve(arr, index, output, ans):
if index >= len(arr):
ans.append(output[:])
return
output.append(arr[index])
solve(arr, index + 1, output, ans)
output.remove(arr[index])
while index + 1 < len(arr) and arr[index] == arr[index + 1]:
index += 1
solve(arr, index + 1, outp... | FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR L... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
College admissions are starting and Chef has also recently completed his high school. There are $N$ colleges, numbered from $1$ to $N$, and they are ranked from $1$ to $N$. Each college has only a single seat left. To apply ... | for i in range(int(input())):
N, M = map(int, input().split())
cRank = list(map(int, input().split()))
sRank = list(map(int, input().split()))
students = []
for i in range(M):
c = list(map(int, input().split()))
_c = sorted(c[1:], key=lambda x: cRank[x - 1])
students.append([... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VA... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
College admissions are starting and Chef has also recently completed his high school. There are $N$ colleges, numbered from $1$ to $N$, and they are ranked from $1$ to $N$. Each college has only a single seat left. To apply ... | t = int(input())
while t != 0:
n, m = list(map(int, input().split()))
coll = list(map(int, input().split()))
stud = list(map(int, input().split()))
pref = []
for i in range(m):
c = list(map(int, input().split()))
_c = sorted(c[1:], key=lambda x: coll[x - 1])
pref.append(_c)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_C... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
College admissions are starting and Chef has also recently completed his high school. There are $N$ colleges, numbered from $1$ to $N$, and they are ranked from $1$ to $N$. Each college has only a single seat left. To apply ... | T = int(input())
for _ in range(T):
N, M = map(int, input().split())
R = list(map(int, input().split()))
S = list(map(int, input().split()))
l = []
h = {}
for i in range(M):
K = list(map(int, input().split()))
K = K[1:]
K.sort(key=lambda x: R[x - 1])
l.append([K, ... | 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
College admissions are starting and Chef has also recently completed his high school. There are $N$ colleges, numbered from $1$ to $N$, and they are ranked from $1$ to $N$. Each college has only a single seat left. To apply ... | t = int(input())
while t != 0:
n, m = list(map(int, input().split()))
collegeRank = list(map(int, input().split()))
studentsRank = list(map(int, input().split()))
chefsRank = studentsRank[0]
studentPreferences = [[-1]] * (chefsRank + 1)
for i in range(m):
CurrentStudentRank = studentsRan... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST LIST NUMBER BI... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
College admissions are starting and Chef has also recently completed his high school. There are $N$ colleges, numbered from $1$ to $N$, and they are ranked from $1$ to $N$. Each college has only a single seat left. To apply ... | clg_choice = []
clg_rank_new = []
testcases = int(input())
for i in range(testcases):
clg_choice.clear()
clg_rank_new.clear()
no_clg = int(0)
N_of_clg, M_of_students = map(int, input().split())
clg_rank = list(map(int, input().split()))
clg_rank = [[clg_rank[i], i + 1, 0] for i in range(N_of_clg... | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR BIN_O... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
College admissions are starting and Chef has also recently completed his high school. There are $N$ colleges, numbered from $1$ to $N$, and they are ranked from $1$ to $N$. Each college has only a single seat left. To apply ... | tot = int(input())
for _ in range(tot):
ans = None
N, M = list(map(int, input().split()))
CR = input()
SR = list(map(int, input().split()))
SP = []
filled = [0] * (N + 1)
for _ in range(M):
sp_temp = list(map(int, input().split()))
SP.append(sp_temp)
chefRank = SR[0]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC... |
There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should ... | a, b = map(int, input().split())
s1, s2, s3 = a**0.5, b**0.5, (a + b) ** 0.5
m = a + b
ans = 0
for i in range(1, int(s3) + 1):
if i <= s1 and a % i == 0:
m = min(m, a // i)
if i <= s2 and b % i == 0:
m = min(m, b // i)
if (a + b) % i == 0:
d = (a + b) // i
if d >= m:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR V... |
There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should ... | inp = input()
inp = inp.split()
a = int(inp[0])
b = int(inp[1])
ma = a + b
mx = ans = 1e19
k = int(ma**0.5)
i = 1
while i <= k:
if a % i == 0:
mx = min(mx, a / i)
if b % i == 0:
mx = min(mx, b / i)
if ma % i == 0 and ma / i >= mx:
ans = min(ans, 2 * (i + ma / i))
i += 1
print(int... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN... |
There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should ... | read_numbers = lambda: map(int, input().split())
INF = 1 << 64
a, b = read_numbers()
ans, n, m = INF, 1, 1
for i in range(1, int((a + b) ** 0.5 + 1)):
if a % i == 0:
n = i
if b % i == 0:
m = i
if (a + b) % i == 0:
second = (a + b) // i
if a // n <= second or b // m <= second:... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF ... |
There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should ... | a, b = map(int, input().split())
ad = []
for i in range(1, a + 1):
if i * i > a:
break
if a % i == 0:
ad.append(i)
if i * i != a:
ad.append(a // i)
bd = []
for i in range(1, b + 1):
if i * i > b:
break
if b % i == 0:
bd.append(i)
if i * i != b:... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP V... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | def solve(n, m):
va = 0
arr = [(1) for i in range(n + 1)]
for i in range(2, n + 1):
a = m % i
va += arr[a]
for j in range(a, n + 1, i):
arr[j] += 1
return va
for i in range(int(input())):
n, m = map(int, input().split())
print(solve(n, m)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR V... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | import sys
input = sys.stdin.readline
T = int(input())
for j in range(T):
N, M = map(int, input().split())
result = 0
arr = [1] * (N + 1)
for i in range(2, N + 1):
x = M % i
result += arr[x]
for j in range(x, N + 1, i):
arr[j] += 1
print(result) | 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | M = 500000.0 + 5
factor = {}
for i in range(1, int(M)):
for j in range(i, int(M), i):
factor.setdefault(j, []).append(i)
t = int(input())
for _ in range(t):
N, M = map(int, input().split())
ans = 0
for i in range(2, N + 1):
X = M - M % i
if X != 0:
ans += factor[X].in... | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR LIST 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 NU... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | M = int(500000.0 + 5)
divisors = [[] for i in range(0, M + 1)]
def findDivisiors():
for i in range(1, M + 1):
for j in range(i, M + 1, i):
divisors[j].append(i)
def binarySearch(numbers, start, end, num):
if start <= end:
mid = (start + end) // 2
if numbers[mid] == num:
... | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VA... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | t = int(input())
for test in range(t):
n, m = map(int, input().split())
c = 0
f = 0
if n > m:
x = n - m
c += x * m
c += x * (x - 1) // 2
n = m
c += n - 1
d = {}
for i in range(n, 1, -1):
x = m % i
f = max(f, x)
try:
d[x] += ... | 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 NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VA... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | t = int(input())
while t > 0:
nm = list(map(int, input().strip().split()))
n, m = nm[0], nm[1]
ans = 0
li = [1] * (n + 1)
for i in range(2, n + 1):
a = m % i
ans += li[a]
for j in range(a, n + 1, i):
li[j] += 1
print(ans)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | for _ in range(int(input())):
n, m = map(int, input().split())
arr = [1] * (n + 1)
k = 0
for i in range(2, n + 1):
md = m % i
k += arr[md]
p = md
while p <= n:
arr[p] += 1
p += i
print(k) | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | t = int(input())
for iii in range(t):
n, m = map(int, input().split())
l = []
for i in range(n + 1):
l.append(int(1))
ans = 0
for a in range(2, n + 1):
x = m % a
ans += l[x]
for b in range(x, n + 1, a):
l[b] += 1
print(ans) | 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 LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | def preCalcMod():
factors = []
M = 500000
factors.insert(0, [])
for i in range(1, M + 1):
j = i
while j <= M:
if i == 1:
factors.insert(j, [])
factors[j].append(i)
j += i
return factors
def modularEquation():
factors = preCalc... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR F... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | mx = 500015
a = [list() for x in range(mx)]
def PreCompute():
for i in range(1, mx):
for j in range(i, mx, i):
a[j].append(i)
def Lower_bound(fr, value):
l, r = [0, len(a[fr]) - 1]
ans = 0
while l <= r:
mid = l + r >> 1
if a[fr][mid] < value:
ans = mid... | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR V... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | test = int(input())
mex = 500001
div = [[] for _ in range(mex)]
for i in range(1, mex):
for j in range(i, mex, i):
div[j].append(i)
for i in range(test):
fans = 0
n, m = map(int, input().split())
mx = min(n, m)
for b in range(2, mx + 1):
amul = m - m % b
s, e = 0, len(div[amu... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR V... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | from sys import stdin
def fact(z, b):
c = 0
l = []
for i in range(1, int(z**0.5) + 1):
if z % i == 0:
if i != z // i:
l.append(i)
l.append(z // i)
else:
l.append(i)
for i in l:
if i < b:
c += 1
retu... | FUNC_DEF ASSIGN VAR NUMBER 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 BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | MAX_M = 5 * 10**5
factors = [[] for i in range(MAX_M + 1)]
for i in range(1, MAX_M + 1):
for j in range(i, MAX_M + 1, i):
factors[j].append(i)
def lowerBound(b, T):
left, right = 0, len(factors[T]) - 1
while left < right:
mid = (left + right) // 2
if factors[T][mid] >= b:
... | ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP B... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | for i in range(int(input())):
x = [int(y) for y in input().split()]
n, m = x[0], x[1]
l = [1] * (n + 1)
ans = 0
for i in range(2, n + 1):
a = m % i
ans += l[a]
for j in range(a, n + 1, i):
l[j] += 1
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | def modEquation(n, m, fact):
ans = 0
for b in range(2, n + 1):
t = m - m % b
if b > m:
ans += b - 1
else:
f = fact[t]
st = 0
en = len(f) - 1
while st <= en:
mid = (st + en) // 2
if f[mid] < b:
... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBE... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | def solve():
t = int(input())
for i in range(t):
N, M = map(int, input().split())
a = [1] * (N + 1)
cnt = 0
for j in range(2, N + 1):
c = M % j
cnt += a[c]
for k in range(c, N + 1, j):
a[k] = a[k] + 1
print(cnt)
def ma... | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR N... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | def lower_bound(arr, val):
n = len(arr)
low = 0
high = n
while low < high:
mid = (high + low) // 2
if arr[mid] >= val:
high = mid
else:
low = mid + 1
if arr[low] < val:
low = low + 1
return low
maxm = int(500000.0 + 1)
div = [[] for i in ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR V... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | for i in range(int(input())):
N, M = map(int, input().split())
count = 0
arr = [(1) for i in range(N + 1)]
for a in range(2, N + 1):
count += arr[M % a]
for b in range(M % a, N + 1, a):
arr[b] += 1
print(count) | 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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMB... |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given integers $N$ and $M$, find the number of ordered pairs $(a, b)$ such that $1 ≤ a < b ≤ N$ and $((M\ \mathrm{mod}\ a)\ \mathrm{mod}\ b) = ((M\ \mathrm{mod}\ b)\ \mathrm{mod}\ a)$.
------ Input ------
The first line co... | def divisor(n):
ans = [[1] for i in range(n + 1)]
ans[0].pop()
for i in range(2, n + 1):
for j in range(i, n + 1, i):
ans[j].append(i)
return ans
def count(n, p, div):
if n >= len(div):
return 0
size = len(div[n])
st, en = 0, size - 1
check = 0
while st ... | FUNC_DEF ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR V... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | def cached(func):
_cache = {}
def wrapped(*args):
nonlocal _cache
if args not in _cache:
_cache[args] = func(*args)
return _cache[args]
return wrapped
def len_num(l):
return 10**l - 10 ** (l - 1) if l > 0 else 0
@cached
def len_sum(l):
return len_sum(l - 1) ... | FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR RETURN VAR FUNC_DEF RETURN VAR NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NU... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | for _ in range(int(input())):
n = int(input())
u = 0
prev = 0
for i in range(1, 50005):
if u + prev + len(str(i)) >= n:
for k in range(1, i + 1):
if u + len(str(k)) >= n:
for j in str(k):
if u + 1 == n:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR F... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | import sys
input = sys.stdin.readline
bsc = {}
def digs(x):
s = 0
while x > 0:
s += 1
x //= 10
return s
def tenp(x):
t = 1
for i in range(x):
t *= 10
return t
def blocksize(b):
if b in bsc:
return bsc[b]
d = digs(b)
tp = tenp(d - 1)
sz = d *... | IMPORT ASSIGN VAR VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR B... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | import sys
input = sys.stdin.readline
def preprocess():
num_len = [0]
s_num_len = [0]
cur_len = 1
next_num = 10
for i in range(1, 50000):
if i == next_num:
cur_len += 1
next_num *= 10
num_len.append(num_len[-1] + cur_len)
s_num_len.append(cur_len)
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VA... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | word = ""
arr = [0]
for i in range(1, 22000):
word = word + str(i)
arr.append(arr[-1] + len(word))
def sol(k):
d = 0
for i in range(1, 22000):
if arr[i] > k:
d = i - 1
break
k = k - arr[d]
if k == 0:
return str(d)[-1]
else:
return word[k - 1]... | ASSIGN VAR STRING ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMB... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | def solve(k):
s = 0
cur = 0
j = -1
for i in range(1, 19):
p = 9 * 10 ** (i - 1)
q = cur * p + i * p * (p + 1) // 2
if k < s + q:
j = i
break
s += q
cur += i * p
if s > 10**18:
break
k -= s
left = 0
right = 9 ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | q = int(input())
def f(n):
take = 0
ret = 0
while True:
if n - take <= 0:
break
ret += (n - take) * (n - take + 1) // 2
take = take * 10 + 9
return ret
def g(n):
take = 0
ret = 0
while True:
if n - take <= 0:
break
ret += n ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | def num_of_digits(number):
if number <= 0:
return 0
soma = 0
start = 0
l = 1
r = 9
digit = 1
past_value = 0
while True:
if r > number:
r = number
times = r - l + 1
left_mapped = past_value + digit
right_mapped = past_value + times * dig... | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | def calc(k):
num, ret, pre = len(str(k)), 0, 0
for i in range(1, num):
cnt = pow(10, i - 1) * 9
ret += pre * cnt + i * (1 + cnt) * cnt // 2
pre += i * cnt
extra = k - pow(10, num - 1) + 1
ret += pre * extra
ret += num * (1 + extra) * extra // 2
return int(ret)
def ds(k)... | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER ... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | def s(i):
n = 1
result = i
while i >= n * 9:
i -= 9 * n
result += i
n *= 10
return result
def n(i):
result = 0
while True:
i //= 10
result += 1
if i == 0:
break
return result
def get_char_from_block(i, k):
k = k if k != 0 el... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN V... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | t = int(input())
def getDigits(quadrant):
return len(str(quadrant))
for i in range(t):
quadrant = 1
digits = 1
remainingDigits = int(input())
while remainingDigits > digits:
remainingDigits -= digits
quadrant += 1
digits += getDigits(quadrant)
i = 1
digit = 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR FUNC_CALL VAR VAR... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | q = int(input())
s = ""
l = [0] * 30001
for i in range(1, 30000):
s += str(i)
l[i] = len(s)
for i in range(q):
k = int(input())
n = 1
t = 2 * k
while n * (n + 1) < t:
n += 1
k -= 1
for i in range(1, n + 1):
if k >= l[i]:
k -= l[i]
else:
pri... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE BIN_OP VAR BIN_OP... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | q = int(input())
def sumto(r, need):
pw = 1
sum = 0
add = 0
len = 1
while 1:
if pw * 10 - 1 < r:
cnt = pw * 10 - pw
if need:
sum += add * cnt + (cnt + 1) * cnt // 2 * len
add += cnt * len
else:
sum += cnt *... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR VA... |
The only difference between the easy and the hard versions is the maximum value of $k$.
You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — f... | def foo(x: int):
if x <= 0:
return 0
a = len(str(x))
ret = a * (x * x + x) // 2
t = 1
cur, prv = 10, 1
while t < a:
l = a - t
freq = cur - prv
ret -= l * (freq * (x - prv + 1 + (x - (cur - 1) + 1)) // 2)
cur, prv = 10 * cur, 10 * prv
t += 1
ret... | FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.