System.in.eachLine{(n,a)=it.split() z=a as List a.each{i=0;z=(s=z.sort()).sum{[a[i++]+it]}} println s[n as Byte]}