description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | 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)
cost[1] = c[0]
for j in range(2, b + 1):
cost[j] = cost[j - 2] + c[j - 1]
k = 0
while k <= b and cost[k] <= m:
k += 1
print(... | 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 ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def solve(p, k, a):
def f(a, p, init):
last_i = init
ans = 0
for i in range(init, len(a), 2):
if p >= a[i]:
ans += 2 if i > 0 else 1
p -= a[i]
last_i = i
else:
break
if last_i + 1 < len(a):
... | FUNC_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CA... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | import sys
from sys import stdin
sys.setrecursionlimit(10**5)
def check(index):
aux = p
for i in range(index, -1, -2):
aux -= arr[i]
return aux >= 0
def binary_search(start, end):
while start < end:
mid = (start + end + 1) // 2
if check(mid):
start = mid
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR RETURN VAR NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR RETURN BIN_OP VA... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def ii():
return int(input())
def si():
return input()
def mi():
return map(int, input().split())
def li():
return list(mi())
for i in range(ii()):
n, p, k = mi()
a = li()
a.sort()
s = []
if a[0] > p:
print(0)
else:
ans = 0
for i in range(n):
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER V... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for t in range(int(input())):
n, p, k = map(int, input().split())
A = list(map(int, input().split()))
B = sorted(A)
coin1 = 0
coin2 = 0
y = False
for i in range(n):
if i % 2 == 0:
coin1 = coin1 + B[i]
else:
coin2 = coin2 + B[i]
if coin1 > p or ... | 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIG... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for z in range(t):
n, p, k = [int(e) for e in input().split()]
line = input().split()
a = []
for x in line:
a.append(int(x))
a.sort()
dp = []
for i in range(n):
dp.append(-1)
before = 0
for i in range(n - 1):
val = before + a[i]
if val... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASS... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
while t > 0:
t -= 1
n, p, k = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
s = 0
u = 0
if n % 2 == 0 or 1:
pp = p
p -= a[0]
s = 1
if p < 0:
s = 0
for i in range(2, n, 2):
if p - a[i] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMB... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for i in range(0, t):
n, p, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
rem = p
j = int(0)
ans1 = int(0)
maxadded = -1
for j in range(1, n, 2):
temp = a[j]
if rem >= temp:
rem -= temp
ans1 +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR 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 VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | from sys import stdin
input = stdin.readline
for xoxo in range(1):
for _ in range(int(input())):
n, p, k = map(int, input().split())
p1 = p
a = list(map(int, input().split()))
a.sort()
l = (n - 1) // 2
l = l * 2
if a[0] > p:
print("0")
... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for _ in range(t):
n, p, k = [int(x) for x in input().split()]
p1 = p
prices = [int(x) for x in input().split()]
prices.sort()
count = 1
i = 1
p -= prices[0]
if p < 0:
i = n + 1
count = 0
while i < n - 1:
if prices[i + 1] <= p:
cou... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIG... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def getmaxnumber(n, p, k, ai):
aod = []
aeve = []
sumod = 0
sumeve = 0
sum = 0
flag = 0
for i in range(0, len(ai)):
if (i + 1) % 2 == 0:
aeve.append(ai[i])
sumeve = sumeve + ai[i]
sum = sumeve
flag = 0
else:
aod.appe... | 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 NUMBER FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR A... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def mi():
return map(int, input().split())
for _ in range(int(input())):
n, p, k = mi()
a = sorted(list(mi()))
i = 0
while i < n:
if i >= k:
a[i] += a[i - k]
if a[i] > p:
break
i += 1
print(i) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | n = int(input())
res = []
for i in range(0, n):
desc = list(map(int, input().split()))
p = desc[1]
max_goods = desc[2]
arr = list(map(int, input().split()))
arr.sort()
cost = []
cart = []
for x in range(0, len(arr)):
prev = cost[x - 2] if x > 1 else 0
cost.append(prev + a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for _ in range(t):
n, p, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
b = [0]
pos = 0
for i in range(k - 1):
b.append(b[-1] + arr[i])
if b[i + 1] <= p:
pos = i + 1
for i in range(k - 1, n):
b.app... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUM... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | T = int(input())
for t in range(1, T + 1):
n, p, k = map(int, input().split())
values = sorted(list(map(int, input().split())))
max_items = 0
odd_sum = 0
even_sum = 0
for i in range(0, n, 2):
odd_sum += values[i]
if odd_sum <= p:
max_items += 1
else:
... | 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBE... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for t in range(int(input())):
n, p, k = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
a.sort()
end = k - 1
sum = 0
while end < n:
sum += a[end]
if sum >= p:
break
end += k
if sum == p:
print(end + 1)
continue
a... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR 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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for _ in range(int(input())):
n, p, k = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
z = p
ans = 0
kk = 0
for i in range(1, n, 2):
if li[i] <= p:
ans += 2
p -= li[i]
else:
kk = 1
break
if p >= li[... | 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VA... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for l in range(0, t):
n, p, k = [int(i) for i in input().split()]
lis = list(map(int, input().split()))
lis.sort()
dp = []
dp.append(lis[0])
for i in range(1, k - 1):
dp.append(dp[i - 1] + lis[i])
dp.append(lis[k - 1])
for i in range(k, n):
dp.append(min(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def calc(l, p, tk, k):
q = 0
for i in range(tk):
if q + l[i] > p:
return -1
q += l[i]
g = 1
while q <= p and k * g + tk - 1 < len(l):
e = l[tk + g * k - 1]
if q + e > p:
break
q += e
g += 1
return k * (g - 1) + tk
t = int(inpu... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR RETURN NUMBER VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
while t > 0:
n, p, k = [int(ele) for ele in input().split()]
a = [int(ele) for ele in input().split()]
a.sort()
count = 0
pref = 0
for i in range(k):
sumi = pref
if sumi > p:
break
cnt = i
for j in range(i + k - 1, n, k):
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VA... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def buy(arr, n, money):
while n < len(arr):
if arr[n] > money:
return n
if n + 1 < len(arr) and arr[n + 1] <= money:
money -= arr[n + 1]
n += 2
else:
money -= arr[n]
n += 1
return n
for _ in range(int(input())):
n, p, k = ... | FUNC_DEF WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR 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... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def find(a, s, c):
n = len(a)
for i in range(1, n, 2):
if a[i] <= s:
s -= a[i]
c += 2
else:
break
return c
t = int(input())
while t > 0:
n, s, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)
if a[... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for _ in range(int(input())):
n, p, k = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
if k == 2:
odds, i = 0, 0
while i < n and odds + array[i] <= p:
odds += array[i]
i += 2
even, j = 0, 1
while j < n and even + arr... | 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBE... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | import sys
from itertools import accumulate
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)... | 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 ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | case = int(input())
number = []
for i in range(case):
a = input()
a = a.split()
n = int(a[0])
p = int(a[1])
k = int(a[2])
cost = input()
cost = list(map(int, cost.split()))
cost.sort()
total = 0
for j in range(k):
sum_p = 0
mount = 0
if sum_p + cost[j] <= ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for i in range(t):
n, p, k = map(int, input().split())
p1 = p
a = sorted(list(map(int, input().split())))
s = 0
ii = -1
flag = True
for i in range(k - 1, n, k):
if a[i] <= p:
ii = i
p -= a[i]
flag = False
s += k
... | 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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | T = int(input())
for iiii in range(T):
n, p, k = map(int, input().strip().split())
A = sorted(list(map(int, input().strip().split())))
for i in range(len(A)):
if i < k - 1 and i > 0:
A[i] = A[i - 1] + A[i]
elif i >= k:
A[i] = A[i] + A[i - k]
flag = 0
if p < A[... | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BI... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
while t:
t += -1
n, p, k = [int(x) for x in input().split()]
l = list(map(int, input().split()))
l.sort()
ind = [-1] * k
ans = [0] * k
a = [p] * k
for i in range(n):
if i + 1 - k >= 0:
if a[(i + 1 - k) % k] - l[i] >= 0:
a[(i + 1 - k) %... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR 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 VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FU... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for i in range(t):
n, p, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
maxi = 0
hehe = 0
for i in range(k - 1):
temp = p
count = 0
hehe += arr[i]
if temp >= hehe:
count += i + 1
temp -... | 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASS... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for _ in range(t):
n, p, k = list(map(int, input().split()))
al = list(map(int, input().split()))
al.sort()
al = [0, 0] + al + [0]
for i in range(2, n + 3):
al[i] += al[i - 2]
if al[i] > p:
break
print(i - 2) | 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_O... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for i in range(t):
n, p, k = list(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
hi = n
lo = 0
odd_index_sums = [goods[1]]
even... | 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 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 NUM... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for i in range(int(input())):
n, p, k = map(int, input().split())
l = [*map(int, input().split())]
l.sort()
w = 0
r = int(p)
t = 0
for i in range(0, n, 2):
if p >= l[i]:
p -= l[i]
w += 1
for i in range(1, n, 2):
if r >= l[i]:
r -= l[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 LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | 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 ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def main():
t = int(input())
for T in range(t):
n, p, k = [int(i) for i in input().split()]
li = sorted([int(i) for i in input().split()])
price = 0
pre = [0] * (len(li) + 1)
for i in range(len(li)):
if i >= k - 1:
temp = li[i] + pre[i - k + 1]... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CAL... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for tcase in range(int(input())):
nitems, coins, k = list(map(int, input().split()))
ls = list(map(int, input().split()))
ls.sort()
if ls[0] > coins:
print(0)
continue
best = 0
spent = 0
ptr = 0
while ptr + 1 < nitems and spent + ls[ptr + 1] <= coins:
spent += ls[... | 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 IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_O... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for test in range(t):
n, p, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
carr = [(0) for i in range(n + 5)]
carr[0] = arr[0]
for i in range(1, k - 1):
carr[i] = carr[i - 1] + arr[i]
carr[k - 1] = arr[k - 1]
for i in range(k, n):
... | 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUM... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for _ in range(int(input())):
n, p, k = map(int, input().split())
u = [0] + list(map(int, input().split()))
a = [0] * (n + 1)
c = [0] * (n + 1)
u.sort()
for i in range(1, n + 1):
if i < k or u[i] > p:
if u[i] + c[i - 1] > p:
c[i] = c[i - 1]
a[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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | q = int(input())
for _ in range(q):
n, p, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
m = 0
for i in range(k):
c = 0
tmp = -1
if i > 0:
tmp = i - 1
c = a[tmp]
while p >= c:
tmp = tmp + k
... | 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
for i in range(n - 1, -1, -1):
res = 0
acc = 0
j = 0
while True:
cur_index = i - 2 * j
if cur_index < 0 or acc + a[cu... | 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
ans = []
for kk in range(t):
n, p, k = list(map(int, input().split()))
goods = list(map(int, input().split()))
goods.sort()
l = 0
h = n - 1
m = (l + h) // 2
while l <= h:
t = sum(goods[m::-2])
if p - t < 0:
h = m - 1
m = (l + h) // 2
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VA... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for _ in range(int(input())):
n, p, k = map(int, input().split())
res1 = 0
res2 = 0
a = list(map(int, input().split()))
a.sort()
ip = p
for i in range(1, len(a), 2):
if a[i] <= p:
res1 += 2
p -= a[i]
else:
break
p = ip
if a[0] <= p:... | 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | def check(x, arr, p, n, k):
ans = sum(arr[0:x])
index = x + k - 1
if ans <= p:
p -= ans
ans = x
else:
ans = 0
while index < n:
if arr[index] <= p:
p -= arr[index]
ans += k
index += k
else:
break
return ans
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER A... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for _ in range(int(input())):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
q = 0
cnt1 = 0
for i in range(0, n, 2):
if a[i] + q > p:
break
q += a[i]
cnt1 = i + 1
q = 0
cnt2 = 0
for i in range(1, n, 2):
if ... | 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VA... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for i in range(t):
n, p, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s1, s2 = 0, 0
c1, c2 = 0, 0
s1n, s2n = True, True
la = len(a)
if a[0] + s1 > p:
s1n = False
else:
s1 += a[0]
c1 += 1
for ii in range(2, la,... | 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 VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for it in range(int(input())):
a = list(map(lambda x: int(x), input().split(" ")))
b = sorted(list(map(lambda x: int(x), input().split(" "))))
mcount = 0
ccount = 0
tcost = a[1]
sprev = 0
for i in range(0, a[2]):
j = 0
ccost = i
tcost = a[1]
s = sprev
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR ... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | for case in range(int(input())):
n, p, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
dp = [1000000000] * n
dp[0] = arr[0]
for i in range(1, k - 1):
dp[i] = arr[i] + dp[i - 1]
dp[k - 1] = arr[k - 1]
for i in range(k, n):
dp[i] = min(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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VA... |
This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.
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" is held in... | t = int(input())
for _ in range(t):
n, p, k = map(int, input().split(" "))
y = list(map(int, input().split()))
y = sorted(y)
even = [0]
odd = [0]
k = 0
for i in y:
if k % 2 == 0:
odd.append(odd[-1] + i)
else:
even.append(even[-1] + i)
k += 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 STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR N... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | import sys
n = int(input())
minmax = list(map(int, input().split()))
childs = [[] for i in range(n)]
for idx, father in enumerate(list(map(int, input().split()))):
childs[father - 1].append(idx + 1)
stack = []
stack.append(0)
ans = [None for ele in range(n)]
vis = [(False) for ele in range(n)]
while len(stack):
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL V... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
dp = [1] * n
o = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(n - 1):
p[i] -= 1
for i in p:
dp[i] = 0
count = sum(dp)
for i in range(n - 2, -1, -1):
if not o[p[i]]:
dp[p[i]] += dp[i + 1]
elif not dp[p[i]]:
dp[p[i]] = dp[i + 1]
el... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
op = [int(g) for g in input().split()]
parent = [(int(g) - 1) for g in input().split()]
tree = [[] for i in range(n)]
for i in range(n - 1):
tree[parent[i]].append(i + 1)
l = sum([(1) for i in range(n) if len(tree[i]) == 0])
l1 = [-1] * n
for i in range(n - 1, -1, -1):
if len(tree[i]) == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBE... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
op = [int(v) for v in input().split()]
f = [int(v) for v in input().split()]
ch = [[] for p in op]
for i, p in enumerate(f):
ch[p - 1].append(i + 1)
q = [0]
for i in range(n):
q += ch[q[i]]
x = [0] * n
nl = 0
for p in q[::-1]:
if not ch[p]:
nl += 1
elif op[p]:
x[p] = min... | 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR V... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
least = [1] * (n + 1)
op = [0] + list(map(int, input().split()))
pa = [0, 0] + list(map(int, input().split()))
for i in range(1, n + 1):
least[pa[i]] = 0
leaves = sum(least)
for i in range(n, 1, -1):
if op[pa[i]] == 0:
least[pa[i]] += least[i]
elif least[pa[i]] == 0:
least[p... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN ... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | N = int(input())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
G = [[] for i in range(N)]
INF = float("inf")
for i in range(1, N):
G[f[i - 1] - 1].append(i)
d = [0] * N
k = 0
for i in range(N - 1, -1, -1):
if len(G[i]) == 0:
d[i] = 1
k += 1
continue
if a[i] ... | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUM... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
f = tuple(map(int, input().split()))
tree = [[] for _ in range(n)]
for i, parent in zip(list(range(1, n + 1)), [(int(x) - 1) for x in input().split()]):
tree[parent].append(i)
d = [0] * n
leaves = 0
for i in reversed(list(range(n))):
if not tree[i]:
d[i] = 1
leaves += 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 VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
is_max = list(map(int, input().split()))
parent = list(map(int, input().split()))
adjList = [[] for _ in range(n)]
used = [0] * n
for v, u in enumerate(parent):
adjList[u - 1].append(v + 1)
for i in range(n - 1, 0, -1):
pi = parent[i - 1] - 1
if is_max[pi]:
if used[pi] == 0:
... | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP V... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
a = [None] + list(map(int, input().split()))
p = [None, None] + list(map(int, input().split()))
f = [[0, 0, 10**9] for i in range(n + 1)]
for i in range(n, 1, -1):
if f[i][0] == 0:
c = x = y = 1
else:
c, x, y = f[i]
w = y if a[i] else x
f[p[i]][0] += c
f[p[i]][1] += ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE NONE FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
oper = list(map(int, input().split()))
rod = list(map(int, input().split()))
s = {i: [] for i in range(n)}
for i in range(len(rod)):
s[rod[i] - 1].append(i + 1)
t = [-1] * n
t[0] = 1
black = []
grey = [0]
while grey != []:
black.append(grey.pop())
for i in s[black[-1]]:
grey.append(... | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | import sys
input = sys.stdin.readline
def dfs(u):
stack = [u]
visit = [False] * n
while stack:
u = stack[-1]
if not visit[u]:
visit[u] = True
for v in child[u]:
stack.append(v)
else:
if len(child[u]) == 0:
global ... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL ... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | N = int(input())
T = [int(a) for a in input().split()]
P = [-1] + [(int(a) - 1) for a in input().split()]
C = [[] for i in range(N)]
for i in range(1, N):
C[P[i]].append(i)
L = sum([(1) for i in range(N) if len(C[i]) == 0])
CT = [0] * N
DP = [-1] * N
i = 0
while i >= 0:
if CT[i] >= len(C[i]):
if len(C[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 LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | import sys
input = sys.stdin.readline
def dfs(u):
stack = [u]
visit = [False] * n
while stack:
u = stack[-1]
if not visit[u]:
visit[u] = True
for v in child[u]:
stack.append(v)
else:
if len(child[u]) == 0:
global ... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL ... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | n = int(input())
a = [None] + list(map(int, input().split()))
p = [None, None] + list(map(int, input().split()))
g = [[] for i in range(n + 1)]
for i in range(n, 0, -1):
if g[i]:
c = 0
x, y = 0, 10**9
for cv, wv in g[i]:
c += cv
x += wv
y = min(y, wv)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE NONE FUNC_CALL 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 VAR NUMBER NUMBER IF VAR VAR ASSIG... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | N = int(input())
T = [int(a) for a in input().split()]
P = [(int(a) - 1) for a in input().split()]
C = [[] for i in range(N)]
for i in range(N - 1):
C[P[i]].append(i + 1)
L = [i for i in range(N) if len(C[i]) == 0]
DP = [-1] * N
def calc(i):
if len(C[i]) == 0:
DP[i] = 1
elif T[i]:
mi = 10*... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL V... |
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex ca... | R = lambda: map(int, input().split())
n = int(input())
fcs = [0] + list(R())
ps = [0, 0] + list(R())
cs = [1] * (n + 1)
for i in range(2, n + 1):
cs[ps[i]] = 0
nc = sum(cs) - 1
for i in range(n, 1, -1):
if fcs[ps[i]] == 0:
cs[ps[i]] += cs[i]
elif not cs[ps[i]]:
cs[ps[i]] = cs[i]
else:
... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
_ord, inp, num, neg, _Index = lambda x: x, [], 0, False, 0
i, s = 0, sys.stdin.buffer.read()
try:
while True:
if s[i] >= b"0"[0]:
num = 10 * num + _ord(s[i]) - 48
elif s[i] == b"-"[0]:
neg = True
elif s[i] != b"\r"[0]:
inp.append(-num if neg el... | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR WHILE NUMBER IF VAR VAR UNKNOWN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR UNKNOWN NUMBER ASSIGN VAR NUMBER IF VAR VAR UNKNOWN NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN V... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
dic = {}
dico = {}
for i in range(1, n + 1):
dic[i] = []
dico[i] = []
for i in range(n - 1):
x, y = map(int, input().split())
dic[x].append(y)
dic[y].append(x)
dico[x... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CA... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
inp = sys.stdin.readline
mod = 10**9 + 7
def solve():
N = int(inp())
d = [set() for _ in range(N + 1)]
for i in range(N - 1):
u, v = map(int, inp().split())
d[u].add((v, i))
d[v].add((u, i))
G = [set() for _ in range(N + 1)]
st = [2]
vis = set([2])
tp_so... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 VAR EXPR FUNC_CALL ... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | for i in range(int(input())):
n = int(input())
tree = [[] for j in range(n)]
paths = [0] * n
degree = [1] * n
branches = [0] * n
for j in range(n - 1):
u, v = map(int, input().split())
tree[u - 1].append(v - 1)
tree[v - 1].append(u - 1)
branches[u - 1] += 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.readline
mod = 10**9 + 7
q = int(input())
res = []
for _ in range(q):
n = int(input())
E = [[] for _ in range(n + 1)]
for i in range(n - 1):
x, y = map(int, input().split())
E[x].append(y)
E[y].append(x)
m = int(input())
V = sorted(map(int, input... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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_CA... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.readline
MOD = 10**9 + 7
res = []
q = int(input())
for _ in range(q):
n = int(input())
adj_lis = [[] for i in range(n)]
adj_cnt = [0] * n
adj_cnt[0] = 1
par = [-1] * n
des_cnt = [1] * n
leaf_q = []
edgeNum = []
for _ in range(n - 1):
u, v = map(i... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR A... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
def input():
return sys.stdin.readline().rstrip()
def input_split():
return [int(i) for i in input().split()]
testCases = int(input())
answers = []
sys.setrecursionlimit(10**5)
for _ in range(testCases):
n = int(input())
edges = [[] for i in range(n)]
freqs = {}
for _ in range(n... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR DI... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | from sys import stdin, stdout
def input():
return stdin.readline().strip()
tests = int(input())
for t in range(tests):
n = int(input())
node_dict = {}
for _ in range(n - 1):
u, v = list(map(int, input().split()))
if u in node_dict:
node_dict[u][0] += 1
node_di... | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 IF VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL V... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | def iin():
return int(input())
def lin():
return list(map(int, input().split()))
def dfs(adj, start=1):
n = len(adj)
visited = [False] * n
euler = []
srt = [start]
parent = [-1] * n
dp = [1] * n
dp[0] = 0
pv = 0
while srt:
v = srt.pop()
if visited[v]:
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUM... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.buffer.readline
mod = 10**9 + 7
def main():
t = int(input())
for _ in range(t):
n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
u, v = u - 1, v - 1
g[u].append(v)
... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR ASSI... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
q = 10**9 + 7
T = int(sys.stdin.readline().strip())
for t in range(0, T):
n = int(sys.stdin.readline().strip())
N = [[] for i in range(0, n)]
D = [0] * n
for i in range(0, n - 1):
u, v = list(map(int, sys.stdin.readline().strip().split()))
u, v = u - 1, v - 1
N[u].app... | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | from sys import stdin
def dfs(i):
stack = []
stack.append([i, []])
while stack:
q, subs = stack[-1]
size = visited[q]
if size == 0:
visited[q] = size = 1
subs[:] = [elem for elem in ed[q] if visited[elem] == 0]
if subs:
stack.append([subs... | FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST VAR LIST WHILE VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_C... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.readline
def dfs(tree, root):
n = len(tree)
visited = [False] * n
visited[root] = True
tp_sorted = [root]
stack = [root]
while stack:
new_stack = []
for v in stack:
for nxt_v in tree[v]:
if visited[nxt_v]:
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR F... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
sys.setrecursionlimit(10**5)
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... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.readline
mod = 1000000007
for f in range(int(input())):
n = int(input())
neig = [0] * n
for i in range(n):
neig[i] = [0]
edges = []
for i in range(n - 1):
vertexa, vertexb = map(int, input().split())
vertexa -= 1
vertexb -= 1
neig... | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.readline
def DFS():
stack = [1]
visited = [0] * (n + 1)
visited[1] = 1
par = [0] * (n + 1)
tp_stack = [1]
while stack:
new_stack = []
for node in stack:
for ne_node in e[node]:
if visited[ne_node] == 0:
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER WHILE VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | DISTRIBUTION_INDEX_MOD = 10**9 + 7
def compute_max_distribution_index(graph, factors_seq):
edges_loading = _compute_edges_loading(graph)
loadings = sorted(edges_loading.values(), reverse=True)
edges_n = len(loadings)
weights = [1] * edges_n
factors_seq = sorted(factors_seq)
first_factors, fact... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR N... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
inp = sys.stdin.buffer.readline
inar = lambda: list(map(int, inp().split()))
inin = lambda: int(inp())
inst = lambda: inp().decode().strip()
wrt = sys.stdout.write
pr = lambda *args, end="\n": wrt(" ".join([str(x) for x in args]) + end)
enum = enumerate
inf = float("inf")
cdiv = lambda x, y: -(-x // y)
mod ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR STRING FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | mod = 1000000007
for _ in range(int(input())):
n = int(input())
routesges = [[] for i in range(n + 1)]
for i in range(n - 1):
u, v = map(int, input().split())
routesges[u].append([v, 0])
routesges[v].append([u, 0])
m = int(input())
p = list(map(int, input().split()))
p.so... | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 LIST VAR NUMBER EXPR FUNC_CALL VAR VAR LI... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | for t in range(int(input())):
n = int(input())
d = {}
children = {}
for i in range(n):
d[i] = set()
for i in range(n):
children[i] = 0
for i in range(n - 1):
u, v = map(int, input().split())
d[u - 1].add(v - 1)
d[v - 1].add(u - 1)
child = []
for i ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | r = 10**9 + 7
for _ in range(int(input())):
N = int(input())
V = [[] for i in range(N)]
for i in range(N - 1):
u, v = map(int, input().split())
V[u - 1] += [v - 1]
V[v - 1] += [u - 1]
C = [[] for i in range(N)]
P = [0] * N
visited = [0] * N
que = [0]
visited[0] = ... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER VAR B... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
inp = sys.stdin.buffer.readline
inar = lambda: list(map(int, inp().split()))
inin = lambda: int(inp())
inst = lambda: inp().decode().strip()
mod = 1000000007
def DFS(gr, cost):
n = len(gr)
vis = [(False) for i in range(n)]
fin = [(False) for i in range(n)]
dp = [None for i in range(n)]
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR ... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | from sys import stdin
input = stdin.readline
t = int(input())
mod = 10**9 + 7
for _ in range(t):
n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
g[u - 1].append(v - 1)
g[v - 1].append(u - 1)
m = int(input())
p = list(map(in... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR B... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.buffer.readline
T = int(input())
MOD = 10**9 + 7
for testcase in range(T):
n = int(input())
edge = [[] for i in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
edge[u - 1].append(v - 1)
edge[v - 1].append(u - 1)
m = int(input())
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CAL... |
You are given a tree that consists of $n$ nodes. You should label each of its $n-1$ edges with an integer in such way that satisfies the following conditions: each integer must be greater than $0$; the product of all $n-1$ numbers should be equal to $k$; the number of $1$-s among all $n-1$ integers must be minimum ... | import sys
input = sys.stdin.readline
MOD = 10**9 + 7
t = int(input())
for _ in range(t):
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
u -= 1
v -= 1
edge[u].append(v)
edge[v].append(u)
m = int(input())
... | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR VAR NUMBER VA... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | l = [0] * 26
n = int(input())
pres = [0] * 26
s = input()
res = [0] * n
ii = -1
for i in s:
ii += 1
ind = ord(i) - ord("a")
lol = 0
for j in range(ind + 1, 26):
if pres[j] != 0:
lol = 1
if l[j] == 1:
lol = 2
break
if lol == 2:
b... | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | input()
s = input()
a, b = [], []
for i, c in enumerate(s):
if not a or c >= s[a[-1]]:
a.append(i)
elif not b or c >= s[b[-1]]:
b.append(i)
else:
print("NO")
exit(0)
print("YES")
ans = ["0"] * len(s)
for c in b:
ans[c] = "1"
print("".join(ans)) | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR V... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | def run():
flag1, flag2 = "a", "a"
n = int(input())
ret = ""
mystr = input()
for i in range(n):
if mystr[i] >= flag1:
ret += "0"
flag1 = mystr[i]
elif mystr[i] >= flag2:
ret += "1"
flag2 = mystr[i]
else:
print("NO")
... | FUNC_DEF ASSIGN VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EX... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | n = int(input())
s = str(input())
x, ans = [0] * n, 1
for i2 in range(n):
for i in range(i2 + 1, n):
if s[i] < s[i2] and x[i] != 0:
if x[i2] == x[i]:
ans = 0
x[i2] = x[i] * -1
if x[i2] == 0:
x[i2] = 1
for i in range(i2 + 1, n):
if s[i] < s[i2] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER A... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | def colorable(s):
mn1 = "a"
mn2 = "a"
res = ""
for c in s:
if c >= mn1:
res += "0"
mn1 = c
elif c >= mn2:
res += "1"
mn2 = c
else:
return False, res
return True, res
n = input()
s = input()
valid, res = colorable(s... | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR RETURN NUMBER VAR RETURN NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | import sys
n = int(input())
s = input()
if n == 1:
print("YES")
print(0)
sys.exit()
s1, s2 = [0], []
for i in range(1, n):
if s[i] >= s[s1[-1]]:
s1.append(i)
elif not s2 or s[i] >= s[s2[-1]]:
s2.append(i)
else:
print("NO")
sys.exit()
print("YES")
ans = ["0"] * n
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR V... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | def opp(c):
if c == "0":
return "1"
return "0"
n = int(input())
s = input()
temp = 0
col = ["-1"] * n
for i in range(0, len(s)):
if col[i] == "-1":
col[i] = "0"
c = col[i]
for j in range(i + 1, len(s)):
if ord(s[j]) < ord(s[i]):
t = opp(c)
if col[j] ... | FUNC_DEF IF VAR STRING RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CA... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | import sys
from _collections import deque
input = lambda: sys.stdin.readline().rstrip("\r\n")
n = int(input())
a = input()
a0 = deque(a[0])
a1 = deque()
for i in a[1:]:
if ord(i) >= ord(a0[-1]):
a0.append(i)
else:
a1.append(i)
if a1 == deque(sorted(a1)):
print("YES")
for i in a:
... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR ... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | from sys import stdin, stdout
for _ in range(1):
n = int(stdin.readline())
s = input()
ans = 0
dp = [-1] * n
dp[n - 1] = 0
flag = 1
for i in range(n - 2, -1, -1):
for j in range(n - 1, i, -1):
if s[i] > s[j]:
if dp[i] == -1:
dp[i] = 1 ... | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR V... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | n = int(input())
s = input()
arr = [(0) for i in range(n)]
grps = []
col = 0
for i in range(len(s)):
if grps == []:
grps.append(s[i])
arr[i] = 1
col += 1
else:
found = 0
for j in range(len(grps)):
if ord(s[i]) >= ord(grps[j]):
found = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
def ceil(tails, L, R, key):
while L + 1 < R:
m = (L + R) // 2
if key < tails[m]:
L = m
else:
R = m
return R
def LIS(a, n):
tails = [0] * (n + 1)
tails[0] = a[0]
seq_... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER... |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the ... | n = int(input())
s = input()
col = [(-1) for i in range(n)]
ok = True
for i in range(n):
if col[i] == -1:
col[i] = 0
for j in range(i + 1, n):
if col[j] == -1:
if s[i] > s[j]:
col[j] = 1 - col[i]
elif s[i] > s[j] and col[i] + col[j] != 1:
ok = Fals... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.