We need to minimize total shots given that shooting order affects the multiplier x: before shooting a can, x is the number of cans already shot. The cost for can i when shot at position p (i.e., after p-1 cans have been shot) is a_i * (p-1) + 1. So total cost = sum_{i in order} (a_i * (k_i) + 1) where k_i is the number of cans shot before it.
Let order be a permutation π of {1..n}. Then total shots = sum_{j=1 to n} (a_{π_j} * (j-1) + 1) = sum (a_{π_j} * (j-1)) + n.
Thus minimizing total shots is equivalent to minimizing sum_{j=1}^n a_{π_j} * (j-1). Since n is constant, we need to order the cans such that the sum of a_i times its position (starting from 0) is minimized. This is like assigning higher a_i to earlier positions? Because (j-1) is increasing, to minimize weighted sum we want larger a_i to have smaller weights (i.e., earlier positions). That suggests sorting by a_i descending: larger a_i first, smaller a_i later. But note: The cost for each can is a_i * (number of previously shot cans) + 1. So if we shoot high a_i early, they get low multiplier; later low a_i get higher multiplier. That seems optimal intuitively.
But is it always optimal? Let's test: suppose we have two cans with durabilities a and b. If we shoot a first, total = 1 + (b * 1 + 1) = b+2. If we shoot b first, total = 1 + (a * 1 + 1) = a+2. So we want to shoot the larger durability first. That matches sorting descending.
For n>2, it's like scheduling to minimize weighted sum where weights are the position index (starting from 0). This is a classic: minimize sum w_i * t_i where t_i are distinct integers 0..n-1 in some order and we assign jobs with processing times (a_i) to slots. Since it's linear, it's optimal to sort a_i in decreasing order and assign to increasing slots (i.e., larger a_i to smaller t_i). That's due to the rearrangement inequality: sum of products is minimized when one sequence is increasing and the other decreasing. Here weights (j-1) are increasing from 0 to n-1. So a_i should be sorted decreasing.
Therefore, the optimal order is to sort cans by durability decreasing. If some a_i are equal, any order among them yields same total cost? Actually if equal, swapping does not change total because a_i are identical. So any permutation among equal values yields same sum. So we can output any order that is sorted decreasing.
But careful: The sample 3: Input: 6 cans with a = [5,4,5,4,4,5]. Sorting decreasing: 5,5,5,4,4,4. Sample output order: 6 1 3 5 2 4. That corresponds to indices: 6 (a_6=5), 1 (a_1=5), 3 (a_3=5), 5 (a_5=4), 2 (a_2=4), 4 (a_4=4). That's exactly decreasing order (by value, not index). So matches.
But sample 2: All 10's, any order is fine; they output 2 1 4 3.
Sample 1: [20,10,20] sorting decreasing gives 20,20,10. But note there are two 20s. The sample output is 1 3 2: a_1=20, a_3=20, a_2=10. That's decreasing order (by value). So matches.
Thus problem is trivial: sort in non-increasing order. However, we need to output the indices (1-based) of the cans in that order.
But is there any nuance? Let's double-check the cost formula: (a_i * x + 1) shots required to knock it down, where x is number already knocked. So if Vasya hasn't shot any yet, x=0, cost = 1. Yes.
Thus total = n + sum_{j} a_{π_j} * (j-1). So sorting descending is optimal.
But wait: The problem states n up to 1000, a_i up to 1000. So trivial.
However, I recall there is a known Codeforces problem "Pistol Shooting" or something. I think it's exactly that.
Thus solution: read n, array a. Create list of pairs (a_i, i). Sort descending by a_i; if equal, any order (like maintain original order or ascending index). Then compute total = n + sum_{k=0}^{n-1} sorted_a[k] * k (where sorted_a is the sorted list of a_i values). Actually careful: after sorting descending, for position j from 1 to n: a_sorted[j-1] * (j-1). So total = n + sum_{j=0}^{n-1} a_sorted[j] * j. Then output total and the indices.
Edge cases: n=2 works.
But let's double-check example 1: sorted values: 20,20,10. total = n=3 + (200 + 201 + 10*2) = 3 + (0+20+20)=43. Good.
Example 2: all 10, total = 4 + (100+101+102+103)=4+60=64. Good.
Example 3: values: sorted: 5,5,5,4,4,4 => total = 6 + (50+51+52+43+44+45) = 6 + (0+5+10+12+16+20)=6+63=69. Good.
Example 4: [1,4] sorted descending: 4,1 => total = 2 + (40+11)=2+1=3. Output: indices: 2 1. Good.
Thus problem solved.
But wait: Could there be any alternative order that yields same total? Yes if equal values; we can output any.
Thus solution is straightforward.
Now I'll write answer with explanation and code.
But the request: The user says "You are ChatGPT... Provide final answer." This is a typical Codeforces style problem. They might want a solution.
Thus output: We need to output the minimum shots and the order.
Implementation: In Python, read input, create list of tuples (a_i, i). sort with key lambda x: -x[0]. Compute total = n + sum(i * value for i, (value, idx) in enumerate(sorted_list)). But careful: enumerate returns index starting 0, which is exactly (j-1). So total = n + sum(index * value for index, (value, idx) in enumerate(sorted_list)). Then print total. Then print indices separated by spaces.
Time O(n log n), fine.
Thus final answer.
But also note: The input size small, but we must be careful about trailing spaces, etc.
Now write solution explanation.
I'll produce a final message containing the explanation and code.
I'll include code in Python.
Let's write.
Potential pitfalls: The output format: first line min shots, second line order. In sample there is trailing space after the last number? Actually they show "1 3 2 " with a space at the end. Not important.
Thus answer.
But the instruction: "You are ChatGPT, ... think step by step... Then provide final answer." So I should output a response with solution.
Thus final. We need to minimize the total number of shots. For each can, the number of shots required is a_i * x + 1, where x is the number of cans already knocked down before it. If we shoot in order π_1, π_2, …, π_n, total shots is
T = Σ_{j=1..n} (a_{π_j}·(j-1) + 1) = n + Σ_{j=1..n} a_{π_j}·(j-1).
Thus we must minimize S = Σ_{j=1..n} a_{π_j}·(j-1). The numbers (j-1) are strictly increasing from 0 to n-1. According to the rearrangement inequality, the sum Σ a_i·w_i is minimized when the larger a_i are paired with the smaller w_i. Therefore we should sort the cans in non‑increasing order of durability a_i. If several cans have equal a_i, their order does not affect the total.
Once the optimal order is known, we compute the total as n + Σ_{k=0}^{n-1} (sorted_a[k] * k). The indices of the cans in that order give the required sequence.
Complexity: O(n log n) time, O(n) memory.
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
n = int(next(it))
a = [(int(next(it)), i+1) for i in range(n)]
# sort by a_i descending
a.sort(key=lambda x: -x[0])
total = n
for pos, (val, _) in enumerate(a):
total += val * pos
order = [str(idx) for _, idx in a]
print(total)
print(' '.join(order))
if __name__ == "__main__":
solve()