import java.util.Scanner object Problem164 { def charToLongValue(c: Char): Long = { c match { case x if x < 58 => x.asDigit // [0-9] -> 0..9 case x => x - 65 + 10 // [a-z] -> 10..35 } } def calcDecimalValue(s: String): Long = { val longs = s.map(charToLongValue) val decimal = longs.max + 1 // 0-indexの最大数値を進数に変換 longs.foldLeft(0L)((a, b) => a * decimal + b) } def proc(numbers: Seq[String]): Long = { numbers.map(calcDecimalValue).min } def main(args: Array[String]): Unit = { val sc = new Scanner(System.in) val n = sc.next.toInt val v = Seq.fill(n)(sc.next) val result = proc(v) println(result) } }