diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..26ddea4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,186 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject +### VirtualEnv template +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +# idea folder, uncomment if you don't need it +.idea +/days/data/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..65d939f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + ".", + "-p", + "*test.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/AOC_Helpers/__init__.py b/AOC_Helpers/__init__.py new file mode 100644 index 0000000..189ed61 --- /dev/null +++ b/AOC_Helpers/__init__.py @@ -0,0 +1,5 @@ +from .utils import * +from .matrix_utils import * +from .graph_utils import * +from .tuple_utils import * +from .file_utils import * \ No newline at end of file diff --git a/AOC_Helpers/file_utils.py b/AOC_Helpers/file_utils.py new file mode 100644 index 0000000..9c5fd85 --- /dev/null +++ b/AOC_Helpers/file_utils.py @@ -0,0 +1,23 @@ +import ast + +def get_input_file(data_path: str, day: int) -> str: + """ + Get the path to the input file for the given problem. + + :param data_path: Path to the data directory. + :param problem: Problem number. + :return: Path to the input file. + """ + return f"{data_path}/input_{day:02d}.txt" + +def list_from_file(file_path): + """ + Read the file containing the brick data and parse it into a Python list. + + :param file_path: Path to the file containing the brick data. + :return: Parsed list of bricks. + """ + with open(file_path, 'r') as file: + data = file.read() + ls = ast.literal_eval(data) + return ls \ No newline at end of file diff --git a/AOC_Helpers/graph_utils.py b/AOC_Helpers/graph_utils.py new file mode 100644 index 0000000..9ee08af --- /dev/null +++ b/AOC_Helpers/graph_utils.py @@ -0,0 +1,116 @@ + +# 5. Graph and Pathfinding Utilities +import heapq +from collections import defaultdict + + +def build_graph(edges): + graph = defaultdict(list) + for edge in edges: + a, b = edge + graph[a].append(b) + graph[b].append(a) + return graph + + +def bfs(graph, start): + visited, queue = set(), [start] + while queue: + vertex = queue.pop(0) + if vertex not in visited: + visited.add(vertex) + queue.extend(set(graph[vertex]) - visited) + return visited + + +def dijkstra(use_graph=False, grid=None, graph=None, grid_wall_val="#"): + """Dijkstra's algorithm either with a grid (with numbers as distances and grid_wall_val as wall) + or graph as list of tuples as (start, dist, end), returns total distance and path points""" + + if use_graph: + return dijkstra_graph(graph) + else: + return dijkstra_grid(grid, grid_wall_val) + + +def dijkstra_grid(grid, wall_val): + if not grid: + return 0, [] + + rows, cols = len(grid), len(grid[0]) + distances = {(i, j): float('inf') for i in range(rows) for j in range(cols)} + distances[(0, 0)] = grid[0][0] + + min_heap = [(distances[(0, 0)], (0, 0))] + path = {} + + while min_heap: + dist, node = heapq.heappop(min_heap) + if node == (rows - 1, cols - 1): + break + + for dx, dy in [(0, 1), (1, 0), (0, -1), (-1, 0)]: + x, y = node[0] + dx, node[1] + dy + if 0 <= x < rows and 0 <= y < cols and grid[x][y] != wall_val: + alt = dist + grid[x][y] + if alt < distances[(x, y)]: + distances[(x, y)] = alt + heapq.heappush(min_heap, (alt, (x, y))) + path[(x, y)] = node + + if (rows - 1, cols - 1) not in path: + return -1, [] + + total_dist = distances[(rows - 1, cols - 1)] + path_points = [] + current = (rows - 1, cols - 1) + + while current: + path_points.append(current) + current = path.get(current) + + path_points.reverse() + return total_dist, path_points + + +def dijkstra_graph(graph): + if not graph: + return 0, [] + + graph_dict = {} + for start, dist, end in graph: + if start not in graph_dict: + graph_dict[start] = [] + graph_dict[start].append((dist, end)) + + distances = {node: float('inf') for _, node in graph} + distances[graph[0][0]] = 0 + + min_heap = [(0, graph[0][0])] + path = {} + + while min_heap: + dist, node = heapq.heappop(min_heap) + if node not in graph_dict: + continue + + for next_dist, neighbor in graph_dict[node]: + alt = dist + next_dist + if alt < distances[neighbor]: + distances[neighbor] = alt + heapq.heappush(min_heap, (alt, neighbor)) + path[neighbor] = node + + if graph[-1][2] not in path: + return -1, [] + + total_dist = distances[graph[-1][2]] + path_points = [] + current = graph[-1][2] + + while current: + path_points.append(current) + current = path.get(current) + + path_points.reverse() + return total_dist, path_points diff --git a/AOC_Helpers/matrix_utils.py b/AOC_Helpers/matrix_utils.py new file mode 100644 index 0000000..7cf1bd9 --- /dev/null +++ b/AOC_Helpers/matrix_utils.py @@ -0,0 +1,140 @@ +def count_in_2d_matrix(vals: str, arr: list[list]): + total = 0 + for i in arr: + for j in i: + if j in vals: + total += 1 + return total +def count_in_list(ls,val): + return int(sum(1 for i in ls if i == val)) +def remove_duplicates_across_keys(d): + """ + Remove duplicate values across different keys in a dictionary, + where each key maps to a list of bricks. + Each brick is represented as [start_point, end_point]. + """ + # Create a set for unique bricks across all keys + unique_bricks = set() + + for key in d: + new_bricks = [] + for brick in d[key]: + # Convert brick to tuple for hashing + brick_tuple = tuple(map(tuple, brick)) + if brick_tuple not in unique_bricks: + new_bricks.append(brick) + unique_bricks.add(brick_tuple) + + # Update the dictionary with non-duplicate bricks + d[key] = new_bricks + + return d + +# 2. Grid and Matrix Utilities +def get_neighbors(x, y, grid): + directions = [(0, 1), (1, 0), (-1, 0), (0, -1)] # 4-directional + neighbors = [] + for dx, dy in directions: + nx, ny = x + dx, y + dy + if 0 <= nx < len(grid) and 0 <= ny < len(grid[0]): + neighbors.append((nx, ny)) + return neighbors + + +def get_neighbors_with_wrap_around(x, y, grid): + directions = [(0, 1, (1,0)), (1, 0, (0,1)), (-1, 0, (0,-1)), (0, -1, (-1,0))] # 4-directional with labels + neighbors = [] + rows, cols = len(grid), len(grid[0]) # Dimensions of the grid + + for dx, dy, label in directions: + nx, ny = (x + dx) % rows, (y + dy) % cols + did_wrap_around = (nx != x + dx) or (ny != y + dy) + wrap_side = label if did_wrap_around else None + neighbors.append(((nx, ny), did_wrap_around, wrap_side)) + + return neighbors + + + +def print_grid(grid): + for row in grid: + print(''.join(str(cell) for cell in row)) + + +def flood_fill(original_grid: list, wall_val="#", empty_val=".", use_inside: bool = False, inside_pos: tuple = (0, 0), + fill_val="*"): + """ + Perform a flood fill operation on a 2D grid. + + Args: + original_grid (list): The original 2D grid represented as a list of lists. + wall_val (str): The value representing walls in the grid. + empty_val (str): The value representing empty spaces in the grid. + use_inside (bool): If True, starts the flood fill from inside_pos. + inside_pos (tuple): The starting position for flood fill if use_inside is True. + fill_val (str): The value to fill the empty spaces with. + + Returns: + list: The grid with the flood fill operation applied. + """ + grid = original_grid.copy() + if type(grid[0]) == str: grid = [list(i) for i in grid] + changes = 1 + if use_inside: + grid[inside_pos[0]][inside_pos[1]] = fill_val + while changes != 0: + changes = 0 + for idx, i in enumerate(grid): + for jdx, j in enumerate(i): + if j == empty_val: + if not use_inside and (idx == 0 or idx == len(grid) - 1 or jdx == 0 or jdx == len(grid[0]) - 1): + grid[idx][jdx] = fill_val + changes += 1 + if j == empty_val and check_neighbors((idx, jdx), grid): + grid[idx][jdx] = fill_val + changes += 1 + return grid + + +def check_neighbors(pos, grid, to_check="*"): + return to_check in get_neighbors(pos[0], pos[1], grid) + + +def rotate_90_degrees(matrix): + """Rotate a 2D matrix 90 degrees clockwise.""" + return [list(row)[::-1] for row in zip(*matrix)] + + +def rotate_180_degrees(matrix): + """Rotate a 2D matrix 180 degrees.""" + return [row[::-1] for row in matrix[::-1]] + + +def rotate_270_degrees(matrix): + """Rotate a 2D matrix 270 degrees clockwise.""" + return [list(row) for row in zip(*matrix[::-1])] + + +def transpose(matrix): + """Transpose a 2D matrix.""" + return [list(row) for row in zip(*matrix)] + + +def reverse_rows(matrix): + """Reverse the rows of a 2D matrix.""" + return matrix[::-1] + + +def reverse_columns(matrix): + """Reverse the columns of a 2D matrix.""" + return [row[::-1] for row in matrix] + + +def invert_horizontal(matrix): + """Invert (flip) a 2D matrix horizontally.""" + return [row[::-1] for row in matrix] + + +def invert_vertical(matrix): + """Invert (flip) a 2D matrix vertically.""" + return matrix[::-1] diff --git a/AOC_Helpers/setup.py b/AOC_Helpers/setup.py new file mode 100644 index 0000000..9bb7c09 --- /dev/null +++ b/AOC_Helpers/setup.py @@ -0,0 +1,11 @@ +from setuptools import setup, find_packages + +setup( + name='aoc_helpers', + version='0.1', + packages=find_packages(), + description='Helper functions for Advent of Code', + author='Elliot', + author_email='captianexpo@gmail.com', + # Add any other necessary information here +) \ No newline at end of file diff --git a/AOC_Helpers/tuple_utils.py b/AOC_Helpers/tuple_utils.py new file mode 100644 index 0000000..a08ef9b --- /dev/null +++ b/AOC_Helpers/tuple_utils.py @@ -0,0 +1,14 @@ +def tuple_add(t1: tuple, t2: tuple) -> tuple: + return t1[0] + t2[0], t1[1] + t2[1] + + +def tuple_mul(t1: tuple, t2: tuple) -> tuple: + return t1[0] * t2[0], t1[1] * t2[1] + + +def tuple_div(t1: tuple, t2: tuple) -> tuple: + return t1[0] / t2[0], t1[1] / t2[1] + + +def tuple_sub(t1: tuple, t2: tuple) -> tuple: + return t1[0] - t2[0], t1[1] - t2[1] diff --git a/AOC_Helpers/utils.py b/AOC_Helpers/utils.py new file mode 100644 index 0000000..ea05f20 --- /dev/null +++ b/AOC_Helpers/utils.py @@ -0,0 +1,204 @@ +# Advent of Code Helper Functions + +import os +from collections import defaultdict +from itertools import permutations, combinations + + +# 1. File Handling + +def read_lines(file_path): + """ + Read lines from a text file and return them as a list of strings. + + Args: + file_path (str): The path to the text file. + + Returns: + list of str: A list of strings containing the lines from the file. + """ + with open(file_path, 'r') as file: + return [line.strip() for line in file.readlines()] + +def read_file(file_path): + with open(file_path, 'r') as file: + return file.read() +def read_numbers(file_path): + """ + Read numbers from a text file and return them as a list of integers. + + Args: + file_path (str): The path to the text file. + + Returns: + list of int: A list of integers parsed from the lines in the file. + """ + return [int(line) for line in read_lines(file_path)] +def replace_all_in2d(grid,rep,new): + nn = [] + for i in grid: + n = [] + for j in i: + if j in rep: + n.append(new) + else: + n.append(j) + nn.append(n) + return nn +def read_grid(file_path): + """ + Read a grid from a text file and return it as a list of lists. + + Args: + file_path (str): The path to the text file. + + Returns: + list of list: A list of lists representing the grid from the file. + """ + return [list(line) for line in read_lines(file_path)] + + +def parse_lines(multi_line_string): + """ + Parse multiple lines from a string and return them as a list of strings. + + Args: + multi_line_string (str): The input string containing multiple lines. + + Returns: + list of str: A list of strings containing the parsed lines. + """ + return [line.strip() for line in multi_line_string.strip().split('\n')] + + +def parse_numbers(multi_line_string): + """ + Parse multiple lines from a string and return them as a list of integers. + + Args: + multi_line_string (str): The input string containing multiple lines with integers. + + Returns: + list of int: A list of integers parsed from the lines in the input string. + """ + return [int(line) for line in parse_lines(multi_line_string)] + + +def parse_grid(multi_line_string): + """ + Parse a grid from a string and return it as a list of lists. + + Args: + multi_line_string (str): The input string containing the grid. + + Returns: + list of list: A list of lists representing the parsed grid. + """ + return [list(line) for line in parse_lines(multi_line_string)] + + +def remove_all(chars, string: str): + """ + Remove all occurrences of specified characters from a string. + + Args: + chars (str): A string containing characters to be removed. + string (str): The input string from which characters should be removed. + + Returns: + str: The input string with specified characters removed. + """ + out = string + for i in chars: + out = out.replace(i, "") + return out + + +# 3. Number Utilities + +def is_prime(n): + """ + Check if a number is prime. + + Args: + n (int): The number to be checked. + + Returns: + bool: True if the number is prime, False otherwise. + """ + if n <= 1: + return False + for i in range(2, int(n ** 0.5) + 1): + if n % i == 0: + return False + return True + + +def factors(n): + """ + Find all factors of a number. + + Args: + n (int): The number for which factors should be found. + + Returns: + set: A set containing all the factors of the number. + """ + return set(x for tup in ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0) for x in tup) + + +# 4. String Utilities + +def hamming_distance(s1, s2): + """ + Calculate the Hamming distance between two strings of equal length. + + Args: + s1 (str): The first string. + s2 (str): The second string. + + Returns: + int: The Hamming distance between the two strings. + """ + return sum(el1 != el2 for el1, el2 in zip(s1, s2)) + + +def string_permutations(s): + """ + Generate all permutations of a string. + + Args: + s (str): The input string. + + Returns: + list of str: A list of all possible permutations of the input string. + """ + return [''.join(p) for p in permutations(s)] + + + + +def shoelace_area(points): + """ + Calculate the area of a polygon using the Shoelace formula. + + Parameters: + points (list of tuples): A list of tuples representing the vertices of the polygon. + + Returns: + float: The area of the polygon. + """ + n = len(points) + + # Check for the minimum number of points needed to form a polygon + if n < 3: + raise ValueError("At least 3 points are required to form a polygon") + + area = 0 + # Sum over the vertices + for i in range(n): + x1, y1 = points[i] + x2, y2 = points[(i + 1) % n] # Modulo for circular indexing + area += x1 * y2 - y1 * x2 + + return abs(area) / 2 diff --git a/src/2024-Advent-of-Code.code-workspace b/src/2024-Advent-of-Code.code-workspace new file mode 100644 index 0000000..d5db428 --- /dev/null +++ b/src/2024-Advent-of-Code.code-workspace @@ -0,0 +1,14 @@ +{ + "folders": [ + { + "path": "../../2024-Advent-of-Code" + }, + { + "path": "../AOC_Helpers" + }, + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/src/cheatsheet.md b/src/cheatsheet.md new file mode 100644 index 0000000..9c8f223 --- /dev/null +++ b/src/cheatsheet.md @@ -0,0 +1,189 @@ +# AOC Python Cheatsheet + +## Imports + +```python +import itertools +import collections +import heapq +import math +import functools +import operator +import re +``` + +## Input Parsing + +```python +# Read all input as a string +raw_input = input() + +# Read lines of input +lines = raw_input.splitlines() + +# Split a line into integers +nums = list(map(int, line.split())) + +# Split by custom delimiter +data = raw_input.split(',') +``` + +## Itertools + +```python +# Cartesian product +itertools.product(A, B) # Equivalent to nested for-loops + +# Permutations +itertools.permutations(iterable, r=None) + +# Combinations +itertools.combinations(iterable, r) + +# Infinite iterators +itertools.count(start=0, step=1) +itertools.cycle(iterable) +itertools.repeat(object, times=None) + +# Group by (requires sorted input for meaningful grouping) +for key, group in itertools.groupby(data): + print(key, list(group)) +``` + +## Collections + +```python +# Counter +counter = collections.Counter(iterable) +most_common = counter.most_common(3) # Top 3 elements + +# defaultdict (with default factory) +def_dict = collections.defaultdict(list) +def_dict[key].append(value) + +# deque (double-ended queue) +deque = collections.deque(maxlen=10) +deque.append(item) +deque.appendleft(item) +deque.pop() +deque.popleft() + +# Named tuple +Point = collections.namedtuple('Point', ['x', 'y']) +p = Point(10, 20) +``` + +## Heapq (Priority Queue) + +```python +# Min-heap +heap = [] +heapq.heappush(heap, item) +heapq.heappop(heap) +heapq.heappushpop(heap, item) +heapq.heapify(data) + +# Max-heap (invert values) +max_heap = [] +heapq.heappush(max_heap, -item) +heapq.heappop(max_heap) +``` + +## Math + +```python +math.gcd(a, b) # Greatest common divisor +math.lcm(a, b) # Least common multiple (Python 3.9+) +math.isqrt(n) # Integer square root +math.comb(n, k) # Combinations (n choose k) +math.factorial(n) +math.prod(iterable) # Product of iterable (Python 3.8+) + +# Trigonometric and exponential +math.sin(x) +math.exp(x) +``` + +## String Manipulation + +```python +# Pattern matching with regex +pattern = r"\d+" +re.findall(pattern, text) +re.sub(pattern, replacement, text) + +# String slicing and reversing +reversed_string = s[::-1] + +# String alignment +s.rjust(width) +s.ljust(width) +s.center(width) +``` + +## Functional Programming + +```python +# Reduce (accumulate values) +result = functools.reduce(operator.add, iterable) + +# Map +mapped = list(map(function, iterable)) + +# Filter +filtered = list(filter(function, iterable)) + +# Sorted with custom key +sorted_data = sorted(data, key=lambda x: x[1]) +``` + +## Grid Utilities + +```python +# Create a grid +grid = [[0] * cols for _ in range(rows)] + +# Directions (4-way and 8-way) +dirs_4 = [(0, 1), (1, 0), (0, -1), (-1, 0)] +dirs_8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1)] + +# Iterate through a grid +for r in range(rows): + for c in range(cols): + value = grid[r][c] + +# Check in-bounds +if 0 <= r < rows and 0 <= c < cols: + pass +``` + +## Binary and Bitwise Operations + +```python +# Convert to binary +bin_str = bin(number)[2:] # Remove '0b' prefix + +# Bitwise AND, OR, XOR, NOT +result = a & b +result = a | b +result = a ^ b +result = ~a + +# Shift operators +result = a << 1 # Left shift +result = a >> 1 # Right shift + +# Count set bits +bin(number).count('1') +``` + +## Debugging + +```python +# Print with debug info +print(f"Variable name: {var}") + +# Pretty print data structures +from pprint import pprint +pprint(data) +``` diff --git a/src/solution_01.py b/src/solution_01.py new file mode 100644 index 0000000..3a1ecee --- /dev/null +++ b/src/solution_01.py @@ -0,0 +1,2042 @@ +data = """ +76569 66648 +38663 66530 +60350 60777 +35330 13469 +88681 66648 +30057 83262 +55455 13469 +48398 40350 +60451 61801 +23979 80612 +20498 47207 +18170 73737 +27928 35371 +45219 20896 +13289 77147 +24458 32690 +33053 45373 +30998 96652 +63320 53803 +18321 62925 +47393 64433 +71112 96929 +21392 87748 +60110 75803 +45686 82976 +43026 50513 +23080 25876 +81346 96652 +45701 27282 +67858 52482 +61483 98326 +52308 60692 +98286 78044 +99386 28829 +31064 24022 +90518 76616 +86055 77147 +77548 78368 +67600 59182 +13410 10920 +14441 94982 +73737 70248 +61602 67267 +88419 40092 +31757 26048 +51810 97947 +37775 64433 +42112 31426 +82029 97947 +84902 75016 +77147 72913 +55928 74888 +30168 26337 +35206 62925 +76009 87748 +51573 21184 +54931 74888 +23466 65978 +34344 62436 +56118 89076 +57495 27190 +20063 84666 +50850 60277 +94982 65172 +82710 50401 +54893 97947 +17029 13015 +31042 27282 +77274 21521 +36836 66530 +64993 32013 +36429 67456 +14228 60117 +93810 77235 +82201 55336 +11071 59405 +62119 76671 +74858 78380 +16332 64287 +41635 61870 +26392 19133 +30081 79653 +46852 54621 +61987 40810 +45439 13469 +16638 72913 +46884 64433 +78775 41746 +28266 21471 +50240 21359 +36216 18921 +63061 80604 +55186 48458 +33521 67895 +88738 32324 +17872 27128 +42966 67895 +74894 66648 +68870 72913 +32631 89974 +22114 32324 +54345 94982 +79241 40092 +75791 30915 +89775 64433 +36196 62925 +97340 64433 +70717 66530 +97532 74017 +17841 85558 +64433 96652 +57281 77235 +60158 68395 +38601 31426 +95768 67206 +74339 96114 +72283 66153 +66648 88997 +77312 64433 +24237 65172 +34725 80360 +81905 45373 +49368 66530 +70080 74811 +36941 56793 +25380 65172 +75150 40092 +95428 65463 +65063 75803 +95286 97947 +76555 67896 +69305 72913 +46692 19873 +60637 79234 +70348 40092 +63575 87748 +18822 86165 +10053 45373 +32355 92574 +33467 59368 +78154 27282 +21154 67895 +34321 62925 +63763 31426 +41970 57327 +95379 32324 +29009 75157 +57863 27282 +93891 71556 +55942 26584 +51505 97947 +57349 56723 +18516 26076 +47757 26741 +88631 64859 +82224 66648 +94668 97947 +37537 63594 +84583 67896 +62925 31426 +83652 21593 +48631 78044 +34328 70839 +17959 12466 +92497 79654 +74945 52837 +30957 96669 +20808 74035 +68043 78044 +92100 27282 +83140 67895 +50451 54565 +99877 28626 +17414 84687 +74459 73737 +71551 10197 +48028 64325 +45144 20896 +77667 38950 +55278 33966 +50857 78698 +71058 62925 +14884 32559 +26322 35307 +19517 72482 +61263 67885 +41865 20896 +46019 74888 +84622 58250 +72924 74609 +65922 82910 +57609 97333 +96221 54856 +58965 96652 +48467 66648 +38822 30889 +89271 78044 +50233 64433 +72132 45373 +50114 87748 +92854 22607 +68597 49674 +31426 77235 +26290 64433 +46519 64433 +99530 77235 +24195 31586 +24855 21184 +12474 79094 +79857 21593 +84581 20896 +14589 92512 +27460 21340 +95913 80901 +96860 32324 +68478 48576 +61539 53107 +54264 19299 +11712 67896 +67895 47673 +21806 32758 +94924 62925 +79279 78044 +71937 39743 +38121 78795 +99405 66123 +23777 32324 +15904 78795 +57158 64433 +90077 94982 +27713 55706 +94225 35262 +26741 86365 +76579 53276 +98566 87748 +96383 31426 +34920 35972 +30857 44851 +72631 28903 +97426 75803 +90023 10480 +42078 72456 +29177 61870 +15290 92102 +30020 31426 +48828 92102 +55399 50795 +92532 96652 +84224 48473 +56107 21184 +94015 15651 +74539 66648 +46023 67896 +65289 27607 +76828 61870 +31980 70248 +29563 77235 +37156 16468 +90827 91595 +90960 19133 +52081 22332 +37539 41719 +45714 54298 +33020 61870 +65172 66530 +48114 78775 +95266 75803 +14319 86650 +15016 35732 +44772 80035 +13318 55618 +66222 52117 +52139 87748 +89430 11409 +94339 75803 +51914 62825 +49546 19721 +77235 33966 +34977 58765 +32268 94658 +32335 78795 +87797 78044 +70688 27282 +34550 65172 +48762 71542 +36225 33519 +14156 37230 +54748 33966 +60824 62925 +23664 80089 +75308 17866 +85167 27282 +31875 87748 +80274 97947 +53914 19133 +65328 87748 +15842 70248 +64679 34977 +72913 72913 +26977 50674 +18805 79402 +50403 92493 +66822 66530 +25130 78795 +43179 73939 +28529 90781 +84485 98917 +88144 64096 +19444 80359 +25094 77147 +23999 94224 +76777 66648 +80395 87748 +87765 75803 +54941 97947 +35440 50102 +47296 40092 +82072 33966 +99634 66367 +66069 67895 +38850 75803 +30653 77235 +56745 45373 +21852 74888 +19323 94982 +83540 88668 +83398 40092 +68475 35769 +32324 94982 +75842 24467 +75024 92102 +30361 31426 +23965 16174 +89063 66946 +33958 47913 +52713 92695 +79512 27282 +57978 89624 +67269 66530 +52343 94982 +68862 38090 +23827 48146 +78795 70248 +51665 94193 +22205 33442 +44361 82174 +32727 61173 +51222 83595 +69372 48212 +87748 96669 +20468 75346 +64252 31030 +85477 67895 +74888 35830 +15886 92371 +50741 63054 +91573 90762 +64501 40092 +58070 47184 +48736 52006 +86830 66648 +42764 20896 +39435 75803 +57300 23024 +27997 29297 +94682 45384 +63535 63310 +61579 69125 +76805 50707 +80476 27282 +78044 33966 +20073 65172 +60476 78795 +67653 25683 +59888 30469 +51791 62925 +69612 27282 +92872 98790 +76912 92147 +39675 87781 +18997 78044 +39931 80845 +54580 34977 +80984 66702 +28979 66122 +90883 87748 +87336 32324 +15586 20896 +54359 91784 +61884 67895 +47021 97947 +44988 45373 +81841 61262 +10463 31426 +20507 45373 +42642 31426 +45174 45373 +98791 92102 +26063 86304 +53202 61016 +68734 77235 +11240 61870 +89762 40475 +26879 43813 +35769 33966 +86763 80861 +23079 63219 +62599 77147 +90177 68212 +89027 13469 +78085 31979 +23181 23639 +60101 43169 +70182 43769 +76082 65349 +23126 44490 +94557 85732 +39903 92382 +53351 92674 +27851 12772 +55945 19133 +94512 31426 +59442 40411 +46111 72913 +33188 40092 +69496 45373 +53706 49971 +84226 51998 +84530 21593 +15619 92382 +92909 32324 +82233 92102 +32228 83737 +22622 75803 +87096 80553 +45821 64433 +53028 41007 +87359 39533 +24280 87748 +33180 45751 +29942 78775 +62815 36056 +34378 33966 +19267 59240 +41823 22936 +19487 66588 +35166 33993 +53863 96652 +37077 22763 +21593 78795 +15250 83295 +97412 75803 +41281 92126 +50748 61126 +85109 73737 +93496 78795 +89991 33966 +21350 78044 +83836 67895 +99183 87748 +83195 64433 +57577 13469 +86197 58388 +75241 48318 +28959 32286 +19106 33966 +24181 13469 +58346 27282 +64260 40092 +63855 37643 +51041 46410 +12780 85519 +39423 85172 +15750 31426 +96117 72913 +48705 66648 +60266 40092 +56098 54353 +84332 62925 +59843 21593 +47823 79304 +92701 37931 +44807 75803 +87047 77312 +12269 20353 +32926 46463 +87543 27282 +37843 19133 +89968 61047 +81630 20896 +78677 21184 +97744 32324 +42608 51250 +80685 81741 +50122 14161 +13469 64433 +46215 62925 +19736 66530 +33883 37191 +57314 73055 +97638 19870 +53667 92382 +57195 61870 +25721 33774 +26068 40724 +25422 72913 +21805 45373 +30357 19952 +84783 64433 +51674 32324 +31130 64009 +66530 87748 +56565 82436 +45075 66648 +20799 40855 +62469 18007 +29429 25209 +28582 78775 +63901 15901 +82320 62925 +13257 70997 +60804 77312 +90339 40092 +42668 65172 +24336 67895 +26868 89300 +50073 98326 +84600 30003 +65452 77235 +95481 73588 +70538 48925 +99276 77147 +92621 19133 +91369 97947 +52612 24257 +36522 17658 +70248 97947 +88603 23450 +14573 70248 +67260 89145 +51191 98661 +44550 49884 +14867 96392 +40341 77267 +36004 77312 +81443 78902 +76574 53093 +87171 17683 +75979 61667 +74276 32324 +35093 13469 +83347 62925 +61220 27315 +75436 90108 +91705 67308 +44016 21184 +77374 85349 +56171 21593 +12623 77147 +67912 22652 +62519 97947 +50408 34621 +92685 77147 +69052 76862 +90063 92382 +19924 11561 +24684 40421 +94603 65926 +93869 66530 +36287 48082 +19610 67895 +41304 70125 +80834 99853 +73110 79715 +34006 80678 +49159 50399 +94986 90400 +23162 65172 +87756 45373 +78614 92102 +48810 91710 +30686 75803 +93411 85238 +92796 62925 +33708 83052 +69230 88895 +80346 97913 +31632 31088 +49454 96652 +87503 32324 +12993 67895 +24790 16973 +27278 77235 +31393 97947 +13890 32206 +45822 65172 +76509 66648 +73570 27282 +68202 65172 +11950 62321 +86295 40092 +59431 21184 +10073 34977 +46959 43185 +38024 77147 +59467 65244 +97947 64378 +52066 33745 +78026 72913 +67778 20896 +36416 90870 +28572 20178 +43037 96652 +13183 78390 +95497 31577 +59588 31486 +87551 74948 +47751 60762 +64227 33966 +25037 96652 +69189 79055 +78690 72913 +97053 33515 +86924 74892 +21239 12234 +70294 94982 +64633 66530 +63033 77235 +20972 67896 +57094 28665 +66334 78044 +84175 45373 +69423 85516 +59629 92102 +26492 56269 +24233 88192 +42703 38887 +43484 27282 +25830 97275 +27148 32324 +70173 63820 +37962 21712 +53875 73269 +62770 30421 +84383 56860 +38809 78044 +14689 37568 +58731 40092 +69616 68542 +12184 61542 +19032 37467 +21184 40092 +81673 65172 +92102 35259 +50429 18155 +41374 87748 +62668 40678 +38465 21184 +48412 74888 +85695 66183 +85327 76099 +40141 48103 +78149 34977 +19512 75803 +90774 24724 +30680 70248 +33876 13469 +48744 87748 +41261 34680 +94345 66648 +17561 77462 +82921 13469 +22353 51441 +66005 67895 +31257 45373 +47358 70248 +89407 31426 +16602 27282 +77071 32324 +33095 94179 +92791 27577 +90001 45373 +76457 64433 +45373 82791 +26903 27282 +94655 61226 +87065 64433 +59434 26586 +31424 78044 +98326 31294 +67336 65172 +63174 57462 +91623 91717 +30997 57264 +16487 56799 +36955 67895 +41035 95689 +40808 78044 +70906 12597 +83126 68388 +27778 34977 +29362 96669 +96931 34603 +49573 77235 +17169 65172 +62241 81818 +44935 84669 +56537 31733 +70264 10099 +53581 20896 +10468 21683 +72084 96652 +10700 29942 +95034 54507 +95618 85158 +44077 18069 +62523 75803 +73000 65172 +86080 27282 +70455 55085 +86887 39416 +36257 66530 +69290 13469 +84621 45373 +28070 27127 +67896 71818 +91077 60253 +28096 58231 +82719 62925 +13753 62925 +13359 73882 +73187 56847 +46578 37833 +51474 29377 +59914 13469 +32994 29637 +47213 64433 +27705 20268 +43458 42766 +55713 70932 +88478 67896 +76437 71309 +47552 30154 +61870 14538 +82030 60684 +66782 57234 +58762 77235 +73779 66648 +39491 97947 +56237 48563 +39046 67465 +83723 75437 +15550 96669 +45705 72913 +61209 75803 +34422 62925 +48150 32431 +54683 10076 +80717 78795 +73513 62925 +17391 40092 +93794 64433 +61475 59675 +53260 77235 +28755 89046 +61345 99015 +70447 19133 +17075 95443 +38645 77312 +34399 79947 +96669 80873 +53242 81188 +73388 38294 +43262 45373 +57113 35769 +99180 23536 +71205 26741 +23208 66648 +16013 66648 +48327 33966 +54890 23799 +35094 42350 +91186 37676 +57274 87515 +75941 61870 +57396 75803 +26112 67895 +54308 77312 +16053 65172 +92418 45373 +33397 22627 +68006 13273 +71144 27282 +41560 28813 +11541 61870 +12314 20591 +84666 35769 +45896 20896 +37274 67618 +25332 12025 +47691 67895 +19593 88018 +59745 52030 +16391 21184 +48465 77312 +27282 20896 +44459 79545 +56759 21184 +31978 77312 +49713 60159 +71736 77235 +48701 94495 +58335 77312 +85731 77235 +36730 87187 +24576 61551 +16255 77312 +86861 77232 +44160 20365 +42957 77235 +37675 21184 +46289 19117 +32863 67895 +44893 63700 +19026 77147 +14203 62925 +79022 20896 +90878 64104 +28194 50591 +99094 17191 +83283 67895 +97463 94724 +21838 99767 +33966 34741 +31560 37806 +51238 77312 +87950 66471 +97414 62666 +22335 73671 +43355 21593 +33567 40218 +77568 61870 +73302 43649 +20178 94062 +41008 40771 +61032 77312 +92382 40092 +28557 74888 +66152 50621 +55335 40092 +94368 34977 +96652 64433 +39401 21593 +33854 54721 +12726 70248 +58078 40066 +86375 88605 +93905 66648 +73642 74437 +10862 96669 +69937 21184 +16483 80995 +33726 32324 +91167 68312 +49496 97947 +40092 79306 +88996 78795 +87107 33435 +95555 59150 +10341 94764 +85542 77312 +67878 23706 +23412 92102 +50765 20896 +32794 62925 +96832 97699 +83174 77235 +64070 21184 +54569 40092 +96530 96652 +17512 94982 +71376 42379 +75803 16374 +85967 31426 +34569 70248 +96867 97811 +56321 22248 +31972 98519 +11367 79119 +16755 77147 +33148 23891 +27699 92382 +58246 34977 +81416 96566 +64682 74553 +14103 31426 +97226 40092 +76494 69441 +33262 43363 +83176 63786 +44601 39137 +19627 35769 +82257 74888 +33338 40646 +65644 20178 +40304 40092 +63980 25399 +35134 33966 +78787 54216 +31147 98280 +70378 45373 +96224 50505 +75530 34977 +43443 31426 +17552 28034 +15131 86681 +59594 73729 +74481 61870 +91569 19681 +67128 78795 +63154 77235 +51586 98318 +41213 20368 +66534 98097 +49095 98255 +25436 21184 +95020 43385 +93614 82529 +46555 62461 +35898 17460 +63537 31992 +71258 91047 +92852 67895 +97125 20896 +88632 75803 +57247 96652 +20277 67895 +10269 85485 +46681 78417 +31928 44190 +12487 21184 +76196 77312 +24895 10004 +46101 87748 +26438 21593 +86041 67868 +99574 74888 +14990 20896 +42622 24596 +76205 62925 +88565 45373 +88447 65172 +11332 28176 +47458 21931 +19133 36318 +58142 35444 +77904 53938 +45223 20384 +32352 96652 +88508 81769 +35832 47885 +79827 77014 +53932 33966 +16064 92102 +73085 20896 +17739 99652 +54478 67896 +28744 57632 +87515 93313 +86271 93951 +15579 74888 +51749 62314 +46430 30608 +24869 67896 +97219 88722 +13106 21184 +22072 66530 +67674 65974 +68925 55818 +33588 21184 +95625 65172 +31443 87748 +94542 32961 +21244 20482 +38829 68138 +68255 77147 +39081 16035 +25336 16043 +31219 92382 +87477 53823 +29146 45373 +37019 65172 +94223 65172 +20896 34977 +15884 86356 +76809 13023 +56403 10503 +23533 40965 +82416 74888 +24373 20896 +""" + +# Step 1: Parse the input into two lists +left_list = [] +right_list = [] + +for line in data.strip().split('\n'): + left, right = map(int, line.split()) + left_list.append(left) + right_list.append(right) + +# Step 2: Sort both lists +left_list.sort() +right_list.sort() + +# Step 3: Calculate the total distance +total_distance = sum(abs(l - r) for l, r in zip(left_list, right_list)) + +print(total_distance) + +# part 2 +data = """ +76569 66648 +38663 66530 +60350 60777 +35330 13469 +88681 66648 +30057 83262 +55455 13469 +48398 40350 +60451 61801 +23979 80612 +20498 47207 +18170 73737 +27928 35371 +45219 20896 +13289 77147 +24458 32690 +33053 45373 +30998 96652 +63320 53803 +18321 62925 +47393 64433 +71112 96929 +21392 87748 +60110 75803 +45686 82976 +43026 50513 +23080 25876 +81346 96652 +45701 27282 +67858 52482 +61483 98326 +52308 60692 +98286 78044 +99386 28829 +31064 24022 +90518 76616 +86055 77147 +77548 78368 +67600 59182 +13410 10920 +14441 94982 +73737 70248 +61602 67267 +88419 40092 +31757 26048 +51810 97947 +37775 64433 +42112 31426 +82029 97947 +84902 75016 +77147 72913 +55928 74888 +30168 26337 +35206 62925 +76009 87748 +51573 21184 +54931 74888 +23466 65978 +34344 62436 +56118 89076 +57495 27190 +20063 84666 +50850 60277 +94982 65172 +82710 50401 +54893 97947 +17029 13015 +31042 27282 +77274 21521 +36836 66530 +64993 32013 +36429 67456 +14228 60117 +93810 77235 +82201 55336 +11071 59405 +62119 76671 +74858 78380 +16332 64287 +41635 61870 +26392 19133 +30081 79653 +46852 54621 +61987 40810 +45439 13469 +16638 72913 +46884 64433 +78775 41746 +28266 21471 +50240 21359 +36216 18921 +63061 80604 +55186 48458 +33521 67895 +88738 32324 +17872 27128 +42966 67895 +74894 66648 +68870 72913 +32631 89974 +22114 32324 +54345 94982 +79241 40092 +75791 30915 +89775 64433 +36196 62925 +97340 64433 +70717 66530 +97532 74017 +17841 85558 +64433 96652 +57281 77235 +60158 68395 +38601 31426 +95768 67206 +74339 96114 +72283 66153 +66648 88997 +77312 64433 +24237 65172 +34725 80360 +81905 45373 +49368 66530 +70080 74811 +36941 56793 +25380 65172 +75150 40092 +95428 65463 +65063 75803 +95286 97947 +76555 67896 +69305 72913 +46692 19873 +60637 79234 +70348 40092 +63575 87748 +18822 86165 +10053 45373 +32355 92574 +33467 59368 +78154 27282 +21154 67895 +34321 62925 +63763 31426 +41970 57327 +95379 32324 +29009 75157 +57863 27282 +93891 71556 +55942 26584 +51505 97947 +57349 56723 +18516 26076 +47757 26741 +88631 64859 +82224 66648 +94668 97947 +37537 63594 +84583 67896 +62925 31426 +83652 21593 +48631 78044 +34328 70839 +17959 12466 +92497 79654 +74945 52837 +30957 96669 +20808 74035 +68043 78044 +92100 27282 +83140 67895 +50451 54565 +99877 28626 +17414 84687 +74459 73737 +71551 10197 +48028 64325 +45144 20896 +77667 38950 +55278 33966 +50857 78698 +71058 62925 +14884 32559 +26322 35307 +19517 72482 +61263 67885 +41865 20896 +46019 74888 +84622 58250 +72924 74609 +65922 82910 +57609 97333 +96221 54856 +58965 96652 +48467 66648 +38822 30889 +89271 78044 +50233 64433 +72132 45373 +50114 87748 +92854 22607 +68597 49674 +31426 77235 +26290 64433 +46519 64433 +99530 77235 +24195 31586 +24855 21184 +12474 79094 +79857 21593 +84581 20896 +14589 92512 +27460 21340 +95913 80901 +96860 32324 +68478 48576 +61539 53107 +54264 19299 +11712 67896 +67895 47673 +21806 32758 +94924 62925 +79279 78044 +71937 39743 +38121 78795 +99405 66123 +23777 32324 +15904 78795 +57158 64433 +90077 94982 +27713 55706 +94225 35262 +26741 86365 +76579 53276 +98566 87748 +96383 31426 +34920 35972 +30857 44851 +72631 28903 +97426 75803 +90023 10480 +42078 72456 +29177 61870 +15290 92102 +30020 31426 +48828 92102 +55399 50795 +92532 96652 +84224 48473 +56107 21184 +94015 15651 +74539 66648 +46023 67896 +65289 27607 +76828 61870 +31980 70248 +29563 77235 +37156 16468 +90827 91595 +90960 19133 +52081 22332 +37539 41719 +45714 54298 +33020 61870 +65172 66530 +48114 78775 +95266 75803 +14319 86650 +15016 35732 +44772 80035 +13318 55618 +66222 52117 +52139 87748 +89430 11409 +94339 75803 +51914 62825 +49546 19721 +77235 33966 +34977 58765 +32268 94658 +32335 78795 +87797 78044 +70688 27282 +34550 65172 +48762 71542 +36225 33519 +14156 37230 +54748 33966 +60824 62925 +23664 80089 +75308 17866 +85167 27282 +31875 87748 +80274 97947 +53914 19133 +65328 87748 +15842 70248 +64679 34977 +72913 72913 +26977 50674 +18805 79402 +50403 92493 +66822 66530 +25130 78795 +43179 73939 +28529 90781 +84485 98917 +88144 64096 +19444 80359 +25094 77147 +23999 94224 +76777 66648 +80395 87748 +87765 75803 +54941 97947 +35440 50102 +47296 40092 +82072 33966 +99634 66367 +66069 67895 +38850 75803 +30653 77235 +56745 45373 +21852 74888 +19323 94982 +83540 88668 +83398 40092 +68475 35769 +32324 94982 +75842 24467 +75024 92102 +30361 31426 +23965 16174 +89063 66946 +33958 47913 +52713 92695 +79512 27282 +57978 89624 +67269 66530 +52343 94982 +68862 38090 +23827 48146 +78795 70248 +51665 94193 +22205 33442 +44361 82174 +32727 61173 +51222 83595 +69372 48212 +87748 96669 +20468 75346 +64252 31030 +85477 67895 +74888 35830 +15886 92371 +50741 63054 +91573 90762 +64501 40092 +58070 47184 +48736 52006 +86830 66648 +42764 20896 +39435 75803 +57300 23024 +27997 29297 +94682 45384 +63535 63310 +61579 69125 +76805 50707 +80476 27282 +78044 33966 +20073 65172 +60476 78795 +67653 25683 +59888 30469 +51791 62925 +69612 27282 +92872 98790 +76912 92147 +39675 87781 +18997 78044 +39931 80845 +54580 34977 +80984 66702 +28979 66122 +90883 87748 +87336 32324 +15586 20896 +54359 91784 +61884 67895 +47021 97947 +44988 45373 +81841 61262 +10463 31426 +20507 45373 +42642 31426 +45174 45373 +98791 92102 +26063 86304 +53202 61016 +68734 77235 +11240 61870 +89762 40475 +26879 43813 +35769 33966 +86763 80861 +23079 63219 +62599 77147 +90177 68212 +89027 13469 +78085 31979 +23181 23639 +60101 43169 +70182 43769 +76082 65349 +23126 44490 +94557 85732 +39903 92382 +53351 92674 +27851 12772 +55945 19133 +94512 31426 +59442 40411 +46111 72913 +33188 40092 +69496 45373 +53706 49971 +84226 51998 +84530 21593 +15619 92382 +92909 32324 +82233 92102 +32228 83737 +22622 75803 +87096 80553 +45821 64433 +53028 41007 +87359 39533 +24280 87748 +33180 45751 +29942 78775 +62815 36056 +34378 33966 +19267 59240 +41823 22936 +19487 66588 +35166 33993 +53863 96652 +37077 22763 +21593 78795 +15250 83295 +97412 75803 +41281 92126 +50748 61126 +85109 73737 +93496 78795 +89991 33966 +21350 78044 +83836 67895 +99183 87748 +83195 64433 +57577 13469 +86197 58388 +75241 48318 +28959 32286 +19106 33966 +24181 13469 +58346 27282 +64260 40092 +63855 37643 +51041 46410 +12780 85519 +39423 85172 +15750 31426 +96117 72913 +48705 66648 +60266 40092 +56098 54353 +84332 62925 +59843 21593 +47823 79304 +92701 37931 +44807 75803 +87047 77312 +12269 20353 +32926 46463 +87543 27282 +37843 19133 +89968 61047 +81630 20896 +78677 21184 +97744 32324 +42608 51250 +80685 81741 +50122 14161 +13469 64433 +46215 62925 +19736 66530 +33883 37191 +57314 73055 +97638 19870 +53667 92382 +57195 61870 +25721 33774 +26068 40724 +25422 72913 +21805 45373 +30357 19952 +84783 64433 +51674 32324 +31130 64009 +66530 87748 +56565 82436 +45075 66648 +20799 40855 +62469 18007 +29429 25209 +28582 78775 +63901 15901 +82320 62925 +13257 70997 +60804 77312 +90339 40092 +42668 65172 +24336 67895 +26868 89300 +50073 98326 +84600 30003 +65452 77235 +95481 73588 +70538 48925 +99276 77147 +92621 19133 +91369 97947 +52612 24257 +36522 17658 +70248 97947 +88603 23450 +14573 70248 +67260 89145 +51191 98661 +44550 49884 +14867 96392 +40341 77267 +36004 77312 +81443 78902 +76574 53093 +87171 17683 +75979 61667 +74276 32324 +35093 13469 +83347 62925 +61220 27315 +75436 90108 +91705 67308 +44016 21184 +77374 85349 +56171 21593 +12623 77147 +67912 22652 +62519 97947 +50408 34621 +92685 77147 +69052 76862 +90063 92382 +19924 11561 +24684 40421 +94603 65926 +93869 66530 +36287 48082 +19610 67895 +41304 70125 +80834 99853 +73110 79715 +34006 80678 +49159 50399 +94986 90400 +23162 65172 +87756 45373 +78614 92102 +48810 91710 +30686 75803 +93411 85238 +92796 62925 +33708 83052 +69230 88895 +80346 97913 +31632 31088 +49454 96652 +87503 32324 +12993 67895 +24790 16973 +27278 77235 +31393 97947 +13890 32206 +45822 65172 +76509 66648 +73570 27282 +68202 65172 +11950 62321 +86295 40092 +59431 21184 +10073 34977 +46959 43185 +38024 77147 +59467 65244 +97947 64378 +52066 33745 +78026 72913 +67778 20896 +36416 90870 +28572 20178 +43037 96652 +13183 78390 +95497 31577 +59588 31486 +87551 74948 +47751 60762 +64227 33966 +25037 96652 +69189 79055 +78690 72913 +97053 33515 +86924 74892 +21239 12234 +70294 94982 +64633 66530 +63033 77235 +20972 67896 +57094 28665 +66334 78044 +84175 45373 +69423 85516 +59629 92102 +26492 56269 +24233 88192 +42703 38887 +43484 27282 +25830 97275 +27148 32324 +70173 63820 +37962 21712 +53875 73269 +62770 30421 +84383 56860 +38809 78044 +14689 37568 +58731 40092 +69616 68542 +12184 61542 +19032 37467 +21184 40092 +81673 65172 +92102 35259 +50429 18155 +41374 87748 +62668 40678 +38465 21184 +48412 74888 +85695 66183 +85327 76099 +40141 48103 +78149 34977 +19512 75803 +90774 24724 +30680 70248 +33876 13469 +48744 87748 +41261 34680 +94345 66648 +17561 77462 +82921 13469 +22353 51441 +66005 67895 +31257 45373 +47358 70248 +89407 31426 +16602 27282 +77071 32324 +33095 94179 +92791 27577 +90001 45373 +76457 64433 +45373 82791 +26903 27282 +94655 61226 +87065 64433 +59434 26586 +31424 78044 +98326 31294 +67336 65172 +63174 57462 +91623 91717 +30997 57264 +16487 56799 +36955 67895 +41035 95689 +40808 78044 +70906 12597 +83126 68388 +27778 34977 +29362 96669 +96931 34603 +49573 77235 +17169 65172 +62241 81818 +44935 84669 +56537 31733 +70264 10099 +53581 20896 +10468 21683 +72084 96652 +10700 29942 +95034 54507 +95618 85158 +44077 18069 +62523 75803 +73000 65172 +86080 27282 +70455 55085 +86887 39416 +36257 66530 +69290 13469 +84621 45373 +28070 27127 +67896 71818 +91077 60253 +28096 58231 +82719 62925 +13753 62925 +13359 73882 +73187 56847 +46578 37833 +51474 29377 +59914 13469 +32994 29637 +47213 64433 +27705 20268 +43458 42766 +55713 70932 +88478 67896 +76437 71309 +47552 30154 +61870 14538 +82030 60684 +66782 57234 +58762 77235 +73779 66648 +39491 97947 +56237 48563 +39046 67465 +83723 75437 +15550 96669 +45705 72913 +61209 75803 +34422 62925 +48150 32431 +54683 10076 +80717 78795 +73513 62925 +17391 40092 +93794 64433 +61475 59675 +53260 77235 +28755 89046 +61345 99015 +70447 19133 +17075 95443 +38645 77312 +34399 79947 +96669 80873 +53242 81188 +73388 38294 +43262 45373 +57113 35769 +99180 23536 +71205 26741 +23208 66648 +16013 66648 +48327 33966 +54890 23799 +35094 42350 +91186 37676 +57274 87515 +75941 61870 +57396 75803 +26112 67895 +54308 77312 +16053 65172 +92418 45373 +33397 22627 +68006 13273 +71144 27282 +41560 28813 +11541 61870 +12314 20591 +84666 35769 +45896 20896 +37274 67618 +25332 12025 +47691 67895 +19593 88018 +59745 52030 +16391 21184 +48465 77312 +27282 20896 +44459 79545 +56759 21184 +31978 77312 +49713 60159 +71736 77235 +48701 94495 +58335 77312 +85731 77235 +36730 87187 +24576 61551 +16255 77312 +86861 77232 +44160 20365 +42957 77235 +37675 21184 +46289 19117 +32863 67895 +44893 63700 +19026 77147 +14203 62925 +79022 20896 +90878 64104 +28194 50591 +99094 17191 +83283 67895 +97463 94724 +21838 99767 +33966 34741 +31560 37806 +51238 77312 +87950 66471 +97414 62666 +22335 73671 +43355 21593 +33567 40218 +77568 61870 +73302 43649 +20178 94062 +41008 40771 +61032 77312 +92382 40092 +28557 74888 +66152 50621 +55335 40092 +94368 34977 +96652 64433 +39401 21593 +33854 54721 +12726 70248 +58078 40066 +86375 88605 +93905 66648 +73642 74437 +10862 96669 +69937 21184 +16483 80995 +33726 32324 +91167 68312 +49496 97947 +40092 79306 +88996 78795 +87107 33435 +95555 59150 +10341 94764 +85542 77312 +67878 23706 +23412 92102 +50765 20896 +32794 62925 +96832 97699 +83174 77235 +64070 21184 +54569 40092 +96530 96652 +17512 94982 +71376 42379 +75803 16374 +85967 31426 +34569 70248 +96867 97811 +56321 22248 +31972 98519 +11367 79119 +16755 77147 +33148 23891 +27699 92382 +58246 34977 +81416 96566 +64682 74553 +14103 31426 +97226 40092 +76494 69441 +33262 43363 +83176 63786 +44601 39137 +19627 35769 +82257 74888 +33338 40646 +65644 20178 +40304 40092 +63980 25399 +35134 33966 +78787 54216 +31147 98280 +70378 45373 +96224 50505 +75530 34977 +43443 31426 +17552 28034 +15131 86681 +59594 73729 +74481 61870 +91569 19681 +67128 78795 +63154 77235 +51586 98318 +41213 20368 +66534 98097 +49095 98255 +25436 21184 +95020 43385 +93614 82529 +46555 62461 +35898 17460 +63537 31992 +71258 91047 +92852 67895 +97125 20896 +88632 75803 +57247 96652 +20277 67895 +10269 85485 +46681 78417 +31928 44190 +12487 21184 +76196 77312 +24895 10004 +46101 87748 +26438 21593 +86041 67868 +99574 74888 +14990 20896 +42622 24596 +76205 62925 +88565 45373 +88447 65172 +11332 28176 +47458 21931 +19133 36318 +58142 35444 +77904 53938 +45223 20384 +32352 96652 +88508 81769 +35832 47885 +79827 77014 +53932 33966 +16064 92102 +73085 20896 +17739 99652 +54478 67896 +28744 57632 +87515 93313 +86271 93951 +15579 74888 +51749 62314 +46430 30608 +24869 67896 +97219 88722 +13106 21184 +22072 66530 +67674 65974 +68925 55818 +33588 21184 +95625 65172 +31443 87748 +94542 32961 +21244 20482 +38829 68138 +68255 77147 +39081 16035 +25336 16043 +31219 92382 +87477 53823 +29146 45373 +37019 65172 +94223 65172 +20896 34977 +15884 86356 +76809 13023 +56403 10503 +23533 40965 +82416 74888 +24373 20896 +""" + +# Step 1: Parse the input into two lists +left_list = [] +right_list = [] + +for line in data.strip().split('\n'): + left, right = map(int, line.split()) + left_list.append(left) + right_list.append(right) + +# Step 2: Count occurrences of each number in the right list +from collections import Counter +right_counter = Counter(right_list) + +# Step 3: Calculate the similarity score +similarity_score = sum(left * right_counter[left] for left in left_list) + +print(similarity_score) \ No newline at end of file diff --git a/src/solution_02.py b/src/solution_02.py new file mode 100644 index 0000000..c537f90 --- /dev/null +++ b/src/solution_02.py @@ -0,0 +1,2044 @@ +def is_safe(report): + increasing = all(1 <= report[i+1] - report[i] <= 3 for i in range(len(report) - 1)) + decreasing = all(1 <= report[i] - report[i+1] <= 3 for i in range(len(report) - 1)) + return increasing or decreasing + +def count_safe_reports(data): + reports = data.strip().split('\n') + safe_count = 0 + for report in reports: + levels = list(map(int, report.split())) + if is_safe(levels): + safe_count += 1 + return safe_count + +data = """45 47 48 51 54 56 54 +76 79 81 84 84 +30 32 35 36 38 40 44 +72 74 77 78 85 +54 55 58 57 60 +61 64 67 66 68 67 +5 7 6 9 12 14 16 16 +82 83 84 82 85 88 91 95 +38 40 43 46 49 47 53 +23 26 28 31 34 35 35 36 +74 75 78 80 81 81 79 +11 13 16 17 18 18 20 20 +20 21 22 23 23 27 +63 64 64 65 68 71 73 79 +44 47 49 53 55 56 58 59 +81 82 84 87 88 92 89 +32 35 38 40 44 44 +53 55 59 60 62 64 65 69 +53 55 56 58 62 67 +57 59 62 68 71 73 74 75 +22 24 25 30 33 35 38 36 +15 17 20 25 28 30 32 32 +83 85 88 94 98 +74 77 78 80 87 92 +57 55 58 61 63 64 65 67 +74 71 73 74 75 73 +32 31 34 35 35 +35 32 34 36 38 40 42 46 +35 32 33 34 36 41 +69 67 66 67 70 71 74 75 +93 91 89 91 94 93 +95 93 92 94 96 96 +23 22 21 22 23 24 28 +27 24 25 26 28 26 29 36 +86 84 86 86 88 +2 1 2 3 3 6 9 7 +35 33 35 35 36 36 +15 13 14 14 16 18 19 23 +73 70 70 71 78 +21 20 23 25 28 32 33 35 +27 25 27 28 32 34 31 +40 39 40 44 44 +67 64 67 71 75 +31 28 29 32 33 37 44 +9 8 11 14 17 19 25 28 +42 41 46 49 51 50 +22 21 26 28 31 33 36 36 +20 19 26 28 32 +32 29 30 37 40 43 48 +20 20 23 25 28 31 32 35 +69 69 72 75 76 75 +51 51 53 54 54 +46 46 47 48 49 53 +72 72 75 76 77 78 80 85 +53 53 54 52 54 +79 79 78 79 78 +72 72 75 73 75 75 +47 47 49 52 54 51 55 +19 19 20 18 21 26 +84 84 85 85 88 91 93 94 +29 29 29 31 33 36 33 +15 15 17 18 21 21 21 +61 61 61 64 67 71 +62 62 63 64 64 70 +64 64 67 71 72 75 77 79 +60 60 63 67 70 68 +76 76 79 81 85 87 88 88 +20 20 23 26 28 31 35 39 +29 29 33 35 42 +25 25 30 32 35 +50 50 52 59 60 62 60 +60 60 61 63 68 69 69 +81 81 83 86 87 92 96 +68 68 73 76 81 +21 25 26 28 31 32 35 38 +38 42 43 44 45 43 +35 39 42 44 46 46 +19 23 24 26 28 29 33 +54 58 60 63 65 67 73 +33 37 38 40 42 39 42 44 +65 69 70 67 68 65 +9 13 10 13 13 +78 82 79 81 83 87 +34 38 40 38 40 41 48 +15 19 19 21 24 +36 40 42 42 39 +4 8 9 9 9 +52 56 57 60 61 61 65 +50 54 56 57 57 60 66 +26 30 32 36 37 +9 13 16 20 22 23 20 +55 59 61 65 65 +45 49 50 53 57 60 63 67 +74 78 82 84 90 +41 45 50 53 56 +72 76 82 83 85 82 +1 5 11 12 12 +72 76 79 81 82 89 93 +54 58 64 65 70 +66 72 74 77 79 81 84 87 +47 53 55 57 60 62 59 +71 78 79 81 82 84 84 +52 57 59 62 64 65 69 +59 64 67 69 71 74 76 83 +78 83 85 82 83 85 86 89 +27 32 34 37 40 37 35 +37 42 40 41 44 44 +44 51 54 51 53 57 +18 24 27 30 32 31 36 +57 63 66 68 68 69 71 72 +65 70 70 71 73 72 +32 37 37 39 42 42 +43 50 52 52 55 58 61 65 +20 26 28 28 29 30 33 38 +50 55 59 62 64 65 66 +44 51 52 56 57 58 61 59 +12 17 18 21 25 26 28 28 +2 9 11 15 19 +61 68 72 73 78 +17 22 28 30 33 +58 64 67 72 74 71 +72 78 79 85 88 90 90 +69 74 76 83 85 89 +24 31 34 35 36 42 49 +22 19 16 14 12 10 9 12 +74 72 70 67 66 66 +42 40 39 36 32 +95 93 92 91 85 +70 68 67 66 65 67 66 63 +82 79 77 74 77 74 77 +74 72 70 71 68 68 +97 95 94 96 93 91 87 +13 11 9 10 8 2 +13 10 8 8 6 4 +80 78 75 75 73 70 72 +64 63 63 60 60 +54 51 50 50 46 +35 32 29 28 28 27 21 +87 85 81 80 78 +27 25 22 18 17 14 17 +94 92 88 85 82 79 78 78 +19 16 15 11 10 7 3 +46 44 42 41 37 34 29 +54 52 49 44 43 41 40 +29 27 26 20 21 +97 95 92 85 85 +55 54 52 47 46 42 +32 31 28 26 23 21 16 9 +43 44 42 40 39 38 +14 15 14 12 11 10 13 +48 50 47 46 46 +90 93 90 87 85 82 78 +78 80 77 74 72 69 68 62 +32 35 37 35 32 29 28 26 +15 16 17 15 14 13 16 +62 65 63 65 65 +75 77 75 78 74 +4 7 5 7 6 1 +98 99 96 93 93 90 +52 55 55 54 57 +76 79 79 78 75 75 +75 77 74 74 73 70 66 +21 23 22 21 21 19 17 12 +79 81 80 76 75 +69 71 69 65 63 61 59 60 +71 73 71 70 69 65 64 64 +59 61 59 56 54 50 46 +86 89 85 84 83 77 +53 55 54 48 47 44 42 39 +13 16 15 14 12 5 6 +63 64 63 60 54 52 52 +55 56 54 47 43 +33 36 33 32 27 22 +30 30 28 27 25 24 21 19 +14 14 12 11 10 12 +34 34 32 31 30 27 24 24 +18 18 17 16 12 +21 21 19 16 10 +26 26 27 24 21 20 +68 68 67 66 64 66 63 64 +77 77 80 78 76 73 73 +71 71 73 71 69 66 65 61 +25 25 24 23 21 19 20 15 +46 46 46 45 44 41 38 37 +73 73 72 70 68 68 67 68 +54 54 54 53 51 49 49 +47 47 47 46 44 43 39 +72 72 70 69 67 67 62 +93 93 90 89 85 82 81 78 +54 54 53 49 47 48 +24 24 20 19 19 +93 93 89 87 83 +30 30 28 24 22 20 14 +97 97 90 88 87 +76 76 71 68 67 66 65 66 +81 81 75 72 72 +50 50 45 42 41 37 +75 75 69 67 61 +49 45 42 41 38 36 +56 52 50 49 46 45 47 +31 27 24 22 19 18 18 +42 38 37 34 33 30 26 +77 73 71 70 67 65 63 58 +36 32 29 26 24 23 25 22 +46 42 39 41 43 +85 81 82 80 78 78 +49 45 43 45 41 +63 59 62 59 54 +91 87 85 85 82 +68 64 62 59 59 61 +9 5 5 4 4 +74 70 68 68 67 63 +25 21 19 18 16 13 13 7 +69 65 64 60 57 54 +68 64 60 59 58 57 60 +94 90 89 87 85 84 80 80 +28 24 20 18 16 12 +26 22 20 16 11 +95 91 89 83 80 +36 32 29 28 23 24 +82 78 75 70 70 +58 54 49 47 44 40 +52 48 47 45 39 32 +98 93 92 90 89 86 84 +32 25 23 20 18 15 17 +26 19 18 15 14 13 10 10 +33 28 26 23 20 18 15 11 +84 78 75 74 73 70 69 64 +86 79 78 76 74 77 74 +73 67 65 62 63 64 +90 84 81 83 83 +94 87 86 84 87 83 +40 33 32 30 33 32 29 24 +25 19 18 18 15 14 +86 80 79 79 78 77 76 77 +10 4 3 3 3 +55 48 48 47 43 +98 92 91 90 87 87 81 +21 16 12 11 9 7 4 2 +27 22 19 15 14 11 12 +22 17 13 12 10 10 +97 90 89 86 82 81 77 +99 94 91 87 82 +72 67 64 63 62 55 53 +63 56 54 53 52 51 44 46 +46 39 36 33 31 26 26 +48 42 37 35 31 +27 20 14 13 11 8 1 +15 17 18 21 23 25 26 24 +65 68 71 74 77 80 81 81 +23 26 28 29 31 32 36 +84 86 87 90 92 93 98 +89 90 91 94 96 95 96 +24 25 26 28 25 26 25 +34 37 34 37 37 +24 26 29 28 32 +72 74 72 73 75 80 +91 93 93 94 97 +21 23 25 25 22 +29 32 35 37 37 37 +52 54 54 56 57 61 +21 23 23 24 30 +16 18 19 23 26 28 29 32 +81 84 88 89 91 94 95 92 +55 57 61 63 63 +77 79 80 82 84 87 91 95 +18 20 21 24 28 31 34 40 +22 23 26 32 35 +29 32 33 35 36 41 38 +25 28 29 31 33 34 39 39 +1 4 9 12 16 +31 33 34 41 44 51 +90 87 89 90 92 93 95 96 +32 30 31 33 31 +85 82 83 85 88 90 90 +76 73 76 78 80 81 82 86 +26 25 27 30 33 35 38 43 +66 64 67 69 71 70 73 +56 53 52 54 57 60 59 +78 75 73 74 74 +7 5 7 5 9 +57 55 53 55 58 61 64 71 +78 76 77 77 79 82 +54 52 52 54 51 +53 50 53 53 53 +88 86 89 91 92 94 94 98 +85 83 83 85 86 92 +6 3 7 9 12 14 +17 16 18 22 24 26 23 +20 17 20 23 24 28 30 30 +58 56 58 59 63 67 +8 5 9 10 17 +77 74 75 77 78 80 87 89 +82 81 82 84 85 87 94 92 +81 78 79 84 84 +60 58 60 61 64 71 75 +66 63 65 71 76 +62 62 65 68 70 72 +22 22 24 26 24 +16 16 18 21 21 +30 30 33 36 38 42 +46 46 47 50 51 52 59 +3 3 4 2 4 6 9 11 +15 15 12 14 16 17 19 17 +32 32 35 34 34 +92 92 95 92 93 94 98 +73 73 70 73 76 83 +18 18 18 21 22 +39 39 42 42 43 41 +88 88 89 92 92 94 96 96 +27 27 27 30 32 36 +63 63 65 66 66 72 +31 31 35 38 39 40 41 +10 10 12 16 17 19 17 +38 38 42 43 45 45 +57 57 61 62 63 65 68 72 +11 11 14 18 21 23 24 31 +63 63 69 71 74 75 +8 8 13 16 15 +22 22 23 26 33 35 35 +7 7 10 13 16 21 25 +20 20 23 24 29 34 +79 83 86 88 91 93 +38 42 44 45 48 51 53 51 +36 40 42 43 45 45 +23 27 29 31 35 +69 73 74 76 81 +14 18 21 22 25 24 27 30 +36 40 37 38 40 42 40 +9 13 11 14 16 16 +73 77 75 78 82 +29 33 31 33 39 +23 27 30 30 32 34 +57 61 64 65 68 68 69 67 +16 20 20 23 24 26 26 +23 27 30 30 31 32 36 +72 76 76 79 86 +53 57 59 60 64 65 67 68 +63 67 71 74 71 +86 90 91 95 96 99 99 +62 66 69 73 77 +61 65 69 70 75 +23 27 30 36 39 40 41 42 +30 34 37 38 39 42 47 46 +50 54 56 61 61 +21 25 27 32 36 +22 26 27 33 36 38 45 +29 34 37 39 40 42 +31 36 38 39 40 43 46 43 +34 39 42 43 46 48 51 51 +29 35 36 37 40 43 46 50 +23 30 33 34 37 40 43 50 +90 95 96 93 95 +58 64 66 69 67 66 +29 34 37 40 37 40 43 43 +24 29 32 35 38 39 37 41 +11 18 17 19 20 27 +49 56 59 59 62 +87 93 96 97 97 96 +5 11 11 12 15 16 16 +45 50 50 51 53 57 +65 71 74 74 81 +35 42 46 47 48 51 54 +76 81 82 83 87 89 87 +2 7 8 11 15 17 17 +30 36 39 43 46 50 +48 53 54 56 60 63 64 70 +75 81 87 88 90 91 +27 32 34 36 41 39 +81 88 95 98 98 +32 38 45 46 49 52 53 57 +45 50 52 58 59 66 +75 72 69 67 68 +16 13 10 9 8 6 6 +96 95 94 91 88 87 83 +44 41 39 37 35 32 27 +34 32 33 30 27 +64 61 60 58 56 54 55 58 +56 55 54 57 54 51 51 +41 39 42 41 39 38 34 +26 25 24 26 25 19 +21 19 17 17 16 +89 86 85 84 83 83 80 83 +15 12 12 9 9 +52 49 47 47 43 +50 49 49 46 43 41 38 31 +97 95 94 92 91 87 86 +39 37 36 33 32 29 25 26 +77 76 73 72 70 67 63 63 +22 20 16 14 11 7 +34 32 31 28 24 23 16 +31 29 26 24 17 15 13 11 +81 79 77 70 67 65 66 +67 64 58 55 55 +22 19 17 14 12 11 6 2 +36 35 34 33 31 30 23 17 +14 15 12 10 7 +15 17 14 11 13 +3 6 5 4 3 3 +68 71 69 67 64 62 58 +34 37 35 32 25 +29 32 29 28 25 27 24 +20 21 24 22 20 19 21 +86 87 84 81 83 82 82 +16 19 17 14 13 11 13 9 +27 28 31 29 28 23 +61 62 62 59 56 55 54 +28 31 29 29 26 28 +78 79 79 76 73 70 70 +18 20 19 17 17 13 +40 41 40 40 38 36 35 28 +87 88 87 83 81 78 +41 44 41 40 39 35 33 35 +88 90 89 85 85 +25 27 23 22 19 18 14 +97 98 95 94 90 87 82 +90 93 87 85 84 82 79 +87 90 89 86 84 78 81 +67 70 65 64 61 61 +94 97 94 92 89 83 79 +57 59 57 52 46 +66 66 63 62 59 +39 39 36 35 32 29 32 +64 64 62 59 57 54 54 +27 27 26 24 21 20 16 +41 41 40 38 36 35 28 +78 78 76 73 70 68 70 69 +54 54 52 51 54 53 50 52 +55 55 54 51 54 53 53 +30 30 29 32 31 27 +97 97 96 99 98 93 +86 86 86 83 80 78 75 72 +93 93 91 89 89 90 +97 97 97 95 95 +62 62 60 57 57 56 52 +75 75 73 73 71 69 62 +50 50 46 44 41 40 +80 80 79 75 73 71 68 69 +38 38 36 33 29 29 +98 98 95 91 87 +78 78 75 73 69 68 63 +84 84 82 79 76 74 67 66 +19 19 16 10 8 11 +32 32 25 22 20 19 16 16 +23 23 22 21 19 13 10 6 +80 80 73 72 71 68 62 +81 77 75 73 72 71 70 69 +65 61 60 58 61 +17 13 10 8 8 +90 86 83 81 77 +69 65 63 62 61 55 +46 42 39 36 38 35 34 +58 54 53 55 56 +80 76 73 76 74 74 +63 59 57 54 53 56 54 50 +45 41 43 42 35 +23 19 19 16 14 +55 51 50 49 49 48 47 48 +96 92 90 87 84 81 81 81 +86 82 80 77 77 74 70 +95 91 90 90 84 +44 40 38 37 36 32 29 +95 91 87 85 82 85 +96 92 91 87 85 85 +66 62 59 55 51 +40 36 32 31 29 27 22 +77 73 71 68 62 61 58 55 +87 83 81 79 73 72 71 74 +52 48 47 41 38 36 36 +88 84 81 76 74 71 67 +89 85 82 79 73 70 63 +87 80 77 75 72 71 +18 12 11 9 7 6 9 +98 92 89 88 88 +78 73 70 69 66 63 60 56 +41 35 32 30 29 23 +39 33 31 28 30 29 +69 64 65 62 64 +59 54 51 52 51 49 47 47 +69 62 64 61 57 +54 48 45 42 41 43 41 34 +60 53 50 48 45 44 44 41 +52 46 46 45 48 +37 30 27 27 24 24 +91 84 84 82 80 76 +94 87 86 83 83 76 +38 32 28 25 23 20 19 17 +17 11 7 6 4 5 +65 58 57 55 52 48 47 47 +60 55 51 48 44 +63 58 55 52 50 46 43 36 +37 30 28 22 19 +96 89 87 81 78 79 +24 18 17 16 14 9 6 6 +40 33 28 25 23 21 20 16 +67 60 57 55 53 47 45 38 +48 50 53 56 57 60 62 59 +47 48 50 52 55 57 57 +34 35 37 38 41 42 45 49 +59 60 61 63 64 66 73 +42 45 47 50 49 51 53 +18 21 23 25 23 24 23 +30 33 32 33 36 38 39 39 +48 49 52 55 58 56 57 61 +54 57 56 57 62 +16 18 19 22 22 24 +74 77 80 81 82 82 79 +17 19 19 22 22 +27 29 31 32 32 33 36 40 +30 31 31 33 34 37 38 45 +77 80 81 82 84 88 89 +56 58 60 61 65 63 +86 88 92 95 95 +58 59 60 61 65 67 71 +55 57 58 62 64 66 73 +39 41 42 49 50 52 55 +8 11 18 21 22 24 26 24 +32 34 40 41 42 42 +35 36 38 41 48 51 55 +63 65 71 73 76 82 +89 88 89 91 92 94 +34 33 36 37 35 +65 64 65 66 69 70 71 71 +24 23 24 26 27 31 +10 9 12 13 14 17 20 25 +47 44 45 46 47 46 49 +51 48 50 47 44 +40 38 39 36 38 38 +75 73 74 71 73 77 +47 46 49 50 47 48 50 56 +12 10 10 12 15 17 +28 26 27 27 30 27 +10 7 10 10 11 13 15 15 +85 84 84 85 89 +35 32 33 35 35 38 44 +70 68 71 73 74 76 80 81 +75 72 76 77 79 80 83 82 +86 84 85 89 92 95 95 +12 9 11 13 16 17 21 25 +6 4 6 10 16 +36 35 37 40 43 50 53 56 +68 65 66 68 71 77 74 +85 83 86 93 95 96 97 97 +25 23 25 27 34 35 38 42 +41 38 45 47 48 54 +46 46 47 49 51 52 53 54 +30 30 33 34 36 37 36 +43 43 45 48 50 51 51 +87 87 89 92 96 +1 1 4 7 8 11 18 +91 91 94 96 99 97 99 +48 48 51 54 53 52 +73 73 76 77 80 82 80 80 +66 66 67 68 70 67 71 +72 72 70 71 77 +7 7 10 13 13 14 +73 73 73 76 79 77 +51 51 52 55 57 57 59 59 +15 15 16 16 20 +70 70 73 76 79 82 82 87 +19 19 23 26 27 29 +40 40 44 46 43 +6 6 9 13 15 18 18 +16 16 20 23 25 27 30 34 +72 72 75 77 79 83 90 +43 43 46 53 54 57 58 +5 5 6 11 13 10 +10 10 13 15 21 21 +29 29 30 37 39 43 +71 71 78 81 87 +45 49 50 51 52 54 +21 25 28 29 32 29 +38 42 43 46 46 +10 14 15 18 19 20 21 25 +10 14 17 18 19 22 23 29 +8 12 11 14 17 19 21 +58 62 61 62 61 +32 36 33 35 35 +1 5 6 4 8 +69 73 74 75 72 75 81 +54 58 59 59 61 +54 58 58 59 60 62 59 +61 65 65 68 71 74 74 +84 88 89 89 93 +51 55 56 56 58 59 60 65 +10 14 17 21 22 +13 17 20 21 25 26 25 +45 49 53 54 54 +80 84 88 90 91 94 98 +19 23 24 26 27 28 32 37 +42 46 48 54 55 +49 53 58 59 62 65 62 +60 64 70 73 75 75 +53 57 60 67 68 72 +27 31 33 35 41 44 51 +20 25 27 28 29 30 33 34 +37 42 45 46 44 +42 49 51 54 55 58 59 59 +36 42 44 47 50 52 56 +11 18 21 22 29 +77 82 79 81 82 +9 14 15 12 9 +37 44 41 43 43 +30 35 33 35 38 39 43 +45 52 53 55 57 59 58 64 +26 31 31 34 36 39 41 +38 43 44 45 47 50 50 49 +10 16 18 18 20 20 +18 24 25 28 29 29 31 35 +52 59 61 64 67 67 68 75 +18 25 26 29 32 33 37 38 +21 28 32 35 33 +24 31 35 36 38 41 41 +47 54 55 59 63 +60 66 70 71 74 75 80 +65 71 72 79 82 85 87 +59 65 66 72 70 +33 38 39 42 47 50 50 +22 29 30 31 33 34 39 43 +5 10 11 18 20 21 26 +91 89 88 85 84 85 +75 73 71 69 69 +23 21 19 17 15 13 12 8 +52 50 48 45 43 38 +34 33 32 31 32 29 26 +41 38 40 38 39 +72 70 69 72 72 +18 15 17 16 13 10 6 +86 85 82 83 77 +28 25 22 19 18 17 17 14 +95 92 92 91 89 91 +80 77 76 76 73 73 +23 20 18 18 17 15 14 10 +60 58 56 56 49 +23 21 17 15 14 +33 30 26 25 23 20 23 +97 96 93 89 89 +51 50 48 45 44 40 36 +84 82 80 79 75 72 71 64 +76 75 68 67 64 62 +97 94 88 86 89 +89 87 81 78 77 77 +97 94 91 86 83 81 80 76 +17 15 13 12 7 2 +24 27 25 23 20 19 17 16 +28 30 27 24 23 21 18 21 +8 9 8 7 6 5 2 2 +51 54 51 49 46 42 +41 43 41 38 36 31 +54 56 55 54 53 56 53 +68 71 69 70 67 65 67 +6 9 8 9 8 6 4 4 +51 53 51 49 47 49 48 44 +40 43 45 43 42 36 +49 50 50 47 45 42 40 38 +4 7 6 4 4 2 3 +98 99 99 98 98 +53 56 54 54 50 +81 82 79 79 77 71 +88 89 86 82 80 +55 58 56 54 51 47 44 45 +58 61 58 57 55 52 48 48 +28 29 28 24 23 19 +56 59 58 54 47 +85 88 86 79 76 +95 98 97 90 88 86 88 +52 53 50 49 47 42 41 41 +60 63 60 54 52 50 46 +55 57 56 55 49 48 45 39 +54 54 51 48 45 43 41 40 +60 60 57 54 53 55 +60 60 59 58 55 53 51 51 +44 44 41 40 36 +81 81 78 77 74 71 70 65 +46 46 43 46 44 +67 67 66 64 65 63 66 +74 74 72 69 66 64 67 67 +61 61 60 61 59 58 54 +48 48 46 48 47 44 39 +25 25 25 24 23 +88 88 88 86 88 +19 19 19 17 14 11 9 9 +70 70 67 65 65 64 60 +17 17 14 12 12 11 8 2 +99 99 96 92 90 +56 56 54 52 48 47 50 +80 80 77 73 72 69 69 +28 28 26 22 20 17 13 +70 70 66 64 58 +93 93 88 86 83 81 79 77 +40 40 34 31 34 +47 47 45 42 39 34 34 +89 89 82 79 78 74 +98 98 97 96 90 87 84 79 +47 43 41 38 35 34 32 29 +63 59 58 55 53 50 51 +80 76 74 71 68 65 65 +47 43 42 41 39 38 37 33 +84 80 77 75 74 67 +87 83 80 78 81 79 +18 14 16 13 16 +31 27 30 28 27 27 +15 11 8 11 9 6 2 +22 18 17 20 17 11 +52 48 47 44 44 41 40 +39 35 35 32 29 27 26 29 +50 46 45 45 43 42 40 40 +91 87 85 85 81 +56 52 50 50 43 +25 21 19 18 14 13 +78 74 70 69 67 69 +21 17 16 15 13 9 9 +59 55 54 51 47 43 +96 92 90 88 84 83 82 77 +49 45 40 37 35 +53 49 43 42 41 44 +50 46 44 38 35 35 +56 52 46 45 43 41 37 +46 42 40 37 30 25 +63 58 56 54 51 48 47 45 +55 50 49 48 47 44 47 +26 21 18 15 15 +65 58 57 55 53 49 +94 89 87 85 84 81 75 +65 59 57 55 56 55 +12 5 4 5 6 +24 17 20 17 17 +17 12 9 7 6 8 7 3 +44 37 39 36 30 +19 12 12 9 7 4 3 +99 94 92 89 87 87 90 +18 13 12 12 12 +65 60 60 58 54 +27 20 17 16 14 12 12 5 +22 15 11 10 8 +67 61 57 55 57 +37 32 29 28 25 21 21 +94 87 83 82 79 78 75 71 +60 54 51 47 44 38 +57 52 49 46 40 38 +84 79 78 73 70 72 +46 39 36 31 30 30 +85 80 79 73 71 67 +52 46 45 39 38 37 32 +76 78 76 74 69 68 66 66 +93 93 92 91 88 86 83 84 +2 1 3 5 8 6 +77 71 69 67 63 61 58 59 +17 10 7 6 6 +93 94 95 96 98 99 98 +66 71 72 74 78 81 +10 13 17 18 21 23 23 +48 48 45 43 37 30 +26 28 28 29 27 +93 91 90 92 95 95 +75 72 71 68 66 65 62 56 +36 40 42 43 46 45 44 +29 33 34 35 35 37 38 39 +20 25 26 28 30 32 36 34 +2 2 4 5 9 12 12 +59 63 66 70 70 +95 95 98 96 94 92 87 +63 56 54 52 55 49 +4 8 11 18 20 17 +54 56 53 51 48 50 47 +99 96 93 91 90 90 88 88 +39 39 41 43 45 49 +23 23 29 31 34 35 +62 58 55 53 46 41 +56 59 57 55 55 54 52 48 +47 50 53 54 55 57 58 +18 16 14 13 10 9 +26 29 31 34 36 39 +61 59 57 55 54 52 49 +34 35 37 39 41 42 44 +54 57 58 59 61 64 66 67 +24 23 22 19 16 15 +63 65 66 67 70 71 72 73 +97 96 93 90 87 84 81 +84 82 80 79 76 74 72 71 +21 23 24 26 28 30 32 33 +77 75 74 72 69 67 66 64 +65 67 70 72 75 77 79 +21 22 24 25 27 28 30 +77 79 81 82 83 +52 51 48 45 42 +21 20 17 15 14 11 10 +50 47 46 43 40 37 34 +50 52 53 56 59 61 63 +74 75 76 77 80 83 +85 86 87 89 90 92 94 96 +16 14 13 12 9 7 5 4 +92 89 86 85 82 81 78 +37 36 33 31 30 27 26 25 +55 53 51 50 48 46 44 41 +4 6 8 11 14 16 17 +31 34 36 37 40 +21 22 25 28 29 +26 28 30 33 35 38 41 +49 46 44 41 40 39 38 36 +66 67 69 72 75 +72 69 66 65 64 61 59 56 +88 91 92 95 98 +11 14 16 19 20 23 +64 62 61 59 58 56 55 53 +82 83 85 86 87 89 92 94 +91 88 85 84 82 +94 93 90 87 84 82 79 +11 14 15 16 19 +39 36 35 32 30 27 24 21 +79 80 81 84 87 +49 50 53 56 59 62 +41 40 39 38 37 +15 14 12 9 6 5 4 1 +9 11 13 15 18 19 20 +67 68 71 74 77 +86 89 92 93 94 97 98 +9 11 13 15 17 19 +81 83 85 88 91 92 +54 52 50 48 47 45 43 +25 24 22 20 19 +91 89 86 83 80 79 77 75 +22 21 19 18 15 14 +64 63 61 60 58 55 +14 17 19 22 24 26 +52 54 57 59 62 65 +11 12 14 17 20 21 +90 89 88 86 85 84 81 +81 82 84 87 89 92 93 +55 53 52 49 47 44 43 +28 26 24 23 21 19 18 17 +83 80 79 78 76 74 71 +95 92 89 86 83 +69 72 74 76 77 +51 54 57 59 62 64 67 +13 14 15 16 19 21 24 +47 46 44 43 41 40 37 36 +75 74 71 68 67 66 64 +30 33 34 36 38 40 41 43 +21 22 23 26 29 +32 35 36 37 38 40 43 45 +11 12 13 16 18 19 20 21 +20 18 16 15 13 10 9 8 +36 39 42 44 46 47 +53 51 49 47 44 43 40 +82 80 78 75 74 71 70 67 +26 25 22 21 20 19 18 17 +62 65 67 68 69 70 71 72 +85 84 81 79 78 77 75 74 +36 38 41 42 45 48 +56 54 53 50 49 48 +80 79 76 73 72 70 68 67 +40 38 37 34 31 +97 96 94 92 89 86 83 80 +62 59 58 56 54 52 +23 26 28 29 30 33 +12 15 17 18 21 22 25 +73 70 69 66 64 61 +34 32 30 29 26 23 +99 98 96 94 92 +67 70 72 74 75 76 +57 60 62 63 66 69 70 +76 74 72 69 68 67 66 63 +5 7 10 11 13 15 +36 38 41 44 46 +94 91 88 85 84 83 82 80 +13 15 16 17 19 22 25 26 +85 87 88 89 90 93 +19 17 16 15 13 10 8 5 +15 17 20 23 24 26 29 32 +93 92 91 88 85 83 80 +27 29 30 31 32 33 +68 70 71 72 74 77 80 +22 20 17 15 13 12 9 +23 20 18 15 14 12 +56 53 52 49 47 +19 16 14 11 10 +32 29 28 27 25 24 +98 96 93 90 88 +86 88 89 91 92 +69 66 65 62 60 59 +19 20 23 25 28 +56 57 60 63 65 68 70 72 +50 47 46 44 42 40 39 38 +54 53 52 50 49 46 44 +5 6 8 9 12 13 16 19 +38 41 43 44 47 50 +37 36 35 33 31 30 27 26 +73 76 78 81 83 84 85 +32 29 28 25 24 21 18 16 +84 86 87 89 91 94 95 +37 40 43 45 48 50 51 54 +91 93 94 96 97 +20 22 24 27 30 +56 59 60 63 64 +58 61 62 65 68 69 +43 40 37 36 34 31 28 26 +33 36 37 38 39 42 +49 47 45 43 42 41 39 38 +82 84 87 89 90 93 +26 23 20 18 17 +71 70 69 67 64 63 +67 69 72 73 74 +99 97 96 93 92 +38 41 42 43 44 45 48 +12 15 16 19 22 24 +72 74 76 79 82 84 85 87 +97 96 93 91 90 +55 52 50 48 47 46 +16 14 12 11 9 7 6 5 +99 96 94 91 88 87 85 83 +87 86 84 82 81 +13 14 15 16 19 21 23 +38 41 42 44 47 48 +19 18 17 16 13 10 +29 30 32 33 35 38 39 +35 34 33 31 30 +86 87 88 90 93 95 +35 32 31 29 27 +68 67 64 61 59 +80 77 74 72 71 +71 70 69 66 65 +15 17 18 19 20 21 +42 45 47 50 51 +33 31 29 28 27 25 24 +73 72 71 69 68 67 65 64 +43 46 48 51 53 54 +39 42 45 48 51 53 +53 52 50 49 47 +47 50 51 54 56 +26 29 30 33 36 37 40 42 +39 36 34 33 30 27 24 +65 66 68 70 72 75 76 77 +51 53 56 57 59 60 62 63 +53 52 50 48 47 45 44 +21 20 18 16 13 12 10 8 +84 85 88 90 92 93 +62 64 67 70 71 73 +33 34 37 40 41 42 +35 32 31 29 26 25 +9 10 13 15 16 18 20 23 +94 93 90 87 86 85 83 +12 9 8 6 5 3 2 +15 18 19 20 22 23 25 28 +96 94 93 90 88 86 85 +89 90 91 93 94 96 +77 76 74 73 70 +48 51 52 53 54 +32 29 27 26 25 +36 39 41 42 45 48 51 +48 50 52 53 54 56 59 +78 77 75 73 72 71 +82 81 78 77 74 73 72 71 +14 13 11 9 6 5 3 2 +69 72 75 77 80 82 83 +75 73 70 68 65 63 +91 89 87 85 82 81 78 76 +98 95 93 92 89 +74 72 69 67 64 62 61 +67 66 64 63 61 59 +73 71 69 68 66 +48 50 53 54 55 58 59 +38 41 43 46 47 49 50 +25 26 27 30 32 33 +62 64 66 67 69 71 72 +22 19 18 16 15 13 +40 38 36 35 34 32 +47 48 50 51 53 +26 29 31 33 35 38 39 +53 52 50 48 46 +57 58 59 62 65 +40 42 43 44 45 48 50 +10 12 14 17 20 +47 46 45 44 42 40 +70 71 73 75 76 78 81 +8 10 12 15 18 +50 51 52 54 56 58 59 +78 80 83 85 86 88 +89 86 85 84 83 81 +52 50 48 45 44 41 +54 51 48 47 46 +26 28 30 32 35 36 +56 59 61 63 66 69 70 +27 25 24 21 18 +79 80 81 84 87 90 93 +24 27 28 30 31 34 37 39 +9 10 13 15 17 +20 21 23 25 27 29 31 +42 39 36 33 31 30 28 27 +75 72 70 68 67 +38 37 34 31 28 +43 46 48 49 51 52 +38 39 41 43 45 +89 88 85 84 83 82 81 +42 39 38 35 33 31 +14 13 11 9 7 4 2 +39 41 42 43 45 46 48 +74 75 78 81 84 87 88 91 +65 68 70 71 73 +60 63 66 68 71 74 76 79""" + +print(count_safe_reports(data)) + + +# part 2 +def is_safe(report): + increasing = all(1 <= report[i+1] - report[i] <= 3 for i in range(len(report) - 1)) + decreasing = all(1 <= report[i] - report[i+1] <= 3 for i in range(len(report) - 1)) + return increasing or decreasing + +def is_safe_with_dampener(report): + if is_safe(report): + return True + for i in range(len(report)): + modified_report = report[:i] + report[i+1:] + if is_safe(modified_report): + return True + return False + +def count_safe_reports(data): + reports = data.strip().split('\n') + safe_count = 0 + for report in reports: + levels = list(map(int, report.split())) + if is_safe_with_dampener(levels): + safe_count += 1 + return safe_count + +data = """45 47 48 51 54 56 54 +76 79 81 84 84 +30 32 35 36 38 40 44 +72 74 77 78 85 +54 55 58 57 60 +61 64 67 66 68 67 +5 7 6 9 12 14 16 16 +82 83 84 82 85 88 91 95 +38 40 43 46 49 47 53 +23 26 28 31 34 35 35 36 +74 75 78 80 81 81 79 +11 13 16 17 18 18 20 20 +20 21 22 23 23 27 +63 64 64 65 68 71 73 79 +44 47 49 53 55 56 58 59 +81 82 84 87 88 92 89 +32 35 38 40 44 44 +53 55 59 60 62 64 65 69 +53 55 56 58 62 67 +57 59 62 68 71 73 74 75 +22 24 25 30 33 35 38 36 +15 17 20 25 28 30 32 32 +83 85 88 94 98 +74 77 78 80 87 92 +57 55 58 61 63 64 65 67 +74 71 73 74 75 73 +32 31 34 35 35 +35 32 34 36 38 40 42 46 +35 32 33 34 36 41 +69 67 66 67 70 71 74 75 +93 91 89 91 94 93 +95 93 92 94 96 96 +23 22 21 22 23 24 28 +27 24 25 26 28 26 29 36 +86 84 86 86 88 +2 1 2 3 3 6 9 7 +35 33 35 35 36 36 +15 13 14 14 16 18 19 23 +73 70 70 71 78 +21 20 23 25 28 32 33 35 +27 25 27 28 32 34 31 +40 39 40 44 44 +67 64 67 71 75 +31 28 29 32 33 37 44 +9 8 11 14 17 19 25 28 +42 41 46 49 51 50 +22 21 26 28 31 33 36 36 +20 19 26 28 32 +32 29 30 37 40 43 48 +20 20 23 25 28 31 32 35 +69 69 72 75 76 75 +51 51 53 54 54 +46 46 47 48 49 53 +72 72 75 76 77 78 80 85 +53 53 54 52 54 +79 79 78 79 78 +72 72 75 73 75 75 +47 47 49 52 54 51 55 +19 19 20 18 21 26 +84 84 85 85 88 91 93 94 +29 29 29 31 33 36 33 +15 15 17 18 21 21 21 +61 61 61 64 67 71 +62 62 63 64 64 70 +64 64 67 71 72 75 77 79 +60 60 63 67 70 68 +76 76 79 81 85 87 88 88 +20 20 23 26 28 31 35 39 +29 29 33 35 42 +25 25 30 32 35 +50 50 52 59 60 62 60 +60 60 61 63 68 69 69 +81 81 83 86 87 92 96 +68 68 73 76 81 +21 25 26 28 31 32 35 38 +38 42 43 44 45 43 +35 39 42 44 46 46 +19 23 24 26 28 29 33 +54 58 60 63 65 67 73 +33 37 38 40 42 39 42 44 +65 69 70 67 68 65 +9 13 10 13 13 +78 82 79 81 83 87 +34 38 40 38 40 41 48 +15 19 19 21 24 +36 40 42 42 39 +4 8 9 9 9 +52 56 57 60 61 61 65 +50 54 56 57 57 60 66 +26 30 32 36 37 +9 13 16 20 22 23 20 +55 59 61 65 65 +45 49 50 53 57 60 63 67 +74 78 82 84 90 +41 45 50 53 56 +72 76 82 83 85 82 +1 5 11 12 12 +72 76 79 81 82 89 93 +54 58 64 65 70 +66 72 74 77 79 81 84 87 +47 53 55 57 60 62 59 +71 78 79 81 82 84 84 +52 57 59 62 64 65 69 +59 64 67 69 71 74 76 83 +78 83 85 82 83 85 86 89 +27 32 34 37 40 37 35 +37 42 40 41 44 44 +44 51 54 51 53 57 +18 24 27 30 32 31 36 +57 63 66 68 68 69 71 72 +65 70 70 71 73 72 +32 37 37 39 42 42 +43 50 52 52 55 58 61 65 +20 26 28 28 29 30 33 38 +50 55 59 62 64 65 66 +44 51 52 56 57 58 61 59 +12 17 18 21 25 26 28 28 +2 9 11 15 19 +61 68 72 73 78 +17 22 28 30 33 +58 64 67 72 74 71 +72 78 79 85 88 90 90 +69 74 76 83 85 89 +24 31 34 35 36 42 49 +22 19 16 14 12 10 9 12 +74 72 70 67 66 66 +42 40 39 36 32 +95 93 92 91 85 +70 68 67 66 65 67 66 63 +82 79 77 74 77 74 77 +74 72 70 71 68 68 +97 95 94 96 93 91 87 +13 11 9 10 8 2 +13 10 8 8 6 4 +80 78 75 75 73 70 72 +64 63 63 60 60 +54 51 50 50 46 +35 32 29 28 28 27 21 +87 85 81 80 78 +27 25 22 18 17 14 17 +94 92 88 85 82 79 78 78 +19 16 15 11 10 7 3 +46 44 42 41 37 34 29 +54 52 49 44 43 41 40 +29 27 26 20 21 +97 95 92 85 85 +55 54 52 47 46 42 +32 31 28 26 23 21 16 9 +43 44 42 40 39 38 +14 15 14 12 11 10 13 +48 50 47 46 46 +90 93 90 87 85 82 78 +78 80 77 74 72 69 68 62 +32 35 37 35 32 29 28 26 +15 16 17 15 14 13 16 +62 65 63 65 65 +75 77 75 78 74 +4 7 5 7 6 1 +98 99 96 93 93 90 +52 55 55 54 57 +76 79 79 78 75 75 +75 77 74 74 73 70 66 +21 23 22 21 21 19 17 12 +79 81 80 76 75 +69 71 69 65 63 61 59 60 +71 73 71 70 69 65 64 64 +59 61 59 56 54 50 46 +86 89 85 84 83 77 +53 55 54 48 47 44 42 39 +13 16 15 14 12 5 6 +63 64 63 60 54 52 52 +55 56 54 47 43 +33 36 33 32 27 22 +30 30 28 27 25 24 21 19 +14 14 12 11 10 12 +34 34 32 31 30 27 24 24 +18 18 17 16 12 +21 21 19 16 10 +26 26 27 24 21 20 +68 68 67 66 64 66 63 64 +77 77 80 78 76 73 73 +71 71 73 71 69 66 65 61 +25 25 24 23 21 19 20 15 +46 46 46 45 44 41 38 37 +73 73 72 70 68 68 67 68 +54 54 54 53 51 49 49 +47 47 47 46 44 43 39 +72 72 70 69 67 67 62 +93 93 90 89 85 82 81 78 +54 54 53 49 47 48 +24 24 20 19 19 +93 93 89 87 83 +30 30 28 24 22 20 14 +97 97 90 88 87 +76 76 71 68 67 66 65 66 +81 81 75 72 72 +50 50 45 42 41 37 +75 75 69 67 61 +49 45 42 41 38 36 +56 52 50 49 46 45 47 +31 27 24 22 19 18 18 +42 38 37 34 33 30 26 +77 73 71 70 67 65 63 58 +36 32 29 26 24 23 25 22 +46 42 39 41 43 +85 81 82 80 78 78 +49 45 43 45 41 +63 59 62 59 54 +91 87 85 85 82 +68 64 62 59 59 61 +9 5 5 4 4 +74 70 68 68 67 63 +25 21 19 18 16 13 13 7 +69 65 64 60 57 54 +68 64 60 59 58 57 60 +94 90 89 87 85 84 80 80 +28 24 20 18 16 12 +26 22 20 16 11 +95 91 89 83 80 +36 32 29 28 23 24 +82 78 75 70 70 +58 54 49 47 44 40 +52 48 47 45 39 32 +98 93 92 90 89 86 84 +32 25 23 20 18 15 17 +26 19 18 15 14 13 10 10 +33 28 26 23 20 18 15 11 +84 78 75 74 73 70 69 64 +86 79 78 76 74 77 74 +73 67 65 62 63 64 +90 84 81 83 83 +94 87 86 84 87 83 +40 33 32 30 33 32 29 24 +25 19 18 18 15 14 +86 80 79 79 78 77 76 77 +10 4 3 3 3 +55 48 48 47 43 +98 92 91 90 87 87 81 +21 16 12 11 9 7 4 2 +27 22 19 15 14 11 12 +22 17 13 12 10 10 +97 90 89 86 82 81 77 +99 94 91 87 82 +72 67 64 63 62 55 53 +63 56 54 53 52 51 44 46 +46 39 36 33 31 26 26 +48 42 37 35 31 +27 20 14 13 11 8 1 +15 17 18 21 23 25 26 24 +65 68 71 74 77 80 81 81 +23 26 28 29 31 32 36 +84 86 87 90 92 93 98 +89 90 91 94 96 95 96 +24 25 26 28 25 26 25 +34 37 34 37 37 +24 26 29 28 32 +72 74 72 73 75 80 +91 93 93 94 97 +21 23 25 25 22 +29 32 35 37 37 37 +52 54 54 56 57 61 +21 23 23 24 30 +16 18 19 23 26 28 29 32 +81 84 88 89 91 94 95 92 +55 57 61 63 63 +77 79 80 82 84 87 91 95 +18 20 21 24 28 31 34 40 +22 23 26 32 35 +29 32 33 35 36 41 38 +25 28 29 31 33 34 39 39 +1 4 9 12 16 +31 33 34 41 44 51 +90 87 89 90 92 93 95 96 +32 30 31 33 31 +85 82 83 85 88 90 90 +76 73 76 78 80 81 82 86 +26 25 27 30 33 35 38 43 +66 64 67 69 71 70 73 +56 53 52 54 57 60 59 +78 75 73 74 74 +7 5 7 5 9 +57 55 53 55 58 61 64 71 +78 76 77 77 79 82 +54 52 52 54 51 +53 50 53 53 53 +88 86 89 91 92 94 94 98 +85 83 83 85 86 92 +6 3 7 9 12 14 +17 16 18 22 24 26 23 +20 17 20 23 24 28 30 30 +58 56 58 59 63 67 +8 5 9 10 17 +77 74 75 77 78 80 87 89 +82 81 82 84 85 87 94 92 +81 78 79 84 84 +60 58 60 61 64 71 75 +66 63 65 71 76 +62 62 65 68 70 72 +22 22 24 26 24 +16 16 18 21 21 +30 30 33 36 38 42 +46 46 47 50 51 52 59 +3 3 4 2 4 6 9 11 +15 15 12 14 16 17 19 17 +32 32 35 34 34 +92 92 95 92 93 94 98 +73 73 70 73 76 83 +18 18 18 21 22 +39 39 42 42 43 41 +88 88 89 92 92 94 96 96 +27 27 27 30 32 36 +63 63 65 66 66 72 +31 31 35 38 39 40 41 +10 10 12 16 17 19 17 +38 38 42 43 45 45 +57 57 61 62 63 65 68 72 +11 11 14 18 21 23 24 31 +63 63 69 71 74 75 +8 8 13 16 15 +22 22 23 26 33 35 35 +7 7 10 13 16 21 25 +20 20 23 24 29 34 +79 83 86 88 91 93 +38 42 44 45 48 51 53 51 +36 40 42 43 45 45 +23 27 29 31 35 +69 73 74 76 81 +14 18 21 22 25 24 27 30 +36 40 37 38 40 42 40 +9 13 11 14 16 16 +73 77 75 78 82 +29 33 31 33 39 +23 27 30 30 32 34 +57 61 64 65 68 68 69 67 +16 20 20 23 24 26 26 +23 27 30 30 31 32 36 +72 76 76 79 86 +53 57 59 60 64 65 67 68 +63 67 71 74 71 +86 90 91 95 96 99 99 +62 66 69 73 77 +61 65 69 70 75 +23 27 30 36 39 40 41 42 +30 34 37 38 39 42 47 46 +50 54 56 61 61 +21 25 27 32 36 +22 26 27 33 36 38 45 +29 34 37 39 40 42 +31 36 38 39 40 43 46 43 +34 39 42 43 46 48 51 51 +29 35 36 37 40 43 46 50 +23 30 33 34 37 40 43 50 +90 95 96 93 95 +58 64 66 69 67 66 +29 34 37 40 37 40 43 43 +24 29 32 35 38 39 37 41 +11 18 17 19 20 27 +49 56 59 59 62 +87 93 96 97 97 96 +5 11 11 12 15 16 16 +45 50 50 51 53 57 +65 71 74 74 81 +35 42 46 47 48 51 54 +76 81 82 83 87 89 87 +2 7 8 11 15 17 17 +30 36 39 43 46 50 +48 53 54 56 60 63 64 70 +75 81 87 88 90 91 +27 32 34 36 41 39 +81 88 95 98 98 +32 38 45 46 49 52 53 57 +45 50 52 58 59 66 +75 72 69 67 68 +16 13 10 9 8 6 6 +96 95 94 91 88 87 83 +44 41 39 37 35 32 27 +34 32 33 30 27 +64 61 60 58 56 54 55 58 +56 55 54 57 54 51 51 +41 39 42 41 39 38 34 +26 25 24 26 25 19 +21 19 17 17 16 +89 86 85 84 83 83 80 83 +15 12 12 9 9 +52 49 47 47 43 +50 49 49 46 43 41 38 31 +97 95 94 92 91 87 86 +39 37 36 33 32 29 25 26 +77 76 73 72 70 67 63 63 +22 20 16 14 11 7 +34 32 31 28 24 23 16 +31 29 26 24 17 15 13 11 +81 79 77 70 67 65 66 +67 64 58 55 55 +22 19 17 14 12 11 6 2 +36 35 34 33 31 30 23 17 +14 15 12 10 7 +15 17 14 11 13 +3 6 5 4 3 3 +68 71 69 67 64 62 58 +34 37 35 32 25 +29 32 29 28 25 27 24 +20 21 24 22 20 19 21 +86 87 84 81 83 82 82 +16 19 17 14 13 11 13 9 +27 28 31 29 28 23 +61 62 62 59 56 55 54 +28 31 29 29 26 28 +78 79 79 76 73 70 70 +18 20 19 17 17 13 +40 41 40 40 38 36 35 28 +87 88 87 83 81 78 +41 44 41 40 39 35 33 35 +88 90 89 85 85 +25 27 23 22 19 18 14 +97 98 95 94 90 87 82 +90 93 87 85 84 82 79 +87 90 89 86 84 78 81 +67 70 65 64 61 61 +94 97 94 92 89 83 79 +57 59 57 52 46 +66 66 63 62 59 +39 39 36 35 32 29 32 +64 64 62 59 57 54 54 +27 27 26 24 21 20 16 +41 41 40 38 36 35 28 +78 78 76 73 70 68 70 69 +54 54 52 51 54 53 50 52 +55 55 54 51 54 53 53 +30 30 29 32 31 27 +97 97 96 99 98 93 +86 86 86 83 80 78 75 72 +93 93 91 89 89 90 +97 97 97 95 95 +62 62 60 57 57 56 52 +75 75 73 73 71 69 62 +50 50 46 44 41 40 +80 80 79 75 73 71 68 69 +38 38 36 33 29 29 +98 98 95 91 87 +78 78 75 73 69 68 63 +84 84 82 79 76 74 67 66 +19 19 16 10 8 11 +32 32 25 22 20 19 16 16 +23 23 22 21 19 13 10 6 +80 80 73 72 71 68 62 +81 77 75 73 72 71 70 69 +65 61 60 58 61 +17 13 10 8 8 +90 86 83 81 77 +69 65 63 62 61 55 +46 42 39 36 38 35 34 +58 54 53 55 56 +80 76 73 76 74 74 +63 59 57 54 53 56 54 50 +45 41 43 42 35 +23 19 19 16 14 +55 51 50 49 49 48 47 48 +96 92 90 87 84 81 81 81 +86 82 80 77 77 74 70 +95 91 90 90 84 +44 40 38 37 36 32 29 +95 91 87 85 82 85 +96 92 91 87 85 85 +66 62 59 55 51 +40 36 32 31 29 27 22 +77 73 71 68 62 61 58 55 +87 83 81 79 73 72 71 74 +52 48 47 41 38 36 36 +88 84 81 76 74 71 67 +89 85 82 79 73 70 63 +87 80 77 75 72 71 +18 12 11 9 7 6 9 +98 92 89 88 88 +78 73 70 69 66 63 60 56 +41 35 32 30 29 23 +39 33 31 28 30 29 +69 64 65 62 64 +59 54 51 52 51 49 47 47 +69 62 64 61 57 +54 48 45 42 41 43 41 34 +60 53 50 48 45 44 44 41 +52 46 46 45 48 +37 30 27 27 24 24 +91 84 84 82 80 76 +94 87 86 83 83 76 +38 32 28 25 23 20 19 17 +17 11 7 6 4 5 +65 58 57 55 52 48 47 47 +60 55 51 48 44 +63 58 55 52 50 46 43 36 +37 30 28 22 19 +96 89 87 81 78 79 +24 18 17 16 14 9 6 6 +40 33 28 25 23 21 20 16 +67 60 57 55 53 47 45 38 +48 50 53 56 57 60 62 59 +47 48 50 52 55 57 57 +34 35 37 38 41 42 45 49 +59 60 61 63 64 66 73 +42 45 47 50 49 51 53 +18 21 23 25 23 24 23 +30 33 32 33 36 38 39 39 +48 49 52 55 58 56 57 61 +54 57 56 57 62 +16 18 19 22 22 24 +74 77 80 81 82 82 79 +17 19 19 22 22 +27 29 31 32 32 33 36 40 +30 31 31 33 34 37 38 45 +77 80 81 82 84 88 89 +56 58 60 61 65 63 +86 88 92 95 95 +58 59 60 61 65 67 71 +55 57 58 62 64 66 73 +39 41 42 49 50 52 55 +8 11 18 21 22 24 26 24 +32 34 40 41 42 42 +35 36 38 41 48 51 55 +63 65 71 73 76 82 +89 88 89 91 92 94 +34 33 36 37 35 +65 64 65 66 69 70 71 71 +24 23 24 26 27 31 +10 9 12 13 14 17 20 25 +47 44 45 46 47 46 49 +51 48 50 47 44 +40 38 39 36 38 38 +75 73 74 71 73 77 +47 46 49 50 47 48 50 56 +12 10 10 12 15 17 +28 26 27 27 30 27 +10 7 10 10 11 13 15 15 +85 84 84 85 89 +35 32 33 35 35 38 44 +70 68 71 73 74 76 80 81 +75 72 76 77 79 80 83 82 +86 84 85 89 92 95 95 +12 9 11 13 16 17 21 25 +6 4 6 10 16 +36 35 37 40 43 50 53 56 +68 65 66 68 71 77 74 +85 83 86 93 95 96 97 97 +25 23 25 27 34 35 38 42 +41 38 45 47 48 54 +46 46 47 49 51 52 53 54 +30 30 33 34 36 37 36 +43 43 45 48 50 51 51 +87 87 89 92 96 +1 1 4 7 8 11 18 +91 91 94 96 99 97 99 +48 48 51 54 53 52 +73 73 76 77 80 82 80 80 +66 66 67 68 70 67 71 +72 72 70 71 77 +7 7 10 13 13 14 +73 73 73 76 79 77 +51 51 52 55 57 57 59 59 +15 15 16 16 20 +70 70 73 76 79 82 82 87 +19 19 23 26 27 29 +40 40 44 46 43 +6 6 9 13 15 18 18 +16 16 20 23 25 27 30 34 +72 72 75 77 79 83 90 +43 43 46 53 54 57 58 +5 5 6 11 13 10 +10 10 13 15 21 21 +29 29 30 37 39 43 +71 71 78 81 87 +45 49 50 51 52 54 +21 25 28 29 32 29 +38 42 43 46 46 +10 14 15 18 19 20 21 25 +10 14 17 18 19 22 23 29 +8 12 11 14 17 19 21 +58 62 61 62 61 +32 36 33 35 35 +1 5 6 4 8 +69 73 74 75 72 75 81 +54 58 59 59 61 +54 58 58 59 60 62 59 +61 65 65 68 71 74 74 +84 88 89 89 93 +51 55 56 56 58 59 60 65 +10 14 17 21 22 +13 17 20 21 25 26 25 +45 49 53 54 54 +80 84 88 90 91 94 98 +19 23 24 26 27 28 32 37 +42 46 48 54 55 +49 53 58 59 62 65 62 +60 64 70 73 75 75 +53 57 60 67 68 72 +27 31 33 35 41 44 51 +20 25 27 28 29 30 33 34 +37 42 45 46 44 +42 49 51 54 55 58 59 59 +36 42 44 47 50 52 56 +11 18 21 22 29 +77 82 79 81 82 +9 14 15 12 9 +37 44 41 43 43 +30 35 33 35 38 39 43 +45 52 53 55 57 59 58 64 +26 31 31 34 36 39 41 +38 43 44 45 47 50 50 49 +10 16 18 18 20 20 +18 24 25 28 29 29 31 35 +52 59 61 64 67 67 68 75 +18 25 26 29 32 33 37 38 +21 28 32 35 33 +24 31 35 36 38 41 41 +47 54 55 59 63 +60 66 70 71 74 75 80 +65 71 72 79 82 85 87 +59 65 66 72 70 +33 38 39 42 47 50 50 +22 29 30 31 33 34 39 43 +5 10 11 18 20 21 26 +91 89 88 85 84 85 +75 73 71 69 69 +23 21 19 17 15 13 12 8 +52 50 48 45 43 38 +34 33 32 31 32 29 26 +41 38 40 38 39 +72 70 69 72 72 +18 15 17 16 13 10 6 +86 85 82 83 77 +28 25 22 19 18 17 17 14 +95 92 92 91 89 91 +80 77 76 76 73 73 +23 20 18 18 17 15 14 10 +60 58 56 56 49 +23 21 17 15 14 +33 30 26 25 23 20 23 +97 96 93 89 89 +51 50 48 45 44 40 36 +84 82 80 79 75 72 71 64 +76 75 68 67 64 62 +97 94 88 86 89 +89 87 81 78 77 77 +97 94 91 86 83 81 80 76 +17 15 13 12 7 2 +24 27 25 23 20 19 17 16 +28 30 27 24 23 21 18 21 +8 9 8 7 6 5 2 2 +51 54 51 49 46 42 +41 43 41 38 36 31 +54 56 55 54 53 56 53 +68 71 69 70 67 65 67 +6 9 8 9 8 6 4 4 +51 53 51 49 47 49 48 44 +40 43 45 43 42 36 +49 50 50 47 45 42 40 38 +4 7 6 4 4 2 3 +98 99 99 98 98 +53 56 54 54 50 +81 82 79 79 77 71 +88 89 86 82 80 +55 58 56 54 51 47 44 45 +58 61 58 57 55 52 48 48 +28 29 28 24 23 19 +56 59 58 54 47 +85 88 86 79 76 +95 98 97 90 88 86 88 +52 53 50 49 47 42 41 41 +60 63 60 54 52 50 46 +55 57 56 55 49 48 45 39 +54 54 51 48 45 43 41 40 +60 60 57 54 53 55 +60 60 59 58 55 53 51 51 +44 44 41 40 36 +81 81 78 77 74 71 70 65 +46 46 43 46 44 +67 67 66 64 65 63 66 +74 74 72 69 66 64 67 67 +61 61 60 61 59 58 54 +48 48 46 48 47 44 39 +25 25 25 24 23 +88 88 88 86 88 +19 19 19 17 14 11 9 9 +70 70 67 65 65 64 60 +17 17 14 12 12 11 8 2 +99 99 96 92 90 +56 56 54 52 48 47 50 +80 80 77 73 72 69 69 +28 28 26 22 20 17 13 +70 70 66 64 58 +93 93 88 86 83 81 79 77 +40 40 34 31 34 +47 47 45 42 39 34 34 +89 89 82 79 78 74 +98 98 97 96 90 87 84 79 +47 43 41 38 35 34 32 29 +63 59 58 55 53 50 51 +80 76 74 71 68 65 65 +47 43 42 41 39 38 37 33 +84 80 77 75 74 67 +87 83 80 78 81 79 +18 14 16 13 16 +31 27 30 28 27 27 +15 11 8 11 9 6 2 +22 18 17 20 17 11 +52 48 47 44 44 41 40 +39 35 35 32 29 27 26 29 +50 46 45 45 43 42 40 40 +91 87 85 85 81 +56 52 50 50 43 +25 21 19 18 14 13 +78 74 70 69 67 69 +21 17 16 15 13 9 9 +59 55 54 51 47 43 +96 92 90 88 84 83 82 77 +49 45 40 37 35 +53 49 43 42 41 44 +50 46 44 38 35 35 +56 52 46 45 43 41 37 +46 42 40 37 30 25 +63 58 56 54 51 48 47 45 +55 50 49 48 47 44 47 +26 21 18 15 15 +65 58 57 55 53 49 +94 89 87 85 84 81 75 +65 59 57 55 56 55 +12 5 4 5 6 +24 17 20 17 17 +17 12 9 7 6 8 7 3 +44 37 39 36 30 +19 12 12 9 7 4 3 +99 94 92 89 87 87 90 +18 13 12 12 12 +65 60 60 58 54 +27 20 17 16 14 12 12 5 +22 15 11 10 8 +67 61 57 55 57 +37 32 29 28 25 21 21 +94 87 83 82 79 78 75 71 +60 54 51 47 44 38 +57 52 49 46 40 38 +84 79 78 73 70 72 +46 39 36 31 30 30 +85 80 79 73 71 67 +52 46 45 39 38 37 32 +76 78 76 74 69 68 66 66 +93 93 92 91 88 86 83 84 +2 1 3 5 8 6 +77 71 69 67 63 61 58 59 +17 10 7 6 6 +93 94 95 96 98 99 98 +66 71 72 74 78 81 +10 13 17 18 21 23 23 +48 48 45 43 37 30 +26 28 28 29 27 +93 91 90 92 95 95 +75 72 71 68 66 65 62 56 +36 40 42 43 46 45 44 +29 33 34 35 35 37 38 39 +20 25 26 28 30 32 36 34 +2 2 4 5 9 12 12 +59 63 66 70 70 +95 95 98 96 94 92 87 +63 56 54 52 55 49 +4 8 11 18 20 17 +54 56 53 51 48 50 47 +99 96 93 91 90 90 88 88 +39 39 41 43 45 49 +23 23 29 31 34 35 +62 58 55 53 46 41 +56 59 57 55 55 54 52 48 +47 50 53 54 55 57 58 +18 16 14 13 10 9 +26 29 31 34 36 39 +61 59 57 55 54 52 49 +34 35 37 39 41 42 44 +54 57 58 59 61 64 66 67 +24 23 22 19 16 15 +63 65 66 67 70 71 72 73 +97 96 93 90 87 84 81 +84 82 80 79 76 74 72 71 +21 23 24 26 28 30 32 33 +77 75 74 72 69 67 66 64 +65 67 70 72 75 77 79 +21 22 24 25 27 28 30 +77 79 81 82 83 +52 51 48 45 42 +21 20 17 15 14 11 10 +50 47 46 43 40 37 34 +50 52 53 56 59 61 63 +74 75 76 77 80 83 +85 86 87 89 90 92 94 96 +16 14 13 12 9 7 5 4 +92 89 86 85 82 81 78 +37 36 33 31 30 27 26 25 +55 53 51 50 48 46 44 41 +4 6 8 11 14 16 17 +31 34 36 37 40 +21 22 25 28 29 +26 28 30 33 35 38 41 +49 46 44 41 40 39 38 36 +66 67 69 72 75 +72 69 66 65 64 61 59 56 +88 91 92 95 98 +11 14 16 19 20 23 +64 62 61 59 58 56 55 53 +82 83 85 86 87 89 92 94 +91 88 85 84 82 +94 93 90 87 84 82 79 +11 14 15 16 19 +39 36 35 32 30 27 24 21 +79 80 81 84 87 +49 50 53 56 59 62 +41 40 39 38 37 +15 14 12 9 6 5 4 1 +9 11 13 15 18 19 20 +67 68 71 74 77 +86 89 92 93 94 97 98 +9 11 13 15 17 19 +81 83 85 88 91 92 +54 52 50 48 47 45 43 +25 24 22 20 19 +91 89 86 83 80 79 77 75 +22 21 19 18 15 14 +64 63 61 60 58 55 +14 17 19 22 24 26 +52 54 57 59 62 65 +11 12 14 17 20 21 +90 89 88 86 85 84 81 +81 82 84 87 89 92 93 +55 53 52 49 47 44 43 +28 26 24 23 21 19 18 17 +83 80 79 78 76 74 71 +95 92 89 86 83 +69 72 74 76 77 +51 54 57 59 62 64 67 +13 14 15 16 19 21 24 +47 46 44 43 41 40 37 36 +75 74 71 68 67 66 64 +30 33 34 36 38 40 41 43 +21 22 23 26 29 +32 35 36 37 38 40 43 45 +11 12 13 16 18 19 20 21 +20 18 16 15 13 10 9 8 +36 39 42 44 46 47 +53 51 49 47 44 43 40 +82 80 78 75 74 71 70 67 +26 25 22 21 20 19 18 17 +62 65 67 68 69 70 71 72 +85 84 81 79 78 77 75 74 +36 38 41 42 45 48 +56 54 53 50 49 48 +80 79 76 73 72 70 68 67 +40 38 37 34 31 +97 96 94 92 89 86 83 80 +62 59 58 56 54 52 +23 26 28 29 30 33 +12 15 17 18 21 22 25 +73 70 69 66 64 61 +34 32 30 29 26 23 +99 98 96 94 92 +67 70 72 74 75 76 +57 60 62 63 66 69 70 +76 74 72 69 68 67 66 63 +5 7 10 11 13 15 +36 38 41 44 46 +94 91 88 85 84 83 82 80 +13 15 16 17 19 22 25 26 +85 87 88 89 90 93 +19 17 16 15 13 10 8 5 +15 17 20 23 24 26 29 32 +93 92 91 88 85 83 80 +27 29 30 31 32 33 +68 70 71 72 74 77 80 +22 20 17 15 13 12 9 +23 20 18 15 14 12 +56 53 52 49 47 +19 16 14 11 10 +32 29 28 27 25 24 +98 96 93 90 88 +86 88 89 91 92 +69 66 65 62 60 59 +19 20 23 25 28 +56 57 60 63 65 68 70 72 +50 47 46 44 42 40 39 38 +54 53 52 50 49 46 44 +5 6 8 9 12 13 16 19 +38 41 43 44 47 50 +37 36 35 33 31 30 27 26 +73 76 78 81 83 84 85 +32 29 28 25 24 21 18 16 +84 86 87 89 91 94 95 +37 40 43 45 48 50 51 54 +91 93 94 96 97 +20 22 24 27 30 +56 59 60 63 64 +58 61 62 65 68 69 +43 40 37 36 34 31 28 26 +33 36 37 38 39 42 +49 47 45 43 42 41 39 38 +82 84 87 89 90 93 +26 23 20 18 17 +71 70 69 67 64 63 +67 69 72 73 74 +99 97 96 93 92 +38 41 42 43 44 45 48 +12 15 16 19 22 24 +72 74 76 79 82 84 85 87 +97 96 93 91 90 +55 52 50 48 47 46 +16 14 12 11 9 7 6 5 +99 96 94 91 88 87 85 83 +87 86 84 82 81 +13 14 15 16 19 21 23 +38 41 42 44 47 48 +19 18 17 16 13 10 +29 30 32 33 35 38 39 +35 34 33 31 30 +86 87 88 90 93 95 +35 32 31 29 27 +68 67 64 61 59 +80 77 74 72 71 +71 70 69 66 65 +15 17 18 19 20 21 +42 45 47 50 51 +33 31 29 28 27 25 24 +73 72 71 69 68 67 65 64 +43 46 48 51 53 54 +39 42 45 48 51 53 +53 52 50 49 47 +47 50 51 54 56 +26 29 30 33 36 37 40 42 +39 36 34 33 30 27 24 +65 66 68 70 72 75 76 77 +51 53 56 57 59 60 62 63 +53 52 50 48 47 45 44 +21 20 18 16 13 12 10 8 +84 85 88 90 92 93 +62 64 67 70 71 73 +33 34 37 40 41 42 +35 32 31 29 26 25 +9 10 13 15 16 18 20 23 +94 93 90 87 86 85 83 +12 9 8 6 5 3 2 +15 18 19 20 22 23 25 28 +96 94 93 90 88 86 85 +89 90 91 93 94 96 +77 76 74 73 70 +48 51 52 53 54 +32 29 27 26 25 +36 39 41 42 45 48 51 +48 50 52 53 54 56 59 +78 77 75 73 72 71 +82 81 78 77 74 73 72 71 +14 13 11 9 6 5 3 2 +69 72 75 77 80 82 83 +75 73 70 68 65 63 +91 89 87 85 82 81 78 76 +98 95 93 92 89 +74 72 69 67 64 62 61 +67 66 64 63 61 59 +73 71 69 68 66 +48 50 53 54 55 58 59 +38 41 43 46 47 49 50 +25 26 27 30 32 33 +62 64 66 67 69 71 72 +22 19 18 16 15 13 +40 38 36 35 34 32 +47 48 50 51 53 +26 29 31 33 35 38 39 +53 52 50 48 46 +57 58 59 62 65 +40 42 43 44 45 48 50 +10 12 14 17 20 +47 46 45 44 42 40 +70 71 73 75 76 78 81 +8 10 12 15 18 +50 51 52 54 56 58 59 +78 80 83 85 86 88 +89 86 85 84 83 81 +52 50 48 45 44 41 +54 51 48 47 46 +26 28 30 32 35 36 +56 59 61 63 66 69 70 +27 25 24 21 18 +79 80 81 84 87 90 93 +24 27 28 30 31 34 37 39 +9 10 13 15 17 +20 21 23 25 27 29 31 +42 39 36 33 31 30 28 27 +75 72 70 68 67 +38 37 34 31 28 +43 46 48 49 51 52 +38 39 41 43 45 +89 88 85 84 83 82 81 +42 39 38 35 33 31 +14 13 11 9 7 4 2 +39 41 42 43 45 46 48 +74 75 78 81 84 87 88 91 +65 68 70 71 73 +60 63 66 68 71 74 76 79""" + +print(count_safe_reports(data)) \ No newline at end of file diff --git a/src/solution_03.py b/src/solution_03.py new file mode 100644 index 0000000..81f64ed --- /dev/null +++ b/src/solution_03.py @@ -0,0 +1,70 @@ +import re + +def extract_and_multiply(memory): + # Regular expression to match valid mul(X,Y) instructions + pattern = re.compile(r'mul\((\d+),(\d+)\)') + + # Find all matches in the memory + matches = pattern.findall(memory) + + # Calculate the sum of the results of the multiplications + total_sum = sum(int(x) * int(y) for x, y in matches) + + return total_sum + +# Example corrupted memory +memory = """mul(498,303);when()}!(%mul(846,233)-,what()($where()how():}mul(334,117)]~>?,<,%^,mul(886,213)/:from()?-how()~}mul(343,197) mul(33,616)~%*~why()^*-from()mul(757,847){{who()why()#mul(927,553)>-?&!-@[mul(589,387)what():[?mul(865,934)#/ (why()+from()when();mul(804,792)-where(144,652)(mul(620,348);];]$mul(584,827):who()^%from()mul(381,633)why()@ when()where()?<;@#do()'< mul(643,715)@@#/>&-@?when(295,120)mul(465,37))]#mul(742,669)?mul(519,650)mul(546,337)@what(),{'^mul(769,202)^mul(808,254)/#why()@~mul(71,204)from();mul(150,335)[mul(302,220)>[$*~don't()mul(385,231)what()?*mul(852,324)#$}<{mul(838,178)<;+}@/*mul(579,121)select()why()*{{:mul(810,214)don't(){what()/)who()*%mul(273,606)&]from()@:why()@mul(788,896) }& don't()select()mul(568,713)$$'from()@+mul(390,36):@who();&from()mul(984,787)/mul(209,744)why()%[:what()mul(929,15)+how() who()@what()$!mul(751,670)$]from()mul(821,742)why()}:/why()>mul(445,950)>:mul(174,953)-where()how()+:mul(529,661)+{+@@why()##mul(513,442)how(827,318)}~}where()#@-:mul(941,152)~[,+{&@why()+mul(468,787)how()!$from()^^>%~from()mul(497,717)mul(930,672)mul(313,480)^%where()~-))#^select()mul(407,85)<#who()mul(776,808)~select()$?@,@mul(420,163)mul(666,491)$:+do()mul(823,835){who()?,mul(728,808))[who()/^<;select()~:mul(38,577)+>mul(985,224):/what()where()[%*what()mul(31,270)<>when()[?!!mul(895,903)%who()select()>/when()!mul(367,623)'#+mul(362,189)&from()'#$':$?{mul(571,203)what()mul(615,719)what(),what() )^mul(663,163)$@;&'select()mul(93,614)~(from()mul(490,261)#mul(530,933)}[from()];don't()$%what()%~'&'what()mul(134,307)}from()%;&why(65,575)?/mul(657,957)where()mul(969,590))how()when()how(){mul(534,951)@},mul(141,80<'mul(573,576)why()mul(952,460from()+#;;mul(36,336)&don't()&}how()why()select()^mul(267:+(+#'~mul(654,481)--mul(17,334)'!*why())how();-$mul(886,695)mul(954,476)where()!mul(73,181)?@mul(326,125)!@{)*mul(945,965)what()-select()~^who(884,691)how(846,544)mul(346,328)!<^~+-when(871,168):-mul(653,891why()when()how()why()mul(603,626)~+when()where(639,311),#mul(527,536)how()]%{/!-do()'@mul(368,63) +how()@]]from()select(976,708)?;what())mul(649,499)}&?how(792,889)~who()why(){do()mul(569,139)^[mul(701,8)why()!#[>'who()from()%mul(288,867)mul(706&*~>?select()@mul(819,789)(@%mul(180,466)from()[why()}&}mul(766,269)}@mul(827,216);???!mul(670,899)!-[%(<@^do()*}mul(475*mul(462,887)'@[])[?&mul(754,83)%]%(~from()}when()?mul(379,965)@why()mul(63,665)+[-{mul(543,711);>?/)(&mul(535,403)?')(mul(603,306)* when())what()-*mul(22,75)#who()<:{where(780,74)]mulwho()'#from()~?how() ,{{+mul(576,621)why()why();mul^;+^'mul(977,718)}why()>'[~ mul(179,326)#[mul(735,639)where() when()/from()$mul(779,50)don't()'<:)'>:}mul(232,847){where()mul(63,282)>mul(737,540)why()+!>don't()when() ']what()#,mul(778,85)how()[mul(809,798)![ $where()%>' }]mul(587,975)-?# }-]mul(800,437)$mul{[mul(603,103)>-/#why()mul(285,453)who();+{@ when()]don't()+[what(730,765) mul(399,137)%]select()#<[^>mul(146,316)~][from() mul(687,295)mul(347,287)when()>!from()&mul);<when()+;{^mul(267,700){~,!]? how()mul(779,914)select()&>^/%?}>-$*^mul(387,58)^who()&mul(157,49)#?/mul(35,606)when()')from()?%mul(451,146)'(where()mul(977,491)mul(916,789))&#how()how()>don't()^*mul(437,605)[how() mul(626,940)^*%/mul(884,929)select()mul(84,192)mul(111,274)what()mul(95where()![[(who()[mul(593,249)]]@#when()why()-/mul(230,390)#~],(:mul(840,931)mul(421,658)from(653,680)>&mul(34,90)>when()&}:why()mul(956,881)!when())$^]@who()select()where()mul(94,737)from()who()mul(816,357)')^^mul(454,208)$&mul(136,496){$what()mul(897,490)>'mul(376,325){why(),%]#what()mul(953,618)+from()mul(378,46)mul(138,440)who()#where() >(from()#mul(708,59)&why()mul(830,439)mul(468,479)why()<$,~},mul(279,437)%([mul(276,252)-#$mul(596,842)from()mul(873,817)*{{from()#(%^mul(765,528)!<< what())^mul$how()}/what() +:mul(411,270,,({(]!mul(627,262)/how()**how()$''+mul(791,814);-;;:mul(990,764)}where())))&((!mul(5,111)~how()from()&,how()mul(492,492)from()[$,+) @(mul(999,416)$&who(959,257)&mul(722,457)@how()) ^>;)@{mul(221,679)?who()$+{-^*{mul(241,314)how()][!mul(940,32){$(~@'+>mul(453,515*;mul(215,275)~/[,why(21,55)(who()',>mul(567,83)mul(330,717)>#!mul(611,308)+&select()(})/mul(744what(424,184)?mul(377,16)):(<[@mul(757,897)#^mul(404,155)%don't()}what(573,178)what()+mul(204,894)%mul(34,307))mul(794,115) +)from()}mul(515,433)^mul(529,684)from()why()where()?mul(956,914)(])?[mul(645,179)+mul(400,263)from()select()&^*mul(422,526){~;what()/)#don't()*%!/(mul(326,211)*%@select()from()[~&mul(456{why()from(138,423)-^(&!?mul(995,210):;when()why()how()!mul(394,185)how()!~who() ^how()'where():mul(348,18)mul(194who()&~*~&{/%mul(505,325) *%mul(459,604)>)) ~ -where()~{mul(579,481)mul(135,794)-*mul(453,355)~/](![from()mul(443,346)mul*[,~%why()-{do()/when(43,713)mul(136,26){^when()why()'mul(108,341)[@?!',+@who()mul(195]{&@{?:how()what()select()don't():]]#mul;what()&?:mul(541,941),&;-what(75,560)who()what()?how()mul(314,260)!)mul(250,620)>#mul(612,209),#?;mul(661,597)/mul(563,594)when()!:!mul(683,595)*what()when())'how();@mul(287,255)how()/^mul(345,555) who()/when()mul(681,924) 'mul(189,542)'mul(102,360)why()!'how()-?;,mul(874,55)+:!>what()mul(538,354)**]~how()who()mul(277,851),where(802,203)<{(];'?mul(268,251)~{:]mul(139,820){^^[ /;when() what()mul(775,595)/,)^;&where(),mul(644,487)?(mul(590,599what()%-who(){mul(112,571){$mul'/#mul(835,137)$&(mul(201,460)how()from()*@where()mul(934,320),[what()where())? :don't()&+'mul(66,8)~ mul(465,911)]?how()what(),;/:*-don't()#:?where()$mul(951,775)from()%@{who()who()!mul(78,456)^[from(),mul(144,347)']where()#([ @[]mul(660,565)}}~mul(738,761)-mul(514,849)mul(648,439who()+<,*/when()!why()mul(904,440)^ select())!@-mul(442,126% #?{mul(47,20)%mul(113,81)/;&+{@mul(504,712);select() mul(720,642)when()*#who()<-'];;mul(821,613)?select()!>when(){mul ,mul(597,943)$-what()*when()where()-}select(){mul(999,17)select(230,593),% mul(920,227)>where()@!~(select()!*mul(301,278)mul(538,232*!/when()mul(283,204)'who() ]mul(861,903)what()? %{* <-mul(112,180)'?(!mul(121,398)']<~/mul(363,850)])from()mul<>?!!from()when()select()!mul(551,325)[where())-:{#)mul(114}}:,,mul(341,114)from()?why() from()# mul(611,400))what()% from()}/when()'mul(874,416)'@&~+]mul(916,295what()@why()how()>where()-^mul(988,626)select()#!)who()why()mul(597,791)};mul(160,184) from()~{;!where()mul(332,928)where()(#!/usr/bin/perl+^who()]:,~}select():mul(810,730)when()mul(312;&what(415,542)who(560,710)who()from()^mul(828,831)> }how(595,281)!why()*/:mul(70,967) +(do(){,-how()<(how()[{why()mul(16,675))+don't()!>-((&what()!mulwhere()+( mul(446,260)#+&how()}}when()who()/do()[,who()]>-~from(),mul(200,312);$mul(997,25);?where(203,706)&?}select(),mul(553,783)@^~mul(779,661)%)mul(252,997)what()from();%mul(439,801)select()#?')~;%}mul?why()+!mul(385,635)@)^):!*)how()mul(563,131)#&mul(720,10)~#<+]^!:@how()mul(24,633)~mul(103,646)mul(331,217)~#mulwhy()@-$> mul(288,357)how() when();;why()<+mul(513,580)?when(299,618)!<^-mul(318,287) }mul(88,924)mul(220,403mul(264,790)mul(78,811),,(/who()who()mul(978,770)[what()$)]#:%mul mul(57,890)'(mul(146,967)[<#%)^;how()]>mul(166,279)]mul(24,319)%;select()-!/don't()>:mul(858,696)mul(622,496)*{{-~why()how()what()-mul(973%}+> mul(904,891)*(:{%mul(618,932)&!~*mul(77,889)}%~{mul(206,797)select()what() who()+*what(499,999)?@@mul(114,405)(()where()}/){]}mul(841,73)@!where(581,676)]#from(879,459)}^mulhow()do()}select()~!~)[why(364,979)who(533,785)mul(839,475)[{;>)(@what()mul(597,209)-$-^select()mul(453+;:#:?&mul(972,784)what()#select()%/[select()[,how()mul(436,10)]!~)select() mul(982,995select()~/%(,do()#who()]!,/*mul(718,383)when()>^*mul(803,383)when(); mul(568,612)/from()from()}what(219,960)from()*don't()@@why();who()where()mul(222,279){ mul(758,766)what()who()!how(38,972)~;],select()/mul(974,879)!don't()mul(368,975)where()^$[^&] -{mul(153,172)what()&+)[mul(97,652)when(534,157)~,:where()do()%%@]?&when(435,925)what(){mul(155,627)?{;@#mul(466,775)(;mul(834,395)//>()-don't() $mul(329,300)<+&'@^mul(469,14)*&why(99,525)',mul(427who()*@< ?do()[>from()when()?#,'&:mul(585,898)mul(128,392)-(?[,where()'^where(575,788)+mul(378,473how() '$'#@who()from()how()?(//mul(768,590)when()-: ](where()who()(mul(716,399)/~)@mul(754,670)what()mul(656,266):(;%!]mul(595,874)why()%@<^?mul(702,835)(![&&/+%mul(421,278)}where()-%^'+mul(842,496)/?@:]mul(282,851)~@)how())mul(543,112))]+^)mul(133,862);#)when()who()why()when(58,966),,mul(513,202)@mul(716,648)(mul(793,735)what()]where()%+-/mul(359,127)-+}/mul(116,988)when()mul(153,16):'@$who():~-mul(441,603)'how(){ #why()%{{mul(877,856)select()who(777,457)select()from())how(345,367)from()mul(447,557)%/$-select(),when()+what()mul(189,616)what()}mul(822,616)mul(454,622)how()&who()&#do():> mul(353,679)^(@select()<;mul(414,440)why()+how()&,]#-&mul(402,532)-})~#$-!mul(883,415):<@]*from() mul(28,253){where()? what()select()~mul(259,972)-(]<}>when()from()$mul(650,381)~from()}from()who()>mul(72,307),who()where()?@{where()mul(706,447)from(671,711))~mul(601,925)} ;what()[mul(533,851~{&what()(@{<'where()mul(799,568)%where()mul$>select()[)#^:mul(414,93)]mul(16,757)&[who(),/mul(629,760)&''how(),from()mul(951,329)^mul(781,711):/',+'{%when();mul(661,844)/why()<^}#mul(337,134)!)mul(339,829)([how()+&~how(512,132)!;:mul(696,374))}/what()from()mul(640,944)'{*how()what(279,739)why(843,673)? &!where()mul(347,404)^?>!$&mul(316,524) when()]mul(875,937)$(@]$don't()/who():/]mul(833,846)who()mul(190,362))mul(183,740)how()}mul(14,502):why();why()'mul(341,888)mul(668,734)]/what())**&(do()how()*:select()}*:]mul(604{mul(123,983)#&why()mul(159,440)mul(437,830)~};'])[?mul(36,75)mul(836,766),?*select()who()mul(548,488)%--where(521,841))$]do():-from()*mul(355]<+>:mul(58,505)what()from(49,769)mul(108*]~>mul(131,644)?!from()mul(11,884):where()!;select();+[select()mul(358,741)(*?]do()(?{@^mul(117,14)^+;what()from()}mul(847,203)/who()where()from(567,960)when()how()%~'}mul(677,415)mul(91,507)when()*when()from()*(mul(935,477) from()@ mul(556,85)?)@mul(196,674)^;*+#$mul(531,124)!what()%select(){who()}';~mul(67,663)when()'?mul(205,527)@:+ ?:why() %mul(513,956/}:,'@+$who()-mul(963,914)@from()why()how(292,305)!from(980,892)mul(456,909)!who()<(*@select()&why()mul(947,805)who()how()^}mul(154,935)+?when()('};]>^mul(855,799){who()]+*{mul(823,352)*<$when()+)^&(do()mul(623,916)(['])^what(){select()mul(815,135)}mul(464,34)' ^)-^~where()where()mul(50,471)*{select()from() mul~:why()when()[why();%, }-where()#mul(184,632)~]+'select()}what()mul(675,164)mul(360,852)mul(875,801):where(811,851)mul(702,746)mul(29,632)[{^]-:!{ who(719,324)mul(720,687);:/[#*mul(431,415)mul(123,914]&?%$how()mul(655,184)]@?how()*$(-what()mul(323,687)mul(474,75);mul(846,335):%;do()~?where()~mul{}?%mul(446,300)^how(),<&from()#!#from()mul(423,746)how()what()don't()what()+*#:mul(268,185)@do()!>?~;@]mul(657,833) ,(who()-who()mul(415,876)]&#?@'!/&mul(437,971)^,+mul(884,392):mul(183,497)^from()mul(204,743)^'>}who()$;}mul(892,574)+ from()?$mul(922,854))select()#,+>where(),*mul(551,303)?}mul(261,657)?why()}why()when()%-mul(124,265!mul(979,380)/@select()}>why()+#mul(384,303)$,@@-mul[mul(479,548)-]#> ?:!do()how()@&mul(917,657{:$&mul(966,387)}what())[-]mul(183,849)^^who()&<,mul(669,375)mul(323,459)$%/from()~+}when()mul(789,390)'+mul(804,927)#who()mul(102,842)$$)how()from()select()][mul(380,252) )>when()where()how()who():#where(184,552)mul(244,943)$&$*}*-mul(727,613)(#why()}>mul(807,274)mul(577,489)mul(731,223)>where()/!]? %where()mul(359,604)/$;$+}mul(182,17)why()-how()mul(792,962)why()/{-(how()%'select()mul(997,718)/{mul(7,739)select();:mul(800,703)[when()' #~why()where()*mul(345,374)mul(308,927)how()%@how()mul(233,785)#{!select()mul(208,457)#from()}what()mul(347,911)where()from()@;(mul(492,896)&;?+, mul(948,682)+~when()}from()mul(930,691)[&]*((#mul(600,425){what()'{)@,where();:mul(844,671)~+)#,(mul(446,155)$%@/:mul(749,494)mul(24,97)where(6,997)&where()?why(449,637)mul(631,323))mul(192,700));/$]what()mul(820,765)who()(>%>mul(702,770)*-[;}(mul(438,245)@)]^/'#mul(554,294)!mul(34,410)where()$<#how(360,499)@#mul(585,680)<^};mul(295,437)where()] {+mul(607,28)why()#% do();mul(96,932)]why()+who(){<,[where()mul(271,645);^:{mul(411,161)]<>do()@';when() (mul(41,299)(!what()*select(387,698)$]mul(942,465)^?~what(),*?-'from()mul(70,415)why()'from()how()mul(682,699)!^-when()?when()#mul(473,999) {(~>^why()}mul(240,258)+why()&%mul(579,916)!(]((select(112,996)#($,mul(584,139)%""" + +# Calculate the result +result = extract_and_multiply(memory) +print(result) # Output should be 161 + + +import re + +def extract_and_multiply_with_conditions(memory): + # Regular expressions to match valid mul(X,Y) instructions and do()/don't() instructions + mul_pattern = re.compile(r'mul\((\d+),(\d+)\)') + do_pattern = re.compile(r'do\(\)') + dont_pattern = re.compile(r"don't\(\)") + + # Initialize variables + total_sum = 0 + enabled = True + + # Iterate through the memory string + i = 0 + while i < len(memory): + if do_pattern.match(memory, i): + enabled = True + i += len("do()") + elif dont_pattern.match(memory, i): + enabled = False + i += len("don't()") + else: + match = mul_pattern.match(memory, i) + if match and enabled: + x, y = map(int, match.groups()) + total_sum += x * y + i += len(match.group(0)) + else: + i += 1 + + return total_sum + +# Example corrupted memory +memory = """mul(498,303);when()}!(%mul(846,233)-,what()($where()how():}mul(334,117)]~>?,<,%^,mul(886,213)/:from()?-how()~}mul(343,197) mul(33,616)~%*~why()^*-from()mul(757,847){{who()why()#mul(927,553)>-?&!-@[mul(589,387)what():[?mul(865,934)#/ (why()+from()when();mul(804,792)-where(144,652)(mul(620,348);];]$mul(584,827):who()^%from()mul(381,633)why()@ when()where()?<;@#do()'< mul(643,715)@@#/>&-@?when(295,120)mul(465,37))]#mul(742,669)?mul(519,650)mul(546,337)@what(),{'^mul(769,202)^mul(808,254)/#why()@~mul(71,204)from();mul(150,335)[mul(302,220)>[$*~don't()mul(385,231)what()?*mul(852,324)#$}<{mul(838,178)<;+}@/*mul(579,121)select()why()*{{:mul(810,214)don't(){what()/)who()*%mul(273,606)&]from()@:why()@mul(788,896) }& don't()select()mul(568,713)$$'from()@+mul(390,36):@who();&from()mul(984,787)/mul(209,744)why()%[:what()mul(929,15)+how() who()@what()$!mul(751,670)$]from()mul(821,742)why()}:/why()>mul(445,950)>:mul(174,953)-where()how()+:mul(529,661)+{+@@why()##mul(513,442)how(827,318)}~}where()#@-:mul(941,152)~[,+{&@why()+mul(468,787)how()!$from()^^>%~from()mul(497,717)mul(930,672)mul(313,480)^%where()~-))#^select()mul(407,85)<#who()mul(776,808)~select()$?@,@mul(420,163)mul(666,491)$:+do()mul(823,835){who()?,mul(728,808))[who()/^<;select()~:mul(38,577)+>mul(985,224):/what()where()[%*what()mul(31,270)<>when()[?!!mul(895,903)%who()select()>/when()!mul(367,623)'#+mul(362,189)&from()'#$':$?{mul(571,203)what()mul(615,719)what(),what() )^mul(663,163)$@;&'select()mul(93,614)~(from()mul(490,261)#mul(530,933)}[from()];don't()$%what()%~'&'what()mul(134,307)}from()%;&why(65,575)?/mul(657,957)where()mul(969,590))how()when()how(){mul(534,951)@},mul(141,80<'mul(573,576)why()mul(952,460from()+#;;mul(36,336)&don't()&}how()why()select()^mul(267:+(+#'~mul(654,481)--mul(17,334)'!*why())how();-$mul(886,695)mul(954,476)where()!mul(73,181)?@mul(326,125)!@{)*mul(945,965)what()-select()~^who(884,691)how(846,544)mul(346,328)!<^~+-when(871,168):-mul(653,891why()when()how()why()mul(603,626)~+when()where(639,311),#mul(527,536)how()]%{/!-do()'@mul(368,63) +how()@]]from()select(976,708)?;what())mul(649,499)}&?how(792,889)~who()why(){do()mul(569,139)^[mul(701,8)why()!#[>'who()from()%mul(288,867)mul(706&*~>?select()@mul(819,789)(@%mul(180,466)from()[why()}&}mul(766,269)}@mul(827,216);???!mul(670,899)!-[%(<@^do()*}mul(475*mul(462,887)'@[])[?&mul(754,83)%]%(~from()}when()?mul(379,965)@why()mul(63,665)+[-{mul(543,711);>?/)(&mul(535,403)?')(mul(603,306)* when())what()-*mul(22,75)#who()<:{where(780,74)]mulwho()'#from()~?how() ,{{+mul(576,621)why()why();mul^;+^'mul(977,718)}why()>'[~ mul(179,326)#[mul(735,639)where() when()/from()$mul(779,50)don't()'<:)'>:}mul(232,847){where()mul(63,282)>mul(737,540)why()+!>don't()when() ']what()#,mul(778,85)how()[mul(809,798)![ $where()%>' }]mul(587,975)-?# }-]mul(800,437)$mul{[mul(603,103)>-/#why()mul(285,453)who();+{@ when()]don't()+[what(730,765) mul(399,137)%]select()#<[^>mul(146,316)~][from() mul(687,295)mul(347,287)when()>!from()&mul);<when()+;{^mul(267,700){~,!]? how()mul(779,914)select()&>^/%?}>-$*^mul(387,58)^who()&mul(157,49)#?/mul(35,606)when()')from()?%mul(451,146)'(where()mul(977,491)mul(916,789))&#how()how()>don't()^*mul(437,605)[how() mul(626,940)^*%/mul(884,929)select()mul(84,192)mul(111,274)what()mul(95where()![[(who()[mul(593,249)]]@#when()why()-/mul(230,390)#~],(:mul(840,931)mul(421,658)from(653,680)>&mul(34,90)>when()&}:why()mul(956,881)!when())$^]@who()select()where()mul(94,737)from()who()mul(816,357)')^^mul(454,208)$&mul(136,496){$what()mul(897,490)>'mul(376,325){why(),%]#what()mul(953,618)+from()mul(378,46)mul(138,440)who()#where() >(from()#mul(708,59)&why()mul(830,439)mul(468,479)why()<$,~},mul(279,437)%([mul(276,252)-#$mul(596,842)from()mul(873,817)*{{from()#(%^mul(765,528)!<< what())^mul$how()}/what() +:mul(411,270,,({(]!mul(627,262)/how()**how()$''+mul(791,814);-;;:mul(990,764)}where())))&((!mul(5,111)~how()from()&,how()mul(492,492)from()[$,+) @(mul(999,416)$&who(959,257)&mul(722,457)@how()) ^>;)@{mul(221,679)?who()$+{-^*{mul(241,314)how()][!mul(940,32){$(~@'+>mul(453,515*;mul(215,275)~/[,why(21,55)(who()',>mul(567,83)mul(330,717)>#!mul(611,308)+&select()(})/mul(744what(424,184)?mul(377,16)):(<[@mul(757,897)#^mul(404,155)%don't()}what(573,178)what()+mul(204,894)%mul(34,307))mul(794,115) +)from()}mul(515,433)^mul(529,684)from()why()where()?mul(956,914)(])?[mul(645,179)+mul(400,263)from()select()&^*mul(422,526){~;what()/)#don't()*%!/(mul(326,211)*%@select()from()[~&mul(456{why()from(138,423)-^(&!?mul(995,210):;when()why()how()!mul(394,185)how()!~who() ^how()'where():mul(348,18)mul(194who()&~*~&{/%mul(505,325) *%mul(459,604)>)) ~ -where()~{mul(579,481)mul(135,794)-*mul(453,355)~/](![from()mul(443,346)mul*[,~%why()-{do()/when(43,713)mul(136,26){^when()why()'mul(108,341)[@?!',+@who()mul(195]{&@{?:how()what()select()don't():]]#mul;what()&?:mul(541,941),&;-what(75,560)who()what()?how()mul(314,260)!)mul(250,620)>#mul(612,209),#?;mul(661,597)/mul(563,594)when()!:!mul(683,595)*what()when())'how();@mul(287,255)how()/^mul(345,555) who()/when()mul(681,924) 'mul(189,542)'mul(102,360)why()!'how()-?;,mul(874,55)+:!>what()mul(538,354)**]~how()who()mul(277,851),where(802,203)<{(];'?mul(268,251)~{:]mul(139,820){^^[ /;when() what()mul(775,595)/,)^;&where(),mul(644,487)?(mul(590,599what()%-who(){mul(112,571){$mul'/#mul(835,137)$&(mul(201,460)how()from()*@where()mul(934,320),[what()where())? :don't()&+'mul(66,8)~ mul(465,911)]?how()what(),;/:*-don't()#:?where()$mul(951,775)from()%@{who()who()!mul(78,456)^[from(),mul(144,347)']where()#([ @[]mul(660,565)}}~mul(738,761)-mul(514,849)mul(648,439who()+<,*/when()!why()mul(904,440)^ select())!@-mul(442,126% #?{mul(47,20)%mul(113,81)/;&+{@mul(504,712);select() mul(720,642)when()*#who()<-'];;mul(821,613)?select()!>when(){mul ,mul(597,943)$-what()*when()where()-}select(){mul(999,17)select(230,593),% mul(920,227)>where()@!~(select()!*mul(301,278)mul(538,232*!/when()mul(283,204)'who() ]mul(861,903)what()? %{* <-mul(112,180)'?(!mul(121,398)']<~/mul(363,850)])from()mul<>?!!from()when()select()!mul(551,325)[where())-:{#)mul(114}}:,,mul(341,114)from()?why() from()# mul(611,400))what()% from()}/when()'mul(874,416)'@&~+]mul(916,295what()@why()how()>where()-^mul(988,626)select()#!)who()why()mul(597,791)};mul(160,184) from()~{;!where()mul(332,928)where()(#!/usr/bin/perl+^who()]:,~}select():mul(810,730)when()mul(312;&what(415,542)who(560,710)who()from()^mul(828,831)> }how(595,281)!why()*/:mul(70,967) +(do(){,-how()<(how()[{why()mul(16,675))+don't()!>-((&what()!mulwhere()+( mul(446,260)#+&how()}}when()who()/do()[,who()]>-~from(),mul(200,312);$mul(997,25);?where(203,706)&?}select(),mul(553,783)@^~mul(779,661)%)mul(252,997)what()from();%mul(439,801)select()#?')~;%}mul?why()+!mul(385,635)@)^):!*)how()mul(563,131)#&mul(720,10)~#<+]^!:@how()mul(24,633)~mul(103,646)mul(331,217)~#mulwhy()@-$> mul(288,357)how() when();;why()<+mul(513,580)?when(299,618)!<^-mul(318,287) }mul(88,924)mul(220,403mul(264,790)mul(78,811),,(/who()who()mul(978,770)[what()$)]#:%mul mul(57,890)'(mul(146,967)[<#%)^;how()]>mul(166,279)]mul(24,319)%;select()-!/don't()>:mul(858,696)mul(622,496)*{{-~why()how()what()-mul(973%}+> mul(904,891)*(:{%mul(618,932)&!~*mul(77,889)}%~{mul(206,797)select()what() who()+*what(499,999)?@@mul(114,405)(()where()}/){]}mul(841,73)@!where(581,676)]#from(879,459)}^mulhow()do()}select()~!~)[why(364,979)who(533,785)mul(839,475)[{;>)(@what()mul(597,209)-$-^select()mul(453+;:#:?&mul(972,784)what()#select()%/[select()[,how()mul(436,10)]!~)select() mul(982,995select()~/%(,do()#who()]!,/*mul(718,383)when()>^*mul(803,383)when(); mul(568,612)/from()from()}what(219,960)from()*don't()@@why();who()where()mul(222,279){ mul(758,766)what()who()!how(38,972)~;],select()/mul(974,879)!don't()mul(368,975)where()^$[^&] -{mul(153,172)what()&+)[mul(97,652)when(534,157)~,:where()do()%%@]?&when(435,925)what(){mul(155,627)?{;@#mul(466,775)(;mul(834,395)//>()-don't() $mul(329,300)<+&'@^mul(469,14)*&why(99,525)',mul(427who()*@< ?do()[>from()when()?#,'&:mul(585,898)mul(128,392)-(?[,where()'^where(575,788)+mul(378,473how() '$'#@who()from()how()?(//mul(768,590)when()-: ](where()who()(mul(716,399)/~)@mul(754,670)what()mul(656,266):(;%!]mul(595,874)why()%@<^?mul(702,835)(![&&/+%mul(421,278)}where()-%^'+mul(842,496)/?@:]mul(282,851)~@)how())mul(543,112))]+^)mul(133,862);#)when()who()why()when(58,966),,mul(513,202)@mul(716,648)(mul(793,735)what()]where()%+-/mul(359,127)-+}/mul(116,988)when()mul(153,16):'@$who():~-mul(441,603)'how(){ #why()%{{mul(877,856)select()who(777,457)select()from())how(345,367)from()mul(447,557)%/$-select(),when()+what()mul(189,616)what()}mul(822,616)mul(454,622)how()&who()&#do():> mul(353,679)^(@select()<;mul(414,440)why()+how()&,]#-&mul(402,532)-})~#$-!mul(883,415):<@]*from() mul(28,253){where()? what()select()~mul(259,972)-(]<}>when()from()$mul(650,381)~from()}from()who()>mul(72,307),who()where()?@{where()mul(706,447)from(671,711))~mul(601,925)} ;what()[mul(533,851~{&what()(@{<'where()mul(799,568)%where()mul$>select()[)#^:mul(414,93)]mul(16,757)&[who(),/mul(629,760)&''how(),from()mul(951,329)^mul(781,711):/',+'{%when();mul(661,844)/why()<^}#mul(337,134)!)mul(339,829)([how()+&~how(512,132)!;:mul(696,374))}/what()from()mul(640,944)'{*how()what(279,739)why(843,673)? &!where()mul(347,404)^?>!$&mul(316,524) when()]mul(875,937)$(@]$don't()/who():/]mul(833,846)who()mul(190,362))mul(183,740)how()}mul(14,502):why();why()'mul(341,888)mul(668,734)]/what())**&(do()how()*:select()}*:]mul(604{mul(123,983)#&why()mul(159,440)mul(437,830)~};'])[?mul(36,75)mul(836,766),?*select()who()mul(548,488)%--where(521,841))$]do():-from()*mul(355]<+>:mul(58,505)what()from(49,769)mul(108*]~>mul(131,644)?!from()mul(11,884):where()!;select();+[select()mul(358,741)(*?]do()(?{@^mul(117,14)^+;what()from()}mul(847,203)/who()where()from(567,960)when()how()%~'}mul(677,415)mul(91,507)when()*when()from()*(mul(935,477) from()@ mul(556,85)?)@mul(196,674)^;*+#$mul(531,124)!what()%select(){who()}';~mul(67,663)when()'?mul(205,527)@:+ ?:why() %mul(513,956/}:,'@+$who()-mul(963,914)@from()why()how(292,305)!from(980,892)mul(456,909)!who()<(*@select()&why()mul(947,805)who()how()^}mul(154,935)+?when()('};]>^mul(855,799){who()]+*{mul(823,352)*<$when()+)^&(do()mul(623,916)(['])^what(){select()mul(815,135)}mul(464,34)' ^)-^~where()where()mul(50,471)*{select()from() mul~:why()when()[why();%, }-where()#mul(184,632)~]+'select()}what()mul(675,164)mul(360,852)mul(875,801):where(811,851)mul(702,746)mul(29,632)[{^]-:!{ who(719,324)mul(720,687);:/[#*mul(431,415)mul(123,914]&?%$how()mul(655,184)]@?how()*$(-what()mul(323,687)mul(474,75);mul(846,335):%;do()~?where()~mul{}?%mul(446,300)^how(),<&from()#!#from()mul(423,746)how()what()don't()what()+*#:mul(268,185)@do()!>?~;@]mul(657,833) ,(who()-who()mul(415,876)]&#?@'!/&mul(437,971)^,+mul(884,392):mul(183,497)^from()mul(204,743)^'>}who()$;}mul(892,574)+ from()?$mul(922,854))select()#,+>where(),*mul(551,303)?}mul(261,657)?why()}why()when()%-mul(124,265!mul(979,380)/@select()}>why()+#mul(384,303)$,@@-mul[mul(479,548)-]#> ?:!do()how()@&mul(917,657{:$&mul(966,387)}what())[-]mul(183,849)^^who()&<,mul(669,375)mul(323,459)$%/from()~+}when()mul(789,390)'+mul(804,927)#who()mul(102,842)$$)how()from()select()][mul(380,252) )>when()where()how()who():#where(184,552)mul(244,943)$&$*}*-mul(727,613)(#why()}>mul(807,274)mul(577,489)mul(731,223)>where()/!]? %where()mul(359,604)/$;$+}mul(182,17)why()-how()mul(792,962)why()/{-(how()%'select()mul(997,718)/{mul(7,739)select();:mul(800,703)[when()' #~why()where()*mul(345,374)mul(308,927)how()%@how()mul(233,785)#{!select()mul(208,457)#from()}what()mul(347,911)where()from()@;(mul(492,896)&;?+, mul(948,682)+~when()}from()mul(930,691)[&]*((#mul(600,425){what()'{)@,where();:mul(844,671)~+)#,(mul(446,155)$%@/:mul(749,494)mul(24,97)where(6,997)&where()?why(449,637)mul(631,323))mul(192,700));/$]what()mul(820,765)who()(>%>mul(702,770)*-[;}(mul(438,245)@)]^/'#mul(554,294)!mul(34,410)where()$<#how(360,499)@#mul(585,680)<^};mul(295,437)where()] {+mul(607,28)why()#% do();mul(96,932)]why()+who(){<,[where()mul(271,645);^:{mul(411,161)]<>do()@';when() (mul(41,299)(!what()*select(387,698)$]mul(942,465)^?~what(),*?-'from()mul(70,415)why()'from()how()mul(682,699)!^-when()?when()#mul(473,999) {(~>^why()}mul(240,258)+why()&%mul(579,916)!(]((select(112,996)#($,mul(584,139)%""" + +# Calculate the result +result = extract_and_multiply_with_conditions(memory) +print(result) # Output should be 48 \ No newline at end of file