Nick and Array

傳送門

Nick had received an awesome array of integers a=[a1,a2,…,an]a=[a1,a2,…,an] as a gift for his 55 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a1⋅a2⋅…ana1⋅a2⋅…an of its elements seemed to him not large enough.

He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index ii (1≤i≤n1≤i≤n) and do ai:=−ai−1ai:=−ai−1.

For example, he can change array [3,−1,−4,1][3,−1,−4,1] to an array [−4,−1,3,1][−4,−1,3,1] after applying this operation to elements with indices i=1i=1 and i=3i=3.

Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index.

Help Kolya and print the array with the maximal possible product of elements a1⋅a2⋅…ana1⋅a2⋅…an which can be received using only this operation in some order.

If there are multiple answers, print any of them.

Input

The first line contains integer nn (1≤n≤1051≤n≤105) — number of integers in the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (−106≤ai≤106−106≤ai≤106) — elements of the array

Output

Print nn numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array.

If there are multiple answers, print any of them.

Examples

Input

4
2 2 2 2

Output

-3 -3 -3 -3 

Input

1
0

Output

0 

Input

3
-3 -3 2

Output

-3 -3 2 

題意:給你一個數組,裏面的數能進行x=-x-1操作。這個數組裏的任意數字能進行任意次這樣的操作,問這個數組變化后里面n個數字的乘積最大是多少。

思路:x=-x-1這個操作是以2爲週期的無論進行多少次操作,只可能爲一個確定的負數或者非負數,而非負數的絕對值更大一些。爲了方便先把所有數都變成非負數。(這很重要)然後,當n爲偶數時,直接全變成負數輸出。當n爲奇數時,找出最大數。最大數輸出爲正數,其餘數輸出爲負數。因爲對n個數的乘積而言,最大數加減一個數相對其他數而言,對結果影響是最小的。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <string>

using namespace std;

typedef long long ll;
const int maxn=1e5+7;
const ll mod= 998244353;

int a[maxn];

int main()
{
//	freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	int Max=-1e7+7;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]<0) a[i]=(-1)*a[i]-1;	
		Max=max(Max,a[i]);
	} 
	int flag=0;//控制輸出 
	int flag1=0;//找到第一個最大值 
	if(n%2==0)
	{
		for(int i=0;i<n;i++)
		{
			if(flag) cout<<" ";
			flag=1;
			cout<<(-1)*a[i]-1;
		}
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			if(a[i]==Max&&!flag1) 
			{
				if(flag) cout<<" ";
				flag=1;
				flag1=1;
				cout<<a[i];
			}
			else 
			{
				if(flag) cout<<" ";
				flag=1;
				cout<<(-1)*a[i]-1;
			}
		}
	}
	
    return 0;
}

爲了我們愛的人,和愛我們的人,無論何時,我們都要樂觀向上、自信努力。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章