← Home
For problem statement at 0-999/700-799/770-779/770/problemB.txt this is a correct solution, but verifier at 0-999/700-799/770-779/770/verifierB.go ends with All 100 tests passed can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		x := scanner.Text()

		bestNum := x
		maxSum := digitSum(x)
		n := len(x)

		// Iterate from the last digit to the first digit.
		// We construct candidates by decrementing the digit at index i
		// and setting all subsequent digits to 9.
		// We process in descending order of i (n-1 down to 0) because
		// candidates closer to the original number x (larger i) are numerically larger.
		// We want the largest number with the maximum sum.
		// Since we start with x (the largest possible) and then try candidates in 
		// descending numerical order, the first time we see a strictly greater sum,
		// we update. If sums are equal, we stick with the numerically larger one (current best).
		
		for i := n - 1; i >= 0; i-- {
			if x[i] == '0' {
				continue
			}

			// Construct candidate
			candBytes := []byte(x)
			candBytes[i]-- // Decrement digit at i
			for j := i + 1; j < n; j++ {
				candBytes[j] = '9' // Set trailing digits to 9
			}

			candStr := string(candBytes)
			// Remove leading zero if necessary (e.g. 100 -> 099 -> 99)
			if n > 1 && candBytes[0] == '0' {
				candStr = candStr[1:]
			}

			currSum := digitSum(candStr)
			if currSum > maxSum {
				maxSum = currSum
				bestNum = candStr
			}
		}

		fmt.Println(bestNum)
	}
}

func digitSum(s string) int {
	sum := 0
	for i := 0; i < len(s); i++ {
		sum += int(s[i] - '0')
	}
	return sum
}
```