summaryrefslogtreecommitdiff
path: root/2_2020.py
blob: 203d09dc276fc7e2b52239b126450cf47cbf9f09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import fileinput
from collections import defaultdict

p1 = 0
p2 = 0
lines = list(fileinput.input())
for line in lines:
    # 5-6 s: zssmssbsms
    words = line.strip().split()
    lo, hi = [int(x) for x in words[0].split("-")]
    ch_req = words[1][0]
    password = words[2]
    counts = defaultdict(int)
    for ch in password:
        counts[ch] += 1
    if lo <= counts[ch_req] <= hi:
        p1 += 1
    if (password[lo - 1] == ch_req) ^ (password[hi - 1] == ch_req):
        p2 += 1
print(p1)
print(p2)