#include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int num, val, ans = INT_MAX - 101; int lower, upper; vector lst { INT_MIN + 100, INT_MAX - 100 }; vector::iterator itIn, itRef; cin >> num; while(num) { cin >> val; itIn = find_if(lst.begin(), lst.end(), [=](int l){ return val < l; }); itRef = lst.insert(itIn, val); lower = *(itRef + 0) - *(itRef - 1); upper = *(itRef + 1) - *(itRef + 0); if(lower) { ans = min(min(lower, upper), ans); } else { lst.erase(itRef); } --num; } cout << ans << endl; return 0; }