This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
DSA/midterm_prep/182.py
2019-03-28 11:45:47 +01:00

37 lines
619 B
Python
Executable file

#!/usr/bin/env python3
import sys
def UFM(A):
if len(A) == 0:
return None
m = 0
M = len(A)
while M - 1 != m:
if M - 2 == m:
if A[m] > A[m + 1]:
return A[m]
else:
return A[m + 1]
lh = (M - m) // 2
if A[lh - 1] < A[lh] and A[lh] > A[lh + 1]:
return A[lh]
elif A[lh - 1] < A[lh]:
m = lh
else:
M = lh
return A[m]
A = []
for line in sys.stdin:
line = line.strip()
if line == '' or line == '\n':
break
A.append(int(line))
print(UFM(A))