description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = [int(i) for i in input().split(" ")]
arr = [(int(i) % m) for i in input().split(" ")]
c = {}
for i in range(m):
c[i] = False
stack = [0]
newstack = []
for i in arr:
for j in stack:
arrrrgh = (i + j) % m
if arrrrgh == 0:
print("YES")
return
elif c[arrrrgh] =... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = [int(i) for i in input().split()]
r = [False] * m
for x in [(int(i) % m) for i in input().split()]:
c = r.copy()
c[x] = True
for i in range(m):
if r[i]:
c[(i + x) % m] = True
r = c.copy()
if r[0]:
print("YES")
exit(0)
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | def main(n, m, a):
if n >= m:
return True
sums = []
vis = set()
for i in range(0, n):
if a[i] == 0:
return True
for j in range(0, len(sums)):
_sum = (sums[j] + a[i]) % m
if _sum == 0:
return True
if _sum not in vis:
... | FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n):
l[i] %= m
l1 = []
c = 0
ans = False
if n > m:
ans = True
if ans == True:
print("YES")
else:
dp = [0] * m
for i in range(n):
dp1 = dp.copy()
for j in range(m):
if dp1[j] == 1:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
if n > 2 * m:
print("YES")
else:
t = [(0) for i in range(m)]
s = input().split()
for i in range(len(s)):
h = int(s[i]) % m
v = [(0) for i in range(m)]
for j in range(m):
if t[j] == 1:
v[(h + j) % m] = 1
for j in... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
arr = list(map(int, input().split()))
if n > m:
print("YES")
else:
dp = [False] * m
for i in range(n):
if dp[0] == True:
break
temp = [False] * m
for j in range(m):
if dp[j] == True:
temp[(j + arr[i]) % m] = Tru... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = (int(t) for t in input().split())
A = [int(t) for t in input().split()]
makeable = set()
for a in A:
new_makeable = set([((a + k) % m) for k in makeable])
makeable |= new_makeable
makeable.add(a % m)
if 0 in makeable:
print("YES")
break
if 0 not in makeable:
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR EXPR FUNC_... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | def solve(n, m, As):
dp = [0] * m
for a in As:
a %= m
newdp = dp[:]
for i, d in enumerate(dp):
if d:
newdp[(i + a) % m] = 1
newdp[a] = 1
dp = newdp
if dp[0]:
return True
return False
n, m = map(int, input().split())
if... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = list(map(int, input().split()))
def intmodm(num):
return int(num) % m
a = list(map(intmodm, input().split()))
states = [[-1] * m]
for index in range(n):
states.append(states[-1][:])
num = a[index]
for i in range(m):
if states[-2][i] != -1:
states[-1][(i + num) % m] = index... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
l = [int(i) for i in input().split()]
if m <= n:
print("YES")
exit()
l = [(i % m) for i in l]
pssbl = [0] * m
for i in range(1, n + 1):
temp = [0] * m
for j in range(m):
if pssbl[j]:
temp[(j + l[i - 1]) % m] = 1
for j in range(m):
if pssbl... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR F... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | def poss(n, m, L):
if n >= m:
return "YES"
dp = [[(0) for _ in range(n)] for _ in range(m)]
x = L[0] % m
dp[x][0] = 1
for i in range(1, n):
y = L[i] % m
for mod in range(m):
if mod == y:
dp[mod][i] = 1
else:
dp[mod][i] =... | FUNC_DEF IF VAR VAR RETURN STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | dp = []
def possible(arr, i, finalSum, m):
if finalSum != 0 and finalSum % m == 0:
return True
if i >= len(arr):
return False
if dp[i][finalSum % m] == -1:
dp[i][finalSum % m] = possible(
arr, i + 1, finalSum % m + arr[i], m
) or possible(arr, i + 1, finalSum, m... | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR BIN_OP VAR VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n > m:
print("YES")
else:
dp = [([0] * m) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if dp[i][j]:
dp[i + 1][j] = 1
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR F... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
a = list(map(int, input().split()))
if n > m:
print("YES")
else:
arr = [([0] * m) for _ in range(n)]
arr[0][a[0] % m] = 1
for i in range(1, n):
arr[i][a[i] % m] = 1
for j in range(m):
if arr[i - 1][j] == 1:
arr[i][j] = 1
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
def good(a, m):
if len(a) > m:
return True
b = [0] * m
for e in a:
b[e % m] += 1
if b[0] > 0:
return True
for r in range(1, (m + 1) // 2):
if b[r] > 0 and b[m - r] > 0:
return True
for r in ran... | FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUM... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | def solve():
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n >= m:
return "YES"
s = set()
for i in a:
w = set()
for j in s:
w.add((i + j) % m)
s.update(w)
s.add(i % m)
if 0 in s:
return "YES"
return... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR B... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
a = [(int(i) % m) for i in input().split()]
if n <= m:
store = set()
x = 0
for i in a:
b = set()
if i == 0:
x = 1
break
if i not in b:
b.add(i)
for j in store:
if (i + j) % m == 0:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [(i % m) for i in a]
b = [0] * 1005
c = []
for v in a:
loc = len(c)
if v in c:
for i in range(b[v], loc):
if (c[i] + v) % m not in c:
c.append((c[i] + v) % m)
else:
c.append(v)
for i ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
a = list(map(int, input().split()))
if n > m:
print("YES")
else:
can = set()
can.add(a[0] % m)
newCan = set(can)
for i in range(1, n):
newCan.add(a[i] % m)
for j in can:
newCan.add((j + a[i]) % m)
can = set(newCan)
if 0 in can:... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = map(int, input().split())
a = [int(x) for x in input().split()]
if n > m or a[0] % m == 0:
print("YES")
exit(0)
can = []
for i in range(n):
can.append([0] * m)
can[0][0] = 1
can[0][a[0] % m] = 1
for i in range(n - 1):
for j in range(m):
if can[i][j] > 0:
r = (j + a[i + 1]) % m... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER NUMBE... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 β€ n β€ 10^6, 2 β€ m β€ 10^3) β the size of th... | n, m = list(map(int, input().split()))
p = [0] * m
for x in map(int, input().split()):
n = p[:]
n[x % m] = 1
for i in range(m):
if p[i] == 1:
n[(i + x) % m] = 1
p = n
if p[0]:
print("YES")
return
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
N = len(height)
valleys = []
i = 0
while i < N - 1:
while i < N - 1 and height[i] <= height[i + 1]:
i += 1
while i < N - 1 and height[i] > height[i + 1]:
i += 1
j = i
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def get_empty_per_level(self, height, level):
print(("Level: ", level))
block_start = 0
n = len(height)
while block_start < n and height[block_start] < level:
block_start += 1
if block_start == n:
print("No start")
return n... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN BIN_OP VAR NUMBER EXPR FUNC_C... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
n = len(height)
l, r, water, minHeight = 0, n - 1, 0, 0
while l < r:
while l < r and height[l] <= minHeight:
water += minHeight - height[l]
l += 1
while r > l and height[r] <= minHeight:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
l_bounds = []
lb = float("-inf")
for h in height:
lb = max(lb, h)
l_bounds.append(lb)
water = 0
rb = float("-inf")
for lb, h in zip(reversed(l_bounds), reversed(height)):
rb = max(rb, h)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR RET... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
if not height:
return 0
result = 0
left = 0
right = len(height) - 1
while left < right:
if height[left] <= height[right]:
tmp = height[left]
left += 1
while left <... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
length = len(height)
if length == 0:
return 0
maxLeft = [0] * length
maxRight = [0] * length
result = 0
maxLeft[0] = height[0]
maxRight[length - 1] = height[length - 1]
for i in range(1, length):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR N... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
ans = 0
max_left, max_right = [0] * len(height), [0] * len(height)
for i in range(1, len(height)):
max_left[i] = max(max_left[i - 1], height[i - 1])
for i in range(len(height) - 2, -1, -1):
max_right[i] = max(max_right[... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
left, right = 0, len(height) - 1
result = 0
while left < right:
mh = min(height[left], height[right])
if height[left] < height[right]:
left = left + 1
while height[left] <= mh and left < right:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER W... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, barHeights):
if barHeights == []:
return 0
numberOfBars = len(barHeights)
leftMaxima = [(0) for counter in range(numberOfBars)]
rightMaxima = [(0) for counter in range(numberOfBars)]
leftMaxima[0] = barHeights[0]
for counter... | CLASS_DEF FUNC_DEF IF VAR LIST RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR N... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
maxRight = 0
maxLeft = 0
left = 0
right = len(height) - 1
ret = 0
while left < right:
maxRight = max(maxRight, height[right])
maxLeft = max(maxLeft, height[left])
if maxLeft > maxRight:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
if not height:
return 0
left, right = 0, len(height) - 1
maxLeft, maxRight = height[left], height[right]
maxTrap = 0
while left <= right:
if height[left] <= height[right]:
if height[left] > maxLe... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN V... |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for cont... | class Solution:
def trap(self, height):
leftmaxes = []
rightmaxes = []
maximum = 0
for i in range(len(height)):
maximum = max(maximum, height[i])
leftmaxes.append(maximum)
maximum = 0
for i in range(len(height)):
maximum = max(maxi... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VA... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
q_max, ans = deque([(nums[0], 0)]), nums[0]
for i in range(1, len(nums)):
nums[i] += max(q_max[0][0], 0)
if q_max[0][1] <= i - k:
q_max.popleft()
while q_max and nums[... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
dp = [nums[0]]
decrease = collections.deque([0])
for i, x in enumerate(nums[1:], 1):
if decrease[0] == i - k - 1:
decrease.popleft()
tmp = max(x, dp[decrease[0]] + x)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR LIST VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
q = []
res = float("-inf")
for i in range(len(nums)):
while q and i - q[0][0] > k:
q.pop(0)
temp = nums[i]
if q and q[0][1] > 0:
temp += q[0][1... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER NUMBE... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
q = [(-nums[0], 0)]
res = nums[0]
dp = [0] * n
for i in range(1, n):
while q and i - q[0][1] > k:
heapq.heappop(q)
t = max(nums[i] - q[0][0],... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR ASSIG... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
dp, q = [nums[0]], deque()
q.append((0, nums[0]))
res = nums[0]
for i in range(1, len(nums)):
while q and i - q[0][0] > k:
q.popleft()
cur = nums[i]
if... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR LIST VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE V... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
dq = collections.deque()
m = -sys.maxsize
for i, n in enumerate(nums):
fi = n
if dq:
fi += max(dq[0][1], 0)
while dq and fi >= dq[-1][1]:
dq.po... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIG... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
deque = []
for i, num in enumerate(nums):
while deque and nums[deque[-1]] < 0:
deque.pop()
while deque and deque[0] < i - k:
deque.pop(0)
if deque:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN ... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums, k):
n = len(nums)
dp = [0] * n
deq = deque([0])
for i in range(n):
if deq and deq[0] < i - k:
deq.popleft()
while deq and nums[i] + dp[deq[0]] > dp[deq[-1]]:
a = deq.pop()
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR WHILE VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BI... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
q = collections.deque()
result = nums[0]
for i in range(n):
while q and q[0][1] < i - k:
q.popleft()
a = q[0][0] if q else 0
m = nums[i] ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER NUMBER EXPR ... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
max_queue = collections.deque([0])
max_sum = nums[0]
for i in range(1, len(nums)):
while max(0, i - k) > max_queue[0]:
max_queue.popleft()
nums[i] += max(0, nums[max_queue... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR V... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
stack = deque()
for i in range(len(nums)):
nums[i] += stack[0] if stack else 0
while stack and stack[-1] < nums[i]:
stack.pop()
if i >= k and stack and stack[0] == num... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER NUMBER WHILE VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR F... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
dp = [-sys.maxsize] * len(nums)
ans = nums[0]
dp[0] = nums[0]
heap = [(-nums[0], 0)]
heapq.heapify(heap)
for i in range(1, len(nums)):
bound = i - k
while heap[0][... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR V... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
maxNum = nums[0]
maxSum = nums[0]
maxNegSum = 0
curNegWindowSum = 0
curWindowSum = 0
rightIndex = 0
leftIndex = 0
midIndex = 0
negativeStreak = False
while... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VA... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
rec = -nums[0]
heap = [(-nums[0], 0)]
for j, n in enumerate(nums[1:]):
while j + 1 - heap[0][1] > k:
heapq.heappop(heap)
cand = -n + heap[0][0] if heap[0][0] <= 0 else -n
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
dp = [(0 - sys.maxsize) for i in range(len(nums))]
heap = []
dp[0] = nums[0]
heapq.heappush(heap, (0 - nums[0], 0))
for i in range(1, len(nums)):
while len(heap) and heap[0][1] < i - ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR V... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
dp, res = collections.deque(), -float("inf")
for i, n in enumerate(nums):
if dp and dp[0][0] < i - k:
dp.popleft()
cur = n + (0 if not dp else dp[0][1])
res = max(res,... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR E... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
_max = collections.deque()
res = max(nums)
for i in range(n):
if len(_max) and _max[0][0] > 0:
val = nums[i] + _max[0][0]
else:
val =... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR F... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class MonoQ:
def __init__(self, k):
self.k = k
self.m = []
def add(self, a, solution):
while len(self.m) > 0:
if solution[a] > solution[self.m[-1]]:
self.m.pop()
else:
break
self.m.append(a)
def grab(self, a, solution... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR ... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
withAdding = [(0) for _ in range(len(nums))]
notAdding = [(-1) for _ in range(len(nums))]
validMax = [nums[0]]
maxValue = nums[0]
withAdding[0] = nums[0]
for i in range(1, len(nums)):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN ... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
dp = [0] * n
dp[0] = nums[0]
heap = []
heappush(heap, (-nums[0], 0))
for i in range(1, n):
while heap[0][1] < i - k:
heappop(heap)
cu... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR B... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
dp = [0] * n
remove = collections.defaultdict(int)
h = []
def get_b():
if not h:
return 0
b = heapq.heappop(h)
while remove[b] >... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR VAR FUNC_CA... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
heap = [(-nums[0], 0)]
result = nums[0]
for i in range(1, n):
while heap and heap[0][1] < i - k:
heapq.heappop(heap)
a = -heap[0][0]
m = ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR V... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
dp = [(-math.inf) for i in range(n)]
dp[0] = nums[0]
ans = [nums[0]]
queue = [0]
for i in range(1, n):
dp[i] = max(dp[i], nums[i], nums[i] + ans[i - 1])
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER E... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
heap = [(-nums[0], 0)]
ret = nums[0]
for i in range(1, len(nums)):
remove = i - k - 1
while remove >= heap[0][1]:
heapq.heappop(heap)
cur = max(0, -heap[0][0])... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR V... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
res = -sys.maxsize
n = len(nums)
dp = [0] * (n + 1)
dq = collections.deque()
for i in range(n):
if not dq:
dp[i + 1] = nums[i]
else:
dp[i +... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BI... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
dp = [-sys.maxsize] * n
dq = []
dp[n - 1] = nums[n - 1]
res = dp[n - 1]
for i in range(n - 2, -1, -1):
while len(dq) != 0 and dp[i + 1] > dp[dq[-1]]:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FU... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
dp = [-sys.maxsize] * n
dp[0] = nums[0]
maxDeque = deque()
ans = -sys.maxsize
for j in range(n):
while len(maxDeque) > 0 and j - maxDeque[0] > k:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER ... |
Given an integer arrayΒ numsΒ and an integer k, return the maximum sum of a non-empty subsequenceΒ of that array such that for everyΒ two consecutive integers in the subsequence,Β nums[i]Β andΒ nums[j], whereΒ i < j, the conditionΒ j - i <= kΒ is satisfied.
AΒ subsequenceΒ of an array isΒ obtained by deleting some number of element... | class Solution:
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:
n = len(nums)
dp = [0] * n
q = deque()
ans = float("-inf")
for i in range(n):
if i > k and q[0] == i - k - 1:
q.popleft()
dp[i] = (0 if len(q) == 0 else ma... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR V... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin, stdout
input = stdin.readline
d1 = ["R", "G", "B"]
d2 = ["G", "B", "R"]
d3 = ["B", "R", "G"]
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input().strip()
ans = float("inf")
temp = s[0:k]
a = b = c = 0
p = 0
q = 1
r = 2
for j in temp... | ASSIGN VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIG... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
R = lambda: map(int, input().split())
(q,) = R()
a = "RGB"
for q1 in range(q):
an = [300000] * 3
n, k = R()
s = input()
for i2 in range(3):
ans = [0] * n
m = 0
for i in range(n):
ans[i] = s[i] == a[(i + i2) % 3]
... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUN... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
n, k = map(int, input().split())
s = input()
R, G, B = 0, 0, 0
ans = float("inf")
for j in range(n):
if j % 3 == 0:
if s[j] == "R":
G += 1
B += 1
elif s[j] == "G... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR NUM... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
q = int(input())
aux = "RGB"
def fun(k, s, ini):
tam = 0
ans = int(1e20)
change = 0
i = 0
j = 0
while len(s) > i:
while len(s) > i and k > tam:
change += 1 if aux[(ini + i) % 3] != s[i] else 0
tam += 1
i += 1
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR N... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = lambda: sys.stdin.readline().strip("\r\n")
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
ans = 0
for color in ["RGB", "GBR", "BRG"]:
cnt = 0
for i in range(k):
if s[i] == color[i % 3]:
cnt += 1
maxi = cn... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(str(input())[:-1])
s = "RGB" * (n // 3 + 2)
res = float("inf")
for i in range(3):
st = s[i : n + i]
s0 = [(0 if arr[j] == st[j] else 1) for j in range(n)]
temp = s... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VA... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
n, k = map(int, input().split())
s = input()[:n]
if k == 1:
print(0)
continue
rgb = [0, 0, 0]
a = 1
for j, c in enumerate(s):
if c == "R":
rgb[j % 3] += 1
elif c == "G":
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
t = int(input())
for _ in range(t):
n, k = list(map(int, sys.stdin.readline().split()))
s = sys.stdin.readline()
d = {}
d["R"] = [0, 0, 0]
d["G"] = [0, 0, 0]
d["B"] = [0, 0, 0]
res = 0
for i in range(k):
d[s[i]][i % 3] += 1
res = max(
d["R"][0] + d["G"][1]... | 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR STRING LIST NUMBER NUMBER NUMBER ASSIGN VAR STRING LIST NUMBER NUMBER NUMBER ASSIGN VAR STRING LIST NUMBER NUMBER NUMBER ASSI... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | def main():
q = int(input())
ans = []
for i in range(q):
n, k = map(int, input().split())
s = input()
min_ans = 10**9
pr1 = [0]
pr2 = [0]
pr3 = [0]
for i in range(n):
count1 = 0
count2 = 0
count3 = 0
if i... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASS... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
q = int(input())
for ppppp in range(q):
[n, k] = [int(item) for item in input().split(" ")]
x = input()
inf_seq = "RGB"
ptr = 0
weights = []
cost = [0, 0, 0]
for i in range(k):
dd = [0, 0, 0]
for d in range(3):
if x[i]... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMB... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | q = int(input())
out = ""
for _ in range(q):
n, k = list(map(int, input().split()))
s = input()
rgb = 0
gbr = 0
brg = 0
RGB = "RGB"
for i in range(k):
if i % 3 == 0:
rgb += int(s[i] != "R")
gbr += int(s[i] != "G")
brg += int(s[i] != "B")
el... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL V... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | def change(d):
for i in range(0, len(d)):
if d[i] == "R":
d[i] = 1
elif d[i] == "G":
d[i] = 2
else:
d[i] = 3
return d
a = int(input())
if a < 100000:
for i in range(0, a):
n, k = map(int, input().split())
c = list(input())
... | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN V... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
t = int(sys.stdin.readline())
x = "RGB"
y = "GBR"
z = "BRG"
for i in range(t):
n, k = list(map(int, sys.stdin.readline().strip().split()))
a = sys.stdin.readline().strip()
xk = x
yk = y
zk = z
op = 2001
xd = []
yd = []
zd = []
xdc = 0
ydc = 0
zdc = 0
b = a... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
t = int(input())
def foo(seq, index):
if index == None:
return seq[0]
index = index % 3
return seq[index]
for j in range(t):
n, k = list(map(int, input().split(" ")))
chars = list(input())
chars.insert(0, None)
diff = [[] for i in ran... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NONE RETURN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NONE ASSIGN VA... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
t = int(stdin.readline())
for _ in range(t):
n, k = map(int, stdin.readline().split())
l = stdin.readline()
m = float("inf")
for q in range(3):
if q == 0:
s = "RGB"
elif q == 1:
s = "GBR"
else:
s = "BRG"
i, count,... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR VAR NUMBER NUMB... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
A = "RGB"
B = "GBR"
C = "BRG"
for nt in range(int(sys.stdin.readline())):
n, k = map(int, sys.stdin.readline().split())
s = sys.stdin.readline()
a = b = c = 0
for i in range(k):
if s[i] != A[i % 3]:
a += 1
if s[i] != B[i % 3]:
b += 1
if s[i] !=... | IMPORT ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBE... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | q = int(input())
f = []
for i in range(q):
n, k = map(int, input().split())
s = input()
mi = 0
num = [0, 0, 0]
for i in range(n):
if i % 3 == 0:
if s[i] == "R":
num[0] += 1
elif s[i] == "G":
num[1] += 1
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER NUMBER IF VAR VAR S... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
n, k = [int(i) for i in input().split()]
s = input()
start = [0] * n
for i in range(n):
if s[i] == "R":
start[i] = i % 3
elif s[i] == "G":
start[i] = (i - 1) % 3
else:
... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR BIN_OP BIN... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
quries = int(sys.stdin.readline())
result = []
mapping = {"R": "G", "G": "B", "B": "R"}
rev_mapping = {"R": "B", "B": "G", "G": "R"}
count = {"R": 0, "B": 0, "G": 0}
memory = {}
for i in range(quries):
n, k = [int(x) for x in sys.stdin.readline().split()]
best = 10000000
lis = sys.stdin.readline... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = lambda: sys.stdin.readline().strip()
nxt = {"R": "G", "G": "B", "B": "R"}
T = int(input())
for _ in range(T):
n, k = list(map(int, input().split()))
s = input()
res = []
for start in ["R", "G", "B"]:
mis = []
cur = start
for j in range(k):
if s[j] ... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR LIST STRING STRING STRING ASSIGN VA... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin, stdout
def check(s, k, n):
t = "RGB"
ans = int(1000000000.0)
for off in range(0, 3):
res = [None] * n
curr = 0
for j in range(n):
res[j] = s[j] != t[(j + off) % 3]
curr += res[j]
if j >= k:
curr -= res[j - k... | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL V... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
s = list(input())
ans = 10**9
a = ["R", "G", "B"]
for l in range(3):
x = l
dp = [0] * (n + 1)
cnt = 10**9
for i in range(n):
if s[i] != a[x]:
... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBE... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
for nt in range(int(input())):
n, k = map(int, input().split())
s = input()
s1 = "RGB"
dp = [[0, 0, 0] for i in range(n)]
ans = 10**18
for i in range(3):
for j in range(k):
if s[j] != s1[(i + j) % 3]:
dp[0][i] += 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 FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
s = str(input())
s1 = "RGB"
s2 = "GBR"
s3 = "BRG"
ans = 200000
cnt1, cnt2, cnt3 = 0, 0, 0
dp = [[(0) for i in range(3)] for j in range(n + 1)]
dp[0][0] = 0
dp[0][1... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
t = int(input())
for _ in range(t):
n, k = map(int, stdin.readline().split())
s = stdin.readline()
one = "RGB" * (n // 3)
s1 = "RGB"
one = one + s1[: n % 3]
two = "GBR" * (n // 3)
s2 = "GBR"
two = two + s2[: n % 3]
s3 = "BRG"
three = s3 * (n // 3)
three... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN ... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
q = int(input())
INF = 10**18
for _ in range(q):
n, k = map(int, stdin.readline().split())
s = stdin.readline()[:-1]
r = ("RGB" * k)[:k]
g = ("GBR" * k)[:k]
b = ("BRG" * k)[:k]
dp = [([0] * 3) for i in range(n)]
for i in range(k):
if s[i] == r[i]:
d... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBE... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
Q = int(input())
D = {"R": 0, "G": 1, "B": 2}
for _ in range(Q):
N, K = list(map(int, input().split()))
S = input()
mi = K
for i in range(3):
d = 0
for j in range(N):
if D[S[j]] != (i + j) % 3:
d += 1
if j >= ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
rgb = ["R", "G", "B"]
def func(s):
r = [0, 0, 0]
i = 0
for c in s:
if c == rgb[i]:
r[1] += 1
r[2] += 1
elif c == rgb[(i + 1) % 3]:
r[2] += 1
r[0] += 1
else:
r[0] += 1
r[1]... | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST STRING STRING STRING FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP B... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
def main():
Q = int(input())
data = []
for _ in range(Q):
N, K = map(int, input().split())
S = input().rstrip()
data.append([N, K, S])
RGB = []
for i in range(300000):
if i % 3 == 0:
RGB.append("R")
elif i %... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FU... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | q = int(input())
rgb = "RGB"
answer = []
for req in range(q):
n, k = map(int, input().split())
s = input()
last1 = rgb[(k - 1) % 3]
last2 = rgb[k % 3]
last3 = rgb[(k + 1) % 3]
dp = [0, 0, 0]
for i in range(k):
if s[i] != rgb[i % 3]:
dp[0] += 1
if s[i] != rgb[(i + ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR L... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
def process(S, k, n):
if k == 1:
return 0
answer = float("inf")
current = [0, 0, 0]
indexes = {"R": 0, "G": 1, "B": 2}
for i in range(k):
c = chr(S[i])
index = (indexes[c] - i) % 3
for j in range(3):
current[j] += 1
current[index] -= 1... | IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VA... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
pure = "RGB" * 100006
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
ans = 0
Rc = 0
Gc = 0
Bc = 0
count = 0
for i in range(k):
if pure[i] == s[i]:
Rc += 1
elif pure[i - 1] == s[i]:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP STRING 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
RI = lambda: [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda: input().strip().split()
infinite = float("inf")
t = int(input())
for _ in range(t):
n, k = RI()
s = input()
mini = n
count = 0
test = "RGB" * (k // 3 + 5)
for j in range(k):
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING 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 ASSIGN VAR VAR ASSIGN VAR NUMBER AS... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
input = stdin.readline
t = int(input())
for i in range(t):
n, k = map(int, input().split(" "))
str_1 = input()
str_2 = ["GBR", "BRG", "RGB"]
do = []
for h in str_2:
count = 0
for j in range(k):
if str_1[j] != h[j % 3]:
... | ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR N... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
for _ in range(int(input())):
n, k = map(int, sys.stdin.readline().split())
a = sys.stdin.readline()
if n == 1:
print(0)
else:
next = a[:2]
parsum1 = [(0) for _ in range(n + 1)]
parsum2 = [(0) for _ in range(n + 1)]
parsum3 = [(0) for _ in range(n + 1)... | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR ... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from itertools import chain
from sys import stdin, stdout
def main():
input = stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
ans = [k, k, k, 1, 1]
fin_ans = k
inp = tuple(
(ord("r") + i - ord(c)) % 3 for i, c in enumerate(input().rstri... | FUNC_DEF 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 LIST VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL FUNC... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
x = 10**5
n, k = list(map(int, input().split()))
s = input()
a = 10**9
ans = [([0] * n) for i in range(3)]
curr = ["R", "G", "B"]
for l in range(3):
z = l
for j in range(n):
if s[j... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING STRING STRING... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin, stdout
inp = stdin.readline
for _ in range(int(inp())):
n, k = map(int, inp().split())
a, b, c, ans = [0], [0], [0], 200000.0 + 5
s = inp()
for i in range(n):
a.append(a[-1] + (s[i] != "RGB"[i % 3]))
b.append(b[-1] + (s[i] != "GBR"[i % 3]))
c.append(c[-1] ... | 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 VAR VAR VAR LIST NUMBER LIST NUMBER LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING BIN_OP VAR NUMB... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | def two(x):
for i in range(len(x) - 1):
if x[i] == "R" and x[i + 1] == "G":
return 0
elif x[i] == "G" and x[i + 1] == "B":
return 0
elif x[i] == "B" and x[i + 1] == "R":
return 0
return 1
t = int(input())
for i in range(t):
n, k = map(int, input(... | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING RETURN NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING RETURN NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.