<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

486. "Bulls and Cows"
Time limit per test: 0.25 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard



You probably know the game "bulls and cows". Just in case, we explain the rules. The first player picks a four-digit number with all digits distinct (leading zero is allowed) and keeps it secret. The second player tries to guess the secret number. For each guess, the first player issues a response in the form "n bulls, m cows". A "bull" is a digit that is present in both the secret and the guess and occurs in the same position in both. A "cow" is a digit that is present in both numbers, but occurs in different positions.

For example, if the first player picked 5071, and the second guessed 6012, the response would be "one bull, one cow". Here the "bull" is the digit 0, as it is in the second position in both numbers, and the "cow" is the digit 1, as it is in the fourth position in the secret, but in the third position in the guess.

Write a program to count the number of cows and bulls for the given the secret and guess.

Input
The first line of the input file contains four digits, the number picked by the first player. The second line contains the number guessed by the second player in the same format.

Output
The first and only line of the output file should contain two integers separated by a space, the number of "bulls" and the number of "cows".

Example(s)
sample input
sample output
5071
6012
1 1

sample input
sample output
4321
4321
4 0

sample input
sample output
1980
0879
0 3

sample input
sample output
1234
5678
0 0

<|response|>
1. Abridged problem statement  
You are given two 4-character strings, `secret` and `guess`, each representing a four-digit number with all digits distinct (leading zeros allowed).  
- A "bull" is a position `i` where `secret[i] == guess[i]`.  
- A "cow" is a digit that appears in both strings but at different positions.  
Output two integers: the count of bulls and the count of cows.

2. Key observations  
- The length is fixed (4) and all digits in each string are distinct.  
- Every bull is also a matching digit; cows are the remaining matching digits in wrong positions.  
- You can compute bulls in one pass, and all matching digits (“bulls + cows”) in another.  
- Then cows = (total matches) − bulls.

3. Full solution approach  
a. Read `secret` and `guess` as strings of length 4.  
b. Initialize `bulls = 0`.  
c. Traverse index `i` from 0 to 3:  
   - If `secret[i] == guess[i]`, increment `bulls`.  
d. Build a set (or boolean array of size 10) containing the digits of `secret`.  
e. Initialize `matches = 0`. Traverse each character `ch` in `guess`:  
   - If `ch` is in the secret’s digit set, increment `matches`.  
f. Compute `cows = matches - bulls`.  
g. Print `bulls` and `cows`.

Time complexity is O(4) = O(1); space complexity is O(1).

4. C++ implementation with detailed comments  
```cpp
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;

int main() {
    // Read the secret number and the guess
    string secret, guess;
    cin >> secret >> guess;

    // 1) Count bulls: same digit at the same position
    int bulls = 0;
    for (int i = 0; i < 4; i++) {
        if (secret[i] == guess[i]) {
            bulls++;
        }
    }

    // 2) Record all digits present in the secret
    unordered_set<char> secretDigits;
    for (char ch : secret) {
        secretDigits.insert(ch);
    }

    // 3) Count total matches (bulls + cows)
    int matches = 0;
    for (char ch : guess) {
        if (secretDigits.count(ch)) {
            matches++;
        }
    }

    // 4) Cows are the matches that are not bulls
    int cows = matches - bulls;

    // 5) Output the result: bulls and cows
    cout << bulls << " " << cows << "\n";
    return 0;
}
```

5. Python implementation with detailed comments  
```python
# Read the secret and guess as strings
secret = input().strip()
guess = input().strip()

# 1) Count bulls: positions where the characters match exactly
bulls = sum(1 for i in range(4) if secret[i] == guess[i])

# 2) Build a set of secret digits for quick membership tests
secret_digits = set(secret)

# 3) Count total matches: every guess digit that appears in the secret
matches = sum(1 for ch in guess if ch in secret_digits)

# 4) Compute cows by removing bulls from the total matches
cows = matches - bulls

# 5) Print bulls and cows
print(bulls, cows)
```