description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.
All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanatio... | class Solution:
def getProbability(self, balls: List[int]) -> float:
M = len(balls)
N = sum(balls)
F = [math.factorial(n) for n in range(N // 2 + 1)]
s1 = [0] * M
s2 = [0] * M
def find(i):
if i == M:
if sum(s1) == sum(s2) and len([n for n... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR... |
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.
Find out how many ways to assign symbols to make sum of integers equal to target S.
Example 1:
Input: nums is [1, 1, 1, 1, 1], ... | class Solution:
def findTargetSumWays(self, nums, S):
total = sum(nums)
if total < S or total + S & 1:
return 0
target = (S + total) // 2
dp = [0] * (target + 1)
dp[0] = 1
for n in nums:
for i in range(target, n - 1, -1):
dp[i]... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.
Find out how many ways to assign symbols to make sum of integers equal to target S.
Example 1:
Input: nums is [1, 1, 1, 1, 1], ... | class Solution:
def findTargetSumWays(self, nums, S):
def findTargetNumber(nums, target):
print(nums, target)
dp = [(0) for _ in range(target + 1)]
dp[0] = 1
for n in nums:
for i in range(target, n - 1, -1):
dp[i] += dp[i ... | CLASS_DEF FUNC_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR RE... |
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.
Find out how many ways to assign symbols to make sum of integers equal to target S.
Example 1:
Input: nums is [1, 1, 1, 1, 1], ... | class Solution:
def findTargetSumWays(self, nums, S):
target = S + sum(nums)
if target % 2 == 1 or sum(nums) < S:
return 0
target //= 2
dp = [(0) for i in range(target + 1)]
dp[0] = 1
for curNum in nums:
for cap in range(len(dp) - 1, -1, -1):
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR BIN_... |
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.
Find out how many ways to assign symbols to make sum of integers equal to target S.
Example 1:
Input: nums is [1, 1, 1, 1, 1], ... | class Solution:
def findTargetSumWays(self, nums, S):
sum_ = sum(nums)
if S > sum_:
return 0
target = sum_ - S
if target % 2:
return 0
target = target // 2
dp = [1] + [0] * target
for n in nums:
i = target
while... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR |
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.
Find out how many ways to assign symbols to make sum of integers equal to target S.
Example 1:
Input: nums is [1, 1, 1, 1, 1], ... | class Solution:
def findTargetSumWays(self, nums, S):
c = [0] * 1001
c[0] = 1
T = sum(nums)
A = T + S
if T < S or A & 1:
return 0
A >>= 1
nums = sorted(nums)
temp = 0
for ind, v in enumerate(nums):
temp += v
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR B... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, s):
res = []
part = []
def ispalin(i, j):
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
def dfs(i):
if i == ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUM... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
def helper(s, v):
if s == n:
ans.append(v)
return
for i in range(s, n):
if S[s : i + 1] == S[s : i + 1][::-1]:
helper(i + 1, v + [S[s : i + 1]])
ans = []
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER LIST RETU... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
ans = []
a = []
n = len(S)
def check(s):
return s == s[::-1]
def sol(i, n):
if i == n:
ans.append(a.copy())
return
for j in range(n - i):
i... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EX... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
def helper(index, s, temp, ans):
if index == len(s):
ans.append([ele for ele in temp])
return
for i in range(index, len(s)):
if isPalindrome(s, index, i):
temp.appe... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR R... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
ans = []
part = []
def dfs(i=0):
if i == len(S):
ans.append(part[:])
return
for j in range(i, len(S)):
if self.checkPal(S[i : j + 1]):
part.append(S... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
n = len(S)
ans = []
res = []
def isPali(s):
n = len(s)
for i in range(n // 2):
if s[i] != s[n - i - 1]:
return False
return True
def bts(i):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CA... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
n = len(S)
res = []
def subs(start, out):
if start == n:
res.append(out)
return
for i in range(start, n):
if S[start : i + 1] == S[start : i + 1][::-1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER LIST RETU... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, s):
l = []
def backtrack(a, s):
if s is "":
l.append(a[:])
return
n = len(s)
x = ""
for i in range(n):
x += s[i]
if x == x[::-1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR STRING EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR RETURN ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | def palindromic_partition_helper(input_string: str, output_string: str, result_arr: []):
if len(input_string) == 0:
result_arr.append(output_string)
return
n = len(input_string)
for i in range(0, n):
word = input_string[0 : i + 1]
ros = input_string[i + 1 :]
if is_pal... | FUNC_DEF VAR VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VA... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
result = []
temp = []
index = 0
self.solve(index, S, temp, result)
return result
def solve(self, index, s, temp, result):
if index == len(s):
result.append(temp[:])
return
for i in... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
def isPalindrom(si, ei):
nonlocal S
for i in range((ei - si + 1) // 2):
if S[si + i] != S[ei - i]:
return False
return True
ans = []
n = len(S)
def backtrack(... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def IsPalindrome(self, start, end, s):
while start <= end:
if s[start] != s[end]:
return False
start += 1
end -= 1
return True
def helper(self, ind, n, s, ans, temp):
if ind == n:
ans.append(temp[:])
... | CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_C... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, s):
m = len(s)
r = []
a = []
def check(string, i, j):
x = j
for y in range(i, x):
if string[y] != string[x]:
return False
x -= 1
return True
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, s):
l = []
def dfs(x, n, a):
if x is "":
l.append(a[:])
return
y = ""
for i in range(n):
y += x[i]
if y != y[::-1]:
continue
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR STRING EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VA... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def isPalindrome(self, s):
n = len(s)
for i in range((n + 1) // 2):
if s[i] != s[n - 1 - i]:
return 0
return 1
def util(self, s, ans):
global a
if len(s) == 0:
a[ans] = 1
print(ans)
return
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUM... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, s):
def func(ind, n, res, ans, s):
if ind == n:
res.append(ans.copy())
return
for i in range(ind, n):
kk = s[ind : i + 1]
if kk == kk[::-1]:
ans.append(... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def is_palindrome(self, string):
j = len(string) - 1
i = 0
while i < j:
if string[i] != string[j]:
return False
i += 1
j -= 1
return True
def partition(self, string, ans, res):
if len(string) == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR N... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def __init__(self):
self.dp = dict()
def isPalin(self, s):
return s == s[::-1]
def allPalindromicPerms(self, s, i=0):
if len(s) == 1:
return [s]
if self.dp.get(s) != None:
return self.dp[s]
till = ""
way = []
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR NUMBER FUNC_DEF NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN LIST VAR IF FUNC_CALL VAR VAR NONE RETURN VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def is_palindrome(self, S):
low = 0
high = len(S) - 1
while low < high:
if S[low] != S[high]:
return False
low += 1
high -= 1
return True
def solve(self, S, part, res):
for i in range(len(S)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | def ispalindrome(s, ind, i):
x = ind
y = i
while x < y:
if s[x] != s[y]:
return False
x += 1
y -= 1
return True
def palinpart(s, ind, n, ans, subs):
if ind == n:
ans.append(subs[:])
return
temp = ""
for i in range(ind, n):
temp +=... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NU... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def isPalin(self, s):
n = len(s)
i = 0
j = n - 1
while i <= j:
if s[i] != s[j]:
return 0
i += 1
j -= 1
return 1
def solve(self, inp, out, ans):
if len(inp) == 0:
ans.append(out.copy(... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CA... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, s):
def check(strs):
return strs == strs[::-1]
ans = []
def fun(temp, t):
nonlocal ans
if len(t) == 0:
ans.append(temp)
return
for gap in range(1, len(t) + 1):
... | CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR RETURN VAR |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def ispal(self, s):
if s == s[::-1]:
return True
return False
def helper(self, allpart, curpart, start, end, s):
if start >= end:
x = curpart.copy()
allpart.append(x)
return
for i in range(start, end):
... | CLASS_DEF FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | def expandByCenter(S, n, c1, c2, graph):
while c1 >= 0 and c2 < n and S[c1] == S[c2]:
graph[c1].add(c2)
c1 -= 1
c2 += 1
def util(graph, S, n, u, ans, path):
if u == n:
path.append(n)
li = []
for i in range(len(path) - 1):
li.append(S[path[i] : path[i... | FUNC_DEF WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN EXPR F... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def is_palindrome(self, data):
i, j = 0, len(data) - 1
while i < j:
if data[i] != data[j]:
return False
i += 1
j -= 1
return True
def solve(self, start, S, palindromes, ans):
if start >= len(S):
ans... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CAL... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
self.res = set()
self.solve(list(S))
return sorted(list(self.res))
def solve(self, arr):
self.res.add(tuple(arr))
if len(arr) <= 1:
return
for i in range(1, len(arr)):
if arr[i - 1] == arr... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def is_palindrome(self, start, end, nums):
while start <= end:
if nums[start] != nums[end]:
return False
start = start + 1
end = end - 1
return True
def helper(self, ind, nums, path, ans):
if ind == len(nums):
... | CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL ST... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def isPali(self, str):
i = 0
j = len(str) - 1
while i < j:
if str[i] != str[j]:
return False
i += 1
j -= 1
return True
def solve(self, str):
if len(str) == 1:
return [[str[0]]]
curr ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSI... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
ans = []
temp = []
def palli(S, start, end):
sub = S[start:end]
return sub == sub[::-1]
def func(i, S, temp, ans):
if i == len(S):
ans.append(temp[:])
for j in range(i... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR VAR VAR RETURN VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
res = []
n = len(S)
def dfs(index, l):
if index == n:
res.append(l.copy())
return
for i in range(index, n):
s1 = S[index : i + 1]
if s1 == s1[::-1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_C... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
res = []
perm = []
def dfs(i):
if i >= len(S):
res.append(perm.copy())
return
for j in range(i, len(S)):
if self.isPali(S, i, j):
perm.append(S[i : ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NU... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
def go(ind):
if ind == len(S):
ans.append(p[:])
return
for i in range(ind, len(S)):
if isP(S[ind : i + 1]):
p.append(S[ind : i + 1])
go(i + 1)
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
def isPalindrome(i, j, S):
while i <= j:
if S[i] != S[j]:
return False
i += 1
j -= 1
return True
def helper(i, arr, ans):
if i == len(S):
... | CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP V... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
s = S
def palindrome(sub):
lt = 0
rt = len(sub) - 1
while lt < rt:
if sub[lt] != sub[rt]:
return False
lt += 1
rt -= 1
return True
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
self.s = S
self.n = len(S)
self.palindromes = []
self.findPalindromes(0, "", [])
return self.palindromes
def findPalindromes(self, index, word, palindrome):
if index >= self.n:
if word == "":
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER STRING LIST RETURN VAR FUNC_DEF IF VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR BIN_O... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | def isPalindrome(string: str, low: int, high: int):
while low < high:
if string[low] != string[high]:
return False
low += 1
high -= 1
return True
def allPalPartUtil(allPart: list, currPart: list, start: int, n: int, string: str):
if start >= n:
x = currPart.copy... | FUNC_DEF VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VA... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, s):
res = []
part = []
def dfs(i):
if i >= len(s):
res.append(part[:])
return
for j in range(i, len(s)):
if self.isPalin(s, i, j):
part.append(s[i : j +... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR RETURN FUNC_CALL VAR... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
def palind(f):
l = len(f)
for i in range(l // 2):
if f[i] != f[l - i - 1]:
return 0
return 1
def manu(i, n, f, s):
if i == n:
x = []
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
self.res = []
self.n = len(S)
self.pals = self.palindrome(S)
curr = []
self.palsTmp(curr, 0, S)
return self.res
def palsTmp(self, curr, i, S):
if i >= self.n:
self.res.append(list(curr))
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
def dfs(i, l):
if i == len(S):
ans.append(l[:])
return
for ind in range(i, len(S)):
if S[i : ind + 1] == S[i : ind + 1][::-1]:
l.append(S[i : ind + 1])
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def isPalindrome(self, s):
i = 0
j = len(s) - 1
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
def backtrack(self, i, n, temp, l, S):
if i >= n:
l.append(temp[:])
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
s = S
n = len(s)
ds, ans = [], []
def ispalindrome(start, end, s):
while start <= end:
if s[start] != s[end]:
return False
start += 1
end -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CAL... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | def func(s, temp, ans):
if not s:
ans.append(temp[:])
return
for i in range(1, len(s) + 1):
t = s[:i]
if t == t[::-1]:
func(s[i:], temp + [t], ans)
class Solution:
def allPalindromicPerms(self, s):
ans = []
func(s, [], ans)
return ans | FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR LIST VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR RETURN VAR |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | def rec(S, ind, res, string):
if ind == len(S):
res.append(list(string.split()))
ans = 0
for i in range(ind + 1, len(S) + 1):
temp = S[ind:i]
if temp == temp[::-1]:
rec(S, i, res, string + " " + temp)
class Solution:
def allPalindromicPerms(self, S):
res = ... | FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR STRING VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CAL... |
Given a String S, Find all possible Palindromic partitions of the given String.
Example 1:
Input:
S = "geeks"
Output:
g e e k s
g ee k s
Explanation:
All possible palindromic partitions
are printed.
Example 2:
Input:
S = "madam"
Output:
m a d a m
m ada m
madam
Your Task:
You don't need to read input or print anything... | class Solution:
def allPalindromicPerms(self, S):
n = len(S)
res = []
curr = []
self.allpartitions(S, res, curr, 0)
return res
def allpartitions(self, s, res, curr, start):
n = len(s)
if start >= n:
x = curr.copy()
res.append(x)
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR B... |
Gildong is experimenting with an interesting machine Graph Traveler. In Graph Traveler, there is a directed graph consisting of n vertices numbered from 1 to n. The i-th vertex has m_i outgoing edges that are labeled as e_i[0], e_i[1], …, e_i[m_i-1], each representing the destination vertex of the edge. The graph can h... | import sys
from sys import stdin
def solve(v, c):
if d[v][c] != None:
return d[v][c]
vnum = 0
visits = set()
while True:
if c * n + v in visits:
last = d[v][c]
vs = set()
for u in visits:
if d[u % n][u // n] <= last:
... | IMPORT FUNC_DEF IF VAR VAR VAR NONE RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ... |
You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r holds 0 ≤ l ≤ r ≤ n. Indices in array are numbered from 0.
For example, if a = [ - 5, 3, 9, 4], then sum(0, 1) = - 5, ... | from itertools import accumulate, chain
class MaxSegTree:
def __init__(self, zero, data=None, size=None):
if data is None and size is None:
raise Exception("data and size both cannot be None simultaneously")
if size is None:
size = len(data)
depth = (size - 1).bit_... | CLASS_DEF FUNC_DEF NONE NONE IF VAR NONE VAR NONE FUNC_CALL VAR STRING IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR BIN_OP LIST VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST VAR VAR VAR BIN_OP LIST VAR BIN... |
You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r holds 0 ≤ l ≤ r ≤ n. Indices in array are numbered from 0.
For example, if a = [ - 5, 3, 9, 4], then sum(0, 1) = - 5, ... | n = int(input())
a = [5] + list(map(int, input().split()))
dp = [[[i, 0] for i in range(n + 1)] for j in range(4)]
end = n
indx_a, indx_b, indx_c = 0, 0, 0
for i in range(1, n + 1):
dp[0][i][1] = dp[0][i - 1][1] + a[i]
dp[1][i][1] = max(dp[0][i - 1][1], dp[1][i - 1][1]) - a[i]
dp[2][i][1] = max(dp[1][i - 1]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIG... |
You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r holds 0 ≤ l ≤ r ≤ n. Indices in array are numbered from 0.
For example, if a = [ - 5, 3, 9, 4], then sum(0, 1) = - 5, ... | n = int(input())
nums = [int(x) for x in input().split()]
best = [None for x in range(len(nums))]
way = [None for x in range(len(nums))]
def find_best_way():
global best, n, nums, way
for j in range(n - 1, -1, -1):
best[j] = dict()
way[j] = dict()
previous = {"s1": 0, "s2": 0, "s3": 0,... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | from sys import stdin
input = stdin.readline
MOD = 1000000007
t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
dp = [([0] * (n + 1)) for _ in range(k)]
for r in range(1, k):
for c in range(1, n + 1):
dp[r][c] = (dp[r][c - 1] + dp[r - 1][n - c] + 1) % MOD
... | ASSIGN VAR VAR ASSIGN VAR NUMBER 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
MOD = 1000000007
def read_ints():
return [int(i) for i in sys.stdin.readline().strip().split()]
def read_int():
return int(sys.stdin.readline().strip())
def solve(n, k):
if k == 1:
return 1
particles = 1
dp = [1] * n
while k > 1:
particles += sum(dp)
par... | IMPORT ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSI... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
sys.setrecursionlimit(10000)
mod = 10**9 + 7
def solve(curr, left):
if dp[curr][left] != -1:
return dp[curr][left]
if left == 1:
return 1
if curr == 0:
if dp[curr][left] != -1:
return dp[curr][left]
dp[curr][left] = (1 + solve(curr + 1, left)) % mod
... | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR IF VAR VA... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
input = sys.stdin.readline
def fun(x, y):
rem = 1000000007
return (x % rem + y % rem) % rem
for _ in range(int(input())):
n, k = map(int, input().split())
if n == 1:
if k > 1:
print(2)
else:
print(1)
else:
left = [0] * (n - 1)
r... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR 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 IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | from sys import stdin
MOD = int(1000000000.0 + 7)
def solve(tc):
n, k = map(int, stdin.readline().split())
if n == 1:
if k == 1:
print(1)
else:
print(2)
return
mem = [(0) for i in range(k + 1)]
planes = [(1) for i in range(n)]
mem[1] = 1
for i i... | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FO... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | from sys import stdin
modulus = int(10**9 + 7)
def resultat(max_decay_age, width):
if max_decay_age == 1:
return 1
current_layer = [1] * (width - 1)
for thing in range(max_decay_age - 2):
current_layer = list(reversed(current_layer))
new_layer = [0] * (width - 1)
total = 1... | ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | modulo = 10**9 + 7
for ct in range(int(input())):
n, k = map(int, input().split())
dp = [[(0) for j in range(n + 1)] for i in range(k + 1)]
for i in range(k + 1):
for j in range(n + 1):
if i == 1 or j == 0:
dp[i][j] = 1
else:
dp[i][j] = (dp[i][... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | MOD = 10**9 + 7
for _ in range(int(input())):
n, k = map(int, input().split())
if k == 1:
print(1)
elif k == 2:
print(n + 1)
elif n == 1:
print(2)
else:
cur = [i for i in range(1, n)]
k -= 3
res = 1 + n + sum(cur)
while k:
k -= 1
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUM... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | mod = int(1000000000.0 + 7)
for _ in range(int(input())):
n, k = map(int, input().split())
if k == 1:
print(1)
continue
if n == 1:
print(2)
continue
ans = 1
n -= 1
a = [(1) for _ in range(n)]
while True:
cursum = 0
for i in range(n):
... | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIG... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
dp = [[[(-1) for i in range(2)] for j in range(k + 1)] for l in range(n + 1)]
for i in range(1, n + 1):
dp[i][1][0], dp[i][1][1] = 1, 1
for i in range(2, k + 1):
for j in range(n, 0, -1)... | 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 NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | t = int(input())
for test in range(1, t + 1):
n, k = list(map(int, input().split()))
if k == 1:
print(1)
elif n == 1:
print(2)
else:
res = 2
ls = [(1) for _ in range(n - 1)]
for i in range(k - 1):
new_ls = []
curr_sum = 0
for j ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUN... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | MOD = 10**9 + 7
def solve(N, K):
last_dp = [1] * (N + 1)
ans = 1
turn = 0
for _ in range(K - 1, 0, -1):
dp = [0] * (N + 1)
if turn == 0:
for j in range(N - 1, -1, -1):
dp[j] = last_dp[j] + dp[j + 1]
ans += dp[0]
else:
for j in... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
mod = int(10**9 + 7)
for _ in range(int(sys.stdin.readline())):
n, k = map(int, sys.stdin.readline().split())
if k == 1:
print(1)
continue
if n == 1:
print(2)
continue
now = [0] * (n - 1)
now[0], ans, direction = 1, 0, 1
for i in range(k):
temp... | IMPORT ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
input = sys.stdin.readline
mod = 10**9 + 7
t = int(input())
for tests in range(t):
n, k = map(int, input().split())
if k == 1:
print(1)
continue
if n == 1:
print(2)
continue
ANS = 1
DP = [1] * n
for i in range(k - 1):
NDP = [0] * n
if i... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VA... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | for _ in range(int(input())):
n, k = map(int, input().split())
MOD = 1000000007
dp = [[(0) for x in range(1010)] for y in range(1010)]
for l in range(k + 1):
for m in range(n + 1):
if l == 1:
dp[l][m] = 1
elif m == 0:
dp[l][m] = 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 NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
md = 10**9 + 7
(t,) = I()
for _ in range(t):
n, k = I()
if n == 1:
print(1 if k == 1 else 2)
elif k == 1:
print(1)
else:
an = 1
arr = [0] * n
di = 1
arr[0] = 1
while... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | MAX_N = 1001
MOD_N = 1000000007
t = int(input())
ans = [[(-1) for _ in range(MAX_N)] for _ in range(MAX_N)]
def dp(n, k, total_k):
if n == 1 or k == 0:
ans[n][k] = 1
return ans[n][k]
if ans[n][k] != -1:
return ans[n][k]
ans[n][k] = (dp(n - 1, total_k - k, total_k) + dp(n, k - 1, to... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBE... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | from itertools import accumulate
t = int(input())
mod = 10**9 + 7
for _ in range(t):
n, k = map(int, input().split())
now = [0] * (n + 1)
now[0] = 1
now[1] = 1
ans = 0
for i in range(k):
if i & 1:
for j in reversed(range(n - 1)):
now[j] += now[j + 1]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | for _ in range(int(input())):
planes, k = (int(x) for x in input().split())
if k == 1:
print(1)
continue
if planes == 1:
print(2)
continue
d = {}
d[k] = 1
ans = 0
temp = k
dp = {}
planes -= 1
mod = 1000000007
for i in range(k, -1, -1):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
def main():
allans = []
t = int(input())
for _ in range(t):
n, k = readIntArr()
dp = makeArr(0, [k + 1, n + 1])
for i in range(1, k + 1):
dp[i][0] = 1
for j in range(n + 1):
dp[1][j] = 1
for i in range(2, k + 1):
for j ... | IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIG... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
input = lambda: sys.stdin.readline().rstrip()
MOD = 1000000000.0 + 7
class Problem:
def __init__(self):
pass
def solve(self):
ans = 0
N, K = map(int, input().split())
dp = [[(0) for j in range(N + 1)] for i in range(K + 1)]
for i in range(1, K + 1):
... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VA... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | from itertools import accumulate
rn = lambda: int(input())
rns = lambda: map(int, input().split())
rl = lambda: list(map(int, input().split()))
rs = lambda: input()
YN = lambda x: print("YES") if x else print("NO")
mod = 10**9 + 7
def pre(a):
return list(accumulate(a, lambda a, b: (a + b) % mod))
def suff(a):
... | ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUN... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | for u in range(int(input())):
n, k = map(int, input().split())
x = [1] * n
ans = 1
mod = 10**9 + 7
if k == 1:
print(1)
elif n == 1:
print(2)
else:
k -= 2
ans += n
x = [1] * (n - 1)
while k > 0:
s = 0
if k % 2 == 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_O... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | for _ in range(int(input())):
n, k = list(map(int, input().split()))
if k == 1:
print(1)
elif k == 2:
print(n + 1)
else:
a = [i for i in range(n - 1, 0, -1)]
s = n + 1
for i in a:
s += i
d, k = 1, k - 2
while k > 1:
if d:
... | 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR VA... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | t = int(input())
MOD = 10**9 + 7
for _ in range(t):
n, k = list(map(int, input().split()))
if k == 1:
print(1)
continue
elif n == 1:
print(2)
continue
counts = [1] * (n - 1)
size = n - 1
ans = 2
left_to_right = True
for age in range(k - 1):
ans += ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
inp = lambda: list(map(int, sys.stdin.readline().rstrip("\r\n").split()))
mod = 10**9 + 7
Mod = 998244353
INF = float("inf")
sys.setrecursionlimit(3 * 10000 + 10)
tc = 1
tc = int(input())
for test in range(1, tc + 1):
N, K = inp()
dp = [[[0, 0] for... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CAL... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
input = sys.stdin.buffer.readline
mod = 10**9 + 7
for t in range(int(input())):
N, K = map(int, input().split())
DP = [[[-1, -1, -1] for j in range(N + 2)] for i in range(K + 2)]
for k in range(1, K + 1):
for x in range(N, -2, -1):
y = 1
if x == N or k == 1 or x =... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | def putin():
return map(int, input().split())
def sol():
C = 10**9 + 7
n, k = putin()
if k == 1:
print(1)
return
if n == 1:
print(2)
return
D = []
for i in range(k):
D.append([0] * n)
for i in range(n):
D[0][i] = 1
for i in range(1, k... | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | MOD = 10**9 + 7
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
dp = [([0] * (n + 1)) for _ in range(k)]
for i in range(n + 1):
dp[0][i] = 1
for b in range(1, k):
cur = 0
for i in range(n + 1):
dp[b][i] = cur + 1
if i < n:
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | R = range
for s in [*open(0)][1:]:
n, k = map(int, s.split())
D = [[1] * (n + 1)] + [([1] + n * [0]) for _ in R(k)]
for d in R(1, k):
for i in R(n):
D[d][i + 1] = (D[d][i] + D[d - 1][n - i - 1]) % (10**9 + 7)
print(D[k - 1][n]) | ASSIGN VAR VAR FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER B... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | mod = 10**9 + 7
def abhi(n, k):
if k <= 0:
return 0
elif n <= 0 and k > 0:
return 1
elif dp[n][k] != -1:
return dp[n][k] % mod
else:
a = abhi(s - n, k - 1) % mod
b = abhi(n - 1, k) % mod
if s - n >= 0:
dp[s - n][k - 1] = a % mod
if n ... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR N... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
def load_sys():
return sys.stdin.readlines()
def load_local():
with open("input.txt", "r") as f:
input = f.readlines()
return input
def f(n, k):
MOD_NUM = 10**9 + 7
dp = [[(0) for _ in range(n + 2)] for _ in range(k + 1)]
for age in range(1, k + 1):
dp[age][0] = ... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF FUNC_CALL VAR STRING STRING VAR ASSIGN VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | for _ in range(int(input())):
n, k = map(int, input().split())
dp = []
for i in range(0, 1005):
dp.append([0] * 1005)
ans = 1
for i in range(1, k + 1):
for j in range(0, n + 1):
if j == 0 or i == 1:
dp[i][j] = 1
else:
dp[i][j] =... | 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 LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF V... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | T = int(input())
M = 10**9 + 7
while T:
n, k = map(int, input().split())
X = [1] * (n - 1)
z = 1 + min(k - 1, 1) * n
for i in range(k - 2):
for j in range(1, n - 1):
X[j] = (X[j] + X[j - 1]) % M
z = (z + sum(X)) % M
X = X[::-1]
print(z % M)
T = T - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE 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 BIN_OP NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR V... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | t = int(input())
inf = 10**9 + 7
for i in range(t):
n, k = map(int, input().split())
a = [0] * (n + 1)
a[1] = 1
ans = 1
if k > 1:
ans += 1
for i in range(k - 1):
pref = [0] * (n + 1)
if i % 2 == 0:
for j in range(1, n):
pref[j] = (a[j] + pref[j... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUM... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import time
t = int(input())
for _ in range(t):
n, k = list(map(int, input().split()))
if k == 1:
print("1")
else:
m = 1000000007
s = 1 + n
k = k - 1
l = [(1) for i in range(n - 1)]
a = 0
while k > 1:
if k % 2 == 0:
for i i... | IMPORT 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | from itertools import accumulate
DIV = 10**9 + 7
def cum_sum(in_list, forward=True):
if forward:
for i in range(1, len(in_list)):
in_list[i] += in_list[i - 1]
in_list[i] %= DIV
else:
for i in range(len(in_list) - 2, -1, -1):
in_list[i] += in_list[i + 1]
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF ... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | module = 10**9 + 7
for _ in range(int(input())):
n, k = map(int, input().split())
if k == 1:
print(1)
elif n == 1:
print(2)
else:
ans = 2
table = [[1] * (n - 1)]
left = 1
while k != 1:
if left:
table.append([table[-1][-1]])
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBE... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | def ss(n, k):
dp = [[(0) for _ in range(n + 1)] for _ in range(k + 1)]
for i in range(n + 1):
dp[0][i] = 1
for i in range(k + 1):
dp[i][0] = 1
for d in range(1, k + 1):
for i in range(n):
dp[d][i + 1] = (dp[d][i] + dp[d - 1][n - i - 1]) % 1000000007
return dp[k - ... | FUNC_DEF ASSIGN VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | def fog():
s = list(map(int, input().split()))
n = s[0]
k = s[1]
lst = []
sm = 0
for i in range(n - 1):
lst.append(1)
if k == 1:
print(1)
elif n == 1:
print(2)
elif k == 2:
print(n + 1)
elif n == 2:
print(k + 1)
else:
for i in r... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR F... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | MOD = int(1000000000.0 + 7)
def solve(k, n):
global dp
for i in range(1, k + 1):
for j in range(1, n + 1):
dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % MOD
return dp[k][n]
for _ in range(int(input())):
n_, k_ = map(int, input().split())
dp = [[(0) for i in range(n_ + 1)] fo... | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR AS... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | import sys
mod = int(1000000000.0 + 7)
input = sys.stdin.readline
def iter_solver(N, K):
dp = [[[(-1) for _ in range(2)] for __ in range(K + 1)] for ___ in range(N + 1)]
for i in range(1, N + 1):
dp[i][1][0] = dp[i][1][1] = 1
for k in range(2, K + 1):
for n in range(N, 0, -1):
... | IMPORT ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR N... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | MOD = 10**9 + 7
t = int(input())
for test in range(t):
n, k = [int(i) for i in input().split()]
if k == 1:
print(1)
elif k == 2:
print(n + 1)
elif n == 1:
print(2)
else:
ans = n + 1
v = [(1) for i in range(n - 1)]
for my_iter in range(k - 2):
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | t = int(input())
for i in range(t):
n, k = map(int, input().split())
sum = []
if k == 1:
print(1)
elif n == 1:
print(2)
elif k == 2:
print(n + 1)
else:
for i in range(k):
tmp = [0] * (n + 1)
sum.append(tmp)
for i in range(n + 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 LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NU... |
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle... | from sys import stdin, stdout
input = stdin.readline
mod = 10**9 + 7
def f(l, r, k):
assert l + r == n
if r == 0:
return 1
if k == 1:
return 1
if dp[l][k]:
return dp[l][k]
ans = f(r, l, k - 1) + f(l + 1, r - 1, k)
ans %= mod
dp[l][k] = ans
return ans
t = int(... | ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.