n = int(input().strip())
    elements = list(map(int, input().strip().split()))
    oldVal, newVal = map(int, input().strip().split())

    # Check input length validity
    if len(elements) != n:
        print("Invalid input")
    else:
        # Check if oldVal exists in the list
        if oldVal not in elements:
            print("Value not found")
        else:
            # Replace all occurrences
            updated = [newVal if x == oldVal else x for x in elements]
            print(*updated)

except:
    print("Invalid input")