description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
t = int(input()) for _ in range(t): s = input() n = len(s) fa, fd, fs, fw = [0], [0], [0], [0] ba, bd, bs, bw = [0], [0], [0], [0] cur = [0, 0] for i in range(n): if s[i] == "A": cur[0] -= 1 elif s[i] == "D": cur[0] += 1 elif s[i] == "S": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER ASSIGN VAR VAR VAR VAR LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF ...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
import sys input = sys.stdin.readline for _ in range(int(input())): s = input() l, r, u, d, fl, fr, fu, fd, x, y = [0] * 10 for i in range(len(s)): if s[i] == "W": y += 1 if y > u: u = y fd = 0 fu = 1 if y == u: ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN V...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
from sys import setrecursionlimit as SRL from sys import stdin SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) t = int(input()) while t: s = str(rd().strip()) s = "0" + s + "0" g = s[::-1] posx = [0] * len(s) posy = [0] * len(s) l = [0] * len(s) r = [0] * len(s) ...
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
def Grid(S): xmin = [0, [-1]] xmax = [0, [-1]] ymin = [0, [-1]] ymax = [0, [-1]] y_s = 0 x_s = 0 n = len(S) for i in range(n): c = S[i] if c == "W": y_s += 1 elif c == "S": y_s -= 1 elif c == "A": x_s -= 1 else: ...
FUNC_DEF ASSIGN VAR LIST NUMBER LIST NUMBER ASSIGN VAR LIST NUMBER LIST NUMBER ASSIGN VAR LIST NUMBER LIST NUMBER ASSIGN VAR LIST NUMBER LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRI...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
import sys input = sys.stdin.readline for _ in range(int(input())): s = input().strip() ans = 10**15 suffix_change = [0] * len(s) mx_x = mn_x = mx_y = mn_y = 0 curr_x = curr_y = 0 for j in range(len(s) - 1, -1, -1): i = s[j] if i == "W": curr_y -= 1 elif i ==...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VA...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
for q in range(int(input())): data = input() mx = [0, 0, 0, 0] x = 0 y = 0 pos = [[-1], [-1], [-1], [-1]] for i in range(len(data)): d = data[i] if d == "W": y += 1 if y > mx[0]: mx[0] = y pos[0] = [] elif d == "S": ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR NUMBER...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
import sys zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x ...
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NU...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
T = int(input()) w = [[-1, 0], [1, 0], [0, 1], [0, -1]] mp = {"A": 0, "D": 1, "W": 2, "S": 3} while T > 0: T -= 1 s = input() l = [0] r = [0] u = [0] d = [0] for dir in s[::-1]: l.append(l[-1]) r.append(r[-1]) u.append(u[-1]) d.append(d[-1]) if dir == ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NU...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
t = int(input()) def possible(presum): l = len(presum) lastmax = -1 firstmin = l mx = max(presum) mn = min(presum) for i in range(l): if mx == presum[i]: lastmax = max(lastmax, i) if mn == presum[i]: firstmin = min(i, firstmin) if lastmax < firstmin:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER RETUR...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
from sys import setrecursionlimit as SRL from sys import stdin SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) n = int(input()) while n: s = map(str, rd().strip()) l = 0 pl = 1 r = 0 pr = 1 u = 0 pu = 1 b = 0 pb = 1 curx = 0 cury = 0 for x in ...
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
T = int(input()) for _ in range(T): s = input() cleft = cup = cdown = cright = 0 left = up = down = right = 0 fleft = lleft = 0 fright = lright = 0 fup = lup = 0 fdown = ldown = 0 x = y = 0 for i, c in enumerate(s): if c == "W": y -= 1 cup += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER VAR N...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
import sys def work(c, c1, s): maxlast, maxfirst, minlast, minfirst = 0, 0, 0, 0 max = 0 min = 0 y = 0 for i in range(len(s)): if s[i] == c: y += 1 elif s[i] == c1: y -= 1 if max < y: maxfirst, maxlast = i, i max = y e...
IMPORT FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VA...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
def main(): hh, vv, r = [0], [0], [] f = {"W": (vv, -1), "S": (vv, 1), "A": (hh, -1), "D": (hh, 1)}.get for _ in range(int(input())): del vv[1:], hh[1:], r[:] for l, d in map(f, input()): l.append(l[-1] + d) for l in (hh, vv): mi, ma = min(l), max(l) ...
FUNC_DEF ASSIGN VAR VAR VAR LIST NUMBER LIST NUMBER LIST ASSIGN VAR DICT STRING STRING STRING STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR VA...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
def lim(s): now = 0 up, down = 0, 0 for i in s: now += i up = max(up, now) down = min(down, now) return up, down def f(a): return a[0] - a[1] + 1 def upg(s): t = lim(s) up, down = t[0], t[1] arr = [1, 1] now = 0 for i in range(len(s) - 1): if n...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
def solve(): i = 0 j = 0 imax = imin = 0 jmax = jmin = 0 fjmin = ljmin = fjmax = ljmax = fimax = limax = fimin = limin = -1 for ind, e in enumerate(input()): if e == "W": i += 1 if i > imax: imax = i fimax = ind lima...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VA...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
n = int(input()) def area(width, height): return (width + 1) * (height + 1) def calcul(s1, c, s2): maxx, maxy, minx, miny = 0, 0, 0, 0 x, y = 0, 0 for k in range(len(s1)): if s1[k] == "W": y += 1 if s1[k] == "S": y -= 1 if s1[k] == "A": x -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
def read_int(): return int(input()) def read_ints(): return map(int, input().split(" ")) t = read_int() INF = int(10000000.0) for case_num in range(t): s = input() x = 0 y = 0 xlist = [0] ylist = [0] for c in s: if c == "W": y += 1 elif c == "S": ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR ST...
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
t = int(input()) for _ in range(t): ss = input() minx = 0 fminxpos = -1 lminxpos = -1 maxx = 0 fmaxxpos = -1 lmaxxpos = -1 miny = 0 fminypos = -1 lminypos = -1 maxy = 0 fmaxypos = -1 lmaxypos = -1 x = 0 y = 0 for i, s in enumerate(ss): if s == "W":...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUM...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = list(map(int, input().split())) mold = list(m) mres = [0] for ind in range(n): m = list(mold) for i in range(ind + 1, n): m[i] = min(m[i - 1], m[i]) for i in range(ind - 1, -1, -1): m[i] = min(m[i + 1], m[i]) if sum(m) >= sum(mres): mres = list(m) print(" ".j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = [int(x) for x in input().split()] nearestLeftSmaller = [(-1) for _ in range(n)] nearestRightSmaller = [(-1) for _ in range(n)] stack = [] for i in range(n): while stack and m[i] < m[stack[-1]]: nearestRightSmaller[stack[-1]] = i stack.pop() stack.append(i) stack = [] for i i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR A...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) l = list(map(int, input().split())) l2 = [(e, i) for i, e in enumerate(l)] l2.sort(reverse=True) if l2[-1][0] == l2[0][0]: print(" ".join(map(str, l))) exit(0) m = 0 for e in l2: if e[0] == l2[0][0]: m += 1 l4 = n * [0] for e in l2: l3 = n * [0] l3[e[1]] = e[0] for i in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FO...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
input() arr = list(map(int, input().split())) marr = [] for i, limit in enumerate(arr): cl = limit tarr = [] for l in reversed(arr[:i]): cl = min(cl, l) tarr.append(cl) tarr.reverse() cl = limit for l in arr[i:]: cl = min(cl, l) tarr.append(cl) marr.append((ta...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = tuple(map(int, input().split())) ma = list(m) best = 0 curlimit = m[0] for i in range(n): if m[i] > curlimit: ma[i] = curlimit if curlimit > m[i]: curlimit = m[i] best += curlimit besti = 0 bestseq = ma for i in range(n): ma = list(m) curlimit = m[i] curbest ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FU...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys n = int(input()) m = list(map(int, input().split())) INF = 10**9 + 1 left = [0] * n right = [0] * n stack = [] for i in range(n): while stack and stack[-1][1] > m[i]: stack.pop() if stack: j = stack[-1][0] left[i] = left[j] + (i - j) * m[i] else: left[i] = (i + 1)...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def loccentr(ci, razr): trazr = razr[:] sum, lm, rm, l, r, n = razr[ci], razr[ci], razr[ci], ci - 1, ci + 1, len(razr) while l >= 0: if trazr[l] < lm: lm = trazr[l] else: trazr[l] = lm sum += lm l -= 1 while r < n: if razr[r] < rm: ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) ml = list(map(int, input().split())) ans = 0 ansl = [] for i in range(n): ans1 = 0 ansl1 = [] top = ml[i] l = ml[i] for j in range(i, 0, -1): if l >= ml[j - 1]: l = ml[j - 1] ans1 += l ansl1 = [l] + ansl1 r = ml[i] for j in range(i, n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys input = sys.stdin.readline MOD = 1000000007 MOD2 = 998244353 ii = lambda: int(input().strip("\n")) si = lambda: input().strip("\n") dgl = lambda: list(map(int, input().strip("\n"))) f = lambda: map(int, input().strip("\n").split()) il = lambda: list(map(int, input().strip("\n").split())) ls = lambda: list(i...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
N = int(input()) B = list(map(int, input().split(" "))) C = B.copy() Ans = [] maxi = -1000000000.0 flag = 0 m = C[0] n = C[-1] for i in range(1, len(C)): if not C[i] <= C[i - 1]: flag = 1 break if flag == 0: print(*B) else: flag = 0 F = C[::-1] for i in range(1, len(F)): if n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) left = [(0) for i in range(n)] right = [(0) for i in range(n)] s = [-1] for i in range(n - 1, -1, -1): while s[-1] != -1 and a[s[-1]] > a[i]: s.pop() if s[-1] == -1: right[i] = a[i] * (n - i) else: right[i] = right[s[-1]] + a[i] * ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def rmin(): global a, n st = [0] r = [0] * (n + 2) for i in range(1, n + 2): while a[st[-1]] > a[i]: j = st.pop() r[j] = i st.append(i) return r def lmin(): global a, n st = [0] l = [0] * (n + 2) j = n for i in range(n + 1, 0, -1): ...
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) sp = list(map(int, input().split())) forw = [(0) for i in range(n)] backw = [(0) for i in range(n)] stack = [(0, -1, 0)] for i in range(n): while sp[i] <= stack[-1][0]: stack.pop() stack.append((sp[i], i, (i - stack[-1][1]) * sp[i] + stack[-1][2])) forw[i] = stack[-1][2] revsp = sp[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR V...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = list(map(int, input().split())) ans = 0 floor = -1 for j in range(n): m_l = m[0:j] m_r = m[j:n] for i in range(len(m_l) - 1, 0, -1): if m_l[i - 1] > m_l[i]: m_l[i - 1] = m_l[i] for i in range(len(m_r) - 1): if m_r[i] < m_r[i + 1]: m_r[i + 1] =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR AS...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) maxx = 0 for i in range(n): s = a[i] k = a[i] b = [0] * n b[i] = k for j in range(i + 1, n): if a[j] > k: b[j] = k else: b[j] = a[j] k = a[j] s += b[j] k = a[i] for j in range(i -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR A...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys def main(): import sys input = sys.stdin.buffer.readline N = int(input()) A = list(map(int, input().split())) inc = [0] * N st = [(0, 1)] S = 0 for i, a in enumerate(A): if a > st[-1][0]: S += a inc[i] = S st.append((a, 1)) ...
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = [0] + list(map(int, input().split())) + [0] left = [0] * (n + 2) right = [0] * (n + 2) left_min = [0] * (n + 2) right_min = [0] * (n + 2) ans = [0] * n st = [0] for i in range(1, n + 2): while a[st[-1]] > a[i]: right_min[st.pop()] = i st.append(i) for j in range(n, -1, -1): whil...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BI...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
t = int(input()) mlist = list(map(int, input().split())) mlist2 = [-1] mlist2.extend(mlist) mlist2.append(-1) mlist = mlist2.copy() peaks = [] for m in range(1, t + 1): if mlist[m] >= mlist[m - 1] and mlist[m] >= mlist[m + 1]: peaks.append(m) if len(peaks) == 1: for i in range(1, t + 1): print(m...
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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def inc(a): if not a: return [] b = [] x = a[-1] n = len(a) for i in range(n - 1, -1, -1): x = min(x, a[i]) b.append(x) return b[::-1] def dec(a): if not a: return [] b = [] x = a[0] n = len(a) for i in range(n): x = min(x, a[i]) ...
FUNC_DEF IF VAR RETURN LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF IF VAR RETURN LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) arr = list(map(int, input().split())) def snip(i): if i > 0 and i < n - 1 and arr[i - 1] >= arr[i] <= arr[i + 1]: return True if i == 0 or i == n - 1: return True return False mounts = [] i, j = 0, 0 for ind in range(n): if snip(ind): mounts.append([i, j]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER N...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = list(map(int, input().split())) assert len(m) == n st = [(m[0], 0)] left = [m[0]] + [0] * (n - 1) for i in range(1, len(m)): if m[i] >= m[i - 1]: left[i] = left[i - 1] + m[i] else: while st and st[-1][0] > m[i]: st.pop() if st: left[i] = left[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) l = list(map(int, input().split())) k = [] p = -1 for i in range(n): mn = l[i] tem = [0] * n tem[i] = l[i] c = l[i] for j in range(i - 1, -1, -1): mn = min(mn, l[j]) tem[j] = mn c += mn mn = l[i] for j in range(i + 1, n): mn = min(mn, l[j]) ...
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIG...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = list(map(int, input().split())) su = 0 si = [] for q in range(n): s = m[q] k = m[q] sia = [k] for i in range(q - 1, -1, -1): k = min(k, m[i]) s += k sia.append(k) sia = sia[::-1] k = m[q] for i in range(q + 1, n): k = min(k, m[i]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR V...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) mi = -1 for i in range(n): a1 = a[:] for j in range(i - 1, -1, -1): if a1[j] > a1[j + 1]: a1[j] = a1[j + 1] for j in range(i + 1, n): if a1[j] > a1[j - 1]: a1[j] = a1[j - 1] if sum(a1) > mi: mi = sum(a1)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) M = list(map(int, input().split())) maxsum = 0 for i in range(n): a = M.copy() Sum = a[i] for j in range(i + 1, n): a[j] = min(a[j], a[j - 1]) Sum += a[j] for j in range(i - 1, -1, -1): a[j] = min(a[j], a[j + 1]) Sum += a[j] if Sum > maxsum: m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys def makeMountain(M, i): m = M[i] curr = m left = [] for j in range(i - 1, -1, -1): curr = min(M[j], curr) left.append(curr) curr = m right = [] for j in range(i + 1, len(M)): curr = min(M[j], curr) right.append(curr) return left[::-1] + [m] + ...
IMPORT FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) def wa(a, n): incsum = [] decsum = [] st1 = [] thissum = 0 le = [0, 0] st1.append(le) for i in a: if i >= st1[-1][0]: st1.append([i, 1]) thissum += i else: c = 0 while i < s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER VAR VAR ASSIGN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) inf = int(2000000000.0) + 1 m = [-inf] + [int(x) for x in input().split()] + [-inf] r = [0] * (n + 2) st = [0] for i in range(1, n + 2): while m[st[-1]] > m[i]: r[st.pop()] = i st.append(i) l = [0] * (n + 2) st = [0] for i in range(n + 1, 0, -1): while m[st[-1]] > m[i]: l[st...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR VAR...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = [int(i) for i in input().split()] a = [0] + a + [0] sx = 0 k = 0 for i in range(1, n + 1): if a[i] > a[i - 1] and a[i] >= a[i + 1] or a[i] >= a[i - 1] and a[i] > a[i + 1]: s = a[i] mx = a[i] b = [s] for j in range(i - 1, 0, -1): mx = min(a[j], mx) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NU...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def solve(): n = int(input()) m = list(map(int, input().split())) answ = [0] * n answc = 0 for i in range(n): cur = [0] * n cur[i] = m[i] for j in range(i + 1, n): cur[j] = min(cur[j - 1], m[j]) for j in range(i - 1, -1, -1): cur[j] = min(cur[j...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL V...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def cal(l, n): lc = [0] for i in range(1, n, 1): if l[i] >= l[i - 1]: lc.append(lc[-1] + l[i - 1]) else: co = 0 j = i - 1 if j == 0: lc.append(lc[-1] + l[i]) else: while 1: if j < 0: ...
FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR WHILE NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ n = int(input()) m = list(map(int, input().split())) score = 0 lis = None for i in range(n): tmp = [0] * n tmp[i] = m[i] left = i - 1 while left >= 0: tmp[left] = min(m[left], tmp[left + 1]) left -= 1 right ...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUM...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) arr = list(map(int, input().split())) ind = [] maxx = max(arr) for i in range(n): if arr[i] == maxx: ind += [i] ans = [] maxx = 0 for x in range(n): t = arr[:] for i in range(x - 1, -1, -1): if t[i] > t[i + 1]: t[i] = t[i + 1] for i in range(x + 1, n): ...
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 ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) fans = 0 height = [0] * n ma = [] for m in range(n): minh = 0 thisans = 0 np = False height[m] = a[m] for i in range(m - 1, -1, -1): height[i] = height[i + 1] if height[i] > a[i]: height[i] = a[i] for i in range(m +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUM...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys reader = (line.rstrip() for line in sys.stdin) input = reader.__next__ n = int(input()) m = list(map(int, input().split())) minID = [([None] * n) for _ in range(n)] for i in range(n): minID[i][i] = i for shift in range(1, n): for L in range(n - shift): R = L + shift prev = minID[L][R...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR B...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = list(map(int, input().split())) left, right = [m[0]], [m[n - 1]] stack = [(m[0], 1)] for i in range(1, n): res = left[-1] num_tmp = 0 while stack and stack[-1][0] > m[i]: res -= stack[-1][0] * stack[-1][1] num_tmp += stack[-1][1] stack.pop() res += m[i] * (nu...
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 LIST VAR NUMBER LIST VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR VAR VAR BIN_OP VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys def get_vals(n, arr, rev): if rev: arr.reverse() st = [] vals = [(0) for i in range(n)] for i in range(n): while len(st) != 0 and arr[st[-1]] >= arr[i]: st.pop() vals[i] = ( (i + 1) * arr[i] if len(st) == 0 else (i - st[-1]) * arr[i] + vals[st...
IMPORT FUNC_DEF IF VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) next = [n] * n q = [] for i in range(n - 1, -1, -1): while q and a[q[-1]] > a[i]: q.pop() if q: next[i] = q[-1] q.append(i) prev = [-1] * n q = [] for i in range(n): while q and a[q[-1]] > a[i]: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR ASSIGN VAR VAR VAR NUMBER EXPR F...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
N = int(input()) L = [int(x) for x in input().split()] X = [] for i in L: X.append(i) All = 0 id = -1 for next in range(N): X = [] for i in L: X.append(i) for i in range(next - 1, -1, -1): if L[i] > X[i + 1]: X[i] = X[i + 1] for i in range(next + 1, N): if L[i] > ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) cap = list(map(int, input().split())) solution = [(0) for i in range(n)] best = 0 bestsum = 0 for i in range(0, n): max_height = cap[i] for j in range(i, n): max_height = min(max_height, cap[j]) solution[j] = max_height max_height = cap[i] for j in range(1, i + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
from sys import stdin, stdout input = stdin.readline n = int(input()) a = list(map(int, input().split())) dict = [] val = -1 i = 0 while i < n: v = a[i] j = i - 1 arr = [] pmin = v while j >= 0: v += min(a[j], pmin) arr.append(min(a[j], pmin)) pmin = min(pmin, min(a[j], pmin...
ASSIGN 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FU...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
N = int(input()) h = list(map(int, input().split(" "))) ans_max = 0 ans = [] for i in range(N): height = h[i] ans_t = [(0) for j in range(N)] ans_t[i] = h[i] pre = h[i] for j in range(i - 1, -1, -1): if h[j] < pre: pre = h[j] ans_t[j] = pre height += pre pre =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def exp(a, idx): n = len(a) b = [a[idx]] pr = a[idx] pl = a[idx] l, r = idx - 1, idx + 1 ansB = b[0] while l >= 0 or r < n: if r < n: R = min(a[r], pr) b.append(R) pr = R r += 1 ansB += R if l >= 0: L = m...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASS...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) ans = [] ma = 0 for j in range(n): an = [0] * n an[j] = a[j] for i in range(j - 1, -1, -1): if a[i] >= an[i + 1]: an[i] = an[i + 1] else: an[i] = a[i] for i in range(j + 1, n): if a[i] >= an[i - 1]: ...
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) maxs = [*map(int, input().split())] low_before = [float("inf") for _ in range(n)] biggest = 0 for p in range(n): low_after = float("inf") count = 0 curr_answer = [] new_p = maxs[p] if p - 1 >= 0 and new_p < low_before[p - 1]: for l in range(0, p): if new_p < low_...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) x = 0 y = 0 z = 0 b = list(a) c = list(a[::-1]) l = [] for _ in range(1, len(b)): if b[_] > b[_ - 1]: b[_] = b[_ - 1] l.append(sum(b)) for _ in range(1, len(c)): if c[_] > c[_ - 1]: c[_] = c[_ - 1] l.append(sum(c)) c = c[::-1] if l[0] >= l[1]:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = [] lis = input().split() for i in lis: m.append(int(i)) maxind = [0] maxx = m[0] for i in range(1, n): if m[i] > maxx: maxind = [i] maxx = m[i] elif m[i] == maxx: maxind.append(i) def find(indd): sum = m[indd] minn = m[indd] for i in range(indd - 1,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF AS...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import itertools import sys def find_floors(peak, ms): score = 0 current_height = ms[peak] for m in reversed(ms[:peak]): current_height = min(m, current_height) score += current_height current_height = ms[peak] for m in ms[peak:]: current_height = min(m, current_height) ...
IMPORT IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CAL...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) l = [int(x) for x in input().split()] maxi = [0, 0] for i in range(n): if i == 0: count = l[i] last = l[i] for j in range(1, n): if l[j] >= last: count += last else: count += l[j] last = l[j] elif i ...
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 FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSI...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
input() List = [int(x) for x in input().strip().split(" ")] res = 0 for i in range(len(List)): L = List[:] ans = L[i] j = i - 1 k = i + 1 while j >= 0: L[j] = min(L[j], L[j + 1]) ans += L[j] j -= 1 while k < len(L): L[k] = min(L[k - 1], L[k]) ans += L[k] ...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER V...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
t = int(input()) l = list(map(int, input().split())) ans = 0 m = 0 for i in range(t): s = 0 a = l[:] for j in range(i, 0, -1): if a[j] < a[j - 1]: a[j - 1] = a[j] s += a[j - 1] s += a[i] for k in range(i, t - 1): if a[k] < a[k + 1]: a[k + 1] = a[k] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR B...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def solve(ns): n = len(ns) res = [] maxv = -1 for i in range(n): ms = ns[:] pre = ms[i] for j in range(i + 1, n): ms[j] = min(ms[j], pre) pre = ms[j] pre = ms[i] for j in range(i - 1, -1, -1): ms[j] = min(ms[j], pre) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
inf = float("inf") n = int(input()) a = [*map(int, input().split())] for x in (0, 1): stack = [-1] s = [0] * n for i in range(n - 1, -1, -1): while a[i] < a[stack[-1]] and stack[-1] != -1: stack.pop() s[i] = ( (n - i) * a[i] if stack[-1] == -1 else s[stack[-1]] + a[i]...
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_C...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input("")) m = list(map(int, input("").split(" "))) v = set() for i in range(1, n - 1): if m[i] < m[i - 1]: if m[i] < m[i + 1]: v.add(i + 1) v.add(i - 1) ans = [0] * n ma = 0 if len(v) == 0: ans = m for e in v: c = [0] * n mc = 0 c[e] = m[e] mc += m[e] for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def main(): n = int(input()) M = list(map(int, input().split())) best_summa = 0 for i in range(n): L = [(0) for i in range(n)] summa = M[i] L[i] = M[i] for j in range(i - 1, -1, -1): summa += min(L[j + 1], M[j]) L[j] = min(L[j + 1], M[j]) f...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) can = [] maxi = 0 for i in range(n): tmp = a[i] now = a[i] tmp2 = [] tmp3 = [] for j in range(i + 1, n): now = min(now, a[j]) tmp += now tmp2.append(now) now = a[i] for j in ra...
IMPORT ASSIGN 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) d = [0] * n mx = -1 t = [0] * n for i in range(n): for k in range(n): t[k] = a[k] for j in range(i, n - 1): if t[j] < t[j + 1]: t[j + 1] = t[j] j = i while j > 0: if t[j] < t[j - 1]: t[j - 1] = t[j] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) nums = [int(x) for x in input().split()] res = [] for i in range(n): tmp = [0] * n tmp[i] = nums[i] t = nums[i] for j in range(i - 1, -1, -1): if nums[j] > t: tmp[j] = t else: t = nums[j] tmp[j] = t t = nums[i] for j in range(i + 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) l = list(map(int, input().strip().split())) left, right = [0] * n, [0] * n s = [0] left[0] = l[0] for i in range(1, n): while len(s) > 0 and l[s[-1]] > l[i]: s.pop() if len(s) == 0: left[i] = (i + 1) * l[i] else: left[i] = left[s[-1]] + (i - s[-1]) * l[i] s.appen...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys n = int(sys.stdin.readline().strip()) m = list(map(int, sys.stdin.readline().strip().split())) left = [] right = [] a = [] highest = 0 floors = 0 for i in range(n): if highest > m[i]: for j in range(i - 1, -1, -1): if a[j] <= m[i]: break floors -= a[j] - m...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR V...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys input = sys.stdin.readline n = int(input()) m = [int(i) for i in input().split()] copy = m[:] def maxsumchecker(arr): stack, lr = [], [0] * n for i in range(n): while stack and stack[-1][1] > m[i]: stack.pop() if stack: j = stack[-1][0] lr[i] = l...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR LIST BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def f(): n = int(input()) M = [int(s) for s in input().split()] def goLeftFrom(s): sum = 0 cur = M[s] for i in range(s - 1, -1, -1): cur = min(cur, M[i]) sum += cur return sum def goRightFrom(s): sum = 0 cur = M[s] for i i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def getlist(x, pivot): ans = [x[pivot]] for i in range(pivot - 1, -1, -1): ans = [min(ans[0], x[i])] + ans for i in range(pivot + 1, len(x)): ans += [min(ans[-1], x[i])] return ans n = int(input()) x = list(map(int, input().split())) ans = [] mx = -1 for i in range(n): l = getlist(...
FUNC_DEF ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
R = lambda: map(int, input().split()) n = int(input()) arr = list(R()) res = [0] * n for i in range(n): tmp = [0] * n tmp[i] = arr[i] for j in range(i - 1, -1, -1): tmp[j] = min(tmp[j + 1], arr[j]) for j in range(i + 1, n): tmp[j] = min(tmp[j - 1], arr[j]) if sum(res) < sum(tmp): ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = list(map(int, input().split())) a = m.copy() if m == sorted(m) or m == sorted(m)[::-1]: for i in range(n): print(m[i], end=" ") print() elif ( n % 2 == 0 and a[: n // 2] == sorted(a[: n // 2]) and a[n // 2 :] == sorted(a[n // 2 :])[::-1] ): for i in range(n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_C...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys input = sys.stdin.readline n = int(input()) ma = 0 ans = [(0) for i in range(n)] it = list(map(int, input().split())) for i in range(1, n): tot = 0 mi = 0 suff = [(0) for i in range(n)] suff[i] = it[i] for j in range(i - 1, -1, -1): suff[j] = it[j] if suff[j + 1] < suff[j...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FO...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) l = list(map(int, input().split())) max_floor = 0 l2 = [0] * n l1 = [0] * n for i in range(n): floor = 0 t = l[i] a = i - 1 while a >= 0: if l[a] <= t: t = l[a] l1[a] = t a -= 1 l1[i] = l[i] b = i + 1 t = l[i] while b < n: if t...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR ASSI...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) b1 = [0] * n for l in range(n): b = [0] * n i, j = l - 1, l + 1 c = a[l] b[l] = a[l] while i != -1 or j != n: if j != n and (i == -1 or a[j] > a[i]): b[j] = min(a[j], c) c = b[j] j += 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR IF...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) (n,) = I() l = I() le = [l[0]] r = [l[-1]] an = 0 d = idx = -1 k = [0] for i in range(1, n): if l[i - 1] <= l[i]: le.append(le[i - 1] + l[i]) else: while k and l[k[-1]] >= l[i]: k.pop() if k: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VA...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) arr = list(map(int, input().split())) maxsum = 0 maxsumAt = 0 for i in range(n): keep = arr[i] sum = keep for j in range(i - 1, -1, -1): keep = min(keep, arr[j]) sum += keep keep = arr[i] for k in range(i + 1, n): keep = min(keep, arr[k]) sum += keep ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys def solve(): input = sys.stdin.readline N = int(input()) M = [int(m) for m in input().split()] maxFloor = -1 Ans = [-1] * N for i in range(N): tAns = [(-1) for _ in range(N)] tAns[i] = M[i] totalFloor = M[i] for j in range(i - 1, -1, -1): ...
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) a = list(map(int, input().split())) b = [] c = [] for i in range(n): p = a[i] l = 0 b = [0] * n b[i] = a[i] l += p for j in range(i - 1, -1, -1): if p < a[j]: b[j] = p elif a[j] <= p: b[j] = a[j] p = a[j] p = a[i] for j...
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
from sys import stdin def solve(): n = int(stdin.readline()) m = list(map(int, stdin.readline().split())) msl = [-1] * n msp = [n] * n q = [] for i in range(n): while q and m[q[-1]] > m[i]: q.pop() if q: msl[i] = q[-1] q.append(i) q = [] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CAL...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys input = sys.stdin.readline print = sys.stdout.write n = int(input()) s = [int(i) for i in input().split()] def nearest_min(dir="l"): stack = [] arr = [-1] * n if dir == "l": x = range(n) elif dir == "r": x = range(n - 1, -1, -1) for i in x: top = -1 whil...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) arr = list(map(int, input().split())) back = [0] * n front = [0] * n back[n - 1] = arr[n - 1] stack = [n - 1] for i in range(n - 2, -1, -1): while stack and arr[i] < arr[stack[-1]]: stack.pop() if len(stack) == 0: back[i] = arr[i] * (n - i) else: back[i] = arr[i] * (...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE V...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) L = list(map(int, input().split())) ans = [0] * n sA = 0 for top in range(n): r = [] if top != 0: left = [] now = L[top] for i in range(top)[::-1]: now = min(now, L[i]) left.append(now) r += left[::-1] r.append(L[top]) if top != n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR E...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
numplots = int(input()) limfloors = list(map(int, input().split())) listsums = [] answers = {} minsofar = max(limfloors) + 1 indexminsofar = 0 for k in range(numplots): sum1 = 0 answerlist = [] max1 = limfloors[k] if max1 <= minsofar: minsofar = max1 indexminsofar = k answerlist += [...
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 ASSIGN VAR DICT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR V...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) m = list(map(int, input().split())) def is_sorted(test_list): flag = False if all(test_list[i] <= test_list[i + 1] for i in range(len(test_list) - 1)): flag = True if not flag and all( test_list[i] >= test_list[i + 1] for i in range(len(test_list) - 1) ): flag ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
import sys reader = (line.rstrip() for line in sys.stdin) input = reader.__next__ n = int(input()) m = list(map(int, input().split())) smaller_left = [-1] * n stack = [] for i in reversed(range(n)): val = m[i] while stack and val < stack[-1][0]: _, j = stack.pop() smaller_left[j] = i stack....
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUN...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
def cal(i): a = [x for x in m] t = a[i] for j in range(i - 1, -1, -1): a[j] = min(t, a[j]) t = a[j] t = a[i] for j in range(i + 1, n): a[j] = min(t, a[j]) t = a[j] return a n = int(input()) m = [int(x) for x in input().split()] res = cal(0) for i in range(1, n):...
FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL ...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
N = int(input()) m = list(map(int, input().split())) ans = 0 def sol(k): ret = l = r = m[k] for i in range(k + 1, N): if m[i] < r: r = m[i] ret += r for i in range(k - 1, -1, -1): if m[i] < l: l = m[i] ret += l return ret ans_idx = -1 for i in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIG...
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the comp...
n = int(input()) al = [0] * n ansl = [0] * n ml = list(map(int, input().split())) mx = 0 for i in range(n): al[i] = ml[i] j = i - 1 while j >= 0: al[j] = min(al[j + 1], ml[j]) j = j - 1 j = i + 1 while j < n: al[j] = min(al[j - 1], ml[j]) j = j + 1 cans = 0 j ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ...