description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
t = int(input()) for i in range(t): n, l, r, s = map(int, input().split()) x = r - l + 1 st = 0 en = 0 sub = [] dic = {} suff = [] for i in range(1, x + 1): st += i sub.append(i) en += n - i + 1 if s >= st and s <= en: diff = s - st a = diff //...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_C...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for _ in range(int(input())): n, l, r, s = map(int, input().split()) values = r - l + 1 min_sum = values * (values + 1) // 2 max_sum = min_sum + (n - values) * values if s < min_sum or s > max_sum: print(-1) continue subarray = [i for i in range(1, r - l + 2)] s = s - min_sum...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
import sys for _ in range(int(sys.stdin.readline())): n, l, r, s = map(int, sys.stdin.readline().split()) k = r - l + 1 low_sum, high_sum = sum(range(1, k + 1)), sum(range(n - k + 1, n + 1)) if s < low_sum or high_sum < s: print(-1) continue idx, limit = k, n temp = [i for i in ...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
from sys import stdin, stdout input = stdin.readline for _ in range(int(input())): n, l, r, s = map(int, input().split()) i = r - l + 1 mi = i * (i + 1) // 2 mx = n * (n + 1) // 2 - (n - i) * (n - i + 1) // 2 if s < mi or s > mx: print(-1) continue right = n - 1 left = right...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
def get_numbbbs(maximum, k, total): nums = list(range(1, k + 1)) s = sum(nums) if s > total: return -1 pointer = -1 while s < total: if nums[pointer] == maximum + pointer + 1: pointer -= 1 else: nums[pointer] += 1 s += 1 if -pointer...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VA...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
from sys import stderr, stdin input = stdin.readline def dbp(*args, **kwargs): print(*args, file=stderr, **kwargs) def get_int_list(): return [int(x) for x in input().strip().split()] def do_thing(): n, l, r, s = get_int_list() l -= 1 r -= 1 sec = [] for i in range(1, r - l + 2): ...
ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for _ in range(int(input())): n, l, r, s = map(int, input().split()) k = r - l + 1 rem = set() out = [] for i in range(n, 0, -1): low = k * (k - 1) // 2 high = k * (2 * i - k + 1) // 2 if k and high >= s and s - i >= low: out.append(i) s -= i ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR B...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
def f(a, b): ans = 0 for i in range(a, b + 1): ans += i return ans for tc in range(int(input())): n, l, r, s = map(int, input().split()) leng = r - l + 1 if f(1, leng) > s or f(n - leng + 1, n) < s: print(-1) continue lr = [i for i in range(n - leng + 1, n + 1)] ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for y in range(int(input())): n, l, r, s = map(int, input().split()) ln = r - l + 1 if ln * (ln + 1) // 2 <= s <= n * (n + 1) // 2 - (n - ln) * (n - ln + 1) // 2: lst = [0] * ln for i in range(ln): lst[i] = i + 1 s -= sum(lst) lst = lst + [10000000000] p =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
t = int(input()) for _ in range(t): n, l, r, s = list(map(int, input().split())) d = r - l + 1 mi = d * (d + 1) // 2 ma = sum(n - x for x in range(d)) if not mi <= s <= ma: print(-1) continue offset = 0 current = [(x + 1) for x in range(d)][::-1] i = 0 while sum(curre...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR ...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for _ in range(int(input())): n, l, r, s = map(int, input().split()) a = [(i + 1) for i in range(n)] d = r - l + 1 low = sum(a[:d]) high = sum(a[-d:]) if s > high or s < low: print(-1) else: t = a[-d:] x = 0 for i in range(d): if high - s > 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASS...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for _ in range(int(input())): n, s, e, su = list(map(int, input().split())) lis = [] for i in range(1, n + 1): lis.append(i) le = e - s + 1 if sum(lis[len(lis) - le :]) < su or sum(lis[:le]) > su: print(-1) continue new = [] for i in lis[:le]: new.append(i) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL V...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for _ in range(int(input())): n, l, r, s = [int(x) for x in input().split(" ")] k = abs(l - r) + 1 mn = k * (k + 1) / 2 mx = mn + (n - k) * k if mn <= s and s <= mx: a = [i for i in range(k)] a.append(n) curr = mn ptr = k - 1 while curr != s: if a[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
def check(l, r, s, num): tmp1 = (2 * l + num - 1) * num // 2 tmp2 = (2 * r - num + 1) * num // 2 return s >= tmp1 and s <= tmp2 cas = int(input()) while cas: cas -= 1 n, l, r, s = map(int, input().split()) a = [(0) for i in range(n + 1)] vis = [(0) for i in range(n + 1)] cnt = l fo...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIG...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for _ in range(int(input())): n, l, r, s = map(int, input().split()) arr = [] t = [] visited = set() cnt = 0 warr = [] for i in range(1, n + 1): if i > s: t.append(i) continue arr.append(i) if cnt < r - l + 1: visited.add(i) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
import sys input = sys.stdin.readline for CASES in range(int(input())): n, l, r, s = map(int, input().split()) l -= 1 r -= 1 le = r - l + 1 now = (1 + le) * le // 2 if now > s: print(-1) continue A = [0] * n for i in range(l, r + 1): A[i] = i - l + 1 for i in...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER ...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
class Solution: def get_n_sum(self, n): return n * (n + 1) // 2 def get_last_n_sum(self, n, k): return k * (2 * n + 1 - k) // 2 def solve(self, n, l, r, s): nsum = self.get_n_sum(n) if s > nsum: return -1 k = r - l + 1 low = self.get_n_sum(k) ...
CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
T = int(input()) for _ in range(T): n, l, r, s = [int(x) for x in input().split()] ma = (2 * n - r + l) * (r - l + 1) // 2 mi = (2 - l + r) * (r - l + 1) // 2 if s > ma or s < mi: print(-1) else: x = int((2 * s / (r - l + 1) + l - r) / 2) dad = s - int((2 * x + r - l) * (r - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NU...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
rn = lambda: int(input()) rns = lambda: map(int, input().split()) rl = lambda: list(map(int, input().split())) rs = lambda: input() YN = lambda x: print("YES") if x else print("NO") mod = 10**9 + 7 for _ in range(rn()): n, l, r, s = rns() diff = r - l + 1 lo = diff * (diff + 1) // 2 hi = lo + diff * (n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL V...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for _ in range(int(input())): n, l, r, s = map(int, input().split()) z = n k = r - l + 1 if s < (k * k + k) // 2 or s > k * (2 * n + 1 - k) // 2: print(-1) else: a = [] s -= (k * k + k) // 2 for i in range(k, 0, -1): a.append(i) i = 0 while...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIG...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
t = int(input()) for z in range(t): n, l, r, s = map(int, input().split()) p = r - l + 1 mn = p * (p + 1) // 2 mx = n * (n + 1) // 2 - (n - p) * (n - p + 1) // 2 if s < mn or s > mx: print(-1) else: brr = [] for i in range(p, 0, -1): brr.append(i) k = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
for i in range(int(input())): n, l, r, s = map(int, input().split()) re = n * (n + 1) // 2 t = r - l + 1 b = [0] * n a = [0] * (r - l + 1) su = 0 d = dict() d1 = dict() for i in range(1, n + 1): d[i] = 0 d1[i] = 0 f = 0 for i in range(0, r - l + 1): a[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
def rec(s, l, arr): arr_ = arr[:l] if sum(arr_) == s: return arr_ while arr_[-1] < arr[-1]: for i in range(l - 1, -1, -1): arr_[i] += 1 if sum(arr_) == s: return arr_ return None def solve(): n, l, r, s = map(int, input().split(" ")) l -=...
FUNC_DEF ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR WHILE VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN V...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
def helper(n, l, r, s): count = r - l + 1 low = (1 + count) * count // 2 high = (n + n - count + 1) * count // 2 if s < low or s > high: return [] res = [0] * n used = set(list()) tl = 1 tr = n while l < r: if s <= (tl + tr) * count / 2: res[l - 1] = tl ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR RETURN LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHIL...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
t = int(input()) for _ in range(t): n, l, r, s = [int(i) for i in input().split()] arr = [(-1) for i in range(n)] l -= 1 r -= 1 fill = r - l + 1 max_possi = 0 m = n for i in range(fill): max_possi += m m -= 1 min_possi = fill * (fill + 1) // 2 if s > max_possi or ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN...
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not. Polycarp was given four integers $n$, $l$, $r$ ($1 \le l \le r \le n)$ and $s$ ($1 \le s \le \frac{...
def somme(n, k, s): if s < k * (k + 1) // 2: return -1 if s > n * (n + 1) // 2 - (n - k) * (n - k + 1) // 2: return -1 l = [] rs = s rk = k for i in range(k): rk -= 1 x = min(n - i, rs - rk * (rk + 1) // 2) rs -= x l.append(x) return l for kT...
FUNC_DEF IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
for _ in range(int(input())): lsen = input() st2 = str(input()) if st2.find("aa") != -1: print(2) elif st2.find("aca") != -1 or st2.find("aba") != -1: print(3) elif st2.find("acba") != -1 or st2.find("abca") != -1: print(4) elif st2.find("accabba") != -1 or st2.find("abba...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR ...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t = int(input()) for q in range(t): n = int(input()) s = input() if "aa" in s: print(2) elif "aba" in s or "aca" in s: print(3) elif "abca" in s or "acba" in s: print(4) elif ( "abcabca" in s or "acbacba" in s or "abbacca" in s or "abcacba"...
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 IF STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR ST...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t = int(input()) for i in range(t): l = input() s = input() if "aa" in s: print(2) elif "aba" in s: print(3) elif "aca" in s: print(3) elif "abca" in s: print(4) elif "acba" in s: print(4) elif "accabba" in s: print(7) elif "abbacca" in...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR NUMBER IF ST...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
import sys l = {"aa": 2, "aba": 3, "aca": 3, "abca": 4, "acba": 4, "abbacca": 7, "accabba": 7} for _ in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) s = sys.stdin.readline() for x in l: if x in s: print(l[x]) break else: print(-1)
IMPORT ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t = int(input()) for p in range(t): n = int(input()) s = input() ans = 0 if "aa" in s: ans = 2 elif "aba" in s: ans = 3 elif "aca" in s: ans = 3 elif "abca" in s: ans = 4 elif "acba" in s: ans = 4 elif "abbacca" in s: ans = 7 elif "...
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 ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER IF STRING VAR...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
pairs = ["aa", "aba", "aca", "abca", "acba", "accabba", "abbacca"] for s in [*open(0)][2::2]: for i in pairs: if i in s: print(len(i)) break else: print(-1)
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t = int(input()) for i in range(t): n = int(input()) s = input() b = False allowed = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] for i in allowed: if i in s: print(len(i)) b = True break if not b: print(-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 ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMB...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
import sys input = sys.stdin.readline def solve(n, S): if "aa" in S: print(2) else: ans = float("inf") for i in range(1, n - 1): if S[i - 1] == S[i + 1] == "a": ans = min(ans, 3) elif i < n - 2 and S[i - 1] == S[i + 2] == "a" and S[i] != S[i + 1...
IMPORT ASSIGN VAR VAR FUNC_DEF IF STRING VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR ...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
import sys ans = [] t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) s = sys.stdin.readline().strip() if s.find("aa") > -1: ans.append("2") elif s.find("aca") > -1 or s.find("aba") > -1: ans.append("3") elif s.find("abca") > -1 or s.find("acba") > -1: ...
IMPORT ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
for _ in range(int(input())): n = int(input()) s = input() l = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] test = 0 for i in l: if i in s: test = 1 print(len(i)) break if not test: print(-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 ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
for s in [*open(0)][2::2]: a = -1 for i in ("abbacca", "accabba", "acba", "abca", "aca", "aba", "aa"): if i in s: a = len(i) print(a)
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR STRING STRING STRING STRING STRING STRING STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
L = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] for t in range(int(input())): n = int(input()) s = input() ans = -1 for i in L: if i in s: ans = len(i) break print(ans)
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
def solve(): _ = int(input()) s = input() words = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] for word in words: if word in s: print(len(word)) return print(-1) for _ in range(int(input())): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
import sys input = sys.stdin.readline for _ in range(int(input().strip())): n = int(input().strip()) s = input().strip() if "aa" in s: print(2) elif "aba" in s or "aca" in s: print(3) elif "abca" in s or "acba" in s: print(4) elif "abbacca" in s or "accabba" in s: ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VA...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
for _ in range(int(input())): n = int(input()) s = input() a = -1 pos = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] for i in pos: if i in s: a = len(i) break print(a)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
def solve(): input() s = input().strip() if "aa" in s: return print(2) elif "aba" in s or "aca" in s: return print(3) elif "abca" in s or "acba" in s: print(4) elif "abbacca" in s or "accabba" in s: print(7) else: print(-1) n = int(input()) for i in ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF STRING VAR RETURN FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR RETURN FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
for i in range(int(input())): num = int(input()) w = input() for i in ("aa", "aba", "aca", "abca", "acba", "accabba", "abbacca"): if i in w: print(i.__len__()) break else: print(-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 FOR VAR STRING STRING STRING STRING STRING STRING STRING IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
for i in range(int(input())): length = int(input()) string = input() master_list = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] ans_list = [i for i in master_list if i in string] if len(ans_list) == 0: print(-1) else: ans_list.sort(key=len) print(len(ans_lis...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
n_test = int(input()) ee = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] def solve(s): for e in ee: if s.count(e) > 0: print(len(e)) return print(-1) for t in range(n_test): n = int(input()) s = input() solve(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FU...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
strs = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] t = int(input()) for p in range(t): l, s = int(input()), input() print(min([len(i) for i in strs if i in s], default=-1))
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t = int(input()) for _ in range(t): n = int(input()) string = input() if string.find("aa") != -1: print(2) elif string.find("aca") != -1: print(3) elif string.find("aba") != -1: print(3) elif string.find("abca") != -1: print(4) elif string.find("acba") != -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 IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STR...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
def solve(n, s): if s.find("aa") != -1: return 2 elif s.find("aca") != -1 or s.find("aba") != -1: return 3 elif s.find("abca") != -1 or s.find("acba") != -1: return 4 elif s.find("abbacca") != -1 or s.find("accabba") != -1: return 7 else: return -1 t = int(i...
FUNC_DEF IF FUNC_CALL VAR STRING NUMBER RETURN NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CAL...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
import sys input = sys.stdin.readline def printL(list): sys.stdout.write(" ".join(map(str, list)) + "\n") def printN(n): sys.stdout.write(str(n) + "\n") t = int(input()) for _ in range(t): n = int(input()) s = input() b = False for i in ("aa", "aba", "aca", "abca", "acba", "accabba", "abb...
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING 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 ASSIGN VAR NUMBER FOR VAR ST...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t = int(input()) for i in range(t): n = int(input()) s = input() y = 0 le = 0 if "aa" in s: y = 1 le = 2 elif "aba" in s: y = 1 le = 3 elif "aca" in s: y = 1 le = 3 elif "abca" in s: y = 1 le = 4 elif "acba" in s: ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF ST...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t, S = int(input()), ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] while t != 0: n, T, flag, ans = input(), input(), False, 100000000 for s in S: if s in T: flag = True ans = ans if ans < len(s) else len(s) print(-1 if flag == False else ans) t = t - 1
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING STRING WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSI...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
t = int(input()) a = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] while t: t -= 1 n = int(input()) s = input().strip() ok = False for x in a: if x in s: print(len(x)) ok = True break if not ok: print("-1\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
def main(): input() string = input() for st in ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"]: if st in string: return len(st) return -1 tests = int(input()) while tests: tests -= 1 print(main())
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR LIST STRING STRING STRING STRING STRING STRING STRING IF VAR VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) s = input().rstrip() p = q = -1 for i in range(n): if s[i] == "a" and p == -1: p = i elif s[i] == "a" and p != -1: q = i if q == -1: print(-1) continue s ...
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 FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBE...
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'. He wants to find the length of the smallest substring, which satisfies the following conditions: Length of the substring is at least $2$ 'a' occurs strictly more times in this substring than 'b' 'a' occurs strictly more times in this...
secs = ["aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"] for _ in range(int(input())): input() string = input() ended = False for j in secs: if j in string: print(len(j)) ended = True break if not ended: print(-1)
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER
You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Your problem is to find such pair of indices $i, j$ ($1 \le i < j \le n$) that $lcm(a_i, a_j)$ is minimum possible. $lcm(x, y)$ is the least common multiple of $x$ and $y$ (minimum positive number such that both $x$ and $y$ are divisors of ...
import sys __version__ = "3.4" __date__ = "2019-04-17" def find_minimum_lcm(n, integers): already_seen = [0] * 10000001 repeated_value = 10000001 * 10000001 repeated_indices = None for index, value in enumerate(integers): if already_seen[value]: if value < repeated_value: ...
IMPORT ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_...
Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be available for playing, and all others will not. On each day Aleksey m...
for _ in range(int(input())): n, m = map(int, input().split()) f = [(m // 2 + m % 2) for i in range(n)] ans = "YES" a = [] fl = [None] * m for i in range(m): a.append(([int(i) for i in input().split()], i)) a.sort() for i in range(m): for j in a[i][0][1:]: if ...
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 BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC...
Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be available for playing, and all others will not. On each day Aleksey m...
tc = int(input()) while tc > 0: n, m = map(int, input().strip().split()) vv, ans, tmp = [], [], [] for i in range(n + 9): empt = [] ans.append(empt) for i in range(m): aa = list(map(int, input().strip().split())) x = aa[0] tmp.append((x, i)) a = [] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_...
Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be available for playing, and all others will not. On each day Aleksey m...
import sys input = sys.stdin.readline for _ in range(int(input())): n, m = map(int, input().split()) days = [] ans = [] for i in range(m): days.append(list(map(int, input().split()))) ans.append(days[i][1]) freq = {} for num in ans: if num in freq: freq[num] ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR ...
Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be available for playing, and all others will not. On each day Aleksey m...
def solve(M, n, m): I = {} S = {} result = [0] * m for i in range(m): k = M[i][0] for j in range(1, k + 1): I[M[i][j]] = I.get(M[i][j], 0) + 1 if k == 1: S[M[i][1]] = S.get(M[i][1], 0) + 1 result[i] = M[i][1] maxFreq = (m + 1) // 2 for ...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ...
Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be available for playing, and all others will not. On each day Aleksey m...
t = int(input()) for i in range(t): n, m = map(int, input().split()) f = [] tot = [0] * n uni = [0] * n pop = 0 popind = -1 threshold = (m + 1) // 2 for j in range(m): f.append(input().split()) for k in range(len(f[j])): cur = int(f[j][k]) f[j][k] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC...
Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these $m$ days. On each of these days some friends will be available for playing, and all others will not. On each day Aleksey m...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) mat = [] for __ in range(m): l = list(map(int, input().split())) mat.append(l) d = [0] * m flag = 0 f = [0] * (n + 1) mx = (m + 1) // 2 for i in range(m): if mat[i][0] == 1: d[i] = ma...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
n = int(input()) s = list(map(int, input().split())) l = [bin(i)[2:] for i in s] length = [len(i) for i in l] maxLen = max(length) minLen = min(length) loc = 0 flag = False for j in range(minLen): for i in range(n): if l[i][j] != l[0][j]: flag = True break if flag: break ...
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 NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
def main(): input() aa = list(map(int, input().split())) le, l = max(aa).bit_length(), [] for i, a in enumerate(aa): j = le - a.bit_length() aa[i] = a << j l.append(j) mi, ma = min(aa), max(aa) a = mask = (1 << le) - 1 if mi == ma: while mi == mi & a: ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN ...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
N = 300000 A, L, R, level, ans, H, UP = ( [0] * N, [0] * N, [0] * N, [0] * N, [0] * N, [0] * N, [0] * N, ) x = 0 for i in range(N): level[i] = level[i // 2] + 1 n = int(input()) arr = list(map(int, input().rstrip().split())) for i in range(n): A[i] = arr[i] for i in range(n): x =...
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR ...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
import itertools n = int(input()) l = list(map(int, input().split())) m = max(l) + 5 freq = [(0) for _ in range(m)] count = [(0) for _ in range(m)] vis = [(-1) for _ in range(m)] for i in range(n): q = [(l[i], 0)] pos = 0 while len(q) > pos: top, c = q[pos] pos += 1 if top >= m or v...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VA...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
read = lambda: map(int, input().split()) n = int(input()) a = list(read()) m = max(a) + 5 cnt = [0] * m step = [0] * m was = [-1] * m for i in range(n): x = a[i] q = [(x, 0)] st = 0 while st < len(q): x, y = q[st] st += 1 if x >= m or was[x] == i: continue was...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
n = int(input()) As = list(map(int, input().split())) def solve(n, As): if n == 1: return 0 Bs = [bin(a)[2:] for a in As] Bs = remove_common_area(Bs) long = max(map(len, Bs)) costs = [0] * (long + 1) for b in Bs: update_costs(costs, b, long) return min(costs) def remove_c...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR V...
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So hi...
n = int(input()) a = [bin(int(i)) for i in input().split()] j = 2 s = "0b" while True: ok = True i = a[0] if j < len(i): c = i[j] else: c = "0" for i in a: if j < len(i): cc = i[j] else: cc = "0" if cc != c: ok = False ...
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 STRING WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASS...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for _ in range(int(input())): p, f = map(int, input().split()) ns, nx = map(int, input().split()) ws, wx = map(int, input().split()) ans = 0 if wx < ws: wx, ws = ws, wx ns, nx = nx, ns if ws <= wx: ans = 0 for i in range(ns + 1): ui = i uj ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NU...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = lambda: range(int(input())) a = lambda: list(map(int, input().split())) for _ in t(): p, f = a() cs, cw = a() s, w = a() if s > w: t = w ts = cw w = s cw = cs s = t cs = ts ans = 0 for a0 in range(0, min(cs, p // s) + 1): b0 = min(cw, (...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIG...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) while t > 0: c1, c2 = [int(x) for x in input().split()] n1, n2 = [int(x) for x in input().split()] w1, w2 = [int(x) for x in input().split()] initial = min(n1, c1 // w1) maxi = 0 for i in range(initial, -1, -1): ans = i rest_c1 = c1 - i * w1 ans += min(n2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for _ in range(int(input())): inip, inif = [int(i) for i in input().split()] cnts, cntw = [int(i) for i in input().split()] s, w = [int(i) for i in input().split()] if s > w: s, w = w, s cnts, cntw = cntw, cnts if inif > inip: inif, inip = inip, inif ini = cnts + cntw ...
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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for ik in range(int(input())): n, k = map(int, input().split()) ca, cw = map(int, input().split()) s, w1 = map(int, input().split()) if s > w1: s, w1 = w1, s ca, cw = cw, ca tot = 0 lwe = [n, k, ca, cw, s, w1] for i in range(ca + 1): ans = 0 n, k, ca, cw, s, w...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR ...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for _ in range(int(input())): p, f = map(int, input().split()) cs, cw = map(int, input().split()) s, w = map(int, input().split()) ans = 0 if s > w: s, w = w, s cs, cw = cw, cs for i in range(min(cs + 1, p // s + 1)): t1 = cs - i t2 = (p - s * i) // w t3 =...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FU...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for _ in range(int(input())): p, f = map(int, input().split()) cs, cw = map(int, input().split()) s, w = map(int, input().split()) ans = 0 if w < s: s, w = w, s cs, cw = cw, cs if f < p: f, p = p, f maxl = f // s + p // s maxl = min(maxl, cs) maximum = 0 f...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VA...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
def forf(cap, cs, cw, s, w): if s > w: return forf(cap, cw, cs, w, s) elif cs * s >= cap: return cap // s else: return cs + min(cw, (cap - cs * s) // w) for t in range(int(input())): p, f = list(map(int, input().split())) cs, cw = list(map(int, input().split())) s, w = ...
FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_C...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) def max_count(cnts, s, cntw, w, l): cs = min(cnts, l // s) cw = min(cntw, (l - cs * s) // w) return cs, cw while t: p, f = map(int, input().split()) cnts, cntw = map(int, input().split()) s, w = map(int, input().split()) if w < s: cnts, cntw = cntw, cnts ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CAL...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
import sys input = sys.stdin.readline (T,) = map(int, input().split()) for _ in range(T): p, q = map(int, input().split()) n, m = map(int, input().split()) w, v = map(int, input().split()) if w > v: w, v = v, w n, m = m, n R = 0 for c in range(n + 1): if p < c * w: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
import sys def main(): inp = [int(x) for x in sys.stdin.read().split()] ii = 0 t = inp[ii] ii += 1 for _ in range(t): p = inp[ii] ii += 1 f = inp[ii] ii += 1 cnts = inp[ii] ii += 1 cntw = inp[ii] ii += 1 s = inp[ii] ii...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for i in range(int(input())): mca, mcb = list(map(int, input().split())) cs, ca = list(map(int, input().split())) ws, wa = list(map(int, input().split())) if ws > wa: temp = wa temp1 = ws temp2 = cs temp3 = ca ws = temp wa = temp1 cs = temp3 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR A...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for _ in range(int(input())): p, f = map(int, input().split()) cs, cw = map(int, input().split()) s, w = map(int, input().split()) res = 0 if (s * cs + cw * w <= p) | (s * cs + cw * w <= f): print(cs + cw) continue if s > w: s, w = w, s cs, cw = cw, cs for i 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP V...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
T = int(input()) for _ in range(T): p, f = tuple(map(int, input().split())) cnts, cntw = tuple(map(int, input().split())) s, w = tuple(map(int, input().split())) if s > w: s, w = w, s cnts, cntw = cntw, cnts ans = 0 for i in range(cnts + 1): if i * s > p: cont...
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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN V...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) for i in range(t): p, f = list(map(int, input().split())) c1, c2 = list(map(int, input().split())) s, w = list(map(int, input().split())) if s <= w: a = min(c1, p // s) ans = 0 for s1 in range(a + 1): s2 = min(c1 - s1, f // s) w1 = min(c2,...
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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BI...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) for _ in range(t): p, f = map(int, input().split()) cnts, cntw = map(int, input().split()) s, w = map(int, input().split()) mx = 0 for i in range(min(p // s + 1, cnts + 1)): cnts_c = cnts p_c = p cntw_c = cntw f_c = f ans = 0 cnts_c -=...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER B...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
import sys T = int(sys.stdin.readline()) def hwa_ga_nan_da(p, f, cs, cw, s, w): a = min(p // w, cw) p -= a * w cw -= a b = min(f // s, cs) f -= b * s cs -= b c = min(f // w, cw) f -= c * w cs -= c return a + b + c for _ in range(T): p, f = map(int, sys.stdin.readline().s...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL V...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for _ in range(int(input())): p, f = map(int, input().split()) cnta, cntb = map(int, input().split()) wa, wb = map(int, input().split()) if wa > wb: wa, wb = wb, wa cnta, cntb = cntb, cnta res = 0 pa = 0 while pa * wa <= p and pa <= cnta: pb = min((p - pa * wa) // wb,...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE ...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
ttt = int(input()) for _ in range(ttt): p, f = [int(x) for x in input().split()] cnts, cntw = [int(x) for x in input().split()] s, w = [int(x) for x in input().split()] if s < w: s, w = w, s cnts, cntw = cntw, cnts qq = -1 for swords in range(cnts + 1): count = swords ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMB...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
def solve2(p1, p2, cnt1, cnt2, w1, w2): ans = 0 ans += min(p1 // w2, cnt2) cnt2 -= ans carry = min(p2 // w1, cnt1) ans += carry cnt1 -= carry p2 -= carry * w1 carry = min(p2 // w2, cnt2) ans += carry return ans def solve(p1, p2, cnt1, cnt2, w1, w2): ans = 0 for i in ran...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) for _ in range(t): [p1, p2] = list(map(int, input().split())) cnt = list(map(int, input().split())) w = list(map(int, input().split())) tot = sum(cnt) MIN = -1 if w[0] < w[1]: MIN = 0 else: MIN = 1 MAX = int(not MIN) max1 = p1 // w[MIN] max2 = p2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBE...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for i in range(int(input())): p, f = map(int, input().split()) cnts, cntw = map(int, input().split()) s, w = map(int, input().split()) if w <= s: if p // w + f // w <= cntw: print(p // w + f // w) else: answer = cntw k = 0 while k * w <= p ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) for _ in range(t): p, f = map(int, input().split()) cs, cw = map(int, input().split()) s, w = map(int, input().split()) if s > w: s, cs, w, cw = w, cw, s, cs res = 0 for i in range(cs + 1): if p < s * i: continue val = i pw = min(int((...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CAL...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
for _ in range(int(input())): p, f = map(int, input().split()) cnts, cntw = map(int, input().split()) s, w = map(int, input().split()) if s > w: s, w = w, s cntw, cnts = cnts, cntw kek = p // s + f // s if kek <= cnts: print(kek) else: ans = cnts for s...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VA...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
z = lambda: map(int, input().split()) zz = lambda a, b: (min(a, b), max(a, b)) for _ in range(int(input())): p, f = z() x, y = z() s, w = z() a, b = zz((s, x), (w, y)) if p // a[0] + f // a[0] <= a[1]: print(p // a[0] + f // a[0]) continue m = 0 for i in range(a[1] + 1): ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBE...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
import sys input = sys.stdin.readline def print(val): sys.stdout.write(str(val) + "\n") def prog(): for _ in range(int(input())): p, f = map(int, input().split()) cnts, cntw = map(int, input().split()) s, w = map(int, input().split()) if s > w: s, w = w, s ...
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR V...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
def take_item(p, f, s_n, a_n, s_w, a_w): axe_p = min(p // a_w, a_n) a_n -= axe_p sword_f = min(f // s_w, s_n) f -= sword_f * s_w axe_f = min(f // a_w, a_n) return axe_p + axe_f + sword_f for _ in range(int(input())): p, f = [int(x) for x in input().split()] s_n, a_n = [int(x) for x in ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR 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 V...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
def solve(): p, f = map(int, input().split()) cs, cw = map(int, input().split()) s, w = map(int, input().split()) ans = 0 for k in range(0, cs + 1): max_pcs = min(p // s, k) max_fcs = min(f // s, cs - k) rp = p - s * max_pcs rf = f - s * max_fcs max_pcw = rp /...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
import sys input = sys.stdin.readline def inInt(): return int(input()) def inStr(): return input().strip("\n") def inIList(): return list(map(int, input().split())) def inSList(): return input().split() def solve(p, f, cs, cw, s, w): pc, fc = 0, 0 sols = [] ss = False if s < w...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR N...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) while t: t -= 1 p, f = map(int, input().split()) cs, cw = map(int, input().split()) s, w = map(int, input().split()) ans = 0 if s > w: s, w = w, s cs, cw = cw, cs for n1 in range(cs + 1): if n1 * s > p: break n2 = min((p - s * n1) ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_C...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ uni...
t = int(input()) for i in range(t): p, f = map(int, input().split()) cs, cw = map(int, input().split()) s, w = map(int, input().split()) maxi = 0 for j in range(min(cs, p // s) + 1): k = min((p - s * j) // w, cw) xcs = cs - j xcw = cw - k if s > w: if w * ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMB...