# Problem Description
This is a grouping problem where we need to calculate the number of groups that can be formed from pairs of direction symbols ('<', '>'). 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 direction symbols: either ['<', '>'] or ['>', '<']
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: ['<', '>'] can connect with ['>', '<'] because they share '>' 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[str]]) -> int:
    """
    Calculate the number of groups in a list of direction pairs.
    Each inner list contains exactly two direction symbols: either ['<', '>'] or ['>', '<'].

    Parameters:
        s (List[List[str]]): A list of direction pairs, where each pair is ['<', '>'] or ['>', '<'].

    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 = ['<', '>']
    B = ['>', '<']
    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`: {[pair for pair in 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`: {[pair for pair in s_]}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()