fin strip for in open input txt readlines fout open output txt from sy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# fin = [i.strip() for i in open('input.txt', 'r').readlines()]
# fout = open('output.txt', 'w')
from sys import stdin
from functools import cmp_to_key
s_input = stdin.readline().strip()
n = int(s_input)
# n = int(fin[0])
# fin = fin[1:]
segments = []
for i in range(n):
# a = int(fin[0].split(' ')[0])
# b = int(fin[0].split(' ')[1])
s_input = stdin.readline().strip()
a = int(s_input.split(' ')[0])
b = int(s_input.split(' ')[1])
# fin = fin[1:]
segments.append([a, b, 0])
points = []
def comparator(o1, o2):
return o1[1] - o2[1]
key_cmp = cmp_to_key(comparator)
segments.sort(key=key_cmp)
def check(p):
for i in range(len(segments)):
if segments[i][2] == 0 and segments[i][0] <= p and segments[i][1] >= p:
segments[i][2] = 1
for i in range(len(segments)):
if segments[i][2] == 0:
points.append(segments[i][1])
check(segments[i][1])
print(len(points))
for i in points:
print(i)