02_checksum.py 362 B

123456789
  1. #!/usr/bin/env python3
  2. import sys
  3. from itertools import combinations
  4. spreadsheet = [list(map(int, line.split())) for line in sys.stdin]
  5. print(sum(max(row) - min(row) for row in spreadsheet))
  6. print(sum(div for row in spreadsheet
  7. for a, b in combinations(row, 2)
  8. for div, rem in (divmod(a, b), divmod(b, a))
  9. if rem == 0))