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 is_safe_with_dampener(report):
"""
Check if a report is safe with the Problem Dampener.
This function tests removing each level one by one to see if it results in a safe report.
"""
# If the report is already safe, return True
if is_safe_report(report):
return True
# Try removing each level one by one
for i in range(len(report)):
modified_report = report[:i] + report[i+1:]
if is_safe_report(modified_report):
return True
# If no single level removal makes the report safe, return False
return False
def count_safe_reports_with_dampener(input_data):
"""
Count the number of safe reports considering the Problem Dampener.
"""
# Parse the input data
reports = [
list(map(int, line.split()))
for line in input_data.strip().split("\n")
]
# Check each report for safety (with the Problem Dampener)
safe_count = sum(1 for report in reports if is_safe_with_dampener(report))
return safe_count
# Example Input (replace this with the actual input)
input_data = """
"""
# Calculate and print the result
result = count_safe_reports_with_dampener(input_data)
print("Number of safe reports with Problem Dampener:", result)