# Problem Description
This is a problem about implementing a custom binary operation on two sequences of integers. The operation involves binary conversions, bitwise AND operations, and addition. Given two sequences of integers, we need to process each sequence independently using binary operations and then combine their results.

# Visual Facts
1. The image shows two examples demonstrating the operation:
   - Example 1: Seq1 = [2,4,2], Seq2 = [3,3,13] → Result = 1
   - Example 2: Seq1 = [4,4,6], Seq2 = [3,3,7] → Result = 7

2. Each sequence gets processed through these steps:
   - Numbers are converted to binary (shown in parentheses)
   - Binary AND operations are performed between all numbers
   - Result is converted back to decimal

3. For Example 1:
   - Seq1: 2(010) AND 4(100) AND 2(010) = 0(000)
   - Seq2: 3(011) AND 3(011) AND 13(1101) = 1(001)

4. For Example 2:
   - Seq1: 4(100) AND 4(100) AND 6(110) = 4(100)
   - Seq2: 3(011) AND 3(011) AND 7(111) = 3(011)

# Visual Patterns
1. Binary Operation Pattern:
   - Each number in a sequence is converted to binary
   - A bitwise AND operation is applied across all binary numbers in the sequence
   - The result is converted back to decimal

2. Combination Pattern:
   - The decimal results from both sequences are added together
   - Example 1: 0 + 1 = 1
   - Example 2: 4 + 3 = 7

3. Sequence Processing Pattern:
   - Each sequence is processed independently
   - The order of numbers within each sequence doesn't affect the result (due to AND operation properties)
   - The length of both sequences appears to be the same in examples (3 numbers each)

4. Binary Conversion Rules:
   - Numbers are represented in 3 or 4 bits as needed
   - Leading zeros are included in the binary representation where shown
   - The AND operation preserves the maximum number of bits needed for representation


# Solution
from typing import List

def solution(sequence1: List[int], sequence2: List[int]) -> int:
    """
    Applies a custom operation to two integer sequences and returns their combined result.

    Args:
        sequence1: First sequence of integers
        sequence2: Second sequence of integers

    Returns:
        Integer result after applying the operation on both sequences
    """
    # Helper function to calculate AND result for a sequence
    def calculate_and(sequence: List[int]) -> int:
        if not sequence:
            return 0  # If the sequence is empty, return 0
        result = sequence[0]  # Initialize result with the first element
        for num in sequence[1:]:
            result &= num  # Perform bitwise AND with the current result
        return result

    # Calculate AND results for both sequences
    result1 = calculate_and(sequence1)
    result2 = calculate_and(sequence2)

    # Return the sum of the two AND results
    return result1 + result2


# Test Script
def test():
    test_cases = [
        {"input": ([2, 4, 2], [3, 3, 13]), "expected": 1},
        {"input": ([4, 5, 6], [3, 1, 7]), "expected": 5},
        {"input": ([1], [2]), "expected": 3},
        {"input": ([0, 0, 0], [0, 0, 0]), "expected": 0},
        {"input": ([8, 16, 32], [7, 3]), "expected": 3}, 
        {"input": ([1, 2, 4, 8], [1, 2, 4, 8]), "expected": 0},
        {"input": ([1, 3, 5, 7], [2, 4, 6, 8]), "expected": 1},
        {"input": ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]), "expected": 0},
        {"input": ([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]), "expected": 0},
        {"input": ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]), "expected": 0},
    ]

    for i, test_case in enumerate(test_cases, start=1):
        sequence1, sequence2 = test_case["input"]
        expected_output = test_case["expected"]
        
        try:
            output = solution(sequence1, sequence2)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`sequence1`: {sequence1}\n"
                f"`sequence2`: {sequence2}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message
            
        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`sequence1`: {sequence1}\n"
                f"`sequence2`: {sequence2}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()