t=[0]*10*N=gets.hex $<.map{|s|eval"t[%d*10+%d]=%d"%s.split} p (R=*0...N).permutation.map{|a|R.map{|i|(i...N).map{|j|t[a[i]*10+a[j]]}.sum}.sum}.max