#include <iostream>
#include <cmath>
using namespace std;
void cau3(int a[], int n) {
int i = 0, j = 0;
int val = 1;
while (i < n && j < n) {
if (!(val == 1 && a[i] > 0) || !(val == -1 && a[i] < 0)) {
j = i;
while (j < n && val*a[j] < 0) j++;
if (j == n) break;
swap(a[j], a[i]);
}
i++;
val *= -1;
}
}
int main() {
int a[] = {8, -8, -8, -8, -8, -8, 8};
int n = sizeof(a) / sizeof(a[0]);
cau3(a, n);
// Output the result
for (int i = 0; i < n; i++) {
printf("%d ", a[i]);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBjYXUzKGludCBhW10sIGludCBuKSB7CiAgICBpbnQgaSA9IDAsIGogPSAwOwogICAgaW50IHZhbCA9IDE7CiAgICB3aGlsZSAoaSA8IG4gJiYgaiA8IG4pIHsKICAgICAgICBpZiAoISh2YWwgPT0gMSAmJiBhW2ldID4gMCkgfHwgISh2YWwgPT0gLTEgJiYgYVtpXSA8IDApKSB7CiAgICAgICAgICAgIGogPSBpOwogICAgICAgICAgICB3aGlsZSAoaiA8IG4gJiYgdmFsKmFbal0gPCAwKSBqKys7CiAgICAgICAgICAgIGlmIChqID09IG4pIGJyZWFrOwogICAgICAgICAgICBzd2FwKGFbal0sIGFbaV0pOwogICAgICAgIH0KICAgICAgICBpKys7CiAgICAgICAgdmFsICo9IC0xOwogICAgfQp9CmludCBtYWluKCkgewogICAgaW50IGFbXSA9IHs4LCAtOCwgLTgsIC04LCAtOCwgLTgsIDh9OwogICAgaW50IG4gPSBzaXplb2YoYSkgLyBzaXplb2YoYVswXSk7CgogICAgY2F1MyhhLCBuKTsKCiAgICAvLyBPdXRwdXQgdGhlIHJlc3VsdAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBwcmludGYoIiVkICIsIGFbaV0pOwogICAgfQoKICAgIHJldHVybiAwOwp9