#C8044. Find Leftmost Positions

    ID: 51983 Type: Default 1000ms 256MiB

Find Leftmost Positions

Find Leftmost Positions

Given an array of n integers sorted in non-decreasing order, your task is to determine the leftmost occurrence of each unique element. Formally, for each unique element \(x\), you need to find the minimum index \(i\) such that \(nums[i] = x\). Output the results as pairs, where each pair consists of the unique element and its corresponding leftmost index.

For example, if the input array is [1, 1, 2, 2, 2, 3, 3, 4, 4, 4], the output should be:

1 0
2 2
3 5
4 7

Make sure your solution reads from standard input and writes to standard output.

inputFormat

The input is given via standard input and consists of two lines:

  • The first line contains a single integer \(n\) indicating the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the sorted array in non-decreasing order.

outputFormat

For each unique element (in the order of their first appearance), output a line containing two space-separated integers: the element value and its leftmost index.

## sample
10
1 1 2 2 2 3 3 4 4 4
1 0

2 2 3 5 4 7

</p>