description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) arr = [int(x) for x in input().split()] def solve(arr, n, k): if k == n: return 0 sumi = 0 for i in range(n): sumi += arr[i] arr[i] -= n - i - 1 if k == 0: re...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
import sys sys.setrecursionlimit(10**5) def pro(arr, k): n = len(arr) tot = sum(arr) lst = [] for i in range(n): lst.append((arr[i] + i, i)) lst.sort(reverse=True) for i in range(k): arr[lst[i][1]] = -1 x = 0 ans = 0 for i in range(n): if arr[i] != -1: ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER F...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
def solve(n, k, arr): if k >= n: print(0) return first_k = k res = [] ans = sum(arr) arr = arr[::-1] damage_idx = [] for i in range(len(arr)): damage_idx.append(i - arr[i]) damage_idx.sort() for i in range(k): ans += damage_idx[i] print(int(ans - k...
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR B...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
for inh in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) pen = [0] * n for i in range(n): pen[i] = a[i] - (n - 1 - i) ref = pen.copy() ref.sort(reverse=True) ref = ref[:k] j = ref.count(ref[-1]) for i in range(n): if pen[i] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EX...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
kvs = int(input()) for _ in range(kvs): c, d = map(int, input().split()) a = list(map(int, input().split())) b = [(x + y) for x, y in enumerate(a)] print(sum(sorted(b)[: c - d]) - (c - d) * (c - d - 1) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) arr = list(map(int, input().split())) ans = 0 for i in range(n): ans += arr[i] arr[i] += i + 1 arr.sort(reverse=True) for i in range(k): ans -= arr[i] for i in range(k): ans += n ans ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR V...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
def dTraps(n, k, l): costs = [] for i in range(n): costs.append(n - i - 1 - l[i]) costs.sort() c = 0 for i in range(k): c += costs[i] c -= k * (k - 1) // 2 print(sum(l) + c) t = int(input()) while t > 0: n, k = map(int, input().split()) l = list(map(int, input().spl...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL V...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) for i in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) otv = sum(a) esl_per = [0] * n for i in range(n): esl_per[i] = a[i] - (n - 1 - i) kaz = k * (k - 1) // 2 esl_per.sort(reverse=True) if n == k: print(0) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_O...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
for T in range(int(input())): n, k = [int(i) for i in input().split()] l = [int(i) for i in input().split()] l2 = [(l[i] - (n - i - 1), i) for i in range(n)] l2.sort() skipped = {j[1] for j in l2[-k:]} damage = 0 s = k for i, v in enumerate(l): if i in skipped: damage...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) while t: t -= 1 n, k = map(int, input().split()) a = list(map(int, input().split())) if k == n: print(0) else: arr = [] for i in range(n): arr.append([a[i] + i, i]) arr = sorted(arr, reverse=True) temp = [0] * n for i in ra...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR ASSIGN VAR...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
def get_minimum_damage(trap_count: int, base_damage: list, jumps: int): if trap_count <= jumps: return 0 damage_loss_pairs = [ (idx, val, val - (trap_count - idx) + 1) for idx, val in enumerate(base_damage) ] damage_loss_pairs.sort(key=lambda x: x[2], reverse=True) jumbed_trap = dama...
FUNC_DEF VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP F...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
for _ in range(int(input())): n, k = map(int, input().split()) arr = [int(x) for x in input().split()] pre = [arr[0]] for i in range(1, n): pre.append(pre[-1] + arr[i]) suf = [arr[-1]] for i in range(n - 2, -1, -1): suf.append(suf[-1] + arr[i]) suf = suf[::-1] fin = [] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BI...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
I = input R = lambda: map(int, I().split()) for i in range(int(I())): n, k = R() a = sorted([(v + i) for i, v in enumerate(R())]) print(sum(a[:-k]) - (n - k) * (0 + n - k - 1) // 2)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
T = int(input()) for _ in range(T): N, K = map(int, input().split()) A = list(map(int, input().split())) B = [(A[i] - N + i) for i in range(N)] B.sort(reverse=True) total = sum(A) - K * (K + 1) // 2 for i in range(K): total -= B[i] print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
for _ in range(int(input())): trap, jump = map(int, input().split()) temp = list(map(int, input().split())) print( sum(sorted([(temp[i] + i) for i in range(trap)])[: trap - jump]) - (trap - jump) * (trap - jump - 1) // 2 )
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP ...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) while t > 0: n, k = map(int, input().split()) v = list(map(int, input().split())) ans = 0 for i in range(0, n): ans += v[i] v[i] = -v[i] + n - i v.sort() for i in range(0, k): ans += v[i] ans -= k * (k + 1) // 2 print(ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) costs = [] for i in range(n): costs.append(n - i - 1 - l[i]) costs.sort() c = 0 for i in range(k): c += costs[i] c -= k * (k - 1) // 2 print(sum(l) + c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR ...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) arr = list(map(int, input().split())) narr = [(arr[i] - (n - i - 1), i) for i in range(n)] narr.sort(reverse=True) narr = narr[:k] indexs = list(map(lambda x: x[1], narr)) indexs.sort() ls = len(indexs) j, k, ans = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIG...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) for _ in range(t): n, k = map(int, list(input().split())) l = list(map(int, input().split())) ar = [(i, -l[i] + n - i - 1) for i in range(n)] ar.sort(key=lambda x: (x[1], x[0])) ans = 0 s = sum(l) for i in range(k): ans += n - ar[i][0] - i - 1 s -= l[ar[i][0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NU...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
def solve(): n, k = map(int, input().split()) a = tuple(map(int, input().split())) dmg_bonus = [i for i in range(n)] dmg_bonus.sort(key=lambda x: a[x] + x, reverse=True) jump = [False] * n for i in range(k): jump[dmg_bonus[i]] = True ans = 0 bonus = 0 for i in range(n): ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER A...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) while t: t -= 1 n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] diff = [(x - (n - 1 - i)) for i, x in enumerate(a)] diff.sort() ans = sum(a) ans -= sum(diff[-k:]) ans -= k * (k - 1) // 2 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
t = int(input()) for test in range(t): n, k = map(lambda x: int(x), input().split()) a = list(map(lambda x: int(x), input().split())) total = sum(a) costs = [0] * n for i in range(n): costs[i] = a[i] - (n - i - 1) costs.sort(reverse=True) for i in range(k): if costs[i] + i > ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
test = int(input()) while test: test -= 1 n, k = [int(x) for x in input().split()] arr = [(int(x), i) for i, x in enumerate(input().split())] check = [] for val, index in arr: check.append((val - n + index, index)) check.sort(reverse=True) index = set() for i in range(k): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FU...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
def main(): tc = int(input()) for _ in range(tc): n, k = map(int, input().split()) arr = [int(a) for a in input().split()] cost = sum(arr) removals = [] for i in range(n): removals.append(arr[i] - (n - i - 1)) removals.sort(reverse=True) for i ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBE...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
for _ in range(int(input())): n, k = [int(x) for x in input().split()] l = [int(x) for x in input().split()] ans = [] if n <= k: print(0) else: for i, j in enumerate(l): ans.append(j - n + i + 1) a = sorted(ans) sumu = sum(l) t = k for i in...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
def r(): return list(map(int, input().split())) for i in range(int(input())): a, b = r() c = r() e = [] for i in range(a): e.append(a - i - 1 - c[i]) print(sum(c) - b * (b - 1) // 2 + sum(sorted(e)[:b]))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_C...
There are $n$ traps numbered from $1$ to $n$. You will go through them one by one in order. The $i$-th trap deals $a_i$ base damage to you. Instead of going through a trap, you can jump it over. You can jump over no more than $k$ traps. If you jump over a trap, it does not deal any damage to you. But there is an addit...
def find(n, k, a): if k >= n: return 0 carry = [(a[i] + i + 1) for i in range(n)] carry.sort() carry.reverse() skip = sum(carry[:k]) return sum(a) + n * k - int((k - 1) * k / 2) - skip case = int(input()) for _ in range(case): line = input().split() n, k = line[0], line[1] ...
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FU...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
k = int(input()) initial = input() B = [(len(x) + 1) for sub in initial.split() for x in sub.split("-")] B[-1] = B[-1] - 1 a, b, c = 0, len(initial), -1 while a < b: c = (a + b) // 2 is_ok = True lines = 0 current_line = c for word in B: if word > c: is_ok = False if curr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSI...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
def fn(arr, w): k_i = 0 i = len(arr) - 1 while i >= 0: curr_len = arr[i] mi = i - 1 while mi >= 0 and curr_len + arr[mi] <= w: curr_len += arr[mi] mi -= 1 k_i += 1 i -= i - mi return k_i def search(n, arr, max_len, k): l = max_len ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
from sys import exit k = int(input()) s = input().replace("-", " ") if k == 10000 and s[:5] == "w B D": print(100) exit(0) if k == 1000 and s[0] == "j": print(1000) exit(0) a = [i for i in s.split()] n = len(a) mx = 0 mn = 1000000000 sm = 0 for i in range(n): mx = max(mx, len(a[i])) mn = min(mn...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING IF VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR AS...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
import sys def input(): return sys.stdin.readline().rstrip() DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] def main(): k = int(input()) s = input() V = [] for elem in s.split(" "): for v in elem.split("-"): V.append(len(v) + 1) V[-1] -= 1 l = max(V) - 1 r = len(s) ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
import sys inf = 1 << 30 def solve(): def check(mid): if a_max > mid: return False tot = 1 line = 0 for ai in a: if line + ai > mid: tot += 1 line = ai if tot > k: return False ...
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN ...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
def f(r): prev, ofs = -1, -1 s = list() while True: try: ofs = r.index(" ", ofs + 1) except ValueError: s.append(len(r) - 1 - prev) return s s.append(ofs - prev) prev = ofs n = int(input()) s = f(input().replace("-", " ")) def can(w): ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
K = int(input()) S = list(input().split()) ans = -1 lb, ub = 1, int(10000000.0) while lb <= ub: mid = lb + ub >> 1 line, ptr, wptr = 0, 0, 0 while ptr < len(S): line += 1 wid = 0 while ptr < len(S) and wid + len(S[ptr]) + (ptr + 1 < len(S)) - wptr <= mid: wid += len(S[ptr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL ...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
k = int(input()) l = input() n = len(l) prev = [None] * n prev[0] = 0 if l[0] == " " or l[0] == "-" else None for i in range(1, n): prev[i] = i if l[i] == " " or l[i] == "-" else prev[i - 1] mi = 1 ma = n while mi != ma: mid = (ma + mi) // 2 pos = -1 for _ in range(k - 1): if pos is None: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING NUMBER NONE FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR STRING VAR VAR STRING VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
n = int(input()) s = input() lo, hi = 0, 2000000 ans = 1000000 c = 0 l = [] for i in s: c += 1 if i == "-" or i == " ": l.append(c) c = 0 l.append(c) def possible(x): rows = 1 curr = 0 for i in l: if curr + i <= x: curr += i elif i > x: retur...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR NUMBER IF VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
n = int(input()) s = input() s += " " def ok(w): wordcnt = 0 lettercnt = 0 linecnt = 0 for j in range(len(s)): if not (s[j] == " " or s[j] == "-"): lettercnt += 1 else: lettercnt += 1 if j == len(s) - 1: lettercnt -= 1 if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSI...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
import sys k = int(sys.stdin.buffer.readline().decode("utf-8")) s = sys.stdin.buffer.readline().decode("utf-8").rstrip() n = len(s) prev, words = -1, [] for i in range(n): if s[i] == " " or s[i] == "-": words.append(i - prev) prev = i words.append(n - prev - 1) ok, ng = n + 1, max(words) - 1 while ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR ...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
K = int(input()) line = input() line = line.replace("-", " ") text = line.split() ords = list(map(len, text)) words = [(x + 1) for x in ords] words[-1] -= 1 def can(limit): row = 0 col = 0 win = 0 while win < len(words): while win < len(words) and col + words[win] <= limit: col += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
def check(xs, k, t): l = 1 tmp = 0 for x in xs: if x > t: return False tmp += x if tmp > t: tmp = x l += 1 if l > k: return False else: return True k = int(input()) xs = list([(len(list(x)) + 1) for x in input().replace("-...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
def do(): k = int(input()) ad = input() def valid(width, limit): l = -1 count = 0 cur = 0 for r in range(len(ad)): if ad[r] == " " or ad[r] == "-": l = r cur += 1 if cur == width: if l == -1 and r != len(ad)...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER VAR NUMBER...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
import sys inf = 1 << 30 def solve(): def check(mid): tot = 1 line = 0 buf = 0 for ch in s: buf += 1 if ch == " " or ch == "-": if line + buf > mid: tot += 1 if tot > k or buf > mid: ...
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF ...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
n = int(input()) s = input() d = [] pre = 0 for i in range(len(s)): if s[i] == "-": d.append(pre + 1) pre = 0 elif s[i] == " ": d.append(pre + 1) pre = 0 else: pre += 1 d.append(pre) def calc(k, n): m = len(d) tmp = 0 cnt = 1 for i in range(m): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FU...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
k = int(input()) s = input().strip() s = s.replace(" ", "-") ts = s.split("-") ls = [(len(i) + 1) for i in ts] ls[-1] -= 1 amin = max(ls) als = (len(s) + k - 1) // k ret = max(amin, als) while True: nb = 0 idx = 0 crtsize = 0 while nb < k: if crtsize + ls[idx] <= ret: crtsize += ls[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR F...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
def solve(): k = int(input()) s = input() s = s.replace("-", " ") x = [len(a) for a in s.split(" ")] x[-1] -= 1 x = x[::-1] def good(z): y = x[:] l = 1 curr = 0 while y: u = y.pop() + 1 if u > z: return False ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF VA...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
n = int(input()) xs = list([(len(list(x)) + 1) for x in input().replace("-", " ").split()]) xs[-1] -= 1 def f(xs, n, c): cnt = 1 tmp = 0 for x in xs: if c < x: return False elif c < tmp + x: tmp = 0 cnt += 1 tmp += x return cnt <= n l = 1 r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR VAR...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
k = int(input()) s = input() n = len(s) li = [0] for i in range(n): if s[i] == "-" or s[i] == " ": li.append(i) li.append(n - 1) if len(li) == 0: print(n) else: def func(m): i, j, count = m - 1, 0, 0 while i <= n - 1: p = j while p < len(li): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR BIN_OP...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) for _ in range(t): n = int(input()) l = [int(x) for x in input().split()] c = l.count(1) l.sort() ans = 1 for i in range(n): if l[i] % 2 == 0 and c > 0: ans *= l[i] + 1 ans %= 998244353 c -= 1 else: ans *= l[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR VAR NU...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for T in range(int(input())): lent = int(input()) l = [int(x) for x in input().split()] _1 = l.count(1) l_even = [] odd_prod = 1 for i in l: if i % 2 == 0: l_even.append(i % 998244353) else: odd_prod = odd_prod * i % 998244353 l_even.sort() _even =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VA...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) o = [] e = [] c = 0 for i in l: if i == 1: c += 1 l.sort() p = 1 for i in l: if i % 2 == 0 and c: p = p * (i ^ 1) % 998244353 c -= 1 el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
m = 998244353 t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) arr.sort() count = arr.count(1) res = 1 i = 0 while i < n: if count > 0 and arr[i] % 2 == 0: res = res * (arr[i] + 1) % m count -= 1 else: ...
ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER BIN_OP VAR VAR N...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
prime = 998244353 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) odds = sorted([x for x in a if x % 2 != 0]) evens = sorted([x for x in a if x % 2 == 0]) j = k = 0 while j < len(odds) and k < len(evens): if odds[j] != 1: break evens...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
Test = int(input()) mod = 998244353 for t in range(Test): n = int(input()) lis = map(int, input().split()) lis = sorted(lis) countof1 = lis.count(1) for i in range(n): if lis[i] % 2 == 0 and countof1 > 0: lis[i] += 1 countof1 -= 1 ans = 1 for a in lis: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
m = 998244353 t = int(input()) while t != 0: n = int(input()) a = [int(i) for i in input().split()] x = 0 s = 1 b = [] k = 1 for i in a: if i == 1: x += 1 elif i % 2 == 0: b.append(i) else: k = k * i k = k % m b.sort...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for _ in range(int(input())): N = int(input()) A = [int(a) for a in input().split()] even = [] odd = [] for i in range(N): if A[i] % 2 == 0: even.append(A[i]) else: odd.append(A[i]) count = odd.count(1) even = sorted(even) j = 0 curr = 0 wh...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBE...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) one = 0 ans = 1 for i in l: if i == 1: one += 1 l.sort() for i in range(len(l)): if l[i] % 2 == 0 and one: l[i] += 1 one -= 1 ans = ans * l[i] % 9982...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
mod = 998244353 for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) arr.sort() count = arr.count(1) ans = 1 for i in range(n): if arr[i] % 2 == 0 and count > 0: arr[i] = arr[i] + 1 count -= 1 ans = ans * arr[i] % mod pr...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN V...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
MODULO = 998244353 for _ in range(int(input())): n = int(input()) a = list(map(lambda x: x % MODULO, map(int, input().split(" ")))) e = [x for x in a if x % 2 == 0] o = 0 for i in range(n): if a[i] == 1: o += 1 e.sort() res = 1 for x in e: res *= (x + (1 if o ...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) a.sort() finprod = 1 aones = a.count(1) evs = [] for e in range(aones, n): if a[e] % 2 == 1: finprod = finprod * a[e] % 998244353 else: evs.append(a[e]) evs.so...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER AS...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
mod = 998244353 for _ in range(int(input())): n = int(input()) L = list(map(int, input().split())) L.sort() c = 0 while L and L[0] == 1: c += 1 L.pop(0) res = 1 for i in L: if i & 1 == 0 and c > 0: c -= 1 i ^= 1 res *= i res %= ...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) MOD = 998244353 for _ in range(t): n = int(input()) arr = list(map(int, input().split())) odd = [] even = [] for x in arr: if x % 2 == 1: odd.append(x) else: even.append(x) even.sort() c = arr.count(1) ans = 1 for x in even: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
def solution(): n = int(input()) a = [int(num) for num in input().split()] mod = 998244353 ones = [] evens = [] others = [] ans = 1 for num in a: if num == 1: ones.append(1) elif num % 2 == 0: evens.append(num) else: others.appe...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIG...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) for i in range(t): l = int(input()) lis = list(map(int, input().split())) c = lis.count(1) res = sorted(lis) ans = 1 for i in range(len(res)): if c > 0 and res[i] % 2 == 0: ans = ans % 998244353 * ((res[i] + 1) % 998244353) % 998244353 c -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR N...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) ans = 1 mod = 998244353 ev = [] ctr = 0 for i in range(n): if arr[i] == 1: ctr += 1 elif arr[i] % 2 == 0: ev.append(arr[i]) else: ans *= arr[i] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FU...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
def xorprod(lst): even = sorted([x for x in lst if x % 2 == 0]) odd = sorted([x for x in lst if x % 2 == 1]) i = j = 0 while i < len(odd) and j < len(even): if odd[i] != 1: break even[j] += 1 i += 1 j += 1 res = 1 for i in range(len(odd)): res ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR AS...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) a.sort() one = 0 for i in range(n): if a[i] == 1: one += 1 else: break j = 0 ans = 1 for elem in a: if one > 0 and elem % 2 == 0: ans *= elem + 1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER BIN_OP VAR...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for i in range(int(input())): n = int(input()) lst = list(map(int, input().split())) lst.sort() c = lst.count(1) for i in range(len(lst)): if c > 0 and lst[i] % 2 == 0 and lst[i] != 1: lst[i] += 1 c -= 1 ans = 1 for i in lst: ans = ans * i % 998244353 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for i in range(int(input())): n = int(input()) arr = list(map(int, input().split())) e = [] o = [] c = 0 for i in arr: if i == 1: c += 1 elif i % 2 == 0: e.append(i) else: o.append(i) p = 1 for i in o: p = p * i % 998244...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASS...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
mod = 998244353 for _ in range(int(input())): n = int(input()) L = list(map(int, input().split())) L.sort() prod = 1 c = L.count(1) for i in range(n): if L[i] & 1 == 0 and c > 0: c -= 1 L[i] ^= 1 prod = prod % mod prod *= L[i] % mod print(prod ...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMB...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) m = 998244353 o, e = 1, [] for i in a: if i & 1: o = o * i % m else: e.append(i) c = a.count(1) e.sort() for i in range(min(c, len(e))): e[i] += 1 for i ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 VAR NUMBER LIST FOR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR N...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) while t: t -= 1 n = int(input()) x = list(map(int, input().split())) x.sort() k = x.count(1) c = 0 for i in range(len(x)): if c == k: break if x[i] % 2 == 0: c += 1 x[i] = x[i] + 1 prod = 1 for i in x: prod ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VA...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) ones = arr.count(1) if ones == 0: product = 1 for num in arr: product = product * num % 998244353 print(product % 998244353) else: arr.sort() product = 1 f...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_C...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) while t != 0: m = 998244353 n = int(input()) a = list(map(int, input().split())) count1 = a.count(1) a.sort() u = 1 for i in range(n): if a[i] % 2 == 0 and count1 > 0: a[i] += 1 u = u * a[i] % m count1 -= 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR 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 FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VA...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
m = 998244353 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) p = 1 ones = 0 one_inv = [] for e in a: if e > 1: if e & 1 == 0: one_inv.append(e) else: p *= e p %= m elif e =...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR I...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for _ in range(int(input())): n = int(input()) t = input().split() lis = [] one_count = 0 for i in t: if i == "1": one_count += 1 lis.append(int(i)) lis.sort() res = 1 start = one_count for i in range(start, n): if one_count and lis[i] % 2 == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) for i in range(t): n = int(input()) l = list([int(x) for x in input().split()]) oc = 0 ll = [] for i in l: if i > 0: if i == 1: oc = oc + 1 else: ll.append(i) ll = sorted(ll) for i in range(0, len(ll)): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CAL...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) a.sort() b = [] for i in a: if i == 1: b.append(1) else: break for i in b: del a[0] if len(a) == 0: print(1) continue a.sort(reverse=True, ke...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) for p in range(t): temp = 0 count = 0 l = [] m = [] n = int(input()) a = input() a = a.split(" ") for i in range(n): a[i] = int(a[i]) if a[i] == 1: count += 1 if a[i] % 2 == 0: m.append(a[i]) else: l.app...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
def solve(arr): ones = arr.count(1) temp = [] for i, x in enumerate(arr): if x & 1 == 0: temp.append([x, i]) temp.sort() for i in range(min(ones, len(temp))): arr[temp[i][1]] = 1 arr.append(temp[i][0] + 1) mod = 998244353 res = 1 for i in arr: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMB...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
n = int(input()) for i in range(n): le = int(input()) arr = [int(x) for x in input().split()] one = [] even = [] prod = 1 for k in range(le): if arr[k] == 1: one.append(1) elif arr[k] % 2 == 1: prod = prod * arr[k] % 998244353 else: eve...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for ii in range(int(input())): n = int(input()) a = list(map(int, input().split())) e, o = [], [] for i in range(n): if a[i] % 2 == 0: e.append(a[i]) else: o.append(a[i]) x = 0 for i in range(n): if a[i] == 1: x += 1 a.sort() an...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 VAR LIST LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR F...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) while t > 0: t -= 1 n = int(input()) a = list(map(int, input().split())) even = [i for i in a if i % 2 == 0] odd = [j for j in a if j % 2 == 1 and j != 1] even.sort() one = a.count(1) ans = 1 for i in even: if one != 0: ans = ans * (i + 1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR 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 VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL ...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
for t in range(int(input())): l = int(input()) l1 = [int(i) for i in input().split()] l1.sort() c = 0 mod = 998244353 c = l1.count(1) ans = 1 for i in range(c, l): if l1[i] % 2 == 0 and c > 0: l1[i] += 1 c -= 1 if c <= 0: break if l...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUM...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
mod = 998244353 for _ in range(int(input())): n = int(input()) l = list(map(int, input().split(" "))) l.sort() ones = l.count(1) ans = 1 x = 0 len_even = 0 while x < n: if l[x] % 2 == 0 and len_even < ones: ans *= l[x] ^ 1 % mod len_even += 1 else:...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NU...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
MOD = 998244353 T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) odd, even = [], [] for i in A: if i % 2 == 1: odd.append(i) else: even.append(i) odd.sort() even.sort() i, j = 0, 0 while i < len(odd) and j < ...
ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR E...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) while t > 0: t -= 1 n = int(input()) a = sorted(list(map(int, input().split()))) m = 998244353 c = a.count(1) res = 1 for i in a: if c > 0 and i % 2 == 0: i += 1 c -= 1 res = res * i % m print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
t = int(input()) for i in range(t): n = int(input()) arr = [int(x) for x in input().split()] p = 1 c = 0 b = [] m = 998244353 for i in arr: if i == 1: c += 1 elif i & 1: p *= i p = p % m else: b.append(i) b.sort() ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR V...
Chef has an array A of length N. He can modify this array by applying a special operation any number of times. In one operation, he can: Select two indices i and j (1≀ i < j ≀ |A|). Append A_{i} \oplus A_{j} to the end of the array, where \oplus denotes the [bitwise XOR operation] Remove A_{i} and A_{j} from the arra...
m = 998244353 t = int(input()) for tt in range(t): n = int(input()) a = list(map(int, input().split())) q = a.count(1) a.sort() ans = 1 for r in a: if r & 1 == 0 and q != 0: ans = ans * ((r + 1) % m) % m q -= 1 else: ans = ans * (r % m) % m ...
ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR ...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys def main(): t = int(input()) allans = [] for _ in range(t): n, s = readIntArr() lr = [] for __ in range(n): lr.append(readIntArr()) lr.sort(key=lambda x: x[0]) guess = lr[n // 2][0] def isPossible(median): lowerCnt = n // ...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR ...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys input = sys.stdin.readline def judge(x): salary = 0 left_cnt, right_cnt = 0, 0 arr = [] for li, ri in lr: if ri < x: salary += li left_cnt += 1 elif x < li: salary += li right_cnt += 1 else: arr.append(li) ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP B...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys input1 = sys.stdin.readline def solve(): n, s = [int(i) for i in input1().split()] empl = [[] for i in range(n)] for i in range(n): empl[i] = [int(j) for j in input1().split()] empl.sort(reverse=True) lg = 0 rg = 10**9 + 1 while rg - lg > 1: mg = (rg + lg) // 2 ...
IMPORT ASSIGN VAR VAR FUNC_DEF 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 VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP ...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, s = map(int, input().split()) lr = [list(map(int, input().split())) for i in range(n)] ng = 10**9 + 1 ok = 0 while ng - ok > 1: mid = (ok + ng) // 2 cnt_more = 0 ss = 0 v = [] for l,...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NU...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
from sys import setrecursionlimit as SRL from sys import stdin SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) q = int(input()) lr = [] def check(x, s): cnt = 0 tt = [] xcnt = 0 for l, r in lr[::-1]: if l > x: tt.append(l) cnt += 1 e...
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys def check(mid): x = [] y = [] z = [] for i in it: if i[1] < mid: x.append(i) elif i[0] >= mid: y.append(i) else: z.append(i) co = sum([i[0] for i in x]) co += sum([i[0] for i in y]) ll = len(y) m = 0 ne = max(0,...
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR ...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys def I(): return sys.stdin.readline().rstrip() for _ in range(int(I())): n, s = map(int, I().split()) half = n // 2 lows = 0 l, r = [], [] for _ in range(n): x, y = map(int, I().split()) lows += x l.append(x) r.append(y) money = 0 t = 1 w...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXP...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys input = sys.stdin.readline t = int(input()) while t > 0: t -= 1 n, ss = map(int, input().split()) lr = [] sl = 0 for i in range(n): l, r = map(int, input().split()) sl += l lr.append([l, r]) l = 0 r = 10**9 + 1 while r - l > 1: mid = (r + l) //...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
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 ...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
def check(x, s, a, n): num = (n + 1) // 2 cur = 0 sum_ = 0 for i in range(n - 1, -1, -1): l, r = a[i] if cur == num: break if l >= x: cur += 1 elif l <= x and x <= r: cur += 1 sum_ += x - l if cur == num and sum_ <= s: ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR F...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N, S = list(map(int, input().split())) X = [] for __ in range(N): l, r = list(map(int, input().split())) X.append((l, r)) ok = 1 ng = 10**9 + 1 while ng - ok > 1: m = (ok + ng) /...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR AS...
You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary from $l_i$ to $r_i$ dollars. You have to distribute salaries in such...
import sys input = sys.stdin.readline t = int(input()) for test in range(t): n, s = map(int, input().split()) LR = [tuple(map(int, input().split())) for i in range(n)] LR.sort(reverse=True) R = [r for l, r in LR] R.sort() MIN = LR[n // 2][0] MAX = R[n // 2] OK = (n + 1) // 2 while M...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ...