package main import ( "bufio" "fmt" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { s := getNextString(scanner) n := len(s) cc := make([]cww, 0) for c := 0; c < n; c++ { for w1 := c + 1; w1 < n; w1++ { for w2 := w1 + 1; w2 < n; w2++ { if s[w1] != s[w2] { continue } if s[c] == s[w1] { continue } if s[c] == '0' { continue } cc = append(cc, cww{used: (1 << uint(c)) | (1 << uint(w1)) | (1 << uint(w2)), score: 100*int(s[c]-'0') + 10*int(s[w1]-'0') + int(s[w2]-'0')}) } } } q := make([]cww, 0) q = append(q, cww{used: 0, score: 0}) m := map[uint32]int{} var ans int for len(q) > 0 { p := q[0] q = q[1:] if ans < p.score { ans = p.score } if m[p.used] > 0 { continue } m[p.used] = p.score for _, c := range cc { if p.used&c.used != 0 { continue } q = append(q, cww{used: p.used | c.used, score: p.score + c.score}) } } fmt.Fprintln(writer, ans) } type cww struct { used uint32 score int }