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)]))