#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
//constexpr ll MOD = 1e9 + 7;
constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<ll> S(N + 1, 0), M(N + 1, 0);
  for (ll i = 0; i < N; i++)
  {
    S.at(i + 1) = S.at(i) + A.at(i);
    M.at(i + 1) = max(M.at(i), A.at(i));
  }
  vector<ll> SS(N + 1, 0);
  for (ll i = 0; i < N; i++)
  {
    SS.at(i + 1) = SS.at(i) + S.at(i);
  }

  for (ll k = 0; k < N; k++)
  {
    ll ans = S.at(k + 1) + (k + 1) * M.at(k + 1) + SS.at(k + 1);
    cout << ans << '\n';
  }
}
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
using ll = long long;
using namespace std;
ll N;

int main(int argc, char *argv[]) {
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 1LL << 60;
  for (ll i = 0; i < (1 << (N - 1)); i++) {
    ll tmp = 0;
    ll total = 0;
    for (ll j = 0; j < N; j++) {
      tmp |= A[j];
      if ((1 << j) & i) {
        total ^= tmp;
        tmp = 0;
      }
    }
    total ^= tmp;
    ans = min(ans, total);
  }
  cout << ans << endl;
}
