summaryrefslogtreecommitdiff
path: root/2016/7b.py
blob: ea31643d83278e28d494a5a8eb430e77ba88eea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python3

import sys

count=0

for line in sys.stdin:
	line=line[:-1].replace("]","[").split("[")
	p1=line[0::2]
	p2=line[1::2]
	p2bab=set()

	for bl in p2:
		for i in range(len(bl)-2):
			if bl[i]==bl[i+2] and bl[i]!=bl[i+1]:
				p2bab.add(bl[i:i+3])

	for bl, i in ((bl,i) for bl in p1 for i in range(len(bl)-2)):
		if bl[i]==bl[i+2] and bl[i]!=bl[i+1] and "".join([bl[i+1],bl[i],bl[i+1]]) in p2bab:
			count+=1
			break

print(count)