#P1154. Barn Assignment
Barn Assignment
Barn Assignment
Farmer John has \(N\) cows, where \(1 \leq N \leq 5000\). Each cow has a unique identification number \(s_i\). There are \(K\) barns in the barn complex, numbered from \(0\) to \(K-1\). Each cow sleeps in the barn corresponding to \(s_i \bmod K\). Given the numbers \(N\) and \(K\) along with the \(N\) cow identification numbers, determine which barn each cow should sleep in.
Input Format: The first line contains two integers \(N\) and \(K\). The second line contains \(N\) space-separated integers \(s_1, s_2, \ldots, s_N\).
Output Format: Output \(N\) lines each containing a single integer: the barn number for the corresponding cow in the order of input. The barn number is computed as \(s_i \bmod K\).
inputFormat
The input consists of two lines. The first line contains two integers, \(N\) and \(K\), separated by a space. The second line contains \(N\) integers \(s_1, s_2, \ldots, s_N\) separated by spaces.
outputFormat
For each cow, print a line with a single integer representing the barn number where the cow should sleep. The barn number is computed as \(s_i \bmod K\).
sample
3 5
7 12 20
2
2
0
</p>