description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | import sys
n = int(input())
l = list(map(int, input().split()))
a = [0] * (n - 1)
for i in range(n - 1):
a[i] = abs(l[i] - l[i + 1]) * (-1) ** i
if n == 2:
print(a[0])
sys.exit()
a1 = [0] * (n - 2)
for i in range(1, n - 1):
a1[i - 1] = abs(l[i] - l[i + 1]) * (-1) ** (i - 1)
ans = a[0]
cur = a[0]
for i ... | IMPORT 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | def m(q):
s = 0
an = 0
for i in range(len(q)):
s += q[i]
if s < 0:
s -= q[i]
an = max(s, an)
s = 0
an = max(s, an)
an = max(s, an)
return an
n = int(input())
a = [int(x) for x in input().split()]
z = []
y = []
p = -1
for i in range(0, n -... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR V... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | n = int(input())
arr = list(map(int, input().split(" ")))
arr.insert(0, 0)
diff_arr = []
end_so_far = 0
max_so_far = 0
l = 1
for i in range(2, len(arr) - 1):
temp = abs(arr[i] - arr[i + 1])
diff_arr.append(temp * pow(-1, i))
end_so_far = end_so_far + diff_arr[-1]
if end_so_far < 0:
if i % 2 == 0... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | n = int(input())
a = list(map(int, input().split()))
da, p = [], 1
for i in range(n - 1):
da.append(p * abs(a[i] - a[i + 1]))
p *= -1
m1, m2, s1, s2 = 0, 0, 0, 0
for x in da:
s1 += x
if s1 < 0:
s1 = 0
s2 -= x
if s2 < 0:
s2 = 0
m1 = max(m1, s1)
m2 = max(m2, s2)
print(max(m... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR ... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | def maxSubArraySum(a, size):
max_so_far = -9999999999999 - 1
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
ret... | FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN 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 FOR VAR... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | def ii():
return int(input())
def si():
return input()
def mi():
return map(int, input().split())
def msi():
return map(str, input().split())
def li():
return list(mi())
n = ii()
a = li()
dp = [[0, 0] for i in range(n)]
for i in range(1, n):
curr = abs(a[i] - a[i - 1])
if dp[i - 1]... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FU... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
d = [0] * n
c = [0] * n
e = [0] * n
x = 1
mx = 0
for i in range(1, n):
d[i] = abs(a[i] - a[i - 1])
for i in range(1, n):
c[i] = max(0, c[i - 1] + d[i] * x)
e[i] = max(0, e[i - 1] + d[i] * -x)
mx = max(mx, max(c[i... | 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_C... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | lectura = lambda: map(int, input().split())
n = list(lectura())[0]
lista = list(lectura())
fDescrita = 0
alt1 = 1
maxV1 = 0
maxV2 = 0
C1 = 0
C2 = 0
for i in range(0, n - 1):
fDescrita = abs(lista[i] - lista[i + 1]) * alt1
maxV1 = max(maxV1 + fDescrita, fDescrita)
maxV2 = max(maxV2, maxV1)
alt1 = alt1 * ... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | from sys import stdin, stdout
n = int(stdin.readline().rstrip())
a = [int(q) for q in stdin.readline().rstrip().split()]
fOdd = []
fEven = []
for i in range(n - 1):
fOdd.append(abs(a[i] - a[i + 1]) * (-1) ** i)
fEven.append(abs(a[i] - a[i + 1]) * (-1) ** (i - 1))
index = 0
fOddCurrent = 0
fEvenCurrent = 0
fMax... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL V... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | def kadane(A):
if len(A) == 0:
return 0
max_c = A[0]
max_g = A[0]
for i in range(1, len(A)):
max_c = max(A[i], max_c + A[i])
if max_c > max_g:
max_g = max_c
return max_g
def answer(n, A):
b = []
for i in range(0, n - 1):
x = abs(A[i] - A[i + 1]) ... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | N = int(input())
L = list(map(int, input().split()))
if N == 2:
print(abs(L[0] - L[1]))
exit()
M = []
for i in range(N - 1):
M.append(abs(L[i] - L[i + 1]))
M1 = [0]
flg = True
for i in range(N - 1):
if flg:
M1.append(M1[-1] + M[i])
else:
M1.append(M1[-1] - M[i])
flg = not flg
M2 ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR ... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | n = int(input())
l = list(map(int, input().split(" ")))
d = []
for i in range(n - 1):
a = 1
if i % 2:
a = -1
d.append(a * abs(l[i] - l[i + 1]))
s, b = 0, 0
sm, bm = 0, 0
for i in range(n - 1):
s = max(d[i], s + d[i])
b = max(s, b)
for i in range(1, n - 1):
sm = min(d[i], sm + d[i])
b... | 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 LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VA... |
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as... | n = int(input())
a = list(map(int, input().split()))
d = [(abs(a[i] - a[i + 1]) * (-1) ** i) for i in range(n - 1)]
maxsum1 = 0
sum1 = 0
for di in d:
if di > 0 or abs(di) < abs(sum1):
sum1 += di
else:
sum1 = 0
maxsum1 = max(maxsum1, abs(sum1))
sum1 = 0
for di in d[1:]:
if di < 0 or abs(d... | 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 FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL V... |
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $T$ seconds after coming.
Fortunately, Adilbek can spend time wit... | mod = 10**9 + 7
MAX = 2 * 10**5 + 1
r = [1] * MAX
factorial = [1] * MAX
rfactorial = [1] * MAX
rp = [1] * MAX
for i in range(2, MAX):
factorial[i] = i * factorial[i - 1] % mod
r[i] = mod - mod // i * r[mod % i] % mod
rfactorial[i] = rfactorial[i - 1] * r[i] % mod
for i in range(1, MAX):
rp[i] = rp[i - 1... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP V... |
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $T$ seconds after coming.
Fortunately, Adilbek can spend time wit... | MOD = 10**9 + 7
MAX = 5 * 10**5
fac, ifac, ipow2 = [1] * MAX, [1] * MAX, [1] * MAX
for i in range(1, MAX):
fac[i] = fac[i - 1] * i % MOD
ifac[i] = pow(fac[i], MOD - 2, MOD)
ipow2[i] = ipow2[i - 1] * (MOD + 1) // 2 % MOD
choose = lambda n, k: fac[n] * ifac[k] % MOD * ifac[n - k] % MOD
n, t = map(int, input()... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR ... |
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $T$ seconds after coming.
Fortunately, Adilbek can spend time wit... | mod = 10**9 + 7
MAX = 2 * 10**5 + 2
n, T = list(map(int, input().split()))
t = [0]
t += list(map(int, input().split()))
t += [MAX]
r = [1] * MAX
factorial = [1] * MAX
rfactorial = [1] * MAX
rp = [1] * MAX
sim = 0
sim_n = 0
sim_k = 0
E = 0
S = [t[0]] * len(t)
for i in range(1, len(t)):
S[i] = S[i - 1] + t[i]
for i i... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BI... |
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $T$ seconds after coming.
Fortunately, Adilbek can spend time wit... | from sys import exit, stdin, stdout
mod = 10**9 + 7
def modinv(x):
return pow(x, mod - 2, mod)
N = 2 * 10**5 + 10
facts = [1] * N
for i in range(1, N):
facts[i] = facts[i - 1] * i
facts[i] %= mod
def binom(n, k):
ans = modinv(facts[k]) * modinv(facts[n - k])
ans %= mod
ans *= facts[n]
... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC... |
There are N dominoes in a line, and we place each domino vertically upright.
In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
After each second, each domino that is falling to the left pushes the adjacent domino on the left.
Similarly, the dominoes falling to the right ... | class Solution:
def pushDominoes(self, dominoes: str) -> str:
l = len(dominoes)
right_force = [0] * l
left_force = [0] * l
force1 = 0
force2 = 0
for i in range(l):
if dominoes[i] == "R":
force1 = l
elif dominoes[i] == "L":
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FOR VAR... |
There are N dominoes in a line, and we place each domino vertically upright.
In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
After each second, each domino that is falling to the left pushes the adjacent domino on the left.
Similarly, the dominoes falling to the right ... | class Solution:
def pushDominoes(self, dominoes: str) -> str:
forces = [0] * len(dominoes)
max_force = len(dominoes)
force = 0
for i, d in enumerate(dominoes):
if d == "R":
force = max_force
elif d == "L":
force = 0
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FU... |
There are N dominoes in a line, and we place each domino vertically upright.
In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
After each second, each domino that is falling to the left pushes the adjacent domino on the left.
Similarly, the dominoes falling to the right ... | INF = float("inf")
class Solution:
def pushDominoes(self, dominoes: str) -> str:
n = len(dominoes)
d1 = [-1] * n
d2 = [-1] * n
cnt = INF
for i in range(n - 1, -1, -1):
if dominoes[i] == "L":
cnt = 0
elif dominoes[i] == ".":
... | ASSIGN VAR FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR A... |
There are N dominoes in a line, and we place each domino vertically upright.
In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
After each second, each domino that is falling to the left pushes the adjacent domino on the left.
Similarly, the dominoes falling to the right ... | class Solution:
def pushDominoes(self, dominoes: str) -> str:
n = len(dominoes)
d = [0] * n
force = 0
for i in range(n):
c = dominoes[i]
if c == "R":
force = n
elif c == "L":
force = 0
else:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP V... |
There are N dominoes in a line, and we place each domino vertically upright.
In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
After each second, each domino that is falling to the left pushes the adjacent domino on the left.
Similarly, the dominoes falling to the right ... | class Solution:
def pushDominoes(self, dominoes: str) -> str:
n = len(dominoes)
balance = [0] * len(dominoes)
b = 0
for index, c in enumerate(dominoes):
if c == "R":
b = n
elif c == "L":
b = 0
else:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, string, k):
def findsubs(maxK):
n = len(string)
normal = {}
dist_cnt = 0
subs = 0
s, e = 0, 0
while e < n:
normal[string[e]] = 1 + normal.get(string[e], 0)
if norma... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUM... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
last, ts = [-1] * 26, []
ans = 0
for i, c in enumerate(s):
v = ord(c) - 97
if last[v] >= 0:
ts.remove(last[v])
last[v] = i
ts.append(i)
M = len(ts)
if M > k:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUM... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
def util(s, k):
if not s:
return 0
mapp = {}
num = 0
left = 0
for i in range(len(s)):
mapp[s[i]] = mapp.get(s[i], 0) + 1
while len(mapp) > k:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | def find(s, k):
c = 0
d = {}
si = 0
dcc = 0
n = len(s)
for i in range(n):
if s[i] in d:
d[s[i]] += 1
else:
d[s[i]] = 1
dcc += 1
while dcc > k:
d[s[si]] -= 1
if d[s[si]] == 0:
dcc -= 1
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
ans = self.solve(s, k) - self.solve(s, k - 1)
return ans
def solve(self, s, k):
dict1 = {}
count = 0
j = 0
for i in range(len(s)):
if s[i] in dict1:
dict1[s[i]] += 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
return self.getAtmost(s, k) - self.getAtmost(s, k - 1)
def getAtmost(self, s, k):
freqMap = {}
right = left = 0
countSubString = 0
while right < len(s):
freqMap[s[right]] = freqMap.get(s[right], 0) + 1
... | CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
return self.counts(s, k) - self.counts(s, k - 1)
def counts(self, s, k):
m = dict()
count = 0
i = 0
j = 0
while j < len(s):
if s[j] in m:
m[s[j]] += 1
else:
m[s[... | CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBE... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def solve(self, s, k):
i = 0
j = 0
dis_cou = 0
hash_arr = [0] * 26
ans = 0
while j < len(s):
if hash_arr[ord(s[j]) - ord("a")] == 0:
dis_cou += 1
hash_arr[ord(s[j]) - ord("a")] += 1
while dis_cou > k... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER WHILE VAR VAR VAR BIN_OP FUN... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
smallhash = {}
biggerhash = {}
idx = 0
i = 0
j = 0
res = 0
while idx < len(s):
while i < len(s) and not (
len(smallhash) == k - 1 and s[i] not in smallhash
):
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VA... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def solve(self, s, k):
ans = 0
i, j = -1, -1
h = {}
while True:
while i < len(s) - 1:
i += 1
h[s[i]] = h.get(s[i], 0) + 1
if len(h) <= k:
ans += i - j
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT WHILE NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR WHILE... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
def lek(s, k):
i, j = 0, 0
res = 0
dictionary = dict()
while j < len(s):
if s[j] in dictionary:
dictionary[s[j]] += 1
else:
dictionary[s[j]] ... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
n = len(s)
if k > n:
return 0
i = 0
j = 1
d = {s[0]: 1}
di = {s[0]: 0}
r = 1
res = 0
if k == 1:
res = 1
while i <= j and j < n:
if s[j] not in di:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
ans, st, dp = 0, 0, {}
last = 0
for e in range(len(s)):
dp[s[e]] = dp.get(s[e], 0) + 1
if len(dp) > k:
ei, n = st, {}
while len(dp) > k:
n[s[ei]] = n.get(s[ei], 0) + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR DICT WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHIL... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
length = len(s)
ans = 0
ib = -1
ism = -1
mapB = {}
mapS = {}
j = -1
if k == 1:
ans = 0
lastChar = s[0]
lastIndex = 0
for i in range(len(s)):
c... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
return self.solve(s, k) - self.solve(s, k - 1)
def solve(self, s, k):
ans = distCnt = release = 0
mp = {}
for aquire in range(len(s)):
currChar = s[aquire]
if currChar in mp:
mp[currChar] += 1
... | CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | def f(A, k):
n = len(A)
i = 0
j = 0
freq = [0] * 26
d = 0
ans = 0
while j < n:
o = ord(A[j]) - ord("a")
freq[o] += 1
if freq[o] == 1:
d += 1
while d > k:
o = ord(A[i]) - ord("a")
freq[o] -= 1
if freq[o] == 0:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
def solve(st, k):
mp = dict()
s = set()
l = 0
ans = 0
for r in range(len(st)):
if st[r] not in mp.keys():
mp[st[r]] = 1
else:
mp[... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def solve(self, s, k):
d = {}
n = len(s)
i, j = 0, 0
count = 0
while j < n:
d[s[j]] = d.get(s[j], 0) + 1
while len(d) > k:
d[s[i]] -= 1
if d[s[i]] == 0:
del d[s[i]]
i ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMB... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def count(self, s, n, k):
m = {}
j = 0
c = 0
for i in range(n):
if s[i] in m:
m[s[i]] += 1
else:
m[s[i]] = 1
while len(m) > k:
m[s[j]] -= 1
if m[s[j]] == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RET... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
st = {x: (0) for x in "abcdefghijklmnopqrstuvwxyz"}
i = 0
c = 0
c1 = 0
for j in range(len(s)):
st[s[j]] += 1
if st[s[j]] == 1:
c += 1
while c > k:
st[s[i]] -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR V... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
def countStrings(diff):
if diff == 0:
return 0
left = 0
right = 0
count = 0
dicti = {}
while right < len(s):
if s[right] in dicti:
dicti[... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def countAtMostK(self, s, k):
start = end = ans = 0
mp = {}
while end < len(s):
if s[end] in mp.keys():
mp[s[end]] += 1
else:
mp[s[end]] = 1
while len(mp) > k:
mp[s[start]] -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def substrCount(self, s, k):
if k == 1:
n = len(s)
c = 1
f = 0
for i in range(n - 1):
if s[i] == s[i + 1]:
c += 1
else:
f += c * (c + 1) // 2
c = 1
... | CLASS_DEF FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR DICT... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | class Solution:
def at_most_k(self, s, k):
n = len(s)
count = 0
freq = {}
start = end = 0
while end < n:
ch = s[end]
freq[ch] = freq.get(ch, 0) + 1
while len(freq) > k:
ch = s[start]
freq[ch] -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_... |
Given a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.
Example 1:
Input:
S = "aba", K = 2
Output:
3
Explanation:
The substrings are:
"ab", "ba" and "aba".
Example 2:
Input:
S = "abaaca", K = 1
Output:
7
Explanation:
The substrings are:
... | def atmost(s, k):
n = len(s)
if n == 0:
return 0
d = {}
x = 0
y = 0
for i in range(n):
if s[i] not in d:
d[s[i]] = 1
else:
d[s[i]] += 1
while len(d) > k:
d[s[y]] -= 1
if d[s[y]] == 0:
d.pop(s[y])
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_O... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in range(int(input())):
n, h = map(int, input().split())
a = list(map(int, input().split()))
mi = a[0]
ma = a[0]
a = a[1:]
s = 1
for x in a:
mi = max(x, mi - h + 1)
ma = min(x + h - 1, ma + h - 1)
if ma < mi:
s = 0
if mi != a[-1]:
s = 0
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def solve():
[n, k] = map(int, input().split(" "))
h = list(map(int, input().split(" ")))
assert len(h) == n
assert n >= 2
lo = h[0] + 1
hi = lo
def bnd(x, xmin, xmax):
return min(xmax, max(xmin, x))
for i in range(1, n):
new_lo = lo - (k - 1)
new_hi = hi + (k -... | FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | from sys import stdin
def main():
from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
n, k = map(int, input().split())
(*h,) = map(int, input().split())
mn = [0] * n
mx = [0] * n
mn[0] = mx[0] = h[0]
for i in range(1, n):
... | 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 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 NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | t = int(input())
for i in range(t):
n, k = tuple(map(int, input().split(" ")))
heights = list(map(int, input().split(" ")))
current_floor_range = [heights[0], heights[0]]
is_possible = True
for j in range(1, n):
current_floor_range = [
max(current_floor_range[0] - k + 1, heights[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIS... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | t = int(input())
for i in range(t):
l = input().split(" ")
n, k = int(l[0]), int(l[1])
l = input().split(" ")
for j in range(n):
l[j] = int(l[j])
lastbl = l[0]
lastbh = l[0]
isok = True
for j in range(1, n - 1):
if lastbh + (k - 1) < l[j]:
isok = False
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in " " * int(input()):
n, k = map(int, input().split())
(*h,) = map(int, input().split())
min_hs = [h[0]] * n
max_hs = [h[0]] * n
for i in range(1, n):
min_touch = min_hs[i - 1] - k + 1
max_touch = max_hs[i - 1] + k - 1
min_ground = h[i]
max_ground = h[i] + k - ... | FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
prev = h[0]
con = 0
for i in range(1, n - 1):
if h[i] > h[i - 1]:
if prev + k > h[i]:
if h[i + 1] > h[i]:
if h[i] + k - 1 < prev + k:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def buildFence():
lowest, highest = heights[0], heights[0]
for i in range(1, n - 1):
newLow, newHigh = heights[i], heights[i] + k - 1
if newHigh + k <= lowest or newLow >= highest + k:
return False
newLow += max(0, lowest + 1 - newLow - k)
newHigh -= max(0, newHigh + ... | FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR N... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return a * b / gcd(a, b)
def main():
for _ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
currmax = h[0] + k
... | IMPORT ASSIGN VAR VAR 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 FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
d = [[-1, -1] for i in range(n)]
d[0] = [h[0], h[0]]
ans = "YES"
for i in range(1, len(h)):
d[i] = [
max(h[i], d[i - 1][0] - (k - 1)),
min(h[i] + (k - 1), d[i - 1][1... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FU... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def solve(arr, k):
n = len(arr)
preL, preH = arr[0] + k, arr[0] + k
for i in range(1, n - 1):
lo = preL - k + 1
hi = preH + k - 1
if lo - k >= arr[i] + k or hi <= arr[i]:
return "NO"
preL, preH = max(lo, arr[i] + k), min(hi, arr[i] + 2 * k - 1)
if preL > p... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in range(int(input())):
n, k = list(map(int, input().split()))
h = [int(i) for i in input().split()]
s = "YES"
hh = hl = h[0]
for i in range(1, n):
hh = min(hh + k - 1, h[i] + k - 1)
hl = max(hl - k + 1, h[i])
if hh < hl:
s = "NO"
break
if hl... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def getints():
return list(map(int, input().split()))
def solve():
n, k = getints()
k1 = k - 1
hi, *hlist = getints()
lo = hi
for h in hlist[:-1]:
lo, hi = max(lo - k1, h), min(hi + k1, h + k1)
if hi < lo:
return "NO"
if lo - k1 <= hlist[-1] <= hi + k1:
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN STRING I... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for y in range(int(input())):
n, m = map(int, input().split())
lst = list(map(int, input().split()))
flag = 0
if n == 1:
print("YES")
continue
minstart = maxstart = 0
for i in range(n):
if i == 0:
minstart = lst[0]
maxstart = lst[0]
min... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSI... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
start = [max(a[0] - k + 1, 0), a[0] + k - 1]
ok = True
for i in range(1, n):
if not ok:
break
if i != n - 1:
p1 = a[i] + k - 1
p2 = a[i]
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL V... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def readInt():
return int(input())
def readLine():
return [int(s) for s in input().split(" ")]
def readString():
return input()
def ask(arr, k):
pLow = arr[0]
pHigh = arr[0]
for i in range(len(arr)):
t = arr[i]
pLow = pLow - (k - 1)
pHigh = pHigh + (k - 1)
i... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
flag = False
lo = h[0] - k + 1
hi = h[0] + k - 1
for i in range(1, n):
if h[i] > hi or h[i] + k <= lo:
flag = True
break
lo = max(lo - k + 1, h[i] - k + 1)
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR I... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | t = int(input())
for testCaseCounter in range(t):
splitted = [int(amit) for amit in input().split(" ")]
n = splitted[0]
k = splitted[1]
arr = [int(amit) for amit in input().split(" ")]
lowestStartingPoint = arr[0]
highestStartingPoint = arr[0]
valid = True
for i in range(1, n):
l... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | case = int(input())
for c in range(case):
n, k = map(int, input().split())
myList = list(map(int, input().split()))
mini = myList[0]
maxi = myList[0]
ok = True
for ind1 in range(1, len(myList)):
mini = max(myList[ind1], mini - (k - 1))
maxi = min(myList[ind1] + k - 1, maxi + k - ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL V... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = a[0]
h = a[0] + k
ans = "YES"
for i in range(1, n - 1):
t1 = a[i] + 2 * k - 1
if t1 <= l or h <= a[i]:
ans = "NO"
l = max(l - k + 1, a[i])
h = ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | from sys import stdin
nii = lambda: map(int, stdin.readline().split())
lnii = lambda: list(map(int, stdin.readline().split()))
t = int(input())
for tt in range(t):
n, k = nii()
h = lnii()
min_h = h[0]
max_h = h[0] + k
for i in range(1, n):
if i < n - 1:
if h[i] > max_h - 1:
... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMB... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n, k = map(int, input().split())
A = list(map(int, input().split()))
MIN = A[0]
MAX = A[0]
flag = 1
for i in range(1, n):
h = A[i]
NMIN = max(h, MIN - (k - 1))
NMAX = min(MAX + (k - 1), h + (k ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [a[0]]
c = [a[-1]]
d = []
for x in a[1:]:
b.append(min(b[-1] + k - 1, x + k - 1))
for x in reversed(a[:-1]):
c.append(min(c[-... | 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR N... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for ___ in range(int(input())):
n, k = list(map(int, input().split()))
hs = list(map(int, input().split()))
rg = [-2, 10**9]
ok = True
for i, h in enumerate(hs):
if i == 0 or i == len(hs) - 1:
rgn = [h, h + k]
else:
rgn = [h, h + k + k - 1]
rg = [max(0... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR V... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | nt = int(input())
for i in range(nt):
[n, k] = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
mins = h
maxs = [(x + k - 1) for x in h]
maxs[0] = h[0]
maxs[n - 1] = h[n - 1]
good = [1]
def update(i, fmin, fmax):
dif = 0
if fmin > mins[i]:
... | 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
ans = "YES"
min_1 = h[0] - (k - 1)
max_1 = h[0] + (k - 1)
for i in range(1, n):
min_2 = h[i]
if i == n - 1:
... | 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FU... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
l = list(map(int, input().split()))
minn = [l[0]]
maxx = [l[0]]
for i in range(1, n):
minnn = max(l[i], minn[i - 1] - k + 1)
maxxx = min(l[i] + k - 1, maxx[i - 1] + k - 1)
minn.append(minnn)
maxx.app... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
for _ in range(int(input())):
n, k = map(int, sys.stdin.readline().split())
h = [int(i) for i in sys.stdin.readline().split()]
flag = 1
available_interval = [h[0] + 1, h[0] + 1]
for h_i in h:
available_interval = [
max(h_i + 1, available_interval[0] - k + 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER BIN_O... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for test in range(int(input())):
_, k = list(map(int, input().split()))
h = list(map(int, input().split()))
if len(h) == 2:
if abs(h[0] - h[1]) <= k - 1:
print("YES")
else:
print("NO")
else:
placement = h[0]
for i, h_i in list(enumerate(h)):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | t = int(input())
for i in range(t):
n, k = list(map(int, input().split()))
heights = list(map(int, input().split()))
min_pos = heights[0]
max_pos = heights[0]
possible = True
for j in range(1, n):
min_pos = min_pos - k + 1
max_pos = max_pos + k - 1
if max_pos >= heights[j... | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
b = [h[0]]
flag = True
for i in range(1, n - 1):
min_must_base = max(0, b[i - 1] - (k - 1))
max_must_base = b[i - 1] + (k - 1)
min_can_bas... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | from sys import stdin
for _ in range(int(input())):
n, k = list(map(int, input().split()))
lst = list(map(int, input().split()))
bot, top = lst[0], lst[0]
for i in range(1, n):
bot = max(0, max(lst[i], bot - k + 1))
top = min(lst[i] + k - 1, top + k - 1)
if bot > top:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP B... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
lines = []
for line in sys.stdin:
lines.append(line.rstrip("\n"))
t = int(lines[0])
for i in range(1, 2 * t + 1, 2):
n, k = map(int, lines[i].split(" "))
h = list(map(int, lines[i + 1].split(" ")))
m, M = h[0], h[0]
for j in range(1, n):
M = min(h[j] + k - 1, M + k - 1)
m... | IMPORT ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING A... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | class minmax:
def __init__(self, min_, max_):
self.min_ = min_
self.max_ = max_
def lop():
n, k = map(int, input().split())
h = input().split()
this_range = minmax(0, 0)
prev_range = minmax(0, 0)
for i in range(n):
if i == 0 or i == n - 1:
this_range = minm... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_O... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
h = list(map(int, input().split()))
ans = 1
lb, ub = h[0], h[0]
for i in range(1, n):
lb_next = h[i]
ub_next = h[i] + k - 1
lb_next = max(lb - (k - 1), lb_next)
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR AS... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | input = __import__("sys").stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
D = [*map(int, input().split())]
min_height = [0] * n
max_height = [0] * n
min_height[0] = D[0]
max_height[0] = D[0]
min_height[n - 1] = D[n - 1]
max_height[n - 1] = D[n - 1]
for i... | ASSIGN VAR 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 LIST 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 NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMB... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def Fence(ground, k):
max_fence_last = ground[0] + k
min_fence_last = ground[0]
for i in range(1, len(ground)):
max_f = min(max_fence_last + k - 1, ground[i] + k + k - 1)
min_f = max(min_fence_last - k + 1, ground[i])
if max_f - min_f < k:
return "NO"
max_fence_la... | FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR RETURN STRING ASSIGN VAR VA... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def cmp(a, h):
return [max(a[0], h[0]), min(a[1], h[1])]
t = input()
for _ in range(int(t)):
sign = 0
n, k = input().split(" ")
n = int(n)
k = int(k)
height = input().split(" ")
height = [int(he) for he in height]
now = [height[0], height[0]]
for i in range(1, n):
tem = (
... | FUNC_DEF RETURN LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRIN... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
def solve():
n, k = map(int, input().split())
H = list(map(int, input().split()))
lo, hi = H[0] + k, H[0] + k
for i in range(1, n - 1):
lo, hi = max(H[i] + k, lo - (k - 1)), min(H[i] + 2 * k - 1, hi - 1 + k)
if lo > hi:
return "NO"
... | IMPORT ASSIGN VAR VAR 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 ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
for nt in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
ans = "YES"
minn = h[0]
maxx = h[0]
for i in range(1, n):
minn = max(h[i], minn - k + 1)
maxx = min(h[i] + k - 1, maxx + k - 1)
if ma... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | R = lambda: map(int, input().split())
(t,) = R()
for _ in [0] * t:
n, k = R()
l, *a, e = R()
h = l
f = 1
for x in a:
l = max(l - k + 1, x)
h = min(h, x) + k - 1
f &= l <= h
print("NYOE S"[f & (l - k < e < h + k) :: 2]) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def intersection(seg1, seg2):
if seg1[0] <= seg2[0]:
if seg1[1] < seg2[0]:
return False
elif seg1[1] <= seg2[1]:
return [seg2[0], seg1[1]]
else:
return [seg2[0], seg2[1]]
elif seg1[0] > seg2[1]:
return False
elif seg1[1] >= seg2[1]:
... | FUNC_DEF IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN LIST VAR NUMBER VAR NUMBER RETURN LIST VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN LIST VAR NUMBER VAR NUMBER RETURN LIST VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL V... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for __ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
status = 1
dom1, dom2 = [h[0] + 1 - k, h[0] + k - 1], []
if dom1[0] < 0:
dom1[0] = 0
for i in range(1, n):
if i != n - 1:
dom2 = [h[i], h[i] + k - 1]
else:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER LIST IF VAR NUMBER NUMBER ASSIGN VAR... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
h = list(map(int, input().split()))
minh = [h[0] + k] + [(0) for i in range(n - 1)]
maxh = [h[0] + k] + [(0) for i in range(n - 1)]
flag = True
for i in range(1, n - 1):
if h[i] >= maxh[i - 1] or h[i] + 2 * k - 1 <= min... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VA... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
def solve():
n, k = map(int, input().split())
H = list(map(int, input().split()))
lv = [-1] * n
lv[0], lv[-1] = H[0] + k, H[-1] + k
idx = 1
while idx < n:
while idx < n and H[idx] >= H[idx - 1]:
idx += 1
peak = idx - 1
... | IMPORT ASSIGN VAR VAR 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for _ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
lo = list(h)
hi = [(i + k - 1) for i in h]
hi[0] = lo[0]
hi[n - 1] = lo[n - 1]
valid = True
for i in range(1, n):
a = lo[i - 1] - k + 1
b = hi[i - 1] + k - 1
if a > ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
try:
sys.stdin = open("input.txt", "r")
except FileNotFoundError:
pass
def next_array():
return [int(i) for i in input().split()]
def prefix(lst):
assert len(lst)
pre = [lst[0]]
for i in range(1, len(lst)):
pre.append(lst[i] + pre[i - 1])
return pre
def solve():
... | IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR AS... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
h = list(map(int, input().split()))
lst = [0] * n
lst[0] = h[0]
for i in range(1, n - 1):
if h[i] - lst[i - 1] >= k or lst[i - 1] - h[i] > 2 * (k - 1):
print("NO")
br... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def sv():
N, K = map(int, input().split())
H = list(map(int, input().split()))
a, b = 0, 10000000000
for n, h in enumerate(H):
a = max(a, h)
b = min(b, h + K - 1 if n > 0 and n < N - 1 else h)
if a > b:
return False
a -= K - 1
b += K - 1
return Tru... | 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 ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | for i in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = 0
x = a[0]
for j in range(1, n):
if a[j] <= a[j - 1]:
x = max(a[j], x - k + 1)
if a[j] > a[j - 1]:
x = a[j]
if x - a[j] >= k:
c = c + 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP ... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | def solution(n, k, h):
minn = h[0]
maxx = h[0]
for i in range(1, n):
minn = max(h[i], minn - k + 1)
maxx = min(maxx + k - 1, h[i] + k - 1)
if minn > maxx:
return "NO"
if not (h[n - 1] >= minn and h[n - 1] <= maxx):
return "NO"
return "YES"
for i in range... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN STRING IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR RETUR... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
n, k = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
mx = s[0] + k
mn = s[0] + k
f = True
for i in range(1, n - 1):
if mx <= s[i] or mn - k + 1 > s[i] + k + k ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL... |
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ... | import sys
input = sys.stdin.readline
def intersect(a, b):
return [max(a[0], b[0]), min(a[1], b[1])]
t = int(input())
for you in range(t):
l = input().split()
n = int(l[0])
k = int(l[1])
l = input().split()
li = [int(i) for i in l]
curr = [li[0], li[0]]
poss = 1
for i in range(1... | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.