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.
n = int(input()) x = input() l = n // 2 r = (n + 1) // 2 fn = lambda i: int(x[:i]) + int(x[i:]) while x[l] == "0": l -= 1 while x[r] == "0": r += 1 if r == n: break ans = float("inf") if l != 0: ans = min(ans, fn(l)) if r != n: ans = min(ans, fn(r)) print(ans)
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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF 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.
def closest_nonzero(s, h, l): index1 = 0 index = 0 for i in range(h, l): if n[i] != "0": index = i break for i in range(h, -1, -1): if n[i] != "0": index1 = i break return index, index1 l = int(input()) n = input() half = l // 2 if l % 2 == 0: even = True else: even = False if even: index, index1 = closest_nonzero(n, half, l) if index == 0 and index1 == 0: ans = min(int(n[index:]), int(n[index1:])) elif index == 0: ans = min(int(n[index:]), int(n[:index1]) + int(n[index1:])) elif index1 == 0: ans = min(int(n[:index]) + int(n[index:]), int(n[index1:])) else: ans = min(int(n[:index]) + int(n[index:]), int(n[:index1]) + int(n[index1:])) print(ans) else: index, index1 = closest_nonzero(n, half, l) if index == 0 and index1 == 0: ans = min(int(n[index:]), int(n[index1:])) elif index == 0: ans = min(int(n[index:]), int(n[:index1]) + int(n[index1:])) elif index1 == 0: ans = min(int(n[:index]) + int(n[index:]), int(n[index1:])) else: ans = min(int(n[:index]) + int(n[index:]), int(n[:index1]) + int(n[index1:])) index, index1 = closest_nonzero(n, half + 1, l) if index == 0 and index1 == 0: ans1 = min(int(n[index:]), int(n[index1:])) elif index == 0: ans1 = min(int(n[index:]), int(n[:index1]) + int(n[index1:])) elif index1 == 0: ans1 = min(int(n[:index]) + int(n[index:]), int(n[index1:])) else: ans1 = min(int(n[:index]) + int(n[index:]), int(n[:index1]) + int(n[index1:])) print(min(ans, ans1))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR RETURN VAR VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 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 ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 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 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 a = sys.stdin.read().split()[1].strip() ans = int(a) n = len(a) k = n // 2 m = 0 i = k while m < 3 and i < n: if a[i] != "0": m += 1 s = int(a[:i]) + int(a[i:]) if s < ans: ans = s i += 1 m = 0 i = k while m < 3 and i > 0: if a[i] != "0": m += 1 s = int(a[:i]) + int(a[i:]) if s < ans: ans = s i -= 1 print(ans)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR 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()) b = input() aaa = n // 2 if n & 1 == 0: for i in range(0, aaa): num1 = aaa + i num = n - num1 if b[num] == "0" and b[num1] == "0": continue elif b[num] == "0": ans1 = int(b[:num1]) + int(b[num1:n]) print(ans1) break elif b[num1] == "0": ans2 = int(b[:num]) + int(b[num:n]) print(ans2) break else: ans1 = int(b[:num]) + int(b[num:n]) ans2 = int(b[:num1]) + int(b[num1:n]) if ans1 > ans2: print(ans2) else: print(ans1) break else: for i in range(0, aaa + 1): num = aaa - i + 1 num1 = aaa + i if b[num] == "0" and b[num1] == "0": continue elif b[num] == "0": ans1 = int(b[:num1]) + int(b[num1:n]) print(ans1) break elif b[num1] == "0": ans2 = int(b[:num]) + int(b[num:n]) print(ans2) break else: ans1 = int(b[:num]) + int(b[num:n]) ans2 = int(b[:num1]) + int(b[num1:n]) if ans1 > ans2: print(ans2) else: print(ans1) break
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 FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR 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 = str(input()) ans = int(n) mid = int(l / 2 + 1) while mid < int(l): if n[mid] == "0": mid += 1 continue l1 = n[0:mid] l2 = n[mid:] ans1 = int(l1) + int(l2) ans = min(ans, ans1) mid += 1 break mid = int(l / 2) while mid > 0: if n[mid] == "0": mid -= 1 continue l1 = n[0:mid] l2 = n[mid:] ans1 = int(l1) + int(l2) ans = min(ans, ans1) mid -= 1 break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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.
def summ(i): global a b = a[:i] c = a[i:] if len(b) < len(c): b = [0] * (len(c) - len(b)) + b[:] if len(c) < len(b): c = [0] * (len(b) - len(c)) + c[:] ans = ["0"] * len(b) car = 0 for i in range(len(b) - 1, -1, -1): ans[i] = str((int(b[i]) + int(c[i]) + car) % 10) car = (int(b[i]) + int(c[i]) + car) // 10 if car != 0: ans = [car] + ans[:] return "".join(ans) def comp(a, b): if len(a) < len(b): return a elif len(b) < len(a): return b else: i = 0 while i < len(a) and a[i] == b[i]: i += 1 if i == len(a): return a elif int(a[i]) < int(b[i]): return a else: return b def minn(i, j): return comp(summ(i), summ(j)) n = int(input()) a = list(input()) if a.count("0") == n - 1: print("".join(a)) elif n % 2 == 0: t = n // 2 if a[t] != "0": print(summ(n // 2)) else: c = 0 j = t while j < n and a[j] == "0": j += 1 i = t while i > 0 and a[i] == "0": i -= 1 t1 = n - i t2 = j if t1 > t2: print(summ(j)) elif t1 < t2: print(summ(i)) else: print(minn(j, i)) else: t = n // 2 if a[t] != "0": print(minn(n // 2, n // 2 + 1)) else: c = 0 j = t while j < n and a[j] == "0": j += 1 i = t while i > 0 and a[i] == "0": i -= 1 t1 = n - i t2 = j if t1 > t2: print(summ(j)) elif t1 < t2: print(summ(i)) else: print(minn(j, i))
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR RETURN FUNC_CALL STRING 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 FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN VAR FUNC_DEF 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 IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR 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 = str(input()) a1 = 0 a2 = 0 for i in range(l // 2 + 1, l): n1 = n[i:] n2 = n[:i] if n1[0] == "0": continue else: a1 = int(n1) + int(n2) break for i in range(l // 2, 0, -1): n1 = n[i:] n2 = n[:i] if n1[0] == "0": continue else: a2 = int(n1) + int(n2) break if a1 == 0: print(a2) elif a2 == 0: print(a1) else: print(min(a1, a2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL 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()) a = input() i_l = n // 2 i_r = n // 2 + 1 while i_r < n and a[i_r] == "0": i_r += 1 min1 = 2**64 - 1 if i_r != n: min1 = int(a[0:i_r]) + int(a[i_r:]) while i_l >= 0 and a[i_l] == "0": i_l -= 1 if i_l > 0: min1 = min(min1, int(a[0:i_l]) + int(a[i_l:])) print(min1)
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 VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER 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()) N = input() mn = int(N) m = (L - 1) // 2 for i in range(m, -1, -1): if N[i + 1] == "0": continue mn = min(mn, int(N[0 : i + 1]) + int(N[i + 1 :])) break m = L // 2 for i in range(m, L): if N[i] == "0": continue mn = min(mn, int(N[0:i]) + int(N[i:])) break print(mn)
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 FOR VAR FUNC_CALL VAR VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING 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.
n = int(input()) s = "0" + input() n += 1 ind = n // 2 ans = [] i = c = 0 while ind - i > 0 and ind + i < n: if s[ind + i] != "0": ans.append(int(s[: ind + i]) + int(s[ind + i :])) c += 1 if s[ind - i] != "0": ans.append(int(s[: ind - i]) + int(s[ind - i :])) c += 1 i += 1 if c > 4: break if n == 3 and s[2] != "0": ans.append(int(s[1]) + int(s[2])) print(min(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP 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 VAR NUMBER 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 VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR 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.
n = int(input()) s = input() al_l = [] al_r = [] for i in range(1, n): if int(s[i]) > 0 and i <= n // 2: al_l.append(i) if int(s[i]) > 0 and i > n // 2: al_r.append(i) if len(al_r) == 3: break if len(al_l) == 3: del al_l[0] ans = int(s) for x in al_l: ans = min(ans, int(s[0:x]) + int(s[x:])) for x in al_r: ans = min(ans, int(s[0:x]) + int(s[x:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR 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()) n = list(input()) ans = int("".join(n)) if l == 1: print(ans) exit(0) f = 0 for i in range(l // 2, 0, -1): if n[i] != "0": ans = min(ans, int("".join(n[:i])) + int("".join(n[i:]))) f = 1 if n[l - i] != "0": ans = min(ans, int("".join(n[: l - i])) + int("".join(n[l - i :]))) f = 1 if f == 1: print(ans) exit(0) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL 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()) num = str(input()) n = int(num) x = len(num) mns = n * 100 h = (x - 1) // 2 def test(i): s = int(num[:i]) + int(num[i:]) if s < mns: return s return mns ct = 0 for i in range(h, -1, -1): if num[i] != "0" and i > 0: mns = test(i) ct += 1 if ct >= 3: break ct = 0 for i in range(h + 1, x): if num[i] != "0": mns = test(i) ct += 1 if ct >= 3: break print(mns)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER 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 = str(input()) mid = int(l / 2) m1 = int(n) m2 = int(n) sp = mid for i in range(sp, 0, -1): if n[i] != "0": temp = int(n[:i]) + int(n[i:]) if m1 > temp: m1 = temp else: break else: pass sp = mid + 1 for i in range(sp, len(n)): if n[i] != "0": temp = int(n[:i]) + int(n[i:]) if m2 > temp: m2 = temp else: break else: pass print(min(m1, m2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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 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() mid = len(s) // 2 l = mid r = mid + 1 while l >= 0 and s[l] == "0": l -= 1 while r < len(s) and s[r] == "0": r += 1 if r == len(s): s1 = int(s[0:l]) s2 = int(s[l:]) print(s1 + s2) elif l == 0: s1 = int(s[0:r]) s2 = int(s[r:]) print(s1 + s2) else: s1 = int(s[0:l]) s2 = int(s[l:]) s3 = int(s[0:r]) s4 = int(s[r:]) print(min(s1 + s2, s3 + s4))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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 NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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.
n = int(input()) s = input() l = n // 2 ans = int(s) if s[l] != "0": ans = int("0" + s[:l]) + int("0" + s[l:]) for i in range(1, n): if l + i < n and s[l + i] != "0": ans = min(ans, int("0" + s[: l + i]) + int("0" + s[l + i :])) if l - i >= 0 and s[l - i] != "0": ans = min(ans, int("0" + s[: l - i]) + int("0" + s[l - i :])) if l + i >= n or l - 1 <= 0 or s[l + i] != "0" or s[l - i] != "0": break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR VAR FUNC_CALL VAR BIN_OP STRING VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING 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() k = 1 i = l // 2 j = l // 2 + 1 while i > 0 and n[i] == "0": i -= 1 while j < l and n[j] == "0": j += 1 ans = -1 if i >= 1: b = int(n[:i]) + int(n[i:]) if ans == -1 or ans > b: ans = b if j < l: b = int(n[:j]) + int(n[j:]) if ans == -1 or ans > b: ans = b print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 ASSIGN VAR NUMBER IF 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 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.
n = int(input()) val = input() mid = n // 2 while mid < n and val[mid] == "0": mid += 1 anmid = n // 2 while anmid > -1 and val[anmid] == "0": anmid -= 1 ans = 10**n if anmid != 0: ans = int(val[:anmid]) + int(val[anmid:]) if mid != n: ans = min(ans, int(val[:mid]) + int(val[mid:])) mid = n // 2 + 1 anmid = mid while mid < n and val[mid] == "0": mid += 1 while anmid > -1 and val[anmid] == "0": anmid -= 1 if anmid != 0: ans = min(ans, int(val[:anmid]) + int(val[anmid:])) if mid != n: ans = min(ans, int(val[:mid]) + int(val[mid:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN 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 ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER 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.
T = int(input()) s = input() mid = len(s) // 2 MIN = -1 if len(s) < 3: print(int(s[0]) + int(s[1])) return for i in range(mid, -1, -1): if s[i + 1] != "0": MIN = int(s[: i + 1]) + int(s[i + 1 :]) break for i in range(mid, len(s)): if s[i] != "0": tmp = int(s[:i]) + int(s[i:]) if MIN > tmp: MIN = tmp break if MIN == -1: MIN = int(s[: len(s) - 1]) + int(s[len(s) - 1 :]) print(MIN)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER 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 FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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 VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL 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.
l = int(input()) s = input() v = [] for i in range(1, len(s)): if s[i] != "0": v.append(i) ans = 1e1000 ch = int(s) for i in range(0, len(v)): if v[i] > l // 2: ans = min(ans, int(ch // int(pow(10, l - v[i]))) + ch % int(pow(10, l - v[i]))) if i > 0: ans = min( ans, int(ch // int(pow(10, l - v[i - 1]))) + ch % int(pow(10, l - v[i - 1])), ) break ans = min( ans, int(ch // int(pow(10, l - v[len(v) - 1]))) + ch % int(pow(10, l - v[len(v) - 1])), ) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL 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.
l = int(input()) s = input() res = None noimp = 0 for it in range(l - 1): i = 0 if it % 2 == 0: i = l // 2 - (it + 1) // 2 else: i = l // 2 + (it + 1) // 2 if s[i] == "0": continue cur = int(s[0:i]) + int(s[i:]) if res is None: res = cur elif cur < res: res = cur else: noimp += 1 if noimp >= 4: break print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER 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.
n = int(input()) a = input() ans = None i = n // 2 for q in range(n // 2): if a[: i + q][0] != "0" and a[i + q :][0] != "0": if ans is None: ans = int(a[: i + q]) + int(a[i + q :]) else: ans = min(ans, int(a[: i + q]) + int(a[i + q :])) if a[: i - q][0] != "0" and a[i - q :][0] != "0": if ans is None: ans = int(a[: i - q]) + int(a[i - q :]) else: ans = min(ans, int(a[: i - q]) + int(a[i - q :])) if not ans is None: break ans1 = ans if n & 1: i += 1 ans = None for q in range(n // 2): if a[: i + q][0] != "0" and a[i + q :][0] != "0": if ans is None: ans = int(a[: i + q]) + int(a[i + q :]) else: ans = min(ans, int(a[: i + q]) + int(a[i + q :])) if a[: i - q][0] != "0" and a[i - q :][0] != "0": if ans is None: ans = int(a[: i - q]) + int(a[i - q :]) else: ans = min(ans, int(a[: i - q]) + int(a[i - q :])) if not ans is None: break if ans is None: print(ans1) elif ans1 is None: print(ans) else: print(min(ans, ans1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER STRING VAR BIN_OP VAR VAR NUMBER STRING IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER STRING VAR BIN_OP VAR VAR NUMBER STRING IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NONE ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER STRING VAR BIN_OP VAR VAR NUMBER STRING IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER STRING VAR BIN_OP VAR VAR NUMBER STRING IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NONE IF VAR NONE EXPR FUNC_CALL VAR VAR IF VAR NONE 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.
def fun(s, l): if l == 1: return int(s) else: i = l // 2 j = i a = s[:i] b = s[j:] front = int(s) while 1: if b[0] == "0": j += 1 i += 1 a = s[:i] b = s[j:] if a == "" or b == "": break else: front = int(a) + int(b) break i = l // 2 j = i a = s[: i + 1] b = s[j + 1 :] if b == "": b = "0" back = int(s) while 1: if b[0] == "0": j -= 1 i -= 1 a = s[:i] b = s[j:] if a == "" or b == "": break else: back = int(a) + int(b) break return min(front, back) return mini l = int(input()) s = input() print(fun(s, l))
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER IF VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER IF VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 = input() s = input() s = str(s) mid = int(len(s) / 2) num = -1 i = mid - 1 while i >= 0: if s[i + 1] == "0": i = i - 1 continue s1 = s[: i + 1] s2 = s[i + 1 :] if num == -1: num = int(s1) + int(s2) else: num = min(int(s1) + int(s2), num) break i = i - 1 for i in range(mid, len(s) - 1): if s[i + 1] == "0": continue s1 = s[: i + 1] s2 = s[i + 1 :] if num == -1: num = int(s1) + int(s2) else: num = min(int(s1) + int(s2), num) break print(num)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER 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 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() ans = 10**100001 if n % 2 == 0: flag = 0 for i in range(n // 2): if s[n // 2 - i] != "0": ans = min(ans, int(s[0 : n // 2 - i]) + int(s[n // 2 - i :])) flag += 1 if flag > 2: break flag = 0 for i in range(n // 2): if s[n // 2 + i] != "0": ans = min(ans, int(s[0 : n // 2 + i]) + int(s[n // 2 + i :])) flag += 1 if flag > 2: break else: flag = 0 for i in range(n // 2): if s[n // 2 - i] != "0": ans = min(ans, int(s[0 : n // 2 - i]) + int(s[n // 2 - i :])) flag += 1 if flag > 2: break flag = 0 for i in range(n // 2 + 1): if s[n // 2 + i] != "0": ans = min(ans, int(s[0 : n // 2 + i]) + int(s[n // 2 + i :])) flag += 1 if flag > 2: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER 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.
n = int(input()) s = input() ans = int(s) cut = n // 2 if s[cut] != "0": ans = min(int(s[:cut]) + int(s[cut:]), int(s[: cut + 1]) + int(s[cut + 1 :])) else: cut1 = cut cut2 = cut while cut1 >= 0 and s[cut1] == "0": cut1 -= 1 while cut2 < n and s[cut2] == "0": cut2 += 1 if cut1 > 0: ans = min(ans, int(s[:cut1]) + int(s[cut1:])) if cut2 < n: ans = min(ans, int(s[:cut2]) + int(s[cut2:])) 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 VAR NUMBER IF VAR VAR STRING ASSIGN 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 NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER 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.
def ssum(s, spl): l = s[:spl] r = s[spl:] p = 0 ret = "" carry = 0 while p < len(l) or p < len(r): dl = int(l[-p - 1]) if p < len(l) else 0 dr = int(r[-p - 1]) if p < len(r) else 0 tmp = carry + int(dl) + int(dr) if tmp > 9: tmp -= 10 carry = 1 else: carry = 0 ret = str(tmp) + ret p += 1 if carry == 1: ret = str(carry) + ret return ret def smin(s1, s2): if len(s1) < len(s2): return s1 if len(s2) < len(s1): return s2 for i in range(len(s1)): if s1[i] < s2[i]: return s1 if s2[i] < s1[i]: return s2 return s1 def sol(s): if len(s) % 2 == 0: l, r = len(s) // 2, len(s) // 2 else: l, r = len(s) // 2, len(s) // 2 + 1 while True: if s[l] == "0" and s[r] == "0": l -= 1 r += 1 continue if s[l] == "0": return ssum(s, r) if s[r] == "0": return ssum(s, l) return smin(ssum(s, l), ssum(s, r)) _ = input() s = input() print(sol(s))
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING RETURN FUNC_CALL VAR VAR VAR IF VAR VAR STRING RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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.
n = int(input()) s = input() if n % 2: if s[n // 2] != "0": print( min( int(s[: n // 2]) + int(s[n // 2 :]), int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]), ) ) else: s1 = s[: n // 2] s2 = s[n // 2 :] mn = int(s) mn1 = int(s) for i in range(len(s2)): if s2[i] != "0": mn = int(s1) + int(s2[i:]) break s1 += s2[i] s1 = s[: n // 2] s2 = s[n // 2 :][::-1] for i in range(len(s1) - 1, -1, -1): if s1[i] != "0": if i == 0: mn1 = mn else: s2 += s1[i] s2 = s2[::-1] s1 = s1[:i] mn1 = int(s1) + int(s2) break else: s2 += s1[i] print(min(mn, mn1)) elif s[n // 2] != "0": s1 = s[: n // 2] s2 = s[n // 2 :] print(int(s1) + int(s2)) else: mn = int(s) mn1 = int(s) for i in range(n // 2, n): if s[i] != "0": s1 = s[:i] s2 = s[i:] mn = int(s1) + int(s2) break for i in range(n // 2, -1, -1): if s[i] != "0": if i != 0: s1 = s[:i] s2 = s[i:] mn1 = int(s1) + int(s2) else: mn1 = mn break print(min(mn, mn1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING 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 VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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.
a = int(input()) b = input() mid = a // 2 f = mid s = mid while f > 0 and b[f] == "0": f = f - 1 while s < a - 1 and b[s] == "0": s = s + 1 ans = 1e1000 for number in [-1, 0, 1]: keysA = f + number keysB = s + number fa = 0 fb = 0 sa = 0 sb = 0 if len(b[:keysA]) > 0: fa = int(b[:keysA]) if len(b[keysA:]) > 0: fb = int(b[keysA:]) if len(b[:keysB]) > 0: sa = int(b[:keysB]) if len(b[keysB:]) > 0: sb = int(b[keysB:]) if keysA >= 0 and keysA <= a - 1 and b[keysA] != "0": ans = min(ans, fa + fb) if keysB >= 0 and keysB <= a - 1 and b[keysB] != "0": ans = min(ans, sa + sb) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING 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.
size = int(input()) number = list(input()) if size < 5: min_num = 99999999 for start2 in range(1, size): if number[start2] == "0": continue num = int("".join(number[:start2])) + int("".join(number[start2:])) if num < min_num: min_num = num print(min_num) exit(0) start1 = size // 2 while start1 >= 0: if number[start1] == "0": start1 -= 1 else: break start2 = size // 2 + 1 while start2 < size: if number[start2] == "0": start2 += 1 else: break if start1 == 0: print(int("".join(number[:start2])) + int("".join(number[start2:]))) exit(0) if start2 == size: print(int("".join(number[:start1])) + int("".join(number[start1:]))) exit(0) sub_num1 = int("".join(number[:start1])) + int("".join(number[start1:])) sub_num2 = int("".join(number[:start2])) + int("".join(number[start2:])) print(min(sub_num1, sub_num2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL 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 = -1 for i in range(int(l / 2), l): if n[i] == "0": continue tmp = int(n[0:i]) + int(n[i:]) if tmp < ans or ans == -1: ans = tmp if i > int(l / 2): break for i in range(int(l / 2), 0, -1): if n[i] == "0": continue tmp = int(n[0:i]) + int(n[i:]) if tmp < ans or ans == -1: ans = tmp break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR 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 fun(): i = m - 1 while i >= 0 and s[i + 1] == "0": i -= 1 j = m + 1 while j < l and s[j] == "0": j += 1 if i < 0: a = int(s) + 1 else: a = int(s[: i + 1]) + int(s[i + 1 :]) if j == l: b = int(s) + 1 else: b = int(s[:j]) + int(s[j:]) return min(a, b) l = int(input()) s = input() m = int(l / 2) print(fun())
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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.
n = input() r = input() n = int(n) ans = int(r) for i in range(n // 2, 0, -1): j = r[0:i] k = r[i:n] if len(j) == 0 or len(k) == 0 or j[0] == "0" or k[0] == "0": continue int_j = int(j) int_k = int(k) ans = min(ans, int_j + int_k) break for i in range(n // 2 + 1, n, 1): j = r[0:i] k = r[i:n] if len(j) == 0 or len(k) == 0 or j[0] == "0" or k[0] == "0": continue int_j = int(j) int_k = int(k) ans = min(ans, int_j + int_k) break print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 get(i): s1 = s[0:i] s2 = s[i:n] j = 0 while j < len(s2) and s2[j] == "0": j += 1 k = i - 1 while k >= 0 and s1[k] == "0": k -= 1 if j == len(s2): a = int(s) else: a = int(s1 + "0" * j) + int(s2[j : len(s2)]) if k == 0: b = int(s1[k : len(s1)] + s2) else: b = int(s[0:k]) + int(s[k : len(s)]) return min(a, b) n = int(input()) s = input() s1 = "" s2 = "" if n % 2 == 0: print(get(n // 2)) else: print(min(get(n // 2), get(n // 2 + 1)))
FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL 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 = str(input()) inf = 10**10**5 minsum = inf flag = False for i in range(n // 2, n): if s[i] != "0": flag = True minsum = min(minsum, int(s[:i]) + int(s[i:])) if s[n - i] != "0": flag = True minsum = min(minsum, int(s[: n - i]) + int(s[n - i :])) if flag: break print(minsum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR 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.
l, s = int(input()), input() ans = int(s) def check(a, b): b = b[::-1] b, a = list(b), list(a) while len(b) and b[-1] == "0": b.pop() a.append("0") if not len(b): return b = b[::-1] b = "".join(b) a = "".join(a) global ans ans = min(ans, int(a) + int(b)) def check2(a, b): b = b[::-1] a = list(a) b = list(b) while len(a) and a[-1] == "0": a.pop() b.append("0") if len(a) <= 1: return b.append(a.pop()) a = "".join(a) b = "".join(b) b = b[::-1] global ans ans = min(ans, int(a) + int(b)) check(s[: l // 2], s[l // 2 :]) check2(s[: l // 2], s[l // 2 :]) if l >= 3: check(s[: l // 2 + 1], s[l // 2 + 1 :]) check2(s[: l // 2 + 1], s[l // 2 + 1 :]) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER 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() ans = int(s) min_len = l pos = [] for i in range(l - 1): if s[i + 1] == "0": continue ll = max(i + 1, l - 1 - i) + 1 if ll < min_len: pos = [i] min_len = ll elif ll == min_len: pos.append(i) else: continue for p in pos: ss = int(s[: p + 1]) + int(s[p + 1 :]) if ss < ans: ans = ss print(int(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN 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 shTofhShiftIfZero(s, fh, sh): curr = "" for i in sh: if i == "0": curr += "0" else: break fh += curr sh = sh[len(curr) :] if fh == "": fh = 0 if sh == "": sh = 0 sum1 = int(fh) + int(sh) return sum1 def fhToshShiftIfZero(s, fh, sh): curr = "" fh1 = fh[::-1] for i in fh1: if i == "0": curr += "0" else: break newSh = fh[len(fh) - len(curr) - 1] + curr + sh sh = newSh fh = fh[0 : len(fh) - len(curr) - 1] if fh == "": fh = 0 if sh == "": sh = 0 sum1 = int(fh) + int(sh) return sum1 n = int(input()) s = input() fh = s[0 : n // 2] sh = s[n // 2 :] miniSum = 0 sum1 = 0 sum2 = 0 sum3 = 0 if sh[0] == "0": sum1 += shTofhShiftIfZero(s, fh, sh) sum2 += fhToshShiftIfZero(s, fh, sh) miniSum = min(sum1, sum2) elif fh[len(fh) - 1] == "0": sum3 += fhToshShiftIfZero(s, fh, sh) miniSum = sum3 else: sh1 = sh sh1 = sh1[1:] fh1 = fh + sh[0] if fh1 == "": fh1 = 0 if sh1 == "": sh1 = 0 fSum = int(fh1) + int(sh1) miniSum = min(int(fh) + int(sh), fSum) print(miniSum)
FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN 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 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() mi = int(s) mid = l // 2 while mid < l: if s[mid] == "0": mid += 1 else: break if mid < l: mi = min(mi, int(s[:mid]) + int(s[mid:])) mid = l // 2 + 1 while mid < l: if s[mid] == "0": mid += 1 else: break if mid < l: mi = min(mi, int(s[:mid]) + int(s[mid:])) mid = l // 2 - 1 while mid >= 0: if s[mid] == "0": mid -= 1 else: break if mid > 0: mi = min(mi, int(s[:mid]) + int(s[mid:])) print(mi)
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 WHILE VAR VAR IF 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 ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF 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 ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER IF 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.
n = int(input()) S = str(input()).strip() ans = int(S) l = n // 2 r = n // 2 while l >= 0 and S[l] == "0": l -= 1 while r < len(S) and S[r] == "0": r += 1 for i in [l, r]: for j in range(max(i - 2, 1), min(len(S), i + 2)): if S[j] != "0": ans = min(ans, int(S[:j]) + int(S[j:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER FOR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR 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.
n = int(input()) s = input() ans = 1e1000 mid = n // 2 i = mid while i > 0: if s[i] != "0": a = int(s[:i]) b = int(s[i:]) ans = a + b break i -= 1 i = mid + 1 while i < len(s): if s[i] != "0": a = int(s[:i]) b = int(s[i:]) ans = min(ans, a + b) break i += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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.
l = int(input()) s = input() n = int(s) mitad = l // 2 base = mitad + 1 while base < l and s[base] == "0": base += 1 base = 10 ** (l - base) a = n // base b = n % base sol = a + b base = mitad while base > 0 and s[base] == "0": base -= 1 base = 10 ** (l - base) a = n // base b = n % base sol = min(sol, a + b) print(sol)
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 ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP 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 calc(s, a): return int(s[:a]) + int(s[a:]) n = int(input()) s = input() if n % 2 == 0: if s[n // 2] != "0": print(calc(s, n // 2)) else: a = n // 2 - 1 b = n // 2 while s[a] == "0" and s[b] == "0": a -= 1 b += 1 res = -1 if s[a] != "0" and a > 0: res = calc(s, a) if s[b] != "0": if res < 0: res = calc(s, b) else: res = min(res, calc(s, b)) print(res) elif s[n // 2] != "0": res = calc(s, n // 2) if s[n // 2 + 1] != "0": res = min(res, calc(s, n // 2 + 1)) print(res) else: a = n // 2 - 1 b = n // 2 + 1 while s[a] == "0" and s[b] == "0": a -= 1 b += 1 res = -1 if s[a] != "0" and a > 0: res = calc(s, a) if s[b] != "0": if res < 0: res = calc(s, b) else: res = min(res, calc(s, b)) print(res)
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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 FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL 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() first = [None] * (n - 1) for i in range(n - 1): if s[i + 1] == "0": first[i] = -1 continue if n % 2 == 1: if i < n // 2: first[i] = int(s[i + 1]) else: first[i] = int(s[i]) elif i == n // 2: first[i] = max(int(s[i]), int(s[i + 1])) elif i < n // 2: first[i] = int(s[i + 1]) else: first[i] = int(s[i]) midl = midr = 0 if n % 2 == 1: midl = (n - 1) // 2 - 1 midr = midl + 1 else: midl = midr = n // 2 - 1 point1 = point2 = flag = 0 while True: if first[midl] == -1 and first[midr] == -1: if midl != 0: midl -= 1 if midr < n - 1: midr += 1 continue if first[midl] == -1: point1 = midr break elif first[midr] == -1: point1 = midl break flag = 1 point1 = midl point2 = midr break ans = 0 if flag == 0: ans = int(s[: point1 + 1]) + int(s[point1 + 1 :]) else: ans1 = int(s[: point1 + 1]) + int(s[point1 + 1 :]) ans2 = int(s[: point2 + 1]) + int(s[point2 + 1 :]) ans = min(ans1, ans2) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER WHILE NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER 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 VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 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() p = 1 if l & 1 else 0 while n[l + p >> 1] == "0" and n[l - p >> 1] == "0": p += 2 if n[l + p >> 1] == "0": print(int(n[l - p >> 1 :]) + int(n[: l - p >> 1])) elif n[l - p >> 1] == "0": print(int(n[l + p >> 1 :]) + int(n[: l + p >> 1])) else: print( min( int(n[l + p >> 1 :]) + int(n[: l + p >> 1]), int(n[l - p >> 1 :]) + int(n[: l - p >> 1]), ) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL 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 BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL 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 EXPR FUNC_CALL VAR FUNC_CALL 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 BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP 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.
x = int(input()) li_t = list(input()) len1 = len(li_t) len1 = len1 // 2 li_t1 = li_t[:len1] li_t2 = li_t[len1:] i = 0 if li_t1[-1] == "0" and li_t2[0] == "0": while i <= len(li_t2) - 1 and li_t2[i] == "0": i += 1 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans1 = li_t1 + li_t2 li_t1 = li_t[:len1] li_t2 = li_t[len1:] i = -1 while i >= -1 * len(li_t1) and li_t1[i] == "0": i -= 1 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans2 = li_t1 + li_t2 elif li_t2[0] == "0": i = 0 while i <= len(li_t2) - 1 and li_t2[i] == "0": i = i + 1 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans1 = li_t1 + li_t2 li_t1 = li_t[:len1] li_t2 = li_t[len1:] try: i = -1 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans2 = li_t1 + li_t2 except: ans2 = 0 elif li_t1[-1] == "0": i = -1 while i >= -1 * len(li_t1) and li_t1[i] == "0": i = i - 1 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans1 = li_t1 + li_t2 li_t1 = li_t[:len1] li_t2 = li_t[len1:] i = 1 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans2 = li_t1 + li_t2 else: i = 0 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans1 = li_t1 + li_t2 i = 1 li_t1 = li_t[: len1 + i] li_t2 = li_t[len1 + i :] if li_t1 != []: li_t1 = int("".join(li_t1)) else: li_t1 = 0 if li_t2 != []: li_t2 = int("".join(li_t2)) else: li_t2 = 0 ans2 = li_t1 + li_t2 if ans1 > ans2: print(ans2) else: print(ans1)
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 VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN 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() t = int(l / 2) if l == 2: print(int(n[0]) + int(n[1])) elif l == 3: if n[1] == "0": print(int(n[0:2]) + int(n[2])) else: print(min(int(n[0:2]) + int(n[2]), int(n[0]) + int(n[1:3]))) elif l % 2 == 0: if n[t] != "0": print(int(n[0:t]) + int(n[t:l])) else: for i in range(1, t): if n[t + i] != "0" or n[t - i] != "0": if n[t + i] != "0" and n[t - i] != "0": print( min( int(n[0 : t - i]) + int(n[t - i : l]), int(n[0 : t + i]) + int(n[t + i : l]), ) ) elif n[t + i] != "0" and n[t - i] == "0": print(int(n[0 : t + i]) + int(n[t + i : l])) elif n[t + i] == "0" and n[t - i] != "0": print(int(n[0 : t - i]) + int(n[t - i : l])) break else: for i in range(0, t): if n[t + 1 + i] != "0" or n[t - i] != "0": if n[t + 1 + i] != "0" and n[t - i] != "0": print( min( int(n[0 : t - i]) + int(n[t - i : l]), int(n[0 : t + 1 + i]) + int(n[t + 1 + i : l]), ) ) elif n[t + 1 + i] != "0" and n[t - i] == "0": print(int(n[0 : t + 1 + i]) + int(n[t + 1 + i : l])) elif n[t + 1 + i] == "0" and n[t - i] != "0": print(int(n[0 : t - i]) + int(n[t - i : l])) break
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR VAR STRING IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP 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().strip() k1 = n // 2 + 1 k2 = n // 2 while k1 < n - 1 and s[k1] == "0": k1 += 1 while k2 > 0 and s[k2] == "0": k2 -= 1 if k1 == n or s[k1:n] == "0": print(int(s[0:k2]) + int(s[k2:n])) elif k2 == 0 or s[0:k2] == "0": print(int(s[0:k1]) + int(s[k1:n])) else: print(min(int(s[0:k1]) + int(s[k1:n]), int(s[0:k2]) + int(s[k2:n])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL 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
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 suu(a, b): a = int(a) b = int(b) return a + b def go(): l = int(input()) s = str(input()) mid = l // 2 pos = l - 1 while 1: if s[pos] == "0": pos -= 1 else: break if pos < mid: print(suu(s[:pos], s[pos:])) return if s[mid] == "0": pos = mid while s[pos] == "0": pos += 1 pos2 = mid while s[pos2] == "0": pos2 -= 1 if pos2 == 0: print(suu(s[:pos], s[pos:])) elif pos >= l: print(suu(s[:pos2], s[pos2:])) else: print(min(suu(s[:pos], s[pos:]), suu(s[:pos2], s[pos2:]))) return if ( mid < l - 1 and s[mid + 1] != "0" and suu(s[:mid], s[mid:]) > suu(s[: mid + 1], s[mid + 1 :]) ): mid += 1 print(suu(s[:mid], s[mid:])) go()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN IF VAR VAR STRING ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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.
def solve(p2, n, s): p3 = p2 while p2 < n and s[p2] == "0": p2 += 1 while p3 >= 0 and s[p3] == "0": p3 -= 1 res = float("inf") if p2 != 0 and p2 != n: res = int(s[0:p2]) + int(s[p2:]) if p3 != 0 and p3 != n: res = min(res, int(s[0:p3]) + int(s[p3:])) return res n = int(input()) s = input() res = solve(n // 2, n, s) if n % 2 == 1: res = min(res, solve(n // 2 + 1, n, s)) print(res)
FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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() min_val = n for i in range(1, n): if s[i] == "0": continue min_val = min(min_val, max(i, n - i)) ans = int(s) for i in range(1, n): if s[i] == "0": continue if max(i, n - i) < min_val - 1 or max(i, n - i) > min_val: continue candi = int(s[:i]) + int(s[i:]) ans = min(ans, candi) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER 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
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()) num = input() mid = int(n / 2) if n % 2 == 1: mid = mid + 1 ans = 0 if num[mid] != "0": ans1 = int(num[0:mid]) + int(num[mid:]) if n % 2 == 1 and num[mid - 1] != "0": ans2 = int(num[0 : mid - 1]) + int(num[mid - 1 :]) ans = min(ans1, ans2) else: ans = ans1 else: t_mid = mid ans1 = -1 ans2 = -1 while t_mid >= 0 and num[t_mid] == "0": t_mid = t_mid - 1 if t_mid >= 0: ans1 = int(num[0:t_mid]) + int(num[t_mid:]) t_mid = mid while t_mid < n and num[t_mid] == "0": t_mid = t_mid + 1 if t_mid < n: ans2 = int(num[0:t_mid]) + int(num[t_mid:]) if ans1 == -1: ans = ans2 elif ans2 == -1: ans = ans1 else: ans = min(ans1, ans2) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
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 f = sys.stdin out = sys.stdout l = int(f.readline().rstrip("\r\n")) n = f.readline().rstrip("\r\n") ans = int(n) p = l >> 1 while p < l and n[p] == "0": p += 1 if p < l: ans = min(ans, int(n[:p]) + int(n[p:])) p += 1 while p < l and n[p] == "0": p += 1 if p < l: ans = min(ans, int(n[:p]) + int(n[p:])) p = l >> 1 while p >= 0 and n[p] == "0": p -= 1 if p > 0: ans = min(ans, int(n[:p]) + int(n[p:])) p -= 1 while p >= 0 and n[p] == "0": p -= 1 if p > 0: ans = min(ans, int(n[:p]) + int(n[p:])) out.write(str(ans))
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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 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 ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 = str(input()) best_len = l best = int(n) to_try = [] for i in range(l - 1): if n[i + 1] != "0": candidate = max(i + 1, l - i - 1) + 1 if candidate < best_len: to_try.clear() to_try.append(i + 1) best_len = candidate elif candidate == best_len: to_try.append(i + 1) for i in to_try: best = min(best, int(n[:i]) + int(n[i:])) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR 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.
def asdf(): l = int(input()) s = input() n = int(s) mid = l // 2 mini = n k = 0 for i in range(0, l // 2 + 1): ind = mid + i if 0 < ind < l and s[ind] != "0": mini = min(mini, int(s[:ind]) + int(s[ind:])) k += 1 ind = mid - i if 0 < ind < l and s[ind] != "0": mini = min(mini, int(s[:ind]) + int(s[ind:])) k += 1 if k >= 5: break print(mini) asdf()
FUNC_DEF 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 ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER 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 check(s1, s2): if len(s1) == 0 or len(s2) == 0 or s2[0] == "0": return -1 else: return int(s1) + int(s2) dummy = input() str = input() left = 0 right = 0 if len(str) % 2 == 0: left = len(str) // 2 - 1 right = len(str) // 2 else: left = len(str) // 2 right = len(str) // 2 answer = -1 while answer == -1: it1 = check(str[0:left], str[left : len(str)]) if it1 != -1: if answer == -1 or answer > it1: answer = it1 it2 = check(str[0:right], str[right : len(str)]) if it2 != -1: if answer == -1 or answer > it2: answer = it2 left -= 1 right += 1 if left > 0: it1 = check(str[0:left], str[left : len(str)]) if it1 != -1: if answer == -1 or answer > it1: answer = it1 if right < len(str): it2 = check(str[0:right], str[right : len(str)]) if it2 != -1: if answer == -1 or answer > it2: answer = it2 print(answer)
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER 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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER 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 = str(input()) ans = 10 ** (10**5 + 1) i = n // 2 + 1 while i < n and s[i] == "0": i += 1 if i < n: ans = min(ans, int(s[:i]) + int(s[i:])) i = n // 2 while s[i] == "0": i -= 1 if i > 0: ans = min(ans, int(s[:i]) + int(s[i:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER 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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF 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.
n = int(input()) s = input() num = int(s) p = n // 2 + 1 while p < n and s[p] == "0": p += 1 p -= 1 p = 10 ** (n - p - 1) l, r = divmod(num, p) m = l + r p = n // 2 while p > -1 and s[p] == "0": p -= 1 p -= 1 p = 10 ** (n - p - 1) l, r = divmod(num, p) m = min(m, l + r) print(m)
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 VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN 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()) inp = input() inp1 = list(inp) mid = l // 2 toLeft = 0 toRight = l if l % 2 != 0: if inp[mid] != "0": opt1 = int(inp[: mid + 1]) opt2 = int(inp[mid:]) if opt1 < opt2: ans = opt1 + int(inp[mid + 1 :]) else: ans = opt2 + int(inp[:mid]) else: i = mid - 1 while i >= 0: if inp[i] != "0": toLeft = i break i -= 1 i = mid + 1 while i < l: if inp[i] != "0": toRight = i break i += 1 if toLeft == 0 and toRight == l: ans = int(inp) elif toRight == l: ans = int(inp[:toLeft]) + int(inp[toLeft:]) elif toLeft == 0: ans = int(inp[:toRight]) + int(inp[toRight:]) else: opt1 = int(inp[:toLeft]) + int(inp[toLeft:]) opt2 = int(inp[:toRight]) + int(inp[toRight:]) if opt1 < opt2: ans = opt1 else: ans = opt2 elif inp[mid] != "0": ans = int(inp[:mid]) + int(inp[mid:]) else: i = mid - 1 while i >= 0: if inp[i] != "0": toLeft = i break i -= 1 i = mid + 1 while i < l: if inp[i] != "0": toRight = i break i += 1 if toLeft == 0 and toRight == l: ans = int(inp) elif toRight == l: ans = int(inp[:toLeft]) + int(inp[toLeft:]) elif toLeft == 0: ans = int(inp[:toRight]) + int(inp[toRight:]) else: opt1 = int(inp[:toLeft]) + int(inp[toLeft:]) opt2 = int(inp[:toRight]) + int(inp[toRight:]) if opt1 < opt2: ans = opt1 else: ans = opt2 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN 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.
def ans(string, sep, l): first = int(string[0:sep]) second = int(string[sep:l]) return first + second l = int(input()) string = input() mid = l // 2 a = 0 b = 0 for i in range(mid, 0, -1): if string[i] != "0": a = ans(string, i, l) break for i in range(mid + 1, l): if string[i] != "0": b = ans(string, i, l) break if a * b == 0: print(a + b) else: print(min(a, b))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL 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.
def main(): l = int(input()) n = input() data = [] for i in range(1, l): if n[i] == "0": continue data.append((abs(l // 2 - i), i)) data.sort() res = -1 for i in range(0, min(10, len(data))): start = data[i][1] x = int(n[0:start]) y = int(n[start:]) z = x + y if res == -1: res = z else: res = min(res, z) print(res) main()
FUNC_DEF 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 FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN 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() n = int(s) mid = l // 2 ans = 10**l for i in range(mid + 1, l): if s[i].isdigit() and s[i] != "0": exp = 10 ** (l - i) fir = n // exp sec = n % exp ans = min(ans, fir + sec) break for i in range(mid, 0, -1): if s[i].isdigit() and s[i] != "0": exp = 10 ** (l - i) fir = n // exp sec = n % exp ans = min(ans, fir + sec) break 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 VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP 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()) s = input() split = [1] * l for i in range(l): if s[i] == "0": split[i] = 0 if l % 2: c1 = l // 2 c2 = 1 + l // 2 else: c1 = l // 2 c2 = l // 2 i = 0 while 1: if c1 - i >= 0 and split[c1 - i]: m1 = int(s[: c1 - i]) + int(s[c1 - i :]) else: m1 = -1 if c2 + i < l and split[c2 + i]: m2 = int(s[: c2 + i]) + int(s[c2 + i :]) else: m2 = -1 if m1 == -1 and m2 == -1: pass elif m1 == -1: ans = m2 break elif m2 == -1: ans = m1 break else: ans = min(m1, m2) break i += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP 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 IF BIN_OP VAR VAR VAR VAR BIN_OP 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 IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR 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.
l = int(input()) a = input() i = l // 2 ans = -1 while i > 0 and a[i] == "0": i -= 1 r = l // 2 + 1 while r < l and a[r] == "0": r += 1 for j in [i, i - 1, r, r + 1]: if j > 0 and j < l: if a[j] != "0": if ans == -1: ans = int(a[:j]) + int(a[j:]) else: ans = min(ans, int(a[:j]) + int(a[j:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN 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 FOR VAR LIST VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN 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.
l = int(input()) s = input() ans = 10**100005 l1, l2 = l // 2, (l + 1) // 2 check = False while True: if s[l1] != "0": check = True m1 = int(s[:l1]) m2 = int(s[l1:]) b = m1 + m2 ans = min(ans, b) if s[l2] != "0": check = True m1 = int(s[:l2]) m2 = int(s[l2:]) b = m1 + m2 ans = min(ans, b) if check == True: print(ans) break l1 = l1 - 1 l2 = l2 + 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR 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.
n = int(input()) a = input() left = [] right = [] t = "" c = 0 idex = n // 2 if n % 2 == 0: if a[idex] == "0": while idex < n and a[idex] == "0": idex += 1 if idex == n: left = int(a) else: left = int(a[:idex]) + int(a[idex:]) idex = n // 2 while idex < n and a[idex] == "0": idex -= 1 right = int(a[:idex]) + int(a[idex:]) print(min(left, right)) else: print(int(a[:idex]) + int(a[idex:])) elif a[idex] != "0" and a[idex + 1] != "0": print(min(int(a[:idex]) + int(a[idex:]), int(a[: idex + 1]) + int(a[idex + 1 :]))) else: while idex < n and a[idex] == "0": idex += 1 if idex == n: left = int(a) else: left = int(a[:idex]) + int(a[idex:]) idex = n // 2 while a[idex] == "0": idex -= 1 if idex == 0: right = int(a) else: right = int(a[:idex]) + int(a[idex:]) s1 = min(left, right) idex = n // 2 + 1 while idex < n and a[idex] == "0": idex += 1 if idex == n: left = int(a) else: left = int(a[:idex]) + int(a[idex:]) idex = n // 2 while idex < n and a[idex] == "0": idex -= 1 if idex == 0: right = int(a) else: right = int(a[:idex]) + int(a[idex:]) s2 = min(left, right) print(min(s1, s2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING WHILE VAR VAR VAR VAR STRING VAR NUMBER 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 BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER 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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER 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 NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER 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 BIN_OP VAR NUMBER WHILE 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 FUNC_CALL VAR VAR VAR 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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR 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 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.
l = int(input().strip()) n = str(input().strip()) n1 = n[: l // 2] n2 = n[l // 2 :] if n1[-1] != "0" and n2[0] != "0": if l % 2 == 0: print(int(n1) + int(n2)) else: print( min( int(n[: l // 2]) + int(n[l // 2 :]), int(n[: l // 2 + 1]) + int(n[l // 2 + 1 :]), ) ) exit() a1, a2 = l // 2 - 1, l // 2 while n[a1] == "0" and a1 > 0: a1 -= 1 while n[a2] == "0" and a2 < l - 1: a2 += 1 if a1 == 0 and a2 == l - 1: if n[a2] == "0": print(n) else: print(n[: l - 2] + n[-1]) elif a1 != 0 and a2 != l - 1: print(min(int(n[:a1]) + int(n[a1:]), int(n[:a2]) + int(n[a2:]))) elif a1 == 0: print(int(n[:a2]) + int(n[a2:])) else: print(int(n[:a1]) + int(n[a1:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR 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 BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP 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 IF VAR NUMBER 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.
n = int(input()) s = input() d = set(s) if "0" in d: mi = 0 m = len(s) for i in range(n // 2 - 1, 0, -1): if s[i] != "0": mi = i break for i in range(n // 2, len(s)): if s[i] != "0": m = i break if mi == 0: mi = int(s) else: mi = int(s[mi:]) + int(s[:mi]) if m == len(s): m = int(s) else: m = int(s[m:]) + int(s[:m]) print(min(mi, m)) elif n % 2 != 0: a = int(s[: n // 2]) + int(s[n // 2 :]) b = int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]) print(min(a, b)) else: print(int(s[: n // 2]) + int(s[n // 2 :]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER 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 EXPR FUNC_CALL 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.
n = input() no = input() n = int(n) if no[n // 2] != "0": ans = int(no[0 : n // 2]) + int(no[n // 2 : n + 1]) if n // 2 + 1 < n and no[n // 2 + 1] != "0": b = int(no[0 : n // 2 + 1]) + int(no[n // 2 + 1 : n]) ans = min(ans, b) if n // 2 + 2 < n and no[n // 2 + 2] != "0": b = int(no[0 : n // 2 + 2]) + int(no[n // 2 + 2 : n]) ans = min(ans, b) if n // 2 - 1 > 0 and no[n // 2 - 1] != "0": c = int(no[0 : n // 2 - 1]) + int(no[n // 2 - 1 : n]) ans = min(ans, c) if n // 2 - 2 > 0 and no[n // 2 - 2] != "0": c = int(no[0 : n // 2 - 2]) + int(no[n // 2 - 2 : n]) ans = min(ans, c) print(ans) else: x = n // 2 y = n // 2 while no[x] == "0": x -= 1 while y < n and no[y] == "0": y += 1 ans = -1 if y < n and no[y] != "0": ans = int(no[0:y]) + int(no[y:n]) if x > 0: b = int(no[0:x]) + int(no[x:n]) if ans != -1: ans = min(ans, b) else: ans = b if x - 1 > 0 and no[x - 1] != "0": c = int(no[0 : x - 1]) + int(no[x - 1 : n]) ans = min(ans, c) if x - 2 > 0 and no[x - 2] != "0": c = int(no[0 : x - 2]) + int(no[x - 2 : n]) ans = min(ans, c) if y + 1 < n and no[y + 1] != "0": d = int(no[0 : y + 1]) + int(no[y + 1 : n]) ans = min(ans, d) if y + 2 < n and no[y + 2] != "0": d = int(no[0 : y + 2]) + int(no[y + 2 : n]) ans = min(ans, d) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR STRING 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 IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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()) num = input() ind = int(n / 2) mini = int(num) while num[ind] == "0": ind += 1 if ind == n: break for i in range(max(1, ind - 1), min(ind + 2, n)): if num[i] != "0": mini = min(mini, int(num[0:i]) + int(num[i:n])) ind = int(n / 2) while num[ind] == "0": ind -= 1 for i in range(max(1, ind - 1), min(ind + 2, n)): if num[i] != "0": mini = min(mini, int(num[0:i]) + int(num[i:n])) print(mini)
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 VAR WHILE VAR VAR STRING VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL 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 res(digits): if "0" not in digits: if len(digits) % 2 == 0: return int(digits[: len(digits) // 2]) + int(digits[len(digits) // 2 :]) else: mid = len(digits) // 2 return min( int(digits[:mid]) + int(digits[mid:]), int(digits[: mid + 1]) + int(digits[mid + 1 :]), ) else: mid = len(digits) // 2 i = mid while i > 0 and digits[i] == "0": i -= 1 closestNonZeroL = i i = mid while i < len(digits) and digits[i] == "0": i += 1 closestNonZeroR = i sum1 = ( int(digits[:closestNonZeroL]) + int(digits[closestNonZeroL:]) if closestNonZeroL > 0 else int(digits) ) sum2 = ( int(digits[:closestNonZeroR]) + int(digits[closestNonZeroR:]) if closestNonZeroR > 0 and closestNonZeroR < len(digits) else int(digits) ) i = mid - 1 while i > 0 and digits[i] == "0": i -= 1 closestNonZeroL = i i = mid - 1 while i < len(digits) and digits[i] == "0": i += 1 closestNonZeroR = i sum3 = ( int(digits[:closestNonZeroL]) + int(digits[closestNonZeroL:]) if closestNonZeroL > 0 else int(digits) ) sum4 = ( int(digits[:closestNonZeroR]) + int(digits[closestNonZeroR:]) if closestNonZeroR > 0 and closestNonZeroR < len(digits) else int(digits) ) return min(min(sum1, sum2), min(sum3, sum4)) l = int(input()) digs = input() print(str(res(digs)))
FUNC_DEF IF STRING VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR 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 NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR 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()) a = input() ans = -1 mid = l // 2 for i in range(mid, 0, -1): if a[i] != "0": if ans != -1: ans = min(ans, int(a[0:i]) + int(a[i:])) else: ans = int(a[0:i]) + int(a[i:]) break for i in range(mid + 1, l): if a[i] != "0": if ans != -1: ans = min(ans, int(a[0:i]) + int(a[i:])) else: ans = int(a[0:i]) + int(a[i:]) break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR 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 VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN 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.
import sys mod = 1000000007 get_arr = lambda: list(map(int, input().split())) get_int = lambda: int(input()) get_ints = lambda: map(int, input().split()) get_str = lambda: input() get_strs = lambda: input().split() n = get_int() s = get_str() ans = int(s) j = 0 for i in range(n // 2, n): if j > 3: break if s[i] == "0": continue ans = min(ans, int(s[:i]) + int(s[i:])) j += 1 j = 0 for i in range(n // 2, 0, -1): if j > 3: break if s[i] == "0": continue ans = min(ans, int(s[:i]) + int(s[i:])) j += 1 print(ans)
IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF 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 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() vec = [] for i in range(1, l): if s[i] == "0": continue vec.append(i) vec = sorted(vec, key=lambda x: abs(x - l / 2)) ans = 10**100000 cnt = 0 for i in vec: cnt += 1 if cnt > 4: break ans = min(ans, int(s[:i]) + int(s[i:])) 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 EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF 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.
n = int(input()) a = input() minsum = -1 if n > 1000: start = n // 2 - 3 end = n // 2 + 3 else: start = 1 end = n i = start while start < end and start < n: str1 = a[:start] str2 = a[start:] if str1[0] != "0" and str2[0] != "0": temp = int(str1) + int(str2) if minsum == -1 or temp < minsum: minsum = temp if minsum == -1 and end <= n: end += 1 start += 1 print(minsum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR NUMBER 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.
def 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 def compare(str1, str2): if len(str1) > len(str2): return str2 elif len(str1) < len(str2): return str1 for i in range(len(str1)): if str1[i] > str2[i]: return str2 elif str1[i] < str2[i]: return str1 return str1 n = int(input()) str = input() result1 = "" result2 = "" bl1 = False bl2 = False if n % 2 == 0: u = n // 2 v = u else: u = n // 2 v = u + 1 while 1: if str[u] != "0" and u != 0: result1 = sum(str[0:u], str[u : len(str)]) bl1 = True break else: if u == 0: break u -= 1 while 1: if str[v] != "0": result2 = sum(str[0:v], str[v : len(str)]) bl2 = True break else: v += 1 if v == n: break if bl1 == True and bl2 == True: print(compare(result1, result2)) elif bl1 == True: print(result1) elif bl2 == True: print(result2)
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 FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR 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.
n = int(input()) s = str(input()) ans = -1 cnt = 0 le = len(s) i = max(1, le // 2) while i < le and cnt < 7: while i + 1 < le and s[i] == "0": i += 1 l = s[:i] r = s[i:] cnt += 1 i += 1 if l[0] == "0" or r[0] == "0": continue if ans == -1: ans = int(l) + int(r) else: ans = min(ans, int(l) + int(r)) i = max(1, le // 2) cnt = 0 while i < le and cnt < 7: while i > 1 and s[i] == "0": i -= 1 if i <= 0 or s[i] == "0": break l = s[:i] r = s[i:] cnt += 1 i -= 1 if l[0] == "0" or r[0] == "0": continue if ans == -1: ans = int(l) + int(r) else: ans = min(ans, int(l) + int(r)) assert ans != -1 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL 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.
def solve(S): n = len(S) cands = [] i = n // 2 while i > 0 and S[i] == "0": i -= 1 cands.append(i) j = n // 2 + 1 while j < n and S[j] == "0": j += 1 cands.append(j) sums = [] for i in set(cands): if i == 0: sums.append([S, "0"]) elif i == n: sums.append([S, "0"]) else: sums.append([S[:i], S[i:]]) return min(int(a) + int(b) for a, b in sums) input() print(solve(input()))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR STRING IF VAR VAR EXPR FUNC_CALL VAR LIST VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR 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.
l = int(input()) n = input() ans = int(n) mid = l // 2 if n[mid] != "0": ans = int(n[:mid]) + int(n[mid:]) i = l // 2 out = False for j in range(1, mid + 1): if i + j < l: if n[i + j] != "0": temp = int(n[: i + j]) + int(n[i + j :]) ans = min(ans, temp) out = True if i - j > 0: if n[i - j] != "0": temp = int(n[: i - j]) + int(n[i - j :]) ans = min(ans, temp) break if out: break 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 VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN 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 ASSIGN VAR FUNC_CALL VAR VAR VAR 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.
import sys input = sys.stdin.readline N = int(input()) S = input().rstrip() L = [[] for _ in range(N)] for n in range(N - 1): if S[n + 1] != "0": L[max(n + 1, N - n - 1)].append(n) def make_sum(s1, s2): if len(s1) < len(s2): tmp = s2 s2 = s1 s1 = tmp l1, l2 = len(s1), len(s2) s2 = "0" * (l1 - l2) + s2 S = [0] * (l1 + 1) for i in range(l1): a = int(s2[-i - 1]) + int(s1[-i - 1]) + S[i] S[i] = a % 10 S[i + 1] += a // 10 go = False a = "" for n in range(l1, -1, -1): if S[n] == 0 and not go: continue else: go = True a += str(S[n]) return a def smaller(s1, s2): if len(s1) > len(s2): return s2 elif len(s1) < len(s2): return s1 else: l = len(s1) for i in range(l): if s1[i] > s2[i]: return s2 elif s1[i] < s2[i]: return s1 return s1 ans = "9" * N c = 0 for l in range(N): update = False for n in L[l]: s1, s2 = S[: n + 1], S[n + 1 :] a = make_sum(s1, s2) ans = smaller(ans, a) update = True if update: c += 1 if c > 3: break print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR 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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR RETURN VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER 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.
import sys l = int(input()) s = input() n = l // 2 ans = 0 c1, c2 = int(s), int(s) f = 0 while n > 0: k = l - n if s[n] != "0": c1 = int(s[0:n:1]) + int(s[n:l:1]) f = 1 if s[k] != "0": c2 = int(s[0:k:1]) + int(s[k:l:1]) f = 1 if f == 1: ans = min(c1, c2) break n -= 1 print(ans)
IMPORT 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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.
l = int(input()) n = input() good = l // 2 lgood = good - 1 rgood = good + 1 if n[good] != "0": print(min(int(n[:good]) + int(n[good:]), int(n[: 1 + good]) + int(n[1 + good :]))) else: while lgood > 0 and n[lgood] == "0": lgood -= 1 while rgood < l and n[rgood] == "0": rgood += 1 if lgood == 0: a = float("inf") else: a = int(n[:lgood]) + int(n[lgood:]) if rgood == l: b = float("inf") else: b = int(n[:rgood]) + int(n[rgood:]) print(min(a, b))
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 IF 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 NUMBER VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL 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
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 mp(): return map(int, input().split()) n = int(input()) a = input() b = cnt = 0 for i in range(n // 2, n): if a[i] != "0": t = int(int(a[:i]) + int(a[i:])) if b == 0 or t < b: b = t cnt += 1 if cnt > 2: break cnt = 0 for i in range(n // 2, 0, -1): if a[i] != "0": t = int(int(a[:i]) + int(a[i:])) if b == 0 or t < b: b = t cnt += 1 if cnt > 2: break print(b)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER 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.
n = int(input()) s = input() ans = int(s) ind = set() for i in range(0, n): if s[i] != "0": ind.add(i) L, R = False, False for i in range(0, n): if n // 2 - i > 0 and not L: if n // 2 - i in ind: ans = min(ans, int(s[: n // 2 - i]) + int(s[n // 2 - i :])) L = True if n // 2 + i < n and not R: if n // 2 + i in ind: ans = min(ans, int(s[: n // 2 + i]) + int(s[n // 2 + i :])) if i: R = True if L and R: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR 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 IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER IF 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 = input() l = len(a) aa = int(a) ans = -1 pos = int(l / 2) pos1 = pos pos2 = pos while pos1 < l and a[pos1] == "0": pos1 += 1 while pos2 >= 0 and a[pos2] == "0": pos2 -= 1 try: n1 = a[:pos1] n2 = a[pos1:] ans = int(n1) + int(n2) except: pass if pos1 + 1 < l and a[pos1 + 1] != "0": n3 = a[: pos1 + 1] n4 = a[pos1 + 1 :] if ans != -1: ans = min(ans, int(n3) + int(n4)) else: ans = int(n3) + int(n4) try: n1 = a[:pos2] n2 = a[pos2:] if ans != -1: ans = min(ans, int(n1) + int(n2)) else: ans = int(n1) + int(n2) except ValueError: pass if pos2 - 1 > 0 and a[pos2 - 1] != "0": n3 = a[: pos2 - 1] n4 = a[pos2 - 1 :] ans = min(ans, int(n3) + int(n4)) if ans != -1: ans = min(ans, int(n3) + int(n4)) else: ans = int(n3) + int(n4) print(ans)
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 NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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()) s = input() num = int(s) pos1, pos2 = len(s) // 2 - 1, len(s) // 2 + 1 while pos1 >= 0 and s[pos1] == "0": pos1 -= 1 while pos2 < n and s[pos2] == "0": pos2 += 1 for i in range(max(1, pos1), min(n, pos2 + 1)): if s[i:][0] == "0": continue num = min(int(s[:i]) + int(s[i:]), num) print(num)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER 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.
length = int(input()) l = input() min_s = None start_pos = length // 2 end_pos = start_pos start_count = 0 while start_pos > 0: if l[start_pos] != "0": n1 = l[:start_pos] n2 = l[start_pos:] start_count += 1 if min_s == None: min_s = int(n1) + int(n2) else: min_s = min(min_s, int(n1) + int(n2)) start_pos -= 1 if start_count == 5: break end_count = 0 while end_pos < length: if l[end_pos] != "0": n1 = l[:end_pos] n2 = l[end_pos:] end_count += 1 if min_s == None: min_s = int(n1) + int(n2) else: min_s = min(min_s, int(n1) + int(n2)) end_pos += 1 if end_count == 5: break print(min_s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER 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() x1, x2 = l // 2, (l + 1) // 2 min_val = 10**1000000 while True: flag = False if n[x1] != "0": a = int(n[:x1]) b = int(n[x1:]) min_val = min(min_val, a + b) flag = True if n[x2] != "0": a = int(n[:x2]) b = int(n[x2:]) min_val = min(min_val, a + b) flag = True if flag == True: print(min_val) break else: x1 -= 1 x2 += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING 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 NUMBER IF VAR VAR STRING 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 NUMBER IF VAR NUMBER 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.
n = int(input()) s = input() if len(s) == 2: print(int(s[0]) + int(s[1])) exit(0) met = len(s) // 2 if s[n // 2] != "0" and s[n // 2 + 1] != "0" and s[n // 2 - 1 + (n == 3)] != "0": print( min( int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]), min( int(s[: n // 2]) + int(s[n // 2 :]), int(s[: n // 2 - 1 + (n == 3)]) + int(s[n // 2 - 1 + (n == 3) :]), ), ) ) exit(0) elif s[n // 2 + 1] != "0" and s[n // 2] != "0": print( min( int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]), int(s[: n // 2]) + int(s[n // 2 :]), ) ) exit(0) elif s[n // 2] != "0" and s[n // 2 - 1 + (n == 3)] != "0": print( min( int(s[: n // 2]) + int(s[n // 2 :]), int(s[: n // 2 - 1 + (n == 3)]) + int(s[n // 2 - 1 + (n == 3) :]), ) ) exit(0) elif s[n // 2 + 1] != "0" and s[n // 2 - 1 + (n == 3)] != "0": print( min( int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]), int(s[: n // 2 - 1 + (n == 3)]) + int(s[n // 2 - 1 + (n == 3) :]), ) ) exit(0) elif s[n // 2] != "0": print(int(s[: n // 2]) + int(s[n // 2 :])) exit(0) elif s[n // 2 + 1] != "0": print(int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :])) exit(0) elif s[n // 2 - 1 + (n == 3)] != "0": print(int(s[: n // 2 - 1 + (n == 3)]) + int(s[n // 2 - 1 + (n == 3) :])) exit(0) ult = n + 1 ult2 = -1 for i in range(n // 2, len(s)): if s[i] != "0": ult = min(ult, i) for i in range(0, n // 2): if s[i] != "0": ult2 = i if ult != n + 1 and ult2 != -1: print(min(int(s[:ult]) + int(s[ult:]), int(s[:ult2]) + int(s[ult2:]))) elif ult != n + 1: print(int(s[:ult]) + int(s[ult:])) elif ult2 != -1: print(int(s[:ult2]) + int(s[ult2:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR 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 FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL 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 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 BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL 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 BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING 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 BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL 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 BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL 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 NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER 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 IF VAR BIN_OP 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
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() ok = False if n % 2: if s[n // 2] != "0": print( min( int(s[: n // 2]) + int(s[n // 2 :]), int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]), ) ) ok = True elif s[n // 2] != "0": s1 = s[: n // 2] s2 = s[n // 2 :] print(int(s1) + int(s2)) ok = True if ok == False: r = l = n // 2 while l >= 0: if s[l] != "0": break l -= 1 while r < n: if s[r] != "0": break r += 1 mn = int(s) if l != 0: mn = min(mn, int(s[:l]) + int(s[l:])) if r != n: mn = min(mn, int(s[:r]) + int(s[r:])) print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING 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 IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER 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.
l = int(input()) n = input() mid = l // 2 + 1 ans = int(n) for x in range(mid, 0, -1): if n[x] == "0": continue ans = min(ans, int(n[:x]) + int(n[x:])) break mid = l // 2 for x in range(mid, l - 1): if n[x] == "0": continue ans = min(ans, int(n[:x]) + int(n[x:])) break 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 FUNC_CALL VAR VAR 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 ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR 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.
l = int(input()) n = str(input()) mn = -1 midpoint = l // 2 i = midpoint numright = 0 while numright < 5 and i < l - 1: if n[i + 1] != "0": first = int(n[: i + 1]) second = int(n[i + 1 :]) if mn == -1: mn = first + second else: mn = min(mn, first + second) numright += 1 i += 1 i = midpoint numleft = 0 while numleft < 5 and i >= 0: if n[i + 1] != "0": first = int(n[: i + 1]) second = int(n[i + 1 :]) if mn == -1: mn = first + second else: mn = min(mn, first + second) numleft += 1 i -= 1 print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER 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 NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER 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 NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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.
n = int(input()) s = input() lim = n // 2 ans = -1 cnt = 0 for i in range(lim, 0, -1): if cnt >= 3: break if s[i] == "0": continue res = int(s[0:i]) + int(s[i:]) if ans == -1: ans = res else: ans = min(ans, res) cnt += 1 cnt = 0 for i in range(lim, n): if cnt >= 3: break if s[i] == "0": continue res = int(s[0:i]) + int(s[i:]) if ans == -1: ans = res else: ans = min(ans, res) cnt += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR 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 = str(input()) z = n // 2 l = z p = "9" * 113110 p = int(p) res = p cnt = 0 for i in range(l, n): if s[i] == "0": continue cnt += 1 s1 = s[:i] s2 = s[i:] s1 = int(s1) s2 = int(s2) p = min(p, s1 + s2) if cnt >= 3: break cnt = 0 for i in range(l, 0, -1): if s[i] == "0": continue cnt += 1 s1 = s[:i] s2 = s[i:] s1 = int(s1) s2 = int(s2) p = min(p, s1 + s2) if cnt >= 3: break print(p)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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.
n = int(input()) s = input() j = (n + 1) // 2 i = j - 1 r = int(s) while i > 0 and s[i] == "0": i -= 1 while j < n and s[j] == "0": j += 1 if i > 0: w = int(s[0:i]) + int(s[i:]) r = min(r, w) if j < n: k = int(s[0:j]) + int(s[j:]) r = min(r, k) print(r)
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 ASSIGN VAR FUNC_CALL VAR VAR 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 NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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.
def cal(s, inx, len): l = int(s[0:inx]) r = int(s[inx:len]) return l + r n = int(input()) s = input() res = -1 i = n // 2 flag = 1 while flag != 0: i += 1 if i > n - 1: break if s[i] == "0": continue flag -= 1 if res == -1: res = cal(s, i, n) else: res = min(res, cal(s, i, n)) flag = 1 i = n // 2 + 1 while flag != 0: i -= 1 if i <= 0: break if s[i] == "0": continue flag -= 1 if res == -1: res = cal(s, i, n) else: res = min(res, cal(s, i, n)) print(res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL 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.
len = int(input()) s = input() best = 0 best2 = 0 for i in range(1, len): if s[i] != "0": if max(i, len - i) < max(best, len - best): best = i elif max(i, len - i) == max(best, len - best): best2 = i ans = int(s[:best]) + int(s[best:]) if best2 != 0: anss = int(s[:best2]) + int(s[best2:]) print(min(ans, anss)) else: print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER 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.
import sys def main(): l = input("") n = input("") min = -1 n = str(n) i = 0 j = 1 while i < int(len(n) // 2): if len(n) % 2 == 0: if n[int(len(n) // 2) + i] != "0": a = n[: int(len(n) // 2) + i] b = n[int(len(n) // 2) + i :] sum = int(a) + int(b) if sum < min or min == -1: min = sum if n[int(len(n) // 2) - i] != "0": a = n[: int(len(n) // 2) - i] b = n[int(len(n) // 2) - i :] sum = int(a) + int(b) if sum < min or min == -1: min = sum i += 1 if min != -1: break else: if n[int(len(n) // 2) + j] != "0": a = n[: int(len(n) // 2) + j] b = n[int(len(n) // 2) + j :] sum = int(a) + int(b) if sum < min or min == -1: min = sum if n[int(len(n) // 2) - i] != "0": a = n[: int(len(n) // 2) - i] b = n[int(len(n) // 2) - i :] sum = int(a) + int(b) if sum < min or min == -1: min = sum i += 1 j += 1 if min != -1: break print(min) main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER 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 main(): q = int(input()) s = input() ans = 10**1000000 for i in range(max(1, q // 2 - 1), q): if s[i] != "0" or s[q - i] != "0": if s[i] != "0": ans = min(ans, int(s[:i]) + int(s[i:])) if s[q - i] != "0": ans = min(ans, int(s[: q - i]) + int(s[q - i :])) if len(str(ans)) <= max(i, q - i) and i > q // 2: break print(ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING VAR BIN_OP VAR VAR STRING IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP 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.
n, s = int(input()), input() for i in range((n - 1) // 2, -1, -1): if s[i + 1] == "0": continue best = int(s[: i + 1]) + int(s[i + 1 :]) break for i in range(n // 2, n): if s[i] == "0": continue best = min(best, int(s[:i]) + int(s[i:])) break print(best)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER 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 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