<|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 count bulls in one pass, mark which digits appear in the secret, then collect all guess digits that appear in the secret into a set (cows_and_bulls). Since all digits are distinct, the set size equals the total number of matching digits (bulls + cows).
- Then cows = cows_and_bulls.size() − bulls.

3. Full solution approach
a. Read `secret` and `guess` as strings of length 4.
b. Initialize `bulls = 0` and a map c1 marking secret digits.
c. Traverse index `i` from 0 to 3:
   - If `secret[i] == guess[i]`, increment `bulls`.
   - Mark c1[secret[i]] = 1.
d. Traverse index `i` from 0 to 3: if c1[guess[i]], insert guess[i] into set cows_and_bulls.
e. Compute `cows = cows_and_bulls.size() - bulls`.
f. Print `bulls` and `cows`.

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

4. C++ implementation

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

string s1, s2;

void read() { cin >> s1 >> s2; }

void solve() {
    // Bulls are positions where the secret and guess share the same digit.
    // Since all digits within a number are distinct, the digits present in both
    // numbers (in any position) are bulls plus cows, so we collect that set and
    // subtract the bull count to get the number of cows. c1 marks which digits
    // appear in the secret.

    map<char, int> c1;
    set<char> cows_and_bulls;
    int bulls = 0;

    for(int i = 0; i < (int)s1.size(); i++) {
        if(s1[i] == s2[i]) {
            bulls++;
        }

        c1[s1[i]] = 1;
    }

    for(int i = 0; i < (int)s1.size(); i++) {
        if(c1[s2[i]]) {
            cows_and_bulls.insert(s2[i]);
        }
    }

    cout << bulls << " " << cows_and_bulls.size() - bulls << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

5. Python implementation

```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)
```
