You are given an array $a$ consisting of $n$ integer numbers.

Let instability of the array be the following value: $\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$.

You have to remove exactly one element from this array to minimize instability of the resulting $(n-1)$-elements array. Your task is to calculate the minimum possible instability.


-----Input-----

The first line of the input contains one integer $n$ ($2 \le n \le 10^5$) — the number of elements in the array $a$.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^5$) — elements of the array $a$.


-----Output-----

Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $a$.


-----Examples-----
Input
4
1 3 3 7

Output
2

Input
2
1 100000

Output
0



-----Note-----

In the first example you can remove $7$ then instability of the remaining array will be $3 - 1 = 2$.

In the second example you can remove either $1$ or $100000$ then instability of the remaining array will be $100000 - 100000 = 0$ and $1 - 1 = 0$ correspondingly.

Difficulty: introductory

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(min(a[-1] - a[1], a[-2] - a[0]))


n=int(input())
a=list(map(int,input().split()))
a.sort()
if a[1]-a[0]>=a[-1]-a[-2]:
    print(a[-1]-a[1])
else:
    print(a[-2]-a[0])


n=int(input())
arr=list(map(int,input().split()))
arr.sort()
val1=max(arr)-min(arr[1:])
val2=max(arr[:n-1])-min(arr)
print(min(val1,val2))


n = int(input())
nums = sorted(list(map(int, input().split())))

r1 = nums[-2] - nums[0]
r2 = nums[-1] - nums[1]
print(min(r1, r2))


#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, = getIntList()
#print(N)
za = getIntList()

za.sort()

t = za[-1] - za[1]
t1 = za[-2] - za[0]

print(min(t,t1))







n = int(input())
a = list(map(int,input().split()))
a.sort()

if(len(a) == 2):
	print(0)
else:
	print(min(a[-1]-a[1], a[-2]-a[0]))

def read_nums():
    return [int(x) for x in input().split()]


def main():
    n, = read_nums()
    nums = sorted(read_nums())
    res = min(nums[-2] - nums[0], nums[-1] - nums[1])
    print(res)


def __starting_point():
    main()

__starting_point()

def solve():
    n = int(input())
    arr = [int(k) for k in input().split()]
    
    arr.sort()
    
    if n == 2:
        print (0)
        return
    
    ans = arr[-1] - arr[1]
    ans = min(ans, arr[-2] - arr[0])
    
    print (ans)
    
def __starting_point():
    solve()
__starting_point()

# alpha = "abcdefghijklmnopqrstuvwxyz"
t = 1
for test in range(t):
    # n,s = (map(int, input().split()))
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    if a[1]-a[0]>a[-1]-a[-2]:
        print(a[-1]-a[1])
    else:
        print(a[-2]-a[0])



def go():
    n = int(input())
    a = [int(i) for i in input().split(' ')]
    if n == 2:
        return 0
    m1 = max(a)
    a.remove(m1)
    m2 = max(a)
    mi1 = min(a)
    a.remove(mi1)
    mi2 = min(a)
    if m2 - mi1 < m1 - mi2:
        return m2 - mi1
    return m1 - mi2

print(go())


n = input()
arr = [int(x) for x in input().split()]
arr.sort()

x1, x2 = arr[0], arr[1]
y1, y2 = arr[-1], arr[-2]

if (y2 - x1) > (y1 - x2):
    print(y1 - x2)
else:
    print(y2 - x1)


n=int(input())
a=[int(s) for s in input().split()]
a.sort()
mn1=a[n-2]-a[0]
mn2=a[n-1]-a[1]
print(min(mn1,mn2))


#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    a=list(map(int,sys.stdin.readline().split(' ')))
    a.sort()

    print(min(a[-2]-a[0],a[-1]-a[1]))
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()


n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
if n > 2:
    ans = min(a[-2] - a[0], a[-1] - a[1])
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if a[1]-a[0]>a[-1]-a[-2]:
	del a[0]
else:
	del a[-1]
print(a[-1]-a[0])

n = int(input())
s = list(map(int, input().split()))
M = max(s)
m = min(s)
i = M - m
s.remove(M)
M1 = max(s)
i1 = M1 - m
s.append(M)
s.remove(m)
m1 = min(s)
i2 = M - m1
print(min(i,i1,i2))


from operator import itemgetter
#int(input())
#map(int,input().split())
#[list(map(int,input().split())) for i in range(q)]
#print("YES" * ans + "NO" * (1-ans))
n = int(input())
ai = list(map(int,input().split()))
ai.sort()
print(min(ai[-2] - ai[0],ai[-1] - ai[1]))


n=int(input())
a=list(map(int,input().split()))
a.sort()
print(min(a[n-1]-a[1],a[n-2]-a[0]))

n = int(input())
a = sorted(list(map(int, input().split())))
print(min(a[n - 2] - a[0], a[n - 1] - a[1]))

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans1 = l[-2] - l[0]
ans2 = l[-1] - l[1]
print(min(ans1, ans2))


n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
print(min(a[0] - a[-2], a[1] - a[-1]))

n=int(input())
l=list(map(int,input().split()))
l.sort()
print(min(l[n-1]-l[0],l[n-1]-l[1],l[n-2]-l[0]))

import sys
sys.setrecursionlimit(10**6)

def main(): 
   nbEntrees = int(input())
   nb = list(map(int, input().split()))
   maximum = max(nb)
   nb.remove(maximum)

   etendue = max(nb) - min(nb)
   nb.append(maximum)
   maximum = min(nb)
   nb.remove(maximum)
   
   etendue = min(etendue, max(nb) - min(nb))

   print(etendue)

main()

#codeforces _1095B_live
gi = lambda : list(map(int,input().split()))
n, = gi()
l = gi()
l.sort()
ans = min(max(l)-min(l[1:]),(max(l[:-1])-min(l)))
print(ans)