Generate program that has the following intention:

The intention of the program below is to create a modified version of the input array arr by sorting it in a specific way. The function p3(arr, k) takes two inputs: an array arr and an integer k. The function first creates a k-length counter array counts and iterates through the elements of arr. For each element x, it increments the corresponding counter in counts.

Next, it initializes an empty array sorted_arr. It iterates through the counts array and extends the sorted_arr with i (the index of the counter) repeated count times. Finally, the function returns the sorted array sorted_arr.

The purpose of this program is to create a sorted array where each element i appears counts[i] times in the output, effectively counting the occurrences of each element in the input array arr.
