using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5");
WillReturn.Add("3 1 4 1 5");
//4 5 13 14 26
}
else if (InputPattern == "Input2") {
WillReturn.Add("6");
WillReturn.Add("1000000000 1000000000 1000000000 1000000000 1000000000 1000000000");
//1000000001 2000000001 3000000001 4000000001 5000000001 6000000001
}
else if (InputPattern == "Input3") {
WillReturn.Add("15");
WillReturn.Add("748 169 586 329 972 529 432 519 408 587 138 249 656 114 632");
//749 918 1921 2250 4861 5390 5822 6428 6836 7796 7934 8294 10109 10223 11373
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static long[] mHArr;
static LazySegmentTree mInsLazySegmentTree;
static long UB;
static void Main()
{
List<string> InputList = GetInputList();
mHArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();
UB = mHArr.GetUpperBound(0);
mInsLazySegmentTree = new LazySegmentTree(UB);
var sb = new System.Text.StringBuilder();
for (long I = 0; I <= UB; I++) {
long Result = ExecNibunhou(mHArr[I], I);
long RangeSta = Result;
long RangeEnd = I;
mInsLazySegmentTree.Internal_RangeUpdate(RangeSta, RangeEnd, mHArr[I]);
long RangeSum = mInsLazySegmentTree.Internal_Query(0, I);
sb.Append(RangeSum + 1);
sb.AppendLine();
}
Console.Write(sb.ToString());
}
// 遅延セグ木でK以下な、最小のIndを返す
static long ExecNibunhou(long pK, long pR)
{
if (mInsLazySegmentTree.Internal_Query(0, 0) <= pK) {
return 0;
}
long L = 0;
long R = pR;
while (L + 1 < R) {
long Mid = (L + R) / 2;
long MidVal = mInsLazySegmentTree.Internal_Query(Mid, Mid);
if (MidVal <= pK) {
R = Mid;
}
else {
L = Mid;
}
}
return R;
}
}
#region LazySegmentTree
// LazySegmentTreeクラス (RSQ and RUQ)
internal class LazySegmentTree
{
private long[] mTreeNodeArr;
private long UB; // 木のノードの配列のUB
private long mLeafCnt; // 葉ノードの数
private long mExternalArrUB;
private long?[] mLazyArr; // 遅延配列
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列
private struct RangeInfoDef
{
internal long StaInd;
internal long EndInd;
}
private RangeInfoDef[] mRangeInfo;
// ノードのIndexの列挙を返す
internal IEnumerable<long> GetNodeIndEnum()
{
for (long I = 0; I <= mExternalArrUB; I++) {
yield return I;
}
}
// 木のノードのUBを返す
internal long GetUB()
{
return mExternalArrUB;
}
// コンストラクタ
internal LazySegmentTree(long pExternalArrUB)
{
mExternalArrUB = pExternalArrUB;
// 簡単のため、葉ノード数を2のべき乗に
long ArrLength = 0;
for (long I = 1; I < long.MaxValue; I *= 2) {
ArrLength += I;
mLeafCnt = I;
if (pExternalArrUB + 1 < mLeafCnt) break;
}
// すべての値を0に
UB = ArrLength - 1;
mTreeNodeArr = new long[UB + 1];
for (int I = 0; I <= UB; I++) {
mTreeNodeArr[I] = 0;
}
// 遅延配列を初期化
mLazyArr = new long?[UB + 1];
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列の作成
mRangeInfo = new RangeInfoDef[UB + 1];
for (long I = 0; I <= UB; I++) {
if (I == 0) {
RangeInfoDef WillSet1;
WillSet1.StaInd = 0;
WillSet1.EndInd = mLeafCnt - 1;
mRangeInfo[I] = WillSet1;
continue;
}
long ParentNode = DeriveParentNode(I);
RangeInfoDef ParentRangeInfo = mRangeInfo[ParentNode];
RangeInfoDef WillSet2;
long Mid = (ParentRangeInfo.StaInd + ParentRangeInfo.EndInd) / 2;
if (I % 2 == 1) { // 奇数ノードの場合
WillSet2.StaInd = ParentRangeInfo.StaInd;
WillSet2.EndInd = Mid;
}
else { // 偶数ノードの場合
WillSet2.StaInd = Mid + 1;
WillSet2.EndInd = ParentRangeInfo.EndInd;
}
mRangeInfo[I] = WillSet2;
}
}
// 親ノードの添字を取得
private long DeriveParentNode(long pTarget)
{
return (pTarget - 1) / 2;
}
// 子ノードの添字(小さいほう)を取得
private long DeriveChildNode(long pTarget)
{
return pTarget * 2 + 1;
}
// カレントノードを引数として、遅延評価を行う
private void LazyEval(long pCurrNode)
{
// 遅延配列が空なら何もしない
if (mLazyArr[pCurrNode].HasValue == false) return;
long CurrNodeStaInd = mRangeInfo[pCurrNode].StaInd;
long CurrNodeEndInd = mRangeInfo[pCurrNode].EndInd;
// 遅延配列の値を反映する
mTreeNodeArr[pCurrNode] = mLazyArr[pCurrNode].Value * (CurrNodeEndInd - CurrNodeStaInd + 1);
long ChildNode1 = DeriveChildNode(pCurrNode);
long ChildNode2 = ChildNode1 + 1;
if (ChildNode1 <= UB) mLazyArr[ChildNode1] = mLazyArr[pCurrNode];
if (ChildNode2 <= UB) mLazyArr[ChildNode2] = mLazyArr[pCurrNode];
// 伝播が終わったので、自ノードの遅延配列を空にする
mLazyArr[pCurrNode] = null;
}
// 開始添字と終了添字とカレントノードを引数として、区間更新を行う
internal void Internal_RangeUpdate(long pSearchStaInd, long pSearchEndInd, long pUpdateVal)
{
Private_RangeUpdate(pSearchStaInd, pSearchEndInd, pUpdateVal, 0);
}
private void Private_RangeUpdate(long pSearchStaInd, long pSearchEndInd, long pUpdateVal, long pCurrNode)
{
// カレントノードの遅延評価を行う
LazyEval(pCurrNode);
long CurrNodeStaInd = mRangeInfo[pCurrNode].StaInd;
long CurrNodeEndInd = mRangeInfo[pCurrNode].EndInd;
// OverLapしてなければ、何もしない
if (CurrNodeEndInd < pSearchStaInd || pSearchEndInd < CurrNodeStaInd) {
return;
}
// 完全に含んでいれば、遅延配列に値を入れた後に評価
if (pSearchStaInd <= CurrNodeStaInd && CurrNodeEndInd <= pSearchEndInd) {
mLazyArr[pCurrNode] = pUpdateVal;
LazyEval(pCurrNode);
return;
}
// そうでなければ、2つの区間に再帰呼出し
long ChildNode1 = DeriveChildNode(pCurrNode);
long ChildNode2 = ChildNode1 + 1;
Private_RangeUpdate(pSearchStaInd, pSearchEndInd, pUpdateVal, ChildNode1);
Private_RangeUpdate(pSearchStaInd, pSearchEndInd, pUpdateVal, ChildNode2);
mTreeNodeArr[pCurrNode] = mTreeNodeArr[ChildNode1] + mTreeNodeArr[ChildNode2];
}
// 開始添字と終了添字とカレントノードを引数として、Sumを返す
internal long Internal_Query(long pSearchStaInd, long pSearchEndInd)
{
return Private_Query(pSearchStaInd, pSearchEndInd, 0);
}
private long Private_Query(long pSearchStaInd, long pSearchEndInd, long pCurrNode)
{
// 該当ノードを遅延評価する
LazyEval(pCurrNode);
long CurrNodeStaInd = mRangeInfo[pCurrNode].StaInd;
long CurrNodeEndInd = mRangeInfo[pCurrNode].EndInd;
// OverLapしてなければ、0
if (CurrNodeEndInd < pSearchStaInd || pSearchEndInd < CurrNodeStaInd)
return 0;
// 完全に含んでいれば、このノードの値
if (pSearchStaInd <= CurrNodeStaInd && CurrNodeEndInd <= pSearchEndInd)
return mTreeNodeArr[pCurrNode];
// そうでなければ、2つの子のSum
long ChildNode1 = DeriveChildNode(pCurrNode);
long ChildNode2 = ChildNode1 + 1;
long ChildVal1 = Private_Query(pSearchStaInd, pSearchEndInd, ChildNode1);
long ChildVal2 = Private_Query(pSearchStaInd, pSearchEndInd, ChildNode2);
return ChildVal1 + ChildVal2;
}
internal void DebugPrint()
{
for (long I = 0; I <= UB; I++) {
if (mLazyArr[I].HasValue) {
Console.WriteLine("mTreeNodeArr[{0}] = {1} , mLazyArr[{0}] = {2}",
I, mTreeNodeArr[I], mLazyArr[I]);
}
else {
Console.WriteLine("mTreeNodeArr[{0}] = {1}", I, mTreeNodeArr[I]);
}
}
}
}
#endregion