#include <iostream>
#include <vector>

int main() {
	typedef unsigned int balloon;
	typedef unsigned int price;
	typedef unsigned short num;

	std::vector<balloon>balloons;
	price Price = 0;
	{
		num n;
		std::cin >> n;
		balloons.resize(n);

		for (num i = 0;i < n;i++) {
			std::cin >> balloons[i];
		}
	}
	//vector is filled
	//take the futherest balloon
	//if balloon[i] == 0, then Kozak Vus have balloon
	//_ and pop it
	{
		num take;
		for (int i = balloons.size() - 1;i >= 0;i--) {
			take = balloons[i];
			Price += take;
			balloons.erase(balloons.begin() + i);

			
			for (short j = 0;j < balloons.size();j++) {
				if (balloons[j] != take) balloons[j]--;
				if (balloons[j] < 1) {
					balloons.erase(balloons.begin());
					j--;
					i--;
				}
			}
		}
	}

	{
		std::cout << Price;
	}
}
