Group by Value
Given an array of N integers, group the indices of the array by the value of the element at that index. For each distinct value present in the array, print the indices where it appears, in ascending order. The groups themselves should be printed in ascending order of the values they represent.
Input
The first line contains an integer N. The second line contains N space-separated integers, the elements of the array.
Output
For each distinct value in the input array, print a line. The line should start with the value, followed by a colon, a space, and then the indices (0-based) where this value appears, separated by spaces. The lines should be ordered by the distinct values in ascending order.
Constraints
1 <= N <= 200000. The values in the array are integers between -10^9 and 10^9.
Example 1
5 1 2 1 3 2
1: 0 2 2: 1 4 3: 3
Value 1 appears at indices 0 and 2. Value 2 appears at indices 1 and 4. Value 3 appears at index 3. Groups are printed in ascending order of values: 1, 2, 3.
Example 2
7 10 20 10 10 20 30 10
10: 0 2 3 6 20: 1 4 30: 5
Value 10 at indices 0, 2, 3, 6. Value 20 at indices 1, 4. Value 30 at index 5. Groups printed for 10, 20, 30.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 1 2 1 3 2
7 10 20 10 10 20 30 10