Rei do Cangaço (连续数相加的速算)

滴答滴答---图木连接 

João has just bought a new game from the store: Lampião, o Rei do Cangaço. The main character of the game is Lampião, a known figure of Soteropolitan culture and probably the most famous cangaceiro of all time. There is a lot of controversy around the reputation of the cangaceiros, but João definitely must stick to their cause to beat this game.

In this game, João must control Lampião through a series of mini-games. There is one mini-game that caught João's attention: the treasure hunt. In this mini-game, there are nn houses in a row, numbered 1 to nn from left to right. Lampião is supposed to break into some of these houses. After breaking into a house, Lampião may earn or lose coins (some houses are guarded by jagunços, which are dangerous mercenaries crazy for money). More specifically, let CC be how many coins Lampião possesses before breaking into the ii-th house. Lampião will have C+aiC+ai coins after breaking into it, where aiai may actually be negative.

Lampião is initially standing in front of one of the houses. Also, he initially possesses 109109coins. The game is played in turns. The turns are numbered starting from one. In the ii-th turn, one of the two actions below can be taken:

  1. Move Lampião 3i3i houses to the right while breaking into every one of them, except for the final one. For instance, if this is the first turn, there are 4 houses, Lampião is standing by house 1 and this action is taken, Lampião will move to house 4 while breaking into houses 1, 2 and 3;
  2. Just move Lampião 3i3i houses to the right.

The game instantly ends when Lampião goes beyond the nn-th house.

Your task is to compute, for every possible starting position, the maximum profit Lampião can achieve if João acts optimally. The profit is defined as the difference between the final amount of coins and the initial amount of coins. Notice that the optimal profit is never negative, since João can choose not to take action (1).

Input

The first line contains an integer nn (1≤n≤500001≤n≤50000) – the number of houses in the mini-game.

The second line contains nn space-separated integers. The ii-th of them is aiai (−300≤ai≤300−300≤ai≤300).

Output

Print nn lines. The ii-th of them should contain a single integer – the maximum possible profit if Lampião starts from the ii-th house.

Examples

Input

5
1 2 3 4 -5

Output

6
9
2
0
0

Input

7
-3 -5 -7 -9 9 -2 -4

Output

0
3
0
0
3
0
0

Input

9
1 2 3 4 5 6 5 -7 2

Output

21
20
18
15
16
6
0
0
2

Input

4
1 -1 2 3

Output

5
4
5
3
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    a[0]=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        a[i]+=a[i-1];
    }
    int k;
    for(int i=1; i<=n; i++)
    {
        int t=3;
        int sum=0;
        for(int j=i; j<=n; j+=t,t+=3)
        {
            k=j+t-1;
            if(k>n)
                k=n;
            sum+=max(0,a[k]-a[j-1]);
        }
        printf("%d\n",sum);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值