Find two different positions i < j with nums[i] + nums[j] == target. If there are several such pairs, choose the one with the smallest j, and for that j the smallest i.
Input
The first line has n and target (2 ≤ n ≤ 10⁵). The second line has the n integers.
Output
i j (positions start at 0), or none.
Examples
Example 1 · Input
4 9 2 7 11 15
Expected output
0 1
Example 2 · Input
5 6 3 3 2 4 3
Expected output
0 1
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
For each number x, the partner you need is target − x.
Hint 2
A dictionary from number to its first position finds the partner in O(1).
Hint 3
Check for the partner before adding x, so x is not paired with itself.
Solution
Show one correct solution (try it yourself first)
n, target = map(int, input().split())
nums = list(map(int, input().split()))
first = {} # number -> its first position
for j, x in enumerate(nums):
if target - x in first:
print(first[target - x], j)
break
first.setdefault(x, j)
else:
print("none")