#include <iostream>
#include <cassert>
#include <cstdio>
using namespace std;
const int N = 1e7 + 5;
int Len, a[N];
int B[N], C[N], res[N];
/**
C[]: temparary storage array
res[]: store result array,
*/
int cntPos, pos[N], cntNeg, neg[N];
void input() {
assert(freopen("CountingSort.inp", "r", stdin)); /// read your own input
cin >> Len;
for (int i = 1; i <= Len; i ++) {
cin >> a[i];
if (a[i] < 0) {
++ cntNeg;
neg[cntNeg] = a[i];
} else {
++ cntPos;
pos[cntPos] = a[i];
}
}
}
void cntSort(int A[], int n) {
int K = -1;
for (int i = 1; i <= n; i ++)
K = max(K, A[i]);
for (int i = 0; i <= K; i ++)
C[i] = 0;
for (int i = 1; i <= n; i ++)
++ C[A[i]];
for (int i = 1; i <= K; i ++)
C[i] += C[i - 1];
for (int j = n; j >= 1; j --) {
B[C[A[j]]] = A[j];
-- C[A[j]];
}
}
void cntNegSort(int A[], int n) { /// case negative array
for (int i = 1; i <= n; i ++)
A[i] = -A[i];
cntSort(A, n);
for (int i = 1; i <= cntNeg; i ++) {
res[i] = -B[cntNeg - i + 1];
}
}
void cntPosSort(int A[], int n) { /// case Positive array
cntSort(A, n);
for (int i = 1; i <= cntPos; i ++)
res[i + cntNeg] = B[i];
}
void output(int A[], int n) {
cout << n << endl;
for (int i = 1; i <= n; i ++)
cout << A[i] << " ";
}
int main() {
input();
if (cntNeg != 0)
cntNegSort(neg, cntNeg);
if (cntPos != 0)
cntPosSort(pos, cntPos);
output(res, Len);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGNzdGRpbz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMWU3ICsgNTsKaW50IExlbiwgYVtOXTsKaW50IEJbTl0sIENbTl0sIHJlc1tOXTsKLyoqCiAgICBDW106IHRlbXBhcmFyeSBzdG9yYWdlIGFycmF5CiAgICByZXNbXTogc3RvcmUgcmVzdWx0IGFycmF5LAogKi8KaW50IGNudFBvcywgcG9zW05dLCBjbnROZWcsIG5lZ1tOXTsKCnZvaWQgaW5wdXQoKSB7CiAgICBhc3NlcnQoZnJlb3BlbigiQ291bnRpbmdTb3J0LmlucCIsICJyIiwgc3RkaW4pKTsgLy8vIHJlYWQgeW91ciBvd24gaW5wdXQKICAgIGNpbiA+PiBMZW47CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBMZW47IGkgKyspIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgICAgICBpZiAoYVtpXSA8IDApIHsKICAgICAgICAgICAgKysgY250TmVnOwogICAgICAgICAgICBuZWdbY250TmVnXSA9IGFbaV07CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgKysgY250UG9zOwogICAgICAgICAgICBwb3NbY250UG9zXSA9IGFbaV07CiAgICAgICAgfQogICAgfQp9CnZvaWQgY250U29ydChpbnQgQVtdLCBpbnQgbikgewogICAgaW50IEsgPSAtMTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkgKyspCiAgICAgICAgSyA9IG1heChLLCBBW2ldKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDw9IEs7IGkgKyspCiAgICAgICAgQ1tpXSA9IDA7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpICsrKQogICAgICAgICsrIENbQVtpXV07CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBLOyBpICsrKQogICAgICAgIENbaV0gKz0gQ1tpIC0gMV07CiAgICBmb3IgKGludCBqID0gbjsgaiA+PSAxOyBqIC0tKSB7CiAgICAgICAgQltDW0Fbal1dXSA9IEFbal07CiAgICAgICAgLS0gQ1tBW2pdXTsKICAgIH0KfQp2b2lkIGNudE5lZ1NvcnQoaW50IEFbXSwgaW50IG4pIHsgLy8vIGNhc2UgbmVnYXRpdmUgYXJyYXkKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkgKyspCiAgICAgICAgQVtpXSA9IC1BW2ldOwogICAgY250U29ydChBLCBuKTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IGNudE5lZzsgaSArKykgewogICAgICAgIHJlc1tpXSA9IC1CW2NudE5lZyAtIGkgKyAxXTsKICAgIH0KfQp2b2lkIGNudFBvc1NvcnQoaW50IEFbXSwgaW50IG4pIHsgLy8vIGNhc2UgUG9zaXRpdmUgYXJyYXkKICAgIGNudFNvcnQoQSwgbik7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBjbnRQb3M7IGkgKyspCiAgICAgICAgcmVzW2kgKyBjbnROZWddID0gQltpXTsKfQp2b2lkIG91dHB1dChpbnQgQVtdLCBpbnQgbikgewogICAgY291dCA8PCBuIDw8IGVuZGw7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpICsrKQogICAgICAgIGNvdXQgPDwgQVtpXSA8PCAiICI7Cn0KaW50IG1haW4oKSB7CiAgICBpbnB1dCgpOwogICAgaWYgKGNudE5lZyAhPSAwKQogICAgICAgIGNudE5lZ1NvcnQobmVnLCBjbnROZWcpOwogICAgaWYgKGNudFBvcyAhPSAwKQogICAgY250UG9zU29ydChwb3MsIGNudFBvcyk7CiAgICBvdXRwdXQocmVzLCBMZW4pOwogICAgcmV0dXJuIDA7Cn0K