n=int(input())
def output():
global n
s=list(map(int,input().split(' ')))
x,y=max(s),min(s)
s.pop(s.index(x))
s.pop(s.index(y))
try:
if x-min(s)>max(s)-y:
return max(s)-y
else:
return x-min(s)
except:
return 0
print(output())
/*
ID: yassine0
LANG: C++17
PROB: Diamond Collector
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void reverseStr(string& str)
{
int n = str.length();
for (int i = 0; i < n / 2; i++)
swap(str[i], str[n - i - 1]);
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;cin>>n;
vector<ll>v(n);
for(ll i=0;i<n;i++){
cin>>v[i];
}
sort(v.begin(),v.end());
if(n==2){
cout<<0;
}
else{
cout<<min(v[n-2]-v[0],v[n-1]-v[1]);
}
}
1401C - Mere Array | 1613B - Absent Remainder |
1536B - Prinzessin der Verurteilung | 1699B - Almost Ternary Matrix |
1545A - AquaMoon and Strange Sort | 538B - Quasi Binary |
424A - Squats | 1703A - YES or YES |
494A - Treasure | 48B - Land Lot |
835A - Key races | 1622C - Set or Decrease |
1682A - Palindromic Indices | 903C - Boxes Packing |
887A - Div 64 | 755B - PolandBall and Game |
808B - Average Sleep Time | 1515E - Phoenix and Computers |
1552B - Running for Gold | 994A - Fingerprints |
1221C - Perfect Team | 1709C - Recover an RBS |
378A - Playing with Dice | 248B - Chilly Willy |
1709B - Also Try Minecraft | 1418A - Buying Torches |
131C - The World is a Theatre | 1696A - NIT orz |
1178D - Prime Graph | 1711D - Rain |