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.
number = int(input("")) input_array = list(input("")) first = 0 second = 0 result = 0 if number % 2 == 0: i = int(number / 2) if input_array[i] == "0": while i != number and input_array[i] == "0": i += 1 if i == number: i = number - 1 while input_array[i] == "0": i -= 1 result = int("".join(input_array[0:i])) + int( "".join(input_array[i:number]) ) else: first = int("".join(input_array[0:i])) + int("".join(input_array[i:number])) i = int(number / 2) - 1 while input_array[i] == "0": i -= 1 second = int("".join(input_array[0:i])) + int( "".join(input_array[i:number]) ) if first > second: result = second else: result = first else: result = int("".join(input_array[0:i])) + int("".join(input_array[i:number])) else: i = int(number / 2) + 1 if input_array[i] == "0": while i != number and input_array[i] == "0": i += 1 if i == number: i = int(number / 2) while input_array[i] == "0": i -= 1 result = int("".join(input_array[0:i])) + int( "".join(input_array[i:number]) ) else: first = int("".join(input_array[0:i])) + int("".join(input_array[i:number])) i = int(number / 2) while input_array[i] == "0": i -= 1 second = int("".join(input_array[0:i])) + int( "".join(input_array[i:number]) ) if first > second: result = second else: result = first else: first = int("".join(input_array[0:i])) + int("".join(input_array[i:number])) i = int(number / 2) if input_array[i] != "0": second = int("".join(input_array[0:i])) + int( "".join(input_array[i:number]) ) if first > second: result = second else: result = first else: result = first print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR 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 BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR IF VAR VAR ASSIGN 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.
n = int(input()) s = input() good = [] for i in range(1, n): if s[i] != "0": good.append([max(n - i, i), i]) good = sorted(good) if len(good) == 0: good.append([n - 1, n - 1]) if len(good) == 1: good.append(good[0]) ans = int(s[: good[0][1]]) + int(s[-(n - good[0][1]) :]) ans = min(ans, int(s[: good[1][1]]) + int(s[-(n - good[1][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 VAR IF VAR VAR STRING EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR 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() L = l // 2 R = l // 2 + 1 R = min(l - 1, R) while s[L] == "0" and L > 1: L -= 1 while s[R] == "0" and R < l - 1: R += 1 a = int(s[0:L]) + int(s[L:l]) b = int(s[0:R]) + int(s[R:l]) if s[L] == "0": print(b) elif s[R] == "0": print(a) else: 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) m = input() k = n // 2 l = n // 2 if n == 1: print(m) elif n == 2: print(int(m) // 10 + int(m) % 10) elif n % 2 == 0: while m[k] == "0": k -= 1 while l < n and m[l] == "0": l += 1 if k == 0: s = int(m) else: s = int(m[:k]) + int(m[k:]) if l == n: t = int(m) else: t = int(m[l:]) + int(m[:l]) print(min(s, t)) elif n % 2 != 0: if m[k] != "0" and m[k + 1] != "0": s = int(m[:k]) + int(m[k:]) t = int(m[: k + 1]) + int(m[k + 1 :]) print(min(s, t)) elif m[k] == "0": while m[k] == "0": k -= 1 while l < n and m[l] == "0": l += 1 if k == 0: s = int(m) else: s = int(m[:k]) + int(m[k:]) if l == n: t = int(m) else: t = int(m[l:]) + int(m[:l]) print(min(s, t)) elif m[k + 1] == "0": print(int(m[:k]) + int(m[k:]))
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING 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 IF 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 IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING WHILE VAR VAR STRING 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 IF 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 VAR BIN_OP VAR NUMBER STRING 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()) l = input() r = int(l) c = 0 while n // 2 > c: a, b = 0, 0 if l[n // 2 - c] == "0": a = r else: a = int(l[: n // 2 - c]) + int(l[n // 2 - c :]) if l[(n + 1) // 2 + c] == "0": b = r else: b = int(l[: (n + 1) // 2 + c]) + int(l[(n + 1) // 2 - c :]) a = min(a, b) if a ^ r: r = a break c += 1 print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP 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.
x = int(input()) y = input() mn = 999999 for i in range(x // 2, 0, -1): if y[i] != "0": mn = int(y[:i]) + int(y[i:]) break for i in range(x // 2 + 1, x): if y[i] != "0": mn = min(mn, int(y[:i]) + int(y[i:])) break print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
input() s = input() n = len(s) pos = n // 2 left = pos right = pos + 1 while s[left] == "0": left -= 1 while right < n and s[right] == "0": right += 1 if left == 0: res = int(s[:right]) + int(s[right:]) elif right == n: res = int(s[:left]) + int(s[left:]) else: res = min(int(s[:left]) + int(s[left:]), int(s[:right]) + int(s[right:])) print(res)
EXPR 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 BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = eval(input()) s = input() ans = 0 k = int(0) for i in range(n): f1 = 0 f2 = 0 ans1 = 0 ans2 = 0 if n // 2 - k > 0 and s[n // 2 - k] != "0": s1 = s[0 : n // 2 - k] s2 = s[n // 2 - k : n] ans1 = eval(s1) + eval(s2) f1 = 1 m = n - (n // 2 - k) if m > 0 and s[m] != "0": f2 = 1 s1 = s[0:m] s2 = s[m:n] ans2 = eval(s1) + eval(s2) if f1 == 1 and f2 == 1: print(min(ans1, ans2)) break elif f1 == 1: print(ans1) break elif f2 == 1: print(ans2) break k = k + 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL 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 ASSIGN VAR BIN_OP VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() best = 0 best2 = None for sl in range(1, l): if s[sl] != "0": if max(sl, l - sl) < max(best, l - best): best = sl best2 = None elif max(sl, l - sl) == max(best, l - best): best2 = sl f = s[:best] b = s[best:] res = int(s[:best]) + int(s[best:]) if best2 is None: print(res) else: res2 = int(s[:best2]) + int(s[best2:]) print(min(res, res2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE 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 ASSIGN VAR NONE IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def add(num1, num2): num1 = num1[::-1] num2 = num2[::-1] result = "" i = 0 j = 0 a_len = len(num1) b_len = len(num2) carry = 0 while i < a_len or j < b_len: A = 0 B = 0 if i < a_len: A = num1[i] if j < b_len: B = num2[j] s = int(A) + int(B) + carry result = result + str(s % 10) carry = s // 10 i = i + 1 j = j + 1 if carry > 0: result = result + str(carry) return result[::-1] N = int(input()) number = input() minimum = 9999999 for i in range(1, N): if number[i] != "0": if max(N - i, i) < minimum: minimum = max(N - i, i) mini_len = 99999999 ans = [] for i in range(1, N): if number[i] != "0": if max(N - i, i) == minimum: res = add(number[:i], number[i:]) if len(res) < mini_len: mini_len = len(res) ans.append(res) answer = [] for num in ans: if len(num) == mini_len: answer.append(num) print(sorted(answer)[0])
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) num = input() smallest = 1000000 points = [] for i, c in enumerate(num): if i == 0: continue if c != "0": if max(i, l - i) < smallest: smallest = max(i, l - i) points.clear() if max(i, l - i) == smallest: points.append(i) ans = int("9" * 100000) for val in points: ans = min(ans, int(num[:val]) + int(num[val:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING 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.
size = int(input()) num = input() j = (size + 1) // 2 i = j - 1 while i > 0 and num[i] == "0": i -= 1 while j < size and num[j] == "0": j += 1 res = int(num) if i > 0: res = min(res, int(num[0:i]) + int(num[i:])) if j < size: res = min(res, int(num[0:j]) + int(num[j:])) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR 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 NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() if n == 2: print(int(s[0]) + int(s[1])) exit() i = n // 2 rez1 = 0 rez2 = 0 while i < n - 1: if s[i:][0] == "0": i += 1 else: break rez1 = int(s[i:]) + int(s[0:i]) j = n // 2 + 1 while j > 1: if s[j:][0] == "0": j -= 1 else: break if s[j:][0] == "0": print(rez1) exit() rez2 = int(s[j:]) + int(s[0:j]) if s[i:][0] == "0": print(rez2) exit() print(min(rez1, rez2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR 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.
t = int(input()) s = input() l = 0 r = t - 1 mid = t / 2 for i in range(t): if s[i] != "0": if i <= mid: l = i else: r = min(r, i) if r == t - 1 and s[r] == "0": r = l - 1 h1 = pow(10, t - r) h2 = pow(10, t - l) s = int(s) ans = min(s // h1 + s % h1, s // h2 + s % h2) 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 VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def solve(n, l): m = l // 2 cnd = [] for i in range(m, l): if n[i] != "0" and len(cnd) < 3: cnd.append(i) for i in range(m, 0, -1): if n[i] != "0" and len(cnd) < 6: cnd.append(i) def get(s, i): s1 = s[0:i] s2 = s[i:] return int(s1) + int(s2) ans = -1 for i in cnd: if ans == -1: ans = get(n, i) ans = min(ans, get(n, i)) return ans def solves(n, l): m = l // 2 cnd = [] for i in range(m, l): if n[i] != "0" and len(cnd) < 3: cnd.append(i) for i in range(m, -1): if n[i] != "0" and len(cnd) < 6: cnd.append(i) def get(s, i): s1 = s[0:i] s2 = s[i:] return int(s1) + int(s2) ans = -1 for i in range(1, l): if n[i] != "0": if ans == -1: ans = get(n, i) ans = min(ans, get(n, i)) return ans l = int(input()) n = input() print(solve(n, l))
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 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 = int(input()) string = input() ans = float("inf") mid = len(string) // 2 cnt = 0 for i in range(mid, n): if cnt >= 2: break if string[i] != "0": l = int(string[0:i]) r = int(string[i:]) cnt += 1 ans = min(ans, l + r) cnt = 0 for i in range(mid, 0, -1): if cnt >= 2: break if string[i] != "0": l = int(string[0:i]) r = int(string[i:]) cnt += 1 ans = min(ans, l + r) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() r = float("inf") half = l // 2 if n[half] != "0": a, b = n[:half], n[half:] r = min(r, int(a) + int(b)) for i in range(half + 1, l): if n[i] != "0": a, b = n[:i], n[i:] r = min(r, int(a) + int(b)) break for i in range(half - 1, 0, -1): if n[i] != "0": a, b = n[:i], n[i:] r = min(r, int(a) + int(b)) break print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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.
l = int(input()) s = input() if l % 2 == 0: inda = l // 2 indb = l // 2 else: inda = l // 2 indb = l // 2 + 1 while s[inda] == "0" and inda > 1: inda -= 1 while s[indb] == "0" and indb < l - 1: indb += 1 al = s[:inda] ar = s[inda:] bl = s[:indb] br = s[indb:] aside = int(s[:inda]) + int(s[inda:]) bside = int(s[:indb]) + int(s[indb:]) if ar[0] == "0": min_sum = bside elif br[0] == "0": min_sum = aside elif aside < bside: min_sum = aside else: min_sum = bside print(min_sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN 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 NUMBER STRING ASSIGN VAR VAR IF VAR NUMBER STRING ASSIGN 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.
minn = 10**100001 n = int(input()) a = input() for i in range(int((n + 1) / 2) - 1, n - 1): if a[i + 1] == "0": continue buf = int(a[i + 1 : n]) + int(a[0 : i + 1]) if buf < minn: minn = buf break for i in range(int(n / 2) - 1, -1, -1): if a[i + 1] == "0": continue buf = int(a[i + 1 : n]) + int(a[0 : i + 1]) if buf < minn: minn = buf break print(minn)
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR 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 VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() ans = -1 for i in range(int((l - 1) / 2), -1, -1): if n[i + 1] != "0": a = int(n[0 : i + 1]) b = int(n[i + 1 : l]) if ans == -1 or a + b < ans: ans = a + b if i != int((l - 1) / 2): break for i in range(int((l - 1) / 2) + 1, l - 1, 1): if n[i + 1] != "0": a = int(n[0 : i + 1]) b = int(n[i + 1 : l]) if ans == -1 or a + b < ans: ans = a + b 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 BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER BIN_OP VAR VAR VAR ASSIGN 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()) a = input() a = str(a) fuck = int(a) count = 0 bb = [] if a[l - 1] != "0": fuck = int(a[: l - 1]) + int(a[l - 1 :]) for i in range(l - 1): if a[i] == "0" and a[i + 1] != "0": count += 1 bb.append(i) elif a[i] != "0" and a[i + 1] != "0": count += 1 bb.append(i) code = [] for i in range(6): tdygdh = 3 mid = l // 2 for i in range(4): iloveamit = 1 for i in range(count): temp = [] temp.append(abs(mid - bb[i])) temp.append(bb[i]) for i in range(1): gigi = 1 code.append(temp) code.sort(key=lambda x: x[0]) for i in range(min(10, len(code))): if int(a[: code[i][1] + 1]) + int(a[code[i][1] + 1 :]) < int(fuck): fuck = int(a[: code[i][1] + 1]) + int(a[code[i][1] + 1 :]) print(fuck)
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 LIST 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 IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR 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.
n = int(input()) s = input() x = int(s) y = 0 mn = 1e1000 tp = 1 l = n // 2 r = n // 2 while s[l] == "0": l -= 1 while r < n and s[r] == "0": r += 1 l = max(1, l - 1) r = min(n - 1, r + 1) for i in range(l, r + 1): if s[i] != "0": x = int(s[:i]) y = int(s[i:]) mn = min(mn, x + y) print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR 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.
n = int(input()) a = input() ans = int(a) k = n // 2 i = k while i < n and a[i] == "0": i += 1 if i < n - 1: ans = min(ans, int(a[:i]) + int(a[i:])) i = k while i >= 0 and a[i] == "0": i -= 1 if i > 0: ans = min(ans, int(a[:i]) + int(a[i:])) k = (n + 1) // 2 i = k while i < n and a[i] == "0": i += 1 if i < n - 1: ans = min(ans, int(a[:i]) + int(a[i:])) i = k while i >= 0 and a[i] == "0": i -= 1 if i > 0: ans = min(ans, int(a[:i]) + int(a[i:])) k = (n + 1) // 2 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 VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN 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 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 IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN 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 VAR FUNC_CALL VAR VAR VAR ASSIGN 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.
n = int(input()) s = input() x, y = n // 2, n // 2 + 1 while x > 0 and s[x] == "0": x -= 1 while y < n and s[y] == "0": y += 1 if x == 0: print(int(s[:y]) + int(s[y:])) elif y == n: print(int(s[:x]) + int(s[x:])) else: print(min(int(s[:y]) + int(s[y:]), int(s[:x]) + int(s[x:])))
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 WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) x = input() p = l // 2 ans = -1 for i in range(p + 1, l): if x[i] != "0": s = int(x[:i]) + int(x[i:]) if ans == -1 or s < ans: ans = s break for i in range(p, 0, -1): if x[i] != "0": s = int(x[:i]) + int(x[i:]) if ans == -1 or s < ans: ans = s break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER 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 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()) m = n // 2 if n % 2 == 0: if s[m] == "0": left = m - 1 right = n - 1 for i in range(m, n): if s[i] != "0": right = i break for i in range(m, -1, -1): if s[i] != "0": left = i break if right == n - 1: print(int(str(s[0 : max(left, 1)])) + int(str(s[left:n]))) else: print( min( int(str(s[0 : max(left, 1)])) + int(str(s[left:n])), int(str(s[0 : max(1, right)])) + int(str(s[right:n])), ) ) else: print(int(str(s[0:m])) + int(str(s[m:n]))) if n % 2 == 1: if s[m] == "0": left = m - 1 right = n - 1 for i in range(m, n): if s[i] != "0": right = i break for i in range(m, -1, -1): if s[i] != "0": left = i break print( min( int(str(s[0 : max(left, 1)])) + int(str(s[left:n])), int(str(s[0 : max(1, right)])) + int(str(s[right:n])), ) ) else: ans1 = int(str(s[0:m])) + int(str(s[m:n])) ans2 = int(str(s[0 : m + 1])) + int(str(s[m + 1 : n])) s111 = str(s[m + 1 : n]) if s111[0] == "0": ans = ans1 else: ans = min(ans1, ans2) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP 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 IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP 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 EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER STRING 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.
def prov(a, b): if b[0] == "0": return False, 0 else: return True, int(a) + int(b) x = int(input()) n = input() l = x // 2 r = l if x % 2 == 1: r += 1 y = 0 while y == 0: q, w = prov(n[:l], n[l:]) q1, w1 = prov(n[:r], n[r:]) l -= 1 r += 1 p = float("inf") if q: p = w if q1: p = min(p, w1) if p != float("inf"): y = 1 print(p)
FUNC_DEF IF VAR NUMBER STRING RETURN NUMBER NUMBER RETURN NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() ans = int(n) i = l // 2 + 1 j = l // 2 flag1 = False flag2 = False if (i < l) & (j > 0): while n[i] == "0" and i < l: i += 1 if i >= l: flag1 = True break while n[j] == "0" and j > 0: j -= 1 if j <= 0: flag2 = True break elif i >= l: flag1 = True elif j <= 0: flag2 = True if (i < l) & (flag1 == False): ans = min(int(n[i:]) + int(n[:i]), ans) if (j > 0) & (flag2 == False): ans = min(int(n[j:]) + int(n[:j]), ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER WHILE VAR VAR STRING VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() def goleft(s): mid = l // 2 while s[mid] == "0": mid -= 1 if mid == 0: return int(n) * 10 return sumof2(s[:mid], s[mid:]) def goright(s): mid = l // 2 + 1 while s[mid] == "0": if mid == len(s) - 1: return int(n) * 10 mid += 1 return sumof2(s[:mid], s[mid:]) def sumof2(s1, s2): s1 = int(s1) s2 = int(s2) return s1 + s2 if l == 2: print(sumof2(n[0], n[1])) else: print(min(goleft(n), goright(n)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() m = int(l / 2) cand1 = int(n) for i in range(m + 1, l): if not n[i] == "0": left = int(n[:i]) right = int(n[i:]) cand1 = min(left + right, cand1) break for i in range(m, 0, -1): if not n[i] == "0": left = int(n[:i]) right = int(n[i:]) cand1 = min(left + right, cand1) break print(cand1)
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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP 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 smaller(x, y): if x < y: return x return y L = int(input()) N = input() middle = L // 2 if L % 2 == 0: if N[middle] != "0": print(int(N[:middle]) + int(N[middle:])) else: index = 1 while True: flag1 = N[middle - index] != "0" flag2 = N[middle + index] != "0" if flag1 and flag2: X = int(N[: middle - index]) + int(N[middle - index :]) Y = int(N[: middle + index]) + int(N[middle + index :]) print(smaller(X, Y)) break elif flag1: X = int(N[: middle - index]) + int(N[middle - index :]) print(X) break elif flag2: Y = int(N[: middle + index]) + int(N[middle + index :]) print(Y) break index += 1 else: flag1 = N[middle] != "0" flag2 = N[middle + 1] != "0" if flag1 and flag2: X = int(N[:middle]) + int(N[middle:]) Y = int(N[: middle + 1]) + int(N[middle + 1 :]) print(smaller(X, Y)) elif flag1: X = int(N[:middle]) + int(N[middle:]) print(X) elif flag2: Y = int(N[: middle + 1]) + int(N[middle + 1 :]) print(Y) else: index = 1 while True: flag1 = N[middle - index] != "0" flag2 = N[middle + 1 + index] != "0" if flag1 and flag2: X = int(N[: middle - index]) + int(N[middle - index :]) Y = int(N[: middle + 1 + index]) + int(N[middle + 1 + index :]) print(smaller(X, Y)) break elif flag1: X = int(N[: middle - index]) + int(N[middle - index :]) print(X) break elif flag2: Y = int(N[: middle + 1 + index]) + int(N[middle + 1 + index :]) print(Y) break index += 1
FUNC_DEF IF VAR VAR RETURN VAR RETURN 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 IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER STRING IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR STRING IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN 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 EXPR FUNC_CALL VAR 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.
n = int(input()) s = input() ans = 10 ** (n + 3) a = [] for i in range(1, n): if s[i] != "0": a.append(i) i = 0 while i < len(a) and a[i] <= n // 2: i += 1 for j in range(max(i - 3, 0), min(i + 3, len(a))): ans = min(int(s[: a[j]]) + int(s[a[j] :]), ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR 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.
n = int(input()) s = input() ans = 0 cnt = 0 for i in range(n // 2 + 1, n): if s[i] >= "1" and s[i] <= "9": if ans == 0: ans = int(s[:i]) + int(s[i:]) else: ans = min(int(s[:i]) + int(s[i:]), ans) break cnt = 0 for i in range(n // 2, 0, -1): if s[i] >= "1" and s[i] <= "9": if ans == 0: ans = int(s[:i]) + int(s[i:]) else: ans = min(int(s[:i]) + int(s[i:]), ans) break 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 BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING 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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING 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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) num = str(input()) idx = l // 2 pos = True while True: if num[idx] != "0": break idx -= 1 if idx < 0: pos = False break ls = num[:idx] rs = num[idx:] s1 = 0 s1found = False if ls != "" and rs != "": s1 = int(ls) + int(rs) s1found = True pos2 = True idx = l // 2 + 1 while True: if num[idx] != "0": break idx += 1 if idx == l: pos2 = False break ls2 = num[:idx] rs2 = num[idx:] s2 = 0 s2found = False if rs2 != "" and ls2 != "": s2 = int(ls2) + int(rs2) s2found = True if s1found and s2found: print(min(s2, s1)) elif s1found: print(s1) else: print(s2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF 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.
def main(): buf = input() l = int(buf) buf = input() n = buf for i in range(l // 2, l): left = None right = None if n[i] != "0": left = i if n[-i] != "0": right = i if left and right: li = int(n[0:i]) + int(n[i:l]) ri = int(n[0 : l - i]) + int(n[l - i : l]) print(min(li, ri)) return elif left: print(int(n[0:i]) + int(n[i:l])) return elif right: print(int(n[0 : l - i]) + int(n[l - i : l])) return main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NONE ASSIGN VAR NONE IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN IF VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR RETURN IF VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN 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.
ln = int(input()) n = input() nmb = int(n) s = "0" l1 = 0 l2 = 0 i = int(ln / 2) while i >= 0: if n[i] != s: l1 = i break i = i - 1 i = int(ln / 2) while i < ln: if n[i] != s: l2 = i break i = i + 1 if l2 == 0: l2 = ln if l1 == l2: l2 = ln - l1 nmbl1a = n[:l1] nmbl1b = n[l1:] nmbl2a = n[:l2] nmbl2b = n[l2:] if l1 == 0: nmbl1a = "0" if l2 == ln: nmbl2b = "0" nmb1 = int(nmbl1a) + int(nmbl1b) nmb2 = int(nmbl2a) + int(nmbl2b) if nmb1 > nmb2: print(nmb2) else: print(nmb1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() itr = l // 2 + l % 2 itr2 = itr - 1 while itr < l and n[itr] == "0": itr += 1 while n[itr2] == "0": itr2 -= 1 x, y = itr - l // 2 - l % 2, l // 2 - itr2 if x == y: p = n[0:itr] q = n[itr2:itr] + n[0:itr2] if int(p) > int(q): a, b = n[0:itr2], n[itr2:l] else: a, b = n[0:itr], n[itr:l] elif x > y: a, b = n[0:itr2], n[itr2:l] else: a, b = n[0:itr], n[itr:l] print(int(a) + int(b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
d = int(input()) num = input() mid = d // 2 s1 = 0 s2 = 0 left = mid right = mid if num[mid] == "0": if int(num[mid:]) != 0: while num[left] == "0": left -= 1 while num[right] == "0" and right != d - 1: right += 1 try: s1 = int(num[:left]) + int(num[left:]) except ValueError: s1 = int(num) s2 = int(num[:right]) + int(num[right:]) if s1 < s2: print(s1) else: print(s2) else: while num[left] == "0": left -= 1 print(int(num[:left]) + int(num[left:])) if num[mid] != "0": if d % 2 == 0: print(int(num[:mid]) + int(num[mid:])) else: s1 = int(num[:mid]) + int(num[mid:]) if num[mid + 1] != "0": s2 = int(num[: mid + 1]) + int(num[mid + 1 :]) else: s2 = s1 + 1 if s1 < s2: print(s1) else: print(s2)
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 ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL 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 BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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.
n = int(input()) a = input() pos = n // 2 ans = -1 for it in range(n // 2, n // 2 - 5, -1): while pos >= 0 and a[pos] == "0": pos -= 1 if pos < 0: break if pos > 0: cur = int(a[0:pos]) + int(a[pos : len(a)]) if ans == -1: ans = cur else: ans = min(ans, cur) pos -= 1 pos = n // 2 for it in range(n // 2, n // 2 + 5): while pos < n and a[pos] == "0": pos += 1 if pos >= n: break if pos > 0: cur = int(a[0:pos]) + int(a[pos : len(a)]) if ans == -1: ans = cur else: ans = min(ans, cur) pos += 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL 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()) a = input() mid = n // 2 while mid < n - 1 and a[mid + 1] == "0": mid += 1 first = a[: mid + 1] if first == "": first = 0 else: first = int(first) second = a[mid + 1 :] if second == "": second = 0 else: second = int(second) ans1 = first + second mid = n // 2 while a[mid] == "0": mid -= 1 first = a[:mid] if first == "": first = 0 else: first = int(first) second = a[mid:] if second == "": second = 0 else: second = int(second) ans2 = first + second print(min(ans1, ans2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() ans = -1 mid = int(n / 2) while s[mid] == "0": mid = mid - 1 if mid in [0, n]: k = 1 elif ans == -1: ans = int(s[:mid]) + int(s[mid:]) else: ans = min(int(s[:mid]) + int(s[mid:]), ans) mid = int(n / 2) - 1 while mid != n and s[mid] == "0": mid = mid + 1 if mid in [0, n]: k = 1 elif ans == -1: ans = int(s[:mid]) + int(s[mid:]) else: ans = min(int(s[:mid]) + int(s[mid:]), ans) mid = int(n / 2) + 1 while mid != n and s[mid] == "0": mid = mid + 1 if mid in [0, n]: k = 1 elif ans == -1: ans = int(s[:mid]) + int(s[mid:]) else: ans = min(int(s[:mid]) + int(s[mid:]), ans) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input().strip() m = l // 2 ans = int(n) * 2 for d in range(m, -1, -1): ok = False for x in [d, l - d]: if x > 0 and x < l and n[x] != "0": ok = True ans = min(ans, int(n[:x]) + int(n[x:])) if ok: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR LIST VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR 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 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 = pow(10, 100000) a = sorted([i for i in range(1, n) if s[i] != "0"], key=lambda x: abs(n / 2 - x)) for i in a[:6]: 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 FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() op1 = -1 op2 = -1 for i in range(n // 2, 0, -1): if s[i] != "0": op1 = i break for i in range(n // 2 + 1, n): if s[i] != "0": op2 = i break if op1 == -1: num = str(int(s[op2:]) + int(s[:op2])) print(num) elif op2 == -1: num = str(int(s[op1:]) + int(s[:op1])) print(num) else: num1 = int(s[op1:]) + int(s[:op1]) num2 = int(s[op2:]) + int(s[:op2]) num = str(min(num1, num2)) print(num)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR 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 l = int(sys.stdin.readline().strip()) s = sys.stdin.readline().strip() mid = l // 2 def getz(a, dr, ed): for i in range(a, ed, dr): if s[i] != "0": return i return -1 if l % 2 == 0: sp1 = getz(mid - 1, -1, 0) sp2 = getz(mid, 1, l) else: sp1 = getz(mid, -1, 0) sp2 = getz(mid + 1, 1, l) if sp1 < 0: print(int(s[0:sp2]) + int(s[sp2:])) elif sp2 < 0: print(int(s[0:sp1]) + int(s[sp1:])) else: print(min(int(s[0:sp1]) + int(s[sp1:]), int(s[0:sp2]) + int(s[sp2:])))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING RETURN VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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() if n == 2: print(int(s[0]) + int(s[1])) else: ans = float("inf") for k in {n // 2, n // 2 - 1, n // 2 + 1}: if k != 0 and k != n: a, b = int(s[:k]), int(s[k:]) if s[k] != "0": ans = min(ans, a + b) for i in range(n // 2, n): if s[i] != "0": ans = min(ans, int(s[:i]) + int(s[i:])) break for i in range(n // 2 + 1, 0, -1): if s[i] != "0": ans = min(ans, int(s[:i]) + int(s[i:])) break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) st = input() kq = -1 mid = int(n / 2) l = mid r = mid for i in range(mid, 0, -1): if st[i] != "0": l = i break for i in range(mid, n, 1): if st[i] != "0": r = i break l = max(l - 5, 1) r = min(r + 5, n) for i in range(l, r, 1): if st[i] != "0": if kq == -1: kq = int(st[i:]) + int(st[0:i]) else: kq = min(kq, int(st[i:]) + int(st[0:i])) print(kq)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() mas = [] for i in s: mas.append(int(i)) centr = n // 2 pos1, pos2 = 0, 0 for i in range(centr, n): if s[i] != "0": pos1 = i break for i in range(centr, -1, -1): if s[i] != "0": pos2 = i break ans = [] var1 = s[:pos2], s[pos2:] var2 = s[:pos1], s[pos1:] if len(var1[0]) > 0 and len(var1[1]) > 0: ans.append(int(var1[0]) + int(var1[1])) if len(var2[0]) > 0 and len(var2[0]) > 0: ans.append(int(var2[0]) + int(var2[1])) if pos1 != n - 1 and s[pos1 + 1] != "0": ans.append(int(s[: pos1 + 1]) + int(s[pos1 + 1 :])) ans.sort() print(ans[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER 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 ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) nb = input() nbr = str(nb) mini = 0 mid = l // 2 if nbr[mid] != "0": tmp = int(nbr[:mid]) + int(nbr[mid:]) if mini == 0 or mini > tmp: mini = tmp cnt = 1 while mid + cnt < l: if nbr[mid + cnt] != "0": tmp = int(nbr[: mid + cnt]) + int(nbr[mid + cnt :]) if mini == 0 or mini > tmp: mini = tmp break else: cnt += 1 cnt = 1 while mid - cnt > 0: if nbr[mid - cnt] != "0": tmp = int(nbr[: mid - cnt]) + int(nbr[mid - cnt :]) if mini == 0 or mini > tmp: mini = tmp break else: cnt += 1 print(mini)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE 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 IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER 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.
l = int(input()) s = str(input()) m = (l - 1) // 2 x1 = y1 = x2 = y2 = -5 ok = True for i in range(l // 2): if m + i + 1 < l and s[m + i + 1] != "0": ok = False x1 = int(s[m + i + 1 :]) y1 = int(s[: m + i + 1]) if m - i > 0 and s[m - i] != "0": ok = False x2 = int(s[m - i :]) y2 = int(s[: m - i]) if not ok: break if x1 == -5: print(x2 + y2) elif x2 == -5: print(x1 + y1) else: print(min(x2 + y2, x1 + y1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
a = int(input()) s = input() x = a // 2 m = s[:x] n = s[x:] o = s[: x + 1] p = s[x + 1 :] l = a // 2 c = a // 2 for ll in range(a // 2, a): if s[ll] == "0": c += 1 else: break for ww in range(a // 2, 0, -1): if s[ww] == "0": l -= 1 else: break if a == 2: print(int(s[0]) + int(s[1])) elif c == l: print(min(int(m) + int(n), int(o) + int(p))) elif c == a: print(min(int(s), int(s[:l]) + int(s[l:]))) elif l == 0: print(min(int(s[:c]) + int(s[c:]), int(s))) else: print(min(int(s[:c]) + int(s[c:]), int(s[:l]) + int(s[l:])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() def lol(k): global s, n, u if k <= 0 or k >= n or s[k] == "0": return x = s[0:k] y = s[k:] u = min(u, int(x) + int(y)) a = n // 2 while a - 1 >= 0 and s[a] == "0": a -= 1 b = n // 2 while b + 1 <= n - 1 and s[b] == "0": b += 1 u = int(s) for i in range(-3, 4): lol(a + i) lol(b + i) print(u)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR VAR STRING RETURN ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL 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.
n = int(input()) s = input() mid = n // 2 a = s[:mid] b = s[mid:] c = s[: mid + 1] d = s[mid + 1 :] if len(b) > 0: while b[0] == "0": if len(b) > 0: b = b[1:] if len(b) <= 0: break a = a + "0" else: break if len(d) > 0: while d[0] == "0": if len(d) > 0: d = d[1:] if len(d) <= 0: break c = c + "0" else: break fl = False ans = 0 if len(a) > 0 and len(b) > 0 and b[0] != "0": sa = int(a) + int(b) if fl == False: ans = sa fl = True else: ans = min(ans, sa) if len(c) > 0 and len(d) > 0 and d[0] != "0": sc = int(c) + int(d) if fl == False: ans = sc fl = True else: ans = min(ans, sc) aa = s[:mid] bb = s[mid:] cc = s[: mid + 1] dd = s[mid + 1 :] if len(bb) > 0: while bb[0] == "0": if len(aa) > 0: bb = aa[-1] + bb aa = aa[:-1] if len(aa) <= 0: break else: break if len(dd) > 0: while dd[0] == "0": if len(cc) > 0: dd = cc[-1] + dd cc = cc[:-1] if len(cc) <= 0: break else: break if len(aa) > 0 and len(bb) > 0 and bb[0] != "0": saa = int(aa) + int(bb) if fl == False: ans = saa fl = True else: ans = min(ans, saa) if len(cc) > 0 and len(dd) > 0 and dd[0] != "0": scc = int(cc) + int(dd) if fl == False: ans = scc fl = True else: ans = min(ans, scc) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() k = l // 2 for i in range(k): m1 = 0 if s[k + i + l % 2] != "0": m1 = int(s[: k + i + l % 2]) + int(s[k + i + l % 2 :]) m2 = 0 if s[k - i] != "0": m2 = int(s[: k - i]) + int(s[k - i :]) if m1 == 0 and m2 == 0: continue if m1 > 0 and m2 == 0: m = m1 if m2 > 0 and m1 == 0: m = m2 if m1 > 0 and m2 > 0: m = min(m1, m2) break print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER 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.
n = int(input()) s = input() if n % 2: mid = n // 2 if s[mid] != "0": if int(s[: mid + 1]) < int(s[mid:]): print(int(s[: mid + 1]) + int(s[mid + 1 :])) else: print(int(s[:mid]) + int(s[mid:])) exit(0) else: mid = n // 2 if s[mid] != "0": print(int(s[:mid]) + int(s[mid:])) exit(0) candidates = [] i = mid while i < n and s[i] == "0": i += 1 if i < n: candidates.append(int(s[:i]) + int(s[i:])) i = mid while i >= 0 and s[i] == "0": i -= 1 if i > 0: candidates.append(int(s[:i]) + int(s[i:])) print(min(candidates))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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()) str = input() md = l // 2 md1 = md + 1 ans = -1 global num while md > 0: if str[md] != "0": i1 = int(str[0:md]) i2 = int(str[md::1]) num = i1 + i2 if num < ans or ans == -1: ans = num break md -= 1 if md == -1: break while md1 < l: if str[md1] != "0": i1 = int(str[0:md1]) i2 = int(str[md1::1]) num = i1 + i2 if num < ans or ans == -1: ans = num break md1 += 1 if md1 == l: break 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 VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR 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()) s = input() l = [i for i in range(1, n) if s[i] != "0"] l.sort(key=lambda x: abs(x - n / 2)) ans = float("inf") for i in l[:10]: 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 VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() l = sorted((abs(n / 2 - i), i) for i in range(1, n) if s[i] != "0") print(min(int(s[:i]) + int(s[i:]) for v, i in l[:2]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def get_sum(arr1, arr2): res = [] n = len(arr1) m = len(arr2) if n > m: n, m = m, n arr1, arr2 = arr2, arr1 carry = 0 i = 0 while i < n: if arr1[n - 1 - i] + arr2[m - 1 - i] + carry >= 10: res.append(arr1[n - 1 - i] + arr2[m - 1 - i] + carry - 10) carry = 1 else: res.append(arr1[n - 1 - i] + arr2[m - 1 - i] + carry) carry = 0 i += 1 while i < m: if arr2[m - 1 - i] + carry >= 10: res.append(arr2[m - 1 - i] + carry - 10) carry = 1 else: res.append(arr2[m - 1 - i] + carry) carry = 0 i += 1 if carry: res.append(carry) return res[::-1] def comp(arr1, arr2): if len(arr1) > len(arr2): return 1 elif len(arr1) < len(arr2): return -1 else: i = 0 while i < len(arr1) and arr1[i] == arr2[i]: i += 1 if arr1[i] > arr2[i]: return 1 elif arr1[i] < arr2[i]: return -1 else: return 0 return 0 l = int(input()) arr = list(map(int, input())) mid = l // 2 i = mid while i >= 0 and arr[i] == 0: i -= 1 arr1 = arr[:i] arr2 = arr[i:] res1 = get_sum(arr1, arr2) i = mid + 1 while i < l and arr[i] == 0: i += 1 arr1 = arr[:i] arr2 = arr[i:] res2 = get_sum(arr1, arr2) if res1 and res2: if comp(res1, res2) == -1: print("{}".format("".join(map(str, res1)))) elif comp(res1, res2) == 1: print("{}".format("".join(map(str, res2)))) else: print("{}".format("".join(map(str, res1))))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) a = input() ans = -1 if n % 2 == 0: if a[n // 2 :][0] == "0": ans0, ans1 = -1, -1 i = n // 2 while a[i] == "0": i -= 1 if len(a[:i]) != 0: ans0 = int(a[:i]) + int(a[i:]) else: ans0 = int(a[i:]) i = n // 2 while i < n and a[i] == "0": i += 1 if len(a[i:]) != 0: ans1 = int(a[:i]) + int(a[i:]) else: ans1 = int(a[:i]) ans = min(ans0, ans1) else: ans = int(a[: n // 2]) + int(a[n // 2 :]) else: ans0, ans1 = -1, -1 if a[n // 2 :][0] == "0": ans00, ans01 = -1, -1 i = n // 2 while a[i] == "0": i -= 1 if len(a[:i]) != 0: ans00 = int(a[:i]) + int(a[i:]) else: ans00 = int(a[i:]) i = n // 2 while i < n and a[i] == "0": i += 1 if len(a[i:]) != 0: ans01 = int(a[:i]) + int(a[i:]) else: ans01 = int(a[:i]) ans0 = min(ans00, ans01) else: ans0 = int(a[: n // 2]) + int(a[n // 2 :]) if a[n // 2 + 1 :][0] == "0": ans10, ans11 = -1, -1 i = n // 2 + 1 while a[i] == "0": i -= 1 if len(a[:i]) != 0: ans10 = int(a[:i]) + int(a[i:]) else: ans10 = int(a[i:]) i = n // 2 + 1 while i < n and a[i] == "0": i += 1 if len(a[i:]) != 0: ans11 = int(a[:i]) + int(a[i:]) else: ans11 = int(a[:i]) ans1 = min(ans10, ans11) else: ans1 = int(a[: n // 2 + 1]) + int(a[n // 2 + 1 :]) ans = min(ans0, ans1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER 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 VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER 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 VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER 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 FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR 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() c1 = n // 2 c2 = n // 2 + 1 while c1 > 0 and s[c1] == "0": c1 -= 1 while c2 < n and s[c2] == "0": c2 += 1 if c1 > 0: x1, x2 = int(s[:c1]), int(s[c1:]) s1 = x1 + x2 else: y1, y2 = int(s[:c2]), int(s[c2:]) s2 = y1 + y2 print(s2) exit(0) if c2 < n: y1, y2 = int(s[:c2]), int(s[c2:]) s2 = y1 + y2 else: x1, x2 = int(s[:c1]), int(s[c1:]) s1 = x1 + x2 print(s1) exit(0) print(min(s1, s2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = int(input()) s = str(n) ans = n R = l // 2 + 1 L = l // 2 while R < l and s[R] == "0": R += 1 if R < l and R > 0: tem = 10 ** (l - R) res = n // tem + n % tem if ans > res: ans = res while L >= 0 and s[L] == "0": L -= 1 if L >= 0: tem = 10 ** (l - L) res = n // tem + n % tem if ans > res: ans = res 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 VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
L = int(input()) D = input() s = 0 b = 42069666 for c in range(1, L): if D[c] != "0": if abs(L / 2 - c) < b: b = abs(L / 2 - c) s = c def c(s): if s == "": return 0 return int(s) res = c(D[:s]) + c(D[s:]) if L % 2: r = L // 2 if D[r] != "0": res = min(c(D[:r]) + c(D[r:]), res) if D[r + 1] != "0": res = min(c(D[: r + 1]) + c(D[r + 1 :]), res) print(res)
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 BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_DEF IF VAR STRING RETURN NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER 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 VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) l = input() arr = [] for i in range(len(l)): if l[i] != "0": arr.append((abs(n // 2 - i), i)) arr.sort() ans = 10**100001 for i in range(min(4, len(arr))): if arr[i][1] == 0: continue ans = min(ans, int(l[arr[i][1] :]) + int(l[: arr[i][1]])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER 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 = input() S = 10**100000 def raspil(number): global S pos = number while pos < n and s[pos] == "0": pos += 1 if pos < n: S = min(S, int(s[pos:]) + int(s[:pos])) pos = number while pos >= 0 and s[pos] == "0": pos -= 1 if pos > 0: S = min(S, int(s[pos:]) + int(s[:pos])) raspil(n // 2) raspil((n + 1) // 2) print(S)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR 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 VAR 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 BIN_OP VAR NUMBER EXPR FUNC_CALL 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.
input() s = input() x = [] for i in range(1, len(s)): if s[i] == "0": continue x += [(max(i, len(s) - i), i)] x.sort() y = [] for j, i in x[:10]: y += [int(s[:i]) + int(s[i:])] y.sort() print(y[0])
EXPR 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 VAR LIST FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR VAR NUMBER VAR LIST BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) a = input() s = str(a) ans = 1e1000 cnt = 0 for i in range(n // 2, -1, -1): if s[int(i + 1)] == "0": continue ans = min(ans, int(s[0 : i + 1]) + int(s[i + 1 : n])) cnt = cnt + 1 if cnt >= 2: break cnt = 0 for i in range(n // 2, n - 1, 1): if s[int(i + 1)] == "0": continue ans = min(ans, int(s[0 : i + 1]) + int(s[i + 1 : n])) cnt = cnt + 1 if cnt >= 2: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR FUNC_CALL 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 VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR FUNC_CALL 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 VAR ASSIGN VAR BIN_OP 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() def func(m): l = r = t = "" for i in range(0, m): l += s[i] for i in range(m, n): r += s[i] cn = 0 for i in range(0, len(r)): if r[i] == "0": l += "0" cn = cn + 1 else: break r = r[cn:] if len(l) == 0: x = int(r) elif len(r) == 0: x = int(l) else: x = int(l) + int(r) for i in range(len(l) - 1, -1, -1): if l[i] == "0": t += l[i] else: t += l[i] break t = t[::-1] l = l[: -len(t)] r = t + r if len(l) == 0: y = int(r) elif len(r) == 0: y = int(l) else: y = int(l) + int(r) return min(x, y) if n % 2 == 0: m = n // 2 print(func(m)) else: m = n // 2 print(min(func(m), func(m + 1)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() n = int(s) ans = n a = [] for i in range(l): a.append(int(s[i])) a = a[::-1] al = l for i in range(l): if a[i] > 0: temp = i + 1 if temp < l - i - 1: temp = l - i - 1 if al > temp: al = temp for i in range(l): if a[i] > 0: temp = i + 1 if temp < l - i - 1: temp = l - i - 1 if al == temp or al == temp + 1 or al == temp + 2: t = 10 ** (i + 1) tt = n % t + n // t if ans > tt: ans = tt print(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 VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def check(s, n): ans = 0 j = 0 for i in range(n // 2, n): j = n - i if s[i] != "0" and s[j] != "0": sumi = getsum(s, i) sumj = getsum(s, j) if sumi < sumj: ans = i else: ans = j elif s[i] != "0": ans = i elif s[j] != "0": ans = j else: continue break return ans def getsum(s, n): f = int(s[:n]) h = int(s[n:]) return f + h n = int(input()) s = input() g = check(s, n) sum = getsum(s, g) print(sum)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
from sys import stdin input = stdin.readline l = int(input()) n = input().rstrip() if l % 2 == 0: i = l // 2 elif int(n[0]) == int(n[l // 2 + 1]): if int(n[: l // 2]) <= int(n[l // 2 + 1 :]): i = l // 2 + 1 else: i = l // 2 elif int(n[0]) > int(n[l // 2 + 1]): i = l // 2 else: i = l // 2 + 1 j = i - 1 while n[i] == "0" and i < l - 1: i += 1 while n[j] == "0" and j > 1: j -= 1 if j == 0 or j == 1 and n[j] == "0": print(int(n[:i]) + int(n[i:])) elif i == l - 1 and n[i] == "0": print(int(n[:j]) + int(n[j:])) else: print(min(int(n[:i]) + int(n[i:]), int(n[:j]) + int(n[j:])))
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN 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 BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
q = int(input()) w = input() r = [] k = int(w) if q % 2 == 0: e = q // 2 i = 1 j = 1 l = 1 if w[e] == "0": while l: if w[e + j] != "0": k = int(w[: e + j]) + int(w[e + j :]) l = 0 j += 1 if w[e - i] != "0": k = min(k, int(w[: e - i]) + int(w[e - i :])) l = 0 i += 1 print(k) else: print(int(w[:e]) + int(w[e:])) else: e = q // 2 i = 0 j = 1 l = 1 while l: if w[e + j] != "0": k = int(w[: e + j]) + int(w[e + j :]) l = 0 j += 1 if w[e - i] != "0": k = min(k, int(w[: e - i]) + int(w[e - i :])) l = 0 i += 1 print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING WHILE 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 NUMBER VAR NUMBER 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 ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE 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 NUMBER VAR NUMBER 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 ASSIGN 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.
l = input() n = input() l = int(l) half = l // 2 if l % 2 == 1: half1 = l // 2 + 1 else: half1 = l // 2 while n[half] == "0" and n[half1] == "0" and half > 1: half = half - 1 half1 = half1 + 1 sum1 = int(n[:half]) + int(n[half:]) sum2 = int(n[:half1]) + int(n[half1:]) if n[half] == "0": sum1 = int(n) if n[half1] == "0": sum2 = int(n) if sum1 < sum2: print(sum1) else: print(sum2)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() k = n / 2 r = int(k) while r < n and s[r] == "0": r = r + 1 l = int(k - 1) while l >= 0 and s[l] == "0": l = l - 1 mn = -1 if l != 0: mn = int(s[:l]) + int(s[l:]) else: mn = int(s) if r != n and mn > int(s[:r]) + int(s[r:]): mn = int(s[:r]) + int(s[r:]) elif mn > int(s): mn = int(s) if n % 2 == 0: print(mn) else: k = (n + 1) / 2 r = int(k) while r < n and s[r] == "0": r = r + 1 l = int(k - 1) while l >= 0 and s[l] == "0": l = l - 1 mn1 = -1 if l != 0: mn1 = int(s[:l]) + int(s[l:]) else: mn1 = int(s) if r != n and mn1 > int(s[:r]) + int(s[r:]): mn1 = int(s[:r]) + int(s[r:]) elif mn1 > int(s): mn1 = int(s) if mn1 > mn: print(mn) else: print(mn1)
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 WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
def minsplit(n, m): if n[m] == "0": i = m while i >= 1 and n[i] == "0": i -= 1 if i == 0: k1 = -1 else: k1 = int(n[:i]) + int(n[i:]) i = m while i < len(n) and n[i] == "0": i += 1 if i == len(n): k2 = -1 else: k2 = int(n[:i]) + int(n[i:]) if k1 == -1: return k2 elif k2 == -1: return k1 else: return min(k1, k2) else: return int(n[:m]) + int(n[m:]) l = int(input()) n = input() if l % 2 == 0: print(minsplit(n, l // 2)) else: print(min(minsplit(n, l // 2), minsplit(n, l // 2 + 1)))
FUNC_DEF IF VAR VAR STRING ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() i = len(s) // 2 j = len(s) // 2 + 1 res = int(s) while i > 0 and s[i] == "0": i -= 1 if i > 0: res = min(res, int(s[:i]) + int(s[i:])) while j < len(s) and s[j] == "0": j += 1 if j < len(s): res = min(res, int(s[:j]) + int(s[j:])) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL 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 VAR FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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.
a = int(input("")) b = str(input("")) c = int(a / 2) g = int(b) for i in range(c, 0, -1): if b[i] != "0": e = int(b[:i]) f = int(b[i:]) g = e + f break for i in range(c + 1, len(b)): if b[i] != "0": h = int(b[:i]) j = int(b[i:]) k = h + j g = min(g, k) break print(g)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR 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 VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP 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 solve(): l = int(input()) num = input() h = l // 2 if num[h] == "0": j = h while j < l and num[j] == "0": j += 1 if j == l: ans = int(num) else: ans = int(num[:j]) + int(num[j:]) j = h while j > 0 and num[j] == "0": j -= 1 if j == 0: cur = int(num) else: cur = int(num[:j]) + int(num[j:]) if cur < ans: ans = cur else: ans = int(num[:h]) + int(num[h:]) if h - 1 > 0 and num[h - 1] != "0": ans2 = int(num[: h - 1]) + int(num[h - 1 :]) if ans2 < ans: ans = ans2 if h + 1 < l and num[h + 1] != "0": ans2 = int(num[: h + 1]) + int(num[h + 1 :]) if ans2 < ans: ans = ans2 print(ans) solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR 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 VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR 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 BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) string = input() if n % 2 == 0: right = n // 2 else: right = n // 2 + 1 left = right - 1 while left > 0 and string[left] == "0": left -= 1 while right < n and string[right] == "0": right += 1 if left != 0 and right < n: ans1 = int(string[:right]) + int(string[right:]) ans2 = int(string[:left]) + int(string[left:]) ans = min(ans1, ans2) elif left == 0: ans = int(string[:right]) + int(string[right:]) else: ans = int(string[:left]) + int(string[left:]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER 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 ASSIGN 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 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(line, pos): if pos == len(line): return int(line) if line[pos] != "0" or pos == 0 or pos == len(line) - 1: L = line[:pos] if pos != 0 else 0 R = line[pos:] if L == "0" or R == "0": return pow(10, 200000) return int(L) + int(R) else: right = left = pos while right < len(line) and line[right] == "0": right += 1 while left >= 0 and line[left] == "0": left -= 1 if right == len(line): right = len(line) - 1 if left < 0: left = 0 return min(calc(line, left), calc(line, right)) input() line = input() pos = len(line) // 2 answer = min(calc(line, pos), calc(line, pos + 1)) print(answer)
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING VAR STRING RETURN FUNC_CALL VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = str(input()) mn = int(s) pos = [] cnt = 0 for i in range(n // 2, n): if cnt < 3 and s[i] != "0": pos.append(i) cnt += 1 cnt = 0 for i in range(n // 2 - 1, 0, -1): if cnt < 3 and s[i] != "0": pos.append(i) cnt += 1 for i in pos: s1 = s[:i] s2 = s[i:] n1 = int(s1) n2 = int(s2) if n1 + n2 < mn: mn = n1 + n2 print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN 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.
import sys input = sys.stdin.readline n = int(input()) x = input() xx = int(x) if n == 2: print(int(x[0]) + int(x[1])) exit(0) li = n // 2 ri = n // 2 + 1 if n % 2 == 0 and x[n // 2] != "0": print(int(x[: n // 2]) + int(x[n // 2 :])) exit(0) if n % 2 == 0: li = n // 2 - 1 while True: ans1 = ans2 = xx if x[li] != "0": ans1 = int(x[:li]) + int(x[li:]) if x[ri] != "0": ans2 = int(x[:ri]) + int(x[ri:]) if ans1 < xx or ans2 < xx: print(min(ans1, ans2)) exit(0) else: li = max(1, li - 1) ri = min(n - 1, ri + 1)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE NUMBER ASSIGN VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) s = input() i = l // 2 if s[i] == "0": j = i while s[i] == "0": i += 1 if i == l: break while s[j] == "0": j -= 1 if j == 0: if i == l: print(s) else: print(int(s[:i]) + int(s[i:])) elif i == l: print(int(s[:j]) + int(s[j:])) else: print(min(int(s[:i]) + int(s[i:]), int(s[:j]) + int(s[j:]))) elif l & 1: print(min(int(s[:i]) + int(s[i:]), int(s[: i + 1]) + int(s[i + 1 :]))) else: print(int(s[:i]) + int(s[i:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER IF VAR VAR WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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 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 BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP 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()) a = input() flag = 0 i = 0 while flag == 0: if n // 2 + i < n: if a[n // 2 + i] != "0": break if n // 2 - i >= 0: if a[n // 2 - i] != "0": break i += 1 min = int(a) if n // 2 + i + 1 < n: if a[n // 2 + i + 1] != "0": if int(a[n // 2 + i + 1 :]) + int(a[: n // 2 + i + 1]) < min: min = int(a[n // 2 + i + 1 :]) + int(a[: n // 2 + i + 1]) if n // 2 + i < n: if a[n // 2 + i] != "0": if int(a[n // 2 + i :]) + int(a[: n // 2 + i]) < min: min = int(a[n // 2 + i :]) + int(a[: n // 2 + i]) if n // 2 + i - 1 < n: if a[n // 2 + i - 1] != "0": if int(a[n // 2 + i - 1 :]) + int(a[: n // 2 + i - 1]) < min: min = int(a[n // 2 + i - 1 :]) + int(a[: n // 2 + i - 1]) if n // 2 - i + 1 > 0: if a[n // 2 - i + 1] != "0": if int(a[n // 2 - i + 1 :]) + int(a[: n // 2 - i + 1]) < min: min = int(a[n // 2 - i + 1 :]) + int(a[: n // 2 - i + 1]) if n // 2 - i > 0: if a[n // 2 - i] != "0": if int(a[n // 2 - i :]) + int(a[: n // 2 - i]) < min: min = int(a[n // 2 - i :]) + int(a[: n // 2 - i]) if n // 2 - i - 1 > 0: if a[n // 2 - i - 1] != "0": if int(a[n // 2 - i - 1 :]) + int(a[: n // 2 - i - 1]) < min: min = int(a[n // 2 - i - 1 :]) + int(a[: n // 2 - i - 1]) print(min)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN 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 BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN 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 BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER 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() res = int(n) toCheck = [l // 2, (l + 1) // 2] while toCheck[0] > 1 and n[toCheck[0]] == "0": toCheck[0] -= 1 while toCheck[1] < l - 1 and n[toCheck[1]] == "0": toCheck[1] += 1 for pos in toCheck: v1 = n[:pos] v2 = n[pos:] if v1[0] != "0" and v2[0] != "0": res = min(res, int(v1) + int(v2)) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER NUMBER VAR VAR NUMBER STRING VAR NUMBER NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER STRING VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR 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.
l = int(input()) n = input() ans = int(n) mid = l // 2 L = mid while L > 0 and n[L] == "0": L -= 1 R = mid + 1 while R < l and n[R] == "0": R += 1 if L != 0 and R != l: num1 = n[0:R] num2 = n[R:l] ans = min(ans, int(num1) + int(num2)) num1 = n[0:L] num2 = n[L:l] ans = min(ans, int(num1) + int(num2)) if L == 0 and R != l: num1 = n[0:R] num2 = n[R:l] ans = min(ans, int(num1) + int(num2)) if L != 0 and R == l: num1 = n[0:L] num2 = n[L:l] ans = min(ans, int(num1) + int(num2)) 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 VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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.
l = int(input()) n = input() mid = l // 2 if l % 2 == 0 and n[mid] != "0": print(int(n[:mid]) + int(n[mid:])) else: ans = -1 pos = mid while pos > 0 and n[pos] == "0": pos -= 1 if pos != 0: ans = int(n[:pos]) + int(n[pos:]) pos = mid + 1 while pos < l and n[pos] == "0": pos += 1 if pos < l: if ans == -1: ans = int(n[:pos]) + int(n[pos:]) else: ans = min(ans, int(n[:pos]) + int(n[pos:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR 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 = str(input()) best = None mid = l // 2 cnt = 0 for i, c in enumerate(s[mid:]): if c != "0": if mid + i >= len(s): break l = s[: mid + i] r = s[mid + i :] if r[0] == "0": continue sm = int(l) + int(r) if best is None or best > sm: best = sm cnt += 1 if cnt == 5: break cnt = 0 for i, c in enumerate(s[mid::-1]): if c != "0": if mid - i < 1: break l = s[: mid - i] r = s[mid - i :] if r[0] == "0": continue sm = int(l) + int(r) if best is None or best > sm: best = sm cnt += 1 if cnt == 5: break print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NONE 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()) string = input() n = len(string) res = 0 def getMin(left, right): left1 = left right1 = right left2 = left right2 = right while right1.startswith("0") and len(right1) > 1: left1 = left1 + right1[0] right1 = right1[1 : len(right1)] while right2.startswith("0") and len(left2) > 1: right2 = left2[len(left2) - 1] + right2 left2 = left2[0 : len(left2) - 1] if not right2.startswith("0") and not right1.startswith("0"): res = min(int(left1) + int(right1), int(left2) + int(right2)) elif not right2.startswith("0"): res = int(left2) + int(right2) elif not right1.startswith("0"): res = int(left1) + int(right2) return res if n % 2 == 0: left = string[0 : int(n / 2)] right = string[int(n / 2) : n] if not right.startswith("0"): res = int(left) + int(right) else: res = getMin(left, right) else: left1 = string[0 : int(n / 2) + 1] right1 = string[int(n / 2) + 1 : n] left2 = string[0 : int(n / 2)] right2 = string[int(n / 2) : n] res = min(getMin(left1, right1), getMin(left2, right2)) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE FUNC_CALL VAR STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR 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() s = 10**100000 * 9 + 1 mid = l // 2 c = 0 while mid >= 1: if n[mid] == "0": mid -= 1 continue x1 = int(n[0:mid]) x2 = int(n[mid:]) s2 = x1 + x2 if s2 < s: s = s2 c += 1 mid -= 1 if c == 3: break mid = l // 2 + 1 c = 0 while mid < l: if n[mid] == "0": mid += 1 continue x1 = int(n[0:mid]) x2 = int(n[mid:]) s2 = x1 + x2 if s2 < s: s = s2 c += 1 mid += 1 if c == 3: break print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING 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 VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING 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 VAR ASSIGN VAR VAR VAR NUMBER 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.
k = int(input()) n = int(input()) s = str(n) x, y = -1, -1 for i in reversed(range(k // 2 + 1)): if s[i] != "0": x = i break for i in range(k // 2 + 1, k): if s[i] != "0": y = i break ans1, ans2 = 0, 0 if x > 0: ans1 = int(s[:x]) + int(s[x:]) if y > 0: ans2 = int(s[:y]) + int(s[y:]) if ans1 == 0: print(ans2) elif ans2 == 0: print(ans1) else: print(min(ans1, ans2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER 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 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()) x = input() r = n // 2 - 2 d = r + 4 ans = int(x) while r <= d: if r < 1: r += 1 continue if r >= n: r += 1 continue w = r if x[w] == "0": while w < n and x[w] == "0": w += 1 if w < n: ans = min(ans, int(x[0:w]) + int(x[w:n])) w = r while w > 0 and x[w] == "0": w -= 1 if w > 0: ans = min(ans, int(x[0:w]) + int(x[w:n])) else: ans = min(ans, int(x[0:w]) + int(x[w:n])) r += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN 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 VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR 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.
mod = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n = ii() ind1 = 0 ind2 = n + 1 s = si() for i in range(n // 2 + 1, n): if s[i] != "0": ind2 = i break for i in range(n // 2, 0, -1): if s[i] != "0": ind1 = i break mn = int("0" + s[:ind1]) + int("0" + s[ind1:]) mn = min(mn, int("0" + s[:ind2]) + int("0" + s[ind2:])) print(mn)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR VAR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR VAR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): l = int(input()) n = str(input()) ans = float("inf") if l % 2 == 0: cur = l // 2 d = 0 while True: found = False if cur + d < l and n[cur + d] != "0": found = True lnum = int(n[: cur + d]) rnum = int(n[cur + d :]) if lnum + rnum < ans: ans = lnum + rnum if cur - d >= 0 and n[cur - d] != "0": found = True lnum = int(n[: cur - d]) rnum = int(n[cur - d :]) if lnum + rnum < ans: ans = lnum + rnum if found: break d += 1 else: cur0 = l // 2 cur1 = cur0 + 1 d = 0 while True: found = False if cur1 + d < l and n[cur1 + d] != "0": found = True lnum = int(n[: cur1 + d]) rnum = int(n[cur1 + d :]) if lnum + rnum < ans: ans = lnum + rnum if cur0 - d >= 0 and n[cur0 - d] != "0": found = True lnum = int(n[: cur0 - d]) rnum = int(n[cur0 - d :]) if lnum + rnum < ans: ans = lnum + rnum if found: break d += 1 print(ans) resolve()
IMPORT EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR 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 = int(input()) str = input() ans = "" for i in range(len(str)): ans += "9" ans = int(ans) def check(str, pos): global ans if pos <= 0: return if str[pos] == "0": while str[pos] == "0": pos -= 1 if pos > 0: ans = min(ans, int(str[:pos]) + int(str[pos:])) pos += 1 while pos != len(str) and str[pos] == "0": pos += 1 if pos > 0 and pos != len(str): ans = min(ans, int(str[:pos]) + int(str[pos:])) else: ans = min(ans, int(str[:pos]) + int(str[pos:])) check(str, (n + 1) // 2) check(str, (n - 1) // 2) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN IF VAR VAR STRING 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 VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR 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.
N = int(input()) s = input() j = 0 k = 0 if N % 2 == 0: if 1: a = N b = 0 for i in range(N // 2, N): if s[i] != "0": a = i break for i in range(N // 2 - 1, -1, -1): if s[i] != "0": b = i break if a != N: m = int(s[:a]) + int(s[a:]) n = m if b != 0: n = int(s[:b]) + int(s[b:]) if m < n: k = m else: k = n elif b != 0: k = int(s[:b]) + int(s[b:]) else: k = int(s) else: if s[N // 2] == "0" or 1: a = N b = 0 for i in range(N // 2, N): if s[i] != "0": a = i break for i in range(N // 2 - 1, -1, -1): if s[i] != "0": b = i break if a != N: m = int(s[:a]) + int(s[a:]) n = m if b != 0: n = int(s[:b]) + int(s[b:]) if m < n: j = m else: j = n elif b != 0: j = int(s[:b]) + int(s[b:]) else: k = int(s) if 1: N = N + 1 a = N for i in range(N // 2, N - 1): if s[i] != "0": a = i break for i in range(N // 2 - 1, -1, -1): if s[i] != "0": b = i break if a != N: m = int(s[:a]) + int(s[a:]) n = m if b != 0: n = int(s[:b]) + int(s[b:]) if m < n: k = m else: k = n elif b != 0: k = int(s[:b]) + int(s[b:]) else: k = int(s) if j < k: k = j print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
n = int(input()) s = input() c = 0 ans = -1 k = n % 2 if n == 2: print(int(s[0]) + int(s[1])) else: if s[n // 2] != "0" and n % 2 == 1: ans = int(s[0 : n // 2]) + int(s[n // 2 :]) while s[n // 2 - c - 1] == "0" and s[n // 2 + c + k] == "0": c += 1 if s[n // 2 - c - 1] != "0" and n // 2 - c - 1 != 0: temp = int(s[0 : n // 2 - c - 1]) + int(s[n // 2 - c - 1 :]) if ans == -1: ans = temp else: ans = min(ans, temp) if s[n // 2 + c + k] != "0": temp = int(s[0 : n // 2 + c + k]) + int(s[n // 2 + c + k :]) if ans == -1: ans = temp else: ans = min(ans, temp) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN 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 BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER 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.
L = int(input()) N = str(input()) ans = 10**100000 l = L // 2 r = L // 2 + 1 while l > 0 and N[l] == "0": l -= 1 while r < L and N[r] == "0": r += 1 if l != 0: ans = min(ans, int(N[:l]) + int(N[l:])) if r != L: ans = min(ans, int(N[:r]) + int(N[r:])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER 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 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.
n = int(input()) s = input().strip() mid = n // 2 while mid + 1 < n and s[mid + 1] == "0": mid += 1 left = s[: mid + 1] right = s[mid + 1 :] if not right or not left: var1 = int(s) else: var1 = int(s[: mid + 1]) + int(s[mid + 1 :]) mid = n // 2 while mid >= 0 and s[mid] == "0": mid -= 1 left = s[:mid] right = s[mid:] if not left or not right: var2 = var1 else: var2 = int(s[:mid]) + int(s[mid:]) print(min(var1, var2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip. Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain. -----Input----- The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number. The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number. The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip. -----Output----- Print a single integer — the smallest number Dima can obtain. -----Examples----- Input 7 1234567 Output 1801 Input 3 101 Output 11 -----Note----- In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$. In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
l = int(input()) n = input() def solve(a): x = n[:a] y = n[a:] if x == "" or y == "": return None elif x[0] == "0" or y[0] == "0": return None while len(x) < len(y): x = "0" + x while len(y) < len(x): y = "0" + y z, c = "", 0 for xr, yr in zip(x[::-1], y[::-1]): z += chr(48 + (int(xr) + int(yr) + c) % 10) c = (int(xr) + int(yr) + c) // 10 if c == 1: z += "1" return z[::-1] def minN(a): ms = None for s in a: if ms == None: ms = s elif s == None: pass elif len(s) < len(ms): ms = s elif len(s) > len(ms): pass elif s < ms: ms = s return ms a = l // 2 while n[a] == "0": a -= 1 b = l - l // 2 while n[b] == "0": b += 1 if b >= l: b = a break r = minN([solve(a), solve(b)]) print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR STRING RETURN NONE IF VAR NUMBER STRING VAR NUMBER STRING RETURN NONE WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR STRING NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NONE FOR VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR NONE IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR