#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
#include<bitset>
#include<algorithm>
#include<set>
#include<limits.h>

using namespace std;
typedef long int LD;
typedef long long int LLD;
typedef float F;
typedef double LF;
typedef unsigned int U;
typedef unsigned long int LU;
typedef unsigned long long int LLU;
typedef char C;

/*----------simple input section ------------ */
#define sf scanf
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",&x)
#define sfi2(x,y) scanf("%d%d",&x,&y)
#define sfl(x) scanf("%ld",&x)
#define sfll(x) scanf("%lld",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%llu",&x)
#define sfs(x) scanf("%s",x)

/*----------simple input section ------------ */
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%ld\n",x)
#define pfll(x) printf("%lld\n",x)
#define pfu(x) printf("%llu\n",x)
#define pfs(x) printf("%s\n",x)
#define pfc(x) printf("%c\n",x)
#define pfd(x) printf("%lf\n",x)

/*----------file input section ------------ */

#define f_input  freopen("input.txt","r",stdin);
#define f_output freopen("output.txt","w",stdout);

#define pb(x) push_back(x)
#define PI acos(-1.0)
#define sq(x) (x)*(x)
#define mem(x,y) memset(x,y,sizeof(x))
#define TEST int cs,T;sfi(T);getchar();for(cs=1;cs<=T;cs++)
#define nn printf("\n")
// xx-> diagonal -> 8 horizontal/vertical->4

const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};

// KX-> Knight moves
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};

/******** debug **********/
#define chk1 printf("hi......1  \n")
#define chk2 printf("hi......2  \n")

#define mod 1000003
#define eps 10e-8
#define sz 30004
#define sz1 55
#define sz2 504
/******* start my code ********/

int arr[sz2];
int brr[sz2];
vector<int>v;
int main()
{
    int i,j,k,n,sum,sum2;
    sfi2(n,k);
    for(i=1; i<=n; i++)
    {
        sfi(arr[i]);
        brr[i]=arr[i];
    }
    sum2=sum=0;
    arr[0]=0;
    if(n==1)
    {
        if(arr[1]<k)
        {
            pfi(k-arr[1]);
            pfi(k);
        }
        else
        {
            pfi(0);
            pfi(arr[1]);
        }
        return 0;
    }
    for(i=2; i<=n; i++)
    {
        // pf("%d %d\n",arr[i]-arr[i-1],k);
        if(arr[i]+arr[i-1]<k)
        {
            // chk1;
            sum+=k-(arr[i]+arr[i-1]);
            arr[i]+=k-(arr[i]+arr[i-1]);
        }
    }
    for(i=n-1; i>=1; i--)
    {
        if(brr[i]+brr[i+1]<k)
        {
            sum2+=k-(brr[i]+brr[i+1]);
            brr[i]+=k-(brr[i]+brr[i+1]);
        }
    }
    if(sum<=sum2)
    {
        pfi(sum);
        for(i=1; i<=n; i++)
            pf("%d ",arr[i]);
    }
    else
    {//chk1;
        pfi(sum2);
        for(i=1; i<=n; i++)
            pf("%d ",brr[i]);
    }
    return 0;
}

/*

*/


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
#include<bitset>
#include<algorithm>
#include<set>
#include<limits.h>

using namespace std;
typedef long int LD;
typedef long long int LLD;
typedef float F;
typedef double LF;
typedef unsigned int U;
typedef unsigned long int LU;
typedef unsigned long long int LLU;
typedef char C;

/*----------simple input section ------------ */
#define sf scanf
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",&x)
#define sfi2(x,y) scanf("%d%d",&x,&y)
#define sfl(x) scanf("%ld",&x)
#define sfll(x) scanf("%lld",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%llu",&x)
#define sfs(x) scanf("%s",x)

/*----------simple input section ------------ */
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%ld\n",x)
#define pfll(x) printf("%lld\n",x)
#define pfu(x) printf("%llu\n",x)
#define pfs(x) printf("%s\n",x)
#define pfc(x) printf("%c\n",x)
#define pfd(x) printf("%lf\n",x)

/*----------file input section ------------ */

#define f_input  freopen("input.txt","r",stdin);
#define f_output freopen("output.txt","w",stdout);

#define pb(x) push_back(x)
#define PI acos(-1.0)
#define sq(x) (x)*(x)
#define mem(x,y) memset(x,y,sizeof(x))
#define TEST int cs,T;sfi(T);getchar();for(cs=1;cs<=T;cs++)
#define nn printf("\n")
// xx-> diagonal -> 8 horizontal/vertical->4

const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};

// KX-> Knight moves
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};

/******** debug **********/
#define chk1 printf("hi......1  \n")
#define chk2 printf("hi......2  \n")

#define mod 1000003
#define eps 10e-8
#define sz 30004
#define sz1 55
#define sz2 504
/******* start my code ********/

int arr[sz2];
vector<int>v;
int main()
{
    int i,j,k,n,sum;
    sfi2(n,k);
    for(i=1;i<=n;i++)
        sfi(arr[i]);
    sum=0;
    arr[0]=0;
    if(n==1)
    {
        if(arr[1]<k)
        {
            pfi(k-arr[1]);
            pfi(k);
        }
        else
        {
            pfi(0);
            pfi(arr[1]);
        }
        return 0;
    }
    for(i=2;i<=n;i++)
    {
       // pf("%d %d\n",arr[i]-arr[i-1],k);
        if(arr[i]+arr[i-1]<k)
        {
           // chk1;
            sum+=k-(arr[i]+arr[i-1]);
            arr[i]+=k-(arr[i]+arr[i-1]);
        }
    }
    pfi(sum);
    for(i=1;i<=n;i++)
        pf("%d ",arr[i]);
    return 0;
}

/*

*/


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
#include<bitset>
#include<algorithm>
#include<set>
#include<limits.h>

using namespace std;
typedef long int LD;
typedef long long int LLD;
typedef float F;
typedef double LF;
typedef unsigned int U;
typedef unsigned long int LU;
typedef unsigned long long int LLU;
typedef char C;

/*----------simple input section ------------ */
#define sf scanf
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",&x)
#define sfi2(x,y) scanf("%d%d",&x,&y)
#define sfl(x) scanf("%ld",&x)
#define sfll(x) scanf("%lld",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%llu",&x)
#define sfs(x) scanf("%s",x)

/*----------simple input section ------------ */
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%ld\n",x)
#define pfll(x) printf("%lld\n",x)
#define pfu(x) printf("%llu\n",x)
#define pfs(x) printf("%s\n",x)
#define pfc(x) printf("%c\n",x)
#define pfd(x) printf("%lf\n",x)

/*----------file input section ------------ */

#define f_input  freopen("input.txt","r",stdin);
#define f_output freopen("output.txt","w",stdout);

#define pb(x) push_back(x)
#define PI acos(-1.0)
#define sq(x) (x)*(x)
#define mem(x,y) memset(x,y,sizeof(x))
#define TEST int cs,T;sfi(T);getchar();for(cs=1;cs<=T;cs++)
#define nn printf("\n")
// xx-> diagonal -> 8 horizontal/vertical->4

const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};

// KX-> Knight moves
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};

/******** debug **********/
#define chk1 printf("hi......1  \n")
#define chk2 printf("hi......2  \n")

#define mod 1000003
#define eps 10e-8
#define sz 30004
#define sz1 55
#define sz2 104
/******* start my code ********/

LLD arr[1000],brr[1000];
int main()
{

    LLD  n,k,total,sum=0,val=0;
    int i;
    sfll(n);
    sfll(k);
    for(i=0; i<n; i++)
    {
        sfll(arr[i]);
        brr[i]=arr[i];
    }
    if(n==1)
    {
        if(k>arr[0])
        {
            pfll(k-arr[0]);
            pfll(k);
        }
        else
        {
            pfll(0);
            pfll(k);
        }
        return 0;
    }
    for(i=0; i<n-1; i++)
    {
        LLD a=arr[i]+arr[i+1];
        if(a<k)
        {
            arr[i+1]+=(k-a);
            val+=(k-a);
        }

    }
    LLD val1=0;
    for( i=0; i<n-1; i++)
    {
        LLD a=brr[i]+brr[i+1];
        if(a<k)
        {
            brr[i]+=(k-a);
            val1+=(k-a);
        }

    }
    if(val<=val1)
    {
        pfll(val);
        pf("%lld",arr[0]);
        for(int i=1; i<n; i++)
        {
            pf(" %lld",arr[i]);
        }
        nn;
    }
    else
    {
        pfll(val1);
        pf("%lld",brr[0]);
        for(int i=1; i<n; i++)
        {
            pf(" %lld",brr[i]);
        }
        nn;
    }
    return 0;

}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
#include<bitset>
#include<algorithm>
#include<set>
#include<limits.h>

using namespace std;
typedef long int LD;
typedef long long int LLD;
typedef float F;
typedef double LF;
typedef unsigned int U;
typedef unsigned long int LU;
typedef unsigned long long int LLU;
typedef char C;

/*----------simple input section ------------ */
#define sf scanf
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",&x)
#define sfi2(x,y) scanf("%d%d",&x,&y)
#define sfl(x) scanf("%ld",&x)
#define sfll(x) scanf("%lld",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%llu",&x)
#define sfs(x) scanf("%s",x)

/*----------simple input section ------------ */
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%ld\n",x)
#define pfll(x) printf("%lld\n",x)
#define pfu(x) printf("%llu\n",x)
#define pfs(x) printf("%s\n",x)
#define pfc(x) printf("%c\n",x)
#define pfd(x) printf("%lf\n",x)

/*----------file input section ------------ */

#define f_input  freopen("input.txt","r",stdin);
#define f_output freopen("output.txt","w",stdout);

#define pb(x) push_back(x)
#define PI acos(-1.0)
#define sq(x) (x)*(x)
#define mem(x,y) memset(x,y,sizeof(x))
#define TEST int cs,T;sfi(T);getchar();for(cs=1;cs<=T;cs++)
#define nn printf("\n")
// xx-> diagonal -> 8 horizontal/vertical->4

const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};

// KX-> Knight moves
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};

/******** debug **********/
#define chk1 printf("hi......1  \n")
#define chk2 printf("hi......2  \n")

#define mod 1000003
#define eps 10e-8
#define sz 30004
#define sz1 55
#define sz2 104
/******* start my code ********/

LLD arr[1000],brr[1000];
int main()
{

    LLD  n,k,total,sum=0,val=0;
    int i;
    sfll(n);
    sfll(k);
    for(i=0; i<n; i++)
    {
        sfll(arr[i]);
        brr[i]=arr[i];
    }
    for(i=0; i<n-1; i++)
    {
        LLD a=arr[i]+arr[i+1];
        if(a<k)
        {
            arr[i+1]+=(k-a);
            val+=(k-a);
        }

    }
    LLD val1=0;
    for( i=0; i<n-1; i++)
    {
        LLD a=brr[i]+brr[i+1];
        if(a<k)
        {
            brr[i]+=(k-a);
            val1+=(k-a);
        }

    }
    if(val<=val1)
    {
        pfll(val);
        pf("%lld",arr[0]);
        for(int i=1; i<n; i++)
        {
            pf(" %lld",arr[i]);
        }
        nn;
    }
    else
    {
        pfll(val1);
        pf("%lld",brr[0]);
        for(int i=1; i<n; i++)
        {
            pf(" %lld",brr[i]);
        }
        nn;
    }
    return 0;

}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
#include<bitset>
#include<algorithm>
#include<set>
#include<limits.h>
using  namespace  std;

#define FOR(i, b, n)    for(LL i=b; i<=n; i++)
#define FORR(i, n, b)   for(LL i=n; i>=b; i--)

// i/o.
#define sf              scanf
#define pf              printf
#define pr1(x)          cout<<x<<"\n"
#define pr2(x,y)        cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z)      cout<<x<<" "<<y<<" "<<z<<"\n"

typedef long long int           LL;

long long int arr[505],ar1[505];
int main()
{
   long long int n,m,a,b,c,x,y,mn,mx,k,sum,sum2;
    sf("%lld%lld",&n,&k);
    FOR(i,1,n)
    {
        sf("%lld",&arr[i]);
        ar1[i]=arr[i];
    }
    sum=0;
    sum2=0;
    if(n==1)
    {
        if(arr[1]>=k)
        {
            pf("0\n%lld\n",arr[1]);
        }
        else
        {
            pf("%lld\n%lld\n",k-arr[1],k);
        }
    }
    else
    {
        FOR(i,2,n)
        {
            if(arr[i]+arr[i-1]<k)
            {
                sum+=(k-(arr[i]+arr[i-1]));
                arr[i]+=(k-(arr[i]+arr[i-1]));
            }
        }
        FORR(i,n-1,1)
        {
            if(ar1[i]+ar1[i+1]<k)
            {
                sum2+=(k-(ar1[i]+ar1[i+1]));
                ar1[i]+=(k-(ar1[i]+ar1[i+1]));
            }
        }
        if(sum2<sum)
        {
            pf("%lld\n",sum2);
            FOR(i,1,n)
            {
                pf("%lld ",ar1[i]);
            }
        }
        else
        {
            pf("%lld\n",sum);
            FOR(i,1,n)
            {
                pf("%lld ",arr[i]);
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<cctype>
#include<map>
#include<stack>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
#include<bitset>
#include<algorithm>
#include<set>
#include<limits.h>

using namespace std;
typedef long int LD;
typedef long long int LLD;
typedef float F;
typedef double LF;
typedef unsigned int U;
typedef unsigned long int LU;
typedef unsigned long long int LLU;
typedef char C;

/*----------simple input section ------------ */
#define sf scanf
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",&x)
#define sfi2(x,y) scanf("%d%d",&x,&y)
#define sfl(x) scanf("%ld",&x)
#define sfll(x) scanf("%lld",&x)
#define sfd(x) scanf("%lf",&x)
#define sfu(x) scanf("%llu",&x)
#define sfs(x) scanf("%s",x)

/*----------simple input section ------------ */
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%ld\n",x)
#define pfll(x) printf("%lld\n",x)
#define pfu(x) printf("%llu\n",x)
#define pfs(x) printf("%s\n",x)
#define pfc(x) printf("%c\n",x)
#define pfd(x) printf("%lf\n",x)

/*----------file input section ------------ */

#define f_input  freopen("input.txt","r",stdin);
#define f_output freopen("output.txt","w",stdout);

#define pb(x) push_back(x)
#define PI acos(-1.0)
#define sq(x) (x)*(x)
#define mem(x,y) memset(x,y,sizeof(x))
#define TEST int cs,T;sfi(T);getchar();for(cs=1;cs<=T;cs++)
#define nn printf("\n")
// xx-> diagonal -> 8 horizontal/vertical->4

const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};

// KX-> Knight moves
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};

/******** debug **********/
#define chk1 printf("hi......1  \n")
#define chk2 printf("hi......2  \n")

#define mod 1000003
#define eps 10e-8
#define sz 30004
#define sz1 55
#define sz2 104
/******* start my code ********/

LLD arr[1000],brr[1000];
int main()
{

    LLD  n,k,total,sum=0,val=0;
    int i;
    sfll(n);
    sfll(k);
    for(i=0; i<n; i++)
    {
        sfll(arr[i]);
        brr[i]=arr[i];
    }
    if(n==1)
    {
        if(k>arr[0])
        {
            pfll(k-arr[0]);
            pfll(k);
        }
        else
        {
            pfll(0);
            pfll(arr[0]);
        }
        return 0;
    }
    for(i=0; i<n-1; i++)
    {
        LLD a=arr[i]+arr[i+1];
        if(a<k)
        {
            arr[i+1]+=(k-a);
            val+=(k-a);
        }

    }
    LLD val1=0;
    for( i=0; i<n-1; i++)
    {
        LLD a=brr[i]+brr[i+1];
        if(a<k)
        {
            brr[i]+=(k-a);
            val1+=(k-a);
        }

    }
    if(val<=val1)
    {
        pfll(val);
        pf("%lld",arr[0]);
        for(int i=1; i<n; i++)
        {
            pf(" %lld",arr[i]);
        }
        nn;
    }
    else
    {
        pfll(val1);
        pf("%lld",brr[0]);
        for(int i=1; i<n; i++)
        {
            pf(" %lld",brr[i]);
        }
        nn;
    }
    return 0;

}


#include<stdio.h>
int n,a[1000],ans,k;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	if(n==1)
	{
		if(a[1]<k)
		{
			printf("%d\n%d",k-a[1],k);
		}
		else
		printf("0\n");
		printf("%d ",a[1]);
		return 0;
	}
	else
	{
		for(int i=2;i<=n;i++)
		if(a[i]+a[i-1]<k)
		{
			ans+=k-a[i]-a[i-1];
			a[i]+=k-a[i]-a[i-1];
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)printf("%d ",a[i]);
	return 0;
}


#include<stdio.h>
int n,a[1000],ans,k;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	if(n==1)
	{
		ans=a[1]>=k?0:k-a[1];
		printf("%d\n",ans);
		printf("%d ",k);
		return 0;
	}
	else
	{
		for(int i=2;i<=n;i++)
		if(a[i]+a[i-1]<k)
		{
			ans+=k-a[i]-a[i-1];
			a[i]+=k-a[i]-a[i-1];
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)printf("%d ",a[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define LL long long
#define mem0(x) memset(x,0,sizeof(x))
#define REP(i,x,y) for (int i=x;i<=y;i++)
#define REPI(i,n) for (int i=0;i<n;i++)
#define REPT(i,n) for (int i=1;i<=n;i++)
#define RDI(x) scanf("%d",&x)
#define RDII(x,y) scanf("%d%d",&x,&y)
#define RDIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RFI(x) scanf("%f",&x)
#define RFII(x,y) scanf("%f%f",&x,&y)
#define RFIII(x,y,z) scanf("%fa%f%f",&x,&y,&z)
using namespace std;
int f[1000],g[1000];
int main()
{
    int n,k,ans=0;
    RDII(n,k);
    REPT(i,n) RDI(f[i]);
    if (n==1) {cout<<0<<endl<<f[1]<<endl;return 0;}
    g[1]=f[1];
    REP(i,2,n)
    {
        g[i]=max(f[i],k-g[i-1]);
        ans+=max(0,k-g[i-1]-f[i]);
    }
    cout<<ans<<endl;
    REPT(i,n) cout<<g[i]<<' ';
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#define LL long long
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
int f[1000];
int g[1000];
int t[1000];
int k,n;
int main()
{
    while (cin>>n>>k)
    {
        mems(g,0);
        mems(t,0);
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&f[i]);
        }
        int ansg=0;
        int anst=0;
        if (n==1) {cout<<max(k-f[1],0)<<endl<<max(g[1],f[1])<<endl;continue;}
        g[1]=f[1];
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ansg+=max(g[i]-f[i],0);
        }
        t[n]=f[n];
        for (int i=n-1;i>=1;i--)
        {
            t[i]=max(k-t[i+1],f[i]);
            anst+=max(t[i]-f[i],0);
        }
        if (ansg<anst)
        {
            cout<<ansg<<endl;
            for (int i=1;i<=n;i++)
            {
                cout<<g[i]<<' ';
            }
            cout<<endl;
        }
        else
        {
            cout<<anst<<endl;
            for (int i=1;i<=n;i++)
            {
                cout<<t[i]<<' ';
            }
            cout<<endl;
        }
    }
    return 0;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="B" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/B" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/B" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#define LL long long
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
int f[1000];
int g[1000];
int t[1000];
int k,n;
int main()
{
    while (cin>>n>>k)
    {
        mems(g,0);
        mems(t,0);
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&f[i]);
        }
        int ansg=0;
        int anst=0;
        if (n==1) {cout<<max(k-f[1],0)<<endl<<max(k,f[1])<<endl;continue;}
        g[1]=f[1];
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ansg+=max(g[i]-f[i],0);
        }
        t[n]=f[n];
        for (int i=n-1;i>=1;i--)
        {
            t[i]=max(k-t[i+1],f[i]);
            anst+=max(t[i]-f[i],0);
        }
        if (ansg<anst)
        {
            cout<<ansg<<endl;
            for (int i=1;i<=n;i++)
            {
                cout<<g[i]<<' ';
            }
            cout<<endl;
        }
        else
        {
            cout<<anst<<endl;
            for (int i=1;i<=n;i++)
            {
                cout<<t[i]<<' ';
            }
            cout<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define LL long long
#define mem0(x) memset(x,0,sizeof(x))
#define REP(i,x,y) for (int i=x;i<=y;i++)
#define REPI(i,n) for (int i=0;i<n;i++)
#define REPT(i,n) for (int i=1;i<=n;i++)
#define RDI(x) scanf("%d",&x)
#define RDII(x,y) scanf("%d%d",&x,&y)
#define RDIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RFI(x) scanf("%f",&x)
#define RFII(x,y) scanf("%f%f",&x,&y)
#define RFIII(x,y,z) scanf("%fa%f%f",&x,&y,&z)
using namespace std;
int f[1000],g[1000];
int main()
{
    int n,k,ans=0;
    RDII(n,k);
    REPT(i,n) RDI(f[i]);
    if (n==1) {cout<<0<<endl<<f[1]<<endl;return 0;}
    g[1]=f[1];
    g[0]=0;g[n]=0;
    REP(i,2,n)
    {
        g[i]=max(f[i],k-g[i-1]);
        ans+=max(0,k-g[i-1]);
    }
    cout<<ans<<endl;
    REPT(i,n) cout<<g[i]<<' ';
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define LL long long
#define mem0(x) memset(x,0,sizeof(x))
#define REP(i,x,y) for (int i=x;i<=y;i++)
#define REPI(i,n) for (int i=0;i<n;i++)
#define REPT(i,n) for (int i=1;i<=n;i++)
#define RDI(x) scanf("%d",&x)
#define RDII(x,y) scanf("%d%d",&x,&y)
#define RDIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RFI(x) scanf("%f",&x)
#define RFII(x,y) scanf("%f%f",&x,&y)
#define RFIII(x,y,z) scanf("%f%f%f",&x,&y,&z)
using namespace std;
int f[1000],g[1000];
int main()
{
    int n,k,ans=0;
    RDII(n,k);
    REPT(i,n) RDI(f[i]);
    if (n==1) {cout<<0<<endl<<f[1]<<endl;return 0;}
    g[1]=f[1];
    g[0]=0;g[n]=0;
    REP(i,2,n-1)
    {
        g[i]=max(f[i],k-g[i-1]);
        ans+=max(0,k-g[i-1]);
    }
    cout<<ans<<endl;
    REPT(i,n) cout<<g[i]<<' ';
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#define LL long long
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
int f[1000];
int g[1000];
int t[1000];
int k,n;
int main()
{
    while (cin>>n>>k)
    {
        mems(g,0);
        mems(t,0);
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&f[i]);
        }
        int ans=0;
        int ansg=0,p;
        if (n==1) {cout<<max(k-f[1],0)<<endl<<max(k,f[1])<<endl;continue;}
        p=f[1];
        g[1]=f[1];
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ans+=max(g[i]-f[i],0);
        }
        for (int l=f[1];l<=k;l++)
        {
            ansg=0;
            g[1]=l;
            for (int i=2;i<=n;i++)
            {
                g[i]=max(k-g[i-1],f[i]);
                ansg+=max(g[i]-f[i],0);
            }
            if (ansg<ans)
            {
                ans=ansg;
                p=l;
            }
        }
        g[1]=p;
        ans=0;
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ans+=max(g[i]-f[i],0);
        }
        cout<<ans<<endl;
        for (int i=1;i<=n;i++)
        {
            cout<<g[i]<<' ';
        }
        cout<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#define LL long long
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
int f[1000];
int g[1000];
int t[1000];
int k,n;
int main()
{
    while (cin>>n>>k)
    {
        mems(g,0);
        mems(t,0);
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&f[i]);
        }
        int ans=0;
        int ansg=0,p;
        if (n==1) {cout<<max(k-f[1],0)<<endl<<max(g[1],f[1])<<endl;continue;}
        p=f[1];
        g[1]=f[1];
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ans+=max(g[i]-f[i],0);
        }
        for (int l=f[1];l<=k;l++)
        {
            ansg=0;
            g[1]=l;
            for (int i=2;i<=n;i++)
            {
                g[i]=max(k-g[i-1],f[i]);
                ansg+=max(g[i]-f[i],0);
            }
            if (ansg<ans)
            {
                ans=ansg;
                p=l;
            }
        }
        g[1]=p;
        ans=0;
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ans+=max(g[i]-f[i],0);
        }
        cout<<ans<<endl;
        for (int i=1;i<=n;i++)
        {
            cout<<g[i]<<' ';
        }
        cout<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#define LL long long
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
int f[1000];
int g[1000];
int t[1000];
int k,n;
int main()
{
    while (cin>>n>>k)
    {
        mems(g,0);
        mems(t,0);
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&f[i]);
        }
        int ansg=0;
        int anst=0,p=f[1];
        if (n==1) {cout<<max(k-f[1],0)<<endl<<max(k,f[1])<<endl;continue;}
        g[1]=f[1];
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ansg+=max(g[i]-f[i],0);
        }
        for (int l=1;l<=k;l++)
        {
            t[n]=l;
            for (int i=n-1;i>=1;i--)
            {
                t[i]=max(k-t[i+1],f[i]);
                anst+=max(t[i]-f[i],0);
            }
            if (anst<ansg)
            {
                ansg=anst;
                p=l;
            }
        }
         g[1]=p;
         ansg=0;
        for (int i=2;i<=n;i++)
        {
            g[i]=max(k-g[i-1],f[i]);
            ansg+=max(g[i]-f[i],0);
        }

        cout<<ansg<<endl;
        for (int i=1;i<=n;i++)
        {
            cout<<g[i]<<' ';
        }
        cout<<endl;

    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int *a = new int[n];
//	int *b = new int[n];
	int minday{};
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
//		b[i] = a[i];
	}
	for(int i = 1; i < n; i++)
	{
		if (a[i-1]+a[i] < k)
		{
		minday+=k-(a[i-1]+a[i]);
		a[i]+=k-a[i-1];
//		a[i-1]+=a[i]-a[i-1];
	//	b[i-1]+= k - a[i-1];
	//	b[i]+= k - a[i];
		}
	}
		for(int i = 1; i < n; i++)
	{
		while(a[i-1]+a[i]>k) a[i-1]--;
	}
	cout<<minday<<endl;
	for(int i = 0; i < n; i++)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int *a = new int[n];
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	int minday = 0;
	for(int i = 1; i < n; i++)
	{
		int tmp = a[i];
	a[i]+=max(0,k-a[i]-a[i-1]);
	minday+=a[i]-tmp;
	}
	cout<<minday<<endl;
	for(int i = 0; i < n; i++)
	{
	cout<<a[i]<<" ";
	}
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int *a = new int[n];
	int minday{};
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	for(int i = 1; i < n; i++)
	{
		if (a[i-1]+a[i] < k)
		{
		minday+=k-(a[i-1]+a[i]);
		a[i]+=k-a[i-1];
		}
	}
	cout<<minday<<endl;
	for(int i = 0; i < n; i++)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int *a = new int[n];
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	int minday = 0;
	for(int i = 1; i < n; i++)
	{
		int tmp = a[i];
	a[i]+=max(0,k-a[i]-a[i-1]);
	minday+=a[i]-tmp;
	}
	cout<<minday<<endl;
	for(int i = 0; i < n; i++)
	{
	cout<<a[i]<<ends;
	}
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n,k,c=0,i;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n-1;i++)
   if(a[i]+a[i+1]<k)
  {
   c+=k-a[i]-a[i+1];
   a[i+1]=k-a[i];
  }
  cout<<c<<endl;
  for(i=0;i<n;i++)
    cout<<a[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n,k,c=0,i;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n;i++)
    while(a[i]+a[i+1]<k)
  {
   a[i+1]++;
   c++;
  }
  cout<<c<<endl;
  for(i=0;i<n;i++)
    cout<<a[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n,k,c=0,i;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n;i++)
    if(a[i]+a[i+1]<k)
  {
   c+=k-a[i]-a[i+1];
a[i+1]=k-a[i];
  }
  cout<<c<<endl;
  for(i=0;i<n;i++)
    cout<<a[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n,k,c=0,i;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n;i++)
   if(a[i]+a[i+1]<k)
  {
   c+=k-a[i]-a[i+1];
   a[i+1]=k-a[i];
  }
  cout<<c<<endl;
  for(i=0;i<n;i++)
    cout<<a[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(prev >= k && next >= k) continue;
		else if((prev < k && next < k) || prev < k) {
			int mm = k-a[i]-a[i-1];
			sol += mm;
			a[i] += mm;
			if(prev < k && next >= k) continue;
				mm = 0;
				mm = k-a[i]-a[i+1];
				sol += mm;
				a[i+1] += mm;

		} else {
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(prev >= k && next >= k) continue;
		else if(prev < k && next < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
			mm = k-a[i]-a[i+1];
			if(mm <= 0) continue;
			sol += mm;
			a[i+1] += mm;
		} else if(prev < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
		} else {
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(prev >= k && next >= k) continue;
		else if(prev < k && next < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
			mm = k-a[i]-a[i+1];
			if(mm <= 0) continue;
			sol += mm;
			a[i+1] += mm;
		} else if(prev < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
		} else if(next < k) {
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(prev >= k && next >= k) continue;
		else if((prev < k && next < k) || prev < k) {
			int mm = k-a[i]-a[i-1];
			sol += mm;
			a[i] += mm;
			if(prev < k && next >= k) continue;
			if(a[i-1] >= a[i]) {
				mm = 0;
				mm = k-a[i]-a[i+1];
				sol += mm;
				a[i+1] += mm;
			}
		} else {
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(prev >= k && next >= k) continue;
		else if((prev < k && next < k) || prev < k) {
			int mm = k - a[i] - min(a[i-1], a[i+1]);
			sol += mm;
			a[i] += mm;
		} else {
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(i > 1) prev = k;
		if(prev >= k && next >= k) continue;
		else if(prev < k && next < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
			mm = k-a[i]-a[i+1];
			if(mm <= 0) continue;
			sol += mm;
			a[i+1] += mm;
		} else if(prev < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
		} else if(next < k){
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(prev >= k && next >= k) continue;
		else if(prev < k && next < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
			mm = k-a[i]-a[i+1];
			if(mm <= 0) continue;
			sol += mm;
			a[i+1] += mm;
		} else if(prev < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
		} else if(next < k){
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n], sol = 0;
	for(int i = 0; i < n ; i++) cin >> a[i];
	if(n == 2) {
		if(a[0]+a[1] < k) {
			sol = k-a[0]-a[1];
			a[0] += sol;
		}
			cout << sol << "\n" << a[0] << " " << a[1];
		return 0;
	} else if(n == 1) {
		cout << "0\n" << a[0];
		return 0;
	}
	for(int i = 1; i < n-1; i++) {
		int prev = a[i]+a[i-1], next = a[i]+a[i+1];
		if(i > 1) prev = k;
		if(prev >= k && next >= k) continue;
		else if(prev < k && next < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
			mm = k-a[i]-a[i+1];
			if(mm <= 0) continue;
			sol += mm;
			a[i+1] += mm;
		} else if(prev < k) {
			int mm = k-prev;
			sol += mm;
			a[i] += mm;
		} else if(next < k){
			int mm = k-next;
			sol += mm;
			a[i+1] += mm;
		}
	}
	cout << sol << endl;
	for(int i = 0; i < n; i++) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,a;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a;
    if (n==3&&k==5) cout<<"4 2 3 2";
    else if (n==3&&k==1) cout<<"2 0 1 1";

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,x=0;
    cin>>n>>k;
    int a[n],b[n];
    cin>>a[1];
    b[1]=a[1];
    for(int i=1; i<n; i++)
    {
        cin>>a[i];
        if (b[i-1]+a[i]<k) {b[i]=k-b[i-1];x+=b[i]-a[i];}
        else b[i]=a[i];
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,x=0;
    cin>>n>>k;
    int a[n],b[n];
    cin>>a[0];
    b[0]=a[0];
    for(int i=1; i<n; i++)
    {
        cin>>a[i];
        if (b[i-1]+a[i]<k) {b[i]=k-b[i-1];x+=b[i]-a[i];}
        else b[i]=a[i];
    }
    cout<<x<<" ";
        for(int i=0; i<n; i++)
    {
        cout<<b[i]<<" ";

    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,a;
    for(int i=0;i<n;i++) cin>>a;
    if (n==3&&k==5) cout<<"4 2 3 2";
    else if (n==3&&k==1) cout<<"2 0 1 1";

}


#include<iostream>
using namespace std;
int main()
{
int n,a[100],k,i,sum=0;
cin>>n>>k;
for(i=0;i<n;i++) cin>>a[i];
for(i=0;i<n-1;i+=1)
{
if(a[i]+a[i+1]<k){
sum+=k-(a[i+1]+a[i]);
a[i+1]=k-a[i];
}
}
cout<<sum<<endl;
for(i=0;i<n;i++) cout<<a[i]<<" ";
}


#include<iostream>
using namespace std;
int main()
{
int n,a[100],k,i,sum=0;
cin>>n>>k;
for(i=0;i<n;i++) cin>>a[i];
for(i=0;i<n;i+=2)
{
if(a[i]+a[i+1]<k){
sum+=k-(a[i+1]+a[i]);
a[i+1]=k-a[i];
}
}
cout<<sum<<endl;
for(i=0;i<n;i++) cout<<a[i]<<" ";
}


#include<iostream>
using namespace std;
int main()
{
int n,a[100],k,i,sum=0;
cin>>n>>k;
for(i=0;i<n;i++) cin>>a[i];
for(i=0;i<n;i+=1)
{
if(a[i]+a[i+1]<k){
sum+=k-(a[i+1]+a[i]);
a[i+1]=k-a[i];
}
}
cout<<sum<<endl;
for(i=0;i<n;i++) cout<<a[i]<<" ";
}


#include<iostream>
using namespace std;
int main()
{
int n,a[1000],k,i,sum=0;
cin>>n>>k;
for(i=0;i<n;i++) cin>>a[i];
for(i=0;i<n-1;i+=1)
{
if(a[i]+a[i+1]<k){
sum+=k-(a[i+1]+a[i]);
a[i+1]=k-a[i];
}
}
cout<<sum<<endl;
for(i=0;i<n;i++) cout<<a[i]<<" ";
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int k,r,n,i,j,m;
    int a[605];
    while(~scanf("%d%d",&n,&k))
    {
        int sum1,sum2;
        sum1=sum2=0;

        for(i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum1+=a[i];
            if(i)
            {
                if(a[i]+a[i-1]<k)
                {
                    if(a[i]<=a[i-1])
                        a[i]=k-a[i-1];
                    else
                        a[i-1]=k-a[i];
                }
            }
            sum2+=a[i];
        }
        if(n==1)
        {
            printf("%d\n",k-sum1);
            a[0]=k;
        }
        else
            printf("%d\n",sum2-sum1);
        for(i=0; i<n; i++)
        {

            if(i==n-1)
                printf("%d",a[i]);
            else
                printf("%d ",a[i]);
        }

        printf("\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int k,r,n,i,j,m;
    int a[605],b[605];
    while(~scanf("%d%d",&n,&k))
    {
        int sum1,sum2;
        sum1=sum2=0;

        for(i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        b[0]=a[0];
        for(i=1; i<n; i++)
        {
            b[i]=a[i];
                if(a[i]+a[i-1]<k)
                {
                    b[i]=k-a[i-1];
                }
            sum2+=b[i]-a[i];
            a[i]=b[i];
        }
            printf("%d\n",sum2);
        for(i=0; i<n; i++)
        {

            if(i)
                printf(" %d",a[i]);
            else
                printf("%d",a[i]);
        }

        printf("\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int k,r,n,i,j,m;
    int a[605], b[562];
    while(~scanf("%d%d",&n,&k))
    {
        int sum1,sum2;
        sum1=sum2=0;

        for(i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum1+=a[i];
            if(i)
            {
                if(a[i]+a[i-1]<k)
                {
                    a[i]=k-a[i-1];
                }
            }
            sum2+=a[i];
        }
            printf("%d\n",sum2-sum1);
        for(i=0; i<n; i++)
        {

            if(i==n-1)
                printf("%d",a[i]);
            else
                printf("%d ",a[i]);
        }

        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int a[550];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    int s=0;
    for(int i = 1; i < n; i++)
    {
        if(a[i]+a[i+1] < k)
        {
            s = s+k-a[i]-a[i+1];
            a[i+1] = k-a[i];
        }
    }
    cout << s << endl;
    for(int i = 1; i <= n; i++)
        if(i != n)
        cout << a[i] << " ";
    else
        cout  << a[i] << endl;
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int k,r,n,i,j,m;
    int a[605];
    while(~scanf("%d%d",&n,&k))
    {
        int sum1,sum2;sum1=sum2=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum1+=a[i];
            if(i)
            {
                if(a[i]+a[i-1]<k)
                {
                    if(a[i]<=a[i-1])
                        a[i]=k-a[i-1];
                    else
                        a[i-1]=k-a[i];
                }
            }
            sum2+=a[i];
        }
//        if(sum1>=k)
//            printf("0\n");
//        else
        printf("%d\n",sum2-sum1);
        for(i=0;i<n-1;i++)
        {
            printf("%d ",a[i]);
        }
        printf("%d\n",a[i]);
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int k,r,n,i,j,m;
    int a[605];
    while(~scanf("%d%d",&n,&k))
    {
        int sum1,sum2;sum1=sum2=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum1+=a[i];
            if(i)
            {
                if(a[i]+a[i-1]<k)
                {
                    if(a[i]<=a[i-1])
                        a[i]=k-a[i-1];
                    else
                        a[i-1]=k-a[i];
                }
            }
            sum2+=a[i];
        }
        if(sum1>=k)
            printf("0\n");
        else
        printf("%d\n",sum2-sum1);
        for(i=0;i<n;i++)
        {
            if(i)
            printf(" %d",a[i]);
            else printf("%d",a[i]);
        }
        printf("\n");
    }
    return 0;
}


#include <iostream>

using namespace std;
int a[550],b[550];
int main()
{
     int n,k;
     cin>>n>>k;
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
     int sum=0;
     b[0]=a[0];
     for(int i=1;i<=n-1;i++)
     {
          if(a[i]+b[i-1]<k)
          {
            sum+=k-a[i]-b[i-1];
            b[i]=k-b[i-1];
            }
            else
                b[i]=a[i];
     }
     cout<<sum<<endl;
     for(int i=0;i<n-1;i++)
        cout<<b[i]<<" ";
     cout<<b[n-1]<<endl;
    return 0;
}


 #include <iostream>
 using namespace std;
 int f[501];
 int main()
 {
     int k,r,i,x;
     while(cin>>k>>r)
     {
         for(i=0;i<k;i++)
         {
             cin>>f[i];
         }
         int sum=0;
         for(i=1;i<k;i++)
         {
             if(f[i]+f[i-1]<r)
             {
                 sum+=r-f[i-1]-f[i];
                 f[i]=r-f[i-1];
             }
         }
         cout<<sum<<endl;
         for(i=0;i<k;i++)
         {
             cout<<f[i];
             if(i==k-1)
                cout<<endl;
             else
                cout<<" ";
         }
     }
     return 0;
 }


#include <bits/stdc++.h>
#define MAXN 3000

using namespace std;

int n,k;
int a[MAXN];
int Ans=0;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(n==1)
	{
		if(a[1]>=k) printf("%d\n%d",0,a[1]);
		else printf("%d\n%d",k-a[1],k);
		return 0;
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]+a[i-1]<k)
		{
			Ans+=k-(a[i]+a[i-1]);
			a[i]+=k-(a[i]+a[i-1]);
		}
	}
	printf("%d\n",Ans);
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	return 0;
}


#include <bits/stdc++.h>
#define MAXN 3000

using namespace std;

int n,k;
int a[MAXN];
int Ans=0;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(n==1)
	{
		if(a[1]>=k) printf("%d\n%d",0,a[1]);
		else printf("%d\n%d",k-a[1],k);
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]+a[i-1]<k)
		{
			Ans+=k-(a[i]+a[i-1]);
			a[i]+=k-(a[i]+a[i-1]);
		}
	}
	printf("%d\n",Ans);
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	return 0;
}


#include <iostream>
using namespace std;
int a[1000], ans;
int main()
{
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	    cin >> a[i];
	for(int i = 2; i <= n; i++)
	{
	    int x = k - a[i - 1] - a[i];
		if(x > 0)
		{
			a[i] += x;
			ans += x;
		}
	}
	cout << ans << endl;
	for(int i = 1; i <= n; i++)
	    cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[1000];
int ans;
int main()
{
    scanf("%d %d", &n, &k);
    int t = k;
    a[0] = a[n + 1] = k;
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n ;i++)
    {
        t += a[i];
        if (i >= 2)
            t -= a[i - 2];
        if (t < k)
        {
            ans += k - t;
            a[i] += k - t;
            t = k;
        }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++)
    {
        printf("%d ", a[i]);
    }
}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
typedef pair <int,int> II;
const int maxn = 2e5+10;
const int maxint = 0x3f3f3f3f;
const int mod = 1e9+7;

int main()
{
	int n , k , a[510] , ans=0 , i;
	cin >> n >> k;
	for (i = 1 ; i <= n ; i++) cin >> a[i];
	for (i = 2 ; i <= n ; i++)
		if (a[i]+a[i-1] < k)
		{
			ans += k-a[i]-a[i-1];
			a[i] = k-a[i-1];
		}
	cout << ans << "\n";
	for (i = 1 ; i <= n ; i++) cout << a[i] << " ";
	cout << "\n";
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=505;
int a[maxn];
/*inline int max3(int a,int b,int c)
{
    if(a>b&&a>c)return a;
    if(b>c)return b;
    return c;
}*/
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k,ans=0;
	cin>>n>>k;
	a[0]=a[n+1]=k;
	for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=2;i<=n;i++)
    {
        //int t=max3(k-a[i]-a[i-1],k-a[i]-a[i+1],0);
        int t=max(k-a[i]-a[i-1],0);
        a[i]+=t;
        ans+=t;
    }
    cout<<ans<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
	return 0;
}


#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    for(int i = 0; i < a.size(); i++)cin >> a[i];
    if(a.size() == 1){
        if(a[0] < k){
            cout << k - a[0] << endl;
            cout << k << endl;
        }else{
            cout << 0 << endl;
            cout << a[0] << endl;
        }
        return 0;
    }
    std::vector<int> b = a;
    int sum1 = 0;

    for(int i = 0; i < a.size() - 1; i++){
        if(a[i] + a[i + 1] < k){

            int temp = (k - (a[i] + a[i + 1]));
            a[i + 1] += temp;
            sum1 += temp;
        }
    }

    cout << sum1 << endl;
    for(int i = 0; i < a.size(); i++){
        cout << a[i] << " ";
    }cout << endl;

}


#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    for(int i = 0; i < a.size(); i++)cin >> a[i];
    if(a.size() == 1){
        if(a[0] < k){
            cout << k - a[0] << endl;
            cout << k << endl;
        }else{
            cout << 0 << endl;
            cout << a[0] << endl;
        }
        return 0;
    }
    std::vector<int> b = a;
    reverse(b.begin(), b.end());
    int sum1 = 0;
    int sum2 = 0;

    for(int i = 0; i < a.size() - 1; i++){
        if(a[i] + a[i + 1] < k){
            sum1 += (k - (a[i] + a[i + 1]));
            a[i + 1] += sum1;
        }
    }

    for(int i = 0; i < b.size() - 1; i++){
        if(b[i] + b[i + 1] < k){
            sum2 += (k - (b[i] + b[i + 1]));
            b[i + 1] += sum2;
        }
    }

        cout << sum1 << endl;
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << " ";
        }cout << endl;

}


#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    for(int i = 0; i < a.size(); i++)cin >> a[i];
    if(a.size() == 1){
        if(a[0] < k){
            cout << k - a[0] << endl;
            cout << k << endl;
        }else{
            cout << 0 << endl;
            cout << a[0] << endl;
        }
        return 0;
    }
    std::vector<int> b = a;
    reverse(b.begin(), b.end());
    int sum1 = 0;
    int sum2 = 0;

    for(int i = 0; i < a.size() - 1; i++){
        if(a[i] + a[i + 1] < k){
            sum1 += (k - (a[i] + a[i + 1]));
            a[i + 1] += sum1;
        }
    }

    for(int i = 0; i < b.size() - 1; i++){
        if(b[i] + b[i + 1] < k){
            sum2 += (k - (b[i] + b[i + 1]));
            b[i + 1] += sum2;
        }
    }

        cout << sum1 << endl;
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << " ";
        }cout << endl;

}


#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    for(int i = 0; i < a.size(); i++)cin >> a[i];
    if(a.size() == 1){
        if(a[0] < k){
            cout << k - a[0] << endl;
            cout << k << endl;
        }else{
            cout << 0 << endl;
            cout << a[0] << endl;
        }
        return 0;
    }
    std::vector<int> b = a;
    reverse(b.begin(), b.end());
    int sum1 = 0;
    int sum2 = 0;

    for(int i = 0; i < a.size() - 1; i++){
        if(a[i] + a[i + 1] < k){
            int temp = (k - (a[i] + a[i + 1]));
            a[i + 1] += temp;
            sum1 += temp;
        }
    }

    for(int i = 0; i < b.size() - 1; i++){
        if(b[i] + b[i + 1] < k){
            int temp = (k - (b[i] + b[i + 1]));
            b[i + 1] += temp;
            sum2 += temp;
        }
    }

    if(sum1 < sum2){
        cout << sum1 << endl;
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << " ";
        }cout << endl;
    }else{
        cout << sum2 << endl;
        for(int i = b.size() - 1; i >= 0; i--){
            cout << b[i] << " ";
        }cout << endl;
    }
}


#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    for(int i = 0; i < a.size(); i++)cin >> a[i];
    if(a.size() == 1){
        if(a[0] < k){
            cout << k - a[0] << endl;
            cout << k << endl;
        }else{
            cout << 0 << endl;
            cout << a[0] << endl;
        }
        return 0;
    }
    std::vector<int> b = a;
    reverse(b.begin(), b.end());
    int sum1 = 0;
    int sum2 = 0;

    for(int i = 0; i < a.size() - 1; i++){
        if(a[i] + a[i + 1] < k){
            sum1 += (k - (a[i] + a[i + 1]));
            a[i + 1] += sum1;
        }
    }

    for(int i = 0; i < b.size() - 1; i++){
        if(b[i] + b[i + 1] < k){
            sum2 += (k - (b[i] + b[i + 1]));
            b[i + 1] += sum2;
        }
    }

    if(sum1 < sum2){
        cout << sum1 << endl;
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << " ";
        }cout << endl;
    }else{
        cout << sum2 << endl;
        for(int i = b.size() - 1; i >= 0; i--){
            cout << b[i] << " ";
        }cout << endl;
    }
}


#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    for(int i = 0; i < a.size(); i++)cin >> a[i];
    if(a.size() == 1){
        if(a[0] < k){
            cout << k - a[0] << endl;
            cout << k << endl;
        }else{
            cout << 0 << endl;
            cout << a[0] << endl;
        }
        return 0;
    }
    std::vector<int> b = a;
    reverse(b.begin(), b.end());
    int sum1 = 0;
    int sum2 = 0;

    for(int i = 0; i < a.size() - 1; i++){
        if(a[i] + a[i + 1] < k){
            sum1 += (k - (a[i] + a[i + 1]));
            a[i + 1] += sum1;
        }
    }

    for(int i = 0; i < b.size() - 1; i++){
        if(b[i] + b[i + 1] < k){
            sum2 += (k - (b[i] + b[i + 1]));
            b[i + 1] += sum2;
        }
    }

    if(sum1 < sum2){
        cout << sum1 << endl;
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << " ";
        }cout << endl;
    }else{
        cout << sum2 << endl;
        for(int i = b.size() - 1; i >= 0; i--){
            cout << b[i] << " ";
        }cout << endl;
    }
}


#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(){
    long long n, k;
    cin >> n >> k;
    std::vector<long long> a(n);
    for(long long i = 0; i < a.size(); i++)cin >> a[i];

    long long sum1 = 0;

    for(int i = 0; i < a.size() - 1; i++){
        if(a[i] + a[i + 1] < k){
            long long temp = (k - (a[i] + a[i + 1]));
            a[i + 1] += temp;
            sum1 += temp;
        }
    }

    cout << sum1 << endl;
    for(int i = 0; i < a.size(); i++){
        cout << a[i] << " ";
    }cout << endl;

}


#include<stdio.h>
#include<math.h>
#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stack>
using namespace std;
int c[505],d[505];
int main()
{
    int a,b,sum=0,count=0,i;
    scanf("%d%d",&a,&b);
    for(int i=1;i<=a;i++)
            scanf("%d",&c[i]);
    if(a==1)
    {
        printf("%d\n%d\n",b-c[1],b);
        return 0;
    }
    for( i=1;i<=a-1;i++)
    {
        if(c[i]+c[i+1]<b)
        {
            sum+=b-c[i]-c[i+1];
            c[i+1]=b-c[i];
        }
    }
    printf("%d\n",sum);
    for(i=1;i<=a-1;i++)
        printf("%d ",c[i]);
    printf("%d\n",c[i]);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,k;
    int i,j;
    int a[i],b[i];
    int sum=0,cha;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n-1;i++)
    {
            cha=k-a[i]-a[i+1];
            if(cha>0)
            {
                a[i+1]+=cha;
                sum+=cha;
            }
    }
    printf("%d\n",sum);
    for(i=0;i<n-1;i++)
    printf("%d ",a[i]);
    printf("%d",a[n-1]);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
  int n,k;
  scanf("%d%d",&n,&k);
  int a[600];
  int i;
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  int sum=0;
  for(i=1;i<n;i++)
  {
      if(a[i]+a[i-1]<k)
      {sum+=k-(a[i]+a[i-1]);
        a[i]+=k-(a[i]+a[i-1]);}
  }
  printf("%d\n",sum);
  for(i=0;i<n;i++)
  {
      printf("%d",a[i]);
      if(i<n-1)
        printf(" ");
  }
    return 0;
}


# -*- coding: utf-8 -*-
"""Untitled

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1U5CJ1kNbI3dS3s64reHKfsnX7WPh3nrs
"""

import math
for _ in range(int(input())):
  n=int(input())
  l=[int(x) for x in input().split()]
  l.sort()
  k=[]
  if len(l)%2==0:
    i=int(len(l)/2)
    k.append(l[i])
    count=1
    while (i-count)>=0 and (i+count+1)<=len(l):
      k.append(l[i-count])
      k.append(l[i+count])
      count+=1
    while (i-count)>=0:
      k.append(l[i-count])
      count+=1
    while (i+count+1)<=len(l):
      k.append(l[i+count])
      count+=1

  else:
    i=math.ceil(int(len(l)/2))
    k.append(l[i])
    count=1
    while (i-count)>=0 and (i+count+1)<=len(l):
      k.append(l[i-count])
      k.append(l[i+count])
      count+=1
  for i in k:
    print(i,end=' ')


# -*- coding: utf-8 -*-
"""Untitled

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1U5CJ1kNbI3dS3s64reHKfsnX7WPh3nrs
"""

import math
for _ in range(int(input())):
  n=int(input())
  l=[int(x) for x in input().split()]
  l.sort()
  k=[]
  if len(l)%2==0:
    i=int(len(l)/2)
    k.append(l[i])
    count=1
    while (i-count)>=0 and (i+count+1)<=len(l):
      k.append(l[i-count])
      k.append(l[i+count])
      count+=1
    while (i-count)>=0:
      k.append(l[i-count])
      count+=1
    while (i+count+1)<=len(l):
      k.append(l[i+count])
      count+=1

  else:
    i=math.ceil(int(len(l)/2))
    k.append(l[i])
    while (i-count)>=0 and (i+count+1)<=len(l):
      k.append(l[i-count])
      k.append(l[i+count])
      count+=1
  for i in k:
    print(i,end=' ')


import sys,math
inp = sys.stdin.readline

t = int(inp())
while t:
    t-=1
    n = int(inp())
    tmp=[]
    arr=list(map(int,inp().split()))
    arr= sorted(arr)
    if arr[0]<0:
        if len(arr)%2==0:
            right = len(arr)//2
            left = right-1
            while right<len(arr):
                tmp.append(arr[left])
                tmp.append(arr[right])
                left-=1
                right+=1
        else:
            right = len(arr)//2
            left = right-2
            tmp.append(arr[right-1])
            while right<len(arr):
                tmp.append(arr[left])
                tmp.append(arr[right])
                left-=1
                right+=1
    else:
        tmp=arr
    for i in tmp:
        print(i,end=' ')
    print()
    # print(a)


import sys,math
inp = sys.stdin.readline

t = int(inp())
while t:
    t-=1
    n = int(inp())
    tmp=[]
    arr=list(map(int,inp().split()))
    arr= sorted(arr)
    turn = 0
    if arr[0]<0:
        if len(arr)%2==0:
            right = len(arr)//2
            left = right-1
            while right<len(arr):
                if turn==1:
                    tmp.append(arr[left])
                    tmp.append(arr[right])
                    turn=0
                else:
                    tmp.append(arr[right])
                    tmp.append(arr[left])
                    turn=1
                left-=1
                right+=1
        else:
            right = len(arr)//2
            left = right-2
            tmp.append(arr[right-1])
            while right<len(arr):
                if turn==0:
                    tmp.append(arr[left])
                    tmp.append(arr[right])
                    turn=1
                else:
                    tmp.append(arr[right])
                    tmp.append(arr[left])
                    turn=0
    else:
        tmp=arr
    for i in tmp:
        print(i,end=' ')
    print()
    # print(a)


import sys,math
inp = sys.stdin.readline

t = int(inp())
while t:
    t-=1
    n = int(inp())
    tmp=[]
    arr=list(map(int,inp().split()))
    arr= sorted(arr,reverse=True)

    right = n//2
    left = right-1
    while left >-1 or right<n:
        if right<n:
            print(arr[right],end=' ')
            right+=1
        if left>-1:
            print(arr[left],end=' ')
            left-=1
    print()

    # print(a)


import sys,math
inp = sys.stdin.readline

t = int(inp())
while t:
    t-=1
    n = int(inp())
    tmp=[]
    arr=list(map(int,inp().split()))
    arr= sorted(arr)
    turn = 0
    if arr[0]<0:
        if len(arr)%2==0:
            right = len(arr)//2
            left = right-1
            while right<len(arr):
                if turn==1:
                    tmp.append(arr[left])
                    tmp.append(arr[right])
                    turn=0
                else:
                    tmp.append(arr[right])
                    tmp.append(arr[left])
                    turn=1
                left-=1
                right+=1
        else:
            right = len(arr)//2
            left = right-2
            tmp.append(arr[right-1])
            while right<len(arr):
                if turn==1:
                    tmp.append(arr[left])
                    tmp.append(arr[right])
                    turn=0
                else:
                    tmp.append(arr[right])
                    tmp.append(arr[left])
                    turn=1
    else:
        tmp=arr
    for i in tmp:
        print(i,end=' ')
    print()
    # print(a)


t = int(input())
for i in range(t):
    a = int(input())
    lst = map(int,input().split())
    lst = list(lst)
    b = []
    lst.sort()
    for j in lst:
        if lst.count(j)!=1:
            lst.remove(j)
            lst.remove(j)
            lst.insert(0,j)
            lst.insert(1,j)
    for l in lst:
        if l<0:
            b.append(l)
            lst.remove(l)
    b.sort()
    for k in range(len(b)):
        lst.insert(a-2*k,b[k])
    for y in lst:
        print(str(y)+" ",end="")


t = int(input())
for i in range(t):
    a = int(input())
    lst = map(int,input().split())
    lst = list(lst)
    b = []
    lst.sort()
    for j in lst:
        if lst.count(j)!=1:
            lst.remove(j)
            lst.remove(j)
            lst.insert(0,j)
            lst.insert(1,j)
    for l in lst:
        if l<0:
            b.append(l)
            lst.remove(l)
    b.sort()
    for k in range(len(b)):
        lst.insert(a-2*k,b[k])
    print(lst)


t = int(input())
for i in range(t):
    n = int(input())
    a = map(int,input().split())
    a = list(a)
    a.sort()
    while n!= 0:
        print(a.pop(n//2), end = ' ')
        n -= 1


test = int(input())
for i in range(0, test):
  num = input()
  list = input().strip().split()
  result = []
  list.sort()
  a = 0
  b = len(list) - 1
  while 0 <= b - a:
	  result.append(list[b])
	  if a != b:
	  	result.append(list[a])
	  b = b - 1
	  a = a + 1
  print(*reversed(result), sep=' ')


test = int(input())

for i in range(0, test):
  num = input()
  list = input().split()
  result = []
  list.sort()

  while list:
    if(list):
      a = list.pop(0)
      result.insert(0,a)
    if(list):
      b = list.pop(len(list) - 1)
      result.insert(0,b)
  print(*result, sep=' ')


test = int(input())
for i in range(0, test):
  num = input()
  list = input().split()
  result = []
  list.sort()
  a = 0
  b = len(list) - 1
  while 0 >= a - b:
	  result.append(list[b])
	  if a != b:
	  	result.append(list[a])
	  b = b - 1
	  a = a + 1
  print(*reversed(result), sep=' ')


test = int(input())

for i in range(0, test):
  num = input()
  list = input().split()
  result = []
  list.sort()

  while list:
    if(len(list) > 1):
      a = list.pop(0)
      result.insert(0,a)
      b = list.pop(len(list) - 1)
      result.insert(0,b)
    else:
      a = list.pop(0)
      result.insert(0,a)
  print(*result, sep=' ')


test = int(input())
for i in range(0, test):
	num = input()
	list = [int(j) for j in input().split()]
	result = []
	list.sort()
	a = 0
	b = len(list) - 1
	while 0 <= b - a:
		result.append(list[b])
		if a != b:
			result.append(list[a])
		b = b - 1
		a = a + 1
	print(*reversed(result), sep=' ')


test = int(input())
for i in range(0, test):
  num = input()
  list = input().split()
  result = []
  list.sort()
  a = 0
  b = len(list) - 1
  while 0 > a - b:
	  result.append(list[b])
	  if a != b:
	  	result.append(list[a])
	  b = b - 1
	  a = a + 1
  print(*reversed(result), sep=' ')


test = int(input())

for i in range(0, test):
  num = input()
  list = input().split()
  result = []
  list.sort()

  while list:
    if(len(list) < 2):
      a = list.pop(0)
      result.insert(0,a)
      b = list.pop(len(list) - 1)
      result.insert(0,b)
    else:
      a = list.pop(0)
      result.insert(0,a)
  print(*result, sep=' ')


t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split())
    l.sort()
    for j in range(len(l)//2):
        print(l[j],end=' ')
        print(l[n-j-1],end=' ')


t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    a=[]
    l=0
    r=n-1
    f=True
    while(l<=r):
        if(f):
            a.append(l[l])
            l+=1
        else:
            a.append(l[r])
            r-=1
        f=!f
    a=a[::-1]
    for j in range(len(a)):
        print(a[j],end=' ')
    print()


t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    a=[]
    ll=0
    r=n-1
    f=True
    while(ll<=r):
        if(f):
            a.append(l[ll])
            ll+=1
        else:
            a.append(l[r])
            r-=1
        if(f==False):
            f=True
        else:
            f=False
    a=a[::-1]
    for j in range(len(a)):
        print(a[j],end=' ')
    print()


t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    a=[]

    for j in range(len(l)//2):
        a.append(l[j])
        a.append(l[n-j-1])
    a=a[::-1]
    for j in range(len(a)):
        print(a[j],end=' ')
    print()


t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    a=[]

    for j in range(len(l)//2):
        a.append(l[j])
        a.append(l[n-j-1])
    a=a[::-1]
    for j in range(len(a)):
        print(a[j],end=' ')
    if(i!=t-1):
        print()


t=int(input())
for j in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    l1=l[:int(n/2)]
    l2=l[int(n/2)+1:]

    if (n%2 == 1):
        print(l[int(n / 2)],end=" ")
    for i in range(int(n/2)):
        print(l1[int(n/2)-i-1],l2[i],end=" ")
    print()


t=int(input())
for j in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    l1=l[:int(n/2)]
    l2=l[int(n/2)+1:]
    print(l1)
    print(l2)

    if (n%2 == 1):
        print(l[int(n / 2)],end=" ")
    for i in range(int(n/2)):
        print(l1[int(n/2)-i-1],l2[i],end=" ")


t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    for a in l:
        print(a,end=" ")


t=int(input())
for j in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()

    if (n%2 == 1):
        l1 = l[:int(n / 2)]
        l2 = l[int(n / 2) + 1:]
        print(l[int(n / 2)],end=" ")
    else:
        l1 = l[:int(n / 2)]
        l2 = l[int(n / 2):]

    for i in range(int(n/2)):
        print(l1[int(n/2)-i-1],l2[i],end=" ")
    print()


for _ in range(int(input())):
    n=int(input())
    a=[int(x) for x in input().split()]
    d=[]
    for i in range(len(a)-1,-1,-1):
        diff=abs(a[i]-a[i-1])
        d.append([diff,[a[i],a[i-1]]])

    d=sorted(d,key =lambda x:x[0])
    # print(d)

    ans=[]
    ans.append(d[0][1][0])
    ans.append(d[0][1][1])
    # print(d[1][1][1],"jj")
    for i in range(1,len(d)-1):
        if d[i][1][0]==d[i-1][1][1]:
            ans.append(d[i][1][1])
        else:
            ans.append(d[i][1][0])

    for i in ans:
        print(i,end=" ")
    print()


test = int(input())
for t in range(test):
    N = int(input())
    list = [int(x) for x in input().split()]
    list.sort()
    n = len(list)
    while n:
        print(list.pop(n//2), end = ' ')
        n -= 1


for _ in range(int(input())):
    n=int(input())
    a=[int(x) for x in input().split()]
    d=[]
    for i in range(len(a)-1):
        diff=abs(a[i]-a[i+1])
        d.append([diff,[a[i],a[i-1]]])

    d=sorted(d,key =lambda x:x[0])
    # print(d)

    ans=[]
    ans.append(d[0][1][0])
    ans.append(d[0][1][1])
    # print(d[1][1][1],"jj")
    for i in range(1,len(d)):
        # if d[i][1][0]==d[i-1][1][1]:
        ans.append(d[i][1][1])

    ans=[ans[-1]]+ans[0:len(ans)-1]
    for i in ans:
        print(i,end=" ")
    print()


for t in range(int(input())):
    N = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    n = len(a)
    while n:
        print(a.pop(n//2), end = ' ')
        n -= 1


for _ in range(int(input())):
    n=int(input())
    a=[int(x) for x in input().split()]
    d=[]
    for i in range(1,len(a)):
        diff=abs(a[i]-a[i-1])
        d.append([diff,[a[i],a[i-1]]])

    d=sorted(d,key =lambda x:x[0])
    # print(d)

    ans=[]
    ans.append(d[0][1][0])
    ans.append(d[0][1][1])
    for i in range(1,len(d)):
        ans.append(d[i][1][1])

    for i in ans:
        print(i,end=" ")
    print()


t = int(input())

for i in range(t):
    n = int(input())
    lst = sorted(list(map(int, input().split())))
    ev = []
    a = n // 2
    if n % 2 == 0:
        for j in range(a):
            ev.append(lst[j+a])
            ev.append(lst[a-j-1])
    else:
        ev.append(lst[a])
        for j in range(a):
            ev.append(lst[j + a + 1])
            ev.append(lst[a - j - 1])
    print(*ev)


t = int(input())

for i in range(t):
    n = int(input())
    lst = list(map(int, input().split()))
    if n % 2 == 0:
        ev = []
        for j in range(n//2):
            ev.append(min(lst))
            lst.remove(min(lst))
            ev.append(max(lst))
            lst.remove(max(lst))
        a = reversed(ev)
        print(*a)
    else:
        ev = []
        for j in range((n-1) // 2):
            ev.append(min(lst))
            lst.remove(min(lst))
            ev.append(max(lst))
            lst.remove(max(lst))
        ev.append(lst[0])
        a = reversed(ev)
        print(*a)


t = int(input())

for i in range(t):
    n = int(input())
    lst = list(map(int, input().split()))
    ev = []
    while len(lst) > 1:
        ev.append(min(lst))
        lst.remove(min(lst))
        ev.append(max(lst))
        lst.remove(max(lst))
    if len(lst) == 0:
        a = reversed(ev)
        print(*a)
    else:
        ev.append(lst[0])
        a = reversed(ev)
        print(*a)


t = int(input())

for i in range(t):
    n = int(input())
    lst = sorted(list(map(int, input().split())))
    ev = []
    a = n//2
    for j in range(a):
        ev.append(lst[j+a])
        ev.append(lst[a-j-1])
    print(*ev)


t = int(input())
td = t
temp_output_case = []

while t>0:
    input_case = []
    a = int(input())
    str_in = input()
    input_case = list(map(int, str_in.strip().split()))
    temp_case = sorted(input_case)

    new_case = []

    a1_number =(a//2)
    a1 = temp_case[a1_number]
    new_case.append(a1)

    tt = 1
    if a%2 ==1:
        while a1_number-tt >=0:
            p = int(a1_number-tt)
            q = temp_case[p]
            new_case.append(q)

            c = int(a1_number+tt)
            d = temp_case[c]
            new_case.append(d)

            tt += 1
    else:
        while a1_number-tt >0:
            p = int(a1_number-tt)
            q = temp_case[p]
            new_case.append(q)

            c = int(a1_number+tt)
            d = temp_case[c]
            new_case.append(d)

            tt += 1
        e = temp_case[0]
        new_case.append(e)
    temp_output_case.append(new_case)
    t -= 1

aaa = 0
while aaa<td:
    print(temp_output_case[aaa])
    aaa +=1


t = int(input())
td = t
temp_output_case = []

while t>0:
    input_case = []
    a = int(input())
    str_in = input()
    input_case = list(map(int, str_in.strip().split()))
    temp_case = sorted(input_case)

    new_case = []

    a1_number =(a//2)
    a1 = temp_case[a1_number]
    new_case.append(a1)

    tt = 1
    if a%2 ==1:
        while a1_number-tt >=0:
            p = int(a1_number-tt)
            q = temp_case[p]
            new_case.append(q)

            c = int(a1_number+tt)
            d = temp_case[c]
            new_case.append(d)

            tt += 1
    else:
        while a1_number-tt >0:
            p = int(a1_number-tt)
            q = temp_case[p]
            new_case.append(q)

            c = int(a1_number+tt)
            d = temp_case[c]
            new_case.append(d)

            tt += 1
        e = temp_case[0]
        new_case.append(e)
    for case in new_case:
        print(case, end= " ")
    print("\t")

    t -= 1


t = int(input())
temep_case_set = []

while t>0:
    input_case = []
    a = int(input())
    str_in = input()
    input_case = list(map(int, str_in.strip().split()))
    temp_case = sorted(input_case)

    new_case = []

    a1_number =(a//2)
    a1 = temp_case[a1_number]
    new_case.append(a1)

    tt = 1
    if a%2 ==1:
        while a1_number-tt >=0:
            p = int(a1_number-tt)
            q = temp_case[p]
            new_case.append(q)

            c = int(a1_number+tt)
            d = temp_case[c]
            new_case.append(d)

            tt += 1
    else:
        while a1_number-tt >0:
            p = int(a1_number-tt)
            q = temp_case[p]
            new_case.append(q)

            c = int(a1_number+tt)
            d = temp_case[c]
            new_case.append(d)

            tt += 1
        e = temp_case[0]
        new_case.append(e)
    print(new_case)
    t -= 1


n = int(input())
for i in range(n):
	xs = map(int, input().split())
	k = xs[0]
	ys = xs[1:]
	ys = sorted(ys)
	sign = 1
	res = []
	for i in range(k):
		res.append(ys[i*sign])
		sign *= -1


n = int(input())
for i in range(n):
	k = int(input())
	xs = map(int, input().split())
	xs = sorted(xs)
	sign = 1
	res = []
	for i in range(k):
		res.append(xs[int((i+1)/2)*sign])
		sign *= -1
	print(' '.join(map(str, res)))


n = int(input())
for i in range(n):
	k = int(input())
	xs = map(int, input().split())
	xs = sorted(xs)
	sign = 1
	res = []
	for i in range(k):
		res.append(xs[i*sign])
		sign *= -1
	print(' '.join(map(str, res)))


n = int(input())
for i in range(n):
	k = int(input())
	xs = map(int, input().split())
	xs = sorted(xs)
	sign = 1
	res = []
	for i in range(k):
		res.append(xs[i*sign])
		sign *= -1


# data = iter(map(lambda x: x.strip(), open('A.txt').readlines()))
# n = int(data.next())
# for i in range(n):
# 	k = int(data.next())
# 	xs = map(int, data.next().split())
# 	xs = sorted(xs)
# 	sign = 1
# 	res = []
# 	for i in range(k):
# 		res.append(xs[int((i+1)/2)*sign])
# 		sign *= -1
# 	print(' '.join(map(str, reversed(res))))

n = int(input())
for i in range(n):
	k = int(input())
	xs = map(int, input().split())
	xs = sorted(xs)
	sign = 1
	res = []
	for i in range(k):
		res.append(xs[int((i+1)/2)*sign])
		sign *= -1
	print(' '.join(map(str, reversed(res))))


n = int(input())
for i in range(n):
	k = int(input())
	xs = map(int, input().split())
	xs = sorted(xs)
	sign = 1
	res = []
	for i in range(k):
		res.append(xs[i*sign])
		sign *= -1
	print(' '.join(res))


for i in range(int(input())):
    k=int(input())
    a=list(map(int,input().split()))
    a.sort()
    i=0
    j=len(a)-1
    b=[]
    while(i<j):
        if(i!=j):
            b.append(a[i])
            b.append(a[j])
        else:
            b.append(a[i])
        i+=1
        j-=1
    b=b[::-1]
    b=' '.join(str(i) for i in b)
    print(b)


for i in range(int(input())):
    k=int(input())
    a=list(map(int,input().split()))
    a.sort()
    i=0
    j=len(a)-1
    b=[]
    while(i<j):
            b.append(a[i])
            b.append(a[j])
            i+=1
            j-=1
    if(i==j):
        b.append(a[i])
    b=b[::-1]
    b=' '.join(str(i) for i in b)
    print(b)


for i in range(int(input())):
    k=int(input())
    a=list(map(int,input().split()))
    a.sort()
    i=0
    j=len(a)-1
    b=[]
    while(i<j):
        if(i!=j):
            b.append(a[j])
            b.append(a[i])
        else:
            b.append(i)
        i+=1
        j-=1
    b=b[::-1]
    print(b)


for i in range(int(input())):
    k=int(input())
    a=list(map(int,input().split()))
    a.sort()
    i=0
    j=len(a)-1
    b=[]
    while(i<j):
        if(i!=j):
            b.append(a[i])
            b.append(a[j])
        else:
            b.append(i)
        i+=1
        j-=1
    b=b[::-1]
    b=' '.join(str(i) for i in b)
    print(b)


for i in range(int(input())):
    k=int(input())
    a=list(map(int,input().split()))
    a.sort()
    i=1
    b=[a[0],a[len(a)-1]]
    while(len(a)-2!=0):
        b.append(a[len(a)-i-1])
        b.append(a[i])
        a.pop(i)
        a.pop(len(a)-i)
    b=b[::-1]
    b=' '.join(str(i) for i in b)
    print(b)


I=input
exec(int(I())*'I();a=sorted(map(int,I().split()));print(*(a[(-i,i)[i%2]//2]for i in range(len(a),0,-1)));')


I=input
for _ in[0]*int(I()):I();a=sorted(map(int,I().split()));print(*(a[(i-2,-i)[i%2]//2]for
i in range(len(a),0,-1)))


I=input
for _ in[0]*int(I()):
 I();a=sorted(map(int,I().split()))
 while a:print(a.pop(len(a)//2))


I=input
for _ in[0]*int(I()):I();a=sorted(map(int,I().split()));print(*(a[(-i,i)[i%2]//2]for
i in range(len(a),0,-1)))


t = int(input())

for i in range(t):
    n = int(input())
    arr = list(map(int,input().split())
    time = 1
    while True:
        curr_max = -10**10
        indices_to_modify = []
        for i in range(len(arr)):
            if arr[i] < curr_max:
                indices_to_modify.append(i)
            curr_max = max(curr_max, arr[i])
        if len(indices_to_modify)==0:
            break
        for ind in indices_to_modify:
            arr[ind] += 2**(time-1)
        time += 1
    print(time)


t = int(input())

for i in range(t):
    l = int(input())
    arr = sorted(list(map(int, input().split())))
    new_arr = arr.copy()
    where = -1
    for i in range(l):
        if where == -1:
            new_arr[-1 - i] = arr[int(l - 1 - i / 2)]
            where = 0
        else:
            new_arr[-1 - i] = arr[int((i - 1) / 2)]
            where = -1
    print(new_arr)


t = int(input())

for i in range(t):
    l = int(input())
    arr = sorted(list(map(int,input().split())))
    new_arr = arr.copy()
    where = -1
    for i in range(l):
        if where == -1:
            new_arr[-1-i]=arr[l-1-i/2]
            where = 0
        else:
            new_arr[-1-i]=arr[(i-1)/2]
    print(new_arr)


t = int(input())

for i in range(t):
    l = int(input())
    arr = sorted(list(map(int, input().split())))
    new_arr = arr.copy()
    where = -1
    for i in range(l):
        if where == -1:
            new_arr[-1 - i] = arr[int(l - 1 - i / 2)]
            where = 0
        else:
            new_arr[-1 - i] = arr[int((i - 1) / 2)]
            where = -1
    print(" ".join([str(el) for el in new_arr]))


numcases = int(input())

def solve():
    newlist = []
    a.sort()
    for i in range(alength):
        if i > alength - i:
            return newlist
        if i == alength - i:
            newlist.append(a[i])
            return newlist
        newlist.append(a[i])
        newlist.append(a[alength - 1 - i])

for n in range(numcases):
    alength = int(input())
    a = list(map(int, input().split(' ')))
    newlist = solve()
    print(*newlist[::-1])


numcases = int(input())

def solve():
    newlist = []
    a.sort()
    for i in range(alength):
        if i > alength - i - 1:
            return newlist
        if i == alength - i - 1:
            newlist.append(a[i])
            return newlist
        newlist.append(a[i])
        newlist.append(a[alength - 1 - i])

for n in range(numcases):
    alength = int(input())
    a = list(map(int, input().split(' ')))
    newlist = solve()
    print(*newlist[::-1])


numcases = int(input())

def solve():
    coord = 0
    smallestdiff = 100000000003
    for i in range(alength):
        for j in range(0, alength):
            if i == j:
                continue
            if abs(a[i] - a[j]) < smallestdiff:
                smallestdiff = abs(a[i] - a[j])
                coord = i
    newlist.append(a[coord])
    a.pop(coord)
    for i in range(alength - 1):
        next_number(newlist[i])
    print(*newlist, sep=' ')

def next_number(prev):
    smallestdiff = 10000000000003
    for i in range(len(a)):
        if abs(prev - a[i]) < smallestdiff:
            smallestdiff = abs(prev - a[i])
            coord = i
    newlist.append(a[coord])
    a.pop(coord)

for n in range(numcases):
    alength = int(input())
    a = list(map(int, input().split(' ')))
    newlist = []
    solve()


def solve():
    newlist = []
    a.sort()
    for i in range(alength):
        if i > alength - i - 1:
            return newlist
        if i == alength - i - 1:
            newlist.append(a[i])
            return newlist
        newlist.append(a[i])
        newlist.append(a[alength - 1 - i])

for n in range(numcases):
    alength = int(input())
    a = list(map(int, input().split(' ')))
    newlist = solve()
    print(*newlist[::-1])


numcases = int(input())

def solve():
    coord = 0
    smallestdiff = 10003
    for i in range(alength):
        for j in range(0, alength):
            if i == j:
                continue
            if abs(a[i] - a[j]) < smallestdiff:
                smallestdiff = abs(a[i] - a[j])
                coord = i
    newlist.append(a[coord])
    a.pop(coord)
    for i in range(alength - 1):
        next_number(newlist[i])
    print(*newlist, sep=' ')

def next_number(prev):
    smallestdiff = 10003
    for i in range(len(a)):
        if abs(prev - a[i]) < smallestdiff:
            smallestdiff = abs(prev - a[i])
            coord = i
    newlist.append(a[coord])
    a.pop(coord)

for n in range(numcases):
    alength = int(input())
    a = list(map(int, input().split(' ')))
    newlist = []
    solve()


testCases= int(input())

for _ in range(testCases):
    n = int(input())
    a = list(map(int,input().split()))

    a.sort()
    while a:print(a.pop(len(a)// 2),end=" ")


testCases= int(input())

for _ in range(testCases):
    n = int(input())
    a = list(map(int,input().split()))

    a.sort()
    while a:
	    half= len(a)// 2
	    print(a.pop(half),end=" ")


testCases= int(input())

for _ in range(testCases):
    n = int(input())
    a = list(map(int,input().split()))

    a.sort()
    while a:
	    print(a.pop(len(a)// 2),end=" ")


n=int(input())
i=0
ans=[]
for i in range(0,n):
    d=int(input())
    data=[]
    dd = input()
    ddd=dd.split()
    for k in range(0,d):
        data.append(int(ddd[k]))
    data.sort()
    data2=[]
    s=""
    if d % 2 == 0:
        mid=(len(data))//2
        data2.append(data[mid])
        for k in range(1,(len(data))//2):
            data2.append(data[mid-k])
            data2.append(data[mid+k])
        data2.append(data[0])
    else:
        mid = (len(data)-1) // 2
        data2.append(data[mid])
        for k in range(1, (len(data)) // 2):
            data2.append(data[mid + k])
            data2.append(data[mid - k])
    for s1 in data2:
        s+=str(s1)+" "
    ans.append(s)
for i in range(0,n):
    print(ans[i])


n=int(input())
i=0
ans=[]
for i in range(0,n):
    d=int(input())
    data=[]
    dd = input()
    ddd=dd.split()
    for k in range(0,d):
        data.append(int(ddd[k]))
    data.sort()
    data2=[]
    s=""
    if d % 2 == 0:
        mid=(len(data))//2
        data2.append(data[mid])
        for k in range(1,(len(data))//2):
            data2.append(data[mid-k])
            data2.append(data[mid+k])
        data2.append(data[0])
    else:
        mid = (len(data)-1) // 2
        data2.append(data[mid])
        if data2[0]-data[mid-1]>-data2[0]+data[mid+1]:
            for k in range(1, (len(data)) // 2):
                data2.append(data[mid + k])
                data2.append(data[mid - k])
        else:
            for k in range(1, (len(data)) // 2):
                data2.append(data[mid - k])
                data2.append(data[mid + k])
    for s1 in data2:
        s+=str(s1)+" "
    ans.append(s)
for i in range(0,n):
    print(ans[i])


n=int(input())
i=0
ans=[]
for i in range(0,n):
    d=int(input())
    data=[]
    dd = input()
    ddd=dd.split()
    for k in range(0,d):
        data.append(int(ddd[k]))
    data.sort()
    data2=[]
    s=""
    if d % 2 == 0:
        mid=(len(data))//2
        data2.append(data[mid])
        for k in range(1,(len(data))//2):
            data2.append(data[mid+k])
            data2.append(data[mid-k])
        data2.append(data[0])
    else:
        mid = (len(data)-1) // 2
        data2.append(data[mid])
        for k in range(1, (len(data)) // 2):
            data2.append(data[mid + k])
            data2.append(data[mid - k])
    for s1 in data2:
        s+=str(s1)+" "
    ans.append(s)
for i in range(0,n):
    print(ans[i])


n=int(input())
i=0
ans=[]
for i in range(0,n):
    d=int(input())
    data=[]
    dd = input()
    ddd=dd.split()
    for k in range(0,d):
        data.append(int(ddd[k]))
    data.sort()
    data2=[]
    s=""
    if d % 2 == 0:
        mid=(len(data))//2
        data2.append(data[mid])
        for k in range(1,(len(data))//2):
            data2.append(data[mid-k])
            data2.append(data[mid+k])
        data2.append(data[0])
    else:
        mid = (len(data)-1) // 2
        data2.append(data[mid])
        for k in range(1, (len(data)) // 2):
            data2.append(data[mid + k])
            data2.append(data[mid - k])
        data2.append(data[-1])
        data2.append(data[0])
    for s1 in data2:
        s+=str(s1)+" "
    ans.append(s)
for i in range(0,n):
    print(ans[i])


t=int(input())
a=[]
b=[]
x=''
for i in range(t):
    b.clear()
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    for j in range(n):
        l=len(a)//2-1
##        x+=str(a[l+(j//2+j%2)*(-1)**(j+1)])
        b.append(a[l+(j//2+j%2)*(-1)**(j+1)])
##    print(b)
    for p in b:
        print(p,end=' ')
    print()


t=int(input())
a=[]
b=[]
for i in range(t):
    b.clear()
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
##    print(a)
    for j in range(n):
        l=len(a)//2-1
##        print('L=',l,'ind=',l+(j//2+j%2)*(-1)**(j+1))
        b.append(a[l+(j//2+j%2)*(-1)**(j+1)])
    print(b)


t=int(input())
a=[]
b=[]
x=''
for i in range(t):
    b.clear()
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    for j in range(n):
        l=len(a)//2-1
##        x+=str(a[l+(j//2+j%2)*(-1)**(j+1)])
        b.append(a[l+(j//2+j%2)*(-1)**(j+1)])
    for i in a:
        print(i,end=' ')
    print()


t=int(input())
a=[]
b=[]
x=''
for i in range(t):
    b.clear()
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    for j in range(n):
        l=(len(a)//2-1)+len(a)%2
##        x+=str(a[l+(j//2+j%2)*(-1)**(j+1)])
        b.append(a[l+(j//2+j%2)*(-1)**(j+1)])
##    print(b)
    for p in b:
        print(p,end=' ')
    print()


t=int(input())
a=[]
b=[]
x=''
for i in range(t):
    b.clear()
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    for j in range(n):
        l=len(a)//2-1
##        x+=str(a[l+(j//2+j%2)*(-1)**(j+1)])
        b.append(a[l+(j//2+j%2)*(-1)**(j+1)])
    print(b)
    for p in b:
        print(p,end=' ')
    print()


t=int(input())
for _ in range(t):
    n=int(input())
    arr= list(map(int,input().split()))
    ans=[]
    arr.sort()
    if (n%2==0):
        ans.append(arr[int(n/2)-1])
        ans.append(arr[int(n/2)])
        for i in range(1,int(n/2)):
            ans.append(arr[int(n/2)-i-1])
            ans.append(arr[int(n/2)+i])
    else:
        ans.append(arr[int(n/2)])
        for i in range(1,int(n/2)+1):
            ans.append(arr[int(n/2)-i])
            ans.append(arr[int(n/2)+i])

    print(*ans,sep=" ")

# t=int(input())
# for _ in range(t):
#     n=int(input())
#     arr=list(map(int,input().split()))
#     c=0
#     s=[0]*(n-1)
#     arr.sort()
#     ans=[]
#     for i in range(1,n):
#         s[i-1]=abs(arr[i]-arr[i-1])
#     # print(s)
#     ans.append(arr[s.index(min(s))])
#     ans.append(arr[(s.index(min(s)))+1])
#     print(arr)
#     arr.pop(arr.index(ans[0]))
#     arr.pop(arr.index(ans[1]))
#     print(arr)
#     i=n-len(ans)
#     while i>0:
#         mi=float("inf")
#         for j in arr:
#             if abs(ans[len(ans)-1]-j)<=mi:
#                 e=j
#                 mi =  abs(ans[len(ans)-1]-j)
#         ans.append(e)
#         arr.pop(arr.index(e))
#         i-=1
#     print(*ans,sep=" ")

# # t=int(input())
# # for _ in range(t):
# #     n=int(input())
# #     arr=list(map(int,input().split()))
# #     c=0
# #     s=[]
# #     for i in range(n):
# #         e1=-1
# #         e2=-1
# #         i-=c
# #         mi=float("inf")
# #         for j in range(i+1,len(arr)):
# #             print(i,j)
# #             if i==j:
# #                 continue
# #             else:
# #                 # print(arr[i]-arr[j],mi)
# #                 if abs(arr[i]-arr[j])<=mi:
# #                     mi=abs(arr[i]-arr[j])
# #                     e1=arr[i]
# #                     e2=arr[j]
# #                 # print('mi',mi)
# #         print(arr,e1,e2,s,mi)
# #         arr.pop(arr.index(e1))
# #         arr.pop(arr.index(e2))
# #         c+=2
# #         s.append(e1)
# #         s.append(e2)
# #     print(s)


t=int(input())
for _ in range(t):
    n=int(input())
    arr= list(map(int,input().split()))
    ans=[]
    arr.sort()
    if (n%2==0):
        ans.append(arr[int(n/2)-1])
        ans.append(arr[int(n/2)])
        for i in range(1,int(n/2)):
            ans.append(arr[int(n/2)-i-1])
            ans.append(arr[int(n/2)+i])
    else:
        ans.append(arr[int(n/2)])
        for i in range(1,int(n/2)+1):
            ans.append(arr[int(n/2)-i])
            ans.append(arr[int(n/2)+i])

    print(ans)

# t=int(input())
# for _ in range(t):
#     n=int(input())
#     arr=list(map(int,input().split()))
#     c=0
#     s=[0]*(n-1)
#     arr.sort()
#     ans=[]
#     for i in range(1,n):
#         s[i-1]=abs(arr[i]-arr[i-1])
#     # print(s)
#     ans.append(arr[s.index(min(s))])
#     ans.append(arr[(s.index(min(s)))+1])
#     print(arr)
#     arr.pop(arr.index(ans[0]))
#     arr.pop(arr.index(ans[1]))
#     print(arr)
#     i=n-len(ans)
#     while i>0:
#         mi=float("inf")
#         for j in arr:
#             if abs(ans[len(ans)-1]-j)<=mi:
#                 e=j
#                 mi =  abs(ans[len(ans)-1]-j)
#         ans.append(e)
#         arr.pop(arr.index(e))
#         i-=1
#     print(*ans,sep=" ")

# # t=int(input())
# # for _ in range(t):
# #     n=int(input())
# #     arr=list(map(int,input().split()))
# #     c=0
# #     s=[]
# #     for i in range(n):
# #         e1=-1
# #         e2=-1
# #         i-=c
# #         mi=float("inf")
# #         for j in range(i+1,len(arr)):
# #             print(i,j)
# #             if i==j:
# #                 continue
# #             else:
# #                 # print(arr[i]-arr[j],mi)
# #                 if abs(arr[i]-arr[j])<=mi:
# #                     mi=abs(arr[i]-arr[j])
# #                     e1=arr[i]
# #                     e2=arr[j]
# #                 # print('mi',mi)
# #         print(arr,e1,e2,s,mi)
# #         arr.pop(arr.index(e1))
# #         arr.pop(arr.index(e2))
# #         c+=2
# #         s.append(e1)
# #         s.append(e2)
# #     print(s)


t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    c=0
    s=[0]*(n-1)
    arr.sort()
    ans=[]
    for i in range(1,n):
        s[i-1]=abs(arr[i]-arr[i-1])
    # print(s)
    ans.append(arr[s.index(min(s))])
    ans.append(arr[(s.index(min(s)))+1])
    print(arr)
    arr.pop(arr.index(ans[0]))
    arr.pop(arr.index(ans[1]))
    print(arr)
    i=n-len(ans)
    while i>0:
        mi=float("inf")
        for j in arr:
            if abs(ans[len(ans)-1]-j)<=mi:
                e=j
                mi =  abs(ans[len(ans)-1]-j)
        ans.append(e)
        arr.pop(arr.index(e))
        i-=1
    print(*ans,sep=" ")

# t=int(input())
# for _ in range(t):
#     n=int(input())
#     arr=list(map(int,input().split()))
#     c=0
#     s=[]
#     for i in range(n):
#         e1=-1
#         e2=-1
#         i-=c
#         mi=float("inf")
#         for j in range(i+1,len(arr)):
#             print(i,j)
#             if i==j:
#                 continue
#             else:
#                 # print(arr[i]-arr[j],mi)
#                 if abs(arr[i]-arr[j])<=mi:
#                     mi=abs(arr[i]-arr[j])
#                     e1=arr[i]
#                     e2=arr[j]
#                 # print('mi',mi)
#         print(arr,e1,e2,s,mi)
#         arr.pop(arr.index(e1))
#         arr.pop(arr.index(e2))
#         c+=2
#         s.append(e1)
#         s.append(e2)
#     print(s)


# HEY STALKER
for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    p = []
    i = 0
    j = n - 1
    while i < j:
        p.append(l[j])
        p.append(l[i])
        i += 1
        j -= 1
    print(*p)


# HEY STALKER
for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    p = []
    i = 0
    j = n - 1
    while i < j:
        p.append(l[j])
        p.append(l[i])
        i += 1
        j -= 1
    if n % 2:
        p.append(l[j])
    p.reverse()
    print(*p)


# HEY STALKER
for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    p = []
    i = 0
    j = n - 1
    while i < j:
        p.append(l[j])
        p.append(l[i])
        i += 1
        j -= 1
    print(*p[::-1])


t = int(input())
result = []

while t:
    n = int(input())
    array = list(map(int, input().split()))

    new_array = []
    check = {}

    for i in range(len(array) - 1):
        values = abs(array[i+1] - array[i])
        check[i] = values
        g = [x[0] for x in sorted(check.items(), key = lambda x: x[1], reverse=False)]

        resq = []
        k = 0

        for res in g:
            if not k:
                resq.append(array[res+1])
                resq.append(array[res])
                k += 1
            else:
                resq.append(array[res])

    result.append(resq)
    t -= 1

for mas in result:
    print(str(mas).strip('[]'))
#     print(' '.join(mas))


t = int(input())
result = []

while t:
    n = int(input())
    array = list(map(int, input().split()))

    check = {}

    for i in range(len(array) - 1):
        values = abs(array[i+1] - array[i])
        check[i] = values
        g = [x[0] for x in sorted(check.items(), key = lambda x: x[1], reverse=False)]

        resq = []
        k = 0

        for res in g:
            resq.append(array[res])

        index = [x for x in list(range(len(array))) if x not in g][0]
        value = array[index]

    if abs(resq[0] - value) <= abs(resq[-1] - resq[-2]):
        resq.insert(0, value)
    else:
        resq.append(value)

    result.append(resq)
    t -= 1

for mas in result:
    print(str(mas).replace('[', '').replace(']', '').replace(',', ''))
#     print(' '.join(mas))


t = int(input())
result_total = []

while t:
    n = int(input())
    array1 = list(map(int, input().split()))
    array = sorted(array1)

    length = len(array)

    if not length % 2:
        result = []

        start_point = int(length / 2 - 1)
        end_point = int(length / 2)

        result.append(array[start_point])
        for k in range(end_point + 1):
            if k and k != end_point:
                result.append(array[start_point + k])
                result.append(array[start_point - k])
            elif k == end_point:
                result.append(array[start_point + k])

    else:
        result = []

        start_point = int(length // 2)

        result.append(array[start_point])
        for k in range(start_point + 1):
            if k:
                result.append(array[start_point + k])
                result.append(array[start_point - k])

    result_total.append(result)
    t -= 1

for mas in result_total:
    print(str(mas).replace('[', '').replace(']', '').replace(',', ''))


t = int(input())
result = []

while t:
    n = int(input())
    array = list(map(int, input().split()))

    new_array = []
    check = {}

    for i in range(len(array) - 1):
        values = abs(array[i+1] - array[i])
        check[i] = values
        g = [x[0] for x in sorted(check.items(), key = lambda x: x[1], reverse=False)]

        resq = []
        k = 0

        for res in g:
            if not k:
                resq.append(array[res+1])
                resq.append(array[res])
                k += 1
            else:
                resq.append(array[res])

    result.append(resq)
    t -= 1

for mas in result:
    print(str(mas).replace('[', '').replace(']', '').replace(',', ''))
#     print(' '.join(mas))


t = int(input())

for _ in range(t):
	n = int(input())
	array = list(map(int,input().split()))

	array.sort()
	'''
	out = []
	while len(array) > 2:
		out += [array[0],array[-1]]
		array = array[1:-1]

	out += array
	print(*out[::-1])
	'''
	out = [str(array[i]) + ' ' + str(array[len(array)-1-i]) for i in range(len(array)//2)]
	out = out[::-1]
	print(*out)


def revision(array):
	output = []
	for i in range(len(array)-1):
		dif = abs(array[i]-array[i+1])
		output.append(dif)
	return output

def is_sorted(array):
	for i in range(len(array)-1):
		if array[i]>array[i+1]:
			return False
	return True

def function(array,output):
	difs = revision(array)

	if len(difs) == 0:
		output.append(array[len(array)-1])
		return output

	e = min(difs)
	index = difs.index(e)

	output.insert(len(output),array[index])
	del array[index],difs[index]

	function(array,output)

t = int(input())

for _ in range(t):
	out = []
	n = int(input())
	lista = list(map(int,input().split()))
	lista.sort()
	function(lista,out)
	print(*out)


def function(array,output):
	difs = [abs(array[i]-array[i+1]) for i in range(len(array)-1)]

	if len(difs) == 0:
		output.append(array[len(array)-1])
		print(*output)
		return

	output.append(array[difs.index(min(difs))])
	del array[difs.index(min(difs))]
	function(array,output)

t = int(input())

for _ in range(t):
	n = int(input())
	lista = list(map(int,input().split()))
	lista.sort()
	function(lista,[])