CodeforcesJun 06, 2025

Heist

Hazrat Ali

Codeforces

All keyboards which were in the store yesterday were numbered in ascending order from some integer number xx. For example, if x=4x=4 and there were 33 keyboards in the store, then the devices had indices 4455 and 66, and if x=10x=10 and there were 77 of them then the keyboards had indices 101011111212131314141515 and 1616.

After the heist, only nn keyboards remain, and they have indices a1,a2,,ana1,a2,…,an. Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither xx nor the number of keyboards in the store before the heist.

Input

The first line contains single integer nn (1n1000)(1≤n≤1000) — the number of keyboards in the store that remained after the heist.

The second line contains nn distinct integers a1,a2,,ana1,a2,…,an (1ai109)(1≤ai≤109) — the indices of the remaining keyboards. The integers aiai are given in arbitrary order and are pairwise distinct.

Output

Print the minimum possible number of keyboards that have been stolen if the staff remember neither xx nor the number of keyboards in the store before the heist.

Examples
Input
4
10 13 12 8
Output
2
Input
5
7 5 6 4 8
Output
0

Solution

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << a[n - 1] - a[0] + 1 - n << endl;
    return 0;
}

 

Comments