description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe to be a response from aliens! The scientists now want to check if the signal $t$ is similar to $s$. The original signal $s...
def gethash(l, r): return (ha[r] - ha[l] * p[r - l] % mod + mod) % mod def check(lenx, leny): ha_0 = -1 ha_1 = -1 j = 0 for i in range(m): if s[i] == "0": tmp = gethash(j, j + lenx) if ha_0 == -1: ha_0 = tmp elif ha_0 != tmp: ...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER VAR VAR ASSIGN VA...
One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe to be a response from aliens! The scientists now want to check if the signal $t$ is similar to $s$. The original signal $s...
s = input() t = input() n, m = len(s), len(t) a = s.count("0") b = len(s) - a pow = [1] * m h = [0] * (m + 1) p, mod = 31, 10**9 + 9 for i in range(1, m): pow[i] = pow[i - 1] * p % mod for i in range(m): h[i + 1] = (h[i] + (ord(t[i]) - ord("a") + 1) * pow[i]) % mod def get_hash(i, j): hash_value = (h[j] -...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR ...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def equi(self, low, high, magnet, n): while low < high: mid = (low + high) / 2 tf = 0 for i in range(n): tf += 1 / (mid - magnet[i]) if abs(tf) < 1e-06: return mid elif tf < 0: high =...
CLASS_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CAL...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def helper(self, a, mid): ans = 0 for i in range(len(a)): if mid - a[i] != 0: ans = ans + 1 / (mid - a[i]) return round(ans, 5) def nullPoints(self, n, a, getAnswer): for i in range(n - 1): s = a[i] e = a[i + 1...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR B...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): for i in range(n - 1): lo = a[i] hi = a[i + 1] while round(lo, 2) != round(hi, 2): mid = (lo + hi) / 2 force = sum(1 / (x - mid) for x in a) if force == 0: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN V...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
GREATER = 1 SMALLER = 2 EQUAL = 3 def check(x, i, a, n): t1 = 0 t2 = 0 for j in range(0, i + 1): if x == a[j]: return GREATER t1 += 1 / (x - a[j]) for j in range(i + 1, n): if x == a[j]: return LESSER t2 += 1 / (a[j] - x) if t1 == t2: ...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR RETURN VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF V...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def calculateForce(self, a, point): force = 0 for i in a: force += 1 / (i - point) return round(force, 5) def nullPoints(self, n, a, getAnswer): for i in range(n - 1): low = a[i] high = a[i + 1] while low <= high: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSI...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
def search(lo, hi, a, n): mid = (lo + hi) / 2 dis = 0 for i in range(n): dis += 1 / (mid - a[i]) if abs(dis) < 1e-12: return mid if dis > 0: return search(mid, hi, a, n) else: return search(lo, mid, a, n) class Solution: def nullPoints(self, n, a, ans): ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSI...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): z = 0 for i in range(n - 1): left = a[i] right = a[i + 1] while True: mid = (left + right) / 2 equation = self.equilibrium(a, mid) if equation > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER F...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def print(self, *args): pass def nullPoints(self, n, a, getAnswer): for i in range(n - 1): fValue = i bComplete = False iTryCounter = 0 iXLeft = a[i] iXRight = a[i + 1] iXMid = (iXLeft + iXRight) / 2 ...
CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR V...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, l, ans): def fun(i, j): while i < j: mid = (i + j) / 2 c = 0 for k in range(n): c += 1 / (l[k] - mid) if abs(c) <= 1e-06: return round(mid, 2) ...
CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER AS...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): def bs(a, start, end, mid): ans = 0 for i in range(n): if mid - a[i] != 0: ans += 1 / (mid - a[i]) return round(ans, 5) for i in range(n - 1): start = a[i] ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIG...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): z = 0 for i in range(n - 1): start = a[i] end = a[i + 1] while True: mid = (start + end) / 2 eq = self.equilibrium(a, mid) if eq > 0: start ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER F...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def calc(self, a, n, mid): ans = 0 for i in range(n): if a[i] < mid: ans += 1 / (mid - a[i]) else: ans -= 1 / (a[i] - mid) return ans def search(self, a, i, n): lo, hi = a[i], a[i + 1] while hi - lo...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VA...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, N, M, getAnswer): res = [] def BinSearch(left, right, min_val, max_val): distance = (min_val + max_val) / 2 left_res = sum([(1 / abs(distance - point)) for point in left]) right_res = sum([(1 / abs(point - distance)) for poin...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def sigmaForce(self, x, a): netForce = 0 for i in a: netForce += 1 / (x - i) return netForce def bs(self, l, r, a): while r - l >= 1e-06: x = l + (r - l) / 2 netForce = self.sigmaForce(x, a) if netForce > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): def sol(i, j, a, n): l = a[i] r = a[j] left = l right = r while right - left >= 1e-06: fl = 0 fr = 0 m = (left + right) / 2 for...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF VAR VA...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def solve(self, a, n, low, high): while low < high: mid = (low + high) / 2 force = 0 for i in range(n): force += 1 / (mid - a[i]) force = round(force, 5) if abs(force) < 1e-06: return round(mid, 2) ...
CLASS_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR N...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): for i in range(0, n - 1): getAnswer[i] = self.check(a, n, a[i], a[i + 1]) def check(self, a, n, low, hig): while low <= hig: mid = (hig + low) / 2 force = 0 for i in range(n): ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF V...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
import sys sys.setrecursionlimit(10**5) class Solution: def bin_search(self, s, e, l, r, a): if abs(s - e) >= 1e-06: mid = (e + s) / 2 lp = rp = 0 for i in range(l): lp += 1 / abs(a[i] - mid) for i in range(l, r): rp += 1 / ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): arr = [] def eq(num): ans = 0 for i in a: if i < num: ans += 1 / (num - i) else: ans -= 1 / (i - num) return ans for i in rang...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR V...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, getAnswer): def left(i, m): f = 0 for j in range(i, n): f += 1 / (a[j] - m) return f def right(i, m): f = 0 for j in range(i - 1, -1, -1): f += 1 / (m - a[j]) ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ...
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now giv...
class Solution: def nullPoints(self, n, a, ans): for i in range(n - 1): fi, si = i, i + 1 l, r = a[fi], a[si] while l < r: mid = (l + r) / 2 force = sum(1 / (mid - v) for v in a if mid - v != 0) if abs(force) < 1e-07: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR N...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
s = set() d = {} s.add(0) for _ in range(int(input())): sign, x = map(str, input().split()) x = int(x) if sign == "+": s.add(x) else: if x not in d: d[x] = x while d[x] in s: d[x] += x print(d[x])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR V...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
n = int(input()) P = {} Si = {} for i in range(n): S = input() a = S[0] x = int(S[1:]) if a == "+": P[x] = True else: if x in Si: a = Si[x] else: a = x while a in P: a += x Si[x] = a print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
T = int(input()) s = {0} d = {} for _ in range(T): ch, n = input().split() n = int(n) if ch == "+": s.add(n) elif ch == "?": if n not in d: d[n] = n while d[n] in s: d[n] += n print(d[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
a, b = dict(), dict() for _ in range(int(input())): s, x = list(input().split()) x = int(x) if s == "+": a[x] = True else: if x in b: y = b[x] else: y = x while y in a: y += x b[x] = y print(y)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
dic = {} for jj in range(int(input())): a, b = input().split() k = int(b) if a == "+": dic[k] = 0 for i in range(k, 10**37, k): if i not in dic: dic[k] = i break elif k not in dic: print(k) else: for i in range(dic[k], 10**3...
ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_O...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
last = {} s = set() q = int(input()) for i in range(q): qt, num = input().split() num = int(num) if qt == "+": s.add(num) else: if num in last: k = last[num] else: k = num while k in s: k += num last[num] = k print(k)
ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
x = int(input()) y = set() q = {} while x: x -= 1 op, m = input().split() m = int(m) if op == "+": y.add(m) continue f = q.get(m, m) while f in y: f += m q[m] = f print(f)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
dic = dict() s = set() for _ in range(int(input())): op, n = input().split() n = int(n) if op == "+": s.add(n) else: m = n if m in dic: m = dic[n] while True: if m not in s: print(m) dic[n] = m break ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSI...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
a = int(input()) s = set() sl = {} s.add(0) sp = [] for i in range(a): x = input() ni = 0 x1 = "" x2 = "" for j in x: if j != " " and x[0] != "?" and j != x[0]: x1 += j ni += 1 elif j != " " and x[0] != "+" and j != x[0]: x2 += j if ni >= 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR NUMBER STRING VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR STRING V...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
map1, map2 = [{}, {}] for test_cases in range(int(input())): type, val = list(input().split()) ans = 0 val = int(val) if type == "+": map1[val] = True else: if val in map2: fuck = map2[val] else: fuck = val while fuck in map1: fuck ...
ASSIGN VAR VAR LIST DICT DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
n = int(input()) HashSet = set() HashMap = dict() for i in range(n): operator, num = map(str, input().split()) if operator == "+": HashSet.add(int(num)) else: num = int(num) if num not in HashMap: HashMap[num] = num while HashMap[num] in HashSet: HashM...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUN...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
s = set([0]) ans = {} q = int(input()) def add(x): s.add(x) def ask(x): if ans.get(x) == None: ans[x] = x while ans[x] in s: ans[x] += x print(ans[x]) for i in range(q): c, x = input().split() if c == "+": add(int(x)) else: ask(int(x))
ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR F...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
s = set() d = {} for _ in range(int(input())): c, a = input().split() a = int(a) if c == "+": s.add(a) else: bg = 1 if a in d.keys(): bg = d[a] for i in range(bg, 100000000): if a * i not in s: print(a * i) d[a] = i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_C...
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries. Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types: + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained ...
q = int(input()) s = {0} mp = dict() for qq in range(q): ch, x = input().split() x = int(x) if ch == "+": s.add(x) else: y = x if x in mp: y = mp[x] while True: if y not in s: print(y) mp[x] = y break...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def solve(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) if k >= m - 1: ans = 0 for i in range(n): if i <= m - 1 or n - i - 1 <= m - 1: ans = max(ans, a[i]) print(ans) return ans = 0 for i in range(k + 1): ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
R = lambda: list(map(int, input().split())) for _ in range(int(input())): n, m, k = R() a = R() k = min(k, m - 1) d = m - k ans = 0 for i in range(k + 1): p = 10**9 for j in range(d): p = min(p, max(a[i + j], a[i + n - k - 1 - (d - 1 - j)])) ans = max(ans, p) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) al = list(map(int, input().split())) mind = min(m - 1, k) ans = 0 for i in range(mind + 1): d = al[i : n - (mind - i)] p = m - mind - 1 l = [] for j in range(p + 1): g = d[j : len(d) -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
for i in range(int(input())): n, m, k = map(int, input().split()) k = min(k, m - 1) a = list(map(int, input().split())) b = [max(a[i], a[i + n - m]) for i in range(0, m)] x = max(min(b[i : i + (m - k)]) for i in range(k + 1)) print(x)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASS...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def Input(): tem = input().split() ans = [] for it in tem: ans.append(int(it)) return ans T = Input()[0] for t in range(T): n, m, k = Input() a = Input() if k + 1 >= m: l, r = 0, n - m ans = -10000000000000 while r < n: ans = max(ans, a[l], a[r])...
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER WHIL...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def find_optimum(length, pos, fix, arr): if pos < length // 2: arr = arr[:pos] + arr[length - pos :] length = len(arr) if fix > pos - 1: fix = pos - 1 picks = [] for i in range(pos): picks += [max(arr[i], arr[i + length - pos])] pick_range = pos - fix optimal = 0 ...
FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUN...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys t = int(sys.stdin.readline()) ans_arr = [] for x in range(t): [n, m, k] = [int(j) for j in sys.stdin.readline().split()] a = [int(g) for g in sys.stdin.readline().split()] if m - 1 > k: ans = -2 for i in range(k + 1): tmp = pow(10, 9) + 10 for j in range(m...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def f(): n, m, k = [int(s) for s in input().split()] A = [int(s) for s in input().split()] maxA = 1 for a in A: maxA = max(maxA, a) limit = min(m - 1, k) free = m - 1 - limit ans = 1 for a0 in range(limit + 1): minX = maxA for a in range(a0, a0 + free + 1): ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys t = input() def solve(n, m, k, nums): ans = 0 new_k = min(m - 1, k) for kk in range(new_k + 1): left = kk right = new_k - kk temp = nums[left : len(nums) - right] c = min([max(temp[i], temp[-(m - new_k - i)]) for i in range(m - new_k)]) ans = max(ans, c)...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
class Solution(object): def minSlidingWindow(self, nums, k): monotonicQueue = [] res = [] for i in range(len(nums)): while monotonicQueue and nums[monotonicQueue[-1]] >= nums[i]: monotonicQueue.pop() monotonicQueue.append(i) if monotonicQu...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def check(arr, m): n = len(arr) min_val = float("inf") for i in range(m): min_val = min(min_val, max(arr[i], arr[n - m + i])) arr.reverse() for i in range(m): min_val = min(min_val, max(arr[i], arr[n - m + i])) if min_val == float("inf"): return 0 return min_val def...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR FUNC_CALL ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) a = list(map(int, input().split())) before = m - 1 k = min(k, m) temp = [max(a[i], a[n + i - 1 - before]) for i in range(before + 1)] if k >= before: print(max(temp)) elif k == 0: print(min(temp)) els...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for _ in range(t): n, m, k = tuple(map(int, input().split())) l = list(map(int, input().split())) M = max(l) k = min(k, m - 1) realp = m - k - 1 ma = -1 for i in range(k + 1): tmp = M for j in range(realp + 1): tmp = min(tmp, max(l[i + j], l[i + j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMB...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def chek(x, li, l): mn = max(li[0], li[l - 1]) for i in range(x + 1): mx = max(li[i], li[l + i - 1]) mn = min(mn, mx) return mn t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) ar = list(map(int, input().split())) b = 0 x = m - 1 - k l = n - k ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR F...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for i in range(t): n, m, k = list(map(int, input().strip().split())) a = list(map(int, input().strip().split())) if k >= m: k = m - 1 z = m - 1 - k sol = [] for j in range(k + 1): big = max(a[j], a[j - k - z - 1]) for o in range(z + 1): if max...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LI...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
a = int(input()) for i in range(a): n, m, k = map(int, input().split()) z = list(map(int, input().split())) if m - 1 <= k: ans1 = z[::-1] print(max(max(z[0:m]), max(ans1[0:m]))) else: alpha = [] for i in range(k + 1): ans = z[i : len(z) - (k - i)] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
from sys import stdin def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return [str(x) for x in stdin.readline().split()] arr = [] for i in range(int(stdin.readline())): n, m, k ...
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUN...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys input = sys.stdin.readline t = int(input()) for _ in [0] * t: n, m, k = map(int, input().split()) a = list(map(int, input().split())) l = n - m + 1 ma = [0] * (n - l + 1) for i in range(n - l + 1): if a[i] > a[i + l - 1]: ma[i] = a[i] else: ma[i] =...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER F...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys input = sys.stdin.readline def f(p, b, c): j = 0 d = [] while j <= p: q = max(b[j], c[p - j]) d.append(q) j += 1 return min(d) def f1(p, b, c): j = 0 d = [] while j <= p: q = max(b[j], c[p - j]) d.append(q) j += 1 return max...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def solve(): n, m, k = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) maxg = None if k >= m: k = m - 1 for start in range(k + 1): end = n - (k - start) - 1 max_val = None left = None if m <= k + 1: left = 0 ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NONE ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input().rstrip()) for i in range(t): n, m, k = map(int, input().rstrip().split()) k = min(k, m - 1) nums = list(map(int, input().rstrip().split())) pk = tuple(max(nums[i], nums[i + (n - m)]) for i in range(m)) best = 0 for j in range(k + 1): best = max(best, min(pk[j : j + m - k]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
for _ in range(int(input())): n, me, k = map(int, input().split()) a = list(map(int, input().split())) sz = n - min(k, me - 1) before = max(0, me - k - 1) ret = -float("inf") for i in range(0, n - sz + 1): t = a[i : i + sz] cur = float("inf") for left in range(before + 1)...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) def slv(): n, m, k = map(int, input().split(" ")) a = list(map(int, input().split(" "))) ntr = max(0, m - k - 1) k = min(k, m - 1) sls = 0 for i in range(k + 1): la = 10000000000.0 for j in range(ntr + 1): la = min(la, max(a[i + j], a[len(a) - (k - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for y in range(t): n, m, k = map(int, input().split()) a = list(map(int, input().split())) if k >= m - 1: ans = max(max(a[:m]), max(a[n - m :])) else: i = k j = 0 ans = 0 while i >= 0: ind1 = i + (m - k) - 1 ind2 = n - j - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys input = sys.stdin.readline t = int(input()) class SegTree: def segfunc(self, x, y): return min(x, y) def __init__(self, n, ide_ele, init_val): self.ide_ele = ide_ele self.num = 2 ** (n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num for i in ran...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) def remchoice(a2, rem): ans = float("inf") for i in range(rem + 1): ans = min(ans, max(a2[i], a2[-rem + i - 1])) return ans for i in range(t): n, m, k = map(int, input().split()) a = list(map(int, input().split())) if m - 1 <= k: print(max(max(a[:m]), max(a[-...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def ma(x): return max(x[0], x[-1]) z = int(input()) for zz in range(z): n, m, k = map(int, input().split()) a = [int(i) for i in input().split()] segs = [] x = n - m + 1 for i in range(m): segs.append(a[i : i + x]) x = len(segs) for i in range(x): segs[i] = ma(segs[i]) ...
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXP...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) k = min(k, m - 1) a = list(map(int, input().split())) b = [] for i in range(m): b.append(max(a[i], a[i + n - m])) sz = m - k ans = 0 j = 0 q = [] for i in range(k + 1): while q and q[0] < i: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR V...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def resolve(): n, pos, control = map(int, input().split()) before = pos - 1 behind = n - pos control = min(before, control) uncontrol = pos - 1 - control line = list(map(int, input().split())) best = 0 for my_first in range(control + 1): strategy = float("inf") for op_fir...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
for _ in range(int(input())): n, m, k = map(int, input().split()) a = list(map(int, input().split())) k = min(k, m - 1) best = 0 before = m - 1 behind = n - m for x in range(k + 1): sans = float("inf") for y in range(m - k): cans = max(a[x + y], a[n - (m - x - y)]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) def solve(n, m, k, arr): if m - 1 <= k: return max(max(arr[:m]), max(arr[n - m :])) else: res = 0 for l in range(k + 1): r = k - l worst_case = 10**9 + 1 for ll in range(m - 1 - k + 1): rr = m - 1 - k - ll ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_O...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def inp(dtype=str, strip=True): s = input() res = [dtype(p) for p in s.split()] res = res[0] if len(res) == 1 and strip else res return res def problemA(): t = int(input()) for _ in range(t): n = int(input()) s = input() s = [int(el) for el in s] res = "-1" ...
FUNC_DEF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def main(): def solve(): n, m, k = map(int, input().split()) aa = [int(a) for a in input().split()] k = min(k, m - 1) u = m - k - 1 best = 0 for f in range(k + 1): b = n - k + f worst = 10000000000.0 + 1 for j in range(0, u + 1): ...
FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR AS...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
for _ in range(int(input())): n, m, k = list(map(int, input().split())) l = list(map(int, input().split())) mi = 0 for i in range(min(k, m - 1) + 1): temp = 100000000000 for j in range(m - min(k, m - 1)): temp = min(temp, max(l[i + j], l[n - m + i + j])) mi = max(mi, ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys input = sys.stdin.readline nn = int(input()) for i in range(nn): n, m, k = map(int, input().split()) k = min(k, m - 1) A = list(map(int, input().split())) B = [] for i in range(m): B.append(max(A[i], A[n - m + i])) ans = -float("inf") for i in range(k + 1): ans = ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL V...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for i in range(t): n, m, k = input().split() n = int(n) m = int(m) k = int(k) arr = list(map(int, input().split())) L = min(m - 1, k) arr1 = [] for i in range(L + 1): min1 = max(arr[i], arr[n - 1 - (m - 1 - i)]) for j in range(0, m - L): if ma...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys class CMindControl: def solve(self): for _ in range(int(input())): n, m, k = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] reachable_set = set() for i in range(m): reachable_set.add(i) rea...
IMPORT CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
V, IDX = [0] * 3501, [0] * 3501 def solve(A, n, m, k): d = n - m B = [0] * m for i in range(m): B[i] = max(A[i], A[i + d]) w = max(1, m - k) res = 0 l = r = 0 for i in range(m): while r > l and V[r - 1] >= B[i]: r -= 1 V[r], IDX[r] = B[i], i r +=...
ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys t = int(sys.stdin.readline().rstrip()) for _ in range(t): n, m, k = list(map(int, sys.stdin.readline().rstrip().split(" "))) s = list(map(int, sys.stdin.readline().rstrip().split(" "))) if k >= m: k = m - 1 sol2 = [] for i in range(k + 1): l = n - k + i - 1 f = i ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) k = min(k, m - 1) a = list(map(int, input().split())) glob_ans = 0 for start_eat in range(k + 1): l_bound, r_bound = start_eat, n - k + start_eat free = m - 1 - k ans = max(a[l_bound], a[r_bound - 1 - fre...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys input = sys.stdin.readline def getInt(): return int(input()) def getVars(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getStr(): return input().strip() def foo(b, before, m): m1 = 10**9 for j in range(m - before): m1 =...
IMPORT ASSIGN VAR VAR 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_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for loop in range(t): n, m, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0 if k < m - 1: for w in range(k + 1): x = k - w nmin = float("inf") for y in range(m - k): z = m - k - 1 - y n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) for ti in range(t): n, m, k = input().split() n = int(n) m = int(m) k = int(k) a = input().split() for i in range(n): a[i] = int(a[i]) if m <= k + 1: b = a[:m] + a[-m:] print(str(max(b))) else: notcontrol = m - k - 1 allans = [] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER AS...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, m, k = map(int, input().split()) a = list(map(int, input().split())) k = min(k, m - 1) ans = 0 for l in range(k + 1): r = k - l tmp = float("inf") for l2 in range(m - k): r2 = m - k - 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
def solve(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) k = min(m - 1, k) ans = 0 for i in range(k + 1): pos1 = i pos2 = n - 1 - (k - i) cur_ans = int(1000000000.0 * 2) for j in range(m - k): cur_ans = min(cur_ans, max(a[pos1 +...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR F...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
import sys def zip_sorted(a, b): a, b = zip(*sorted(zip(a, b))) sorted(zip(a, b), key=lambda x: x[1]) return a, b input = sys.stdin.readline I = lambda: list(map(int, input().split())) S = lambda: list(map(str, input().split())) (t,) = I() for t1 in range(t): n, m, k = I() a = I() a = [0] + ...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
from sys import stdin, stdout def main(): T = int(stdin.readline()) for zzz in range(T): arr = list(map(int, stdin.readline().split())) n, m, k = arr item = list(map(int, stdin.readline().split())) if m <= k: k = m - 1 luck = m - k - 1 maxer = 0 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VA...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
t = int(input()) while t != 0: n, m, k = map(int, input().split()) list1 = list(map(int, input().split())) mini = pow(10, 9) + 7 u = 0 list2 = list() k = min(k, m - 1) for i in range(m - 1, -1, -1): p = max(list1[i], list1[len(list1) - 1 - u]) list2.append(p) u += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR ...
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): ri, ci = 0, m - 1 while ri < n and ci >= 0: e = matrix[ri][ci] if x == e: return 1 if e < x: ri += 1 else: ci -= 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): found = 0 for i in range(m): found = matrix[i].count(x) if found != 0: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): for i in range(n): l = 0 h = m - 1 while l <= h: mid = (l + h) // 2 if matrix[i][mid] > x: h = mid - 1 elif matrix[i][mid] < x: l = ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): i = 0 j = m - 1 while i < n and j >= 0: if matrix[i][j] == x: return 1 elif matrix[i][j] < x: i = i + 1 else: j = j - 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): for i in range(n): for j in range(m): if matrix[i][j] == x: return 1 elif matrix[i][j] > x: break return 0
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): row = 0 col = m - 1 while row < n and col < m: if matrix[row][col] == target: return True elif matrix[row][col] > target: col -= 1 else: row += 1 re...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): def bs(arr, s, e, x): while s <= e: mid = s + (e - s) // 2 if arr[mid] == x: return True elif arr[mid] < x: s = mid + 1 else: ...
CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): for i in range(len(matrix)): if x >= matrix[i][0] and x <= matrix[i][-1]: def binary(arr, element, start, end): while start <= end: mid = (start + end) // 2 if...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP F...
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): res = False i = 0 j = m - 1 while i < n and j >= 0: if matrix[i][j] == x: res = True break elif matrix[i][j] < x: i += 1 else: j -= ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): pn = [] pc = [] for i in range(n): if matrix[i][0] <= x and matrix[i][m - 1] >= x: pn.append(i) for i in range(m): if matrix[0][i] <= x and matrix[n - 1][i] >= x: pc.append(i) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUM...
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
def solve(l, h, mat, x): while l < len(mat) and j > 0: if mat[l][h] == x: return True elif mat[l][h] < x: l += 1 else: h -= 1 return False class Solution: def search(self, matrix, n, m, x): i, j = 0, m - 1 while matrix[i][j] < x ...
FUNC_DEF WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBE...
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): ans = 0 for i in range(n): if matrix[i][m - 1] >= x: if matrix[i][m - 1] == x: ans = 1 break l = 0 h = n - 1 while l <= h: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_O...
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): st_r = n - 1 st_c = 0 while st_c < m and st_r < n: if x > matrix[st_r][st_c]: st_c += 1 elif x < matrix[st_r][st_c]: st_r -= 1 else: return 1 return...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): l = [] c = 0 for i in range(len(matrix)): for j in range(len(matrix[0])): l.append(matrix[i][j]) for i in range(len(l)): if l[i] == x: c += 1 if c > 0: retu...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER