description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
pref = [0]
for i in a[: k - 1]:
pref.append(pref[-1] + i)
ans = 0
for i, num in enumerate(pref):
cur_ans = 0
_p = p
if _p >= num:
_... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMB... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for t in range(int(input())):
n, p, k = map(int, input().split())
a = [0] + sorted(list(map(int, input().split())))
dp = [(-1) for i in range(n + 1)]
dp[0] = p
for i in range(1, n + 1):
if i - k < 0:
dp[i] = max(dp[i], dp[i - 1] - a[i])
else:
dp[i] = max(dp[i]... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | def check(costs, k, bought):
res = 0
while bought > 0:
res += costs[bought - 1]
if bought >= k:
bought -= k
else:
bought -= 1
return res
t = int(input())
for _ in range(t):
n, p, k = list(map(int, input().split(" ")))
costs = sorted(list(map(int, inp... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for test in range(t):
n, p, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
sum1 = [0] * (n + 1)
ans = 0
sum1[0] = 0
sum1[1] = l[0]
if sum1[1] <= p:
ans = 1
for i in range(2, k):
sum1[i] = sum1[i - 1] + l[i - 1]
if s... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for h in range(int(input())):
n, p, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.sort()
a.insert(0, 0)
price = p
maxi = 0
for i in range(k):
if a[i] <= price:
p -= a[i]
price = p
j = i + k
goods = ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in [0] * int(input()):
n, p, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
pref = 0
ans = 0
for i in range(k + 1):
sum = pref
if sum > p:
break
cnt = i
for j in range(i + k - 1, n, k):
if sum + a[j] <= p:
... | FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | q = int(input())
def binarySearch(arr, l, r, x):
if 1 <= len(arr[l : r + 1]) <= 2:
return l
if r >= l:
mid = int(l + (r - l) / 2)
if arr[mid] == x:
return mid
elif arr[mid] > x:
return binarySearch(arr, l, mid - 1, x)
else:
return bin... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
leftMoney = [(0) for i in range(n)]
dp = [(0) for i in range(n)]
leftMoney[0] = p
for i in range(n):
if i >= k - 1:
if leftMoney[i] >= a[i]:
dp[i] = d... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
dp = [(10**10) for i in range(n + 1)]
dp[0] = 0
for i in range(1, n + 1):
dp[i] = min(dp[i], dp[i - 1] + a[i - 1])
if i >= k:
dp[i] = min(dp[i], d... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR V... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for i in range(t):
n, p, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l1 = []
c = 0
for i in range(n):
if i < k - 1:
c += l[i]
l1.append(c)
elif i == k - 1:
l1.append(l[i])
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_C... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.readline
a = int(input())
for i in range(a):
n, p, k = map(int, input().split())
z = list(map(int, input().split()))
z.sort()
ans = [0]
for i in range(len(z)):
ans.append(ans[-1] + z[i])
dp = [(0) for i in range(len(ans))]
for i in range(len(ans)):
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
dp = [0]
for i in range(k - 1):
dp.append(dp[-1] + a[i])
for i in range(k - 1, n):
dp.append(dp[i - k + 1] + a[i])
ans = 0
for i in range(1, n + 1):... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | def idp(a, dp, i, k):
if i - k >= 0:
return min(a[i] + dp[i - 1], a[i] + dp[i - k])
else:
return a[i] + dp[i - 1]
t = int(input())
for tc in range(t):
n, p, k = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
dp = [0] * n
dp[0] = a[0]
for i in r... | FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
t = int(input())
input = sys.stdin.readline
while t > 0:
t -= 1
n, p, k = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
dp = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
if i - k >= 0:
dp[i] = a[i - 1] + dp[i - k]
else:
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))
arr.sort()
ans = 0
tempans = 0
for qw in range(k):
ptemp = p
tempans = qw
for i in range(qw + k - 1, n, k):
ptemp -= arr[i]
if ptemp >= 0:... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | T = int(input())
for t in range(1, T + 1):
n, p, k = map(int, input().split())
values = sorted(list(map(int, input().split())))
cumsum = [0]
for i in range(k - 1):
cumsum.append(cumsum[-1] + values[i])
best = 0
for i in range(k):
ith_best = 0
mysum = cumsum[i]
if ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | T = int(input())
for _ in range(T):
n, amt, k = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
dp = [0] * (n + 1)
ans = 0
for i in range(n):
if i - k >= -1:
dp[i] = dp[i - k] + l[i]
else:
dp[i] = l[i] + dp[i - 1]
for i in r... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for o in range(t):
n, p, k = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.sort()
maxBundles = 1
c = p
ans = 0
while 1:
if maxBundles * k - 1 < len(a):
c -= a[maxBundles * k - 1]
else:
maxBundles -= 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.readline
t = int(input())
for testcases in range(t):
n, p, k = map(int, input().split())
A = sorted(map(int, input().split()))
S = [0] * (n + k + 3)
for i in range(k - 1):
S[i] = A[i] + S[i - 1]
for i in range(k - 1, n):
S[i] = S[i - k] + A[i]
ANS = ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
prefix_sums = [0]
for a_i in a[:k]:
prefix_sums.append(a_i + prefix_sums[-1])
max_goods = 0
for ind, start_sum in enumerate(prefix_sums):
balance = p - start_sum
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIG... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for i in range(t):
n, p, k = map(int, input().split())
goods = list(map(int, input().split()))
goods.sort()
if goods[0] > p:
print(0)
continue
elif len(goods) == 1:
print(1)
continue
sums = [[0]]
for i in range(k - 1):
sums.append([sum... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | T = int(input())
def solve():
[N, P, K] = list(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A)
dp = [float("inf") for _ in range(N)]
ans = 0
for i in range(N):
if i < K - 1:
if i == 0:
dp[i] = A[i]
continue
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | import sys
input = sys.stdin.readline
def inp():
return int(input().rstrip())
def inlt():
return list(map(int, input().rstrip().split()))
def insr():
s = input().rstrip()
return s[: len(s) - 1]
def invr():
return map(int, input().rstrip().split())
t = inp()
for _ in range(t):
n, p, k ... | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN ... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | a = int(input())
for i in range(a):
b, m, k = map(int, input().split(" "))
c = list(map(int, input().split(" ")))
c.sort()
cost = [0] * (b + 1)
for l in range(1, k):
cost[l] = c[l - 1] + cost[l - 1]
for j in range(k, b + 1):
cost[j] = cost[j - k] + c[j - 1]
for n in range(b +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VA... |
This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \le k \le n$.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$k$ of goods for the price of one" ... | t = int(input())
for j in range(t):
n, p, k = map(int, input().split())
l = input().split()
for j1 in range(len(l)):
l[j1] = int(l[j1])
l.sort()
ans = [(0) for i in range(len(l))]
ans[0] = l[0]
for i in range(1, k):
ans[i] = l[i] + ans[i - 1]
for i in range(k - 1, len(ans... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VA... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
begin = [-1] * n
end = [-1] * n
hurt = [-1] * n
adj = [[] for i in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
adj[u - 1].append(v - 1)
adj[v - 1].append(u - 1)
hurt[0] = 1
begin[0] = 0
stack = [0]
curr = 1
while s... | IMPORT ASSIGN VAR VAR ASSIGN VAR 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 LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
input = sys.stdin.buffer.readline
n, k = map(int, input().split())
edge = [[] for i in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
edge[u - 1].append(v - 1)
edge[v - 1].append(u - 1)
par = [-2] * n
par[0] = -1
tank = [0]
order = [0]
while tank:
p = tank.pop()
for e ... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUM... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def MI1():
return map(int1, sys.stdin.readline().split())
def LI():
return list(map(int, sys... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR 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... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, m = map(int, input().split())
a = [[] for i in range(n)]
for i in range(n - 1):
x, y = map(int, input().split())
a[x - 1].append(y - 1)
a[y - 1].append(x - 1)
ht = [(-1) for i in range(n)]
par = [(-1) for i in range(n)]
h = 0
stack = [0]
order = []
while stack:
node = stack.pop()
order.append(nod... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
s = [0]
d = [-1] * n
d[0] = 0
l = [-1] * n
while s:
p = s.pop()
if l[p] == -1:
s.append(p)
l[p] = -2
for node in g... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NU... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
roads = {}
nodes = {}
for _ in range(n - 1):
u, v = map(int, input().split())
roads.setdefault(u, set()).add(v)
roads.setdefault(v, set()).add(u)
proc = set()
proc_stack = [1]
in_stack = []
chlds = {}
while len(proc_stack) > 0:
node = proc_stack[-1]
if node not in pr... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
u = []
for i in range(n):
u.append([])
cnt = [0] * n
for i in range(n - 1):
a, b = map(int, input().split())
u[a - 1].append(b - 1)
u[b - 1].append(a - 1)
cnt[a - 1] += 1
cnt[b - 1] += 1
d = [n] * n
d[0] = 0
q = [0]
q0 = 0
par = [-1] * n
while len(q) > q0:
v ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_C... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
n, k = map(int, sys.stdin.readline().split())
edge = [
list(map(lambda x: int(x) - 1, sys.stdin.readline().split())) for _ in range(n - 1)
]
nbhd = [[] for _ in range(n)]
for x in edge:
nbhd[x[0]].append(x[1])
nbhd[x[1]].append(x[0])
son = [[] for _ in range(n)]
lev = [None] * n
des = [0] * n
le... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | from sys import *
input = stdin.readline
n, k = map(int, input().split())
graph = [set([]) for _ in range(n + 1)]
for _ in range(n - 1):
x, y = map(int, input().split())
graph[x].add(y)
graph[y].add(x)
dep, par, cn = [0] * (n + 1), [0] * (n + 1), 0
q, p = [1], []
vis = [0] * (n + 1)
vis[1] = 1
while q:
... | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
ints = (int(x) for x in sys.stdin.read().split())
def dfs(u):
value[u] = is_leave[u]
for v in G[u]:
if value[v] == None:
dfs(v)
value[u] += value[v]
return
n, k = (next(ints) for i in range(2))
G = [[] for i in range(n)]
for e in range(n - 1):
i, j = (next... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FOR VAR VAR VAR IF VAR VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | t = 1
for i in range(t):
n, k = [int(j) for j in input().split()]
vicini = [[] for j in range(n)]
for l in range(n - 1):
a, b = [int(j) for j in input().split()]
vicini[a - 1].append(b - 1)
vicini[b - 1].append(a - 1)
livello = [(0) for j in range(n)]
padre = [(0) for j in ra... | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BI... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split(" "))
k = n - k
arr = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split(" "))
arr[a - 1].append(b - 1)
arr[b - 1].append(a - 1)
visited = [False] * n
stack = [0]
height = [-1] * n
height[0] = 0
while stack:
temp = stack.pop()
for i in arr[temp]... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUM... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | from sys import setrecursionlimit, stdin, stdout
setrecursionlimit(10**5 + 5)
def dfs(graph, root, par, level, levelArr):
F = 0
c = 0
for i in graph[root]:
if i == par:
continue
F += 1
c += dfs(graph, i, root, level + 1, levelArr)
levelArr.append(level - c)
ret... | EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VA... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
lines = sys.stdin.readlines()
n, k = map(int, lines[0].strip().split(" "))
edges = {}
for i in range(1, n):
a, b = map(int, lines[i].strip().split(" "))
if a not in edges:
edges[a] = []
if b not in edges:
edges[b] = []
edges[a].append(b)
edges[b].append(a)
seen = set([1])... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR ASSIGN VAR VAR LIST IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_C... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
input = sys.stdin.readline
N, K = map(int, input().split())
d = [set() for _ in range(N + 1)]
for i in range(N - 1):
a, b = map(int, input().split())
d[a].add(b)
d[b].add(a)
d2 = [set() for _ in range(N + 1)]
stack = [1]
vs = set([1])
vs_dfs = list()
depth = [0] * (N + 1)
while stack:
v = st... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
LI = lambda: list(map(int, sys.stdin.readline().strip("\n").split()))
MI = lambda: map(int, sys.stdin.readline().strip("\n").split())
SI = lambda: sys.stdin.readline().strip("\n")
II = lambda: int(sys.stdin.readline().strip("\n"))
n, k = MI()
g = {i: [] for i in range(n + 1)}
for _ in range(n - 1):
u, v... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FUNC_CAL... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(lambda x: int(x) - 1, input().split())
G[u].append(v)
G[v].append(u)
order = []
par = [-1] * n
stack = [0]
while stack:
v = stack.pop()
order.append(v)
for c in G[v]:
if c != par[v]:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | from sys import stdin
input = stdin.readline
n, k = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for _ in range(n - 1)]
b = [[] for x in range(n)]
for u, v in a:
b[u - 1].append(v - 1)
b[v - 1].append(u - 1)
marked = [False] * n
depth = [0] * n
childs = [0] * n
stack = []
stack.appe... | ASSIGN 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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_O... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n, k = list(map(int, input().split()))
citydis = {}
for i in range(n - 1):
cityf, cityt = list(map(int, input().split()))
desf = citydis.get(cityf, [])
dest = citydis.get(cityt, [])
desf.append(cityt)
dest.append(cityf)
... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR LIST ASSIGN VAR FUNC_CALL VAR VAR LIST... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
E = [[] for _ in range(n + 1)]
for _ in range(n - 1):
a, b = map(int, input().split())
E[a].append(b)
E[b].append(a)
D = [0] * (n + 1)
P = [0] * (n + 1)
C = [0] * (n + 1)
def dfs(n, p, d):
D[n] = d
P[n] = p
for u in E[n]:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP V... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | from sys import stdin
inp = stdin.readline
n, industrial = [int(x) for x in inp().strip().split()]
adj = [[] for _ in range(n)]
for _ in range(n - 1):
v, u = [int(x) for x in inp().strip().split()]
adj[v - 1].append(u - 1)
adj[u - 1].append(v - 1)
bfs = [0]
parent = [(-1) for _ in range(n)]
for node in bfs... | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | from sys import stdin
input = stdin.readline
def dfs():
size = [0] * n
parent = [0] * n
depth = [0] * n
marked = [False] * n
stack = [0]
while stack:
node = stack[-1]
if marked[node]:
stack.pop()
if node != 0:
size[parent[node]] += size[... | ASSIGN VAR VAR FUNC_DEF 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 ASSIGN VAR LIST NUMBER WHILE VAR ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR V... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
gs = [[] for _ in range(n + 1)]
for _ in range(n - 1):
u, v = map(int, input().split())
gs[u].append(v)
gs[v].append(u)
q = [1]
ccnt = [0] * (n + 1)
ds = [None] * (n + 1)
ds[1] = 0
par = [0] * (n + 1)
par[1] = 0
while q:
u = q.pop()
if u < 0:
ccnt[par[-u]] +=... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = [int(x) for x in input().split(" ")]
edges = []
for i in range(n - 1):
edges.append(list(map(int, input().split(" "))))
for i in range(n - 1):
edges[i][0] -= 1
edges[i][1] -= 1
neighbours = []
for i in range(n):
neighbours.append(list())
for x in edges:
neighbours[x[0]].append(x[1])
neigh... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_C... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
g = [[] for i in range(n)]
for _ in range(n - 1):
x, y = map(int, input().split())
g[x - 1].append(y - 1)
g[y - 1].append(x - 1)
d = [-1] * n
d[0] = 0
q = [[-1, 0, 0]]
while q:
par, ver, cnt = q.pop()
for to in g[ver]:
if d[to] == -1:
d[to] = cnt ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n - 1):
u, v = map(lambda x: int(x) - 1, input().split())
g[u].append(v)
g[v].append(u)
lvl = {}
stack = [(0, 0)]
children = [[] for _ in range(n)]
while stack:
node, l = stack.pop()
lvl... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN V... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
readline = sys.stdin.readline
class Segtree:
def __init__(self, A, intv, initialize=True):
self.N = len(A)
self.N0 = 2 ** (self.N - 1).bit_length()
self.intv = intv
if initialize:
self.data = [intv] * self.N0 + A + [intv] * (self.N0 - self.N)
fo... | IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST VAR VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR B... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | i = lambda: map(int, input().split())
n, k = i()
e = [[] for i in range(n)]
for t in range(n - 1):
a, b = i()
a -= 1
b -= 1
e[b].append(a)
e[a].append(b)
d = [0] * n
c = [0] * n
p = [0] * n
s = [0]
while s:
a = s.pop()
for b in e[a]:
if b != p[a]:
s.append(b)
... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIS... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | def createGraph(arr, n):
graph = []
for _ in range(n):
graph.append([])
for x in arr:
x = x.split(" ")
u = int(x[0]) - 1
v = int(x[1]) - 1
graph[u].append(v)
graph[v].append(u)
return graph
def createTree(graph, n):
tree = []
p = [0] * n
p[0]... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
input = sys.stdin.readline
N, K = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = map(int, input().split())
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
Par = [-1] * N
que = []
childs = [0] * N
stack = [0]
Ind = [0] * N
D = [0] * N
while stack:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUM... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | import sys
input = sys.stdin.buffer.readline
n, k = map(int, input().split())
neig = [0] * n
lev = [0] * n
for i in range(n):
neig[i] = [0]
lev[i] = [-1]
lev[0][0] = 0
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
neig[a][0] += 1
neig[b][0] += 1
neig[a].append(b)... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER ASSIGN VAR VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_C... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = list(map(int, input().split()))
graph = [[] for i in range(n)]
weight = [None] * n
def dfs(graph):
global weight
stack = [0]
parents = [None] * n
children = [0] * n
curDep = -1
while len(stack):
s = stack[-1]
if weight[s] == None:
curDep += 1
weig... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NONE V... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
nodes = [[] for i in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
nodes[a - 1].append(b - 1)
nodes[b - 1].append(a - 1)
parents = [(-2) for i in range(n)]
parents[0] = -1
order = [0]
que = [0]
depth = [(0) for i in range(n)]
my_que = [0]
while len(my_que... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | def dfs():
while stack:
u, p, depth = stack.pop()
if not visited[u]:
visited[u] = True
stack.append((u, p, depth))
for v in adj[u]:
if v != p:
stack.append((v, u, depth + 1))
else:
for v in adj[u]:
... | FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VA... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n - 1):
i, j = map(lambda i: int(i) - 1, input().split())
g[i].append(j)
g[j].append(i)
q = [0]
c = [0] * n
p = [None] + [0] * (n - 1)
d = [0] + [None] * (n - 1)
while True:
i = q.pop()
if i == -1:
break
j = -(i +... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST ... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | n, k = map(int, input().split())
edge = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
edge[a].append(b)
edge[b].append(a)
order = []
par = [-1] * n
tank = [0]
dist = [-1] * n
dist[0] = 0
while tank:
pele = tank.pop()
order.append(pele)
for e... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR AS... |
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | def main():
for _ in range(1):
n, k = [int(x) for x in input().split()]
P = [[] for i in range(n + 1)]
T = [0] * (n + 1)
D = [0] * (n + 1)
for _ in range(n - 1):
a, b = [int(x) for x in input().split()]
P[a].append(b)
P[b].append(a)
... | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
a = input().split(" ")
a = [int(a[i]) for i in range(n)]
def calcHoleStranges(holes, m, pen1=True):
if m < 0:
return n
result = 0
if pen1:
holes_pen1 = [h for h in holes if h[1] == 1]
if len(holes_pen1) == 1:
hole = holes_pen1[0]
result = mi... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BI... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
odd = 0
even = 0
if n % 2:
odd = n // 2 + 1
even = n // 2
else:
odd = n // 2
even = n // 2
jugad = [
[[[(100) for i in range(2)] for j in range(50 + 2)] for k in range(50 + 2)]
for l in range(100 + 2)
]... | 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 NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIG... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def main():
n = int(input())
p = list(map(int, input().split()))
s = set(p)
cnt = [0, 0]
for i in range(1, n + 1):
if not i in s:
cnt[i % 2] += 1
m = {}
def eq(a, b):
if a == b:
return 0
else:
return 1
def solve(idx, even, odd... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NU... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
a = list(map(int, input().split()))
s = set(a)
rem_parity = [0, 0]
for i in range(1, n + 1):
if i not in s:
rem_parity[i % 2] += 1
inf = 10**9
dp = [[([inf] * 2) for _ in range(n)] for _ in range(n)]
rem = rem_parity[0] + rem_parity[1]
if a[0] != 0:
dp[0][rem_parity[0]][a[0] % 2] = 0
el... | ASSIGN VAR FUNC_CALL VAR 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 LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VA... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def calculate(ar, num):
s = 0
for x in range(len(ar)):
if num >= ar[x][0]:
num -= ar[x][0]
else:
s += 1 if ar[x][1] else 2
return s
def calculate1(ar, num):
s = calculate(ar, num)
ar1 = []
for x in range(len(ar)):
if ar[x][1]:
ar1.app... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER A... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | debug = 0
def solve(n, a, war):
mis = set(range(1, n + 1)).difference(a)
typ = [0, 0, 0]
typs = [[], [], []]
i = 0
juz = 0
while i < n:
if a[i] == 0:
j = i
while j < n and a[j] == 0:
j += 1
if i == 0 and j == n:
return... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR RE... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def inp(dtype=str, strip=True):
s = input()
res = [dtype(p) for p in s.split()]
res = res[0] if len(res) == 1 and strip else res
return res
def problem1():
t = inp(int)
for _ in range(t):
n = inp(int)
s = inp(str)
i = 0
while i < n and s[i] == "P":
i... | FUNC_DEF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
s = list(map(int, input().split()))
dp = [[[float("INF"), float("INF")] for i in range(n // 2 + 1)] for i in range(n + 1)]
dp[0][0] = [0, 0]
for i in range(1, n + 1):
if s[i - 1] == 0:
for j in range(1, n // 2 + 1):
dp[i][j][0] = min(dp[i - 1][j - 1][0], dp[i - 1][j - 1][1] + 1)... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMB... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
n = int(input())
if n == 1:
print(0)
sys.exit()
arr = list(map(int, input().split()))
arr = [(i % 2 if i != 0 else -1) for i in arr]
skipped = sum([(i == -1) for i in arr])
if skipped == n:
print(1)
sys.exit()
ans = 0
for i in range(n - 1):
if arr[i] == 0 and arr[i + 1] == 1 or arr[i] ==... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CA... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def parity(p):
if p == 0:
return 0
return 1 if A[p] != A[p - 1] else 0
def sol(p, pa, ip):
if pa < 0 or ip < 0:
return 1000000
if p == n:
return 0
if p > 0 and DP[p][ip][pa][A[p - 1]] != -1:
return DP[p][ip][pa][A[p - 1]]
if A[p] == -1:
A[p] = 1
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def garland(a):
n = len(a)
a = [0] + a
oo = n + 1
dp = [[[oo, oo] for __ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = dp[0][0][1] = 0
for i in range(1, n + 1):
for j in range(i + 1):
if a[i] % 2 == 1 or a[i] == 0:
dp[i][j][1] = min(dp[i - 1][j][0] + 1... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
ps = list(map(int, input().split()))
used = [False] * (n + 1)
all_zeros = True
for p in ps:
used[p] = True
if p > 0:
all_zeros = False
if all_zeros:
if n == 1:
print(0)
else:
print(1)
else:
start_i = 0
while ps[start_i] == 0:
start_i += 1
star... | 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 ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VA... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int, input().split()))
def maxDiff(p, n):
if n == 1:
return 0
used = {i for i in p}
rest = {(0): 0, (1): 0}
for i in range(1, n + 1):
if i not in used:
rest[i % 2] += 1
A00 = []
A11 = []
A01 = ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER A... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
arr = list(map(int, input().split()))
final = 0
if n % 2 == 0:
odd, even = n // 2, n // 2
else:
odd = n // 2 + 1
even = n // 2
temp, ind = [], []
for i in range(n):
if arr[i] == 0:
arr[i] = None
else:
if arr[i] % 2 == 0:
even -= 1
arr[i] = arr... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VA... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def main():
n = int(input())
l = [int(s) for s in input().split()]
e, o = n // 2, n - n // 2
for i in range(n):
if l[i] != 0:
if l[i] % 2 == 0:
e -= 1
else:
o -= 1
dp... | IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR ... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
input = lambda: sys.stdin.readline()
n = int(input())
if n == 1:
print(0)
exit(0)
a = list(map(int, input().split()))
t = -1
o, e = 0, 0
for i in a:
if i != 0:
e += (i + 1) % 2
o += i % 2
ans = 0
for j in range(n - 1):
if a[j] != 0 and a[j + 1] != 0:
ans += int(a[j] %... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
p = input().split()
allnos = range(1, n + 1)
thenos = []
givnos = []
extra = []
comp = 0
no = None
gap = 0
for i in range(len(p)):
if int(p[i]) != 0:
givnos.append(int(p[i]))
if no == None and gap > 0:
extra.append([int(p[i]), int(p[i]), gap])
elif gap > 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
a = list(map(int, input().split()))
z = []
if len(set(a)) == 1:
if len(a) == 1:
print(0)
else:
print(1)
exit()
even = n // 2
odd = n - even
for i in a:
if i:
if i % 2:
odd -= 1
else:
even -= 1
for i in a:
if i == 0:
if ... | 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 IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FO... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
a = [int(i) for i in input().split()]
odd = n // 2 + (n & 1)
even = n // 2
if sum(a) == 0:
print(1) if n > 1 else print(0)
exit(0)
for i in a:
if i & 1 == 1:
odd -= 1
elif i & 1 == 0 and i != 0:
even -= 1
ans = 0
s = [[], [], []]
for i in range(0, len(a) - 1):
if a[i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUM... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def solve(bulbs, i, ec, oc, prev, memo={}):
if i == len(bulbs):
if min(ec, oc) != 0:
return float("inf")
return 0
if bulbs[i] != 0:
return (prev != bulbs[i] % 2) + solve(bulbs, i + 1, ec, oc, bulbs[i] % 2, memo)
if (i, ec, oc, prev) not in memo:
eit = (prev == 1) ... | FUNC_DEF DICT IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR STRING RETURN NUMBER IF VAR VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VA... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | N = int(input())
A = [int(a) for a in input().split()]
M = A.count(0)
A2 = [(a % 2) for a in A]
O = A2.count(1)
E = N - M - O
O = (N + 1) // 2 - O
E = N // 2 - E
C = [M]
for a in A:
C.append(C[-1] - (a == 0))
X = [([999] * (N + 2)) for _ in range(N)]
Y = [([999] * (N + 2)) for _ in range(N)]
if A[0] % 2:
X[0][O... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUM... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | INF = 1000
def mod2(a, n):
even, odd = 0, 0
for i in range(n):
if a[i] == 0:
a[i] = -1
elif a[i] & 1:
a[i] = 1
odd += 1
else:
a[i] = 0
even += 1
even = n // 2 - even
odd = (n - 1) // 2 + 1 - odd
return even, odd
... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def f(mass, a):
mass.sort()
prov = True
for i in range(len(mass)):
if a >= mass[i]:
a -= mass[i]
else:
prov = False
break
if prov:
return [0, a]
return [2 * (len(mass) - i), a]
n = int(input())
if n == 1:
print(0)
else:
mass = [in... | FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN LIST NUMBER VAR RETURN LIST BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL ... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def main():
n = int(input())
lst = list(map(int, input().split()))
nums = set()
for el in lst:
if el != 0:
nums.add(el)
odd = 0
even = 0
for i in range(1, n + 1):
if not i in nums:
if i % 2 == 0:
even += 1
else:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBE... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
a = list(map(int, input().split()))
e = n // 2
o = n - e
ptf = [[[0, 0] for i in range(e + 2)] for j in range(o + 2)]
dt = {}
for i in range(n):
if a[i] != 0:
dt[i + 1] = a[i]
for i in range(o + 1):
for j in range(e + 1):
if i == 0:
ptf[i][j][0] = 99999
if j ... | 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 VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMB... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
p = list(map(int, input().split()))
total_chet = n // 2
total_nechet = n // 2 + n % 2
hang_chet = len([item for item in p if item > 0 and item % 2 == 0])
hang_nechet = len([item for item in p if item > 0 and item % 2 == 1])
rest_chet = total_chet - hang_chet
rest_nechet = total_nechet - hang_nechet
pre... | 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 VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP VAR... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
bulbs = list(map(int, input().split()))
li = []
odds = 0
blanks = 0
for i, e in enumerate(bulbs):
if e != 0:
if e % 2 == 1:
li.append((i, 1))
odds += 1
else:
li.append((i, 0))
else:
blanks += 1
odds = (n + 1) // 2 - odds
even = blanks ... | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN V... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
input = sys.stdin.readline
INF = 10**14
N = int(input())
A = list(map(int, input().split()))
odds = (N + 1) // 2
evens = N // 2
for a in A:
if a == 0:
continue
if a % 2 == 0:
evens -= 1
else:
odds -= 1
dp = [
[[[INF, INF] for _ in range(odds + 1)] for _ in range(evens... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR L... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
pr = 0
t = 0
ch = n // 2
nech = n // 2 + n % 2
mass1 = []
mass3 = []
answer = 0
for i in [int(x) for x in input().split()]:
if i == 0:
pr += 1
elif pr > 0:
if i % 2 == 0:
ch -= 1
else:
nech -= 1
if t == 0:
t = i % 2 + 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBE... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def ip():
n = int(input())
a = list(map(int, input().split()))
rem = set([i for i in range(1, n + 1)]) - set(a)
if n == 1:
return 0
o = e = 0
for i in rem:
if i % 2 == 0:
e += 1
else:
o += 1
ct = 0
i = 0
while i < len(a) and a[i] == 0:
... | FUNC_DEF 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 VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUM... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
p = list(map(int, input().split()))
if n == 1:
print(0)
exit(0)
if sum(p) == 0:
print(1)
exit(0)
INF = 100
dp = [([INF] * 2) for _ in range(n // 2 + 1)]
if p[0] == 0:
dp[1][0] = 0
dp[0][1] = 0
elif p[0] % 2:
dp[0][1] = 0
else:
dp[1][0] = 0
for i in range(1, n):
newdp... | 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 NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VA... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | import sys
input = sys.stdin.readline
INF = 10**9
n = int(input())
array = [int(item) for item in input().split()]
seen = set(array)
odd_num = 0
eve_num = 0
for i in range(1, n + 1):
if i not in seen:
if i % 2 == 0:
eve_num += 1
else:
odd_num += 1
num = odd_num + eve_num
dp ... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMB... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
girl = list(map(int, input().split()))
odd = 0
even = 0
for g in girl:
if g != 0:
if g % 2 != 0:
odd += 1
else:
even += 1
left_odd = (n + 1) // 2 - odd
left_even = n // 2 - even
series = []
left = 0
right = n - 1
while girl[left] == 0:
left += 1
if le... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN V... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | prime = 1000000007
t = 1
for test in range(t):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(0)
else:
b = set(a)
if len(b) == 1:
print(1)
else:
even = 0
odd = 0
for i in range(1, n + 1):
... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR ... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | n = int(input())
a = list(map(int, input().split()))
if a.count(0) == n:
if n == 1:
print(0)
else:
print(1)
exit(0)
chc = [0, 0]
ans = -1
sob = []
curch = -1
cc = 0
isfirst = [-1, 0]
islast = [-1, 0]
for i in range(n):
if a[i] == 0:
cc += 1
elif curch == a[i] % 2:
if ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR N... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def answer(A, odd, even):
odds = []
evens = []
waseven = 1
wasodd = 1
waszero = -1
ans = 0
for i in range(len(A)):
if A[i] and not A[i] % 2:
if waszero >= 0 and waseven:
evens.append(i - waszero)
waszero = -1
elif waszero >= 0 a... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER... |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland.... | def solve():
N = int(input())
P = list(map(int, input().split()))
if N <= 1:
return 0
taken = [(False) for i in range(N + 1)]
for i in range(len(P)):
if P[i] == 0:
continue
taken[P[i]] = True
if P[i] % 2 == 0:
P[i] = 2
else:
... | FUNC_DEF 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 RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.