1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

#define getchar_custom getc_unlocked

//#define DEBUG

char c;

template <typename T>
inline T read_custom() {

	c = getchar_custom(stdin);

	while (c<'0' || c>'9')
	{
		c = getchar_custom(stdin);
	}

	T returnValue = 0;
	while (c >= '0' && c <= '9') {
		returnValue = (returnValue << 3) + (returnValue << 1) + c - 48;
		c = getchar_custom(stdin);
	}

	return returnValue;
}

int main() {


	int n = read_custom<int>();

	std::vector<long long> v;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - i; j++) {
			v.push_back(read_custom<long long>());
		}
	}
    std::sort(v.begin(), v.end());


	long long sum = 0;
	for (int i = 0; i < n ;  i++) {
	    sum += v[i];
	}

    std::cout << sum << std::endl;

}