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 := 13 pp := make([]int, 10) for i := 0; i < n; i++ { pp[int(s[i]-'0')]++ } mm := make([][3]int, 0) for i := 1; i < 8; i++ { mm = append(mm, [3]int{i, i + 1, i + 2}) } for i := 1; i < 10; i++ { mm = append(mm, [3]int{i, i, i}) } ans := make([]int, 0) for i := 1; i < 10; i++ { if pp[i] == 4 { continue } pp[i]++ if designedchildren(pp) || lohengrin(pp, mm) { ans = append(ans, i) } pp[i]-- } for i := 0; i < len(ans); i++ { fmt.Fprintln(writer, ans[i]) } } func designedchildren(pp []int) bool { p := 0 for i := 1; i < 10; i++ { if pp[i] == 2 { p++ } } return p == 7 } func lohengrin(pp []int, mm [][3]int) bool { n := len(mm) for i := 0; i < n; i++ { for j := 0; j < n; j++ { for k := 0; k < n; k++ { for l := 0; l < n; l++ { rr := make([]int, 10) for c := 0; c < 3; c++ { rr[mm[i][c]]++ rr[mm[j][c]]++ rr[mm[k][c]]++ rr[mm[l][c]]++ } if valid(pp, rr) { return true } } } } } return false } func valid(pp, rr []int) bool { v := true for i := 0; i < 10; i++ { pp[i] -= rr[i] } for i := 0; i < 10; i++ { if pp[i] < 0 || pp[i] == 1 { v = false break } } for i := 0; i < 10; i++ { pp[i] += rr[i] } return v }