#!ruby -pal
$c={}
def f a,s,l
a[0]?($c[a.sort]||=a.map{h,*t=a.rotate!;f(t,s+(4*h*l)**0.5,h)}.min):s+l
end
m,*r=$F.map &:to_i
$_=((n=r.map{h,*t=r.rotate!;f(t,h,h)}.min)-m<=[1e-10,1e-10*[m,n].max].max)?:OK: :NA