def is_safe_report(report):
"""
Check if a report is safe according to the rules:
- All numbers are either increasing or decreasing.
- The difference between adjacent numbers is between 1 and 3.
"""
differences = []
for i in range(len(report) - 1):
diff = report[i+1] - report[i]
if abs(diff) < 1 or abs(diff) > 3:
return False # Adjacent difference not in range [1, 3]
differences.append(diff)
# Check if all differences are positive (increasing) or negative (decreasing)
if all(d > 0 for d in differences) or all(d < 0 for d in differences):
return True
return False
def count_safe_reports(input_data):
"""
Count the number of safe reports in the input data.
"""
# Parse the input data
reports = [
list(map(int, line.split()))
for line in input_data.strip().split("\n")
]
# Check each report for safety
safe_count = sum(1 for report in reports if is_safe_report(report))
return safe_count
# Example Input (replace this with the actual input)
input_data = """
"""
# Calculate and print the result
result = count_safe_reports(input_data)
print("Number of safe reports:", result)