#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

class segmenttree{
    /*
    Copyright (c) 2021 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    int n;
    long long identity = 0;//単位元
    std::vector<long long> dat;
    public:
    
    void init(int N){
        n=1;
        while(n<N)n*=2;
        dat.clear();
        for(int i=0;i<2*n-1;++i){
            dat.push_back(identity);
        }
    }
    
    segmenttree(int N){
        init(N);
    }

    long long calc();
    
    void update(int k,long long a){
        k+=n-1;
        dat[k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[k]=calc(dat[2*k+1],dat[2*k+2]);
        }
    }
    
    long long query(long long a,long long b){
        a+=n;
        b+=n;
        long long R=0;
        while(a < b){
            if(a % 2 == 1){
                R = calc(R, dat[a - 1]);
                a += 1;
            }
            a /= 2;
            if(b % 2 == 1){
                b -= 1;
                R = calc(R, dat[b - 1]);
            }
            b /= 2;
        }
        return R;
    }
    
    long long calc(long long a,long long b){
        //your monoid here
        return max(a,b);
    }
    
};

int main(void){
    
    ll N;
    vector<ll> A,B(214514);
    
    cin >> N;
    REP(i,N){
        ll a;
        cin >> a;
        A.push_back(a);
    }
    
    B[0]=A[0];
    REP(i,N-1){
        B[i+1]=B[i]+A[i+1];
    }
    
    segmenttree SEG(N);
    REP(i,N){
        SEG.update(i,A[i]);
    }
    
    ll num = 0;
    REP(i,N){
        ll m = SEG.query(0,i+1);
        num += B[i];
        
        ll Ans = num;
        Ans += (i+1)*m;
        cout << Ans << endl;
    }
    
    
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool f(int n){
  string s = to_string(n);
  for(auto c : s){
    if(c == '7') return false;
  }
  while(n != 0){
    int now = n % 8;
    if(now == 7) return false;
    n /= 8;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  n++;
  int ans = 0;
  rep2(i, 1, n){
    if(f(i) == true) ans++;
  }
  cout << ans << endl;
  return 0;
}