import sys def bad_level(report): delta = None prev = None safe = True for i in range(len(report)): n = report[i] if prev: d2 = n - prev if not delta: delta = d2 if abs(d2) > 3 or d2 == 0 or (delta and delta * d2 < 0): return i prev = n return -1 total = 0 for l in sys.stdin: report = [int(x) for x in l.split()] t = total bad = bad_level(report) if bad == -1: total += 1 else: # it could be that the bad index is any of: # - the result returned by bad_level (1 10 2 3) -- bad causes spike # - the index before that (bad - 1) (10 1 2 3) -- prev bad causes spike # - the index before that (bad - 2) (1 2 1 0) -- sign change for i in [0, 1, 2]: if bad - i >= 0: subrep = [report[j] for j in range(len(report)) if j != bad - i] if bad_level(subrep) == -1: total += 1 break print(total)