fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define ll long long
  5. #define nl '\n'
  6. //#define int long long
  7.  
  8. void file()
  9. {
  10. #ifndef ONLINE_JUDGE
  11. freopen("in.txt", "r", stdin);
  12. freopen("out.txt", "w", stdout);
  13. #endif
  14. }
  15.  
  16. bool getBit(ll num, int idx)
  17. {
  18. return ((num >> idx) & 1);
  19. }
  20.  
  21.  
  22.  
  23. signed main()
  24. {
  25. ios::sync_with_stdio(false);
  26. cin.tie(nullptr);
  27. file();
  28.  
  29. int n;
  30. cin >> n;
  31.  
  32.  
  33. vector <int> fr(32, 0);
  34. for (int i = 0; i < n; i++)
  35. {
  36. int x;
  37. cin >> x;
  38.  
  39. for (int j = 0; j < 32; j++)
  40. fr[j] += getBit(x, j);
  41. }
  42.  
  43. ll res = 0;
  44. for (int i = 0; i < 32; i++)
  45. {
  46. ll x = fr[i], y = n - fr[i];
  47.  
  48. res += (1LL << i) * x * y;
  49. }
  50. cout << res << nl;
  51.  
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
0