#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e7+9;
struct node
{
int id,v,len;
} dp[19],l;
inline int read() {
int x = 0, f = 1; char c = getchar();
while (!isdigit(c)) { if (c == '-')f = -1; c = getchar(); }
while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
return x*f;
}
inline void write(int x){
if(x0)
{
putchar('0');
putchar(' ');
return ;
}
char F[200];
int tmp=x>0?x:-x;
int cnt=0;
while(tmp>0){
F[cnt++]=tmp%10+'0';
tmp/=10;
}
while(cnt>0){
putchar(F[--cnt]);
}
putchar(' ');
}
int main() {
int n;
n=read();
for(int i=1;i<=n;i++){
int x;
x=read();
l=dp[0];
for(int j=1;j<=x;j++){
if(dp[j].len>l.len) l=dp[j];
else if(dp[j].lenl.len){
if(dp[j].id<l.id) l=dp[j];
}
}
write(l.v+x);
dp[x].id=i,dp[x].len=l.len+1,dp[x].v=l.v+x;
}
return 0;
}