# Problem Description
This is a grouping problem where we need to calculate the number of groups that can be formed from pairs of binary symbols (0, 1). The groups are formed based on how these pairs can connect with each other at their boundaries. A connection is possible when adjacent pairs have compatible directions at their shared border.

# Visual Facts
1. Each element in the input is a pair of binary symbols: either [0, 1] or [1, 0]
2. The image shows two cases:
   - Case 1: Shows a sequence divided into 3 groups
   - Case 2: Shows a sequence divided into 4 groups
3. There are three types of marks above the pairs:
   - Red check marks (✓)
   - Blue check marks (✓)
   - Purple prohibited symbols (⌀)
4. Groups are highlighted with green dashed boxes
5. Groups can contain different numbers of pairs (some have 2 pairs, others have 3 pairs)

# Visual Patterns
1. Connection Rules:
   - Pairs can connect when they share a compatible border
   - Compatible means the right symbol of the left pair matches the left symbol of the right pair
   - Example: [0, 1] can connect with [1, 0] because they share 1 at the border

2. Group Formation Rules:
   - A group must contain at least one pair
   - Multiple pairs can form a single group if they have compatible connections
   - When pairs cannot connect (shown by purple prohibited symbols), they form separate groups


# Solution
from typing import List

def solution(s: List[List[int]]) -> int:
    """
    Calculate the number of groups in a list of binary pairs.
    Each inner list contains exactly two binary symbols: either [0, 1] or [1, 0].

    Parameters:
        s (List[List[int]]): A list of binary pairs, where each pair is [0, 1] or [1, 0].

    Returns:
        int: The total number of groups.
    """
    # Initialize the number of groups
    groups = 0

    # Iterate through the list of pairs
    for i in range(len(s)):
        # If it's the first pair, it starts a new group
        if i == 0:
            groups += 1
        else:
            # Check if the current pair is the same as the previous pair
            if s[i] == s[i - 1]:
                # Start a new group if the current pair differs
                groups += 1

    return groups


# Test Script
def test():
    A = [0, 1]
    B = [1, 0]
    test_cases = [
        ([A], 1),
        ([A, B], 1),
        ([A, A], 2),
        ([A, A, B], 2),
        ([A, B, A, B], 1),
        ([A, B, A, A, A, B, B, B], 5),
        ([A, B, B, B, A, A, B, B, B, B], 7),
        ([A, B, A, B, A, B, A, B, A, B, A], 1),
        ([A, A, A, A, A, A, B, B, B, B], 9),
        ([A, A, A, A, A, A, A, A, A, A], 10)
    ]

    for s, expected_output in test_cases:
        try:
            output = solution(s)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`s`: {s}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`s`: {s}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()