Codeforces Round #569 (Div. 2) B. Nick and Array

Codeforces Round #569 (Div. 2)

 

B. Nick and Array

Nick had received an awesome array of integers a=[a1,a2,…,an] as a gift for his 5 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⋅…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 i (1≤i≤n) and do ai:=−ai−1.

For example, he can change array [3,−1,−4,1] to an array [−4,−1,3,1] after applying this operation to elements with indices i=1and i=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⋅…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 n (1≤n≤105) — number of integers in the array.

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

Output

Print n 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

 

The meaning of problems: Title number n mean to you, you can operate on any of a number: num = -num-1, let you output through the operation after the product of the maximum number n of a sequence of

Ideas: Obviously if it is positive or zero, after the operation becomes negative, the absolute value of a plus, since it is absolute increase, then we should put these numbers have become negative,

So the absolute value of the product is the biggest, it is clear that the product can not be negative, then we have to determine what n, if n is even, the product is positive on ok;

If n is odd, it should find the maximum absolute value of a negative number of n, in which, after the operation becomes positive, then the product becomes a positive maximum ......

 

 

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<map>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 using namespace std;
11 #define ll long long 
12 const int mod=1e9+7;
13 const int inf=1e9+7;
14 
15 const int maxn=1e5+5;
16 
17 int num[maxn];
18 
19 int main()
20 {
21     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
22     
23     int n;
24     
25     while(cin>>n)
26     {
27         
28         for(int i=0;i<n;i++)
29         {
30             cin>>num[i];
31             if(num[i]>=0)
32                 num[i]=-num[i]-1;
33         }
34         
35         if(n&1)
36         {
37             int minn=-1;
38             int mark_i=0;
39             
40             for(int i=0;i<n;i++)
41             {
42                 if(num[i]<minn)
43                 {
44                     minn=num[i];
45                     mark_i=i;
46                 }
47             }
48             
49             num[mark_i]=-num[mark_i]-1;
50             
51         }
52         
53         for(int i=0;i<n-1;i++)
54             cout<<num[i]<<" ";
55         cout<<num[n-1]<<endl;
56         
57     }
58     
59     return 0;
60 }

 

Guess you like

Origin www.cnblogs.com/xwl3109377858/p/11070253.html