fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. string s;
  7. cin >> s;
  8. int val = 0, cnt = 0;
  9. string st = "";
  10. for (char x : s)
  11. if (x == '0') cnt++;
  12. else
  13. {
  14. val += x-'0';
  15. st += x;
  16. }
  17. if (val%3 != 0 or cnt == 0)
  18. {
  19. cout << -1;
  20. return 0;
  21. }
  22. sort(st.begin(),st.end(),greater<char>());
  23. for (char x : st) cout << x;
  24. for (int i = 1; i <= cnt; i++) cout << 0;
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
-1