def two_sum(nums, target):
num_to_index = {} # Dictionary to store numbers and their indices
for index, num in enumerate(nums):
complement = target - num
# Check if the complement exists in the dictionary
if complement in num_to_index:
return [num_to_index[complement], index], [complement, num]
# Store the current number and its index in the dictionary
num_to_index[num] = index
return None # If no solution is found
# Input
nums = list(map(int, input("Enter a list of integers separated by spaces: ").split()))
target = int(input("Enter the target sum: "))
result = two_sum(nums, target)
if result:
indices, numbers = result
print(f"The indices of the two numbers are {indices[0]} and {indices[1]}.")
print(f"The two numbers are {numbers[0]} and {numbers[1]}.")
else:
print("No solution found.")