Problem:
Problem C:
Towns along a Highway
There are several towns on a highway. The highway has no forks. Given the distances between the neighboring towns, we can calculate all distances from any town to others. For example, given five towns (A, B, C, D and E) and the distances between neighboring towns like in Figure C.1, we can calculate the distance matrix as an upper triangular matrix containing the distances between all pairs of the towns, as shown in Figure C.2.
Figure C.1: An example of towns
Figure C.2: The distance matrix for Figure C.1
In this problem, you must solve the inverse problem. You know only the distances between all pairs of the towns, that is,
N
(
N
- 1)/2 numbers in the above matrix. Then, you should recover the order of the towns and the distances from each town to the next.
Input
The input is a sequence of datasets. Each dataset is formatted as follows.
N
d
1
d
2
...
d
N
(
N
-1)/2
The first line contains an integer
N
(2 ≤
N
≤ 20), which is the number of the towns on the highway. The following lines contain
N
(
N
-1)/2 integers separated by a single space or a newline, which are the distances between all pairs of the towns. Numbers are given in descending order without any information where they appear in the matrix. You can assume that each distance is between 1 and 400, inclusive. Notice that the longest distance is the distance from the leftmost town to the rightmost.
The end of the input is indicated by a line containing a zero.
Output
For each dataset, output
N
- 1 integers in a line, each of which is the distance from a town to the next in the order of the towns. Numbers in a line must be separated by a single space. If the answer is not unique, output multiple lines ordered by the lexicographical order as a sequence of integers, each of which corresponds to an answer. For example, '
2 10
' should precede '
10 2
'. If no answer exists, output nothing. At the end of the output for each dataset, a line containing five minus symbols '
-----
' should be printed for human readability. No extra characters should occur in the output. For example, extra spaces at the end of a line are not allowed.
Sample Input
2
1
3
5 3 2
3
6 3 2
5
9 8 7 6 6 4 3 2 2 1
6
9 8 8 7 6 6 5 5 3 3 3 2 2 1 1
6
11 10 9 8 7 6 6 5 5 4 3 2 2 1 1
7
72 65 55 51 48 45 40 38 34 32 27 25 24 23 21 17 14 13 11 10 7
20
190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171
170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151
150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131
130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111
110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91
90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71
70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51
50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11
10 9 8 7 6 5 4 3 2 1
19
60 59 58
...(truncated)

Submitted solutions:

code_snippet: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <iostream>
#include <vector>
using namespace std;
int d[500];
int sum[100];
int n;
vector<int>ans[1148576];
int cnt;
bool vis[1148576];
int dis[500];
int num[500];
bool check(int l,int r,int id,int val)
{
	bool flag=true;
	dis[id]=val;
	for(int i=1;i<=l;i++)
	{
	    num[dis[id]-dis[i]]--;
        if(num[dis[id]-dis[i]]<0)
        {
            flag=false;
        }
	}
	for(int i=r;i<=n;i++)
    {
        num[dis[i]-dis[id]]--;
        if(num[dis[i]-dis[id]]<0)
        {
            flag=false;
        }
    }
	if(flag) return true;
	return false;
}
void dfs(int l,int r)
{
    if(l==r-1)
    {
        for(int i=1;i<=n;i++)
        {
            ans[cnt].push_back(dis[i]);
        }
        cnt++;
        return ;
    }
    int k=1;
	while(num[d[k]]==0) k++;
	if(check(l,r,l+1,dis[n]-d[k]))dfs(l+1,r);
	for(int i=1;i<=l;i++)
    {
        num[dis[l+1]-dis[i]]++;
    }
	for(int i=r;i<=n;i++)
    {
        num[dis[i]-dis[l+1]]++;
    }
	if(check(l,r,r-1,d[k]))dfs(l,r-1);
	for(int i=1;i<=l;i++)
	{
	    num[dis[r-1]-dis[i]]++;
	}
	for(int i=r;i<=n;i++)
    {
        num[dis[i]-dis[r-1]]++;
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        if(n==0)break;
        cnt=0;
        memset(vis,0,sizeof(vis));
        memset(num,0,sizeof(num));
        for(int i=0;i<300000;i++)
        {
            ans[i].clear();
        }
        for(int i=0;i<n*(n-1)/2;i++)
        {
            scanf("%d",d+i);
            num[d[i]]++;
        }
        dis[n]=d[0];
        num[d[0]]--;
        memset(sum,0,sizeof(sum));
        dfs(1,n);
        for(int i=0;i<cnt;i++)
        {
            if(vis[i])continue;
            for(int j=i+1;j<cnt;j++)
            {
                int len=ans[i].size();
                int k;
                for(k=0;k<len;k++)
                {
                    if(ans[i][k]!=ans[j][k])break;
                }
                if(k==len)
                {
                    vis[j]=1;
                }

            }
        }
       // cout<<"~~"<<cnt<<endl;
        for(int i=0;i<cnt;i++)
        {
            if(vis[i])continue;
            int len=ans[i].size();
            for(int k=1;k<len;k++)
            {
                if(k==len-1)
                printf("%d\n",ans[i][k]-ans[i][k-1]);
                else
                printf("%d ",ans[i][k]-ans[i][k-1]);
            }
        }
        printf("-----\n");
    }
}
accuracy: 1
time_ms: 20
memory_kb: 31440
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define per(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define per2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define each(e, x) for (auto &e : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define eb emplace_back
#define MM << ' ' <<
#define TT template <typename T>
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

TT bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
TT bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

TT using minheap = priority_queue<T, vector<T>, greater<T>>;
TT using maxheap = priority_queue<T>;

TT void print(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (n == 0) cout << '\n';
}

TT void printn(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << '\n';
}

TT void rearrange(vector<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), end(v));
}

TT int lb(vector<T> &v, T x) { return lower_bound(all(v), x) - begin(v); }
TT int ub(vector<T> &v, T x) { return upper_bound(all(v), x) - begin(v); }

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main() {
    while (true) {
        int N;
        cin >> N;
        if (N == 0) break;

        int D;
        cin >> D;

        vector<int> c(D + 1, 0);
        rep(i, N * (N - 1) / 2 - 1) {
            int x;
            cin >> x;
            c[x]++;
        }

        auto solve = [&](int S) -> vector<int> {
            int ptr = D;
            vector<int> d(N);
            d[0] = 0, d[N - 1] = D;
            auto c2 = c;
            int l = 1, r = N - 2;
            rep(i, N - 2) {
                while (ptr > 0 && c2[ptr] == 0) ptr--;
                if ((S >> i) & 1) {
                    d[r] = d[0] + ptr;
                    rep(j, l) {
                        int x = d[r] - d[j];
                        if (x < 0 || c2[x]-- == 0) return {};
                    }
                    rep2(j, r + 1, N) {
                        int x = d[j] - d[r];
                        if (x < 0 || c2[x]-- == 0) return {};
                    }
                    r--;
                } else {
                    d[l] = d[N - 1] - ptr;
                    rep(j, l) {
                        int x = d[l] - d[j];
                        if (x < 0 || c2[x]-- == 0) return {};
                    }
                    rep2(j, r + 1, N) {
                        int x = d[j] - d[l];
                        if (x < 0 || c2[x]-- == 0) return {};
                    }
                    l++;
                }
            }
            vector<int> ret(N - 1);
            rep(i, N - 1) ret[i] = d[i + 1] - d[i];
            return ret;
        };

        vector<vector<int>> ans;
        rep(S, 1 << (N - 2)) {
            auto v = solve(S);
            if (!empty(v)) ans.eb(v);
        }

        rearrange(ans);

        each(e, ans) print(e);
        cout << "-----\n";
    }
}
accuracy: 1
time_ms: 1210
memory_kb: 3208
final_rank: 16

code_snippet: #include "bits/stdc++.h"
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>int LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>int UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<vector<int>>ans;
void solve(multiset<int>kyo,vector<int>La,vector<int>Ra,int n,int S){
	//Sが両端の長さ
	int i;
	if(n==0){
		vector<int> now;
		for(i=1;i<La.size();i++){
			now.pub(La[i]-La[i-1]);
		}
		now.pub(S-La.back()-Ra.back());
		for(i=Ra.size()-1;i>0;i--){
			now.pub(Ra[i]-Ra[i-1]);
		}
		ans.pub(now);
		return;
	}
	int X=S-*prev(kyo.end());
	{
		auto kyob=kyo;
		if(La.back()>=X){goto LEND;}
		for(i=0;i<La.size();i++){
			auto itr=kyob.lower_bound(X-La[i]);
			if(itr==kyob.end()||*itr!=X-La[i]){goto LEND;}
			kyob.erase(itr);
		}
		for(i=0;i<Ra.size();i++){
			auto itr=kyob.lower_bound(S-Ra[i]-X);
			if(itr==kyob.end()||*itr!=S-Ra[i]-X){goto LEND;}
			kyob.erase(itr);
		}
		auto Lb=La;
		Lb.pub(X);
		solve(kyob,move(Lb),Ra,n-1,S);
	}
	LEND:
	{
		auto kyob=kyo;
		if(Ra.back()>=X){goto REND;}
		for(i=0;i<Ra.size();i++){
			auto itr=kyob.lower_bound(X-Ra[i]);
			if(itr==kyob.end()||*itr!=X-Ra[i]){goto REND;}
			kyob.erase(itr);
		}
		for(i=0;i<La.size();i++){
			auto itr=kyob.lower_bound(S-La[i]-X);
			if(itr==kyob.end()||*itr!=S-La[i]-X){goto REND;}
			kyob.erase(itr);
		}
		auto Rb=Ra;
		Rb.pub(X);
		solve(kyob,La,move(Rb),n-1,S);
	}
	REND:
	return;
}
int main(void){
	while(-1){
		int n,i,j,S;cin>>n;
		if(n==0){return 0;}
		cin>>S;
		multiset<int>kyo;
		for(i=1;i<n*(n-1)/2;i++){
			int x;cin>>x;kyo.ins(x);
		}
		solve(kyo,{0},{0},n-2,S);
		SO(ans);
		for(i=0;i<ans.size();i++){
			if(i>0&&ans[i]==ans[i-1]){continue;}
			for(j=0;j<ans[i].size();j++){
				cout<<ans[i][j];
				if(j+1!=ans[i].size()){cout<<" ";}
			}
			cout<<endl;
		}
		cout<<"-----"<<endl;
		ans.clear();
	}
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3484
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N;
int D[409], Count1[409], Count2[409];
vector<vector<int>> Answer;

void Initialize() {
	for (int i = 0; i < 409; i++) Count1[i] = 0;
	for (int i = 0; i < 409; i++) Count2[i] = 0;
	Answer.clear();
}

bool check(vector<int> List) {
	vector<int> Distance_List;
	for (int i = 0; i < (int)List.size(); i++) {
		int sum = 0;
		for (int j = i; j < (int)List.size(); j++) {
			sum += List[j];
			Distance_List.push_back(sum);
		}
	}
	sort(Distance_List.begin(), Distance_List.end());
	reverse(Distance_List.begin(), Distance_List.end());
	for (int i = 0; i < N*(N-1)/2; i++) {
		if (D[i] != Distance_List[i]) return false;
	}
	return true;
}

void dfs(int cur_dist, vector<int> V1, vector<int> V2) {
	int new_dist = cur_dist;
	int Left = V1[V1.size() - 1];
	int Right = V2[V2.size() - 1];
	while (new_dist >= 0) {
		if (Count1[new_dist] < Count2[new_dist]) return;
		if (Count1[new_dist] > Count2[new_dist]) break;
		new_dist -= 1;
	}
	/*cout << "> cur_dist = " << cur_dist << endl;
	cout << "> new_dist = " << new_dist << endl;
	cout << "> Count2[1] = " << Count2[1] << endl;
	cout << "> V1 = {"; for (int i = 0; i < (int)V1.size(); i++) { if (i) cout << ", "; cout << V1[i]; } cout << "}" << endl;
	cout << "> V2 = {"; for (int i = 0; i < (int)V2.size(); i++) { if (i) cout << ", "; cout << V2[i]; } cout << "}" << endl;
	cout << endl;*/
	
	// When All Completed
	if (new_dist == -1) {
		vector<int> Final;
		for (int i = 1; i < (int)V1.size(); i++) Final.push_back(V1[i] - V1[i-1]);
		Final.push_back(D[0] - Left - Right);
		for (int i = (int)V2.size() - 1; i >= 1; i--) Final.push_back(V2[i] - V2[i-1]);
		if (check(Final) == true) {
			Answer.push_back(Final);
		}
		return;
	}
	
	// Adding Left
	int new_left = D[0] - new_dist;
	if (new_left + Right < D[0] && new_left > Left) {
		vector<int> V3 = V1;
		for (int i : V1) Count2[new_left - i] += 1;
		for (int i : V2) Count2[D[0] - new_left - i] += 1;
		V3.push_back(new_left);
		dfs(new_dist, V3, V2);
		for (int i : V1) Count2[new_left - i] -= 1;
		for (int i : V2) Count2[D[0] - new_left - i] -= 1;
	}
	
	// Adding Right
	int new_right = D[0] - new_dist;
	if (new_right + Left < D[0] && new_right > Right) {
		vector<int> V3 = V2;
		for (int i : V1) Count2[D[0] - new_right - i] += 1;
		for (int i : V2) Count2[new_right - i] += 1;
		V3.push_back(new_right);
		dfs(new_dist, V1, V3);
		for (int i : V1) Count2[D[0] - new_right - i] -= 1;
		for (int i : V2) Count2[new_right - i] -= 1;
	}
}

int main() {
	while (true) {
		// Input
		Initialize();
		cin >> N; if (N == 0) break;
		for (int i = 0; i < N * (N-1) / 2; i++) cin >> D[i];
		for (int i = 0; i < N * (N-1) / 2; i++) Count1[D[i]] += 1;
		
		// Solve
		vector<int> ZERO = {0};
		Count2[D[0]] += 1;
		dfs(400, ZERO, ZERO);
		sort(Answer.begin(), Answer.end());
		Answer.erase(unique(Answer.begin(), Answer.end()), Answer.end());
		
		// Output
		for (int i = 0; i < (int)Answer.size(); i++) {
			for (int j = 0; j < N - 1; j++) {
				if (j >= 1) cout << " ";
				cout << Answer[i][j];
			}
			cout << endl;
		}
		cout << "-----" << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3540
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        set<vector<int>> ans;
        vector<int> cnsv(801);
        int ma=-1;
        for(int i=0;i<N*(N-1)/2;i++){
            int x;cin>>x;
            chmax(ma,x);
            cnsv[x]++;
        }
        cnsv[ma]--;
        
        for(int bit=0;bit<(1<<(N-2));bit++){
            int L=0,R=N-2;
            vector<int> kaku;
            for(int i=0;i<N-2;i++){
                if(bit&(1<<i)){
                    kaku.push_back(R);
                    R--;
                }else{
                    kaku.push_back(L);
                    L++;
                }
            }
            L=0;R=N-2;
            
            vector<int> cn=cnsv;
            vector<int> dis(N-1,-1);
            bool ok=true;
            int la=ma;
            for(int t=0;t<si(kaku);t++){
                while(cn[la]==0) la--;
                int x=kaku[t];
                
                if(L==x){
                    int rem=ma;
                    for(int i=0;i<L;i++) rem-=dis[i];
                    rem-=la;
                    if(rem<0||cn[rem]==0){
                        ok=false;
                        break;
                    }
                    dis[x]=rem;
                    
                    rem=ma;
                    for(int i=0;i<=L;i++) rem-=dis[i];
                    
                    for(int i=N-2;i>=R;i--){
                        if(rem<0||cn[rem]==0){
                            ok=false;
                            break;
                        }
                        cn[rem]--;
                        rem-=dis[i];
                    }
                    if(!ok) break;
                    
                    rem=0;
                    for(int i=L;i>=0;i--){
                        rem+=dis[i];
                        if(rem<0||cn[rem]==0){
                            ok=false;
                            break;
                        }
                        cn[rem]--;
                    }
                    if(!ok) break;
                    
                    L++;
                }else{
                    int rem=ma;
                    for(int i=R+1;i<N-1;i++) rem-=dis[i];
                    rem-=la;
                    if(rem<0||cn[rem]==0){
                        ok=false;
                        break;
                    }
                    dis[x]=rem;
                    
                    rem=ma;
                    for(int i=R;i<N-1;i++) rem-=dis[i];
                    
                    for(int i=0;i<=L;i++){
                        if(rem<0||cn[rem]==0){
                            ok=false;
                            break;
                        }
                        cn[rem]--;
                        rem-=dis[i];
                    }
                    if(!ok) break;
                    
                    rem=0;
                    for(int i=R;i<N-1;i++){
                        rem+=dis[i];
                        if(rem<0||cn[rem]==0){
                            ok=false;
                            break;
                        }
                        cn[rem]--;
                    }
                    if(!ok) break;
                    
                    R--;
                }
            }
            
            if(ok){
                int z=-1,sum=ma;
                for(int i=0;i<N-1;i++){
                    if(dis[i]==-1){
                        z=i;
                    }else{
                        sum-=dis[i];
                    }
                }
                dis[z]=sum;
                ans.insert(dis);
            }
        }
        
        for(auto a:ans){
            for(int i=0;i<N-1;i++){
                if(i) cout<<" ";
                cout<<a[i];
            }
            cout<<"\n";
        }
        cout<<"-----\n";
    }
}
accuracy: 1
time_ms: 3250
memory_kb: 3364
final_rank: 20

code_snippet: #line 1 "e.cpp"
// cSpell:disable
/*	author:  Kite_kuma
	created: 2022.09.14 00:17:26 */

#line 1 "SPJ-Library/data_structure/counter.hpp"
#include <cassert>
#include <iostream>
#include <map>

template <typename key_type, typename amount_type>
struct counter : public std::map<key_type, amount_type> {
	void increase(key_type key, amount_type amount = 1) {
		if(this->count(key)) {
			this->operator[](key) += amount;
			if(!this->operator[](key)) this->erase(key);
			return;
		}
		if(!amount) return;
		this->operator[](key) = amount;
	}

	void decrease(key_type key, amount_type amount = 1) { increase(key, -amount); }

	amount_type amount(key_type key) { return this->count(key) ? this->at(key) : 0; }
};

template <typename key_type, typename amount_type>
std::ostream &operator<<(std::ostream &os, const counter<key_type, amount_type> &ctr) {
	os << "{\n";
	for(typename counter<key_type, amount_type>::const_iterator it = ctr.begin(); it != ctr.end(); it++) {
		os << "\t[" << it->first << "] : " << it->second << '\n';
	}
	os << "}";
	return os;
}
#line 2 "SPJ-Library/template/kuma.hpp"

#line 2 "SPJ-Library/template/basic_func.hpp"

#include <algorithm>
#line 6 "SPJ-Library/template/basic_func.hpp"
#include <vector>

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

void Yes(bool flag = true) { std::cout << (flag ? "Yes" : "No") << '\n'; }
void YES(bool flag = true) { std::cout << (flag ? "YES" : "NO") << '\n'; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(const T &x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(const Head &H, const Tail &... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T value) {
	for(auto &a : v) a += value;
	return;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

// ceil(a / b);
template <class T>
T dup(T a, T b) {
	assert(b);
	if(b < 0) {
		a *= -1;
		b *= -1;
	}
	return least_upper_multiple(a, b) / b;
}

long long pow_ll(long long a, long long n) {
	assert(n >= 0LL);
	if(n == 0) return 1LL;
	if(a == 0) return 0LL;
	if(a == 1) return 1LL;
	if(a == -1) return (n & 1LL) ? -1LL : 1LL;
	long long res = 1;
	while(n > 1LL) {
		if(n & 1LL) res *= a;
		a *= a;
		n >>= 1;
	}
	return res * a;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, const long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(const std::vector<T> &a) {
	std::vector<T> vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(const auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}
#line 1 "SPJ-Library/template/header.hpp"
#include <bits/stdc++.h>
#line 2 "SPJ-Library/template/io.hpp"

#line 4 "SPJ-Library/template/io.hpp"

#line 8 "SPJ-Library/template/debug.hpp"

#line 3 "SPJ-Library/template/constants.hpp"

constexpr int inf = 1000'000'000;
constexpr long long INF = 1'000'000'000'000'000'000LL;
constexpr int mod_1000000007 = 1000000007;
constexpr int mod_998244353 = 998244353;
const long double pi = acosl(-1.);
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#line 10 "SPJ-Library/template/debug.hpp"

namespace viewer {

template <typename T, typename U>
void view(const std::pair<T, U> &p);

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p);

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p);

void view(const long long &e);

void view(const int &e);

template <typename T>
void view(const T &e);

template <typename T>
void view(const std::set<T> &s);

template <typename T>
void view(const std::unordered_set<T> &s);

template <typename T>
void view(const std::multiset<T> &s);

template <typename T>
void view(const std::unordered_multiset<T> &s);

template <typename T>
void view(const std::vector<T> &v);

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v);

template <typename T>
void view(const std::vector<std::vector<T>> &vv);

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v);

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v);

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v);

template <typename map_type>
void view_map_container(const map_type &m);

template <typename T, typename U>
void view(const std::map<T, U> &m);

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m);

template <typename container_type>
void view_container(const container_type &c, bool vertically = false) {
	typename container_type::const_iterator begin = c.begin();
	const typename container_type::const_iterator end = c.end();
	if(vertically) {
		std::cerr << "{\n";
		while(begin != end) {
			std::cerr << '\t';
			view(*(begin++));
			if(begin != end) std::cerr << ',';
			std::cerr << '\n';
		}
		std::cerr << '}';
		return;
	}
	std::cerr << "{ ";
	while(begin != end) {
		view(*(begin++));
		if(begin != end) std::cerr << ',';
		std::cerr << ' ';
	}
	std::cerr << '}';
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << '(';
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ')';
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ')';
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ')';
}

void view(const long long &e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int &e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T &e) {
	std::cerr << e;
}

template <typename T>
void view(const std::set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::vector<T> &v) {
	view_container(v);
}

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v) {
	view_container(v);
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	view_container(vv, true);
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	view_container(v, true);
}

template <typename map_type>
void view_map_container(const map_type &m) {
	std::cerr << "{\n";
	for(typename map_type::const_iterator it = m.begin(); it != m.end(); it++) {
		std::cerr << "\t[";
		view(it->first);
		std::cerr << "] : ";
		view(it->second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	view_map_container(m);
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	view_map_container(m);
}

}  // namespace viewer

// when compiling : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename T>
void debug_out(const T &x) {
	viewer::view(x);
}
template <typename Head, typename... Tail>
void debug_out(const Head &H, const Tail &... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "]\n";                                       \
	} while(0)
#else
#define debug(...) (void(0))
#endif
#line 2 "SPJ-Library/template/scanner.hpp"

#line 6 "SPJ-Library/template/scanner.hpp"

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#line 7 "SPJ-Library/template/io.hpp"

#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

template <typename T1, typename T2>
std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << ' ' << p.second;
	return os;
}

struct fast_io {
	fast_io() {
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout << std::fixed << std::setprecision(15);
		srand((unsigned)time(NULL));
	}
} fast_io_;
#line 2 "SPJ-Library/template/macros.hpp"

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;
#line 7 "SPJ-Library/template/kuma.hpp"

using namespace std;
#line 7 "e.cpp"

void solve(int n) {
	int pair_count = n * (n - 1) / 2;
	VEC(int, lens, pair_count);
	if(n == 2) {
		print(lens.front());
		return;
	}
	sort(all(lens));
	const int longest = lens.back();

	counter<int, int> c;
	for(auto len : lens) c.increase(len, 1);

	c.decrease(longest, 1);

	vector<int> slices = {0, longest};

	vvi answers;

	auto dfs = [&](auto self) -> void {
		if(c.empty()) {
			auto slices_copy = slices;
			sort(all(slices));
			rep(i, n - 1) { slices[i] = slices[i + 1] - slices[i]; }
			slices.pop_back();
			answers.push_back(slices);
			swap(slices_copy, slices);
			return;
		}

		const int tmp_longest = prev(c.end())->first;

		auto add_slice = [&](int from_left) -> bool {
			slices.push_back(from_left);
			bool ret = true;
			rep(i, int(slices.size()) - 1) {
				int diff = abs(from_left - slices[i]);
				if(c.amount(diff) == 0) {
					ret = false;
				}
				c.decrease(diff, 1);
			}
			return ret;
		};

		auto rem_slice = [&]() -> void {
			const int from_left = slices.back();
			rep(i, int(slices.size()) - 1) {
				int diff = abs(from_left - slices[i]);
				c.increase(diff, 1);
			}
			slices.pop_back();
			return;
		};

		auto chk = [&](int from_left) -> void {
			if(add_slice(from_left)) self(self);
			rem_slice();
			return;
		};

		chk(tmp_longest);
		chk(longest - tmp_longest);

		return;
	};

	dfs(dfs);

	unq_sort(answers);
	foa(vec, answers) { vout(vec, 0); }
	return;
}
int main() {
	int n;
	while(cin >> n && n) {
		// if(n > 12) break;
		solve(n);
		rep(5) cout << '-';
		cout << '\n';
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3228
final_rank: 7

code_snippet: #pragma region Macros
#if defined(noimi) && defined(_GLIBCXX_DEBUG) && defined(_GLIBCXX_DEBUG_PEDANTIC)
// #pragma comment(linker, "/stack:200000000")
#include <stdc++.h>
#pragma GCC optimize("O3")
#else
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("popcnt")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2")
// #pragma GCC target("avx2")
// #include <bits/stdc++.h>
#include <bits/stdc++.h>
#endif
#include <cstdint>
#include <immintrin.h>
#include <variant>

#ifdef noimi
#define oj_local(a, b) b
#else
#define oj_local(a, b) a
#endif

#define LOCAL if(oj_local(0, 1))
#define OJ if(oj_local(1, 0))

using namespace std;
using ll = long long;
using ull = unsigned long long int;
using i128 = __int128_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vc<T>>;
template <typename T> using vvvc = vector<vvc<T>>;
using vi = vc<int>;
using vl = vc<ll>;
using vpi = vc<pii>;
using vpl = vc<pll>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename T> int si(const T &x) { return x.size(); }
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
vi iota(int n) {
    vi a(n);
    return iota(a.begin(), a.end(), 0), a;
}
template <typename T> vi iota(const vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(res.begin(), res.end(), 0);
    sort(res.begin(), res.end(), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}

// macros
#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define endl '\n'
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n)-1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a)-1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define fore0(a) rep(a.size())
#define fore1(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
#define fore4(a, b, c, d, v) for(auto &&[a, b, c, d] : v)
#define fore(...) overload5(__VA_ARGS__, fore4, fore3, fore2, fore1, fore0)(__VA_ARGS__)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define rng(v, l, r) v.begin() + l, v.begin() + r
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
template <typename T = ll, typename S> T SUM(const S &v) { return accumulate(all(v), T(0)); }
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)                                                                                                                         \
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
constexpr pii dx4[4] = {pii{1, 0}, pii{0, 1}, pii{-1, 0}, pii{0, -1}};
constexpr pii dx8[8] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

namespace yesno_impl {
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
const string firstsecond[2] = {"second", "first"};
const string FirstSecond[2] = {"Second", "First"};
const string possiblestr[2] = {"impossible", "possible"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { cout << yesno[t] << endl; }
void no(bool t = 1) { yes(!t); }
void first(bool t = 1) { cout << firstsecond[t] << endl; }
void First(bool t = 1) { cout << FirstSecond[t] << endl; }
void possible(bool t = 1) { cout << possiblestr[t] << endl; }
}; // namespace yesno_impl
using namespace yesno_impl;

#define INT(...)                                                                                                                                               \
    int __VA_ARGS__;                                                                                                                                           \
    IN(__VA_ARGS__)
#define LL(...)                                                                                                                                                \
    ll __VA_ARGS__;                                                                                                                                            \
    IN(__VA_ARGS__)
#define STR(...)                                                                                                                                               \
    string __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                                                                               \
    char __VA_ARGS__;                                                                                                                                          \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                                                                               \
    double __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define VEC(type, name, size)                                                                                                                                  \
    vector<type> name(size);                                                                                                                                   \
    IN(name)
#define VEC2(type, name1, name2, size)                                                                                                                         \
    vector<type> name1(size), name2(size);                                                                                                                     \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i])
#define VEC3(type, name1, name2, name3, size)                                                                                                                  \
    vector<type> name1(size), name2(size), name3(size);                                                                                                        \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i])
#define VEC4(type, name1, name2, name3, name4, size)                                                                                                           \
    vector<type> name1(size), name2(size), name3(size), name4(size);                                                                                           \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i], name4[i]);
#define VV(type, name, h, w)                                                                                                                                   \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN(name)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
    scan(head);
    IN(tail...);
}

template <typename T, typename S> T ceil(T x, S y) {
    assert(y);
    return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y));
}

template <typename T, typename S> T floor(T x, S y) {
    assert(y);
    return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : x / y - (x % y == 0 ? 0 : 1)));
}
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
template <class T, class S> T POW(T x, S n, const ll &mod) {
    T res = 1;
    x %= mod;
    for(; n; n >>= 1, x = x * x % mod)
        if(n & 1) res = res * x % mod;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    UNIQUE(y);
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
template <class S> void fold_in(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void fold_in(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto e : a) v.emplace_back(e);
    fold_in(v, tail...);
}
template <class S> void renumber(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void renumber(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto &&e : a) e = lb(v, e);
    renumber(v, tail...);
}
template <class S, class... Args> vector<S> zip(vector<S> &head, Args &&...args) {
    vector<S> v;
    fold_in(v, head, args...);
    sort(all(v)), v.erase(unique(all(v)), v.end());
    renumber(v, head, args...);
    return v;
}
template <typename T> vector<T> RUI(const vector<T> &v) {
    vector<T> res(v.size() + 1);
    for(int i = 0; i < v.size(); i++) res[i + 1] = res[i] + v[i];
    return res;
}
// 反時計周りに 90 度回転
template <typename T> void rot(vector<vector<T>> &v) {
    if(empty(v)) return;
    int n = v.size(), m = v[0].size();
    vector res(m, vector<T>(n));
    rep(i, n) rep(j, m) res[m - 1 - j][i] = v[i][j];
    v.swap(res);
}
// x in [l, r)
template <class T, class S> bool inc(const T &x, const S &l, const S &r) { return l <= x and x < r; }

// 便利関数
constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
constexpr ll tri(ll n) { return n * (n + 1) / 2; }
// l + ... + r
constexpr ll tri(ll l, ll r) { return (l + r) * (r - l + 1) / 2; }
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
// bit 演算系
ll pow2(int i) { return 1LL << i; }
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int lowbit(ll a) { return a == 0 ? 64 : __builtin_ctzll(a); }
// int allbit(int n) { return (1 << n) - 1; }
constexpr ll mask(int n) { return (1LL << n) - 1; }
// int popcount(signed t) { return __builtin_popcount(t); }
// int popcount(ll t) { return __builtin_popcountll(t); }
int popcount(uint64_t t) { return __builtin_popcountll(t); }
static inline uint64_t popcount64(uint64_t x) {
    uint64_t m1 = 0x5555555555555555ll;
    uint64_t m2 = 0x3333333333333333ll;
    uint64_t m4 = 0x0F0F0F0F0F0F0F0Fll;
    uint64_t h01 = 0x0101010101010101ll;

    x -= (x >> 1) & m1;
    x = (x & m2) + ((x >> 2) & m2);
    x = (x + (x >> 4)) & m4;

    return (x * h01) >> 56;
}
bool ispow2(int i) { return i && (i & -i) == i; }

ll rnd(ll l, ll r) { //[l, r)
#ifdef noimi
    static mt19937_64 gen;
#else
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif
    return uniform_int_distribution<ll>(l, r - 1)(gen);
}
ll rnd(ll n) { return rnd(0, n); }

template <class t> void random_shuffle(vc<t> &a) { rep(i, si(a)) swap(a[i], a[rnd(0, i + 1)]); }

int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}

template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }

template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    constexpr bool operator<(const edge<T> &rhs) const noexcept { return cost < rhs.cost; }
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
    friend ostream operator<<(ostream &os, edge &e) { return os << e.to; }
};
template <typename T> using Edges = vector<edge<T>>;

using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return res;
}
Graph getTreeFromPar(int n, int margin = 1) {
    Graph res(n);
    for(int i = 1; i < n; i++) {
        int a;
        cin >> a;
        res[a - margin].emplace_back(i);
    }
    return res;
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        scan(a), scan(b), scan(c);
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return res;
}
void add(Graph &G, int x, int y) { G[x].eb(y), G[y].eb(x); }
template <class S, class T> void add(Wgraph<S> &G, int x, int y, T c) { G[x].eb(y, c), G[y].eb(x, c); }

#define TEST                                                                                                                                                   \
    INT(testcases);                                                                                                                                            \
    while(testcases--)

istream &operator>>(istream &is, i128 &v) {
    string s;
    is >> s;
    v = 0;
    for(int i = 0; i < (int)s.size(); i++) {
        if(isdigit(s[i])) { v = v * 10 + s[i] - '0'; }
    }
    if(s[0] == '-') { v *= -1; }
    return is;
}

ostream &operator<<(ostream &os, const i128 &v) {
    if(v == 0) { return (os << "0"); }
    i128 num = v;
    if(v < 0) {
        os << '-';
        num = -num;
    }
    string s;
    for(; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); }
    reverse(s.begin(), s.end());
    return (os << s);
}
namespace aux {
template <typename T, unsigned N, unsigned L> struct tp {
    static void output(std::ostream &os, const T &v) {
        os << std::get<N>(v) << (&os == &cerr ? ", " : " ");
        tp<T, N + 1, L>::output(os, v);
    }
};
template <typename T, unsigned N> struct tp<T, N, N> {
    static void output(std::ostream &os, const T &v) { os << std::get<N>(v); }
};
} // namespace aux
template <typename... Ts> std::ostream &operator<<(std::ostream &os, const std::tuple<Ts...> &t) {
    if(&os == &cerr) { os << '('; }
    aux::tp<std::tuple<Ts...>, 0, sizeof...(Ts) - 1>::output(os, t);
    if(&os == &cerr) { os << ')'; }
    return os;
}
template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) {
    if(&os == &cerr) { return os << "(" << p.first << ", " << p.second << ")"; }
    return os << p.first << " " << p.second;
}
template <class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, const Container &x) {
    bool f = true;
    if(&os == &cerr) os << "[";
    for(auto &y : x) {
        if(&os == &cerr)
            os << (f ? "" : ", ") << y;
        else
            os << (f ? "" : " ") << y;
        f = false;
    }
    if(&os == &cerr) os << "]";
    return os;
}

#ifdef noimi
#undef endl
void debug() { cerr << endl; }
void debug(bool) { cerr << endl; }
template <class Head, class... Tail> void debug(bool is_front, Head head, Tail... tail) {
    if(!is_front) cerr << ", ";
    cerr << head;
    debug(false, tail...);
}

#define dump(args...)                                                                                                                                          \
    {                                                                                                                                                          \
        vector<string> _debug = _split(#args, ',');                                                                                                            \
        err(true, begin(_debug), args);                                                                                                                        \
    }

vector<string> _split(const string &s, char c) {
    vector<string> v;
    stringstream ss(s);
    string x;
    while(getline(ss, x, c)) {
        if(empty(v))
            v.eb(x);
        else {
            bool flag = false;
            for(auto [c, d] : {pair('(', ')'), pair('[', ']'), pair('{', '}')}) {
                if(count(all(v.back()), c) != count(all(v.back()), d)) flag = true;
            }
            if(flag)
                v.back() += "," + x;
            else
                v.eb(x);
        }
    }
    return move(v);
}

void err(bool, vector<string>::iterator) { cerr << endl; }
template <typename T, typename... Args> void err(bool is_front, vector<string>::iterator it, T a, Args... args) {
    if(!is_front) cerr << ", ";
    cerr << it->substr((*it)[0] == ' ', (*it).size()) << " = " << a, err(false, ++it, args...);
}

// #define dump(...) cerr << #__VA_ARGS__ << " : ", debug(true, __VA_ARGS__)
#else
#define dump(...) static_cast<void>(0)
#define dbg(...) static_cast<void>(0)
#endif
void OUT() { cout << endl; }
template <class Head, class... Tail> void OUT(const Head &head, const Tail &...tail) {
    cout << head;
    if(sizeof...(tail)) cout << ' ';
    OUT(tail...);
}

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
template <class T, class S> constexpr pair<T, S> inf<pair<T, S>> = {inf<T>, inf<S>};

template <class F> struct REC {
    F f;
    REC(F &&f_) : f(std::forward<F>(f_)) {}
    template <class... Args> auto operator()(Args &&...args) const { return f(*this, std::forward<Args>(args)...); }
};

template <class S> vector<pair<S, int>> runLength(const vector<S> &v) {
    vector<pair<S, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}
vector<pair<char, int>> runLength(const string &v) {
    vector<pair<char, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}

int toint(const char &c, const char start = 'a') { return c - start; }
int toint(const char &c, const string &chars) { return find(all(chars), c) - begin(chars); }
int alphabets_to_int(const char &c) { return (islower(c) ? c - 'a' : c - 'A' + 26); }
template <typename T> auto toint(const T &v, const char &start = 'a') {
    vector<decltype(toint(v[0]))> ret;
    ret.reserve(v.size());
    for(auto &&e : v) ret.emplace_back(toint(e, start));
    return ret;
}
template <typename T> auto toint(const T &v, const string &start) {
    vector<decltype(toint(v[0]))> ret;
    ret.reserve(v.size());
    for(auto &&e : v) ret.emplace_back(toint(e, start));
    return ret;
}
// a -> 0, A -> 26
template <typename T> auto alphabets_to_int(const T &s) {
    vector<decltype(alphabets_to_int(s[0]))> res;
    res.reserve(s.size());
    for(auto &&e : s) { res.emplace_back(alphabets_to_int(e)); }
    return res;
}

template <class T, class F> T bin_search(T ok, T ng, const F &f) {
    while(abs(ok - ng) > 1) {
        T mid = ok + ng >> 1;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
template <class T, class F> T bin_search_double(T ok, T ng, const F &f, int iter = 80) {
    while(iter--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(11);
    }
} setup_io;

#pragma endregion

int main() {
    rep(100) {
        INT(n);
        if(!n) exit(0);
        VEC(int, d, n *(n - 1) / 2);
        multiset<int> s;
        fore(e, d) s.emplace(e);

        vvc<int> ans;
        vi v{0, *rbegin(s)};
        s.erase(--end(s));

        REC([&](auto &&f, int i, vi &v) -> void {
            // dump(i, v, s);
            if(i == n) {
                ans.eb(v);
                return;
            }
            int d = *rbegin(s);

            vi w;
            for(auto D : {d, v[1] - d}) {
                bool flag = true;
                fore(e, v) {
                    int k = abs(D - e);
                    auto it = s.lower_bound(k);
                    if(it != end(s) and *it == k) {
                        w.eb(k);
                        s.erase(it);
                    } else {
                        flag = false;
                        break;
                    }
                }
                if(flag) {
                    v.eb(D);
                    f(i + 1, v);
                    fore(e, w) s.emplace(e);
                    v.pop_back();
                } else {
                    fore(e, w) s.emplace(e);
                }
                w.clear();
            }
        })
        (2, v);
        fore(e, ans) SORT(e);
        UNIQUE(ans);
        fore(e, ans) {
            SORT(e);
            vi w;
            rep(i, n - 1) w.eb(e[i + 1] - e[i]);
            OUT(w);
        }
        cout << "-----" << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3560
final_rank: 10

code_snippet: //#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,-1,0,1 };

ll gcd(ll a, ll b) {
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}

int n;
void solve() {
	vector<int> d;
	int m = n * (n - 1) / 2;
	rep(i, n * (n - 1) / 2) {
		int x; cin >> x; d.push_back(x);
	}
	sort(all(d));
	/*if (n == 2) {
		cout << d[0] << "\n";
		cout << "-----\n";
		return;
	}*/
	vector<int> ori(401);
	for (int dd : d)ori[dd]++;
	vector<vector<int>> ans;
	
	rep(i, (1 << (n - 2))) {
		vector<int> cnt = ori;
		int tmp = 400;
		auto takema = [&]() {
			while (cnt[tmp] == 0)tmp--;
			return tmp;
		};
		int al = takema(); cnt[al]--;
		vector<int> cur(n-1, -1);
		int locl = 0, locr = n - 2;
		int sl = 0, sr = 0;
		bool valid = true;
		rep(j, n - 2) {
			int ma = takema(); cnt[ma]--;
			if (i & (1 << j)) {
				int val = al - ma - sr;
				cur[locr] = val; locr--; sr += val;
				for (int k = 0; k < locl; k++) {
					ma -= cur[k];
					if (ma<0||cnt[ma] == 0) {
						valid = false; break;
					}
					else {
						cnt[ma]--;
					}
				}
			}
			else {
				int val = al - ma - sl;
				cur[locl] = val; locl++; sl += val;
				for (int k = n - 2; k > locr; k--) {
					ma -= cur[k];
					if (ma<0||cnt[ma] == 0) {
						valid = false; break;
					}
					else {
						cnt[ma]--;
					}
				}
			}
			if (!valid)break;
		}
		if (!valid)continue;
		int r = al;
		rep(i, n - 1)if (cur[i] >= 0)r -= cur[i];
		rep(i, n - 1)if (cur[i] < 0)cur[i] = r;
		cnt = ori;
		rep(i, n - 1) {
			int sum = 0;
			Rep(j, i, n - 1) {
				sum += cur[j];
				if (cnt[sum] == 0) {
					valid = false;
				}
				cnt[sum]--;
			}
		}
		if (valid)ans.push_back(cur);
	}
	
	//cout << "ans is " << "\n";
	sort(all(ans));
	ans.erase(unique(all(ans)), ans.end());
	rep(i, ans.size()) {
		rep(j, n - 1) {
			if (j > 0)cout << " ";
			cout << ans[i][j];
		}
		cout << "\n";
	}
	cout << "-----\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(8);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)
	while(cin>>n,n)
		solve();
	return 0;
}
accuracy: 1
time_ms: 1930
memory_kb: 3428
final_rank: 17

code_snippet: #include<cstdio>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;

int n, m, d[190], ans[20], len, skip[401], counter[401];
set<string> double_count;

bool check() {
  vector<int> sum(n, 0), tmp;
  for (int i = 0; i < n-1; i++) sum[i+1] = sum[i] + ans[i];
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      tmp.push_back(sum[j] - sum[i]);
    }
  }
  sort(tmp.begin(), tmp.end(), greater<int>());
  for (int i = 0; i < m; i++) if (tmp[i] != d[i]) return false;
  string s = "";
  for (int i = 0; i < n-1; i++) s += to_string(ans[i]) + " ";
  if (double_count.count(s)) return false;
  double_count.insert(s);
  return true;
}

void dfs(int l, int r, int num, int lsum, int rsum) {
  if (l == r) {
    ans[l] = len - lsum - rsum;
    if (ans[l] > 0 && check()) {
      for (int i = 0; i < n-1; i++) printf("%d%c", ans[i], i == n-2 ? '\n' : ' ');
    }
    return;
  }
  if (skip[d[num]] > 0) {
    skip[d[num]]--;
    dfs(l, r, num+1, lsum, rsum);
    skip[d[num]]++;
    return;
  }
  counter[d[num]]--;
  ans[l] = len - d[num] - lsum;
  if (ans[l] > 0) { // 重複???
    bool ok = true;
    for (int r2 = r+1, s_tmp = len - lsum - rsum - ans[l]; r2 <= n-2 && s_tmp >= 0 && s_tmp <= d[num]; s_tmp += ans[r2], r2++) {
      skip[s_tmp]++;
      if (skip[s_tmp] > counter[s_tmp]) ok = false;
    }
    if (ok) dfs(l+1, r, num+1, lsum + ans[l], rsum);
    for (int r2 = r+1, s_tmp = len - lsum - rsum - ans[l]; r2 <= n-2 && s_tmp >= 0 && s_tmp <= d[num]; s_tmp += ans[r2], r2++) {
      skip[s_tmp]--;
    }
  }
  ans[r] = len - d[num] - rsum;
  if (ans[r] > 0) {
    bool ok = true;
    for (int l2 = l-1, s_tmp = len - lsum - rsum - ans[r]; l2 >= 0 && s_tmp >= 0 && s_tmp <= d[num]; s_tmp += ans[l2], l2--) {
      skip[s_tmp]++;
      if (skip[s_tmp] > counter[s_tmp]) ok = false;
    }
    if (ok) dfs(l, r-1, num+1, lsum, rsum + ans[r]);
    for (int l2 = l-1, s_tmp = len - lsum - rsum - ans[r]; l2 >= 0 && s_tmp >= 0 && s_tmp <= d[num]; s_tmp += ans[l2], l2--) {
      skip[s_tmp]--;
    }
  }
  counter[d[num]]++;
}

int main() {
  while (scanf("%d", &n), n) {
    double_count.clear();
    m = n * (n-1) / 2;
    for (int i = 0; i <= 400; i++) counter[i] = 0;
    for (int i = 0; i < m; i++) scanf("%d", &d[i]), counter[d[i]]++;
    len = d[0];
    if (n == 2) {
      printf("%d\n", d[0]);
    } else {
      dfs(0, n-2, 1, 0, 0);
    }
    printf("-----\n");
  }
}
accuracy: 1
time_ms: 10
memory_kb: 2828
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  REP(i, SZ(v)) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

void sch(int n, int k, int l, multiset<int> &st, vi &ans, set<vi> &res) {
  if(k > l) {
    vi v2(n-1);
    REP(i, SZ(ans)-1) {
      v2[i] = ans[i+1] - ans[i];
    }
    res.insert(v2);
    return;
  }

  multiset<int> deleted;
  multiset<int> use;
  auto it = --st.end();
  int val = *it;
  st.erase(it);

  // 1
  bool ok = true;
  ans[k] = ans[n-1] - val;
  REP(i, k) {
    use.insert(ans[k] - ans[i]);
  }
  for(int i=n-2;i>l;--i) {
    use.insert(ans[i] - ans[k]);
  }
  for(auto &e: use) {
    it = st.find(e);
    if(it == st.end()) {
      ok = false;
      break;
    }
    st.erase(it);
    deleted.insert(e);
  }
  if(ok) {
    sch(n, k+1, l, st, ans, res);
  }
  st.merge(deleted);
  use.clear();
  ans[k] = -1;

  // 2
  ok = true;
  ans[l] = ans[0] + val;
  FOR(i, 1, k) {
    use.insert(ans[l] - ans[i]);
  }
  for(int i=n-1;i>l;--i) {
    use.insert(ans[i] - ans[l]);
  }
  for(auto &e: use) {
    it = st.find(e);
    if(it == st.end()) {
      ok = false;
      break;
    }
    st.erase(it);
    deleted.insert(e);
  }
  if(ok) {
    sch(n, k, l-1, st, ans, res);
  }
  ans[l] = -1;
  st.merge(deleted);
  use.clear();

  st.insert(val);
}

bool solve() {
  int n;
  cin >> n;
  if (n == 0) return false;
  int sz = n * (n - 1) / 2;
  multiset<int> st;
  REP(i, sz) {
    int v;
    cin >> v;
    st.insert(v);
  }

  vi ans(n, -1);
  ans[0] = 0;
  auto it = --st.end();
  int val = *it;
  st.erase(it);
  ans[n-1] = val;
  set<vi> res;
  sch(n, 1, n-2, st, ans, res);

  for (auto &v: res) {
    REP(i, SZ(v)) {
      cout << v[i];
      if (i == SZ(v) - 1) cout << "\n";
      else cout << " ";
    }
  }
  cout << "-----" << endl;
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (solve()) {}

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3408
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;

class Solution {
public:
	void solve() {
		while (1) {
			int n;
			cin >> n;
			if (n == 0) return;
			vector<int> d((n * (n - 1)) / 2, 0);
			for (int i = 0; i < (n * (n - 1)) / 2; i++) cin >> d[i];
			vector<int> _cnt(d[0] + 1);
			vector<int> _x(n, -1);
			for (int i = 0; i < (n * (n - 1)) / 2; i++) _cnt[d[i]]++;
			_x[0] = 0;
			_x[n - 1] = d[0];
			_cnt[d[0]]--;
			vector<vector<int> > ans;
			for (int i = 0; i < (1 << (n - 2)); i++) {
				bool ok = true;
				vector<int> x(_x.begin(), _x.end());
				vector<int> cnt(_cnt.begin(), _cnt.end());
				int l = 1, r = n - 2;
				int sh = n - 3;
				for (int j = d[0]; j > 0; j--) {
					while (cnt[j] > 0 && sh >= 0) {
						int id;
						if ((i >> sh) & 1) {
							id = r;
							x[r--] = j;
						} else {
							id = l;
							x[l++] = d[0] - j;
						}
						for (int k = 0; k < n; k++) {
							if (id == k || x[k] == -1) continue;
							if (!cnt[abs(x[id] - x[k])]--) {
								ok = false;
								break;
							}
						}
						sh--;
						if (!ok) break;
					}
					if (!ok) break;
				}
				if (!ok) continue;
				ans.push_back(x);
			}
			sort(ans.begin(), ans.end());
			ans.erase(unique(ans.begin(), ans.end()), ans.end());
			for (int i = 0; i < ans.size(); i++) {
				for (int j = 1; j < n; j++) {
					if (j == 1)
						cout << ans[i][j] - ans[i][j - 1];
					else
						cout << " " << ans[i][j] - ans[i][j - 1];
				}
				cout << "\n";
			}
			cout << "-----\n";
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Solution solution;
	solution.solve();
	return 0;
}
accuracy: 1
time_ms: 2300
memory_kb: 3164
final_rank: 18

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

// http://koturn.hatenablog.com/entry/2018/06/10/060000
template<typename F> struct FixPoint : F {
    FixPoint(F&& f) : F(forward<F>(f)) { }
    template<typename... Args> decltype(auto) operator()(Args&&... args) {
        return F::operator()(*this, forward<Args>(args)...);
    }
};
template<typename F> decltype(auto) MFP(F&& f) {    // makeFixPoint
    return FixPoint<F>{forward<F>(f)};
}

int main() {
    int n;
    while (cin >> n, n) {
        int nC2 = n * (n - 1) / 2;
        vector<int> ds(nC2); for (auto &d: ds) cin >> d;
        multiset<int> ms; for (auto &d: ds) ms.emplace(d);
        int ma = ds[0]; ms.erase(ms.find(ma));
        vector<int> acc({0, ma});
        map<int, int> cnt; for (auto &d: ds) cnt[d]++;
        set<vector<int>> res;
        MFP([&](auto dfs) -> void {
            if (ms.empty()) {
                auto tmp(acc); sort(tmp.begin(), tmp.end());
                res.emplace(tmp);
                return ;
            }
            for (int nxt: {*ms.rbegin(), ma - *ms.rbegin()}) {
                bool flg = true;
                for (auto x: acc) flg &= --cnt[abs(x - nxt)] >= 0;
                if (flg) {
                    for (auto x: acc) ms.erase(ms.find(abs(x - nxt)));
                    acc.emplace_back(nxt);
                    dfs();
                    acc.pop_back();
                    for (auto x: acc) ms.emplace(abs(x - nxt));
                }
                for (auto x: acc) ++cnt[abs(x - nxt)];
            }
        })();
        for (auto &v: res) {
            for (int i = 0; i + 1 < n; i++) cout << v[i + 1] - v[i] << " \n"[i == n - 2];
        }
        cout << string(5, '-') << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3068
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    while(cin >> n, n) {
        multiset<int, greater<>> d;
        for(int i = 0; i < n * (n - 1) / 2; ++i) {
            int x; cin >> x;
            d.insert(x);
        }

        vector<int> cur = {0, *d.begin()}; // x position
        d.erase(d.begin());
        vector<vector<int>> ans;
        function<void(multiset<int, greater<>>&)> dfs = [&] (multiset<int, greater<>>& s) {
            if((int)cur.size() == n) { // ok
                ans.push_back({});
                for(int i = 1; i < n; ++i) {
                    ans.back().push_back(cur[i] - cur[i - 1]);
                }
                return;
            }
            auto attempt = [&] (int p) {
                vector<int> rm;
                for(auto x : cur) {
                    const auto it = s.lower_bound(abs(p - x));
                    if(it == end(s) || *it != abs(p - x)) break;
                    rm.push_back(*it);
                    s.erase(it);
                }
                if(rm.size() == cur.size()) {
                    cur.insert(lower_bound(begin(cur), end(cur), p), p);
                    dfs(s);
                    cur.erase(find(begin(cur), end(cur), p));
                }
                s.insert(begin(rm), end(rm));
            };
            attempt(*s.begin());
            attempt(cur.back() - *s.begin());
        };

        dfs(d);
        sort(begin(ans), end(ans));
        ans.erase(unique(begin(ans), end(ans)), end(ans));
        for(auto const& v : ans) {
            for(int i = 0; i < n - 1; ++i) {
                cout << v[i] << " \n"[i + 1 == n - 1];
            }
        }
        cout << "-----" << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3204
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }  
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  int n;
  while(cin>>n,n){
    n--;
    int m=n*(n+1)/2;
    vector<int> ds(m);
    for(int i=0;i<m;i++) cin>>ds[i];

    multiset<int> ms;
    for(int d:ds) ms.emplace(d);
    
    int len=ds[0];
    ms.erase(ms.find(len));
    vector<int> vs({0,len});
    
    map<int, int> cnt;
    for(int x:ms) cnt[x]++;    
    
    set<vector<int>> ans;
    // [l, r]
    MFP([&](auto dfs)->void{     
          if(ms.empty()){
            auto us(vs);
            sort(us.begin(),us.end());            
            ans.emplace(us);
            return;
          }          
          for(int k=0;k<2;k++){
            int nxt=k?*ms.rbegin():len-*ms.rbegin();            
            int flg=1;
            for(int v:vs){
              cnt[abs(v-nxt)]--;
              flg&=cnt[abs(v-nxt)]>=0;
            }
            if(flg){
              for(int v:vs)
                ms.erase(ms.find(abs(v-nxt)));
              vs.emplace_back(nxt);
              dfs();
              vs.pop_back();
              for(int v:vs)
                ms.emplace(abs(v-nxt));              
            }            
            for(int v:vs)
              cnt[abs(v-nxt)]++;
          }          
        })();
    
    for(auto vs:ans){
      for(int i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<vs[i+1]-vs[i];
      }
      cout<<endl;
    }
    cout<<"-----"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3084
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll MOD=1000000007;
const ll E=1e18;

set<vector<ll>> ans;
multiset<ll> cost;
set<ll> point;
ll n;
ll l,r;

void dfs(ll d){
  if(d==n){
    ll L=l;
    auto I=point.begin(); ++I;
    vector<ll> ret;
    for(;I!=point.end();++I){
      ret.push_back((*I)-L);
      L=*I;
    }
    ans.insert(ret);
    return;
  }
  auto I=cost.end(); I--;
  ll dist=*I;
  ll w=dist+l;
  vector<ll> used;
  bool j=true;
  for(auto I=point.begin();I!=point.end();++I){
    auto T=cost.find(abs(*I-w));
    if(T!=cost.end()){
      used.push_back(abs(*I-w));
      cost.erase(T);
    }
    else{
      j=false;
      break;
    }
  }
  if(j && point.count(w)==0){
    point.insert(w);
    dfs(d+1);
    point.erase(w);
  }
  for(auto &I:used){cost.insert(I);}
  used.clear();
  
  w=r-dist;
  j=true;
  for(auto I=point.begin();I!=point.end();++I){
    auto T=cost.find(abs(*I-w));
    if(T!=cost.end()){
      used.push_back(abs(*I-w));
      cost.erase(T);
    }
    else{
      j=false;
      break;
    }
  }
  if(j && point.count(w)==0){
    point.insert(w);
    dfs(d+1);
    point.erase(w);
  }
  for(auto &I:used){cost.insert(I);}
}




int main(){
  while(cin>>n){
    if(n==0){break;}
    //for(auto &I:ans){I.clear();}
    ans.clear();
    cost.clear();
    point.clear();
    l=0; cin>>r;
    for(int i=1;i<n*(n-1)/2;i++){
      ll d;
      cin>>d;
      cost.insert(d);
    }
    point.insert(l);
    point.insert(r);
    dfs(2);
    for(auto &I:ans){
      for(int i=0;i+1<n;i++){cout<<I[i]<<(i+2==n?"\n":" ");}
    }
    cout<<"-----"<<endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3152
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N,M;
int d[410],cnt[410];
int x[22];
set<vector<int> > res;

void dfs(int l,int r){
  //dbg(l); dbg(r);
  //rep(i,10)dbg(cnt[i]);
  if(l+1>=r){
    vector<int> tmp;
    rep(j,N-1)tmp.push_back(x[j+1]-x[j]);
    res.insert(tmp); return ;
  }
  int mx=-1;
  rep(i,401)if(cnt[i]>0)maxch(mx,i);
  if(mx==-1)return ;
  //dbg(mx);

  // left
  x[r-1]=x[0]+mx;
  bool ok=true;
  vector<int> sav;
  repl(i,r,N){
    int crtd=x[i]-x[r-1];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  repl(i,0,l+1){
    int crtd=x[r-1]-x[i];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  if(ok)dfs(l,r-1);
  rep(i,sav.size())cnt[sav[i]]++;

  // left
  x[r-1]=x[N-1]-mx;
  ok=true;
  sav.clear();
  repl(i,r,N){
    int crtd=x[i]-x[r-1];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  repl(i,0,l+1){
    int crtd=x[r-1]-x[i];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  if(ok)dfs(l,r-1);
  rep(i,sav.size())cnt[sav[i]]++;

  // right
  x[l+1]=x[N-1]-mx;
  ok=true;
  sav.clear();
  repl(i,0,l+1){
    int crtd=x[l+1]-x[i];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  repl(i,r,N){
    int crtd=x[i]-x[l+1];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  if(ok)dfs(l+1,r);
  rep(i,sav.size())cnt[sav[i]]++;

  // right
  x[l+1]=mx-x[0];
  ok=true;
  sav.clear();
  repl(i,0,l+1){
    int crtd=x[l+1]-x[i];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  repl(i,r,N){
    int crtd=x[i]-x[l+1];
    if(crtd<0||cnt[crtd]==0){
      ok=false; break;
    }
    cnt[crtd]--;
    sav.push_back(crtd);
  }
  if(ok)dfs(l+1,r);
  rep(i,sav.size())cnt[sav[i]]++;

}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1){
    cin>>N;
    if(N==0)break;
    int mx=0;
    M=N*(N-1)/2;
    memset(cnt,0,sizeof(cnt));
    rep(i,M){
      cin>>d[i];
      cnt[d[i]]++;
    }
    sort(d,d+M);
    x[0]=0;
    x[N-1]=d[M-1]; cnt[d[M-1]]--; M--;
    res.clear();
    dfs(0,N-1);
    for(vector<int> ans : res){
      cout<<ans[0];
      repl(j,1,ans.size())cout<<" "<<ans[j];
      cout<<endl;
    }
    cout<<"-----"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3160
final_rank: 4

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 20

enum Type{
	L,
	R,
};

struct Info{
	bool operator<(const struct Info &arg) const{
		return dist > arg.dist;
	}
	int dist,count;
};

struct Answer{

	void set(int arg_length,int arg_table[NUM]){
		length = arg_length;
		for(int i = 0; i < length; i++){
			table[i] = arg_table[i];
		}
	}
	bool operator<(const struct Answer &arg) const{
		for(int i = 0; i < length; i++){
			if(table[i] != arg.table[i]){
				return table[i] < arg.table[i];
			}
		}
		return true;
	}

	bool operator==(const struct Answer &arg) const{

		bool FLG = true;
		for(int i = 0; i < length; i++){
			if(table[i] != arg.table[i]){
				FLG = false;
			}
		}
		return FLG;
	}

	int table[NUM],length;
};

int N;
int info_index;
Info info[(NUM*(NUM-1))/2];
map<string,bool> MAP;
map<int,int> LOC;
vector<Answer> ANS;

string make_str(int dist_array[NUM]){

	string ret;

	for(int i = 0; i < info_index; i++){
		ret.append(to_string(dist_array[i])).append("@");
	}

	return ret;
}

int get_index(int rest_num[(NUM*(NUM-1))/2]){

	for(int i = 0; i < info_index; i++){
		if(rest_num[i] > 0){
			return i;
		}
	}
	return -1; //Error
}

void recursive(int dist_array[NUM],int rest_num[(NUM*(NUM-1))/2],int index,int num_decided){

	if(num_decided == N){

		int work[NUM];
		Answer ans;

		for(int i = 0; i < N-1; i++){
			work[i] = dist_array[i+1]-dist_array[i];
		}
		ans.set(N-1,work);

		ANS.push_back(ans);

		return;
	}

	int tmp_dist = info[index].dist;
	rest_num[index]--;

	int next_dist_array[2][NUM],next_rest_num[2][(NUM*(NUM-1))/2];

	for(int i = 0; i < 2; i++){
		for(int k = 0; k < N; k++){
			next_dist_array[i][k] = dist_array[k];
		}
		for(int k = 0; k < info_index; k++){
			next_rest_num[i][k] = rest_num[k];
		}
	}

	int tmp_pos;

	for(int i = N-2; i >= 0; i--){
		if(next_dist_array[L][i] == -1){
			next_dist_array[L][i] = tmp_dist;
			tmp_pos = i;
			break;
		}
	}

	int tmp_diff,tmp_loc;
	bool FLG = true;

	for(int i = 1; i < N; i++){
		if(next_dist_array[L][i] == -1 || i == tmp_pos)continue;

		tmp_diff = abs(next_dist_array[L][i]-tmp_dist);

		auto at = LOC.find(tmp_diff);

		if(at == LOC.end()){
			FLG = false;
			break;
		}

		tmp_loc = LOC[tmp_diff];

		if(next_rest_num[L][tmp_loc] == 0){
			FLG = false;
			break;
		}
		next_rest_num[L][tmp_loc]--;
	}

	if(FLG){

		string tmp_str = make_str(next_dist_array[L]);

		auto ch = MAP.find(tmp_str);

		if(ch == MAP.end()){

			MAP[tmp_str] = true;
			int next_index = get_index(next_rest_num[L]);
			recursive(next_dist_array[L],next_rest_num[L],next_index,num_decided+1);
		}
	}

	tmp_dist = dist_array[N-1]-tmp_dist;

	auto a_r = LOC.find(tmp_dist);
	if(a_r == LOC.end() || rest_num[LOC[tmp_dist]] == 0)return;

	for(int i = 0; i < N; i++){
		if(next_dist_array[R][i] == -1){
			next_dist_array[R][i] = tmp_dist;
			tmp_pos = i;
			break;
		}
	}

	 FLG = true;

	for(int i = 0; i < N-1; i++){
		if(next_dist_array[R][i] == -1 || i == tmp_pos)continue;

		tmp_diff = abs(next_dist_array[R][i]-tmp_dist);

		auto at = LOC.find(tmp_diff);

		if(at == LOC.end()){
			FLG = false;
			break;
		}

		tmp_loc = LOC[tmp_diff];

		if(next_rest_num[R][tmp_loc] == 0){
			FLG = false;
			break;
		}
		next_rest_num[R][tmp_loc]--;
	}

	if(FLG){

		string tmp_str = make_str(next_dist_array[R]);

		auto ch = MAP.find(tmp_str);

		if(ch == MAP.end()){

			MAP[tmp_str] = true;
			int next_index = get_index(next_rest_num[R]);
			recursive(next_dist_array[R],next_rest_num[R],next_index,num_decided+1);
		}
	}
}

void func(){

	MAP.clear();
	LOC.clear();
	ANS.clear();
	info_index = 0;

	int tmp;
	bool FLG;

	for(int i = 0; i < (N*(N-1))/2; i++){

		scanf("%d",&tmp);

		FLG = false;

		for(int k = 0;k < info_index; k++){
			if(info[k].dist == tmp){
				info[k].count++;
				FLG = true;
				break;
			}
		}

		if(FLG)continue;

		info[info_index].dist = tmp;
		info[info_index].count = 1;
		info_index++;
	}

	for(int i = 0; i < info_index; i++){
		LOC[info[i].dist] = i;
	}

	if(info[0].count != 1){
		printf("-----\n");
		return;
	}

	int first_dist_array[NUM];
	int first_rest_num[(NUM*(NUM-1))/2];

	first_dist_array[0] = 0;
	for(int i = 1; i <= N-2; i++)first_dist_array[i] = -1;
	first_dist_array[N-1] = info[0].dist;

	first_rest_num[0] = 0;
	for(int i = 1; i < info_index; i++)first_rest_num[i] = info[i].count;

	recursive(first_dist_array,first_rest_num,1,2);

	if(ANS.size() > 0){
		sort(ANS.begin(),ANS.end());
		ANS.erase(unique(ANS.begin(),ANS.end()),ANS.end());
	}

	for(int i = 0; i < ANS.size(); i++){
		printf("%d",ANS[i].table[0]);
		for(int k = 1; k < N-1; k++){
			printf(" %d",ANS[i].table[k]);
		}
		printf("\n");
	}

	printf("-----\n");
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3464
final_rank: 11

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 20

enum Type{
	L,
	R,
};

struct Info{
	bool operator<(const struct Info &arg) const{ //距離の降順
		return dist > arg.dist;
	}
	int dist,count;
};

struct Answer{

	void set(int arg_length,int arg_table[NUM]){
		length = arg_length;
		for(int i = 0; i < length; i++){
			table[i] = arg_table[i];
		}
	}
	bool operator<(const struct Answer &arg) const{
		for(int i = 0; i < length; i++){
			if(table[i] != arg.table[i]){
				return table[i] < arg.table[i];
			}
		}
		return true;
	}

	bool operator==(const struct Answer &arg) const{

		bool FLG = true;
		for(int i = 0; i < length; i++){
			if(table[i] != arg.table[i]){
				FLG = false;
			}
		}
		return FLG;
	}

	int table[NUM],length;
};

int N;
int info_index;
Info info[(NUM*(NUM-1))/2];
map<string,bool> MAP;
map<int,int> LOC;
vector<Answer> ANS;

string make_str(int dist_array[NUM]){

	string ret;

	for(int i = 0; i < info_index; i++){
		ret.append(to_string(dist_array[i])).append("@");
	}

	return ret;
}

//0でない最初の場所を返却する関数
int get_index(int rest_num[(NUM*(NUM-1))/2]){

	for(int i = 0; i < info_index; i++){
		if(rest_num[i] > 0){
			return i;
		}
	}
	return -1; //Error
}

//index:rest_numの、非0の最小インデックス
void recursive(int dist_array[NUM],int rest_num[(NUM*(NUM-1))/2],int index,int num_decided){

	if(num_decided == N){

		//町同士の距離をstring配列化して、ANSに格納
		int work[NUM];
		Answer ans;

		for(int i = 0; i < N-1; i++){
			work[i] = dist_array[i+1]-dist_array[i];
		}
		ans.set(N-1,work);

		ANS.push_back(ans);

		return;
	}

	//今回処理する距離
	int tmp_dist = info[index].dist;
	rest_num[index]--;

	int next_dist_array[2][NUM],next_rest_num[2][(NUM*(NUM-1))/2];

	for(int i = 0; i < 2; i++){
		for(int k = 0; k < N; k++){
			next_dist_array[i][k] = dist_array[k];
		}
		for(int k = 0; k < info_index; k++){
			next_rest_num[i][k] = rest_num[k];
		}
	}

	/*★★残っている最大の距離を、左端からの距離と解釈する場合★★*/
	int tmp_pos;

	//右端から数えて、一番近い空きスペースを探す
	for(int i = N-2; i >= 0; i--){
		if(next_dist_array[L][i] == -1){
			next_dist_array[L][i] = tmp_dist;
			tmp_pos = i;
			break;
		}
	}

	int tmp_diff,tmp_loc;
	bool FLG = true;

	//既に配置されている他の距離と矛盾がないか調べる
	for(int i = 1; i < N; i++){ //★i == 0からやると、tmp_distをデクリメントしているのでfalseになってしまう★
		if(next_dist_array[L][i] == -1 || i == tmp_pos)continue;

		tmp_diff = abs(next_dist_array[L][i]-tmp_dist);

		auto at = LOC.find(tmp_diff);

		if(at == LOC.end()){ //入力にない距離なら不適
			FLG = false;
			break;
		}

		tmp_loc = LOC[tmp_diff];

		if(next_rest_num[L][tmp_loc] == 0){ //距離がもう残っていない場合は不適
			FLG = false;
			break;
		}
		next_rest_num[L][tmp_loc]--;
	}

	if(FLG){ //計算済みでないか調べる

		string tmp_str = make_str(next_dist_array[L]);

		auto ch = MAP.find(tmp_str);

		if(ch == MAP.end()){

			MAP[tmp_str] = true;
			int next_index = get_index(next_rest_num[L]);
			recursive(next_dist_array[L],next_rest_num[L],next_index,num_decided+1);
		}
	}

	/*★残っている最大の距離を、右端からの距離と解釈する場合★*/

	tmp_dist = dist_array[N-1]-tmp_dist; //★★左端からの距離にする(右端からの距離 == tmp_dist)★★

	auto a_r = LOC.find(tmp_dist);
	if(a_r == LOC.end() || rest_num[LOC[tmp_dist]] == 0)return;

	//左端から数えて、一番近い空きスペースを探す
	for(int i = 0; i < N; i++){
		if(next_dist_array[R][i] == -1){
			next_dist_array[R][i] = tmp_dist;
			tmp_pos = i;
			break;
		}
	}

	 FLG = true;

	//既に配置されている他の距離と矛盾がないか調べる
	for(int i = 0; i < N-1; i++){ //★i == N-1までやると、tmp_distをデクリメントしているのでfalseになってしまう★
		if(next_dist_array[R][i] == -1 || i == tmp_pos)continue;

		tmp_diff = abs(next_dist_array[R][i]-tmp_dist);

		auto at = LOC.find(tmp_diff);

		if(at == LOC.end()){ //入力にない距離なら不適
			FLG = false;
			break;
		}

		tmp_loc = LOC[tmp_diff];

		if(next_rest_num[R][tmp_loc] == 0){ //距離がもう残っていない場合は不適
			FLG = false;
			break;
		}
		next_rest_num[R][tmp_loc]--;
	}

	if(FLG){ //計算済みでないか調べる

		string tmp_str = make_str(next_dist_array[R]);

		auto ch = MAP.find(tmp_str);

		if(ch == MAP.end()){

			MAP[tmp_str] = true;
			int next_index = get_index(next_rest_num[R]);
			recursive(next_dist_array[R],next_rest_num[R],next_index,num_decided+1);
		}
	}
}

void func(){

	MAP.clear();
	LOC.clear();
	ANS.clear();
	info_index = 0;

	int tmp;
	bool FLG;

	//距離の入力
	for(int i = 0; i < (N*(N-1))/2; i++){

		scanf("%d",&tmp);

		FLG = false;

		//既に登場した距離か調べる
		for(int k = 0;k < info_index; k++){
			if(info[k].dist == tmp){
				info[k].count++;
				FLG = true;
				break;
			}
		}

		if(FLG)continue;

		info[info_index].dist = tmp;
		info[info_index].count = 1;
		info_index++;
	}

	for(int i = 0; i < info_index; i++){ //数字の位置を記録
		LOC[info[i].dist] = i;
	}

	if(info[0].count != 1){ //最長距離が1つでないならreturn
		//printf("not 1\n");
		printf("-----\n");
		return;
	}

	int first_dist_array[NUM]; //左端の町からの相対距離配列
	int first_rest_num[(NUM*(NUM-1))/2]; //距離の使用数の残数配列<★infoの並びに対応★>

	first_dist_array[0] = 0;
	for(int i = 1; i <= N-2; i++)first_dist_array[i] = -1;
	first_dist_array[N-1] = info[0].dist;

	first_rest_num[0] = 0;
	for(int i = 1; i < info_index; i++)first_rest_num[i] = info[i].count;

	recursive(first_dist_array,first_rest_num,1,2);

	if(ANS.size() > 0){
		sort(ANS.begin(),ANS.end());
		ANS.erase(unique(ANS.begin(),ANS.end()),ANS.end());
	}

	for(int i = 0; i < ANS.size(); i++){
		printf("%d",ANS[i].table[0]);
		for(int k = 1; k < N-1; k++){
			printf(" %d",ANS[i].table[k]);
		}
		printf("\n");
	}

	printf("-----\n");
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3500
final_rank: 12

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

bool try_insert(map<int,int>&mp,const vector<int>&anss, int place,int rest, int l, int r) {
	vector<int>del_nums;

	if(l==place){
		int sum=anss[place];
		del_nums.push_back(sum);
		for (int x = l - 1; x >= 0; --x) {
			sum+=anss[x];
			del_nums.push_back(sum);
		}

		sum=rest-anss[place];
		del_nums.push_back(sum);
		for (int x = r; x < anss.size(); ++x) {
			sum+=anss[x];
			del_nums.push_back(sum);
		}
	}
	else {
		int sum = rest-anss[place];
		del_nums.push_back(sum);
		for (int x = l - 1; x >= 0; --x) {
			sum += anss[x];
			del_nums.push_back(sum);
		}

		sum = anss[place];
		del_nums.push_back(sum);
		for (int x = r; x < anss.size(); ++x) {
			sum+=anss[x];
			del_nums.push_back(sum);
		}
	}
	for (auto del_num : del_nums) {
		auto m=mp.find(del_num);
		if(m==mp.end())return false;
		else {
			mp[del_num]--;
			if(mp[del_num]==0)mp.erase(m);
		}
	}
	return true;
}

vector<vector<int>>answers;

void dfs(const vector<int>&anss, int rest,map<int,int>&v,int l,int r) {
	if (l + 1 == r) {
		assert(v.empty());
		{
			auto n_anss(anss);
			n_anss[l]=rest;
			answers.push_back(n_anss);
		}
		return ;
	}
	else {
		int max_num = prev(v.end())->first;
		{
			int l_num = max_num - accumulate(anss.begin(), anss.begin() + l, 0);
			if (l_num <= 0) {
			}
			else {
				map<int, int>next_v(v);
				auto n_anss(anss);
				n_anss[l] = l_num;
				if (try_insert(next_v, n_anss, l, rest, l, r)) {
					dfs(n_anss, rest - l_num, next_v, l + 1, r);
				}
			}


		}
		{
			int l_num = (rest + accumulate(anss.begin() + r, anss.end(), 0)) - max_num;
			if (l_num <= 0) {
			}
			else {
				map<int, int>next_v(v);
				auto n_anss(anss);
				n_anss[l] = l_num;
				if (try_insert(next_v, n_anss, l, rest, l, r)) {
					dfs(n_anss, rest - l_num, next_v, l + 1, r);
				}
			}
		}
		{
			int r_num = max_num - accumulate(anss.begin() + r, anss.end(), 0);
			if (r_num <= 0) {
			}
			else {
				map<int, int>next_v(v);
				auto n_anss(anss);
				n_anss[r - 1] = r_num;
				if (try_insert(next_v, n_anss, r - 1, rest, l, r)) {
					dfs(n_anss, rest - r_num, next_v, l, r - 1);
				}
			}
		}
		{
			int r_num = (rest + accumulate(anss.begin(), anss.begin() + l, 0)) - max_num;
			if (r_num <= 0) {
			}
			else {
				map<int, int>next_v(v);
				auto n_anss(anss);
				n_anss[r - 1] = r_num;
				if (try_insert(next_v, n_anss, r - 1, rest, l, r)) {
					dfs(n_anss, rest - r_num, next_v, l, r - 1);
				}
			}
		}
		return ;
	}
	
}

void solve(int N) {
	vector<int>v(N*(N-1)/2);
	map<int,int>mp;
	for(int i=0;i<(N*(N-1))/2;++i)cin>>v[i];
	for(int i=1;i<(N*(N-1))/2;++i)mp[v[i]]++;

	if (N ==2) {
		answers=(vector<vector<int>>{vector<int>{1}});
	}
	else {

		vector<int>anss(N - 1, -1);
		dfs(anss, v[0], mp, 0, N - 1);
	}
}

bool operator <(const vector<int>&l, const vector<int>&r) {
	for (int i = 0; i < l.size(); ++i) {
		if(l[i]<r[i])return true;
		else if(l[i]>r[i])return false;
	}
	return false;
}

int main()
{
	int N;
	while (cin >> N) {
		if(!N)break;
		answers.clear();
		solve(N);
		sort(answers.begin(),answers.end());
		answers.erase(unique(answers.begin(),answers.end()),answers.end());
		for (auto answer : answers) {
			for (int k = 0; k < N-1; ++k) {
				cout<<answer[k];
				if(k==N-2)cout<<endl;
				else cout<<" ";
			}
		}
		cout<<"-----"<<endl;
	}

	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3284
final_rank: 13

code_snippet: #include<bits/stdc++.h>

using namespace std;



#define FOR(i,bg,ed) for(int i=bg;i<ed;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

#define fi first
#define se second
#define pb push_back
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;

set<VV> memo; 
set<V> ret;

bool g(VV& dist,int l,int r,map<LL,int>& cnt){
    FOR(k,l+1,r){
        if(dist[k][l]==-1&&dist[r][k]==-1)continue;
        if(dist[k][l]==-1){
            dist[k][l]=dist[r][l]-dist[r][k];
            if(cnt.count(dist[k][l])==0)return false;
            if(--cnt[dist[k][l]]==0)cnt.erase(dist[k][l]);
            if(g(dist,l,k,cnt)==false)return false;
        }
        if(dist[r][k]==-1){
            dist[r][k]=dist[r][l]-dist[k][l];
            if(cnt.count(dist[r][k])==0)return false;
            if(--cnt[dist[r][k]]==0)cnt.erase(dist[r][k]);
            if(g(dist,k,r,cnt)==false)return false;
        }
    }
    return true;
}

void f(int N,VV dist,int l,int r,map<LL,int> m){
    if(memo.count(dist))return;
    memo.insert(dist);
    if(m.size()==0){
        V r;
        REP(i,N-1){
            r.pb(dist[i+1][i]);
        }
        ret.insert(r);
        return;
    }
    const int bg=0;
    const int ed=N-1;
    {
        VV nxt = dist;
        auto cp = m;
        LL x = cp.rbegin()->fi;
        nxt[r][bg]=x;
        if(--cp[x] == 0)cp.erase(x);
        LL y =nxt[ed][bg]-x;
        nxt[ed][r]=y;
        if(cp.count(y)==1){
            if(--cp[y]==0)cp.erase(y);
            if(g(nxt,bg,r,cp)&&g(nxt,r,ed,cp))f(N,nxt,l,r-1,cp);
        }
    }

    {
        VV nxt = dist;
        auto cp = m;
        LL x = cp.rbegin()->fi;
        nxt[ed][l]=x;
        if(--cp[x] == 0)cp.erase(x);
        LL y =nxt[ed][bg]-x;
        nxt[l][bg]=y;
        if(cp.count(y)==1){
            if(--cp[y] == 0)cp.erase(y);
            if(g(nxt,bg,l,cp)&&g(nxt,l,ed,cp))
                f(N,nxt,l+1,r,cp);
        }
    }

}
void solve(int N){
    if(N>=2){    
        memo.clear();
        ret.clear();
        map<LL,int> d;
        int M = N*(N-1) /2;
        VV dist(N);
        REP(i,N)dist[i].assign(i,-1);
        REP(i,M){
            LL x;
            cin>>x;
            if(i==0){
                dist[N-1][0]=x;
            }
            else{
                d[x]++;
            }
        }
        
        f(N,dist,1,N-2,d);
        for(auto &v:ret){
            REP(i,N-1)cout<<" "+(!i)<<v[i];cout<<endl;
        }
    }
    cout<<"-----"<<endl;
}

int main(){
    int N;
    while(cin>>N,N)solve(N);
}
accuracy: 1
time_ms: 30
memory_kb: 4116
final_rank: 15