P10194 [USACO24FEB] Milk Exchange G

Description

Farmer John's $N$ $(1 \leq N \leq 5 \cdot 10^5)$ cows are lined up in a circle. The $i$th cow has a bucket with integer capacity $a_i$ $(1 \leq a_i \leq 10^9)$ liters. All buckets are initially full. Every minute, cow $i$ will pass all the milk in their bucket to cow $i+1$ for $1\le i

Input Format

The first line contains $N$. The next line contains integers $a_1,a_2,...,a_N$.

Output Format

Output $N$ lines, where the $i$-th line is the total milk left among all cows after $i$ minutes.

Explanation/Hint

##### For Sample 1: Initially, the amount of milk in each bucket is $[2, 2, 2, 1, 2, 1]$. - After $1$ minute, the amount of milk in each bucket is $[1, 2, 2, 1, 1, 1]$ so the total amount of milk is $8$. - After $2$ minutes, the amount of milk in each bucket is $[1, 1, 2, 1, 1, 1]$ so the total amount of milk is $7$. - After $3$ minutes, the amount of milk in each bucket is $[1, 1, 1, 1, 1, 1]$ so the total amount of milk is $6$. - After $4$ minutes, the amount of milk in each bucket is $[1, 1, 1, 1, 1, 1]$ so the total amount of milk is $6$. - After $5$ minutes, the amount of milk in each bucket is $[1, 1, 1, 1, 1, 1]$ so the total amount of milk is $6$. - After $6$ minutes, the amount of milk in each bucket is $[1, 1, 1, 1, 1, 1]$ so the total amount of milk is $6$. ##### For Sample 2: After $1$ minute, the amount of milk in each bucket is $[1, 3, 6, 4, 4, 3, 3, 1]$ so the total amount of milk is $25$. #### SCORING: - Inputs 4-5: $N \le 2000$ - Inputs 6-8: $a_i \le 2$ - Inputs 9-13: All $a_i$ are generated uniformly at random in the range $[1,10^9]$. - Inputs 14-23: No additional constraints.