"""筑駒2026 大問1: 上下左右の区画を重複なく数える。Python 3。"""
from itertools import combinations
from collections import Counter
masks=[]
for p in range(25):
    r,c=divmod(p,5)
    masks.append(sum(1 << (rr*5+cc) for rr,cc in [(r-1,c),(r+1,c),(r,c-1),(r,c+1)] if 0<=rr<5 and 0<=cc<5))
def covered(positions):
    seen=0
    for p in positions: seen |= masks[p]
    return seen.bit_count()
hist=Counter(covered(ps) for ps in combinations(range(25),6))
print("6台:",dict(sorted(hist.items())))
print("6台配置数:",sum(hist.values()))
print("8台で全25区画を見られる配置:",sum(covered(ps)==25 for ps in combinations(range(25),8)))
print("9台の例:",covered([p-1 for p in [1,2,4,9,12,17,19,20,22]]))
