<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

207. Robbers
time limit per test: 0.5 sec.
memory limit per test: 65536 KB
input: standard
output: standard



N robbers have robbed the bank. As the result of their crime they chanced to get M golden coins. Before the robbery the band has made an agreement that after the robbery i-th gangster would get Xi/Y of all money gained. However, it turned out that M may be not divisible by Y.

The problem which now should be solved by robbers is what to do with the coins. They would like to share them fairly. Let us suppose that i-th robber would get Ki coins. In this case unfairness of this fact is |Xi/Y-Ki/M|. The total unfairness is the sum of all particular unfairnesses. Your task as the leader of the gang is to spread money among robbers in such a way that the total unfairness is minimized.

Input
The first line of the input file contains numbers N, M and Y (1 ≤ N ≤ 1000, 1 ≤ M, Y ≤ 10000). N integer numbers follow - Xi (1 ≤ Xi ≤ 10000, sum of all Xi is Y).

Output
Output N integer numbers — Ki (sum of all Ki must be M), so that the total unfairness is minimal.

Sample test(s)

Input
3 10 4
1 1 2

Output
2 3 5
Author:	Andrew Stankevich
Resource:	Petrozavodsk Summer Trainings 2003
Date:	2003-08-23

<|response|>
1. Abridged Problem Statement  
   Given N robbers and M indivisible coins. They originally agreed that robber i should receive the fraction Xi/Y of the total. Since M may not be divisible by Y, we must assign each robber an integer number of coins Ki (sum Ki = M) so as to minimize the total unfairness  
     ∑_{i=1..N} | Xi/Y − Ki/M |.

2. Key Observations  
   • Define the “ideal” real share (in coins) for robber i as  
       a_i* = (Xi / Y) · M = Xi·M / Y.  
   • To minimize | Xi/Y − Ki/M | is equivalent to minimizing | a_i* − Ki | (up to the common factor 1/M).  
   • The best integer Ki for each i is either floor(a_i*) or ceil(a_i*).  
   • If we let f_i = ⌊a_i*⌋ and frac_i = a_i* − f_i, then choosing Ki = f_i has error frac_i, while Ki = f_i+1 has error (1 − frac_i).  
   • The total sum of floors S = ∑ f_i will be ≤ M, and ∑ ceil(a_i*) ≥ M. We must pick exactly B = M − S robbers whose Ki we bump up from f_i to f_i+1.  
   • To minimize the total error, we should bump those B robbers with the largest fractional parts frac_i (since they benefit most by rounding up).

3. Full Solution Approach  
   1. Read N, M, Y and the array X of length N.  
   2. For each i from 0 to N−1:  
      a. Compute a_i* = Xi·M / Y as a double.  
      b. Let f_i = floor(a_i*) (integer division).  
      c. Compute frac_i = a_i* − f_i.  
   3. Compute S = ∑ f_i and B = M − S (number of robbers to round up).  
   4. Create an array of indices idx = [0,1,2,…,N−1] and sort it in descending order of frac[idx[j]].  
   5. Initialize K[i] = f_i for all i.  
   6. For the first B indices in the sorted list, set K[idx[j]] = f_{idx[j]} + 1.  
   7. Output K[0], K[1], …, K[N−1].  

   This runs in O(N log N) time and uses O(N) memory, which easily handles N up to 1000.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M, Y;
    cin >> N >> M >> Y;
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    // Step 1–2: Compute floors and fractional parts
    vector<int> floorShare(N);
    vector<double> frac(N);
    long long sumFloor = 0;

    for (int i = 0; i < N; i++) {
        // exact real share in coins
        double exact = double(X[i]) * M / Y;
        int f = int(floor(exact));    // floor(a_i*)
        floorShare[i] = f;
        frac[i] = exact - f;          // fractional part
        sumFloor += f;
    }

    // Step 3: How many to round up
    int B = M - int(sumFloor);
    // B might be zero; no rounding needed in that case

    // Step 4: Sort indices by descending frac[i]
    vector<int> idx(N);
    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(),
         [&](int i, int j) {
             return frac[i] > frac[j];
         });

    // Step 5–6: Build the final Ki
    vector<int> K = floorShare;
    for (int t = 0; t < B; t++) {
        K[idx[t]] += 1;
    }

    // Step 7: Output result
    for (int i = 0; i < N; i++) {
        cout << K[i] << (i+1 < N ? ' ' : '\n');
    }
    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import sys

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    N = int(next(it))
    M = int(next(it))
    Y = int(next(it))
    X = [int(next(it)) for _ in range(N)]

    # Step 1–2: Compute floors and fractional parts
    floor_share = [0]*N
    frac = [0.0]*N
    sum_floor = 0

    for i in range(N):
        exact = X[i] * M / Y          # real-valued ideal share
        f = int(exact)                # floor
        floor_share[i] = f
        frac[i] = exact - f           # fractional remainder
        sum_floor += f

    # Step 3: Number to round up
    B = M - sum_floor

    # Step 4: Sort indices by descending fractional part
    idx = list(range(N))
    idx.sort(key=lambda i: frac[i], reverse=True)

    # Step 5–6: Assign final shares
    K = floor_share[:]              # start with all floors
    for t in range(B):
        K[idx[t]] += 1              # bump up the largest fractions

    # Step 7: Output
    print(' '.join(map(str, K)))

if __name__ == "__main__":
    main()
```