#include <bits/stdc++.h>
using namespace std;
using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>; 
template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>;
#define INF 9223372036854775807LL/2
void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; }
template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}}
template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;}
template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;}
#define rep(i,n) for(ll i=0;i<n;i++)  
#define reps(si, i,n) for(ll i=si;i<n;i++) 

int main(){
    string s;
    ll n;

    cin>>n>>s;

    if(n==1){
        cout<<-1<<endl;
        return 0;
    }

    if(s.at(0)!=s.at(n-1)){
        cout<<1<<endl;
        return 0;
    }

    char sc=s.at(0);
    bool allsame=true;
    rep(i,n) if(sc!=s.at(i)) allsame=false;
    if(allsame){
        cout<<-1<<endl;
        return 0;
    }


    bool sucdif=false;

    reps(1,i,n) if(sc!=s.at(i) && sc!=s.at(i-1))sucdif=true;

    if(sucdif){
        
        cout<<2<<endl;
        return 0;
    }



    cout<<-1<<endl;





    
}
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;


ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; }
istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; }
template<typename T>
void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; }
void amax(int& a, int b) { a = max(a, b); }
void amin(int& a, int b) { a = min(a, b); }
int ceilInt(int a, int b) {
    if(!b) return 0;
    if(a%b) return a/b + 1;
    return a/b;
}

int INF = 1e18;
int MOD = 998244353;

void solve()
{
    int n; cin>>n;
    vi arr(n);
    rep(i, 0, n) cin>>arr[i];
    vi pre = arr;
    rep(i, 1, n) pre[i] += pre[i-1];
    int till = 0, mx = -1;
    rep(i, 0, n) {
        amax(mx, arr[i]);
        till += pre[i];
        cout<<till+mx*(i+1)<<endl;
    }
}


signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    rep(i, 0, t)
    {   
        // cout<<"Case #"<<i+1<<": ";
        solve();
    }
    return 0;
}