# Problem Description
This is a problem about implementing a custom binary operation on two sequences of integers. The operation involves binary conversions, bitwise XOR 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,12] → Result = 16
   - Example 2: Seq1 = [4,4,4], Seq2 = [3,1,7] → Result = 9

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

3. For Example 1:
   - Seq1: 2(010) XOR 4(100) XOR 2(010) = 4(100)
   - Seq2: 3(011) XOR 3(011) XOR 12(1100) = 12(1100)

4. For Example 2:
   - Seq1: 4(100) XOR 4(100) XOR 4(100) = 4(100)
   - Seq2: 3(011) XOR 1(001) XOR 7(111) = 5(101)

# Visual Patterns
1. Binary Operation Pattern:
   - Each number in a sequence is converted to binary
   - A bitwise XOR 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: 4 + 12 = 16
   - Example 2: 4 + 5 = 9

3. Sequence Processing Pattern:
   - Each sequence is processed independently
   - The order of numbers within each sequence doesn't affect the result (due to XOR 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 XOR 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, 12]), "expected": 16},
        {"input": ([4, 5, 6], [3, 1, 7]), "expected": 12},
        {"input": ([1], [2]), "expected": 3},
        {"input": ([0, 0, 0], [0, 0, 0]), "expected": 0},
        {"input": ([8, 16, 32], [7, 3]), "expected": 60}, 
        {"input": ([1, 2, 4, 8], [1, 2, 4, 8]), "expected": 30},
        {"input": ([1, 3, 5, 7], [2, 4, 6, 8]), "expected": 8},
        {"input": ([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]), "expected": 11},
        {"input": ([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]), "expected": 2},
        {"input": ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]), "expected": 2},
    ]

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