Загрузка данных


passive = []
active = []

with open('26.txt', 'r') as file:
    for line in file:
        line = line.strip()
        a, b = map(int, line.split())
        passive.append(a)
        active.append(b)

N = len(passive)
all_values = []

for i in range(N):
    all_values.append((passive[i], i + 1, 'passive'))
    all_values.append((active[i], i + 1, 'active'))

all_values.sort()

ranking = [0] * N
left = 0
right = N - 1
last_smartphone = None

for value, smartphone_id, mode in all_values:
    if smartphone_id in ranking:
        continue
    if mode == 'passive':
        ranking[left] = smartphone_id
        left += 1
    else:
        ranking[right] = smartphone_id
        right -= 1
    if left > right:
        last_smartphone = smartphone_id

last_position = ranking.index(last_smartphone)
below_count = N - last_position - 1

print(last_smartphone, below_count)