description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
d = int(input()) l = list(map(int, input().split())) res = 0 cr = 0 w = l[0] // 2 b = l[0] - w for i in range(1, d): if (i + 1) % 2 != 0: w = w + l[i] // 2 b = b + l[i] - l[i] // 2 else: b = b + l[i] // 2 w = w + l[i] - l[i] // 2 print(min(b, w))
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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR V...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) L = list(map(int, input().split())) col = "white" w = 0 b = 0 for i in range(n): if col == "white": w += (L[i] + 1) // 2 b += L[i] // 2 col = "black" else: b += (L[i] + 1) // 2 w += L[i] // 2 col = "white" print(min(w, b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP VAR VAR NUMBER NUM...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
a = int(input()) A = list(map(int, input().split())) w = 0 b = 0 for i in range(a): A[i] += i % 2 b += A[i] // 2 w += A[i] - A[i] // 2 - i % 2 print(min(b, w))
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 VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR V...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) l = list(map(int, input().split())) r = 0 b = 0 for i in range(len(l)): if l[i] % 2 == 1: if i % 2 == 1: r += int(l[i] / 2) + 1 b += int(l[i] / 2) else: r += int(l[i] / 2) b += int(l[i] / 2) + 1 else: r += int(l[i] / 2) ...
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 FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) data = list(map(int, input().split())) b, w = 0, 0 for i in range(n): n_even = int(data[i] / 2) n_odd = data[i] - n_even if i % 2 == 0: b += n_even w += n_odd else: b += n_odd w += n_even print(min(b, w))
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 NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUN...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) vals = list(map(int, input().split(" "))) black, white = 0, 0 even = False for v in vals: vdiv2 = v // 2 black += vdiv2 white += vdiv2 if v & 1: if even: black += 1 else: white += 1 even = not even print(min(black, white))
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 NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR V...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = list(map(int, input().split())) ans = 0 for q in range(n): if q % 2 == 0: ans += (a[q] + 1) // 2 else: ans += a[q] // 2 print(min(ans, sum(a) - ans))
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 BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = list(map(int, input().split())) w = 0 b = 0 for i in range(n): if i % 2 == 0: if a[i] % 2 == 1: b += 1 b += a[i] // 2 w += a[i] // 2 else: if a[i] % 2 == 1: w += 1 b += a[i] // 2 w += a[i] // 2 print(min(w, b))
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 IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMB...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = list(map(int, input().split(" "))) A, B = 0, 0 for i, v in enumerate(a): g = (v + 1) // 2 l = v - g if i % 2: g, l = l, g A, B = A + g, B + l print(min(A, B))
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 FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_O...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = input() L = map(int, input().split()) base_is_white = True white = 0 black = 0 for x in L: if base_is_white: white += x // 2 + x % 2 black += x // 2 base_is_white = False else: white += x // 2 black += x // 2 + x % 2 base_is_white = True print(min(white, black...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NU...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = input().split(" ") for i in range(n): a[i] = int(a[i]) w = a[0] // 2 b = a[0] - w c = 1 def no(x): if x == 1: return 0 return 1 for i in range(1, len(a)): if a[i - 1] % 2 == 0: if a[i] % 2 == 0: w += a[i] // 2 b += a[i] // 2 c ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) white = 0 black = 0 for i, a in enumerate(A): if a % 2 == 0: white += a // 2 black += a // 2 elif i % 2 == 0: black += a // 2 white += a // 2 + 1 else: white += a // 2 ...
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 NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
import sys input = sys.stdin.readline lastodd = [] n = int(input()) a = [int(i) for i in input().split()] ans = 0 for i in range(n): if not a[i] & 1: ans += a[i] // 2 else: if lastodd: if i - lastodd[-1] & 1: ans += 1 lastodd.pop() else: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST 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 VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL ...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) array = list(map(int, input().split())) c1, c2 = 0, 0 for i in range(n): a = array[i] if a % 2 == 0: c1 += a // 2 c2 += a // 2 else: c1 += a // 2 c2 += a // 2 if i % 2 == 0: c1 += 1 else: c2 += 1 print(min(c1, c2))
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 NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUM...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) hist = [int(i) for i in input().split()] total = sum(hist) white = 0 black = 0 for i in range(n): if i % 2 == 0: white += hist[i] // 2 else: white += (hist[i] + 1) // 2 black = total - white print(min(white, black))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CAL...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = list(map(int, input().split())) b = w = 0 key = True for j in range(len(a)): if key: if a[j] % 2 == 0: b += a[j] // 2 w += a[j] // 2 else: b += a[j] // 2 + 1 w += a[j] // 2 key = False else: if a[j] % 2 == 0: ...
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = list(map(int, input().split())) ans = [0, 0] color = 0 for x in a: ans[color] += x // 2 color ^= 1 ans[color] += x - x // 2 print(min(ans))
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 ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = list(map(int, input().split())) black = 0 white = 0 j = 0 while j < n: black += (a[j] + 1) // 2 white += a[j] // 2 black, white = white, black j += 1 print(min(black, white))
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 WHILE VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) b, w = 0, 0 cols = [int(x) for x in input().split()] for c in range(n): if cols[c] % 2 == 1: b += c % 2 w += (c + 1) % 2 print((sum(cols) - abs(b - w)) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) A = list(map(int, input().split())) x, y = 0, 0 for a in A: x += a // 2 y += (a + 1) // 2 x, y = y, x print(min(x, y))
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 NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = list(map(int, input().split())) dp = [(0) for _ in range(2)] pre = -1 for i in range(n): if i % 2 == 0: dp[0] += a[i] // 2 dp[1] += a[i] - a[i] // 2 else: dp[0] += a[i] - a[i] // 2 dp[1] += a[i] // 2 print(min(dp[0], dp[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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP ...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
from sys import stdin, stdout def scal(typ=int): return typ(stdin.readline()) def vec(typ=int): if isinstance(typ, list): inp = stdin.readline().split() return [typ[i](inp[i]) for i in range(len(inp))] else: return list(map(typ, stdin.readline().split())) n = scal() A = vec() i...
FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VA...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) arr = [int(x) for x in input().split()] ans = 0 for i in range(len(arr)): ans += arr[i] // 2 arr[i] %= 2 for i in range(2, len(arr)): arr[i % 2] += arr[i] if n > 1: ans += min(arr[0], arr[1]) print(ans)
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 FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR N...
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 recta...
n = int(input()) a = [int(i) for i in input().split()] m = [0, 0] for i in range(n): m[0] += a[i] // 2 m[1] += a[i] // 2 if a[i] % 2 != 0: m[i % 2] += 1 print(int(min(m[0], m[1])))
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 VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CAL...
Morning desert sun horizon Rise above the sands of time... Fates Warning, "Exodus" After crossing the Windswept Wastes, Ori has finally reached the Windtorn Ruins to find the Heart of the Forest! However, the ancient repository containing this priceless Willow light did not want to open! Ori was taken aback, but th...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) s = input()[:-1] lcp = [([0] * (n + 1)) for _ in range(n + 1)] for i in range(n - 1, -1, -1): for j in range(n - 1, -1, -1): if s[i] == s[j]: lcp[i][j] = lcp[i + 1][j + 1] + 1 d...
IMPORT ASSIGN VAR 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER...
Morning desert sun horizon Rise above the sands of time... Fates Warning, "Exodus" After crossing the Windswept Wastes, Ori has finally reached the Windtorn Ruins to find the Heart of the Forest! However, the ancient repository containing this priceless Willow light did not want to open! Ori was taken aback, but th...
import sys for _ in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) s = sys.stdin.readline().strip() d = [0] * n l = [0] * (n + 1) for i in range(n - 1, -1, -1): for j in range(i + 1, n): if s[i] < s[j]: d[i] = max(d[i], d[j]) if s[i] ...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VA...
Morning desert sun horizon Rise above the sands of time... Fates Warning, "Exodus" After crossing the Windswept Wastes, Ori has finally reached the Windtorn Ruins to find the Heart of the Forest! However, the ancient repository containing this priceless Willow light did not want to open! Ori was taken aback, but th...
import sys input = sys.stdin.readline def SA_IS(a): a += [0] k = max(a) + 1 n = len(a) def induce_l(sa, a, n, k, stype): bucket = get_buckets(a, k, 1) for i in range(n): j = sa[i] - 1 if j >= 0 and not stype[j]: sa[bucket[a[j]]] = j ...
IMPORT ASSIGN VAR VAR FUNC_DEF VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN 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 = int(input()) q = d = 0 p = False ar = list(map(int, input().split())) min = 10000000000 r = max(ar) for i in ar: if i >= 0: if i < min: min = i q += i else: p = True d += -i if r >= 0: if p: max = q + d else: max = q - min - min else: m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER IF VAR ASSIGN VAR BIN_OP 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(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) a.sort() c = a[n - 1] f = a[0] if n > 1: for i in range(1, n - 1): if a[i] >= 0: f -= a[i] elif a[i] < 0: f += a[i] print(c - f) else: print(a[0])
IMPORT 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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER 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()) l1 = list(map(int, input().split())) x = l1[0] flag1 = 0 flag2 = 0 ans = 0 for item in l1: ans += abs(item) if item < 0: flag1 = 1 else: flag2 = 1 for i in range(0, n): l1[i] = abs(l1[i]) if flag1 == 1 and flag2 == 1: print(ans) elif n != 1: print(sum(l1) - 2 * 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_C...
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())) all_positive = True all_negative = True min_positive_index = None max_negative_index = None min_abs_value = abs(a[0]) total = 0 if n == 1: print(a[0]) else: for i in range(n): value = a[i] all_positive &= value > 0 all_negative &= valu...
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 NONE ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR 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...
I = lambda: map(int, input().split()) n = int(input()) a = list(I()) s = 0 if n == 1: exit(print(a[0])) if all(i > 0 for i in a): print(sum(a) - 2 * min(a)) elif all(i < 0 for i in a): print(-(sum(a) - 2 * max(a))) else: for i in a: s += abs(i) print(s)
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 NUMBER IF 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 I...
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 input = sys.stdin.readline n = int(input()) ar = list(map(int, input().split())) if n == 1: print(ar[0]) elif n == 2: print(abs(ar[0] - ar[1])) else: flag = False for i in range(1, n): if ar[i] * ar[i - 1] <= 0: flag = True break if flag: ans = 0 ...
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR 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...
n = int(input()) l = list(map(int, input().split())) pos = 0 neg = 0 w = [] for i in range(n): if l[i] >= 0: pos += 1 else: neg += 1 w.append(abs(l[i])) if n == 1: print(l[0]) elif neg != 0 and pos == 0: print(sum(w) - min(w) * 2) elif pos != 0 and neg == 0: print(sum(w) - min(w)...
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 LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMB...
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 = input().split() for i in range(n): a[i] = int(a[i]) if n == 1: print(a[0]) else: sm = 0 havePositive = False haveNegative = False for c in a: if c == 0: haveNegative = True havePositive = True elif c > 0: havePositive = Tru...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN 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()) a = [int(i) for i in input().split()] if n == 1: print(a[0]) exit() mx, mxi = -(10**10), -1 mn, mni = 10**10, -1 for i in range(n): if a[i] > mx: mx, mxi = a[i], i if a[i] < mn: mn, mni = a[i], i if mn < 0: if mx < 0: print(-sum(a) + 2 * mx) else: ...
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 EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF 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 input = sys.stdin.readline n = int(input()) v = list(sorted(map(int, input().split()))) if n == 1: print(v[0]) else: print(v[n - 1] - v[0] + sum(map(abs, v)) - (abs(v[0]) + abs(v[n - 1])))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP 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...
def f(arr, N): if N == 1: return arr[0] a = 0 a_min = 10**9 + 1 b = 0 c = False d = False b_min = -1 * a_min for i in arr: if i >= 0: c = True a += i a_min = min(a_min, i) else: d = True b += i ...
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR 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...
from sys import stdin n = int(input()) a = [int(x) for x in stdin.readline().split()] if n == 1: print(a[0]) else: cnt = 0 b = [0] * n li1 = [0] * n li2 = [0] * n for i in range(n): b[i] = abs(a[i]) for i in range(n): if b[i] == a[i]: cnt += 1 else: ...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR 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()) lis = list(map(int, input().split())) if len(lis) == 1: print(lis[0]) else: lis.sort() a = -lis[0] + lis[-1] lis = list(map(abs, lis)) print(a + sum(lis[1:-1]))
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 VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR 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...
n = int(input()) l = list(map(int, input().split())) if n == 1: print(l[0]) exit(0) pos = 0 neg = 0 for i in l: if i >= 0: pos -= -1 else: neg -= -1 if neg > 0 and pos > 0: sm = 0 for i in l: sm += abs(i) print(sm) elif neg == 0: print(sum(l) - 2 * min(l)) else: ...
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 NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR F...
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())) arr.sort() arr1 = [] arr2 = [] val1 = 0 for i in range(n - 1): val1 += arr[i] arr1.append(val1) val1 = 0 for i in range(n - 1, 0, -1): val1 += arr[i] arr2.append(val1) fans = -10000000000000000000000 for i in range(n - 1): fans = max(fans, arr2[...
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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBE...
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: prod_minus = False for i in range(n - 1): if a[i] * a[i + 1] <= 0: prod_minus = True break Min_abs = float("inf") Sum = 0 for num in a: Sum += abs(num) if abs(num) < ...
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 FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMB...
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())) if n == 1: print(l[0]) exit() l = sorted(l) s = abs(l[0] - l[-1]) for i in range(1, n - 1): s += abs(l[i]) print(s)
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 VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER 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...
n = int(input()) a = [int(s) for s in input().split()] if n == 1: print(a[0]) exit() mi, po, sum, mix = 0, 0, 0, 1000000000.0 + 1 for i in a: if i < 0: mi += 1 if i >= 0: po += 1 sum += abs(i) mix = min(mix, abs(i)) if mi and po: print(sum) else: print(sum - mix * 2)
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 EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR F...
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()) lis = [int(x) for x in input().split()] total = 0 l_negative = -1000000000000 s_positive = 1000000000000 for i in lis: if i <= 0: l_negative = max(l_negative, i) if i >= 0: s_positive = min(s_positive, i) total += abs(i) if l_negative == -1000000000000: total -= 2 * s_po...
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 NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF 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()) lis = list(map(int, input().split())) pos = [] neg = [] for i in lis: if i >= 0: pos.append(i) else: neg.append(i) pos.sort(reverse=True) neg.sort(reverse=True) if n == 1: print(lis[0]) exit() if len(pos) > 0: if len(neg) > 0: print(sum(pos) - sum(neg)) e...
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 VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR 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()) a = list(map(int, input().split())) mina = abs(a[0]) summ = 0 okeye = False mosbat = 0 for adad in a: if abs(adad) < mina: mina = abs(adad) summ += abs(adad) if adad == 0: okeye = True elif adad > 0: mosbat += 1 if n == 1: print(a[0]) elif okeye or 0 < mosbat...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF 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()) arr = list(map(int, input().split())) sum = 0 for i in range(n): sum += abs(arr[i]) ans = 0 if n == 1: print(arr[0]) else: for i in range(n - 1): ans = max(ans, sum - abs(arr[i]) - abs(arr[i + 1]) + abs(arr[i] - arr[i + 1])) print(ans)
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 VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP...
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()) H = list(map(int, input().split())) d = 0 f = 0 m = 10**9 + 7 if n > 1: for i in range(n): if H[i] < 0: f += 1 d += abs(H[i]) if abs(H[i]) < m: m = abs(H[i]) if f == 0 or f == n: print(d - m * 2) else: print(d) else: print(...
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 BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN 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()) s = list(map(int, input().split())) s.sort() ans = 0 if n == 1: ans = s[0] elif s[0] >= 0: ans = sum(s[1:]) - s[0] elif s[-1] < 0: ans = -sum(s[0 : n - 1]) + s[-1] else: for i in range(n): s[i] = abs(s[i]) ans = sum(s) print(ans)
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 ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BI...
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(0) min_idx = 0 min_res = a[0] max_idx = 0 max_res = a[0] for i in range(1, n): if a[i] < min_res: min_idx, min_res = i, a[i] if a[i] > max_res: max_idx, max_res = i, a[i] res = 0 for i in range(n): if 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR 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()) a = list(map(int, input().split())) if n == 1: print(a[0]) exit() if max(a) > 1 and min(a) < 1: print(sum(abs(x) for x in a)) else: print(sum(abs(x) for x in a) - 2 * min(abs(x) for x in a))
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 IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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 = list(map(int, input().split())) if n == 1: exit(print(*a)) pos, neg = False, False mn = 10**9 + 5 ans = 0 for i in a: pos |= i >= 0 neg |= i <= 0 ans += abs(i) mn = min(abs(i), mn) if pos and neg: print(ans) else: print(ans - 2 * mn)
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 VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL 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...
for _ in range(1): n = int(input()) arr = list(map(int, input().split())) s = 0 for i in range(n): s += abs(arr[i]) if min(arr) < 0 and max(arr) >= 0: print(s) continue if n == 1: print(arr[0]) continue d = 999999999999999 for i in range(1, n): ...
FOR VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR 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...
n = int(input()) xs = [int(x) for x in input().split()] prefix = [(-1) for i in range(n)] suffix = [(-1) for i in range(n)] prefix[0] = 0 pre_has_neg = [(False) for i in range(n)] suffix[-1] = 0 suf_has_neg = [(False) for i in range(n)] for i in range(n): if i == 0: prefix[i] = xs[i] else: prefi...
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 NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_C...
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()) A = list(map(int, input().split())) if n == 1: print(A[0]) sys.exit(0) suma = 0 mine = 1000000001 d = False for i in range(0, n): mine = min(mine, abs(A[i])) suma += abs(A[i]) if i > 0 and (A[i] >= 0 and A[i - 1] < 0 or A[i] < 0 and A[i - 1] >= 0): d = True if d:...
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR 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...
def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) n = ii() a = li() b = [abs(x) for x in a] if n == 1: ans = a[0] elif all(x > 0 for x in a) or all(x < 0 for x in a): b.sort() ans = sum(b) - 2 * b[0] else: ans = sum(b) print(ans)
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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR 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...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) exit() m, M = min(a), max(a) if m >= 0: print(sum(a) - 2 * m) elif M < 0: print(-sum(a) + 2 * M) else: print(sum(abs(ai) for ai in a))
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF...
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: print(input()) else: a = [int(x) for x in input().split()] b = [abs(x) for x in a] if min(a) >= 0: print(sum(b) - 2 * min(a)) elif max(a) <= 0: print(sum(b) + 2 * max(a)) else: print(sum(b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER 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()) a = list(map(int, input().split())) a.sort() ans = 0 ck = 0 d1 = -10000000000 d2 = 10000000000 for i in a: ans += abs(i) d1 = max(d1, i) d2 = min(d2, i) if i == 0: ck = 1 if ck == 1: print(ans) elif n == 1: print(a[0]) else: ans -= abs(d1) + abs(d2) ans += abs(d1...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN 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()) a = list(map(int, input().split())) a.sort() x = 0 y = 0 s = 0 if n == 1: print(a[0]) exit(0) for i in a: if i > 0: x += 1 if i < 0: y += 1 s = s + abs(i) if x == n or y == n: if x == n: print(s - 2 * a[0]) if y == n: print(s + 2 * a[n - 1]) e...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN 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...
from sys import stdin input = stdin.readline n = int(input()) lst = sorted(map(int, input().split())) if n == 1: print(lst[0]) exit() elif lst[-1] <= 0: s = abs(sum(lst)) + 2 * lst[-1] elif lst[0] >= 0: s = sum(lst) - 2 * lst[0] else: s = 0 for i in lst: s += abs(i) print(s)
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP F...
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())) minval = abs(a[0]) havepos = 0 haveneg = 0 ans = 0 if n == 1: print(a[0]) else: for i in range(n): minval = min(abs(a[i]), minval) havepos = havepos or a[i] >= 0 haveneg = haveneg or a[i] <= 0 ans += abs(a[i]) if haveneg an...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASS...
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())) fl = 0 f = 0 s = 0 for i in l: if i <= 0: fl = 1 if i >= 0: f = 1 s = s + abs(i) x = min(l) y = max(l) if n == 1: print(l[0]) elif f == 1 and fl == 1: print(s) elif fl == 1: print(s - 2 * abs(y)) else: print(s - 2 * x)
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 FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN 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, minus = int(input()), 100000000000000000000 x = [int(x) for x in input().split()] if n == 1: print(x[0]) exit(0) if min(x) > 0: for i in range(1, n): if x[i] - x[i - 1] <= 0 or x[i - 1] - x[i] <= 0: minus = min(minus, abs(x[i]) + abs(x[i - 1]) - abs(x[i] - x[i - 1])) if max(x) < 0: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR 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()) ans = 0 i = 0 l = list(map(int, input().split())) t = 0 if n == 1: print(l[0]) else: while i < n: if l[i] >= 0: c = 0 t += 1 while l[i] >= 0: c += l[i] i += 1 if i == n: break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF 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...
n = int(input()) x = [int(x) for x in input().split()] result = 0 i = 1 j = n - 2 k = 0 l = 0 x.sort() def check(x): a = 0 for i in range(0, n): if x[i] >= 0: a = x[i] return a if x[0] < 0 and x[n - 1] <= 0: result = x[n - 1] while j >= 0: result = result - x[...
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 NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN ...
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(x) for x in input().split(" ")] if len(a) == 1: print(a[0]) exit() a.sort() if all(x > 0 for x in a): print(sum(a) - a[0] * 2) exit() if all(x < 0 for x in a): print(-sum(a) + a[-1] * 2) exit() print(sum(abs(x) for x in a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL 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()) x = 0 cp = 0 cn = 0 a = [int(i) for i in input().split()] sum1 = 0 for i in range(n): sum1 += abs(a[i]) if i == 0: x = abs(a[i]) else: x = min(x, abs(a[i])) if a[i] > 0: cp = 1 elif a[i] < 0: cn = 1 else: cp = 1 cn = 1 if n == 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF...
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(w) for w in input().split()] s = sum(abs(x) for x in a) if len(a) == 1: print(a[0]) elif all(x > 0 for x in a) or all(x < 0 for x in a): print(max(abs(s - 2 * abs(x)) for x in a)) else: print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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()) if n == 1: print(int(input())) exit(0) a, b = [], [] for i in map(int, input().split()): if i > 0: a.append(i) elif i < 0: b.append(i) if len(a) != 0 and len(b) != 0: print(sum(a) - sum(b)) elif len(a) + len(b) != n: print(sum(a) - sum(b)) elif len(a) == 0: p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER 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...
n = int(input()) a = list(map(int, input().split())) a.sort() if n == 1: print(a[0]) else: i = 0 while i < n and a[i] <= 0: i += 1 if i == 0: print(sum(a) - 2 * a[0]) elif i == n: print(2 * a[-1] - sum(a)) else: print(sum(a[i:]) - sum(a[:i]))
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 EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER IF 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...
n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) exit(0) hasp, hasn = False, False for aa in a: hasp = hasp or aa > 0 hasn = hasn or aa < 0 if hasn and hasp: print(sum(list(map(abs, a)))) elif hasn or hasp: print(sum(list(map(abs, a))) - 2 * min(list(map(abs, a)))) els...
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 VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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().strip()) arr = [int(__) for __ in input().strip().split()] if n == 1: print(arr[0]) else: ne = 0 for i in arr: if i < 0: ne += 1 if ne == len(arr): arr = [abs(i) for i in arr] print(sum(arr) - 2 * min(arr)) else: mi = min(arr) arr =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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...
def abs(a): if a < 0: return -a return a def min(a, b): if a < b: return a return b def max(a, b): if b > a: return b return a n = int(input()) a = input() a = list(map(int, a.split(" "))) if n == 1: print(a[0]) exit() pos = int(0) neg = int(0) mn = int(1000...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER 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(x) for x in input().split()] B = [abs(x) for x in A] if N == 1: print(A[0]) exit(0) s = sum(B) if any(x >= 0 for x in A) and any(x <= 0 for x in A): print(s) else: print(s - 2 * min(B))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER 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()) val = sorted(map(int, input().split())) sval = sum(map(abs, val)) if n == 1: print(val[0]) elif val[0] > 0: print(sval - val[0] * 2) elif val[-1] < 0: print(val[-1] * 2 + sval) else: print(sval)
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP ...
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(sum(a)) return mn = min(a) mx = max(a) s = 0 for i in a: s += abs(i) print(s - abs(mn) - abs(mx) + mx - mn)
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 RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP...
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()) s = list(map(int, input().split())) ans = 0 smax = -(10**9) smin = 10**9 for i in s: if i > smax: smax = i if i < smin: smin = i f1 = False f2 = False for i in s: if not f1 and i == smax: ans += smax f1 = True continue if not f2 and i == smin: ...
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 NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR 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()) s = list(map(int, input().split())) if n == 1: exit(print(s[0])) f = [] if any(i <= 0 for i in s) and any(i >= 0 for i in s): exit(print(sum(map(abs, s)))) s.sort(key=abs) cs = s[0] for i in s[1:]: cs -= i print(abs(cs))
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 NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EX...
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 abs_sum(lis): ans = 0 for item in lis: ans += abs(item) return ans n = int(input()) lis = [int(x) for x in input().split()] if n == 1: print(lis[0]) sys.exit() a = abs_sum(lis) b = sum(lis) if a != b and a != -b: print(a) elif b >= 0: minn = min(lis) print(a - ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR ...
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())) s = 0 if max(a) <= 0: print(abs(sum(a)) + 2 * max(a)) elif min(a) >= 0: print(abs(abs(sum(a)) - 2 * min(a))) else: for i in a: s += abs(i) print(s)
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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL 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...
tot = int(input()) arr = [int(x) for x in input().split()] n, p, z = 0, 0, 0 for i in arr: if i > 0: p += 1 elif i < 0: n += 1 else: z += 1 ans = 0 for i in arr: ans += abs(i) if tot == 1: print(arr[0]) elif p == 0 or n == 0: mi = min(arr) if mi < 0: mi = max(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER 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()) a = list(map(int, input().split())) p = 0 if n <= 1: print(a[0]) else: for j in range(n): if a[j] < 0: p += 1 if p == 0: print(sum(a) - 2 * min(a)) elif p == n: print(abs(sum(a)) - 2 * abs(max(a))) else: s = 0 for j 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 NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF 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()) b = list(map(int, input().split())) if n == 1: print(b[0]) exit(0) min1 = min(b) max1 = max(b) s = 0 for i in range(n): s = s + abs(b[i]) print(s + max1 - min1 - abs(max1) - abs(min1))
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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR 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()) arr = [int(x) for x in input().split()] if n == 1: print(arr[0]) exit() sum = sum(abs(x) for x in arr) if not any(x < 0 for x in arr): sum = sum - 2 * min(arr) if not any(x >= 0 for x in arr): sum = sum - 2 * abs(max(arr)) print(sum)
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 EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF 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...
N = int(input()) A = list(map(int, input().split())) p = 0 n = 0 for i in A: if i >= 0: p += 1 elif i < 0: n += 1 if N == 0: print(0) elif N == 1: print(A[0]) elif p > 0 and n > 0: for i in range(N): if A[i] < 0: A[i] = -1 * A[i] print(sum(A)) elif p == len(A)...
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 VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER FOR 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()) x = list(map(int, input().split())) ans, mi = 0, 1234567654321 for i in range(n): ans += abs(x[i]) if i > 0: mi = min(mi, abs(x[i]) + abs(x[i - 1]) - abs(x[i] - x[i - 1])) if n == 1: print(x[i]) else: print(ans - mi)
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 NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_...
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]) elif n == 2: print(max(a[0] - a[1], a[1] - a[0])) else: x = min(a) y = max(a) a = list(map(abs, a)) print(sum(a) - (2 * min(a) if x * y > 0 else 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 IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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()) A = list(map(int, input().split())) if n == 1: print(A[0]) elif n == 2: print(abs(A[0] - A[1])) else: SUM = 0 for i in range(n): SUM += abs(A[i]) ANS = 0 for i in range(n - 1): if ANS < SUM - abs(A[i]) - abs(A[i + 1]) + abs(A[i] - A[i + 1]): ANS = SUM...
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 BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR 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...
def solve(): n = int(input()) worms = list(map(int, input().split())) if n == 1: return worms[0] if len(list(filter(lambda x: x >= 0, worms))) == 0: worms = list(map(abs, worms)) minimum = min(worms) return sum(worms) - 2 * minimum minimum = min(worms) worms_sum =...
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 RETURN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR 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 input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) exit() if min(a) > 0: print(sum(a) - 2 * min(a)) elif max(a) < 0: print(-sum(a) + 2 * max(a)) else: x = 0 for i in range(n): x += abs(a[i]) print(x)
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMB...
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 solve(a): if len(a) == 1: return a[0] if max(a) < 0: return 2 * max(a) - sum(a) elif min(a) >= 0: return sum(a) - 2 * min(a) else: return sum(abs(x) for x in a) n = int(input()) a = list(map(int, input().split())) print(solve(a))
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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()) a = list(map(int, input().split())) if n == 1: print(a[0]) elif all(ele > 0 for ele in a): s = sum(a) - 2 * min(a) print(s) elif all(ele < 0 for ele in a): s = abs(sum(a)) - 2 * abs(max(a)) print(s) else: ans = 0 for ele in a: ans += abs(ele) 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 IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER 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())) arr.sort() s = 0 if n == 1: s = arr[0] elif arr[-1] < 0: s = abs(sum(arr)) - abs(arr[-1]) * 2 elif arr[0] < 0: for i in range(len(arr)): s += abs(arr[i]) else: s = sum(arr) - 2 * arr[0] print(s)
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 ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER FOR VAR FU...
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 mi(): return map(int, input().split()) n = int(input()) a = list(mi()) cp, cn = 0, 0 for i in a: if i >= 0: cp += 1 if i <= 0: cn += 1 s = 0 if n == 1: print(a[0]) exit(0) for i in a: s += abs(i) if cn and cp: print(s) else: m = -1e100 for i in a: m = ma...
FUNC_DEF RETURN 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 VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR 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...
from sys import stdin input = stdin.buffer.readline n = int(input()) (*a,) = map(int, input().split()) x = max(a) ans = x a.remove(x) if n > 1: x = min(a) ans -= x a.remove(x) for i in a: ans += abs(i) print(ans)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR 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...
n = int(input()) a = list(map(int, input().split())) if n == 1: print(a[0]) else: s = 0 a.sort() pos = 0 neg = 0 k = 1 for i in range(n): if a[i] > 0: pos += 1 if a[i] < 0: neg += 1 s += abs(a[i]) if pos == n: print(s - 2 * a[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 ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER 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...
l = int(input()) a = [*map(int, input().split())] p = n = 0 for i in a: if i > 0: p += 1 else: n += 1 ans = 0 if p and n: a.sort() for i in a: if i < 0: ans -= i else: ans += i elif p: a.sort() ans -= a[0] for i in a[1:]: ans +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR NUMBER VAR...