fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define el "\n"
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define se second
  7. #define fi first
  8. #define be begin()
  9. #define en end()
  10. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  11. ll check(ll n)
  12. {
  13. ll tmp = sqrt(n);
  14. if(tmp * tmp == n) return 1;
  15. return 0;
  16. }
  17. int main()
  18. {
  19. Faster;
  20. int n; cin >> n;
  21. ll ans = 0;
  22. vector<int> vt;
  23. while(n--)
  24. {
  25. ll x; cin >> x;
  26. if(check(x))
  27. {
  28. vt.push_back(x);
  29. ans += x;
  30. }
  31. }
  32. if(vt.size() != 0)
  33. {
  34. for(auto &x : vt) cout << x << " ";
  35. cout << el << ans;
  36. }
  37. return 0;
  38. }
  39.  
  40.  
Success #stdin #stdout 0.01s 5280KB
stdin
3
1 9 16
stdout
1 9 16 
26