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.
|
def main():
n = int(input())
num = int(input())
string = str(num)
if n % 2:
half = n // 2
if string[half] == "0":
i = half - 1
j = half + 1
while i >= 0 and string[i] == "0":
i -= 1
while j < n and string[j] == "0":
j += 1
print(
min(
int(max(string[:i], "0")) + int(max(string[i:], "0")),
int(max(string[:j], "0")) + int(max(string[j:], "0")),
)
)
else:
print(
min(
int(string[: n // 2 + 1]) + int(string[n // 2 + 1 :]),
int(string[: n // 2]) + int(string[n // 2 :]),
)
)
else:
half = n // 2
if string[half] == "0":
i = half - 1
j = half + 1
while i >= 0 and string[i] == "0":
i -= 1
while j < n and string[j] == "0":
j += 1
print(
min(
int(max(string[:i], "0")) + int(max(string[i:], "0")),
int(max(string[:j], "0")) + int(max(string[j:], "0")),
)
)
else:
print(int(string[: n // 2]) + int(string[n // 2 :]))
main()
|
FUNC_DEF 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 ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING 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 FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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 IF VAR VAR STRING 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 FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their 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()
mn = int(-1)
sum = int()
i = l // 2
while 0 < i and i < l:
if s[i] == "0":
i += 1
continue
a = int(s[:i])
b = int(s[i:])
sum = a + b
if mn == -1 or mn > sum:
mn = sum
else:
break
i += 1
i = l // 2
while 0 < i and i < l:
if s[i] == "0":
i -= 1
continue
a = int(s[:i])
b = int(s[i:])
sum = a + b
if mn == -1 or mn > sum:
mn = sum
else:
break
i -= 1
stdout.write(str(mn))
stdout.write("\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER VAR VAR VAR IF VAR VAR STRING 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 VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER VAR VAR VAR IF VAR VAR STRING 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 VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
len = int(input())
s = input()
ans = int(s)
for i in range((len - 1) // 2, 0, -1):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
break
for i in range(len // 2 + 1, len):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
break
if len % 2 == 0 and s[len // 2] != "0":
i = len // 2
ans = min(ans, int(s[:i]) + int(s[i:]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN 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.
|
k = int(input())
p = input()
if k % 2 == 0:
m = int(k // 2)
c = m
d = m
if int(p[m]) == 0:
while c <= k - 1:
if int(p[c]) != 0:
break
c += 1
while int(p[d]) == 0:
d -= 1
if c == k:
print(int(p[:d]) + int(p[d:]))
elif int(p[:c]) + int(p[c:]) > int(p[:d]) + int(p[d:]):
print(int(p[:d]) + int(p[d:]))
else:
print(int(p[:c]) + int(p[c:]))
else:
print(int(p[:m]) + int(p[m:]))
elif k % 2 != 0:
m = int(k // 2)
c = m
d = m
if k == 3:
print(11)
elif int(p[m]) == 0:
while c <= k - 1:
if int(p[c]) != 0:
break
c += 1
while int(p[d]) == 0:
d -= 1
if c == k:
print(int(p[:d]) + int(p[d:]))
elif int(p[:c]) + int(p[c:]) > int(p[:d]) + int(p[d:]):
print(int(p[:d]) + int(p[d:]))
else:
print(int(p[:c]) + int(p[c:]))
elif int(p[:m]) + int(p[m:]) > int(p[: m + 1]) + int(p[m + 1 :]):
print(int(p[: m + 1]) + int(p[m + 1 :]))
elif int(p[: m + 1]) + int(p[m + 1 :]) > int(p[:m]) + int(p[m:]):
print(int(p[:m]) + int(p[m:]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = str(input())
m = l // 2
while n[m] == "0":
m -= 1
x = int(n[0:m]) + int(n[m:l]) if m > 0 else int(n)
m = (l + 1) // 2
while m < l and n[m] == "0":
m += 1
if m < l:
x = min([x, int(n[0:m]) + int(n[m:l])])
print(x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR LIST 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 = int(input())
s = input()
res = int(s)
center = int(n / 2)
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
else:
while s[center] == "0" and center < n - 1:
center += 1
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
center = int(n / 2)
while s[center] == "0" and center > 1:
center -= 1
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
center = int(n / 2) + 1
if center < n:
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
else:
while s[center] == "0" and center < n - 1:
center += 1
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
center = int(n / 2) + 1
while s[center] == "0" and center > 1:
center -= 1
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
center = int(n / 2) - 1
if center > 0:
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
else:
while s[center] == "0" and center < n - 1:
center += 1
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
center = int(n / 2) - 1
while s[center] == "0" and center > 1:
center -= 1
q1 = s[:center]
q2 = s[center:]
if q2[0] != "0":
res = min(res, int(q1) + int(q2))
print(res)
|
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 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 WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR 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 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 NUMBER STRING 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 IF VAR VAR 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 WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR 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 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 NUMBER STRING 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 IF VAR 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 WHILE VAR VAR STRING VAR BIN_OP VAR NUMBER VAR 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 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 NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
import sys
n = int(sys.stdin.readline(40))
buff = sys.stdin.readline(n)
length = len(buff)
maxlen = 100005
ans = 1e1000
minList = []
for i in range(1, length):
if buff[i] != "0":
tmp = max(i, length - i) + 1
if tmp < maxlen:
minList = [i]
maxlen = tmp
elif tmp == maxlen:
minList.append(i)
maxlen = tmp
for i in minList:
A = int(buff[0:i])
B = int(buff[i:])
ans = min(ans, A + B)
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR 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 main():
length = int(input(""))
number = input("")
sol = half(number, length, 0, 0)
if sol != None:
print(int(sol[0]) + int(sol[1]))
def half(number, length, target, i):
if target == 0:
target = length // 2
fHalf = number[:target]
lHalf = number[target:]
while lHalf[0] == "0":
if i % 2 == 0:
target = target - i
else:
target = target + i
fHalf = number[:target]
lHalf = number[target:]
i = i + 1
sols = check(number, length, target, i)
if sols != None:
return sols
def check(number, length, target, i):
fHalf = number[:target]
lHalf = number[target:]
if number[target] >= fHalf[0] and length % 2 != 0 and target < length / 2:
j = 0
while fHalf[:j] == lHalf[:j]:
j = j + 1
if j * 2 >= length:
j = 0
return number[:target], number[target:]
break
if fHalf[:j] < lHalf[:j] and not (j > len(fHalf) or j > len(lHalf)):
half(number, length, target + 1, i)
break
if not (fHalf[:j] < lHalf[:j] and not (j > len(fHalf) or j > len(lHalf))):
return number[:target], number[target:]
elif (len(fHalf) == 1 or len(lHalf) == 1) and length > 4 and lHalf[-1] != "0":
if i % 2 == 0:
target = target - i
else:
target = target + i
fHalf2 = number[:target]
lHalf2 = number[target:]
if int(lHalf) + int(fHalf) > int(lHalf2) + int(fHalf2):
return fHalf2, lHalf2
else:
return fHalf, lHalf
else:
print(int(fHalf) + int(lHalf))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR NONE EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NONE RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER RETURN VAR VAR VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR RETURN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
num = input()
upperInd = n // 2
while num[upperInd : upperInd + 1] == "0":
upperInd -= 1
if upperInd == 0:
moveUp = int(num)
else:
moveUp = int(num[0:upperInd]) + int(num[upperInd:n])
lowerInd = n - n // 2
while lowerInd < n and num[lowerInd : lowerInd + 1] == "0":
lowerInd += 1
if lowerInd == n:
moveDown = int(num)
else:
moveDown = int(num[0:lowerInd]) + int(num[lowerInd:n])
print(int(min(moveUp, moveDown)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER 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 BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR 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 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()
print(
min(
int(s[:i]) + int(s[i:])
for i in sorted(
(i for i in range(1, n) if s[i] != "0"), key=lambda i: abs(i - n / 2)
)[:4]
)
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING FUNC_CALL VAR BIN_OP 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())
s = input()
ans = int(s)
for i in range(max(1, l // 2 - 2), l):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
if i >= l // 2 + 2:
break
for i in range(min(l - 1, l // 2 + 2), 0, -1):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
if i <= l // 2 - 2:
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 FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER 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 FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
m = input()
mi = 100001
for i in range(1, n):
if m[i] != "0":
mi = min(mi, max(i, n - i) - min(i, n - i))
res = -1
for i in range(1, n):
if m[i] != "0" and mi == max(i, n - i) - min(i, n - i):
if res == -1:
res = int(m[:i]) + int(m[i:])
else:
res = min(res, int(m[:i]) + int(m[i:]))
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = int(input())
min_sum = -1
n_str = str(n)
l = len(n_str) // 2
r = (len(n_str) + 1) // 2
while True:
if n_str[l] == "0" and n_str[r] == "0":
l -= 1
r += 1
continue
elif n_str[l] != "0" and n_str[r] != "0":
a = int(n_str[:l]) + int(n_str[l:])
b = int(n_str[:r]) + int(n_str[r:])
if a > b:
min_sum = b
else:
min_sum = a
break
elif n_str[l] == "0":
min_sum = int(n_str[:r]) + int(n_str[r:])
break
elif n_str[r] == "0":
min_sum = int(n_str[:l]) + int(n_str[l:])
break
print(min_sum)
|
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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
import sys
input = sys.stdin.readline
def calc(s, i):
p1 = s[:i]
p2 = s[i:]
return int(p1) + int(p2)
n = int(input())
s = input().strip()
if n == 2:
print(int(s[0]) + int(s[1]))
else:
res = int(s)
cnt = 0
for i in range((n - 1) // 2, 0, -1):
if s[i] != "0":
res = min(res, calc(s, i))
cnt += 1
if cnt >= 3:
break
for i in range((n - 1) // 2, n):
if s[i] != "0":
res = min(res, calc(s, i))
cnt += 1
if cnt >= 6:
break
print(res)
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL 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.
|
l = int(input())
num = input()
pos = l // 2
ans = -1
c = 0
while pos >= 0 and c < 2:
if pos + 1 < l and num[pos + 1] != "0":
if ans == -1:
ans = int(num[: pos + 1]) + int(num[pos + 1 :])
else:
ans = min(ans, int(num[: pos + 1]) + int(num[pos + 1 :]))
c += 1
pos -= 1
pos = l // 2 + 1
while pos < l - 1:
if num[pos + 1] != "0":
if ans == -1:
ans = int(num[: pos + 1]) + int(num[pos + 1 :])
else:
ans = min(ans, int(num[: pos + 1]) + int(num[pos + 1 :]))
break
pos += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
L = int(input())
S = input()
x1, x2 = int(L / 2), int((L + 1) / 2)
ans = 10**100005
while True:
flag = False
if S[x1] != "0":
flag = True
s1 = int(S[:x1])
s2 = int(S[x1:])
ans = min(ans, s1 + s2)
if S[x2] != "0":
flag = True
s1 = int(S[:x2])
s2 = int(S[x2:])
ans = min(ans, s1 + s2)
if flag:
print(ans)
break
x1 = x1 - 1
x2 = x2 + 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
res = 0
mn = int(n)
find = False
for i in range(l // 2, l):
if find and i > l // 2 + 3:
break
if n[i] != "0":
mn = min(mn, int(n[:i]) + int(n[i:]))
find = True
for i in range(l // 2, 0, -1):
if n[i] != "0":
mn = min(mn, int(n[:i]) + int(n[i:]))
break
print(mn)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR 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.
|
p = int(input())
n = int(input())
s = str(n)
c = n
k = p // 2
while k < p and s[k] == "0":
k += 1
if k < p:
y = int(s[k:])
x = int(s[:k])
c = min(c, x + y)
k = p // 2
k += 1
while k < p and s[k] == "0":
k += 1
if k < p:
y = int(s[k:])
x = int(s[:k])
c = min(c, x + y)
k = p // 2
k -= 1
while k > 0 and s[k] == "0":
k -= 1
if k > 0:
y = int(s[k:])
x = int(s[:k])
c = min(c, x + y)
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
x = input()
num = x[n // 2]
num2 = x[(n + 1) // 2]
ans = -1
if num == "0":
p = n // 2
k = p
while p >= 0 and x[p] == "0":
p -= 1
while k < n and x[k] == "0":
k += 1
n1 = 0
if len(x[:p]) > 0:
n1 = int(x[:p])
n2 = 0
if len(x[p:]) > 0:
n2 = int(x[p:])
nn1 = 0
if len(x[:k]) > 0:
nn1 = int(x[:k])
nn2 = 0
if len(x[k:]) > 0:
nn2 = int(x[k:])
best = min(n1 + n2, nn1 + nn2)
if ans == -1:
ans = best
else:
ans = min(ans, best)
else:
n1 = int(x[: n // 2])
n2 = int(x[n // 2 :])
best = n1 + n2
if ans == -1:
ans = best
else:
ans = min(ans, best)
if num2 == "0":
p = (n + 1) // 2
k = p
while p >= 0 and x[p] == "0":
p -= 1
while k < n and x[k] == "0":
k += 1
n1 = 0
if len(x[:p]) > 0:
n1 = int(x[:p])
n2 = 0
if len(x[p:]) > 0:
n2 = int(x[p:])
nn1 = 0
if len(x[:k]) > 0:
nn1 = int(x[:k])
nn2 = 0
if len(x[k:]) > 0:
nn2 = int(x[k:])
best = min(n1 + n2, nn1 + nn2)
if ans == -1:
ans = best
else:
ans = min(ans, best)
else:
n1 = int(x[: (n + 1) // 2])
n2 = int(x[(n + 1) // 2 :])
best = n1 + n2
if ans == -1:
ans = best
else:
ans = min(ans, best)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN 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 ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
res = int(s)
for i in range(-1, 2):
mid = n // 2 + i
while mid > 0 and mid < n and s[mid] == "0":
mid += -1 if i < 0 else 1
if mid > 0 and mid < n:
res = min(res, int(s[:mid]) + int(s[mid:]))
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER VAR VAR VAR VAR STRING VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
minx = int(n)
for i in {l // 2 - 1, l // 2, l // 2 + 1, l // 2 + 2}:
if n[:i] != "" and n[i:] != "" and n[i:][0] != "0":
minx = min(minx, int(n[:i]) + int(n[i:]))
for i in range(l // 2, -1, -1):
if n[:i] != "" and n[i:] != "":
if n[i] != "0":
minx = min(minx, int(n[:i]) + int(n[i:]))
break
for i in range(l // 2, l):
if n[:i] != "" and n[i:] != "":
if n[i] != "0":
minx = min(minx, int(n[:i]) + int(n[i:]))
break
print(minx)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING 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 BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR VAR STRING IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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()
index1 = l // 2
index2 = l // 2 if not l % 2 else l // 2 + 1
while True:
num1 = n[:index1]
num2 = n[index1:]
num3 = n[:index2]
num4 = n[index2:]
if num1[0] == "0" or num2[0] == "0":
if num3[0] == "0" or num4[0] == "0":
index1 -= 1
index2 += 1
else:
print(int(num3) + int(num4))
break
elif num3[0] == "0" or num4[0] == "0":
print(int(num1) + int(num2))
break
else:
print(min(int(num1) + int(num2), int(num3) + int(num4)))
break
|
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 BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
a = int(s)
s = list(s)
tt = 10 ** max(0, n // 2 - 2)
ans = a
for i in range(max(0, n // 2 - 2), min(n, n // 2 + 3)):
a1 = a // tt
a2 = a % tt
if a2 * 10 // tt > 0:
ans = min(ans, a1 + a2)
tt *= 10
s.reverse()
if ans == a:
i = n // 2
while i <= len(s) and s[i - 1] == "0":
i += 1
tt = 10**i
a1 = a // tt
a2 = a % tt
if a2 * 10 // tt > 0:
ans = min(ans, a1 + a2)
i = n // 2
while i > 0 and s[i - 1] == "0":
i -= 1
tt = 10**i
a1 = a // tt
a2 = a % tt
if a2 * 10 // tt > 0:
ans = min(ans, a1 + a2)
print(int(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN 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.
|
n = int(input())
s = input()
dt = [n + 10] * n
for i in range(n):
if i > 0 and s[i] != "0":
dt[i] = max([i, n - i])
mn = min(dt)
ans = int(s)
for i in range(n):
if dt[i] == mn:
ans = min([ans, int(s[:i]) + int(s[i:])])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST 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
def IO():
import sys
sys.stdout = open("output.txt", "w")
sys.stdin = open("input.txt", "r")
def main():
l = int(input())
n = str(input())
i = l // 2 - 1
lidx = -1
while i >= 0:
if n[i + 1] != "0":
lidx = i
break
i -= 1
ridx = l
i = l // 2 + 1
while i < l:
if n[i] != "0":
ridx = i
break
i += 1
option1 = int()
if lidx != -1:
option1 = int(n[0 : lidx + 1]) + int(n[lidx + 1 :])
option2 = int()
if ridx < l:
option2 = int(n[0:ridx]) + int(n[ridx:])
if l == 2:
print(int(n[0]) + int(n[1]))
elif lidx == -1:
print(option2)
elif ridx == l:
print(option1)
else:
print(min(option1, option2))
main()
|
IMPORT FUNC_DEF IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR 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.
|
def ab(n, p, q):
ans = -1
x = min(len(p), len(q))
if q[0] != "0":
ans = int(p) + int(q)
return ans
for i in range(x - 1):
if p[len(p) - i - 1] != "0" and q[i + 1] != "0":
return min(
int(p[: len(p) - 1 - i]) + int(p[len(p) - 1 - i :] + q),
int(p + q[: i + 1]) + int(q[i + 1 :]),
)
if p[len(p) - 1 - i] != "0":
return int(p[: len(p) - 1 - i]) + int(p[len(p) - 1 - i :] + q)
if q[i + 1] != "0":
return int(p + q[: i + 1]) + int(q[i + 1 :])
return int("9" * n)
t = 1
while t:
t -= 1
n = int(input())
s = input()
if n % 2 == 0:
p = s[: n // 2]
q = s[n // 2 :]
print(ab(n, p, q))
else:
p = s[: n // 2 + 1]
q = s[n // 2 + 1 :]
p1 = s[: n // 2]
q1 = s[n // 2 :]
print(min(ab(n, p, q), ab(n, p1, q1)))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER STRING RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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())
a = input()
check = []
for i in range(l - 1):
if a[i + 1] != "0":
check.append([abs(i + 1 - (l - i - 1)), i])
check.sort()
ans = -1
d = check[0][0]
for i in check:
if i[0] != d:
break
if ans == -1:
ans = int(a[: i[1] + 1]) + int(a[i[1] + 1 :])
else:
ans = min(ans, int(a[: i[1] + 1]) + int(a[i[1] + 1 :]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR 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 = str(input())
ans = int(s)
mid = n // 2
if n % 2 == 0:
mid -= 1
c = int(s[mid])
d = int(s[mid + 1])
if c != 0 or d != 0:
if c != 0 and mid > 0:
ans = int(s[:mid]) + int(s[mid:n])
if d != 0 and mid + 1 < n:
tmp = int(s[: mid + 1]) + int(s[mid + 1 : n])
ans = min(ans, tmp)
print(ans)
else:
posl = -2
posr = -2
for i in range(mid, 0, -1):
if int(s[i]) != 0:
posl = i
break
for i in range(mid, n):
if int(s[i]) != 0:
posr = i
break
if posl > 0:
ans = min(ans, int(s[:posl]) + int(s[posl:n]))
if posr > 0:
ans = min(ans, int(s[:posr]) + int(s[posr:n]))
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 BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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.
|
n = int(input())
s = str(input())
sLen = len(s)
def getSum(ss, cut):
num1 = int(ss[0 : int(cut)])
num2 = int(ss[cut:])
ans = num1 + num2
return ans
split1 = -1
for i in range(int(sLen / 2) - 1, -1, -1):
if s[i + 1] != "0":
split1 = i + 1
break
split2 = -1
for i in range(int(sLen / 2), sLen - 1, 1):
if s[i + 1] != "0":
split2 = i + 1
break
ans1, ans2, ans = 0, 0, 0
if split1 != -1:
ans1 = getSum(s, split1)
if split2 != -1:
ans2 = getSum(s, split2)
if split1 == -1 or split2 == -1:
if split1 == -1:
ans = ans2
elif split2 == -1:
ans = ans1
elif split1 != -1 and split2 != -1:
ans = min(ans1, ans2)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
import sys
inp = sys.stdin.readlines()
a = int(inp[0].strip())
numb = str(inp[1].strip())
mind = len(numb)
n = len(numb)
lst = []
for i in range(1, n):
if not numb[i] == "0":
mind = min(mind, max(i, n - i))
mind += 1
for i in range(1, n):
if max(i, n - i) <= mind:
if not numb[i] == "0":
lst.append(int(numb[:i]) + int(numb[i:]))
print(min(lst))
|
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST 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 VAR NUMBER 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.
|
length = int(input())
number = list(filter(lambda x: x, input()))
def make_num(tab):
if tab:
return int("".join(tab) if tab else "0") if tab[0] != "0" else float("inf")
return 0
def solve(number, n):
current_min = float("inf")
for index_right, digit_right in enumerate(number[n // 2 :]):
if digit_right != "0":
break
index_right += n // 2
for index_left, digit_left in enumerate(reversed(number[: n // 2])):
if digit_left != "0":
break
index_left = n // 2 - index_left - 1
current_min = min(
make_num(number[index_right:]) + make_num(number[:index_right]),
make_num(number[index_left:]) + make_num(number[:index_left]),
)
for i in range(1, 4):
try:
current_min = min(
make_num(number[index_right + i :])
+ make_num(number[: index_right + i]),
current_min,
)
except:
break
for i in range(1, 4):
try:
current_min = min(
make_num(number[index_right - i :])
+ make_num(number[: index_right - i]),
current_min,
)
except:
break
for i in range(1, 4):
try:
current_min = min(
make_num(number[index_left + i :]) + make_num(number[: index_left + i]),
current_min,
)
except:
break
for i in range(1, 4):
try:
current_min = min(
make_num(number[index_left - i :]) + make_num(number[: index_left - i]),
current_min,
)
except:
break
return current_min
print(solve(number, length))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF IF VAR RETURN VAR NUMBER STRING FUNC_CALL VAR VAR FUNC_CALL STRING VAR STRING FUNC_CALL VAR STRING RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER 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 FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN 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 = str(input())
def summ(l1, l2):
l1.reverse()
l2.reverse()
n_ = max(len(l1), len(l2))
k = n_ - min(len(l1), len(l2))
l1.extend(["0"] * k)
l2.extend(["0"] * k)
l3 = []
re = 0
for i in range(n_):
x = int(l1[i]) + int(l2[i]) + re
l3.append(x % 10)
re = x // 10
if re == 1:
l3.append(re)
l3.reverse()
kq = ""
for i in l3:
kq += str(i)
return kq
def com(r1, r2):
g = len(r1)
h = len(r2)
if g > h:
return r2
elif h > g:
return r1
else:
for i in range(g):
if int(r1[i]) == int(r2[i]):
continue
elif int(r1[i]) < int(r2[i]):
return r1
elif int(r1[i]) > int(r2[i]):
return r2
return r1
if n % 2 == 0:
l1 = list(l[: n // 2])
l2 = list(l[n // 2 :])
if l2[0] != "0":
print(summ(l1, l2))
elif l2[0] == "0":
inde = n // 2
q = "9" * n
kq_ = "9" * n
for i in range(n // 2, n):
if l[i] != "0":
inde = i
break
if inde != n // 2:
l2 = list(l[inde:])
l1 = list(l[:inde])
q = summ(l1, l2)
inde = n // 2
for i in range(n // 2, 0, -1):
if l[i] != "0":
inde = i
break
if inde != n // 2:
l2 = list(l[inde:])
l1 = list(l[:inde])
kq_ = summ(l1, l2)
print(com(q, kq_))
else:
l1 = list(l[: n // 2])
l2 = list(l[n // 2 :])
r1 = "9" * n
r2 = "9" * n
fi = "9" * n
se = "9" * n
if l2[0] != "0":
r1 = summ(l1, l2)
elif l2[0] == "0":
inde = n // 2
kq = "9" * n
kq_ = "9" * n
for i in range(n // 2, n):
if l[i] != "0":
inde = i
break
if inde != n // 2:
l2 = list(l[inde:])
l1 = list(l[:inde])
kq = summ(l1, l2)
inde = n // 2
for i in range(n // 2, 0, -1):
if l[i] != "0":
inde = i
break
if inde != n // 2:
l2 = list(l[inde:])
l1 = list(l[:inde])
kq_ = summ(l1, l2)
fi = com(kq, kq_)
v1 = list(l[: n // 2 + 1])
v2 = list(l[n // 2 + 1 :])
if v2[0] != "0":
r2 = summ(v1, v2)
elif v2[0] == "0":
inde = n // 2 + 1
kq = "9" * n
kq_ = "9" * n
for i in range(n // 2 + 1, n):
if l[i] != "0":
inde = i
break
if inde != n // 2 + 1:
v2 = list(l[inde:])
v1 = list(l[:inde])
kq = summ(v1, v2)
inde = n // 2 + 1
for i in range(n // 2 + 1, 0, -1):
if l[i] != "0":
inde = i
break
if inde != n // 2 + 1:
v2 = list(l[inde:])
v1 = list(l[:inde])
kq_ = summ(v1, v2)
se = com(kq, kq_)
r1 = com(r1, r2)
r1 = com(r1, fi)
r1 = com(r1, se)
print(r1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL 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 ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their 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()
foundr = 0
foundl = 0
ans = int(n_str)
for i in range(l // 2, l):
if n_str[i] == "0":
continue
elif foundr == 0:
foundr = 1
ans = int(n_str[0:i]) + int(n_str[i:l])
else:
ans = min(ans, int(n_str[0:i]) + int(n_str[i:l]))
foundr = foundr + 1
if foundr > 1:
break
for i in range(l // 2 - 1, 0, -1):
if n_str[i] == "0":
continue
else:
foundl += 1
ans = min(ans, int(n_str[0:i]) + int(n_str[i:l]))
if foundl > 1:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
h = (n + 1) // 2
ans = pow(10, 100000) + 9
for i in range(h, n):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
break
for i in range(h, 0, -1):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
break
h -= 1
if h > 0:
for i in range(h, n):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
break
for i in range(h, 0, -1):
if s[i] != "0":
ans = min(ans, int(s[:i]) + int(s[i:]))
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
L = int(input())
n = str(input())
def breakleft(n, split):
for i in range(split):
if n[split - i] != "0":
return int(n[: split - i]) + int(n[split - i :])
return int(n)
def breakright(n, split):
global L
for i in range(L - split):
if n[split + i] != "0":
return int(n[: split + i]) + int(n[split + i :])
return int(n)
half = L // 2
r = L % 2
if r == 0:
print(min(breakleft(n, half), breakright(n, half)))
else:
print(min(breakleft(n, half + 1), breakright(n, half)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
a = str(input())
if n == 1:
print(a)
else:
b, c = 0, 0
res = 1e1000
pos1 = int(n / 2)
pos2 = int(n / 2)
pos3 = int(n / 2) + 1
pos4 = int(n / 2) - 1
while pos1 < n and a[pos1] == "0":
pos1 += 1
while pos3 < n and a[pos3] == "0":
pos3 += 1
while pos2 >= 0 and a[pos2] == "0":
pos2 -= 1
while pos4 >= 0 and a[pos4] == "0":
pos4 -= 1
if pos1 < n and a[pos1] != "0":
b = int(a[0:pos1])
if pos1 != n - 1:
c = int(a[pos1:])
else:
c = int(a[n - 1])
res = min(res, b + c)
if pos2 >= 0 and a[pos2] != "0":
if pos2 != 0:
b = int(a[0:pos2])
else:
b = 0
c = int(a[pos2:])
res = min(res, b + c)
if pos3 < n and a[pos3] != "0":
b = int(a[0:pos3])
if pos3 != n - 1:
c = int(a[pos3:])
else:
c = int(a[n - 1])
res = min(res, b + c)
if pos4 >= 0 and a[pos4] != "0":
if pos4 != 0:
b = int(a[0:pos4])
else:
b = 0
c = int(a[pos4:])
res = min(res, b + c)
print(int(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER 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 VAR IF VAR NUMBER VAR VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER 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 VAR IF VAR NUMBER VAR VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER 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
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their 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()
resp = 10 ** (n + 1)
cnt = 0
for i in range(n // 2, 0, -1):
if s[i] != "0":
cnt += 1
s2 = s[:i]
s3 = s[i:]
if len(s2) >= 1 and len(s3) >= 1:
resp = min(resp, int(s2) + int(s3))
if cnt == 2:
break
cnt = 0
for i in range(n // 2, n):
if s[i] != "0":
cnt += 1
s2 = s[:i]
s3 = s[i:]
if len(s2) >= 1 and len(s3) >= 1:
resp = min(resp, int(s2) + int(s3))
if cnt == 2:
break
print(resp)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR 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 = eval(input())
s = input()
l = n // 2
Sum = 0
kk = 1
for i in range(l, n):
if s[i] != "0":
if Sum == 0:
Sum = int(s[i:]) + int(s[0:i])
else:
Sum = min(Sum, int(s[i:]) + int(s[0:i]))
kk += 1
if kk == 3:
break
kk = 1
for i in range(l, 0, -1):
if s[i] != "0":
if Sum == 0:
Sum = int(s[i:]) + int(s[0:i])
else:
Sum = min(Sum, int(s[i:]) + int(s[0:i]))
kk += 1
if kk == 3:
break
print(Sum)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR 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()
inn = -1
ind = -1
for i in range(n // 2, -1, -1):
if s[i] != "0":
inn = i
break
for i in range(n // 2 + 1, n):
if s[i] != "0":
ind = i
break
if inn > 0 and ind < n and inn != -1 and ind != -1:
ans = min(int(s[:inn]) + int(s[inn:]), int(s[:ind]) + int(s[ind:]))
elif inn == 0 or inn == -1:
ans = int(s[:ind]) + int(s[ind:])
elif ind == 0 or ind == -1:
ans = int(s[:inn]) + int(s[inn:])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER 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 IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
p = len(s) // 2
i, j = 1, 0
while p + i < len(s) and s[p + i] == "0":
i += 1
while p - j >= 0 and s[p - j] == "0":
j += 1
s1, s2 = s[: i + p], s[i + p :]
s3, s4 = s[: p - j], s[p - j :]
n1, n2 = 0, 0
if s1 != "":
n1 += int(s1)
if s2 != "":
n1 += int(s2)
if s3 != "":
n2 += int(s3)
if s4 != "":
n2 += int(s4)
if n1 < n2:
print(n1)
else:
print(n2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR STRING VAR FUNC_CALL VAR VAR IF VAR STRING VAR FUNC_CALL VAR VAR IF VAR STRING VAR FUNC_CALL VAR VAR IF VAR STRING VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
i1 = n // 2
i2 = i1 + 1
while i1 > 0 and s[i1] == "0":
i1 -= 1
while i2 < n and s[i2] == "0":
i2 += 1
if i1 == 0:
print(int(s[0:i2]) + int(s[i2:n]))
elif i2 == n:
print(int(s[0:i1]) + int(s[i1:n]))
else:
s1 = int(s[0:i1])
s2 = int(s[0:i2])
p1 = int(s[i1:n])
p2 = int(s[i2:n])
ans1 = s1 + p1
ans2 = s2 + p2
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 BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def sum(str, i):
if i <= 0 or i == len(str):
return int(str)
return int(str[0:i]) + int(str[i : len(str)])
def main():
n = int(input())
str = input()
middle = int(len(str) / 2)
result = int(str)
for i in range(middle, -1, -1):
if str[i] != "0":
result = min(result, sum(str, i))
break
for i in range(middle + 1, len(str)):
if str[i] != "0":
result = min(result, sum(str, i))
break
print(result)
main()
|
FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR 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 spt(s, lLen):
a = int(n[0:lLen])
b = int(n[lLen:])
return a + b
l = int(input())
n = input()
half = l // 2
for lLen in range(half, l):
temp1 = -1
temp2 = -1
if n[lLen] != "0":
temp1 = spt(n, lLen)
if n[l - lLen] != "0":
temp2 = spt(n, l - lLen)
if temp1 != -1 and temp2 != -1:
ans = min(temp1, temp2)
print(ans)
exit(0)
if temp1 != -1:
ans = temp1
print(ans)
exit(0)
if temp2 != -1:
ans = temp2
print(ans)
exit(0)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN 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.
|
def main():
n = int(input())
a = input()
b = []
for i in range(1, n):
if a[i] != "0":
b.append(max(i, n - i))
b.sort()
ans = float("inf")
for i in b[0 : min(len(b), 5)]:
if a[i] != "0":
ans = min(ans, int(a[0:i]) + int(a[i:n]))
if a[n - i] != "0":
ans = min(ans, int(a[0 : n - i]) + int(a[n - i : n]))
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR 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 IF VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR 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.
|
from sys import stdin
input = stdin.readline
n = int(input())
s = input()
m = 10**10**5
p = []
for i in range(n // 2, 0, -1):
if s[i] == "0":
continue
p.append(i)
break
for i in range(n // 2 + 1, n):
if s[i] == "0":
continue
p.append(i)
break
for i in p:
m = min(m, int(s[i:]) + int(s[:i]))
print(m)
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
m = int(input())
n = input()
l = m // 2
while l > 0 and n[l] == "0":
l -= 1
r = m // 2 + 1
while r < m and n[r] == "0":
r += 1
a = None
if r < m:
a = int(n[:r]) + int(n[r:])
b = None
if l > 0:
b = int(n[:l]) + int(n[l:])
if a and b:
print(min(a, b))
else:
print(a or b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NONE IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE IF VAR NUMBER 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 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.
|
l = int(input())
number = str(input())
def sum(a, b):
result = [0] * (max(len(a), len(b)) + 1)
memory = 0
for i in range(1, max(len(a), len(b)) + 1):
current = memory
memory = 0
if i <= len(a):
current += int(a[-i])
if i <= len(b):
current += int(b[-i])
if current >= 10:
current = current % 10
memory = 1
result[-i] = current
result[0] = memory
return result if result[0] != 0 else result[1:]
def a_less_then_b(a, b):
if len(a) < len(b):
return True
if len(a) > len(b):
return False
for i in range(0, len(a)):
if a[i] < b[i]:
return True
if a[i] > b[i]:
return False
return False
minimum = [9] * l
def update_minimum(middle_left, middle_right):
global minimum
while number[middle_left] == "0":
middle_left -= 1
while middle_right < l and number[middle_right] == "0":
middle_right += 1
current = sum(number[:middle_left], number[middle_left:])
if a_less_then_b(current, minimum):
minimum = current
if middle_right < l and number[middle_right] != "0":
current = sum(number[:middle_right], number[middle_right:])
if a_less_then_b(current, minimum):
minimum = current
if l % 2 == 0:
update_minimum(l // 2, l // 2)
else:
update_minimum(l // 2, l // 2)
update_minimum(l // 2 + 1, l // 2 + 1)
print("".join(map(str, minimum)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR RETURN VAR NUMBER NUMBER VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
mid = l // 2
endfrom0 = mid + 1
beginforend = mid - 1
def so(i):
if i == 0 or i == l:
return int(s)
return int(s[0:i]) + int(s[i:l])
while endfrom0 < l and s[endfrom0] == "0":
endfrom0 += 1
while beginforend > -1 and s[beginforend] == "0":
beginforend -= 1
if s[mid] != "0":
print(min(so(mid), so(endfrom0), so(beginforend)))
else:
print(min(so(endfrom0), so(beginforend)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
L = int(input())
S = input()
arr = []
for i in range(1, L):
if S[i] != "0":
arr.append((abs(L - i - i), i))
arr.sort()
if len(arr) >= 2:
print(
min(
[
int(S[: arr[0][1]]) + int(S[arr[0][1] :]),
int(S[: arr[1][1]]) + int(S[arr[1][1] :]),
]
)
)
else:
print(int(S[: arr[0][1]]) + int(S[arr[0][1] :]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR 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.
|
len = int(input())
str = input()
mid = len // 2 - 1
ans = int(str)
lcnt = 2
for i in range(mid, -1, -1):
if str[i + 1] != "0":
sum = int(str[: i + 1]) + int(str[i + 1 :])
if sum < ans:
ans = sum
lcnt -= 1
if lcnt == 0:
break
rcnt = 2
for i in range(mid + 1, len - 1):
if str[i + 1] != "0":
sum = int(str[: i + 1]) + int(str[i + 1 :])
if sum < ans:
ans = sum
rcnt -= 1
if rcnt == 0:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP 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 IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
ans = int("1" + "0" * 10**5)
if l % 2 == 0:
k = l // 2
left = k
while n[left] == "0":
left -= 1
right = k
while right < l and n[right] == "0":
right += 1
if left > 0:
ans = min(int(n[:left]) + int(n[left:]), ans)
if right < l:
ans = min(int(n[:right]) + int(n[right:]), ans)
else:
for k in range(l // 2, l // 2 + 2):
left = k
while n[left] == "0":
left -= 1
right = k
while right < l and n[right] == "0":
right += 1
if left > 0:
ans = min(int(n[:left]) + int(n[left:]), ans)
if right < l:
ans = min(int(n[:right]) + int(n[right:]), ans)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR 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 VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
result = int(s)
mid = int(n / 2)
count = 0
i = 0
while count < 4:
index = mid + i
if index > n - 1:
break
if s[index] != "0":
result = min(int(s[:index]) + int(s[index:]), result)
count += 1
index2 = mid - i
if index2 > 0 and s[index2] != "0":
result = min(int(s[:index2]) + int(s[index2:]), result)
count += 1
i += 1
print(result)
|
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 NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
S = input()
pos = l // 2
res = int(S)
if pos != 0 and S[pos] != "0":
left = int(S[0:pos:1])
right = int(S[pos:])
res = left + right
pos = l // 2 - 1
while pos > 0:
if S[pos] == "0":
pos -= 1
else:
left = int(S[0:pos:1])
right = int(S[pos:])
res = min(res, left + right)
break
pos = l // 2 + 1
while pos < l:
if S[pos] == "0":
pos += 1
else:
left = int(S[0:pos:1])
right = int(S[pos:])
res = min(left + right, res)
break
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER 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 VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
mv = n + 1
for i in range(1, n):
if s[i] != "0":
mv = min(mv, max(i, n - i))
lst = []
for i in range(1, n):
if s[i] != "0":
l = max(i, n - i)
if l == mv or l == mv + 1:
lst.append(i)
res = int(s)
for i in lst:
a = int(s[0:i])
b = int(s[i:n])
res = min(res, a + b)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
L = int(input())
n = input()
ans = int(n)
def v(k):
if k[0] == "0":
return False
return True
if L % 2 == 0:
for i in range(L // 2):
split1 = L // 2 + i
split2 = L // 2 - i
if n[split1] != "0":
sum1 = int(n[:split1]) + int(n[split1:])
if ans > sum1:
ans = sum1
if n[split2] != "0":
sum2 = int(n[:split2]) + int(n[split2:])
if ans > sum2:
ans = sum2
break
if n[split2] != "0":
sum2 = int(n[:split2]) + int(n[split2:])
if ans > sum2:
ans = sum2
break
else:
for i in range(L // 2):
split1 = L // 2 + i + 1
split2 = L // 2 - i
if n[split1] != "0":
sum1 = int(n[:split1]) + int(n[split1:])
if ans > sum1:
ans = sum1
split1 = -1
if n[split2] != "0":
sum2 = int(n[:split2]) + int(n[split2:])
if ans > sum2:
ans = sum2
break
if n[split2] != "0":
sum2 = int(n[:split2]) + int(n[split2:])
if ans > sum2:
ans = sum2
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER STRING RETURN NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
best = []
b = 10**9
for i in range(n - 1):
if s[i + 1] == "0":
continue
x = max(i + 1, n - i - 1)
if x < b:
best = []
b = x
if x == b:
best.append(i + 1)
res = int(s)
for i in best:
res = min(res, int(s[0:i]) + int(s[i:]))
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR 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())
y = input()
pek = int
def int(x):
if x == "":
return 0
else:
return pek(x)
if n % 2 == 0:
mul1 = 0
mul2 = n - 1
for i in range(n // 2, n):
mul1 = i
if y[i] == "0":
continue
else:
break
for i in range(n // 2 - 1, -1, -1):
mul2 = i
if y[i] == "0":
continue
else:
break
if mul1 == n - 1 and y[mul1] == "0":
mul1 = mul2
m = min(int(y[mul1:n]) + int(y[0:mul1]), int(y[mul2:n]) + int(y[0:mul2]))
print(m)
else:
res1 = res2 = 0
if True:
mul1 = 0
mul2 = n - 1
for i in range(n // 2, n):
mul1 = i
if y[i] == "0":
continue
else:
break
for i in range(n // 2 - 1, -1, -1):
mul2 = i
if y[i] == "0":
continue
else:
break
if mul1 == n - 1 and y[mul1] == "0":
mul1 = mul2
res1 = min(int(y[mul1:n]) + int(y[0:mul1]), int(y[mul2:n]) + int(y[0:mul2]))
if True:
mul1 = 0
mul2 = n - 1
for i in range(n // 2 + 1, n):
mul1 = i
if y[i] == "0":
continue
else:
break
for i in range(n // 2, -1, -1):
mul2 = i
if y[i] == "0":
continue
else:
break
if mul1 == n - 1 and y[mul1] == "0":
mul1 = mul2
res2 = min(int(y[mul1:n]) + int(y[0:mul1]), int(y[mul2:n]) + int(y[0:mul2]))
print(min(res1, res2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF IF VAR STRING RETURN NUMBER RETURN FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR IF NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
x = input()
ans = -1
options = []
for i in range(len(x)):
if x[i] != "0":
options.append(i)
start = len(options) - 1
for i in range(len(options)):
if options[i] >= n // 2:
start = i
break
for i in range(3):
for ind in [start + i, start - i]:
if ind < 0 or ind >= len(options):
continue
pos = options[ind]
if pos <= 0 or pos >= n:
continue
option = int(x[:pos]) + int(x[pos:])
if ans == -1 or option < ans:
ans = option
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n, s, a = int(input()), input(), 9**9
for i in range(1, n):
if s[i] != "0":
if max(a, n - a) > max(i, n - i):
a = i
elif max(a, n - a) == max(i, n - i) and int(s[:a]) + int(s[a:]) > int(
s[:i]
) + int(s[i:]):
a = i
print(int(s[:a]) + int(s[a:]))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
a = input()
m = int(a)
P = 10 ** (n // 2 + 1)
p = P
A = int(a[: n // 2])
B = int(a[n // 2 :])
kek = a[n // 2 :]
if kek[0] != "0":
m = min(m, A + B)
C = A
D = B
if n % 2 == 0:
P //= 10
k = 0
for i in range(n // 2, n):
if a[i] != "0":
m = min(int(a[:i]) + int(a[i:]), m)
break
for i in range(n // 2 - 1, 0, -1):
if a[i] != "0":
m = min(int(a[:i]) + int(a[i:]), m)
break
for i in range(n // 2, n - 1):
if k > 5:
break
A *= 10
A += int(a[i])
P //= 10
B %= P
k += 1
if A + B >= m:
break
if a[i + 1] == "0":
continue
m = A + B
A = C
B = D
P = p // 10
if n % 2 == 0:
P //= 10
for i in range(n // 2 - 1, 0, -1):
if k > 10:
break
P *= 10
B += int(a[i]) * P
A //= 10
k += 1
if A + B >= m:
break
if a[i] == "0":
continue
m = A + B
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR VAR STRING 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.
|
n, s = int(input()), input()
h = n // 2
ans = 3 * 10**100000
i = h
while i < n - 1 and s[i] == "0":
i += 1
if not (i >= n - 1 and s[i] == "0"):
ans = min(ans, int(s[:i]) + int(s[i:]))
i = min(h + 1, n - 1)
while i < n - 1 and s[i] == "0":
i += 1
if not (i >= n - 1 and s[i] == "0"):
ans = min(ans, int(s[:i]) + int(s[i:]))
i = h - 1
while s[i] == "0":
i -= 1
if i > 0:
ans = min(ans, int(s[:i]) + int(s[i:]))
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
l, r = n // 2, (n + 1) // 2
ans = int(s)
while True:
flag = False
if s[l] != "0":
flag = True
num1, num2 = int(s[:l]), int(s[l:])
ans = min(ans, num1 + num2)
if s[r] != "0":
flag = True
num1, num2 = int(s[:r]), int(s[r:])
ans = min(ans, num1 + num2)
if flag:
break
l = l - 1
r = r + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
pos = len(n) // 2
while pos < len(n) and n[pos] == "0":
pos += 1
ans = -1
if pos < len(n):
left = int(n[:pos])
right = int(n[pos:])
ans = left + right
pos += 1
if pos < len(n) and n[pos] != "0":
left = int(n[:pos])
right = int(n[pos:])
if ans == -1:
ans = left + right
else:
ans = min(ans, left + right)
pos = len(n) // 2 - 1
while 1 <= pos and n[pos] == "0":
pos -= 1
if 1 <= pos:
left = int(n[:pos])
right = int(n[pos:])
if ans == -1:
ans = left + right
else:
ans = min(ans, left + right)
pos -= 1
if 1 <= pos and n[pos] != "0":
left = int(n[:pos])
right = int(n[pos:])
if ans == -1:
ans = left + right
else:
ans = min(ans, left + right)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE NUMBER VAR VAR VAR STRING VAR NUMBER IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF NUMBER VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
mn = int(n)
mid1 = l // 2
mid2 = l // 2
while n[mid1] == "0":
mid1 -= 1
while mid2 < l and n[mid2] == "0":
mid2 += 1
if mid2 == l:
mid2 = l // 2
while n[mid2] == "0":
mid2 -= 1
for i in range(mid2 - 1, min(l - 1, mid2 + 1)):
if n[i + 1] == "0":
continue
a1 = int(n[: i + 1])
a2 = int(n[i + 1 :])
mn = min(mn, a1 + a2)
for i in range(max(0, mid1 - 1), min(l - 1, mid1 + 1)):
if n[i + 1] == "0":
continue
a1 = int(n[: i + 1])
a2 = int(n[i + 1 :])
mn = min(mn, a1 + a2)
print(mn)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
mi = int(n)
for A in range(l // 2 - 1, l // 2 + 2):
if A > 0 and A < len(n) and n[:A][0] != "0" and n[A:][0] != "0":
a = int(n[:A])
b = int(n[A:])
mi = min(mi, a + b)
if mi == int(n):
i = l // 2
while n[i] == "0":
i -= 1
if i > 0:
mi = min(mi, int(n[:i]) + int(n[i:]))
i = l // 2
while i < len(n) and n[i] == "0":
i += 1
if i < len(n) and n[i] != "0":
mi = min(mi, int(n[:i]) + int(n[i:]))
print(mi)
|
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 BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER STRING VAR 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 VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR 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.
|
def calc(s, pos):
A = s[0:pos]
B = s[pos:]
return int(A) + int(B)
n = input()
s = input()
n = int(n)
result = int(s)
n2 = n // 2
ctr = 0
for i in range(n // 2, 0, -1):
if s[i] == "0":
continue
ctr += 1
if ctr == 4:
break
val = calc(s, i)
result = min(result, val)
ctr = 0
for i in range(n // 2, n, 1):
if s[i] == "0":
continue
ctr += 1
if ctr == 4:
break
val = calc(s, i)
result = min(result, val)
print(result)
|
FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
lens = []
for i in range(len(s) - 1):
if s[i + 1] != "0":
lens.append((i, max(i + 1, len(s) - i - 1)))
mnlen = len(s) + 1
for a, b in lens:
mnlen = min(mnlen, b)
ans = int("9" * (len(s) + 1))
for a, b in lens:
if b == mnlen or b == mnlen + 1:
ans = min(ans, int(s[: a + 1]) + int(s[a + 1 :]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR 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.
|
l = int(input())
n = input()
def solve(ind, d):
global ans
if ind < 1 or ind >= l:
return
if n[ind] == "0":
if d == 0:
return
while 1 <= ind < l and n[ind] == "0":
ind += d
if ind < 1 or ind >= l:
return
if n[ind] == "0":
return
res = int(n[:ind]) + int(n[ind:])
try:
ans = min(ans, res)
except:
ans = res
inds = []
for i in range(l // 2 - 3, l // 2 + 3):
if 1 <= i < l:
inds += [i]
for i in range(len(inds)):
if i == 0:
d = -1
elif i == len(inds) - 1:
d = 1
else:
d = 0
solve(inds[i], d)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN IF VAR VAR STRING IF VAR NUMBER RETURN WHILE NUMBER VAR VAR VAR VAR STRING VAR VAR IF VAR NUMBER VAR VAR RETURN IF VAR VAR STRING RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR 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 = int(input())
s = input()
a = s
a = "0" + s
s = [int(i) for i in s]
s = [0] + s
p = []
if n % 2 is 0:
i = n // 2 + 1
while i <= n and s[i] == 0:
i += 1
if i <= n and s[i] != 0:
p.append(i)
i = n // 2
while i >= 1 and s[i] == 0:
i -= 1
if i > 1 and s[i] != 0:
p.append(i)
if n % 2 is 1:
i = n // 2 + 1 + 1
while i <= n and s[i] == 0:
i += 1
if i <= n and s[i] != 0:
p.append(i)
i = n // 2 + 1
while i >= 1 and s[i] == 0:
i -= 1
if i > 1 and s[i] != 0:
p.append(i)
ans = []
for i in p:
ans.append(int(a[1:i]) + int(a[i:]))
print(min(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR 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.
|
a = input()
a = int(a)
c = input()
b = str(c)
l = int(a / 2)
while l >= 1:
if b[l] == "0":
l -= 1
else:
break
r = int(a / 2) + 1
while r < a:
if b[r] == "0":
r += 1
else:
break
if l == 0:
print(str(int(b[:r]) + int(b[r:])))
elif r == a:
print(str(int(b[:l]) + int(b[l:])))
else:
print(str(min(int(b[:r]) + int(b[r:]), int(b[:l]) + int(b[l:]))))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
def main():
n = int(input())
x = input()
mid = n // 2
cnt = 0
ans = None
for i in range(mid + 2):
j = mid + i
if j < n and x[j] != "0":
val = int(x[:j]) + int(x[j:])
cnt += 1
if ans is None:
ans = val
else:
ans = min(ans, val)
j = mid - i
if j > 0 and x[j] != "0":
val = int(x[:j]) + int(x[j:])
cnt += 1
if ans is None:
ans = val
else:
ans = min(ans, val)
if cnt >= 7:
break
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
num = input()
def mn(a, b):
x = int(num[:a]) + int(num[a:])
y = int(num[:b]) + int(num[b:])
if x < y:
return a
else:
return b
if n & 1 > 0:
idx = mn(n // 2, n // 2 + 1)
else:
idx = n // 2
lead_a = 0
lead_b = 0
i = idx
while i < n:
if num[i] == "0":
lead_a += 1
if i == n - 1:
lead_a = n
else:
break
i += 1
i = idx - 1
while i >= 0:
if num[i] == "0":
lead_b += 1
else:
break
i -= 1
if lead_a == n:
idx -= lead_b + 1
elif idx - lead_b - 1 == 0:
idx += lead_a
else:
idx = mn(idx + lead_a, idx - lead_b - 1)
ans = int(num[:idx]) + int(num[idx:])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF 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 RETURN VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
n = int(input())
s = input()
a = ""
b = ""
ans = 0
l = r = n // 2
while r < len(s) and s[r] == "0":
r = r + 1
while l >= 0 and s[l] == "0":
l = l - 1
if l > 0:
a = s[:l]
b = s[l:]
if ans == 0:
ans = int(a) + int(b)
else:
ans = min(ans, int(a) + int(b))
if r < len(s):
a = s[:r]
b = s[r:]
if ans == 0:
ans = int(a) + int(b)
else:
ans = min(ans, int(a) + int(b))
if l == r and l + 1 != len(s):
a = s[: l + 1]
b = s[l + 1 :]
ans = min(ans, int(a) + int(b))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR 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 IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR 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 IF VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
import sys
def IO():
import sys
sys.stdout = open("output.txt", "w")
sys.stdin = open("input.txt", "r")
def main():
l = int(input())
n = input()
pos = [i for i in range(1, l) if n[i] != "0"]
pos = sorted(pos, key=lambda i: abs(i - l // 2))
ans = float("inf")
for i in range(min(6, len(pos))):
ans = min(ans, int(n[0 : pos[i]]) + int(n[pos[i] :]))
print(ans)
main()
|
IMPORT FUNC_DEF IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
n = input()
if l % 2 == 1:
m = l // 2
for i in range(0, l - m):
variants = []
if n[m - i] != "0":
variants.append(int(n[: m - i]) + int(n[m - i :]))
if n[m + i + 1] != "0":
variants.append(int(n[: m + i + 1]) + int(n[m + i + 1 :]))
if variants:
print(min(variants))
exit(0)
else:
m = l // 2
for i in range(0, l - m):
variants = []
if n[m - i] != "0":
variants.append(int(n[: m - i]) + int(n[m - i :]))
if n[m + i] != "0":
variants.append(int(n[: m + i]) + int(n[m + i :]))
if variants:
print(min(variants))
exit(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST IF VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST IF VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR 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.
|
l = int(input())
s = input()
ans = -1
cp = int((l - 1) / 2)
dist = 1
if l % 2 == 1:
dist = 0
while ans == -1:
if s[cp + 1] != "0":
ans = int(s[: cp + 1]) + int(s[cp + 1 :])
if cp + dist < l and s[cp + dist] != "0":
if ans == -1:
ans = int(s[: cp + dist]) + int(s[cp + dist :])
else:
ans = min(ans, int(s[: cp + dist]) + int(s[cp + dist :]))
cp -= 1
dist += 2
if ans != -1:
if cp >= 0 and s[cp + 1] != "0":
ans = min(ans, int(s[: cp + 1]) + int(s[cp + 1 :]))
if cp + dist < l and s[cp + dist] != "0":
ans = min(ans, int(s[: cp + dist]) + int(s[cp + dist :]))
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE 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 IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR 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
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
_ = input()
num = input()
ansi = len(num) - 1
leni = len(num)
for i in range(leni):
if i == 0 or num[i] == "0":
continue
ansi = min(ansi, max(i, leni - i))
l = []
for i in range(leni):
if i == 0 or num[i] == "0":
continue
tk = max(i, leni - i)
if tk == ansi or tk - 1 == ansi:
l.append(int(num[0:i]) + int(num[i:]))
mini = l[0]
for i in l:
if i < mini:
mini = i
print(mini)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.
Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.
-----Input-----
The first line contains a single integer $l$ ($2 \le l \le 100\,000$) — the length of the Dima's favorite number.
The second line contains the positive integer $n$ initially written on the strip: the Dima's favorite number.
The integer $n$ consists of exactly $l$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.
-----Output-----
Print a single integer — the smallest number Dima can obtain.
-----Examples-----
Input
7
1234567
Output
1801
Input
3
101
Output
11
-----Note-----
In the first example Dima can split the number $1234567$ into integers $1234$ and $567$. Their sum is $1801$.
In the second example Dima can split the number $101$ into integers $10$ and $1$. Their sum is $11$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
|
l = int(input())
s = input()
s = str(s)
if l % 2 == 0:
i = l // 2
i1 = i - 1
while i1 >= 0:
if s[i1] != "0":
break
i1 = i1 - 1
i2 = i
while i2 < l:
if s[i2] != "0":
break
i2 = i2 + 1
s1 = 0
s1 = str(s1)
i3 = 0
while i3 < i1:
s1 = s1 + s[i3]
i3 = i3 + 1
s2 = 0
s2 = str(s2)
i3 = i1
while i3 < l:
s2 = s2 + s[i3]
i3 = i3 + 1
i3 = 0
s3 = 0
s3 = str(s3)
while i3 < i2:
s3 = s3 + s[i3]
i3 = i3 + 1
s4 = 0
s4 = str(s4)
i3 = i2
while i3 < l:
s4 = s4 + s[i3]
i3 = i3 + 1
s11 = int(s1) + int(s2)
s22 = int(s3) + int(s4)
if s11 < s22:
print(s11)
else:
print(s22)
else:
i = l // 2
if s[i] == "0":
i1 = i - 1
while i1 >= 0:
if s[i1] != "0":
break
i1 = i1 - 1
i2 = i + 1
while i2 < l:
if s[i2] != "0":
break
i2 = i2 + 1
s1 = 0
s1 = str(s1)
i3 = 0
while i3 < i1:
s1 = s1 + s[i3]
i3 = i3 + 1
s2 = 0
s2 = str(s2)
i3 = i1
while i3 < l:
s2 = s2 + s[i3]
i3 = i3 + 1
i3 = 0
s3 = 0
s3 = str(s3)
while i3 < i2:
s3 = s3 + s[i3]
i3 = i3 + 1
s4 = 0
s4 = str(s4)
i3 = i2
while i3 < l:
s4 = s4 + s[i3]
i3 = i3 + 1
s11 = int(s1) + int(s2)
s22 = int(s3) + int(s4)
if s11 < s22:
print(s11)
else:
print(s22)
else:
i = l // 2
s11 = 0
s22 = 0
if s[i + 1] != "0":
i1 = 0
s1 = 0
s1 = str(s1)
while i1 <= i:
s1 = s1 + s[i1]
i1 = i1 + 1
i1 = i + 1
s2 = 0
s2 = str(s2)
while i1 < l:
s2 = s2 + s[i1]
i1 = i1 + 1
s11 = int(s2) + int(s1)
i1 = 0
s1 = 0
s1 = str(s1)
while i1 < i:
s1 = s1 + s[i1]
i1 = i1 + 1
i1 = i
s2 = 0
s2 = str(s2)
while i1 < l:
s2 = s2 + s[i1]
i1 = i1 + 1
s22 = int(s1) + int(s2)
if s[i + 1] != 0:
print(min(s11, s22))
else:
print(s22)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
a = []
m = []
for i in range(n):
x = float(input())
y = [int(x), x - int(x)]
if x < 0 and y[1] != 0:
y[0] -= 1
a.append(y)
sum = 0
for i in range(n):
sum += a[i][0]
for i in range(n):
if sum < 0 and a[i][1] != 0:
a[i][0] += 1
sum += 1
for i in range(n):
print(a[i][0])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
arr = [float(input()) for _ in range(n)]
arr2 = [int(arr[i]) for i in range(n)]
diff = sum(arr2)
if diff == 0:
for i in range(n):
print(arr2[i])
elif diff < 0:
cnt = 0
for i in range(n):
if arr[i] > 0:
if cnt < abs(diff):
if arr[i] != arr2[i]:
print(arr2[i] + 1)
cnt += 1
else:
print(arr2[i])
else:
print(arr2[i])
else:
print(arr2[i])
else:
cnt = 0
for i in range(n):
if arr[i] > 0:
print(arr2[i])
elif cnt < diff:
if arr[i] != arr2[i]:
print(arr2[i] - 1)
cnt += 1
else:
print(arr2[i])
else:
print(arr2[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
def main():
n = int(input())
i = 0
ng = []
tp = []
tg = 0
while i < n:
str = input()
x, y = [int(t) for t in str.split(".")]
if y != 0:
tg += x if x >= 0 and str[0] != "-" else x - 1
ng.append(x if x >= 0 and str[0] != "-" else x - 1)
else:
tg += x
ng.append(x)
tp.append(y)
i += 1
i = 0
while i < n:
if tp[i] == 0 or tg == 0:
print(ng[i])
else:
print(ng[i] + 1)
tg += 1
i += 1
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR NUMBER VAR NUMBER STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
ar = []
a = [(0) for i in range(0, n)]
for i in range(0, n):
ar.append(input())
s = 0
for i in range(0, n):
a[i] = float(ar[i]) // 1
s = s + a[i]
i = 0
if s < 0:
while s != 0:
if float(ar[i]) != float(ar[i]) // 1:
a[i] += 1
s += 1
i += 1
for i in range(0, n):
a[i] = int(a[i])
print(a[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
a = int(input())
ans = []
aller = [(0) for i in range(a)]
for i in range(a):
s = input()
if s[0] == "-":
s = s[1:]
t = s.find(".")
q = int(s[0:t])
m = s[t + 1 :]
ans.append(-q)
if len(m) == m.count("0"):
aller[i] = 0
continue
aller[i] = 1
else:
t = s.find(".")
q = int(s[0:t])
ans.append(q)
m = s[t + 1 :]
if len(m) == m.count("0"):
aller[i] = 0
continue
aller[i] = -1
alpha = sum(ans)
for i in range(len(ans)):
if alpha == 0:
continue
if aller[i] == 0:
continue
if aller[i] == 1 and alpha > 0:
ans[i] -= 1
alpha -= 1
continue
if aller[i] == -1 and alpha < 0:
ans[i] += 1
alpha += 1
continue
for i in range(len(ans)):
print(ans[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
pos = [0] * (10**5 + 1)
neg = [0] * (10**5 + 1)
positive = []
negitive = []
n = int(input())
for i in range(n):
a = float(input())
if a >= 0:
positive.append([int(a), i])
if a != int(a):
pos[len(positive) - 1] = 1
if a < 0:
negitive.append([int(a), i])
if a != int(a):
neg[len(negitive) - 1] = 1
a, b = 0, 0
for i in range(len(positive)):
a += positive[i][0]
for i in range(len(negitive)):
b += negitive[i][0]
it = 0
while a < abs(b):
if pos[it]:
positive[it][0] += 1
a += 1
it += 1
it = 0
while abs(b) < a:
if neg[it]:
negitive[it][0] -= 1
b -= 1
it += 1
stock = []
for i in range(len(negitive)):
stock.append(negitive[i])
for i in range(len(positive)):
stock.append(positive[i])
stock.sort(key=lambda x: x[1])
for i in range(n):
print(stock[i][0])
|
ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
from sys import stdin
input = stdin.readline
n = int(input())
a = []
for i in range(n):
b, c = map(str, input().split("."))
k = int(b)
if c == "0" * 5 + "\n":
a.append([k, k])
elif k > 0:
a.append([k, k + 1])
elif k < 0:
a.append([k - 1, k])
elif b[0] == "-":
a.append([-1, 0])
else:
a.append([0, 1])
ba = 0
for i in a:
ba += i[1]
ans = []
for i in a:
if ba > 0 and i[0] != i[1]:
ba -= 1
ans.append(i[0])
else:
ans.append(i[1])
for i in ans:
print(i)
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP STRING NUMBER STRING EXPR FUNC_CALL VAR LIST VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
i = 0
b = []
c = []
res = 0
while i < n:
s = input()
z = s.find(".")
if z == -1 or s[z : z + 6] == ".00000":
r = float(s)
r = int(r)
c.append(0)
else:
r = int(s[0:z])
if s[0:1] == "-":
c.append(-1)
else:
c.append(1)
b.append(r)
res = res + r
i = i + 1
i = 0
while res > 0:
while c[i] != -1:
i = i + 1
b[i] = b[i] - 1
i = i + 1
res = res - 1
i = 0
while res < 0:
while c[i] != 1:
i = i + 1
b[i] = b[i] + 1
i = i + 1
res = res + 1
i = 0
while i < n:
print(b[i])
i = i + 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
from sys import stdin, stdout
n = int(input())
negitives = []
positives = []
for i in range(2):
negitives.append([])
positives.append([])
sums = 0
answer = [0] * n
for i in range(n):
x = [float(x) for x in input().split()][0]
if x < 0:
if abs(int(x) - x) >= 10**-6:
negitives[1].append((i, x))
sums += int(x)
answer[i] = int(x)
else:
negitives[0].append((i, x))
sums += int(x)
answer[i] = int(x)
if x > 0:
if abs(int(x) - x) >= 10**-6:
positives[1].append((i, x))
sums += int(x)
answer[i] = int(x)
else:
positives[0].append((i, x))
sums += int(x)
answer[i] = int(x)
if sums > 0:
for i in range(sums):
answer[negitives[1][i][0]] -= 1
elif sums < 0:
for i in range(abs(sums)):
answer[positives[1][i][0]] += 1
for i in range(n):
print(answer[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
a = [(0) for i in range(n)]
_sum = 0
for i in range(n):
num = float(input())
a[i] = num
_sum += int(num)
i = 0
while _sum > 0 and i < n:
if abs(a[i] - int(a[i])) > 1e-05 and a[i] < 0:
a[i] -= 1
_sum -= 1
i += 1
i = 0
while _sum < 0 and i < n:
if abs(a[i] - int(a[i])) > 1e-05 and a[i] > 0:
a[i] += 1
_sum += 1
i += 1
for i in range(n):
print(int(a[i]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
a = []
d = 0
p = []
q = []
for i in range(n):
s = float(input())
if s < 0 and s % 1 != 0:
k = int(s // 1) + 1
a.append(k)
d += k
p.append(i)
elif s > 0 and s % 1 != 0:
k = int(s // 1)
a.append(k)
d += k
q.append(i)
else:
k = int(s // 1)
a.append(k)
d += k
if d > 0:
i = 0
while d > 0:
a[p[i]] -= 1
i += 1
d -= 1
elif d < 0:
i = 0
while d < 0:
a[q[i]] += 1
d += 1
i += 1
print(*a, sep="\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
a = []
n = int(input())
for _ in range(n):
a.append(float(input()))
ns = 0
ps = 0
for i in range(n):
if a[i] < 0:
ns += int(a[i])
else:
ps += int(a[i])
cha = ps + ns
if cha == 0:
for i in range(n):
print(int(a[i]))
elif cha < 0:
i = 0
while cha != 0 and i < n:
if a[i] - int(a[i]) != 0 and a[i] > 0:
a[i] = int(a[i]) + 1
cha += 1
i += 1
for i in range(n):
print(int(a[i]))
else:
i = 0
while cha != 0 and i < n:
if a[i] - int(a[i]) != 0 and a[i] < 0:
a[i] = int(a[i]) - 1
cha -= 1
i += 1
for i in range(n):
print(int(a[i]))
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
arr = []
brr = []
for i in range(n):
x = float(input())
if x < 0 and int(x) != x:
arr.append(int(x) - 1)
brr.append(x)
elif x > 0 and int(x) != x:
arr.append(int(x) + 1)
brr.append(x)
else:
arr.append(int(x))
brr.append(x)
s = sum(arr)
if s == 0:
print(*arr, sep="\n")
elif s > 0:
i = 0
while s != 0:
if arr[i] > 0 and abs(brr[i] - arr[i]) != 0:
arr[i] -= 1
s = sum(arr)
i += 1
print(*arr, sep="\n")
else:
i = 0
while s != 0:
if arr[i] < 0 and abs(brr[i] - arr[i]) != 0:
arr[i] += 1
s = sum(arr)
i += 1
print(*arr, sep="\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
d = []
p = 0
m = 0
for i in range(n):
s = float(input())
d.append(s)
if s > 0:
p = p + int(s)
else:
m = m + int(s)
a = p + m
s = d[::1]
s.sort()
if a == 0:
for i in d:
print(int(i))
elif a > 0:
for i in d:
if i >= 0:
print(int(i))
elif i == int(i):
print(int(i))
elif a > 0:
a = a - 1
print(int(i) - 1)
else:
print(int(i))
else:
for i in d:
if i < 0:
print(int(i))
elif i == int(i):
print(int(i))
elif a < 0:
a = a + 1
print(int(i) + 1)
else:
print(int(i))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
dig = []
dec = 0
z = 0
for _ in range(n):
x = float(input())
dec += round(x - int(x), 5)
dig.append([int(x), round(x - int(x), 5)])
c = round(dec)
f = -1 if c > 0 else 1
for i in range(n):
if c * (dig[i][0] + dig[i][1]) > 0 and c != 0 and dig[i][1] != 0:
dig[i][0] += -f
c += f
print(*[dig[i][0] for i in range(n)])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
from sys import stdin
def solve():
N = int(stdin.readline())
A = []
neg_0 = set()
pos_0 = set()
ignore = set()
for i in range(N):
x = float(stdin.readline())
if x == int(x):
ignore.add(i)
elif int(x) == 0:
if x >= 0:
pos_0.add(i)
else:
neg_0.add(i)
A.append(int(x))
S = sum(A)
if S > 0:
i = 0
while i < N and S > 0:
if i in ignore:
i += 1
continue
if A[i] == 0:
if i in neg_0:
A[i] -= 1
S -= 1
i += 1
continue
if A[i] > 0:
i += 1
continue
A[i] -= 1
i += 1
S -= 1
elif S < 0:
i = 0
while i < N and S < 0:
if i in ignore:
i += 1
continue
if A[i] == 0:
if i in pos_0:
A[i] += 1
S += 1
i += 1
continue
if A[i] < 0:
i += 1
continue
A[i] += 1
i += 1
S += 1
print("\n".join(map(str, A)))
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
a = [float(input()) for i in range(n)]
b = a.copy()
s = 0
for i in range(0, n):
b[i] = int(b[i])
s = s + b[i]
if s != 0:
for i in range(0, n):
if s == 0:
break
if b[i] != a[i]:
if s < 0 and b[i] >= 0 and a[i] >= 0:
b[i] = b[i] + 1
s = s + 1
elif s > 0 and b[i] < 0 and a[i] < 0:
b[i] = b[i] - 1
s = s - 1
for i in range(0, n):
print(b[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
numbers = []
d = []
s = 0
for i in range(int(input())):
n = input()
if n[len(n) - 5 :] == "00000":
num = int(n[: len(n) - 6])
numbers.append(num)
s += num
d.append(0)
elif n[0] == "-":
num = int(n[: len(n) - 6]) - 1
numbers.append(num)
s += num
d.append(-1)
else:
num = int(n[: len(n) - 6])
numbers.append(num)
s += num
d.append(1)
if s == 0:
for i in numbers:
print(i)
else:
for i in range(len(numbers)):
if s < 0:
if d[i] != 0:
s += 1
print(numbers[i] + 1)
else:
print(numbers[i])
else:
print(numbers[i])
|
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
v, a = [0] * n, [0] * n
for i in range(n):
v[i] = float(input())
if abs(v[i]) - int(abs(v[i])) > 0.0:
a[i] = 1
if v[i] >= 0.0:
v[i] = int(v[i])
else:
v[i] = int(v[i]) - 1
else:
v[i] = int(v[i])
s = sum(v)
i = 0
while i < n and s < 0:
if a[i]:
v[i] += 1
s += 1
i += 1
for i in range(n):
print(v[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
arr = [(0) for i in range(n)]
flag = [(0) for i in range(n)]
for i in range(n):
arr[i] = float(input())
if int(arr[i]) == arr[i]:
flag[i] = 1
if flag[i] == 0 and arr[i] < 0:
arr[i] = int(arr[i]) - 1
else:
arr[i] = int(arr[i])
suma = sum(arr)
for i in range(n):
if suma != 0:
if flag[i] == 0:
arr[i] += 1
suma += 1
else:
break
for i in arr:
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
mas = []
checker = []
tmp = ""
for i in range(n):
num = input()
for ind, item in enumerate(num):
if item != ".":
tmp = tmp + item
else:
if tmp == "-0":
mas.append("-0")
else:
mas.append(int(tmp))
tmp = ""
for j in range(ind + 1, len(num)):
if num[j] != "0":
checker.append(True)
break
if j == len(num) - 1 and num[j] == "0":
checker.append(False)
break
summa = 0
for item in mas:
if item == "-0":
summa += 0
else:
summa += item
if summa != 0:
if summa > 0:
for ind, item in enumerate(mas):
if checker[ind]:
if item == "-0":
mas[ind] = -1
summa -= 1
elif item < 0:
mas[ind] -= 1
summa -= 1
if summa == 0:
break
elif summa < 0:
for ind, item in enumerate(mas):
if checker[ind]:
if item == "-0":
continue
elif item >= 0:
mas[ind] += 1
summa += 1
if summa == 0:
break
for item in mas:
if item == "-0":
print(0)
else:
print(item)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR IF VAR NUMBER IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR STRING IF VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vus the Cossack has $n$ real numbers $a_i$. It is known that the sum of all numbers is equal to $0$. He wants to choose a sequence $b$ the size of which is $n$ such that the sum of all numbers is $0$ and each $b_i$ is either $\lfloor a_i \rfloor$ or $\lceil a_i \rceil$. In other words, $b_i$ equals $a_i$ rounded up or down. It is not necessary to round to the nearest integer.
For example, if $a = [4.58413, 1.22491, -2.10517, -3.70387]$, then $b$ can be equal, for example, to $[4, 2, -2, -4]$.
Note that if $a_i$ is an integer, then there is no difference between $\lfloor a_i \rfloor$ and $\lceil a_i \rceil$, $b_i$ will always be equal to $a_i$.
Help Vus the Cossack find such sequence!
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of numbers.
Each of the next $n$ lines contains one real number $a_i$ ($|a_i| < 10^5$). It is guaranteed that each $a_i$ has exactly $5$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $0$.
-----Output-----
In each of the next $n$ lines, print one integer $b_i$. For each $i$, $|a_i-b_i|<1$ must be met.
If there are multiple answers, print any.
-----Examples-----
Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4
Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2
-----Note-----
The first example is explained in the legend.
In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.
|
n = int(input())
a = []
b = []
for i in range(0, n):
a.append(float(input()))
for i in range(0, n):
b.append(int(a[i]))
if a[i] > 0 and a[i] % 1 != 0:
b[i] += 1
s = sum(b)
if s > 0:
i = 0
while s > 0 and i < n:
if a[i] % 1 != 0:
b[i] -= 1
s -= 1
i += 1
elif s < 0:
i = 0
while s < 0 and i < n:
if a[i] % 1 != 0:
b[i] -= 1
s -= 1
i += 1
for i in b:
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.