#C5886. Safe Cracking: Guess the 4-Digit Combination

    ID: 49584 Type: Default 1000ms 256MiB

Safe Cracking: Guess the 4-Digit Combination

Safe Cracking: Guess the 4-Digit Combination

You are given a secret 4-digit combination (an integer between 1000 and 9999). Your task is to implement an algorithm that finds the secret combination using a process of elimination based on feedback.

In each query, your algorithm prints a 4-digit guess. It then receives feedback in the form of two integers \(a\) and \(b\), where:

  • \(a\) is the number of digits that are exactly correct (i.e. the digit is correct and in the correct position).
  • \(b\) is the number of digits that are correct but located in the wrong position.

The feedback for a guess \(G\) and candidate combination \(S\) is computed as follows:

[ a = \text{number of positions } i \text{ such that } G_i = S_i, ]

[ b = \left(\sum_{d \in {0,1,\dots,9}} \min(\text{count}(d \text{ in } G), \text{count}(d \text{ in } S))\right) - a. ]

You must eliminate all candidates that would not produce the same \((a,b)\) feedback for your guess. Continue guessing until your guess exactly matches the secret combination (i.e. when \(a = 4\)).

Note: In this version, the secret combination is provided as input and the program simulates the process by computing the feedback against the secret combination.

inputFormat

The input consists of a single line containing a 4-digit combination as a string (an integer between 1000 and 9999).

Example:

1000

outputFormat

Print each guess (a 4-digit number) on a new line. The program should output guesses until it prints the secret combination (when feedback \(a = 4\) is achieved), then terminate.

Example:

1000

(If the secret is 1000, the program outputs 1000 and stops immediately.)

## sample
1000
1000

</p>