Second Largest and Second Smallest

Program to find second largest and second smallest number from the list.

n = int(input())
li = list(map(int,input().split()))[:n]
li.sort()
print(li[1],li[-2])
Input
7
8 6 4 2 9 7 3
Output
3 8