package main import ( "bufio" "fmt" _ "math" _ "math/big" "os" _ "reflect" _ "regexp" "strconv" _ "strings" ) func callable(ns []string, bs []bool) int64 { res := int64(0) for i := 0; i < len(ns); i++ { if bs[i] == true { continue } for j := i + 1; j < len(ns); j++ { if bs[j] == true { continue } for k := j + 1; k < len(ns); k++ { if bs[k] == true { continue } if ns[i] != "0" && ns[i] != ns[j] && ns[j] == ns[k] { x, _ := strconv.ParseInt(ns[i]+ns[j]+ns[k], 10, 64) bs[i], bs[j], bs[k] = true, true, true comp := x + callable(ns, bs) if res < comp { res = comp } bs[i], bs[j], bs[k] = false, false, false } } } } return res } func main() { scanner := bufio.NewScanner(os.Stdin) th := 0 lines := []string{} for scanner.Scan() { th += 1 text := scanner.Text() lines = append(lines, text) if th == 1 { break } } bs := []bool{} tn := lines[0] ns := []string{} for _, x := range []rune(tn) { ns = append(ns, string(x)) bs = append(bs, false) } fmt.Println(callable(ns, bs)) }