#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return (b ? __gcd(a, b) : a);
}
template <typename T>
T lcm(T a, T b) {
  return (a * (b / gcd(a, b)));
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream &operator<<(ostream &os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream &operator<<(ostream &os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}";
}
namespace fio {
template <typename T>
void scan(T &x) {
  cin >> x;
}
template <class T>
void scan(vector<T> &a);
template <class T>
void scan(vector<T> &a) {
  for (int i = 0; i < ((int)(a).size()); ++i) scan(a[i]);
}
template <class T, class... Ts>
void scan(T &t, Ts &...ts) {
  scan(t);
  scan(ts...);
}
template <typename T>
void print(T x) {
  cout << x << endl;
}
template <class T, class... Ts>
void println(const T &t, const Ts &...ts) {
  println(t);
  println(ts...);
}
}  // namespace fio
using namespace fio;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  scan(n);
  vector<int> v(n);
  scan(v);
  sort(begin(v), end(v));
  int ans = 0;
  for (int i = 1; i < (n); ++i)
    if (v[i] <= v[i - 1]) {
      ans += v[i - 1] - v[i] + 1;
      v[i] = v[i - 1] + 1;
    }
  print(ans);
  return 0;
}
