fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin>>n;
  7. int a[n+1],odd=0,even;
  8. for(int i=1;i<=n;++i)
  9. {
  10. cin>>a[i];
  11. if(a[i]==1) odd++;
  12. }
  13. even=n-odd;
  14. if(even>0)
  15. {
  16. cout<<2<<" ";
  17. even--;
  18. }
  19. if(odd>0)
  20. {
  21. cout<<1<<" ";
  22. odd--;
  23. }
  24. for(int i=1;i<=even;++i) cout<<2<<" ";
  25. for(int i=1;i<=odd;++i) cout<<1<<" ";
  26. return 0;
  27. }
Success #stdin #stdout 0s 15232KB
stdin
9
1 1 2 1 1 1 2 1 1
stdout
2 1 2 1 1 1 1 1 1