description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) sum = 0 k = 0 for i in range(0, n): if l[i] > 0: sum += l[i] k = k + 1 if sum % 2 == 1: print(sum) else: min = float("inf") if k >= 2: for i in range(0, n): if l[i] > 0 and l[i] < min and l[i] % 2 != 0: min = l[i] for i in range(0, n): temp = -1 * l[i] if temp > 0 and temp < min and temp % 2 != 0: min = temp else: for i in range(0, n): temp = -1 * l[i] if temp > 0 and temp < min and l[i] % 2 != 0: min = temp print(sum - min)
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 VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = [int(x) for x in input().split()] even = [] odd = [] odd_n = [] s = 0 for i in arr: if i > 0: s += i if i % 2: odd.append(i) else: even.append(i) elif i % 2: odd_n.append(i) if s % 2: print(s) else: if len(odd) > 0 and len(odd_n) > 0: s = max(s - min(odd), s + max(odd_n)) elif len(odd) > 0: s = s - min(odd) else: s += max(odd_n) print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) even = -float("Inf") odd = -float("Inf") for i in range(n): if a[i] % 2 == 0: even = max([even + a[i], a[i], even]) odd = max([odd + a[i], odd]) if a[i] % 2 != 0: odd, even = max([even + a[i], odd, a[i]]), max([odd + a[i], even]) if odd % 2 == 0: print(0) else: print(odd)
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 STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) INF = 10**18 dp = [([-INF] * 2) for i in range(n)] if a[0] % 2 == 0: dp[0][0] = a[0] else: dp[0][1] = a[0] for i in range(1, n): if a[i] % 2: dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][0]) dp[i][1] = max([a[i], dp[i - 1][0] + a[i], dp[i - 1][1]]) else: dp[i][0] = max([a[i], dp[i - 1][0] + a[i], dp[i - 1][0]]) dp[i][1] = max(dp[i - 1][1] + a[i], dp[i - 1][1]) print(dp[-1][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 BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR LIST VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR LIST VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
def odd_sum(lst): k, m = 0, 10**9 for elem in lst: if elem >= 0: k += elem if k % 2: return k for elem in lst: if elem % 2: m = min(m, abs(elem)) return k - m n = int(input()) a = [int(i) for i in input().split()] print(odd_sum(a))
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER RETURN VAR FOR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) codd, odd, even = 0, 0, 0 modd = 0 Modd = 10**5 K = -(10**5) for i in range(n): if a[i] > 0: if a[i] % 2 == 0: even += a[i] if a[i] % 2 == 1: odd += a[i] modd = max(modd, a[i]) Modd = min(Modd, a[i]) codd += 1 elif a[i] % 2 == 1: K = max(K, a[i]) if codd % 2 == 1: print(odd + even) else: print(even + odd - min(Modd, -K))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = sorted(list(map(int, input().split()))) mx = max(a) b = [] c = [] d = [] e = [] sum1 = 0 sum2 = 0 for i in range(n): if a[i] >= 0: sum1 += a[i] if a[i] % 2 == 0: b.append(a[i]) else: c.append(a[i]) else: sum2 += a[i] if a[i] % 2 == 0: d.append(a[i]) else: e.append(a[i]) if sum1 % 2 == 1 and sum1 > 0: print(sum1) elif len(e) > 0: if len(c) > 0: print(max(sum1 + e[-1], sum1 - c[0])) else: print(sum1 + e[-1]) elif len(c) > 0: print(sum1 - c[0])
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
k = int(input()) liste = list(map(int, input().split())) x = 0 list1 = [] for i in liste: if i > 0: x += i if x % 2: print(x) else: for i in liste: if i % 2: list1.append(abs(i)) print(x - min(list1))
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 VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) su = 0 minodd = 2147483647 for i in range(n): if l[i] > 0: su += l[i] if l[i] % 2 != 0: minodd = min(abs(l[i]), minodd) if su % 2 != 0: print(su) else: print(su - minodd)
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 VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) oddSum = 0 evenSum = 0 smallPos = 10**4 + 1 smallNeg = -(10**4) + 1 for i in range(n): if a[i] > 0: if a[i] % 2 == 0: evenSum += a[i] else: oddSum += a[i] smallPos = min(smallPos, a[i]) elif a[i] % 2 == 1: smallNeg = max(smallNeg, a[i]) if oddSum == 0: print(smallNeg + evenSum) elif oddSum % 2 == 1: print(oddSum + evenSum) else: print(max(evenSum + oddSum - smallPos, evenSum + oddSum + smallNeg))
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 ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l_n = list(map(int, input().split())) l_o = list() s = 0 for n in l_n: if n % 2 == 0: if abs(n) == n: s += n else: l_o.append(n) l_o.sort() m_s = s t_s = s m_n_o = None n_i = -1 for i in range(len(l_o)): if abs(l_o[i]) != l_o[i]: m_n_o = l_o[i] n_i = i else: break if len(l_o) - n_i - 1 == 0: print(s + m_n_o) elif (len(l_o) - n_i - 1) % 2 == 0: print( max( s + sum(l_o[n_i + 2 :]), s + sum(l_o[n_i + 1 :]) + (m_n_o if m_n_o else int(-10000000000.0)), ) ) else: print(s + sum(l_o[n_i + 1 :]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = [int(x) for x in input().split()] dp = [[(0) for x in range(2)] for y in range(n)] dp[0][not a[0] % 2] = 0 dp[0][a[0] % 2] = a[0] for i in range(1, n): if a[i] % 2 == 0: dp[i][0] = max(a[i] + dp[i - 1][0], dp[i - 1][0], a[i]) if dp[i - 1][1] != 0: dp[i][1] = max(a[i] + dp[i - 1][1], dp[i - 1][1]) else: dp[i][1] = dp[i - 1][1] elif dp[i - 1][1] != 0: dp[i][1] = max(a[i] + dp[i - 1][0], dp[i - 1][1], a[i]) dp[i][0] = max(a[i] + dp[i - 1][1], dp[i - 1][0]) else: dp[i][1] = max(a[i] + dp[i - 1][0], a[i]) dp[i][0] = dp[i - 1][0] print(dp[-1][1])
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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) a.sort() b = [] c = [] for i in range(n): if a[i] >= 0: b = a[i:] break c.append(a[i]) r = sum(b) c = c[::-1] if r % 2 != 0: print(r) else: m = k = -10000000000.0 for i in b: if (r - i) % 2 != 0: k = r - i break for i in c: if (r + i) % 2 != 0: m = r + i break print(max(m, k))
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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) o1 = [] o2 = [] e1 = [] e2 = [] l = list(map(int, input().split())) for i in range(n): if l[i] % 2 == 0: if l[i] < 0: e1.append(l[i]) elif l[i] > 0: e2.append(l[i]) elif l[i] > 0: o2.append(l[i]) elif l[i] < 0: o1.append(l[i]) if len(o2) == 0: print(max(o1) + sum(e2)) elif len(o2) % 2 == 0: a2 = sum(o2) + sum(e2) - min(o2) if len(o1) > 0: a1 = sum(o2) + sum(e2) + max(o1) print(max(a1, a2)) else: print(a2) else: print(sum(o2) + sum(e2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
N = int(input()) A = [int(i) for i in input().split()] try: minposodd = min(a for a in A if a > 0 and a % 2) except ValueError: minposodd = None try: maxnegodd = max(a for a in A if a < 0 and a % 2) except ValueError: maxnegodd = None sm = sum(a for a in A if a > 0) if sm % 2: print(sm) else: best = float("-inf") if minposodd is not None: best = sm - minposodd if maxnegodd is not None: best = max(best, sm + maxnegodd) print(best)
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 VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NONE ASSIGN VAR BIN_OP VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) t = list(map(int, input().split())) s = sum(i for i in t if i > 0) if s % 2: print(s) else: m = [abs(i) for i in t if i % 2 == 1] print(s - min(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 FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
input() a = list(map(int, input().split())) s = 0 p, n = [i for i in a if i > 0], [j for j in a if j < 0] s = sum(p) if s % 2 == 1: print(s) else: m = -10000000 for x in sorted(n)[::-1]: if x % 2 == 1: m = x break for y in sorted(p): if y % 2 == 1: m = max(m, -y) print(s + m)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) op = float("inf") on = float("-inf") flag1 = 0 flag2 = 0 sum = 0 for i in l: if i > 0: sum += i if i % 2 != 0 and i > 0: flag1 = 1 op = min(op, i) elif i % 2 != 0 and i < 0: flag2 = 1 on = max(on, i) if flag1 == 0: op = 0 if flag2 == 0: on = 0 if sum == 0: ans = on elif sum % 2 != 0: ans = sum elif op != 0 and on != 0: ans = max(sum - op, sum + on) elif op != 0: ans = sum - op elif on != 0: ans = sum + on 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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) odds = 0 evens = 0 even_sum = 0 odd_sum = 0 ev_min = 100000 odd_min = 100000 neg_ev_max = -1000000 neg_odd_max = -1000000 for x in a: if x >= 0: if x % 2 == 0: even_sum += x evens += 1 ev_min = min(ev_min, x) else: odd_sum += x odd_min = min(x, odd_min) odds += 1 elif x % 2 == 0: neg_ev_max = max(x, neg_ev_max) else: neg_odd_max = max(x, neg_odd_max) ans = -100000000000 if odds > 0: ans = even_sum + odd_sum if odds % 2 == 0: ans = ans - odd_min if neg_odd_max != -1000000: ans = max(ans, ans + odd_min + neg_odd_max) if neg_odd_max != -1000000: ans = max(ans, even_sum + neg_odd_max, neg_odd_max) if neg_ev_max != -1000000: ans = max(ans, neg_odd_max + neg_ev_max) 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = [int(i) for i in input().split()] otrmax = -(10**4) - 1 polmin = 10**4 + 1 sm = 0 for i in a: if i < 0: if i > otrmax and i % 2 == 1: otrmax = i else: if i < polmin and i % 2 == 1: polmin = i sm += i if sm % 2 == 0: vrs = [] if polmin != 10 ^ 4 + 1: vrs.append(sm - polmin) if otrmax != -10 ^ 4 - 1: vrs.append(sm + otrmax) print(max(vrs)) else: print(sm)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) li = list(map(int, input().split())) pos_sum = 0 mop = False mon = False min_od = int(pow(10, 6)) max_od = int(pow(10, 6)) max_od *= -1 for i in range(n): if li[i] > 0: pos_sum += li[i] if li[i] % 2 != 0: mop = True min_od = min(min_od, li[i]) elif abs(li[i]) % 2 != 0: mon = True max_od = max(max_od, li[i]) if pos_sum % 2 != 0: print(pos_sum) elif mon == True and mop == True: print(max(pos_sum + max_od, pos_sum - min_od)) elif mon == True: print(pos_sum + max_od) else: print(pos_sum - min_od)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) li = list(map(int, input().split())) evensum, lis = 0, [] for i in li: if i > 0: evensum += i if i % 2 != 0: lis.append(abs(i)) print(evensum if evensum % 2 != 0 else evensum - min(lis))
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 LIST FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) p = 9999 ne = -9999 s = 0 for i in l: if i > 0: s += i if i % 2 == 1 and i < p: p = i elif i % 2 == 1 and i > ne: ne = i if s % 2 == 0: print(s - min(p, -ne)) else: 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
input() l = list(map(int, input().split())) l.sort(reverse=True) s = 0 beforeNeg = -(10**12) posEven = [x for x in l if x > 0 and x % 2 == 0] posOdd = [x for x in l if x > 0 and x % 2 != 0] posEven.sort() posOdd.sort() negOdd = [x for x in l if x < 0 and x % 2 != 0] negOdd.sort(reverse=True) if len(posOdd) % 2: print(sum(posOdd) + sum(posEven)) elif len(posOdd) > 0: if len(negOdd) > 0: if -negOdd[0] < posOdd[0]: print(sum(posOdd) + sum(posEven) + negOdd[0]) else: print(sum(posOdd[1:]) + sum(posEven)) else: print(sum(posOdd[1:]) + sum(posEven)) else: print(sum(posEven) + negOdd[0])
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) line = [int(x) for x in input().split()] m = -10001 ans = [] b = [] for i in line: if i % 2 == 0 and i > 0: ans.append(i) elif i % 2 != 0: if i > 0: ans.append(i) m = 0 else: b.append(i) if m < i: m = i ans.append(m) s = sum(ans) if s % 2 == 0: ans.sort() for i in ans: if i % 2 == 1: if len(b) > 0: s = max(s + max(b), s - i) else: s -= i break print(s)
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 LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().strip().split(" "))) s = 0 pos = [] neg = [] for i in arr: if i % 2 == 0: s += max(0, i) elif i >= 0: pos.append(i) else: neg.append(i) pos.sort(reverse=True) neg.sort(reverse=True) if len(pos) % 2 == 1: s += sum(pos[:]) elif len(pos) > 0: if len(neg) > 0: if pos[len(pos) - 1] > abs(neg[0]): s = s + sum(pos[:]) + neg[0] else: s += sum(pos[: len(pos) - 1]) elif len(pos) > 1: s += sum(pos[: len(pos) - 1]) else: s += pos[0] else: s += neg[0] print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER 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 BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().strip().split())) m = 2**31 res = 0 odd = False for i in range(n): if arr[i] > 0: res += arr[i] if arr[i] % 2 != 0: odd = True m = min(m, abs(arr[i])) if not odd: print(-1) else: if res % 2 == 0: res -= m print(res)
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 BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) INF = 10**10 even = 0 odd = [] one = -INF for x in a: if x % 2: odd.append(x) elif x > 0: even += x odd = list(reversed(sorted(odd))) ans = even + odd[0] i = 0 while i < len(odd): ans = max(even + odd[i], ans) if i < len(odd) - 1: if odd[i] + odd[i + 1] > 0: even += odd[i] + odd[i + 1] i += 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 ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
import sys n = int(input()) A = list(int(i) for i in input().split()) positiveeven = 0 positiveodd = 0 negativeeven = 0 negativeodd = 0 minpositiveodd = 10**18 maxnnegativeodd = -(10**18) for i in range(n): if A[i] % 2 == 0: if A[i] >= 0: positiveeven += A[i] else: negativeeven += A[i] elif A[i] >= 0: positiveodd += A[i] minpositiveodd = min(A[i], minpositiveodd) else: maxnnegativeodd = max(A[i], maxnnegativeodd) ans = positiveeven if positiveodd % 2 != 0: ans += positiveodd elif positiveodd > 0: ans1 = ans + positiveodd + maxnnegativeodd ans2 = ans + positiveodd - minpositiveodd ans = max(ans1, ans2) else: ans += maxnnegativeodd print(ans)
IMPORT 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) al = list(map(int, input().split())) alpp = [a for a in al if a > 0 and a % 2 == 0] s = sum(alpp) alpi = [a for a in al if a > 0 and a % 2 == 1] if len(alpi) % 2 == 0: if alpi: mini = min(alpi) s += sum(alpi) alni = [a for a in al if a < 0 and a % 2 == 1] if alni: maxi = max(alni) s += max(-mini, maxi) else: s -= mini else: s += sum(alpi) alni = [a for a in al if a < 0 and a % 2 == 1] maxi = max(alni) s += maxi else: s += sum(alpi) 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 VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().split())) i = 0 arr = sorted(arr, reverse=True) Sum = 0 while i < n and arr[i] > 0: Sum += arr[i] i += 1 if Sum % 2 == 1: print(Sum) else: k = i negSum = Sum while k < n and negSum % 2 == 0: if arr[k] % 2 == 1: negSum += arr[k] k += 1 posSum = Sum j = i - 1 while j >= 0 and posSum % 2 == 0: if arr[j] % 2 == 1: posSum -= arr[j] j -= 1 if posSum % 2 == 0 and negSum % 2 == 1: print(negSum) elif posSum % 2 == 1 and negSum % 2 == 0: print(posSum) else: print(max(posSum, negSum))
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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) x = sorted(map(int, input().split())) s = 0 odd = [] ev = [] for i in range(n): if x[i] % 2 == 0: if x[i] > 0: s += x[i] else: odd += [x[i]] s += odd[-1] j = len(odd) - 2 while j >= 1: if odd[j] + odd[j - 1] > 0: s += odd[j] + odd[j - 1] j -= 2 else: break 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 ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR LIST VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) ans = int(0) mx = int(-2000000000.0) for i in a: if i > 0: ans += i if ans % 2: print(ans) else: for i in a: if i < 0 and i % 2: mx = max(mx, ans + i) if i > 0 and i % 2: mx = max(mx, ans - i) print(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 NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().split())) max_odd_neg = -1000000000.0 for i in arr: if i < 0 and i % 2 == 1: max_odd_neg = max(max_odd_neg, i) min_pos_odd = 1000000000.0 for i in arr: if i > 0 and i % 2 == 1: min_pos_odd = min(min_pos_odd, i) s = 0 for i in arr: if i > 0: s += i if s % 2 == 1: print(s) else: print(max(s - min_pos_odd, s + max_odd_neg))
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 VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = input() A = list(map(int, list(a.split()))) e = [0] * n o = [0] * n if A[0] % 2 == 0: e[0] = A[0] else: o[0] = A[0] for i in range(1, n): if A[i] % 2 == 0: e[i] = max(A[i], A[i] + e[i - 1], e[i - 1]) if o[i - 1] != 0: o[i] = max(A[i] + o[i - 1], o[i - 1]) else: o[i] = o[i - 1] else: if o[i - 1] != 0: e[i] = max(A[i] + o[i - 1], e[i - 1]) else: e[i] = e[i - 1] if o[i - 1] != 0: o[i] = max(A[i], A[i] + e[i - 1], o[i - 1]) else: o[i] = max(A[i] + e[i - 1], A[i]) print(o[n - 1])
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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) ans = 0 min_odd = float("-inf") max_odd = float("inf") for i in a: if i > 0: ans += i if i % 2 != 0: if i < 0: min_odd = max(min_odd, i) else: max_odd = min(max_odd, i) if ans % 2 == 0: print(max(ans + min_odd, ans - max_odd)) else: 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 ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) s = 0 b = 0 c = 0 for i in a: if i > 0: s += i if i % 2 != 0: if b > 0: b = min(b, i) if b == 0: b = i if i < 0 and i % 2 != 0: if c < 0: c = max(c, i) if c == 0: c = i if s % 2 != 0: print(s) else: if (abs(c) < b or b == 0) and c != 0: s = s + c else: s = s - b 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) x = list(map(int, input().split())) odd_cnt = [] ans = 0 for i in range(n): if x[i] % 2 == 0 and x[i] > 0: ans += x[i] elif x[i] % 2 != 0: odd_cnt.append(x[i]) odd_cnt.sort(reverse=True) for j in range(len(odd_cnt)): if j == 0 and odd_cnt[j] < 0: ans += odd_cnt[j] elif odd_cnt[j] < 0 and ans % 2 == 0: if abs(odd_cnt[j]) > odd_cnt[j - 1]: ans -= odd_cnt[j - 1] else: ans += odd_cnt[j] break elif len(odd_cnt) % 2 == 0: if j == len(odd_cnt) - 1: break elif odd_cnt[j] > 0: ans += odd_cnt[j] else: if j % 2 == 0: ans -= odd_cnt[j - 1] break elif len(odd_cnt) % 2 != 0: if odd_cnt[j] > 0: ans += odd_cnt[j] else: if ans % 2 == 0: ans -= odd_cnt[j - 1] break if j == len(odd_cnt) - 1 and ans % 2 == 0: ans -= odd_cnt[j] 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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split(" "))) minus_odd = -10001 plus_odd = 10001 total = 0 for i in a: if i % 2: if i < 0: minus_odd = max(minus_odd, i) else: plus_odd = min(plus_odd, i) if i > 0: total += i if total % 2 == 0: if minus_odd == -10001: print(total - plus_odd) elif plus_odd == 10001: print(total + minus_odd) elif -minus_odd > plus_odd: print(total - plus_odd) else: print(total + minus_odd) else: print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
def LOS(L): sum1 = 0 for i in range(len(L)): if L[i] > 0: sum1 = sum1 + L[i] if sum1 % 2 != 0: return sum1 isodd = False min = 0 for i in range(len(L)): if isodd == False and L[i] % 2 != 0: isodd = True min = L[i] elif isodd == True and L[i] % 2 != 0 and abs(L[i]) < abs(min): min = L[i] return sum1 - abs(min) i = int(input("")) L = [x for x in input("").split()] for i in range(len(L)): L[i] = int(L[i]) print(LOS(L))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = [int(i) for i in input().split()] s = 0 for i in range(n): if arr[i] > 0: s += arr[i] if s % 2 != 0: print(s) else: m = 100000 for i in range(n): if arr[i] > 0 and arr[i] % 2 != 0: m = min(m, arr[i]) ans = s - m for i in range(n): if arr[i] < 0 and arr[i] % 2 != 0: ans = max(ans, s + arr[i]) 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 VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
tam = int(input()) numeros = [*map(int, input().split())] intMax = 1000000 soma = 0 m = intMax for e in numeros: if e > 0: soma += e if e % 2 != 0: m = min(m, abs(e)) if soma % 2 == 0: soma -= m print(soma)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
def makeodd(listt): c = 0 for r in range(len(listt)): if listt[r] % 2 == 0: listt[r] = "blah" c += 1 for e in range(c): listt.remove("blah") n = int(input()) inp = input() nums = inp.split(" ") for w in range(len(nums)): nums[w] = int(nums[w]) sum = 0 tsum = 0 neg = [] pos = [] an = False noTroll = True for i in range(n): if nums[i] > 0: sum += nums[i] pos.append(nums[i]) elif nums[i] < 0: neg.append(nums[i]) if sum % 2 == 1: print(sum) else: neg.sort() neg.reverse() pos.sort() makeodd(neg) makeodd(pos) z = 0 while sum % 2 == 0 and noTroll: if len(pos) > z and len(neg) > z: if pos[z] % 2 != 0 and pos[z] < neg[z] * -1: sum -= pos[z] break elif neg[z] % 2 != 0: for q in range(len(pos) - z): if pos[q + z] > neg[z] * -1 and pos[q + z] % 2 != 0: an = True break if an: sum += neg[z] break elif len(neg) > z: if neg[z] % 2 != 0: sum += neg[z] break elif len(pos) > z: if pos[z] % 2 != 0: sum -= pos[z] break z += 1 print(sum)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
from sys import stdin, stdout def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end="\n"): stdout.write(str(a) + end) def putf(a, sep=" ", end="\n"): stdout.write(sep.join(map(str, a)) + end) def main(): n = int(get()) a = getf() odPos = [] odNeg = [] xp, xn = 0, 0 sm = 0 for i in range(n): if a[i] % 2 == 0: if a[i] > 0: sm += a[i] elif a[i] > 0: odPos += [a[i]] xp += 1 else: odNeg += [a[i]] xn += 1 if xp % 2 == 1: sm += sum(odPos) elif xp == 0: sm += max(odNeg) elif xn == 0: sm += sum(odPos) - min(odPos) else: a, b = min(odPos), max(odNeg) if -b > a: sm += sum(odPos) - a else: sm += sum(odPos) + b put(sm) main()
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF STRING STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR LIST VAR VAR VAR NUMBER VAR LIST VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().split())) smallest_odd = 10**9 greatest_neg_odd = -(10**9) ans = 0 for i in arr: if i > 0: ans += i if i > 0 and i % 2 != 0: smallest_odd = min(smallest_odd, i) if i < 0 and i % 2 != 0: greatest_neg_odd = max(greatest_neg_odd, i) if ans % 2 != 0: print(ans) elif ans % 2 == 0: print(max(ans - smallest_odd, ans + greatest_neg_odd))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
_ = input() v = [int(x) for x in input().split()] neg_par = [] neg_impar = [] poz_par = [] poz_impar = [] for x in v: if x < 0: if x % 2 == 0: neg_par.append(x) else: neg_impar.append(x) elif x % 2 == 0: poz_par.append(x) else: poz_impar.append(x) neg_par.sort() neg_impar.sort() poz_par.sort() poz_impar.sort() res = sum(poz_par) if len(poz_impar) > 0: if len(poz_impar) % 2 == 1: res += sum(poz_impar) elif len(neg_impar) > 0 and neg_impar[-1] + poz_impar[0] > 0: res += sum(poz_impar) res += neg_impar[-1] else: res += sum(poz_impar[1:]) else: res += neg_impar[-1] print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) cn = sum([val for val in a if val % 2 == 0 and val > 0]) odd = [val for val in a if val & 1] odd.sort() if odd[-1] < 0: cn += odd[-1] else: pos = [val for val in odd if val > 0] neg = [val for val in odd if val < 0] sz = len(pos) cn += sum(pos[sz + 1 & 1 :]) if neg != [] and pos[0] + neg[-1] > 0 and sz + 1 & 1: cn += pos[0] + neg[-1] print(cn)
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 VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR LIST BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split(" "))) s = 0 od = [] od_neg = [] for i in range(n): if a[i] > 0: s += a[i] if a[i] > 0 and a[i] % 2: od.append(a[i]) elif a[i] < 0 and a[i] % 2: od_neg.append(a[i]) od.sort() od_neg.sort() if s % 2: print(s) elif od and od_neg: print(max(s - od[0], s + od_neg[-1])) elif od: print(s - od[0]) elif od_neg: print(s + od_neg[-1]) else: print(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = [int(i) for i in input().split()] sp = 0 for i in a: if i >= 0: sp += i if sp % 2 == 1: print(sp) else: v = list(filter(lambda x: x > 0 and x % 2 == 1, a)) if len(v) == 0: sm = -1000000000.0 else: sm = sp - min(v) for i in a: if i < 0 and i % 2 == 1: sm = max(sp + i, sm) print(sm)
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 VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) numbers = [int(i) for i in input().split()] l = 0 r = 0 positive = [i for i in numbers if i >= 0] negative = [i for i in numbers if i < 0] sumT = sum(positive) negative.sort(reverse=True) positive.sort() imparPositivo = 0 flag = False for v in positive: if v % 2 == 1: flag = True imparPositivo = v break if sumT % 2 != 1: for i in range(len(negative)): if negative[i] % 2 == 1: if flag: sumT -= min(imparPositivo, -negative[i]) else: sumT += negative[i] flag = False break if flag: sumT -= imparPositivo print(sumT)
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 VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) A = list(map(int, input().split())) p = [] m = [] for a in A: if a > 0: p.append(a) elif a < 0 and a % 2: m.append(a) if p: p.sort() sm = sum(p) else: sm = 0 if sm % 2: print(sm) exit() pcand = float("inf") if m: mcand = max(m) else: mcand = -float("inf") for pp in p: if pp % 2: pcand = pp break print(max(sm - pcand, sm + mcand))
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 IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) A = list(map(int, input().split())) sumpos = 0 maxoddneg = 100000000 minoddpos = 100000000 for i in A: if i > 0: sumpos += i if i % 2: minoddpos = min(minoddpos, i) elif i % 2: maxoddneg = min(-i, maxoddneg) if sumpos % 2: print(sumpos) else: print(sumpos - min(minoddpos, maxoddneg))
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 VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) su = 0 l1 = [] for x in l: if x % 2 == 0 and x > 0: su += x elif abs(x) % 2 != 0: l1.append(x) l1 = sorted(l1) l1 = l1[::-1] su += l1[0] for i in range(2, len(l1), 2): q = l1[i] + l1[i - 1] if q > 0: su += q print(su)
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 VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) A = [int(num) for num in input().split()] odd = sorted(list(filter(lambda t: t % 2 != 0, A)), reverse=True) even = sorted(list(filter(lambda t: t % 2 == 0, A)), reverse=True) max_ev = 0 i = 0 while i < len(even) and even[i] > 0: max_ev += even[i] i += 1 d = [] for j in odd: if d == []: d.append(j) else: d.append(j + d[-1]) i = 0 m_o = None while i < len(d): if m_o is None: m_o = d[i] elif d[i] > m_o: m_o = d[i] i += 2 if max_ev > 0: m_o += max_ev print(m_o)
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 FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) d = [] a.sort() e = [] for j in range(n): if a[j] >= 0: d.append(a[j]) else: e.append(a[j]) if len(d) == 0: for j in range(n - 1, -1, -1): if a[j] % 2 == 1: val = a[j] break else: s = sum(d) if s % 2 == 1: val = s else: flag = 0 s1 = s s2 = s for j in range(len(d)): if d[j] % 2 == 1: flag = 1 s1 -= d[j] break flag1 = 0 for j in range(len(e) - 1, -1, -1): if e[j] % 2 == 1: flag1 = 1 s2 += e[j] break if flag == 0: val = s2 elif flag1 == 0: val = s1 else: val = max(s1, s2) print(val)
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 EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
input() nums = sorted(int(x) for x in input().split()) s = 0 odds, s = [], 0 for n in nums: if n % 2 != 0: odds.append(n) elif n > 0: s += n cnt, last = 0, None while True: if not odds: break if odds[-1] < 0: break o = odds.pop(-1) s += o last = o cnt += 1 if last is None: print(s + odds[-1]) elif cnt % 2 != 0: print(s) elif not odds: print(s - last) else: print(s + (-last if -odds[-1] > last else odds[-1]))
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER NONE WHILE NUMBER IF VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) nas = min(map(abs, filter(lambda n: n % 2 == 1, l))) out = sum(filter(lambda n: n > 0, l)) if out % 2 == 0: print(out - nas) else: print(out)
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 FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
def main(): n = int(input()) a = list(map(int, input().split())) ans = sum(x for x in a if x > 0) if ans % 2 == 1: print(ans) return c = None for x in a: if x % 2 == 1: if c is None: c = abs(x) else: c = min(c, abs(x)) print(ans - c) main()
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 FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NONE FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = [int(m) for m in input().split()] b = [] ans = 0 for i in a: if i & 1: b.append(i) elif i > 0: ans += i b.sort(reverse=True) ans += b[0] L = len(b) for i in range(1, L, 2): if i + 1 >= L: break r = b[i] + b[i + 1] if r > 0: ans += r else: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) nums = list(map(int, input().split())) pos = [x for x in nums if x > 0] neg = [x for x in nums if x < 0] s1 = sum(pos) if s1 % 2 == 1: print(s1) exit() podd = [x for x in pos if x % 2 == 1] nodd = [x for x in neg if x % 2 == 1] if podd: min_podd = min(podd) if not nodd: s1 -= min_podd else: max_nodd = max(nodd) if min_podd + max_nodd > 0: s1 += max_nodd else: s1 -= min_podd else: s1 += max(nodd) print(s1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
def solve(n, arr): ans = 0 min_odd = float("inf") max_neg = float("-inf") for v in arr: if v < 0: if abs(v) % 2 == 1: max_neg = max(max_neg, v) else: ans += v if v % 2 == 1: min_odd = min(min_odd, v) if ans % 2 == 0: ans -= min(min_odd, -max_neg) print(ans) n = int(input()) arr = list(map(int, input().split())) solve(n, arr)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR EXPR 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 EXPR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = [int(s) for s in input().split()] ap = [x for x in a if x > 0] ap.sort() bp = [(x % 2) for x in ap] ao = [x for x in a if x < 0] ao.sort() ao.reverse() bo = [(x % 2) for x in ao] s = sum(ap) cp = bp.count(1) co = bo.count(1) if cp % 2 == 1: print(s) elif cp > 0: if co > 0: print(max(s + ao[bo.index(1)], s - ap[bp.index(1)])) else: print(s - ap[bp.index(1)]) else: print(s + ao[bo.index(1)])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) l1, l2, l1e, l1o, l2e, l2o = [], [], [], [], [], [] for i in range(len(l)): if l[i] >= 0: l1.append(l[i]) else: l2.append(l[i]) for i in range(len(l)): if l[i] >= 0 and l[i] % 2 == 0 and l[i] != 0: l1e.append(l[i]) elif l[i] >= 0 and l[i] % 2 != 0 and l[i] != 0: l1o.append(l[i]) elif l[i] < 0 and l[i] % 2 == 0 and l[i] != 0: l2e.append(l[i]) elif l[i] < 0 and l[i] % 2 != 0 and l[i] != 0: l2o.append(l[i]) l1.sort() l2.sort() l1o.sort() l1e.sort() l2o.sort() l2e.sort() if sum(l1) % 2 != 0: print(sum(l1)) elif len(l1o) != 0 and len(l2o) != 0: print(sum(l1) - min(min(l1o), abs(max(l2o)))) elif len(l1o) != 0 and len(l2o) == 0: print(sum(l1) - min(l1o)) else: print(sum(l1) - abs(max(l2o)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR LIST LIST LIST LIST LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(n): if a[i] > 0: ans += a[i] if ans % 2 != 0: print(ans) else: x = [i for i in a if i % 2 != 0 and i < 0] y = [i for i in a if i % 2 != 0 and i > 0] x = sorted(x) y = sorted(y) if x and y: if abs(x[-1]) > abs(y[0]): print(ans - y[0]) else: print(ans + x[-1]) elif y: print(ans - y[0]) elif x: print(ans + x[-1]) else: print(-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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
from sys import exit negative = [] positive = [] n = int(input()) total = 0 for i in input().split(): a = int(i) if a > 0: positive.append(a) total += a else: negative.append(-a) if total % 2 == 1: print(total) exit(0) positive.sort() negative.sort() a1 = 10000007 a2 = 10000007 for i in range(0, len(positive)): if positive[i] % 2 == 1: a1 = positive[i] break for i in range(0, len(negative)): if negative[i] % 2 == 1: a2 = negative[i] break if a1 < a2: print(total - a1) else: print(total - a2)
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = input().split() s = 0 mc = 10001 mn = -10001 for i in a: i = int(i) if i > 0: s += i if i % 2 != 0 and i < mc: mc = i elif i > mn and i % 2 != 0: mn = i if s % 2 != 0: print(s) elif s == 0: print(mn) else: print(s - min(mc, mn * -1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = [int(i) for i in input().split()] mn = 20000 s = 0 for k in a: if k > 0: s += k if k % 2 == 1: mn = min(mn, k) elif k % 2 == 1: mn = min(mn, abs(k)) if s % 2 == 1: print(s) else: print(s - mn)
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 FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) ls = list(map(int, input().split())) pos_sum = sum(list(filter(lambda x: x > 0, ls))) ls = list(map(abs, ls)) ls = list(filter(lambda x: x % 2 != 0, ls)) if pos_sum % 2 != 0: print(pos_sum) else: print(pos_sum - min(ls))
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 FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().strip().split())) minOddPos = float("inf") minOddNeg = -float("inf") posSumi = 0 for i in arr: if i > 0: if i % 2: minOddPos = min(minOddPos, i) posSumi += i elif i % 2: minOddNeg = max(minOddNeg, i) if posSumi > 0: if posSumi % 2: print(posSumi) elif minOddNeg != -float("inf") and minOddPos != float("inf"): print(posSumi - min(abs(minOddNeg), minOddPos)) elif minOddNeg != -float("inf"): print(posSumi + minOddNeg) else: print(posSumi - minOddPos) else: print(minOddNeg)
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 STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
import sys n = int(input()) a = list(map(int, input().split())) minf = -(2 * 10**9) dp = [([minf] * 2) for _ in range(n + 1)] dp[0][0] = 0 for i, x in enumerate(a): dp[i + 1][0 + x & 1] = max(dp[i][0 + x & 1], dp[i + 1][0 + x & 1], dp[i][0] + x) dp[i + 1][1 + x & 1] = max(dp[i][1 + x & 1], dp[i + 1][1 + x & 1], dp[i][1] + x) print(dp[-1][1])
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
a = int(input()) z = list(map(int, input().split())) oddp = [] eve = [] oddn = [] for i in range(len(z)): if z[i] % 2 == 0 and z[i] > 0: eve.append(z[i]) elif z[i] % 2 == 1: if z[i] > 0: oddp.append(z[i]) else: oddn.append(z[i]) if len(oddp) == 0: print(max(oddn) + sum(eve)) elif len(oddp) % 2 == 1: print(sum(oddp) + sum(eve)) else: oddp.sort() if len(oddn) == 0: print(sum(oddp) - oddp[0] + sum(eve)) elif len(oddp) == 0: print(min(oddn) + sum(eve)) else: print(max(max(oddn) + sum(oddp), sum(oddp) - oddp[0]) + sum(eve))
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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
import sys n = int(input()) x = list(map(int, input().strip().split()))[:n] sum = 0 for i in x: if i > 0: sum += i if sum % 2 == 1: print(sum) else: sum1 = sum ans1 = -sys.maxsize for i in x: if i < 0 and i % 2 == 1: ans1 = max(ans1, i) sum1 += ans1 sum2 = sum ans2 = sys.maxsize for i in x: if i > 0 and i % 2 == 1: ans2 = min(ans2, i) sum2 -= ans2 print(max(sum1, sum2))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
import sys input = sys.stdin.readline n = int(input()) a = [int(x) for x in input().split(" ")] dp = [(0, -float("inf"))] for i in range(n): if a[i] % 2 == 0: dp.append((max(a[i], 0) + dp[-1][0], max(a[i], 0) + dp[-1][1])) else: dp.append((max(dp[-1][0], dp[-1][1] + a[i]), max(dp[-1][1], dp[-1][0] + a[i]))) print(dp[-1][1])
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
import sys n = int(sys.stdin.readline()) l = list(map(int, sys.stdin.readline().split())) ans = 0 for i in range(n): if l[i] > 0: ans += l[i] max_odd_neg = -(10**5) min_odd_pos = 10**5 for i in range(n): if l[i] % 2 == 1: if l[i] > 0: min_odd_pos = min(min_odd_pos, l[i]) elif l[i] < 0: max_odd_neg = max(max_odd_neg, l[i]) if ans % 2 == 0: ans -= min(min_odd_pos, -max_odd_neg) print(ans)
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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) sum_l = int(0) m1, m2 = -(10**5), 10**5 for ele in l: if ele > 0: sum_l += ele if ele % 2 != 0: if ele < 0: m1 = max(m1, ele) else: m2 = min(m2, ele) if sum_l % 2 != 0: print(sum_l) else: if m1 != -(10**5) and m2 != 10**5: if abs(m1) < abs(m2): sum_l += m1 else: sum_l -= m2 elif m1 != -(10**5): sum_l += m1 else: sum_l -= m2 print(sum_l)
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 NUMBER ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: list(map(int, input().split())) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n = ii() l = il() dpeve = [0] * (n + 1) dpodd = [0] * (n + 1) if l[0] & 1: dpodd[0] = l[0] dpeve[0] = 0 else: dpeve[0] = l[0] dpodd[0] = -(10**10) for i in range(1, n): if l[i] & 1: dpodd[i] = max(l[i], dpodd[i - 1], dpeve[i - 1] + l[i]) dpeve[i] = max(dpodd[i - 1] + l[i], dpeve[i - 1]) else: dpodd[i] = max(l[i] + dpodd[i - 1], dpodd[i - 1]) dpeve[i] = max(l[i], dpeve[i - 1], dpeve[i - 1] + l[i]) print(dpodd[n - 1])
ASSIGN VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
from itertools import chain, compress, islice def f(s): s = [int(x) for x in s.split(" ")] even = [x for x in s if x % 2 == 0 and x > 0] odd = [x for x in s if x % 2 == 1] odd.sort() odd.reverse() _sum = odd[0] if len(odd) else 0 i = 1 while i + 1 < len(odd): t_sum = odd[i] + odd[i + 1] if t_sum < 0: break _sum += t_sum i += 2 return sum(even) + _sum input() print(f(input()))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
def meu_map(l): for i in range(len(l)): l[i] = int(l[i]) def f(n, array): impares = [] primeiro = True maior_negativo = 0 for i in range(len(array) - 1, -1, -1): if array[i] % 2 == 1 or array[i] % 2 == -1: if array[i] < 0: if primeiro: impares.append(array[i]) break else: maior_negativo = array[i] break impares.append(array[i]) primeiro = False soma = 0 for e in impares: soma += e if soma % 2 == 0: if maior_negativo == 0: soma = soma - impares[-1] else: soma = max(soma + maior_negativo, soma - impares[-1]) for i in range(len(array) - 1, -1, -1): if array[i] < 0: break if array[i] % 2 == 0: soma += array[i] return soma n = int(input()) array = input().split() meu_map(array) array.sort() print(f(n, array))
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split(" "))) odd = [None] * n even = [None] * n is_odd = lambda x: True if x % 2 else False if is_odd(a[0]): odd[0] = a[0] else: even[0] = a[0] def my_sum(a, b): if a is None: return b if b is None: return a return a + b def my_max(*args): nn = list(filter(lambda x: x is not None, args)) if len(nn): return max(nn) return None for i in range(1, n): if is_odd(a[i]): odd[i] = my_max(my_sum(even[i - 1], a[i]), odd[i - 1], a[i]) even[i] = my_max( odd[i - 1] + a[i] if odd[i - 1] is not None else None, even[i - 1] ) else: odd[i] = my_max( odd[i - 1] + a[i] if odd[i - 1] is not None else None, odd[i - 1] ) even[i] = my_max(my_sum(even[i - 1], a[i]), even[i - 1], a[i]) print(odd[-1])
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 BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FUNC_DEF IF VAR NONE RETURN VAR IF VAR NONE RETURN VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NONE VAR IF FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN NONE FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NONE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NONE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NONE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NONE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) s = 0 neg = -10000 pos = 10000 for i in range(n): if a[i] % 2: if a[i] < 0: neg = max(a[i], neg) else: pos = min(a[i], pos) if a[i] > 0: s += a[i] if neg % 2 == 0: neg = 10000 if pos % 2 == 0: pos = 10000 if s % 2 == 0: s -= min(abs(neg), pos) 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) ar = list(map(int, input().split())) odd = [i for i in ar if i % 2 == 1] even = [i for i in ar if i % 2 == 0] odd.sort(reverse=True) even.sort(reverse=True) sum_even = 0 for i in even: if i > 0: sum_even += i preSum = [] preSum.append(odd[0]) for i in range(1, len(odd)): preSum.append(preSum[i - 1] + odd[i]) max_odd_sum = preSum[0] for i in range(2, len(odd), 2): max_odd_sum = max(max_odd_sum, preSum[i]) print(max(max_odd_sum + sum_even, max_odd_sum))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) lis = list(map(int, input().split())) pe = [] po = [] ne = [] no = [] for i in lis: if i > 0 and i % 2: po.append(i) elif i > 0 and i % 2 == 0: pe.append(i) elif i < 0 and i % 2: no.append(i) else: ne.append(i) po.sort() pe.sort() no.sort() ne.sort() if len(po) >= 1 and len(po) % 2: print(sum(po) + sum(pe)) elif len(po) >= 1 and len(po) % 2 == 0: aa = sum(pe) + sum(po[1:]) bb = 0 if len(no) >= 1: bb = sum(pe) + sum(po) + no[-1] print(max(aa, bb)) else: print(sum(pe) + no[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) s = 0 p = 99999999 q = -9999999 for i in range(n): if a[i] > 0: s += a[i] if a[i] < 0 and a[i] > q and a[i] % 2 != 0: q = a[i] if a[i] > 0 and a[i] < p and a[i] % 2 != 0: p = a[i] if s % 2 == 0: print(max(s + q, s - p)) else: 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) s = input() s = s.split() l = [] o = [] on = [] sum = 0 for i in s: te = int(i) l.append(te) if te > 0 and te % 2 == 1: o.append(te) elif te > 0 and te % 2 == 0: sum += te elif te < 0 and te % 2 == 1: on.append(te) o.sort(reverse=True) on.sort(reverse=True) ko = 0 for i in on: if i % 2 == 1: ko = i break j = 2 sumo = 0 if len(o) > 0: sumo = o[0] while j < len(o): sumo += o[j] + o[j - 1] j += 2 if len(o) == 0: print(sum + ko) elif len(o) % 2 == 1: print(sum + sumo) elif len(o) % 2 == 0: if len(on) > 0 and ko < 0: print(max(sum + sumo, sum + sumo + ko + o[-1])) elif len(on) > 0 and ko == 0: print(sum + sumo) else: print(sum + sumo)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) maxOdd, maxEven = -1000000001, 0 for x in map(int, input().split()): if x % 2 == 1: maxOdd, maxEven = max(maxOdd, maxEven + x), max(maxEven, maxOdd + x) elif x > 0: maxOdd += x maxEven += x print(maxOdd)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = [int(i) for i in input().split()] l.sort() a = 0 for i in l: if i > 0: a += i x = float("inf") y = -1 * x if a % 2 == 0: for i in l: if i % 2 != 0 and i < 0: y = max(y, i) elif i % 2 != 0 and i > 0: x = min(x, i) a -= min(x, -1 * y) print(a)
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 FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().split())) s = sum([a for a in arr if a > 0]) if s % 2 == 1: print(s) else: mn_odd = 10001 for ele in arr: if ele % 2 == 1 and ele > 0: mn_odd = min(mn_odd, ele) mx_odd = -10001 for ele in arr: if ele % 2 == 1 and ele < 0: mx_odd = max(mx_odd, ele) print(max(s - mn_odd, s + mx_odd))
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 VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) res = 0 new_a = [] for i in range(n): if a[i] % 2 == 0: if a[i] > 0: res += a[i] else: new_a.append(a[i]) a = new_a a.sort() res += a[-1] a.pop() while len(a) > 1: if a[-1] + a[-2] > 0: res += a[-1] + a[-2] a.pop() a.pop() else: break print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().strip().split())) c = 0 d = [] for i in range(n): if a[i] % 2 == 0: if a[i] > 0: c += a[i] else: d.append(a[i]) d.sort(reverse=True) c += d[0] i = 1 while i < len(d) - 1: if d[i] + d[i + 1] > 0: c += d[i] + d[i + 1] i += 2 else: i = len(d) print(c)
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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) pe = [] po = [] ne = [] no = [] for i in range(n): if a[i] > 0 and a[i] % 2 == 0: pe.append(a[i]) if a[i] > 0 and a[i] % 2 != 0: po.append(a[i]) if a[i] < 0 and a[i] % 2 == 0: ne.append(a[i]) if a[i] < 0 and a[i] % 2 != 0: no.append(a[i]) if (sum(pe) + sum(po)) % 2 != 0: print(sum(pe) + sum(po)) else: b = [] if len(no) > 0: b.append(sum(pe) + sum(po) + max(no)) if len(po) > 0: b.append(sum(pe) + sum(po) - min(po)) print(max(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 LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
from sys import stderr, stdin def find(A): big = 0 for i in range(len(A)): if A[i] > 0: big += A[i] if big % 2 == 1: return big else: minodd = 10**10 for i in range(len(A)): if A[i] % 2 == 1: if A[i] > 0 and A[i] < minodd: minodd = A[i] maxodd = -(10**10) for i in range(len(A)): if A[i] % 2 == 1 and A[i] < 0: if A[i] > maxodd: maxodd = A[i] if minodd == 10**10: return big + maxodd elif maxodd == -(10**10): return big - minodd else: return max(big - minodd, big + maxodd) n = int(input()) A = list(map(int, input().strip().split(" "))) print(find(A))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER RETURN BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER RETURN BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input().strip()) ais = list(map(int, input().strip().split())) def solve(n, ais): s = sum(a for a in ais if a >= 0) if s % 2 == 1: return s maxoddneg = max([a for a in ais if a % 2 == 1 and a < 0], default=0) minoddpos = min([a for a in ais if a % 2 == 1 and a > 0], default=0) v = [-maxoddneg, minoddpos] v = [e for e in v if e != 0] return s - min(v) res = solve(n, ais) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
le = int(input()) seq = input().split() neg = -(10**4 + 1) odd = 0 z = 0 min_odd = 10**4 for i in seq: if int(i) > 0 and int(i) % 2 == 0: z += int(i) elif int(i) > 0 and int(i) % 2 == 1: odd += int(i) if int(i) < min_odd: min_odd = int(i) elif int(i) < 0 and int(i) % 2 == 1: if neg < int(i): neg = int(i) if (z + odd) % 2 == 1: print(z + odd) else: print(odd + z - min(min_odd, -neg))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) A = list(map(int, input().split())) dp = [[-9999999999, -9999999999]] for elem in A: dp += [[0, 0]] if elem % 2 == 0: dp[-1][0] = max(dp[-2][0] + elem, dp[-2][0], elem) dp[-1][1] = max(dp[-2][1] + elem, dp[-2][1]) else: dp[-1][0] = max(dp[-2][1] + elem, dp[-2][0]) dp[-1][1] = max(dp[-2][0] + elem, dp[-2][1], elem) print(dp[-1][1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR VAR VAR LIST LIST NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) arr = list(map(int, input().split())) res = sum(filter(lambda x: x > 0, arr)) if res & 1 == 0: delta = abs(min(filter(lambda x: x & 1, arr), key=abs)) res -= delta print(res)
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 NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) f = 0 for i in range(n): if a[i] >= 0: f += a[i] if f % 2: print(f) else: m = 10**9 for i in range(n): if a[i] % 2: m = min(m, abs(a[i])) print(f - m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) l = list(map(int, input().split())) l1 = [] l2 = [] l3 = [] l4 = [] for i in l: if i > 0: if i % 2 == 0: l1.append(i) else: l2.append(i) elif i < 0: if i % 2 == 0: l3.append(i) else: l4.append(i) l1.sort() l2.sort() l3.sort() l4.sort() ans = sum(l1) + sum(l2) if ans % 2 != 0: print(ans) elif len(l4) != 0 and len(l2) != 0: if l2[0] > abs(l4[-1]): print(ans + l4[-1]) else: print(ans - l2[0]) elif len(l4) == 0 and len(l2) != 0: print(ans - l2[0]) elif len(l4) != 0 and len(l2) == 0: print(ans + l4[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) neg = list() pos = list() for i in range(n): if a[i] < 0: neg.append(a[i]) elif a[i] > 0: pos.append(a[i]) sn = sum(pos) mnp = 100000 mxn = -100000 for i in range(len(neg)): if neg[i] % 2 == 1 and neg[i] > mxn: mxn = neg[i] for j in range(len(pos)): if pos[j] % 2 == 1 and pos[j] < mnp: mnp = pos[j] mxn *= -1 if sn % 2 == 0: print(sn - min(mnp, mxn)) else: print(sn)
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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) s = 0 for i in range(n): if a[i] > 0: s += a[i] else: break if s % 2: print(s) else: mx = -100000 for i in range(n): if a[i] < 0 and a[i] % 2: mx = max(a[i], mx) mn = 100000 for i in range(n): if a[i] >= 0 and a[i] % 2: mn = min(a[i], mn) print(max(s + mx, s - mn))
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. -----Input----- The first line contains integer number n (1 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4). The sequence contains at least one subsequence with odd sum. -----Output----- Print sum of resulting subseqeuence. -----Examples----- Input 4 -2 2 -3 1 Output 3 Input 3 2 -5 -3 Output -1 -----Note----- In the first example sum of the second and the fourth elements is 3.
def max(a, b): if a > b: return a else: return b def min(a, b): if a < b: return a else: return b def __starting_point(): n = int(input()) A = input().split(" ") ans, count, Min, Max = 0, 0, 1000000000, -100000000000 for i in range(n): now = int(A[i]) if now % 2 == 0: ans += max(now, 0) elif now < 0: Max = max(Max, now) else: Min = min(Min, now) ans += now if ans % 2 == 0: ans = max(ans - Min, ans + Max) print(ans) __starting_point()
FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR