#include <bits/stdc++.h>
#include<string>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
    ios;
    long long N,k;
    cin>>N>>k;
    long long a[N];
    int i=0;
    int l=0,d=k-1;
    for(int j =0;j<N;j++){
        cin>>a[j];
    }
    while(l<d){
        if(a[l]<=a[d]){
            a[d]-=a[l];
            a[l]=0;
            l++;
        }
        else
        {
            a[l]-=a[d];
            a[d]=0;
            d--;
        }
    for(int j =0;j<N;j++){
        cout<<a[j]<<" ";
    }
    cout<<endl;
    }
    cout<<a[l];
    return 0;
}