summaryrefslogtreecommitdiffstats
path: root/5/2.py
blob: a172cdd86546a5419dbbc1ff6e06e28e4fe29a95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from collections import defaultdict
def check(w):
    pairs = defaultdict(list)
    rep = False
    last2 = (None, None)
    for i, c in enumerate(w):
        if last2[1] is not None:
            pairs[(last2[1], c)].append(i)
        if not rep and last2[0] == c:
            rep = True
        last2 = (last2[1], c)
    if not rep:
        return False
    for _, p in pairs.items():
        if len(p) < 2:
            continue
        if len(p) > 2:
            break
        if p[1] - p[0] > 1:
            break
    else:
        return False
    return True
print(len([w for w in open('input') if check(w)]))