#include using namespace std; typedef long long ll; int main() { ll n; cin >> n; int a[200005]; for(int i = 0; i < n; i++) { cin >> a[i]; } ll ans = 0; for(int c = 0; c < 28; c++) { ans += (n * (n + 1) / 2) << c; ll s = 0; for(int i = 0; i < n; i++) { if(!((a[i] >> c) & 1)) { s++; } else { s = 0; } ans -= s << c; } } cout << ans << endl; }