1.py (532B) [raw]
1 import sys 2 3 total = 0 4 for l in sys.stdin: 5 report = [int(x) for x in l.split()] 6 7 delta = None 8 prev = None 9 safe = True 10 for n in report: 11 if prev: 12 d2 = n - prev 13 if not delta: 14 delta = d2 15 if abs(d2) > 3 or d2 == 0: 16 safe = False 17 break 18 # check for same signage 19 if delta and delta * d2 < 0: 20 safe = False 21 break 22 prev = n 23 if safe: 24 total += 1 25 26 print(total)