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
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>

#define ull unsigned long long

int main(int argc, char** argv)
{
  std::ios_base::sync_with_stdio(false);
  int N;
  std::cin>>N;
  std::vector<ull> costs;
  costs.reserve(N * (N / 2 + 1));
  for(int i = 0; i < N; ++i)
  {
    for(int j = i; j < N; ++j)
    {
      ull v;
      std::cin>>v;
      costs.push_back(v);
    }
  }

  std::sort(costs.begin(), costs.end(), std::less<ull>());

  std::cout<<std::accumulate(costs.begin(), costs.begin() + N , 0L)<<std::endl;
 
  return 0;
}