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