description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
arr = [int(x) for x in input().split()]
if n == 1:
print(arr[0])
else:
allpos = True
allneg = True
for i in arr:
if i > 0:
allneg = False
elif i < 0:
allpos = False
if allpos:
print(sum(arr) - min(arr) * 2)
elif allneg:
pri... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL ... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
l = list(map(int, input().split()))
mx = max(l)
mn = min(l)
lx = l.index(mx)
lm = l.index(mn)
if lx == lm and n != 1:
lm = l.index(mn, lx + 1)
s = sum([abs(x) for i, x in enumerate(l) if i != lx and i != lm])
if n == 1:
print(mn)
exit()
if n == 2:
print(mx - mn)
exit()
print(s + mx ... | 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = input()
ls = [int(x) for x in input().split()]
if n == "1":
print(ls[0])
else:
ls = sorted(ls)
start = ls[0]
end = ls[-1]
mid = ls[1:-1]
res = end - start + sum([abs(x) for x in mid])
print(res) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
a = [int(el) for el in input().split()]
a.sort()
kotr = 0
k0 = 0
for i in a:
if i < 0:
kotr += 1
elif i == 0:
k0 += 1
if n == 1:
print(a[0])
raise SystemExit
if n == 2:
print(abs(a[0] - a[1]))
raise SystemExit
if kotr == n:
out = a[n - 1]
for i in range(n... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR N... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
exit()
ans = sum(map(abs, a))
pos = sum(x > 0 for x in a)
neg = n - pos
if pos == n:
ans -= min(a) * 2
if neg == n:
ans += max(a) * 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VA... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | import sys
n = int(input())
line = list(map(int, input().split()))
if n == 1:
print(line[0])
sys.exit(0)
sum = 0
minNum = 10**9
maxNum = -(10**9)
for i in line:
if minNum > i:
minNum = i
if maxNum < i:
maxNum = i
sum += abs(i)
if minNum * maxNum < 0:
print(sum)
elif minNum < 0:
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
arr = list(map(int, input().split()))
absArr = list(map(abs, arr))
positiveCount, negativeCount = 0, 0
for num in arr:
if num > 0:
positiveCount += 1
elif num < 0:
negativeCount += 1
if n == 1:
print(arr[0])
elif positiveCount == n or negativeCount == n:
print(sum(absArr... | 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 FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CAL... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
a = list(map(int, input().split()))
a.sort()
if n != 1:
total = a[0]
for i in range(1, n - 1):
if total < 0 and a[i] < 0:
total += a[i]
else:
total = min(total - a[i], a[i] - total)
print(max(total - a[n - 1], a[n - 1] - total))
else:
print(a[0]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUN... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
p = 0
m = []
for s in input().split():
x = int(s)
p += abs(x)
m.append(x)
m.sort()
if len(m) > 2:
m.pop(1)
if n == 1:
print(m[0])
elif m[0] > 0:
print(p - 2 * m[0])
elif m[1] < 0:
print(p + 2 * m[1])
else:
print(p) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER EXP... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
else:
p, e = 0, 0
for i in range(n):
if a[i] >= 0:
p = p + 1
else:
e = e + 1
if p > 0 and e > 0:
ans = 0
for i in range(n):
ans = ans + abs(a[i])
print(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUM... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | import sys
def input():
return sys.stdin.readline().rstrip()
def slv():
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
return
elif all(a[i] <= 0 for i in range(n)):
minabs = 1 << 128
s = 0
for v in a:
minabs = min(m... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | import sys
n = int(input())
l = list(map(int, input().split()))
f = 0
f1 = 0
ans = 0
if n == 1:
print(l[0])
sys.exit()
for i in range(n):
if l[i] <= 0:
f = 1
ans += abs(l[i])
else:
f1 = 1
if f == 1:
ans = sum(l) + 2 * ans
if f1 == 0:
ans -= abs(max(l) * 2)
pr... | 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR AS... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | def f(a):
if len(a) == 1:
return a[0]
pos = 0
neg = 0
ans = 0
a = sorted(a)
for i in a[1 : len(a) - 1]:
ans += abs(i)
ans -= a[0]
ans += a[-1]
return ans
s = input()
a = list(map(int, input().strip().split()))
print(f(a)) | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | import sys
n = int(input())
l = list(map(int, sys.stdin.readline().split()))
if len(l) == 1:
exit(print(l[0]))
if all(i > 0 for i in l):
print(sum(l) - 2 * min(l))
elif all(i < 0 for i in l):
print(abs(sum(l)) + 2 * max(l))
else:
s = 0
for i in l:
s = s + abs(i)
print(s) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NU... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | from sys import setrecursionlimit, stdin, stdout
n = int(input())
a = sorted([int(i) for i in input().split()])
minus = plus = 0
for x in a:
if x <= 0:
minus += 1
else:
plus += 1
if n == 1:
print(a[0])
elif plus > 0 and minus > 0:
a = [abs(x) for x in a]
print(sum(a))
elif plus == 0... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR V... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | N = int(input())
slimes = [int(s) for s in input().split()]
all_same = True
for i in range(N - 1):
if (slimes[i] > 0) != (slimes[i + 1] > 0):
all_same = False
if N == 1:
print(slimes[0])
else:
slimes = [abs(x) for x in slimes]
print(sum(slimes) - (2 * min(slimes) if all_same else 0)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR B... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
mx = max(a)
mn = min(a)
s = 0
if n == 1:
print(a[0])
exit()
for i in range(1, n - 1):
s += abs(a[i])
print(s + mx - mn) | 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
exit()
dp = [[[0, 0], [0, 0]] for i in range(n + 1)]
dp[1][0][1] = -a[0]
dp[1][1][0] = a[0]
dp[1][1][1] = -(10**18)
for i in range(2, n + 1):
dp[i][0][1] = -a[i - 1] + dp[i - 1][0][1]
dp[i][1][0] = a[i - 1] + dp[i - 1][1][0]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
arr = list(map(int, input().strip().split()))
k = min(arr)
h = max(arr)
s = 0
for i in arr:
if i >= 0:
s += i
else:
s -= i
if n == 1:
print(arr[0])
elif k < 0 and h >= 0:
print(s)
elif k >= 0:
print(s - 2 * k)
else:
print(s + 2 * h) | 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VA... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
if n == 1:
a = input()
print(a)
else:
a = list(map(int, input().split()))
b = [abs(i) for i in a]
if min(a) * max(a) > 0:
print(sum(b) - 2 * min(b))
else:
print(sum(b)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
exit()
a.sort()
if a[0] < 0 and a[n - 1] >= 0:
suma = 0
for i in range(n):
suma += abs(a[i])
print(suma)
exit()
suma = 0
mina = 9999999999
for i in range(n):
suma += abs(a[i])
mina = min(mina, abs(a[i]))
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CA... |
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.
Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).
When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears... | n = int(input())
arr = list(map(int, input().split()))
if n == 1:
print(arr[0])
else:
brr = [abs(i) for i in arr]
fl = False
for i in range(n - 1):
if arr[i] * arr[i + 1] < 0:
fl = True
if not fl:
print(sum(brr) - 2 * min(brr))
else:
print(sum(brr)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXP... |
You are given a permutation p consisting of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once).
Let's call an array a bipartite if the following undirected graph is bipartite:
* the graph consists of n vertices;
* two vertices i and j are connected by an edge i... | import sys
I = lambda: [*map(int, sys.stdin.readline().split())]
N = 1 << 20
P = print
for _ in [0] * I()[0]:
(n,) = I()
p = I()
D = [[-N, -N, N, N]]
for i in range(1, n):
a, b, c, d = [N] * 4
w, x, y, z = D[i - 1]
q, r = p[i], p[i - 1]
if q > r:
a = w
... | IMPORT ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST VAR N... |
You are given a permutation p consisting of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once).
Let's call an array a bipartite if the following undirected graph is bipartite:
* the graph consists of n vertices;
* two vertices i and j are connected by an edge i... | import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
I = lambda: [*map(int, inpu().split())]
big = 1 << 20
(t,) = I()
for _ in range(t):
(n,) = I()
p = I()
dp = [[-big, -big, big, big]]
for i in range(1, n):
a, b, c, d = big, big, big, big
y = dp[i - 1][0]
if p[i] > p[i ... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR... |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
sortedPair = sorted(Parr, key=lambda x: x.b)
result = 0
prevEnd = -float("inf")
for part in sortedPair:
if part.a > prevEnd:
result += 1
prevEnd = part.b
return result | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Pair(object):
def __init__(self, a, b):
self.a = a
self.b = b
class Solution:
def maxChainLen(self, Parr, n):
Parr.sort(key=lambda x: x.b)
ans = 1
i, j = 0, 1
while j < n:
if Parr[i].b < Parr[j].a:
ans += 1
i =... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
P = sorted(Parr, key=lambda x: x.b)
start = P[0].b
ans = 1
for i in range(1, n):
if start < P[i].a:
ans += 1
start = P[i].b
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
lst = []
for i in Parr:
lst.append([i.a, i.b])
lst.sort(key=lambda x: x[1])
c = 1
j = 0
for i in range(1, len(lst)):
if lst[j][1] < lst[i][0]:
j = i
c = c + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
Parr.sort(key=lambda x: x.b)
result = 1
end = Parr[0].b
for pair in Parr:
if pair.a > end:
result += 1
end = pair.b
return result | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
Parr.sort(key=lambda x: x.b)
count = 1
i = 0
j = 1
while j < n:
if Parr[i].b < Parr[j].a:
count += 1
i = j
j += 1
return count | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
arr = [(Parr[i].a, Parr[i].b) for i in range(n)]
arr.sort(key=lambda x: x[1])
time = -1
count = 0
for start, end in arr:
if time < start:
count += 1
time = end
return count | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
def abc(x):
return x[1]
ans = [[i.a, i.b] for i in Parr]
ans = sorted(ans, key=abc)
c = 1
i = 1
x = ans[0][1]
while i < n:
if ans[i][0] > x:
c += 1
x = a... | CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
arr = [(x.a, x.b) for x in Parr]
arr.sort(key=lambda x: x[1])
curr_end = arr[0][1]
chain_len = 1
for start, end in arr[1:]:
if start > curr_end:
curr_end = end
chain_len += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, arr, n):
p = []
for i in arr:
p.append([i.a, i.b])
p.sort(key=lambda x: x[1])
ans = 0
prev = float("-inf")
for i in p:
if i[0] > prev:
ans += 1
prev = i[1]
return an... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
sorted_pair_list = sorted(Parr, key=lambda x: x.a)
final_list = []
if sorted_pair_list:
final_list.append(sorted_pair_list[0])
if len(sorted_pair_list) > 1:
for idx in range(1, len(sorted_pair_list)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST IF VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VA... |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
Parr.sort(key=lambda x: x.b)
count = 1
prev = Parr[0].b
for i in range(1, n):
if prev < Parr[i].a:
prev = Parr[i].b
count += 1
return count | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
arr = []
for i in range(n):
arr.append((Parr[i].a, Parr[i].b, i))
arr.sort(key=lambda x: x[1])
end_time = 0
meeting = 0
for x in arr:
if end_time == 0 or end_time < x[0]:
end_time... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
arr = []
for i in Parr:
arr.append((i.a, i.b))
arr.sort(key=lambda x: x[1])
currMeet = 0
nextMeet = 1
ans = 1
while nextMeet < n:
if arr[currMeet][1] < arr[nextMeet][0]:
a... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
a1 = 0
b1 = 0
a2 = 0
b2 = 0
c = 1
Parr.sort(key=lambda x: x.b)
b1 = Parr[0].b
for i in range(len(Parr) - 1):
if b1 < Parr[i + 1].a:
b1 = Parr[i + 1].b
c = c + ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, parr, n):
l = []
for i in range(n):
l.append([parr[i].b, parr[i].a])
l.sort()
ans = 1
val = l[0][0]
for i in range(1, n):
if l[i][1] > val:
val = l[i][0]
ans = ans + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | def bs(st, a):
l, h = 0, len(st) - 1
ind = -1
while l <= h:
mid = (l + h) // 2
if st[mid] > a:
ind = mid
h = mid - 1
else:
l = mid + 1
return ind
class Solution:
def maxChainLen(self, arr, n):
arr.sort(key=lambda x: x.b)
... | FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBE... |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Pair(object):
def __init__(self, a, b):
self.a = a
self.b = b
class Solution:
def maxChainLen(self, Parr, n):
Parr.sort(key=lambda x: x.b)
ans = 1
for i in range(1, n):
if Parr[0].b < Parr[i].a:
ans += 1
Parr[0].b = Pa... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
l = []
for i in range(n):
l.append([Parr[i].a, Parr[i].b])
l.sort()
dp = [-1] * n
def fun(i):
if i == n:
return 0
if dp[i] != -1:
return dp[i]
mx ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSI... |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def bisectleft(self, arr, s, e, val):
while s < e:
mid = (s + e) // 2
if arr[mid].b > val:
e = mid
else:
s = mid + 1
return s
def maxChainLen(self, Parr, n):
Parr.sort(key=lambda x: x.b)
length ... | CLASS_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, a, n):
l = []
for i in range(0, n):
l.append([a[i].a, a[i].b])
l.sort(key=lambda x: x[1])
count = 0
prev = -1
for i in range(len(l)):
if prev == -1:
count = count + 1
prev =... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_... |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, arr, n):
dp = [(1) for i in range(n)]
arr.sort(key=lambda x: x.b)
ans = 0
mi = -1
for i in range(len(arr)):
if arr[i].a > mi:
mi = arr[i].b
ans += 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
parr = sorted(Parr, key=lambda x: x.b)
dp = [(1) for i in range(n + 1)]
prev = parr[0].b
ans = 1
for i in range(1, n):
a, b = parr[i].a, parr[i].b
if a > prev:
dp[i] = dp[i - 1] + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETU... |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
if n == 0:
return 0
def func(obj):
return obj.b
Parr.sort(key=func)
result = []
result.append(Parr[0])
curr = Parr[0]
for i in range(1, n):
if Parr[i].a > curr.b:
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FUNC_DEF RETURN VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | def solver(pairs, i, n, dct):
if i in dct:
return dct[i]
sm = 0
for j in range(i + 1, n):
if pairs[j][0] > pairs[i][1]:
sm = max(sm, solver(pairs, j, n, dct) + 1)
else:
sm = max(sm, solver(pairs, j, n, dct))
dct[i] = sm
return sm
class Solution:
... | FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VA... |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
data = [[el.a, el.b] for el in Parr]
data.sort(key=lambda x: x[1])
ans = 1
prev = data[0][1]
for i in range(1, n):
if data[i][0] > prev:
prev = data[i][1]
ans += 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
count = 1
def func(x):
return x.b
arr = sorted(Parr, key=func)
curr = arr[0]
j = 0
for i in range(len(arr) - 1):
if curr.b < arr[i + 1].a:
count += 1
curr = arr[... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, parr, n):
ss = []
for i in range(n):
ans = [parr[i].a, parr[i].b]
ss.append(ans)
ss.sort(key=lambda x: x[1])
li = []
for i in ss:
if li and li[-1][1] < i[0]:
li.append(i)
if... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
def SecondElement(Pair):
return Pair.b
Parr.sort(key=SecondElement)
max_length = 1
curr_length = 1
first = Parr[0].a
second = Parr[0].b
for i in range(1, len(Parr)):
if Parr[i].a > seco... | CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR EXPR FUNC_CALL VAR VAR 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 VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, parr, n):
ans = list()
parr = sorted(parr, key=lambda x: x.b)
arr = list()
for i in range(n):
arr.append([parr[i].a, parr[i].b])
ans.append(arr[0])
for i in range(1, n):
if ans[-1][1] < arr[i][0]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
x = [(-1) for i in range(n)]
for i in range(n):
x[i] = [Parr[i].a, Parr[i].b]
x = sorted(x, key=lambda sub: sub[1])
f = 1
i = 0
j = 1
while j < n:
if x[i][1] < x[j][0]:
f ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
arr = []
for i in range(n):
arr.append([Parr[i].a, Parr[i].b])
new_arr = sorted(arr, key=lambda x: x[0], reverse=True)
count = 1
c = new_arr[0][0]
for i in range(1, n):
if c > new_arr[i][1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR |
You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. You have to find the longest chain which can be formed from the given set of pairs.
Example 1:
Input:
N = 5
... | class Solution:
def maxChainLen(self, Parr, n):
Parr.sort(key=lambda x: (x.a, x.b))
ans = [Parr[0]]
for p in Parr:
if p.a > ans[-1].b:
ans.append(p)
elif p.b < ans[-1].b:
ans[-1] = p
return len(ans) | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR RETURN FUNC_CALL VAR VAR |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | n, m = map(int, input().split())
dishes = [(0) for _ in range(n + m)]
father = [(-1) for _ in range(n + m)]
e_out = dict()
v_in = [(0) for _ in range(n + m)]
def get_father(n):
if father[n] == -1:
return n
else:
father[n] = get_father(father[n])
return father[n]
compare_matrix = []
f... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | n, m = (int(t) for t in input().split(" "))
def direction(c):
if c == "=":
return 0
if c == ">":
return 1
return -1
mx = [[direction(c) for c in input()] for _ in range(n)]
index = 0
class DSet(object):
def __init__(self, value):
nonlocal index
self.values = set([v... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR VAR VAR NUMBER ASS... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | import time
debug = False
n1, m2 = list(map(int, input().split()))
tests = []
for i in range(n1):
tests.append(list(input()))
if debug:
print(tests)
begin = time.time()
if debug:
print("---")
marks1 = []
result1 = []
for i in range(n1):
marks1.append([i, 0.0])
result1.append(0)
marks2 = []
result2 ... | IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CA... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | import sys
r, c = map(int, input().split())
m = []
p = [i for i in range(0, r + c)]
tree = [[] for i in range(0, r + c)]
for i in range(0, r):
s = input().split("\n")[0]
m.append(list(s))
def find(i):
if p[i] == i:
return i
par = find(p[i])
p[i] = par
return p[i]
def join(i, j):
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF I... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | def prov(mass, now):
check = True
for i in range(n):
for k in range(m):
if now[i][k] == ">" and mass[i] <= mass[n + k]:
check = False
break
elif now[i][k] == "<" and mass[i] >= mass[n + k]:
check = False
break
... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR RETURN VAR FUNC_DEF ASSIGN VAR NU... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | class mergefind:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
def find(self, a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | n, m = list(map(int, input().split()))
g = []
for i in range(n):
g += [input()]
memo = {}
def dfs(u):
if u not in memo:
memo[u] = res = 1
if u < n:
for v in range(m):
if g[u][v] == ">":
res = max(res, dfs(n + v) + 1)
for v in range(m)... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VA... |
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the d... | import sys
sys.setrecursionlimit(2000)
def dfs1(v, mintime):
localtime = mintime
vis1[v] = 1
for v2 in range(m):
if a[v][v2] == ">":
if not vis2[v2]:
dfs2(v2, 1)
localtime = max(localtime, time2[v2] + 1)
for v2 in range(m):
if a[v][v2] == "=":
... | IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def max_subarray(numbers):
best_sum = 0
current_sum = 0
for x in numbers:
current_sum = max(0, current_sum + x)
best_sum = max(best_sum, current_sum)
return best_sum
t = int(input())
for _ in range(t):
l = int(input())
a = list(map(int, input().split()))
z = []
y = []
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR A... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for I in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
else:
prev = 0
for i, num in enumerate(a):
if i % 2 == 0:
prev += num
resulting = [0]
resulting.append(max(0, a[1] - a[0]))
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CAL... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | t = int(input())
for _ in range(t):
n = int(input())
lst = list(map(int, input().split()))
e_sum = 0
for i in range(0, n, 2):
e_sum += lst[i]
mx1 = 0
mmx1 = 0
for i in range(0, n - 1, 2):
tmp = lst[i + 1] - lst[i]
mx1 = max(mx1 + tmp, 0)
if mmx1 < mx1:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | t = int(input())
buf = []
for _ in range(t):
n = int(input())
aaa = list(map(int, input().split()))
dp = [0, 0, 0, 0]
for i, a in enumerate(aaa):
if i % 2 == 0:
dp[3] = max(dp[1], dp[3]) + a
dp[1] = max(dp[0], dp[1])
dp[0] += a
else:
dp[3] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_C... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
temp, mx, ans = 0, 0, 0
for i in range(0, n, 2):
ans += l[i]
for i in range(0, n - 1, 2):
temp += l[i + 1] - l[i]
mx = max(mx, temp)
if temp < 0:
temp = 0
temp = 0
f... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def solve(nums):
best = 0
cur = 0
for x in nums:
cur += x
best = max(cur, best)
cur = max(cur, 0)
return best
for _ in range(int(input())):
input()
seq = list(map(int, input().split()))
base = 0
diff1 = []
diff2 = []
for x in range(0, len(seq), 2):
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIG... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | w = int(input())
for _ in range(w):
n = int(input())
A = list(map(int, input().split(" ")))
e, o = 0, 1
L, R = [-1, -1]
MAX = 0
total = 0
l, r = 0, 1
while e < n and o < n:
diff = A[e + 1] - A[e]
total += diff
if total < 0:
total = 0
e += 2... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def lagade_kadane(A):
max_end = 0
max_far = -1e18
for i in range(len(A)):
max_end += A[i]
if max_end < 0:
max_end = 0
if max_far < max_end:
max_far = max_end
return max_far
for _ in range(int(input())):
n = int(input())
A = list(map(int, input().... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VA... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
se = 0
for i in range(n):
if i % 2 == 0:
se += l[i]
cs = 0
ans = se
for i in range(1, n, 2):
cs += l[i] - l[i - 1]
if cs < 0:
cs = 0
else:
an... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
s = 0
for i in range(len(l)):
if i % 2 == 0:
s = s + l[i]
o, e = 0, 0
r = 0
for i in range(1, n, 2):
o = o + l[i]
e = e + l[i - 1]
if o > e:
r = max(r, o... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER F... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | t = int(input())
for i in range(t):
n = int(input())
b = list(map(int, input().split()))
if n == 1:
print(b[0])
elif n == 2:
print(max(b[0], b[1]))
else:
j = 0
res = 0
while j < n:
if j % 2 == 0:
res += b[j]
j += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def kadane(arr):
globalsum = float("-inf")
currentsum = 0
for i in arr:
currentsum += i
currentsum = max(currentsum, i)
if currentsum > globalsum:
globalsum = currentsum
return globalsum
t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for _ in range(0, int(input())):
n = int(input())
a = list(map(int, input().split()))
even = []
i = 0
while True:
if i + 1 < n:
even.append(a[i + 1] - a[i])
else:
break
i += 2
maxe = 0
sum = 0
for i in even:
sum += i
if sum ... | FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL 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 WHILE NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = 0
s = a[0]
d = 0
m = 0
for i in range(1, n, 2):
b += a[i] - a[i - 1]
if b - m > d:
d = b - m
if b < m:
m = b
b = m = e = 0
for i in range(2, n, 2):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
f = []
s = []
num = 0
if n < 3:
print(max(arr))
continue
for i in range(n):
if not i & 1:
num += arr[i]
for i in range(n - 1):
if not i & 1:
f.appe... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 LIST ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR FOR ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | import sys
input = sys.stdin.readline
inp, ip = lambda: int(input()), lambda: [int(w) for w in input().split()]
for _ in range(inp()):
n = inp()
x = ip()
maxdf = 0
diff = 0
i = 0
while i + 1 < n:
diff += x[i + 1] - x[i]
if diff < 0:
diff = 0
else:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def contiguous_subset(arr):
cur = 0
best = 0
for i in arr:
cur = max(cur + i, 0)
best = max(cur, best)
return best
def best_evens(arr):
if len(arr) == 1:
return arr[0]
left_flip = [(arr[i - 1] - arr[i]) for i in range(2, len(arr), 2)]
right_flip = [(arr[i + 1] - arr... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP V... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def maxSubArraySum(a, size):
max_so_far = -100000000
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | inp = lambda: map(int, input().split(" "))
(t,) = inp()
for _ in range(t):
(n,) = inp()
arr = list(inp())
s_e = 0
max_diff = [0, 0]
curr_sum = [0, 0]
for i in range(0, n, 2):
s_e += arr[i]
if i + 1 < n:
curr_sum[0] += arr[i + 1] - arr[i]
curr_sum[0] = max(... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR IF BIN_OP VAR N... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def main():
for i in range(int(input())):
solve()
def solve():
n = int(input())
a = list(map(int, input().split()))
mseg = 0
diffs = []
for i in range(1, n, 2):
diffs.append(a[i] - a[i - 1])
m1 = 0
maxAtP1 = 0
for i in diffs:
maxAtP1 = max(maxAtP1 + i, i, 0)... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMB... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | from sys import stdin, stdout
def maxSubArraySum(a):
size = len(a)
if size == 0:
return 0
max_so_far = a[0]
curr_max = a[0]
for i in range(1, size):
curr_max = max(a[i], curr_max + a[i])
max_so_far = max(max_so_far, curr_max)
return max_so_far
for _ in range(int(stdin... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_C... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | from sys import stdin
inp = lambda: stdin.readline().strip()
t = int(inp())
for _ in range(t):
n = int(inp())
a = [int(x) for x in inp().split()]
even = 0
for i in range(0, n, 2):
even += a[i]
x = [0] * n
p = [0] * n
for i in range(0, n - 1, 2):
x[i // 2] = a[i + 1] - a[i]
... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LI... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | import sys
def solve(arr):
if len(arr) <= 1:
return 0 if len(arr) == 0 else arr[0]
max_sum = 0
l = len(arr)
evens = arr[0::2]
odds = arr[1::2]
if l % 2 == 1:
odds.append(0)
hl = len(evens)
even_cum = [arr[0]] * hl
odd_cum = [arr[1]] * hl
for ei in range(1, hl):
... | IMPORT FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def maxsum(a):
if len(a) == 0:
return 0
ans = a[0]
notmaxisum = 0
maxisum = 0
for i in range(len(a)):
notmaxisum += a[i]
d = notmaxisum - maxisum
if d > ans:
ans = d
maxisum = min(maxisum, notmaxisum)
return ans
def solve():
n = int(input... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | import sys
def maxSubArraySum(arr, len1):
maxSumHere = 0
maxSumTillNow = -1 * sys.maxsize
for i in range(len1):
maxSumHere += arr[i]
if maxSumTillNow < maxSumHere:
maxSumTillNow = maxSumHere
if maxSumHere < 0:
maxSumHere = 0
return maxSumTillNow
t = in... | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUN... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def solution(arr):
even = 0
for i in range(0, len(arr), 2):
even = even + arr[i]
diff = 0
curr = 0
for i in range(1, len(arr), 2):
val = arr[i] - arr[i - 1]
curr = curr + val
diff = max(diff, curr)
curr = max(curr, 0)
curr = 0
for j in range(1, len(arr... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR F... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | n = 0
nums = list()
def solve():
max_ending = 0
mmax = 0
for i in range(0, n - 1, 2):
max_ending = max(0, max_ending + nums[i + 1] - nums[i])
mmax = max(mmax, max_ending)
max_ending = 0
for i in range(1, n - 1, 2):
max_ending = max(0, max_ending + nums[i] - nums[i + 1])
... | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | T = int(input())
while T > 0:
n = int(input())
arr = list(map(int, input().split()))
res = 0
temp = 0
now = 0
increase = 0
for i in range(0, n, 2):
now += arr[i]
for i in range(0, n, 2):
if i + 1 < n:
temp += arr[i + 1] - arr[i]
increase = max(incr... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR N... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def f(s, neg):
t = []
for i in range(0, len(s), 2):
t.append((s[i] - s[i + 1]) * neg)
MAX = SUM = 0
for x in t:
SUM += x
if SUM < 0:
SUM = 0
MAX = max(SUM, MAX)
return MAX
for _ in range(int(input())):
input()
s = list(map(int, input().split()))
... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR F... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
print(max(a))
else:
s = sum(a[::2])
diff1 = []
for i in range(1, n, 2):
diff1.append(a[i] - a[i - 1])
diff2 = []
for i in range(2, n, 2):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR F... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def find_max_sum(a):
if len(a) == 1:
return 0
if len(a) == 2:
return a[0] + a[1]
if len(a) == 3:
return max(a[0] + a[1], a[1] + a[2])
n = int(len(a) / 2)
l_max = find_max_sum(a[0:n])
r_max = find_max_sum(a[n : len(a)])
lsum_odd = a[n - 1]
lsum_even = float("-inf")... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR A... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | def maxSubArraySum(a, size):
max_so_far = -float("inf") - 1
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
retu... | FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR ... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_numb... | IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for s in [*open(0)][2::2]:
l = [*map(int, s.split())]
x = sum(l[::2])
n = len(l)
l = [((2 * (i & 1) - 1) * l[i]) for i in range(n)]
min_e = min_o = 0
sm = 0
a = 0
for i in range(n):
sm += l[i]
if 1 & i:
a = max(a, sm - min_o)
min_o = min(sm, min_o)... | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR... |
You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).
You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{... | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
maxi = 0
curr = 0
for i in range(0, n - 1, 2):
curr += arr[i + 1] - arr[i]
curr = max(0, curr)
maxi = max(curr, maxi)
curr = 0
for i in range(1, n - 1, 2):
curr += arr[i] - ar... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.