← run

lcb-0068

1.000
4/4 tests· algorithms

Proposed solution

I'll solve this step by step.

## Problem Understanding

1. We have 7 cards with integers A₁ to A₇
2. We need to choose 5 cards that form a "full house"
3. A full house means:
   - One number appears exactly 3 times
   - Another number appears exactly 2 times
   - Total: 3 + 2 = 5 cards

## Approach

1. Count the frequency of each number in the 7 cards
2. Check if there exists a combination where:
   - One number has frequency ≥ 3
   - Another number has frequency ≥ 2
   - The total count is exactly 5 (3 + 2)

Wait, let me re-read this more carefully...

Actually, we're choosing 5 cards from 7 cards. So we need to check if among the 7 cards:
- There's at least one number that appears 3 times (we can take all 3 of those)
- And there's another number that appears at least 2 times (we can take 2 of those)
- Or some other valid combination

Let me think differently:
- We need exactly 5 cards with frequencies that sum to 5
- The pattern must be: one value appears 3 times, another value appears 2 times
- This means we have 2 distinct values in our selection

So the approach is:
1. Count frequency of each number (1-13) among all 7 cards
2. Check if there exists a number with frequency ≥ 3 AND another number with frequency ≥ 2
3. But we also need to make sure that when we select 5 cards, we get exactly this pattern

Actually, let me think even more carefully:
- We have 7 cards total
- We want to choose 5 cards
- These 5 cards must form a full house (3 of one kind + 2 of another kind)

So we need to check if among the 7 cards:
- There's at least one number that appears 3+ times, AND
- There's at least one other number that appears 2+ times

But wait - what if there are 5 identical cards? That would be 5 of a kind, not full house.

Let me trace through Sample 1:
Cards: [1, 4, 1, 4, 2, 1, 3]
Frequencies: 1→3, 4→2, 2→1, 3→1
We can take 3 cards of 1 and 2 cards of 4 → full house

Sample 3:
Cards: [7, 7, 7, 7, 7, 7, 7] 
Frequencies: 7→7
We have 7 cards with same number - we can't form a full house (would be 5 of a kind)

## Better Approach

1. Count frequency of each card value (1-13)
2. Check if there exists a combination where:
   - One value appears at least 3 times, and another value appears at least 2 times
   - OR one value appears at least 5 times (but this would be 5 of a kind, not full house)

Wait, let me re-read the definition again.

A full house means: "For different integers x and y, there are three cards with x and two cards with y."

So we need exactly:
- One number that appears 3 times in our chosen 5 cards
- Another number that appears 2 times in our chosen 5 cards

This means among the 7 cards:
- We must have at least one number that appears 3+ times (we can take 3 of them)
- We must have at least one other number that appears 2+ times (we can take 2 of them)

But we also need to make sure we don't overcount or undercount.

Let me trace sample 1 again:
Cards: [1, 4, 1, 4, 2, 1, 3]
Frequencies: 1→3, 4→2, 2→1, 3→1
We can choose 3 cards of 1 and 2 cards of 4 → total 5 cards

## Algorithm

1. Count frequency of each number in the 7 cards
2. For each possible pair of numbers (x,y) where x≠y:
   - Check if freq[x] ≥ 3 AND freq[y] ≥ 2
   - If so, we can form a full house by taking 3 cards of x and 2 cards of y
3. Also check if there's one number with frequency ≥ 5 (but this would be 5 of a kind, not full house)
4. Actually, let me think more systematically.

The key insight is:
- We want to select exactly 5 cards that form a full house
- This means we need exactly 2 distinct values in our selection
- One value appears 3 times, another appears 2 times

So among the 7 cards:
- If there's a number that appears at least 3 times AND another number that appears at least 2 times → YES
- But we also need to make sure we can actually select exactly 5 cards (which is always possible if we have enough)

Wait, let me be more precise:
- Count frequency of each card value
- Check if there exists a value with frequency ≥ 3 AND another value with frequency ≥ 2

But what about the case where one value appears 5 times? 
That would be 5 of a kind, not full house.

Actually, let's think of it this way:
We want to select 5 cards that form a full house.
The only valid pattern is: 3 cards with value x and 2 cards with value y (x ≠ y).

So we need:
1. At least one number that appears ≥ 3 times in the original 7 cards
2. At least one other number that appears ≥ 2 times in the original 7 cards

## Implementation Plan

1. Read input and count frequencies
2. Check if there exists a value with frequency ≥ 3 AND another value with frequency ≥ 2
3. Output result

Let me trace all samples:

Sample 1: [1,4,1,4,2,1,3]
Frequencies: {1:3, 4:2, 2:1, 3:1}
Has 1 with freq≥3 and 4 with freq≥2 → YES

Sample 2: [11,12,13,10,13,12,11]  
Frequencies: {11:2, 12:2, 13:2, 10:1}
No value has freq≥3 → NO

Sample 3: [7,7,7,7,7,7,7]
Frequencies: {7:7}
Has 7 with freq≥3 but no other value with freq≥2 → NO

Sample 4: [13,13,1,1,7,4,13]  
Frequencies: {13:3, 1:2, 7:1, 4:1}
Has 13 with freq≥3 and 1 with freq≥2 → YES

This looks correct.

## Code Implementation

```python
# Read input
cards = list(map(int, input().split()))

# Count frequency of each card
freq = {}
for card in cards:
    freq[card] = freq.get(card, 0) + 1

# Check if we can form a full house
found = False

# For each number that appears at least 3 times
for num1, count1 in freq.items():
    if count1 >= 3:
        # Look for another number that appears at least 2 times
        for num2, count2 in freq.items():
            if num1 != num2 and count2 >= 2:
                found = True
                break
    if found:
        break

# If we couldn't find such a pair, check if there's one number with at least 5 cards
if not found:
    for num, count in freq.items():
        if count >= 5:
            # This would be 5 of a kind, not full house
            pass
        elif count >= 3:
            # Check if we can make a full house with this number and another
            for num2, count2 in freq.items():
                if num != num2 and count2 >= 2:
                    found = True
                    break

# Actually, let me simplify this approach
found = False

# We need at least one number with frequency >= 3 and another with frequency >= 2
for num1, count1 in freq.items():
    if count1 >= 3:
        for num2, count2 in freq.items():
            if num1 != num2 and count2 >= 2:
                found = True
                break
    if found:
        break

if found:
    print("Yes")
else:
    print("No")
```

Wait, I think I'm overcomplicating this. Let me re-read sample 3.

Sample 3: [7,7,7,7,7,7,7] - all same number
We have one number (7) with frequency 7.
We need another number with frequency ≥ 2 to make a full house.
But there's no other number. So it should be "No".

This is correct.

Let me also think about the case where we have 5 of a kind:
If we had [1,1,1,1,1,2,3], then we'd have 1 with frequency 5.
We'd need another number with frequency ≥ 2 to make full house. But there isn't one.
So it's "No". 

But wait, what if we had [1,1,1,1,1,1,1]? 
We'd have 1 with frequency 7.
We'd want to take 3 of 1 and 2 of 1 → but that's not valid since we need different numbers.

So the approach is:
- We need at least one number with frequency ≥ 3
- And another number with frequency ≥ 2

But what if we have [1,1,1,1,1,1,2]? 
We'd have 1 with frequency 6 and 2 with frequency 1.
We can take 3 of 1 and 2 of 1 → but that's not valid since we need two different numbers.

So the correct approach:
- We need at least one number with frequency ≥ 3
- And another number with frequency ≥ 2  
- These must be different numbers

```python
# Read input
cards = list(map(int, input().split()))

# Count frequency of each card
freq = {}
for card in cards:
    freq[card] = freq.get(card, 0) + 1

# Check if we can form a full house
found = False

# For each number that appears at least 3 times
for num1, count1 in freq.items():
    if count1 >= 3:
        # Look for another number that appears at least 2 times
        for num2, count2 in freq.items():
            if num1 != num2 and count2 >= 2:
                found = True
                break
    if found:
        break

if found:
    print("Yes")
else:
    print("No")
```

Test output (stdout)

....                                                                     [100%]
4 passed in 0.06s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.