description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
L = int(input()) num = input() rem = [] for i in range(1, L): if num[i] != "0": a = i b = L - i rem.append((max(a, b), max(a, b) + 1, i)) rem.sort() ans = int(num[: rem[0][2]]) + int(num[rem[0][2] :]) for item in rem: if item[0] > rem[0][1]: break tmp = int(num[: item[2]]) + int(num[item[2] :]) ans = min(ans, tmp) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() ans = None ml = None for i in range(1, l): if s[i] == "0": continue la = i lb = l - i ll = max(la, lb) if ml is None or ml > ll: ml = ll for i in range(1, l): if s[i] == "0": continue la = i lb = l - i ll = max(la, lb) if ll > ml + 2: continue a = int(s[:i]) b = int(s[i:]) sum = a + b if ans is None or ans > sum: ans = sum print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
from sys import stdin, stdout l = int(stdin.readline()) s = stdin.readline().strip() mid = l // 2 front = s[:mid][::-1] back = s[mid:] i = 0 ll = len(back) while i < ll: if back[i] != "0": break i += 1 j = 0 ll = l - ll while j < ll: if front[j] != "0": break j += 1 best = int(s) for loc in range(mid - i - 3, mid - i + 3): if loc <= 0 or loc >= l - 1 or s[loc] == "0": continue best = min(best, int(s[:loc]) + int(s[loc:])) for loc in range(mid + j - 3, mid + j + 3): if loc <= 0 or loc > l - 1 or s[loc] == "0": continue best = min(best, int(s[:loc]) + int(s[loc:])) stdout.write(str(best) + "\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys input = sys.stdin.readline n = int(input()) x = input() res = int(x) idx = n // 2 for i in range(idx, 0, -1): if x[i] == "0": continue res = min(res, int(x[i:]) + int(x[:i])) break for i in range(idx + 1, n): if x[i] == "0": continue res = min(res, int(x[i:]) + int(x[:i])) break print(res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() def valid(l): return l > 0 and l < n ANS = int(s) def test(l): if not valid(l): return ANS sL = s[:l] sR = s[l:] if sL[0] == "0": return ANS if sR[0] == "0": return ANS L = int(s[:l]) R = int(s[l:]) M = L + R return M l = n // 2 while valid(l - 1) and s[l - 1] == "0": l -= 1 ANS = test(l) m = n // 2 while valid(m) and s[m] == "0": m -= 1 ANS = min(ANS, test(m)) m = n // 2 while valid(m) and s[m] == "0": m += 1 ANS = min(ANS, test(m)) r = n // 2 + 1 while valid(r) and s[r] == "0": r += 1 ANS = min(ANS, test(r)) print(ANS)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING RETURN VAR IF VAR NUMBER STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def is_empty(x): return len(x) == 0 def has_leading_zero(x): return x[0] == "0" def is_legal(x): return is_empty(x) or not has_leading_zero(x) def safe_to_int(x): if len(x) == 0: return 0 return int(x) length_string = input() number_string = input() length = int(length_string) ans = int(number_string) if length == 1: ans = int(number_string) else: border = middle = int((length + 1) / 2) while border >= 0: first = number_string[:border] second = number_string[border:] found = False if is_legal(first) and is_legal(second): tmp_ans = safe_to_int(first) + safe_to_int(second) ans = min(ans, tmp_ans) found = True other_border = length - border first = number_string[:other_border] second = number_string[other_border:] if is_legal(first) and is_legal(second): tmp_ans = safe_to_int(first) + safe_to_int(second) ans = min(ans, tmp_ans) found = True if found: break border = border - 1 print(ans)
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN VAR NUMBER STRING FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() m = int(n) for i in range(l // 2, l): if n[i] != "0": m = int(n[0:i]) + int(n[i:]) break for i in range(l // 2, l): if n[l - i] != "0": print(min(m, int(n[0 : l - i]) + int(n[l - i :]))) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if n % 2 == 0: if s[n // 2] != "0": print(int(s[: n // 2]) + int(s[n // 2 :])) else: ok = 0 for i in range(1, n // 2 + 1): if ok == 1: break if s[n // 2 - i] != "0" and s[n // 2 + i] != "0": ok = 1 print( min( int(s[: n // 2 - i]) + int(s[n // 2 - i :]), int(s[: n // 2 + i]) + int(s[n // 2 + i :]), ) ) elif s[n // 2 - i] != "0": ok = 1 print(int(s[: n // 2 - i]) + int(s[n // 2 - i :])) elif s[n // 2 + i] != "0": ok = 1 print(int(s[: n // 2 + i]) + int(s[n // 2 + i :])) else: ok = 0 for i in range(1, n // 2 + 1): if ok == 1: break if s[n // 2 - i + 1] != "0" and s[n // 2 + i] != "0": ok = 1 print( min( int(s[: n // 2 - i + 1]) + int(s[n // 2 - i + 1 :]), int(s[: n // 2 + i]) + int(s[n // 2 + i :]), ) ) elif s[n // 2 - i + 1] != "0": ok = 1 print(int(s[: n // 2 - i + 1]) + int(s[n // 2 - i + 1 :])) elif s[n // 2 + i] != "0": ok = 1 print(int(s[: n // 2 + i]) + int(s[n // 2 + i :]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) number = input() ans = 0 def give_sum(split_point): str1 = "" for i in range(split_point): str1 = str1 + number[i] str2 = "" for i in range(split_point, n): str2 = str2 + number[i] n1 = 0 n2 = 0 if str1 != "": n1 = int(str1) if str2 != "": n2 = int(str2) return n1 + n2 split_point = n // 2 actual_split_point = n for i in range(split_point): if number[i + 1] != "0": actual_split_point = i + 1 actual_split_point2 = n for i in range(split_point, n - 1): if number[i + 1] != "0": actual_split_point2 = i + 1 break ans = give_sum(actual_split_point) ans2 = give_sum(actual_split_point2) ans = min(ans, ans2) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) k = input() mi = float("inf") inda = n // 2 indb = n // 2 while inda < n and k[inda] == "0": inda += 1 while indb >= 0 and k[indb] == "0": indb -= 1 a = float("inf") b = float("inf") if inda < n: a = int(k[:inda]) + int(k[inda:]) if inda + n % 2 < n and k[inda + n % 2] != "0": a = min(a, int(k[: inda + n % 2]) + int(k[inda + n % 2 :])) if indb > 0: b = int(k[:indb]) + int(k[indb:]) if indb + n % 2 < n and indb + n % 2 > 0 and k[indb + n % 2] != "0": b = min(b, int(k[: indb + n % 2]) + int(k[indb + n % 2 :])) if inda >= n and indb < 0: print(0) else: print(min(a, b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys n = int(input()) s = input() k1 = int(s) d = list(s) mini = sys.maxsize k = n // 2 if s[k] == "0": lo, bo = 10**18, 10**18 for i in range(k, n): if s[i] != "0": z = n - i b = int(s[:i]) + int(s[i:]) if s[z] != 0 and s[n - i] != "0": a = int(s[:z]) + int(s[z:]) b = int(s[:i]) + int(s[i:]) lo = min(a, b) else: lo = b break for i in range(k, 0, -1): if s[i] != "0": z = n - i b1 = int(s[:i]) + int(s[i:]) if s[z] != 0 and s[n - i] != "0": a = int(s[:z]) + int(s[z:]) b1 = int(s[:i]) + int(s[i:]) bo = min(a, b1) else: bo = b1 break print(min(bo, lo)) elif n % 2 == 0: a = int(s[:k]) + int(s[k:]) print(a) elif s[k + 1] != "0": z = k + 1 a = int(s[:k]) + int(s[k:]) b = int(s[:z]) + int(s[z:]) print(min(a, b))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
le = int(input()) n = input() l = le // 2 if le % 2 == 0: l -= 1 r = le // 2 if le % 2 != 0: r += 1 minSum = -1 while l >= 0 and r < le: if int(n[l]) != 0: s = int(n[:l]) + int(n[l:]) if minSum == -1 or s < minSum: minSum = s if int(n[r]) != 0: s = int(n[:r]) + int(n[r:]) if minSum == -1 or s < minSum: minSum = s if minSum != -1: break l -= 1 r += 1 print(minSum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) m = input() if n % 2 == 0: if m[n // 2] == "0": k1 = n // 2 while m[k1] == "0": k1 += 1 if k1 >= n: break k2 = n // 2 while m[k2] == "0": k2 -= 1 if k2 <= 0: break if k1 == n: print(int(m[:k2]) + int(m[k2:])) elif k2 == 0: print(int(m[:k1]) + int(m[k1:])) else: print(min(int(m[:k2]) + int(m[k2:]), int(m[:k1]) + int(m[k1:]))) else: print(int(m[: n // 2]) + int(m[n // 2 :])) elif m[n // 2] == "0" and m[n // 2 + 1] == "0": k1 = n // 2 while m[k1] == "0": k1 += 1 if k1 >= n: break k2 = n // 2 while m[k2] == "0": k2 -= 1 if k2 <= 0: break if k1 == n: print(int(m[:k2]) + int(m[k2:])) elif k2 == 0: print(int(m[:k1]) + int(m[k1:])) else: print(min(int(m[:k2]) + int(m[k2:]), int(m[:k1]) + int(m[k1:]))) elif m[n // 2] == "0": k2 = n // 2 + 1 print(int(m[:k2]) + int(m[k2:])) elif m[n // 2 + 1] == "0": k2 = n // 2 print(int(m[:k2]) + int(m[k2:])) else: k1 = n // 2 k2 = n // 2 + 1 print(min(int(m[:k2]) + int(m[k2:]), int(m[:k1]) + int(m[k1:])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) arr = input() arr1 = [] arr2 = [] arr3 = [] arr4 = [] if len(arr) % 2 == 0: i = len(arr) // 2 j = len(arr) // 2 - 1 else: i = len(arr) // 2 j = len(arr) // 2 while arr[i] == "0" and i < len(arr) - 1: i += 1 while arr[j] == "0" and j > 0: j -= 1 if i == len(arr): i -= 1 if j == 0: j += 1 arr1 = arr[:i] arr2 = arr[i:] if len(arr) % 2 == 0: arr3 = arr[:j] arr4 = arr[j:] elif arr[j + 1] == "0" and j - 1 != -1: arr3 = arr[:j] arr4 = arr[j:] else: arr3 = arr[: j + 1] arr4 = arr[j + 1 :] flag1 = 0 flag2 = 0 if arr2[0] == "0": flag1 = 1 if arr4[0] == "0": flag2 = 1 x1 = int(arr1) x2 = int(arr2) y1 = int(arr3) y2 = int(arr4) if flag1 == 1 and flag2 == 0: print(y1 + y2) elif flag1 == 0 and flag2 == 1: print(x1 + x2) elif flag1 == 0 and flag2 == 0: if x1 + x2 >= y1 + y2: print(y1 + y2) else: print(x1 + x2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def solve(): l = int(input()) x_s = input() def calculate(split_pos): return int(x_s[:split_pos]) + int(x_s[split_pos:]) lth = l pos = -1 result = int(x_s) for i in range(1, l): if x_s[i] != "0": dl = max(i, l - i) if dl < lth: pos = i elif dl == lth: result = calculate(pos) pos = i lth = min(lth, dl) result = min(result, calculate(pos)) return result print(solve())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys class BSplitANumber: def __init__(self): self.t = 0 def solve(self): l = int(input()) n = input() s = (l - 1) // 2 lo = s hi = s + 1 while lo >= 0 and n[lo] == "0": lo -= 1 while hi < l and n[hi] == "0": hi += 1 a, b = float("inf"), float("inf") if lo != 0: a = eval(n[:lo] + "+" + n[lo:]) if hi != l: b = eval(n[:hi] + "+" + n[hi:]) print(min(a, b)) solver = BSplitANumber() input = sys.stdin.readline solver.solve()
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR STRING VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) inf = 10**10**5 + 1 n = input() if l % 2: k1 = l // 2 while n[k1] == "0": k1 -= 1 if k1: n1 = int(n[:k1]) + int(n[k1:]) else: n1 = inf k2 = l // 2 + 1 while n[k2] == "0": k2 += 1 if k2 == l: n2 = inf break else: n2 = int(n[:k2]) + int(n[k2:]) print(min(n1, n2)) else: k1 = l // 2 while n[k1] == "0": k1 -= 1 if k1: n1 = int(n[:k1]) + int(n[k1:]) else: n1 = inf k2 = l // 2 + 1 while n[k2] == "0": k2 += 1 if k2 == l: n2 = inf break else: n2 = int(n[:k2]) + int(n[k2:]) print(min(n1, n2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys def rint(): return map(int, sys.stdin.readline().split()) def cal_sum(s): return int(n[:s]) + int(n[s:]) def is_valid_left(sl): return sl > 0 and n[sl] != "0" def is_valid_right(sr): return sr < l and n[sr] != "0" l = int(input()) n = input() sl_ori = l // 2 sr_ori = l // 2 + l % 2 for i in range(0, l + 1): sl = sl_ori - i sr = sr_ori + i sl2 = sl - 1 sr2 = sr + 1 if not is_valid_right(sr) and not is_valid_left(sl): continue sum_sl = 10**100002 sum_sr = 10**100002 sum_sl2 = 10**100002 sum_sr2 = 10**100002 if is_valid_left(sl): sum_sl = cal_sum(sl) if is_valid_right(sr): sum_sr = cal_sum(sr) if is_valid_left(sl2): sum_sl2 = cal_sum(sl2) if is_valid_right(sr2): sum_sr2 = cal_sum(sr2) print(min(sum_sl, sum_sr, sum_sl2, sum_sr2)) break
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN VAR NUMBER VAR VAR STRING FUNC_DEF RETURN VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = [*map(int, input())] def f(i): a = s[:i] b = s[i:] c = [] carry = 0 while a or b: c.append((a if a else [0]).pop() + (b if b else [0]).pop() + carry) carry = c[-1] // 10 c[-1] %= 10 c.reverse() return c def key(x, y): if len(x) != len(y): return len(x) < len(y) return x < y c = [] i = n // 2 while i > 0 and s[i] == 0: i -= 1 if i > 0: c.append(i) i = (n + 1) // 2 while i < n and s[i] == 0: i += 1 if i < n: c.append(i) res = s[:] for e in c: curr = f(e) if key(curr, res): res = curr print("".join(map(str, res)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR LIST NUMBER FUNC_CALL VAR VAR LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
length = int(input()) number = input().strip() lStart = length // 2 if length % 2 == 0: rStart = length // 2 else: rStart = length // 2 + 1 lCut = 0 for i in reversed(range(1, lStart + 1)): rSubstring = number[i:length] if not rSubstring.startswith("0"): lCut = i break rCut = -1 for i in range(rStart, length): rSubstring = number[i:length] if not rSubstring.startswith("0"): rCut = i break if lCut == 0: caseOne = int(number) else: caseOneLeft = int(number[0:lCut]) caseOneRight = int(number[lCut:length]) caseOne = caseOneLeft + caseOneRight if rCut == -1: print(caseOne) else: caseTwoLeft = int(number[0:rCut]) caseTwoRight = int(number[rCut:length]) caseTwo = caseTwoLeft + caseTwoRight print(min(caseOne, caseTwo))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) a = input() i = l // 2 if l % 2 == 0: if a[i] != "0": s1 = "" s2 = "" for x in range(0, i): s1 += a[x] for x in range(i, l): s2 += a[x] num1 = int(s1) num2 = int(s2) print(num1 + num2) else: x = i y = i while a[x - 1] == "0": x = x - 1 while y < l - 1 and a[y + 1] == "0": y = y + 1 s1 = "" s2 = "" if x > 1: for j in range(x - 1): s1 += a[j] for j in range(x - 1, l): s2 += a[j] num1 = int(s1) num2 = int(s2) n1 = num1 + num2 s1 = "" s2 = "" if y < l - 1: for j in range(y + 1): s1 += a[j] for j in range(y + 1, l): s2 += a[j] num1 = int(s1) num2 = int(s2) n2 = num1 + num2 if y == l - 1: print(n1) elif x == 1: print(n2) elif n1 < n2: print(n1) else: print(n2) elif a[i] != "0": s1 = "" s2 = "" for x in range(i): s1 += a[x] for x in range(i, l): s2 += a[x] num1 = int(s1) num2 = int(s2) n1 = num1 + num2 if a[i + 1] == "0": print(n1) else: s1 = "" s2 = "" for x in range(i + 1): s1 += a[x] for x in range(i + 1, l): s2 += a[x] num1 = int(s1) num2 = int(s2) n2 = num1 + num2 s1 = "" s2 = "" if n1 < n2: print(n1) else: print(n2) else: x = i y = i while a[x - 1] == "0": x = x - 1 while y < l - 1 and a[y + 1] == "0": y = y + 1 s1 = "" s2 = "" if x > 1: for j in range(x - 1): s1 += a[j] for j in range(x - 1, l): s2 += a[j] num1 = int(s1) num2 = int(s2) n1 = num1 + num2 s1 = "" s2 = "" if y < l - 1: for j in range(y + 1): s1 += a[j] for j in range(y + 1, l): s2 += a[j] num1 = int(s1) num2 = int(s2) n2 = num1 + num2 if y == l - 1: print(n1) elif x == 1: print(n2) elif n1 < n2: print(n1) else: print(n2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() ret = int(s) testing = 2 def debug(s): if testing == 1: print(s) def check(middle, dir): global s while middle > 0 and middle < l - 1 and s[middle] == "0": debug(middle) middle += dir s1 = s[:middle] s2 = s[middle:] if s1 == "" or s2 == "": return middle elif s1[0] == "0" or s2[0] == "0": return middle else: debug("middle : %d, %s" % (middle, s[middle])) debug("s1:" + s1) debug("s2:" + s2) ret1 = int(s1) + int(s2) global ret if ret1 < ret: ret = ret1 return middle middle = l // 2 - 1 debug(middle) for i in range(3): middle = check(middle, 1) middle += 1 middle = l // 2 + 1 for i in range(3): middle = check(middle, -1) middle += 1 print(ret)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR STRING RETURN VAR IF VAR NUMBER STRING VAR NUMBER STRING RETURN VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if n % 2 == 0: fir = n // 2 - 1 sec = n // 2 while fir >= 0 and s[fir] == "0": fir -= 1 while sec < n and s[sec] == "0": sec += 1 if sec == n: temp1 = int(s[fir:]) temp2 = int(s[:fir]) print(temp2 + temp1) elif fir == 0: temp1 = int(s[:sec]) temp2 = int(s[sec:]) print(temp1 + temp2) else: temp1 = int(s[:sec]) temp2 = int(s[sec:]) temp3 = int(s[fir:]) temp4 = int(s[:fir]) print(min(temp1 + temp2, temp3 + temp4)) else: mid = n // 2 if s[mid] != "0": temp1 = int(s[: n // 2]) + int(s[n // 2 :]) temp2 = int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]) print(min(temp1, temp2)) else: fir = n // 2 - 1 sec = n // 2 + 1 while fir >= 0 and s[fir] == "0": fir -= 1 while sec < n and s[sec] == "0": sec += 1 if sec == n: temp1 = int(s[fir:]) temp2 = int(s[:fir]) print(temp2 + temp1) elif fir == 0: temp1 = int(s[:sec]) temp2 = int(s[sec:]) print(temp1 + temp2) else: temp1 = int(s[:sec]) temp2 = int(s[sec:]) temp3 = int(s[fir:]) temp4 = int(s[:fir]) print(min(temp1 + temp2, temp3 + temp4))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def t(c): one = a // 2 two = a // 2 + a % 2 if sum((int(c[:two]), int(c[-one:]))) > sum((int(c[:one]), int(c[-two:]))): return c[:one], c[-two:] return c[:two], c[-one:] def f1(a, b): while b[0] == "0": b = a[-1] + b a = a[:-1] if a == "": a = "0" if b == "": b = "0" return sum((int(a), int(b))) def f2(a, b): while b != "" and b[0] == "0": a = a + b[0] b = b[1:] if a == "": a = "0" if b == "": b = "0" return sum((int(a), int(b))) a = int(input()) b = str(input()) c, u = t(b) if u[0] != "0": print(sum((int(c), int(u)))) else: print(min(f1(c, u), f2(c, u)))
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR RETURN VAR VAR VAR VAR FUNC_DEF WHILE VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR STRING VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() def solvef(n, i): while n[i] == "0": i = i + 1 if i == len(n): return 1000000000000000 n1 = n[0:i] n2 = n[i:] return int(n1) + int(n2) def solveb(n, i): while n[i] == "0": i = i - 1 if i == -1: return 1000000000000000 n1 = n[0:i] n2 = n[i:] return int(n1) + int(n2) if l % 2 == 0: i = l // 2 print(min(solvef(n, i), solveb(n, i))) else: i = l // 2 print(min(min(solvef(n, i), solveb(n, i + 1)), min(solvef(n, i), solveb(n, i + 1))))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def main(): N = int(input()) S = str(input()) mid = 100010 C = 10**mid for i in range(1, N): if S[i] != "0": mid = min(mid, max(i, N - i) + 2) for i in range(1, N): if S[i] != "0" and max(i, N - i) <= mid: T = int(S[:i]) + int(S[i:]) C = min(C, T) print(C) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() mx = int(s) half = l // 2 half += 1 i = half while i < l: if s[i] != "0": break i = i + 1 if i <= l - 1: pref = int(s[:i]) suff = int(s[i:]) mx = min(mx, pref + suff) i = half - 1 while s[i] == "0": i = i - 1 if i >= 1: pref = int(s[:i]) suff = int(s[i:]) mx = min(mx, pref + suff) print(mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() ans = float("inf") temp = 1 mid1 = l // 2 mid2 = l // 2 while mid1 < l and int(n[mid1]) == 0: mid1 += 1 while mid2 >= 0 and int(n[mid2]) == 0: mid2 -= 1 if mid1 != l: ans = min(ans, int(n[0:mid1]) + int(n[mid1:l])) if mid2 >= 1: ans = min(ans, int(n[0:mid2]) + int(n[mid2:l])) if mid1 < l - 1 and int(n[mid1 + 1] != 0): ans = min(ans, int(n[0 : mid1 + 1]) + int(n[mid1 + 1 : l])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
totlen = [] def mykey(ele): return max(ele + 1, totlen[0] - ele) def mykey2(ele): return max(ele, totlen[0] - ele - 1) k = int(input()) num = list(input()) possible = [] totlen.append(len(num)) for i in range(1, totlen[0]): if num[i] == "0": continue possible.append(i) possible.sort(key=mykey) final = -1 flag = mykey(possible[0]) + 2 for i in range(0, len(possible)): if mykey2(possible[i]) > flag: break p = possible[i] num1 = int("".join(num[0:p])) num2 = int("".join(num[p:])) res = num1 + num2 if final == -1 or res < final: final = res print(final)
ASSIGN VAR LIST FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() j = 0 k = 0 if n % 2 == 0: if s[n // 2] != "0": print(int(s[: n // 2]) + int(s[n // 2 :])) else: for i in range(n): if s[i] != "0" and i < n // 2: j = i elif s[i] != "0": k = i break if j == 0: print(int(s[:k]) + int(s[k:])) elif k == 0: print(int(s[:j]) + int(s[j:])) else: print(min(int(s[:j]) + int(s[j:]), int(s[:k]) + int(s[k:]))) else: for i in range(n): if s[i] != "0" and i <= n // 2: j = i elif s[i] != "0": k = i break if j == 0: print(int(s[:k]) + int(s[k:])) elif k == 0: print(int(s[:j]) + int(s[j:])) else: print(min(int(s[:j]) + int(s[j:]), int(s[:k]) + int(s[k:])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) l = list(input()) inf = -1 ans = 0 left = [] right = [] for i in range(1, n // 2 + n % 2): if l[i] != "0": left.append(i) for i in range(n // 2, n): if l[i] != "0": right.append(i) for i in range(len(left) - 1, max(len(left) - 3, 0) - 1, -1): if ans == 0: ans = int("".join(l[0 : left[i]])) + int("".join(l[left[i] :])) else: ans = min(ans, int("".join(l[0 : left[i]])) + int("".join(l[left[i] :]))) for i in range(min(3, len(right))): if ans == 0: ans = int("".join(l[0 : right[i]])) + int("".join(l[right[i] :])) else: ans = min(ans, int("".join(l[0 : right[i]])) + int("".join(l[right[i] :]))) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() if l % 2 == 0: left = l // 2 right = l // 2 while left >= 1 and n[left] == "0": left -= 1 while right < l and n[right] == "0": right += 1 if left == 0: print(int(n[:right]) + int(n[right:])) elif right == l: print(int(n[:left]) + int(n[left:])) else: print(min([int(n[:right]) + int(n[right:]), int(n[:left]) + int(n[left:])])) else: left = l // 2 right = l // 2 res1 = 0 res2 = 0 while left >= 1 and n[left] == "0": left -= 1 while right < l and n[right] == "0": right += 1 if left == 0: res1 = int(n[:right]) + int(n[right:]) elif right == l: res1 = int(n[:left]) + int(n[left:]) else: res1 = min([int(n[:right]) + int(n[right:]), int(n[:left]) + int(n[left:])]) left = l // 2 + 1 right = l // 2 + 1 res2 = 0 while left >= 1 and n[left] == "0": left -= 1 while right < l and n[right] == "0": right += 1 if left == 0: res2 = int(n[:right]) + int(n[right:]) elif right == l: res2 = int(n[:left]) + int(n[left:]) else: res2 = min([int(n[:right]) + int(n[right:]), int(n[:left]) + int(n[left:])]) print(min([res1, res2]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() i1 = l // 2 i2 = i1 + 1 i3 = i1 - 1 i4 = i2 + 1 p1 = p2 = p3 = p4 = int(s) if i1 < l and i1 >= 0: while i1 > 0 and s[i1] == "0": i1 -= 1 if i1 > 0: p1 = int(s[i1:]) + int(s[:i1]) if i2 < l and i2 >= 0: while i2 < l and s[i2] == "0": i2 += 1 if i2 < l: p2 = int(s[:i2]) + int(s[i2:]) mini = min(p1, p2) if i3 < l and i3 > 0: if s[i3] != "0": p3 = int(s[:i3]) + int(s[i3:]) if p3 < mini: mini = p3 if l % 2 != 0: if i4 < l and i4 > 0: if s[i4] != "0": p4 = int(s[:i4]) + int(s[i4:]) if p4 < mini: mini = p4 print(mini)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() possible = [] for i in range(1, l): if s[i] is not "0": possible.append(i) good = [possible[0]] digits1 = good[0] digits2 = l - digits1 maxdigits = max(digits1, digits2) + 1 for p in possible: digits1 = p digits2 = l - digits1 localmax = max(digits1, digits2) + 1 if localmax < maxdigits: maxdigits = localmax good = [p] elif localmax == maxdigits: good.append(p) best = 10 * int(s) for g in good: part1 = int(s[:g]) part2 = int(s[g:]) best = min(best, part1 + part2) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def do(s, j): return int(s[:j]) + int(s[j:]) def main(): n = int(input()) x = input() mid = n // 2 cnt = 0 best = None for i in range(mid + 2): j = mid + i if j < n and x[j] != "0": val = do(x, j) cnt += 1 if best is None: best = val else: best = min(best, val) j = mid - i if j > 0 and x[j] != "0": val = do(x, j) cnt += 1 if best is None: best = val else: best = min(best, val) if cnt >= 7: break print(best) def __starting_point(): main() __starting_point()
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input().strip()) str = input() ans = 1e1000 pos = int(n / 2 - 1) while pos >= 0 and str[pos + 1] == "0": pos = pos - 1 if pos >= 0 and str[pos + 1] != "0": suma = int(str[0 : pos + 1]) sumb = int(str[pos + 1 : n + 1]) sum = suma + sumb if sum < ans: ans = sum pos = int(n / 2 - 1) while pos < n - 1 and str[pos + 1] == "0": pos = pos + 1 if pos < n - 1 and str[pos + 1] != "0": suma = int(str[0 : pos + 1]) sumb = int(str[pos + 1 : n + 1]) sum = suma + sumb if sum < ans: ans = sum pos = int(n / 2) while pos >= 0 and str[pos + 1] == "0": pos = pos - 1 if pos >= 0 and str[pos + 1] != "0": suma = int(str[0 : pos + 1]) sumb = int(str[pos + 1 : n + 1]) sum = suma + sumb if sum < ans: ans = sum pos = int(n / 2) while pos < n - 1 and str[pos + 1] == "0": pos = pos + 1 if pos < n - 1 and str[pos + 1] != "0": suma = int(str[0 : pos + 1]) sumb = int(str[pos + 1 : n + 1]) sum = suma + sumb if sum < ans: ans = sum print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if n == 2: print(int(s[0]) + int(s[1])) exit(0) mid = n // 2 tmid = mid INF = pow(10, 50002) ras = INF ans = INF while tmid < n - 1: if s[tmid + 1] != "0": a = int(s[0 : tmid + 1]) b = int(s[tmid + 1 :]) ras = a + b break tmid += 1 if ras != INF: ans = ras tmid = mid las = INF while tmid > 0: if s[tmid] != "0": b = int(s[tmid:]) a = int(s[0:tmid]) las = a + b break tmid -= 1 if las != INF: ans = min(ans, las) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys L = int(input()) S = input() res = 0 if L % 2 == 1: for i in range(int(L / 2)): if S[int(L / 2) + i + 1] != "0" or S[int(L / 2) - i] != "0": if S[int(L / 2) + i + 1] != "0": res = int(S[0 : int(L / 2) + i + 1]) + int(S[int(L / 2) + i + 1 : L]) if ( S[int(L / 2) - i] != "0" and int(S[0 : int(L / 2) - i]) + int(S[int(L / 2) - i : L]) < res ): res = int(S[0 : int(L / 2) - i]) + int(S[int(L / 2) - i : L]) else: res = int(S[0 : int(L / 2) - i]) + int(S[int(L / 2) - i : L]) print(res) sys.exit() elif S[int(L / 2)] != "0": res = int(S[0 : int(L / 2)]) + int(S[int(L / 2) : L]) print(res) sys.exit() else: for i in range(int(L / 2) - 1): if S[int(L / 2) + i + 1] != "0" or S[int(L / 2) - i - 1] != "0": if S[int(L / 2) + i + 1] != "0": res = int(S[0 : int(L / 2) + i + 1]) + int(S[int(L / 2) + i + 1 : L]) if ( S[int(L / 2) - i - 1] != "0" and int(S[0 : int(L / 2) - i - 1]) + int(S[int(L / 2) - i - 1 : L]) < res ): res = int(S[0 : int(L / 2) - i - 1]) + int( S[int(L / 2) - i - 1 : L] ) else: res = int(S[0 : int(L / 2) - i - 1]) + int(S[int(L / 2) - i - 1 : L]) print(res) sys.exit()
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING IF VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING IF VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
a = int(input()) n = input() INF = 1e1000 res = INF wei = INF for i in range(1, a): if n[i] != "0": wei = min(wei, max(i, a - i)) for i in range(1, a): if n[i] != "0" and max(i, a - i) <= wei: res = min(int(n[:i]) + int(n[i:]), res) wei = max(i, a - i) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def v(s): return len(s) > 0 and s[0] != "0" def i(s): try: return int(s) except: return 0 n = int(input()) s = input() a = n // 2 b = n // 2 + 1 while a > 0 and s[a] == "0": a -= 1 while b < n and s[b] == "0": b += 1 print(min(i(s[:a]) + i(s[a:]), i(s[:b]) + i(s[b:])))
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING FUNC_DEF RETURN FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n, c = int(input()), input() x, y = n // 2, (n + 1) // 2 while x >= 1 and y < n: if c[x] == "0" and c[y] == "0": x -= 1 y += 1 continue a = int(c[:x]) + int(c[x:]) b = int(c[:y]) + int(c[y:]) if c[x] == "0": print(b) elif c[y] == "0": print(a) else: print(min(a, b)) break
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() if l % 2: flag = False for i in range(1, l // 2 + 1): seg1 = int(l / 2 + i) seg2 = int(l / 2 - i) + 1 ans1 = -1 ans2 = -1 if n[seg1] != "0": flag = True ans1 = int(n[:seg1]) + int(n[seg1:]) if n[seg2] != "0": flag = True ans2 = int(n[:seg2]) + int(n[seg2:]) if flag == True: if ans1 > 0 and ans2 > 0: print(min(ans1, ans2)) elif ans1 > 0: print(ans1) elif ans2 > 0: print(ans2) break else: flag = False for i in range(0, l // 2): seg1 = int(l / 2 + i) seg2 = int(l / 2 - i) ans1 = -1 ans2 = -1 if n[seg1] != "0": flag = True ans1 = int(n[:seg1]) + int(n[seg1:]) if n[seg2] != "0": flag = True ans2 = int(n[:seg2]) + int(n[seg2:]) if flag == True: if ans1 > 0 and ans2 > 0: print(min(ans1, ans2)) elif ans1 > 0: print(ans1) elif ans2 > 0: print(ans2) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() ans = float("inf") if l < 20: for i in range(1, l): x = int(n[:i]) y = n[i:] if y[0] != "0": ans = min(ans, x + int(y)) else: s = list(n) ind = [] cur = l for i in range(1, l): if s[i] != "0": num = float("inf") if abs(l - i - i) <= 1: num = max(l - i, i) + 1 else: num = max(l - i, i) if num < cur: cur = num for i in range(1, l): if s[i] != "0": num = float("inf") if abs(l - i - i) <= 1: num = max(l - i, i) + 1 else: num = max(l - i, i) if num == cur: ind.append(i) for i in ind: x, y = int(n[:i]), int(n[i:]) ans = min(ans, x + y) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() first = l // 2 + 1 second = l // 2 while second < l and n[second] == "0": second += 1 while n[first] == "0": first -= 1 ans = -1 if second == l: ans = int(n[0:first]) + int(n[first:l]) elif first == 0: ans = int(n[0:second]) + int(n[second:l]) else: ans = min(int(n[0:second]) + int(n[second:l]), int(n[0:first]) + int(n[first:l])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def sum(a, b): if len(a) < len(b): a, b = b, a k = len(a) - 1 k2 = len(b) - 1 i = k j = k2 ost = 0 while j >= 0: sum = int(b[j]) + int(a[i]) + ost ost = sum // 10 sum %= 10 a[i] = str(sum) i -= 1 j -= 1 while i >= 0 and ost != 0: sum = int(a[i]) + ost ost = sum // 10 sum %= 10 a[i] = str(sum) i -= 1 if ost != 0: a = str(ost) + "".join(a) else: a = "".join(a) return a def greather(a, b): if len(a) < len(b): return a elif len(b) < len(a): return b else: k = 0 while k < len(a) and a[k] == b[k]: k += 1 if k == len(a): return a elif a[k] < b[k]: return a else: return b def work(s, bound): c = list(s) if c[bound] != "0": a = c[:bound] b = c[bound:] return sum(a, b) else: k = bound while k >= 0 and c[k] == "0": k -= 1 if k > 0: a = c[:k] b = c[k:] x = sum(a, b) else: x = "" k = bound while k < len(c) and c[k] == "0": k += 1 if k < len(c): a = c[:k] b = c[k:] y = sum(a, b) else: y = "" if x == "" and y != "": return y elif x != "" and y == "": return x elif x == "" and y == "": return "".join(c) else: return greather(x, y) n = int(input()) s = input() if n % 2 == 0: bound = n // 2 rez = work(s, bound) else: bound = n // 2 + 1 rez1 = work(s, bound) bound = n // 2 rez2 = work(s, bound) rez = greather(rez1, rez2) print(rez)
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING IF VAR STRING VAR STRING RETURN VAR IF VAR STRING VAR STRING RETURN VAR IF VAR STRING VAR STRING RETURN FUNC_CALL STRING VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = str(input()) def sum(x): return int(n[:x]) + int(n[x:]) if l % 2 == 0: left = l // 2 - 1 right = l // 2 while n[left] == "0": left -= 1 while right < l and n[right] == "0": right += 1 if right - left == 1: print(sum(right)) elif right == l: if left == 0: print(n) else: print(sum(left)) elif left == 0: print(sum(right)) else: print(min(sum(right), sum(left))) else: left = l // 2 - 1 right = l // 2 while n[left] == "0": left -= 1 while right < l and n[right] == "0": right += 1 if right - left == 1: if n[right + 1] != "0": print(min(sum(right), sum(right + 1))) else: print(sum(right)) elif right == l: if left == 0: print(n) else: print(sum(left)) elif left == 0: print(sum(right)) else: print(min(sum(right), sum(left)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def main(): l = int(input()) s = input() if l % 2 == 0: left = l // 2 right = l // 2 else: left = l // 2 right = l // 2 + 1 while True: if right == left: if s[right] == "0": left -= 1 right += 1 else: first = int(s[:left]) second = int(s[right:]) print(first + second) break elif s[left] != "0" and s[right] != "0": first_left = int(s[:left]) second_left = int(s[left:]) first_right = int(s[:right]) second_right = int(s[right:]) print(min(first_left + second_left, first_right + second_right)) break elif s[left] == "0" and s[right] != "0": first_right = int(s[:right]) second_right = int(s[right:]) print(first_right + second_right) break elif s[left] != "0" and s[right] == "0": first_left = int(s[:left]) second_left = int(s[left:]) print(first_left + second_left) break else: left -= 1 right += 1 main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE NUMBER IF VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if n % 2: k = n // 2 if s[k] != "0": ans = int(s[:k]) + int(s[k:]) if s[k + 1] != "0": ans1 = int(s[: k + 1]) + int(s[k + 1 :]) ans = min(ans, ans1) else: p = k + 1 while p < len(s) and s[p] == "0": p += 1 p1 = k while s[p1] == "0": p1 -= 1 if p1 == 0: ans = int(s[:p]) + int(s[p:]) else: ans = int(s[:p1]) + int(s[p1:]) if p != len(s): ans1 = int(s[:p]) + int(s[p:]) if ans1 < ans: ans = ans1 else: k = n // 2 if s[k] != "0": ans = int(s[:k]) + int(s[k:]) if k + 1 < len(s) and s[k + 1] != "0": ans1 = int(s[: k + 1]) + int(s[k + 1 :]) ans = min(ans, ans1) else: p = k while p < len(s) and s[p] == "0": p += 1 p1 = k while s[p1] == "0": p1 -= 1 if p1 == 0: ans = int(s[:p]) + int(s[p:]) else: ans = int(s[:p1]) + int(s[p1:]) if p != len(s): ans1 = int(s[:p]) + int(s[p:]) if ans1 < ans: ans = ans1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
k = int(input()) a = input() m = int(a) sub = [] ii = (k - 1) // 2 jj = ii + 1 while ii > 0 or jj < k: if ii > 0: if a[ii] != "0": sub.append(ii) ii -= 1 if jj < k: if a[jj] != "0": sub.append(jj) jj += 1 for i in sub[:2]: m = min(m, int(a[:i]) + int(a[i:])) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
le = int(input()) num = input() data = [-1] * 4 mid = le // 2 for i in range(mid + 1, le): if num[i] != "0": if data[2] == -1: data[2] = i else: data[3] = i break for i in range(mid, -1, -1): if num[i] != "0": if data[1] == -1: data[1] = i else: data[0] = i break mn = float("inf") for i in [0, 1, 2, 3]: if data[i] != -1: a = data[i] if a == 0: mn = min(mn, int(num)) else: mn = min(mn, int(num[: data[i]]) + int(num[data[i] :])) print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def getSum(s, rhInd): r1 = rhInd while r1 >= 0 and s[r1] == "0": r1 -= 1 if r1 == 0: s1 = int(s) else: s1 = int(s[:r1]) + int(s[r1:]) r2 = rhInd while r2 < len(s) and s[r2] == "0": r2 += 1 if r2 == len(s): s2 = int(s) else: s2 = int(s[:r2]) + int(s[r2:]) return min(s1, s2) n = int(input()) s = input() if n % 2 == 0: print(getSum(s, n // 2)) else: getSum(s, n // 2) getSum(s, n // 2 + 1) print(min(getSum(s, n // 2), getSum(s, n // 2 + 1)))
FUNC_DEF ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() a = s[: n // 2 + n % 2] b = s[n // 2 + n % 2 :] ch1 = ch3 = int(a) ch2 = ch4 = int(b) fa = 0 for i in range(len(a) - 1, 0, -1): if a[i] != "0": fa = i break for i in range(len(b)): if b[i] != "0": fb = i break if b[0] == "0": if fa != 0: ch1 = int(a[:fa]) else: ch1 = int(s) + 1 ch2 = int(a[fa:] + b) if b.count("0") != len(b): ch3 = int(a + b[:fb]) ch4 = int(b[fb:]) print(min(ch1 + ch2, ch3 + ch4)) else: print(ch1 + ch2) elif a[-1] == "0": print(ch1 + ch2) else: print(min(ch1 + ch2, int(s[: n // 2]) + int(s[n // 2 :])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def findSum(str1, str2): if len(str1) > len(str2): t = str1 str1 = str2 str2 = t str = "" n1 = len(str1) n2 = len(str2) str1 = str1[::-1] str2 = str2[::-1] carry = 0 for i in range(n1): sum = ord(str1[i]) - 48 + (ord(str2[i]) - 48 + carry) str += chr(sum % 10 + 48) carry = int(sum / 10) for i in range(n1, n2): sum = ord(str2[i]) - 48 + carry str += chr(sum % 10 + 48) carry = int(sum / 10) if carry: str += chr(carry + 48) str = str[::-1] return str q = 1 for _ in range(q): n = int(input()) s = input() if n % 2 == 0: j = n // 2 i = n // 2 - 1 if s[i] != "0" and s[j] != "0": p1 = s[0 : i + 1] p2 = s[j:] x = findSum(p1, p2) print(x) else: ans = int(s) while s[i] == "0": i -= 1 p1 = "" if i > 0: p1 = s[0:i] p2 = s[i:] x = findSum(p1, p2) ans = min(ans, int(x)) while j < n and s[j] == "0": j += 1 p1 = s[0:j] p2 = "" if j < n: p2 = s[j:] x = findSum(p1, p2) ans = min(ans, int(x)) print(ans) else: j = n // 2 ans = int(s) if s[j] != "0": p1 = s[0:j] p2 = s[j:] x = findSum(p1, p2) ans = min(ans, int(x)) p1 = s[0 : j + 1] p2 = s[j + 1 :] x = findSum(p1, p2) ans = min(ans, int(x)) print(ans) else: ans = int(s) i = n // 2 while s[i] == "0": i -= 1 p1 = "" if i > 0: p1 = s[0:i] p2 = s[i:] x = findSum(p1, p2) ans = min(ans, int(x)) while j < n and s[j] == "0": j += 1 p1 = s[0:j] p2 = "" if j < n: p2 = s[j:] x = findSum(p1, p2) ans = min(ans, int(x)) print(ans)
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) b = input() flag = 0 newRange = 5 oldRange = 0 ans = int(b) if n < 20: for i in range(0, len(b) - 1): if b[i + 1] != "0": ans = min(ans, int(b[0 : i + 1]) + int(b[i + 1 :])) while flag == 0 and newRange <= n: for i in range(n // 2 - newRange, n // 2 - oldRange): if i < 0 or i >= len(b) - 1: continue if b[i + 1] != "0": flag = 1 ans = min(ans, int(b[0 : i + 1]) + int(b[i + 1 :])) for i in range(n // 2 + oldRange, n // 2 + newRange): if i < 0 or i >= len(b) - 1: continue if b[i + 1] != "0": flag = 1 ans = min(ans, int(b[0 : i + 1]) + int(b[i + 1 :])) oldRange = newRange newRange += 5 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() mini = 1000000000 for i in range(1, n): if s[i] != "0": mini = min(mini, max(i, n - i) + 1) res = 0 for i in range(1, n): if s[i] != "0" and max(i, n - i) + 1 == mini: d = int(s[0:i]) + int(s[i:n]) if res == 0 or res > d: res = d print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if n % 2 == 0: t1 = n // 2 - 1 t2 = n // 2 while s[t1] == "0": t1 -= 1 while t2 < n and s[t2] == "0": t2 += 1 if t2 == n: ans = int(s[:t1]) + int(s[t1:]) elif t1 > 0: ans = min(int(s[:t2]) + int(s[t2:]), int(s[:t1]) + int(s[t1:])) else: ans = int(s[:t2]) + int(s[t2:]) else: t1 = n // 2 - 1 t2 = n // 2 while s[t1] == "0": t1 -= 1 while t2 < n and s[t2] == "0": t2 += 1 if t2 == n: ans = int(s[:t1]) + int(s[t1:]) elif t1 > 0: ans = min(int(s[:t2]) + int(s[t2:]), int(s[:t1]) + int(s[t1:])) else: ans = int(s[:t2]) + int(s[t2:]) t1 = n // 2 t2 = n // 2 + 1 while s[t1] == "0": t1 -= 1 while t2 < n and s[t2] == "0": t2 += 1 if t2 == n: ans = min(ans, int(s[:t1]) + int(s[t1:])) elif t1 > 0: ans = min(ans, int(s[:t2]) + int(s[t2:]), int(s[:t1]) + int(s[t1:])) else: ans = min(ans, int(s[:t2]) + int(s[t2:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys sys.setrecursionlimit(150000) n = int(input()) str1 = input() mid = n // 2 ck1 = mid - 1 ck2 = mid fl1 = fl2 = 0 while ck1 >= 0: if str1[ck1 + 1] != "0": fl1 = 1 break ck1 = ck1 - 1 while ck2 < n - 1: if str1[ck2 + 1] != "0": fl2 = 1 break ck2 = ck2 + 1 in1 = in2 = int(str1) if fl1: in1 = int(str1[0 : ck1 + 1]) + int(str1[ck1 + 1 : n]) if fl2: in2 = int(str1[0 : ck2 + 1]) + int(str1[ck2 + 1 : n]) print(min(in1, in2))
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() poz = [] if n < 100: for i in range(1, n): if s[i] != "0": poz.append(i) else: pol = n // 2 a, b = pol - 1, pol while a > 0 and s[a] == "0": a -= 1 if a > 0 and s[a] != "0": poz.append(a) while a > 0 and s[a] == "0": a -= 1 if a > 0 and s[a] != "0": poz.append(a) while b < n and s[b] == "0": b += 1 if b < n and s[b] != "0": poz.append(b) while b < n and s[b] == "0": b += 1 if b < n and s[b] != "0": poz.append(b) res = -1 for i in poz: l = int(s[:i]) p = int(s[i:]) sum = l + p if res == -1 or sum < res: res = sum print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
len = int(input()) number = input() mid1 = len // 2 while mid1 > 0 and number[mid1] == "0": mid1 -= 1 mid2 = (len + 1) // 2 while mid2 < len and number[mid2] == "0": mid2 += 1 num11 = int(number[0:mid1]) if mid1 > 0 else 0 num12 = int(number[mid1:]) if mid1 < len else 0 num21 = int(number[0:mid2]) if mid2 > 0 else 0 num22 = int(number[mid2:]) if mid2 < len else 0 result = min(num11 + num12, num21 + num22) print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
L = int(input()) X = input() ans = float("inf") cnt = 0 idx = L // 2 while cnt < 5 and idx >= 1: if X[idx] != "0": ans = min(ans, int(X[:idx]) + int(X[idx:])) cnt += 1 idx -= 1 cnt = 0 idx = L // 2 while cnt < 5 and idx < L: if X[idx] != "0": ans = min(ans, int(X[:idx]) + int(X[idx:])) cnt += 1 idx += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys input = lambda: sys.stdin.readline().strip("\r\n") l = int(input()) n = input() ans = float("inf") if l % 2 == 0: mid = l // 2 r = mid l = mid while True: if n[r] != "0": ans = min(ans, int(n[:r]) + int(n[r:])) if n[l] != "0": ans = min(ans, int(n[:l]) + int(n[l:])) if ans != float("inf"): print(ans) break r += 1 l -= 1 else: mid = l // 2 r = mid + 1 l = mid while True: if n[r] != "0": ans = min(ans, int(n[:r]) + int(n[r:])) if n[l] != "0": ans = min(ans, int(n[:l]) + int(n[l:])) if ans != float("inf"): print(ans) break r += 1 l -= 1
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() st = l // 2 if l % 2 != 0 and int(n[: st + 1]) < int(n[st:]): st += 1 if n[st] != "0": sum = int(n[:st]) + int(n[st:]) else: ip = st while n[ip] == "0" and ip < l - 1: ip += 1 il = st while n[il] == "0": il -= 1 if il == 0: sum = int(n[:ip]) + int(n[ip:]) elif ip == l - 1: sum = int(n[:il]) + int(n[il:]) else: sum = min(int(n[:il]) + int(n[il:]), int(n[:ip]) + int(n[ip:])) print(sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) number = int(input()) s = str(number) def nextNum(num): if num < l / 2: return l - num else: return l - 1 - num m = l // 2 while s[m] == "0": m = nextNum(m) f = int(s[:m]) + int(s[m:]) next = nextNum(m) if next > 0 and s[next] != "0": g = int(s[:next]) + int(s[next:]) print(min(f, g)) else: print(f)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() l = n // 2 r = (n + 1) // 2 while s[l] == "0" == s[r]: l -= 1 r += 1 f = [] if l and s[l] != "0": f.append(int(s[:l]) + int(s[l:])) if r < n and s[r] != "0": f.append(int(s[:r]) + int(s[r:])) print(min(f))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() if l & 1 == 0: if n[l // 2] != "0": print(int(n[: l // 2]) + int(n[l // 2 :])) else: ind = l // 2 while ind < l and n[ind] == "0": ind += 1 if ind >= l: temp1 = int(n[:ind]) else: temp1 = int(n[:ind]) + int(n[ind:]) ind = l // 2 while ind > 0 and n[ind] == "0": ind -= 1 if ind > 0: temp2 = int(n[:ind]) + int(n[ind:]) else: temp2 = int(n) print(min(temp1, temp2)) else: if n[l // 2] != "0": temp1 = int(n[: l // 2]) + int(n[l // 2 :]) else: ind = l // 2 while ind < l and n[ind] == "0": ind += 1 if ind >= l: temp1 = int(n[:ind]) else: temp1 = int(n[:ind]) + int(n[ind:]) ind = l // 2 while ind > 0 and n[ind] == "0": ind -= 1 if ind > 0: temp2 = int(n[:ind]) + int(n[ind:]) else: temp2 = int(n) temp1 = min(temp1, temp2) if n[l // 2 + 1] != "0": temp3 = int(n[: l // 2 + 1]) + int(n[l // 2 + 1 :]) else: ind = l // 2 + 1 while ind < l and n[ind] == "0": ind += 1 if ind >= l: temp3 = int(n[:ind]) else: temp3 = int(n[:ind]) + int(n[ind:]) ind = l // 2 + 1 while ind > 0 and n[ind] == "0": ind -= 1 if ind > 0: temp4 = int(n[:ind]) + int(n[ind:]) else: temp4 = int(n) temp3 = min(temp3, temp4) print(min(temp3, temp1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
input() a = input() lena = len(a) x = lena // 2 y = x + 1 while a[x] == "0": x -= 1 while y < lena - 1 and a[y] == "0": y += 1 s = [] inf = int("9" * 100001) def sum(x): try: b = int(a[:x]) c = int(a[x:]) 1 / int(a[x:][0]) res = b + c except Exception: res = inf return res s.append(sum(x)) s.append(sum(x - 1)) s.append(sum(x + 1)) s.append(sum(y)) s.append(sum(y - 1)) s.append(sum(y + 1)) print(min(s))
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP STRING NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = input() n = input() l = int(l) k = int(n) if l == 1: print(n) elif l == 2 and k % 10 == 0: print(int(n[0]) + int(n[1])) else: mid = int(l / 2) p = mid x = mid while p < l: if n[p] == "0": p = p + 1 else: break while x >= 0: if n[x] == "0": x = x - 1 else: break if l % 2 == 0: if p < l: s1 = n[:p] s2 = n[p:] if x != 0: s3 = n[:x] s4 = n[x:] if int(s1) + int(s2) > int(s3) + int(s4): print(int(s3) + int(s4)) else: print(int(s1) + int(s2)) else: print(int(s1) + int(s2)) else: s3 = n[:x] s4 = n[x:] print(int(s3) + int(s4)) elif n[mid] == "0": if p < l: s1 = n[:p] s2 = n[p:] if x != 0: s3 = n[:x] s4 = n[x:] if int(s1) + int(s2) > int(s3) + int(s4): print(int(s3) + int(s4)) else: print(int(s1) + int(s2)) else: print(int(s1) + int(s2)) else: s3 = n[:x] s4 = n[x:] print(int(s3) + int(s4)) else: s1 = n[:p] s2 = n[p:] s3 = n[: p + 1] s4 = n[p + 1 :] if int(s1) + int(s2) > int(s3) + int(s4): print(int(s3) + int(s4)) else: print(int(s1) + int(s2))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() l = n // 2 i = l j = l + 1 k1 = 0 k2 = 0 while i > 0 and s[i] == "0": i -= 1 while j < n and s[j] == "0": j += 1 if j != n: k2 = int(s[:j]) + int(s[j:]) if i == 0: print(k2) elif j == n: k1 = int(s[:i]) + int(s[i:]) print(k1) else: k1 = int(s[:i]) + int(s[i:]) print(min(k1, k2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def calc(i): res = -1 a = s[0 : i + 1] b = s[i + 1 :] if b[0] != "0": if res == -1: res = int(a) + int(b) else: res = min(int(a) + int(b), res) return res n = int(input()) s = input() x = n // 2 y = (n + 1) // 2 a = [] for i in range(n): l = x - i - 1 r = y + i - 1 t1 = -1 t2 = -1 if l >= 0: t1 = calc(l) if r < n - 1: t2 = calc(r) if t1 != -1: a.append(t1) if t2 != -1: a.append(t2) if len(a) > 5: break a.sort() print(a[0])
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() mid = l // 2 choose = [] for i in range(mid, l): if n[i] == "0": continue choose.append(int(n[:i]) + int(n[i:])) if len(choose) >= 3: break for i in range(1, mid)[::-1]: if n[i] == "0": continue choose.append(int(n[:i]) + int(n[i:])) if len(choose) >= 6: break choose.sort() print(choose[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def gns(): return list(map(int, input().split())) n = int(input()) s = input() def sm(x): ans = [] l = 0 i, j = x, n - 1 while i >= 0 or j > x: if i >= 0: si = s[i] else: si = 0 sj = s[j] if j > x else 0 t = int(si) + int(sj) + l l = t // 10 t = t % 10 ans.append(t) i -= 1 j -= 1 if ans[-1] == 0: ans.pop() return ans def cm(x, y): if len(x) > len(y): return True if len(y) > len(x): return False i = len(x) - 1 while i >= 0: if x[i] > y[i]: return True elif x[i] == y[i]: i -= 1 continue else: return False def r(x): print("".join(map(str, x[::-1]))) if n % 2 == 0: m = n // 2 - 1 x, y = m, m else: m = n // 2 x, y = m - 1, m if True: while x >= 0 and y < n and s[x + 1] == "0" and s[y + 1] == "0": x -= 1 y += 1 if s[x + 1] != "0" and s[y + 1] != "0": smx = sm(x) smy = sm(y) if cm(smx, smy): r(smy) quit() else: r(smx) quit() elif s[x + 1] != "0": smx = sm(x) r(smx) quit() elif s[y + 1] != "0": smy = sm(y) r(smy) quit()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if "0" not in s: if n % 2 == 0: print(int(s[: n // 2]) + int(s[n // 2 :])) else: print( min( int(s[: n // 2]) + int(s[n // 2 :]), int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]), ) ) else: right = -1 left = -1 for i in range(n // 2, -1, -1): if s[i] != "0": left = i break for i in range(n // 2, n): if s[i] != "0": right = i break ans1 = int(s[left:]) if left != 0: ans1 += int(s[0:left]) an2 = int(s[right:]) + int(s[0:right]) if right == -1: an2 = ans1 print(min(ans1, an2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) a = int(input()) s = str(a) l = [] for i in range(int(n / 2), n): if s[i] != "0": l.append(int(s[i:]) + int(s[:i])) break if n > 2: for i in range(int(n / 2) + 1, 0, -1): if s[i] != "0": l.append(int(s[i:]) + int(s[:i])) break print(min(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def solve_left(num, len): x = num[0 : (len + 1) // 2] y = num[(len + 1) // 2 : len] ptr = 1 while y.startswith("0"): x = num[0 : (len + 1) // 2 - ptr] y = num[(len + 1) // 2 - ptr : len] ptr = ptr + 1 if y == num: return int(y) return int(x) + int(y) def solve_right(num, len): x = num[0 : len // 2] y = num[len // 2 : len] ptr = 1 while y.startswith("0"): x = num[0 : (len + 1) // 2 + ptr] y = num[(len + 1) // 2 + ptr : len] ptr = ptr + 1 if x == num: return int(x) return int(x) + int(y) def main(): len = int(input()) num = input() print(min(solve_left(num, len), solve_right(num, len))) main()
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input().strip() ans = int(s) mid = n // 2 + 1 mid1 = n // 2 while mid < n and s[mid] == "0": mid = mid + 1 while mid1 > 0 and s[mid1] == "0": mid1 = mid1 - 1 try: if mid1 > 0: ans = min(ans, int(s[0:mid1]) + int(s[mid1:])) if mid < n: ans = min(ans, int(s[0:mid]) + int(s[mid:])) except: pass print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() for i in range(l // 2, 0, -1): if s[i] != "0" and s[l - i] != "0": print(min(int(s[:i]) + int(s[i:]), int(s[: l - i]) + int(s[l - i :]))) break elif s[i] != "0": print(int(s[:i]) + int(s[i:])) break elif s[l - i] != "0": print(int(s[: l - i]) + int(s[l - i :])) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys l = int(input()) S = input() if l % 2 == 0: m2 = l // 2 m1 = m2 - 1 if S[m2] != "0": print(int(S[:m2]) + int(S[m2:])) sys.exit() m2 += 1 else: m1 = l // 2 m2 = m1 + 1 while S[m1] == "0" and S[m2] == "0": m1 -= 1 m2 += 1 if S[m1] != "0" and S[m2] != "0": print(min(int(S[:m1]) + int(S[m1:]), int(S[:m2]) + int(S[m2:]))) elif S[m1] != "0": print(int(S[:m1]) + int(S[m1:])) else: print(int(S[:m2]) + int(S[m2:]))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) ns = input() rr = l // 2 ll = (l + 1) // 2 def gett(x): return int(ns[:x]) + int(ns[x:]) for _ in range(l): if (ll >= 1 and ns[ll] != "0") and (rr < l and ns[rr] != "0"): ansl = gett(ll) ansr = gett(rr) print(min(ansl, ansr)) break if ll >= 1 and ns[ll] != "0": print(gett(ll)) break if rr < l and ns[rr] != "0": print(gett(rr)) break ll = ll - 1 rr = rr + 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() pos1 = l // 2 pos2 = pos1 + 1 while pos1 >= 0 and n[pos1] == "0": pos1 -= 1 while pos2 < l and n[pos2] == "0": pos2 += 1 s1 = int("0" + n[:pos1]) + int("0" + n[pos1:]) s2 = int("0" + n[:pos2]) + int("0" + n[pos2:]) print(min(s1, s2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR VAR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR VAR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() ans = float("inf") if l & 1: i, j = l // 2, l // 2 + 1 while j < l and n[j] == "0": j += 1 while i > 0 and n[i] == "0": i -= 1 if i: ans = min(ans, int(n[:i]) + int(n[i:])) if j != l: ans = min(ans, int(n[:j]) + int(n[j:])) print(ans) else: i, j = l // 2 - 1, l // 2 while j < l and n[j] == "0": j += 1 while i > 0 and n[i] == "0": i -= 1 if i: ans = min(ans, int(n[:i]) + int(n[i:])) if j != l: ans = min(ans, int(n[:j]) + int(n[j:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) a = int(input()) b = str(a) t = [0] * n counter = 0 x = 1 y = n - 1 z = 0 for i in range(n - 1, 0, -1): if b[i] != "0": t[z] = [max(x, y) + 1, x] z += 1 x += 1 y -= 1 temp = [0] * z for i in range(z): temp[i] = t[i] if z == 1: x1 = pow(10, temp[0][1]) a1 = a // x1 + a % x1 print(a1) else: temp.sort() x1 = pow(10, temp[0][1]) x2 = pow(10, temp[1][1]) a1 = a // x1 + a % x1 a2 = a // x2 + a % x2 if a1 < a2: print(a1) else: print(a2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR LIST BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input().strip() k = l // 2 ans = int(n) def getLeft(i): while i >= 0: if n[i] is not "0": break else: i = i - 1 return i def getRight(i, l): while i < l: if n[i] is not "0": break else: i = i + 1 return i if l % 2 is 0: if n[k] is not "0": ans = int(n[:k]) + int(n[k:]) else: i = getLeft(k) ans = int(n[:i]) + int(n[i:]) i = getRight(k, l) if i is l: ans = min(ans, int(n)) else: ans = min(ans, int(n[:i]) + int(n[i:])) else: k1 = l // 2 if n[k1] is not "0": ans1 = int(n[:k1]) + int(n[k1:]) else: i = getLeft(k1) if i is 0 or i is l: ans1 = int(n) else: ans1 = int(n[:i]) + int(n[i:]) i = getRight(k1, l) if i is 0 or i is l: ans1 = min(ans1, int(n)) else: ans1 = min(ans1, int(n[:i]) + int(n[i:])) k2 = k1 + 1 if n[k2] is not "0": if k2 is l: ans2 = int(n) else: ans2 = int(n[:k2]) + int(n[k2:]) else: i = getLeft(k2) if i is 0 or i is l: ans2 = int(n) else: ans2 = int(n[:i]) + int(n[i:]) i = getRight(k2, l) if i is 0 or i is l: ans2 = min(ans2, int(n)) else: ans2 = min(ans2, int(n[:i]) + int(n[i:])) ans = min(ans1, ans2) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
len_num = int(input()) num_str = input() len_1 = len_num // 2 len_2 = len_1 if len_num & 1: len_2 += 1 flag = 0 ans = 0 while True: if num_str[len_1] != "0": num1 = int(num_str[:len_1]) + int(num_str[len_1:len_num]) ans = num1 flag = 1 if len_2 < len_num and num_str[len_2] != "0": num2 = int(num_str[:len_2]) + int(num_str[len_2:len_num]) if flag: if ans > num2: ans = num2 else: ans = num2 flag = 1 len_1 -= 1 len_2 += 1 if flag: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def string_sum(str1, str2): if len(str1) > len(str2): t = str1 str1 = str2 str2 = t str = "" n1 = len(str1) n2 = len(str2) str1 = str1[::-1] str2 = str2[::-1] carry = 0 for i in range(n1): sum = ord(str1[i]) - 48 + (ord(str2[i]) - 48 + carry) str += chr(sum % 10 + 48) carry = int(sum / 10) for i in range(n1, n2): sum = ord(str2[i]) - 48 + carry str += chr(sum % 10 + 48) carry = int(sum / 10) if carry: str += chr(carry + 48) str = str[::-1] return str l = int(input()) n = input() if 1: res = 0 s1 = "" s2 = "" n1 = str(n) cnt = 0 for i in range(0, l // 2): s1 += n1[i] for i in range(l // 2, l): s2 += n1[i] if s2[0] != "0": res = string_sum(s1, s2) for i in s2: if i == "0": cnt += 1 else: break res1 = 0 if s2[cnt:] != "": res1 = string_sum(s1 + s2[:cnt], s2[cnt:]) if res != 0 and res1 != 0: if len(res) < len(res1): res = res elif len(res) > len(res1): res = res1 else: res = min(res, res1) elif res1 != 0: res = res1 id1 = 0 res2 = 0 if 1: for i in range(len(s1)): if s1[i] != "0": id = i temp = "" for i in range(id, len(s1)): temp += s1[i] s2 = temp + s2 temp = "" for i in range(0, id): temp += s1[i] s1 = temp res2 = 0 if s1 != "" and s2 != "" and s2[0] != "0": res2 = string_sum(s1, s2) if res != 0 and res2 != 0: if len(res) < len(res2): res = res elif len(res) > len(res2): res = res2 else: res = min(res, res2) elif res2 != 0: res = res2 if l % 2 != 0: s1 = "" s2 = "" n1 = str(n) cnt = 0 for i in range(0, l // 2 + 1): s1 += n1[i] for i in range(l // 2 + 1, l): s2 += n1[i] if s2[0] != "0" and res != 0: temp = string_sum(s1, s2) if len(res) < len(temp): res = res elif len(res) > len(temp): res = temp else: res = min(res, temp) for i in s2: if i == "0": cnt += 1 else: break res1 = 0 if s2[cnt:] != "": res1 = string_sum(s1 + s2[:cnt], s2[cnt:]) if res != 0 and res1 != 0: if len(res) < len(res1): res = res elif len(res) > len(res1): res = res1 else: res = min(res, res1) elif res1 != 0: res = res1 id1 = 0 res2 = 0 if 1: for i in range(len(s1)): if s1[i] != "0": id = i temp = "" for i in range(id, len(s1)): temp += s1[i] s2 = temp + s2 temp = "" for i in range(0, id): temp += s1[i] s1 = temp res2 = 0 if s1 != "" and s2 != "" and s2[0] != "0": res2 = string_sum(s1, s2) if res != 0 and res2 != 0: if len(res) < len(res2): res = res elif len(res) > len(res2): res = res2 else: res = min(res, res2) elif res2 != 0: res = res2 print(res)
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def main(): n = int(input()) s = input() s2 = "" s1 = "" mid = n // 2 l = mid while s[l] == "0": l -= 1 for i in range(l, n, 1): s2 += s[i] for i in range(0, l, 1): s1 += s[i] if len(s1) and len(s2): sum1 = int(s1) + int(s2) else: sum1 = int(s) p1 = "" p2 = "" l = mid while l + 1 < n and s[l + 1] == "0": l += 1 for i in range(l + 1, n, 1): p2 += s[i] for i in range(0, l + 1, 1): p1 += s[i] if len(p1) and len(p2): sum2 = int(p1) + int(p2) else: sum2 = int(s) res = min(sum1, sum2) print(res) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) t = n // 2 s = input() while s[t] == "0": t -= 1 k = n // 2 + 1 while k < len(s) and s[k] == "0": k += 1 ans1 = -1 ans2 = -1 if t > 0: ans1 = int(s[:t]) + int(s[t:]) if k < len(s): ans2 = int(s[:k]) + int(s[k:]) if ans1 == -1: print(ans2) elif ans2 == -1: print(ans1) else: print(min(ans1, ans2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() ans = float("inf") for i in range(n // 2, n - 1): if s[i + 1] != "0": ans = min(ans, int(s[: i + 1]) + int(s[i + 1 :])) break for i in range(n // 2 - 1, -1, -1): if s[i + 1] != "0": ans = min(ans, int(s[: i + 1]) + int(s[i + 1 :])) break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() n = int(s) if l % 2 == 0: div = int(l / 2) if s[div] != "0": s1 = int(s[:div]) s2 = int(s[div:]) print(s1 + s2) else: right = l for i in range(int(l / 2), l): if s[i] != "0": right = i break for i in range(int(l / 2) - 1, -1, -1): if s[i] != "0": left = i break if right != l: s1 = int(s[:right]) s2 = int(s[right:]) else: s1 = n s2 = n if left != 0: s3 = int(s[:left]) s4 = int(s[left:]) else: s3 = n s4 = n print(min(s1 + s2, s3 + s4)) else: check1 = int(l / 2) s1 = n s2 = n s3 = n s4 = n if s[check1 + 1] != "0": s1 = int(s[: check1 + 1]) s2 = int(s[check1 + 1 :]) if s[check1] != "0": s3 = int(s[:check1]) s4 = int(s[check1:]) if s[check1] == "0" and s[check1 + 1] == "0": right = l for i in range(int(l / 2), l): if s[i] != "0": right = i break for i in range(int(l / 2), -1, -1): if s[i] != "0": left = i break if right != l: s5 = int(s[:right]) s6 = int(s[right:]) else: s5 = n s6 = n if left != 0: s7 = int(s[:left]) s8 = int(s[left:]) else: s7 = n s8 = n print(min(s5 + s6, s7 + s8)) else: print(min(s1 + s2, s3 + s4))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() l = int(n / 2) r = int((n + 1) / 2) while l and s[l] == "0": l -= 1 while r != n - 1 and s[r] == "0": r += 1 if l == 0 or r == n - 1: if l == 0: ans = int(s[:r]) + int(s[r:]) else: ans = int(s[:l]) + int(s[l:]) else: ans = min(int(s[:l]) + int(s[l:]), int(s[:r]) + int(s[r:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def main(): n = int(input()) num = input() bsum = None begin = n // 2 i = -1 while True: i += 1 if begin + i + 1 >= n: break if num[begin + i + 1] == "0": continue csum = int(num[: begin + i + 1]) + int(num[begin + i + 1 :]) if not bsum: bsum = csum else: bsum = min([bsum, csum]) if i > 2: break begin = n // 2 i = 1 while True: i -= 1 if begin + i <= 0: break if num[begin + i] == "0": continue csum = int(num[: begin + i]) + int(num[begin + i :]) if not bsum: bsum = csum else: bsum = min([bsum, csum]) if i < -2: break print(bsum) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def findSum(str1, str2): if len(str1) > len(str2): t = str1 str1 = str2 str2 = t str = "" n1 = len(str1) n2 = len(str2) str1 = str1[::-1] str2 = str2[::-1] carry = 0 for i in range(n1): sum = ord(str1[i]) - 48 + (ord(str2[i]) - 48 + carry) str += chr(sum % 10 + 48) carry = int(sum / 10) for i in range(n1, n2): sum = ord(str2[i]) - 48 + carry str += chr(sum % 10 + 48) carry = int(sum / 10) if carry: str += chr(carry + 48) str = str[::-1] return str l = int(input()) s = input() i = l // 2 + 1 while i < l and s[i] == "0": i += 1 j = l // 2 while j >= 0 and s[j] == "0": j -= 1 j -= 1 if i != l and j != -1: a1 = findSum(s[0:i], s[i:]) a2 = findSum(s[0 : j + 1], s[j + 1 :]) if len(a1) < len(a2): print(a1) elif len(a2) < len(a1): print(a2) else: print(min(a1, a2)) elif i != l: print(findSum(s[0:i], s[i:])) else: print(findSum(s[0 : j + 1], s[j + 1 :]))
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys def rl(proc=None): if proc is not None: return proc(sys.stdin.readline()) else: return sys.stdin.readline().rstrip() def srl(proc=None): if proc is not None: return list(map(proc, rl().split())) else: return rl().split() def test(r, s, p): if p <= 0 or p >= len(s) or s[p] == "0": return r return min(r, int(s[:p]) + int(s[p:])) def main(): rl() x = rl() r = int(x) p = len(x) // 2 for i in range(-3, 3): r = test(r, x, p + i) for t in range(p - 3, 0, -1): if x[t] != "0": r = test(r, x, t) break for t in range(p + 3, len(x)): if x[t] != "0": r = test(r, x, t) break print(r) main()
IMPORT FUNC_DEF NONE IF VAR NONE RETURN FUNC_CALL VAR FUNC_CALL VAR RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE IF VAR NONE RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() a = int(s) for k in range(-1, 2): if n // 2 + k >= 0 and n // 2 + k < n: for i in range(max(1, n // 2 + k), n): if s[i] != "0": a = min(a, int(s[i:]) + int(s[:i])) break for i in range(n // 2 + k, 0, -1): if s[i] != "0": a = min(a, int(s[i:]) + int(s[:i])) break print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys try: sys.stdin = open("in.in", "r") except: pass n = int(input()) s = input().strip() l_non0 = [-1] * n r_non0 = [-1] * n for i in range(n): if s[i] == "0": l_non0[i] = -1 if i == 0 else l_non0[i - 1] else: l_non0[i] = i for i in range(n - 1, -1, -1): if s[i] == "0": r_non0[i] = -1 if i == n - 1 else r_non0[i + 1] else: r_non0[i] = i bl = max(0, n // 2 - 2) br = min(n, n // 2 + 2) def Calc(pos): return int(s[0:pos]) + int(s[pos:n]) ans = -1 for i in range(bl, br): if l_non0[i] != -1 and l_non0[i] != 0: tans = Calc(l_non0[i]) if ans == -1 or ans > tans: ans = tans if r_non0[i] != -1 and r_non0[i] != 0: tans = Calc(r_non0[i]) if ans == -1 or ans > tans: ans = tans print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if n == 2: print(int(s[0]) + int(s[1])) else: mid = len(s) // 2 mid1 = mid - 1 mid2 = mid + 1 while mid1 > 0 and s[mid1] == "0": mid1 -= 1 while mid2 < n and s[mid2] == "0": mid2 += 1 r = [] if s[mid] != "0": bst1 = int(s[:mid]) + int(s[mid:]) r.append(bst1) if mid1 > 0: r.append(int(s[:mid1]) + int(s[mid1:])) if mid2 < n: r.append(int(s[:mid2]) + int(s[mid2:])) print(min(r))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR LIST IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() x = l // 2 while n[x] == "0": x += 1 if x == l: break y = l // 2 while n[y] == "0": y -= 1 A = 10**101 B = A C = A if y != 0: A = int(n[:y]) + int(n[y:]) if x != l: B = int(n[:x]) + int(n[x:]) if x < l - 1 and n[x + 1] != "0": C = int(n[: x + 1]) + int(n[x + 1 :]) print(min(A, B, C))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() ans = int(n) x = l // 2 + 1 while x < l and n[x] == "0": x += 1 if x < l and n[x] != "0": ans = min(int(n[x:]) + int(n[:x]), ans) x = l // 2 while x and n[x] == "0": x -= 1 if x and n[x] != "0": ans = min(int(n[x:]) + int(n[:x]), ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) number = input() checks = [] counter = 0 i = l // 2 while counter < 2 and i < l: if number[i] != "0": checks.append(i) counter += 1 i += 1 i = l // 2 - 1 counter = 0 while counter < 1 and i > 0: if number[i] != "0": checks.append(i) counter += 1 i -= 1 ans = -1 for check in checks: new_sum = int(number[check:]) + int(number[:check]) if ans == -1 or new_sum < ans: ans = new_sum print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() mid = l // 2 c = 0 v1 = v2 = int(n) if n[mid] == "0": for i in n[mid:]: if i == "0": c += 1 else: break if mid + c < l: v1 = int(n[: mid + c]) + int(n[mid + c :]) c = 0 for i in n[mid::-1]: if i == "0": c -= 1 else: break if mid + c > 0: v2 = int(n[: mid + c]) + int(n[mid + c :]) print(min(v1, v2)) elif mid + 1 < l: print(min(int(n[: mid + 1]) + int(n[mid + 1 :]), int(n[:mid]) + int(n[mid:]))) else: print(int(n[:mid]) + int(n[mid:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR VAR VAR IF VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) string = input() if n % 2 == 0: index = n // 2 for i in range(index, n): if string[i] != "0": index = i break ans = int(10**100000) if string[index] != "0": ans = int(string[:index]) + int(string[index:]) index = n // 2 - 1 for i in range(index, -1, -1): if string[i] != "0": index = i break if index != 0 and string[index] != "0": ans = min(ans, int(string[:index]) + int(string[index:])) print(ans) else: index = n // 2 + 1 for i in range(index, n): if string[i] != "0": index = i break ans = int(10**100000) if string[index] != "0": ans = int(string[:index]) + int(string[index:]) index = n // 2 for i in range(index, -1, -1): if string[i] != "0": index = i break if index != 0 and string[index] != "0": ans = min(ans, int(string[:index]) + int(string[index:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR