N=gets.hex t={} $<.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]]||0}.sum}.sum}.max