Your task is to write a function that does just what the title suggests (so, fair warning, be aware that you are not getting out of it just throwing a lame bas sorting method there) with an array/list/vector of integers and the expected number `n` of smallest elements to return.

Also:

* the number of elements to be returned cannot be higher than the array/list/vector length;
* elements can be duplicated;
* in case of duplicates, just return them according to the original order (see third example for more clarity).

Same examples and more in the test cases:

```python
first_n_smallest([1,2,3,4,5],3) == [1,2,3]
first_n_smallest([5,4,3,2,1],3) == [3,2,1]
first_n_smallest([1,2,3,4,1],3) == [1,2,1]
first_n_smallest([1,2,3,-4,0],3) == [1,-4,0]
first_n_smallest([1,2,3,4,5],0) == []
```

[Performance version by FArekkusu](https://www.codewars.com/kata/5aeed69804a92621a7000077) also available.

Source: codewars | Difficulty: EASY
Tags: Data structures

Starter code: def first_n_smallest(arr, n):
	

Solutions:
def first_n_smallest(arr, n):
	lst = sorted(enumerate(arr), key=lambda it: it[1])[:n]
	lst.sort(key=lambda it: it[0])
	return [v for (_, v) in lst]


def first_n_smallest(arr, n):
	m = sorted(arr)[:n]
	return [m.pop(m.index(i)) for i in arr if i in m]


from operator import itemgetter

def first_n_smallest(arr, n):
	(by_index, by_value) = map(itemgetter, (0, 1))
	all_ascending = sorted(enumerate(arr), key=by_value)
	n_chronologic = sorted(all_ascending[:n], key=by_index)
	return list(map(by_value, n_chronologic))


def first_n_smallest(arr, n):
	return [x[1] for x in sorted(sorted(enumerate(arr), key=lambda x: x[1])[:n])]


def first_n_smallest(arr, n):
	smallest = []
	replacement = max(arr) + 1
	while n and arr:
		num = min(arr)
		idx = arr.index(num)
		arr[idx] = replacement
		smallest.append((num, idx))
		n -= 1
	sort = sorted(smallest, key=lambda pair: pair[1])
	return [p[0] for p in sort]


def first_n_smallest(lst, n):
	std = sorted(enumerate(lst), key=lambda e: e[1])[:n]
	return [n for (i, n) in sorted(std)]


from collections import Counter

def first_n_smallest(arr, n):

	def f():
		xs = Counter(sorted(arr)[:n])
		for x in arr:
			if xs[x]:
				xs[x] -= 1
				yield x
	return list(f())


from heapq import nsmallest

def first_n_smallest(arr, n):
	small = nsmallest(n, arr)
	return [a for a in arr if a in small and (small.remove(a) or 1)]


first_n_smallest = lambda a, n: [v for (_, v) in sorted(sorted(enumerate(a), key=lambda x: x[1])[:n])]


def first_n_smallest(arr, n):
	for i in range(len(arr) - n):
		arr.pop(len(arr) - 1 - arr[::-1].index(max(arr)))
	return arr