description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, nums: List[int], target: int) -> int: nums.sort() ans = 0 for i in range(len(nums)): if 2 * nums[i] <= target: ans += 1 lo, hi = i + 1, len(nums) - 1 while lo < hi: m = (lo + hi) // 2 + 1...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VA...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, lis: List[int], tar: int) -> int: n = len(lis) mod = 1000000000 + 7 lis.sort() i = 0 j = n - 1 ans = 0 tmp = pow(2, n, mod) - 1 while i <= j: if lis[i] + lis[j] <= tar: i += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, nums: List[int], target: int) -> int: nums.sort() i = 0 j = len(nums) - 1 result = 0 mod = 10**9 + 7 while i <= j: if nums[i] + nums[j] > target: j -= 1 else: sublen = j - i ...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR VAR VA...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, x: List[int], t: int) -> int: def bi(lo, hi, val): while lo <= hi: m = (lo + hi) // 2 if x[m] <= val: lo = m + 1 else: hi = m - 1 return lo - 1 x.sor...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, nums: List[int], target: int) -> int: nums.sort() n = len(nums) res = 0 mod = 10**9 + 7 f = [1] + [0] * (n - 1) for i in range(1, n): f[i] = f[i - 1] * 2 % mod pos = n - 1 for i, num in enumerate(nums): ...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, nums: List[int], target: int) -> int: nums.sort() res = 0 i = 0 j = len(nums) - 1 while i < len(nums): if target - nums[i] < nums[i]: i = i + 1 continue while j > i: i...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, nums: List[int], target: int) -> int: nums.sort() l = len(nums) left = 0 right = l - 1 ans = 0 while left <= right: curr = nums[left] leftover = target - curr if leftover < curr: ...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR BIN_OP BI...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
max_cap = 7 + 10**9 class Solution: def numSubseq(self, nums: List[int], target: int) -> int: init_seq_len = len(nums) nums.sort() l = 0 r = init_seq_len - 1 count = 0 while l <= r: if nums[l] + nums[r] > target: r -= 1 else:...
ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VA...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, nums: List[int], target: int) -> int: MOD = int(1000000000.0 + 7) pw = [1] for i in range(1, 100001): pw.append(pw[-1] * 2 % MOD) nums.sort() i = 0 j = len(nums) - 1 ret = 0 for i in range(len(nums)): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL...
Given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal than target. Since the answer may be too large, return it modulo 10^9 + 7.   Example 1: Input: nums = [3,5,6,7], target = 9 Output: 4 Exp...
class Solution: def numSubseq(self, nums, target: int) -> int: n = len(nums) nums.sort() res = 0 i = 0 last = n - 1 while i < n and 2 * nums[i] <= target: j = last while j >= i and nums[i] + nums[j] > target: j -= 1 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR ...
Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance c_{i} and width w_{i}. Stepan decided to expose some of his cups on a shelf with width d in such a way, that: there is at least on...
n, m, d = map(int, input().split()) ph = [[int(j) for j in input().split()] for i in range(n)] inf = [[int(j) for j in input().split()] for i in range(m)] for i in range(n): ph[i][1] = -ph[i][1] for i in range(m): inf[i][1] = -inf[i][1] ph.sort(reverse=True) inf.sort(reverse=True) sw, sc = 0, 0 for p in inf: ...
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 VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR V...
Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance c_{i} and width w_{i}. Stepan decided to expose some of his cups on a shelf with width d in such a way, that: there is at least on...
n, m, d = list(map(int, input().split())) a = [] b = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(list(map(int, input().split()))) a = sorted(a, key=lambda x: x[0] + (1 - x[1] * 1e-10)) b = sorted(b, key=lambda x: x[0] + (1 - x[1] * 1e-10)) tc, td = 0, 0 tc += a[-1...
ASSIGN VAR VAR VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR ...
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def isSub(s1, s2): it = iter(s2) return all(i in it for i in s1) keep, max1, N = False, -1, len(strs) mask = [True] * N for i in range(N): for j in range(N): if i != j and isSub(strs...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ...
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def isSubseq(s1, s2): i, m = 0, len(s1) for c in s2: if i == m: return True if s1[i] == c: i += 1 return i == m strs.sort(key=len, reverse=Tru...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def issub(w1, w2): i = 0 for w in w2: if i < len(w1) and w1[i] == w: i += 1 return i == len(w1) strs.sort(key=len, reverse=True) for s in strs: strs_copy = st...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def isSubseq(s1, s2): s2_it = iter(s2) return all(i in s2_it for i in s1) for k in sorted(strs, key=len, reverse=True): if sum(isSubseq(k, k2) for k2 in strs) == 1: return len(k) return -1
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN NUMBER
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def is_subseq(a, b): if len(b) > len(a): return False i = 0 for c in a: if i < len(b) and b[i] == c: i += 1 return i == len(b) strs.sort(key=lambda x:...
CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ...
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): answer = -1 for i in range(len(strs)): x = strs[i] if len(x) > answer and all( [ (not self.isSubsequence(x, strs[j])) for j in range(len(strs)) if i != ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VA...
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def isSubsequence(a, b): i = 0 j = 0 while i < len(a) and j < len(b): if j == len(b) - 1 and (i < len(a) - 1 or a[i] != b[j]): return False if a[i] != b[j]: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST F...
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def check(a, b): i = 0 for ai in a: while i < len(b) and ai != b[i]: i += 1 if i == len(b): return False else: i += 1 ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CA...
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one seque...
class Solution: def findLUSlength(self, strs): def is_subsequence(s, substr): i = 0 j = 0 while i < len(s) and j < len(substr): if s[i] == substr[j]: i += 1 j += 1 else: i += 1 ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for z in range(t): n, q = [int(x) for x in input().split()] a = [int(x) for x in input().split()] dic = {} for c in range(n): dic.update({(c + 1): 0}) start = a[0] end = 1 starti = 0 for v in range(n): if start < a[v]: for w in range(end, star...
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR DICT BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for _ in range(t): n, q = map(int, input().split()) a = list(map(int, input().split())) st = [0] * n if a[0] > a[1]: mx = a[0] p = 0 else: mx = a[1] p = 1 a.append(10**5 + 5) for i in range(2, n + 1): if a[i] > mx: mx = a[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for _ in range(t): n, q = map(int, input().split()) arr = list(map(int, input().split())) res = [[] for _ in range(n + 1)] maxi = arr.index(n) r = max(maxi, 1) if maxi > 1: index = 1 start = 1 level = arr[0] for i in range(1, n): if ar...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for test in range(t): n, k = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] if arr[0] == n or arr[1] == n: for i in range(k): i, q = [int(i) for i in input().split()] if arr[i - 1] == n: print(q) else: ...
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for i in range(t): n, q = (int(temp) for temp in input().split()) nums = [int(temp) for temp in input().split()] minind = [n + 2] * (n + 1) jl = [0] * (n + 1) winpre = [0] * (n + 1) winpre[1] = 1 mx = nums[0] for i in range(n): jl[nums[i]] = i + 1 mx = ma...
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER ...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for _ in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) p = [a[0]] freq = {} for x in range(1, n): k = max(a[x], p[x - 1]) p += [k] try: freq[k] += [x] except: freq[k] = [x] for query in range(q): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR LIST VAR VA...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for _ in range(t): n, q = map(int, input().split(" ")) a = list(map(int, input().split(" "))) b = [] for i in range(n): b.append([a[i], i + 1]) c = [0] * (n + 1) d = [0] * (n + 1) for i in range(n): d[a[i]] = i + 1 x = b[0] for i in range(1, n): ...
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 STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NU...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
T = int(input()) for _ in range(T): n, q = map(int, input().split()) a = list(map(int, input().split())) M = [] cur = [-1, 0] for i in range(n): if a[i] > cur[1]: cur = [i, a[i]] M.append(cur) marker = {} for i in range(1, n): if M[i][0] not in marker: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR EXPR FUNC...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
R = lambda: [*map(int, input().split())] for _ in range(*R()): n, q = R() a = R() maxx = 0 c = 0 b = [(0) for i in range(n)] for i in range(1, n): if a[i] > a[maxx]: b[maxx] = c maxx = i c = 1 b[maxx] = c else: c += 1 ...
ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) res = [] for _ in range(t): n, q = list(map(int, input().split())) a = [0] + list(map(int, input().split())) m = [[0, 0] for _ in range(n + 1)] winner = 1 for i in range(2, n + 1): if a[winner] < a[i]: winner = i if m[winner][0] == 0: m[winner...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBE...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for iters in range(int(input())): n, q = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] wonlist = {} wonlist[0] = 1 losslist = {} last = a[0] last_index = 0 for i in range(1, n): nex = a[i] if nex == n: losslist[i] = n if...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN V...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for _ in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) d = {} last = {} first = {} if a[0] > a[1]: winning = [0] d[0] = 1 last[0] = 1 first[0] = 1 else: winning = [1] d[1] = 1 last[1] = 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for _ in range(int(input())): n, xx = map(int, input().split()) l = list(map(int, input().split())) question = [] for _ in range(xx): question.append(map(int, input().split())) p = l[:] for i in range(1, n): p[i] = max(p[i], p[i - 1]) s = [(n + 1) for _ in range(n)] q = [...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
def bb(l, k): p1 = 0 p2 = len(l) while p1 != p2: m = (p1 + p2) // 2 if k >= l[m]: p1 = m + 1 else: p2 = m return p1 for i in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) w = [] wc = [[] for i i...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN 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 FUNC_CALL VAR FUNC_CAL...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for w in range(t): n, q = map(int, input().split()) a = list(map(int, input().split())) z = a.index(n) - 1 s = [0] * n for x in range(n): s[x] = [0, 0] if a[0] > a[1]: s[0] = [1, 1] vigr = 0 else: s[1] = [1, 1] vigr = 1 sled = 2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER N...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for _ in range(int(input())): n, q = map(int, input().split()) l = list(map(int, input().split())) idx = l.index(n) t = [] d = {i: (0) for i in range(n + 1)} mx = max(l[0], l[1]) for i in range(1, idx): if l[i] > mx: mx = l[i] d[mx] += 1 ids = {} for i in ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUM...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
xx = int(input()) for jj in range(xx): n, q = [int(i) for i in input().split(" ")] arr = [0] + [int(i) for i in input().split(" ")] r = [-1] * (n + 1) tt = 0 for i in range(1, n + 1): if arr[i] == n: r[i] = 0 r[tt] = i break if arr[i] < arr[tt]: ...
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 STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VA...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
test = int(input()) for _ in range(test): n, q = list(map(int, input().split())) nums = list(map(int, input().split())) lar = max(nums) ques = [] for _ in range(q): ques.append(list(map(int, input().split()))) c = {} left = 0 right = 1 for i in range(len(nums) - 1): i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for _ in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) amax = [] if n == 100000 and q == 100000 and a[0] == 1: for i in range(n): print(1) else: for i in range(n): o = 0 p = 1.5 while o < n: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VA...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
t = int(input()) for _ in range(t): n, q = input().split() n, q = int(n), int(q) arr = input().split() arr = [int(i) for i in arr] wins_times = [(0) for _ in range(n)] if arr[0] < arr[1]: wins_times[1] += 1 win_now = 1 else: wins_times[0] += 1 win_now = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
def p(s): pass def f(): n, q = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] idx = 0 winner = a[0] wins = 0 for i in range(1, n): if a[i] == n: a[idx] = wins idx = i a[idx] = -1 break if a[i] > winner...
FUNC_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN ...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
import sys input = sys.stdin.readline def int_num(): return int(input()) def int_list(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) def solve(): n, q = int_list() a = int_list() d = {...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for t in range(int(input())): n, q = map(int, input().split()) l = list(map(int, input().split())) ls = [] lsi = [] i = 0 m = l[0] for j in l: if j > m: m = j lsi.append(i) ls.append(m) i += 1 for j in range(q): i, k = map(int, inpu...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for t in range(int(input())): n, q = map(int, input().split()) L = list(map(int, input().split())) P = [] N = [] P.append(L[0]) for i in range(n): N.append(0) c = 0 for i in range(1, n): if P[-1] < L[i]: P.append(L[i]) c = i N[c] += 1 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_C...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def swap(a, b): a, b = b, a return a, b def bits(n): c = 0 while n: n &= n - 1 c += 1 return c t = int(input()) while t > 0: n, q = map(int, input().split()) arr = list(map(int, input().split())) ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIG...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for _ in range(int(input())): n, q = map(int, input().split()) x = list(map(int, input().split())) y = [(0) for j in range(len(x))] w = x[0] wp = 0 if w == n: mp = 0 y[0] = -1 else: mp = -1 for j in range(1, len(x)): if mp != -1: y[j] = 0 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBE...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
import sys input = sys.stdin.readline t = int(input()) for t_item in range(t): n, q = map(int, input().split()) a = [int(i) for i in input().split()] b = [0] * n prev = 0 for i in range(1, n): if a[i] > a[prev]: prev = i b[prev] += 1 for j in range(q): i, k =...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) for _ in range(inp()): n, q = invr() arr = inlt() k = {} ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL V...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
for _ in range(int(input())): leng, tests = [int(x) for x in input().split()] conts = [int(x) for x in input().split()] wins = 0 ma = conts[0] max_ind = 0 for i in range(1, leng): if conts[i] > ma: conts[max_ind] = wins ma = conts[i] max_ind = i ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN V...
Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $n$ athletes participate in the tournament, numbered from $1$ to $n$. Burenka determined the strength of the $i$-th athlete as an integer $a_i$, where $1 \leq a_i \leq n$. All the strength v...
z = lambda: map(int, input().split()) (t,) = z() for _ in [1] * t: n, q = z() d = {i: (0) for i in range(n + 1)} a = [*z()] mx = max(a[0], a[1]) for i in a[1:]: if i > mx: mx = i d[mx] += 1 idmx = a.index(mx) idx = {} for i in range(n): idx[a[i]] = i ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VA...
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a_{i} is written on the i-th card in the deck. After receiving...
def gcd(a, b): if a == 0: return b return gcd(b % a, a) n, k = [int(x) for x in input().split()] a = [gcd(int(x), k) for x in input().split()] if k == 1: print((n + 1) * (n + 2) // 2 - n - 1) else: s = 0 e = 0 total = (n + 1) * (n + 2) // 2 - 1 - n c = 1 while e < n: fl...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NU...
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a_{i} is written on the i-th card in the deck. After receiving...
n, k = map(int, input().split()) l = list(map(int, input().split())) pf = [] needed = [] for i in range(2, 40000): if k % i == 0: pf.append(i) c = 0 while k % i == 0: k //= i c += 1 needed.append(c) if k > 1: pf.append(k) needed.append(1) pfl = len(pf)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL ...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def binary(self, dp, start, end, k, temp): mid, idx = -1, -1 diff = float("inf") while start <= end: mid = start + (end - start) // 2 first = dp[mid] - temp second = k - dp[mid] if abs(first - second) < diff: id...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BI...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def minDifference(self, n, arr): summ = [0] * (n + 1) for i, e in enumerate(arr): summ[i + 1] = summ[i] + e def parts(l, r): low, high = l, r while low < high: m = low + (high - low) // 2 lp = summ[m + 1] -...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP V...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def minDifference(self, N, A): arr = [0] * N arr[0] = A[0] for i in range(1, N): arr[i] = A[i] + arr[i - 1] ans = float("inf") for i in range(2, N - 1): index = self.binary_search(arr, 0, i - 1, arr[i - 1], 0) w = arr[index...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBE...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def minDifference(self, N, A): def helper(lst, low, high): left = lst[low - 1] if low > 0 else 0 localTot = lst[high] - left while low < high: mid = low + (high - low) // 2 if lst[mid] - left < localTot // 2: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def minmax(self, A, l, h): low = l high = h while low < high: mid = low + (high - low) // 2 lsum = A[mid + 1] - A[l] rsum = A[h + 1] - A[mid] if lsum >= rsum: high = mid else: low = m...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def minDifference(self, N, A): sums = [0] * (N + 1) for i, e in enumerate(A): sums[i + 1] = sums[i] + e sumrange = lambda l, r: sums[r + 1] - sums[l] def search(l, r): goal = sumrange(l, r) // 2 lo, hi = l, r while lo ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_O...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
from itertools import accumulate class Solution: def minDifference(self, N, A): def _split(L, R): LSUM = acc[L - 1] if L > 0 else 0 tot = acc[R] - LSUM goal = tot // 2 while L < R: m = (L + R) // 2 if acc[m] - LSUM < goal: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VA...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def find_split(self, a): n = len(a) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i] = a[i] if i > 0: prefix_sum[i] += prefix_sum[i - 1] split_points = [[0, 0]] for i in range(1, n): low, high = 1...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUM...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
from itertools import chain class Solution: def minDifference(self, N, A): def get_prefix_sums(arr): n = len(arr) sums = [0] * n sums[0] = arr[0] for i in range(1, n): sums[i] = sums[i - 1] + arr[i] return sums def find...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP VAR VAR...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def helper(self, i, j, reduction): x, y = i, j score = float("inf") best = 0 MaxVal = self.subA[j - 1] while x < y: mid = (x + y) // 2 subres = MaxVal - 2 * self.subA[mid] + reduction abssubres = abs(subres) if ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER AS...
Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that each element of the array A[] should be present in any subarray. Let W, X, Y, and Z be the sum of the elements in P, Q, R, and S respectively. Find the smallest absolute difference betw...
class Solution: def minDifference(self, N, A): x = self.partition(A, N) A.reverse() y = self.partition(A, N) y.reverse() ans = 10**18 for i in range(1, N - 2): ans = min( ans, max(x[i][0], x[i][1], y[i + 1][0], y[i + 1][1])...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_O...
Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B. Example 1: Input: nums = [1,3,1] k = 1 Output: 0 Explanation: Here are all the pairs: (1,3) -> 2 (1,1) -> 0 (3,1) -> 2 Then the 1st smallest distance pa...
class Solution(object): def smallestDistancePair(self, nums, k): def possible(guess): count = left = 0 for right, x in enumerate(nums): while x - nums[left] > guess: left += 1 count += right - left return count >= k ...
CLASS_DEF VAR FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR...
Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B. Example 1: Input: nums = [1,3,1] k = 1 Output: 0 Explanation: Here are all the pairs: (1,3) -> 2 (1,1) -> 0 (3,1) -> 2 Then the 1st smallest distance pa...
class Solution: def smallestDistancePair(self, nums, k): nums.sort() l, r = 0, nums[-1] - nums[0] while l < r: m = l + (r - l) // 2 count = 0 left = 0 for right in range(len(nums)): while nums[right] - nums[left] > m: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_O...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A.sort() for i in range(n - 1, 0, -1): left = 0 right = i - 1 while left < right: if A[left] + A[right] + A[i] == X: return 1 elif A[left] + A[right] + A[i] > X: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): dic = dict() for i in range(0, n - 2): for j in range(i + 1, n): curr = X - (A[i] + A[j]) if curr in dic: return 1 else: dic[A[j]] = 1 dic...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): for i in range(1, n): temp = A[i] curr = i while A[curr] < A[curr - 1] and curr >= 1: A[curr], A[curr - 1] = A[curr - 1], A[curr] curr = curr - 1 remain = 0 ans = [] ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR I...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A.sort() count = 0 for i in range(n - 2): left = i + 1 right = n - 1 while left < right: s = A[i] + A[left] + A[right] if s == X: count += 1 ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, arr_size, sum): for i in range(0, arr_size - 1): s = set() curr_sum = sum - A[i] for j in range(i + 1, arr_size): if curr_sum - A[j] in s: return True s.add(A[j]) return...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): for i in range(n - 1): a = set() for j in range(i + 1, n): if X - (A[i] + A[j]) in a: return 1 a.add(A[j]) return 0
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A.sort() res = [] for i, v in enumerate(A): if i > 0 and v == A[i - 1]: continue left, right = i + 1, len(A) - 1 while left < right: currentSum = A[i] + A[left] + A[right] ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_O...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def f(self, a, n, s): l = 0 r = n - 1 a.sort() for i in range(n - 2): l = i + 1 r = n - 1 while l < r: if a[i] + a[l] + a[r] == s: return 1 elif a[i] + a[l] + a[r] < s: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMB...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): for i in range(n): T = X - A[i] h2 = {} for j in range(n): if i == j: continue if T - A[j] in h2: return True else: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, arr, n, X): dic = {} for i in range(n): dic[arr[i]] = dic.get(arr[i], []) + [i] count = 0 for i in range(n): for j in range(i + 1, n): temp = X - arr[i] - arr[j] if temp in dic: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR LIST LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, a, n, x): a.sort() for i in range(n): num1 = a[i] low = i + 1 high = n - 1 reqsum = x - num1 while low < high: if a[low] + a[high] == reqsum: return True ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, nums, n, k): ans = set() nums.sort() for i in range(len(nums)): start = i + 1 end = len(nums) - 1 while start < end: sum_ = nums[start] + nums[end] + nums[i] if sum_ == k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR BI...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A.sort() for i in range(n): j = i + 1 k = n - 1 while j < k: sum = A[i] + A[j] + A[k] if sum == X: return True elif sum < X: j...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, arr, n, x): arr.sort() for i in range(n - 2): l = i + 1 h = n - 1 while l < h: if arr[h] > x: h = h - 1 if arr[l] + arr[h] + arr[i] == x: return True ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR ...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A.sort() cnt = 0 for i in range(n - 2): requiredSum = X - A[i] left, right = i + 1, n - 1 while left < right: currentSum = A[left] + A[right] if currentSum == requiredSum: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A.sort() for i in range(n - 2): rem_sum = X - A[i] j = i + 1 k = n - 1 while j != k: s = A[j] + A[k] if s < rem_sum: j += 1 else: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): for i in range(n): d = [(0) for _ in range(X + 1)] for j in range(i + 1, n): if X - A[i] - A[j] > 0 and d[X - A[i] - A[j]] == 1: return 1 elif A[j] <= X: d[A[j]] ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A = sorted(A) if n <= 3: return False for i in range(n): front = i + 1 back = n - 1 while front < n and back > i and front < back: if A[front] + A[back] == X - A[i]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): def two_sum(a, arr, x): d = {} for i in range(len(arr)): if x - arr[i] in d: return True else: d[arr[i]] = i return False A.sort() f...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): for i in range(n): A.sort() c = A[i] p1 = i + 1 p2 = n - 1 while p1 < p2: if A[p1] + A[p2] == X - c: return True elif A[p1] + A[p2] < X - c: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A = set(A) A = list(A) n = len(A) for i in range(n - 1): s = A[i] for j in range(i + 1, n): if X - (s + A[j]) in A[j + 1 : n]: return True return False
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A = sorted(A) for i in range(n - 2): j = i + 1 k = n - 1 while j < k: sum = X - A[i] if A[j] + A[k] == sum: return 1 elif A[j] + A[k] > sum: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): count = 0 z = {} for i in A: z.setdefault(i, 0) z[i] += 1 x = 0 y = 0 for i in range(n): for j in range(i + 1, n): x = 0 y = 0 if X - ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF BI...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): for i in range(n): newTarget = X - A[i] hashtable = {} for j in range(i + 1, n): need = newTarget - A[j] if need in hashtable: return True hashtable[A[j]]...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): dic = {} for i in A: if i in dic: dic[i] += 1 else: dic[i] = 1 for i in range(0, n): dic[A[i]] -= 1 for j in range(i + 1, n): dic[A[j]] -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR VAR VAR NUMBER VAR VAR VAR N...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): count = 0 for i in range(n): st = set() sm = X - A[i] for j in range(i + 1, n): if sm - A[j] in st: count += 1 else: st.add(A[j]) retu...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, nums, n, X): res = [] nums.sort() for i, a in enumerate(nums): if i > 0 and a == nums[i - 1]: continue left, right = i + 1, len(nums) - 1 while left < right: s = a + nums[left] + nums[...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def twoSum(self, arr, target): hash_set = set() for num in arr: if num in hash_set: return True else: hash_set.add(target - num) return False def find3Numbers(self, A, n, X): target = X for i in ran...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): count = 0 A.sort() for i in range(n): if i > 0 and A[i] == A[i - 1]: continue j = i + 1 k = n - 1 while j < k: sum = A[i] + A[j] + A[k] if sum < X...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUM...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): A.sort() n = len(A) found = False for i in range(n): left = i + 1 right = n - 1 while left < right: sum = A[left] + A[right] + A[i] if sum == X: f...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF V...
Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X. Example 1: Input: n = 6, X = 13 arr[] = [1 4 45 6 10 8] Output: 1 Explanation: The triplet {1, 4, 8} in the array sums up to 13. Example 2: Input: n = 5, X = 10 arr[] = [1 2 4 3 6] Output: 1 Exp...
class Solution: def find3Numbers(self, A, n, X): dic = {} for i in A: if i not in dic: dic[i] = 1 continue dic[i] += 1 count = 0 for a in range(n): for b in range(n): if a == b: c...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR V...
You are given an array $a$ of $n$ integers. You are asked to find out if the inequality $$\max(a_i, a_{i + 1}, \ldots, a_{j - 1}, a_{j}) \geq a_i + a_{i + 1} + \dots + a_{j - 1} + a_{j}$$ holds for all pairs of indices $(i, j)$, where $1 \leq i \leq j \leq n$. -----Input----- Each test contains multiple test cases. ...
import sys input = sys.stdin.readline def sol(arr, n): l = 0 r = n - 1 for i in range(n - 1): if arr[i] > 0 and arr[i + 1] > 0: return "NO" while l < n and arr[l] <= 0: l += 1 while r >= 0 and arr[r] <= 0: r -= 1 if r < 0: return "YES" res = [] ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN STRING WHILE VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING ASSIGN VAR LIST WHILE VAR VAR ...
You are given an array $a$ of $n$ integers. You are asked to find out if the inequality $$\max(a_i, a_{i + 1}, \ldots, a_{j - 1}, a_{j}) \geq a_i + a_{i + 1} + \dots + a_{j - 1} + a_{j}$$ holds for all pairs of indices $(i, j)$, where $1 \leq i \leq j \leq n$. -----Input----- Each test contains multiple test cases. ...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) pre = [0] suf = [0] min_suf = [0] * n min_pre = [0] * n stk = [] flag = True for i in range(n): pre.append(pre[-1] + a[i]) temp_min = pre[i] while len(stk) and a[stk[-1]] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER F...
You are given an array $a$ of $n$ integers. You are asked to find out if the inequality $$\max(a_i, a_{i + 1}, \ldots, a_{j - 1}, a_{j}) \geq a_i + a_{i + 1} + \dots + a_{j - 1} + a_{j}$$ holds for all pairs of indices $(i, j)$, where $1 \leq i \leq j \leq n$. -----Input----- Each test contains multiple test cases. ...
import sys input = sys.stdin.readline def solve(): n = int(input()) arr = list(map(int, input().split())) ng1, ng2 = [-1] * n, [-1] * n st1, st2 = [], [] ps, ss = [0] * n, [0] * n v1 = v2 = 0 for i in range(n): while st1 and arr[st1[-1]] <= arr[i]: ng1[st1.pop()] = i ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_C...