fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define GG ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  5. int main () { GG;
  6. int n,nz=0,nf=0,x;
  7. cin>>n;
  8. for(int i=0;i<n;i++)
  9. { cin>>x;
  10. if(x==5) nf++;
  11. else nz++;
  12. }
  13.  
  14. if(nf>=9 && nz>=1)
  15. { x=(nf/9) *9;
  16. for(int i=1;i<=x;i++)
  17. cout<<5;
  18. while(nz--)
  19. cout<<0;
  20. }
  21. else if(nz>=1)
  22. cout<<0;
  23. else
  24. cout<<"-1\n";
  25. return 0;}
Success #stdin #stdout 0.01s 5304KB
stdin
11
5 5 5 5 5 5 5 5 0 5 5
stdout
5555555550