import re with open('input', 'r') as f: arrival = int(f.readline()) buses = list(map(int, re.findall(r'[0-9]+', f.readline().strip()))) earliest = None earliest_bus = None print(f'{arrival=}') for bus in buses: wait = bus - arrival % bus wait = 0 if wait == bus else wait if earliest is None or wait < earliest: earliest = wait earliest_bus = bus print(bus, wait) print(f'{earliest=} {earliest_bus=}') print('Solution') print(earliest * earliest_bus)