02_boxes.py 494 B

1234567891011121314151617181920
  1. #!/usr/bin/env python3
  2. import sys
  3. from collections import Counter
  4. boxes = [line.rstrip() for line in sys.stdin]
  5. two = three = 0
  6. for box in boxes:
  7. hist = Counter(box)
  8. two += int(2 in hist.values())
  9. three += int(3 in hist.values())
  10. print(two * three)
  11. for box1 in boxes:
  12. for box2 in boxes:
  13. dist = 0
  14. for a, b in zip(box1, box2):
  15. dist += int(a != b)
  16. if dist == 1:
  17. print(''.join(c for c in box1 if c in box2))
  18. sys.exit(0)