#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	std::map<int, int> f;
	for (auto& v : a)
	{
		std::cin >> v;
		if (f.find(v) != f.end())
			f[v]++;
		else
			f[v] = 1;
	}
	long long r = 0;
	int c = 0;
	for (const auto& p : f)
	{
		int i = p.first;
		int v = p.second;
		c += v;
		r += (long long)v * std::max((i - (n - c)), 0);
	}
	std::cout << r << std::endl;
}
