A squirrel has discovered a storage with nuts. The storage contains rows of rooms numbered from to . The row with index contains rooms numbered from to . The room located in the row and column contains nuts.
In the rooms, the numbers are all distinct and have values between and .
Formally, the storage has the shape of a triangle half-matrix, the one located below the main diagonal (including the main diagonal), in which each element represents a number of nuts. The numbers in this half-matrix are the numbers from to , with each number appearing exactly once.
For example, for the storage would have rooms containing the numbers from to . An example of such a storage could be the half-matrix shown below:

The squirrel walks along the main diagonal, and at each room located at position it chooses a single room located in the rectangle with the top-right corner at position and the bottom-left corner at position , and eats the acorns from that room. In the example above, when the squirrel is at position , it may choose to eat the nuts from one of the rooms colored in red. After it has gone through all the rooms on the main diagonal and has eaten the nuts from exactly different rooms, the squirrel leaves satisfied.
Task
Given and for any with and with , find the maximum number of nuts the squirrel can eat.
Also, for each of the rooms visited, find the number of nuts eaten by the squirrel.
Implementation
You must implement the function
void solve(int N, vector<vector<int>> A, long long& answer, vector<int>& solution)
Function parameters:
Input data:
int N: storage size / number of rowsvector<vector<int>> A: Number of nuts in each room (More precisely, in with and you will find the number of nuts in the room at position of row )
Output data:
long long &answer: will contain the maximum number of nuts that the squirrel can eat after going through all rooms of the diagonal.vector<int> &solution: a vector that will contain the amount of nuts eaten by the squirrel in each room. (More precisely, with represents the number of nuts eaten by the squirrel when it is in the room )
ATTENTION!! For both and , the indices start from and the size of the vector should be exactly .
Constraints
| # | Points | Constraints |
|---|---|---|
| 1 | 11 | . |
| 2 | 12 | . |
| 3 | 23 | . |
| 4 | 15 | . |
| 5 | 13 | . |
| 6 | 8 | The contents of the matrix are assigned randomly. |
| 7 | 18 | No additional constraints. |
Example
input
5
1
14 6
8 2 15
3 10 4 12
9 5 13 11 7
output
64
14 10 15 12 13