description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
L = int(input())
s = input()
best = int(s)
for i in range((L + 1) // 2, 0, -1):
if s[i] != "0":
a = int(s[:i])
b = int(s[i:])
best = min(best, a + b)
break
for i in range(L // 2, L):
if s[i] != "0":
a = int(s[:i])
b = int(s[i:])
best = min(best, a + b)
break
print(best)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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 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 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())
num = input()
start = len(num) // 2
ans = -1
for i in range(start, len(num) - 1):
if num[i + 1] != "0":
ans = int(num[: i + 1]) + int(num[i + 1 :])
break
for i in range(start):
if num[start - i] != "0":
if ans == -1 or int(num[: start - i]) + int(num[start - i :]) < ans:
ans = int(num[: start - i]) + int(num[start - i :])
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
ans = 10**100000 + 2
i = n // 2
j = n // 2 + 1
cp = 0
while i > 0:
if s[i] != "0":
cp += 1
ans = ans = min(ans, int(s[0:i]) + int(s[i:n]))
i -= 1
if cp == 3:
break
cp = 0
while j < n:
if s[j] != "0":
cp += 1
ans = ans = min(ans, int(s[0:j]) + int(s[j:n]))
j += 1
if cp == 3:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR 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())
m = input()
ans = 10**110000
ind = n // 2
while ind >= 0:
if m[ind] != "0":
break
ind -= 1
if ind > 0:
ans = min(ans, int(m[:ind]) + int(m[ind:]))
ind = n // 2 + 1
while ind < n:
if m[ind] != "0":
break
ind += 1
if ind < n:
ans = min(ans, int(m[:ind]) + int(m[ind:]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
v = int(s)
i = len(s) // 2
if len(s) % 2 == 0 and s[i] != "0":
v = int(s[0:i]) + int(s[i:])
elif len(s) % 2 == 1 and s[i] != "0" and s[i - 1] != "0" and s[i + 1] != "0":
v = int(s[0:i]) + int(s[i:])
v = min(v, int(s[0 : i + 1]) + int(s[i + 1 :]))
else:
while i > 0:
if s[i] != "0":
v = min(v, int(s[0:i]) + int(s[i:]))
if s[i] != "0" and s[i + 1] == "0":
break
i -= 1
i = len(s) // 2
while i < len(s):
if s[i] != "0":
v = min(v, int(s[0:i]) + int(s[i:]))
if s[i] != "0" and s[i - 1] == "0":
break
i += 1
print(v)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING 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.
|
le = int(input())
num = input()
data = [0] * 2
for i in range(le // 2 + 1, le):
if num[i] != "0":
data[1] = i
break
for i in range(le // 2, -1, -1):
if num[i] != "0":
data[0] = i
break
num = "0" + num
print(
min(
int(num[: data[0] + 1]) + int(num[data[0] + 1 :]),
int(num[: data[1] + 1]) + int(num[data[1] + 1 :]),
)
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR 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())
n = input()
result = int(n)
for k, i in ((1, len(n) // 2), (-1, (len(n) + 1) // 2)):
while 0 < i < len(n) and n[i] == "0":
i += k
if 0 < i < len(n):
result = min(result, int(n[:i]) + int(n[i:]))
print(result)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE NUMBER VAR FUNC_CALL VAR VAR VAR VAR STRING VAR VAR IF NUMBER 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.
|
n = int(input())
l = str(input())
value = int(l)
if n % 2 == 0:
i = int(n / 2)
while i < n and l[i] == "0":
i += 1
if i != n:
x = l[:i]
y = l[i:]
if x == "":
x = 0
if y == "":
y = 0
value = min(value, int(x) + int(y))
i = int(n / 2) - 1
while l[i] == "0" and i > 0:
i -= 1
x = l[:i]
y = l[i:]
if x == "":
x = 0
if y == "":
y = 0
value = min(value, int(x) + int(y))
else:
i = int(n / 2) + 1
while i < n and l[i] == "0":
i += 1
if i != n:
x = l[:i]
y = l[i:]
if x == "":
x = 0
if y == "":
y = 0
value = min(value, int(x) + int(y))
i = int(n / 2)
while l[i] == "0" and i > 0:
i -= 1
x = l[:i]
y = l[i:]
if x == "":
x = 0
if y == "":
y = 0
value = min(value, int(x) + int(y))
print(value)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER 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.
|
k = int(input())
s = input()
k2 = k / 2
Y = k + 1
if k - s.count("0") > 1:
for i in range(k):
if s[i] != "0":
z = abs(i - k2)
if z < Y:
Y = z
elif z == Y:
kk1 = int(s[int(Y + k2) :])
kk3 = int(s[: int(Y + k2)])
kk2 = int(s[int(-Y + k2) :])
kk4 = int(s[: int(-Y + k2)])
print(min(kk1 + kk3, kk2 + kk4))
if Y != 0:
if Y != k + 1:
if s[int(-Y + k2)] == "0":
kk1 = int(s[int(Y + k2) :])
kk3 = int(s[: int(Y + k2)])
print(kk1 + kk3)
elif s[int(Y + k2)] == "0":
kk2 = int(s[int(-Y + k2) :])
kk4 = int(s[: int(-Y + k2)])
print(kk2 + kk4)
else:
print(s)
else:
print(int(s[int(k2) :]) + int(s[: int(k2)]))
else:
print(s)
|
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 BIN_OP VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
c = int(n)
i = l // 2
while i > 0 and n[i] == "0":
i -= 1
if i <= 0:
break
if i > 0:
t = int(n[0:i]) + int(n[i:])
c = min(c, t)
i = (l + 1) // 2
while i < l and n[i] == "0":
i += 1
if i < l:
t = int(n[0:i]) + int(n[i:l])
c = min(c, t)
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def findright(ind):
mid1 = float("+inf")
for i in range(ind + 1, nils):
if nil[i] != nil[i - 1] + 1:
mid1 = nil[i - 1] + 1
break
if nil[-1] < n - 1:
mid1 = min(mid1, nil[-1] + 1)
return mid1
def findleft(ind):
mid2 = 0
if ind == 0:
mid2 = nil[ind] - 1
else:
for i in range(ind - 1, -1, -1):
if nil[i] != nil[i + 1] - 1:
mid2 = nil[i + 1] - 1
break
if mid2 == 0 and nil[0] > 1:
mid2 = nil[0] - 1
return mid2
n = int(input())
s = input()
nil = []
for i in range(n):
if s[i] == "0":
nil.append(i)
nils = len(nil)
mid = n // 2
S1 = S2 = S3 = float("+inf")
if mid in nil:
ind = nil.index(mid)
r = findright(ind)
l = findleft(ind)
if r != float("+inf"):
S1 = int(s[r:]) + int(s[:r])
if l != 0:
S1 = min(S1, int(s[:l]) + int(s[l:]))
else:
S1 = int(s[:mid]) + int(s[mid:])
if mid > 1:
if mid - 1 in nil:
ind = nil.index(mid - 1)
r = findright(ind)
l = findleft(ind)
if r != float("+inf"):
S2 = int(s[r:]) + int(s[:r])
if l != 0:
S2 = min(S2, int(s[:l]) + int(s[l:]))
else:
S2 = int(s[: mid - 1]) + int(s[mid - 1 :])
if mid + 1 < n:
if mid + 1 in nil:
ind = nil.index(mid + 1)
r = findright(ind)
l = findleft(ind)
if r != float("+inf"):
S3 = int(s[r:]) + int(s[:r])
if l != 0:
S3 = min(S3, int(s[:l]) + int(s[l:]))
else:
S3 = int(s[: mid + 1]) + int(s[mid + 1 :])
print(min(S1, S2, S3))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
var = []
z = int(s[0])
n = len(s)
for i in range(1, n):
if s[i] != "0":
var.append((i, n - i, int(s[i])))
for i in range(0, len(var)):
if var[i][0] > var[i][1]:
break
z = i
arr = []
for j in range(max(i - 1, 0), min(i + 1, len(var))):
arr.append(int(s[: var[j][0]]) + int(s[var[j][0] :]))
print(min(arr))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
m = input()
index = 0
index_right = -1
if m[len(m) // 2] == "0":
for i in range(len(m) // 2, -1, -1):
if m[i] != "0":
index = i
break
for i in range(len(m) // 2, len(m)):
if m[i] != "0":
index_right = i
break
if index_right == -1:
right = m[index:]
left = m[:index]
print(int(left) + int(right))
elif index == 0:
left1 = m[:index_right]
right1 = m[index_right:]
print(int(left1) + int(right1))
else:
left1 = m[:index_right]
right1 = m[index_right:]
left2 = m[:index]
right2 = m[index:]
print(min(int(left1) + int(right1), int(right2) + int(left2)))
else:
print(
min(
int(m[0 : len(m) // 2 + 1]) + int(m[len(m) // 2 + 1 :]),
int(m[0 : len(m) // 2]) + int(m[len(m) // 2 :]),
int(m[0 : len(m) // 2 - 1]) + int(m[len(m) // 2 - 1 :]),
)
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR 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.
|
def get_sum(string, d):
s1 = s[:d]
s2 = s[d:]
if s1 == "" or s2 == "" or s2[0] == "0":
return int(string)
return int(s1) + int(s2)
def solve(string):
if len(string) == 2:
return int(s[0]) + int(s[1])
x = len(string) // 2
x1 = x
while x < len(string) and string[x] == "0":
x += 1
while x1 > 0 and string[x1] == "0":
x1 -= 1
s1 = get_sum(string, x)
s2 = get_sum(string, x1)
s3 = get_sum(string, x - 1)
s4 = get_sum(string, x + 1)
return min(s1, s2, s3, s4)
input()
s = input()
print(str(solve(s)))
|
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR STRING VAR NUMBER STRING RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
line = input()
if l % 2 == 0:
index = l // 2
m = float("inf")
while index < l - 1 and line[index] == "0":
index += 1
if line[index] != "0":
f = int(line[0:index])
s = int(line[index:])
m = min(m, f + s)
index = l // 2 + 1
while index >= 1 and line[index] == "0":
index -= 1
if line[index] != "0":
f = int(line[0:index])
s = int(line[index:])
m = min(m, f + s)
print(m)
else:
index = l // 2 + 1
m = float("inf")
while index < l - 1 and line[index] == "0":
index += 1
if line[index] != "0":
f = int(line[0:index])
s = int(line[index:])
m = min(m, f + s)
index = l // 2 + 1
while index >= 1 and line[index] == "0":
index -= 1
if line[index] != "0":
f = int(line[0:index])
s = int(line[index:])
m = min(m, f + s)
index = l // 2
q = float("inf")
while index < l - 1 and line[index] == "0":
index += 1
if line[index] != "0":
f = int(line[0:index])
s = int(line[index:])
q = min(q, f + s)
index = l // 2 + 1
while index >= 1 and line[index] == "0":
index -= 1
if line[index] != "0":
f = int(line[0:index])
s = int(line[index:])
q = min(q, f + s)
print(min(q, m))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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()
poss = []
for i in range(1, n):
if s[i] != "0":
poss.append((abs(i - (n - i)), i))
poss = sorted(poss)
def build(n, s, idx):
a = int(s[0 : idx[1]])
b = int(s[idx[1] :])
return a + b
v1 = build(n, s, poss[0])
if len(poss) > 1:
v2 = build(n, s, poss[1])
print(min(v1, v2))
else:
print(v1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = int(input())
s = str(n)
x = l // 2
if s[x] != "0" and s[x + 1] != "0":
a = int(s[:x])
b = int(s[x:])
c = int(s[: x + 1])
d = int(s[x + 1 :])
if a + b < c + d:
print(a + b)
else:
print(c + d)
elif s[x] != "0":
a = int(s[:x])
b = int(s[x:])
print(a + b)
elif s[x + 1] != "0":
c = int(s[: x + 1])
d = int(s[x + 1 :])
print(c + d)
else:
left = -1
right = -1
for i in range(x, -1, -1):
if s[i] != "0":
left = i
break
for i in range(x + 1, l):
if s[i] != "0":
right = i
break
lefta, leftb, righta, rightb, ans = 0, 0, 0, 0, 0
if right != -1:
righta = int(s[:right])
rightb = int(s[right:])
ans = righta + rightb
if left > 0:
lefta = int(s[:left])
leftb = int(s[left:])
ans = min(lefta + leftb, righta + rightb)
if righta + rightb == 0:
ans = lefta + leftb
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 BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER 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.
|
def solve(x, str):
i = (x + 1) // 2
j = i - 1
while i < x and str[i] == "0":
i += 1
while j > 0 and str[j] == "0":
j -= 1
res = min(
int(str[:i]) + int(str[i:] if i != x else 10**100000),
int(str[:j] if j != 0 else 10**100000) + int(str[j:]),
)
return res
def main():
x = int(input())
st = input()
print(solve(x, st))
main()
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER NUMBER FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
j = l // 2
i = j + 1
while j > 0 and s[j] == "0":
j -= 1
while i < l and s[i] == "0":
i += 1
print(
min(
int(s[0 if i >= l else i :]) + int(s[:i]),
int(s[j:]) + int(s[: l if j == 0 else j]),
)
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER 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 = int(s)
if l == 2:
print(int(s[0]) + int(s[1]))
else:
for i in range(l // 2, l):
if s[i] != "0":
m = min(int(s[i:]) + int(s[:i]), m)
break
for i in range(l // 2 + 1, 0, -1):
if s[i] != "0":
m = min(int(s[i:]) + int(s[:i]), m)
break
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
if n[l // 2] != "0" and n[l // 2 - 1] != "0":
print(
min(
int(n[: l // 2 + 1]) + int(n[l // 2 + 1 :]),
int(n[: l // 2]) + int(n[l // 2 :]),
)
)
else:
i = l // 2
while n[i] == "0":
i -= 1
if i != 0:
a = int(n[:i]) + int(n[i:])
else:
a = int(n)
i = l // 2
while i < l and n[i] == "0":
i += 1
if i != l:
b = int(n[:i]) + int(n[i:])
else:
b = int(n)
print(min(a, b))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 digits2num(digit_list):
n = len(digit_list) - 1
ans = 0
for i in range(len(digit_list)):
ans += digit_list[i] * 10**n
n -= 1
return ans
def magic(numList):
s = map(str, numList)
s = "".join(s)
s = int(s)
return s
def split_number(digits, n):
if n % 2 == 0:
mid = n // 2
if digits[mid] != 0:
return magic(digits[0:mid]) + magic(digits[mid:n])
else:
i = 1
while digits[mid - i] == 0 and digits[mid + i] == 0:
i += 1
if digits[mid - i] != 0 and digits[mid + i] == 0:
return magic(digits[0 : mid - i]) + magic(digits[mid - i : n])
if digits[mid + i] != 0 and digits[mid - i] == 0:
return magic(digits[0 : mid + i]) + magic(digits[mid + i : n])
if digits[mid - i] != 0 and digits[mid + i] != 0:
sum1 = magic(digits[0 : mid - i]) + magic(digits[mid - i : n])
sum2 = magic(digits[0 : mid + i]) + magic(digits[mid + i : n])
return min(sum1, sum2)
else:
mid = (n - 1) // 2
if digits[mid] != 0:
if digits[mid + 1] == 0:
return magic(digits[0:mid]) + magic(digits[mid:n])
else:
sum1 = magic(digits[0:mid]) + magic(digits[mid:n])
sum2 = magic(digits[0 : mid + 1]) + magic(digits[mid + 1 : n])
return min(sum1, sum2)
else:
i = 1
while digits[mid - i] == 0 and digits[mid + i] == 0:
i += 1
if digits[mid + i] != 0:
return magic(digits[0 : mid + i]) + magic(digits[mid + i : n])
elif digits[mid + i + 1] == 0:
return magic(digits[0 : mid - i]) + magic(digits[mid - i : n])
else:
sum1 = magic(digits[0 : mid - i]) + magic(digits[mid - i : n])
sum2 = magic(digits[0 : mid + i + 1]) + magic(digits[mid + i + 1 : n])
return min(sum1, sum2)
n = int(input())
digits = [int(x) for x in list(input())]
print(split_number(digits, n))
|
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP 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 RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN 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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP 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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL 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())
numstr = input()
mid = len(numstr) // 2
mn = int(numstr) * 10
zright = mid
while zright < len(numstr) and numstr[zright] == "0":
zright += 1
zleft = mid
while zleft > 0 and numstr[zleft] == "0":
zleft -= 1
todo = {i for i in range(zleft - 5, zleft + 5)}
for i in range(zright - 5, zright + 5):
todo.add(i)
for i in todo:
if i < 1 or i >= len(numstr):
continue
second = numstr[i:]
if second[0] == "0":
continue
mn = min(mn, int(numstr[:i]) + int(second))
print(mn)
|
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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
A = input()
answer = float("inf")
check = True
m = int(n / 2)
j = int(n / 2)
if n % 2 != 0:
m = m + 1
while check:
a = A[:m]
b = A[m:]
c = A[:j]
d = A[j:]
if (a[0] == "0" or b[0] == "0") and (c[0] == "0" or d[0] == "0"):
m += 1
j -= 1
continue
if a[0] == "0" or b[0] == "0":
c = int(c)
d = int(d)
answer = min(answer, c + d)
check = False
elif c[0] == "0" or d[0] == "0":
a = int(a)
b = int(b)
answer = min(answer, a + b)
check = False
else:
a = int(a)
b = int(b)
c = int(c)
d = int(d)
answer = min(answer, min(a + b, c + d))
check = False
print(answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR 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.
|
a1 = int(input())
s = input()
min1 = pow(10, 1000000)
l1 = a1 // 2
l2 = (a1 - 1) // 2
for i in range(l1, len(s)):
if s[i] == "0":
continue
else:
s1 = s[0:i]
s2 = s[i : len(s)]
if len(s1) > 0 and len(s2) > 0:
if s1[0] != "0" and s2[0] != "0":
c = int(s1) + int(s2)
if c < min1:
min1 = c
break
for i in range(l2, -1, -1):
if s[i + 1] == "0":
continue
else:
s1 = s[0 : i + 1]
s2 = s[i + 1 : len(s)]
if len(s1) > 0 and len(s2) > 0:
if s1[0] != "0" and s2[0] != "0":
c = int(s1) + int(s2)
if c < min1:
min1 = c
break
print(min1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR 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.
|
l = int(input())
n = input()
mid = l // 2
if l % 2 != 0:
i = 0
while n[i] == n[l // 2 + i]:
i += 1
if n[i] < n[l // 2 + i]:
mid += 1
m1 = m2 = mid
while m1 < l and n[m1] == "0":
m1 += 1
while m2 > 0 and n[m2] == "0":
m2 -= 1
out = int(n)
if m1 != l:
out = min(out, int(n[:m1]) + int(n[m1:]))
if m2 != 0:
out = min(out, int(n[:m2]) + int(n[m2:]))
print(out)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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()
i = l // 2 + 1
while i < l and n[i] == "0":
i += 1
if i == l:
ans = int(n)
else:
ans = int(n[:i]) + int(n[i:])
i = l // 2
while i >= 0 and n[i] == "0":
i -= 1
if not (l <= 3 and i == 0):
ans = min(ans, int(n[:i]) + int(n[i:]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER 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()
if s[n // 2] == "0":
i = n // 2
while i >= 0 and s[i] == "0":
i -= 1
if i < 1:
z1 = -1
else:
l1 = int(s[:i])
r1 = int(s[i:])
z1 = l1 + r1
j = n // 2
while j < n and s[j] == "0":
j += 1
if j == n:
z2 = -1
else:
l2 = int(s[:j])
r2 = int(s[j:])
z2 = l2 + r2
if z1 == -1:
print(z2)
elif z2 == -1:
print(z1)
else:
print(min(z1, z2))
elif n % 2 == 0:
print(int(s[: n // 2]) + int(s[n // 2 :]))
else:
print(
min(
int(s[: n // 2]) + int(s[n // 2 :]),
int(s[: n // 2 + 1]) + int(s[1 + n // 2 :]),
)
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP 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 IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP 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.
|
n = int(input())
s = input()
len1 = n // 2
len2 = (n + 1) // 2
S = 10**100000
def calc(d):
nonlocal S
h = d
while h < n and s[h] == "0":
h += 1
if h < n:
S = min(S, int(s[h:]) + int(s[:h]))
h = d
while 0 <= h and s[h] == "0":
h -= 1
if 0 < h:
S = min(S, int(s[h:]) + int(s[:h]))
calc(len1)
calc(len2)
print(S)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP 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 NUMBER VAR VAR VAR STRING VAR NUMBER IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL 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()
pos = []
bestdiff = 100000000
for i in range(l - 1):
if n[i + 1] != "0":
pos.append(i)
bestdiff = min(bestdiff, max(i + 1, l - i - 1))
ans = []
for i in pos:
if max(i + 1, l - i - 1) == bestdiff:
ans.append(int(n[: i + 1]) + int(n[i + 1 :]))
print(min(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER 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 FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def main():
n = int(input())
s = input()
ans = int(s)
half = len(s) // 2
if len(s) % 2 == 0:
for i in range(0, half):
if s[half + i] == "0" and s[half - i] == "0":
continue
else:
if s[half + i] != "0":
ans = min(ans, int(s[: half + i]) + int(s[half + i :]))
if s[half - i] != "0":
ans = min(ans, int(s[: half - i]) + int(s[half - i :]))
break
else:
for i in range(0, half):
if s[half + 1 + i] == "0" and s[half - i] == "0":
continue
else:
if s[half + 1 + i] != "0":
ans = min(ans, int(s[: half + 1 + i]) + int(s[half + 1 + i :]))
if s[half - i] != "0":
ans = min(ans, int(s[: half - i]) + int(s[half - i :]))
break
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR VAR STRING IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR 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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
a = int(input())
b = input()
d = a // 2
p = d
if a & 1:
d = d + 1
while d < a:
if b[d] is "0":
d = d + 1
else:
break
while p > 0:
if b[p] is "0":
p = p - 1
else:
break
if d == a:
ans = int(b[0:d])
else:
ans = int(b[0:d]) + int(b[d:a])
if p == 0:
ans1 = int(b)
else:
ans1 = int(b[0:p]) + int(b[p:a])
print(min(ans, ans1))
|
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 ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR 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.
|
MAX = int("9" * 100001)
N = int(input())
S = str(input())
a = N // 2
b = N - a
while True:
M1 = None
if S[a] != "0":
A1 = S[0:a]
B1 = S[a:]
M1 = int(A1) + int(B1)
M2 = None
if S[b] != "0":
A2 = S[0:b]
B2 = S[b:]
M2 = int(A2) + int(B2)
if M1 != None and M2 != None:
print(min(M1, M2))
exit(0)
elif M1 != None:
print(M1)
exit(0)
elif M2 != None:
print(M2)
exit(0)
a -= 1
b += 1
|
ASSIGN VAR FUNC_CALL VAR BIN_OP STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE NUMBER ASSIGN VAR NONE IF VAR VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE IF VAR VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NONE VAR NONE EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
ar = list(sorted(range(1, n), key=lambda x: max(x, n - x)))
t = int(s)
rem = 4
for x in ar:
if s[x] != "0":
if rem == 0:
break
rem -= 1
t = min(t, int(s[:x]) + int(s[x:]))
print(t)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR STRING IF VAR NUMBER 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.
|
import sys
input = sys.stdin.readline
n = int(input())
s = input().strip()
p = 0
for i in range(n):
if s[i] == 0:
p += 1
else:
break
s = s[p:]
n = len(s)
m = n // 2
while m < n - 1 and s[m] == "0":
m += 1
if m == n // 2:
if n & 1:
a = int(s[m:]) + int(s[:m])
b = int(s[m + 1 :]) + int(s[: m + 1])
print(min(a, b))
elif m == 1:
print(int(s[0]) + int(s[1]))
else:
a = int(s[:m]) + int(s[m:])
b = int(s[: m + 1]) + int(s[m + 1 :])
c = int(s[: m - 1]) + int(s[m - 1 :])
print(min(a, b, c))
else:
if m == n - 1 and s[m] == "0":
a = int(s)
else:
a = int(s[:m]) + int(s[m:])
m = n // 2
while m > 0 and s[m] == "0":
m -= 1
if m == 0:
b = int(s)
else:
b = int(s[:m]) + int(s[m:])
print(min(a, b))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER IF 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 BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR 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 BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 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()
i = int(n / 2)
while i != 0:
a = i
b = n - a
total1, total2 = -1, -1
if s[a] != "0":
total1 = int(s[0:a]) + int(s[a:])
if s[b] != "0":
total2 = int(s[0:b]) + int(s[b:])
if total1 != -1 and total2 != -1:
print(min(total1, total2))
break
if total1 != -1:
print(total1)
break
if total2 != -1:
print(total2)
break
i -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR 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 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(s):
if s is None or s == "":
return 0
return int(s)
n = int(input())
s = input()
l = len(s)
m = l >> 1
pl, pr = m, m + 1
while pl >= 0 and s[pl] == "0":
pl -= 1
while pr < l and s[pr] == "0":
pr += 1
x = min(get(s[:pl]) + get(s[pl:]), get(s[:pr]) + get(s[pr:]))
print(x)
|
FUNC_DEF IF VAR NONE VAR STRING RETURN NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR 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 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.
|
from sys import stdin
[_, l] = stdin.readlines()
q = list()
l = l.strip()
for i in range(1, len(l)):
if l[i] != "0":
q.append((abs(2 * i - len(l)), i))
if len(q) > 3:
q.sort(key=lambda v: v[0])
q = q[:4]
print(min([(int(l[:i]) + int(l[i:])) for _, i in q]))
|
ASSIGN LIST VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
a = input()
l = (n - 1) // 2
r = n // 2
while a[l] == "0" and a[r] == "0":
l -= 1
r += 1
ans = -1
if a[l] != "0" and l > 0:
x = int(a[0:l])
y = int(a[l : len(a)])
if ans == -1 or ans > x + y:
ans = x + y
if a[r] != "0":
x = int(a[0:r])
y = int(a[r : len(a)])
if ans == -1 or ans > x + y:
ans = x + y
l -= 1
r += 1
if l > 0 and a[l] != "0":
x = int(a[0:l])
y = int(a[l : len(a)])
if ans == -1 or ans > x + y:
ans = x + y
if r < len(a) and a[r] != "0":
x = int(a[0:r])
y = int(a[r : len(a)])
if ans == -1 or ans > x + y:
ans = x + y
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP 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())
s = input()
ans = -1
mid = l // 2
for i in range(mid + 1, l):
s1 = s[:i]
s2 = s[i:]
if s1[0] == "0":
continue
if s2[0] == "0":
continue
if ans == -1:
ans = int(s1) + int(s2)
else:
ans = min(ans, int(s1) + int(s2))
break
for i in range(mid, 0, -1):
s1 = s[:i]
s2 = s[i:]
if s1[0] == "0":
continue
if s2[0] == "0":
continue
if ans == -1:
ans = int(s1) + int(s2)
else:
ans = min(ans, int(s1) + int(s2))
break
for i in range(mid - 1, 0, -1):
s1 = s[:i]
s2 = s[i:]
if s1[0] == "0":
continue
if s2[0] == "0":
continue
if ans == -1:
ans = int(s1) + int(s2)
else:
ans = min(ans, int(s1) + int(s2))
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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 = max(1, n // 2)
r = min(n - 1, n // 2 + 1)
ans = -1
cnt = 0
while l >= 0 or r < n:
if l > 0 and s[l] != "0":
cnt += 1
cur = int(s[:l]) + int(s[l:])
if ans == -1 or cur < ans:
ans = cur
if r <= n - 1 and s[r] != "0":
cur = int(s[:r]) + int(s[r:])
cnt += 1
if ans == -1 or cur < ans:
ans = cur
if ans != -1 and cnt > 5:
break
l -= 1
r += 1
if ans == -1:
print(int(s))
else:
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
x = input()
vpos = []
mpos = n + 1
for i in range(1, n):
if x[i] != "0":
if mpos > max(i, n - i):
mpos = max(i, n - i)
vpos = []
if mpos == max(i, n - i):
vpos.append(i)
def f(a, i):
return int(a[i:]) + int(a[:i])
if len(vpos) == 1:
print(f(x, vpos[0]))
else:
print(min(f(x, vpos[0]), f(x, vpos[1])))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER 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.
|
l = int(input())
n = input()
if l == 2:
print(int(n[0]) + int(n[1]))
exit()
m = l // 2
i = 1
while not int(n[m]) + int(n[m - i]) + int(n[m + i]):
i += 1
potentials = []
if n[: m - i] and n[m - i :] and not n[m - i :].startswith("0"):
potentials.append(int(n[: m - i]) + int(n[m - i :]))
if n[:m] and n[m:] and not n[m:].startswith("0"):
potentials.append(int(n[:m]) + int(n[m:]))
if n[: m + i] and n[m + i :] and not n[m + i :].startswith("0"):
potentials.append(int(n[: m + i]) + int(n[m + i :]))
print(min(potentials))
|
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 WHILE BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def trial(s, k):
n = int("0" + s[k:])
if not n:
return []
k = len(str(n))
return [int(s[:-k]) + int(s[-k:])]
def trial2(s, k):
r = "".join(reversed(s))
n = int("0" + r[k:])
if not n:
return []
k = len(str(n))
if k < 2:
return []
return [int(s[: k - 1]) + int(s[k - 1 :])]
n = int(input())
s = input().strip()
print(
min(
trial(s, n // 2)
+ trial(s, n // 2 + 1)
+ trial2(s, n // 2)
+ trial2(s, n // 2 + 1)
)
)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR VAR IF VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN LIST BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR VAR IF VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN LIST RETURN LIST BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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.
|
num = input()
num = input()
n = len(num)
def split_value(s, ind):
ans = int(s)
if s[ind + 1] == "0":
tmp = ind + 1
while ind >= 0:
if s[ind] == "0":
ind -= 1
else:
s1 = s[:ind]
s2 = s[ind:]
if s1 == "":
pass
else:
ans = min(ans, int(s1) + int(s2))
break
ind = tmp
while ind < len(s):
if s[ind] == "0":
ind += 1
else:
s1 = s[:ind]
s2 = s[ind:]
ans = min(ans, int(s1) + int(s2))
break
else:
s1 = s[: ind + 1]
s2 = s[ind + 1 :]
if s2 == "":
pass
else:
ans = min(ans, int(s1) + int(s2))
return ans
print(min(split_value(num, n // 2), split_value(num, n // 2 - 1)))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR 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.
|
def kotogula_zero(n):
ln = len(n)
if ln % 2 == 0:
s = n[ln // 2 : ln]
s1 = str(int(s))
rt1 = ln // 2 - len(s1)
if s1 == "0":
rt1 += 1
ss = n[0 : ln // 2][::-1]
ss1 = str(int(ss))
rt2 = ln // 2 - len(ss1)
if ss1 == "0":
rt2 += 1
return rt1, rt2
n = int(input())
s = input()
if n == 2:
print(int(s[0]) + int(s[1]))
exit(0)
if n % 2 == 0:
if s[n // 2] != "0":
print(int(s[0 : n // 2]) + int(s[n // 2 : n]))
exit(0)
else:
nex, prev = kotogula_zero(s)[0], kotogula_zero(s)[1]
kot = nex + prev
if n // 2 - prev == 1:
print(int(s[0] + "0" * kot) + int(s[-1]))
exit(0)
if n // 2 - nex == 0:
print(int(s[0 : n // 2 - prev - 1]) + int(s[n // 2 - prev - 1 : n]))
exit(0)
ab = int(s[0 : n // 2 + nex]) + int(s[n // 2 + nex : n])
ba = int(s[0 : n // 2 - prev - 1]) + int(s[n // 2 - prev - 1 : n])
if ab == int(s):
print(ba)
elif ba == int(s):
print(ab)
else:
print(min(ab, ba))
exit(0)
elif s[n // 2] != "0":
print(
min(
int(s[0 : n // 2 + 1]) + int(s[n // 2 + 1 : n]),
int(s[0 : n // 2]) + int(s[n // 2 : n]),
)
)
exit(0)
else:
ne, pr = kotogula_zero(s[0 : n // 2] + s[n // 2 + 1 : n])
kot = ne + pr + 1
if n // 2 - pr == 1:
print(int(s[0] + "0" * kot) + int(s[-1]))
exit(0)
if n // 2 - ne == 0:
y = int(s[0 : n // 2 - (pr + 1)]) + int(s[n // 2 - (pr + 1) : n])
print(y)
exit(0)
ne1 = 1 + ne
pr1 = 1 + pr
x = int(s[0 : n // 2 + ne1]) + int(s[n // 2 + ne1 : n])
y = int(s[0 : n // 2 - pr1]) + int(s[n // 2 - pr1 : n])
print(min(x, y))
exit(0)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL 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 VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR 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 VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def main():
n = int(input())
s = input().strip()
if n % 2 == 0:
if s[n // 2] != "0":
print(int(s[: n // 2]) + int(s[n // 2 :]))
else:
i = n // 2
while i > 0 and s[i] == "0":
i -= 1
if i != 0:
ans1 = int(s[:i]) + int(s[i:])
else:
ans1 = -1
i += 1
while i < n and s[i] == "0":
i += 1
if i != n:
ans2 = int(s[:i]) + int(s[i:])
else:
ans2 = -1
if ans1 == -1:
print(ans2)
elif ans2 == -1:
print(ans1)
else:
print(min(ans1, ans2))
elif s[n // 2] == "0" or s[n // 2 + 1] == "0":
if s[n // 2] == "0":
i = n // 2
while i > 0 and s[i] == "0":
i -= 1
if i != 0:
ans1 = int(s[:i]) + int(s[i:])
else:
ans1 = -1
i += 1
while i < n and s[i] == "0":
i += 1
if i != n:
ans2 = int(s[:i]) + int(s[i:])
else:
ans2 = -1
if ans1 == -1:
print(ans2)
elif ans2 == -1:
print(ans1)
else:
print(min(ans1, ans2))
else:
i = n // 2 + 1
while i > 0 and s[i] == "0":
i -= 1
if i != 0:
ans1 = int(s[:i]) + int(s[i:])
else:
ans1 = -1
i += 1
while i < n and s[i] == "0":
i += 1
if i != n:
ans2 = int(s[:i]) + int(s[i:])
else:
ans2 = -1
if ans1 == -1:
print(ans2)
elif ans2 == -1:
print(ans1)
else:
print(min(ans1, ans2))
else:
print(
min(
int(s[: n // 2]) + int(s[n // 2 :]),
int(s[: n // 2 + 1]) + int(s[n // 2 + 1 :]),
)
)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR 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 NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER 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 IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER 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 ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their 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 readint():
return int(input())
def readfloat():
return float(input())
def readarray(n, f=input):
return [f() for i in range(n)]
def readlinearray(f=int):
return list(map(f, input().split()))
def euclide(a, b):
if a < 0:
g, x, y = euclide(-a, b)
return g, -x, y
if b < 0:
g, x, y = euclide(a, -b)
return g, x, -y
if b == 0:
return a, 1, 0
g, x, y = euclide(b, a % b)
return g, y, x - a // b * y
def gen_primes(max):
primes = [1] * (max + 1)
for i in range(2, max + 1):
if primes[i]:
for j in range(i + i, max + 1, i):
primes[j] = 0
primes[0] = 0
return [x for x in range(max + 1) if primes[x]]
def is_prime(N):
if N % 2 == 0:
return N == 2
i = 3
while i * i <= N:
if N % i == 0:
return False
i += 2
return True
def answer():
return ""
def gcj():
l = readint()
s = input()
best = int(s)
for i in range(len(s) // 2, 0, -1):
if s[i] != "0":
best = min(best, int(s[:i]) + int(s[i:]))
break
for i in range(len(s) // 2 + 1, len(s)):
if s[i] != "0":
best = min(best, int(s[:i]) + int(s[i:]))
break
print(best)
gcj()
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER RETURN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF RETURN STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR 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 FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR 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 EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def ii():
return int(input())
n = ii()
s = input()
l = len(s)
max_sum = float("inf")
def min_sum(i):
global max_sum
max_sum1 = int(s[: i + 1])
max_sum2 = int(s[i + 1 :])
sum0 = max_sum1 + max_sum2
if sum0 < max_sum:
max_sum = sum0
cnt = 0
for i in range(l // 2, -1, -1):
if s[i + 1] == "0":
continue
min_sum(i)
cnt += 1
if cnt == 3:
break
cnt = 0
for i in range(l // 2 + 1, l - 1):
if s[i + 1] == "0":
continue
min_sum(i)
cnt += 1
if cnt == 3:
break
print(int(max_sum))
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = int(input())
t = str(n)
a = []
x = 1
mid = (l + 1) // 2
L = l
R = 0
LEN = l - 1
while LEN >= 0:
if t[LEN] != "0":
if x >= mid:
L = min(L, x)
if x < mid:
R = max(R, x)
x += 1
LEN -= 1
N = 100005
ans = 10**N
b = []
if L != l:
b.append(L)
if R != 0:
b.append(R)
for x in b:
deg = 10**x
cur = n % deg + n // deg
ans = min(cur, ans)
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 LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR 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 smallest(a, b):
if len(a) < len(b):
return a
elif len(b) < len(a):
return b
else:
i = 0
while i < len(a) and a[i] == b[i]:
i += 1
if i >= len(a):
return a
if a[i] < b[i]:
return a
elif a[i] > b[i]:
return b
def addingFunc(number1, number2):
n1 = len(number1)
n2 = len(number2)
greater = number2
smaller = number1
if n1 > n2:
greater = number1
smaller = number2
diff = abs(n1 - n2)
result = ""
c = 0
for i in range(len(smaller) - 1, -1, -1):
sumVal = str(int(greater[diff + i]) + int(smaller[i]) + c)
c = 0
if len(sumVal) > 1:
c = int(sumVal[0])
sumVal = sumVal[1]
result += sumVal
for i in range(diff - 1, -1, -1):
sumVal = str(int(greater[i]) + c)
c = 0
if len(sumVal) >= 2:
c = int(sumVal[0])
sumVal = sumVal[1]
result += sumVal
if c > 0:
result += str(c)
return result[::-1]
def main():
l = int(input())
string = input()
if l % 2 == 0:
part1 = string[0 : int(l // 2)]
part2 = string[int(l // 2) :]
l1 = 0
while int(l // 2) + l1 < len(string) and string[int(l // 2) + l1] == "0":
l1 += 1
l2 = 0
while int(l // 2) - l2 < len(string) and string[int(l // 2) - l2] == "0":
l2 += 1
small = min(l1 + 1, l2)
if small == l1 + 1:
small -= 1
part1 = string[: int(l // 2) + small]
part2 = string[int(l // 2) + small :]
else:
part1 = string[int(l // 2) - small :]
part2 = string[: int(l // 2) - small]
print(addingFunc(part1, part2))
else:
first = string[0 : int(l / 2) + 1]
second = string[int(l / 2) :]
cut1 = l // 2 + 1
cut2 = l // 2
l1 = 0
while int(cut1) + l1 < len(string) and string[int(cut1) + l1] == "0":
l1 += 1
l2 = 0
while int(cut1) - l2 >= 0 and string[int(cut1) - l2] == "0":
l2 += 1
small = min(l1, l2)
if small == l1:
c1part1 = string[: int(cut1) + small]
c1part2 = string[int(cut1) + small :]
else:
c1part1 = string[int(cut1) - small :]
c1part2 = string[: int(cut1) - small]
l1 = 0
while int(cut2) + l1 < len(string) and string[int(cut2) + l1] == "0":
l1 += 1
l2 = 0
while int(cut2) - l2 >= 0 and string[int(cut2) - l2] == "0":
l2 += 1
small = min(l1, l2)
if small == l1:
c2part1 = string[: int(cut2) + small]
c2part2 = string[int(cut2) + small :]
else:
c2part1 = string[int(cut2) - small :]
c2part2 = string[: int(cut2) - small]
print(smallest(addingFunc(c1part1, c1part2), addingFunc(c2part1, c2part2)))
main()
|
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def f(s):
if s == "":
return 0
else:
return int(s)
l = int(input())
s = input()
x = l // 2
y = x + 1
while 0 <= y + 1 < l and s[y + 1] == "0":
y -= 1
z = x - 1
while 0 <= z + 1 < l and s[z + 1] == "0":
z += 1
p = x
while 0 <= p + 1 < l and s[p + 1] == "0":
p -= 1
q = x
while 0 <= q + 1 < l and s[q + 1] == "0":
q += 1
print(
min(
f(s[: y + 1]) + f(s[y + 1 :]),
f(s[: z + 1]) + f(s[z + 1 :]),
f(s[: p + 1]) + f(s[p + 1 :]),
f(s[: q + 1]) + f(s[q + 1 :]),
)
)
|
FUNC_DEF IF VAR STRING RETURN NUMBER RETURN 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 BIN_OP VAR NUMBER WHILE NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR WHILE NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR WHILE NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
x = l // 2 - 1
res = int("9" * 100005)
while x < l - 1 and n[x + 1] == "0":
x += 1
if x != l - 1:
res = int(n[: x + 1]) + int(n[x + 1 :])
x = l // 2
while x < l - 1 and n[x + 1] == "0":
x -= 1
if x < l - 1:
res = min(res, int(n[: x + 1]) + int(n[x + 1 :]))
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 FUNC_CALL VAR BIN_OP STRING NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
d = input()
l = len(d)
half = int(l / 2)
minV = None
cnt = 0
for i in range(half, l):
if d[i] == "0":
continue
val = int(d[:i]) + int(d[i:])
cnt += 1
if minV is not None:
minV = min(minV, val)
else:
minV = val
if cnt >= 2:
break
cnt = 0
for i in range(half, 0, -1):
if d[i] == "0":
continue
val = int(d[:i]) + int(d[i:])
cnt += 1
if minV is not None:
minV = min(minV, val)
else:
minV = val
if cnt >= 2:
break
print(minV)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER 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 VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
sz = int(input())
n = input()
if sz % 2 == 0:
ptr = sz // 2
if n[ptr] != "0":
print(int(n[0:ptr]) + int(n[ptr:sz]))
exit(0)
while ptr >= 0 and n[ptr] == "0":
ptr -= 1
if ptr == 0:
ans = int(n)
else:
ans = int(n[0:ptr]) + int(n[ptr:sz])
ptr = sz // 2
while ptr < sz and n[ptr] == "0":
ptr += 1
if ptr == sz:
ans = min(ans, int(n))
else:
ans = min(ans, int(n[0:ptr]) + int(n[ptr:sz]))
print(ans)
else:
ptr = sz // 2
if n[ptr] != "0" and n[ptr + 1] != "0":
ans = min(
int(n[0:ptr]) + int(n[ptr:sz]), int(n[0 : ptr + 1]) + int(n[ptr + 1 : sz])
)
print(ans)
exit(0)
elif n[ptr] != "0":
ans = int(n[0:ptr]) + int(n[ptr:sz])
print(ans)
exit(0)
while ptr >= 0 and n[ptr] == "0":
ptr -= 1
if ptr == 0:
ans = int(n)
else:
ans = int(n[0:ptr]) + int(n[ptr:sz])
ptr = sz // 2
while ptr < sz and n[ptr] == "0":
ptr += 1
if ptr == sz:
ans = min(ans, int(n))
else:
ans = min(ans, int(n[0:ptr]) + int(n[ptr:sz]))
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 IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER 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 NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER 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 NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = input()
a = str(input())
idx = (len(a) + 1) // 2
l = idx - 1
r = idx
lt = 0
rt = 0
ans = -1
while l > 0:
if a[l] != "0":
if ans == -1:
ans = int(a[:l]) + int(a[l:])
ans = min(ans, int(a[:l]) + int(a[l:]))
lt = lt + 1
l = l - 1
if lt >= 2:
break
while r < len(a):
if a[r] != "0":
if ans == -1:
ans = int(a[:r]) + int(a[r:])
ans = min(ans, int(a[:r]) + int(a[r:]))
rt = rt + 1
r = r + 1
if rt >= 2:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 conv(x):
try:
return int(x)
except:
return 0
mid = n // 2
if s[mid] == "0":
rmid = mid
lmid = mid
while rmid < n and s[rmid] == "0":
rmid += 1
while lmid >= 0 and s[lmid] == "0":
lmid -= 1
if rmid == n:
rmid = lmid
print(min(conv(s[0:rmid]) + conv(s[rmid:]), conv(s[0:lmid]) + conv(s[lmid:])))
elif n % 2 == 0:
print(conv(s[0:mid]) + conv(s[mid:]))
else:
print(
min(conv(s[0 : mid + 1]) + conv(s[mid + 1 :]), conv(s[0:mid]) + conv(s[mid:]))
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN 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 IF BIN_OP VAR NUMBER 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 BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 = str(input())
mid = len(s) // 2
index1 = -1
ans1 = -1
for i in range(mid, len(s)):
if s[i] != "0":
index1 = i
break
if index1 != -1:
ans1 = int(s[:index1]) + int(s[index1:])
index2 = -1
ans2 = -1
for i in range(mid, -1, -1):
if s[i + 1] != "0":
index2 = i
break
if index2 != -1:
ans2 = int(s[: index2 + 1]) + int(s[index2 + 1 :])
if ans1 == -1:
print(ans2)
elif ans2 == -1:
print(ans1)
else:
print(min(ans2, ans1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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.
|
l = int(input())
s = input()
mi = int(s)
c = 0
for i in range(int(l / 2 + 1), l):
if s[i] == "0":
continue
n1 = int(s[:i])
n2 = int(s[i:])
mi = min(mi, n1 + n2)
c += 1
if c >= 2:
break
c = 0
for i in range(int(l / 2), 0, -1):
if s[i] == "0":
continue
n1 = int(s[:i])
n2 = int(s[i:])
mi = min(mi, n1 + n2)
break
c += 1
if c >= 2:
break
print(mi)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER 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 VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
mid = l // 2
mid1 = mid
mid2 = mid + 1
mi = int(n)
while mid1 >= 1:
if n[mid1] != "0":
mi = min(mi, int(n[0:mid1]) + int(n[mid1:]))
break
mid1 -= 1
while mid2 < l:
if n[mid2] != "0":
mi = min(mi, int(n[0:mid2]) + int(n[mid2:]))
break
mid2 += 1
print(mi)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR 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())
str = input()
ans = int(str)
flg = 0
for i in range(n // 2, 0, -1):
tmp1 = str[:i]
tmp2 = str[i:]
if tmp2[0] != "0":
ans = min(ans, int(tmp1) + int(tmp2))
tmp1 = str[: n - i]
tmp2 = str[n - i :]
if tmp2[0] != "0":
flg = 1
ans = min(ans, int(tmp1) + int(tmp2))
if flg == 1:
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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
mstr = str(input())
a = 0
b = int(mstr)
ans = 2 * b
i = 0
p = len(mstr)
l = len(mstr)
while mstr[p - 1] == "0":
p = p - 1
id = int(l / 2)
clr = id + 1
cll = id
while clr < l and mstr[clr] == "0":
clr = clr + 1
while cll > 0 and mstr[cll] == "0":
cll = cll - 1
if clr < l:
ans = min(ans, int(mstr[0:clr]) + int(mstr[clr:l]))
if cll > 0:
ans = min(ans, int(mstr[0:cll]) + int(mstr[cll:l]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
import sys
l = int(input())
n = int(input())
s = str(n)
length = len(s)
pos1 = max(length // 2 - 1, 1)
pos2 = min(length // 2 + 1, length - 1)
while pos1 > 1 and s[pos1] == "0":
pos1 -= 1
while pos2 < length - 1 and s[pos2] == "0":
pos2 += 1
sum = n
for p in range(pos1, pos2 + 1):
if s[p] != "0":
sum = min(sum, int(s[0:p]) + int(s[p:length]))
print(sum)
sys.exit(0)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL 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())
num = input()
ans = 10**100005
k = n // 2
for i in range(k, n):
if num[i] != "0":
ans = int(num[i:]) + int(num[:i])
break
for i in range(k + 1, 0, -1):
if k + 1 < n and num[i] != "0":
ans = min(ans, int(num[i:]) + int(num[:i]))
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR 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 VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
cands = []
for i in range(0, l - 1):
if n[i + 1] != "0":
cands.append((max(i + 1, l - i - 1), i))
cands.sort()
ans = -1
for i in range(0, min(4, len(cands))):
mx, idx = cands[i]
tmp = int(n[0 : idx + 1]) + int(n[idx + 1 : l])
if ans == -1 or tmp < ans:
ans = tmp
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
len = 1000000
ans = int(s)
for i in range(0, n - 1):
if s[i + 1] is not "0":
len = min(max(i + 1, n - i - 1), len)
for i in range(0, n - 1):
if max(i + 1, n - i - 1) == len and s[i + 1] is not "0":
ans = min(ans, int(s[0 : i + 1]) + int(s[i + 1 : n]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR 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 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())
string = input()
def right(i):
choice = -1
while i < l and string[i] == "0":
i += 1
if i < l:
choice = int(string[:i]) + int(string[i:])
return choice
def left(i):
choice = -1
while i > 0 and string[i] == "0":
i -= 1
if i > 0:
choice = int(string[:i]) + int(string[i:])
return choice
def minimum(c1, c2):
if c1 == -1:
return c2
elif c2 == -1:
return c1
return min(c1, c2)
if l & 1:
c1 = right(l // 2)
c2 = left(l // 2)
t1 = minimum(c1, c2)
c3 = right(l // 2 + 1)
c4 = left(l // 2 + 1)
t2 = minimum(c3, c4)
print(min(t1, t2))
else:
c1 = right(l // 2)
c2 = left(l // 2)
print(minimum(c1, c2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP 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.
|
n = int(input())
s = input()
ans = int(s)
mid = n // 2
while s[mid] == "0" and mid > 0:
mid -= 1
if mid != 0:
ans = min(ans, int(s[:mid]) + int(s[mid:]))
elif s[1] != "0":
ans = min(ans, int(s[0]) + int(s[1:]))
mid = n // 2 + 1
while s[mid] == "0" and mid < n - 1:
mid += 1
if s[mid] != "0":
ans = min(ans, int(s[:mid]) + int(s[mid:]))
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 WHILE VAR VAR STRING VAR NUMBER 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 NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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 de(n, le):
if n % 2 == 0:
if le % 2 == 0:
return le // 2 - 1 - n // 2
else:
return le // 2 - n // 2
elif le % 2 == 0:
return le // 2 + n // 2
else:
return (le + 1) // 2 + n // 2
l = int(input())
n = input()
ans = []
for i in range(l):
d = de(i, l)
if d == l - 1:
continue
if n[d + 1] != "0":
s1 = n[: d + 1]
s2 = n[d + 1 :]
if not s1 or not s2:
continue
ans.append(int(s1) + int(s2))
if len(ans) > 3:
break
print(min(ans))
|
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
if l % 2 == 0:
m1 = l // 2
m2 = m1
else:
m1 = l // 2
m2 = m1 + 1
while s[m1] == "0" and s[m2] == "0":
m1 = m1 - 1
m2 = m2 + 1
if s[m1] == "0":
res = int(s[:m2]) + int(s[m2:])
elif s[m2] == "0":
res = int(s[:m1]) + int(s[m1:])
else:
res = min(int(s[:m1]) + int(s[m1:]), int(s[:m2]) + int(s[m2:]))
print(res)
|
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 VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = int(input())
s = str(n)
mmax = 1e1000
def cal(x):
if x < 1 or x > l - 1:
return mmax
elif s[l - x] == "0":
return mmax
else:
base = pow(10, x)
tmp = n // base + n % base
return tmp
index = l // 2
mmin = min(min(cal(index), cal(l - index)), min(cal(index - 1), cal(n + 1 - index)))
while mmin == mmax:
index -= 1
mmin = min(cal(index), cal(l - index))
print(mmin)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR IF VAR BIN_OP VAR VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 = input()
str = input()
i = int(len(str) // 2)
Len = len(str)
ans = "1"
for ii in range(1, 100220):
ans += "0"
ans = int(ans)
iii = i
while iii < Len:
if str[iii] != "0":
break
iii += 1
jjj = i
while jjj >= 0:
if str[jjj] != "0":
break
jjj -= 1
if iii == jjj:
for j in range(jjj - 1, iii + 2):
id = j
if id <= 0 or Len - id <= 0:
continue
str1 = str[0:id]
str2 = str[id:Len]
if str1[0] == "0" or str2[0] == "0":
continue
num1 = int(str1)
num2 = int(str2)
ans = min(ans, num1 + num2)
else:
la = {iii + 1, jjj - 1, iii, jjj}
for j in la:
id = j
if id <= 0 or Len - id <= 0:
continue
str1 = str[0:id]
str2 = str[id:Len]
if str1[0] == "0" or str2[0] == "0":
continue
num1 = int(str1)
num2 = int(str2)
ans = min(ans, num1 + num2)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
mndig = l
consid = 10 ** (l + 1)
for i in range(1, l):
if n[i] != "0":
dig = max((i, l - i))
mndig = min((mndig, dig))
for i in range(1, l):
if n[i] != "0":
dig = max((i, l - i))
if dig <= mndig + 2:
consid = min((consid, int(n[:i]) + int(n[i:])))
print(consid)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP 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.
|
l = int(input())
n = str(input())
ret = int(n)
mod_l = l // 2
if l % 2:
for i in range(mod_l):
if int(n[mod_l + i + 1]):
temp = int(n[: mod_l + i + 1]) + int(n[mod_l + i + 1 :])
else:
temp = ret
if int(n[mod_l - i]):
temp = min(temp, int(n[: mod_l - i]) + int(n[mod_l - i :]))
if ret > temp:
ret = temp
break
else:
for i in range(mod_l):
if int(n[mod_l + i]):
temp = int(n[: mod_l + i]) + int(n[mod_l + i :])
else:
temp = ret
if int(n[mod_l - i]):
temp = min(temp, int(n[: mod_l - i]) + int(n[mod_l - i :]))
if ret > temp:
ret = temp
break
print(ret)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF 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 ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR 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()
d = n // 2
som = []
if n % 2 == 0:
if s[d] != "0":
som.append(int(s[0:d]) + int(s[d:]))
else:
mid = d
while mid < n:
if s[mid] != "0":
break
mid += 1
if mid < n - 1:
som.append(int(s[0:mid]) + int(s[mid:]))
mid = d
while mid >= 0:
if s[mid] != "0":
break
mid -= 1
if mid > 0:
som.append(int(s[0:mid]) + int(s[mid:]))
else:
if s[d + 1] != "0":
som.append(int(s[0 : d + 1]) + int(s[d + 1 :]))
if s[d] != "0":
som.append(int(s[0:d]) + int(s[d:]))
else:
mid = d
while mid < n:
if s[mid] != "0":
break
mid += 1
if mid < n - 1:
som.append(int(s[0:mid]) + int(s[mid:]))
mid = d
while mid >= 0:
if s[mid] != "0":
break
mid -= 1
if mid > 0:
som.append(int(s[0:mid]) + int(s[mid:]))
print(min(som))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER 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 VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their 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()
mn = l
for i, v in enumerate(a):
if v != "0" and mn > max(i, l - i):
mn = max(i, l - i)
b = []
for i in range(mn - 1, mn + 2):
if i > 0 and i < l:
if a[i] != "0":
b.append(int(a[:i]) + int(a[i:]))
j = l - i
if a[j] != "0":
b.append(int(a[:j]) + int(a[j:]))
print(min(b))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def summator(s, n):
num_1 = int(s[:n])
num_2 = int(s[n:])
return num_1 + num_2
def main_sum(s, n, a, b):
for i in range(n // 2):
if s[a - i] != "0" or s[b + i] != "0":
if s[a - i] == "0":
sum_1 = summator(s, b + i)
return sum_1
elif s[b + i] == "0":
sum_1 = summator(s, a - i)
return sum_1
else:
sum_1 = summator(s, b + i)
sum_2 = summator(s, a - i)
if sum_1 > sum_2:
return sum_2
else:
return sum_1
n = int(input())
number = input()
if n % 2 == 1:
ans = main_sum(number, n, n // 2, n // 2 + 1)
elif number[n // 2] != "0":
ans = summator(number, n // 2)
else:
ans = main_sum(number, n, n // 2 - 1, n // 2 + 1)
print(ans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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()
def cmp(x):
s1 = s[:x]
s2 = s[x:]
if s1[0] != "0" and s2[0] != "0":
return int(s1) + int(s2)
else:
return -1
m = -1
i = n // 2
h = 1
if n % 2 == 0:
m = cmp(i)
while m < 0:
m2 = cmp(i + h)
m1 = cmp(i - h)
if m1 > 0 and m2 > 0:
m = min(m1, m2)
elif m1 > 0:
m = m1
elif m2 > 0:
m = m2
h += 1
else:
m1 = cmp(i)
m2 = cmp(i + 1)
if m1 > 0 and m2 > 0:
m = min(m1, m2)
elif m1 > 0:
m = m1
elif m2 > 0:
m = m2
while m < 0:
m2 = cmp(i + h)
m1 = cmp(i - h)
if m1 > 0 and m2 > 0:
m = min(m1, m2)
elif m1 > 0:
m = m1
elif m2 > 0:
m = m2
h += 1
print(m)
|
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 NUMBER STRING VAR NUMBER STRING RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
r = int(s)
x, y = -1, -1
for i in range(0, l // 2):
if s[i + 1] != "0":
x = i
for i in range((l + 1) // 2, l):
if s[i] != "0":
y = i
break
if x != -1:
r = min(r, int(s[: x + 1]) + int(s[x + 1 :]))
if y != -1:
r = min(r, int(s[:y]) + int(s[y:]))
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER 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 VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
from sys import stdin, stdout
l = int(stdin.readline())
s = stdin.readline()
i = l // 2
j = (l + 1) // 2
while 1:
if i >= 0 and s[i] != "0" and s[j] != "0" and j < l:
x = int(s[:i]) + int(s[i:])
y = int(s[:j]) + int(s[j:])
if x < y:
stdout.write(str(x))
else:
stdout.write(str(y))
break
elif i >= 0 and s[i] != "0":
x = int(s[:i]) + int(s[i:])
stdout.write(str(x))
break
elif j < l and s[j] != "0":
x = int(s[:j]) + int(s[j:])
stdout.write(str(x))
break
i -= 1
j += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE NUMBER IF VAR NUMBER VAR VAR STRING VAR VAR STRING VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def findNotZero(s, half):
min = 10000000
pos = 0
for i in s:
if int(i) != 0:
if abs(pos - half) < abs(min - half):
min = pos
elif abs(pos - half) == abs(min - half):
first = ""
second = ""
for i in s[min:]:
first += str(i)
for i in s[:pos]:
second += str(i)
if first == "":
min = pos
elif int(first) > int(second):
min = pos
pos += 1
return min
def findResult(first, second):
pos = 0
first = first[::-1]
second = second[::-1]
res = ""
r = 0
for i in range(len(first)):
if i < len(second):
plus = first[i] + second[i] + r
else:
plus = first[i] + r
res += str(plus % 10)
r = plus // 10
pos += 1
if r != 0:
res += str(r)
print(res[::-1])
l = int(input())
s = [int(i) for i in input()]
half = len(s) // 2
if s[half] == 0:
half = findNotZero(s, half)
first = s[:half]
second = s[half:]
elif l % 2 == 1 and s[half] > s[0]:
first = s[: half + 1]
second = s[half + 1 :]
elif l % 2 == 1 and s[half] == s[0]:
first = ""
second = ""
for i in s[: half + 1]:
first += str(i)
for i in s[half:]:
second += str(i)
if first > second:
first = s[:half]
second = s[half:]
else:
first = s[: half + 1]
second = s[half + 1 :]
else:
first = s[:half]
second = s[half:]
if len(first) >= len(second):
findResult(first, second)
else:
findResult(second, first)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR 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 = int(s)
for i in range(n // 2 + 1, n):
if s[i] == "0":
continue
a = s[:i]
b = s[i:]
ans = min(ans, int(a) + int(b))
break
for i in range(n // 2, 0, -1):
if s[i] == "0":
continue
a = s[:i]
b = s[i:]
ans = min(ans, int(a) + int(b))
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN 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 ASSIGN 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.
|
a = int(input())
b = str(input())
ans = int(b)
counter = 1
for i in range(0, a // 2 + 1):
s = a // 2 - i
if s > 0:
if b[s] != "0":
ans = min(ans, int(b[:s]) + int(b[s:]))
if counter == 1:
counter = 2
s = a // 2 + i
if a - s > 0:
if b[s] != "0":
ans = min(ans, int(b[:s]) + int(b[s:]))
if counter == 1:
counter = 2
if counter >= 2:
counter = counter + 1
if counter == 4:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER 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()
if n % 2 == 0:
i = n // 2
j = i
while i < n - 1 and int(s[i]) == 0:
i = i + 1
if s[i] != "0":
x = int(s[:i])
y = int(s[i:])
Sum = x + y
else:
Sum = float("inf")
i = n // 2 + 1
j = i
while j > 0 and int(s[j]) == 0:
j -= 1
if s[j] != "0":
x = int(s[:j])
y = int(s[j:])
sum2 = x + y
else:
sum2 = float("inf")
print(min(Sum, sum2))
else:
i = n // 2 + 1
j = i
while i < n - 1 and int(s[i]) == 0:
i += 1
if s[i] != "0":
x = int(s[:i])
y = int(s[i:])
Sum = x + y
else:
Sum = float("inf")
while j > 0 and int(s[j]) == 0:
j -= 1
if s[j] != 0:
x = int(s[:j])
y = int(s[j:])
sum2 = x + y
else:
sum2 = float("inf")
Sum3 = min(Sum, sum2)
i = n // 2
j = i + 1
while i < n - 1 and int(s[i]) == 0:
i += 1
if s[i] != "0":
x = int(s[:i])
y = int(s[i:])
Sum = x + y
else:
Sum = float("inf")
while j > 0 and int(s[j]) == 0:
j -= 1
if s[j] != "0":
x = int(s[:j])
y = int(s[j:])
sum2 = x + y
else:
sum2 = float("inf")
Sum4 = min(Sum, sum2)
print(min(Sum3, Sum4))
|
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 VAR WHILE VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN 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 BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
a = int(input())
l = input()
aa = 0
pi = -1
for i in range(a // 2 + 1, a, 1):
if l[i] != "0":
pi = i
break
for i in range(a // 2, -1, -1):
if l[i] != "0":
aa = i
break
mi = 10**100000
if pi != -1:
mi = min(mi, int(l[:pi]) + int(l[pi:]))
if aa != 0:
mi = min(mi, int(l[:aa]) + int(l[aa:]))
print(mi)
|
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 NUMBER 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 NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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()
i = 0
mini = 789546312675
while i + 1 < n:
if i + 1 == n:
break
if s[i + 1] != "0":
len1 = i + 1
len2 = n - i - 1
mini = min(mini, max(len1, len2))
i += 1
ans = int(s)
i = 0
while i + 1 < n:
if i + 1 == n:
break
if s[i + 1] != "0":
len1 = i + 1
len2 = n - i - 1
if max(len1, len2) <= mini + 1:
str1 = ""
str2 = ""
for it in range(n):
if it < len1:
str1 += s[it]
else:
str2 += s[it]
ans = min(ans, int(str1) + int(str2))
i += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
mid = l // 2
def f(pos):
if pos == 0 or pos == l or n[pos] == "0":
return False
return True
arr = []
for i in range((l + 1) // 2):
pos = mid - i
if not (pos == 0 or pos == l or n[pos] == "0"):
arr.append(pos)
pos = mid + i
if not (pos == 0 or pos == l or n[pos] == "0"):
arr.append(pos)
if len(arr) > 2:
break
best_ans = int(n + "00")
for pos in arr:
ans = int(n[:pos]) + int(n[pos:])
best_ans = min(best_ans, ans)
print(best_ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
a = input()
ind = l // 2
prev = []
minn = 10**100
start = ""
for i in range(0, l // 2):
if a[i + 1] != "0":
if len(prev) == 0:
prev.append(i + 1)
elif abs(prev[-1] - l // 2) > abs(i + 1 - l // 2):
prev.pop()
prev.append(i + 1)
prev1 = []
for i in range(l // 2, l - 1):
if a[i + 1] != "0":
if len(prev1) == 0:
prev1.append(i + 1)
elif abs(prev1[-1] - l // 2) > abs(i + 1 - l // 2):
prev1.pop()
prev1.append(i + 1)
if len(prev) + len(prev1) == 2:
print(
min(
int(a[: prev[-1]]) + int(a[prev[-1] :]),
int(a[: prev1[-1]]) + int(a[prev1[-1] :]),
)
)
elif len(prev):
print(int(a[: prev[-1]]) + int(a[prev[-1] :]))
else:
print(int(a[: prev1[-1]]) + int(a[prev1[-1] :]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER 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.
|
l = int(input())
n = input()
mid = int(l / 2)
ans = int(n)
cnt = 0
for i in range(mid, 0, -1):
if n[i] == "0":
continue
cnt += 1
if cnt > 3:
break
a = int(n[0:i])
b = int(n[i:])
ans = min(ans, a + b)
cnt = 0
for i in range(mid + 1, l, 1):
if n[i] == "0":
continue
cnt += 1
if cnt > 3:
break
a = int(n[0:i])
b = int(n[i:])
ans = min(ans, a + b)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def solution(s):
k = 1
while s[k] == "0":
k += 1
maxsize = max(k, len(s) - k)
anscut = k
for i in range(k, len(s) - 1):
if s[i] != "0":
if (
max(i, len(s) - i) < maxsize
or max(i, len(s) - i) == maxsize
and int(s[:i]) + int(s[i:]) < int(s[:anscut]) + int(s[anscut:])
):
maxsize = max(i, len(s) - i)
anscut = i
return int(s[:anscut]) + int(s[anscut:])
N = int(input())
s = input()
print(solution(s))
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def get_min(a, b):
if len(a) < len(b):
return a
if len(a) > len(b):
return b
return min(a, b)
n = int(input())
s = input()
l, r = 0, n
for i in range(1, n):
if s[i] == "0":
continue
if i <= n // 2:
l = i
if i > n // 2 and r == n:
r = i
res1, res2 = "9" * (n + 1), "9" * (n + 1)
if l != 0:
res1 = str(int(s[:l]) + int(s[l:]))
if r != n:
res2 = str(int(s[:r]) + int(s[r:]))
print(get_min(res1, res2))
|
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL 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.
|
n = int(input())
l = input()
m = n // 2
flag = True
s = int(l)
for i in [-1, 0, 1]:
m1 = m
m1 += i
if len(l[m1:]) and len(l[:m1]):
if l[m1:][0] != "0":
s = min(s, int(l[:m1]) + int(l[m1:]))
for i in range(m, len(l)):
if l[i] != "0":
if len(l[i:]) and len(l[:i]):
s = min(s, int(l[:i]) + int(l[i:]))
flag = False
break
for i in range(m, -1, -1):
if l[i] != "0":
if len(l[i:]) and len(l[:i]):
s = min(s, int(l[:i]) + int(l[i:]))
flag = False
break
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING IF 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 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.
|
n = int(input())
s = input()
ans = int(s)
l = n // 2
while l > 0 and s[l] == "0":
l -= 1
if l > 0 and int(s[:l]) + int(s[l:]) < ans:
ans = int(s[:l]) + int(s[l:])
r = n // 2 + 1
while r < n and s[r] == "0":
r += 1
if r < n and int(s[:r]) + int(s[r:]) < ans:
ans = int(s[:r]) + int(s[r:])
if s[1] != "0" and int(s[0]) + int(s[1:]) < ans:
ans = int(s[0]) + int(s[1:])
if int(s[-1]) + int(s[:-1]) < ans:
ans = int(s[0]) + int(s[1:])
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 WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
k = int(s)
res = k
c = 0
for i in range(max(n // 2 - 2, 0), n):
if s[i] == "0":
continue
x = k // 10 ** (n - i)
y = k % 10 ** (n - i)
res = min(res, x + y)
c += 1
if c == 3:
break
c = 0
for i in range(min(n - 1, n // 2 + 2), 0, -1):
if s[i] == "0":
continue
x = k // 10 ** (n - i)
y = k % 10 ** (n - i)
res = min(res, x + y)
c += 1
if c == 3:
break
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
i = n // 2
while i < n and s[i] == "0":
i += 1
ans = -1
if i != n:
for newi in range(i - 3, i + 3):
if newi <= 0 or newi >= n or s[newi] == "0":
continue
if ans == -1:
ans = int(s[:newi]) + int(s[newi:])
else:
ans = min(ans, int(s[:newi]) + int(s[newi:]))
i = n // 2
while i >= 0 and s[i] == "0":
i -= 1
if i != 0:
for newi in range(i - 3, i + 3):
if newi <= 0 or newi >= n or s[newi] == "0":
continue
if ans == -1:
ans = int(s[:newi]) + int(s[newi:])
else:
ans = min(ans, int(s[:newi]) + int(s[newi:]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
right = (l // 2, l // 2 + 1)[l % 2]
left = (l // 2 - 1, l // 2)[l % 2]
while right < l and s[right] == "0":
right += 1
while s[left] == "0":
left -= 1
if left == 0:
left = right
if right == l:
right = left
ans = min(int(s[:right]) + int(s[right:]), int(s[:left]) + int(s[left:]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
sol_in = 0
best_len = 1000000.0
def zbr(ind):
a = n[:ind]
b = n[ind:]
return int(a) + int(b)
for i in range(1, l):
if n[i] == "0":
continue
if max(i, l - i) == best_len:
if zbr(i) < zbr(sol_in):
sol_in = i
if max(i, l - i) < best_len:
best_len = max(i, l - i)
sol_in = i
print(zbr(sol_in))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
from sys import stdin, stdout
n = int(stdin.readline())
num = stdin.readline()
lst = []
may = n
for i in range(1, n):
if num[i] != "0":
may = min(may, max(i, n - i))
for i in range(1, n):
if max(i, n - i) <= may:
if num[i] != "0":
lst.append(int(num[:i]) + int(num[i:]))
print(min(lst))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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()
i = n // 2
j = i
if a[i] == "0":
while i < n and a[i] == "0":
i += 1
if i == n:
i = 1
while a[j] == "0":
j -= 1
if j == 0:
j = i
a1 = int(a[:j])
a2 = int(a[j:])
ans1 = a1 + a2
a3 = int(a[:i])
a4 = int(a[i:])
ans2 = a3 + a4
print(min(ans1, ans2))
else:
a1 = int(a[:i])
a2 = int(a[i:])
ans1 = a1 + a2
a3 = int(a[: i + 1])
a4 = int(a[i + 1 :])
ans2 = a3 + a4
print(min(ans1, ans2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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())
m = n // 2
num = input()
ll = m + 1
rr = m
while ll < n and num[ll] == "0":
ll = ll + 1
while rr >= 0 and num[rr] == "0":
rr = rr - 1
if ll == n:
print(int(num[0:rr]) + int(num[rr:n]))
elif rr == 0:
print(int(num[0:ll]) + int(num[ll:n]))
else:
print(min(int(num[0:ll]) + int(num[ll:n]), int(num[0:rr]) + int(num[rr:n])))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.