description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() seg = n // k if s.count("0") % seg != 0 or s.count("1") % seg != 0: print("IMPOSSIBLE") else: for i in range(seg): if i % 2 == 0: for j in range(s.count("0") // seg): ...
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 ASSIGN VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR STRING VAR NUMBER BIN_OP FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) while t > 0: t -= 1 n, k = map(int, input().split()) a = input() s = n // k z = 0 o = 0 for i in a: if i == "0": z += 1 else: o += 1 if o % s != 0 or z % s != 0: print("IMPOSSIBLE") else: z = z // s o = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) while t: t -= 1 n, k = map(int, input().strip().split(" ")) s = input() g = n // k fq = [0] * 2 for i in range(n): fq[ord(s[i]) - ord("0")] += 1 if fq[0] % g != 0 or fq[1] % g != 0: print("IMPOSSIBLE") else: it = n // k f0 = fq[0] // g ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF BIN_OP V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) while t: n, k = map(int, input().split()) s = input() ans = "" ans1 = "" finans = "" set_len = int(len(s) / k) count_1 = 0 count_0 = 0 for i in s: if i == "1": count_1 += 1 else: count_0 += 1 if count_1 % set_len == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMB...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
try: def solve(): n, k = map(int, input().split()) s = list(map(int, input())) segments = int(n / k) zerocount = 0 onecount = 0 for i in s: if i == 0: zerocount += 1 if i == 1: onecount += 1 if zerocount...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() o = s.count("1") z = n - o k = n // k if o % k or z % k: print("IMPOSSIBLE") else: word = "1" * (o // k) + "0" * (z // k) rev = word[::-1] ans = [] for i in range(k): ...
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 ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for i in range(t): n, k = map(int, input().split()) s = input() l = [] l1 = [] a = n // k if s.count("0") % a != 0 or s.count("1") % a != 0: print("IMPOSSIBLE") else: n0 = s.count("0") // a n1 = s.count("1") // a while n0 != 0: l.a...
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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR STRING VAR NUMBER BIN_OP FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for i in range(t): x = input() x = x.split() n = int(x[0]) k = int(x[1]) s = input() factor = n // k n0 = s.count("0") n1 = s.count("1") if n0 % factor != 0 or n1 % factor != 0: print("IMPOSSIBLE") else: r = "0" * (n0 // factor) + "1" * (n1 // fac...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def k_fold_string(string: list, n, k): counts = [string.count("0"), string.count("1")] if counts[0] % (n // k) != 0 and counts[1] % (n // k) != 0: return "IMPOSSIBLE" else: pattern = [ "0" * (counts[0] // (n // k)) + "1" * (counts[1] // (n // k)), "1" * (counts[1] // ...
FUNC_DEF VAR ASSIGN VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER RETURN STRING ASSIGN VAR LIST BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR NUM...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() a = [0] * 2 for i in s: if i == "0": a[0] += 1 else: a[1] += 1 r = n // k if n < k or a[0] % r != 0 or a[1] % r != 0: print("IMPOSSIBLE") else: k0, k1 = a[...
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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for i in range(int(input())): a, b = map(int, input().split()) c = input() x = c.count("1") y = c.count("0") z = a // b d = x // z e = y // z f = "" h = "" j = 0 if y % z != 0 or x % z != 0: print("IMPOSSIBLE") else: f = "0" * e + "1" * d g = 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 ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() a = [int(i) for i in s] zero = a.count(0) one = a.count(1) m = n // k if zero % m != 0 or one % m != 0: print("IMPOSSIBLE") else: ans = "" e = zero // m p = one // m while e...
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 ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def gcd(x, y): if x > y: small = y else: small = x for i in range(1, small + 1): if x % i == 0 and y % i == 0: gcd = i return gcd def pal(s, n): k = 0 for i in range(int(n / 2)): if s[i] == s[n - i]: k += 1 if k == int(n / 2): ...
FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() l = [0, 0] for i in s: if i == "0": l[0] += 1 else: l[1] += 1 a = n // k o = l[0] // a e = l[1] // a if l[0] % a == 0 and l[1] % a == 0: temp = "0" * o + "1" * e ...
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 ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF B...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = [int(x) for x in input().split()] s = input() if s.count("0") % (n / k) != 0 or s.count("1") % (n / k) != 0: print("IMPOSSIBLE") else: l = "" f = 0 while True: l += "0" * int(s.count("0") // (n / k)) + "1" * int(s.count("1"...
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 IF BIN_OP FUNC_CALL VAR STRING BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR STRING BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE NUMBER VAR BI...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def find(n, k, s): repeat = n // k zero = 0 one = 0 for i in s: if i == "0": zero += 1 else: one += 1 li = [] for i in range(0, k + 1): z = i o = k - i if z * repeat == zero and o * repeat == one: temp = "" s...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BI...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() count_1 = s.count("1") count_0 = s.count("0") num_of_seg = n // k if count_1 % num_of_seg == 0 and count_0 % num_of_seg == 0: for x in range(num_of_seg): if x % 2 == 0: for y in r...
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 ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for i in range(int(input())): n, k = map(int, input().split()) string = input() list1 = [0, 0] for i in range(n): if string[i] == "0": list1[0] += 1 else: list1[1] += 1 pass1 = n // k if list1[0] % pass1 != 0 and list1[1] % pass1 != 0: print("IMPOS...
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 ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def kfolded(s, k): n = len(s) if n == 0: return "IMPOSSIBLE" c1 = 0 c2 = 0 seg = n // k for c in s: if c == "0": c1 += 1 else: c2 += 1 if c1 == 0 or c2 == 0: return s if c1 % seg == 0 and c2 % seg == 0 and c1 // seg != 0 and c2 // s...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def kfold(n, k, s): zero = 0 one = 0 segment_count = n // k for i in s: if i == "0": zero += 1 else: one += 1 if zero % segment_count != 0 or one % segment_count != 0: return "IMPOSSIBLE" zero = zero // segment_count one = one // segment_count ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FU...
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the mu...
def main(): N = int(input()) A = list(map(int, input().strip().split(" "))) primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 6...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMB...
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the mu...
def main(): N = int(input()) a = [int(x) for x in input().split()] p = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FU...
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the mu...
from sys import stdin primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ] def getPrime(n): arr = [0] * 25 for i, p in enumerate(primes): if p > ...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER...
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the mu...
import sys def solve(n, arr, queries): store = { (2): [], (3): [], (5): [], (7): [], (11): [], (13): [], (17): [], (19): [], (23): [], (29): [], (31): [], (37): [], (41): [], (43): [], (47): [],...
IMPORT FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIS...
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the mu...
primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ] def getPrimeFactors(num): arr = [0] * 25 for index, i in enumerate(primes): if i > num: ...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER...
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): arr = preorder.split(",") k = len(arr) for _ in range(k): print(arr) if arr == ["#"]: return True newArr = [] i = 0 while i < len(arr): if ( ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR LIST STRING RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER...
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): if not preorder: return False nodes = preorder.split(",") stack = [0] if nodes[0] != "#" else [] dt = {(0): 2} i = 1 while stack and i < len(nodes): dt[stack[-1]] -= 1 if dt...
CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER STRING LIST NUMBER LIST ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ...
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): if not preorder: return True arr = preorder.split(",") s = [] for a in arr: s.append(a) while len(s) >= 3 and s[-1] == "#" and s[-2] == "#" and s[-3] != "#": s.pop() ...
CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF VAR LIST STRING RETURN NUM...
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): stack, preorder = [], preorder.split(",") top = -1 for s in preorder: stack.append(s) top += 1 while self.endsWithTwoHashes(stack, top): h, top = stack.pop(), top - 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR LIST FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER STRING RETURN FUNC_CALL VAR ...
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): new_preorder = preorder for i in range(len(new_preorder) - 1, 0, -1): if (new_preorder[i] != "#" and new_preorder[i] != ",") and ( new_preorder[i - 1] != "#" and new_preorder[i - 1] != "," ): ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA...
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): if len(preorder) < 1: return False stack = [] for s in preorder.split(","): stack.append(False) if s == "#": while len(stack) > 2 and stack[-2]: stack.pop() ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR LIST NUMBER NUMBER
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): preorder, first = preorder.split(","), preorder.split(",") def backward(index): if index >= len(preorder) or index < 0: return if ( index + 1 < len(preorder) and preord...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_O...
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution(object): def isValidSerialization(self, preorder): p = preorder.split(",") slot = 1 for node in p: if slot == 0: return False if node == "#": slot -= 1 else: slot += 1 return slot == 0
CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR STRING VAR NUMBER VAR NUMBER RETURN VAR NUMBER
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ / \ 4 1 # 6 / \ / \ / \ # # # # # # For example, the above binary tree can...
class Solution: def isValidSerialization(self, preorder): preorder = preorder.split(",") if preorder[0] == "#": return len(preorder) == 1 s = [] curr = preorder[0] on_left = True for i in range(1, len(preorder)): if not curr: r...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR VAR IF VAR STRING IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUM...
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
from sys import stdin, stdout quests = int(stdin.readline().rstrip()) multi_set = {} p = str.maketrans("0123456789", "0101010101") for i in range(quests): quest, core = stdin.readline().rstrip().split() pattern = int(core.translate(p)) if quest == "+": if pattern in multi_set.keys(): mu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR VAR NUMB...
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
t = int(input()) ans = [0] * 2**18 y = str.maketrans("0123456789", "0101010101") for i in range(t): x, s = map(str, input().split()) if x == "+": ans[int(s.translate(y), 2)] += 1 elif x == "-": ans[int(s.translate(y), 2)] -= 1 else: print(ans[int(s.translate(y), 2)])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING VAR FUNC_CALL VAR FUNC_CALL VA...
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
present = {} coded = {} cc = {} def encode(s): a = "" for i in range(len(s)): if int(s[i]) % 2 == 0: a += "0" else: a += "1" x = "" for i in range(18 - len(a)): x += "0" x += a return x def add(num): present[num] = present.get(num, 0) + 1 ...
ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR STRING VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR STRING VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR BIN_OP FUNC...
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
from sys import stdin input() cnt = [0] * 2**18 t = str.maketrans("0123456789", "0101010101") for ch, s in map(str.split, stdin): if ch == "?": print(cnt[int(s, 2)]) else: cnt[int(s.translate(t), 2)] += 1 if ch == "+" else -1
EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR STRING NUMBER NUMBER
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
num = int(input()) multiset = [0] * 2**18 t = str.maketrans("0123456789", "0101010101") while num: opr = input().split() if opr[0] == "+": multiset[int(opr[1].translate(t), 2)] += 1 elif opr[0] == "-": multiset[int(opr[1].translate(t), 2)] -= 1 elif opr[0] == "?": print(multiset[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMB...
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
t = int(input()) trantab = str.maketrans("0123456789", "0101010101") a = {} for i in range(t): string = input() oper, number = string.split() pattern = int(number.translate(trantab)) if oper == "+": a[pattern] = a.get(pattern, 0) + 1 elif oper == "-": a[pattern] -= 1 if not a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING VAR VAR NUMBER IF VAR...
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
t = int(input()) dc = [0] * 2**19 tt = str.maketrans("0123456789", "0101010101") for i in range(0, t): st = input().split() if st[0] == "+": dc[int(st[1].translate(tt), 2)] += 1 elif st[0] == "-": dc[int(st[1].translate(tt), 2)] -= 1 else: mu = int(st[1], 2) print(dc[mu])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR FUNC_C...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = map(int, input().split()) A = list(map(int, input().split())) for _ in range(q): d = int(input()) curr_max = max(A[i] for i in range(d)) min_of_maxes = curr_max for i in range(1, n - d + 1): a, b = A[i - 1], A[i + d - 1] if b > curr_max: curr_max = b if cur...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASS...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def naive_solve(arr, d): return min(max(arr[i : i + d]) for i in range(len(arr) - d + 1)) def max_last(start, stop, arr): i = start for j in range(start, stop): if arr[j] >= arr[i]: i = j return i def naive_solve2(arr, d): imax = max_last(0, d, arr) res = arr[imax] fo...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUM...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
stin = lambda: tuple(map(int, input().strip().split())) n, q = stin() lst = stin() def nearest_largers(): lfts = [-1] * n rgts = [n] * n st = list() for i, a in enumerate(lst): while st and lst[st[-1]] < a: rgts[st.pop()] = i if st: if lst[st[-1]] > a: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = map(int, input().strip().split(" ")) a = list(map(int, input().strip().split(" "))) for _ in range(q): d = int(input().strip()) maxs = max(a[0:d]) res = maxs for i in range(1, n - d + 1): if maxs == a[i - 1]: maxi = max(a[i : i + d]) else: maxi = max(maxs, ...
ASSIGN VAR 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def max_c(l): if not l: return None m = l[0] c = 1 for i in l[1:]: if i > m: m = i c = 1 elif i == m: c += 1 return m, c def min_max(n, d, l): m, c = max_c(l[:d]) min_max = m for i in range(n - d): if l[i] == m: ...
FUNC_DEF IF VAR RETURN NONE ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VA...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, m = map(int, input().split(" ")) numbers = list(map(int, input().split(" "))) for _ in range(m): q = int(input()) comparing_i = 0 answer = max(numbers[:q]) cur_max = answer for n in range(q, len(numbers)): if numbers[n] > cur_max: cur_max = numbers[n] temp = numbers[co...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR ...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def min_max(array, sub_length): curr_max = max(array[0:sub_length]) least_max = curr_max front = 0 end = sub_length while end < len(array): dequeued = array[front] enqueued = array[end] if dequeued == curr_max: curr_max = max(array[front + 1 : end + 1]) el...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN ...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = map(int, input().split()) sequence = list(map(int, input().split())) def debug(ds): for i in ds: print(i, end=" ") print() for _ in range(q): d = int(input()) max_current = max(sequence[0:d]) min_ans = max_current for left in range(1, len(sequence) - d + 1): removed = ...
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 FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR FOR VA...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = [int(arr) for arr in input().strip().split()] data = [int(data) for data in input().strip().split()] query = [] for i in range(q): query.append(int(input())) for d in query: max_index = [] min_nums = [] for i in range(n): while max_index != [] and data[i] > data[max_index[-1]]: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR LIST VAR VAR ...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def calMax(l, s, len): m = l[s] for i in range(s + 1, s + len): m = (m, l[i])[l[i] > m] return m [n, q] = list(map(int, input().rstrip().split())) nu = list(map(int, input().rstrip().split())) for i in range(q): d = int(input()) max = calMax(nu, 0, d) min = max mc = 1 for j in ...
FUNC_DEF ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN LIST 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 FOR VAR FUNC_CALL VAR VAR AS...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = map(int, input().split()) A = [int(_) for _ in input().split()] for _ in range(q): d = int(input()) current_max = max(A[:d]) current_min = current_max for i in range(1, n - d + 1): if A[i - 1] == current_max: if A[i + d - 1] != current_max: current_max = max(A[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR IF VAR...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
import sys num, n = map(int, input().split(" ")) lst = list(map(int, input().strip(" ").split())) for i in range(n): x = int(input()) temp = 0 count = 0 i = 0 minimum = 0 while i < num - x + 1: temp = 0 for j in range(i, x + i): if lst[j] > temp: temp...
IMPORT 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 FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR ...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
_, Q = map(int, input().split()) values = list(map(int, input().split())) for _ in range(Q): d = int(input()) cmin = cmax = max(values[i] for i in range(d)) for i in range(d, len(values)): if values[i - d] == cmax: cmax = max(values[i] for i in range(i - d + 1, i + 1)) else: ...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR AS...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = input().strip().split(" ") n, q = [int(n), int(q)] a = list(map(int, input().strip().split(" "))) def findMax(arr): val = arr[0] idx = 0 for i in range(len(arr)): if val < arr[i]: val = arr[i] idx = i return val, idx for q0 in range(q): d = int(input()) ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR A...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = [int(x) for x in input().strip().split()] arr = [int(x) for x in input().strip().split()] for _ in range(q): d = int(input().strip()) maxes = [] was_first = False for i in range(n - d + 1): if i == 0 or was_first == True: maxes.append(max(arr[i : i + d])) else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMB...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def decr_queue_append(max_queue, elem, i): while max_queue and max_queue[-1][0] < elem: max_queue.pop() max_queue.append((elem, i)) n, q = input().strip().split(" ") n, q = int(n), int(q) a = list(map(int, input().strip().split(" "))) for _ in range(q): Min = 1000000 d = int(input()) max_q...
FUNC_DEF WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBE...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] for i in range(q): a = int(input()) b = arr[:a] maxi = max(b) large = maxi mini = maxi front = 0 size = a for j in range(a, n): avail = (front + a) % a deq = b[front] b[avail] = arr[j...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def build_affected_area(arr): left = [0] * len(arr) for i in range(1, len(arr)): accu = 0 j = i - 1 while j >= 0: if arr[i] < arr[j]: break accu += left[j] + 1 j -= left[j] + 1 left[i] = accu right = [0] * len(arr) for i...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_C...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = [int(number) for number in input().split()] mylist = [int(number) for number in input().split()] for step in range(q): minmax = 0 d = int(input()) maxnumber = 0 for i in range(n): if mylist[i] >= maxnumber: maxnumber = mylist[i] elif i >= d: if mylist[i - d...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR BIN_OP VAR VAR VAR ASSI...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
import sys line = sys.stdin.readline().split(" ") n, q = int(line[0]), int(line[1]) line = sys.stdin.readline().split(" ") A = [int(a) for a in line] def findmax(D, m, n): m_val = D[m] m_idx = m for i in range(m + 1, n): if D[i] > m_val: m_val = D[i] m_idx = i return m...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def minmax(sequence, d): maxlist = [] start = 0 end = d if d == 1: return min(sequence) if d == len(sequence): return max(sequence) submax = max(sequence[start:end]) maxlist.append(submax) for _ in range(1, len(sequence) + 1 - d): start = start + 1 end = e...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR B...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def Sol(a, d): if d == len(a): return max(a) maxqueue = [0] for k in range(1, d): while maxqueue and a[k] > a[maxqueue[-1]]: maxqueue.pop() maxqueue.append(k) res = a[maxqueue[0]] for k in range(d, len(a)): if k - maxqueue[0] >= d: maxqueue.pop...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = input().split() n, q = [int(n), int(q)] l = list(map(int, input().split())) for q_i in range(q): d = int(input()) temp = [] ma = max(l[:d]) temp.append(ma) for i in range(1, len(l) - d + 1): if l[i - 1] == ma: ma = max(l[i : i + d]) temp.append(ma) elif...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def solve(a, q): min_ = 10**6 max_ = -1 ind = None upper = q lower = 0 while upper <= len(a): for i in range(lower, upper): temp = a[i] if temp > max_: ind = i + 1 max_ = temp if max_ < min_: min_ = max_ ...
FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = map(int, input().strip().split(" ")) arr = list(map(int, input().strip().split(" "))) for _ in range(q): d = int(input().strip()) i = 1 tempMax = max(arr[i - 1 : d]) minm = tempMax while i < len(arr) - d: skipped = arr[i] added = arr[i + d] if added >= tempMax: ...
ASSIGN VAR 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR WHI...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
n, q = [int(c) for c in input().strip().split(" ")] alist = [int(c) for c in input().strip().split(" ")] for _ in range(q): d = int(input().strip()) dq = [] amin = 10**6 + 1 for i in range(d): while dq and alist[i] > alist[dq[-1]]: dq.pop() dq.append(i) for i in range(d, ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
import sys class NotEvenAQueue: def __init__(self, size): self.data = [(-sys.maxsize) for _ in range(size)] self.size = size self.maximum = -sys.maxsize def put(self, d, i): if self.data[i % self.size] == self.maximum: self.data[i % self.size] = -sys.maxsize ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
N, Q = map(int, input().split()) A = list(map(int, input().split())) D = [] for q in range(Q): d = int(input()) min_num = 10**6 + 1 i = 0 max_idx = -1 while i <= N - d: if i > max_idx: max_num = -1 for j in range(i, i + d): if A[j] >= max_num: ...
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR IF VAR V...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
import sys def find_min(d, A): max_val = 0 for i in range(d): max_val = max(max_val, A[i]) min_of_max = max_val for i in range(d, len(A)): if A[i] > max_val: max_val = max(max_val, A[i]) elif A[i - d] == max_val: max_val = max(A[i - d + 1 : i + 1]) ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
str = input() li = str.split() n = int(li[0]) q = int(li[1]) str = input() arr = str.split() for i in range(n): arr[i] = int(arr[i]) li = [] for i in range(q): li.append(int(input())) mx = -4 for i in range(q): d = li[i] j = d mx = max(arr[:j]) mn = mx while j < n: if mx <= arr[j]: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL ...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
nq = input().split() n = int(nq[0]) q = int(nq[1]) arr = list(map(int, input().rstrip().split())) queries = [] for _ in range(q): queries_item = int(input()) queries.append(queries_item) i = 0 while i < len(queries): d = queries[i] max_ele = max(arr[0:d]) current_min = max_ele if d == 1: ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def query(n, d, a): minimum = maximum = max(a[:d]) for i in range(1, n - d + 1): if maximum <= a[i + d - 1]: maximum = a[i + d - 1] elif maximum == a[i - 1]: maximum = max(a[i : i + d]) minimum = min(maximum, minimum) return minimum n, q = input().split(...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR ...
Consider an $n$-integer sequence, $A=\{a_0,a_1,\ldots,a_{n-1}\}$. We perform a query on $\mbox{A}$ by using an integer, $\boldsymbol{d}$, to calculate the result of the following expression: $\underset{0\leq i\leq n-d}{\text{min}}\left(\underset{i\leq j\lt i+d}{\text{max}}a_j\right)$ In other words, if we let $m_i=\t...
def minOfMax(arr, d): if len(arr) == 0: return 10**5 elif d == 1: return min(arr) else: M = max(arr) idx = arr.index(M) if idx < d and len(arr) - idx - 1 < d: return M elif idx < d: return min(M, minOfMax(arr[idx + 1 :], d)) eli...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP NUMBER NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): dp = [[(0) for i in range(N + 1)] for j in range(N + 1)] for i in range(1, N + 1): for j in range(1, N + 1): dp[i][j] = ( dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + mat[i - 1][j - 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): dp = [[(0) for i in range(N + 1)] for j in range(N + 1)] ans = 0 for i, r in enumerate(dp): for j, _ in enumerate(r): if i > 0 and j > 0: dp[i][j] = ( mat[i - 1][j - 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VA...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, n, k): dp = [([0] * (n + 1)) for i in range(n + 1)] maxm = -10000000.0 for i in range(n + 1): for j in range(n + 1): if i == 0 or j == 0: dp[i][j] = 0 else: dp[i][j...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, k): if k > N: return stripSum = [[(0) for j in range(N)] for i in range(N)] for j in range(N): sum = 0 for i in range(k): sum += mat[i][j] stripSum[0][j] = sum for i in ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): psa = [[(0) for i in range(N)] for j in range(N)] psa[0][0] = mat[0][0] for i in range(1, N): psa[i][0] = psa[i - 1][0] + mat[i][0] for j in range(1, N): psa[0][j] = psa[0][j - 1] + mat[0][j] for i in ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
def calsum(mat, n): temp = [[(0) for i in range(n)] for j in range(n)] temp[0][0] = mat[0][0] for i in range(1, n): temp[0][i] = mat[0][i] + temp[0][i - 1] for i in range(1, n): temp[i][0] = temp[i - 1][0] + mat[i][0] for i in range(1, n): for j in range(1, n): te...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR N...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): for i in range(N): for j in range(N): if i != 0: mat[i][j] += mat[i - 1][j] for i in range(N): for j in range(N): if j != 0: mat[i][j] += mat[i][j - 1] ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NU...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): if K > N: return 0 tl = [] max_sum = 0 i = 0 while i < N: j = 0 while j < N - K + 1: x = i t = sum(mat[i][j : j + K]) tl.append(t) ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUM...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): maxsum = -5 * pow(10, 5) prefix_mat = [[(0) for i in range(N)] for j in range(N)] for i in range(N): for j in range(N): prefix_mat[i][j] = mat[i][j] for i in range(1, N): prefix_mat[i][0] += pr...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMB...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
import sys class Solution: def Maximum_Sum(self, mat, N, K1): mat1 = [] mat2 = [] for i in range(0, N): k = 0 p = [] for j in range(0, N): k += mat[i][j] p.append(k) mat1.append(p) for i in range(0, N)...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR ...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): for i, _ in enumerate(mat): for j, e in enumerate(mat[i]): if j > 0: mat[i][j] += mat[i][j - 1] if i > 0: mat[i][j] += mat[i - 1][j] if i > 0 and j > 0: ...
CLASS_DEF FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BI...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): for i in range(N): for j in range(1, N): mat[i][j] += mat[i][j - 1] for i in range(1, N): for j in range(N): mat[i][j] += mat[i - 1][j] res = mat[K - 1][K - 1] for i in range(K ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): cp = mat.copy() for i in range(N): for j in range(1, N): cp[i][j] += cp[i][j - 1] for j in range(N): for i in range(1, N): cp[i][j] += cp[i - 1][j] maxi = -1000000000000.0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
def calsum(mat, n): temp = [[(0) for i in range(n)] for j in range(n)] temp[0][0] = mat[0][0] for i in range(1, n): temp[0][i] = mat[0][i] + temp[0][i - 1] for i in range(1, n): temp[i][0] = temp[i - 1][0] + mat[i][0] for i in range(1, n): for j in range(1, n): te...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR N...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
def window(arr, l): m = 0 mx = -float("inf") s = 0 for i in range(l): m += arr[i] mx = max(mx, m) for i in range(l, len(arr)): m -= arr[s] m += arr[i] mx = max(mx, m) s += 1 return mx class Solution: def Maximum_Sum(self, mat, N, k): m =...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR A...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
import sys class Solution: def Maximum_Sum(self, mat, N, K): dp = [[(0) for i in range(N)] for i in range(N)] for i in range(N): for j in range(N): dp[i][j] = mat[i][j] if i > 0: dp[i][j] += dp[i - 1][j] if j > 0: ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR BIN_...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, n, k): prefix_sum = [[(0) for i in range(n)] for j in range(n)] res = [[float("-inf") for j in range(n)] for i in range(n)] max_sum = float("-inf") for i in range(n): for j in range(n): if i == 0 and j == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBE...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, n, k): def get(x, y): if x < 0 or y < 0: return 0 return mat[x][y] def calc(x, y): up = get(x - 1, y) left = get(x, y - 1) diag = get(x - 1, y - 1) return up + left -...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUN...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): max_sum = 0 s = [[(0) for i in range(n + 1)] for j in range(n + 1)] for i in range(n): for j in range(n): s[i + 1][j + 1] = mat[i][j] s[i + 1][j + 1] += s[i][j + 1] s[i + 1][j + 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR N...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): def f(temp, k, N): l = 0 h = 0 su = 0 maxi = -1000000000.0 while h < k: su += temp[h] h += 1 maxi = max(maxi, su) while h < N: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR F...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
import sys class Solution: def Maximum_Sum(self, mat, N, K): sum_arr = [[(0) for _ in range(N)] for _ in range(N)] for i in range(N): for j in range(N): if i > 0 and j > 0: sum_arr[i][j] = ( sum_arr[i - 1][j] ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMB...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, n, k): def get(x, y): if x < 0 or y < 0: return 0 return mat[x][y] def calc(x, y, d, m=1): return ( get(x, y) + get(x - d, y) * m + get(x, y - d) * m ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN VAR VAR VAR FUNC_DEF NUMBER RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): ans = -55664651 for i in range(N): for j in range(N): if j - 1 >= 0: mat[i][j] += mat[i][j - 1] if i - 1 >= 0: mat[i][j] += mat[i - 1][j] if j - 1 >=...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR N...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, mat, N, K): gmax = None l1 = [0] * (len(mat[0]) + 1) sumgrid = [] for i in range(len(mat) + 1): sumgrid.append(l1[:]) for i in range(len(mat)): sum1 = 0 for j in range(len(mat[i])): sum...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
class Solution: def Maximum_Sum(self, m, n, k): store = [[(0) for i in range(n)] for i in range(n - k + 1)] for j in range(n): s = 0 for i in range(k): s += m[i][j] store[0][j] = s for i in range(1, n - k + 1): s = s - ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR ...
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K. Note: Coins of the negative denomination are also possible at Geekland. Example 1: Input: N = 5, K = 3 mat[[]] = {1, 1, 1, 1, 1} {2, 2, 2, 2, 2} {3, 8, 6, 7, 3} ...
from itertools import * class Solution: def Maximum_Sum(self, a, n, t): dp = [[(0) for _ in range(n + 1)] for _ in range(n + 1)] res = float("-inf") for i, j in product(range(1, n + 1), range(1, n + 1)): dp[i][j] += a[i - 1][j - 1] dp[i][j] += dp[i - 1][j] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP ...