3

Python 2 & PuLP — 2,644,688 squares (optimally minimized)
Minimally golfed to 1152 bytes
from pulp import*
x=0
f=open("c","r")
g=open("s","w")
for k,m in enumerate(f):
if k%2:
b=map(int,m.split())
p=LpProblem("Nn",LpMinimize)
q=map(str,range(18))
ir=q[1:18]
e=LpVariable.d...