// editor5
def warehouse_update():
    try:
        # Input for the number of elements in the sequence
        n = input()

        # Check if n is an integer
        if not n.isdigit():
            print("Invalid input")
            return

        n = int(n)

        # Input for the list of elements in the sequence
        sequence = input().split()

        # Verify if the input contains only integers
        if not all(item.isdigit() for item in sequence):
            print("Invalid input")
            return

        # Convert sequence elements from strings to integers
        sequence = list(map(int, sequence))

        # Check if the number of elements matches n
        if len(sequence) != n:
            print("Invalid input")
            return

        # Input for oldVal and newVal (used to update the sequence)
        try:
            oldVal, newVal = map(int, input().split())
        except ValueError:
            print("Invalid input")
            return

        # Replace occurrences of oldVal with newVal
        if oldVal in sequence:
            updated_sequence = [newVal if item == oldVal else item for item in sequence]
            print(" ".join(map(str, updated_sequence)))
        else:
            print("Value not found")

    except Exception as e:
        print("Invalid input")


# Run the function
warehouse_update()