#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <iostream>
#include <ctime>
#include <bitset>
#define gc getchar()
#define ll long long
#define il inline
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repn(i, b, a) for (int i = b; i >= a; --i)
#define ite iterator
#define eps 1e-8

using namespace std;

const int N = 5005, mod = 998244353;

template<class o> il void qr(o &x) {
    x = 0; char c = gc; int f = 1;
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = gc;}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = gc;}
    x *= f;
}

template<class o> void qw(o x) {
    if(x / 10) qw(x / 10); putchar(x % 10 + 48);
}

template<class o> void pr1(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); putchar(' ');
}

template<class o> void pr2(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); puts("");
}

il int ksm(int a, int b = mod - 2) {
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1) ans = 1ll * ans * a % mod;
    return ans;
}

il int add(int a, int b) {return a += b, a >= mod ? a - mod : a;}
il int sub(int a, int b) {return a -= b, a < 0 ? a + mod : a;}

/* code */

vector<int> e[N];
int match[N], p[N], c[N], q[N], ans[N];
bool vis[N], v[N];

bool dfs(int x) {
	for (int y : e[x]) if (!v[y]) {
		v[y] = 1;
		if (match[y] == -1 || dfs(match[y])) {match[y] = x; return 1;}
	} return 0;
}

void solve() {
    int n, m; qr(n), qr(m);
    rep (i, 1, n) qr(p[i]);
	rep (i, 1, n) qr(c[i]);
	rep (i, 0, n) match[i] = -1;
	int d; qr(d);
	rep (i, 1, d) {
		qr(q[i]); vis[q[i]] = 1;
	}
	rep (i, 1, n) if (!vis[i]) e[p[i]].pb(c[i]);
	int j = 0;
	repn (i, d, 1) {
		memset(v, 0, sizeof v);
		while (j <= m + 1 && dfs(j)) {++j; memset(v, 0, sizeof v);}
		ans[i] = j; e[p[q[i]]].pb(c[q[i]]);
	} rep (i, 1, d) pr2(ans[i]);
}
//
int main() {
    //int T; qr(T); while (T--) {
        solve();
    //}
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <iostream>
#include <ctime>
#include <bitset>
#define gc getchar()
#define ll long long
#define il inline
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repn(i, b, a) for (int i = b; i >= a; --i)
#define ite iterator
#define eps 1e-8

using namespace std;

const int N = 5005, mod = 998244353;

template<class o> il void qr(o &x) {
    x = 0; char c = gc; int f = 1;
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = gc;}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = gc;}
    x *= f;
}

template<class o> void qw(o x) {
    if(x / 10) qw(x / 10); putchar(x % 10 + 48);
}

template<class o> void pr1(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); putchar(' ');
}

template<class o> void pr2(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); puts("");
}

il int ksm(int a, int b = mod - 2) {
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1) ans = 1ll * ans * a % mod;
    return ans;
}

il int add(int a, int b) {return a += b, a >= mod ? a - mod : a;}
il int sub(int a, int b) {return a -= b, a < 0 ? a + mod : a;}

/* code */

vector<int> e[N];
int match[N], p[N], c[N], q[N], ans[N];
bool vis[N], v[N];

bool dfs(int x) {
	for (int y : e[x]) if (!v[y]) {
		v[y] = 1;
		if (match[y] == -1 || dfs(match[y])) {match[y] = x; return 1;}
	} return 0;
}

void solve() {
    int n, m; qr(n), qr(m);
    rep (i, 1, n) qr(p[i]);
	rep (i, 1, n) qr(c[i]);
	rep (i, 0, n) match[i] = -1;
	int d; qr(d);
	rep (i, 1, d) {
		qr(q[i]); vis[q[i]] = 1;
	}
	rep (i, 1, n) if (!vis[i]) e[p[i]].pb(c[i]);
	int j = 0;
	repn (i, d, 1) {
		while (j <= m + 1 && dfs(j)) {++j; memset(v, 0, sizeof(v));}
		ans[i] = j; e[p[q[i]]].pb(c[q[i]]);
	} rep (i, 1, d) pr2(ans[i]);
}

int main() {
    //int T; qr(T); while (T--) {
        solve();
    //}
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <iostream>
#include <ctime>
#include <bitset>
#define gc getchar()
#define ll long long
#define il inline
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repn(i, b, a) for (int i = b; i >= a; --i)
#define ite iterator
#define eps 1e-8

using namespace std;

const int N = 5005, mod = 998244353;

template<class o> il void qr(o &x) {
    x = 0; char c = gc; int f = 1;
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = gc;}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = gc;}
    x *= f;
}

template<class o> void qw(o x) {
    if(x / 10) qw(x / 10); putchar(x % 10 + 48);
}

template<class o> void pr1(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); putchar(' ');
}

template<class o> void pr2(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); puts("");
}

il int ksm(int a, int b = mod - 2) {
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1) ans = 1ll * ans * a % mod;
    return ans;
}

il int add(int a, int b) {return a += b, a >= mod ? a - mod : a;}
il int sub(int a, int b) {return a -= b, a < 0 ? a + mod : a;}

/* code */

vector<int> e[N];
int match[N], p[N], c[N], q[N], ans[N];
bool vis[N];

bool dfs(int x) {
	for (int y : e[x]) {
		if (!match[y] || dfs(match[y])) {match[y] = x; return 1;}
	} return 0;
}

void solve() {
    int n, m; qr(n), qr(m);
    rep (i, 1, n) qr(p[i]);
	rep (i, 1, n) qr(c[i]);
	int d; qr(d);
	rep (i, 1, d) {
		qr(q[i]); vis[q[i]] = 1;
	}
	rep (i, 1, n) if (!vis[i]) e[p[i]].pb(c[i]);
	int j = 0;
	repn (i, d, 1) {
		while (j <= m && dfs(j)) ++j;
		ans[i] = j; e[p[q[i]]].pb(c[q[i]]);
	} rep (i, 1, d) pr2(ans[i]);
}

int main() {
    //int T; qr(T); while (T--) {
        solve();
    //}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fr first
#define sc second

long long n,m,nn=0,a[5069],cl[5069],qq[5069],wg[20069],sq[5069],mn;
bitset<5069> alr;
vector<pair<long long,long long>> al[10069];
map<pair<long long,long long>,bool> ve;
bitset<10069> vtd;
stack<long long> sk;
bool r0;

void ae(long long x,long long y,long long w)
{
	if(!ve[{x,y}])
	{
		wg[nn+(y<x)]=w;
		al[x].push_back({y,nn+(y<x)});
		al[y].push_back({x,nn+(x<y)});
		nn+=2;
		ve[{x,y}]=1;
		ve[{y,x}]=1;
	}
}

void dfs(long long x)
{
	long long i,sz=al[x].size(),l,p;

	vtd[x]=1;
	if(x==10001)
	{
		r0=1;
		mn=sk.top();
		return;
	}
	for(i=0;i<sz;i++)
	{
		l=al[x][i].fr;
		p=al[x][i].sc;
		if(!vtd[l]&&wg[p])
		{
			sk.push(min(sk.top(),wg[p]));
			dfs(l);
			sk.pop();
			if(r0)
			{
				wg[p]-=mn;
				wg[p/2*2+!(p%2)]+=mn;
				return;
			}
		}
	}
}

int main()
{
	long long t,rr,i,z=0;

	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",a+i);
	}
	for(i=1;i<=n;i++)
	{
		scanf("%lld",cl+i);
	}
	scanf("%lld",&t);
	for(rr=1;rr<=t;rr++)
	{
		scanf("%lld",qq+rr);
		alr[qq[rr]]=1;
	}
	for(i=1;i<=m;i++)
	{
		ae(5000+i,10001,1);
	}
	for(i=1;i<=n;i++)
	{
		if(!alr[i])
		{
			ae(a[i],5000+cl[i],1);
		}
	}
	sk.push(1e18);
	for(rr=t;rr;rr--)
	{
		for(;z<5000;z++)
		{
			r0=0;
			vtd.reset();
			dfs(z);
			if(!r0)
			{
				break;
			}
		}
		sq[rr]=z;
		ae(a[qq[rr]],5000+cl[qq[rr]],1);
	}
	for(rr=1;rr<=t;rr++)
	{
		printf("%lld\n",sq[rr]);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fr first
#define sc second

long long n,m,nn=0,a[5069],cl[5069],qq[5069],wg[10069],sq[5069],mn;
bitset<5069> alr;
vector<pair<long long,long long>> al[10069];
map<pair<long long,long long>,bool> ve;
bitset<10069> vtd;
stack<long long> sk;
bool r0;

void ae(long long x,long long y,long long w)
{
	if(!ve[{x,y}])
	{
		wg[nn+(y<x)]=w;
		al[x].push_back({y,nn+(y<x)});
		al[y].push_back({x,nn+(x<y)});
		nn+=2;
		ve[{x,y}]=1;
		ve[{y,x}]=1;
	}
}

void dfs(long long x)
{
	long long i,sz=al[x].size(),l,p;

	vtd[x]=1;
	if(x==10001)
	{
		r0=1;
		mn=sk.top();
		return;
	}
	for(i=0;i<sz;i++)
	{
		l=al[x][i].fr;
		p=al[x][i].sc;
		if(!vtd[l]&&wg[p])
		{
			sk.push(min(sk.top(),wg[p]));
			dfs(l);
			sk.pop();
			if(r0)
			{
				wg[p]-=mn;
				wg[p/2*2+!(p%2)]+=mn;
				return;
			}
		}
	}
}

int main()
{
	long long t,rr,i,z=0;

	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",a+i);
	}
	for(i=1;i<=n;i++)
	{
		scanf("%lld",cl+i);
	}
	scanf("%lld",&t);
	for(rr=1;rr<=t;rr++)
	{
		scanf("%lld",qq+rr);
		alr[qq[rr]]=1;
	}
	for(i=1;i<=m;i++)
	{
		ae(5000+i,10001,1);
	}
	for(i=1;i<=n;i++)
	{
		if(!alr[i])
		{
			ae(a[i],5000+cl[i],1);
		}
	}
	sk.push(1e18);
	for(rr=t;rr;rr--)
	{
		for(;z<5000;z++)
		{
			r0=0;
			vtd.reset();
			dfs(z);
			if(!r0)
			{
				break;
			}
		}
		sq[rr]=z;
		ae(a[qq[rr]],5000+cl[qq[rr]],1);
	}
	for(rr=1;rr<=t;rr++)
	{
		printf("%lld\n",sq[rr]);
	}
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e3 + 10;
int n, m;
int p[maxn], c[maxn];
vector<int> v[maxn];
int from[maxn];
int d[maxn];
bool vis[maxn];

bool match(int x) {
    for (int i = 0; i < v[x].size(); ++i) {
        int u = v[x][i];
        if (vis[u] == 0) {
            vis[u] = 1;
            if (from[u] == -1 ||
                match(from[u])) {
                from[u] = x;
                return 1;
            }
        }
    }
    return 0;
}

int tot = 0;

int hungry() {
    for (int i = tot; i <= 5000; ++i) {
        memset(vis, 0, sizeof vis);
        if (match(i)) {
            ++tot;
        } else break;
    }
    return tot;
}

bool vv[maxn];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(from, -1, sizeof(from));
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> c[i];
    }
    int z;
    cin >> z;
    for (int i = 1; i <= z; ++i) {
        cin >> d[i];
        vv[d[i]] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        if (vv[i] == 0) {
            v[p[i]].push_back(c[i]);
        }
    }
    vector<int> ans;
    for (int i = z; i >= 1; --i) {
        ans.push_back(hungry());
        v[p[d[i]]].push_back(c[d[i]]);
    }
    for (int i = ans.size() - 1; i >= 0; --i) {
        cout << ans[i] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e3 + 10;
int n, m;
int p[maxn], c[maxn];
vector<int> v[maxn];
int from[maxn];
int d[maxn];
bool vis[maxn];

bool match(int x) {
    for (int i = 0; i < v[x].size(); ++i) {
        int u = v[x][i];
        if (vis[u] == 0) {
            vis[u] = 1;
            if (from[u] == -1 ||
                match(from[u])) {
                from[u] = x;
                return 1;
            }
        }
    }
    return 0;
}

int hungry() {
    int tot = 0;
    memset(from, -1, sizeof(from));
    for (int i = 0; i <= 5000; ++i) {
        memset(vis, 0, sizeof vis);
        if (match(i)) {
            ++tot;
        } else break;
    }
    return tot;
}

bool vv[maxn];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> c[i];
    }
    int z;
    cin >> z;
    for (int i = 1; i <= z; ++i) {
        cin >> d[i];
        vv[d[i]] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        if (vv[i] == 0) {
            v[p[i]].push_back(c[i]);
        }
    }
    vector<int> ans;
    for (int i = z; i >= 1; --i) {
        ans.push_back(hungry());
        v[p[d[i]]].push_back(c[d[i]]);
    }
    for (int i = ans.size() - 1; i >= 0; --i) {
        cout << ans[i] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e3 + 10;
int n, m;
int p[maxn], c[maxn];
vector<int> v[maxn];
bool vis[maxn];
int from[maxn];
bool vv[maxn];

bool match(int x) {
    for (int i = 0; i < v[x].size(); ++i) {
        if (vis[v[x][i]] == 0) {
            int u = v[x][i];
            vv[c[u]] = 1;
            if (from[c[u]] == -1 || match(from[c[u]])) {
                from[c[u]] = u;
                return 1;
            }
        }
    }
    return 0;
}

int hungry() {
    int tot = 0;
    memset(from, -1, sizeof(from));
    for (int i = 0; i < n; ++i) {
        memset(vv, 0, sizeof(vv));
        if (match(i)) {
            ++tot;
        } else break;
    }
    return tot;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> c[i];
        v[p[i]].push_back(i);
    }
    int d;
    cin >> d;
    while (d--) {
        int x;
        cin >> x;
        vis[x] = 1;
        cout << hungry() << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,p[N],c[N],d,k[N];
int tag[N];
int tot=0,f[N],nxt[N<<1];
int Ans[N],dxx=0,dfn[N],match[N];
struct Edge
{
	int u,v;
}e[N<<1];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
void Add(int u,int v)
{
	tot++;
	nxt[tot]=f[u];
	f[u]=tot;
	e[tot]=(Edge){u,v};
	return;
}
int DFS(int x)
{
	for (int j=f[x];j!=-1;j=nxt[j])
	{
		int v=e[j].v;
		if (dfn[v]==dxx) continue;
		dfn[v]=dxx;
		if ((!match[v])||DFS(match[v]))
		{
			match[v]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	memset(f,-1,sizeof(f));
	n=read(),m=read();
	for (int i=1;i<=n;i++) p[i]=read(),p[i]++;
	for (int i=1;i<=n;i++) c[i]=read();
	d=read();
	for (int i=1;i<=d;i++) k[i]=read(),tag[k[i]]=-1;
	for (int i=1;i<=n;i++) if (tag[i]!=-1) Add(p[i],10000+c[i]);
	for (int i=d;i>=1;i--)
	{
		dxx++;
		Ans[i]=Ans[i+1];
		for (int j=Ans[i]+1;j<=m;j++)
		{
			dxx++;
			if (DFS(j)) Ans[i]++;
			else break;
		}
		Add(p[k[i]],10000+c[k[i]]);
	}
	for (int i=1;i<=d;i++) printf("%d\n",Ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,p[N],c[N],d,k[N];
int tag[N];
int tot=0,f[N],nxt[N<<1];
int Ans[N],dxx=0,dfn[N],match[N];
struct Edge
{
	int u,v;
}e[N<<1];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
void Add(int u,int v)
{
	tot++;
	nxt[tot]=f[u];
	f[u]=tot;
	e[tot]=(Edge){u,v};
	return;
}
int DFS(int x)
{
	for (int j=f[x];j!=-1;j=nxt[j])
	{
		int v=e[j].v;
		if (dfn[v]==dxx) continue;
		dfn[v]=dxx;
		if ((!match[v])||DFS(match[v]))
		{
			match[v]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	memset(f,-1,sizeof(f));
	n=read(),m=read();
	for (int i=1;i<=n;i++) p[i]=read();
	for (int i=1;i<=n;i++) c[i]=read();
	d=read();
	for (int i=1;i<=d;i++) k[i]=read(),tag[k[i]]=-1;
	for (int i=1;i<=n;i++) if (tag[i]!=-1) Add(p[i],6000+c[i]);
	for (int i=d;i>=1;i--)
	{
		dxx++;
		Ans[i]=Ans[i+1];
		for (int j=Ans[i];j<=m;j++)
		{
			if (DFS(j)) Ans[i]++;
			else break;
		}
		Add(p[k[i]],6000+c[k[i]]);
	}
	for (int i=1;i<=d;i++) printf("%d\n",Ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int n,m,p[N],c[N],d,k[N];
int tag[N];
int tot=0,f[N],nxt[N<<1];
int Ans[N],dxx=0,dfn[N],match[N];
struct Edge
{
	int u,v;
}e[N<<1];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
void Add(int u,int v)
{
	tot++;
	nxt[tot]=f[u];
	f[u]=tot;
	e[tot]=(Edge){u,v};
	return;
}
int DFS(int x)
{
	for (int j=f[x];j!=-1;j=nxt[j])
	{
		int v=e[j].v;
		if (dfn[v]==dxx) continue;
		dfn[v]=dxx;
		if ((!match[v])||DFS(match[v]))
		{
			match[v]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	memset(f,-1,sizeof(f));
	n=read(),m=read();
	for (int i=1;i<=n;i++) p[i]=read(),p[i]++;
	for (int i=1;i<=n;i++) c[i]=read();
	d=read();
	for (int i=1;i<=d;i++) k[i]=read(),tag[k[i]]=-1;
	for (int i=1;i<=n;i++) if (tag[i]!=-1) Add(p[i],5000+c[i]);
	for (int i=d;i>=1;i--)
	{
		dxx++;
		Ans[i]=Ans[i+1];
		while (DFS(Ans[i]+1)) Ans[i]++;
		Add(p[k[i]],5000+c[k[i]]);
	}
	for (int i=1;i<=d;i++) printf("%d\n",Ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int n,m,p[N],c[N],d,k[N];
int tag[N];
int tot=0,f[N],nxt[N<<1];
int Ans[N],dxx=0,dfn[N],match[N];
struct Edge
{
	int u,v;
}e[N<<1];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
void Add(int u,int v)
{
	tot++;
	nxt[tot]=f[u];
	f[u]=tot;
	e[tot]=(Edge){u,v};
	return;
}
int DFS(int x)
{
	for (int j=f[x];j!=-1;j=nxt[j])
	{
		int v=e[j].v;
		if (dfn[v]==dxx) continue;
		dfn[v]=dxx;
		if ((!match[v])||DFS(match[v]))
		{
			match[v]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	memset(f,-1,sizeof(f));
	n=read(),m=read();
	for (int i=1;i<=n;i++) p[i]=read(),p[i]++;
	for (int i=1;i<=n;i++) c[i]=read();
	d=read();
	for (int i=1;i<=d;i++) k[i]=read(),tag[k[i]]=-1;
	for (int i=1;i<=n;i++) if (tag[i]!=-1) Add(p[i],5001+c[i]);
	for (int i=d;i>=1;i--)
	{
		dxx++;
		Ans[i]=Ans[i+1];
		while (DFS(Ans[i]+1)) Ans[i]++;
		Add(p[k[i]],5001+c[k[i]]);
	}
	for (int i=1;i<=d;i++) printf("%d\n",Ans[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[212345];
ll a[212345];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n/2; i++)
    {
        scanf("%I64d",&b[i]);
    }
    int o=1;
    int p=n;
    int t=0;
    a[o++]=0;
    a[p--]=b[1];
    for(int i=2; i<=n/2; i++)
    {
        while(1)
        {
            if(b[i]-t<=a[p+1]&&t<=b[i]-t)
            {
                a[o++]=t;
                a[p--]=b[i]-t;
                break;
            }
            else
            {
                ll l=t,r=1e18;
                ll mid;
                while(l<r)
                {
                    mid=(l+r)/2;
                    if(b[i]-mid>a[p+1])
                        l=mid+1;
                    else if(mid>b[i]-mid)
                        r=mid;
                    else if(mid<a[o-1])
                        l=mid+1;
                    else if(b[i]-mid<=a[p+1]&&mid<=b[i]-mid&&mid>=a[o-1])
                    {
                        break;
                    }
                }
                a[o++]=mid;
                a[p--]=b[i]-mid;
                break;
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(i==1)
            printf("%I64d",a[i]);
        else
            printf(" %I64d",a[i]);
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[212345];
ll a[212345];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n/2; i++)
    {
        scanf("%I64d",&b[i]);
    }
    int o=1;
    int p=n;
    int t=0;
    a[o++]=0;
    a[p--]=b[1];
    for(int i=2; i<=n/2; i++)
    {
        while(1)
        {
            if(b[i]-t<=a[p+1]&&t<=b[i]-t)
            {
                a[o++]=t;
                a[p--]=b[i]-t;
                break;
            }
            else
            {
                t++;
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(i==1)
            printf("%I64d",a[i]);
        else
            printf(" %I64d",a[i]);
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[212345];
ll a[212345];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n/2; i++)
    {
        scanf("%I64d",&b[i]);
    }
    int o=1;
    int p=n;
    int t=0;
    a[o++]=0;
    a[p--]=b[1];
    for(int i=2; i<=n/2; i++)
    {
        while(1)
        {
            if(b[i]-t<=a[p+1]&&t<=b[i]-t)
            {
                a[o++]=t;
                a[p--]=b[i]-t;
                break;
            }
            else
            {
                ll l=t,r=1e18;
                ll mid;
                while(l<r)
                {
                    mid=(l+r)/2;
                    if(b[i]-mid>a[p+1])
                        l=mid+1;
                    else if(mid>b[i]-mid)
                        r=mid;
                    else if(b[i]-mid<=a[p+1]&&mid<=b[i]-mid)
                    {
                        break;
                    }
                }
                a[o++]=mid;
                a[p--]=b[i]-mid;
                break;
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(i==1)
            printf("%I64d",a[i]);
        else
            printf(" %I64d",a[i]);
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[212345];
ll a[212345];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n/2; i++)
    {
        scanf("%I64d",&b[i]);
    }
    int o=1;
    int p=n;
    a[o++]=0;
    a[p--]=b[1];
    for(int i=2;i<=n/2;i++)
    {

        if(b[i]>a[p+1])
        {
            int tmp=p+1;
            a[p--]=a[tmp];
            a[o++]=b[i]-a[tmp];
        }
        else
        {
            a[o++]=0;
            a[p--]=b[i];
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(i==1)
            printf("%I64d",a[i]);
        else
            printf(" %I64d",a[i]);
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[212345];
ll a[212345];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n/2; i++)
    {
        scanf("%I64d",&b[i]);
    }
    int o=1;
    int p=n;
    int t=0;
    a[o++]=0;
    a[p--]=b[1];
    for(int i=2; i<=n/2; i++)
    {
        if(b[i]-t<=a[p+1]&&t<=b[i]-t)
        {
            a[o++]=t;
            a[p--]=b[i]-t;
            //break;
        }
        else
        {
            int tmp=p+1;
            a[p--]=a[tmp];
            a[o++]=b[i]-a[tmp];
            t=a[o];
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(i==1)
            printf("%I64d",a[i]);
        else
            printf(" %I64d",a[i]);
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char st[1500];
        scanf("%s",st);
        int l=strlen(st);
        map<char,int>mp;
        int s=0;
        int data[30];
        memset(data,0,sizeof(data));
        for(int i=0;i<l;i++)
        {
            data[st[i]-'a']++;
            if(mp[st[i]]==0)
            {
                mp[st[i]]=1;
                s++;
            }
        }
        if(s==1)
            printf("-1\n");
        else
        {
            int f=0;
            for(int i=0;i<=l/2;i++)
            {
                if(st[i]!=st[l-i-1])
                    f=1;
            }
            if(f)
                printf("%s\n",st);
            else
            {
                for(int i=0;i<26;i++)
                {
                    if(data[i]!=0)
                    {
                        for(int j=1;j<=data[i];j++)
                            cout<<(char)(i+'a');
                    }
                }
                cout<<endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	while(sc>=sl&&fc<=fl)
	{
		sc--;
		fc++;
	}
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	if (sc<sl)
	{
		sc=sl;fc=b[i]-sl;
	}
	if (fc>fl)
	{
		fc=fl;sc=b[i]-fl;
	}
	/*while(sc>sl||fc<fl)
	{
		sc--;
		fc++;
	}*/
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	if (sc<sl)
	{
		sc=sl;fc=b[i]-sl;
	}
	if (fc>fl)
	{
		fc=fl;sc=b[i]-fl;
	}
	while(sc>sl||fc<fl)
	{
		sc--;
		fc++;
	}
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];
	while(sc>sl)
	{
		sc--;
		fc++;
	}
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;
int dif=0;
for (int i = 1; i < n; ++i)
{
	fc=fl;sc=b[i]-fc;
	if (sc>sl)
	{
		dif=sc-sl;
		fc=fc+dif;
		sc=sc-dif;
	}

	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	fc=fl;sc=b[i]-fc;
	if (sc>sl)
	{
		sc=sl;fc=b[i]-sl;
	}
	/*if (fc<fl)
	{
		fc=fl;sc=b[i]-fl;
	}
	while(sc>sl||fc<fl)
	{
		sc--;
		fc++;
	}*/
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	if (sc>sl)
	{
		sc=sl;fc=b[i]-sl;
	}
	if (fc<fl)
	{
		fc=fl;sc=b[i]-fl;
	}
	/*while(sc>sl||fc<fl)
	{
		sc--;
		fc++;
	}*/
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

long long int a[2*n]={0};
long long int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

long long int fc=0,sc=0;
long long int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;
long long int dif=0;
for (int i = 1; i < n; ++i)
{
	fc=fl;sc=b[i]-fc;
	if (sc>sl)
	{
		dif=sc-sl;
		fc=fc+dif;
		sc=sc-dif;
	}

	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}

//499372215468999473
//498465318726257937


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	while(sc>sl||fc<fl)
	{
		sc--;
		fc++;
	}
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	while(sc>sl)
	{
		sc--;
		fc++;
	}
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	while(sc>sl&&fc<fl)
	{
		sc--;
		fc++;
	}
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
n=n/2;

int a[2*n]={0};
int b[n];

for (int i = 0; i < n; ++i)
	cin>>b[i];

int fc=0,sc=0;
int fl=0,sl=0;

fc=0;sc=b[0];
a[0]=fc;a[2*n-1]=sc;
fl=fc;sl=sc;

for (int i = 1; i < n; ++i)
{
	sc=b[i];fc=0;
	if (sc>sl)
	{
		sc=sl;fc=b[i]-sl;
	}
	if (fc<fl)
	{
		fc=fl;sc=b[i]-fl;
	}
	while(sc>sl||fc<fl)
	{
		sc--;
		fc++;
	}
	a[i]=fc;a[2*n-1-i]=sc;
	fl=fc;sl=sc;
}

for (int i = 0; i < 2*n; ++i)
	cout<<a[i]<<" ";
}


#include<bits/stdc++.h>

#define ll long long
#define dl double

using namespace std;

int a[200010];

int main()
{
    int n;
    cin >> n;

    ll b[100010];

    for(int i = 1; i <= n / 2; i++){
        cin >> b[i];
    }

    ll N = 0;
    for(int i = 1, j = n; i <= n / 2; i++, j--){
        if(i == 1){
            a[i] = N;
            a[j] = b[i] - N;
        }
        else if(b[i] - N > a[j + 1]){
            a[j] = a[j + 1];
            N = b[i] - a[j];
            a[i] = N;
        }
        else {
            a[i] = N;
            a[j] = b[i] - N;
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include<bits/stdc++.h>

#define ll long long
#define dl double

using namespace std;

int a[200010];

int main()
{
    int n;
    cin >> n;

    ll b[100010];

    for(int i = 1; i <= n / 2; i++){
        cin >> b[i];
    }

    ll N = 0;
    for(int i = 1, j = n; i <= n / 2; i++, j--){
        if(i == 1){
            a[i] = N;
            a[j] = b[i] - N;
        }
        else{
            if(a[j + 1] < b[i]){
                a[j] = a[j + 1];
                N = b[i] - a[j];
                a[i] = N;
            }
            else {
                a[j] = b[i];
                a[i] = b[i] - a[j];
            }
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include<bits/stdc++.h>

#define ll long long
#define dl double

using namespace std;

ll a[200010];

int main()
{
    int n;
    cin >> n;

    ll b[100010];

    for(int i = 1; i <= n / 2; i++){
        cin >> b[i];
    }

    ll N = 0;
    for(int i = 1, j = n; i <= n / 2; i++, j--){
        if(i == 1){
            a[i] = N;
            a[j] = b[i] - N;
        }
        else if(b[i] - N > a[j + 1]){
            a[j] = a[j + 1];
            N = b[i] - a[j];
            a[i] = N;
        }
        else {
            a[i] = N;
            a[j] = b[i] - N;
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include<bits/stdc++.h>

#define ll long long
#define dl double

using namespace std;

int a[200010];

int main()
{
    int n;
    cin >> n;

    ll b[100010];

    for(int i = 1; i <= n / 2; i++){
        cin >> b[i];
    }

    ll N = 0;
    for(int i = 1, j = n; i <= n / 2; i++, j--){
        if(i == 1){
            a[i] = N;
            a[j] = b[i] - N;
        }
        else{
            if(a[j + 1] < b[i]){
                a[j] = a[j + 1];
                N = b[i] - a[j];

                if(N < a[i - 1]){
                    N = a[i - 1];
                    a[j] = b[i] - N;
                }
                a[i] = N;
            }
            else {
                a[i] = N;
                a[j] = b[i] - N;
            }
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include<bits/stdc++.h>

#define ll long long
#define dl double

using namespace std;

ll a[200010];

int main()
{
    int n;
    cin >> n;

    ll b[100010];
    for(int i = 1; i <= n / 2; i++){
        cin >> b[i];
    }

    ll N = 0;
    for(int i = 1, j = n; i <= n / 2; i++, j--){
        if(i == 1){
            a[i] = N;
            a[j] = b[i] - N;
        }
        else if(b[i] - N > a[j + 1]){
            a[j] = a[j + 1];
            N = b[i] - a[j];
            a[i] = N;
        }
        else {
            a[i] = N;
            a[j] = b[i] - N;
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include<bits/stdc++.h>

#define ll long long
#define dl double

using namespace std;

int a[200010];

int main()
{
    int n;
    cin >> n;

    ll b[100010];

    for(int i = 1; i <= n / 2; i++){
        cin >> b[i];
    }

    ll N = 0;
    for(int i = 1, j = n; i <= n / 2; i++, j--){
        if(i == 1){
            a[i] = N;
            a[j] = b[i] - N;
        }
        if(b[i] - N > a[j + 1]){
            a[j] = a[j + 1];
            N = b[i] - a[j];
            a[i] = N;
        }
        else {
            a[i] = N;
            a[j] = b[i] - N;
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include<bits/stdc++.h>

#define ll long long
#define dl double

using namespace std;

int a[200010];

int main()
{
    int n;
    cin >> n;

    ll b[100010];

    for(int i = 1; i <= n / 2; i++){
        cin >> b[i];
    }

    ll N = 0;
    for(int i = 1, j = n; i <= n / 2; i++, j--){
        if(i == 1){
            a[i] = N;
            a[j] = b[i] - N;
        }
        else{
            if(a[j + 1] < b[i]){
                a[j] = a[j + 1];
                N = b[i] - a[j];
                a[i] = N;
            }
            else {
                a[i] = N;
                a[j] = b[i] - N;
            }
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi B(n >> 1);

    for(ll &i : B) cin >> i;

    vi A(n);
    ll mn = 0, mx = B[0];
    A[n - 1] = mx;
    for(int i=1; i<n/2; i++) {
        if(B[i] <= mx && mn == 0) {
            A[n - i - 1] = B[i];
            mx = B[i];
        } else if(B[i] <= mx) {
            A[i] = mn;
            A[n - i - 1] = B[i] - mn; // 1
            mn = A[i], mx = A[n - i - 1];
        } else if(B[i] > mx) {
            A[n - i - 1] = mx;
            A[i] = B[i] - A[n - i - 1];
            mn = A[i], mx = A[n - i - 1];
        }
    }
    for(int i=0; i<B.size(); i++)
        assert(B[i] == A[i] + A[n - i - 1]);

    for(ll i : A) cout << i << ' '; cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi B(n >> 1);

    for(ll &i : B) cin >> i;

    vi A(n);
    ll mn = 0, mx = B[0];
    A[n - 1] = mx;

    for(int i=1; i<n/2; i++) {
        if(B[i] <= mx && mn == 0) {
            A[n - i - 1] = B[i];
            mx = B[i];
        } else if(B[i] <= mx) {
            A[i] = mn;
            A[n - i - 1] = B[i] - mn; // 1
            mn = A[i], mx = A[n - i - 1];
        } else if(B[i] > mx) {
            A[n - i - 1] = mx;
            A[i] = B[i] - A[n - i - 1];
            mn = A[i], mx = A[n - i - 1];
        }
    }

    for(int i=1; i<A.size(); i++)
        assert(A[i] >= A[i - 1]);

    for(ll i : A) cout << i << ' '; cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi B(n >> 1);

    for(ll &i : B) cin >> i;

    vi A(n);
    ll mn = 0, mx = B[0];
    A[n - 1] = mx;

    for(int i=1; i<n/2; i++) {
        if(B[i] <= mx && mn == 0) {
            A[n - i - 1] = B[i];
            mx = B[i];
        } else if(B[i] <= mx) {
            A[i] = mn;
            A[n - i - 1] = B[i] - mn; // 1
            mn = A[i], mx = A[n - i - 1];
        } else if(B[i] > mx) {
            A[n - i - 1] = mx;
            A[i] = B[i] - A[n - i - 1];
            if(A[i] < mn) {
                int diff = mn - A[i];
                A[i] += diff;
                A[n -i - 1] -= diff;
            } else {
                mn = A[i], mx = A[n - i - 1];
            }
        }
    }

    for(ll i : A) cout << i << ' '; cout << endl;
    // for(int i=1; i<A.size(); i++)
    //     assert(A[i] >= A[i - 1]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi B(n >> 1);

    for(ll &i : B) cin >> i;

    vi A(n);
    ll mn = 0, mx = B[0];
    A[n - 1] = mx;

    for(int i=1; i<n/2; i++) {
        if(B[i] <= mx && mn == 0) {
            A[n - i - 1] = B[i];
            mx = B[i];
        } else if(B[i] <= mx) {
            A[i] = mn;
            A[n - i - 1] = B[i] - mn; // 1

            if(A[n - i - 1] > mx) {
                int diff = A[n - i - 1] - mx;
                A[i] += diff;
                A[n -i - 1] -= diff;
            }
            mn = A[i], mx = A[n - i - 1];
        } else if(B[i] > mx) {
            A[n - i - 1] = mx;
            A[i] = B[i] - A[n - i - 1];

            if(A[i] < mn) {
                int diff = mn - A[i];
                A[i] += diff;
                A[n -i - 1] -= diff;
            }

            mn = A[i], mx = A[n - i - 1];
        }
    }

    for(ll i : A) cout << i << ' '; cout << endl;
    // for(int i=1; i<A.size(); i++)
    //     assert(A[i] >= A[i - 1]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi B(n >> 1);

    for(ll &i : B) cin >> i;

    vi A(n);
    ll mn = 0, mx = B[0];
    A[n - 1] = mx;

    for(int i=1; i<n/2; i++) {
        if(B[i] <= mx && mn == 0) {
            A[n - i - 1] = B[i];
            mx = B[i];
        } else if(B[i] <= mx) {
            A[i] = mn;
            A[n - i - 1] = B[i] - mn; // 1

            if(A[n - i - 1] > mx) {
                ll diff = A[n - i - 1] - mx;
                A[i] += diff;
                A[n -i - 1] -= diff;
            }
            mn = A[i], mx = A[n - i - 1];
        } else if(B[i] > mx) {
            A[n - i - 1] = mx;
            A[i] = B[i] - A[n - i - 1];

            if(A[i] < mn) {
                ll diff = mn - A[i];
                A[i] += diff;
                A[n -i - 1] -= diff;
            }

            mn = A[i], mx = A[n - i - 1];
        }
    }

    for(ll i : A) cout << i << ' '; cout << endl;
    // for(int i=1; i<A.size(); i++)
    //     assert(A[i] >= A[i - 1]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi B(n >> 1);

    for(ll &i : B) cin >> i;

    vi A(n);
    ll mn = 0, mx = B[0];
    A[n - 1] = mx;
    for(int i=1; i<n/2; i++) {
        if(B[i] <= mx && mn == 0) {
            A[n-1-i] = B[i];
            mx = B[i];
        } else if(B[i] <= mx) {
            A[i] = mn;
            A[n - i - 1] = (mx - mn);
            mn = A[i], mx = A[n - i - 1];
        } else if(B[i] > mx) {
            A[n - i - 1] = mx;
            A[i] = B[i] - A[n - i - 1];
            mn = A[i], mx = A[n - i - 1];
        }
    }
    for(ll i : A) cout << i << ' '; cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi B(n >> 1);

    for(ll &i : B) cin >> i;

    vi A(n);
    ll mn = 0, mx = B[0];
    A[n - 1] = mx;
    for(int i=1; i<n/2; i++) {
        if(B[i] <= mx && mn == 0) {
            A[n - i - 1] = B[i];
            mx = B[i];
        } else if(B[i] <= mx) {
            A[i] = mn;
            A[n - i - 1] = B[i] - mn; // 1
            mn = A[i], mx = A[n - i - 1];
        } else if(B[i] > mx) {
            A[n - i - 1] = mx;
            A[i] = B[i] - A[n - i - 1];
            mn = A[i], mx = A[n - i - 1];
        }
    }
    for(ll i : A) cout << i << ' '; cout << endl;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL N,b,A[200005];

template <class T>
inline void RI(T &x)
{
    x=0;int f=0;
    char c=getchar();
    while(c<'0'||c>'9'){f|=(c=='-');c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    if(f)x=-x;
}

int main()
{
    RI(N);
    for(LL i=1;i<=(N>>1);++i)
    {
        RI(b);
        if(i==1)
            A[N]=b;
        else if(b-A[i-1]<=A[N-i+2])
        {
            A[i]=A[i-1];
            A[N-i+1]=b-A[i];
        }
        else
        {
            A[N-i+1]=A[N-i+2];
            A[i]=b-A[N-i+1];
        }
    }
    for(LL i=1;i<=N;++i)
        printf("%I64d ",A[i]);
    return 0;
}


#include<bits/stdc++.h>
#define inf 1e18
#define re register
using namespace std;
inline long long read()
{
	re long long x=0;
	re char ch=getchar();
	for(;ch>'9'||ch<'0';ch=getchar()) ;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch^48);
	return x;
}
const int N=200005;
int n;
long long a[N],b[N>>1],lastl,lastr=inf,l,r;
int main()
{
	scanf("%d",&n);n>>=1;
	for(re int i=1;i<=n;i++) b[i]=read();
	for(re int i=1;i<=n;i++)
	{
		l=lastl,r=b[i]-l;
		if(r>lastr) l+=r-lastr,r-=r-lastr;
		a[i]=l,a[(n<<1)-i+1]=r;
		lastl=l,lastr=r;
	}
	n<<=1;
	for(re int i=1;i<=n;i++) printf("%lld ",a[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef int INT;
#define int long long

const int N = 200000 + 10;
#define Max(x, y) ((x) > (y) ? (x) : (y))
#define Min(x, y) ((x) < (y) ? (x) : (y))

int n;

int a[N], b[N];

INT main()
{
    cin >> n;
    for(int i = 1; i <= (n >> 1); i++) cin >> b[i]; a[1] = 0, a[n] = b[1];
    for(int i = 2; i <= (n >> 1); i++)
        a[i] = Max(a[i - 1], b[i] - a[n - i + 2]),
        a[n - i + 1] = b[i] - a[i];
    for(int i = 1; i <= n; i++) cout << a[i] << ' ';
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
#define LL long long
#define up(a, b) (a = (a > b ? a : b))
#define down(a, b) (a = (a > b ? b : a))
#define	cmax(a, b) (a > b ? a : b)
#define cmin(a, b) (a > b ? b : a)
using namespace std;

LL read() {
	LL X = 0, p = 1; char c = getchar();
	for (; c > '9' || c < '0'; c = getchar())
		if (c == '-') p = -1;
	for (; c >= '0' && c <= '9'; c = getchar())
		X = X * 10 + c - '0';
	return X * p;
}

const int N = 2e5 + 1e4;

int n;
LL b[N], a[N];

int main()
{
	n = rd;
	for (int i = 1; i <= n / 2; ++i)
		b[i] = rd;
	a[n + 1] = 1e18 + 5;
	for (int i = 1; i <= n / 2; ++i) {
		int r = n - i + 1;
		LL tmp = cmax(a[i - 1], b[i] - a[r + 1]);
		a[i] = tmp; a[r] = b[i] - tmp;
	}
	for (int i = 1; i <= n; ++i)
		printf("%lld ", a[i]);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	long long a[n];
	for(int i=0;i<n/2;i++)
	{
		long long s;
		cin >> s;
		if(!i)
		{
			a[i]=0;
			a[n-i-1]=s;
		}
		else
		{
			a[i]=a[i-1];
			a[i] += max(0ll,s-a[n-i]+a[i-1]);
			a[n-i-1]=s-a[i];
		}
	}
	for(int i=0;i<n;i++)
		cout << a[i] << ' ';
	puts("");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline long long read(){
    long long s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
long long n,x,l=-1,r,last=-1;
long long a[200005];
int main(){
    n=read();
    for(long long i=1;i<=n/2;i++){
	x=read();
	if(x>last){
	    l++;r=x-l;
	    a[i]=l;
	    a[n-i+1]=r;
	    last=x;
	}
	else if(x<last){
	    r--;l=x-r;
	    a[i]=l;
	    a[n-i+1]=r;
	    last=x;
	}
	else if(x==last){
	    a[i]=l;
	    a[n-i+1]=r;
	}
    }
    for(long long i=1;i<=n;i++){
	printf("%lld ",a[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll gi()
{
	char c; ll x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
	return x*f;
}
const int N=200005;
ll a[N],b[N];
int n;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("c.in","r",stdin);
#endif
	n=gi();
	for(int i=1;i<=n/2;i++) b[i]=gi();
	a[1]=0,a[n]=b[1];
	for(int i=2;i<=n/2;i++)
	{
		ll x=max(a[i-1],b[i]-a[n-(i-1)+1]);
		a[i]=x,a[n-i+1]=b[i]-x;
	}
	for(int i=1;i<=n;i++) printf("%I64d ",a[i]);
}


#include <bits/stdc++.h>
#define int long long
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
using namespace std;
const int N=2e5+5;
int n,m,a[N],b[N];
signed main()
{
	scanf("%lld",&n);
	For(i,1,n>>1) scanf("%lld",&a[i]);
	b[1]=0,b[n]=a[1];
	For(i,2,n>>1) if(a[i]>a[i-1]) b[i]=a[i]-b[n-(i-1)+1],b[n-i+1]=a[i]-b[i];
	else b[i]=b[i-1],b[n-i+1]=a[i]-b[i];
	For(i,1,n) printf("%lld ",b[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define read(t) scanf("%d",&t)
#define readll(t) scanf("%lld",&t)
#define maxn 200000
#define ll long long

int n;
ll a[maxn+5],b[maxn+5];

int main() {
	read(n);
	for(int i=1;i<=n/2;i++) readll(b[i]);

	a[n+1]=(1LL<<62);
	for(int i=1;i<=n/2;i++) {
		a[i]=a[i-1];
		a[n-i+1]=b[i]-a[i];
		if(a[n-i+1]>a[n-i+2]) {
			a[n-i+1]=a[n-i+2];
			a[i]=b[i]-a[n-i+1];
		}
	}

	for(int i=1;i<=n;i++) printf("%lld ",a[i]);

	return 0;
}////////////


#include<bits/stdc++.h>
using namespace std;
inline long long read(){
    long long s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
long long n,x,l=-1,r,last=-1;
long long a[200005];
int main(){
    n=read();
    for(long long i=1;i<=n/2;i++){
	x=read();
	if(x>last){
	    l++;r=x-l;
	    a[i]=l;
	    a[n-i+1]=r;
	    last=x;
	}
	else if(x<last){
	    r--;l=x-r;
	    a[i]=l;
	    a[n-i+1]=r;
	    last=x;
	}
	else if(x==last){
	    a[i]=l;
	    a[n-i+1]=r;
	}
    }
    for(long long i=1;i<=n;i++){
	printf("%I64d ",a[i]);
    }
    return 0;
}


//
// Created by Aaron Lafitte on 1/15/19.
//

#include <iostream>
#include <vector>

using namespace std;

int main() {

    int n;

    cin >> n;

    vector<int> a;

    int temp;
    for(int i = 0; i < n/2; i++){
        cin >> temp;
        a.push_back(temp);
    }

    vector<int> b(n);

    for(int i = 0; i < a.size(); i++, n--){
        int temp2 = a[i]/2;
        a[i] = a[i] - temp2;

        b[i] = temp2;
        b[n-1] = a[i];

    }

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

    return 0;
}


//
// Created by Aaron Lafitte on 1/15/19.
//

#include <iostream>
#include <vector>

using namespace std;

int main() {

    int n;

    cin >> n;

    vector<int> a;

    int temp;
    for(int i = 0; i < n/2; i++){
        cin >> temp;
        a.push_back(temp);
    }

    vector<int> b(n);

    b[0] = 0;
    b[n-1] = a[a.size()-1];
    n--;

    for(int i = 1; i < a.size(); i++, n--){
        int temp2 = a[i]/2;
        a[i] = a[i] - temp2;

        b[i] = temp2;
        b[n-1] = a[i];

    }

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

    return 0;
}


//
// Created by Aaron Lafitte on 1/15/19.
//

#include <iostream>
#include <vector>

using namespace std;

int main() {

    int n;

    cin >> n;

    vector<int> a;

    int temp;
    for(int i = 0; i < n/2; i++){
        cin >> temp;
        a.push_back(temp);
    }

    vector<int> b(n);

    b[0] = 0;
    b[n-1] = a[0];
    n--;

    for(int i = 1; i < a.size(); i++, n--){
        int temp2 = a[i]/2;
        a[i] = a[i] - temp2;

        b[i] = temp2;
        b[n-1] = a[i];

    }

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

    return 0;
}


//
// Created by Aaron Lafitte on 1/15/19.
//

#include <iostream>
#include <vector>

using namespace std;

int main() {

    long long n;

    cin >> n;

    vector<long long> a;

    long long temp;
    for(long long i = 0; i < n/2; i++){
        cin >> temp;
        a.push_back(temp);
    }

    vector<long long> b(n);

    long max, min;
    n--;
    b[0] = 0;
    min = 0;
    b[n] = a[0];
    max = a[0];
    n--;

    for(long long i = 1; i < a.size(); i++, n--){

        if(a[i] > max){
            b[i] = a[i] - max;
            b[n] = a[i] - b[i];
        } else {
            b[i] = min;
            b[n] = a[i] - min;
        }

        max = b[n];
        min = b[i];

    }

    for(long long i=0; i < b.size(); i++){
        cout << b[i] << " ";
    }

    return 0;
}


//
// Created by Aaron Lafitte on 1/15/19.
// Help with understanding Problem with jdevey
//

#include <iostream>
#include <vector>

using namespace std;

int main() {

    long long n;

    cin >> n;

    vector<long long> a;

    long long temp;
    for(long long i = 0; i < n/2; i++){
        cin >> temp;
        a.push_back(temp);
    }

    vector<long long> b(n);

    long long max, min;
    n--;
    b[0] = 0;
    min = 0;
    b[n] = a[0];
    max = a[0];
    n--;

    for(long long i = 1; i < a.size(); i++, n--){

        if(a[i] > max && a[i] - max > min){
            b[i] = a[i] - max;
            b[n] = a[i] - b[i];
        } else {
            b[i] = min;
            b[n] = a[i] - min;
        }

        max = b[n];
        min = b[i];

    }

    for(long long i=0; i < b.size(); i++){
        cout << b[i] << " ";
    }

    return 0;
}


//
// Created by Aaron Lafitte on 1/15/19.
//

#include <iostream>
#include <vector>

using namespace std;

int main() {

    long long n;

    cin >> n;

    vector<long long> a;

    long long temp;
    for(long long i = 0; i < n/2; i++){
        cin >> temp;
        a.push_back(temp);
    }

    vector<long long> b(n);

    long max, min;
    n--;
    b[0] = 0;
    min = 0;
    b[n] = a[0];
    max = a[0];
    n--;

    for(long long i = 1; i < a.size(); i++, n--){

        if(a[i] > max && a[i] - max > min){
            b[i] = a[i] - max;
            b[n] = a[i] - b[i];
        } else {
            b[i] = min;
            b[n] = a[i] - min;
        }

        max = b[n];
        min = b[i];

    }

    for(long long i=0; i < b.size(); i++){
        cout << b[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include<bits/stdc++.h>
#define int long long
//#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define inf 10000000000
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#include <string.h>
#include <algorithm>
using namespace std;

//for the binary search the array should be in ascending order.
int binarysearch(int arr[],int start,int end,int find){
    int mid = (start+end)/2;
    if(find == arr[mid]){
        return mid;
    }
    else if(find < arr[mid]){
        // end = mid - 1;
        return binarysearch(arr,start,mid-1,find);

    }
    else if(find > arr[mid]){
        //start = mid+1;
        return binarysearch(arr,mid+1,end,find);
    }
}

int isprime(int n){
    int root = sqrt(n);
    int k=0;
    for(int i=2;i<=root;i++){
        if(n%i == 0){
            return 0;
            k=1;
            break;
        }
    }
    if(k==0){
        return 1;
    }
}

// function to check and print if
// two numbers are co-prime or not
int reducednr = 0;
int reduceddr = 0;
void coprime(int a, int b) {

    if ( __gcd(a, b) == 1){
        reducednr = a;
        reduceddr = b;
    }
    else{
        int c = a%b;
        int nr = a;
        int dr = b;
        while(c>0){
            a = b;
            b = c;
            c = a%b;
        }
        int gcd = b;
        reducednr = nr/gcd;
        reduceddr = dr/gcd;
    }
}

int factorial(int n)
{
    int f = 1;
    for (int i = 2; i <= n; i++)
        f *= i;
    return f;
}

int C(int n,int m){
    // calculating nCm
    return (factorial(n))/(factorial(n-m)*factorial(m));
}

int32_t main(){
    int n;
    cin >> n;
    int arr[n/2];
    int arr1[n];
    int max = -1;
    for(int i=0;i<(n/2);i++){
       cin >> arr[i];
    }
    arr1[0] = 0;
    arr1[n-1] = arr[0];
    max = arr[0];
    int min = 0;
    for(int i=1;i<n/2;i++){
        if(max >= arr[i]){
            max = arr[i];
            cout << "max:" << max<< endl;
            arr1[i] = 0+min;
            arr1[n-1-i] = arr[i]-min;
            if(max > arr1[n-1-i]){
                max = arr1[n-1-i];
                cout << "max:" << max<< endl;
            }
        }
        else{
            arr1[i] = arr[i] - max;
            if(arr1[i]>=min){
                min = arr1[i];
                cout << "min:" << min << endl;
                arr1[n-i-1] = max;
            }
            else{
                arr1[i] = min;
                arr1[n-1-i] = arr[i] - min;
            }

        }
    }
    for(int i=0;i<n;i++){
        cout << arr1[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include<bits/stdc++.h>
#define int long long
//#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define inf 10000000000
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#include <string.h>
#include <algorithm>
using namespace std;

//for the binary search the array should be in ascending order.
int binarysearch(int arr[],int start,int end,int find){
    int mid = (start+end)/2;
    if(find == arr[mid]){
        return mid;
    }
    else if(find < arr[mid]){
        // end = mid - 1;
        return binarysearch(arr,start,mid-1,find);

    }
    else if(find > arr[mid]){
        //start = mid+1;
        return binarysearch(arr,mid+1,end,find);
    }
}

int isprime(int n){
    int root = sqrt(n);
    int k=0;
    for(int i=2;i<=root;i++){
        if(n%i == 0){
            return 0;
            k=1;
            break;
        }
    }
    if(k==0){
        return 1;
    }
}

// function to check and print if
// two numbers are co-prime or not
int reducednr = 0;
int reduceddr = 0;
void coprime(int a, int b) {

    if ( __gcd(a, b) == 1){
        reducednr = a;
        reduceddr = b;
    }
    else{
        int c = a%b;
        int nr = a;
        int dr = b;
        while(c>0){
            a = b;
            b = c;
            c = a%b;
        }
        int gcd = b;
        reducednr = nr/gcd;
        reduceddr = dr/gcd;
    }
}

int factorial(int n)
{
    int f = 1;
    for (int i = 2; i <= n; i++)
        f *= i;
    return f;
}

int C(int n,int m){
    // calculating nCm
    return (factorial(n))/(factorial(n-m)*factorial(m));
}

int32_t main(){
    int n;
    cin >> n;
    int arr[n/2];
    int arr1[n];
    for(int i=0;i<(n/2);i++){
       cin >> arr[i];
       arr1[i] = 0;
    }
    //sort arr.
    sort(arr,arr+(n/2));
    for(int i=(n/2);i<n;i++){
        arr1[i] = arr[i-(n/2)];
    }
    for(int i=0;i<(n);i++){
        cout << arr1[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include<bits/stdc++.h>
#define int long long
//#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define inf 10000000000
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#include <string.h>
#include <algorithm>
using namespace std;

//for the binary search the array should be in ascending order.
int binarysearch(int arr[],int start,int end,int find){
    int mid = (start+end)/2;
    if(find == arr[mid]){
        return mid;
    }
    else if(find < arr[mid]){
        // end = mid - 1;
        return binarysearch(arr,start,mid-1,find);

    }
    else if(find > arr[mid]){
        //start = mid+1;
        return binarysearch(arr,mid+1,end,find);
    }
}

int isprime(int n){
    int root = sqrt(n);
    int k=0;
    for(int i=2;i<=root;i++){
        if(n%i == 0){
            return 0;
            k=1;
            break;
        }
    }
    if(k==0){
        return 1;
    }
}

// function to check and print if
// two numbers are co-prime or not
int reducednr = 0;
int reduceddr = 0;
void coprime(int a, int b) {

    if ( __gcd(a, b) == 1){
        reducednr = a;
        reduceddr = b;
    }
    else{
        int c = a%b;
        int nr = a;
        int dr = b;
        while(c>0){
            a = b;
            b = c;
            c = a%b;
        }
        int gcd = b;
        reducednr = nr/gcd;
        reduceddr = dr/gcd;
    }
}

int factorial(int n)
{
    int f = 1;
    for (int i = 2; i <= n; i++)
        f *= i;
    return f;
}

int C(int n,int m){
    // calculating nCm
    return (factorial(n))/(factorial(n-m)*factorial(m));
}

int32_t main(){
    int n;
    cin >> n;
    int arr[n/2];
    int arr1[n];
    int max = -1;
    for(int i=0;i<(n/2);i++){
       cin >> arr[i];
    }
    arr1[0] = 0;
    arr1[n-1] = arr[0];
    max = arr[0];
    int min = 0;
    for(int i=1;i<n/2;i++){
        if(max >= arr[i]){
            max = arr[i];
           // cout << "max:" << max<< endl;
            arr1[i] = 0+min;
            arr1[n-1-i] = arr[i]-min;
            if(max > arr1[n-1-i]){
                max = arr1[n-1-i];
               // cout << "max:" << max<< endl;
            }
        }
        else{
            arr1[i] = arr[i] - max;
            if(arr1[i]>=min){
                min = arr1[i];
               // cout << "min:" << min << endl;
                arr1[n-i-1] = max;
            }
            else{
                arr1[i] = min;
                arr1[n-1-i] = arr[i] - min;
            }

        }
    }
    for(int i=0;i<n;i++){
        cout << arr1[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include<bits/stdc++.h>
#define int long long
//#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define inf 10000000000
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#include <string.h>
#include <algorithm>
using namespace std;

//for the binary search the array should be in ascending order.
int binarysearch(int arr[],int start,int end,int find){
    int mid = (start+end)/2;
    if(find == arr[mid]){
        return mid;
    }
    else if(find < arr[mid]){
        // end = mid - 1;
        return binarysearch(arr,start,mid-1,find);

    }
    else if(find > arr[mid]){
        //start = mid+1;
        return binarysearch(arr,mid+1,end,find);
    }
}

int isprime(int n){
    int root = sqrt(n);
    int k=0;
    for(int i=2;i<=root;i++){
        if(n%i == 0){
            return 0;
            k=1;
            break;
        }
    }
    if(k==0){
        return 1;
    }
}

// function to check and print if
// two numbers are co-prime or not
int reducednr = 0;
int reduceddr = 0;
void coprime(int a, int b) {

    if ( __gcd(a, b) == 1){
        reducednr = a;
        reduceddr = b;
    }
    else{
        int c = a%b;
        int nr = a;
        int dr = b;
        while(c>0){
            a = b;
            b = c;
            c = a%b;
        }
        int gcd = b;
        reducednr = nr/gcd;
        reduceddr = dr/gcd;
    }
}

int factorial(int n)
{
    int f = 1;
    for (int i = 2; i <= n; i++)
        f *= i;
    return f;
}

int C(int n,int m){
    // calculating nCm
    return (factorial(n))/(factorial(n-m)*factorial(m));
}

int32_t main(){
    int n;
    cin >> n;
    int arr[n/2];
    int arr1[n];
    int max = -1;
    for(int i=0;i<(n/2);i++){
       cin >> arr[i];
    }
    arr1[0] = 0;
    arr1[n-1] = arr[0];
    max = arr[0];
    int min = 0;
    for(int i=1;i<n/2;i++){
        if(max >= arr[i]){
            max = arr[i];
            arr1[i] = 0+min;
            arr1[n-1-i] = arr[i]-min;
            if(max > arr1[n-1-i]){
                max = arr1[n-1-i];
            }
        }
        else{
            arr1[i] = arr[i] - max;
            if(arr[i]-max>min){
                min = arr[i]-max;
            }
            arr1[n-i-1] = max;
        }
    }
    for(int i=0;i<n;i++){
        cout << arr1[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include<bits/stdc++.h>
#define int long long
//#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define inf 10000000000
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#include <string.h>
#include <algorithm>
using namespace std;

//for the binary search the array should be in ascending order.
int binarysearch(int arr[],int start,int end,int find){
    int mid = (start+end)/2;
    if(find == arr[mid]){
        return mid;
    }
    else if(find < arr[mid]){
        // end = mid - 1;
        return binarysearch(arr,start,mid-1,find);

    }
    else if(find > arr[mid]){
        //start = mid+1;
        return binarysearch(arr,mid+1,end,find);
    }
}

int isprime(int n){
    int root = sqrt(n);
    int k=0;
    for(int i=2;i<=root;i++){
        if(n%i == 0){
            return 0;
            k=1;
            break;
        }
    }
    if(k==0){
        return 1;
    }
}

// function to check and print if
// two numbers are co-prime or not
int reducednr = 0;
int reduceddr = 0;
void coprime(int a, int b) {

    if ( __gcd(a, b) == 1){
        reducednr = a;
        reduceddr = b;
    }
    else{
        int c = a%b;
        int nr = a;
        int dr = b;
        while(c>0){
            a = b;
            b = c;
            c = a%b;
        }
        int gcd = b;
        reducednr = nr/gcd;
        reduceddr = dr/gcd;
    }
}

int factorial(int n)
{
    int f = 1;
    for (int i = 2; i <= n; i++)
        f *= i;
    return f;
}

int C(int n,int m){
    // calculating nCm
    return (factorial(n))/(factorial(n-m)*factorial(m));
}

int32_t main(){
    int n;
    cin >> n;
    int arr[n/2];
    int arr1[n];
    int max = -1;
    for(int i=0;i<(n/2);i++){
       cin >> arr[i];
    }
    arr1[0] = 0;
    arr1[n-1] = arr[0];
    max = arr[0];
    for(int i=1;i<n/2;i++){
        if(max >= arr[i]){
            max = arr[i];
            arr1[i] = 0;
            arr1[n-1-i] = arr[i];
        }
        else{
            arr1[i] = arr[i] - max;
            arr1[n-i-1] = max;
        }
    }
    for(int i=0;i<n;i++){
        cout << arr1[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;

int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

void sort(int arr[],int n){
    for(int i=0;i<=n;i++){
        for(int j=i;j<=n;j++){
            if(arr[i] > arr[j]){
                int t = arr[i];
                arr[i] = arr[j];
                arr[j] = t;
            }
        }
    }

}

int modd(int n,int m){
    if(n-m>0){
        return n-m;
    }
    else{
        return m-n;
    }
}

int mod(int n){
    if(n>=0){
        return n;
    }
    else{
        return -n;
    }
}

int isperfectsquare(int n){
    int k = sqrt(n);
    if(n%k==0 && n/k==k){
        return 1;
    }
    else{
        return 0;
    }
}

//int a[10]= {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};
// sort(a, a+10); // sorts this array.
//The prototype for sort is sort(startaddress, endaddress);
vector <int> q;
vector <int> v[500005];
map <int,int> ct;
int vis[500005];
int cnt = 1;

void dfs(int x){
    vis[x] = cnt;
    //insert all the adjacent non visited elements into queue.
    for(int i=0;i<v[x].size();i++){
        if(vis[v[x][i]]==0){
            dfs(v[x][i]);
        }
    }
}

void pairsort(int a[], int b[], int n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}

int32_t main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        a[i] = 0;
    }
    for(int i=n/2-1;i>=0;i--){
        cin>>a[i+n/2];
    }
    for(int i=1;i<n/2;i++){
        if(a[i]<a[i-1]){
            int t=a[i-1]-a[i];
            a[i]=a[i-1];
            a[n-1-i] -= t;
        }

        if(a[n-1-i]>a[n-i]){
            int t=a[n-i-1]-a[n-i];
            a[n-i-1]=a[n-i];
            a[i]+=t;
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i){
        cin >> b[i];
        a[n / 2 + i] = b[i];
    }
    reverse(a.begin() + n / 2 + 1, a.end());
    ll mx, mxa = 0, mn = a[n], mna = 1e18, d = 0;
    for (int i = n; i > n / 2; --i){
        mn = min(mn, a[i]);
        mxa = max(mxa, a[n - i + 1]);
        if (a[i] > mn){
            a[n - i + 1] += a[i] - mn;
            a[i] = mn;
        }
        if (mxa > a[n - i + 1]){
            a[i] -= mxa - a[n - i + 1];
            a[n - i + 1] = mxa;
            mn = min(mn, a[i]);
        }
    }
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<int> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i){
        cin >> b[i];
        a[n / 2 + i] = b[i];
    }
    reverse(a.begin() + n / 2 + 1, a.end());
    int mn = a[n], d = 0;
    for (int i=n; i>=n / 2; --i){
        mn = min(mn, a[i]);
        if (a[i] > mn){
            d += a[i] - mn;
            a[n - i + 1] += d;
            a[i] -= d;
        }
    }
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i){
        cin >> b[i];
        a[n / 2 + i] = b[i];
    }
    reverse(a.begin() + n / 2 + 1, a.end());
    ll mx, mn = a[n], mna = 1e18, d = 0;
    for (int i = n; i >= 1; --i){
        mn = min(mn, a[i]);
        if (a[i] > mn){
            d += a[i] - mn;
            a[n - i + 1] += d;
            a[i] -= d;
        }
    }
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i){
        cin >> b[i];
        a[n / 2 + i] = b[i];
    }
    reverse(a.begin() + n / 2 + 1, a.end());
    ll mx, mn = a[n], d = 0;
    for (int i = n; i > n / 2; --i){
        mn = min(mn, a[i]);
        if (a[i] > mn){
            d += a[i] - mn;
            a[n - i + 1] += d;
            a[i] -= d;
        }
        mn = min(mn, a[i]);
    }
    mx = a[1];
    for (int i=2; i<=n / 2; ++i){
        mx = max(a[i], mx);
        if (a[i] < mx){
            a[n - i + 1] -= mx - a[i];
            a[i] = mx;
        }
    }
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i){
        cin >> b[i];
        a[n / 2 + i] = b[i];
    }
    reverse(a.begin() + n / 2 + 1, a.end());
    ll mx, mxa = 0, mn = a[n], mna = 1e18, d = 0;
    for (int i = n; i > n / 2; --i){
        mn = min(mn, a[i]);
        mxa = max(mxa, a[n - i + 1]);
        if (a[i] > mn){
            d += a[i] - mn;
            a[n - i + 1] += d;
            a[i] -= d;
        }
        if (mxa > a[n - i + 1]){
            a[i] -= mxa - a[n - i + 1];
            a[n - i + 1] = mxa;
            mn = min(mn, a[i]);
        }
    }
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i) cin >> b[i];

    ll mx, mn = a[n], d = 0;
    a[n] = b[1];
    for (int i=2; i<=n / 2; ++i){
        int l = n - i + 1;
        mn = min(a[l + 1], mn);
        mx = max(a[i - 1], mx);
        a[l] = b[i];
        if (a[l] > a[l + 1]){
            a[i] += a[l] - a[l + 1];
            a[l] = a[l + 1];
        }
        if (a[i - 1] > a[i]){
            a[l] += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i){
        cin >> b[i];
        a[n / 2 + i] = b[i];
    }
    reverse(a.begin() + n / 2 + 1, a.end());
    ll mx, mn = a[n], mna = 1e18, d = 0;
    for (int i = n; i > n / 2; --i){
        mn = min(mn, a[i]);
        if (a[i] > mn){
            d += a[i] - mn;
            a[n - i + 1] += d;
            a[i] -= d;
        }
    }
    mx = a[1];
    for (int i=2; i<=n / 2; ++i){
        mx = max(a[i], mx);
        if (a[i] < mx){
            a[n - i + 1] -= mx - a[i];
            a[i] = mx;
        }
    }
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b){
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);

    int n;
    cin >> n;
    vector<ll> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i) cin >> b[i];

    ll mx, mn = a[n], d = 0;
    a[n] = b[1];
    for (int i=2; i<=n / 2; ++i){
        int l = n - i + 1;
        a[l] = b[i];
        if (a[l] > a[l + 1]){
            a[i] += a[l] - a[l + 1];
            a[l] = a[l + 1];
        }
        if (a[i - 1] > a[i]){
            a[l] -= a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    for (int j=1; j<=n; ++j) cout << a[j] << " ";
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define sqr(x) ((x) * (x))
#define pii pair<int, int>
#define stop system("pause");
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define ms(args...) {args}
#define sz(x) (int)x.size()
typedef long long ll;
typedef long double ld;
using namespace std;

template <typename T>
void vout(T x){
    cout << x << endl;
    exit(0);
}

int gcd(int a, int b){
    while(a && b)
    {
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}

const int inf = 2e9 + 7;
const ll INF = 1e18;
const int mod = 998244353;
const int N = 15;
int main()
{
    fast_io

//    freopen("backforth.in", "r", stdin);
//    freopen("backforth.out", "w", stdout);
    int n;
    cin >> n;
    vector<int> a(n + 1, 0), b(n + 1, 0);
    for (int i = 1; i <= n / 2; ++i){
        cin >> b[i];
        a[n / 2 + i] = b[i];
    }
    reverse(a.begin() + n / 2 + 1, a.end());
    for (int i=1; i<=n; ++i) cout << a[i] << " ";
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	int n;
	cin>>n;
	int b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	int arr[n];
	int l = 1;
	int r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	int best = 0;
	for(int i = 1; i < (n/2); i++){
			for(int j = best; j <= (b[i]/2); j++){
				if(j >= arr[l-1] && (b[i]-j) <= arr[r+1]) { arr[l] = j; arr[r] = (b[i]-j); l++; r--; break; best = j; }
			}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	ll n;
	cin>>n;
	ll b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	ll arr[n];
	ll l = 1;
	ll r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	ll best = 0;
	for(ll i = 1; i < (n/2); i++){
			if(arr[r+1] < b[i] ){
				best = b[i] - arr[r+1];
				if(arr[l-1] > best) best = arr[l-1];
			}
			for(ll j = best; j <= (b[i]/2); j++){
				if(j >= arr[l-1] && (b[i]-j) <= arr[r+1]) { arr[l] = j; arr[r] = (b[i]-j); l++; r--; best = j; break;}
			}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	ll n;
	cin>>n;
	ll b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	ll arr[n];
	ll l = 1;
	ll r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	ll best = 0;
	for(ll i = 1; i < (n/2); i++){
			if(arr[r+1] < b[i] ) best = b[i] - arr[r+1];
			for(ll j = best; j <= (b[i]/2); j++){
				if(j >= arr[l-1] && (b[i]-j) <= arr[r+1]) { arr[l] = j; arr[r] = (b[i]-j); l++; r--; best = j; break;}
			}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	int n;
	cin>>n;
	int b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	int arr[n];
	int l = 1;
	int r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	for(int i = 1; i < (n/2); i++){
			for(int j = 0; j <= (b[i]/2); j++){
				if(j >= arr[l-1] && (b[i]-j) <= arr[r+1]) { arr[l] = j; arr[r] = (b[i]-j); l++; r--; break; }
			}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	int n;
	cin>>n;
	int b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	int arr[n];
	int l = 1;
	int r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	for(int i = 1; i < (n/2); i++){
			vector<pair<int,int>> v;
			for(int j = 0; j <= (b[i]/2); j++){
				v.push_back({j,b[i]-j});
			}
			for(auto  f : v){
				if(f.first >= arr[l-1] && f.second <= arr[r+1]) { arr[l] = f.first; arr[r] = f.second; l++; r--; break; }
			}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	ll n;
	cin>>n;
	ll b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	ll arr[n];
	ll l = 1;
	ll r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	ll best = 0;
	for(ll i = 1; i < (n/2); i++){
			//if(arr[r+1] < b[i] ) best = b[i] - arr[r+1];
			for(ll j = best; j <= (b[i]/2); j++){
				if(j >= arr[l-1] && (b[i]-j) <= arr[r+1]) { arr[l] = j; arr[r] = (b[i]-j); l++; r--; best = j; break;}
			}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	int n;
	cin>>n;
	int b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	int arr[n];
	int l = 1;
	int r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	for(int i = 1; i < (n/2); i++){
		while(1){
			bool flag = false;
			vector<pair<int,int>> v;
			for(int j = 0; j <= (b[i]/2); j++){
				v.push_back({j,b[i]-j});
			}
			for(auto  f : v){
				if(f.first >= arr[l-1] && f.second <= arr[r+1]) { arr[l] = f.first; arr[r] = f.second; l++; r--; flag = true; 					break; }
			}
			if(flag) break;
		}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	ll n;
	cin>>n;
	ll b[n/2];
	mov(i,0,(n/2)) cin>>b[i];
	ll arr[n];
	ll l = 1;
	ll r = n-2;
	arr[0] = 0;
	arr[n-1] = b[0];
	ll best = 0;
	for(ll i = 1; i < (n/2); i++){
			for(ll j = best; j <= (b[i]/2); j++){
				if(j >= arr[l-1] && (b[i]-j) <= arr[r+1]) { arr[l] = j; arr[r] = (b[i]-j); l++; r--; break; best = j; }
			}
	}
	for(auto x : arr) cout<<x<<"\n";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x;
int main(){
    cin >> n;
    ll a[n],b[n];
    int j=n-1;
    a[0]=0;
    b[0]=0;
    cin >> x;
    a[j]=x;
    j--;
    for(int i=1; i<n/2; i++){
        cin >> x;
        b[i]=x;
        if(x>a[j+1] && x>b[i-1]){
            a[i]=x-a[j+1];
            a[j]=x-a[i];
        } else {
            a[i]=a[i-1];
            a[j]=x-a[i];
        }
        j--;
    }
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x;
int main(){
    cin >> n;
    ll a[n],b[n];
    int j=n-1;
    for(int i=0; i<n/2; i++){
        cin >> x;
        b[i]=x;
        if(x%2==0){
            a[i]=x/2;
            a[j]=x/2;
        } else {
            a[i]=x/2;
            a[j]=x/2+1;
        }
        j--;
    }
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x;
int main(){
    cin >> n;
    ll a[n],b[n];
    int j=n-1;
    for(int i=0; i<n/2; i++){
        cin >> x;
        b[i]=x;
    }
    sort(b,b+n/2);
    for(int i=0; i<n/2; i++){
        if(b[i]%2==0){
            a[i]=b[i]/2;
            a[j]=b[i]/2;
        } else {
            a[i]=b[i]/2;
            a[j]=b[i]/2+1;
        }
        j--;
    }
    sort(a,a+n);
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x;
int main(){
    cin >> n;
    ll a[n],b[n];
    int j=n-1;
    a[0]=0;
    cin >> x;
    a[j]=x;
    j--;
    for(int i=1; i<n/2; i++){
        cin >> x;
        b[i]=x;
        if(x>a[j+1] && x>b[i-1]){
            a[i]=x-a[j+1];
            a[j]=x-a[i];
        } else {
            a[i]=a[i-1];
            a[j]=x-a[i];
        }
        j--;
    }
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x;
int main(){
    cin >> n;
    ll a[n],b[n];
    int j=n-1;
    a[0]=0;
    cin >> x;
    a[j]=x;
    j--;
    for(int i=1; i<n/2; i++){
        cin >> x;
        if(x>a[j+1]){
            a[i]=x-a[j+1];
            a[j]=x-a[i];
        } else {
            a[i]=a[i-1];
            a[j]=x-a[i];
        }
        j--;
    }
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x;
int main(){
    cin >> n;
    ll a[n],b[n];
    int j=n-1;
    for(int i=0; i<n/2; i++){
        cin >> x;
        b[i]=x;
        if(x%2==0){
            a[i]=x/2;
            a[j]=x/2;
        } else {
            a[i]=x/2;
            a[j]=x/2+1;
        }
        j--;
    }
    sort(a,a+n);
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n , a[2*N] , b[N]  , cnt ;

int main(){

    cin >> n ;
    for ( int i = 1; i <= n / 2; i++ ){
            cin >> b[i] ;
    }
    for ( int i = 1; i <= n / 2 ; i++ ){
            a[i] = cnt ;
            a[n-i+1] = b[i] - cnt ;
            cnt++ ;
    }
    for ( int i = 1; i <= n ; i++ ){
            cout << a[i] << " " ;
    }

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

long long n , a[2*N] , b[N]  , cnt ;

int main(){

    cin >> n ;
    for ( int i = 1; i <= n / 2; i++ ){
            cin >> b[i] ;
    }
    a[0] = 0 ;
    a[n] = b[1] ;
    for ( int i = 2; i <= n / 2 ; i++ ){
            int x = a[i-1] ;
            int y = b[i] ;
            if ( y > a[n-i+2] ){
                    y = a[n-i+2] ;
                    x = b[i] - y ;
            }
            a[i] = x ;
            a[n-i+1] = y ;
    }
    for ( int i = 1; i <= n ; i++ ){
            cout << a[i] << " " ;
    }

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

long long n , a[2*N] , b[N]  , cnt ;

int main(){

    cin >> n ;
    for ( int i = 1; i <= n / 2; i++ ){
            cin >> b[i] ;
    }
    a[1] = 0  ;
    a[n] = b[1] ;
    int l = 2 , r = n - 1;
    for ( int i = 2; i <= n / 2 ; i++ ){
            if ( b[i-1] < b[i] ){
                    cnt++ ;
            }
            a[l++] = cnt ;
            a[r--] = b[i] - cnt ;
    }
    for ( int i = 1; i <= n ; i++ ){
            cout << a[i] << " " ;
    }

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

long long n , a[2*N] , b[N]  , cnt ;

int main(){

    cin >> n ;
    for ( int i = 1; i <= n / 2; i++ ){
            cin >> b[i] ;
    }
    a[0] = 0 ;
    a[n] = b[1] ;
    for ( int i = 2; i <= n / 2 ; i++ ){
            long long int x = a[i-1] ;
            long long int y = b[i] - x ;
            if ( y > a[n-i+2] ){
                    y = a[n-i+2] ;
                    x = b[i] - y ;
            }
            a[i] = x ;
            a[n-i+1] = y ;
    }
    for ( int i = 1; i <= n ; i++ ){
            cout << a[i] << " " ;
    }

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n , a[2*N] , b[N] ;

int main(){

    cin >> n ;
    for ( int i = 1; i <= n / 2; i++ ){
            cin >> b[i] ;
    }
    for ( int i = 1; i <= n / 2 ; i++ ){
            a[i] = 0 ;
            a[n-i+1] = b[i] ;
    }
    for ( int i = 1; i <= n ; i++ ){
            cout << a[i] << " " ;
    }

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

long long n , a[2*N] , b[N]  , cnt ;

int main(){

    cin >> n ;
    for ( int i = 1; i <= n / 2; i++ ){
            cin >> b[i] ;
    }
    a[0] = 0 ;
    a[n] = b[1] ;
    for ( int i = 2; i <= n / 2 ; i++ ){
            int x = a[i-1] ;
            int y = b[i] - x ;
            if ( y > a[n-i+2] ){
                    y = a[n-i+2] ;
                    x = b[i] - y ;
            }
            a[i] = x ;
            a[n-i+1] = y ;
    }
    for ( int i = 1; i <= n ; i++ ){
            cout << a[i] << " " ;
    }

}


#include<stdio.h>

using ll=long long;

ll inp[100000];
ll res[200000];

int main(void){
	int n;
	scanf("%d",&n);
	for(int i=0;2*i<n;i++){
		scanf("%lld",inp+i);
	}
	ll l=0,r=inp[0];
	for(int i=0;2*i<n;i++){
		if(r>inp[i]-l) r=inp[i]-l;
		else l=inp[i]-r;
		res[i]=l;
		res[n-i-1]=r;
	}
	for(int i=0;i<n;i++){
		printf("%lld ",inp[i]);
	}
}


#include <iostream>
#include <cmath>
#include <string.h>
#include <stdio.h>
#define eps 1e-6
int map[10010];
int n , k , temp;
bool flag;
int main() {
	int ans;
	while(~scanf("%d%d" , &n , &k)) {
		temp = n;
		ans = 0;
		for (int i = 0 ; i < n ; i ++) {
			scanf("%d" , & map[i]);
		}
		while(k) {
			flag = false;
			for (int i = temp - 1 ; i >= 0 ; i --) {
				if (map[i] < 0) {
					map[i] = map[i] * -1;
					k --;
					temp = i;
					flag = true;
					break;
				}
			}
			if (flag == false) break;
		}
		for (int i = 0 ; i < n ; i ++) {
			ans += map[i];
		}
		printf("%d\n" , ans);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[100010];
int main()
{
      int n,k;
      while(~scanf("%d%d",&n,&k))
      {
           int num=0;
           int sum=0;
           for(int i=0;i<n;i++)
           {
               scanf("%d",&a[i]);
               if(a[i]<0) num++;
               sum+=a[i];
           }
           if(num>=k){
              for(int i=0;i<k;i++)
                  sum=sum-2*a[i];
           }
           else if(num==0){
                if(k%2!=0)
                   sum=sum-2*a[0];
           }
           else if(num>0 && num<k){
                for(int i=0;i<num;i++)
                {
                    a[i]=a[i]*(-1);
                    sum=sum+2*a[i];
                }
                k=k-num;
                sort(a,a+n);
                if(k%2!=0)
                   sum=sum-2*a[0];
           }
          printf("%d\n",sum);
      }
     // system("pause");
      return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

int n,k;
int m[123456];

int main(){
int i,j;
while(~scanf("%d%d",&n,&k)){
for(i=0;i<n;i++){
scanf("%d",&m[i]);
if(k&&m[i]<=0){
k--;
m[i]=-m[i];
}
}

if(k%2){
sort(m,m+n);
m[0]=-m[0];
}

for(i=j=0;i<n;i++)
j+=m[i];
printf("%d\n",j);

}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<queue>
using namespace std;
void _qsort(int arr[],int l,int h){
	int key,ll=l,hh=h,q,temp;
	if(l>=h) return;
	q=rand()%(h-l)+l;
	temp=arr[q];
	arr[q]=arr[ll];
	arr[ll]=temp;
	key=arr[ll];
	while(ll<hh){
            while(ll<hh&&key<=arr[hh])
                hh--;
            if(ll<hh){
                arr[ll]=arr[hh];
                ll++;
            }
            while(ll<hh&&arr[ll]<=key)
                ll++;
            if(ll<hh){
                arr[hh]=arr[ll];
                hh--;
            }
    }
	arr[ll]=key;
	_qsort(arr,l,ll-1);
	_qsort(arr,ll+1,h);
}

int x[123456];
int main(){
	int a,b,c,i,j,k,temp,sum;
	while(scanf("%d%d",&a,&b)!=EOF){
		for(i=0;i<a;i++){
			scanf("%d",&x[i]);
		}
		_qsort(x,0,a-1);

		for(i=0,j=0;i<a;i++){
			if(x[i]>=0)break;
			x[i]=-x[i];
			j++;
			if(j==b)break;
		}
		if(j!=b){
			j=b-j;
			if(j%2!=0){
				if(x[i]>x[i-1]&&i>=1)
			    	x[i-1]=-x[i-1];
			    else {
					x[i]=-x[i];
				}
			}
		}
		for(i=0,sum=0;i<a;i++){
			sum+=x[i];
		}
		printf("%d\n",sum);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int a[100010],b[100010],c[100010];
int main(){
    int n,m,s,ss,i,k,t,ia,ib,sum1,sum2,sum;
    while(~scanf("%d %d",&n,&m)){
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(a));
        memset(c,0,sizeof(a));
        for(i=ia=ib=0,ss=10000; i<n; i++){
            scanf("%d",&s);
            if(s<0){
                c[i]=b[ib++]=-s;
                if(-s<ss)ss=-s;
            }
            else{
                c[i]=a[ia++]=s;
                if(s<ss)ss=s;
            }
        }
        sum=sum1=sum2=0;
        if(m>=ib){
            m-=ib;
            for(i=0;i<n;i++)
                sum+=c[i];
            if(m%2==0);
            else sum=sum-2*ss;
        }
        else{
          m=ib-m;
          for(i=0;i<m;i++)
          sum1+=b[i];
          for(i=0;i<ib;i++)
          sum2+=b[i];
          sum=sum2-2*sum1;
          for(i=0;i<ia;i++)
          sum+=a[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#define N 100010
using namespace std;
int a[N],b[N];
int main()
{
    int n,k;
	while(~scanf("%d%d",&n,&k)){
	    memset(b,0,sizeof(b));
	    int i,j=0,res=0,sign=0;
	    for(i=0;i<n;i++){
	        scanf("%d",&a[i]);
	       // res+=a[i];
	        if(a[i]<0){sign++;}
	    }//sort(b,b+j);
	    if(sign>=k){
            for(i=0;i<k;i++){
                a[i]*=-1;
            }
	    }else{
	        j=k-sign;
	        for(i=0;i<sign;i++){
                a[i]*=-1;
            }sort(a,a+n);
	        if(j&1)a[0]*=-1;//min
	    }
	    for(i=0;i<n;i++)res+=a[i];
	    printf("%d\n",res);
	}
	return 0;
}
/*
3 2
-1 -1 1
3 1
-1 -1 1
3 3
-1 -1 1
*/


#include<stdio.h>
#include<math.h>
#include<string.h>
void _qsort(int arr[],int l,int h){
    int m,key,t,ll,hh;
	if(l>=h)return;
else{
     m=rand()%(h-l)+l;
	 t=arr[m];
	 arr[m]=arr[l];
	 arr[l]=t;
	 key=arr[l];
     while(ll<hh){
                  while(ll<hh&&arr[hh]>key) hh--;
                  if(ll<hh)
                  {
                                            arr[ll]=arr[hh];
                                            ll++;
                                                }
                  while(ll<hh&&arr[ll]<key) ll++;
                  if(ll<hh)
                  {
                                            arr[hh]=arr[ll];
                                            hh--;
                                                }
                  }
     }
	arr[ll]=key;
	_qsort(arr,l,ll-1);
	_qsort(arr,ll+1,h);
}

int main(){
    int n,k,a[10002],i,sum,count,j,h,temp;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        if(a[i]>0)
            break;
    }
    count=i;
    if(count>=k){
        for(i=0;i<k;i++)
            a[i]=a[i]*(-1);
    }
    else{
        k-=count;
        for(i=0;i<count;i++)
            a[i]=a[i]*(-1);
        _qsort(a,0,n);
        /*for(j=0;j<n;j++){
            for(h=j+i;h<n;h++){
                if(a[j]<a[h]){
                    temp=a[j];
                    a[j]=a[h];
                    a[h]=temp;
                }
            }
        }*/
        if(k%2)
            a[0]=a[0]*(-1);
    }

    /*for(i=0;i<k;i++){
        if(a[i]>=0) break;
        else{
            a[i]=a[i]*(-1);
        }
    }*/
    sum=0;
    for(i=0;i<n;i++){
        sum=sum+a[i];
    }
    printf("%d\n",sum);
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int i, n, k, j=0, resultado=0;
    cin>> n >> k;
    int income[n];
    for(int i=0; i<n; i++)
        cin >> income[i];

    for( i=0; i< k; i++){
        if( income[i] <0 ){
            income[i] = -1*income[i];
//            cout << income[i]<< " ";
        }
        else j++;
    }
//    cout<< "j es par? "<< j <<endl;
    if( j %2  ){
        sort(income, income + n);
        income[0]= -1*income[0];
//        cout << income[0]<< endl;
    }

    for(int i=0; i<n; i++)
        resultado+= income[i];

    cout << resultado<< endl;
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, k, resultado=0;
    cin>> n >> k;
    int income[n];
    for(int i=0; i<n; i++)
        cin >> income[i];

    for(int i=0; i< k; i++)
        income[i]*= -1;

    for(int i=0; i<n; i++)
        resultado+= income[i];

    cout << resultado<< endl;
    return 0;
}