fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, t, f(0), z(0);
  6. cin >> n;
  7.  
  8. for (int i = 0; i < n; i++)
  9. {
  10. cin >> t;
  11. if (t == 0)
  12. z++;
  13. else if (t == 5)
  14. f++;
  15. }
  16.  
  17. if (z == 0)
  18. cout << -1 << endl;
  19. else if (f < 9)
  20. cout << 0 << endl;
  21. else
  22. {
  23. f -= f % 9;
  24. for (int i = 0; i < f; i++)
  25. cout << 5;
  26. for (int i = 0; i < z; i++)
  27. cout << 0;
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3472KB
stdin
11
5 5 5 5 5 5 5 5 0 5 5
stdout
5555555550