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()) a = list(map(int, input().split())) c = list(filter(lambda x: x % 2 == 0 and x > 0, a)) b = list(filter(lambda x: x % 2 != 0, a)) b = sorted(b, reverse=True) mm = int(-10000000000.0) s = 0 for i in range(len(b)): s += b[i] if i % 2 == 0: mm = max(mm, s) print(sum(c) + mm)
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 BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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()) posdd = [] odd = [] even = 0 t = list(map(int, input().split())) for j in range(n): if abs(t[j]) % 2 == 0: if t[j] > 0: even += t[j] elif t[j] > 0: posdd.append(t[j]) even += t[j] else: odd.append(t[j]) if even % 2: print(even) else: u = 99999999999 if len(odd) > 0: u = min(u, -max(odd)) if len(posdd) > 0: u = min(u, min(posdd)) print(even - u)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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())) odd = [] oddp = [] even = [] for i in a: if i % 2 == 0: if i > 0: even.append(i) elif i > 0: oddp.append(i) else: odd.append(i) odd = sorted(odd) oddp = sorted(oddp) s = sum(even) if len(oddp) > 0: if len(oddp) % 2 != 0: print(sum(oddp) + s) elif len(odd) == 0: print(sum(oddp) - oddp[0] + s) else: print(max(sum(oddp) - oddp[0], sum(oddp) + odd[-1]) + s) else: print(s + odd[-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 FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR 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()) lst = [int(x) for x in input().split(" ")] even = list(filter(lambda x: x % 2 == 0, lst)) odd = list(filter(lambda x: x % 2 != 0, lst)) even_sum = 0 for i in even: if i > 0: even_sum += i odd = reversed(sorted(odd)) possible = [] rolling = 0 for i in odd: rolling += i possible.append(even_sum + rolling) possible = reversed(sorted(possible)) for i in possible: if i % 2 != 0: print(i) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER 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 = [int(i) for i in input().split()] s = 0 for i in a: if i > 0: s += i if s % 2 == 1: print(s) else: maxot = -100000000000000 for i in a: if i % 2 == 1 and i < 0 and i >= maxot: maxot = i minpo = 10000000000000000 for i in a: if i > 0 and i % 2 == 1 and i <= minpo: minpo = i if (s + maxot) % 2 == 0: print(s - minpo) elif (s - minpo) % 2 == 0: print(s + maxot) else: print(max(s + maxot, s - minpo))
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 NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP 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.
amount = input() cases = input() cases = cases.split() cases = list(map(int, cases)) minOdd = +2147483 sum = 0 for i in range(int(amount)): if cases[i] > 0: sum = sum + cases[i] if cases[i] % 2 != 0: if minOdd > abs(cases[i]): minOdd = abs(cases[i]) if sum % 2 == 0: sum = sum - minOdd print(sum)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER 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 VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER 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())) mini = 9999 sum = 0 for i in a: if i > 0: sum += i if i % 2 != 0: if abs(i) < mini: mini = abs(i) if sum % 2 == 0: sum = sum - mini print(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 NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER 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()) l = list(map(int, input().split())) c = [[], []] for i in l: c[i % 2].append(i) c[0].sort() c[1].sort() ans = 0 for i in c[0]: if i > 0: ans += i ans += c[1][-1] for i in range(len(c[1]) - 2, 0, -2): ans = max(ans, ans + c[1][i] + c[1][i - 1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP 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()) max_even = -10002 max_odd = -10001 l = [int(x) for x in input().split()] for i in l: if i % 2 == 1: a, b = max(max_odd, i, max_even + i), max(max_even, max_odd + i) max_odd = a max_even = b else: a, b = max(max_odd, max_odd + i), max(max_even, max_even + i, i) max_odd = a max_even = b print(max_odd)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN 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.
len = int(input()) a = list(map(int, input().split())) a.sort() sum = 0 for i in range(len): if a[~i] < 0: break sum += a[~i] if sum % 2 == 1: print(sum) exit() a = sorted(list(map(abs, a))) for i in range(len): if a[i] % 2 == 1: sum -= a[i] break print(sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR 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()) l = list(map(int, input().split())) odd = [] even = [] for i in range(n): if l[i] % 2 == 0: if l[i] > 0: even.append(l[i]) else: odd.append(l[i]) odd.sort(reverse=True) even.sort(reverse=True) ans = 0 for i in range(len(odd)): if odd[i] < 0: if ans == 0: ans += odd[i] break else: if i % 2 == 0: if abs(odd[i - 1]) < abs(odd[i]): ans -= odd[i - 1] else: ans += odd[i] break else: ans += odd[i] if odd[-1] >= 0 and len(odd) % 2 == 0: ans -= odd[-1] print(ans + sum(even))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR 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() l = list(map(int, input().split())) pos = [] neg = [] for num in l: if num < 0: neg.append(num) else: pos.append(num) neg.sort() pos.sort() total = sum(pos) if total % 2 == 1: print(total) else: lowest = 10**10 for num in pos: if num % 2 == 1 and num < lowest: lowest = num highest = -(10**10) for num in neg: if -num % 2 == 1 and num > highest: highest = num temp = min(-highest, lowest) print(total - temp)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR 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.
import sys input() arr = list(map(int, input().split())) negs = sorted([x for x in arr if x < 0]) poss = sorted([x for x in arr if x > 0]) r = sum(poss) if r % 2 == 1: print(r) sys.exit(0) pos = [x for x in poss if x % 2 == 1] pes = [x for x in poss if x % 2 == 0] nos = [x for x in negs if x % 2 == 1] nes = [x for x in negs if x % 2 == 0] if not nos and not nes: print(r - pos[0]) elif not pos and not pes: print(0 + nos[-1]) elif not pos: print(r + nos[-1]) elif not nos: print(r - pos[0]) else: print(r - min(pos[0], -nos[-1]))
IMPORT EXPR 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 ASSIGN VAR FUNC_CALL 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 NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER 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 BIN_OP VAR FUNC_CALL VAR VAR NUMBER 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.
import sys n = int(sys.stdin.readline()) l = list(map(int, sys.stdin.readline().split())) b = [] c = [] d = [] for i in range(0, n): if l[i] % 2 == 0 and l[i] >= 0: b.append(l[i]) elif l[i] % 2 != 0 and l[i] >= 0: c.append(l[i]) elif l[i] % 2 != 0: d.append(l[i]) k = len(c) sum1 = 0 if k == 0: sum1 += sum(b) else: sum1 += sum(b) + sum(c) c.sort() kk = len(d) if kk != 0: d.sort() if k % 2 != 0: print(sum1) elif k == 0: sum1 += d[kk - 1] print(sum1) elif kk == 0: sum1 -= c[0] print(sum1) else: p = d[0] pp = c[0] sum2 = max(sum1 + d[kk - 1], sum1 - c[0]) print(sum2)
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 LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP 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 = [int(x) for x in input().split()] s = 0 r = -(10**5) minodd = 10**5 minminodd = -(10**5) for i in range(n): if a[i] > 0: s += a[i] if a[i] & 1 and a[i] < minodd: minodd = a[i] if a[i] < 0 and a[i] > minminodd and a[i] & 1: minminodd = a[i] if s > 0 and s & 1: print(s) elif minodd == 0: print(minminodd) else: print(max(s - minodd, s + minminodd))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR 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.
def readInts(): num = [] for c in input().strip().split(): num.append(int(c)) return num def solve(num): minOdd = 10000000 maxNegOdd = -10000000 sum = 0 for x in num: if x > 0: sum = sum + x if x & 1: minOdd = min(minOdd, x) elif x & 1: maxNegOdd = max(maxNegOdd, x) if sum & 1: return sum if minOdd != 10000000 and maxNegOdd == -10000000: return sum - minOdd if maxNegOdd != -10000000 and minOdd == 10000000: return sum + maxNegOdd return max(sum - minOdd, sum + maxNegOdd) n = int(input().strip()) num = readInts() print(solve(num))
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP 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 RETURN VAR IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR IF VAR NUMBER VAR 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 FUNC_CALL VAR ASSIGN VAR 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())) a.sort(key=lambda x: -x) s_p = sum(filter(lambda x: x > 0, a)) if s_p % 2 == 1: print(s_p) else: m_p = list(filter(lambda x: x > 0 and x % 2 == 1, a)) m_n = list(filter(lambda x: x < 0 and x % 2 == 1, a)) if len(m_p) > 0 and len(m_n) > 0: s_p += max(-min(m_p), max(m_n)) elif len(m_p) == 0 and len(m_n) > 0: s_p += max(m_n) else: s_p += -min(m_p) print(s_p)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER 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()) inp = list(map(int, input().split())) poseven = [] posodd = [] negeven = [] negodd = [] for item in inp: if item < 0 and item % 2 == 0: negeven.append(item) elif item < 0 and item % 2 == 1: negodd.append(item) elif item > 0 and item % 2 == 0: poseven.append(item) elif item > 0 and item % 2 == 1: posodd.append(item) sumi = 0 sumi = sumi + sum(posodd) + sum(poseven) if sumi % 2 == 0: if len(negodd) > 0: if len(posodd) > 0: sumi = max(sumi + max(negodd), sumi - min(posodd)) else: sumi = sumi + max(negodd) else: sumi = sumi - min(posodd) print(sumi) else: print(sumi)
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 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 NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR 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.
x = int(input()) lista = list(map(int, input().split())) ans = 0 impares = [] for i in range(x): if lista[i] > 0 and lista[i] % 2 == 0: ans += lista[i] elif lista[i] % 2 != 0: impares.append(lista[i]) som_imp = [(0) for i in range(len(impares))] impares.sort() impares.reverse() som_imp[0] = impares[0] for i in range(1, len(impares)): som_imp[i] += impares[i] + som_imp[i - 1] som_fin = [] k = -1000000000000 for i in range(0, len(som_imp), 2): k = max(som_imp[i], k) ans += k 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 LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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()) vals = input().split() a_list = [int(val) for val in vals] max_even = None max_odd = None for a in a_list: me = max_even mo = max_odd if a % 2 == 0: if mo is not None: max_odd = max(mo, mo + a) if me is not None: max_even = max(me, a, me + a) else: max_even = a elif me is None and mo is None: max_odd = a elif me is None: max_odd = max(mo, a) max_even = mo + a elif mo is None: max_odd = max(me + a, a) else: max_odd = max(mo, me + a, a) max_even = max(me, mo + a) print(max_odd)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NONE VAR NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR 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 = list(map(int, input().split())) even = [] odd = [] for i in a: if i & 1: odd.append(i) else: even.append(i) odd.sort(reverse=True) even.sort(reverse=True) ans = 0 for i in even: if i < 0: break ans += i ocount = 0 for i in range(len(odd)): if odd[i] >= 0: ans += odd[i] ocount += 1 elif odd[i] < 0 and not ocount & 1: if ocount == 0: ans += odd[i] break elif odd[i - 1] < abs(odd[i]): ans -= odd[i - 1] break else: ans += odd[i] break if not ans & 1: ans -= odd[-1] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP 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()) seq = input().split(" ") summ = 0 arr = [] minPosOdd = +999999999999999999999999999999999999 foundOdd = False for i in seq: arr.append(int(i)) for i in range(n): if arr[i] > 0: summ = summ + arr[i] if arr[i] % 2 != 0: foundOdd = True if arr[i] > 0: minPosOdd = min(minPosOdd, arr[i]) else: minPosOdd = min(minPosOdd, -1 * arr[i]) if summ % 2 == 0: summ = summ - minPosOdd print(summ)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR IF BIN_OP VAR NUMBER 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()) array = list(map(int, input().split())) array.sort() array.reverse() odd = 0 odde = [] for k in range(n): if array[k] % 2 == 0 and array[k] > 0: odd += array[k] elif array[k] % 2 == 1: odde.append(array[k]) odd += odde[0] m = len(odde) i = 2 while m - i > 0: if odde[i - 1] + odde[i] > 0: odd += odde[i - 1] + odde[i] i += 2 print(odd)
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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST 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 VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER 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.
n = int(input()) l = list(map(int, input().split(" "))) l_even = [] l_odd = [] for i in l: if i % 2 == 0: if i > 0: l_even.append(i) else: l_odd.append(i) sum_even = sum(l_even) l_odd.sort() countt = 0 index = -999 tt = 0 l2 = [] for i in range(len(l_odd)): if l_odd[i] < 0: index = i if l_odd[i] > 0: countt += 1 l2.append(l_odd[i]) if countt == 0: print(sum_even + l_odd[index]) elif countt % 2 != 0: print(sum_even + sum(l2)) elif countt % 2 == 0: if index == -999 or l2[0] <= abs(l_odd[index]): del l2[0] print(sum_even + sum(l2)) elif l2[0] > abs(l_odd[index]): print(sum_even + sum(l2) + l_odd[index])
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 LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR 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())) s = [] s2 = [] for i in a: if i > 0: s.append(i) elif i < 0: s2.append(i) s.sort() s2 = sorted(s2)[::-1] if sum(s) % 2: print(sum(s)) else: sm = sum(s) mn = 1e18 for i in s2: if i % 2: mn = min(abs(i), mn) break for i in s: if i % 2: mn = min(i, mn) print(sm - mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF BIN_OP VAR 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.
def max_odd_subsequence(): input() array = [int(x) for x in input().split()] sum = 0 leastodd = 999999 for i in array: if i > 0: sum += i if i % 2 == 1 and abs(i) < abs(leastodd): leastodd = i if sum % 2 == 1: return sum else: return sum - abs(leastodd) print(max_odd_subsequence())
FUNC_DEF EXPR 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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR EXPR 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.
input() a = [int(x) for x in input().split()] oc = 0 ps = 0 pmo = 1000000.0 nmo = -1000000.0 for x in a: if x > 0: ps += x if x % 2 == 1 and x > 0 and pmo > x: pmo = x if x % 2 == 1 and x > 0: oc += 1 if x % 2 == 1 and x < 0 and nmo < x: nmo = x if oc % 2 == 1: print(ps) else: print(max(ps - pmo, ps + nmo))
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER 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 VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR ASSIGN 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.
import sys def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(str, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n = int(input()) Arr = get_array() min_odd_pos = 10**9 max_odd_neg = -(10**9) total = 0 for i in Arr: if i > 0: total += i if i > 0 and i & 1 and i < min_odd_pos: min_odd_pos = i if i < 0 and i & 1 and i > max_odd_neg: max_odd_neg = i if total & 1: print(total) else: print(total - min(min_odd_pos, -1 * max_odd_neg))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP NUMBER 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) i = 0 m1 = float("inf") m2 = -float("inf") while i < n and a[i] >= 0: if a[i] % 2 == 1: m1 = a[i] i += 1 s = sum(a[:i]) if s % 2 == 1: print(s) else: while i < n and a[i] % 2 == 0: i += 1 if i < n: m2 = a[i] print(max(s - m1, s + m2))
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 ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN 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 OddSum(n, a): c = 0 a.sort(reverse=True) i = 0 minposodd = 99999 maxnegodd = -99999 while i < n: if a[i] > 0: c = c + a[i] if a[i] % 2 == 1: if a[i] > 0: minposodd = min(minposodd, a[i]) else: maxnegodd = max(maxnegodd, a[i]) i = i + 1 if c % 2 == 1: return c if minposodd < abs(maxnegodd): c = c - minposodd else: c = c - abs(maxnegodd) return c n = int(input()) a = list(map(int, input().rstrip().split())) ans = OddSum(n, a) print(ans)
FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN 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 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.
n = int(input()) arr = [int(i) for i in input().split()] par_positivo = [] impar_positivo = [] menor_par_neg = float("inf") maior_impar_neg = -float("inf") for el in arr: if el % 2 == 0: if el > 0: par_positivo.append(el) elif el < menor_par_neg: menor_par_neg = el elif el > 0: impar_positivo.append(el) elif el > maior_impar_neg: maior_impar_neg = el soma_par = sum(par_positivo) resp = soma_par impar_positivo.sort(reverse=True) if len(impar_positivo) > 0: si = sum(impar_positivo) resp += si if len(impar_positivo) % 2 == 0 and len(impar_positivo) > 0: mi_ip = min(impar_positivo) if abs(maior_impar_neg) < mi_ip: resp += maior_impar_neg else: resp -= mi_ip else: resp += maior_impar_neg print(resp)
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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR 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 = input() seq = list(map(int, input().split())) positive = list(filter(lambda x: x > 0, seq)) negative = list(filter(lambda x: x < 0, seq)) s = sum(positive) if s % 2 == 0: p = list(map(lambda x: -x, positive)) remove = sorted(p + negative) for i in range(len(remove) - 1, -1, -1): if (s + remove[i]) % 2 == 1: s += remove[i] break print(s)
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR 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()) lis = list(map(int, input().split())) ans = 0 Min = 2**63 for i in lis: if i > 0: ans += i if ans % 2: print(ans) else: ref = min([abs(i) for i in lis if i % 2]) ans -= ref 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 BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP 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.
import sys n = int(sys.stdin.readline()) l = list(map(int, sys.stdin.readline().split())) pos = [] neg = [] for i in range(n): if l[i] < 0: neg.append(l[i]) elif l[i] > 0: pos.append(l[i]) neg.sort(reverse=True) pos.sort(reverse=True) ans = 0 for i in range(len(pos)): if pos[i] % 2 == 0: ans += pos[i] odd_pos = [] for i in range(len(pos)): if pos[i] % 2 == 1: odd_pos.append(pos[i]) odd_neg = [] for i in range(len(neg)): if neg[i] % 2 == 1: odd_neg.append(neg[i]) odd_neg.sort(reverse=True) if len(odd_pos) > 0: if len(odd_pos) % 2 == 0: odd_pos.sort() for i in range(1, len(odd_pos)): ans += odd_pos[i] if len(odd_neg) > 0: if odd_pos[0] + odd_neg[0] > 0: ans += odd_pos[0] + odd_neg[0] else: ans += sum(odd_pos) else: ans += odd_neg[0] 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 LIST ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL 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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL 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.
n = int(input()) tab = map(int, input().split()) tab = sorted(tab, reverse=True) maxi = 0 tmpOdd = 0 maxOdd = 0 oddFirst = True for i in tab: if i % 2 == 0 and i > 0: maxi += i elif i % 2 == 1: tmpOdd += i if tmpOdd % 2 == 1: if maxOdd < tmpOdd or oddFirst: oddFirst = False maxOdd = tmpOdd maxi += maxOdd print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN 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())) odd_plus_min = 1000000000.0 odd_minus_max = -1000000000.0 sum = 0 for i in range(n): if a[i] > 0: sum += a[i] if abs(a[i]) % 2 != 0: if a[i] > 0: odd_plus_min = min(odd_plus_min, a[i]) elif a[i] < 0: odd_minus_max = max(odd_minus_max, a[i]) res = 1000000000.0 if sum % 2 != 0: res = sum else: if odd_plus_min < 1000000000.0: res = sum - odd_plus_min if odd_minus_max > -1000000000.0: if res < 1000000000.0: res = max(res, sum + odd_minus_max) else: res = sum + odd_minus_max 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP FUNC_CALL VAR 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 ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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.
import sys n = int(sys.stdin.readline().strip()) integer_line = sys.stdin.readline().strip().split() integers = [] for integer in integer_line: integers.append(int(integer)) max_odd = [None] * (len(integers) + 1) max_even = [None] * (len(integers) + 1) max_odd[-1] = 0 max_even[-1] = 0 for index in range(len(integers) - 1, -1, -1): if integers[index] % 2 == 0: max_even[index] = max( integers[index] + max_even[index + 1], max_even[index + 1] ) max_odd[index] = max(integers[index] + max_odd[index + 1], max_odd[index + 1]) continue if max_odd[index + 1] % 2 == 0: max_even[index] = max_even[index + 1] max_odd[index] = max_even[index + 1] + integers[index] continue max_even[index] = max(integers[index] + max_odd[index + 1], max_even[index + 1]) max_odd[index] = max(integers[index] + max_even[index + 1], max_odd[index + 1]) sys.stdout.write(str(max_odd[0]) + "\n")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR 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 FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING
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.
_ = int(input()) a = list(map(int, input().split())) r = sum([i for i in a if 0 < i]) if r % 2 == 1: print(r) else: print( max( r + max([i for i in a if i % 2 == 1 and i < 0], default=-(10**12)), r - min([i for i in a if i % 2 == 1 and 0 < i], default=10**12), ) )
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 NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP NUMBER NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP 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.
from sys import stdin def ii(): return int(stdin.readline()) def mi(): return map(int, stdin.readline().split()) def li(): return list(mi()) n = ii() a = li() m, s, m1 = -10010, 0, 10010 for i in range(n): if a[i] > 0: s += a[i] if a[i] % 2: m1 = min(m1, a[i]) elif a[i] % 2: m = max(m, a[i]) if not s % 2: if m1 > 10000: s += m elif m < -1000: s -= m1 elif abs(m) < m1: s += m else: s -= m1 print(s)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR 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()) seq = list(map(int, input().split())) d = [[(-float("Inf")) for i in range(n + 1)] for j in range(2)] for k in range(n): if seq[k] % 2 == 0: d[0][k + 1] = max(d[0][k], d[0][k] + seq[k], seq[k]) d[1][k + 1] = max(d[1][k], d[1][k] + seq[k]) else: d[0][k + 1] = max(d[0][k], d[1][k] + seq[k]) d[1][k + 1] = max(d[1][k], d[0][k] + seq[k], seq[k]) print(d[1][n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER 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(): input() aa, l = list(map(int, input().split())), [] for i, a in enumerate(aa): if a & 1: l.append(i) elif a < 0: aa[i] = 0 l.sort(key=aa.__getitem__) i = 1 - len(l) & 1 if i: aa[l[0]] = 0 for j, k in zip(l[i::2], l[i + 1 :: 2]): if aa[j] + aa[k] >= 0: break aa[j] = aa[k] = 0 print(sum(aa)) main()
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR 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()) a = list(map(int, input().split())) s, r, t, o = 0, [], [], [] for i in a: if i > 0: s += i if s % 2 == 0: for i in a: if i > 0 and i % 2 == 1: r += [i] elif i < 0 and i % 2 == 1: t += [i] q = s - (min(r) if r else 0) w = s + (max(t) if t else 0) if q % 2 == 1: o += [q] if w % 2 == 1: o += [w] print(max(o)) 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 VAR VAR VAR NUMBER LIST LIST LIST FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR LIST VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR LIST VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR LIST VAR IF BIN_OP VAR NUMBER NUMBER VAR LIST 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.
x = int(input()) s = list(map(int, input().split(" "))) kek = 10000 answer = 0 for i in range(0, len(s)): if s[i] > 0: answer += s[i] if abs(s[i]) < kek and s[i] % 2 == 1: kek = abs(s[i]) if answer % 2 == 0: print(answer - kek) else: print(answer)
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 FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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.
N = int(input()) A = list(map(int, input().split())) dp = [[(-int(1000000000.0)) for i in range(2)] for j in range(N + 1)] dp[0][0] = 0 for i in range(N): for j in range(2): if abs(A[i]) & 1: dp[i + 1][j] = max(dp[i][j], dp[i][j ^ 1] + A[i]) else: dp[i + 1][j] = max(dp[i][j], dp[i][j] + A[i]) print(dp[N][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 NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR 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 = input() listt = list(map(int, input().strip().split())) ans = 0 listt.sort() pos = [] neg = [] for i in listt: if i > 0: ans += i if i % 2 == 1: if i > 0: pos.append(i) else: neg.append(i) if ans % 2 == 1: print(ans) else: if len(pos) == 0: ans += neg[-1] elif len(neg) == 0: ans -= pos[0] else: ans -= min(abs(neg[-1]), pos[0]) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR 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()) ai = list(map(int, input().split())) ans = 0 for i in range(n): if ai[i] > 0: ans += ai[i] if ans % 2 == 1: print(ans) else: mini = 100000000 maxi = -1000000 for i in range(n): if ai[i] > 0 and ai[i] % 2 == 1: if mini > ai[i]: mini = ai[i] elif ai[i] < 0 and ai[i] % 2 == 1: if maxi < ai[i]: maxi = ai[i] maxi = abs(maxi) print(ans - min(mini, maxi))
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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()) li = list(map(int, input().split())) evensum, x, y = 0, 999999999, -999999999 for i in li: if i > 0: evensum += i if i > 0 and i % 2 != 0: x = min(x, i) if i < 0 and i % 2 != 0: y = max(y, i) print(evensum if evensum % 2 != 0 else max(evensum - x, evensum + y))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER 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 EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER 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().strip()) ints = list(map(int, input().strip().split())) negative = -20000 positive = 20000 ans = 0 for item in ints: if item > 0: ans += item if item % 2: if item < 0: negative = max(negative, item) else: positive = min(positive, item) if ans % 2 == 0: ans -= min(abs(negative), positive) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER 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 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()) a = list(map(int, input().split())) res, lst = 0, [] for i, x in enumerate(a): if x % 2 == 0: if x > 0: res += x else: lst.append(x) lst.sort() lst.reverse() res, k = res + lst[0], 1 for i, x in enumerate(lst): if i == 0: continue if x < 0: if k == 0: if abs(x) < lst[i - 1]: res += x k = 1 else: res -= lst[i - 1] k = 1 break else: res += x if k == 1: k = 0 else: k = 1 if k == 0: res -= lst[i] 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 VAR NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR 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()) arr = list(map(int, input().split())) o, e = -(10**8), -(10**8) for i in range(n): if i == 0 and arr[i] % 2: o = arr[i] elif i == 0 and arr[i] % 2 == 0: e = arr[i] elif arr[i] % 2 == 0: if o != -(10**8): o = max(o, arr[i] + o) e = max(e, e + arr[i], arr[i]) else: temp = e if o != -(10**8): e = max(e, o + arr[i]) o = max(o, temp + arr[i], arr[i]) print(o)
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 BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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.
input() s = input() nums = s.split() n = len(nums) a = [0] * n odd = list() res = 0 for i in range(n): a[i] = int(nums[i]) if a[i] % 2 == 1: odd.append(a[i]) else: res += a[i] if a[i] > 0 else 0 odd.sort() res += odd[-1] for i in range(len(odd) - 2, 0, -2): if odd[i] + odd[i - 1] > 0: res += odd[i] + odd[i - 1] else: break print(res)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP 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()) l = list(map(int, input().split())) ans = 0 for i in range(n): if l[i] >= 0: ans = ans + l[i] if ans % 2 == 0: o = 10**9 for i in range(n): if abs(l[i]) % 2 == 1: o = min(o, abs(l[i])) print(ans - o) 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR 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.
n = int(input()) l = list(map(int, input().split())) maxi = max(l) if maxi < 0: if abs(maxi) % 2 == 1: print(maxi) else: mini = -(10**9) for i in range(n): if l[i] > mini and abs(l[i]) % 2 == 1: mini = l[i] print(max(maxi + mini, mini)) else: odd = 0 even = 0 neg = [] min_odd = 10**9 for i in range(n): if l[i] > 0 and l[i] % 2 == 1: odd += l[i] if l[i] < min_odd: min_odd = l[i] elif l[i] > 0 and l[i] % 2 == 0: even += l[i] else: neg.append(l[i]) if (odd + even) % 2 == 1: print(odd + even) else: mini = -(10**9) for i in range(len(neg)): if abs(neg[i]) % 2 == 1 and neg[i] > mini: mini = neg[i] print(max(odd + even + mini, odd + even - min_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 IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR 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 = list(map(int, input().split())) odd_pos = [] odd_neg = [] even_pos = [] even_neg = [] for i in range(len(l)): if l[i] % 2 == 1 and l[i] > 0: odd_pos.append(l[i]) elif l[i] % 2 == 0 and l[i] > 0: even_pos.append(l[i]) elif l[i] % 2 == 1 and l[i] < 0: odd_neg.append(l[i]) else: even_neg.append(l[i]) if len(odd_pos): odd_pos.sort(reverse=True) if len(odd_pos) % 2 == 0: if len(odd_neg): t = max(odd_pos[-1] + max(odd_neg), 0) else: t = 0 odd_pos = odd_pos[: len(odd_pos) - 1] ans1 = sum(odd_pos) + t else: ans1 = sum(odd_pos) if len(even_pos): ans2 = sum(even_pos) else: ans2 = 0 print(ans1 + ans2) elif len(odd_neg): ans1 = max(odd_neg) if len(even_pos): ans2 = sum(even_pos) else: ans2 = 0 print(ans1 + ans2)
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 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 VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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.
gi = lambda: list(map(int, input().strip().split())) gi() l = gi() ev = sorted([e for e in l if e % 2 == 0 and e > 0]) od = sorted([e for e in l if e % 2 == 1]) ans = od.pop() + sum(ev) if len(od) % 2 == 1: od.remove(od[0]) while od and od[-2] > 0: ans += od.pop() + od.pop() if od and od[-1] + od[-2] > 0: ans += od.pop() + od.pop() print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions β€” moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction β€” to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. Input The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≀ n ≀ 50, 1 ≀ m, k ≀ n, m β‰  k). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" β€” that's the terminal train station. Output If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Examples Input 5 3 2 to head 0001001 Output Stowaway Input 3 2 1 to tail 0001 Output Controller 2
n, z1, k1 = map(int, input().split()) z1 -= 1 k1 -= 1 s = input() if s == "to head": napr = -1 else: napr = 1 s = input() for i in range(len(s)): if k1 == z1: print("Controller", i) exit(0) if s[i] == "0": if k1 > z1 and z1 != 0: z1 -= 1 elif k1 < z1 and z1 != n - 1: z1 += 1 k1 += napr if k1 == 0 or k1 == n - 1: napr = -napr else: k1 += napr if k1 == 0 or k1 == n - 1: napr = -napr if k1 == 0: z1 = n - 1 elif k1 == n - 1: z1 = 0 elif napr == 1 and k1 != 0: z1 = 0 else: z1 = n - 1 if k1 == z1: print("Controller", i + 1) exit(0) print("Stowaway")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions β€” moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction β€” to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. Input The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≀ n ≀ 50, 1 ≀ m, k ≀ n, m β‰  k). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" β€” that's the terminal train station. Output If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Examples Input 5 3 2 to head 0001001 Output Stowaway Input 3 2 1 to tail 0001 Output Controller 2
n, m, k = list(map(int, input().split())) a = {"to head": -1, "to tail": 1}[input()] b = input() l = len(b) for i in range(l - 1): if b[i] == "0": if k + a == m or not 1 <= k + a <= n and k - a == m: if ( 1 <= m + a <= n and 1 <= k + a <= n or not 1 <= k + a <= n and 1 <= m - a <= n ): m += a elif not 1 <= k + a <= n and 1 <= m - a <= n: m -= a else: print("Controller", i + 1) break elif a == -1 and k != 1 or a == 1 and k == n: m = n else: m = 1 if not 1 <= k + a <= n: a = -a k += a else: print("Stowaway")
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR IF NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions β€” moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction β€” to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. Input The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≀ n ≀ 50, 1 ≀ m, k ≀ n, m β‰  k). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" β€” that's the terminal train station. Output If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Examples Input 5 3 2 to head 0001001 Output Stowaway Input 3 2 1 to tail 0001 Output Controller 2
import sys n, rider, cop = map(int, input().split()) rider, cop = rider - 1, cop - 1 if input().strip() == "to head": cop_dir = -1 else: cop_dir = 1 for pos, ch in enumerate(input().strip()): if ch == "1": rider = -1 elif cop_dir == -1 and rider < cop: rider = max(0, rider - 1) elif cop_dir == 1 and rider > cop: rider = min(n - 1, rider + 1) cop += cop_dir if cop == rider: print("Controller %d" % (pos + 1)) import sys sys.exit() if cop == 0: cop_dir = 1 elif cop == n - 1: cop_dir = -1 if ch == "1": if cop_dir == -1: if cop == n - 1: rider = 0 else: rider = n - 1 elif cop == 0: rider = n - 1 else: rider = 0 print("Stowaway")
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER IMPORT EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING IF VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING
A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions β€” moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction β€” to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. Input The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≀ n ≀ 50, 1 ≀ m, k ≀ n, m β‰  k). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" β€” that's the terminal train station. Output If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Examples Input 5 3 2 to head 0001001 Output Stowaway Input 3 2 1 to tail 0001 Output Controller 2
J = lambda: map(int, input().split()) v, y, z = J() dir = "to tail" == input() for t, x in enumerate(map(int, input())): if z == 1: dir = 1 elif z == v: dir = 0 if not x: y = min(v, y + 1) if z < y else max(1, y - 1) else: y = 1 if dir else v z = z + 1 if dir else z - 1 if y == z: print("Controller " + str(t + 1)) exit(0) print("Stowaway")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR STRING FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions β€” moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction β€” to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. Input The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≀ n ≀ 50, 1 ≀ m, k ≀ n, m β‰  k). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" β€” that's the terminal train station. Output If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Examples Input 5 3 2 to head 0001001 Output Stowaway Input 3 2 1 to tail 0001 Output Controller 2
from sys import exit, stdin, stdout n, m, k = map(int, stdin.readline().split()) d = 1 if stdin.readline()[6] == "l" else -1 m = 1 if m < k else n for i, c in enumerate(stdin.readline(), 1): if c == "0": if k == 1: k, d = 2, 1 elif k == n: k, d = n - 1, -1 else: k += d if m == k: stdout.write("Controller " + str(i)) exit(0) elif k == 1: k, d, m = 2, 1, 1 elif k == n: k, d, m = n - 1, -1, n elif d == 1: k += 1 m = 1 else: k -= 1 m = n stdout.write("Stowaway")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING
A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions β€” moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction β€” to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. Input The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≀ n ≀ 50, 1 ≀ m, k ≀ n, m β‰  k). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" β€” that's the terminal train station. Output If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Examples Input 5 3 2 to head 0001001 Output Stowaway Input 3 2 1 to tail 0001 Output Controller 2
n, p1, p2 = map(int, input().split()) s = input() state = list(input()) l = len(state) head = 1 if s == "to head" else 0 for i in range(l): s = state[i] if s == "0": if head: if p1 < p2: if p1 > 1: p1 -= 1 elif p2 < p1: if p1 < n: p1 += 1 if p2 > 1: p2 -= 1 else: head = 1 - head p2 += 1 else: if p1 < p2: if p1 > 1: p1 -= 1 elif p2 < p1: if p1 < n: p1 += 1 if p2 < n: p2 += 1 else: head = 1 - head p2 -= 1 if p1 == p2: print("Controller", i + 1) exit() else: if head: if p2 > 1: p2 -= 1 else: head = 1 - head p2 += 1 elif p2 < n: p2 += 1 else: head = 1 - head p2 -= 1 if head and p2 != n: p1 = n elif head and p2 == n: p1 = 1 elif p2 != 1: p1 = 1 else: p1 = n print("Stowaway")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF VAR IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
input_s = input().split(" ") m = int(input_s[0]) s = int(input_s[1]) result_max = "" result_min = "" if m == 1 and s == 0: print("0 0") elif s == 0 or s > m * 9: print("-1 -1") else: for index, i in enumerate(range(s // 9)): result_max += "9" result_min += "9" if s % 9 != 0: result_max += str(s % 9) result_min += str(s % 9) if m - len(result_min) > 0: result_min = result_min[:-1] + str(int(result_min[-1]) - 1) for i in range(m - len(result_max)): result_max += "0" result_min += "0" print( "1" + result_min[:-1][::-1] if result_min.find("0") >= 0 else result_min[::-1], result_max, )
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER BIN_OP STRING VAR NUMBER NUMBER VAR NUMBER VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def to_num(x): if x[0] == "0": for i in range(len(x)): if x[i] != "0": n0 = str(int(x[i]) - 1) x = "1" + x[1:i] + n0 + x[i + 1 : len(x)] break if str(int(x)) == x: return x else: return -1 m, s = map(int, input().split()) x = "" while m > 0: u = s - 9 * (m - 1) if 10 > u > 0: x += str(u) + "9" * (m - 1) break elif u <= 0: x += "0" else: x = "00" break m -= 1 print(to_num(x), to_num(x[::-1]))
FUNC_DEF IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
x, y = map(int, input().split()) if x == 1 and y == 0: print(0, 0) exit() if y > 9 * x or y == 0: print(-1, -1) else: s = "" t = [] while y >= 9: s = s + "9" y = y - 9 if len(s) != x: s = s + str(y) if len(s) != x: while len(s) != x: s = s + "0" ans = s[::-1] if s.count("0") != 0: t = list(ans) for i in range(len(t)): if t[i] != "0": break t[0] = 1 t[i] = int(t[i]) - 1 print("".join(map(str, t)), s) else: print("".join(map(str, ans)), s)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
input2 = input().split() m, s = int(input2[0]), int(input2[1]) def digitsum(m, s): if m == 1 and s == 0: print(0, 0) return if s > 9 * m or s < 1: print(-1, -1) return n9 = s // 9 r9 = s % 9 if n9 == 0: print(10 ** (m - 1) + r9 - 1) print(r9 * 10 ** (m - 1)) return if r9 == 0: minn = 10 ** (m - 1) for i in range(n9): if i == n9 - 1: minn += 8 * 10**i continue minn += 9 * 10**i elif n9 == m - 1: minn = r9 * 10 ** (m - 1) for i in range(n9): minn += 9 * 10**i else: minn = 10 ** (m - 1) for i in range(n9): minn += 9 * 10**i minn += (r9 - 1) * 10**n9 maxn = 0 for i in range(n9): maxn += 9 * 10 ** (m - 1 - i) if m > n9: maxn += r9 * 10 ** (m - 1 - n9) print(minn) print(maxn) return digitsum(m, s)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = input().split() m, s = int(m), int(s) if 9 * m < s or s == 0 and m != 1: print(-1, -1) else: lis = [(0) for i in range(m)] q = int(s // 9) r = int(s % 9) if s == 0: print(0, 0) elif m == 1 and s == 9: print(9, 9) elif m == 2 and s == 18: print(99, 99) elif q == m - 1: for i in range(q): lis[i] = "9" lis[m - 1] = str(r) lis1 = lis[:] if r != 0: print(int("".join(lis[::-1])), int("".join(lis))) else: print(int("".join(["1", "8"] + lis[::-1][2:m])), int("".join(lis1))) elif q < m - 1: for i in range(q): lis[i] = "9" lis[q] = str(r) for i in range(q + 1, m): lis[i] = "0" lis1 = lis[:] if r != 0: lis[m - 1] = "1" lis[q] = str(r - 1) print(int("".join(lis[::-1])), int("".join(lis1))) else: lis[m - 1] = "1" lis[q - 1] = "8" print(int("".join(lis[::-1])), int("".join(lis1))) else: for i in range(m): lis[i] = "9" print(int("".join(lis)), int("".join(lis)))
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING BIN_OP LIST STRING STRING VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def findmaxnum(a, b): strmax = "" strmin = "" for i in range(a): if b - 9 > 0: strmax += "9" b -= 9 else: strmax += str(b) if a - 1 - i > 0: strmin = "1" + "0" * (a - i - 2) for j in range(len(strmax)): if j == 0: strmin += str(int(strmax[len(strmax) - 1]) - 1) else: strmin += str(strmax[len(strmax) - 1 - j]) else: for j in range(len(strmax)): strmin += strmax[len(strmax) - 1 - j] strmax += "0" * (a - 1 - i) break return strmin + " " + strmax def findminnum(a, b): strmin = "" a, b = map(int, input().split()) if a == 1 and b == 0: print("0 0") elif b > 9 * a or b == 0: print("-1 -1") else: print(findmaxnum(a, b))
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR STRING VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s == 0: if m == 1: print(0, 0) else: print(-1, -1) elif 9 * m < s: print(-1, -1) else: ans = [0] * m S = 0 for j in range(m - 1, -1, -1): if S == s: break for i in range(9, -1, -1): if S + i < s: ans[j] = i S += i break elif S + i == s: if j == 0: ans[j] = i break else: ans[j] = i - 1 ans[0] = 1 S = s break ans2 = [0] * m S = 0 for j in range(m): if s - S > 8: ans2[j] = 9 S += 9 elif s == S: break else: ans2[j] = s - S break print(*ans, sep="", end=" ") print(*ans2, sep="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s == 0 and m != 1: print(-1, -1) elif s > m * 9: print(-1, -1) elif m == 1: print(s, s) elif s < 10: print(1 * 10 ** (m - 1) + (s - 1), s * 10 ** (m - 1)) else: number, number2 = 0, 0 a = (s - 1) // 9 b = s // 9 for i in range(a): number = number + 9 * 10**i if m - a > 1: number += 1 * 10 ** (m - 1) + (s - a * 9 - 1) * 10**a else: number += (s - a * 9) * 10 ** (m - 1) for i in range(1, b + 1): number2 += 9 * 10 ** (m - i) number2 += s % 9 * 10 ** max(0, m - b - 1) print(number, number2)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = list(map(int, input().split())) s1 = s s_init = s a_max = [] a_min = m * [0] p = 1 flag = 0 if s == 0 and m > 1 or s > 9 * m: print(-1, -1) flag = 1 else: while s > 9: a_max.append(9) s -= 9 if s <= 9: a_max.append(s) s -= s while len(a_max) != m: a_max.append(0) if s1 > 9: while s1 > 9: a_min[-p] = 9 s1 -= 9 p += 1 if s1 <= 9 and p < m: a_min[-p] = s1 - 1 a_min[0] = 1 elif s1 <= 9 and p == m: a_min[0] = s1 elif s1 <= 9: s1 -= 1 a_min[0] = 1 for v in range(1, m): if v < m - 1: a_min[v] = 0 elif v == m - 1: a_min[v] = s1 if m == 1 and s_init <= 9: print(s_init, s_init) elif flag == 0: if m != 1 and s_init != 0: print(*a_min, sep="") print(*a_max, sep="")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if m == 1: l = 0 else: l = 1 r = 9 * m if not l <= s <= r: print(-1, -1) else: if m > 1: num_min = [1] + [(0) for i in range(m - 1)] else: num_min = [0] num_max = [(9) for i in range(m)] x = (r - s) // 9 for i in range(m - x, m): num_max[i] = 0 num_max[m - x - 1] -= (r - s) % 9 y = (s - l) // 9 for i in range(m - y, m): num_min[i] = 9 num_min[m - y - 1] += (s - l) % 9 for i in range(m): print(num_min[i], end="", sep="") print(" ", end="", sep="") for i in range(m): print(num_max[i], end="", sep="") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) maxi = 0 t1 = m t2 = s a = [] while t1 > 0: if t2 == 0: maxi *= 10 a.append(0) else: temp = min(9, t2) maxi = maxi * 10 + temp a.append(temp) t2 -= temp t1 -= 1 a.reverse() i = 0 while i < m: if a[i] != 0: break i += 1 if t2 != 0: print("-1 -1") elif i == 0: print("".join(map(str, a)), maxi) elif i == m: if m == 1 and s == 0: print("0 0") else: print("-1 -1") else: a[0] += 1 a[i] -= 1 print("".join(map(str, a)), maxi)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] if m > 1 and s == 0: print("-1 -1") elif m == 1 and s == 0: print("0 0") elif m * 9 < s: print("-1 -1") elif m == 1: print(s, s) else: k = max(s - (m - 1) * 9, 1) print(k, end="") n9 = (s - k) // 9 r9 = (s - k) % 9 n0 = m - n9 - 2 if n0 > 0: for i in range(n0): print("0", end="") if m - n9 - 2 > -1: print(r9, end="") if n9 > 0: for i in range(n9): print("9", end="") print(" ", end="") n9 = s // 9 r9 = s % 9 if n9 > 0: for i in range(n9): print("9", end="") if n9 < m: print(r9, end="") if n9 + 1 < m: for i in range(m - n9 - 1): print("0", end="") else: print(r9, end="") for i in range(m - 1): print("0", end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR VAR EXPR FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = list(map(int, input().split())) if m == 1 and s < 10: print(s, s) elif 1 <= m <= 100 and 0 <= s <= 900 and m * 9 >= s and not (m > 1 and s == 0): max, min = ["0"] * m, [] for i in range(m): if s >= 9: max[i] = "9" min.append("9") s -= 9 else: max[i] = str(s) break if max.count("0") != 0: if s == 0: min[-1] = "8" min.append("1") elif s != 1: min.append(str(s - 1)) min.append("1") else: min.append("1") min = str(min[-1]) + "0" * (m - len(min)) + "".join(reversed(min[:-1])) print(int("".join(min)), int("".join(max))) else: print(int("".join(reversed(max))), int("".join(max))) else: print("-1 -1")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF NUMBER VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP LIST STRING VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER IF VAR NUMBER ASSIGN VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
l, s = map(int, input().split()) if s == 0 and l == 1: print(0, 0) elif s < 1 or 9 * l < s: print(-1, -1) else: a = [0] * l b = [0] * l m = s for q in range(l): if s >= 9: a[q] = 9 s -= 9 else: a[q] = s s = 0 s = m j = 0 for q in range(l - 1, -1, -1): if s > 9: b[q] = 9 s -= 9 else: b[q] = s - 1 s = 1 j = 1 b[0] += j for q in b: print(q, end="") print(" ", end="") for q in a: print(q, end="") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = list(map(int, input().split())) def find_min(m, s): result = [] s -= 1 for k in range(m): if s >= 9: result.append(9) s -= 9 else: result.append(s % 9) s -= s % 9 result[-1] += 1 return "".join(list(map(str, reversed(result)))) def find_max(m, s): result = [] for k in range(m): if s >= 9: result.append(9) s -= 9 else: result.append(s % 9) s -= s % 9 return "".join(list(map(str, result))) if m * 9 < s: print(-1, -1) else: if s == 0: if m == 1: minimal, maximal = 0, 0 else: minimal, maximal = -1, -1 else: minimal = find_min(m, s) maximal = find_max(m, s) print(minimal, maximal)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) mn = mx = [] if s == 0 and m == 1: print(2 * "0 ") exit() if s == 0 or 9 * m < s: print(2 * "-1 ") exit() for _ in range(m): if s >= 9: mx.append(9) s -= 9 else: mx.append(s) s = 0 mn = mx[::-1] if not mn[0]: mn[next((i for i, x in enumerate(mn) if x), None)] -= 1 mn[0] = 1 print(int("".join(str(i) for i in mn))) print(int("".join(str(i) for i in mx)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER STRING EXPR FUNC_CALL VAR IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NONE NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n = input().split() min = "" max = "" if int(n[0]) == 1 and int(n[1]) == 0: print(0, 0) elif int(n[1]) == 0 or int(n[0]) * 9 < int(n[1]): print(-1, -1) elif int(n[1]) == 9 * int(n[0]): print("9" * int(n[0]), "9" * int(n[0])) else: a = int(n[1]) // 9 b = int(n[1]) - 9 * a c = int(n[0]) - a - 1 max = "9" * a + str(b) for i in range(c): max = max + "0" d = (int(n[1]) - 1) // 9 e = int(n[1]) - 9 * d - 1 f = int(n[0]) - d - 2 if f >= 0: for i in range(f): min = min + "0" min = "1" + min + str(e) + "9" * d else: e = 1 + e min = str(e) + "9" * d print(min, max)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER BIN_OP STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def find_length_sum_digits(m, s): if m * 9 < s or s == 0 and m != 1: return "-1 -1" digits = [] length = m - 1 while length != 0: for i in range(9, -1, -1): if 1 <= s - i <= 9 * length: s -= i digits.insert(0, str(i)) break length -= 1 digits.insert(0, str(s)) min_n = "".join(digits) try: first_zero_index = min_n.index("0") last_zero_index = min_n.rindex("0") max_n = ( min_n[first_zero_index : last_zero_index + 1] + min_n[:first_zero_index] + min_n[last_zero_index + 1 :] )[::-1] except ValueError: max_n = min_n[::-1] max_n = [int(e) for e in list(max_n)] for i in range(1, len(max_n)): max_add = min(9 - max_n[i - 1], max_n[i]) max_n[i - 1] += max_add max_n[i] -= max_add return min_n + " " + "".join([str(e) for e in max_n]) m, s = [int(e) for e in input().split()] print(find_length_sum_digits(m, s))
FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) a = s b = s c = [] d = [] f = [] if s == 0 and m == 1: print("0 " * 2) elif 9 * m < s or s == 0: print("-1 " * 2) else: while b > 0: d.append(min(b, 9)) b -= min(b, 9) d.reverse() if len(d) == m: print(*d, sep="", end=" ") elif len(d) == 1: d[0] -= 1 print("1", "0" * (m - 2), *d, sep="", end=" ") else: d[0] -= 1 print("1", "0" * (m - len(d) - 1), *d[0 : len(d)], sep="", end=" ") while a > 0: c.append(min(a, 9)) a -= min(a, 9) print(*c, "0" * (m - len(c)), sep="")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING BIN_OP STRING BIN_OP VAR NUMBER VAR STRING STRING VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR STRING STRING WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
q, w = map(int, input().split()) r = 9 * q - w if q == 1 and w == 0: print("0 0") elif r < 0 or w == 0: print("-1 -1") else: t = "9" * (q - r // 9 - 1) + str(9 - r % 9) + "0" * (r // 9) if r // 9 > 0: if 9 - r % 9 > 0: e = "1" + "0" * (r // 9 - 1) + str(9 - r % 9 - 1) + "9" * (q - r // 9 - 1) else: e = "1" + "0" * (r // 9) + str(9 - 1) + "9" * (q - r // 9 - 2) else: e = str(9 - r % 9) + "9" * (q - r // 9 - 1) print(e + " " + t)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, s = map(int, input().split()) r = "" s1 = s if s == 0 and n == 1: print("0" * n, "0" * n) elif s == 0: print("-1 -1") else: while s > 0: a = min(s, 9) s = s - a r = r + str(a) if len(r) > n: r = -1 else: z = n - len(r) r = r + "0" * z if r[0] == "0" and r[-1] != "0": r = -1 if r == -1: print("-1", end=" ") else: r = str(r) if r[-1] != "0": print(r[::-1], end=" ") else: a = list(r[::-1]) for i in range(1, len(a)): if a[i] == "0": pass else: a[i] = str(int(a[i]) - 1) break a[0] = "1" p = "".join(a) print(p, end=" ") print(r, end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, k = map(int, input().split()) if n != 1 and k == 0 or k > 9 * n: print("-1 -1") else: p = k // 9 r = k % 9 u = "0" * n x = u su = 0 i = n - 1 while su != k: if su < k: x = k - su if x < 9: u = u[:i] + str(x) + u[i + 1 :] su += x else: u = u[:i] + "9" + u[i + 1 :] su += 9 elif su > k: u = u[:i] + "0" + u[i + 1 :] su -= 1 if su == k: g = u.count("0") x = u[::-1] if g == 0: break else: u = "1" + "0" * (g - 1) + str(int(u[i]) - 1) + u[i + 1 :] i -= 1 print(u, x)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
import sys def main(): number = [] m, s = map(int, input().split()) if s > 9 * m: print("-1 -1") return i = 9 _len = m while m != 0 and i > -1: if s - i > -1: m -= 1 s -= i number.append(i) i = 9 else: i -= 1 if sum(number) == 0 and _len != 1: print("-1 -1") return _max = "" for i in range(_len): _max += str(number[i]) if _len > 1 and number[0] > 1: end = 1 _min = "" while number[0] > 1 and _len - end != 0: if number[_len - end] != 9: number[0] -= 1 number[_len - end] += 1 else: end += 1 i = end = 1 while _len - end != i: if number[_len - end] != 9: if number[i] > 0: number[i] -= 1 number[_len - end] += 1 else: i += 1 else: end += 1 for i in range(_len): _min += str(number[i]) print(_min + " " + _max) return else: print(_max + " " + _max) return sys.exit(main())
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) a = [(0) for i in range(m)] pt = s for x in range(m): if s >= 10: a[x] = 9 s -= 9 elif s == 0: break else: a[x] = s s = 0 dn, an = [int(p) for p in a], [int(p) for p in a] dn.sort(reverse=True) an.sort() if an[0] == 0: for q in range(1, len(an)): if an[q] != 0: an[0] += 1 an[q] -= 1 break dn.sort(reverse=True) if sum(an) == sum(dn) == pt != 0 or m == 1 and pt == 0: for t in an: print(t, end="") print(" ", end="") for t in dn: print(t, end="") else: print("-1 -1")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, s = map(int, input().split()) if n > 1 and s == 0 or s > 9 * n: print(-1, -1) elif n == 1 and s == 0: print(0, 0) else: l = [0] * (n - 1) + [1] x = 0 while sum(l) < s: if l[x] == 9: x += 1 l[x] += 1 l2 = [9] * n x = 0 while sum(l2) > s: if l2[x] == 0: x += 1 l2[x] = l2[x] - 1 l1 = [str(x) for x in l] l2 = [str(x) for x in l2] l1 = l1[::-1] l2 = l2[::-1] print("".join(l1), "".join(l2))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
a = [int(i) for i in input().split()] m = a[0] s = a[1] h = [0] * m x = 0 for d in range(m): for i in range(1, 10): if x < s: h[d] = h[d] + 1 x = x + 1 x = 0 q = [0] * m q[0] = 1 x = 1 for d in range(m - 1, -1, -1): for i in range(1, 10): if x < s: q[d] = q[d] + 1 x = x + 1 if s > m * 9: print("-1 -1") elif m == 1 and s == 0: print("0 0") elif s == 0 or m == 0: print("-1 -1") else: num1 = "".join([str(f) for f in h]) num2 = "".join([str(f) for f in q]) print(num2 + " " + num1)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) if s == 0 and m == 1: print(0, 0) elif s == 0 or s > 9 * m: print(-1, -1) else: final_max = "" temp = s for j in range(m): for k in range(9, -1, -1): if temp - k >= 0: temp -= k final_max += str(k) break final_min = "" for j in range(m): if j == 0: for k in range(1, 10): if 9 * (m - j - 1) >= s - k: s -= k final_min += str(k) break else: for k in range(0, 10): if 9 * (m - j - 1) >= s - k: s -= k final_min += str(k) break print(final_min, final_max)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
a = input() m = int(a.split()[0]) s = int(a.split()[1]) if s == 0 and m > 1 or 9 * m < s: print(-1, -1) elif s == 0 and m == 1: print(0, 0) else: list1 = [] temp1 = s while temp1 > 9: temp1 -= 9 list1.append("9") list1.append(str(temp1)) while len(list1) < m: list1.append("0") b = "".join(list1) list2 = [] temp2 = s while temp2 > 9: temp2 -= 9 list2.insert(0, "9") list2.insert(0, str(temp2)) while len(list2) < m: list2.insert(0, "0") if "0" not in list2: a = "".join(list2) else: t = list2.count("0") temp3 = int(list2[t]) - 1 list2[t] = str(temp3) list2[0] = "1" a = "".join(list2) print(a, b)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING IF STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] if m == 1 and s == 0: print("0 0") elif s == 0 or 9 * m < s: print("-1 -1") else: x = s // 9 y = s % 9 if y == 0: y = 9 x -= 1 big = "9" * x + str(y) + "0" * (m - x - 1) if x + 1 == m: small = str(y) + "9" * x else: small = "1" + "0" * (m - x - 2) + str(y - 1) + "9" * x print(small, big)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) ans_min = 0 ans_max = 0 if s == 0 and m == 1: print("0 0") elif s > 9 * m or s == 0: print("-1 -1") else: ans = 0 ans = 10 ** (m - 1) for i in range(s - 1): ans += 10 ** (i // 9) ans_min = ans ans = 0 for i in range(s): ans += 10 ** (m - 1 - i // 9) ans_max = ans print(ans_min, ans_max)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
[a, b] = map(int, input().split()) if a == 1 and b == 0: print(0, 0) elif b > 9 * a or b == 0: print(-1, -1) else: c = (b - 1) // 9 if c == a - 1: d = b - 9 * c print(str(d) + c * "9", c * "9" + str(d)) elif c == 0: d = b - 1 print("1" + (a - 2) * "0" + str(d), str(d + 1) + (a - 1) * "0") else: d = b - 1 - 9 * c print( "1" + (a - c - 2) * "0" + str(d) + c * "9", c * "9" + str(d + 1) + (a - c - 1) * "0", )
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR STRING BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING FUNC_CALL VAR VAR BIN_OP VAR STRING BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = map(int, input().split()) max_ = 0 min_ = 0 if m > 1: if s > 9 * m or s == 0: print("-1 -1") else: i = 0 while s > 9 * i: i += 1 a = s - 9 * (i - 1) stra = str(a) string = "9" * (i - 1) + stra + "0" * (m - i) max_ = string if s == 1: min_ = max_ = "1" + "0" * (m - 1) else: j = 0 while s > 9 * j: j += 1 b = s - 1 - 9 * (j - 1) if m > j + 1: strb = str(b) string2 = "1" + "0" * (m - j - 1) + strb + "9" * (j - 1) min_ = string2 elif m == j - 1: string1 = "9" * m min_ = string1 elif m == j: strb = str(b + 1) string3 = strb + "9" * (j - 1) min_ = string3 elif m == j + 1: strb = str(b) string4 = "1" + strb + "9" * (j - 1) min_ = string4 print("%s %s" % (min_, max_)) if m == 1: if s > 9: print("-1 -1") else: max_ = s min_ = s print("%s %s" % (min_, max_))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def f(m, s): a, b = divmod(s, 9) res = "9" * a if b: res += str(b) + "0" * (m - a - 1) else: res += "0" * (m - a) return res m, s = map(int, input().split()) if m == 1 and s == 0: print(0, 0) exit() if 9 * m >= s > 0: a, b = divmod(s, 9) if m - a > 1: print("1", f(m - 1, s - 1)[::-1], sep="", end=" ") else: print(f(m, s)[::-1], end=" ") print(f(m, s)) exit() print(-1, -1)
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP STRING BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER STRING STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, n = list(map(int, input().split())) s1 = n s2 = n l = 9 m1 = [0] * m m2 = [0] * m if n > int(9 * m) or n == 0 and m != 1: print(-1, -1) else: for i in range(m): if s1 >= 9: m2[i] = 9 s1 -= 9 else: m2[i] = s1 break for j in range(m - 1, -1, -1): if s2 > 9: m1[j] = 9 s2 -= 9 elif j != 0 and s2 == 1: m1[0] = s2 break elif j == 0: m1[0] = s2 else: m1[j] = s2 - 1 s2 -= m1[j] for p in m1: print(p, end="") print(" ", end="") for q in m2: print(q, end="")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(i) for i in input().split()] if s > 9 * m or s < 1 and m > 1: print(-1, -1) exit() if s == 0 and m == 1: print("0 0") exit() min1 = [] max1 = [] k = s for i in range(m): if k - (i + 1) * 9 > 0: min1.append(9) else: min1.append(max(0, k - i * 9)) if i < m - 1 and min1[i] > 0: min1[i] -= 1 if i == m - 1 and min1[i] == 0: min1[i] += 1 for i in range(len(min1) - 1, -1, -1): print(min1[i], end="") print(" ", end="") for i in range(m): max1.append(9) if k - i * 9 < 9: max1[i] = k - i * 9 if k - i * 9 <= 0: max1[i] = 0 for i in range(len(max1)): print(max1[i], end="")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
x = input() m, s = list(map(int, x.strip().split())) smallest = [(0) for _ in range(m)] smallest[0] = 1 vsota_s = 1 i = len(smallest) - 1 while vsota_s < s and i >= 0: if s - vsota_s <= 9 - smallest[i]: smallest[i] = s - vsota_s + smallest[i] vsota_s += s - vsota_s i = i - 1 break else: member = smallest[i] smallest[i] = 9 vsota_s += 9 - member i = i - 1 biggest = [(0) for _ in range(m)] biggest[0] = 1 vsota_b = 1 i = 0 while vsota_b < s and i < len(biggest): if s - vsota_b <= 9 - biggest[i]: biggest[i] = s - vsota_b + biggest[i] vsota_b += s - vsota_b i += 1 break else: member = biggest[i] vsota_b += 9 - member biggest[i] = 9 i = i + 1 if s == 0 and m == 1: print(0, 0) elif vsota_s == vsota_b == s: print("".join(map(str, smallest)), "".join(map(str, biggest))) elif vsota_s == s and vsota_b != s: print("".join(map(str, smallest)), -1) elif vsota_s != s and vsota_b == s: print(-1, "".join(map(str, biggest))) else: print(-1, -1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
m, s = [int(x) for x in input().split()] mindsum = 1 maxdsum = 9 * m if m == 1 and s == 0: print(0, 0) elif s < mindsum or s > maxdsum: print(-1, -1) else: mncount = s // 9 mrest = s % 9 if mncount == m: mnum = "9" * m elif mncount == m - 1: if mrest == 0: mnum = "1" + "8" + "9" * (mncount - 1) else: mnum = str(mrest) + "9" * mncount elif mrest == 0: zerocount = m - 2 - mncount + 1 mnum = "1" + "0" * zerocount + "8" + "9" * (mncount - 1) elif mrest == 1: zerocount = m - 1 - mncount mnum = "1" + "0" * zerocount + "9" * mncount else: zerocount = m - 2 - mncount mnum = "1" + "0" * zerocount + str(mrest - 1) + "9" * mncount maxnum = "" t = s while t >= 9: maxnum += "9" t -= 9 if mncount != m: maxnum += str(t) while len(maxnum) != m: maxnum += "0" print(mnum, maxnum)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP STRING VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
n, m = map(int, input().split()) if n == 1: if m > 9 or m < 0: print("-1 -1") else: print(m, m) if (m < 1 or m > n * 9) and n > 1: print("-1 -1") elif n > 1: u = m small = [0] * n large = [0] * n x = 0 while m // 9 > 0: m -= 9 large[x] = 9 x += 1 try: large[x] = m large[x + 1 :] = [0] * (n - x - 1) except: pass x = n - 1 while u >= 10: u -= 9 small[x] = 9 x -= 1 if x == 0: small[x] = u else: small[x] = u - 1 small[0] = 1 for x in range(n): print(small[x], end="") print(" ", end="") for x in range(n): print(large[x], end="") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
def solve(): m, s = map(int, input().split()) if s == 0 and m == 1: print(0, 0) return s_copy = s largestNo = [0] * m i = 0 while i < m and s > 0: largestNo[i] += min(9, s) s -= min(9, s) i += 1 if s != 0 or s_copy == 0: print(-1, -1) return s = s_copy - 1 smallestNo = [0] * m smallestNo[0] = 1 i = m - 1 while i < m and s > 0: smallestNo[i] += min(s, 9) s -= min(s, 9) i -= 1 smallestNo = [str(d) for d in smallestNo] largestNo = [str(d) for d in largestNo] print("".join(smallestNo), "".join(largestNo)) solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR