# Untitled

unknown
python
6 months ago
1.3 kB
35
Indexable
Never
```#Задача А

def reverse_in_parentheses(s):
stack = []
result = []

for char in s:
if char == '(':
stack.append(result)
result = []
elif char == ')':
inner = result
result = stack.pop()
result.extend(inner[::-1])
else:
result.append(char)

return ''.join(result)

input_str = input()
result = reverse_in_parentheses(input_str)
print(result)

#Задача B

def shortest_palindrome(input_str):
def is_palindrome(s):
return s == s[::-1]

for i in range(len(input_str)):
if is_palindrome(input_str[i:]):
return input_str + input_str[:i][::-1]

return input_str + input_str[:-1][::-1]

input_str = input()
result = shortest_palindrome(input_str)
print(result)

Задача С

m = int(input())
n = int(input())
mx = [0] * m
for i in range(m):
mx[i] = [0] * n
s = input()
s = s.replace(" ", "")
for i in range(m):
for j in range(n):
mx[i][j] = s[0]
s = s[1::]
print(mx)
for i in range(m):
for j in range(n):
if i == m-1:
break
if mx[i][j] == "0":
mx[i+1][j] = "0"
k = 0
for i in range(m):
for j in range(n):
k += int(mx[i][j])
print(k)```