logo AlgoBeat OnlineJudge
登录 注册

#212890. [NERC 2021] Job Lookup

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Julia's friends want to organize a startup in a new country they moved to. They assigned each other numbers from 1 to according to the jobs they have, from the most front-end tasks to the most back-end ones. They also estimated a matrix , where is the average number of messages per month between people doing jobs and .

Now they want to make a hierarchy tree. It will be a with each node containing one member of the team. Some member will be selected as a leader of the team and will be contained in the root node. In order for the leader to be able to easily reach any subordinate, for each node of the tree, the following should apply: all members in its left subtree must have smaller numbers than , and all members in its right subtree must have larger numbers than .

After the hierarchy tree is settled, people doing jobs and will be communicating via the shortest path in the tree between their nodes. Let's denote the length of this path as . Thus, the cost of their communication is .

Your task is to find a hierarchy tree that minimizes the total cost of communication over all pairs: .

输入格式

The first line contains an integer () -- the number of team members organizing a startup.

The next lines contain integers each, -th number in -th line is --- the estimated number of messages per month between team members and ().

输出格式

Output a description of a hierarchy tree that minimizes the total cost of communication. To do so, for each team member from 1 to output the number of the member in its parent node, or 0 for the leader. If there are many optimal trees, output a description of any one of them.

样例

样例输入 1

4
0 566 1 0
566 0 239 30
1 239 0 1
0 30 1 0

样例输出 1

2 4 2 0

数据范围与提示

The minimal possible total cost is :