blob: cb6d86de6579bdabedf4dffed7e68f9de896bd3c (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
|
res = 0
vals = []
with open('2.txt', 'r') as file:
for line in file:
parts = line.strip().split(" ")
inlist = []
for num in parts:
inlist.append(int(num))
vals.append(inlist)
slists = []
for val in vals:
print(val)
isafe = False
for i in range(len(val)):
row = val.copy()
row.pop(i)
print(row)
increasing = False
decreasing = False
safe = True
prev = -1
for j in row:
if prev == -1:
prev = j
continue
if prev < j:
increasing = True
elif prev > j:
decreasing = True
if (abs(prev - j) > 3 or prev == j or
(j > prev and decreasing) or (j < prev and increasing) or
(increasing and decreasing) or (not increasing and not decreasing)):
safe = False
break
prev = j
if safe:
isafe = True
break
slists.append(isafe)
res = sum(slists)
print(res)
|