Program to Interchange first and last elements in list
n = int(input())
li = list(map(int,input().split()))[:n]
#Swapping first and last elements
li[0],li[-1] = li[-1],li[0]
print(*li)
li = list(map(int,input().split()))[:n]
#Swapping first and last elements
li[0],li[-1] = li[-1],li[0]
print(*li)
Input
5
1 2 3 4 5
Output
5 2 3 4 1
5
1 2 3 4 5
Output
5 2 3 4 1