import math._ object Main { def calc(a: Int, b: Int, c: Int, xs: Array[Int]): Int = { val dp = Array.fill(31)(Integer.MAX_VALUE / 10) for (i <- Array(a, b, c)) { dp(i) = 1 for (j <- i+1 to 30) { dp(j) = min(dp(j), dp(j-i) + 1) } } xs.map { e => dp(e) }.sum } def main(args: Array[String]) { val sc = new java.util.Scanner(System.in) val xs = Array.fill(4)(sc.nextInt) var ans = Integer.MAX_VALUE for (i <- 1 to 30) { for (j <- i+1 to 30) { for (k <- j+1 to 30) { ans = min(ans, calc(i, j, k, xs)) } } } println(ans) } }