Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

26 lines
656B

  1. import re
  2. import sys
  3. from collections import Counter
  4. def decode(string, n):
  5. def replacer(match):
  6. char = match.group(0)
  7. return chr((ord(char) + n - ord('a')) % 26 + ord('a'))
  8. return re.sub(r'\w', replacer, string)
  9. text = sys.stdin.read()
  10. ans1 = 0
  11. for line in text.splitlines():
  12. name, sid, checksum = re.match(r'^(.+)-(\d+)\[(.+)\]$', line).groups()
  13. by_count = ''.join(dict(Counter(sorted(name)).most_common()))
  14. calc = by_count.replace('-', '')[:5]
  15. if calc == checksum:
  16. ans1 += int(sid)
  17. decoded = decode(name, int(sid))
  18. if 'north' in decoded:
  19. ans2 = sid
  20. print(ans1)
  21. print(ans2)