description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
res = [] for _ in range(int(input())): n = int(input()) S = list(map(int, input().split())) result = 0 for i in range(n): rejumps = 0 for j in range(i): rejumps += max(0, S[j] - (i - j)) result = max(result, S[i] + rejumps - 1) res.append(result) print(*res, sep="...
ASSIGN VAR LIST 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIG...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
for _ in range(int(input())): n = int(input()) s = [int(i) for i in input().split()] passes = 0 jumps = [0] * (n + 1) for ind in range(n): jump = jumps[ind] if s[ind] - 1 > jump: passes += s[ind] - 1 - jump jump += s[ind] - 1 - jump jumps[ind + 1] += j...
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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER V...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
t = int(input()) for _ in range(t): n = int(input()) nums = list(map(int, input().split())) minus = [0] * n ans = 0 for i in range(n): ans += nums[i] - minus[i] - 1 cur = 0 for j in range(i + 2, n): if j <= i + nums[i]: cur += 1 if not ...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) l = [0] * n ans = 0 for i in range(n): x = a[i] - 1 - l[i] ans += max(x, 0) for j in range(min(a[i], n - i - 1) - 1): l[i + 2 + j] += 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_C...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def solve(): t = int(input()) listOfArr = [] for x in range(t): n = int(input()) listOfArr.append(list(map(int, input().split()))) for x in range(t): currentArr = listOfArr[x] ans = 0 for y in range(len(currentArr) - 1, -1, -1): for z in range(y + 2, m...
FUNC_DEF 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 EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
t = int(input()) for _ in range(t): n = int(input()) a = [0] + [int(i) for i in input().split()] dp = [0] * (n + 5) res = 0 cnt = 0 s = 0 for i in range(1, n + 1): s += dp[i] cnt += s if cnt >= a[i] - 1: cnt -= a[i] cnt += 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) ans = 0 g = [0] * (n + 5) las = 0 for i in range(n): tmp = g[i] + las las = tmp if tmp > a[i] - 1: g[i + 1] += tmp - a[i] + 1 g[i + 2] -= tmp - a[i] + 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def read_list() -> list: return [int(i) for i in input().strip().split()] def read_num() -> int: return int(input().strip()) t = read_num() for _ in range(t): n = read_num() arr = read_list() ans = 0 cnt_change = [0] * (n + 5) cnt = 0 for i in range(n): cnt += cnt_change[i] ...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER F...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline def solution(n, a): s_s_p = [(0) for _ in range(n)] s_s_p[-1] = a[-1] - 1 if n > 1: s_s_p[-2] = a[-2] - 1 for p in range(n - 3, -1, -1): val = a[p] if val > 1: if p + val > n - 1: s_s_p[p] += p + val - (n - 1) ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR ...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
t = int(input().strip()) for _ in range(t): n = int(input().strip()) res = 0 jump = [0] * (n + 1) for i, s in enumerate(map(int, input().strip().split())): if s != 1: m = min(n + 1, i + s + 1) res += s - m + i + 1 for x in range(i + 2, m): jump...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NU...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [int(a) for a in input().split()] B = [0] * N ans = 0 for i in range(N): a = A[i] ans += max(a - 1 - B[i], 0) for j in range(2, min(a + 1, N - i)): B...
IMPORT ASSIGN VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BI...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def solve(N, nums): ans = 0 for i in range(N): temp = 0 for j in range(i): temp += max(0, nums[j] - (i - j)) ans = max(ans, temp + nums[i] - 1) return ans T = int(input()) for _ in range(T): N = int(input()) nums = list(map(int, input().split())) ans = solve...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
for _ in range(int(input())): n = int(input()) arr = [int(x) for x in input().split()] extra = [0] * n cost = 0 for i in range(n): if arr[i] == 1: if extra[i] > 0: if i != n - 1: extra[i + 1] += extra[i] elif extra[i] + 1 < 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF BI...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def array(f): return list(map(f, input().split())) def slv(): n = int(input()) a = array(int) rabbit = [0] * (n + 1) ans = 0 for i, v in enumerate(a): if v - rabbit[i] > 1: new_rabbit = v - rabbit[i] - 1 rabbit[i] += new_rabbit ans += new_rabbit ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def main(): t = int(input()) result = [] for _ in range(t): n = int(input()) s = list(map(int, input().split())) ans = 0 jumps_cnt = [0] * (n + 1) for i in range(n): curr_jumps = jumps_cnt[i] if curr_jumps < s[i] - 1: ans += s[i...
FUNC_DEF 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def solution(n): pref = [(0) for _ in range(n + 1)] s = [int(i) for i in input().split()] for i in range(n): if s[i] > 1: pref[min(i + 2, n)] += 1 pref[min(s[i] + 1 + i, n)] -= 1 for i in range(n): pref[i + 1] += pref[i] for i in range(n): if pref[i] -...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) s = [int(x) for x in input().split()] a = [] for i in range(n): a.append((i + 1, i)) a.append((s[i] + i, i)) a.sort() j = 0 o = set() ans = 0 b = [] for i in range(n...
ASSIGN VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) S = list(map(int, input().split())) todo = [0] * n out = 0 for i in range(n): need = S[i] - 1 smol = todo[i] act = max(smol, need) out += act - smol for j in range(2, S...
IMPORT ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR V...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys pin = sys.stdin.readline def aupdate(n, v): while n < len(tree): tree[n] += v n += n & -n def update(l, d, v): aupdate(l, v) aupdate(l + d, -v) def query(n): ans = 0 while n: ans += tree[n] n -= n & -n return ans for T in range(int(pin())): ...
IMPORT ASSIGN VAR VAR FUNC_DEF WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FU...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) li = [0] * n ans = 0 for i in range(n): xx = ar[i] - 1 - li[i] tem = max(xx, 0) ans += tem if xx < 0 and i + 1 < n: li[i + 1] += abs(...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline def main(): n = int(input()) slst = list(map(int, input().split())) ans = 0 minus = [0] * (n + 1) for i, s in enumerate(slst): tmp = s - 1 for j in range(2, s + 1): pos = i + j try: minus[pos] += 1 ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR ...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def solve(): n = int(input()) s = list(map(int, input().split())) on = [0] * n ans = 0 for i, x in enumerate(s): ans += max(0, x - on[i] - 1) on[i] += max(0, x - on[i] - 1) for j in range(2, min(n - i, x + 1)): on[i + j] += 1 on[i] -= x - 1 if i < ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER FOR...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) dp = [] dp.append([max(0, a[0] - 1)]) dp[0].append(0) for i in range(1, n): temp = 0 for j in range(0, i - 1): if a[j] + j >= i: temp += 1 temp += dp[i - 1][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 ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR N...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") inp = lambda: list(map(int, sys.stdin.readline().rstrip("\r\n").split())) mod = 10**9 + 7 Mod = 998244353 INF = float("inf") tc = 1 (tc,) = inp() for _ in range(tc): (n,) = inp() a = inp() ans = 0 free = [0] * n for i in range(n): ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL V...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def func(A): n = len(A) C = [(0) for x in range(n)] res = 0 for i in range(n): if A[i] - C[i] > 1: res += A[i] - 1 - C[i] C[i] = A[i] - 1 try: C[i + 1] += C[i] - A[i] + 1 except: pass for j in range(i + 2, min(n - 1, i + A[i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
from sys import stdin, stdout input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] pre = [(0) for i in range(n)] ans = 0 for i in range(n): jumps = [(0) for j in range(n)] jumps[0] = pre[0] for j in range(1, n): ...
ASSIGN VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) s = [int(x) for x in input().split()] a = [0] * (n + 1) b = [] ans = 0 for i in range(n): b.append(s[i] - 1 - a[i]) if s[i] - 1 - a[i] < 0: a[i + 1] += abs(s[i] - 1 - a[...
ASSIGN VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
TC = int(input().strip()) for tc in range(TC): n = int(input().strip()) arr = [int(i) for i in input().strip().split()] curr = [0] * (n + 1) ans = 0 for x in range(n): temp = curr[x] if temp < arr[x] - 1: ans += arr[x] - 1 - temp y = arr[x] - 1 - temp ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR ...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = [0] * (n + 1) for i in range(n): if a[i] == 1: continue if i + a[i] >= n: for j in range(i + 2, n): s[j] += 1 else: for j in range(i + 2, 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
test = int(input()) for t in range(test): n = int(input()) s = list(map(int, input().split())) r = [0] * n res = 0 for i in range(n): b = i + 2 e = min(i + s[i], n - 1) if e >= b: for i2 in range(b, e + 1): r[i2] += 1 if i < n - 1 and r[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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) prev = [0] * n res = 0 for i in range(n): a[i] -= 1 for i in range(n - 1): if prev[i] > a[i]: prev[i + 1] += prev[i] - a[i] if a[i] > n - i - 2: res += a[i] - (n - 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP V...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
for _ in range(int(input())): n = int(input()) s = list(map(int, input().split())) d = 0 debt = 0 k = 0 kmap = dict() for i in range(n): k -= kmap.get(i, 0) d += max(s[i] - (debt + k), 0) debt = max(debt + k - s[i], 0) k += 1 kmap[i + s[i] + 1] = kmap....
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 NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR V...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
p = lambda: list(map(int, input().split())) exec( "N=p()[0];s=p();print(max(s[i]+sum([max(0,s[j]-i+j)for j in range(i)])-1for i in range(N)));" * p()[0] )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR NUMBER
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
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.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline for nt in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = 0 c = [0] * n for i in range(n): if a[i] > c[i] + 1: ans += a[i] - c[i] - 1 c[i] += a[i] - c[i] - 1 if i != n - 1: c[i ...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR V...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
def main(): t = int(input()) for i in range(t): print(solve()) def add_range(pos, _range, array, diff): n = len(array) start, end = _range if pos + start < n: array[pos + start] += diff if pos + end < n: array[pos + end] -= diff return array def solve(): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN ...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline def slow_solve(n, Ss): ans = 0 for i in range(n): if Ss[i] >= n - i: ans += Ss[i] - (n - i) Ss[i] = n - i while Ss[i] > 1: ans += 1 cur = i while cur < n: pre = cur ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUM...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys class BinaryIndexedTree: def __init__(self, size): self.data = [0] * (size + 1) self.msb = 1 << size.bit_length() - 1 def _add(self, i, w): i += 1 while i < len(self.data): self.data[i] += w i += i & -i def _get_sum(self, i): re...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER FUNC_DEF VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
from sys import * for _ in range(int(stdin.readline())): n = int(stdin.readline()) l = [int(x) for x in stdin.readline().split()] ind = 0 ans = 0 sp = [0] * n while ind < n and l[ind] == 1: ind += 1 if ind == n: print(0) continue while ind < n: if l[ind] ...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR IF VAR VAR NU...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline def solve(): n = int(input()) s = list(map(int, input().split())) z = list(range(n)) r = 0 for i in range(n): v = s[i] if v + i > n - 1: v = max(n - 1 - i, 1) if s[i] != v: r += s[i] - v ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VA...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
t = int(input()) for _ in range(t): n = int(input()) arr = [int(i) for i in input().split()] cur = [0] * (n + 10) ans = 0 for i in range(n): diff = cur[i] - arr[i] if diff >= 0: cur[i + 1] += diff + 1 else: ans += abs(diff) cur[i + 1] += 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMB...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) ans = 0 s = list(map(int, input().split())) l = [0] * (n + 1) for i in range(n): if s[i] <= l[i]: l[i + 1] += l[i] - s[i] + 1 ans += max(0, s[i] - l[i] - 1) for j in range(...
IMPORT ASSIGN VAR 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 NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR N...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) arr = [int(x) for x in input().split()] temp = [(0) for i in range(n)] ans = 0 for i in range(n): curr = temp[i] if temp[i] + 1 < arr[i]: ans += arr[i] - (curr + 1) curr += a...
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR V...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
n = int(input()) while n > 0: n -= 1 counter = 0 num = int(input()) arr = list(map(int, input().split())) z = [0] * (num + 1) for i in range(len(arr)): current = z[i] if current < arr[i] - 1: counter += arr[i] - current - 1 current += arr[i] - current - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR ...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
t = int(input()) while t: t -= 1 n = int(input()) arr = list(map(int, input().split())) c = [(0) for i in range(n)] ans = 0 for i in range(n): if i > 0: c[i] += c[i - 1] if c[i] <= arr[i] - 1: ans += arr[i] - 1 - c[i] if arr[i] > 1: if ...
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR ...
There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$. Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, a...
import sys input = sys.stdin.readline flush = sys.stdout.flush for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) B = [0] * n ans = 0 for i in range(n): if A[i] - B[i] > 1: ans += A[i] - B[i] - 1 B[i] = A[i] - 1 for j in range(...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_O...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
q = int(input()) for _ in range(q): t = input() n = int(input()) S = [input() for i in range(n)] cur = 0 mx = -1 ans = [] mxid = 0 flag_bad = False for i in range(len(t)): for ids in range(len(S)): if i + len(S[ids]) <= len(t) and t[i : i + len(S[ids])] == S[ids]:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CAL...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
for _ in range(int(input())): st = input() case = [] length = len(st) for i in range(int(input())): case.append(input()) tas = [] dp = [0] + [float("inf")] * length dic = {} dic2 = {} bre = False for i in range(0, length): for x in range(len(case)): le...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR DICT ASSIGN VAR DICT AS...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
q = int(input()) def find(index, text, arr, n): id = -1 mx_length = 0 for i in range(n): if text[index:].find(arr[i]) == 0 and len(arr[i]) > mx_length: mx_length = len(arr[i]) id = i + 1 return id def solve(): t = input() n = int(input()) arr = [] for ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR AS...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
from itertools import islice t = int(input()) for i in range(t): text = input() m = int(input()) strings = [] indexes = {} for i in range(m): strings.append(input()) indices = [-1] * (len(text) + 1) for index, string in enumerate(strings): i = 0 while i + len(string)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN V...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
def main(): t = input() n = len(t) ans = [] ok = True substrings = [] for _ in range(int(input())): substrings.append(input()) s = sorted(substrings, key=len, reverse=True) i = 0 while i < n: max_len = i index = 0 pos = 0 for w in s: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER F...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
def solve(): t = input() n = int(input()) strings = [] for i in range(n): strings.append(input()) intervals = [] for i in range(n): for j in range(len(t)): if t[j : j + len(strings[i])] == strings[i]: intervals.append((j, j + len(strings[i]), i)) i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR FUNC...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
def find(a, b, t, strs, ans): maxi, id, pos = 0, -1, -1 for i in range(a, b + 1): for j in range(len(strs)): s = strs[j] c = i + len(s) if c > len(t) or c <= b: continue if t[i:c] == s and c > maxi: maxi = c ...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN LI...
You are given some text $t$ and a set of $n$ strings $s_1, s_2, \dots, s_n$. In one step, you can choose any occurrence of any string $s_i$ in the text $t$ and color the corresponding characters of the text in red. For example, if $t={bababa}$ and $s_1={ba}$, $s_2={aba}$, you can get $t={{ba}}{baba}$, $t={b}{{aba}}{ba...
ans = 0 ok = True def Find(a, b, t, s_list, match): global ans, ok Max, id, pos = 0, -1, -1 for i in range(a, b + 1): for j in range(len(s_list)): s = s_list[j] if i + len(s) > len(t) or i + len(s) <= b: continue if t[i : i + len(s)] == s: ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF BI...
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$. You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times: select an index $i$ ($1 \le i \le n$) such that $a_i=0$; then rep...
t = int(input()) for _ in range(t): n = int(input()) a = [int(i) for i in input().strip().split()] s = [] curr = 0 for i in range(n): curr += a[i] s.append(curr) ans = 0 l = [] for i in range(n): if a[i] == 0: l.append(i) a[i] = ans if ...
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 FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VA...
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$. You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times: select an index $i$ ($1 \le i \le n$) such that $a_i=0$; then rep...
t = int(input()) while t > 0: a = int(input()) b = list(map(int, input().split())) ans = 0 sum = 0 d = {} maxCount = 0 for i in range(len(b) - 1, -1, -1): if b[i] == 0: zeroCount = 0 if 0 in d: zeroCount = d[0] ans += max(maxCount, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER AS...
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$. You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times: select an index $i$ ($1 \le i \le n$) such that $a_i=0$; then rep...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) ls = [int(x) for x in input().split()] dp = [0] * (n + 1) for i in range(1, n + 1): dp[i] = dp[i - 1] + ls[i - 1] s = 0 d = {} for i in reversed(range(n)): d[dp[i + 1]] = d.get(dp[i + 1], 0)...
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 FUNC_CALL VAR VAR VAR FUNC_CALL 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 VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VA...
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$. You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times: select an index $i$ ($1 \le i \le n$) such that $a_i=0$; then rep...
from itertools import groupby def Most_Common(lst): lst.sort() m = 0 for k, g in groupby(lst): tmp = len(list(g)) if tmp > m: m = tmp return m t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) pr_sum = [] zero_ind = [...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CA...
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$. You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times: select an index $i$ ($1 \le i \le n$) such that $a_i=0$; then rep...
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) Z = [] if not A[0]: Z.append(0) C = [A[0]] for i in range(1, n): C.append(C[-1] + A[i]) if not A[i]: Z.append(i) z = len(Z) Z.append(n) total = C[: Z[0]].count(0) ...
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF ...
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$. You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times: select an index $i$ ($1 \le i \le n$) such that $a_i=0$; then rep...
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) first_zero = False s = 0 poss = [] res = 0 for i in range(len(arr)): if arr[i] == 0: if first_zero == True: count = {} for e in poss: ...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN ...
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$. You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times: select an index $i$ ($1 \le i \le n$) such that $a_i=0$; then rep...
def max_beauty(arr): cumsum = [(0) for i in range(len(arr) + 1)] not_first = False first_beauty = 0 for i in range(len(arr)): if arr[i] == 0: not_first = True cumsum[i + 1] = cumsum[i] + arr[i] if cumsum[i + 1] == 0 and not not_first: first_beauty += 1 ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUN...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
for _ in range(int(input())): s = input() l = len(s) stack = [] d = {i: v for v, i in enumerate(s)} st = set() for i in range(l): if s[i] not in st: while stack and s[i] > stack[-1] and d[stack[-1]] > i: st.discard(stack.pop()) stack.append(s[i]) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUN...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
t = int(input()) for k in range(t): a = input() b = list(a) new = [] povt = {} for i in b: if i in povt.keys(): povt[i] += 1 else: povt[i] = 1 i = 0 while i < len(b) - 1: if b[i] in b[:i]: povt[b[i]] -= 1 b.pop(i) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER E...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
T = int(input()) r = 1 while r <= T: s = input() n = len(s) lastappear = [0] * 26 for i in range(n): lastappear[ord(s[i]) - 97] = i stack = [] already = [False] * 26 for i in range(n): if already[ord(s[i]) - 97]: continue while stack and ord(stack[-1]) <= ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") MOD = 10**9 + 7 def solve(): S = input().rstrip() d = {i: v for v, i in enumerate(S)} res = [] seen = set() for i, s in enumerate(S): if s not in seen: while res and s > res[-1] and d[res[-...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
from sys import stdin, stdout input = stdin.readline t = int(input()) for _ in range(t): s = input().strip() n = len(s) d = {} for i in s: d[i] = d.get(i, 0) + 1 l = len(d) used = set() places = [] last = 0 for p in range(l): for j in range(25, -1, -1): i...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VA...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
for _ in range(int(input())): ans = "" s = input() occ = {} for c in s: if c not in occ: occ[c] = 0 occ[c] += 1 remove = set() prev_i = -1 for i in range(len(s)): occ[s[i]] -= 1 if s[i] in remove: continue if prev_i == -1 or s[i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR ASSI...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
t = int(input()) for _ in range(t): S = input() l = [[] for i in range(26)] for i in range(len(S)): l[ord(S[i]) - ord("a")].append(i) last = [10**10] * 26 for i in range(26): if l[i]: l[i] = l[i][::-1] last[i] = l[i][0] ans = "" now = -1 while True...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUM...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
t = int(input()) for _ in range(t): s = str(input()) n = len(s) dict1 = {} for i in range(n): dict1[ord(s[i])] = i stack = [] vis = [0] * 26 for i in range(n): if vis[ord(s[i]) - 97] == 0: while stack and ord(s[i]) > stack[-1] and i < dict1[stack[-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 VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR V...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
for i in range(int(input())): s = input() if len(set(s[0:])) != len(s): while s: DEL = "" S = set(s[0:]) abc = sorted(set(s[0:])) for j in range(len(abc) - 1, -1, -1): if len(set(s[s.index(abc[j]) :])) == len(S): DEL = a...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF ...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
def solve(): s = input() exists = [[]] * 26 for i in range(len(s) - 1, -1, -1): ch = ord(s[i]) - ord("a") if exists[ch]: exists[ch].append(i) else: exists[ch] = [i] start = 0 while True: something_happened = False for use in range(25, -...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUN...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
t = int(input()) for _ in range(t): list_s = input() lastPositions = {c: pos for pos, c in enumerate(list_s)} assigned = {c: (False) for c in lastPositions} new_string = [] for pos, c in enumerate(list_s): if len(new_string) == len(assigned): break if not assigned[c]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys from sys import stdin tt = int(stdin.readline()) alp = "abcdefghijklmnopqrstuvwxyz" ANS = [] for loop in range(tt): s = list(stdin.readline()[:-1]) n = len(s) alis = [] adic = {} use = [False] * n for i in s: if i not in adic: adic[i] = True alis.appen...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR ...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys input = sys.stdin.readline t = int(input().strip()) for __ in range(t): s = input().strip() cnt = [0] * 26 vis = [0] * 26 n = len(s) for i in s: cnt[ord(i) - ord("a")] += 1 res = [] for i, c in enumerate(s): cnt[ord(c) - ord("a")] -= 1 if not vis[ord(c) - ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIST ...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
def CountAparicions(s): repeatedChars = {} for i in range(len(s)): char = s[i] if char in repeatedChars: repeatedChars[char] += 1 else: repeatedChars[char] = 1 return repeatedChars def MaxSubStr(word, NewWord=""): if word == "": return NewWord ...
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF STRING IF VAR STRING RETURN VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR NUM...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
t = int(input()) for _ in range(t): a = list(input()) trans = lambda x: ord(x) - 97 d = {} for i in a: d[trans(i)] = 0 for i in range(len(a)): d[trans(a[i])] = i used = [False] * 26 ans = [a[0]] + [""] * len(a) used[trans(a[0])] = True p = 0 for i in range(1, len(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NU...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
t = int(input()) for j in range(t): s = input() n = len(s) d = {} for i in range(n): d[s[i]] = i ans = [] st = set() for i in range(n): if s[i] not in st: while ans and s[i] > ans[-1] and d[ans[-1]] > i: st.remove(ans.pop()) ans.append(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR F...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys for _ in range(int(input())): s = input() d = {} for i in s: if i in d: d[i] += 1 else: d[i] = 1 v = [(False) for i in range(26)] temp = [] for i in s: d[i] -= 1 if v[ord(i) - ord("a")] == True: continue whil...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER WHILE VAR VAR NU...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys def can(tc, s, A, chars): t = tc[:-1] c = tc[-1] j = 0 for i in range(len(s)): if not t: break if s[i] == t[j]: j += 1 if j == len(t): break i = i + 1 if t else 0 found = False while i < len(s): if s[i] == c: ...
IMPORT FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
from sys import stdin def solve(tc): s = stdin.readline().strip() n = len(s) si = [(0) for i in range(n)] remaining = [(0) for i in range(26)] for i in range(n): key = ord(s[i]) - ord("a") si[i] = key remaining[key] += 1 st = [] curUsed = [(0) for i in range(26)] ...
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
def count(s, remove=None): c = dict() y = "" o = "" for x in s: if x == y or x == remove: continue if x not in c: c[x] = 0 c[x] += 1 o += x y = x return o, c def one(s): ptr = 0 best = "" s, c = count(s) while True: ...
FUNC_DEF NONE ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER W...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
for nt in range(int(input())): s = input() n = len(s) vis = [0] * 26 d = {} for i in range(n): d[s[i]] = i ans = [] stack = [] for i in range(n): if not vis[ord(s[i]) - 97]: while stack and s[i] > stack[-1] and i < d[stack[-1]]: vis[ord(stack.p...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
n = int(input()) for _ in range(n): s = input() n = len(s) ch_set = set(s) t = "" for i in range(len(ch_set)): for ch in sorted(ch_set, reverse=True): if set(s[s.find(ch) :]).issuperset(ch_set): s = s[s.find(ch) :].replace(ch, "") ch_set.remove(ch)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUN...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
for _ in range(int(input())): stroke = input() arr = {b: a for a, b in enumerate(stroke)} tec = [] tecs = set() for num, j in enumerate(stroke): if j not in tecs: while len(tec) != 0 and tec[-1] < j and num < arr[tec[-1]]: tecs.discard(tec.pop()) tec.a...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR V...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
from sys import stdin, stdout input = stdin.readline t = int(input()) for _ in range(t): s = input().strip() n = len(s) freq = {} check = {} for i in s: freq[i] = freq.get(i, 0) + 1 check[i] = 0 stack = [] for i in range(n): freq[s[i]] -= 1 if check[s[i]]: ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NU...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys input = sys.stdin.readline def maxthestring3(): for _ in range(int(input())): s = input().rstrip() lastpos = {v: i for i, v in enumerate(s)} queue = [] his = set() for i in range(len(s)): nowl = s[i] if nowl not in his: if...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR WHILE VAR NUMBER VAR VAR VAR NUMBER VAR E...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys max_int = 2147483648 min_int = -max_int t = int(input()) for _t in range(t): s = input() d = {} for ss in s: if ss in d: d[ss] += 1 else: d[ss] = 1 st = [] was = set() for ss in s: if ss not in was: while st and ss >= st[-1]...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys input = sys.stdin.readline for _ in range(int(input())): S = list(map(lambda x: ord(x) - ord("a"), list(input())[:-1])) n = len(S) table = [0] * 26 res = [] for x in S: table[x] += 1 last = 0 for _ in range(len(set(S))): c = 0 start = last for i in...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER F...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
import sys def charToInt(c): return ord(c) - ord("a") def intToChar(x): return chr(ord("a") + x) def main(): t = int(input()) allans = [] for _ in range(t): s = input() n = len(s) arr = [charToInt(c) for c in s] charIndexes = [[] for _ in range(26)] for ...
IMPORT FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FUNC_DEF 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 VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN V...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
for _ in range(int(input())): s = input() stack = [] seen = set() last_occurrence = {c: i for i, c in enumerate(s)} for i, c in enumerate(s): if c not in seen: while stack and c > stack[-1] and i < last_occurrence[stack[-1]]: seen.discard(stack.pop()) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
from sys import stdin, stdout def maximize_the_remaining_string(s): check_a = [False] * 26 c_a = [[] for _ in range(26)] hs = set() for i in range(len(s)): c_a[ord(s[i]) - ord("a")].append(i) check_a[ord(s[i]) - ord("a")] = True hs.add(s[i]) r = "" p = -1 for _ in r...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR VAR ...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
t = int(input()) for test in range(1, t + 1): s = list(input()) store = [(0) for _ in range(len(s))] curr = 0 visited = set() last_seen = {} for idx, ch in enumerate(s[::-1]): if ch not in visited: curr += 1 visited.add(ch) store[-idx - 1] = curr i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ...
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation: you choose the index $i$ ($1 \le i \le |s|$) such that the character at position $i$ occurs at least two times in the string $...
for i in range(int(input())): s = input() if len(set(s[0:])) != len(s): n = len(set(s[0:])) a = sorted(set(s[0:])) while s: DEL = "" for j in range(len(a) - 1, -1, -1): if len(set(s[s.index(a[j]) :])) == n: DEL = a[j] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER WHILE VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUM...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) a = list(map(int, input().split())) arr, x, ans = [], 0, 0 for i in range(n): if a[i] < 0: arr.append(a[i]) arr = sorted(arr, reverse=True) x = x + a[i] if x < 0: x -= arr.pop() else: ans = ans + 1 print(ans)
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 LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR ASSIGN ...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) list1 = list(map(int, input().split())) s = 0 c = 0 b = [] for i in list1: s += i c += 1 if i < 0: b.append(i) b.sort() if s < 0: s -= b[0] b.pop(0) c -= 1 print(c)
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 VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) l = list(map(int, input().split())) s = 0 c = 0 a = [] k = 0 for i in range(n): s += l[i] if l[i] < 0: a.append(l[i]) a.sort(reverse=True) if s < 0: x = a.pop() s = s - x k += 1 print(n - k)
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 VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL ...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) l1 = [int(a) for a in input().split()] negs = [] ctr, sm = 0, 0 for i in range(n): sm += l1[i] ctr += 1 if l1[i] < 0: negs.append(l1[i]) negs.sort(reverse=True) while sm < 0: sm -= negs[-1] negs.pop() ctr -= 1 print(ctr)
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 VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMB...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) drinkings = [int(item) for item in input().split(" ")] health = 0 drinks = [] for i in range(n): health += drinkings[i] drinks.append(drinkings[i]) if health < 0: Min = min(drinks) health -= Min drinks.remove(Min) print(len(drinks))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) potions = tuple(map(int, input().split())) health = 0 res = 0 considered_harmful_potions = {} most_harmful_potion = 0 for potion in potions: res += 1 if potion < 0: if potion in considered_harmful_potions: considered_harmful_potions[potion] += 1 else: con...
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 DICT ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR ...
This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on the far right. Each potion will increase your health by $a_i$ when d...
n = int(input()) A = list(map(int, input().split())) sm = 0 cnt = 0 Neg = [] for i in range(n): if sm + A[i] >= 0: cnt += 1 sm += A[i] if A[i] < 0: Neg.append(A[i]) elif Neg: if A[i] > min(Neg): sm += A[i] - min(Neg) Neg.remove(min(Neg)) ...
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 FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR IF VAR VAR FUNC_CALL VAR VAR VAR...