1. 

/**
* Angewandte Mathematik, SS11
* Problem: 10586 Polynomial Remains
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1527
*
* @author Fabian Trampusch
* @author Robert Schwarz
* @version 1.0, 29.05.2011
*
* Method : Polynomdivision.
* Status : Accepted!
* Runtime: 0.504
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringTokenizer st = null;

int n = 0, k = 0;
long[] polynom = null;
long[] resultPolynom = null;
long[] remainderPolynom = null;

while (true) {
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());

if (k == n && n == -1) {
System.exit(0);
}

polynom = readPolynomDesc(br.readLine());

if (k <= n && k != 0) {
resultPolynom = new long[n - k + 1];
remainderPolynom = new long[n + 1];

for (int i = 0; i < n - k + 1; i++) {
if (polynom[i] == 0)
continue;

resultPolynom[i] = polynom[i];
remainderPolynom[i] = resultPolynom[i];
remainderPolynom[i + k] = resultPolynom[i];

polynom[i] = polynom[i] - remainderPolynom[i];
polynom[i + k] = polynom[i + k] - remainderPolynom[i + k];

remainderPolynom[i] = 0;
remainderPolynom[i + k] = 0;

// for (int j = 0; j < polynom.length; j++) {
// if (remainderPolynom[j] != 0) {
// polynom[j] = polynom[j] - remainderPolynom[j];
// remainderPolynom[j] = 0;
// }
// }
}

printArrayReverseNotZero(polynom);
} else if(k == 0) {
System.out.println("0");
} else {
printArrayReverseNotZero(polynom);
}
}
}

public static void printArrayReverseNotZero(long[] array) {
int firstNotZeroIndex = array.length - 1;

for (int i = array.length - 1; i >= 0; i--) {
if (array[i] != 0) {
firstNotZeroIndex = i;
}
}

StringBuilder sp = new StringBuilder();
for (int i = array.length - 1; i >= firstNotZeroIndex; i--) {
sp.append(array[i] + " ");
}

System.out.println(sp.substring(0, sp.length() - 1).toString());
}

public static long[] readPolynomDesc(String line) {
StringTokenizer st = new StringTokenizer(line);

int countElements = st.countTokens();
long[] readLongs = new long[countElements];

for (int i = 0; i < countElements; i++) {
readLongs[countElements - i - 1] = Integer.parseInt(st.nextToken());
}

return readLongs;
}

public static long[] subtractPolynoms(long[] a, long[] b) {
long[] result = new long[a.length];

for (int i = 0; i < a.length; i++) {
result[i] = a[i] - b[i];
}

return result;
}
}