#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
ld PI=3.14159265358979323846;
//using namespace atcoder;

int main(){
    ll N;
    string S;
    cin >> S;
    N = S.size();
    if(N==1){
        if(S == "8"){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }else if(N==2){
        if(S == "16" || S == "24" || S == "32" || S == "48" || S == "56" || S == "64" || S == "72" || S == "88" || S == "96"){
            cout << "Yes" << endl;
            return 0;
        }
        swap(S[0], S[1]);
        if(S == "16" || S == "24" || S == "32" || S == "48" || S == "56" || S == "64" || S == "72" || S == "88" || S == "96"){
            cout << "Yes" << endl;
            return 0;
        }
        cout << "No" << endl;
        return 0;
    }else{
        vector<ll> v(10);
        rep(i,N){
            ll c = S[i] - '0';
            v[c]++;
        }
        for(ll i = 112; i<1000; i += 8){
            bool flag = 1;
            string s = to_string(i);
            vector<ll> u(10);
            rep(j,3){
                u[s[j] - '0']++;
            }
            rep(j,10){
                if(v[j] < u[j] || u[0] > 0){
                    flag = 0;
                    break;
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+10;
struct BIT{
	int n,tr[N];
	void init(int _n){
		n=_n;
		memset(tr,0,sizeof tr);
	}
	void add(int x,int v){
		for(int i=x;i<=n;i+=i&-i)
		tr[i]+=v;
	}
	int sum(int x){
		int ans=0; 
		for(int i=x;i;i-=i&-i)
		ans+=tr[i];
		return ans;
	}
}tr;
int n,a[N];
ll ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		a[i]++;
	}
	tr.init(n+2);
	for(int i=1;i<=n;++i){
		int v=i-1-tr.sum(a[i]);
		ans+=v;
		tr.add(a[i],1);
	}
	for(int i=1;i<=n;++i){
		printf("%lld\n",ans);
		tr.add(a[i],-1);
		int v=tr.sum(a[i]);
		ans-=v;
		v=tr.sum(n+2)-tr.sum(a[i]);
		ans+=v;
		tr.add(a[i],1);
	}
	return 0;
}