def process(array):
result = []
for i in range(1, len(array)-1):
if (array[i] < 0 and array[i-1] < 0) or \
(array[i] < 0 and array[i+1] < 0) or \
(array[i] > 0 and array[i-1] > 0) or \
(array[i] > 0 and array[i+1] > 0):
return 'YES'
return 'NO'
def main():
N = int(input())
assert N>=1 and N<= 10000
input_array = [int(i) for i in input().split()]
assert len(input_array) == N
print(process(input_array))
if __name__ == '__main__':
main()
Объяснение:
Протестировано на стандартном вводе/выводе + один доп тест
Доп тест:
Ввод:
5
1 2 -2 3 -4
Вывод:
YES
P.S Сайт ломает Python-код. Ниже приложен скриншот исходного кода
def process(array):
result = []
for i in range(1, len(array)-1):
if (array[i] < 0 and array[i-1] < 0) or \
(array[i] < 0 and array[i+1] < 0) or \
(array[i] > 0 and array[i-1] > 0) or \
(array[i] > 0 and array[i+1] > 0):
return 'YES'
return 'NO'
def main():
N = int(input())
assert N>=1 and N<= 10000
input_array = [int(i) for i in input().split()]
assert len(input_array) == N
print(process(input_array))
if __name__ == '__main__':
main()
Объяснение:
Протестировано на стандартном вводе/выводе + один доп тест
Доп тест:
Ввод:
5
1 2 -2 3 -4
Вывод:
YES
P.S Сайт ломает Python-код. Ниже приложен скриншот исходного кода
text=input()
text_list=list(text)
reverse_list=list(text[::-1])
error=None
for i in range(0,len(text_list)):
try:
if(text_list[i]!=reverse_list[i] and error==None):
error=len(text)-i
del text_list[len(text)-i-1]
del reverse_list[i]
elif(text_list[i]!=reverse_list[i] and error!=None):
error=0
break
except IndexError:
pass
print(error)
Объяснение:
P.S. оптимизация может быть не очень