description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
if In:
index = In.index(post.pop())
root = Node(In[index])
root.right = buildTree(In[index + 1 :], post, n)
root.left = buildTree(In[:index], post, n)
return root | FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | postIndex = -1
def helper(d, post, l, r):
global postIndex
if l > r:
return None
x = post[postIndex]
postIndex -= 1
index = d[x]
node = Node(x)
if l == r:
return node
node.right = helper(d, post, index + 1, r)
node.left = helper(d, post, l, index - 1)
return nod... | ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
global preOrderIndex
preOrderIndex = n - 1
def solve(In, post, inorderStart, inorderEnd):
global preOrderIndex
if preOrderIndex < 0 or inorderStart > inorderEnd:
return None
root = Node(post[preOrderIndex])
preOrderIndex -= 1
f... | FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(inorder, postorder, n):
lookup = dict()
for i, num in enumerate(inorder):
lookup[num] = i
return buildTreeRecu(lookup, postorder, inorder, len(postorder), 0, len(inorder))
def buildTreeRecu(lookup, postorder, inorder, postEnd, inStart, inEnd):
if inStart == inEnd:
return ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP B... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
i = n - 1
j = n - 1
root = Node("a")
st = []
st.append(root)
cur = root
while i >= 0:
if st[-1].data != In[j]:
if st[-1].data == cur.data:
cur.right = Node(post[i])
cur = cur.right
else:
... | FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXP... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(inorder, post, n):
inmap = {}
for i, n in enumerate(inorder):
if inmap.get(n, False):
inmap[n].append(i)
else:
inmap[n] = [i]
return Util(inorder, 0, len(inorder) - 1, post, 0, len(inorder) - 1, inmap)
def findInRoot(num, inmap, offset):
val = inma... | FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR RETURN FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def tree(In, post, start, end, n):
global index
if index < 0 or start > end:
return None
element = post[index]
index -= 1
root = Node(element)
for pos in range(start, end + 1):
if In[pos] == element:
break
root.right = tree(In, post, pos + 1, end, n)
root.left... | FUNC_DEF IF VAR NUMBER VAR VAR RETURN NONE ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def positioner(In, start, end, element):
i = start
while i <= end:
if In[i] == element:
return i
i += 1
def treeBuilder(In, post, n, index, start, end):
if index[0] < 0 or start > end:
return None
element = post[index[0]]
index[0] = index[0] - 1
root = Node(... | FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR RETURN VAR VAR NUMBER FUNC_DEF IF VAR NUMBER NUMBER VAR VAR RETURN NONE ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMB... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def helper(inorder, postorder, indexS, indexE, mp):
global postindex
if indexS > indexE:
return None
root = Node(postorder[postindex])
postindex -= 1
index = mp[root.data]
root.right = helper(inorder, postorder, index + 1, indexE, mp)
root.left = helper(inorder, postorder, indexS, in... | FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR V... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildUtil(In, post, inStrt, inEnd, pIndex):
if inStrt > inEnd:
return None
node = Node(post[pIndex[0]])
pIndex[0] -= 1
if inStrt == inEnd:
return node
iIndex = search(In, inStrt, inEnd, node.data)
node.right = buildUtil(In, post, iIndex + 1, inEnd, pIndex)
node.left = bui... | FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST BIN_OP VAR NU... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
global index
def findPosition(element, In):
for i in range(len(In)):
if In[i] == element:
return i
def rec(In, post):
global index
if len(In) == 0:
return None
elem = post[index]
index -= 1
... | FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NONE ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(inorder, postorder, n):
if inorder == [] or postorder == []:
return
root = Node(postorder[-1])
index = inorder.index(postorder[-1])
root.left = buildTree(inorder[0:index], postorder[0:index], n)
root.right = buildTree(
inorder[index + 1 : len(inorder)], postorder[index ... | FUNC_DEF IF VAR LIST VAR LIST RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN VAR |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def sieve(x):
is_prime = [True] * (x + 1)
is_prime[0] = is_prime[1] = False
ret = []
for i in range(2, x + 1):
if is_prime[i]:
ret.append(i)
for j in range(i * 2, x + 1, i):
is_prime[j] = False
return ret
def main():
n = int(input())
a = list... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR F... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | import sys
input = sys.stdin.readline
def mult_input():
return map(int, input().split())
def list_input():
return list(map(int, input().split()))
prime = [[] for i in range(200001)]
for i in range(2, 200001):
if len(prime[i]) == 0:
for j in range(i, 200001, i):
prime[j].append(i)
... | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def solve(arr, n):
ans = arr[0]
for i in range(1, n):
ans = gcd(ans, arr[i])
return ans
n = int(input())
arr = [int(i) for i in input().split()]
arr.insert(0, 0)
suffix = [int(0) for _ in range(n + 1)]
suffix[n... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIG... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def gcd(num1, num2):
while num1:
num2, num1 = num1, num2 % num1
return num2
n = int(input())
arr = list(map(int, input().rstrip().split()))
gcdPreComp = [0] * (n - 1) + [arr[-1]]
for pos in range(len(arr) - 2, -1, -1):
gcdPreComp[pos] = gcd(arr[pos], gcdPreComp[pos + 1])
res = 0
for pos in range(n... | FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER A... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | n = int(input())
arr = input().split(" ")
lis = [int(s) for s in arr]
prime = [(True) for i in range(200001)]
p = 2
while p <= 200000:
if prime[p] == True:
for i in range(p * p, 200001, p):
prime[i] = False
p += 1
prime[1] = False
primes = []
ans = 1
for i in range(2, 200000):
if prime[i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | import sys
chk = [0] * 200001
prm = []
fact = {(1): [1]}
for i in range(2, 200001):
if chk[i] == 0:
prm.append(i)
j = 1
while True:
if i * j > 200000:
break
if i * j not in fact:
fact[i * j] = [i]
else:
fact... | IMPORT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR DICT NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR LIST VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR V... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | n = int(input())
a = sorted(list(map(int, input().split(" "))))
d = {}
def pow_of(prime, number):
i = 0
divisor = 1
while number % divisor == 0:
i += 1
divisor *= prime
return i - 1
def p_upto(n):
primes = [2, 3, 5, 7]
i = 11
while i <= n:
bhul = True
for ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN ... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | n = int(input())
As = list(map(int, input().split()))
def gcd(n, m):
a = max(n, m)
b = min(n, m)
while b:
a, b = b, a % b
return a
def lcm(n, m):
return n * m // gcd(n, m)
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR LIST... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | import sys
input = sys.stdin.readline
def prime(n):
if n == 1:
return []
if n == 2:
return [2]
p = 2
while p * p <= n:
if n % p == 0:
return [p] + prime(n // p)
p += 1
if p * p > n and n % p != 0:
return [n]
n = int(input())
a = list(map(int, ... | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP LIST VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | from sys import stdin, stdout
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def lcm(a, b):
return a * b / gcd(a, b)
a_Length = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
pref = [0] * a_Length
suf = [0] * a_Length
pref[0] = a[0]
suf[a_Length - 1] ... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR N... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | n = int(input())
arr = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
arr.insert(0, 0)
pre = [0] * (n + 1)
suf = [0] * (n + 1)
pre[1] = arr[1]
suf[n] = arr[n]
for i in range(2, n + 1):
pre[i] = gcd(pre[i - 1], arr[i])
for i in range(n - 1, 0, -1):
suf... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR ... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | import sys
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a // gcd(a, b) * b
def main(n, a):
l = [0]
for ai in a:
l.append(gcd(l[-1], ai))
r = [0]
for ai in reversed(a):
r.append(gcd(r[-1], ai))
r.reverse()
ans = 1
for i in ra... | IMPORT FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
g = []
for i in range(n):
g.append(0)
g[n - 1] = a[n - 2] * a[n - 1]
g1 = a[n - 1]
for i in range(n - 2, 0, -1):
g1 = gcd(a[i], g1)
g[i] = a[i - 1] * g1
g1 = gcd(g1, a[0]... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR B... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | import sys
input = sys.stdin.readline
n = int(input())
ar = [int(x) for x in input().split()]
d = {}
count = {}
def power(x, p):
res = 1
while p:
if p & 1:
res = res * x
x = x * x
p >>= 1
return res
for i in ar:
ct = 0
temp = i
while i % 2 == 0:
c... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN V... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
divs = {}
i = 0
for numb in a:
for d in divs:
foo = 0
if divs[d][1] > 0:
while numb % d == 0:
numb //= d
foo += 1
if foo < divs[d][0]:
d... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a * b // gcd(a, b)
def solve(n, array):
pref = [(0) for i in range(n)]
suff = [(0) for i in range(n)]
g = [(0) for i in range(n)]
for i in range(1, n):
pref[i] = gcd(pref[i - 1], array[i - 1])
... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def primes235(limit):
yield 2
yield 3
yield 5
if limit < 7:
return
modPrms = [7, 11, 13, 17, 19, 23, 29, 31]
gaps = [4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2, 4, 6, 2, 6]
ndxs = [
0,
0,
0,
0,
1,
1,
2,
2,
2,
2,
... | FUNC_DEF EXPR NUMBER EXPR NUMBER EXPR NUMBER IF VAR NUMBER RETURN ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUM... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | import sys
I = sys.stdin.readline
n = int(I())
a = list(map(int, I().split()))
def gcd(a, b):
while b != 0:
temp = b
b = a % b
a = temp
return a
suff_gcd = [0] * n
suff_gcd[-1] = a[-1]
gcd_list = []
for i in range(n - 2, -1, -1):
suff_gcd[i] = gcd(a[i], suff_gcd[i + 1])
for i in... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VA... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return a * b // gcd(a, b)
n = int(input())
a = list(map(int, input().split()))
gcda = [a[-1]]
m = a[::-1]
for i in range(1, n):
gcda.append(gcd(gcda[-1], m[i]))
gcda = gcda[::-1]
answer = lcm(a[0], gcda[1])
for i in range... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VA... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | def prime_factorizatoon(n):
ans = {}
ta = 0
while n % 2 == 0:
n //= 2
ta += 1
if ta > 0:
ans[2] = ta
i = 3
while i * i <= n:
ta = 0
while n % i == 0:
n //= i
ta += 1
if ta > 0:
ans[i] = ta
i += 2
if n... | FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | n = int(input())
a = list(map(int, input().split()))
ans = 1
m = [0] * 200000
for i in range(2, 200000):
counter = 0
fstpos = -1
breakflag = 0
r = 0
while r < 2:
breakflag = 0
for j in range(n):
if a[j] % i == 0:
b = a[j] // i
if (b + 1) * ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CAL... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | n = int(input())
A = list(map(int, input().split(" ")))
gcd = {}
gcd[1] = A[-1]
def GCD(a, b):
if a == 0:
return b
return GCD(b % a, a)
temp = A[-1]
for i in range(n - 2, -1, -1):
temp = GCD(temp, A[i])
gcd[n - i] = temp
arr = []
for i in range(n - 1, 0, -1):
arr.append(gcd[i] * A[n - i ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR F... |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | maxn = 200005
fac = [[] for i in range(maxn)]
cnt = [[] for i in range(maxn)]
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
print(arr[0])
else:
for i in range(n):
j = 2
while j * j <= arr[i]:
count = 0
if arr[i] % j == 0:
while arr[i] %... | ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR ASS... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
a = S[:]
s = 0
for i, j, k in sorted(zip(index, sources, targets)):
if S[i : i + len(j)] == j:
i = i + s
a = a[:i] + k + a[i + len(j) :]
s += len(k) - len(j)
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
n = len(S)
m = 0
for i in range(Q - 1, -1, -1):
idx = index[i]
s = sources[i]
t = targets[i]
if S[idx : idx + len(s)] == s:
S = S[:idx] + t + S[idx + len(... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL V... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
for index, sources, targets in sorted(
zip(index, sources, targets), reverse=True
):
if S[index : index + len(sources)] == sources:
S = S[:index] + targets + S[index + len(sources) :]
... | CLASS_DEF FUNC_DEF FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
S = list(S)
to_replace_target = []
to_replace_source = []
for q_no in range(Q):
i = index[q_no]
n = len(sources[q_no])
if S[i : i + n] == list(sources[q_no]):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN ... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
index.reverse()
sources.reverse()
targets.reverse()
for i, s, t in zip(index, sources, targets):
if S[i : i + len(s)] == s:
S = S[0:i] + t + S[i + len(s) :]
return S | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
answer = ""
input_idx = 0
read_idx = 0
while read_idx < len(S):
if input_idx == Q:
answer += S[read_idx:]
return answer
if read_idx == index[input_idx]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
leng = 0
for i in range(len(index)):
index[i] += leng
if S[index[i] : index[i] + len(sources[i])] != sources[i]:
continue
str = S[: index[i]] + targets[i] + S[index[i] + len(... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
idx = {index[i]: i for i in range(len(index))}
in_window, i, j, end, valid = False, 0, 0, -1, False
ans, sr_idx, s = [], -1, ""
while i < len(S):
if i in idx:
in_window = True
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER STRING WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUM... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, s, Q, index, sources, targets):
list_new = []
ctr = 0
range_list = [x for x in range(0, len(s))]
range_list_iter = iter(range_list)
steps = 0
i = 0
for r in range_list_iter:
if r in index:
t... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VA... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
diff = 0
for j in range(len(index)):
x = sources[j]
y = targets[j]
i = index[j]
if x == S[i + diff : i + diff + len(x)]:
S = S[: i + diff] + y + S[i + diff + len(... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
replacements = [(index[i], sources[i], targets[i]) for i in range(Q)]
replacements.sort(reverse=True)
for i, source, target in replacements:
if S[i : i + len(source)] == source:
S = S[:i] + ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
res = []
i = 0
while i < len(S):
if i in index:
temp = index.index(i)
if S[i : i + len(sources[temp])] == sources[temp]:
res.append(targets[temp])
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUM... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
n = len(S)
diff = 0
for i in range(Q):
curr_ind = index[i]
curr_s = sources[i]
curr_t = targets[i]
m = len(curr_s)
p = len(curr_t)
if curr_ind + d... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
arr = [i for i in S]
for i in range(Q):
if sources[i] == "".join(arr[index[i] : index[i] + len(sources[i])]):
arr[index[i]] = targets[i]
for x in range(index[i] + 1, index[i] + len(s... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL STRING VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def find(self, S, source, index):
l = len(source)
for i in range(l):
if S[index + i] != source[i]:
return -1
return 1
def replaceStr(self, S, index, source, target):
s1 = S[index:]
S = S[:index]
s1 = s1.replace(source,... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VA... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
listChanges = []
for i in range(Q):
l = len(sources[i])
start = index[i]
end = start + l
if S[start:end] == sources[i]:
listChanges.append(i)
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
n = len(S)
res = ""
i = 0
while i < n:
j = 0
while j < Q:
if i == index[j]:
if S[i : i + len(sources[j])] == sources[j]:
res +... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
x = ""
i = 0
while i < len(S):
if len(index) and i == index[0]:
j = i
k = 0
while j < len(S) and k < len(sources[0]) and sources[0][k] == S[j]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER A... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
res = list(S)
for i in range(Q):
start = index[i]
end = index[i] + len(sources[i])
if S[start:end] == sources[i]:
res[index[i]] = targets[i]
for i in range(st... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
sNew = ""
i = 0
currIndex = 0
while i < Q:
if i == 0 and index[i] != 0:
sNew = sNew + S[0 : index[i]]
currIndex = index[i]
indexSub = len(sources[i])
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VA... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
ans = ""
pos = 0
for i in range(Q):
idx = index[i]
if S[idx : idx + len(sources[i])] == sources[i]:
ans += S[pos:idx]
ans += targets[i]
pos = idx ... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
valid_queries = list(
filter(
lambda x: S[x[0] : x[0] + len(x[1])] == x[1],
zip(index, sources, targets),
)
)
valid_queries.sort()
diff = 0
res = ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
sortd = []
for i in range(Q):
sortd.append([index[i], i])
sortd.sort(reverse=True)
for ind in sortd:
i = ind[0]
s = sources[ind[1]]
t = targets[ind[1]]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR FUNC_CAL... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
test = S
z = 0
for i in range(0, len(index)):
x = sources[i]
y = len(x)
if S[index[i] : index[i] + y] == x:
test = test[: index[i] + z] + targets[i] + test[index[i] +... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VA... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
string = []
st, j = "", 0
rep = -1
i = 0
while i < len(S):
if j < Q:
if i == index[j]:
if S[i : i + len(sources[j])] == sources[j]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
rlen = 0
for x in range(Q):
substr = S[index[x] + rlen : index[x] + len(sources[x]) + rlen]
if substr == sources[x]:
S = (
S[0 : index[x] + rlen]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VA... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
replace_index = []
for i in range(Q):
if S.find(sources[i], index[i], index[i] + len(sources[i])) == index[i]:
replace_index.append(i)
if not replace_index:
return S
offs... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
new = S
prevt = 0
prevs = 0
l2 = 0
for i in range(Q):
l = int(len(sources[i]))
upto = index[i] + l
l2 += l
if S[index[i] : upto] == sources[i]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
index.reverse()
sources.reverse()
targets.reverse()
for ind, so, tar in zip(index, sources, targets):
if S[ind : ind + len(so)] == so:
S = S[0:ind] + tar + S[ind + len(so) :]
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
res = []
beg = 0
for i in range(Q):
ind = index[i]
if S[ind : ind + len(sources[i])] == sources[i]:
res.append(S[beg:ind])
res.append(targets[i])
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
org = S
for i in range(Q - 1, -1, -1):
l = 0
m = 0
source = sources[i]
s_ind = index[i]
while l < len(source):
if S[s_ind] == source[l]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR ... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
for i in range(Q):
n = len(sources[-i - 1])
j = index[-i - 1]
if S[j : j + n] == sources[-i - 1]:
S = S[:j] + targets[-i - 1] + S[j + n :]
return S | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
st = 0
res = []
for i, src, tgt in zip(index, sources, targets):
if S[i:].startswith(src):
res.extend(S[st:i])
res.extend(tgt)
st = i + len(src)
if st... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
lookup = {i: (src, tgt) for i, src, tgt in zip(index, sources, targets)}
res = ""
i = 0
while i < len(S):
if i in lookup:
ptn, tar = lookup[i]
if S[i:].startswith(ptn... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
s = S[:]
toBeAdded = 0
for i in range(Q):
sourceLen = len(sources[i])
if S[index[i] : index[i] + sourceLen] == sources[i]:
s = s[: index[i] + toBeAdded] + targets[i] + S[index[i]... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
idx = []
for i in range(Q):
if S.find(sources[i], index[i]) == index[i]:
idx.append(i)
for i in idx:
S = S[: index[i]] + targets[i] + S[index[i] + len(sources[i]) :]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VA... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
indexEnum = []
for i, val in enumerate(index):
indexEnum.append((i, val))
indexEnum.sort(reverse=True)
for i, index in indexEnum:
s = sources[i]
t = targets[i]
if... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING LIST VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
ans = ""
j = 0
for i, s, t in zip(index, sources, targets):
while j < i:
ans += S[j]
j += 1
if S[j : j + len(s)] == s:
ans += t
j ... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
arr = []
for k in range(Q):
ind = index[k]
pat = sources[k]
flag = True
i = ind
for j in range(len(pat)):
if i >= len(S) or S[i] != pat[j]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR F... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, s, q, index, sources, targets):
arr = [(index[i], sources[i], targets[i]) for i in range(q)]
arr.sort()
d = []
for i in range(q):
m = len(arr[i][1])
if s[index[i] : arr[i][0] + m] == arr[i][1]:
d.append... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, s, Q, index, sources, targets):
for i in range(Q - 1, -1, -1):
if s[index[i] : len(sources[i]) + index[i]] == sources[i]:
s = s[: index[i]] + targets[i] + s[index[i] + len(sources[i]) :]
return s | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
modified = list(S)
for idx, source, target in zip(index, sources, targets):
if not S[idx:].startswith(source):
continue
else:
modified[idx] = target
for i... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
c = 0
m = {}
for i in range(Q):
d = S.find(sources[i], index[i])
if d == index[i]:
m[d] = [len(sources[i]), targets[i]]
t = ""
i = 0
n = len(S)
wh... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
l = len(S)
ans = ""
i = 0
while i < l:
if i in index:
a = index.index(i)
s = sources[a]
t = targets[a]
if i + len(s) <= l:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUM... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
prev = 0
cnt = 0
for i in range(Q):
if S[index[i] : index[i] + len(sources[i])] == sources[i]:
St = list(S)
tar = list(targets[i])
St[index[i] : index[i] + le... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR ... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
word = ""
i = j = 0
while i < len(S):
if j < len(index) and index[j] == i:
till = index[j] + len(sources[j])
str1 = S[index[j] : till]
if sources[j] in str1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN V... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
d = {}
for i in range(Q):
if S[index[i] : len(sources[i]) + index[i]] == sources[i]:
d[index[i]] = [sources[i], targets[i]]
ans = ""
n = len(S)
i = 0
while i < n:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL ... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
res = []
i = 0
while i < len(S):
if i in index:
temp = index.index(i)
if S[i : i + len(sources[temp])] == sources[temp]:
res.append(targets[temp])
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUM... |
Given a string S on which you need to perform Q replace operations.
Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: A... | class Solution:
def findAndReplace(self, S, Q, index, sources, targets):
te = S
S = list(S)
for i in range(Q):
if sources[i] in te:
ind = te.find(sources[i], index[i])
else:
ind = -1
if index[i] == ind:
S[in... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR STRING RETURN FUNC_CALL STR... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | n, q = map(int, input().split())
s = input()
palindromes = [[] for i in range(27)]
def getIndex(char):
return ord(char) - ord("a")
def prepare(s):
for i in range(len(s)):
for j in range(len(s)):
if i + j >= len(s) or i - j < 0:
break
elif s[i + j] == s[i - j]:... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | import sys
a = 100001
m = 10**9 + 7
n, q = map(int, input().strip().split(" "))
s = str(input().strip())
pals = list()
for ndx, char in enumerate(s):
start, end = ndx, ndx
while start >= 0 and end < n and s[start] == s[end]:
pals.append(s[start : end + 1])
start -= 1
end += 1
start,... | IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FU... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | import sys
def all_palindromes(text):
results = []
text_length = len(text)
for idx, char in enumerate(text):
start, end = idx, idx
while start >= 0 and end < text_length and text[start] == text[end]:
results.append(text[start : end + 1])
start -= 1
end +... | IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR V... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | def Function(S):
result = 0
for i, s in enumerate(reversed(S)):
result += ord(s) * (10**5 + 1) ** i
result %= 10**9 + 7
return result
def FindPalindromes(S, left, right):
result = []
while left >= 0 and right < len(S) and S[left] == S[right]:
result += [S[left : right + 1]]... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR LIST VAR VAR BIN_OP VAR NUMBER VAR NUMBE... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | A = 10**5 + 1
M = 10**9 + 7
a_powers = []
def add_palindromes(result, string, i, j):
while i >= 0 and j < len(string) and string[i] == string[j]:
result.append(string[i : j + 1])
i -= 1
j += 1
def get_palindromes(string):
result = []
for i in range(len(string)):
add_palin... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL V... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | PRIME = 1000000007
BASE = 100001
def power(a, n, modulo):
if a == 0:
if n == 0:
return 1
else:
return 0
result = 1
current = a
while n > 0:
if n % 2 == 1:
result = result * current % modulo
n //= 2
current = current * current ... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | def f(word):
a = 100001
m = 10**9 + 7
l = len(word)
result = 0
for letter in word:
result = (result * a + ord(letter)) % m
return result
def all_palindromes(word):
palindromes = []
n = len(word)
for idx, char in enumerate(word):
i, j = idx, idx
while i >= 0 ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE VA... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | n, q = (int(x) for x in input().split(" "))
text = input()
palindromes = {}
MOD = 1000000007
def func(string):
t = len(string) - 1
s = 0
for c in string:
s += ord(c) * pow(100001, t, MOD)
t -= 1
s %= MOD
return s
def calculate():
N = n
if N == 0:
return
N ... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR... |
Let's define a function, $\mbox{f}$, on a string, $\boldsymbol{p}$, of length $\boldsymbol{l}$ as follows:
$f(p)=(p_1\cdot a^{l-1}+p_2\cdot a^{l-2}+\cdots+p_l\cdot a^0)\ \text{mod}\ m$
where $p_i$ denotes the ASCII value of the $i^{\mbox{th}}$ character in string $\boldsymbol{p}$, $a=1\textbf{0000}1$, and $m=10^9+7$.... | def f(text):
ans = 0
l = len(text)
if l % 2 == 0:
for i in range(l // 2):
ans += (
ord(text[i]) * a ** (l - (i + 1)) % m + ord(text[-(i + 1)]) * a**i % m
) % m
else:
for i in range(l // 2):
ans += (
ord(text[i]) * a ** (... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN... |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) ... | for i in range(int(input())):
Low, Up, Num, Spc = 0, 0, 0, 0
S = input()
if len(S) >= 10:
for i in range(len(S)):
if S[i] >= "a" and S[i] <= "z":
Low = 1
if i > 0 and i < len(S) - 1:
if S[i] >= "A" and S[i] <= "Z":
Up = 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR VAR... |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) ... | q = int(input())
for i in range(q):
s = input()
countC = 0
countD = 0
countS = 0
countL = 0
n = len(s)
if n > 9:
for t in s[0:n]:
if t.islower() == True:
countL += 1
break
for j in s[1 : n - 1]:
if j.isupper() == True:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR VAR NUMBER VAR IF FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR NUM... |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) ... | T = int(input())
while T != 0:
password = input()
if len(password) >= 10:
speclCon = False
upperCon = False
lowerCon = False
digitCon = False
insidePass = password[1 : len(password) - 1]
for i in insidePass:
if i in "abcdefghijklmnopqrstuvwxyz":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR ST... |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) ... | for _ in range(int(input())):
s = input()
flag1 = flag2 = flag3 = flag4 = 0
if len(s) > 9:
for i in range(1, len(s) - 1):
if s[i] in "@#%&?":
flag1 = 1
if 64 < ord(s[i]) < 91:
flag2 = 1
if s[i].isdigit():
flag3 = 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR N... |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) ... | import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
return input().strip()
def invr():
return map(int, input().split())
def outp(n):
sys.stdout.write(str(n) + "\n")
def outlt(lst):
sys.stdout.write(" ".j... | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL ... |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) ... | for _ in range(int(input())):
s = input()
n = len(s)
if n < 10:
print("NO")
else:
u, d, sp, l = False, False, False, False
for i in range(n):
if s[i] >= "a" and s[i] <= "z":
l = True
if i > 0 and i < n - 1:
if s[i].isupper()... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL... |
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied:
1) Password must contain at least one lower case letter $[a-z]$;
2) ... | try:
for _ in range(int(input())):
s = input()
special = {"@", "#", "%", "&", "?"}
c1 = c2 = c3 = c4 = c5 = False
flag = 0
for i in range(len(s)):
if s[i].islower():
c1 = True
if i > 0 and i < len(s) - 1 and s[i].isupper():
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.